Merge pull request #46362 from symphorien/non-broken-fetchcargo

Non broken fetchcargo
This commit is contained in:
Jörg Thalheim 2018-09-17 20:28:16 +01:00 committed by GitHub
commit 8a94866817
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 94 additions and 25 deletions

View File

@ -1,6 +1,6 @@
{ stdenv,
lib,
fetchgit,
fetchFromGitHub,
rustPlatform,
cmake,
makeWrapper,
@ -51,18 +51,16 @@ let
];
in buildRustPackage rec {
name = "alacritty-unstable-${version}";
version = "2018-08-30";
version = "2018-08-05";
# At the moment we cannot handle git dependencies in buildRustPackage.
# This fork only replaces rust-fontconfig/libfontconfig with a git submodules.
src = fetchgit {
url = https://github.com/Mic92/alacritty.git;
rev = "rev-${version}";
sha256 = "0izvg7dwwb763jc6gnmn47i5zrkxvmh3vssn6vzrrmqhd4j3msmf";
fetchSubmodules = true;
src = fetchFromGitHub {
owner = "jwilm";
repo = "alacritty";
rev = "1adb5cb7fc05054197aa08e0d1fa957df94888ab";
sha256 = "06rc7dy1vn59lc5hjh953h9lh0f39c0n0jmrz472mrya722fl2ab";
};
cargoSha256 = "1ijgkwv9ij4haig1h6n2b9xbhp5vahy9vp1sx72wxaaj9476msjx";
cargoSha256 = "0ms0248bb2lgbzcqks6i0qhn1gaiim3jf1kl17qw52c8an3rc652";
nativeBuildInputs = [
cmake

View File

@ -0,0 +1,41 @@
#!/usr/bin/env python
import sys
import toml
def quote(s: str) -> str:
escaped = s.replace('"', r"\"").replace("\n", r"\n").replace("\\", "\\\\")
return '"{}"'.format(escaped)
def main() -> None:
data = toml.load(sys.stdin)
assert list(data.keys()) == ["source"]
# this value is non deterministic
data["source"]["vendored-sources"]["directory"] = "@vendor@"
lines = []
inner = data["source"]
for source, attrs in sorted(inner.items()):
lines.append("[source.{}]".format(quote(source)))
if source == "vendored-sources":
lines.append('"directory" = "@vendor@"\n')
else:
for key, value in sorted(attrs.items()):
attr = "{} = {}".format(quote(key), quote(value))
lines.append(attr)
lines.append("")
result = "\n".join(lines)
real = toml.loads(result)
assert real == data, "output = {} while input = {}".format(real, data)
print(result)
if __name__ == "__main__":
main()

View File

@ -1,7 +1,7 @@
{ stdenv, cacert, git, rust, cargo-vendor }:
{ stdenv, cacert, git, rust, cargo-vendor, python3 }:
let
fetchcargo = import ./fetchcargo.nix {
inherit stdenv cacert git rust cargo-vendor;
inherit stdenv cacert git rust cargo-vendor python3;
};
in
{ name, cargoSha256 ? "unset"
@ -61,14 +61,12 @@ in stdenv.mkDerivation (args // {
${setupVendorDir}
mkdir .cargo
cat >.cargo/config <<-EOF
[source.crates-io]
registry = 'https://github.com/rust-lang/crates.io-index'
replace-with = 'vendored-sources'
[source.vendored-sources]
directory = '$(pwd)/$cargoDepsCopy'
EOF
config="$(pwd)/$cargoDepsCopy/.cargo/config";
if [[ ! -e $config ]]; then
config=${./fetchcargo-default-config.toml};
fi;
substitute $config .cargo/config \
--subst-var-by vendor "$(pwd)/$cargoDepsCopy"
unset cargoDepsCopy

View File

@ -0,0 +1,7 @@
[source."crates-io"]
"replace-with" = "vendored-sources"
[source."vendored-sources"]
"directory" = "@vendor@"

View File

@ -1,8 +1,26 @@
{ stdenv, cacert, git, rust, cargo-vendor }:
{ stdenv, cacert, git, rust, cargo-vendor, python3 }:
let cargo-vendor-normalise = stdenv.mkDerivation {
name = "cargo-vendor-normalise";
src = ./cargo-vendor-normalise.py;
nativeBuildInputs = [ python3.pkgs.wrapPython ];
unpackPhase = ":";
installPhase = "install -D $src $out/bin/cargo-vendor-normalise";
pythonPath = [ python3.pkgs.toml ];
postFixup = "wrapPythonPrograms";
doInstallCheck = true;
installCheckPhase = ''
# check that ./fetchcargo-default-config.toml is a fix point
reference=${./fetchcargo-default-config.toml}
< $reference $out/bin/cargo-vendor-normalise > test;
cmp test $reference
'';
preferLocalBuild = true;
};
in
{ name ? "cargo-deps", src, srcs, patches, sourceRoot, sha256, cargoUpdateHook ? "" }:
stdenv.mkDerivation {
name = "${name}-vendor";
nativeBuildInputs = [ cacert cargo-vendor git rust.cargo ];
nativeBuildInputs = [ cacert cargo-vendor git cargo-vendor-normalise rust.cargo ];
inherit src srcs patches sourceRoot;
phases = "unpackPhase patchPhase installPhase";
@ -23,9 +41,16 @@ stdenv.mkDerivation {
${cargoUpdateHook}
cargo vendor
cp -ar vendor $out
mkdir -p $out
cargo vendor $out | cargo-vendor-normalise > config
# fetchcargo used to never keep the config output by cargo vendor
# and instead hardcode the config in ./fetchcargo-default-config.toml.
# This broke on packages needing git dependencies, so now we keep the config.
# But not to break old cargoSha256, if the previous behavior was enough,
# we don't store the config.
if ! cmp config ${./fetchcargo-default-config.toml} > /dev/null; then
install -Dt $out/.cargo config;
fi;
'';
outputHashAlgo = "sha256";