From 52887dda76c814cdec71b4b87e425ca9cf9c72e0 Mon Sep 17 00:00:00 2001 From: Immae Date: Sat, 8 Feb 2025 23:44:37 +0100 Subject: [PATCH] replace-workspace-values.py: Allow "package" key in Cargo.toml dependencies (#377721) * Allow "package" key in Cargo.toml dependencies * Update replace-workspace-values.py Some dependencies in Cargo.toml have a "package" key, which serves as an alias: ``` foo = { package = "original-name" ... } ``` which with nixpkgs triggered ``` > Copying to /nix/store/jay72vz43afnlymsah7v543zmnv6l7ck-gcli-0.3.0-vendor/subxt-0.37.0 > Patching /nix/store/jay72vz43afnlymsah7v543zmnv6l7ck-gcli-0.3.0-vendor/subxt-0.37.0/Cargo.toml > Traceback (most recent call last): > File "/nix/store/harh7nnnib9896dwqr0xjqrr0l8wdcw7-replace-workspace-values/bin/replace-workspace-values", line 127, in > main() > File "/nix/store/harh7nnnib9896dwqr0xjqrr0l8wdcw7-replace-workspace-values/bin/replace-workspace-values", line 104, in main > changed |= replace_dependencies(workspace_manifest, crate_manifest) > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > File "/nix/store/harh7nnnib9896dwqr0xjqrr0l8wdcw7-replace-workspace-values/bin/replace-workspace-values", line 77, in replace_dependencies > changed |= replace_key(workspace_manifest, root[key], "dependencies", k) > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > File "/nix/store/harh7nnnib9896dwqr0xjqrr0l8wdcw7-replace-workspace-values/bin/replace-workspace-values", line 58, in replace_key > raise Exception(f"Unhandled keys in inherited dependency {key}: {local_dep}") > Exception: Unhandled keys in inherited dependency codec: {'package': 'parity-scale-codec'} > Traceback (most recent call last): > File "/nix/store/qrf1j1w95va92fzv55lxpvw2dpm03bnr-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 314, in > main() > File "/nix/store/qrf1j1w95va92fzv55lxpvw2dpm03bnr-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 310, in main > subcommand_func() > File "/nix/store/qrf1j1w95va92fzv55lxpvw2dpm03bnr-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 302, in > "create-vendor": lambda: create_vendor(vendor_staging_dir=Path(sys.argv[2]), out_dir=Path(sys.argv[3])) > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > File "/nix/store/qrf1j1w95va92fzv55lxpvw2dpm03bnr-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 259, in create_vendor > copy_and_patch_git_crate_subtree(git_tree, pkg["name"], crate_out_dir) > File "/nix/store/qrf1j1w95va92fzv55lxpvw2dpm03bnr-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 215, in copy_and_patch_git_crate_subtree > subprocess.check_output(cmd) > File "/nix/store/qrc496n6fsqp4p5m5h8wmw5d5jwyw5mr-python3-3.12.8/lib/python3.12/subprocess.py", line 466, in check_output > return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > File "/nix/store/qrc496n6fsqp4p5m5h8wmw5d5jwyw5mr-python3-3.12.8/lib/python3.12/subprocess.py", line 571, in run > raise CalledProcessError(retcode, process.args, > subprocess.CalledProcessError: Command '['replace-workspace-values', '/nix/store/jay72vz43afnlymsah7v543zmnv6l7ck-gcli-0.3.0-vendor/subxt-0.37.0/Cargo.toml', '/nix/store/c4jdggg9ihgi032pyc7g6ysdpb30xv1r-gcli-0.3.0-vendor-staging/git/00f181c1a5d8986e7146ddc72a745c793a9a1d8e/Cargo.toml']' returned non-zero exit status 1. ``` This fixes that --- pkgs/build-support/rust/replace-workspace-values.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/build-support/rust/replace-workspace-values.py b/pkgs/build-support/rust/replace-workspace-values.py index 003023ff2560..a03bf42eae38 100644 --- a/pkgs/build-support/rust/replace-workspace-values.py +++ b/pkgs/build-support/rust/replace-workspace-values.py @@ -53,6 +53,9 @@ def replace_key( if optional: final["optional"] = True + if "package" in local_dep: + final["package"] = local_dep.pop("package") + if local_dep: raise Exception(f"Unhandled keys in inherited dependency {key}: {local_dep}")