2024-05-28 16:43:04 +00:00
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
2011-09-14 05:59:29 +00:00
|
|
|
|
source common.sh
|
|
|
|
|
|
2024-06-16 10:51:46 +00:00
|
|
|
|
TODO_NixOS
|
|
|
|
|
|
2024-06-16 15:56:50 +00:00
|
|
|
|
clearStoreIfPossible
|
2011-09-14 05:59:29 +00:00
|
|
|
|
|
2017-11-24 17:07:29 +00:00
|
|
|
|
rm -f $TEST_ROOT/result*
|
|
|
|
|
|
2020-08-07 19:09:26 +00:00
|
|
|
|
# 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" ]
|
|
|
|
|
|
2011-12-21 13:47:21 +00:00
|
|
|
|
# Test whether read-only evaluation works when referring to the
|
2016-11-25 23:37:43 +00:00
|
|
|
|
# ‘drvPath’ attribute.
|
2011-12-21 13:47:21 +00:00
|
|
|
|
echo "evaluating c..."
|
2011-12-21 18:19:05 +00:00
|
|
|
|
#drvPath=$(nix-instantiate multiple-outputs.nix -A c --readonly-mode)
|
2011-12-21 13:47:21 +00:00
|
|
|
|
|
|
|
|
|
# And check whether the resulting derivation explicitly depends on all
|
|
|
|
|
# outputs.
|
2011-12-21 18:19:05 +00:00
|
|
|
|
drvPath=$(nix-instantiate multiple-outputs.nix -A c)
|
|
|
|
|
#[ "$drvPath" = "$drvPath2" ]
|
2021-12-09 15:26:46 +00:00
|
|
|
|
grepQuiet 'multiple-outputs-a.drv",\["first","second"\]' $drvPath
|
|
|
|
|
grepQuiet 'multiple-outputs-b.drv",\["out"\]' $drvPath
|
2011-12-21 13:47:21 +00:00
|
|
|
|
|
2016-11-25 23:37:43 +00:00
|
|
|
|
# While we're at it, test the ‘unsafeDiscardOutputDependency’ primop.
|
2012-09-11 23:10:11 +00:00
|
|
|
|
outPath=$(nix-build multiple-outputs.nix -A d --no-out-link)
|
2011-12-21 14:42:06 +00:00
|
|
|
|
drvPath=$(cat $outPath/drv)
|
|
|
|
|
outPath=$(nix-store -q $drvPath)
|
2014-08-21 19:50:19 +00:00
|
|
|
|
(! [ -e "$outPath" ])
|
2011-12-21 14:42:06 +00:00
|
|
|
|
|
2011-12-21 13:47:21 +00:00
|
|
|
|
# Do a build of something that depends on a derivation with multiple
|
|
|
|
|
# outputs.
|
|
|
|
|
echo "building b..."
|
2012-09-11 23:10:11 +00:00
|
|
|
|
outPath=$(nix-build multiple-outputs.nix -A b --no-out-link)
|
2011-09-14 05:59:29 +00:00
|
|
|
|
echo "output path is $outPath"
|
2024-06-12 16:42:38 +00:00
|
|
|
|
[ "$(cat "$outPath/file")" = "success" ]
|
2011-12-20 17:08:43 +00:00
|
|
|
|
|
2012-09-11 23:10:11 +00:00
|
|
|
|
# Test nix-build on a derivation with multiple outputs.
|
2017-11-24 17:07:29 +00:00
|
|
|
|
outPath1=$(nix-build multiple-outputs.nix -A a -o $TEST_ROOT/result)
|
2012-11-26 16:46:45 +00:00
|
|
|
|
[ -e $TEST_ROOT/result-first ]
|
2014-08-21 19:50:19 +00:00
|
|
|
|
(! [ -e $TEST_ROOT/result-second ])
|
2012-11-26 16:46:45 +00:00
|
|
|
|
nix-build multiple-outputs.nix -A a.all -o $TEST_ROOT/result
|
2012-09-11 23:10:11 +00:00
|
|
|
|
[ "$(cat $TEST_ROOT/result-first/file)" = "first" ]
|
|
|
|
|
[ "$(cat $TEST_ROOT/result-second/file)" = "second" ]
|
|
|
|
|
[ "$(cat $TEST_ROOT/result-second/link/file)" = "first" ]
|
|
|
|
|
hash1=$(nix-store -q --hash $TEST_ROOT/result-second)
|
|
|
|
|
|
2017-11-24 17:07:29 +00:00
|
|
|
|
outPath2=$(nix-build $(nix-instantiate multiple-outputs.nix -A a) --no-out-link)
|
|
|
|
|
[[ $outPath1 = $outPath2 ]]
|
|
|
|
|
|
|
|
|
|
outPath2=$(nix-build $(nix-instantiate multiple-outputs.nix -A a.first) --no-out-link)
|
|
|
|
|
[[ $outPath1 = $outPath2 ]]
|
|
|
|
|
|
|
|
|
|
outPath2=$(nix-build $(nix-instantiate multiple-outputs.nix -A a.second) --no-out-link)
|
|
|
|
|
[[ $(cat $outPath2/file) = second ]]
|
|
|
|
|
|
|
|
|
|
[[ $(nix-build $(nix-instantiate multiple-outputs.nix -A a.all) --no-out-link | wc -l) -eq 2 ]]
|
|
|
|
|
|
2012-09-11 23:10:11 +00:00
|
|
|
|
# Delete one of the outputs and rebuild it. This will cause a hash
|
|
|
|
|
# rewrite.
|
2021-07-26 04:54:55 +00:00
|
|
|
|
env -u NIX_REMOTE nix store delete $TEST_ROOT/result-second --ignore-liveness
|
2012-11-26 16:46:45 +00:00
|
|
|
|
nix-build multiple-outputs.nix -A a.all -o $TEST_ROOT/result
|
2012-09-11 23:10:11 +00:00
|
|
|
|
[ "$(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" ]
|
|
|
|
|
|
2011-12-20 17:08:43 +00:00
|
|
|
|
# Make sure that nix-build works on derivations with multiple outputs.
|
2011-12-21 13:47:21 +00:00
|
|
|
|
echo "building a.first..."
|
2012-09-11 23:10:11 +00:00
|
|
|
|
nix-build multiple-outputs.nix -A a.first --no-out-link
|
2011-12-20 17:08:43 +00:00
|
|
|
|
|
|
|
|
|
# Cyclic outputs should be rejected.
|
2011-12-21 13:47:21 +00:00
|
|
|
|
echo "building cyclic..."
|
2012-09-11 23:10:11 +00:00
|
|
|
|
if nix-build multiple-outputs.nix -A cyclic --no-out-link; then
|
2011-12-20 17:08:43 +00:00
|
|
|
|
echo "Cyclic outputs incorrectly accepted!"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2021-08-25 12:05:25 +00:00
|
|
|
|
# Do a GC. This should leave an empty store.
|
2011-12-21 13:47:21 +00:00
|
|
|
|
echo "collecting garbage..."
|
2012-09-12 22:49:35 +00:00
|
|
|
|
rm $TEST_ROOT/result*
|
2017-11-20 16:50:49 +00:00
|
|
|
|
nix-store --gc --keep-derivations --keep-outputs
|
2012-09-12 22:49:35 +00:00
|
|
|
|
nix-store --gc --print-roots
|
2021-08-25 12:05:25 +00:00
|
|
|
|
rm -rf $NIX_STORE_DIR/.links
|
|
|
|
|
rmdir $NIX_STORE_DIR
|
2023-01-18 13:21:17 +00:00
|
|
|
|
|
2021-12-09 15:26:46 +00:00
|
|
|
|
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'
|