Don't write $(shell ...) stdout to stderr on failure

If a $(shell ...) invocation failed due to a command-not-found error,
make wrote the stdout of that shell to our stderr for some reason.
That seems very wrong.

If the command's stderr was not redirected then its output would have
already been written to its stderr, and if it was redirected then we
shouldn't take it upon ourselves to force it to go to stderr!

* src/function.c (func_shell_base): Append shell stdout even if the
shell command failed.
* tests/run_make_tests.pl: Determine the error generated for
command-not-found situations.
* tests/scripts/functions/shell: Verify that redirecting stderr to
stdout will behave properly if the command is not found.
This commit is contained in:
Paul Smith
2022-02-06 16:22:40 -05:00
parent 6761122be0
commit 342a9bb54b
3 changed files with 29 additions and 25 deletions

View File

@@ -46,10 +46,11 @@ if ($port_type ne 'W32') {
# This needs to be ported to Windows, or else Windows error messages
# need to converted to look like more normal make errors.
run_make_test('
.RECIPEPREFIX = >
all:
@echo hi
$(shell ./basdfdfsed there)
@echo $(.SHELLSTATUS)
>@echo hi
>$(shell ./basdfdfsed there)
>@echo $(.SHELLSTATUS)
',
'', "#MAKE#: ./basdfdfsed: $ERR_no_such_file\nhi\n127\n");
@@ -81,10 +82,17 @@ $(shell kill -2 $$$$)
STAT := $(.SHELLSTATUS)
all: ; @echo STAT=$(STAT)
','',"STAT=$ret\n");
# Test that not-found errors can be redirected
if ($ERR_command_not_found) {
$_ = $ERR_command_not_found;
s/#CMDNAME#/bad-command/g;
run_make_test(q!
out := $(shell bad-command 2>&1)
all: ; @echo '$(.SHELLSTATUS): $(out)'
!,
'', "127: $_\n");
}
}
1;
### Local Variables:
### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action))
### End: