crane/lib/downloadCargoPackageFromGit.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.0 KiB
Nix
Raw Normal View History

{ cargo
, jq
, lib
, remarshal
, runCommandLocal
2022-02-08 07:03:12 +03:00
}:
{ git
2022-02-08 07:03:12 +03:00
, rev
, ref ? null
, allRefs ? ref == null
2022-10-24 02:20:22 +03:00
}:
2022-02-08 07:03:12 +03:00
let
maybeRef = lib.optionalAttrs (ref != null) { inherit ref; };
repo = builtins.fetchGit (maybeRef // {
inherit allRefs rev;
2022-02-08 07:03:12 +03:00
url = git;
submodules = true;
});
deps = {
nativeBuildInputs = [
cargo
jq
remarshal
];
};
2022-02-08 07:03:12 +03:00
in
runCommandLocal "cargo-git" deps ''
mkdir -p $out
existing_crates=()
while read -r cargoToml; do
local crate=$(toml2json <"$cargoToml" | \
jq -r 'select(.package != null) | .package | "\(.name)-\(.version)"'
)
if [ -n "$crate" ]; then
if [[ " ''${existing_crates[*]} " =~ " $crate " ]]; then
>&2 echo "warning: skipping duplicate package $crate found at $cargoToml"
continue
fi
local dest="$out/$crate"
cp -r "$(dirname "$cargoToml")" "$dest"
chmod +w "$dest"
echo '{"files":{}, "package":null}' > "$dest/.cargo-checksum.json"
existing_crates+=("$crate")
fi
done < <(find ${repo} -name Cargo.toml)
2022-02-08 07:03:12 +03:00
''