Merge pull request #137303 from yu-re-ka/feature/import-cargo-lock-git-branch
importCargoLock: git deps with rev, branch or tag
This commit is contained in:
commit
2d3131692e
17 changed files with 262 additions and 24 deletions
|
@ -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
|
||||
''
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
{ callPackage }:
|
||||
|
||||
# Build like this from nixpkgs root:
|
||||
# $ nix-build -A tests.importCargoLock
|
||||
{
|
||||
basic = callPackage ./basic { };
|
||||
gitDependency = callPackage ./git-dependency { };
|
||||
gitDependencyNoRev = callPackage ./git-dependency-no-rev { };
|
||||
gitDependencyRev = callPackage ./git-dependency-rev { };
|
||||
gitDependencyTag = callPackage ./git-dependency-tag { };
|
||||
gitDependencyBranch = callPackage ./git-dependency-branch { };
|
||||
maturin = callPackage ./maturin { };
|
||||
}
|
||||
|
|
72
pkgs/build-support/rust/test/import-cargo-lock/git-dependency-branch/Cargo.lock
generated
Normal file
72
pkgs/build-support/rust/test/import-cargo-lock/git-dependency-branch/Cargo.lock
generated
Normal file
|
@ -0,0 +1,72 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "git-dependency-branch"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.94"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.4"
|
||||
source = "git+https://github.com/rust-random/rand.git?branch=master#fcc5baf31565a94f63dce41c2e739e6f182475f4"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "git+https://github.com/rust-random/rand.git?branch=master#fcc5baf31565a94f63dce41c2e739e6f182475f4"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.3"
|
||||
source = "git+https://github.com/rust-random/rand.git?branch=master#fcc5baf31565a94f63dce41c2e739e6f182475f4"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
|
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "git-dependency-branch"
|
||||
version = "0.1.0"
|
||||
authors = ["Daniël de Kok <me@danieldk.eu>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
rand = { git = "https://github.com/rust-random/rand.git", branch = "master" }
|
|
@ -1,7 +1,7 @@
|
|||
{ rustPlatform }:
|
||||
|
||||
rustPlatform.buildRustPackage {
|
||||
pname = "git-dependency-no-rev";
|
||||
pname = "git-dependency-branch";
|
||||
version = "0.1.0";
|
||||
|
||||
src = ./.;
|
||||
|
@ -9,13 +9,13 @@ rustPlatform.buildRustPackage {
|
|||
cargoLock = {
|
||||
lockFile = ./Cargo.lock;
|
||||
outputHashes = {
|
||||
"rand-0.8.3" = "0ya2hia3cn31qa8894s3av2s8j5bjwb6yq92k0jsnlx7jid0jwqa";
|
||||
"rand-0.8.4" = "1ilk9wvfw3mdm57g199ys8f5nrgdrh0n3a4c8b7nz6lgnqvfrv6z";
|
||||
};
|
||||
};
|
||||
|
||||
doInstallCheck = true;
|
||||
|
||||
installCheckPhase = ''
|
||||
$out/bin/git-dependency-no-rev
|
||||
$out/bin/git-dependency-branch
|
||||
'';
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
|
@ -18,7 +20,7 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "git-dependency-no-rev"
|
||||
name = "git-dependency-rev"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rand",
|
||||
|
@ -39,7 +41,7 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
|||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.3"
|
||||
source = "git+https://github.com/rust-random/rand.git#f0e01ee0a7257753cc51b291f62666f4765923ef"
|
||||
source = "git+https://github.com/rust-random/rand.git?rev=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
|
@ -50,7 +52,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.0"
|
||||
source = "git+https://github.com/rust-random/rand.git#f0e01ee0a7257753cc51b291f62666f4765923ef"
|
||||
source = "git+https://github.com/rust-random/rand.git?rev=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
|
@ -58,8 +60,8 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.2"
|
||||
source = "git+https://github.com/rust-random/rand.git#f0e01ee0a7257753cc51b291f62666f4765923ef"
|
||||
version = "0.6.1"
|
||||
source = "git+https://github.com/rust-random/rand.git?rev=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
@ -67,7 +69,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.3.0"
|
||||
source = "git+https://github.com/rust-random/rand.git#f0e01ee0a7257753cc51b291f62666f4765923ef"
|
||||
source = "git+https://github.com/rust-random/rand.git?rev=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
|
@ -1,8 +1,8 @@
|
|||
[package]
|
||||
name = "git-dependency-no-rev"
|
||||
name = "git-dependency-rev"
|
||||
version = "0.1.0"
|
||||
authors = ["Daniël de Kok <me@danieldk.eu>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
rand = { git = "https://github.com/rust-random/rand.git" }
|
||||
rand = { git = "https://github.com/rust-random/rand.git", rev = "0.8.3" }
|
|
@ -0,0 +1,21 @@
|
|||
{ rustPlatform }:
|
||||
|
||||
rustPlatform.buildRustPackage {
|
||||
pname = "git-dependency-rev";
|
||||
version = "0.1.0";
|
||||
|
||||
src = ./.;
|
||||
|
||||
cargoLock = {
|
||||
lockFile = ./Cargo.lock;
|
||||
outputHashes = {
|
||||
"rand-0.8.3" = "0l3p174bpwia61vcvxz5mw65a13ri3wy94z04xrnyy5lzciykz4f";
|
||||
};
|
||||
};
|
||||
|
||||
doInstallCheck = true;
|
||||
|
||||
installCheckPhase = ''
|
||||
$out/bin/git-dependency-rev
|
||||
'';
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
use rand::Rng;
|
||||
|
||||
fn main() {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// Always draw zero :).
|
||||
let roll: u8 = rng.gen_range(0..1);
|
||||
assert_eq!(roll, 0);
|
||||
}
|
81
pkgs/build-support/rust/test/import-cargo-lock/git-dependency-tag/Cargo.lock
generated
Normal file
81
pkgs/build-support/rust/test/import-cargo-lock/git-dependency-tag/Cargo.lock
generated
Normal file
|
@ -0,0 +1,81 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "git-dependency-tag"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.94"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.3"
|
||||
source = "git+https://github.com/rust-random/rand.git?tag=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
"rand_hc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.0"
|
||||
source = "git+https://github.com/rust-random/rand.git?tag=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.1"
|
||||
source = "git+https://github.com/rust-random/rand.git?tag=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.3.0"
|
||||
source = "git+https://github.com/rust-random/rand.git?tag=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
|
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "git-dependency-tag"
|
||||
version = "0.1.0"
|
||||
authors = ["Daniël de Kok <me@danieldk.eu>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
rand = { git = "https://github.com/rust-random/rand.git", tag = "0.8.3" }
|
|
@ -0,0 +1,21 @@
|
|||
{ rustPlatform }:
|
||||
|
||||
rustPlatform.buildRustPackage {
|
||||
pname = "git-dependency-tag";
|
||||
version = "0.1.0";
|
||||
|
||||
src = ./.;
|
||||
|
||||
cargoLock = {
|
||||
lockFile = ./Cargo.lock;
|
||||
outputHashes = {
|
||||
"rand-0.8.3" = "0l3p174bpwia61vcvxz5mw65a13ri3wy94z04xrnyy5lzciykz4f";
|
||||
};
|
||||
};
|
||||
|
||||
doInstallCheck = true;
|
||||
|
||||
installCheckPhase = ''
|
||||
$out/bin/git-dependency-tag
|
||||
'';
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
use rand::Rng;
|
||||
|
||||
fn main() {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// Always draw zero :).
|
||||
let roll: u8 = rng.gen_range(0..1);
|
||||
assert_eq!(roll, 0);
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
|
@ -39,7 +41,7 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
|||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.3"
|
||||
source = "git+https://github.com/rust-random/rand.git?rev=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7"
|
||||
source = "git+https://github.com/rust-random/rand.git#f0e01ee0a7257753cc51b291f62666f4765923ef"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
|
@ -50,7 +52,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.0"
|
||||
source = "git+https://github.com/rust-random/rand.git?rev=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7"
|
||||
source = "git+https://github.com/rust-random/rand.git#f0e01ee0a7257753cc51b291f62666f4765923ef"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
|
@ -58,8 +60,8 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.1"
|
||||
source = "git+https://github.com/rust-random/rand.git?rev=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7"
|
||||
version = "0.6.2"
|
||||
source = "git+https://github.com/rust-random/rand.git#f0e01ee0a7257753cc51b291f62666f4765923ef"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
@ -67,7 +69,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.3.0"
|
||||
source = "git+https://github.com/rust-random/rand.git?rev=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7"
|
||||
source = "git+https://github.com/rust-random/rand.git#f0e01ee0a7257753cc51b291f62666f4765923ef"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
|
|
@ -5,4 +5,4 @@ authors = ["Daniël de Kok <me@danieldk.eu>"]
|
|||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
rand = { git = "https://github.com/rust-random/rand.git", rev = "0.8.3" }
|
||||
rand = { git = "https://github.com/rust-random/rand.git" }
|
||||
|
|
|
@ -9,7 +9,7 @@ rustPlatform.buildRustPackage {
|
|||
cargoLock = {
|
||||
lockFile = ./Cargo.lock;
|
||||
outputHashes = {
|
||||
"rand-0.8.3" = "0l3p174bpwia61vcvxz5mw65a13ri3wy94z04xrnyy5lzciykz4f";
|
||||
"rand-0.8.3" = "0ya2hia3cn31qa8894s3av2s8j5bjwb6yq92k0jsnlx7jid0jwqa";
|
||||
};
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue