tests/binary-cache.sh: Improve incomplete closure test

Issue #3373.
This commit is contained in:
Eelco Dolstra 2020-05-12 13:49:55 +02:00
parent 5bdb67c843
commit 5722f9690c
11 changed files with 42 additions and 23 deletions

View file

@ -105,10 +105,24 @@ mv $cacheDir/nar2 $cacheDir/nar
# incomplete closure. # incomplete closure.
clearStore clearStore
rm $(grep -l "StorePath:.*dependencies-input-2" $cacheDir/*.narinfo) rm -v $(grep -l "StorePath:.*dependencies-input-2" $cacheDir/*.narinfo)
nix-build --substituters "file://$cacheDir" --no-require-sigs dependencies.nix -o $TEST_ROOT/result 2>&1 | tee $TEST_ROOT/log nix-build --substituters "file://$cacheDir" --no-require-sigs dependencies.nix -o $TEST_ROOT/result 2>&1 | tee $TEST_ROOT/log
grep -q "copying path" $TEST_ROOT/log grep -q "copying path.*input-0" $TEST_ROOT/log
grep -q "copying path.*input-2" $TEST_ROOT/log
grep -q "copying path.*top" $TEST_ROOT/log
# Idem, but without cached .narinfo.
clearStore
clearCacheCache
nix-build --substituters "file://$cacheDir" --no-require-sigs dependencies.nix -o $TEST_ROOT/result 2>&1 | tee $TEST_ROOT/log
grep -q "don't know how to build" $TEST_ROOT/log
grep -q "building.*input-1" $TEST_ROOT/log
grep -q "building.*input-2" $TEST_ROOT/log
grep -q "copying path.*input-0" $TEST_ROOT/log
grep -q "copying path.*top" $TEST_ROOT/log
if [ -n "$HAVE_SODIUM" ]; then if [ -n "$HAVE_SODIUM" ]; then

View file

@ -4,13 +4,13 @@ let
input1 = mkDerivation { input1 = mkDerivation {
name = "build-hook-input-1"; name = "build-hook-input-1";
builder = ./dependencies.builder1.sh; buildCommand = "mkdir $out; echo FOO > $out/foo";
requiredSystemFeatures = ["foo"]; requiredSystemFeatures = ["foo"];
}; };
input2 = mkDerivation { input2 = mkDerivation {
name = "build-hook-input-2"; name = "build-hook-input-2";
builder = ./dependencies.builder2.sh; buildCommand = "mkdir $out; echo BAR > $out/bar";
}; };
in in

View file

@ -20,5 +20,5 @@ cat $outPath/foobar | grep FOOBAR
# Ensure that input1 was built on store1 due to the required feature. # Ensure that input1 was built on store1 due to the required feature.
p=$(readlink -f $outPath/input-2) p=$(readlink -f $outPath/input-2)
(! nix path-info --store $TEST_ROOT/store0 --all | grep dependencies.builder1.sh) (! nix path-info --store $TEST_ROOT/store0 --all | grep builder-build-hook-input-1.sh)
nix path-info --store $TEST_ROOT/store1 --all | grep dependencies.builder1.sh nix path-info --store $TEST_ROOT/store1 --all | grep builder-build-hook-input-1.sh

View file

@ -11,7 +11,7 @@ rec {
derivation ({ derivation ({
inherit system; inherit system;
builder = shell; builder = shell;
args = ["-e" args.builder or (builtins.toFile "builder.sh" "if [ -e .attrs.sh ]; then source .attrs.sh; fi; eval \"$buildCommand\"")]; args = ["-e" args.builder or (builtins.toFile "builder-${args.name}.sh" "if [ -e .attrs.sh ]; then source .attrs.sh; fi; eval \"$buildCommand\"")];
PATH = path; PATH = path;
} // removeAttrs args ["builder" "meta"]) } // removeAttrs args ["builder" "meta"])
// { meta = args.meta or {}; }; // { meta = args.meta or {}; };

View file

@ -1,2 +0,0 @@
mkdir $out
echo FOO > $out/foo

View file

@ -1,2 +0,0 @@
mkdir $out
echo BAR > $out/bar

View file

@ -2,18 +2,27 @@ with import ./config.nix;
let { let {
input0 = mkDerivation {
name = "dependencies-input-0";
buildCommand = "mkdir $out; echo foo > $out/bar";
};
input1 = mkDerivation { input1 = mkDerivation {
name = "dependencies-input-1"; name = "dependencies-input-1";
builder = ./dependencies.builder1.sh; buildCommand = "mkdir $out; echo FOO > $out/foo";
}; };
input2 = mkDerivation { input2 = mkDerivation {
name = "dependencies-input-2"; name = "dependencies-input-2";
builder = "${./dependencies.builder2.sh}"; buildCommand = ''
mkdir $out
echo BAR > $out/bar
echo ${input0} > $out/input0
'';
}; };
body = mkDerivation { body = mkDerivation {
name = "dependencies"; name = "dependencies-top";
builder = ./dependencies.builder0.sh + "/FOOBAR/../."; builder = ./dependencies.builder0.sh + "/FOOBAR/../.";
input1 = input1 + "/."; input1 = input1 + "/.";
input2 = "${input2}/."; input2 = "${input2}/.";

View file

@ -6,7 +6,7 @@ drvPath=$(nix-instantiate dependencies.nix)
echo "derivation is $drvPath" echo "derivation is $drvPath"
nix-store -q --tree "$drvPath" | grep '───.*builder1.sh' nix-store -q --tree "$drvPath" | grep '───.*builder-dependencies-input-1.sh'
# Test Graphviz graph generation. # Test Graphviz graph generation.
nix-store -q --graph "$drvPath" > $TEST_ROOT/graph nix-store -q --graph "$drvPath" > $TEST_ROOT/graph

View file

@ -11,7 +11,7 @@ checkRef() {
outPath=$(nix-build ./export-graph.nix -A 'foo."bar.runtimeGraph"' -o $TEST_ROOT/result) outPath=$(nix-build ./export-graph.nix -A 'foo."bar.runtimeGraph"' -o $TEST_ROOT/result)
test $(nix-store -q --references $TEST_ROOT/result | wc -l) = 2 || fail "bad nr of references" test $(nix-store -q --references $TEST_ROOT/result | wc -l) = 3 || fail "bad nr of references"
checkRef input-2 checkRef input-2
for i in $(cat $outPath); do checkRef $i; done for i in $(cat $outPath); do checkRef $i; done

View file

@ -4,12 +4,12 @@ rec {
input1 = mkDerivation { input1 = mkDerivation {
name = "dependencies-input-1"; name = "dependencies-input-1";
builder = ./dependencies.builder1.sh; buildCommand = "mkdir $out; echo FOO > $out/foo";
}; };
input2 = mkDerivation { input2 = mkDerivation {
name = "dependencies-input-2"; name = "dependencies-input-2";
builder = ./dependencies.builder2.sh; buildCommand = "mkdir $out; echo BAR > $out/bar";
}; };
test1 = mkDerivation { test1 = mkDerivation {
@ -23,5 +23,5 @@ rec {
builder = ./gc-concurrent2.builder.sh; builder = ./gc-concurrent2.builder.sh;
inherit input1 input2; inherit input1 input2;
}; };
} }

View file

@ -32,10 +32,10 @@ if [ "$xmllint" != false ]; then
$xmllint --noout $TEST_ROOT/meta.xml || fail "malformed XML" $xmllint --noout $TEST_ROOT/meta.xml || fail "malformed XML"
fi fi
grep -q 'meta.*description.*Random test package' $TEST_ROOT/meta.xml grep -q 'meta.*description.*Random test package' $TEST_ROOT/meta.xml
grep -q 'item.*attrPath="foo".*name="dependencies"' $TEST_ROOT/meta.xml grep -q 'item.*attrPath="foo".*name="dependencies-top"' $TEST_ROOT/meta.xml
# Do an install. # Do an install.
nix-env -i dependencies nix-env -i dependencies-top
[ -e $TEST_HOME/.nix-profile/foobar ] [ -e $TEST_HOME/.nix-profile/foobar ]
clearProfiles clearProfiles
@ -51,9 +51,9 @@ if [ "$xmllint" != false ]; then
$xmllint --noout $TEST_ROOT/meta.xml || fail "malformed XML" $xmllint --noout $TEST_ROOT/meta.xml || fail "malformed XML"
fi fi
grep -q 'meta.*description.*Random test package' $TEST_ROOT/meta.xml grep -q 'meta.*description.*Random test package' $TEST_ROOT/meta.xml
grep -q 'item.*attrPath="foo".*name="dependencies"' $TEST_ROOT/meta.xml grep -q 'item.*attrPath="foo".*name="dependencies-top"' $TEST_ROOT/meta.xml
# Do an install. # Do an install.
nix-env -i dependencies nix-env -i dependencies-top
[ -e $TEST_HOME/.nix-profile/foobar ] [ -e $TEST_HOME/.nix-profile/foobar ]