Module Name: src
Committed By: rillig
Date: Tue Sep 22 19:41:09 UTC 2020
Modified Files:
src/usr.bin/make/unit-tests: deptgt-end.exp deptgt-end.mk
Log Message:
make(1): add test for unintended double expansion of deferred commands
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/deptgt-end.exp
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/deptgt-end.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/unit-tests/deptgt-end.exp
diff -u src/usr.bin/make/unit-tests/deptgt-end.exp:1.2 src/usr.bin/make/unit-tests/deptgt-end.exp:1.3
--- src/usr.bin/make/unit-tests/deptgt-end.exp:1.2 Sat Aug 29 17:34:21 2020
+++ src/usr.bin/make/unit-tests/deptgt-end.exp Tue Sep 22 19:41:09 2020
@@ -1,4 +1,7 @@
-: .BEGIN
-: all
-: .END
+: .BEGIN '${VAR}'
+: all '${VAR}'
+: .END '${VAR}'
+: .END '${VAR}' deferred
+: .BEGIN 'Should not be expanded.' deferred
+: all 'Should not be expanded.' deferred
exit status 0
Index: src/usr.bin/make/unit-tests/deptgt-end.mk
diff -u src/usr.bin/make/unit-tests/deptgt-end.mk:1.3 src/usr.bin/make/unit-tests/deptgt-end.mk:1.4
--- src/usr.bin/make/unit-tests/deptgt-end.mk:1.3 Sat Aug 29 17:34:21 2020
+++ src/usr.bin/make/unit-tests/deptgt-end.mk Tue Sep 22 19:41:09 2020
@@ -1,13 +1,36 @@
-# $NetBSD: deptgt-end.mk,v 1.3 2020/08/29 17:34:21 rillig Exp $
+# $NetBSD: deptgt-end.mk,v 1.4 2020/09/22 19:41:09 rillig Exp $
#
# Tests for the special target .END in dependency declarations,
# which is run after making the desired targets.
+VAR= Should not be expanded.
+
.BEGIN:
- : $@
+ : $@ '$${VAR}'
+ ...
+ : $@ '$${VAR}' deferred
+# Oops: The deferred command must not be expanded twice.
+# The Var_Subst in Compat_RunCommand looks suspicious.
.END:
- : $@
+ : $@ '$${VAR}'
+ ...
+ : $@ '$${VAR}' deferred
all:
- : $@
+ : $@ '$${VAR}'
+ ...
+ : $@ '$${VAR}' deferred
+# Oops: The deferred command must not be expanded twice.
+# The Var_Subst in Compat_RunCommand looks suspicious.
+
+# The deferred commands are run in the order '.END .BEGIN all'.
+# This may be unexpected at first since the natural order would be
+# '.BEGIN all .END', but it is implemented correctly.
+#
+# At the point where the commands of a node with deferred commands are run,
+# the deferred commands are appended to the commands of the .END node.
+# This happens in Compat_RunCommand, and to prevent an endless loop, the
+# deferred commands of the .END node itself are not appended to itself.
+# Instead, the deferred commands of the .END node are run as if they were
+# immediate commands.