fix(rust-cargo-vendor): patch manifest attributes that use workspace.package aswell (#1082)

This commit is contained in:
dusk 2024-12-20 21:13:37 +00:00 committed by GitHub
parent bf02c10f6d
commit 98c1c2e934
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 9 deletions

View File

@ -1,7 +1,7 @@
def normalizeWorkspaceDep: def normalizeWorkspaceDep:
if ($workspaceDependencies."\(.key)" | type) == "object" if ($workspaceAttrs."dependencies"."\(.key)" | type) == "object"
then [.value, $workspaceDependencies."\(.key)"] | add then [.value, $workspaceAttrs."dependencies"."\(.key)"] | add
else [.value, {"version":$workspaceDependencies."\(.key)"}] | add else [.value, {"version":$workspaceAttrs."dependencies"."\(.key)"}] | add
end end
# remove workspace option from the dependency # remove workspace option from the dependency
| del(.workspace) | del(.workspace)
@ -33,8 +33,28 @@ def mapWorkspaceDeps:
| mapWorkspaceDepsFor("build-dependencies") | mapWorkspaceDepsFor("build-dependencies")
; ;
# normalize workspace inherited deps # normalizes workpsace inherited package attributes
def mapWorkspaceAttrs(name):
if has(name)
then
."\(name)" = (
."\(name)"
| to_entries
| map(
if (.value | type) == "object" and .value.workspace == true
then .value = $workspaceAttrs."\(name)"."\(.key)"
else .
end
)
| from_entries
)
else .
end
;
# normalize workspace inherited deps and attributes
mapWorkspaceDeps mapWorkspaceDeps
| mapWorkspaceAttrs("package")
| if has("target") | if has("target")
then then
# normalize workspace inherited deps in target specific deps # normalize workspace inherited deps in target specific deps

View File

@ -94,16 +94,16 @@ in rec {
exit 1 exit 1
fi fi
else else
# we need to patch dependencies with `workspace = true` (workspace inheritance) # we need to patch manifest attributes with `workspace = true` (workspace inheritance)
workspaceDependencies="$(cat "$tree/Cargo.toml" | ${tomlToJson} | ${jq} -cr '.workspace.dependencies')" workspaceAttrs="$(cat "$tree/Cargo.toml" | ${tomlToJson} | ${jq} -cr '.workspace')"
if [[ "$workspaceDependencies" != "null" ]]; then if [[ "$workspaceAttrs" != "null" ]]; then
tree="$(pwd)/${pkg.name}-${pkg.version}" tree="$(pwd)/${pkg.name}-${pkg.version}"
cp -prd --no-preserve=mode,ownership "$(dirname $crateCargoTOML)" "$tree" cp -prd --no-preserve=mode,ownership "$(dirname $crateCargoTOML)" "$tree"
crateCargoTOML="$tree/Cargo.toml" crateCargoTOML="$tree/Cargo.toml"
cat "$crateCargoTOML" \ cat "$crateCargoTOML" \
| ${tomlToJson} \ | ${tomlToJson} \
| ${jq} -cr --argjson workspaceDependencies "$workspaceDependencies" \ | ${jq} -cr --argjson workspaceAttrs "$workspaceAttrs" \
--from-file ${./patch-workspace-deps.jq} \ --from-file ${./patch-workspace.jq} \
| ${jsonToToml} \ | ${jsonToToml} \
| ${sponge} "$crateCargoTOML" | ${sponge} "$crateCargoTOML"
fi fi