nixpkgs/pkgs/build-support/testers/expect-failure.sh
Artturin 238a6053c4 stdenv: support opt-in __structuredAttrs
Co-authored-by: Robin Gloster <mail@glob.in>

stdenv: print message if structuredAttrs is enabled

stdenv: add _append

reduces the chance of a user doing it wrong

fix nix develop issue

output hooks don't work yet in nix develop though

making $outputs be the same on non-structuredAttrs and structuredAttrs
is too much trouble.

lets instead make a function that gets the output names

reading environment file '/nix/store/2x7m69a2sm2kh0r6v0q5s9z1dh41m4xf-xz-5.2.5-env-bin'
nix: src/nix/develop.cc:299: std::string Common::makeRcScript(nix::ref<nix::Store>, const BuildEnvironment&, const Path&): Assertion `outputs != buildEnvironment.vars.end()' failed.

use a function to get all output names instead of using $outputs

copy env functionality from https://github.com/NixOS/nixpkgs/pull/76732/commits
2022-12-08 06:13:19 +02:00

62 lines
1.8 KiB
Bash

# Run a builder, flip exit code, save log and fix outputs
#
# Sub-goals:
# - Delegate to another original builder passed via args
# - Save the build log to output for further checks
# - Make the derivation succeed if the original builder fails
# - Make the derivation fail if the original builder returns exit code 0
#
# Requirements:
# This runs before, without and after stdenv. Do not modify the environment;
# especially not before invoking the original builder. For example, use
# "@" substitutions instead of PATH.
# Do not export any variables.
# Stricter bash
set -eu
# ------------------------
# Run the original builder
echo "testBuildFailure: Expecting non-zero exit from builder and args: ${*@Q}"
("$@" 2>&1) | @coreutils@/bin/tee $TMPDIR/testBuildFailure.log \
| while IFS= read -r ln; do
echo "original builder: $ln"
done
r=${PIPESTATUS[0]}
if [[ $r = 0 ]]; then
echo "testBuildFailure: The builder did not fail, but a failure was expected!"
exit 1
fi
echo "testBuildFailure: Original builder produced exit code: $r"
# -----------------------------------------
# Write the build log to the default output
outs=( $(getAllOutputNames) )
defOut=${outs[0]}
defOutPath=${!defOut}
if [[ ! -d $defOutPath ]]; then
if [[ -e $defOutPath ]]; then
@coreutils@/bin/mv $defOutPath $TMPDIR/out-node
@coreutils@/bin/mkdir $defOutPath
@coreutils@/bin/mv $TMPDIR/out-node $defOutPath/result
fi
fi
@coreutils@/bin/mkdir -p $defOutPath
@coreutils@/bin/mv $TMPDIR/testBuildFailure.log $defOutPath/testBuildFailure.log
echo $r >$defOutPath/testBuildFailure.exit
# ------------------------------------------------------
# Put empty directories in place for any missing outputs
for outputName in ${outputs:-out}; do
outputPath="${!outputName}"
if [[ ! -e "${outputPath}" ]]; then
@coreutils@/bin/mkdir "${outputPath}";
fi
done