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:
if ($workspaceDependencies."\(.key)" | type) == "object"
then [.value, $workspaceDependencies."\(.key)"] | add
else [.value, {"version":$workspaceDependencies."\(.key)"}] | add
if ($workspaceAttrs."dependencies"."\(.key)" | type) == "object"
then [.value, $workspaceAttrs."dependencies"."\(.key)"] | add
else [.value, {"version":$workspaceAttrs."dependencies"."\(.key)"}] | add
end
# remove workspace option from the dependency
| del(.workspace)
@ -33,8 +33,28 @@ def mapWorkspaceDeps:
| 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
| mapWorkspaceAttrs("package")
| if has("target")
then
# normalize workspace inherited deps in target specific deps

View File

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