Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make/unit-tests make(1): add test for unintended dou...



details:   https://anonhg.NetBSD.org/src/rev/6aa3b9a53227
branches:  trunk
changeset: 955176:6aa3b9a53227
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Sep 22 19:41:09 2020 +0000

description:
make(1): add test for unintended double expansion of deferred commands

diffstat:

 usr.bin/make/unit-tests/deptgt-end.exp |   9 ++++++---
 usr.bin/make/unit-tests/deptgt-end.mk  |  31 +++++++++++++++++++++++++++----
 2 files changed, 33 insertions(+), 7 deletions(-)

diffs (58 lines):

diff -r ce43ef499bfe -r 6aa3b9a53227 usr.bin/make/unit-tests/deptgt-end.exp
--- a/usr.bin/make/unit-tests/deptgt-end.exp    Tue Sep 22 19:08:47 2020 +0000
+++ b/usr.bin/make/unit-tests/deptgt-end.exp    Tue Sep 22 19:41:09 2020 +0000
@@ -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
diff -r ce43ef499bfe -r 6aa3b9a53227 usr.bin/make/unit-tests/deptgt-end.mk
--- a/usr.bin/make/unit-tests/deptgt-end.mk     Tue Sep 22 19:08:47 2020 +0000
+++ b/usr.bin/make/unit-tests/deptgt-end.mk     Tue Sep 22 19:41:09 2020 +0000
@@ -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.



Home | Main Index | Thread Index | Old Index