mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-12-01 18:16:14 +02:00
Merge pull request #2689 from tollb/fix/delete_tmp_dir_when_build_check_ok
Delete temporary directory on successful build
This commit is contained in:
commit
db25a6d7bb
3 changed files with 84 additions and 2 deletions
|
@ -1680,6 +1680,7 @@ void DerivationGoal::buildDone()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buildMode == bmCheck) {
|
if (buildMode == bmCheck) {
|
||||||
|
deleteTmpDir(true);
|
||||||
done(BuildResult::Built);
|
done(BuildResult::Built);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,45 @@
|
||||||
|
{checkBuildId ? 0}:
|
||||||
|
|
||||||
with import ./config.nix;
|
with import ./config.nix;
|
||||||
|
|
||||||
{
|
{
|
||||||
nondeterministic = mkDerivation {
|
nondeterministic = mkDerivation {
|
||||||
|
inherit checkBuildId;
|
||||||
name = "nondeterministic";
|
name = "nondeterministic";
|
||||||
buildCommand =
|
buildCommand =
|
||||||
''
|
''
|
||||||
mkdir $out
|
mkdir $out
|
||||||
date +%s.%N > $out/date
|
date +%s.%N > $out/date
|
||||||
|
echo "CHECK_TMPDIR=$TMPDIR"
|
||||||
|
echo "checkBuildId=$checkBuildId"
|
||||||
|
echo "$checkBuildId" > $TMPDIR/checkBuildId
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
deterministic = mkDerivation {
|
||||||
|
inherit checkBuildId;
|
||||||
|
name = "deterministic";
|
||||||
|
buildCommand =
|
||||||
|
''
|
||||||
|
mkdir $out
|
||||||
|
echo date > $out/date
|
||||||
|
echo "CHECK_TMPDIR=$TMPDIR"
|
||||||
|
echo "checkBuildId=$checkBuildId"
|
||||||
|
echo "$checkBuildId" > $TMPDIR/checkBuildId
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
failed = mkDerivation {
|
||||||
|
inherit checkBuildId;
|
||||||
|
name = "failed";
|
||||||
|
buildCommand =
|
||||||
|
''
|
||||||
|
mkdir $out
|
||||||
|
echo date > $out/date
|
||||||
|
echo "CHECK_TMPDIR=$TMPDIR"
|
||||||
|
echo "checkBuildId=$checkBuildId"
|
||||||
|
echo "$checkBuildId" > $TMPDIR/checkBuildId
|
||||||
|
false
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,62 @@
|
||||||
source common.sh
|
source common.sh
|
||||||
|
|
||||||
|
checkBuildTempDirRemoved ()
|
||||||
|
{
|
||||||
|
buildDir=$(sed -n 's/CHECK_TMPDIR=//p' $1 | head -1)
|
||||||
|
checkBuildIdFile=${buildDir}/checkBuildId
|
||||||
|
[[ ! -f $checkBuildIdFile ]] || ! grep $checkBuildId $checkBuildIdFile
|
||||||
|
}
|
||||||
|
|
||||||
|
# written to build temp directories to verify created by this instance
|
||||||
|
checkBuildId=$(date +%s%N)
|
||||||
|
|
||||||
clearStore
|
clearStore
|
||||||
|
|
||||||
nix-build dependencies.nix --no-out-link
|
nix-build dependencies.nix --no-out-link
|
||||||
nix-build dependencies.nix --no-out-link --check
|
nix-build dependencies.nix --no-out-link --check
|
||||||
|
|
||||||
nix-build check.nix -A nondeterministic --no-out-link
|
# check for dangling temporary build directories
|
||||||
nix-build check.nix -A nondeterministic --no-out-link --check 2> $TEST_ROOT/log || status=$?
|
# only retain if build fails and --keep-failed is specified, or...
|
||||||
|
# ...build is non-deterministic and --check and --keep-failed are both specified
|
||||||
|
nix-build check.nix -A failed --argstr checkBuildId $checkBuildId \
|
||||||
|
--no-out-link 2> $TEST_ROOT/log || status=$?
|
||||||
|
[ "$status" = "100" ]
|
||||||
|
checkBuildTempDirRemoved $TEST_ROOT/log
|
||||||
|
|
||||||
|
nix-build check.nix -A failed --argstr checkBuildId $checkBuildId \
|
||||||
|
--no-out-link --keep-failed 2> $TEST_ROOT/log || status=$?
|
||||||
|
[ "$status" = "100" ]
|
||||||
|
if checkBuildTempDirRemoved $TEST_ROOT/log; then false; fi
|
||||||
|
|
||||||
|
nix-build check.nix -A deterministic --argstr checkBuildId $checkBuildId \
|
||||||
|
--no-out-link 2> $TEST_ROOT/log
|
||||||
|
checkBuildTempDirRemoved $TEST_ROOT/log
|
||||||
|
|
||||||
|
nix-build check.nix -A deterministic --argstr checkBuildId $checkBuildId \
|
||||||
|
--no-out-link --check --keep-failed 2> $TEST_ROOT/log
|
||||||
|
if grep -q 'may not be deterministic' $TEST_ROOT/log; then false; fi
|
||||||
|
checkBuildTempDirRemoved $TEST_ROOT/log
|
||||||
|
|
||||||
|
nix-build check.nix -A nondeterministic --argstr checkBuildId $checkBuildId \
|
||||||
|
--no-out-link 2> $TEST_ROOT/log
|
||||||
|
checkBuildTempDirRemoved $TEST_ROOT/log
|
||||||
|
|
||||||
|
nix-build check.nix -A nondeterministic --argstr checkBuildId $checkBuildId \
|
||||||
|
--no-out-link --check 2> $TEST_ROOT/log || status=$?
|
||||||
grep 'may not be deterministic' $TEST_ROOT/log
|
grep 'may not be deterministic' $TEST_ROOT/log
|
||||||
[ "$status" = "104" ]
|
[ "$status" = "104" ]
|
||||||
|
checkBuildTempDirRemoved $TEST_ROOT/log
|
||||||
|
|
||||||
|
nix-build check.nix -A nondeterministic --argstr checkBuildId $checkBuildId \
|
||||||
|
--no-out-link --check --keep-failed 2> $TEST_ROOT/log || status=$?
|
||||||
|
|
||||||
|
# The above nix-build fails with status=1 on darwin (not sure why)
|
||||||
|
# ...but the primary purpose of the test case is to verify the temp directory is retained
|
||||||
|
if [ "$(uname -s)" != "Darwin" ]; then
|
||||||
|
grep 'may not be deterministic' $TEST_ROOT/log
|
||||||
|
[ "$status" = "104" ]
|
||||||
|
fi
|
||||||
|
if checkBuildTempDirRemoved $TEST_ROOT/log; then false; fi
|
||||||
|
|
||||||
clearStore
|
clearStore
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue