Skip to content

Commit

Permalink
cargo: Embed resolved manifest
Browse files Browse the repository at this point in the history
Cargo with `inherit-workspace` feature requires workspace packages
Cargo.toml's to be resolved when using vendored sources, because
the workspace manifest won't be available when building them.
  • Loading branch information
gasinvein committed Mar 28, 2023
1 parent 67fc223 commit de81f43
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cargo/flatpak-cargo-generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from urllib.parse import urlparse, ParseResult, parse_qs
import os
import contextlib
import copy
import glob
import subprocess
import argparse
Expand Down Expand Up @@ -121,6 +122,23 @@ class _GitPackage(NamedTuple):
package: _TomlType
workspace: Optional[_TomlType]

@property
def normalized(self) -> _TomlType:
package = copy.deepcopy(self.package)
if self.workspace is None:
return package
for section_key, section in package.items():
# XXX We ignore top-level lists here; maybe we should iterate over list items, too
if not isinstance(section, dict):
continue
for key, value in section.items():
if not isinstance(value, dict):
continue
if not value.get('workspace'):
continue
package[section_key][key] = self.workspace[section_key][key]
return package


_GitPackagesType = Dict[str, _GitPackage]

Expand Down Expand Up @@ -293,6 +311,12 @@ async def get_git_package_sources(
f'cp -r --reflink=auto "{pkg_repo_dir}" "{CARGO_CRATES}/{name}"'
],
},
{
'type': 'inline',
'contents': toml.dumps(git_pkg.normalized),
'dest': f'{CARGO_CRATES}/{name}', #-{version}',
'dest-filename': 'Cargo.toml',
},
{
'type': 'inline',
'contents': json.dumps({'package': None, 'files': {}}),
Expand Down

0 comments on commit de81f43

Please sign in to comment.