summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2023-01-28 11:03:54 -0500
committerPaul Smith <psmith@gnu.org>2023-01-28 13:04:47 -0500
commitfaedfdb0afd0f774bd58b5a30ca8117d70fa85c7 (patch)
tree654821120000d7cae7100584cfd70d85103e4a6c /tests
parent9709d273b299b3ced3ebd3cdce2cdca907846451 (diff)
downloadmake-git-faedfdb0afd0f774bd58b5a30ca8117d70fa85c7.tar.gz
[SV 63667] In .POSIX, use shell flags -c when ignoring errors
* src/variable.c (lookup_variable_for_file): New function to retrieve a variable assignment in a file context. * src/variable.h (lookup_variable_for_file): Declare it. * src/job.c (construct_command_argv): Look up .SHELLFLAGS. If .POSIX is set and we're using the default value, choose -c if we're ignoring errors else choose -ec. (construct_command_argv_internal): Ditto. * tests/scripts/targets/POSIX: Add tests.
Diffstat (limited to 'tests')
-rw-r--r--tests/scripts/targets/POSIX44
1 files changed, 42 insertions, 2 deletions
diff --git a/tests/scripts/targets/POSIX b/tests/scripts/targets/POSIX
index ade0b1ee..325d58cb 100644
--- a/tests/scripts/targets/POSIX
+++ b/tests/scripts/targets/POSIX
@@ -7,12 +7,52 @@ $details = "";
# Ensure turning on .POSIX enables the -e flag for the shell
-run_make_test(qq!
+run_make_test(q!
.POSIX:
-all: ; \@#HELPER# -q fail 1; true
+all: ; @#HELPER# -q fail 1; #HELPER# out hello
!,
'', "#MAKE#: *** [#MAKEFILE#:3: all] Error 1\n", 512);
+# But explicit settings must still take precedence
+
+run_make_test(q!
+.POSIX:
+all: ; @-#HELPER# -q fail 1; #HELPER# out hello
+.SHELLFLAGS = -c
+!,
+ '', "hello");
+
+run_make_test(q!
+.POSIX:
+all: ; @-#HELPER# -q fail 1; #HELPER# out hello
+all: .SHELLFLAGS = -c
+!,
+ '', "hello");
+
+# SV 63667: We shouldn't add -e to sh if errors are ignored
+
+run_make_test(q!
+.POSIX:
+all: ; @-#HELPER# -q fail 1; #HELPER# out hello
+!,
+ '', "hello\n");
+
+# But explicit settings must still take precedence
+
+run_make_test(q!
+.POSIX:
+all: ; @-#HELPER# -q fail 1; #HELPER# out hello
+.SHELLFLAGS = -ec
+!,
+ '', "#MAKE#: [#MAKEFILE#:3: all] Error 1 (ignored)\n");
+
+run_make_test(q!
+.POSIX:
+all: ; @-#HELPER# -q fail 1; #HELPER# out hello
+all: .SHELLFLAGS = -ec
+!,
+ '', "#MAKE#: [#MAKEFILE#:3: all] Error 1 (ignored)\n");
+
# User settings must override .POSIX
# In the standard .POSIX must be the first thing in the makefile
# but we relax that rule in GNU Make.