Module Name: src
Committed By: rillig
Date: Sun Jun 30 11:37:21 UTC 2024
Modified Files:
src/usr.bin/make: main.c
src/usr.bin/make/unit-tests: var-op-shell.exp var-op-shell.mk
varmod-assign-shell.exp varmod-assign-shell.mk varmod-assign.exp
varmod-assign.mk varmod-shell.exp varmod-shell.mk
varmod-sun-shell.exp varmod-sun-shell.mk
Log Message:
make: add detailed exit status to message for failed sub-commands
Several commands communicate via the exit status and not only
distinguish between zero and non-zero, so make this information
available to ease investigations.
The command "false" is not guaranteed to exit with a consistent status,
so use "(exit 13)" instead in the tests, to keep these tests portable
across different operating systems. The exit status 127 is required for
a shell that cannot find a command, so keep that one.
To generate a diff of this commit:
cvs rdiff -u -r1.624 -r1.625 src/usr.bin/make/main.c
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/var-op-shell.exp \
src/usr.bin/make/unit-tests/varmod-shell.exp
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/var-op-shell.mk \
src/usr.bin/make/unit-tests/varmod-shell.mk
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/varmod-assign-shell.exp \
src/usr.bin/make/unit-tests/varmod-assign-shell.mk
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/make/unit-tests/varmod-assign.exp \
src/usr.bin/make/unit-tests/varmod-assign.mk
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/varmod-sun-shell.exp
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/varmod-sun-shell.mk
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.624 src/usr.bin/make/main.c:1.625
--- src/usr.bin/make/main.c:1.624 Sun Jun 2 15:31:26 2024
+++ src/usr.bin/make/main.c Sun Jun 30 11:37:21 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.624 2024/06/02 15:31:26 rillig Exp $ */
+/* $NetBSD: main.c,v 1.625 2024/06/30 11:37:21 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -111,7 +111,7 @@
#include "trace.h"
/* "@(#)main.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.624 2024/06/02 15:31:26 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.625 2024/06/30 11:37:21 rillig Exp $");
#if defined(MAKE_NATIVE)
__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
"The Regents of the University of California. "
@@ -1784,10 +1784,15 @@ Cmd_Exec(const char *cmd, char **error)
if (WIFSIGNALED(status))
*error = str_concat3("\"", cmd, "\" exited on a signal");
- else if (WEXITSTATUS(status) != 0)
- *error = str_concat3(
- "\"", cmd, "\" returned non-zero status");
- else if (saved_errno != 0)
+ else if (WEXITSTATUS(status) != 0) {
+ Buffer errBuf;
+ Buf_Init(&errBuf);
+ Buf_AddStr(&errBuf, "Command \"");
+ Buf_AddStr(&errBuf, cmd);
+ Buf_AddStr(&errBuf, "\" exited with status ");
+ Buf_AddInt(&errBuf, WEXITSTATUS(status));
+ *error = Buf_DoneData(&errBuf);
+ } else if (saved_errno != 0)
*error = str_concat3(
"Couldn't read shell's output for \"", cmd, "\"");
else
Index: src/usr.bin/make/unit-tests/var-op-shell.exp
diff -u src/usr.bin/make/unit-tests/var-op-shell.exp:1.6 src/usr.bin/make/unit-tests/var-op-shell.exp:1.7
--- src/usr.bin/make/unit-tests/var-op-shell.exp:1.6 Thu Jun 1 20:56:35 2023
+++ src/usr.bin/make/unit-tests/var-op-shell.exp Sun Jun 30 11:37:21 2024
@@ -1,8 +1,8 @@
-make: "var-op-shell.mk" line 32: warning: "echo "failed"; false" returned non-zero status
-make: "var-op-shell.mk" line 39: warning: "false" returned non-zero status
+make: "var-op-shell.mk" line 32: warning: Command "echo "failed"; (exit 13)" exited with status 13
+make: "var-op-shell.mk" line 39: warning: Command "exit 13" exited with status 13
make: "var-op-shell.mk" line 62: warning: "kill $$" exited on a signal
/bin/no/such/command: not found
-make: "var-op-shell.mk" line 69: warning: "/bin/no/such/command" returned non-zero status
+make: "var-op-shell.mk" line 69: warning: Command "/bin/no/such/command" exited with status 127
stderr
Capturing the output of command "echo '$$$$'"
Global: OUTPUT = $$$$
Index: src/usr.bin/make/unit-tests/varmod-shell.exp
diff -u src/usr.bin/make/unit-tests/varmod-shell.exp:1.6 src/usr.bin/make/unit-tests/varmod-shell.exp:1.7
--- src/usr.bin/make/unit-tests/varmod-shell.exp:1.6 Sun Jun 30 11:00:06 2024
+++ src/usr.bin/make/unit-tests/varmod-shell.exp Sun Jun 30 11:37:21 2024
@@ -1,12 +1,12 @@
-make: "varmod-shell.mk" line 25: warning: while evaluating "${:!echo word; false!} != "word"": "echo word; false" returned non-zero status
-make: "varmod-shell.mk" line 29: warning: while evaluating "${:Uprevious value:!echo word; false!} != "word"": "echo word; false" returned non-zero status
+make: "varmod-shell.mk" line 25: warning: while evaluating "${:!echo word; (exit 13)!} != "word"": Command "echo word; (exit 13)" exited with status 13
+make: "varmod-shell.mk" line 29: warning: while evaluating "${:Uprevious value:!echo word; (exit 13)!} != "word"": Command "echo word; (exit 13)" exited with status 13
Global: _ = # (empty)
-Var_Parse: ${:!echo word; ${:Ufalse}!} (eval-keep-dollar-and-undefined)
+Var_Parse: ${:!echo word; ${:U(exit 13)}!} (eval-keep-dollar-and-undefined)
Evaluating modifier ${:!...} on value "" (eval-keep-dollar-and-undefined, undefined)
-Modifier part: "echo word; false"
-Capturing the output of command "echo word; false"
-make: "varmod-shell.mk" line 36: warning: while evaluating "${:!echo word; ${:Ufalse}!}": "echo word; false" returned non-zero status
-Result of ${:!echo word; ${:Ufalse}!} is "word" (eval-keep-dollar-and-undefined, defined)
+Modifier part: "echo word; (exit 13)"
+Capturing the output of command "echo word; (exit 13)"
+make: "varmod-shell.mk" line 36: warning: while evaluating "${:!echo word; ${:U(exit 13)}!}": Command "echo word; (exit 13)" exited with status 13
+Result of ${:!echo word; ${:U(exit 13)}!} is "word" (eval-keep-dollar-and-undefined, defined)
Global: _ = word
Global: .MAKEFLAGS = -r -k -d v -d
Global: .MAKEFLAGS = -r -k -d v -d 0
Index: src/usr.bin/make/unit-tests/var-op-shell.mk
diff -u src/usr.bin/make/unit-tests/var-op-shell.mk:1.8 src/usr.bin/make/unit-tests/var-op-shell.mk:1.9
--- src/usr.bin/make/unit-tests/var-op-shell.mk:1.8 Fri Jan 5 23:36:45 2024
+++ src/usr.bin/make/unit-tests/var-op-shell.mk Sun Jun 30 11:37:21 2024
@@ -1,4 +1,4 @@
-# $NetBSD: var-op-shell.mk,v 1.8 2024/01/05 23:36:45 rillig Exp $
+# $NetBSD: var-op-shell.mk,v 1.9 2024/06/30 11:37:21 rillig Exp $
#
# Tests for the != variable assignment operator, which runs its right-hand
# side through the shell.
@@ -28,15 +28,15 @@ OUTPUT!= true
# '::!=', expression modifier ':!...!'), a failed command generates only a
# warning, not an "error". These "errors" are ignored in default mode, for
# compatibility, but not in lint mode (-dL).
-# expect+1: warning: "echo "failed"; false" returned non-zero status
-OUTPUT!= echo "failed"; false
+# expect+1: warning: Command "echo "failed"; (exit 13)" exited with status 13
+OUTPUT!= echo "failed"; (exit 13)
.if ${OUTPUT} != "failed"
. error
.endif
# A command with empty output may fail as well.
-# expect+1: warning: "false" returned non-zero status
-OUTPUT!= false
+# expect+1: warning: Command "exit 13" exited with status 13
+OUTPUT!= exit 13
.if ${OUTPUT} != ""
. error
.endif
@@ -50,7 +50,7 @@ OUTPUT!= echo "line 1"; echo "line 2"
# A failing command in the middle results in the exit status 0, which in the
# end means that the whole sequence of commands succeeded.
-OUTPUT!= echo "before"; false; echo "after"
+OUTPUT!= echo "before"; (exit 13); echo "after"
.if ${OUTPUT} != "before after"
. error
.endif
@@ -65,7 +65,7 @@ OUTPUT!= kill $$$$
.endif
# A nonexistent command produces a non-zero exit status.
-# expect+1: warning: "/bin/no/such/command" returned non-zero status
+# expect+1: warning: Command "/bin/no/such/command" exited with status 127
OUTPUT!= /bin/no/such/command
.if ${OUTPUT} != ""
. error
Index: src/usr.bin/make/unit-tests/varmod-shell.mk
diff -u src/usr.bin/make/unit-tests/varmod-shell.mk:1.8 src/usr.bin/make/unit-tests/varmod-shell.mk:1.9
--- src/usr.bin/make/unit-tests/varmod-shell.mk:1.8 Sun Jun 30 11:00:06 2024
+++ src/usr.bin/make/unit-tests/varmod-shell.mk Sun Jun 30 11:37:21 2024
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-shell.mk,v 1.8 2024/06/30 11:00:06 rillig Exp $
+# $NetBSD: varmod-shell.mk,v 1.9 2024/06/30 11:37:21 rillig Exp $
#
# Tests for the ':!cmd!' variable modifier, which runs the shell command
# given by the variable modifier and returns its output.
@@ -21,19 +21,19 @@
# Between 2000-04-29 and 2020-11-17, the error message mentioned the previous
# value of the expression (which is usually an empty string) instead of the
# command that was executed.
-# expect+1: warning: while evaluating "${:!echo word; false!} != "word"": "echo word; false" returned non-zero status
-.if ${:!echo word; false!} != "word"
+# expect+1: warning: while evaluating "${:!echo word; (exit 13)!} != "word"": Command "echo word; (exit 13)" exited with status 13
+.if ${:!echo word; (exit 13)!} != "word"
. error
.endif
-# expect+1: warning: while evaluating "${:Uprevious value:!echo word; false!} != "word"": "echo word; false" returned non-zero status
-.if ${:Uprevious value:!echo word; false!} != "word"
+# expect+1: warning: while evaluating "${:Uprevious value:!echo word; (exit 13)!} != "word"": Command "echo word; (exit 13)" exited with status 13
+.if ${:Uprevious value:!echo word; (exit 13)!} != "word"
. error
.endif
.MAKEFLAGS: -dv # to see the "Capturing" debug output
-# expect+1: warning: while evaluating "${:!echo word; ${:Ufalse}!}": "echo word; false" returned non-zero status
-_:= ${:!echo word; ${:Ufalse}!}
+# expect+1: warning: while evaluating "${:!echo word; ${:U(exit 13)}!}": Command "echo word; (exit 13)" exited with status 13
+_:= ${:!echo word; ${:U(exit 13)}!}
.MAKEFLAGS: -d0
Index: src/usr.bin/make/unit-tests/varmod-assign-shell.exp
diff -u src/usr.bin/make/unit-tests/varmod-assign-shell.exp:1.5 src/usr.bin/make/unit-tests/varmod-assign-shell.exp:1.6
--- src/usr.bin/make/unit-tests/varmod-assign-shell.exp:1.5 Thu Jun 1 20:56:35 2023
+++ src/usr.bin/make/unit-tests/varmod-assign-shell.exp Sun Jun 30 11:37:21 2024
@@ -1,11 +1,11 @@
-make: "varmod-assign-shell.mk" line 28: warning: "echo output; false" returned non-zero status
+make: "varmod-assign-shell.mk" line 28: warning: Command "echo output; (exit 13)" exited with status 13
Global: _ = # (empty)
-Var_Parse: ${ASSIGNED::!=echo output; ${:Ufalse}} (eval-keep-dollar-and-undefined)
+Var_Parse: ${ASSIGNED::!=echo output; ${:U(exit 13)}} (eval-keep-dollar-and-undefined)
Evaluating modifier ${ASSIGNED::...} on value "previous" (eval-keep-dollar-and-undefined, regular)
-Modifier part: "echo output; false"
-Capturing the output of command "echo output; false"
-make: "echo output; false" returned non-zero status
-Result of ${ASSIGNED::!=echo output; ${:Ufalse}} is "" (eval-keep-dollar-and-undefined, regular)
+Modifier part: "echo output; (exit 13)"
+Capturing the output of command "echo output; (exit 13)"
+make: Command "echo output; (exit 13)" exited with status 13
+Result of ${ASSIGNED::!=echo output; ${:U(exit 13)}} is "" (eval-keep-dollar-and-undefined, regular)
Global: _ = # (empty)
Global: .MAKEFLAGS = -r -k -d v -d
Global: .MAKEFLAGS = -r -k -d v -d 0
Index: src/usr.bin/make/unit-tests/varmod-assign-shell.mk
diff -u src/usr.bin/make/unit-tests/varmod-assign-shell.mk:1.5 src/usr.bin/make/unit-tests/varmod-assign-shell.mk:1.6
--- src/usr.bin/make/unit-tests/varmod-assign-shell.mk:1.5 Thu Jun 1 20:56:35 2023
+++ src/usr.bin/make/unit-tests/varmod-assign-shell.mk Sun Jun 30 11:37:21 2024
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-assign-shell.mk,v 1.5 2023/06/01 20:56:35 rillig Exp $
+# $NetBSD: varmod-assign-shell.mk,v 1.6 2024/06/30 11:37:21 rillig Exp $
#
# Tests for the variable modifier '::!=', which assigns the output of a shell
# command to the variable, but only if the command exited successfully. This
@@ -24,12 +24,12 @@
# assignment operator '!=' is another unnecessary inconsistency.
DIRECT= previous
-# expect+1: warning: "echo output; false" returned non-zero status
-DIRECT!= echo output; false
+# expect+1: warning: Command "echo output; (exit 13)" exited with status 13
+DIRECT!= echo output; (exit 13)
ASSIGNED= previous
.MAKEFLAGS: -dv # to see the actual command
-_:= ${ASSIGNED::!=echo output; ${:Ufalse}}
+_:= ${ASSIGNED::!=echo output; ${:U(exit 13)}}
.MAKEFLAGS: -d0
all:
Index: src/usr.bin/make/unit-tests/varmod-assign.exp
diff -u src/usr.bin/make/unit-tests/varmod-assign.exp:1.20 src/usr.bin/make/unit-tests/varmod-assign.exp:1.21
--- src/usr.bin/make/unit-tests/varmod-assign.exp:1.20 Sat Apr 20 10:18:55 2024
+++ src/usr.bin/make/unit-tests/varmod-assign.exp Sun Jun 30 11:37:21 2024
@@ -48,7 +48,7 @@ sysv:y
make: Unfinished modifier for "ASSIGN" ('}' missing)
ok=word
-make: " echo word; false " returned non-zero status
+make: Command " echo word; (exit 13) " exited with status 13
err=previous
Command: TARGET_CMD_VAR = cmd-value
Global: TARGET_GLOBAL_VAR = global-value
Index: src/usr.bin/make/unit-tests/varmod-assign.mk
diff -u src/usr.bin/make/unit-tests/varmod-assign.mk:1.20 src/usr.bin/make/unit-tests/varmod-assign.mk:1.21
--- src/usr.bin/make/unit-tests/varmod-assign.mk:1.20 Sat Apr 20 10:18:55 2024
+++ src/usr.bin/make/unit-tests/varmod-assign.mk Sun Jun 30 11:37:21 2024
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-assign.mk,v 1.20 2024/04/20 10:18:55 rillig Exp $
+# $NetBSD: varmod-assign.mk,v 1.21 2024/06/30 11:37:21 rillig Exp $
#
# Tests for the obscure ::= variable modifiers, which perform variable
# assignments during evaluation, just like the = operator in C.
@@ -105,7 +105,7 @@ mod-assign-shell-error:
# If the command fails, the variable keeps its previous value.
@${SH_ERR::=previous}
- @${SH_ERR::!= echo word; false } echo err=${SH_ERR}
+ @${SH_ERR::!= echo word; (exit 13) } echo err=${SH_ERR}
# XXX: The ::= modifier expands its right-hand side exactly once.
# This differs subtly from normal assignments such as '+=' or '=', which copy
Index: src/usr.bin/make/unit-tests/varmod-sun-shell.exp
diff -u src/usr.bin/make/unit-tests/varmod-sun-shell.exp:1.4 src/usr.bin/make/unit-tests/varmod-sun-shell.exp:1.5
--- src/usr.bin/make/unit-tests/varmod-sun-shell.exp:1.4 Sun Jun 30 11:00:06 2024
+++ src/usr.bin/make/unit-tests/varmod-sun-shell.exp Sun Jun 30 11:37:21 2024
@@ -1,12 +1,12 @@
-make: "varmod-sun-shell.mk" line 17: warning: while evaluating variable "echo word; false": "echo word; false" returned non-zero status
+make: "varmod-sun-shell.mk" line 17: warning: while evaluating variable "echo word; (exit 13)": Command "echo word; (exit 13)" exited with status 13
Global: _ = # (empty)
-Var_Parse: ${echo word; ${:Ufalse}:L:sh} (eval-keep-dollar-and-undefined)
-Evaluating modifier ${echo word; false:L} on value "" (eval-keep-dollar-and-undefined, undefined)
-Result of ${echo word; false:L} is "echo word; false" (eval-keep-dollar-and-undefined, defined)
-Evaluating modifier ${echo word; false:s...} on value "echo word; false" (eval-keep-dollar-and-undefined, defined)
-Capturing the output of command "echo word; false"
-make: "varmod-sun-shell.mk" line 24: warning: while evaluating variable "echo word; false": "echo word; false" returned non-zero status
-Result of ${echo word; false:sh} is "word" (eval-keep-dollar-and-undefined, defined)
+Var_Parse: ${echo word; ${:U(exit 13)}:L:sh} (eval-keep-dollar-and-undefined)
+Evaluating modifier ${echo word; (exit 13):L} on value "" (eval-keep-dollar-and-undefined, undefined)
+Result of ${echo word; (exit 13):L} is "echo word; (exit 13)" (eval-keep-dollar-and-undefined, defined)
+Evaluating modifier ${echo word; (exit 13):s...} on value "echo word; (exit 13)" (eval-keep-dollar-and-undefined, defined)
+Capturing the output of command "echo word; (exit 13)"
+make: "varmod-sun-shell.mk" line 24: warning: while evaluating variable "echo word; (exit 13)": Command "echo word; (exit 13)" exited with status 13
+Result of ${echo word; (exit 13):sh} is "word" (eval-keep-dollar-and-undefined, defined)
Global: _ = word
Global: .MAKEFLAGS = -r -k -d v -d
Global: .MAKEFLAGS = -r -k -d v -d 0
Index: src/usr.bin/make/unit-tests/varmod-sun-shell.mk
diff -u src/usr.bin/make/unit-tests/varmod-sun-shell.mk:1.3 src/usr.bin/make/unit-tests/varmod-sun-shell.mk:1.4
--- src/usr.bin/make/unit-tests/varmod-sun-shell.mk:1.3 Sun Jun 30 11:00:06 2024
+++ src/usr.bin/make/unit-tests/varmod-sun-shell.mk Sun Jun 30 11:37:21 2024
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-sun-shell.mk,v 1.3 2024/06/30 11:00:06 rillig Exp $
+# $NetBSD: varmod-sun-shell.mk,v 1.4 2024/06/30 11:37:21 rillig Exp $
#
# Tests for the :sh variable modifier, which runs the shell command
# given by the variable value and returns its output.
@@ -13,15 +13,15 @@
.endif
# If the command exits with non-zero, a warning is printed.
-# expect+1: warning: while evaluating variable "echo word; false": "echo word; false" returned non-zero status
-.if ${echo word; false:L:sh} != "word"
+# expect+1: warning: while evaluating variable "echo word; (exit 13)": Command "echo word; (exit 13)" exited with status 13
+.if ${echo word; (exit 13):L:sh} != "word"
. error
.endif
.MAKEFLAGS: -dv # to see the "Capturing" debug output
-# expect+1: warning: while evaluating variable "echo word; false": "echo word; false" returned non-zero status
-_:= ${echo word; ${:Ufalse}:L:sh}
+# expect+1: warning: while evaluating variable "echo word; (exit 13)": Command "echo word; (exit 13)" exited with status 13
+_:= ${echo word; ${:U(exit 13)}:L:sh}
.MAKEFLAGS: -d0