Skip to content

Commit

Permalink
importCargoLock: git deps with rev, branch or tag
Browse files Browse the repository at this point in the history
Previously importCargoLog only recognized git dependencies with `rev =`.
This adds support for git dependencies with `branch =` or `tag =`.
  • Loading branch information
yu-re-ka committed Sep 10, 2021
1 parent 91a4081 commit 00b1ac5
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pkgs/build-support/rust/import-cargo-lock.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
''
Expand Down

0 comments on commit 00b1ac5

Please sign in to comment.