importCargoLock: git deps with rev, branch or tag

Previously importCargoLog only recognized git dependencies with `rev =`.
This adds support for git dependencies with `branch =` or `tag =`.
This commit is contained in:
Yureka 2021-09-10 19:30:05 +02:00
parent 91a4081ce4
commit 00b1ac5b23

View file

@ -12,14 +12,15 @@ let
# Parse a git source into different components.
parseGit = src:
let
parts = builtins.match ''git\+([^?]+)(\?rev=(.*))?#(.*)?'' src;
rev = builtins.elemAt parts 2;
parts = builtins.match ''git\+([^?]+)(\?(rev|tag|branch)=(.*))?#(.*)'' src;
type = builtins.elemAt parts 2; # rev, tag or branch
value = builtins.elemAt parts 3;
in
if parts == null then null
else {
url = builtins.elemAt parts 0;
sha = builtins.elemAt parts 3;
} // lib.optionalAttrs (rev != null) { inherit rev; };
sha = builtins.elemAt parts 4;
} // lib.optionalAttrs (type != null) { inherit type value; };
packages = (builtins.fromTOML (builtins.readFile lockFile)).package;
@ -137,7 +138,7 @@ let
cat > $out/.cargo-config <<EOF
[source."${gitParts.url}"]
git = "${gitParts.url}"
${lib.optionalString (gitParts ? rev) "rev = \"${gitParts.rev}\""}
${lib.optionalString (gitParts ? type) "${gitParts.type} = \"${gitParts.value}\""}
replace-with = "vendored-sources"
EOF
''