From 3fc6cf0e2f0258cf64bb2bab6611b64a06fd91f2 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Fri, 31 Dec 2021 08:22:11 +0000 Subject: [PATCH] iffe: really abort on output{ fail (re: e20c0c6b, e72543a, b6bd981) After further examining the iffe code I found that fail{ ... }end as well as pass{ ... }end blocks are executed in iffe's current environment, using a simple 'eval', with no safeguards whatsoever! This does of course afford maximum flexibility... for example, a block can 'exit 1' to abort the iffe run and the whole build with it. We can use this to abort properly on fatal compilation errors. src/cmd/INIT/iffe.sh: - Complete the fail{ and pass{ documentation; it should really be known that they run in iffe's current environment. - Make one change: for just the 'eval' command that runs these blocks, redirect standard error back to the saved $stderr file descriptor so these blocks can write error messages using the standard >&2 instead of the undocumented >&$stderr. src/lib/**/features/*: - Write error message to standard error and error out properly when an output{ ... }end block fails to compile, instead of writing an #error directive to error out later. --- src/cmd/INIT/iffe.sh | 18 ++++++++++++------ src/cmd/builtin/features/pty | 3 ++- src/lib/libast/features/common | 3 ++- src/lib/libast/features/float | 9 ++++++--- src/lib/libast/features/lib | 3 ++- src/lib/libast/features/sfio | 3 ++- src/lib/libast/features/sizeof | 3 ++- src/lib/libdll/features/dll | 3 ++- 8 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/cmd/INIT/iffe.sh b/src/cmd/INIT/iffe.sh index 4cf448561..bdfa59571 100644 --- a/src/cmd/INIT/iffe.sh +++ b/src/cmd/INIT/iffe.sh @@ -32,7 +32,7 @@ AIX) unset LIBPATH ;; esac command=iffe -version=2021-12-22 +version=2021-12-31 compile() # $cc ... { @@ -873,8 +873,8 @@ case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in } [+?\abegin\a\b{\b ... \b}end\b delimit multiline code blocks that override or augment the default code provided by \biffe\b. User supplied code - blocks should be compatible with the K&R, ANSI, and C++ C language - dialects for maximal portability. Test code may call the function + blocks should be compatible with the C89/C90 C language + standard for maximal portability. Test code may call the function \bNOTE("...")\b to emit short text in \b--verbose\b output; only one \bNOTE()\b should be called per test for readability. In addition to all macro definitions generated by previous tests, all generated @@ -1066,7 +1066,12 @@ case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in [+execute?The block is compiled, linked, and executed. \b0\b exit status means success.] [+fail?If the test fails then the block text is evaluated by - \bsh\b(1).] + \bsh\b(1) in \biffe\b'\'$'s current shell environment. + Changes in the shell state, such as variables, will survive the block. + Standard input is redirected to \b/dev/null\b. + Standard output is copied to the output file. + Standard error may be used to log informative or error messages. + The block may use \bexit\b to abort the \biffe\b run.] [+link?The block is compiled and linked (\bcc -o\b).] [+macro?The block is preprocessed (\bcc -E\b) and lines containing text bracketed by \b<<"\b ... \b">>\b (\aless-than\a \aless-than\a @@ -1080,7 +1085,7 @@ case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in [+output?The block is compiled, linked, and executed, and the output is copied to the output file.] [+pass?If the test succeeds then the block text is evaluated by - \bsh\b(1).] + \bsh\b(1) in the same manner as \bfail\b above.] [+preprocess?The block is preprocessed (\bcc -E\b).] [+run?The block is executed as a shell script and the output is copied to the output file. Successful test macros are also @@ -4543,7 +4548,8 @@ struct xxx* f() { return &v; }" *) user_pf=$pass user_yn=$yes ;; esac case $user_pf in - ?*) eval "$user_pf" <&$nullin ;; + ?*) # Run a pass{ or fail{ block in iffe's current environment + eval "$user_pf" <&$nullin 2>&$stderr ;; esac case $user_yn in ?*) case $def in diff --git a/src/cmd/builtin/features/pty b/src/cmd/builtin/features/pty index 5652c0a3a..317816c2c 100644 --- a/src/cmd/builtin/features/pty +++ b/src/cmd/builtin/features/pty @@ -50,7 +50,8 @@ tst - -lm output{ return 0; } }end fail{ - echo '#error The output block in src/cmd/builtin/features/pty failed to compile. Rebuild with IFFEFLAGS=-d1 to debug.' + echo "$0: Output block failed to compile. Export IFFEFLAGS=-d1 to debug." >&2 + exit 1 }end extern _getpty char* (int*, int, mode_t, int) diff --git a/src/lib/libast/features/common b/src/lib/libast/features/common index 3c34d7504..f507876b1 100644 --- a/src/lib/libast/features/common +++ b/src/lib/libast/features/common @@ -319,7 +319,8 @@ tst - output{ return 0; } }end fail{ - echo '#error Output block #2 in src/lib/libast/features/common failed to compile. Rebuild with IFFEFLAGS=-d1 to debug.' + echo "$0: Output block failed to compile. Export IFFEFLAGS=-d1 to debug." >&2 + exit 1 }end tst - -DN=1 - -DN=0 output{ diff --git a/src/lib/libast/features/float b/src/lib/libast/features/float index 07e892688..8edfc9577 100644 --- a/src/lib/libast/features/float +++ b/src/lib/libast/features/float @@ -890,7 +890,8 @@ tst - note{ missing floating point limits }end output{ return 0; } }end fail{ - echo '#error Output block #1 in src/lib/libast/features/float failed to compile. Rebuild with IFFEFLAGS=-d1 to debug.' + echo "$0: Output block failed to compile. Export IFFEFLAGS=-d1 to debug." >&2 + exit 1 }end tst - note{ double exponent bitfoolery }end output{ @@ -926,7 +927,8 @@ tst - note{ double exponent bitfoolery }end output{ return 0; } }end fail{ - echo '#error Output block #2 in src/lib/libast/features/float failed to compile. Rebuild with IFFEFLAGS=-d1 to debug.' + echo "$0: Output block failed to compile. Export IFFEFLAGS=-d1 to debug." >&2 + exit 1 }end tst - note{ long double exponent bitfoolery }end output{ @@ -962,7 +964,8 @@ tst - note{ long double exponent bitfoolery }end output{ return 0; } }end fail{ - echo '#error Output block #3 in src/lib/libast/features/float failed to compile. Rebuild with IFFEFLAGS=-d1 to debug.' + echo "$0: Output block failed to compile. Export IFFEFLAGS=-d1 to debug." >&2 + exit 1 }end tst - -DN=1 - -DN=2 note{ _ast_fltmax_t maximum integral type }end output{ diff --git a/src/lib/libast/features/lib b/src/lib/libast/features/lib index 75003dc36..34b68fa05 100644 --- a/src/lib/libast/features/lib +++ b/src/lib/libast/features/lib @@ -659,7 +659,8 @@ tst - output{ } }end fail{ - echo '#error The output block in src/lib/libast/features/lib failed to compile. Rebuild with IFFEFLAGS=-d1 to debug.' + echo "$0: Output block failed to compile. Export IFFEFLAGS=-d1 to debug." >&2 + exit 1 }end tst no64 note{ largefile 64 broken }end execute{ diff --git a/src/lib/libast/features/sfio b/src/lib/libast/features/sfio index d0f6f6807..1f548a3a8 100644 --- a/src/lib/libast/features/sfio +++ b/src/lib/libast/features/sfio @@ -15,7 +15,8 @@ tst - note{ number of bits in pointer }end output{ return 0; } }end fail{ - echo '#error The output block in src/lib/libast/features/sfio failed to compile. Rebuild with IFFEFLAGS=-d1 to debug.' + echo "$0: Output block failed to compile. Export IFFEFLAGS=-d1 to debug." >&2 + exit 1 }end tst tmp_rmfail note{ open files cannot be removed }end execute{ diff --git a/src/lib/libast/features/sizeof b/src/lib/libast/features/sizeof index bab4edc70..46b93712f 100644 --- a/src/lib/libast/features/sizeof +++ b/src/lib/libast/features/sizeof @@ -11,5 +11,6 @@ tst - note{ sizeof(integral-type) }end output{ return 0; } }end fail{ - echo '#error The output block in src/lib/libast/features/sizeof failed to compile. Rebuild with IFFEFLAGS=-d1 to debug.' + echo "$0: Output block failed to compile. Export IFFEFLAGS=-d1 to debug." >&2 + exit 1 }end diff --git a/src/lib/libdll/features/dll b/src/lib/libdll/features/dll index 28e5264e6..525d7d1c0 100644 --- a/src/lib/libdll/features/dll +++ b/src/lib/libdll/features/dll @@ -261,5 +261,6 @@ tst - -lm output{ return 0; } }end fail{ - echo '#error The output block in src/lib/libdll/features/dll failed to compile. Rebuild with IFFEFLAGS=-d1 to debug.' + echo "$0: Output block failed to compile. Export IFFEFLAGS=-d1 to debug." >&2 + exit 1 }end