Module Name: src
Committed By: rillig
Date: Fri Jun 10 18:58:07 UTC 2022
Modified Files:
src/usr.bin/make/unit-tests: cmdline.exp cmdline.mk
Log Message:
tests/make: demonstrate spaces and '#' in command line arguments
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/cmdline.exp \
src/usr.bin/make/unit-tests/cmdline.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/cmdline.exp
diff -u src/usr.bin/make/unit-tests/cmdline.exp:1.3 src/usr.bin/make/unit-tests/cmdline.exp:1.4
--- src/usr.bin/make/unit-tests/cmdline.exp:1.3 Wed Feb 9 18:54:19 2022
+++ src/usr.bin/make/unit-tests/cmdline.exp Fri Jun 10 18:58:07 2022
@@ -2,4 +2,7 @@ makeobjdir-direct:
show-objdir: <tmpdir>/6a8899d2-d227-4b55-9b6b-f3c8eeb83fd5
makeobjdir-indirect:
show-objdir: <tmpdir>/a7b41170-53f8-4cc2-bc5c-e4c3dd93ec45/
+space-and-comment:
+value # no comment $
+value # no comment $
exit status 0
Index: src/usr.bin/make/unit-tests/cmdline.mk
diff -u src/usr.bin/make/unit-tests/cmdline.mk:1.3 src/usr.bin/make/unit-tests/cmdline.mk:1.4
--- src/usr.bin/make/unit-tests/cmdline.mk:1.3 Sat Feb 6 18:26:03 2021
+++ src/usr.bin/make/unit-tests/cmdline.mk Fri Jun 10 18:58:07 2022
@@ -1,4 +1,4 @@
-# $NetBSD: cmdline.mk,v 1.3 2021/02/06 18:26:03 sjg Exp $
+# $NetBSD: cmdline.mk,v 1.4 2022/06/10 18:58:07 rillig Exp $
#
# Tests for command line parsing and related special variables.
@@ -11,6 +11,7 @@ DIR12= ${TMPBASE}/${SUB1}/${SUB2}
all: prepare-dirs
all: makeobjdir-direct makeobjdir-indirect
+all: space-and-comment
prepare-dirs:
@rm -rf ${DIR2} ${DIR12}
@@ -34,3 +35,24 @@ makeobjdir-indirect:
show-objdir:
@echo $@: ${.OBJDIR:Q}
+
+
+# Variable assignments in the command line are handled differently from
+# variable assignments in makefiles. In the command line, trailing whitespace
+# is preserved, and the '#' does not start a comment. This is because the
+# low-level parsing from ParseRawLine does not take place.
+#
+# Preserving '#' and trailing whitespace has the benefit that when passing
+# such values to sub-makes via MAKEFLAGS, no special encoding is needed.
+# Leading whitespace in the variable value is discarded though, which makes
+# the behavior inconsistent.
+space-and-comment: .PHONY
+ @echo $@:
+
+ @env -i \
+ ${MAKE} -r -f /dev/null ' VAR= value # no comment ' -v VAR \
+ | sed 's,$$,$$,'
+
+ @env -i MAKEFLAGS="' VAR= value # no comment '" \
+ ${MAKE} -r -f /dev/null -v VAR \
+ | sed 's,$$,$$,'