Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ptxd_make_world_extract_cargo: improve workspace handling
To handle all downloads manually, PTXdist basically fakes vendoring all dependencies. This can cause problems with workspaces where packages inherit from the workspace. 'cargo vendor' used to have the same problem[1] and fixed it by rewriting the Cargo.toml. Do the same thing here to fix this. [1] rust-lang/cargo#11192 Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
- Loading branch information
1 parent
65f8db9
commit 51496ff
Showing
2 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import toml | ||
from copy import deepcopy | ||
from os.path import dirname, join, relpath | ||
|
||
parser = argparse.ArgumentParser(description='vendor cargo workspace package') | ||
parser.add_argument('--input') | ||
parser.add_argument('--output') | ||
parser.add_argument('--workspace') | ||
args = parser.parse_args() | ||
|
||
pkg_input = toml.load(args.input) | ||
pkg_output = deepcopy(pkg_input) | ||
workspace = toml.load(args.workspace) | ||
|
||
rel = relpath(dirname(args.workspace), dirname(args.input)) | ||
|
||
for section, data in pkg_input.items(): | ||
if not isinstance(data, dict): | ||
continue | ||
for key, value in data.items(): | ||
if not isinstance(value, dict): | ||
continue | ||
if not 'workspace' in value: | ||
continue | ||
if not value['workspace']: | ||
continue | ||
if not 'workspace' in workspace: | ||
print(f'missing section "workspace" {args.workspace}') | ||
exit(1) | ||
if section in workspace['workspace']: | ||
wsection = section | ||
else: | ||
wsection = section.removeprefix('dev-') | ||
if not wsection in workspace['workspace']: | ||
print(f'missing section "workspace.{section}" in {args.workspace} for {args.input}') | ||
exit(1) | ||
try: | ||
copy = deepcopy(workspace['workspace'][wsection][key]) | ||
except KeyError: | ||
print(f'missing "workspace.{section}.{key}" in {args.workspace} for {args.input}') | ||
exit(1) | ||
if isinstance(copy, dict): | ||
if 'path' in copy: | ||
copy['path'] = join(rel, copy['path']) | ||
pkg_output[section][key].pop('workspace') | ||
pkg_output[section][key].update(copy) | ||
else: | ||
pkg_output[section][key] = copy | ||
|
||
|
||
with open(args.output, 'w') as f: | ||
toml.dump(pkg_output, f) |