Module Name:    src
Committed By:   rillig
Date:           Mon Jan 10 20:32:29 UTC 2022

Modified Files:
        src/usr.bin/make: main.c
        src/usr.bin/make/unit-tests: directive-export-impl.exp var-op-shell.exp
            var-op-shell.mk varmod-assign-shell.exp varmod-assign-shell.mk
            varmod-shell.exp varmod-shell.mk varmod-sun-shell.exp
            varmod-sun-shell.mk varname-empty.exp

Log Message:
make: add debug logging for capturing the output of external commands

This applies to all 4 situations in which the output of an external
command is used for modifying a variable or an expression:

* the assignment operator '!='
* the assignment modifier '::!='
* the SUN shell modifier ':sh'
* the other shell modifier ':!cmd!'

Previously, only the shell modifier ':!cmd!' had debug logging.

Suggested by Christoph Badura.


To generate a diff of this commit:
cvs rdiff -u -r1.568 -r1.569 src/usr.bin/make/main.c
cvs rdiff -u -r1.15 -r1.16 \
    src/usr.bin/make/unit-tests/directive-export-impl.exp
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/var-op-shell.exp
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/var-op-shell.mk
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/varmod-assign-shell.exp
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/varmod-assign-shell.mk \
    src/usr.bin/make/unit-tests/varmod-shell.exp
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/varmod-shell.mk
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/varmod-sun-shell.exp \
    src/usr.bin/make/unit-tests/varmod-sun-shell.mk
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/make/unit-tests/varname-empty.exp

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.568 src/usr.bin/make/main.c:1.569
--- src/usr.bin/make/main.c:1.568	Sun Jan  9 18:49:28 2022
+++ src/usr.bin/make/main.c	Mon Jan 10 20:32:28 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.568 2022/01/09 18:49:28 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.569 2022/01/10 20:32:28 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.568 2022/01/09 18:49:28 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.569 2022/01/10 20:32:28 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	    "The Regents of the University of California.  "
@@ -1720,6 +1720,7 @@ Cmd_Exec(const char *cmd, char **error)
 	args[1] = "-c";
 	args[2] = cmd;
 	args[3] = NULL;
