1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +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

@ -43,6 +43,10 @@ issue_6572_dependent_outputs() {
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.
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)"
p=$(nix build -f multiple-outputs.nix use-a --no-link --print-out-paths)
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' : [],
'tests' : [
'build-cache.sh',
'build-delete.sh',
'build-with-garbage-path.sh',
'build.sh',
'concurrent-builds.sh',
@ -18,6 +19,7 @@ suites += {
'eval-store.sh',
'gc.sh',
'import-from-derivation.sh',
'multiple-outputs.sh',
'new-build-cmd.sh',
'nix-copy.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*
# Test whether the output names match our expectations
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" ]
# Placeholder strings are opaque, so cannot do this check for floating
# content-addressing derivations.
if [[ ! -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
# Test whether the output names match our expectations
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
# drvPath attribute.
@ -29,8 +33,12 @@ grepQuiet 'multiple-outputs-b.drv",\["out"\]' $drvPath
# While we're at it, test the unsafeDiscardOutputDependency primop.
outPath=$(nix-build multiple-outputs.nix -A d --no-out-link)
drvPath=$(cat $outPath/drv)
outPath=$(nix-store -q $drvPath)
(! [ -e "$outPath" ])
if [[ -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
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
# 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 ]]
# Delete one of the outputs and rebuild it. This will cause a hash
# rewrite.
env -u NIX_REMOTE nix store delete $TEST_ROOT/result-second --ignore-liveness
nix-build multiple-outputs.nix -A a.all -o $TEST_ROOT/result
[ "$(cat $TEST_ROOT/result-second/file)" = "second" ]
[ "$(cat $TEST_ROOT/result-second/link/file)" = "first" ]
hash2=$(nix-store -q --hash $TEST_ROOT/result-second)
[ "$hash1" = "$hash2" ]
if [[ ! -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
# Delete one of the outputs and rebuild it. This will cause a hash
# rewrite.
env -u NIX_REMOTE nix store delete $TEST_ROOT/result-second --ignore-liveness
nix-build multiple-outputs.nix -A a.all -o $TEST_ROOT/result
[ "$(cat $TEST_ROOT/result-second/file)" = "second" ]
[ "$(cat $TEST_ROOT/result-second/link/file)" = "first" ]
hash2=$(nix-store -q --hash $TEST_ROOT/result-second)
[ "$hash1" = "$hash2" ]
fi
# Make sure that nix-build works on derivations with multiple outputs.
echo "building a.first..."
@ -88,5 +98,9 @@ nix-store --gc --print-roots
rm -rf $NIX_STORE_DIR/.links
rmdir $NIX_STORE_DIR
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'
# TODO inspect why this doesn't work with floating content-addressing
# 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