Skip to content

Commit

Permalink
fix(rust-cargo-vendor): patch manifest attributes that use workspace.…
Browse files Browse the repository at this point in the history
…package aswell (#1082)
  • Loading branch information
yusdacra authored Dec 20, 2024
1 parent bf02c10 commit 98c1c2e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions modules/dream2nix/rust-cargo-vendor/vendor.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 98c1c2e

Please sign in to comment.