lol
1# Run a builder, flip exit code, save log and fix outputs
2#
3# Sub-goals:
4# - Delegate to another original builder passed via args
5# - Save the build log to output for further checks
6# - Make the derivation succeed if the original builder fails
7# - Make the derivation fail if the original builder returns exit code 0
8#
9# Requirements:
10# This runs before, without and after stdenv. Do not modify the environment;
11# especially not before invoking the original builder. For example, use
12# "@" substitutions instead of PATH.
13# Do not export any variables.
14
15# Stricter bash
16set -eu
17
18# ------------------------
19# Run the original builder
20
21echo "testBuildFailure: Expecting non-zero exit from builder and args: ${*@Q}"
22
23("$@" 2>&1) | @coreutils@/bin/tee $TMPDIR/testBuildFailure.log \
24 | while IFS= read -r ln; do
25 echo "original builder: $ln"
26 done
27
28r=${PIPESTATUS[0]}
29if [[ $r = 0 ]]; then
30 echo "testBuildFailure: The builder did not fail, but a failure was expected!"
31 exit 1
32fi
33echo "testBuildFailure: Original builder produced exit code: $r"
34
35# -----------------------------------------
36# Write the build log to the default output
37#
38# # from stdenv setup.sh
39getAllOutputNames() {
40 if [ -n "$__structuredAttrs" ]; then
41 echo "${!outputs[*]}"
42 else
43 echo "$outputs"
44 fi
45}
46
47outs=( $(getAllOutputNames) )
48defOut=${outs[0]}
49defOutPath=${!defOut}
50
51if [[ ! -d $defOutPath ]]; then
52 if [[ -e $defOutPath ]]; then
53 @coreutils@/bin/mv $defOutPath $TMPDIR/out-node
54 @coreutils@/bin/mkdir $defOutPath
55 @coreutils@/bin/mv $TMPDIR/out-node $defOutPath/result
56 fi
57fi
58
59@coreutils@/bin/mkdir -p $defOutPath
60@coreutils@/bin/mv $TMPDIR/testBuildFailure.log $defOutPath/testBuildFailure.log
61echo $r >$defOutPath/testBuildFailure.exit
62
63# ------------------------------------------------------
64# Put empty directories in place for any missing outputs
65
66for outputName in ${outputs:-out}; do
67 outputPath="${!outputName}"
68 if [[ ! -e "${outputPath}" ]]; then
69 @coreutils@/bin/mkdir "${outputPath}";
70 fi
71done