1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 03:56:01 +01:00

Run multiple outputs and build-delete test for CA drvs also

This commit is contained in:
John Ericson 2025-09-19 14:16:35 -04:00
parent af82c847a7
commit 7ea31c6e56
6 changed files with 53 additions and 17 deletions

View file

@ -233,10 +233,12 @@
# Content-addressed test files that use recursive-*looking* sourcing # Content-addressed test files that use recursive-*looking* sourcing
# (cd .. && source <self>), causing shellcheck to loop # (cd .. && source <self>), causing shellcheck to loop
# They're small wrapper scripts with not a lot going on # They're small wrapper scripts with not a lot going on
''^tests/functional/ca/build-delete\.sh$''
''^tests/functional/ca/build-dry\.sh$'' ''^tests/functional/ca/build-dry\.sh$''
''^tests/functional/ca/eval-store\.sh$'' ''^tests/functional/ca/eval-store\.sh$''
''^tests/functional/ca/gc\.sh$'' ''^tests/functional/ca/gc\.sh$''
''^tests/functional/ca/import-from-derivation\.sh$'' ''^tests/functional/ca/import-from-derivation\.sh$''
''^tests/functional/ca/multiple-outputs\.sh$''
''^tests/functional/ca/new-build-cmd\.sh$'' ''^tests/functional/ca/new-build-cmd\.sh$''
''^tests/functional/ca/nix-shell\.sh$'' ''^tests/functional/ca/nix-shell\.sh$''
''^tests/functional/ca/post-hook\.sh$'' ''^tests/functional/ca/post-hook\.sh$''

View file

