mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-22 14:01:41 +03:00
fix(rust-cargo-vendor): patch manifest attributes that use workspace.package aswell (#1082)
This commit is contained in:
parent
bf02c10f6d
commit
98c1c2e934
@ -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
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user