[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.
This commit is contained in:
Paul Smith
2023-01-28 11:03:54 -05:00
parent 9709d273b2
commit faedfdb0af
4 changed files with 78 additions and 4 deletions

View File

@@ -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.