@ -43,6 +43,10 @@ issue_6572_dependent_outputs() {
nix-store --delete "$p" # Clean up for next test nix-store --delete "$p" # Clean up for next test
# Make sure that 'nix build' tracks input-outputs correctly when a single output is already present. # Make sure that 'nix build' tracks input-outputs correctly when a single output is already present.
if [[ -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
# Resolved derivations interferre with the deletion
nix-store --delete "${NIX_STORE_DIR}"/*.drv
fi
nix-store --delete "$(jq -r <"$TEST_ROOT"/a.json .[0].outputs.second)" nix-store --delete "$(jq -r <"$TEST_ROOT"/a.json .[0].outputs.second)"
p=$(nix build -f multiple-outputs.nix use-a --no-link --print-out-paths) p=$(nix build -f multiple-outputs.nix use-a --no-link --print-out-paths)
cmp "$p" <<EOF cmp "$p" <<EOF

View file

@ -0,0 +1,7 @@
#!/usr/bin/env bash
source common.sh
export NIX_TESTS_CA_BY_DEFAULT=1
cd ..
source ./build-delete.sh

View file

@ -9,6 +9,7 @@ suites += {
'deps' : [], 'deps' : [],
'tests' : [ 'tests' : [
'build-cache.sh', 'build-cache.sh',
'build-delete.sh',
'build-with-garbage-path.sh', 'build-with-garbage-path.sh',
'build.sh', 'build.sh',
'concurrent-builds.sh', 'concurrent-builds.sh',
@ -18,6 +19,7 @@ suites += {
'eval-store.sh', 'eval-store.sh',
'gc.sh', 'gc.sh',
'import-from-derivation.sh', 'import-from-derivation.sh',
'multiple-outputs.sh',
'new-build-cmd.sh', 'new-build-cmd.sh',
'nix-copy.sh', 'nix-copy.sh',
'nix-run.sh', 'nix-run.sh',

View file

@ -0,0 +1,7 @@
#!/usr/bin/env bash
source common.sh
export NIX_TESTS_CA_BY_DEFAULT=1
cd ..
source ./multiple-outputs.sh

View file

@ -8,11 +8,15 @@ clearStoreIfPossible
rm -f $TEST_ROOT/result* rm -f $TEST_ROOT/result*
# Test whether the output names match our expectations # Placeholder strings are opaque, so cannot do this check for floating
outPath=$(nix-instantiate multiple-outputs.nix --eval -A nameCheck.out.outPath) # content-addressing derivations.
[ "$(echo "$outPath" | sed -E 's_^".*/[^-/]*-([^/]*)"$_\1_')" = "multiple-outputs-a" ] if [[ ! -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
outPath=$(nix-instantiate multiple-outputs.nix --eval -A nameCheck.dev.outPath) # Test whether the output names match our expectations
[ "$(echo "$outPath" | sed -E 's_^".*/[^-/]*-([^/]*)"$_\1_')" = "multiple-outputs-a-dev" ] outPath=$(nix-instantiate multiple-outputs.nix --eval -A nameCheck.out.outPath)
[ "$(echo "$outPath" | sed -E 's_^".*/[^-/]*-([^/]*)"$_\1_')" = "multiple-outputs-a" ]
outPath=$(nix-instantiate multiple-outputs.nix --eval -A nameCheck.dev.outPath)
[ "$(echo "$outPath" | sed -E 's_^".*/[^-/]*-([^/]*)"$_\1_')" = "multiple-outputs-a-dev" ]
fi
# Test whether read-only evaluation works when referring to the # Test whether read-only evaluation works when referring to the
# drvPath attribute. # drvPath attribute.
@ -29,8 +33,12 @@ grepQuiet 'multiple-outputs-b.drv",\["out"\]' $drvPath
# While we're at it, test the unsafeDiscardOutputDependency primop. # While we're at it, test the unsafeDiscardOutputDependency primop.
outPath=$(nix-build multiple-outputs.nix -A d --no-out-link) outPath=$(nix-build multiple-outputs.nix -A d --no-out-link)
drvPath=$(cat $outPath/drv) drvPath=$(cat $outPath/drv)
outPath=$(nix-store -q $drvPath) if [[ -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
(! [ -e "$outPath" ]) expectStderr 1 nix-store -q $drvPath | grepQuiet "Cannot use output path of floating content-addressing derivation until we know what it is (e.g. by building it)"
else
outPath=$(nix-store -q $drvPath)
(! [ -e "$outPath" ])
fi
# Do a build of something that depends on a derivation with multiple # Do a build of something that depends on a derivation with multiple
# outputs. # outputs.
@ -60,14 +68,16 @@ outPath2=$(nix-build $(nix-instantiate multiple-outputs.nix -A a.second) --no-ou
[[ $(nix-build $(nix-instantiate multiple-outputs.nix -A a.all) --no-out-link | wc -l) -eq 2 ]] [[ $(nix-build $(nix-instantiate multiple-outputs.nix -A a.all) --no-out-link | wc -l) -eq 2 ]]
# Delete one of the outputs and rebuild it. This will cause a hash if [[ ! -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
# rewrite. # Delete one of the outputs and rebuild it. This will cause a hash
env -u NIX_REMOTE nix store delete $TEST_ROOT/result-second --ignore-liveness # rewrite.
nix-build multiple-outputs.nix -A a.all -o $TEST_ROOT/result env -u NIX_REMOTE nix store delete $TEST_ROOT/result-second --ignore-liveness
[ "$(cat $TEST_ROOT/result-second/file)" = "second" ] nix-build multiple-outputs.nix -A a.all -o $TEST_ROOT/result
[ "$(cat $TEST_ROOT/result-second/link/file)" = "first" ] [ "$(cat $TEST_ROOT/result-second/file)" = "second" ]
hash2=$(nix-store -q --hash $TEST_ROOT/result-second) [ "$(cat $TEST_ROOT/result-second/link/file)" = "first" ]
[ "$hash1" = "$hash2" ] hash2=$(nix-store -q --hash $TEST_ROOT/result-second)
[ "$hash1" = "$hash2" ]
fi
# Make sure that nix-build works on derivations with multiple outputs. # Make sure that nix-build works on derivations with multiple outputs.
echo "building a.first..." echo "building a.first..."
@ -88,5 +98,9 @@ nix-store --gc --print-roots
rm -rf $NIX_STORE_DIR/.links rm -rf $NIX_STORE_DIR/.links
rmdir $NIX_STORE_DIR rmdir $NIX_STORE_DIR
expect 1 nix build -f multiple-outputs.nix invalid-output-name-1 2>&1 | grep 'contains illegal character' # TODO inspect why this doesn't work with floating content-addressing
expect 1 nix build -f multiple-outputs.nix invalid-output-name-2 2>&1 | grep 'contains illegal character' # derivations.
if [[ ! -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
expect 1 nix build -f multiple-outputs.nix invalid-output-name-1 2>&1 | grep 'contains illegal character'
expect 1 nix build -f multiple-outputs.nix invalid-output-name-2 2>&1 | grep 'contains illegal character'
fi