mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 15:03:28 +00:00
rust: find nested packages in git repositories
this mimics the heuristic cargo uses for finding crates in their git repositories ([cargo-issue-1462]). [cargo-issue-1462]: https://github.com/rust-lang/cargo/issues/1462
This commit is contained in:
parent
8dd1b6f151
commit
b2aa19efe7
@ -125,20 +125,31 @@ let
|
|||||||
};
|
};
|
||||||
in runCommand "${pkg.name}-${pkg.version}" {} ''
|
in runCommand "${pkg.name}-${pkg.version}" {} ''
|
||||||
tree=${tree}
|
tree=${tree}
|
||||||
if grep --quiet '\[workspace\]' "$tree/Cargo.toml"; then
|
|
||||||
# If the target package is in a workspace, find the crate path
|
|
||||||
# using `cargo metadata`.
|
|
||||||
crateCargoTOML=$(${cargo}/bin/cargo metadata --format-version 1 --no-deps --manifest-path $tree/Cargo.toml | \
|
|
||||||
${jq}/bin/jq -r '.packages[] | select(.name == "${pkg.name}") | .manifest_path')
|
|
||||||
|
|
||||||
|
# If the target package is in a workspace, or if it's the top-level
|
||||||
|
# crate, we should find the crate path using `cargo metadata`.
|
||||||
|
crateCargoTOML=$(${cargo}/bin/cargo metadata --format-version 1 --no-deps --manifest-path $tree/Cargo.toml | \
|
||||||
|
${jq}/bin/jq -r '.packages[] | select(.name == "${pkg.name}") | .manifest_path')
|
||||||
|
|
||||||
|
# If the repository is not a workspace the package might be in a subdirectory.
|
||||||
|
if [[ -z $crateCargoTOML ]]; then
|
||||||
|
for manifest in $(find $tree -name "Cargo.toml"); do
|
||||||
|
echo Looking at $manifest
|
||||||
|
crateCargoTOML=$(${cargo}/bin/cargo metadata --format-version 1 --no-deps --manifest-path "$manifest" | ${jq}/bin/jq -r '.packages[] | select(.name == "${pkg.name}") | .manifest_path' || :)
|
||||||
if [[ ! -z $crateCargoTOML ]]; then
|
if [[ ! -z $crateCargoTOML ]]; then
|
||||||
tree=$(dirname $crateCargoTOML)
|
break
|
||||||
else
|
|
||||||
>&2 echo "Cannot find path for crate '${pkg.name}-${pkg.version}' in the Cargo workspace in: $tree"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -z $crateCargoTOML ]]; then
|
||||||
|
>&2 echo "Cannot find path for crate '${pkg.name}-${pkg.version}' in the tree in: $tree"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo Found crate ${pkg.name} at $crateCargoTOML
|
||||||
|
tree=$(dirname $crateCargoTOML)
|
||||||
|
|
||||||
cp -prvd "$tree/" $out
|
cp -prvd "$tree/" $out
|
||||||
chmod u+w $out
|
chmod u+w $out
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user