+	DEBUG1(VAR, "Capturing the output of command \"%s\"\n", cmd);
 
 	if (pipe(pipefds) == -1) {
 		*error = str_concat3(

Index: src/usr.bin/make/unit-tests/directive-export-impl.exp
diff -u src/usr.bin/make/unit-tests/directive-export-impl.exp:1.15 src/usr.bin/make/unit-tests/directive-export-impl.exp:1.16
--- src/usr.bin/make/unit-tests/directive-export-impl.exp:1.15	Tue Dec 28 15:49:00 2021
+++ src/usr.bin/make/unit-tests/directive-export-impl.exp	Mon Jan 10 20:32:29 2022
@@ -14,6 +14,7 @@ CondParser_Eval: ${:!echo "\$UT_VAR"!} !
 Var_Parse: ${:!echo "\$UT_VAR"!} != "<>" (eval-defined)
 Evaluating modifier ${:!...} on value "" (eval-defined, undefined)
 Modifier part: "echo "$UT_VAR""
+Capturing the output of command "echo "$UT_VAR""
 Var_Parse: ${.MAKE.EXPORTED:O:u} (eval)
 Evaluating modifier ${.MAKE.EXPORTED:O} on value "UT_VAR"
 Result of ${.MAKE.EXPORTED:O} is "UT_VAR"
@@ -37,6 +38,7 @@ CondParser_Eval: ${:!echo "\$UT_VAR"!} !
 Var_Parse: ${:!echo "\$UT_VAR"!} != "<defined>" (eval-defined)
 Evaluating modifier ${:!...} on value "" (eval-defined, undefined)
 Modifier part: "echo "$UT_VAR""
+Capturing the output of command "echo "$UT_VAR""
 Var_Parse: ${.MAKE.EXPORTED:O:u} (eval)
 Evaluating modifier ${.MAKE.EXPORTED:O} on value "UT_VAR"
 Result of ${.MAKE.EXPORTED:O} is "UT_VAR"

Index: src/usr.bin/make/unit-tests/var-op-shell.exp
diff -u src/usr.bin/make/unit-tests/var-op-shell.exp:1.4 src/usr.bin/make/unit-tests/var-op-shell.exp:1.5
--- src/usr.bin/make/unit-tests/var-op-shell.exp:1.4	Sun Jan  9 18:22:31 2022
+++ src/usr.bin/make/unit-tests/var-op-shell.exp	Mon Jan 10 20:32:29 2022
@@ -4,4 +4,8 @@ make: "var-op-shell.mk" line 59: warning
 /bin/no/such/command: not found
 make: "var-op-shell.mk" line 65: warning: "/bin/no/such/command" returned non-zero status
 stderr
+Capturing the output of command "echo '$$$$'"
+Global: OUTPUT = $$$$
+Global: .MAKEFLAGS =  -r -k -d v -d
+Global: .MAKEFLAGS =  -r -k -d v -d 0
 exit status 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.5 src/usr.bin/make/unit-tests/var-op-shell.mk:1.6
--- src/usr.bin/make/unit-tests/var-op-shell.mk:1.5	Sun Jan  9 18:22:31 2022
+++ src/usr.bin/make/unit-tests/var-op-shell.mk	Mon Jan 10 20:32:29 2022
@@ -1,4 +1,4 @@
-# $NetBSD: var-op-shell.mk,v 1.5 2022/01/09 18:22:31 rillig Exp $
+# $NetBSD: var-op-shell.mk,v 1.6 2022/01/10 20:32:29 rillig Exp $
 #
 # Tests for the != variable assignment operator, which runs its right-hand
 # side through the shell.
@@ -81,4 +81,10 @@ OUTPUT!=	echo '$$$$$$$$'
 .  error
 .endif
 
+
+# As a debugging aid, log the exact command that is run via the shell.
+.MAKEFLAGS: -dv
+OUTPUT!=	echo '$$$$$$$$'
+.MAKEFLAGS: -d0
+
 all:

Index: src/usr.bin/make/unit-tests/varmod-assign-shell.exp
diff -u src/usr.bin/make/unit-tests/varmod-assign-shell.exp:1.2 src/usr.bin/make/unit-tests/varmod-assign-shell.exp:1.3
--- src/usr.bin/make/unit-tests/varmod-assign-shell.exp:1.2	Sun Jan  9 18:22:31 2022
+++ src/usr.bin/make/unit-tests/varmod-assign-shell.exp	Mon Jan 10 20:32:29 2022
@@ -1,5 +1,14 @@
 make: "varmod-assign-shell.mk" line 27: warning: "echo output; false" returned non-zero status
+Global: _ = 
+Var_Parse: ${ASSIGNED::!=echo output; ${:Ufalse}} (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)
+Global: _ = 
+Global: .MAKEFLAGS =  -r -k -d v -d
+Global: .MAKEFLAGS =  -r -k -d v -d 0
 DIRECT=output
 ASSIGNED=previous
 exit status 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.3 src/usr.bin/make/unit-tests/varmod-assign-shell.mk:1.4
--- src/usr.bin/make/unit-tests/varmod-assign-shell.mk:1.3	Sun Jan  9 18:22:31 2022
+++ src/usr.bin/make/unit-tests/varmod-assign-shell.mk	Mon Jan 10 20:32:29 2022
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-assign-shell.mk,v 1.3 2022/01/09 18:22:31 rillig Exp $
+# $NetBSD: varmod-assign-shell.mk,v 1.4 2022/01/10 20:32:29 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
@@ -27,7 +27,9 @@ DIRECT=		previous
 DIRECT!=	echo output; false
 
 ASSIGNED=	previous
-_:=		${ASSIGNED::!=echo output; false}
+.MAKEFLAGS: -dv			# to see the actual command
+_:=		${ASSIGNED::!=echo output; ${:Ufalse}}
+.MAKEFLAGS: -d0
 
 all:
 	@echo DIRECT=${DIRECT:Q}
Index: src/usr.bin/make/unit-tests/varmod-shell.exp
diff -u src/usr.bin/make/unit-tests/varmod-shell.exp:1.3 src/usr.bin/make/unit-tests/varmod-shell.exp:1.4
--- src/usr.bin/make/unit-tests/varmod-shell.exp:1.3	Tue Nov 17 20:11:02 2020
+++ src/usr.bin/make/unit-tests/varmod-shell.exp	Mon Jan 10 20:32:29 2022
@@ -1,3 +1,13 @@
 make: "echo word; false" returned non-zero status
 make: "echo word; false" returned non-zero status
+Global: _ = 
+Var_Parse: ${:!echo word; ${:Ufalse}!} (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: "echo word; false" returned non-zero status
+Result of ${:!echo word; ${:Ufalse}!} 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
 exit status 0

Index: src/usr.bin/make/unit-tests/varmod-shell.mk
diff -u src/usr.bin/make/unit-tests/varmod-shell.mk:1.6 src/usr.bin/make/unit-tests/varmod-shell.mk:1.7
--- src/usr.bin/make/unit-tests/varmod-shell.mk:1.6	Sun Feb 14 20:16:17 2021
+++ src/usr.bin/make/unit-tests/varmod-shell.mk	Mon Jan 10 20:32:29 2022
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-shell.mk,v 1.6 2021/02/14 20:16:17 rillig Exp $
+# $NetBSD: varmod-shell.mk,v 1.7 2022/01/10 20:32:29 rillig Exp $
 #
 # Tests for the ':!cmd!' variable modifier, which runs the shell command
 # given by the variable modifier and returns its output.
@@ -20,8 +20,7 @@
 #
 # 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.  It's strange that such a simple bug could
-# survive such a long time.
+# command that was executed.
 .if ${:!echo word; false!} != "word"
 .  error
 .endif
@@ -29,4 +28,9 @@
 .  error
 .endif
 
+
+.MAKEFLAGS: -dv			# to see the actual command
+_:=	${:!echo word; ${:Ufalse}!}
+.MAKEFLAGS: -d0
+
 all:

Index: src/usr.bin/make/unit-tests/varmod-sun-shell.exp
diff -u src/usr.bin/make/unit-tests/varmod-sun-shell.exp:1.1 src/usr.bin/make/unit-tests/varmod-sun-shell.exp:1.2
--- src/usr.bin/make/unit-tests/varmod-sun-shell.exp:1.1	Sun Feb 14 20:16:17 2021
+++ src/usr.bin/make/unit-tests/varmod-sun-shell.exp	Mon Jan 10 20:32:29 2022
@@ -1,2 +1,13 @@
 make: "echo word; false" returned non-zero status
+Global: _ = 
+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: "echo word; false" returned non-zero status
+Result of ${echo word; false: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
 exit status 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.1 src/usr.bin/make/unit-tests/varmod-sun-shell.mk:1.2
--- src/usr.bin/make/unit-tests/varmod-sun-shell.mk:1.1	Sun Feb 14 20:16:17 2021
+++ src/usr.bin/make/unit-tests/varmod-sun-shell.mk	Mon Jan 10 20:32:29 2022
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-sun-shell.mk,v 1.1 2021/02/14 20:16:17 rillig Exp $
+# $NetBSD: varmod-sun-shell.mk,v 1.2 2022/01/10 20:32:29 rillig Exp $
 #
 # Tests for the :sh variable modifier, which runs the shell command
 # given by the variable value and returns its output.
@@ -18,4 +18,9 @@
 .  error
 .endif
 
+
+.MAKEFLAGS: -dv			# to see the actual command
+_:=	${echo word; ${:Ufalse}:L:sh}
+.MAKEFLAGS: -d0
+
 all:

Index: src/usr.bin/make/unit-tests/varname-empty.exp
diff -u src/usr.bin/make/unit-tests/varname-empty.exp:1.17 src/usr.bin/make/unit-tests/varname-empty.exp:1.18
--- src/usr.bin/make/unit-tests/varname-empty.exp:1.17	Tue Oct 19 15:59:26 2021
+++ src/usr.bin/make/unit-tests/varname-empty.exp	Mon Jan 10 20:32:29 2022
@@ -13,6 +13,7 @@ Var_SetExpand: variable name "" expands 
 SetVar: variable name is empty - ignored
 Var_SetExpand: variable name "" expands to empty string, with value "" - ignored
 Var_SetExpand: variable name "" expands to empty string, with value "subst" - ignored
+Capturing the output of command "echo 'shell-output'"
 Var_SetExpand: variable name "" expands to empty string, with value "shell-output" - ignored
 Var_SetExpand: variable name "${:U}" expands to empty string, with value "assigned indirectly" - ignored
 Var_AppendExpand: variable name "${:U}" expands to empty string, with value "appended indirectly" - ignored

Reply via email to