diff options
Diffstat (limited to 'contrib/bmake/unit-tests')
347 files changed, 6162 insertions, 2262 deletions
diff --git a/contrib/bmake/unit-tests/Makefile b/contrib/bmake/unit-tests/Makefile index c3b64abad84a..6c41bf811dcf 100644 --- a/contrib/bmake/unit-tests/Makefile +++ b/contrib/bmake/unit-tests/Makefile @@ -1,6 +1,6 @@ -# $Id: Makefile,v 1.180 2022/04/18 21:25:37 sjg Exp $ +# $Id: Makefile,v 1.211 2024/03/10 17:46:44 sjg Exp $ # -# $NetBSD: Makefile,v 1.312 2022/04/18 15:06:28 rillig Exp $ +# $NetBSD: Makefile,v 1.342 2024/01/07 02:07:44 sjg Exp $ # # Unit tests for make(1) # @@ -25,10 +25,6 @@ # named makefile (*.mk), with its own set of expected results (*.exp), # and it should be added to the TESTS list. # -# A few *.mk files are helper files for other tests (such as include-sub.mk) -# and are thus not added to TESTS. Such files must be ignored in -# src/tests/usr.bin/make/t_make.sh. -# .MAIN: all @@ -36,6 +32,21 @@ .MAKE.OS?= ${uname -s:L:sh} .MAKE.UID?= ${id -u:L:sh} +# for many tests we need a TMPDIR that will not collide +# with other users. +.if ${.OBJDIR} != ${.CURDIR} +# easy +TMPDIR:= ${.OBJDIR}/tmp +.elif defined(TMPDIR) +TMPDIR:= ${TMPDIR}/uid${.MAKE.UID} +.else +TMPDIR:= /tmp/uid${.MAKE.UID} +.endif +# make sure it exists +.if !exist(${TMPDIR}) +_!= mkdir -p ${TMPDIR} +.endif + # Each test is in a sub-makefile. # Keep the list sorted. # Any test that is commented out must be ignored in @@ -83,7 +94,6 @@ TESTS+= cond-token-plain TESTS+= cond-token-string TESTS+= cond-token-var TESTS+= cond-undef-lint -TESTS+= cond1 TESTS+= counter TESTS+= counter-append TESTS+= dep @@ -168,6 +178,8 @@ TESTS+= directive-export-impl TESTS+= directive-export-gmake TESTS+= directive-export-literal TESTS+= directive-for +TESTS+= directive-for-break +TESTS+= directive-for-empty TESTS+= directive-for-errors TESTS+= directive-for-escape TESTS+= directive-for-generating-endif @@ -183,6 +195,7 @@ TESTS+= directive-ifndef TESTS+= directive-ifnmake TESTS+= directive-include TESTS+= directive-include-fatal +TESTS+= directive-include-guard TESTS+= directive-info TESTS+= directive-misspellings TESTS+= directive-sinclude @@ -199,14 +212,12 @@ TESTS+= export TESTS+= export-all TESTS+= export-env TESTS+= export-variants -TESTS+= forloop -TESTS+= forsubst TESTS+= gnode-submake TESTS+= hanoi-include TESTS+= impsrc TESTS+= include-main TESTS+= job-flags -#TESTS+= job-output-long-lines +TESTS+= job-output-long-lines TESTS+= job-output-null TESTS+= jobs-empty-commands TESTS+= jobs-empty-commands-error @@ -217,7 +228,6 @@ TESTS+= lint TESTS+= make-exported TESTS+= meta-cmd-cmp TESTS+= moderrs -TESTS+= modmatch TESTS+= modmisc .if ${.MAKE.UID} > 0 TESTS+= objdir-writable @@ -239,7 +249,7 @@ TESTS+= opt-debug-graph1 TESTS+= opt-debug-graph2 TESTS+= opt-debug-graph3 TESTS+= opt-debug-hash -#TESTS+= opt-debug-jobs +TESTS+= opt-debug-jobs TESTS+= opt-debug-lint TESTS+= opt-debug-loud TESTS+= opt-debug-meta @@ -324,6 +334,7 @@ TESTS+= ternary TESTS+= unexport TESTS+= unexport-env TESTS+= use-inference +TESTS+= var-readonly TESTS+= var-scope TESTS+= var-scope-cmdline TESTS+= var-scope-env @@ -362,6 +373,7 @@ TESTS+= varmod-loop-delete TESTS+= varmod-loop-varname TESTS+= varmod-match TESTS+= varmod-match-escape +TESTS+= varmod-mtime TESTS+= varmod-no-match TESTS+= varmod-order TESTS+= varmod-order-numeric @@ -408,12 +420,20 @@ TESTS+= varname-dot-make-makefiles TESTS+= varname-dot-make-meta-bailiwick TESTS+= varname-dot-make-meta-created TESTS+= varname-dot-make-meta-files +.if ${.MAKE.PATH_FILEMON:Uno:Nktrace:N/dev*} == "" && ${TMPDIR:N/tmp*:N/var/tmp*} != "" +# these tests will not work if TMPDIR is or is a subdir of +# /tmp or /var/tmp +.if ${.MAKE.PATH_FILEMON:N/dev/*} != "" || exists(${.MAKE.PATH_FILEMON}) TESTS+= varname-dot-make-meta-ignore_filter TESTS+= varname-dot-make-meta-ignore_paths TESTS+= varname-dot-make-meta-ignore_patterns +TESTS+= varname-dot-make-path_filemon +.else +.warning Skipping tests that require ${.MAKE.PATH_FILEMON} +.endif +.endif TESTS+= varname-dot-make-meta-prefix TESTS+= varname-dot-make-mode -TESTS+= varname-dot-make-path_filemon TESTS+= varname-dot-make-pid TESTS+= varname-dot-make-ppid TESTS+= varname-dot-make-save_dollars @@ -439,7 +459,6 @@ TESTS+= varparse-dynamic TESTS+= varparse-errors TESTS+= varparse-mod TESTS+= varparse-undef-partial -TESTS+= varquote # some shells have quirks _shell := ${.SHELL:tA:T} @@ -450,10 +469,35 @@ BROKEN_TESTS+= opt-debug-x-trace BROKEN_TESTS+= sh-flags .endif +.if ${UTC_1:Uno} == "" +# this will not work if UTC_1 is set empty +BROKEN_TESTS+= varmod-localtime +.endif + +.if ${.MAKE.OS:NCYGWIN*} == "" +BROKEN_TESTS+= \ + export \ + opt-chdir \ + opt-keep-going-indirect \ + +.endif + + .if ${.MAKE.OS:NDarwin} == "" BROKEN_TESTS+= shell-ksh .endif +.if ${.MAKE.OS:MIRIX*} != "" +BROKEN_TESTS+= \ + cmd-interrupt \ + deptgt-interrupt \ + job-output-null \ + opt-chdir \ + opt-debug-x-trace \ + sh-leading-hyphen \ + +.endif + .if ${.MAKE.OS} == "SCO_SV" BROKEN_TESTS+= \ opt-debug-graph[23] \ @@ -501,7 +545,8 @@ TESTS:= ${TESTS:${BROKEN_TESTS:S,^,N,:ts:}} ENV.depsrc-optional+= TZ=UTC ENV.deptgt-phony+= MAKESYSPATH=. ENV.directive-undef= ENV_VAR=env-value -ENV.envfirst= FROM_ENV=value-from-env +ENV.opt-env= FROM_ENV=value-from-env +ENV.opt-m-include-dir= ${MAKEOBJDIR:DMAKEOBJDIR=${MAKEOBJDIR}} ENV.varmisc= FROM_ENV=env ENV.varmisc+= FROM_ENV_BEFORE=env ENV.varmisc+= FROM_ENV_AFTER=env @@ -521,6 +566,12 @@ FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmdline-plain' # Some tests need extra postprocessing. SED_CMDS.deptgt-phony= ${STD_SED_CMDS.dd} SED_CMDS.dir= ${STD_SED_CMDS.dd} +SED_CMDS.directive-include-guard= \ + -e '/\.MAKEFLAGS/d' \ + -e '/^Parsing line/d' \ + -e '/^SetFilenameVars:/d' \ + -e '/^ParseDependency/d' \ + -e '/^ParseEOF:/d' SED_CMDS.export= -e '/^[^=_A-Za-z0-9]*=/d' SED_CMDS.export-all= ${SED_CMDS.export} SED_CMDS.export-env= ${SED_CMDS.export} @@ -540,6 +591,9 @@ SED_CMDS.opt-chdir= -e 's,\(nonexistent\).[1-9][0-9]*,\1,' \ -e '/name/s,file,File,' \ -e 's,no such,No such,' \ -e 's,Filename,File name,' + +# meta line numbers can vary based on filemon implementation +SED_CMDS.meta-ignore= -e 's,\(\.meta:\) [1-9][0-9]*:,\1 <line>:,' SED_CMDS.opt-debug-graph1= ${STD_SED_CMDS.dg1} SED_CMDS.opt-debug-graph2= ${STD_SED_CMDS.dg2} SED_CMDS.opt-debug-graph3= ${STD_SED_CMDS.dg3} @@ -563,6 +617,7 @@ SED_CMDS.sh-dots+= -e 's,^\(\*\*\* Error code \)[1-9][0-9]*,\1<nonzero>,' SED_CMDS.sh-errctl= ${STD_SED_CMDS.dj} SED_CMDS.sh-flags= ${STD_SED_CMDS.hide-from-output} SED_CMDS.shell-csh= ${STD_SED_CMDS.white-space} +SED_CMDS.sh-leading-hyphen= ${STD_SED_CMDS.shell} SED_CMDS.suff-main+= ${STD_SED_CMDS.dg1} SED_CMDS.suff-main-several+= ${STD_SED_CMDS.dg1} SED_CMDS.suff-transform-debug+= ${STD_SED_CMDS.dg1} @@ -570,17 +625,24 @@ SED_CMDS.var-op-shell+= ${STD_SED_CMDS.shell} SED_CMDS.var-op-shell+= -e '/command/s,No such.*,not found,' SED_CMDS.var-op-shell+= ${STD_SED_CMDS.white-space} SED_CMDS.vardebug+= -e 's,${.SHELL},</path/to/shell>,' +SED_CMDS.varmod-mtime+= -e "s,': .*,': <ENOENT>," SED_CMDS.varmod-subst-regex+= ${STD_SED_CMDS.regex} +SED_CMDS.varparse-errors+= ${STD_SED_CMDS.timestamp} +SED_CMDS.varname-dot-make-meta-ignore_filter+= ${SED_CMDS.meta-ignore} +SED_CMDS.varname-dot-make-meta-ignore_paths+= ${SED_CMDS.meta-ignore} +SED_CMDS.varname-dot-make-meta-ignore_patterns+= ${SED_CMDS.meta-ignore} SED_CMDS.varname-dot-parsedir= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,' SED_CMDS.varname-dot-parsefile= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,' SED_CMDS.varname-dot-shell= -e 's, = /[^ ]*, = (details omitted),g' SED_CMDS.varname-dot-shell+= -e 's,"/[^" ]*","(details omitted)",g' SED_CMDS.varname-dot-shell+= -e 's,\[/[^] ]*\],[(details omitted)],g' -SED_CMDS.varname-empty= ${.OBJDIR .PARSEDIR .PATH .SHELL:L:@v@-e '/\\$v/d'@} +SED_CMDS.varname-empty= ${.OBJDIR .PARSEDIR .PATH .SHELL .SYSPATH:L:@v@-e '/\\$v/d'@} # Some tests need an additional round of postprocessing. +POSTPROC.depsrc-wait= sed -e '/^---/d' -e 's,^\(: Making 3[abc]\)[123]$$,\1,' POSTPROC.deptgt-suffixes= awk '/^\#\*\*\* Suffixes/,/^never-stop/' POSTPROC.gnode-submake= awk '/Input graph/, /^$$/' +POSTPROC.varname-dot-make-mode= sed 's,^\(: Making [abc]\)[123]$$,\1,' # Some tests reuse other tests, which makes them unnecessarily fragile. export-all.rawout: export.mk @@ -599,13 +661,15 @@ STD_SED_CMDS.dd+= -e '/^CachedDir /d' # Omit details such as process IDs from the output of the -dg1 option. STD_SED_CMDS.dg1= -e '/\#.* \.$$/d' STD_SED_CMDS.dg1+= -e '/\.MAKE.PATH_FILEMON/d' -STD_SED_CMDS.dg1+= -e '/^MAKE_VERSION/d;/^\#.*\/mk/d' +STD_SED_CMDS.dg1+= -e '/^\#.*\/mk/d' STD_SED_CMDS.dg1+= -e 's, ${DEFSYSPATH:U/usr/share/mk}$$, <defsyspath>,' STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE *=\) .*,\1 <details omitted>,' STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE\.[A-Z_]* *=\) .*,\1 <details omitted>,' +STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE\.JOBS\.C *=\) .*,\1 <details omitted>,' STD_SED_CMDS.dg1+= -e 's,^\(MACHINE[_ARCH]* *=\) .*,\1 <details omitted>,' STD_SED_CMDS.dg1+= -e 's,^\(MAKE *=\) .*,\1 <details omitted>,' STD_SED_CMDS.dg1+= -e 's,^\(\.SHELL *=\) .*,\1 <details omitted>,' +STD_SED_CMDS.dg1+= -e '/\.SYSPATH/d' STD_SED_CMDS.dg2= ${STD_SED_CMDS.dg1} STD_SED_CMDS.dg2+= -e 's,\(last modified\) ..:..:.. ... ..\, ....,\1 <timestamp>,' @@ -649,9 +713,11 @@ STD_SED_CMDS.hide-from-output= \ # bash 5.1.0 bash: line 1: /nonexistent: No such file or directory # dash dash: 1: cannot open /nonexistent: No such file # +STD_SED_CMDS.shell+= -e 's,^${.SHELL},${.SHELL:T},' STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: line [0-9][0-9]*: ,,' STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: [0-9][0-9]*: ,,' STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: ,,' +STD_SED_CMDS.shell+= -e 's,: command not found,: not found,' STD_SED_CMDS.white-space= -e 's, *, ,g' -e 's, *$$,,' @@ -660,6 +726,11 @@ STD_SED_CMDS.white-space= -e 's, *, ,g' -e 's, *$$,,' STD_SED_CMDS.regex= \ -e 's,\(Regex compilation error:\).*,\1 (details omitted),' +# Normalize timestamps from ':gmtime' or ':localtime' to '<timestamp>'. +# See STD_SED_CMDS.dg2 for timestamps from the debug log. +STD_SED_CMDS.timestamp= \ + -e 's,[A-Z][a-z][a-z] [A-Z][a-z][a-z] [ 0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [12][0-9][0-9][0-9],<timestamp>,' + # End of the configuration helpers section. .-include "Makefile.inc" @@ -703,28 +774,22 @@ LANG= C _MKMSG_TEST= : .endif - -# for many tests we need a TMPDIR that will not collide -# with other users. -.if ${.OBJDIR} != ${.CURDIR} -# easy -TMPDIR:= ${.OBJDIR}/tmp -.elif defined(TMPDIR) -TMPDIR:= ${TMPDIR}/uid${.MAKE.UID} -.else -TMPDIR:= /tmp/uid${.MAKE.UID} -.endif -# make sure it exists -.if !exist(${TMPDIR}) -_!= mkdir -p ${TMPDIR} +# Some Linux systems such as Fedora have deprecated egrep in favor of grep -E. +.if ${.MAKE.OS:NLinux} == "" +EGREP= grep -E .endif +# Keep the classical definition for all other systems. Just as the bmake code +# is kept compatible with C90, the tests are kept compatible with systems that +# are several decades old and don't follow modern POSIX standards. +EGREP?= egrep -MAKE_TEST_ENV= MALLOC_OPTIONS="JA" # for jemalloc 100 +MAKE_TEST_ENV= EGREP="${EGREP}" +MAKE_TEST_ENV+= MALLOC_OPTIONS="JA" # for jemalloc 100 MAKE_TEST_ENV+= MALLOC_CONF="junk:true" # for jemalloc 510 MAKE_TEST_ENV+= TMPDIR=${TMPDIR} .if ${.MAKE.OS} == "NetBSD" -LIMIT_RESOURCES?= ulimit -v 200000 +LIMIT_RESOURCES?= ulimit -v 300000 .endif LIMIT_RESOURCES?= : @@ -746,27 +811,31 @@ LIMIT_RESOURCES?= : echo $$status > ${.TARGET:R}.status @mv ${.TARGET}.tmp ${.TARGET} -# Postprocess the test output so that the results can be compared. +# Postprocess the test output to make the output platform-independent. # -# always pretend .MAKE was called 'make' -_SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,' -_SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,' -_SED_CMDS+= -e 's,^usage: ${TEST_MAKE:T:S,.,\\.,g} ,usage: make ,' -# replace anything after 'stopped in' with unit-tests +# Replace anything after 'stopped in' with unit-tests _SED_CMDS+= -e '/stopped/s, /.*, unit-tests,' # Allow the test files to be placed anywhere. _SED_CMDS+= -e 's,\(\.PARSEDIR}\) = `'"/[^']*'"',\1 = <some-dir>,' _SED_CMDS+= -e 's,\(\.INCLUDEDFROMDIR}\) = `'"/[^']*'"',\1 = <some-dir>,' -_SED_CMDS+= -e 's,${TMPDIR},<tmpdir>,g' +_SED_CMDS+= -e 's,${TMPDIR},<tmpdir>,g' -e 's,${TMPDIR:tA},<tmpdir>,g' # canonicalize ${.OBJDIR} and ${.CURDIR} +_SED_CMDS+= -e 's,${.CURDIR},<curdir>,g' .if ${.OBJDIR} != ${.CURDIR} # yes this is inaccurate but none of the tests expect <objdir> anywhere # which we get depending on how MAKEOBJDIR is set. -_SED_CMDS+= -e 's,${.OBJDIR},<curdir>,g' +_SED_CMDS+= -e 's,${.OBJDIR},<curdir>,g' -e 's,${.OBJDIR:tA},<curdir>,g' .endif -_SED_CMDS+= -e 's,${.CURDIR},<curdir>,g' +# always pretend .MAKE was called 'make' +_SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,' +_SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,' +_SED_CMDS+= -e 's,^usage: ${TEST_MAKE:T:S,.,\\.,g} ,usage: make ,' +_SED_CMDS+= -e 's,${TEST_MAKE:T:S,.,\\.,g}\(\[[1-9][0-9]*\]:\),make\1,' _SED_CMDS+= -e 's,<curdir>/,,g' _SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g' +_SED_CMDS+= -e '/MAKE_VERSION/d' +_SED_CMDS+= -e '/EGREP=/d' + # on AT&T derived systems: false exits 255 not 1 .if ${.MAKE.OS:N*BSD} != "" _SED_CMDS+= -e 's,\(Error code\) 255,\1 1,' diff --git a/contrib/bmake/unit-tests/Makefile.config.in b/contrib/bmake/unit-tests/Makefile.config.in index 3139a0d4d0b5..30049eaa7c26 100644 --- a/contrib/bmake/unit-tests/Makefile.config.in +++ b/contrib/bmake/unit-tests/Makefile.config.in @@ -1,6 +1,7 @@ -# $Id: Makefile.config.in,v 1.3 2021/10/22 07:48:57 sjg Exp $ +# $Id: Makefile.config.in,v 1.4 2022/09/09 18:44:56 sjg Exp $ srcdir= @srcdir@ +EGREP= @egrep@ TOOL_DIFF?= @diff@ DIFF_FLAGS?= @diff_u@ UTC_1= @UTC_1@ diff --git a/contrib/bmake/unit-tests/cmd-errors-jobs.exp b/contrib/bmake/unit-tests/cmd-errors-jobs.exp index 9ed0557975b3..d0a6e51eb84d 100644 --- a/contrib/bmake/unit-tests/cmd-errors-jobs.exp +++ b/contrib/bmake/unit-tests/cmd-errors-jobs.exp @@ -1,9 +1,9 @@ -: undefined eol +: undefined--eol make: Unclosed variable "UNCLOSED" -: unclosed-variable -make: Unclosed variable expression (expecting '}') for "UNCLOSED" -: unclosed-modifier +: unclosed-variable- +make: Unclosed expression, expecting '}' for "UNCLOSED" +: unclosed-modifier- make: Unknown modifier "Z" -: unknown-modifier eol -: end eol +: unknown-modifier--eol +: end-eol exit status 0 diff --git a/contrib/bmake/unit-tests/cmd-errors-jobs.mk b/contrib/bmake/unit-tests/cmd-errors-jobs.mk index 8462a2e3497e..b3dc982de35f 100644 --- a/contrib/bmake/unit-tests/cmd-errors-jobs.mk +++ b/contrib/bmake/unit-tests/cmd-errors-jobs.mk @@ -1,4 +1,4 @@ -# $NetBSD: cmd-errors-jobs.mk,v 1.1 2020/12/27 05:11:40 rillig Exp $ +# $NetBSD: cmd-errors-jobs.mk,v 1.2 2022/09/25 12:51:37 rillig Exp $ # # Demonstrate how errors in variable expansions affect whether the commands # are actually executed in jobs mode. @@ -9,24 +9,24 @@ all: undefined unclosed-variable unclosed-modifier unknown-modifier end # Undefined variables are not an error. They expand to empty strings. undefined: - : $@ ${UNDEFINED} eol + : $@-${UNDEFINED}-eol # XXX: As of 2020-11-01, this command is executed even though it contains # parse errors. unclosed-variable: - : $@ ${UNCLOSED + : $@-${UNCLOSED # XXX: As of 2020-11-01, this command is executed even though it contains # parse errors. unclosed-modifier: - : $@ ${UNCLOSED: + : $@-${UNCLOSED: # XXX: As of 2020-11-01, this command is executed even though it contains # parse errors. unknown-modifier: - : $@ ${UNKNOWN:Z} eol + : $@-${UNKNOWN:Z}-eol end: - : $@ eol + : $@-eol # XXX: As of 2020-11-02, despite the parse errors, the exit status is 0. diff --git a/contrib/bmake/unit-tests/cmd-errors-lint.exp b/contrib/bmake/unit-tests/cmd-errors-lint.exp index 90b63bbcb08e..bdf4ae1a17e8 100644 --- a/contrib/bmake/unit-tests/cmd-errors-lint.exp +++ b/contrib/bmake/unit-tests/cmd-errors-lint.exp @@ -1,7 +1,7 @@ : undefined make: Unclosed variable "UNCLOSED" : unclosed-variable -make: Unclosed variable expression (expecting '}') for "UNCLOSED" +make: Unclosed expression, expecting '}' for "UNCLOSED" : unclosed-modifier make: Unknown modifier "Z" : unknown-modifier diff --git a/contrib/bmake/unit-tests/cmd-errors.exp b/contrib/bmake/unit-tests/cmd-errors.exp index 9ed0557975b3..d0a6e51eb84d 100644 --- a/contrib/bmake/unit-tests/cmd-errors.exp +++ b/contrib/bmake/unit-tests/cmd-errors.exp @@ -1,9 +1,9 @@ -: undefined eol +: undefined--eol make: Unclosed variable "UNCLOSED" -: unclosed-variable -make: Unclosed variable expression (expecting '}') for "UNCLOSED" -: unclosed-modifier +: unclosed-variable- +make: Unclosed expression, expecting '}' for "UNCLOSED" +: unclosed-modifier- make: Unknown modifier "Z" -: unknown-modifier eol -: end eol +: unknown-modifier--eol +: end-eol exit status 0 diff --git a/contrib/bmake/unit-tests/cmd-errors.mk b/contrib/bmake/unit-tests/cmd-errors.mk index 356fe1a3e4a2..6d3880684bcf 100644 --- a/contrib/bmake/unit-tests/cmd-errors.mk +++ b/contrib/bmake/unit-tests/cmd-errors.mk @@ -1,4 +1,4 @@ -# $NetBSD: cmd-errors.mk,v 1.4 2020/12/27 05:11:40 rillig Exp $ +# $NetBSD: cmd-errors.mk,v 1.5 2022/09/25 12:51:37 rillig Exp $ # # Demonstrate how errors in variable expansions affect whether the commands # are actually executed in compat mode. @@ -7,24 +7,24 @@ all: undefined unclosed-variable unclosed-modifier unknown-modifier end # Undefined variables are not an error. They expand to empty strings. undefined: - : $@ ${UNDEFINED} eol + : $@-${UNDEFINED}-eol # XXX: As of 2020-11-01, this command is executed even though it contains # parse errors. unclosed-variable: - : $@ ${UNCLOSED + : $@-${UNCLOSED # XXX: As of 2020-11-01, this command is executed even though it contains # parse errors. unclosed-modifier: - : $@ ${UNCLOSED: + : $@-${UNCLOSED: # XXX: As of 2020-11-01, this command is executed even though it contains # parse errors. unknown-modifier: - : $@ ${UNKNOWN:Z} eol + : $@-${UNKNOWN:Z}-eol end: - : $@ eol + : $@-eol # XXX: As of 2020-11-02, despite the parse errors, the exit status is 0. diff --git a/contrib/bmake/unit-tests/cmd-interrupt.exp b/contrib/bmake/unit-tests/cmd-interrupt.exp index 91f4439e7bea..242db1d9507d 100755 --- a/contrib/bmake/unit-tests/cmd-interrupt.exp +++ b/contrib/bmake/unit-tests/cmd-interrupt.exp @@ -2,7 +2,6 @@ make: *** cmd-interrupt-ordinary removed interrupt-ordinary: ok > cmd-interrupt-phony -make: *** cmd-interrupt-phony removed interrupt-phony: ok > cmd-interrupt-precious interrupt-precious: ok diff --git a/contrib/bmake/unit-tests/cmd-interrupt.mk b/contrib/bmake/unit-tests/cmd-interrupt.mk index fa0d85fc9063..140651b55c62 100755 --- a/contrib/bmake/unit-tests/cmd-interrupt.mk +++ b/contrib/bmake/unit-tests/cmd-interrupt.mk @@ -1,4 +1,4 @@ -# $NetBSD: cmd-interrupt.mk,v 1.3 2020/11/15 14:07:53 rillig Exp $ +# $NetBSD: cmd-interrupt.mk,v 1.4 2023/03/18 22:20:12 sjg Exp $ # # Tests for interrupting a command. # @@ -30,7 +30,7 @@ interrupt-ordinary: interrupt-phony: .PHONY @${.MAKE} ${MAKEFLAGS} -f ${MAKEFILE} cmd-interrupt-phony || true # The ././ is necessary to work around the file cache. - @echo ${.TARGET}: ${exists(././cmd-interrupt-phony) :? error : ok } + @echo ${.TARGET}: ${exists(././cmd-interrupt-phony) :? ok : error } interrupt-precious: .PRECIOUS @${.MAKE} ${MAKEFLAGS} -f ${MAKEFILE} cmd-interrupt-precious || true diff --git a/contrib/bmake/unit-tests/cmdline-undefined.exp b/contrib/bmake/unit-tests/cmdline-undefined.exp index 977ceee6dbf5..197f6da60131 100644 --- a/contrib/bmake/unit-tests/cmdline-undefined.exp +++ b/contrib/bmake/unit-tests/cmdline-undefined.exp @@ -1,17 +1,17 @@ The = assignment operator -make: "cmdline-undefined.mk" line 29: From the command line: Undefined is . -make: "cmdline-undefined.mk" line 30: From .MAKEFLAGS '=': Undefined is . -make: "cmdline-undefined.mk" line 31: From .MAKEFLAGS ':=': Undefined is . -make: "cmdline-undefined.mk" line 35: From the command line: Undefined is now defined. -make: "cmdline-undefined.mk" line 36: From .MAKEFLAGS '=': Undefined is now defined. -make: "cmdline-undefined.mk" line 37: From .MAKEFLAGS ':=': Undefined is now defined. +make: "cmdline-undefined.mk" line 31: From the command line: Undefined is . +make: "cmdline-undefined.mk" line 34: From .MAKEFLAGS '=': Undefined is . +make: "cmdline-undefined.mk" line 37: From .MAKEFLAGS ':=': Undefined is . +make: "cmdline-undefined.mk" line 43: From the command line: Undefined is now defined. +make: "cmdline-undefined.mk" line 46: From .MAKEFLAGS '=': Undefined is now defined. +make: "cmdline-undefined.mk" line 49: From .MAKEFLAGS ':=': Undefined is now defined. The := assignment operator -make: "cmdline-undefined.mk" line 29: From the command line: Undefined is . -make: "cmdline-undefined.mk" line 30: From .MAKEFLAGS '=': Undefined is . -make: "cmdline-undefined.mk" line 31: From .MAKEFLAGS ':=': Undefined is . -make: "cmdline-undefined.mk" line 35: From the command line: Undefined is now defined. -make: "cmdline-undefined.mk" line 36: From .MAKEFLAGS '=': Undefined is now defined. -make: "cmdline-undefined.mk" line 37: From .MAKEFLAGS ':=': Undefined is now defined. +make: "cmdline-undefined.mk" line 31: From the command line: Undefined is . +make: "cmdline-undefined.mk" line 34: From .MAKEFLAGS '=': Undefined is . +make: "cmdline-undefined.mk" line 37: From .MAKEFLAGS ':=': Undefined is . +make: "cmdline-undefined.mk" line 43: From the command line: Undefined is now defined. +make: "cmdline-undefined.mk" line 46: From .MAKEFLAGS '=': Undefined is now defined. +make: "cmdline-undefined.mk" line 49: From .MAKEFLAGS ':=': Undefined is now defined. exit status 0 diff --git a/contrib/bmake/unit-tests/cmdline-undefined.mk b/contrib/bmake/unit-tests/cmdline-undefined.mk index 5a3375cbbfb8..81b44518dd41 100644 --- a/contrib/bmake/unit-tests/cmdline-undefined.mk +++ b/contrib/bmake/unit-tests/cmdline-undefined.mk @@ -1,6 +1,6 @@ -# $NetBSD: cmdline-undefined.mk,v 1.2 2020/11/04 04:49:33 rillig Exp $ +# $NetBSD: cmdline-undefined.mk,v 1.4 2023/11/19 21:47:52 rillig Exp $ # -# Tests for undefined variable expressions in the command line. +# Tests for undefined expressions in the command line. all: # When the command line is parsed, variable assignments using the @@ -26,14 +26,26 @@ all: .MAKEFLAGS: MAKEFLAGS_ASSIGN='Undefined is $${UNDEFINED}.' .MAKEFLAGS: MAKEFLAGS_SUBST:='Undefined is $${UNDEFINED}.' +# expect+2: From the command line: Undefined is . +# expect+1: From the command line: Undefined is . .info From the command line: ${CMDLINE} +# expect+2: From .MAKEFLAGS '=': Undefined is . +# expect+1: From .MAKEFLAGS '=': Undefined is . .info From .MAKEFLAGS '=': ${MAKEFLAGS_ASSIGN} +# expect+2: From .MAKEFLAGS ':=': Undefined is . +# expect+1: From .MAKEFLAGS ':=': Undefined is . .info From .MAKEFLAGS ':=': ${MAKEFLAGS_SUBST} UNDEFINED?= now defined +# expect+2: From the command line: Undefined is now defined. +# expect+1: From the command line: Undefined is now defined. .info From the command line: ${CMDLINE} +# expect+2: From .MAKEFLAGS '=': Undefined is now defined. +# expect+1: From .MAKEFLAGS '=': Undefined is now defined. .info From .MAKEFLAGS '=': ${MAKEFLAGS_ASSIGN} +# expect+2: From .MAKEFLAGS ':=': Undefined is now defined. +# expect+1: From .MAKEFLAGS ':=': Undefined is now defined. .info From .MAKEFLAGS ':=': ${MAKEFLAGS_SUBST} print-undefined: diff --git a/contrib/bmake/unit-tests/cmdline.exp b/contrib/bmake/unit-tests/cmdline.exp index e5748c5f88cb..5700da3295fb 100644 --- a/contrib/bmake/unit-tests/cmdline.exp +++ b/contrib/bmake/unit-tests/cmdline.exp @@ -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 diff --git a/contrib/bmake/unit-tests/cmdline.mk b/contrib/bmake/unit-tests/cmdline.mk index f82e7f967ef8..a24d46208e52 100644 --- a/contrib/bmake/unit-tests/cmdline.mk +++ b/contrib/bmake/unit-tests/cmdline.mk @@ -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,$$,$$,' diff --git a/contrib/bmake/unit-tests/comment.mk b/contrib/bmake/unit-tests/comment.mk index 2471c8cf659d..a3bf781b9a67 100644 --- a/contrib/bmake/unit-tests/comment.mk +++ b/contrib/bmake/unit-tests/comment.mk @@ -1,4 +1,4 @@ -# $NetBSD: comment.mk,v 1.4 2022/01/23 18:00:53 rillig Exp $ +# $NetBSD: comment.mk,v 1.6 2023/11/19 21:47:52 rillig Exp $ # # Demonstrate how comments are written in makefiles. @@ -23,7 +23,7 @@ on and on. .endif # And after the closing directive. VAR= # This comment makes the variable value empty. - # ParseGetLine removes any whitespace before the + # ParseRawLine removes any whitespace before the # comment. .if ${VAR} != "" . error @@ -55,7 +55,7 @@ VAR= \# # Both in the assignment. # Since 2012-03-24 the variable modifier :[#] does not need to be escaped. # To keep the parsing code simple, any "[#" does not start a comment, even -# outside of a variable expression. +# outside of an expression. WORDS= ${VAR:[#]} [# .if ${WORDS} != "1 [#" . error diff --git a/contrib/bmake/unit-tests/compat-error.mk b/contrib/bmake/unit-tests/compat-error.mk index 4cbc48d4b6bb..bcfeb14ac408 100644 --- a/contrib/bmake/unit-tests/compat-error.mk +++ b/contrib/bmake/unit-tests/compat-error.mk @@ -1,17 +1,24 @@ -# $NetBSD: compat-error.mk,v 1.3 2020/12/13 19:33:53 rillig Exp $ +# $NetBSD: compat-error.mk,v 1.5 2022/05/08 06:51:27 rillig Exp $ # # Test detailed error handling in compat mode. # -# Until 2020-12-13, .ERROR_TARGET was success3, which was wrong. -# Since compat.c 1.215 from 2020-12-13, it is 'fail1', which is the first -# failed top-level target. XXX: Even better would be if .ERROR_TARGET were -# the smallest target that caused the build to fail, even if it were a -# sub-sub-sub-dependency of a top-level target. +# Make several targets that alternately succeed and fail. # -# XXX: As of 2020-12-13, .ERROR_CMD is empty, which is wrong. +# The first failing top-level target is recorded in '.ERROR_TARGET'. While +# this information may give a hint as to which target failed, it would be more +# useful at that point to know the actual target that failed, or the complete +# chain from root cause to top-level target. +# +# Historic bugs +# Before compat.c 1.215 from 2020-12-13, '.ERROR_TARGET' was 'success3', +# which was obviously wrong. +# +# Bugs +# As of 2020-12-13, '.ERROR_CMD' is empty, which does not provide any +# insight into the command that actually failed. # # See also: -# Compat_Run +# Compat_MakeAll # # The commit that added the NULL command to gn->commands: # CVS: 1994.06.06.22.45.?? @@ -20,10 +27,10 @@ # 2020: LstNode_SetNull(cmdNode); # # The commit that skipped NULL commands for .ERROR_CMD: -# CVS: 2016.08.11.19.53.?? +# CVS: 2016.08.11.19.53.17 # Git: 58b23478b7353d46457089e726b07a49197388e4 -.MAKEFLAGS: success1 fail1 success2 fail2 success3 +.MAKEFLAGS: -k success1 fail1 success2 fail2 success3 success1 success2 success3: : Making ${.TARGET} out of nothing. diff --git a/contrib/bmake/unit-tests/cond-cmp-numeric-eq.exp b/contrib/bmake/unit-tests/cond-cmp-numeric-eq.exp index 72d3d935755b..059007f00c84 100644 --- a/contrib/bmake/unit-tests/cond-cmp-numeric-eq.exp +++ b/contrib/bmake/unit-tests/cond-cmp-numeric-eq.exp @@ -1,5 +1,5 @@ -make: "cond-cmp-numeric-eq.mk" line 67: Malformed conditional (!(12345 = 12345)) -make: "cond-cmp-numeric-eq.mk" line 74: Malformed conditional (!(12345 === 12345)) +make: "cond-cmp-numeric-eq.mk" line 68: Malformed conditional (!(12345 = 12345)) +make: "cond-cmp-numeric-eq.mk" line 76: Malformed conditional (!(12345 === 12345)) make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/cond-cmp-numeric-eq.mk b/contrib/bmake/unit-tests/cond-cmp-numeric-eq.mk index c6b39876e75e..1d0ade26087e 100755 --- a/contrib/bmake/unit-tests/cond-cmp-numeric-eq.mk +++ b/contrib/bmake/unit-tests/cond-cmp-numeric-eq.mk @@ -1,4 +1,4 @@ -# $NetBSD: cond-cmp-numeric-eq.mk,v 1.5 2020/11/08 21:47:59 rillig Exp $ +# $NetBSD: cond-cmp-numeric-eq.mk,v 1.7 2023/09/07 05:36:33 rillig Exp $ # # Tests for numeric comparisons with the == operator in .if conditions. @@ -40,7 +40,7 @@ . error .endif -# As of 2020-08-23, numeric comparison is implemented as parsing both sides +# Numeric comparison works by parsing both sides # as double, and then performing a normal comparison. The range of double is # typically 16 or 17 significant digits, therefore these two numbers seem to # be equal. @@ -64,6 +64,7 @@ .endif # There is no = operator for numbers. +# expect+1: Malformed conditional (!(12345 = 12345)) .if !(12345 = 12345) . error .else @@ -71,11 +72,9 @@ .endif # There is no === operator for numbers either. +# expect+1: Malformed conditional (!(12345 === 12345)) .if !(12345 === 12345) . error .else . error .endif - -all: - @:; diff --git a/contrib/bmake/unit-tests/cond-cmp-numeric-ge.mk b/contrib/bmake/unit-tests/cond-cmp-numeric-ge.mk index e64be7f0c1a8..62975f950c2a 100755 --- a/contrib/bmake/unit-tests/cond-cmp-numeric-ge.mk +++ b/contrib/bmake/unit-tests/cond-cmp-numeric-ge.mk @@ -1,4 +1,4 @@ -# $NetBSD: cond-cmp-numeric-ge.mk,v 1.2 2020/10/24 08:46:08 rillig Exp $ +# $NetBSD: cond-cmp-numeric-ge.mk,v 1.3 2023/09/07 05:36:33 rillig Exp $ # # Tests for numeric comparisons with the >= operator in .if conditions. @@ -62,7 +62,7 @@ . error .endif -# As of 2020-08-23, numeric comparison is implemented as parsing both sides +# Numeric comparison works by parsing both sides # as double, and then performing a normal comparison. The range of double is # typically 16 or 17 significant digits, therefore these two numbers seem to # be equal. diff --git a/contrib/bmake/unit-tests/cond-cmp-numeric-gt.mk b/contrib/bmake/unit-tests/cond-cmp-numeric-gt.mk index 1cdcc9891d6f..6134f7daf3fe 100755 --- a/contrib/bmake/unit-tests/cond-cmp-numeric-gt.mk +++ b/contrib/bmake/unit-tests/cond-cmp-numeric-gt.mk @@ -1,4 +1,4 @@ -# $NetBSD: cond-cmp-numeric-gt.mk,v 1.2 2020/10/24 08:46:08 rillig Exp $ +# $NetBSD: cond-cmp-numeric-gt.mk,v 1.3 2023/09/07 05:36:33 rillig Exp $ # # Tests for numeric comparisons with the > operator in .if conditions. @@ -61,11 +61,11 @@ . error .endif -# As of 2020-08-23, numeric comparison is implemented as parsing both sides +# Numeric comparison works by parsing both sides # as double, and then performing a normal comparison. The range of double is # typically 16 or 17 significant digits, therefore these two numbers seem to # be equal. -.if 1.000000000000000001 > 1.000000000000000002 +.if 1.000000000000000002 > 1.000000000000000001 . error .endif diff --git a/contrib/bmake/unit-tests/cond-cmp-numeric-le.mk b/contrib/bmake/unit-tests/cond-cmp-numeric-le.mk index 05f5e8dba312..231db76ba618 100755 --- a/contrib/bmake/unit-tests/cond-cmp-numeric-le.mk +++ b/contrib/bmake/unit-tests/cond-cmp-numeric-le.mk @@ -1,4 +1,4 @@ -# $NetBSD: cond-cmp-numeric-le.mk,v 1.2 2020/10/24 08:46:08 rillig Exp $ +# $NetBSD: cond-cmp-numeric-le.mk,v 1.3 2023/09/07 05:36:33 rillig Exp $ # # Tests for numeric comparisons with the <= operator in .if conditions. @@ -62,7 +62,7 @@ . error .endif -# As of 2020-08-23, numeric comparison is implemented as parsing both sides +# Numeric comparison works by parsing both sides # as double, and then performing a normal comparison. The range of double is # typically 16 or 17 significant digits, therefore these two numbers seem to # be equal. diff --git a/contrib/bmake/unit-tests/cond-cmp-numeric-lt.mk b/contrib/bmake/unit-tests/cond-cmp-numeric-lt.mk index b0dddd591543..9529fa9ff0eb 100755 --- a/contrib/bmake/unit-tests/cond-cmp-numeric-lt.mk +++ b/contrib/bmake/unit-tests/cond-cmp-numeric-lt.mk @@ -1,4 +1,4 @@ -# $NetBSD: cond-cmp-numeric-lt.mk,v 1.2 2020/10/24 08:46:08 rillig Exp $ +# $NetBSD: cond-cmp-numeric-lt.mk,v 1.3 2023/09/07 05:36:33 rillig Exp $ # # Tests for numeric comparisons with the < operator in .if conditions. @@ -61,7 +61,7 @@ . error .endif -# As of 2020-08-23, numeric comparison is implemented as parsing both sides +# Numeric comparison works by parsing both sides # as double, and then performing a normal comparison. The range of double is # typically 16 or 17 significant digits, therefore these two numbers seem to # be equal. diff --git a/contrib/bmake/unit-tests/cond-cmp-numeric-ne.mk b/contrib/bmake/unit-tests/cond-cmp-numeric-ne.mk index 0a366a905a21..e311d21f0a54 100755 --- a/contrib/bmake/unit-tests/cond-cmp-numeric-ne.mk +++ b/contrib/bmake/unit-tests/cond-cmp-numeric-ne.mk @@ -1,4 +1,4 @@ -# $NetBSD: cond-cmp-numeric-ne.mk,v 1.2 2020/10/24 08:46:08 rillig Exp $ +# $NetBSD: cond-cmp-numeric-ne.mk,v 1.3 2023/09/07 05:36:33 rillig Exp $ # # Tests for numeric comparisons with the != operator in .if conditions. @@ -37,7 +37,7 @@ . error .endif -# As of 2020-08-23, numeric comparison is implemented as parsing both sides +# Numeric comparison works by parsing both sides # as double, and then performing a normal comparison. The range of double is # typically 16 or 17 significant digits, therefore these two numbers seem to # be equal. diff --git a/contrib/bmake/unit-tests/cond-cmp-numeric.exp b/contrib/bmake/unit-tests/cond-cmp-numeric.exp index d913a44ff889..69a8a1e4fca0 100644 --- a/contrib/bmake/unit-tests/cond-cmp-numeric.exp +++ b/contrib/bmake/unit-tests/cond-cmp-numeric.exp @@ -1,15 +1,15 @@ CondParser_Eval: !(${:UINF} > 1e100) -make: "cond-cmp-numeric.mk" line 11: String comparison operator must be either == or != +make: "cond-cmp-numeric.mk" line 15: Comparison with '>' requires both operands 'INF' and '1e100' to be numeric CondParser_Eval: ${:UNaN} > NaN -make: "cond-cmp-numeric.mk" line 16: String comparison operator must be either == or != +make: "cond-cmp-numeric.mk" line 21: Comparison with '>' requires both operands 'NaN' and 'NaN' to be numeric CondParser_Eval: !(${:UNaN} == NaN) Comparing "NaN" == "NaN" CondParser_Eval: 123 ! 123 -make: "cond-cmp-numeric.mk" line 34: Malformed conditional (123 ! 123) +make: "cond-cmp-numeric.mk" line 38: Malformed conditional (123 ! 123) CondParser_Eval: ${:U 123} < 124 Comparing 123.000000 < 124.000000 CondParser_Eval: ${:U123 } < 124 -make: "cond-cmp-numeric.mk" line 50: String comparison operator must be either == or != +make: "cond-cmp-numeric.mk" line 54: Comparison with '<' requires both operands '123 ' and '124' to be numeric make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/cond-cmp-numeric.mk b/contrib/bmake/unit-tests/cond-cmp-numeric.mk index b34e5bfc0a06..e025b99b27cd 100644 --- a/contrib/bmake/unit-tests/cond-cmp-numeric.mk +++ b/contrib/bmake/unit-tests/cond-cmp-numeric.mk @@ -1,6 +1,9 @@ -# $NetBSD: cond-cmp-numeric.mk,v 1.5 2021/07/29 06:31:18 rillig Exp $ +# $NetBSD: cond-cmp-numeric.mk,v 1.7 2023/03/04 08:07:29 rillig Exp $ # # Tests for numeric comparisons in .if conditions. +# +# See also: +# cond-token-number.mk .MAKEFLAGS: -dc @@ -8,11 +11,13 @@ # Even if strtod(3) parses "INF" as +Infinity, make does not accept this # since it is not really a number; see TryParseNumber. +# expect+1: Comparison with '>' requires both operands 'INF' and '1e100' to be numeric .if !(${:UINF} > 1e100) . error .endif # Neither is NaN a number; see TryParseNumber. +# expect+1: Comparison with '>' requires both operands 'NaN' and 'NaN' to be numeric .if ${:UNaN} > NaN . error .endif @@ -29,8 +34,7 @@ # whether the operator is valid, leaving the rest of the work to the # evaluation functions EvalCompareNum and EvalCompareStr. Ensure that this # parse error is properly reported. -# -# XXX: The warning message does not mention the actual operator. +# expect+1: Malformed conditional (123 ! 123) .if 123 ! 123 . error .else @@ -46,7 +50,7 @@ # Trailing spaces are NOT allowed for numbers. # See EvalCompare and TryParseNumber. -# expect+1: String comparison operator must be either == or != +# expect+1: Comparison with '<' requires both operands '123 ' and '124' to be numeric .if ${:U123 } < 124 . error .else @@ -54,4 +58,3 @@ .endif all: - @:; diff --git a/contrib/bmake/unit-tests/cond-cmp-string.exp b/contrib/bmake/unit-tests/cond-cmp-string.exp index a10341ed2121..e0aabfdadca4 100644 --- a/contrib/bmake/unit-tests/cond-cmp-string.exp +++ b/contrib/bmake/unit-tests/cond-cmp-string.exp @@ -1,11 +1,11 @@ -make: "cond-cmp-string.mk" line 18: Malformed conditional (str != str) -make: "cond-cmp-string.mk" line 42: Malformed conditional ("string" != "str""ing") -make: "cond-cmp-string.mk" line 49: Malformed conditional (!("value" = "value")) -make: "cond-cmp-string.mk" line 56: Malformed conditional (!("value" === "value")) -make: "cond-cmp-string.mk" line 113: String comparison operator must be either == or != -make: "cond-cmp-string.mk" line 120: String comparison operator must be either == or != -make: "cond-cmp-string.mk" line 127: String comparison operator must be either == or != -make: "cond-cmp-string.mk" line 134: String comparison operator must be either == or != +make: "cond-cmp-string.mk" line 19: Malformed conditional (str != str) +make: "cond-cmp-string.mk" line 44: Malformed conditional ("string" != "str""ing") +make: "cond-cmp-string.mk" line 52: Malformed conditional (!("value" = "value")) +make: "cond-cmp-string.mk" line 60: Malformed conditional (!("value" === "value")) +make: "cond-cmp-string.mk" line 118: Comparison with '<' requires both operands 'string' and 'string' to be numeric +make: "cond-cmp-string.mk" line 126: Comparison with '<=' requires both operands 'string' and 'string' to be numeric +make: "cond-cmp-string.mk" line 134: Comparison with '>' requires both operands 'string' and 'string' to be numeric +make: "cond-cmp-string.mk" line 142: Comparison with '>=' requires both operands 'string' and 'string' to be numeric make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/cond-cmp-string.mk b/contrib/bmake/unit-tests/cond-cmp-string.mk index 305a41099b98..7b13ebf2212b 100644 --- a/contrib/bmake/unit-tests/cond-cmp-string.mk +++ b/contrib/bmake/unit-tests/cond-cmp-string.mk @@ -1,4 +1,4 @@ -# $NetBSD: cond-cmp-string.mk,v 1.15 2021/12/11 09:53:53 rillig Exp $ +# $NetBSD: cond-cmp-string.mk,v 1.18 2023/11/19 21:47:52 rillig Exp $ # # Tests for string comparisons in .if conditions. @@ -15,15 +15,16 @@ # The left-hand side of the comparison must be enclosed in quotes. # This one is not enclosed in quotes and thus generates an error message. +# expect+1: Malformed conditional (str != str) .if str != str . error .endif -# The left-hand side of the comparison requires that any variable expression +# The left-hand side of the comparison requires that any expression # is defined. # # The variable named "" is never defined, nevertheless it can be used as a -# starting point for variable expressions. Applying the :U modifier to such +# starting point for expressions. Applying the :U modifier to such # an undefined expression turns it into a defined expression. # # See ApplyModifier_Defined and DEF_DEFINED. @@ -39,6 +40,7 @@ # It is not possible to concatenate two string literals to form a single # string. In C, Python and the shell this is possible, but not in make. +# expect+1: Malformed conditional ("string" != "str""ing") .if "string" != "str""ing" . error .else @@ -46,6 +48,7 @@ .endif # There is no = operator for strings. +# expect+1: Malformed conditional (!("value" = "value")) .if !("value" = "value") . error .else @@ -53,19 +56,20 @@ .endif # There is no === operator for strings either. +# expect+1: Malformed conditional (!("value" === "value")) .if !("value" === "value") . error .else . error .endif -# A variable expression can be enclosed in double quotes. +# An expression can be enclosed in double quotes. .if ${:Uword} != "${:Uword}" . error .endif # Between 2003-01-01 (maybe even earlier) and 2020-10-30, adding one of the -# characters " \t!=><" directly after a variable expression resulted in a +# characters " \t!=><" directly after an expression resulted in a # "Malformed conditional", even though the string was well-formed. .if ${:Uword } != "${:Uword} " . error @@ -85,12 +89,12 @@ . error .endif -# Adding another variable expression to the string literal works though. +# Adding another expression to the string literal works though. .if ${:Uword} != "${:Uwo}${:Urd}" . error .endif -# Adding a space at the beginning of the quoted variable expression works +# Adding a space at the beginning of the quoted expression works # though. .if ${:U word } != " ${:Uword} " . error @@ -110,6 +114,7 @@ .endif # Strings cannot be compared relationally, only for equality. +# expect+1: Comparison with '<' requires both operands 'string' and 'string' to be numeric .if "string" < "string" . error .else @@ -117,6 +122,7 @@ .endif # Strings cannot be compared relationally, only for equality. +# expect+1: Comparison with '<=' requires both operands 'string' and 'string' to be numeric .if "string" <= "string" . error .else @@ -124,6 +130,7 @@ .endif # Strings cannot be compared relationally, only for equality. +# expect+1: Comparison with '>' requires both operands 'string' and 'string' to be numeric .if "string" > "string" . error .else @@ -131,8 +138,17 @@ .endif # Strings cannot be compared relationally, only for equality. +# expect+1: Comparison with '>=' requires both operands 'string' and 'string' to be numeric .if "string" >= "string" . error .else . error .endif + +# Two variables with different values compare unequal. +VAR1= value1 +VAR2= value2 +.if ${VAR1} != ${VAR2} +.else +. error +.endif diff --git a/contrib/bmake/unit-tests/cond-cmp-unary.exp b/contrib/bmake/unit-tests/cond-cmp-unary.exp index 89f90dc1651f..c5b800122eb9 100755 --- a/contrib/bmake/unit-tests/cond-cmp-unary.exp +++ b/contrib/bmake/unit-tests/cond-cmp-unary.exp @@ -1,2 +1,2 @@ -make: "cond-cmp-unary.mk" line 53: This is only reached because of a bug in EvalNotEmpty. +make: "cond-cmp-unary.mk" line 54: This is only reached because of a bug in EvalTruthy. exit status 0 diff --git a/contrib/bmake/unit-tests/cond-cmp-unary.mk b/contrib/bmake/unit-tests/cond-cmp-unary.mk index 168de0f30e3f..80626a279358 100755 --- a/contrib/bmake/unit-tests/cond-cmp-unary.mk +++ b/contrib/bmake/unit-tests/cond-cmp-unary.mk @@ -1,11 +1,11 @@ -# $NetBSD: cond-cmp-unary.mk,v 1.2 2020/11/11 07:30:11 rillig Exp $ +# $NetBSD: cond-cmp-unary.mk,v 1.6 2023/11/19 21:47:52 rillig Exp $ # # Tests for unary comparisons in .if conditions, that is, comparisons with # a single operand. If the operand is a number, it is compared to zero, # if it is a string, it is tested for emptiness. -# The number 0 evaluates to false. -.if 0 +# The number 0 in all its various representations evaluates to false. +.if 0 || 0.0 || 0e0 || 0.0e0 || 0.0e10 . error .endif @@ -24,35 +24,52 @@ . error .endif -# The empty string may come from a variable expression. +# The empty string may come from an expression. # -# XXX: As of 2020-11-11, this empty string is interpreted "as a number" in -# EvalNotEmpty, which is plain wrong. The bug is in TryParseNumber. +# XXX: As of 2023-06-01, this empty string is interpreted "as a number" in +# EvalTruthy, which is plain wrong. The bug is in TryParseNumber. .if ${:U} . error .endif -# A variable expression that is not surrounded by quotes is interpreted +# An expression that is not surrounded by quotes is interpreted # as a number if possible, otherwise as a string. .if ${:U0} . error .endif -# A non-zero number from a variable expression evaluates to true. +# A non-zero number from an expression evaluates to true. .if !${:U12345} . error .endif # A string of whitespace should evaluate to false. # -# XXX: As of 2020-11-11, the implementation in EvalNotEmpty does not skip +# XXX: As of 2023-06-01, the implementation in EvalTruthy does not skip # whitespace before testing for the end. This was probably an oversight in # a commit from 1992-04-15 saying "A variable is empty when it just contains # spaces". .if ${:U } -. info This is only reached because of a bug in EvalNotEmpty. +# expect+1: This is only reached because of a bug in EvalTruthy. +. info This is only reached because of a bug in EvalTruthy. .else . error .endif +# The condition '${VAR:M*}' is almost equivalent to '${VAR:M*} != ""'. The +# only case where they differ is for a single word whose numeric value is zero. +.if ${:U0:M*} +. error +.endif +.if ${:U0:M*} == "" +. error +.endif +# Multiple words cannot be parsed as a single number, thus evaluating to true. +.if !${:U0 0:M*} +. error +.endif +.if ${:U0 0:M*} == "" +. error +.endif + all: # nothing diff --git a/contrib/bmake/unit-tests/cond-eof.exp b/contrib/bmake/unit-tests/cond-eof.exp index 3016a9b27805..58a74d854d91 100644 --- a/contrib/bmake/unit-tests/cond-eof.exp +++ b/contrib/bmake/unit-tests/cond-eof.exp @@ -1,6 +1,6 @@ -make: "cond-eof.mk" line 15: Malformed conditional (0 ${SIDE_EFFECT} ${SIDE_EFFECT2}) -make: "cond-eof.mk" line 17: Malformed conditional (1 ${SIDE_EFFECT} ${SIDE_EFFECT2}) -make: "cond-eof.mk" line 19: Malformed conditional ((0) ${SIDE_EFFECT} ${SIDE_EFFECT2}) +make: "cond-eof.mk" line 17: Malformed conditional (0 ${SIDE_EFFECT} ${SIDE_EFFECT2}) +make: "cond-eof.mk" line 20: Malformed conditional (1 ${SIDE_EFFECT} ${SIDE_EFFECT2}) +make: "cond-eof.mk" line 23: Malformed conditional ((0) ${SIDE_EFFECT} ${SIDE_EFFECT2}) make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/cond-eof.mk b/contrib/bmake/unit-tests/cond-eof.mk index ddf4a4cd20c8..a5f7ce95f89e 100644 --- a/contrib/bmake/unit-tests/cond-eof.mk +++ b/contrib/bmake/unit-tests/cond-eof.mk @@ -1,20 +1,24 @@ -# $NetBSD: cond-eof.mk,v 1.3 2021/12/10 23:12:44 rillig Exp $ +# $NetBSD: cond-eof.mk,v 1.6 2023/11/19 21:47:52 rillig Exp $ # -# Tests for parsing conditions, especially the end of such conditions, which -# are represented as the token TOK_EOF. +# Tests for parsing the end of '.if' conditions, which are represented as the +# token TOK_EOF. + SIDE_EFFECT= ${:!echo 'side effect' 1>&2!} SIDE_EFFECT2= ${:!echo 'side effect 2' 1>&2!} # In the following conditions, ${SIDE_EFFECT} is the position of the first # parse error. Before cond.c 1.286 from 2021-12-10, it was always fully -# evaluated, even if it was not necessary to expand the variable expression. +# evaluated, even if it was not necessary to expand the expression. # These syntax errors are an edge case that does not occur during normal # operation. Still, it is easy to avoid evaluating these expressions, just in # case they have side effects. +# expect+1: Malformed conditional (0 ${SIDE_EFFECT} ${SIDE_EFFECT2}) .if 0 ${SIDE_EFFECT} ${SIDE_EFFECT2} .endif +# expect+1: Malformed conditional (1 ${SIDE_EFFECT} ${SIDE_EFFECT2}) .if 1 ${SIDE_EFFECT} ${SIDE_EFFECT2} .endif +# expect+1: Malformed conditional ((0) ${SIDE_EFFECT} ${SIDE_EFFECT2}) .if (0) ${SIDE_EFFECT} ${SIDE_EFFECT2} .endif diff --git a/contrib/bmake/unit-tests/cond-func-defined.exp b/contrib/bmake/unit-tests/cond-func-defined.exp index 878f56de2ecc..d556f3b982b3 100644 --- a/contrib/bmake/unit-tests/cond-func-defined.exp +++ b/contrib/bmake/unit-tests/cond-func-defined.exp @@ -1,8 +1,8 @@ -make: "cond-func-defined.mk" line 23: Missing closing parenthesis for defined() -make: "cond-func-defined.mk" line 33: Missing closing parenthesis for defined() -make: "cond-func-defined.mk" line 45: In .for loops, variable expressions for the loop variables are -make: "cond-func-defined.mk" line 46: substituted at evaluation time. There is no actual variable -make: "cond-func-defined.mk" line 47: involved, even if it feels like it. +make: "cond-func-defined.mk" line 24: Missing closing parenthesis for defined() +make: "cond-func-defined.mk" line 34: Missing closing parenthesis for defined() +make: "cond-func-defined.mk" line 47: In .for loops, expressions for the loop variables are +make: "cond-func-defined.mk" line 49: substituted at evaluation time. There is no actual variable +make: "cond-func-defined.mk" line 51: involved, even if it feels like it. make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/cond-func-defined.mk b/contrib/bmake/unit-tests/cond-func-defined.mk index 43db548a572b..14597398bc62 100644 --- a/contrib/bmake/unit-tests/cond-func-defined.mk +++ b/contrib/bmake/unit-tests/cond-func-defined.mk @@ -1,4 +1,4 @@ -# $NetBSD: cond-func-defined.mk,v 1.8 2021/12/12 08:55:28 rillig Exp $ +# $NetBSD: cond-func-defined.mk,v 1.11 2023/11/19 21:47:52 rillig Exp $ # # Tests for the defined() function in .if conditions. @@ -20,16 +20,17 @@ ${:UA B}= variable name with spaces .endif # The argument of a function must not directly contain whitespace. +# expect+1: Missing closing parenthesis for defined() .if !defined(A B) . error .endif -# If necessary, the whitespace can be generated by a variable expression. +# If necessary, the whitespace can be generated by an expression. .if !defined(${:UA B}) . error .endif -# Parse error: missing closing parenthesis; see ParseWord. +# expect+1: Missing closing parenthesis for defined() .if defined(DEF . error .else @@ -42,11 +43,19 @@ ${:UA B}= variable name with spaces . if defined(var) . error . else -. info In .for loops, variable expressions for the loop variables are +# expect+1: In .for loops, expressions for the loop variables are +. info In .for loops, expressions for the loop variables are +# expect+1: substituted at evaluation time. There is no actual variable . info substituted at evaluation time. There is no actual variable +# expect+1: involved, even if it feels like it. . info involved, even if it feels like it. . endif .endfor -all: - @:; +# Neither of the conditions is true. Before July 2020, the right-hand +# condition was evaluated even though it was irrelevant. +.if defined(UNDEF) && ${UNDEF:Mx} != "" +. error +.endif + +all: .PHONY diff --git a/contrib/bmake/unit-tests/cond-func-empty.exp b/contrib/bmake/unit-tests/cond-func-empty.exp index d1dfda7c03ee..1d955124d1c6 100644 --- a/contrib/bmake/unit-tests/cond-func-empty.exp +++ b/contrib/bmake/unit-tests/cond-func-empty.exp @@ -1,5 +1,5 @@ -make: "cond-func-empty.mk" line 149: Unclosed variable "WORD" -make: "cond-func-empty.mk" line 149: Malformed conditional (empty(WORD) +make: "cond-func-empty.mk" line 168: Unclosed variable "WORD" +make: "cond-func-empty.mk" line 168: Malformed conditional (empty(WORD) make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/cond-func-empty.mk b/contrib/bmake/unit-tests/cond-func-empty.mk index 24cb7a680b2a..057b175a7693 100644 --- a/contrib/bmake/unit-tests/cond-func-empty.mk +++ b/contrib/bmake/unit-tests/cond-func-empty.mk @@ -1,18 +1,19 @@ -# $NetBSD: cond-func-empty.mk,v 1.17 2021/12/28 22:13:56 rillig Exp $ +# $NetBSD: cond-func-empty.mk,v 1.24 2023/12/19 19:33:40 rillig Exp $ # -# Tests for the empty() function in .if conditions, which tests a variable +# Tests for the empty() function in .if conditions, which tests an # expression for emptiness. # -# Note that the argument in the parentheses is a variable name, not a variable -# expression, optionally followed by variable modifiers. +# Note that the argument in the parentheses is a variable name, not an +# expression. That name may be followed by ':...' modifiers. # .undef UNDEF EMPTY= # empty SPACE= ${:U } +ZERO= 0 WORD= word -# An undefined variable is empty. +# An undefined variable counts as empty. .if !empty(UNDEF) . error .endif @@ -24,11 +25,13 @@ WORD= word . error .endif -# The :S modifier replaces the empty value with an actual word. The -# expression is now no longer empty, but it is still based on an undefined -# variable (DEF_UNDEF). There are a few variable modifiers that turn an -# undefined expression into a defined expression, among them :U and :D, but -# not :S. +# The :S modifier replaces the empty value with an actual word. After +# applying the :S modifier to the expression, its value is 'empty', so it is +# no longer empty, but it is still based on an undefined variable. There are +# a few modifiers that turn an undefined expression into a defined expression, +# among them :U and :D, but not :S. Therefore, at the end of evaluating the +# expression, the expression is still undefined, so its final value becomes an +# empty string. # # XXX: This is hard to explain to someone who doesn't know these # implementation details. @@ -45,15 +48,17 @@ WORD= word . error .endif -# And now to the surprising part. Applying the following :S modifier to the -# undefined expression makes it non-empty, but the expression is still in -# state DEF_UNDEF. The :U modifier that follows only looks at the state -# DEF_UNDEF to decide whether the variable is defined or not. This kind of -# makes sense since the :U modifier tests the _variable_, not the +# When an expression is based on an undefined variable, its modifiers interact +# in sometimes surprising ways. Applying the :S modifier to the undefined +# expression makes its value non-empty, but doesn't change that the expression +# is based on an undefined variable. The :U modifier that follows only looks +# at the definedness state to decide whether the variable is defined or not. +# This kind of makes sense since the :U modifier tests the _variable_, not the # _expression_. # -# But since the variable was undefined to begin with, the fallback value from -# the :U modifier is used in this expression. +# Since the variable was undefined to begin with, the fallback value from the +# :U modifier is used in this expression, instead of keeping the 'value' from +# the :S modifier. # .if ${UNDEF:S,^$,value,W:Ufallback} != "fallback" . error @@ -74,6 +79,17 @@ WORD= word . error .endif +# The variable ZERO has the numeric value 0, but is not empty. This is a +# subtle difference between using either 'empty(ZERO)' or the expression +# '${ZERO}' in a condition. +.if empty(ZERO) +. error +.elif ${ZERO} +. error +.elif ${ZERO} == "" +. error +.endif + # The following example constructs an expression with the variable name "" # and the value " ". This expression counts as empty since the value contains # only whitespace. @@ -90,19 +106,21 @@ WORD= word # neither leading nor trailing spaces are trimmed in the argument of the # function. If the spaces were trimmed, the variable name would be "" and # that variable is indeed undefined. Since CondParser_FuncCallEmpty calls -# Var_Parse without VARE_UNDEFERR, the value of the undefined variable is -# returned as an empty string. +# Var_Parse without VARE_UNDEFERR, the value of the undefined variable "" +# would be returned as an empty string. ${:U }= space .if empty( ) . error .endif -# The value of the following expression is " word", which is not empty. +# The value of the following expression is " word", which is not empty. To be +# empty, _all_ characters in the expression value have to be whitespace, not +# only the first. .if empty(:U word) . error .endif -# The :L modifier creates a variable expression that has the same value as +# The :L modifier creates an expression that has the same value as # its name, which both are "VAR" in this case. The value is therefore not # empty. .if empty(VAR:L) @@ -120,19 +138,19 @@ ${:U }= space . error .endif -# Ensure that variable expressions that appear as part of the argument are -# properly parsed. Typical use cases for this are .for loops, which are -# expanded to exactly these ${:U} expressions. +# Ensure that expressions that appear as part of the function call +# argument are properly parsed. Typical use cases for this are .for loops, +# which are expanded to exactly these ${:U} expressions. # -# If everything goes well, the argument expands to "WORD", and that variable -# is defined at the beginning of this file. The surrounding 'W' and 'D' -# ensure that CondParser_FuncCallEmpty keeps track of the parsing position, -# both before and after the call to Var_Parse. +# The argument expands to "WORD", and that variable is defined at the +# beginning of this file. The surrounding 'W' and 'D' ensure that +# CondParser_FuncCallEmpty keeps track of the parsing position, both before +# and after the call to Var_Parse. .if empty(W${:UOR}D) . error .endif -# There may be spaces at the outside of the parentheses. +# There may be spaces outside the parentheses. # Spaces inside the parentheses are interpreted as part of the variable name. .if ! empty ( WORD ) . error @@ -145,7 +163,8 @@ ${:U WORD }= variable name with spaces . error .endif -# Parse error: missing closing parenthesis. +# expect+2: Unclosed variable "WORD" +# expect+1: Malformed conditional (empty(WORD) .if empty(WORD . error .else @@ -159,10 +178,9 @@ ${:U WORD }= variable name with spaces # Since at least 1993, the manual page claimed that irrelevant parts of # conditions were not evaluated, but that was wrong for a long time. The # expressions in irrelevant parts of the condition were actually evaluated, -# they just allowed undefined variables to be used in the conditions, and the -# result of evaluating them was not used further. These unnecessary -# evaluations were fixed in several commits, starting with var.c 1.226 from -# 2020-07-02. +# they just allowed undefined variables to be used in the conditions. These +# unnecessary evaluations were fixed in several commits, starting with var.c +# 1.226 from 2020-07-02. # # In this example, the variable "VARNAME2" is not defined, so evaluation of # the condition should have stopped at this point, and the rest of the @@ -170,20 +188,20 @@ ${:U WORD }= variable name with spaces # side containing the '!empty' was evaluated though, as it had always been. # # When evaluating the !empty condition, the variable name was parsed as -# "VARNAME${:U2}", but without expanding any nested variable expression, in +# "VARNAME${:U2}", but without expanding any nested expression, in # this case the ${:U2}. The expression '${:U2}' was replaced with an empty # string, the resulting variable name was thus "VARNAME". This conceptually # wrong variable name should have been discarded quickly after parsing it, to # prevent it from doing any harm. # -# The variable expression was expanded though, and this was wrong. The -# expansion was done without VARE_WANTRES (called VARF_WANTRES back -# then) though. This had the effect that the ${:U1} from the value of VARNAME +# The expression was expanded, and this was wrong. The +# expansion was done without VARE_WANTRES (called VARF_WANTRES back then) +# though. This had the effect that the ${:U1} from the value of VARNAME # expanded to an empty string. This in turn created the seemingly recursive # definition VARNAME=${VARNAME}, and that definition was never meant to be # expanded. # -# This was fixed by expanding nested variable expressions in the variable name +# This was fixed by expanding nested expressions in the variable name # only if the flag VARE_WANTRES is given. VARNAME= ${VARNAME${:U1}} .if defined(VARNAME${:U2}) && !empty(VARNAME${:U2}) diff --git a/contrib/bmake/unit-tests/cond-func-exists.mk b/contrib/bmake/unit-tests/cond-func-exists.mk index 48d7e727dc3f..40228cd44902 100644 --- a/contrib/bmake/unit-tests/cond-func-exists.mk +++ b/contrib/bmake/unit-tests/cond-func-exists.mk @@ -1,4 +1,4 @@ -# $NetBSD: cond-func-exists.mk,v 1.6 2020/11/30 20:12:29 rillig Exp $ +# $NetBSD: cond-func-exists.mk,v 1.7 2023/11/19 21:47:52 rillig Exp $ # # Tests for the exists() function in .if conditions. @@ -17,7 +17,7 @@ .endif # The only way to escape characters that would otherwise influence the parser -# is to enclose them in a variable expression. For function arguments, +# is to enclose them in an expression. For function arguments, # neither the backslash nor the dollar sign act as escape character. .if exists(\.) . error @@ -27,7 +27,7 @@ . error .endif -# The argument to the function can have several variable expressions. +# The argument to the function can have several expressions. # See cond-func.mk for the characters that cannot be used directly. .if !exists(${.PARSEDIR}/${.PARSEFILE}) . error diff --git a/contrib/bmake/unit-tests/cond-func-make.exp b/contrib/bmake/unit-tests/cond-func-make.exp index 922203b72cbf..04ef6e29fee1 100644 --- a/contrib/bmake/unit-tests/cond-func-make.exp +++ b/contrib/bmake/unit-tests/cond-func-make.exp @@ -1,3 +1,4 @@ +make: "cond-func-make.mk" line 24: warning: Unfinished character list in pattern argument '[' to function 'make' : via-cmdline : via-dot-makeflags exit status 0 diff --git a/contrib/bmake/unit-tests/cond-func-make.mk b/contrib/bmake/unit-tests/cond-func-make.mk index d75b69bcf98f..15bc9f04d4e0 100644 --- a/contrib/bmake/unit-tests/cond-func-make.mk +++ b/contrib/bmake/unit-tests/cond-func-make.mk @@ -1,4 +1,4 @@ -# $NetBSD: cond-func-make.mk,v 1.3 2020/09/25 20:11:06 rillig Exp $ +# $NetBSD: cond-func-make.mk,v 1.5 2023/06/23 04:56:54 rillig Exp $ # # Tests for the make() function in .if conditions, which tests whether # the argument has been passed as a target via the command line or later @@ -20,5 +20,10 @@ . error .endif +# expect+1: warning: Unfinished character list in pattern argument '[' to function 'make' +.if make([) +. error +.endif + via-cmdline via-dot-makeflags: : $@ diff --git a/contrib/bmake/unit-tests/cond-func.exp b/contrib/bmake/unit-tests/cond-func.exp index d0663ea68647..eeaa89445887 100644 --- a/contrib/bmake/unit-tests/cond-func.exp +++ b/contrib/bmake/unit-tests/cond-func.exp @@ -1,12 +1,12 @@ -make: "cond-func.mk" line 36: Missing closing parenthesis for defined() -make: "cond-func.mk" line 51: Missing closing parenthesis for defined() -make: "cond-func.mk" line 54: Missing closing parenthesis for defined() -make: "cond-func.mk" line 94: The empty variable is never defined. -make: "cond-func.mk" line 103: A plain function name is parsed as defined(...). -make: "cond-func.mk" line 110: A plain function name is parsed as defined(...). -make: "cond-func.mk" line 120: Symbols may start with a function name. -make: "cond-func.mk" line 125: Symbols may start with a function name. -make: "cond-func.mk" line 131: Missing closing parenthesis for defined() +make: "cond-func.mk" line 37: Missing closing parenthesis for defined() +make: "cond-func.mk" line 53: Missing closing parenthesis for defined() +make: "cond-func.mk" line 57: Missing closing parenthesis for defined() +make: "cond-func.mk" line 98: The empty variable is never defined. +make: "cond-func.mk" line 108: A plain function name is parsed as defined(...). +make: "cond-func.mk" line 116: A plain function name is parsed as defined(...). +make: "cond-func.mk" line 127: Symbols may start with a function name. +make: "cond-func.mk" line 133: Symbols may start with a function name. +make: "cond-func.mk" line 139: Missing closing parenthesis for defined() make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/cond-func.mk b/contrib/bmake/unit-tests/cond-func.mk index 959367f5c6ab..aabd31b4db46 100644 --- a/contrib/bmake/unit-tests/cond-func.mk +++ b/contrib/bmake/unit-tests/cond-func.mk @@ -1,12 +1,12 @@ -# $NetBSD: cond-func.mk,v 1.11 2022/01/07 19:30:17 rillig Exp $ +# $NetBSD: cond-func.mk,v 1.14 2023/11/19 21:47:52 rillig Exp $ # # Tests for those parts of the functions in .if conditions that are common # among several functions. # -# The below test uses the function defined(...) since it has no side-effects, -# the other functions (except empty(...)) would work equally well. The -# function empty is special because it uses a different parsing algorithm for -# its argument. +# The below test uses the 'defined' function since it has no side-effects. +# The other functions would work equally well, except for 'empty', which +# parses its argument differently from the other functions. +# DEF= defined ${:UA B}= variable name with spaces @@ -33,11 +33,12 @@ ${VARNAME_UNBALANCED_BRACES}= variable name with unbalanced braces .endif # The argument of a function must not directly contain whitespace. +# expect+1: Missing closing parenthesis for defined() .if !defined(A B) . error .endif -# If necessary, the whitespace can be generated by a variable expression. +# If necessary, the whitespace can be generated by an expression. .if !defined(${:UA B}) . error .endif @@ -48,9 +49,11 @@ ${VARNAME_UNBALANCED_BRACES}= variable name with unbalanced braces # # It's not entirely clear why these characters are forbidden. # The most plausible reason seems to be typo detection. +# expect+1: Missing closing parenthesis for defined() .if !defined(A&B) . error .endif +# expect+1: Missing closing parenthesis for defined() .if !defined(A|B) . error .endif @@ -74,7 +77,7 @@ ${VARNAME_UNBALANCED_BRACES}= variable name with unbalanced braces # There may be spaces around the operators and parentheses, and even # inside the parentheses. The spaces inside the parentheses are not -# allowed for the empty() function (see cond-func-empty.mk), therefore +# allowed for the 'empty' function (see cond-func-empty.mk), therefore # they are typically omitted for the other functions as well. .if ! defined ( DEF ) . error @@ -91,6 +94,7 @@ ${VARNAME_UNBALANCED_BRACES}= variable name with unbalanced braces .if defined() . error .else +# expect+1: The empty variable is never defined. . info The empty variable is never defined. .endif @@ -100,6 +104,7 @@ ${VARNAME_UNBALANCED_BRACES}= variable name with unbalanced braces .if defined . error .else +# expect+1: A plain function name is parsed as defined(...). . info A plain function name is parsed as defined(...). .endif @@ -107,6 +112,7 @@ ${VARNAME_UNBALANCED_BRACES}= variable name with unbalanced braces # is interpreted as 'defined(defined)', and the condition evaluates to true. defined= # defined but empty .if defined +# expect+1: A plain function name is parsed as defined(...). . info A plain function name is parsed as defined(...). .else . error @@ -117,17 +123,19 @@ defined= # defined but empty .if defined-var . error .else +# expect+1: Symbols may start with a function name. . info Symbols may start with a function name. .endif defined-var= # defined but empty .if defined-var +# expect+1: Symbols may start with a function name. . info Symbols may start with a function name. .else . error .endif -# Missing closing parenthesis when parsing the function argument. +# expect+1: Missing closing parenthesis for defined() .if defined( . error .else diff --git a/contrib/bmake/unit-tests/cond-late.exp b/contrib/bmake/unit-tests/cond-late.exp index e179e8c74cc4..703677da634c 100644 --- a/contrib/bmake/unit-tests/cond-late.exp +++ b/contrib/bmake/unit-tests/cond-late.exp @@ -1,4 +1,4 @@ -make: Bad conditional expression ' != "no"' in ' != "no"?:' +make: Bad conditional expression ' != "no"' before '?:' yes no exit status 0 diff --git a/contrib/bmake/unit-tests/cond-late.mk b/contrib/bmake/unit-tests/cond-late.mk index 4df3df2cf1d4..8e3d41f60001 100644 --- a/contrib/bmake/unit-tests/cond-late.mk +++ b/contrib/bmake/unit-tests/cond-late.mk @@ -1,11 +1,12 @@ -# $NetBSD: cond-late.mk,v 1.3 2020/11/15 14:07:53 rillig Exp $ +# $NetBSD: cond-late.mk,v 1.6 2023/12/10 20:12:28 rillig Exp $ # -# Using the :? modifier, variable expressions can contain conditional +# Using the :? modifier, expressions can contain conditional # expressions that are evaluated late, at expansion time. # -# Any variables appearing in these -# conditions are expanded before parsing the condition. This is -# different from many other places. +# Any expressions appearing in these conditions are expanded before parsing +# the condition. This is different from conditions in .if directives, where +# expressions are evaluated individually and only as far as necessary, see +# cond-short.mk. # # Because of this, variables that are used in these lazy conditions # should not contain double-quotes, or the parser will probably fail. @@ -22,10 +23,14 @@ COND.false= "yes" != "yes" # If the order of evaluation were to change to first parse the condition # and then expand the variables, the output would change from the # current "yes no" to "yes yes", since both variables are non-empty. +# expect: yes +# expect: no cond-literal: @echo ${ ${COND.true} :?yes:no} @echo ${ ${COND.false} :?yes:no} -VAR+= ${${UNDEF} != "no":?:} +VAR= ${${UNDEF} != "no":?:} +# expect-reset +# expect: make: Bad conditional expression ' != "no"' before '?:' .if empty(VAR:Mpattern) .endif diff --git a/contrib/bmake/unit-tests/cond-op-and-lint.exp b/contrib/bmake/unit-tests/cond-op-and-lint.exp index 8817fd0d658b..0f2cdb0028f9 100644 --- a/contrib/bmake/unit-tests/cond-op-and-lint.exp +++ b/contrib/bmake/unit-tests/cond-op-and-lint.exp @@ -1,4 +1,4 @@ -make: "cond-op-and-lint.mk" line 9: Unknown operator '&' +make: "cond-op-and-lint.mk" line 10: Unknown operator '&' make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/cond-op-and-lint.mk b/contrib/bmake/unit-tests/cond-op-and-lint.mk index 6262339016f5..bac4566314b0 100644 --- a/contrib/bmake/unit-tests/cond-op-and-lint.mk +++ b/contrib/bmake/unit-tests/cond-op-and-lint.mk @@ -1,4 +1,4 @@ -# $NetBSD: cond-op-and-lint.mk,v 1.1 2020/11/08 23:54:28 rillig Exp $ +# $NetBSD: cond-op-and-lint.mk,v 1.2 2023/06/01 20:56:35 rillig Exp $ # # Tests for the && operator in .if conditions, in lint mode. @@ -6,6 +6,7 @@ # The '&' operator is not allowed in lint mode. # It is not used in practice anyway. +# expect+1: Unknown operator '&' .if 0 & 0 . error .else diff --git a/contrib/bmake/unit-tests/cond-op-and.exp b/contrib/bmake/unit-tests/cond-op-and.exp index cd6b03a8359e..6d5a14b211cc 100644 --- a/contrib/bmake/unit-tests/cond-op-and.exp +++ b/contrib/bmake/unit-tests/cond-op-and.exp @@ -1,7 +1,7 @@ -make: "cond-op-and.mk" line 36: Malformed conditional (0 || (${DEF} && ${UNDEF})) -make: "cond-op-and.mk" line 40: Malformed conditional (0 || (${UNDEF} && ${UNDEF})) -make: "cond-op-and.mk" line 42: Malformed conditional (0 || (!${UNDEF} && ${UNDEF})) -make: "cond-op-and.mk" line 71: Malformed conditional (0 &&& 0) +make: "cond-op-and.mk" line 37: Malformed conditional (0 || (${DEF} && ${UNDEF})) +make: "cond-op-and.mk" line 42: Malformed conditional (0 || (${UNDEF} && ${UNDEF})) +make: "cond-op-and.mk" line 45: Malformed conditional (0 || (!${UNDEF} && ${UNDEF})) +make: "cond-op-and.mk" line 75: Malformed conditional (0 &&& 0) make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/cond-op-and.mk b/contrib/bmake/unit-tests/cond-op-and.mk index 83386ed77de4..19a0672ba44e 100644 --- a/contrib/bmake/unit-tests/cond-op-and.mk +++ b/contrib/bmake/unit-tests/cond-op-and.mk @@ -1,4 +1,4 @@ -# $NetBSD: cond-op-and.mk,v 1.6 2021/12/10 19:14:35 rillig Exp $ +# $NetBSD: cond-op-and.mk,v 1.9 2023/12/17 09:44:00 rillig Exp $ # # Tests for the && operator in .if conditions. @@ -33,12 +33,15 @@ # Test combinations of outer '||' with inner '&&', to ensure that the operands # of the inner '&&' are only evaluated if necessary. DEF= defined +# expect+1: Malformed conditional (0 || (${DEF} && ${UNDEF})) .if 0 || (${DEF} && ${UNDEF}) .endif .if 0 || (!${DEF} && ${UNDEF}) .endif +# expect+1: Malformed conditional (0 || (${UNDEF} && ${UNDEF})) .if 0 || (${UNDEF} && ${UNDEF}) .endif +# expect+1: Malformed conditional (0 || (!${UNDEF} && ${UNDEF})) .if 0 || (!${UNDEF} && ${UNDEF}) .endif .if 1 || (${DEF} && ${UNDEF}) @@ -68,9 +71,14 @@ DEF= defined .endif # There is no operator &&&. +# expect+1: Malformed conditional (0 &&& 0) .if 0 &&& 0 . error .endif -all: - @:; +# The '&&' operator must be preceded by whitespace, otherwise it becomes part +# of the preceding bare word. The condition is parsed as '"1&&" != "" && 1'. +.if 1&& && 1 +.else +. error +.endif diff --git a/contrib/bmake/unit-tests/cond-op-not.exp b/contrib/bmake/unit-tests/cond-op-not.exp index 440670ca7249..fcdceee9af21 100644 --- a/contrib/bmake/unit-tests/cond-op-not.exp +++ b/contrib/bmake/unit-tests/cond-op-not.exp @@ -1,9 +1,9 @@ -make: "cond-op-not.mk" line 29: Not empty evaluates to true. -make: "cond-op-not.mk" line 37: Not space evaluates to false. -make: "cond-op-not.mk" line 41: Not 0 evaluates to true. -make: "cond-op-not.mk" line 49: Not 1 evaluates to false. -make: "cond-op-not.mk" line 55: Not word evaluates to false. -make: "cond-op-not.mk" line 59: Malformed conditional (!) +make: "cond-op-not.mk" line 30: Not empty evaluates to true. +make: "cond-op-not.mk" line 39: Not space evaluates to false. +make: "cond-op-not.mk" line 44: Not 0 evaluates to true. +make: "cond-op-not.mk" line 53: Not 1 evaluates to false. +make: "cond-op-not.mk" line 60: Not word evaluates to false. +make: "cond-op-not.mk" line 65: Malformed conditional (!) make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/cond-op-not.mk b/contrib/bmake/unit-tests/cond-op-not.mk index ffd5bc89e4bf..28f835fa3cbd 100644 --- a/contrib/bmake/unit-tests/cond-op-not.mk +++ b/contrib/bmake/unit-tests/cond-op-not.mk @@ -1,4 +1,4 @@ -# $NetBSD: cond-op-not.mk,v 1.7 2021/01/19 17:49:13 rillig Exp $ +# $NetBSD: cond-op-not.mk,v 1.8 2023/06/01 20:56:35 rillig Exp $ # # Tests for the ! operator in .if conditions, which negates its argument. @@ -26,6 +26,7 @@ .endif .if !${:U} +# expect+1: Not empty evaluates to true. . info Not empty evaluates to true. .else . info Not empty evaluates to false. @@ -34,10 +35,12 @@ .if !${:U } . info Not space evaluates to true. .else +# expect+1: Not space evaluates to false. . info Not space evaluates to false. .endif .if !${:U0} +# expect+1: Not 0 evaluates to true. . info Not 0 evaluates to true. .else . info Not 0 evaluates to false. @@ -46,16 +49,19 @@ .if !${:U1} . info Not 1 evaluates to true. .else +# expect+1: Not 1 evaluates to false. . info Not 1 evaluates to false. .endif .if !${:Uword} . info Not word evaluates to true. .else +# expect+1: Not word evaluates to false. . info Not word evaluates to false. .endif # A single exclamation mark is a parse error. +# expect+1: Malformed conditional (!) .if ! . error .else diff --git a/contrib/bmake/unit-tests/cond-op-or-lint.exp b/contrib/bmake/unit-tests/cond-op-or-lint.exp index 8abae99b6c4c..0fb1d0dae166 100644 --- a/contrib/bmake/unit-tests/cond-op-or-lint.exp +++ b/contrib/bmake/unit-tests/cond-op-or-lint.exp @@ -1,4 +1,4 @@ -make: "cond-op-or-lint.mk" line 9: Unknown operator '|' +make: "cond-op-or-lint.mk" line 10: Unknown operator '|' make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/cond-op-or-lint.mk b/contrib/bmake/unit-tests/cond-op-or-lint.mk index aa29e9a6c2f2..9ece9d5c9af6 100644 --- a/contrib/bmake/unit-tests/cond-op-or-lint.mk +++ b/contrib/bmake/unit-tests/cond-op-or-lint.mk @@ -1,4 +1,4 @@ -# $NetBSD: cond-op-or-lint.mk,v 1.1 2020/11/08 23:54:28 rillig Exp $ +# $NetBSD: cond-op-or-lint.mk,v 1.2 2023/06/01 20:56:35 rillig Exp $ # # Tests for the || operator in .if conditions, in lint mode. @@ -6,6 +6,7 @@ # The '|' operator is not allowed in lint mode. # It is not used in practice anyway. +# expect+1: Unknown operator '|' .if 0 | 0 . error .else diff --git a/contrib/bmake/unit-tests/cond-op-or.exp b/contrib/bmake/unit-tests/cond-op-or.exp index 43b9a5438a31..b10bc4bf7c52 100644 --- a/contrib/bmake/unit-tests/cond-op-or.exp +++ b/contrib/bmake/unit-tests/cond-op-or.exp @@ -1,7 +1,7 @@ -make: "cond-op-or.mk" line 46: Malformed conditional (1 && (!${DEF} || ${UNDEF})) -make: "cond-op-or.mk" line 48: Malformed conditional (1 && (${UNDEF} || ${UNDEF})) -make: "cond-op-or.mk" line 50: Malformed conditional (1 && (!${UNDEF} || ${UNDEF})) -make: "cond-op-or.mk" line 71: Malformed conditional (0 ||| 0) +make: "cond-op-or.mk" line 47: Malformed conditional (1 && (!${DEF} || ${UNDEF})) +make: "cond-op-or.mk" line 50: Malformed conditional (1 && (${UNDEF} || ${UNDEF})) +make: "cond-op-or.mk" line 53: Malformed conditional (1 && (!${UNDEF} || ${UNDEF})) +make: "cond-op-or.mk" line 75: Malformed conditional (0 ||| 0) make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/cond-op-or.mk b/contrib/bmake/unit-tests/cond-op-or.mk index 0b7ac55e6c35..165408f3c130 100644 --- a/contrib/bmake/unit-tests/cond-op-or.mk +++ b/contrib/bmake/unit-tests/cond-op-or.mk @@ -1,4 +1,4 @@ -# $NetBSD: cond-op-or.mk,v 1.8 2021/12/10 19:14:35 rillig Exp $ +# $NetBSD: cond-op-or.mk,v 1.11 2023/12/17 09:44:00 rillig Exp $ # # Tests for the || operator in .if conditions. @@ -43,10 +43,13 @@ DEF= defined .endif .if 1 && (${DEF} || ${UNDEF}) .endif +# expect+1: Malformed conditional (1 && (!${DEF} || ${UNDEF})) .if 1 && (!${DEF} || ${UNDEF}) .endif +# expect+1: Malformed conditional (1 && (${UNDEF} || ${UNDEF})) .if 1 && (${UNDEF} || ${UNDEF}) .endif +# expect+1: Malformed conditional (1 && (!${UNDEF} || ${UNDEF})) .if 1 && (!${UNDEF} || ${UNDEF}) .endif @@ -68,9 +71,14 @@ DEF= defined .endif # There is no operator |||. +# expect+1: Malformed conditional (0 ||| 0) .if 0 ||| 0 . error .endif -all: - @:; +# The '||' operator must be preceded by whitespace, otherwise it becomes part +# of the preceding bare word. The condition is parsed as '"1||" != "" || 0'. +.if 1|| || 0 +.else +. error +.endif diff --git a/contrib/bmake/unit-tests/cond-op-parentheses.exp b/contrib/bmake/unit-tests/cond-op-parentheses.exp index 63f7b19570b5..1daad92b2682 100644 --- a/contrib/bmake/unit-tests/cond-op-parentheses.exp +++ b/contrib/bmake/unit-tests/cond-op-parentheses.exp @@ -1,7 +1,7 @@ -make: "cond-op-parentheses.mk" line 19: String comparison operator must be either == or != -make: "cond-op-parentheses.mk" line 22: Malformed conditional ((3) > 2) -make: "cond-op-parentheses.mk" line 40: Malformed conditional (() -make: "cond-op-parentheses.mk" line 53: Malformed conditional ()) +make: "cond-op-parentheses.mk" line 22: Comparison with '>' requires both operands '3' and '(2' to be numeric +make: "cond-op-parentheses.mk" line 25: Malformed conditional ((3) > 2) +make: "cond-op-parentheses.mk" line 44: Malformed conditional (() +make: "cond-op-parentheses.mk" line 58: Malformed conditional ()) make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/cond-op-parentheses.mk b/contrib/bmake/unit-tests/cond-op-parentheses.mk index b790f8bec330..b6c9bd3c0e9d 100644 --- a/contrib/bmake/unit-tests/cond-op-parentheses.mk +++ b/contrib/bmake/unit-tests/cond-op-parentheses.mk @@ -1,4 +1,4 @@ -# $NetBSD: cond-op-parentheses.mk,v 1.5 2022/01/22 21:50:41 rillig Exp $ +# $NetBSD: cond-op-parentheses.mk,v 1.7 2023/06/01 20:56:35 rillig Exp $ # # Tests for parentheses in .if conditions, which group expressions to override # the precedence of the operators '!', '&&' and '||'. Parentheses cannot be @@ -15,7 +15,10 @@ # Parentheses cannot enclose numbers as there is no need for it. Make does # not implement any arithmetic functions in its condition parser. If # absolutely necessary, use expr(1). -# expect+1: String comparison operator must be either == or != +# +# XXX: It's inconsistent that the right operand has unbalanced parentheses. +# +# expect+1: Comparison with '>' requires both operands '3' and '(2' to be numeric .if 3 > (2) .endif # expect+1: Malformed conditional ((3) > 2) @@ -37,6 +40,7 @@ .endif # An unbalanced opening parenthesis is a parse error. +# expect+1: Malformed conditional (() .if ( . error .else @@ -50,6 +54,7 @@ # TOK_TRUE, TOK_FALSE or TOK_ERROR. In cond.c 1.241, the return type of that # function was changed to a properly restricted enum type, to prevent this bug # from occurring again. +# expect+1: Malformed conditional ()) .if ) . error .else diff --git a/contrib/bmake/unit-tests/cond-op.exp b/contrib/bmake/unit-tests/cond-op.exp index b8f6a4301819..33bab484a6c8 100644 --- a/contrib/bmake/unit-tests/cond-op.exp +++ b/contrib/bmake/unit-tests/cond-op.exp @@ -1,22 +1,21 @@ -make: "cond-op.mk" line 50: Malformed conditional ("!word" == !word) -make: "cond-op.mk" line 76: Malformed conditional (0 ${ERR::=evaluated}) -make: "cond-op.mk" line 80: A misplaced expression after 0 is not evaluated. -make: "cond-op.mk" line 84: Malformed conditional (1 ${ERR::=evaluated}) -make: "cond-op.mk" line 88: A misplaced expression after 1 is not evaluated. -make: "cond-op.mk" line 92: Parsing continues until here. -make: "cond-op.mk" line 95: A B C => (A || B) && C A || B && C A || (B && C) -make: "cond-op.mk" line 102: 0 0 0 => 0 0 0 -make: "cond-op.mk" line 102: 0 0 1 => 0 0 0 -make: "cond-op.mk" line 102: 0 1 0 => 0 0 0 -make: "cond-op.mk" line 102: 0 1 1 => 1 1 1 -make: "cond-op.mk" line 102: 1 0 0 => 0 1 1 -make: "cond-op.mk" line 102: 1 0 1 => 1 1 1 -make: "cond-op.mk" line 102: 1 1 0 => 0 1 1 -make: "cond-op.mk" line 102: 1 1 1 => 1 1 1 -make: "cond-op.mk" line 113: Malformed conditional (1 &&) -make: "cond-op.mk" line 121: Malformed conditional (0 &&) -make: "cond-op.mk" line 129: Malformed conditional (1 ||) -make: "cond-op.mk" line 138: Malformed conditional (0 ||) +make: "cond-op.mk" line 51: Malformed conditional ("!word" == !word) +make: "cond-op.mk" line 72: Malformed conditional (0 ${ERR::=evaluated}) +make: "cond-op.mk" line 77: A misplaced expression after 0 is not evaluated. +make: "cond-op.mk" line 82: Malformed conditional (1 ${ERR::=evaluated}) +make: "cond-op.mk" line 87: A misplaced expression after 1 is not evaluated. +make: "cond-op.mk" line 93: A B C => (A || B) && C A || B && C A || (B && C) +make: "cond-op.mk" line 108: 0 0 0 => 0 0 0 +make: "cond-op.mk" line 108: 0 0 1 => 0 0 0 +make: "cond-op.mk" line 108: 0 1 0 => 0 0 0 +make: "cond-op.mk" line 108: 0 1 1 => 1 1 1 +make: "cond-op.mk" line 108: 1 0 0 => 0 1 1 +make: "cond-op.mk" line 108: 1 0 1 => 1 1 1 +make: "cond-op.mk" line 108: 1 1 0 => 0 1 1 +make: "cond-op.mk" line 108: 1 1 1 => 1 1 1 +make: "cond-op.mk" line 120: Malformed conditional (1 &&) +make: "cond-op.mk" line 129: Malformed conditional (0 &&) +make: "cond-op.mk" line 138: Malformed conditional (1 ||) +make: "cond-op.mk" line 148: Malformed conditional (0 ||) make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/cond-op.mk b/contrib/bmake/unit-tests/cond-op.mk index c3ab09f7709a..6371e4db0594 100644 --- a/contrib/bmake/unit-tests/cond-op.mk +++ b/contrib/bmake/unit-tests/cond-op.mk @@ -1,4 +1,4 @@ -# $NetBSD: cond-op.mk,v 1.15 2021/12/10 23:12:44 rillig Exp $ +# $NetBSD: cond-op.mk,v 1.16 2023/06/01 20:56:35 rillig Exp $ # # Tests for operators like &&, ||, ! in .if conditions. # @@ -47,6 +47,7 @@ # appear unquoted. If any, it must be enclosed in quotes. # In any case, it is not interpreted as a negation of an unquoted string. # See CondParser_String. +# expect+1: Malformed conditional ("!word" == !word) .if "!word" == !word . error .endif @@ -66,32 +67,29 @@ # nevertheless, since CondParser_Or and CondParser_And asked for the expanded # next token, even though in this position of the condition, only comparison # operators, TOK_AND, TOK_OR or TOK_RPAREN are allowed. -# -# -# -# -# -# .undef ERR +# expect+1: Malformed conditional (0 ${ERR::=evaluated}) .if 0 ${ERR::=evaluated} . error .endif .if ${ERR:Uundefined} == undefined +# expect+1: A misplaced expression after 0 is not evaluated. . info A misplaced expression after 0 is not evaluated. .endif .undef ERR +# expect+1: Malformed conditional (1 ${ERR::=evaluated}) .if 1 ${ERR::=evaluated} . error .endif .if ${ERR:Uundefined} == undefined +# expect+1: A misplaced expression after 1 is not evaluated. . info A misplaced expression after 1 is not evaluated. .endif -# Just in case that parsing should ever stop on the first error. -.info Parsing continues until here. # Demonstration that '&&' has higher precedence than '||'. +# expect+1: A B C => (A || B) && C A || B && C A || (B && C) .info A B C => (A || B) && C A || B && C A || (B && C) .for a in 0 1 . for b in 0 1 @@ -99,6 +97,14 @@ . for r1 in ${ ($a || $b) && $c :?1:0} . for r2 in ${ $a || $b && $c :?1:0} . for r3 in ${ $a || ($b && $c) :?1:0} +# expect+8: 0 0 0 => 0 0 0 +# expect+7: 0 0 1 => 0 0 0 +# expect+6: 0 1 0 => 0 0 0 +# expect+5: 0 1 1 => 1 1 1 +# expect+4: 1 0 0 => 0 1 1 +# expect+3: 1 0 1 => 1 1 1 +# expect+2: 1 1 0 => 0 1 1 +# expect+1: 1 1 1 => 1 1 1 . info $a $b $c => ${r1} ${r2} ${r3} . endfor . endfor @@ -110,6 +116,7 @@ # This condition is obviously malformed. It is properly detected and also # was properly detected before 2021-01-19, but only because the left hand # side of the '&&' evaluated to true. +# expect+1: Malformed conditional (1 &&) .if 1 && . error .else @@ -118,6 +125,7 @@ # This obviously malformed condition was not detected as such before cond.c # 1.238 from 2021-01-19. +# expect+1: Malformed conditional (0 &&) .if 0 && . error .else @@ -126,6 +134,7 @@ # This obviously malformed condition was not detected as such before cond.c # 1.238 from 2021-01-19. +# expect+1: Malformed conditional (1 ||) .if 1 || . error .else @@ -135,6 +144,7 @@ # This condition is obviously malformed. It is properly detected and also # was properly detected before 2021-01-19, but only because the left hand # side of the '||' evaluated to false. +# expect+1: Malformed conditional (0 ||) .if 0 || . error .else diff --git a/contrib/bmake/unit-tests/cond-short.exp b/contrib/bmake/unit-tests/cond-short.exp index 2865dcb6ef33..44681b57ebc1 100644 --- a/contrib/bmake/unit-tests/cond-short.exp +++ b/contrib/bmake/unit-tests/cond-short.exp @@ -7,10 +7,7 @@ expected M pattern expected or expected or exists expected or empty -defined(V42) && ${V42} > 0: Ok -defined(V66) && ( "${iV2}" < ${V42} ): Ok -1 || ${iV1} < ${V42}: Ok -1 || ${iV2:U2} < ${V42}: Ok -0 || ${iV1} <= ${V42}: Ok -0 || ${iV2:U2} < ${V42}: Ok -exit status 0 +make: "cond-short.mk" line 231: Comparison with '<' requires both operands '' and '42' to be numeric +make: Fatal errors encountered -- cannot continue +make: stopped in unit-tests +exit status 1 diff --git a/contrib/bmake/unit-tests/cond-short.mk b/contrib/bmake/unit-tests/cond-short.mk index f4e8f87043b5..bcdf372ca6e6 100644 --- a/contrib/bmake/unit-tests/cond-short.mk +++ b/contrib/bmake/unit-tests/cond-short.mk @@ -1,4 +1,4 @@ -# $NetBSD: cond-short.mk,v 1.19 2021/12/27 18:54:19 rillig Exp $ +# $NetBSD: cond-short.mk,v 1.23 2023/11/19 22:32:44 rillig Exp $ # # Demonstrates that in conditions, the right-hand side of an && or || # is only evaluated if it can actually influence the result. @@ -9,9 +9,9 @@ # Before 2020-06-28, the right-hand side of an && or || operator was always # evaluated, which was wrong. In cond.c 1.69 and var.c 1.197 on 2015-10-11, # Var_Parse got a new parameter named 'wantit'. Since then it would have been -# possible to skip evaluation of irrelevant variable expressions and only +# possible to skip evaluation of irrelevant expressions and only # parse them. They were still evaluated though, the only difference to -# relevant variable expressions was that in the irrelevant variable +# relevant expressions was that in the irrelevant # expressions, undefined variables were allowed. This allowed for conditions # like 'defined(VAR) && ${VAR:S,from,to,} != ""', which no longer produced an # error message 'Malformed conditional', but the irrelevant expression was @@ -135,28 +135,32 @@ VAR= # empty again, for the following tests .elif ${echo "unexpected nested or" 1>&2 :L:sh} .endif -# make sure these do not cause complaint -#.MAKEFLAGS: -dc -# TODO: Rewrite this whole section and check all the conditions and variables. -# Several of the assumptions are probably wrong here. -# TODO: replace 'x=' with '.info' or '.error'. -V42= 42 -iV1= ${V42} -iV2= ${V66} +NUMBER= 42 +INDIR_NUMBER= ${NUMBER} +INDIR_UNDEF= ${UNDEF} -.if defined(V42) && ${V42} > 0 -x= Ok +.if defined(NUMBER) && ${NUMBER} > 0 .else -x= Fail +. error .endif -x!= echo 'defined(V42) && $${V42} > 0: $x' >&2; echo -# With cond.c 1.76 from 2020-07-03, the following condition triggered a -# warning: "String comparison operator should be either == or !=". -# This was because the variable expression ${iV2} was defined, but the -# contained variable V66 was undefined. The left-hand side of the comparison -# therefore evaluated to the string "${V66}", which is obviously not a number. +# Starting with var.c 1.226 from from 2020-07-02, the following condition +# triggered a warning: "String comparison operator should be either == or !=". +# +# The left-hand side of the '&&' evaluated to false, which should have made +# the right-hand side irrelevant. +# +# On the right-hand side of the '&&', the expression ${INDIR_UNDEF} was +# defined and had the value '${UNDEF}', but the nested variable UNDEF was +# undefined. The right hand side "${INDIR_UNDEF}" still needed to be parsed, +# and in parse-only mode, the "value" of the parsed expression was the +# uninterpreted variable value, in this case '${UNDEF}'. And even though the +# right hand side of the '&&' should have been irrelevant, the two sides of +# the comparison were still parsed and evaluated. Comparing these two values +# numerically was not possible since the string '${UNDEF}' is not a number, +# so the comparison fell back to string comparison, which then complained +# about the '>' operator. # # This was fixed in cond.c 1.79 from 2020-07-09 by not evaluating irrelevant # comparisons. Instead, they are only parsed and then discarded. @@ -164,59 +168,94 @@ x!= echo 'defined(V42) && $${V42} > 0: $x' >&2; echo # At that time, there was not enough debug logging to see the details in the # -dA log. To actually see it, add debug logging at the beginning and end of # Var_Parse. -.if defined(V66) && ( ${iV2} < ${V42} ) -x= Fail -.else -x= Ok +.if defined(UNDEF) && ${INDIR_UNDEF} < ${NUMBER} +. error +.endif +# Adding a ':U' modifier to the irrelevant expression didn't help, as that +# expression was only parsed, not evaluated. The resulting literal string +# '${INDIR_UNDEF:U2}' was not numeric either, for the same reason as above. +.if defined(UNDEF) && ${INDIR_UNDEF:U2} < ${NUMBER} +. error .endif -# XXX: This condition doesn't match the one above. The quotes are missing -# above. This is a crucial detail since without quotes, the variable -# expression ${iV2} evaluates to "${V66}", and with quotes, it evaluates to "" -# since undefined variables are allowed and expand to an empty string. -x!= echo 'defined(V66) && ( "$${iV2}" < $${V42} ): $x' >&2; echo -.if 1 || ${iV1} < ${V42} -x= Ok -.else -x= Fail + +# Since cond.c 1.76 from 2020.06.28 and before var.c 1.225 from 2020.07.01, +# the following snippet resulted in the error message 'Variable VAR is +# recursive'. The condition '0' evaluated to false, which made the right-hand +# side of the '&&' irrelevant. Back then, irrelevant condition parts were +# still evaluated, but in "irrelevant mode", which allowed undefined variables +# to occur in expressions. In this mode, the variable name 'VAR' was +# unnecessarily evaluated, resulting in the expression '${VAR${:U1}}'. In +# this expression, the variable name was 'VAR${:U1}', and of this variable +# name, only the fixed part 'VAR' was evaluated, without the part '${:U1}'. +# This partial evaluation led to the wrong error message about 'VAR' being +# recursive. +VAR= ${VAR${:U1}} +.if 0 && !empty(VAR) .endif -x!= echo '1 || $${iV1} < $${V42}: $x' >&2; echo -# With cond.c 1.76 from 2020-07-03, the following condition triggered a -# warning: "String comparison operator should be either == or !=". -# This was because the variable expression ${iV2} was defined, but the -# contained variable V66 was undefined. The left-hand side of the comparison -# therefore evaluated to the string "${V66}", which is obviously not a number. + +# Enclosing the expression in double quotes changes how that expression is +# evaluated. In irrelevant expressions that are enclosed in double quotes, +# expressions based on undefined variables are allowed and evaluate to an +# empty string. # -# This was fixed in cond.c 1.79 from 2020-07-09 by not evaluating irrelevant -# comparisons. Instead, they are only parsed and then discarded. +# The manual page stated from at least 1993 on that irrelevant conditions were +# not evaluated, but that was wrong. These conditions were evaluated, the +# only difference was that undefined variables in them didn't trigger an +# error. Since numeric conditions are quite rare, this subtle difference +# didn't catch much attention, as most other conditions such as pattern +# matches or equality comparisons worked fine and never produced error +# messages. +.if defined(UNDEF) && "${INDIR_UNDEF}" < ${NUMBER} +. error +.endif + +# Since the condition is relevant, the indirect undefined variable is +# evaluated as usual, resolving nested undefined expressions to an empty +# string. # -# At that time, there was not enough debug logging to see the details in the -# -dA log. To actually see it, add debug logging at the beginning and end of -# Var_Parse. -.if 1 || ${iV2:U2} < ${V42} -x= Ok +# Comparing an empty string numerically is not possible, however, make has an +# ugly hack in TryParseNumber that treats an empty string as a valid numerical +# value, thus hiding bugs in the makefile. +.if ${INDIR_UNDEF} < ${NUMBER} +# only due to the ugly hack +.else +. error +.endif + +# Due to the quotes around the left-hand side of the '<', the operand is +# marked as a string, thus preventing a numerical comparison. +# +# expect+1: Comparison with '<' requires both operands '' and '42' to be numeric +.if "${INDIR_UNDEF}" < ${NUMBER} +. info yes .else -x= Fail +. info no .endif -x!= echo '1 || $${iV2:U2} < $${V42}: $x' >&2; echo -# the same expressions are fine when the lhs is expanded -# ${iV1} expands to 42 -.if 0 || ${iV1} <= ${V42} -x= Ok +# The right-hand side of '||' is irrelevant and thus not evaluated. +.if 1 || ${INDIR_NUMBER} < ${NUMBER} .else -x= Fail +. error .endif -x!= echo '0 || $${iV1} <= $${V42}: $x' >&2; echo -# ${iV2:U2} expands to 2 -.if 0 || ${iV2:U2} < ${V42} -x= Ok +# The right-hand side of '||' is relevant and thus evaluated normally. +.if 0 || ${INDIR_NUMBER} < ${NUMBER} +. error +.endif + +# The right-hand side of '||' evaluates to an empty string, as the variable +# 'INDIR_UNDEF' is defined, therefore the modifier ':U2' has no effect. +# Comparing an empty string numerically is not possible, however, make has an +# ugly hack in TryParseNumber that treats an empty string as a valid numerical +# value, thus hiding bugs in the makefile. +.if 0 || ${INDIR_UNDEF:U2} < ${NUMBER} +# only due to the ugly hack .else -x= Fail +. error .endif -x!= echo '0 || $${iV2:U2} < $${V42}: $x' >&2; echo + # The right-hand side of the '&&' is irrelevant since the left-hand side # already evaluates to false. Before cond.c 1.79 from 2020-07-09, it was @@ -229,8 +268,8 @@ x!= echo '0 || $${iV2:U2} < $${V42}: $x' >&2; echo # Ensure that irrelevant conditions do not influence the result of the whole # condition. As of cond.c 1.302 from 2021-12-11, an irrelevant function call -# evaluates to true (see CondParser_FuncCall and CondParser_FuncCallEmpty), an -# irrelevant comparison evaluates to false (see CondParser_Comparison). +# evaluated to true (see CondParser_FuncCall and CondParser_FuncCallEmpty), an +# irrelevant comparison evaluated to false (see CondParser_Comparison). # # An irrelevant true bubbles up to the outermost CondParser_And, where it is # ignored. An irrelevant false bubbles up to the outermost CondParser_Or, diff --git a/contrib/bmake/unit-tests/cond-token-number.exp b/contrib/bmake/unit-tests/cond-token-number.exp index f078cb007323..d05833b4e01b 100644 --- a/contrib/bmake/unit-tests/cond-token-number.exp +++ b/contrib/bmake/unit-tests/cond-token-number.exp @@ -1,8 +1,7 @@ -make: "cond-token-number.mk" line 15: Malformed conditional (-0) -make: "cond-token-number.mk" line 25: Malformed conditional (+0) -make: "cond-token-number.mk" line 35: Malformed conditional (!-1) -make: "cond-token-number.mk" line 45: Malformed conditional (!+1) -make: "cond-token-number.mk" line 89: End of the tests. +make: "cond-token-number.mk" line 16: Malformed conditional (-0) +make: "cond-token-number.mk" line 27: Malformed conditional (+0) +make: "cond-token-number.mk" line 38: Malformed conditional (!-1) +make: "cond-token-number.mk" line 49: Malformed conditional (!+1) make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/cond-token-number.mk b/contrib/bmake/unit-tests/cond-token-number.mk index eef528f4b7c6..7e73f8b76f94 100644 --- a/contrib/bmake/unit-tests/cond-token-number.mk +++ b/contrib/bmake/unit-tests/cond-token-number.mk @@ -1,4 +1,4 @@ -# $NetBSD: cond-token-number.mk,v 1.7 2022/01/02 02:57:39 rillig Exp $ +# $NetBSD: cond-token-number.mk,v 1.10 2023/11/19 21:47:52 rillig Exp $ # # Tests for number tokens in .if conditions. # @@ -12,6 +12,7 @@ # accepted by the condition parser. # # See the ch_isdigit call in CondParser_String. +# expect+1: Malformed conditional (-0) .if -0 . error .else @@ -22,6 +23,7 @@ # accepted by the condition parser. # # See the ch_isdigit call in CondParser_String. +# expect+1: Malformed conditional (+0) .if +0 . error .else @@ -32,6 +34,7 @@ # accepted by the condition parser. # # See the ch_isdigit call in CondParser_String. +# expect+1: Malformed conditional (!-1) .if !-1 . error .else @@ -42,19 +45,20 @@ # accepted by the condition parser. # # See the ch_isdigit call in CondParser_String. +# expect+1: Malformed conditional (!+1) .if !+1 . error .else . error .endif -# When the number comes from a variable expression though, it may be signed. +# When the number comes from an expression though, it may be signed. # XXX: This is inconsistent. .if ${:U+0} . error .endif -# When the number comes from a variable expression though, it may be signed. +# When the number comes from an expression though, it may be signed. # XXX: This is inconsistent. .if !${:U+1} . error @@ -85,7 +89,21 @@ HEX= dead . error .endif -# Ensure that parsing continues until here. -.info End of the tests. +# Very small numbers round to 0. +.if 12345e-400 +. error +.endif +.if 12345e-200 +.else +. error +.endif + +# Very large numbers round up to infinity on IEEE 754 implementations, or to +# the largest representable number (VAX); in particular, make does not fall +# back to checking whether a variable of that name is defined. +.if 12345e400 +.else +. error +.endif -all: # nothing +all: diff --git a/contrib/bmake/unit-tests/cond-token-plain.exp b/contrib/bmake/unit-tests/cond-token-plain.exp index 90da7644bd9e..8044f3bac826 100644 --- a/contrib/bmake/unit-tests/cond-token-plain.exp +++ b/contrib/bmake/unit-tests/cond-token-plain.exp @@ -9,11 +9,11 @@ Comparing "\" != "\" CondParser_Eval: ${:U#hash} != #hash Comparing "#hash" != "#hash" CondParser_Eval: 0 # This is treated as a comment, but why? -CondParser_Eval: ${0 # comment :?yes:no} != no -CondParser_Eval: 0 # comment +CondParser_Eval: ${0 # comment:?yes:no} != no +CondParser_Eval: 0 # comment Comparing "no" != "no" -CondParser_Eval: ${1 # comment :?yes:no} != yes -CondParser_Eval: 1 # comment +CondParser_Eval: ${1 # comment:?yes:no} != yes +CondParser_Eval: 1 # comment Comparing "yes" != "yes" CondParser_Eval: ${UNDEF:Uundefined}!=undefined Comparing "undefined" != "undefined" @@ -27,36 +27,37 @@ Comparing "var&&name" != "var&&name" CondParser_Eval: ${:Uvar}||name != "var||name" Comparing "var||name" != "var||name" CondParser_Eval: bare -make: "cond-token-plain.mk" line 105: A bare word is treated like defined(...), and the variable 'bare' is not defined. +make: "cond-token-plain.mk" line 106: A bare word is treated like defined(...), and the variable 'bare' is not defined. CondParser_Eval: VAR -make: "cond-token-plain.mk" line 111: A bare word is treated like defined(...). +make: "cond-token-plain.mk" line 113: A bare word is treated like defined(...). CondParser_Eval: V${:UA}R -make: "cond-token-plain.mk" line 118: ok +make: "cond-token-plain.mk" line 121: ok CondParser_Eval: V${UNDEF}AR -make: "cond-token-plain.mk" line 126: Undefined variables in bare words expand to an empty string. +make: "cond-token-plain.mk" line 130: Undefined variables in bare words expand to an empty string. CondParser_Eval: 0${:Ux00} -make: "cond-token-plain.mk" line 134: Numbers can be composed from literals and variable expressions. +make: "cond-token-plain.mk" line 139: Numbers can be composed from literals and expressions. CondParser_Eval: 0${:Ux01} -make: "cond-token-plain.mk" line 138: Numbers can be composed from literals and variable expressions. +make: "cond-token-plain.mk" line 144: Numbers can be composed from literals and expressions. CondParser_Eval: "" == -make: "cond-token-plain.mk" line 144: Missing right-hand side of operator '==' +make: "cond-token-plain.mk" line 151: Missing right-hand side of operator '==' CondParser_Eval: == "" -make: "cond-token-plain.mk" line 152: Malformed conditional (== "") +make: "cond-token-plain.mk" line 160: Malformed conditional (== "") CondParser_Eval: \\ -make: "cond-token-plain.mk" line 167: The variable '\\' is not defined. +make: "cond-token-plain.mk" line 176: The variable '\\' is not defined. CondParser_Eval: \\ -make: "cond-token-plain.mk" line 172: Now the variable '\\' is defined. +make: "cond-token-plain.mk" line 182: Now the variable '\\' is defined. CondParser_Eval: "unquoted\"quoted" != unquoted"quoted Comparing "unquoted"quoted" != "unquoted"quoted" CondParser_Eval: $$$$$$$$ != "" +make: "cond-token-plain.mk" line 197: Malformed conditional ($$$$$$$$ != "") CondParser_Eval: left == right -make: "cond-token-plain.mk" line 195: Malformed conditional (left == right) +make: "cond-token-plain.mk" line 206: Malformed conditional (left == right) CondParser_Eval: ${0:?:} || left == right CondParser_Eval: 0 -make: "cond-token-plain.mk" line 201: Malformed conditional (${0:?:} || left == right) +make: "cond-token-plain.mk" line 212: Malformed conditional (${0:?:} || left == right) CondParser_Eval: left == right || ${0:?:} -make: "cond-token-plain.mk" line 206: Malformed conditional (left == right || ${0:?:}) -make: "cond-token-plain.mk" line 225: Malformed conditional (VAR.${IF_COUNT::+=1} != "") +make: "cond-token-plain.mk" line 217: Malformed conditional (left == right || ${0:?:}) +make: "cond-token-plain.mk" line 236: Malformed conditional (VAR.${IF_COUNT::+=1} != "") make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/cond-token-plain.mk b/contrib/bmake/unit-tests/cond-token-plain.mk index 1e9f30be9153..79fcc771a855 100644 --- a/contrib/bmake/unit-tests/cond-token-plain.mk +++ b/contrib/bmake/unit-tests/cond-token-plain.mk @@ -1,4 +1,4 @@ -# $NetBSD: cond-token-plain.mk,v 1.15 2021/12/30 02:14:55 rillig Exp $ +# $NetBSD: cond-token-plain.mk,v 1.19 2023/11/19 21:47:52 rillig Exp $ # # Tests for plain tokens (that is, string literals without quotes) # in .if conditions. These are also called bare words. @@ -63,10 +63,10 @@ # anybody really use this? This is neither documented nor obvious since # the '#' is escaped. It's much clearer to write a comment in the line # above the condition. -.if ${0 \# comment :?yes:no} != no +.if ${0 \# comment:?yes:no} != no . error .endif -.if ${1 \# comment :?yes:no} != yes +.if ${1 \# comment:?yes:no} != yes . error .endif @@ -89,7 +89,7 @@ # a coincidence that the '!' is both used in the '!=' comparison operator # as well as for negating a comparison result. # -# The boolean operators '&' and '|' don't terminate a comparison operand. +# The characters '&' and '|' are part of the comparison operand. .if ${:Uvar}&&name != "var&&name" . error .endif @@ -97,24 +97,27 @@ . error .endif -# A bare word may appear alone in a condition, without any comparison -# operator. It is implicitly converted into defined(bare). +# A bare word may occur alone in a condition, without any comparison +# operator. It is interpreted as the function call 'defined(bare)'. .if bare . error .else +# expect+1: A bare word is treated like defined(...), and the variable 'bare' is not defined. . info A bare word is treated like defined(...), and the variable $\ 'bare' is not defined. .endif VAR= defined .if VAR +# expect+1: A bare word is treated like defined(...). . info A bare word is treated like defined(...). .else . error .endif -# Bare words may be intermixed with variable expressions. +# Bare words may be intermixed with expressions. .if V${:UA}R +# expect+1: ok . info ok .else . error @@ -123,6 +126,7 @@ VAR= defined # In bare words, even undefined variables are allowed. Without the bare # words, undefined variables are not allowed. That feels inconsistent. .if V${UNDEF}AR +# expect+1: Undefined variables in bare words expand to an empty string. . info Undefined variables in bare words expand to an empty string. .else . error @@ -131,16 +135,19 @@ VAR= defined .if 0${:Ux00} . error .else -. info Numbers can be composed from literals and variable expressions. +# expect+1: Numbers can be composed from literals and expressions. +. info Numbers can be composed from literals and expressions. .endif .if 0${:Ux01} -. info Numbers can be composed from literals and variable expressions. +# expect+1: Numbers can be composed from literals and expressions. +. info Numbers can be composed from literals and expressions. .else . error .endif # If the right-hand side is missing, it's a parse error. +# expect+1: Missing right-hand side of operator '==' .if "" == . error .else @@ -149,6 +156,7 @@ VAR= defined # If the left-hand side is missing, it's a parse error as well, but without # a specific error message. +# expect+1: Malformed conditional (== "") .if == "" . error .else @@ -164,11 +172,13 @@ VAR= defined .if \\ . error .else +# expect+1: The variable '\\' is not defined. . info The variable '\\' is not defined. .endif ${:U\\\\}= backslash .if \\ +# expect+1: Now the variable '\\' is defined. . info Now the variable '\\' is defined. .else . error @@ -183,6 +193,7 @@ ${:U\\\\}= backslash # FIXME: In CondParser_String, Var_Parse returns var_Error without a # corresponding error message. +# expect+1: Malformed conditional ($$$$$$$$ != "") .if $$$$$$$$ != "" . error .else @@ -194,7 +205,7 @@ ${:U\\\\}= backslash # expect+1: Malformed conditional (left == right) .if left == right .endif -# Before cond.c 1.276 from 2021-09-21, a variable expression containing the +# Before cond.c 1.276 from 2021-09-21, an expression containing the # modifier ':?:' allowed unquoted string literals for the rest of the # condition. This was an unintended implementation mistake. # expect+1: Malformed conditional (${0:?:} || left == right) @@ -234,7 +245,7 @@ ${:U\\\\}= backslash # A different situation is when CondParser.leftUnquotedOK is true. This # situation arises in expressions of the form ${cond:?yes:no}. As of # 2021-12-30, the condition in such an expression is evaluated before parsing -# the condition, see varmod-ifelse.mk. To pass a variable expression to the +# the condition, see varmod-ifelse.mk. To pass an expression to the # condition parser, it needs to be escaped. This rarely happens in practice, # in most cases the conditions are simple enough that it doesn't matter # whether the condition is first evaluated and then parsed, or vice versa. diff --git a/contrib/bmake/unit-tests/cond-token-string.exp b/contrib/bmake/unit-tests/cond-token-string.exp index 1c0f086b464e..db07adcb2d09 100644 --- a/contrib/bmake/unit-tests/cond-token-string.exp +++ b/contrib/bmake/unit-tests/cond-token-string.exp @@ -1,18 +1,21 @@ -make: "cond-token-string.mk" line 13: Unknown modifier "Z" -make: "cond-token-string.mk" line 13: Malformed conditional ("" != "${:Uvalue:Z}") -make: "cond-token-string.mk" line 22: xvalue is not defined. -make: "cond-token-string.mk" line 28: Malformed conditional (x${:Uvalue} == "") -make: "cond-token-string.mk" line 37: Expected. +make: "cond-token-string.mk" line 15: Unknown modifier "Z" +make: "cond-token-string.mk" line 15: Malformed conditional ("" != "${:Uvalue:Z}") +make: "cond-token-string.mk" line 25: xvalue is not defined. +make: "cond-token-string.mk" line 32: Malformed conditional (x${:Uvalue} == "") +make: "cond-token-string.mk" line 42: Expected. CondParser_Eval: "UNDEF" -make: "cond-token-string.mk" line 46: The string literal "UNDEF" is not empty. +make: "cond-token-string.mk" line 52: The string literal "UNDEF" is not empty. CondParser_Eval: " " -make: "cond-token-string.mk" line 54: The string literal " " is not empty, even though it consists of whitespace only. +make: "cond-token-string.mk" line 61: The string literal " " is not empty, even though it consists of whitespace only. CondParser_Eval: "${UNDEF}" -make: "cond-token-string.mk" line 63: An undefined variable in quotes expands to an empty string, which then evaluates to false. +make: "cond-token-string.mk" line 71: An undefined variable in quotes expands to an empty string, which then evaluates to false. CondParser_Eval: "${:Uvalue}" -make: "cond-token-string.mk" line 68: A nonempty variable expression evaluates to true. +make: "cond-token-string.mk" line 77: A nonempty expression evaluates to true. CondParser_Eval: "${:U}" -make: "cond-token-string.mk" line 76: An empty variable evaluates to false. +make: "cond-token-string.mk" line 86: An empty variable evaluates to false. +CondParser_Eval: ("${VAR}") +CondParser_Eval: "quoted" == quoted +Comparing "quoted" == "quoted" make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/cond-token-string.mk b/contrib/bmake/unit-tests/cond-token-string.mk index a92d3a896116..d13c68da134a 100644 --- a/contrib/bmake/unit-tests/cond-token-string.mk +++ b/contrib/bmake/unit-tests/cond-token-string.mk @@ -1,4 +1,4 @@ -# $NetBSD: cond-token-string.mk,v 1.4 2021/01/21 00:38:28 rillig Exp $ +# $NetBSD: cond-token-string.mk,v 1.9 2023/11/19 21:47:52 rillig Exp $ # # Tests for quoted string literals in .if conditions. # @@ -9,7 +9,9 @@ # TODO: Implementation # Cover the code in CondParser_String that frees the memory after parsing -# a variable expression based on an undefined variable. +# an expression based on an undefined variable. +# expect+2: Malformed conditional ("" != "${:Uvalue:Z}") +# expect+1: Unknown modifier "Z" .if "" != "${:Uvalue:Z}" . error .else @@ -19,12 +21,14 @@ .if x${:Uvalue} . error .else +# expect+1: xvalue is not defined. . info xvalue is not defined. .endif # The 'x' produces a "Malformed conditional" since the left-hand side of a -# comparison in an .if directive must be either a variable expression, a +# comparison in an .if directive must be either an expression, a # quoted string literal or a number that starts with a digit. +# expect+1: Malformed conditional (x${:Uvalue} == "") .if x${:Uvalue} == "" . error .else @@ -34,6 +38,7 @@ # In plain words, a '\' can be used to escape any character, just as in # double-quoted string literals. See CondParser_String. .if \x${:Uvalue} == "xvalue" +# expect+1: Expected. . info Expected. .else . error @@ -43,6 +48,7 @@ # A string in quotes is checked whether it is not empty. .if "UNDEF" +# expect+1: The string literal "UNDEF" is not empty. . info The string literal "UNDEF" is not empty. .else . error @@ -51,6 +57,7 @@ # A space is not empty as well. # This differs from many other places where whitespace is trimmed. .if " " +# expect+1: The string literal " " is not empty, even though it consists of whitespace only. . info The string literal " " is not empty, even though it consists of $\ whitespace only. .else @@ -60,12 +67,14 @@ .if "${UNDEF}" . error .else +# expect+1: An undefined variable in quotes expands to an empty string, which then evaluates to false. . info An undefined variable in quotes expands to an empty string, which $\ then evaluates to false. .endif .if "${:Uvalue}" -. info A nonempty variable expression evaluates to true. +# expect+1: A nonempty expression evaluates to true. +. info A nonempty expression evaluates to true. .else . error .endif @@ -73,10 +82,28 @@ .if "${:U}" . error .else +# expect+1: An empty variable evaluates to false. . info An empty variable evaluates to false. .endif +# A non-empty string evaluates to true, no matter if it's a literal string or +# if it contains expressions. The parentheses are not necessary for +# the parser, in this case their only purpose is to make the code harder to +# read for humans. +VAR= value +.if ("${VAR}") +.else +. error +.endif + +# In the conditions in .if directives, the left-hand side of a comparison must +# be enclosed in quotes. The right-hand side does not need to be enclosed in +# quotes. +.if "quoted" == quoted +.else +. error +.endif + .MAKEFLAGS: -d0 -all: - @:; +all: .PHONY diff --git a/contrib/bmake/unit-tests/cond-token-var.exp b/contrib/bmake/unit-tests/cond-token-var.exp index fcd92d12a3da..d84ca56e981b 100644 --- a/contrib/bmake/unit-tests/cond-token-var.exp +++ b/contrib/bmake/unit-tests/cond-token-var.exp @@ -1,7 +1,7 @@ -make: "cond-token-var.mk" line 20: ok -make: "cond-token-var.mk" line 27: Malformed conditional (${UNDEF} == ${DEF}) -make: "cond-token-var.mk" line 33: Malformed conditional (${DEF} == ${UNDEF}) -make: "cond-token-var.mk" line 42: Malformed conditional (${UNDEF}) +make: "cond-token-var.mk" line 21: ok +make: "cond-token-var.mk" line 28: Malformed conditional (${UNDEF} == ${DEF}) +make: "cond-token-var.mk" line 34: Malformed conditional (${DEF} == ${UNDEF}) +make: "cond-token-var.mk" line 44: Malformed conditional (${UNDEF}) make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/cond-token-var.mk b/contrib/bmake/unit-tests/cond-token-var.mk index 168c63c46ac1..c6471756a3dd 100644 --- a/contrib/bmake/unit-tests/cond-token-var.mk +++ b/contrib/bmake/unit-tests/cond-token-var.mk @@ -1,11 +1,11 @@ -# $NetBSD: cond-token-var.mk,v 1.6 2021/04/25 21:05:38 rillig Exp $ +# $NetBSD: cond-token-var.mk,v 1.8 2023/11/19 21:47:52 rillig Exp $ # -# Tests for variable expressions in .if conditions. +# Tests for expressions in .if conditions. # -# Note the fine distinction between a variable and a variable expression. -# A variable has a name and a value. To access the value, one writes a -# variable expression of the form ${VAR}. This is a simple variable -# expression. Variable expressions can get more complicated by adding +# Note the fine distinction between a variable and an expression. +# A variable has a name and a value. To access the value, one writes an +# expression of the form ${VAR}. This is a simple +# expression. Expressions can get more complicated by adding # variable modifiers such as in ${VAR:Mpattern}. # # XXX: Strictly speaking, variable modifiers should be called expression @@ -17,19 +17,20 @@ DEF= defined # A defined variable may appear on either side of the comparison. .if ${DEF} == ${DEF} +# expect+1: ok . info ok .else . error .endif # A variable that appears on the left-hand side must be defined. -# The following line thus generates a parse error. +# expect+1: Malformed conditional (${UNDEF} == ${DEF}) .if ${UNDEF} == ${DEF} . error .endif # A variable that appears on the right-hand side must be defined. -# The following line thus generates a parse error. +# expect+1: Malformed conditional (${DEF} == ${UNDEF}) .if ${DEF} == ${UNDEF} . error .endif @@ -39,6 +40,7 @@ DEF= defined .endif # An undefined variable on its own generates a parse error. +# expect+1: Malformed conditional (${UNDEF}) .if ${UNDEF} .endif @@ -47,7 +49,7 @@ DEF= defined .if ${UNDEF:U} .endif -# If the value of the variable expression is a number, it is compared against +# If the value of the expression is a number, it is compared against # zero. .if ${:U0} . error @@ -56,7 +58,7 @@ DEF= defined . error .endif -# If the value of the variable expression is not a number, any non-empty +# If the value of the expression is not a number, any non-empty # value evaluates to true, even if there is only whitespace. .if ${:U} . error diff --git a/contrib/bmake/unit-tests/cond-undef-lint.exp b/contrib/bmake/unit-tests/cond-undef-lint.exp index 2c4feb0376ff..efab46113f67 100755 --- a/contrib/bmake/unit-tests/cond-undef-lint.exp +++ b/contrib/bmake/unit-tests/cond-undef-lint.exp @@ -1,7 +1,10 @@ -make: "cond-undef-lint.mk" line 23: Variable "UNDEF" is undefined -make: "cond-undef-lint.mk" line 38: Variable "UNDEF" is undefined -make: "cond-undef-lint.mk" line 38: Variable "VAR." is undefined -make: "cond-undef-lint.mk" line 49: Variable "VAR.defined" is undefined +make: "cond-undef-lint.mk" line 25: Variable "UNDEF" is undefined +make: "cond-undef-lint.mk" line 25: Malformed conditional (${UNDEF}) +make: "cond-undef-lint.mk" line 43: Variable "UNDEF" is undefined +make: "cond-undef-lint.mk" line 43: Variable "VAR." is undefined +make: "cond-undef-lint.mk" line 43: Malformed conditional (${VAR.${UNDEF}}) +make: "cond-undef-lint.mk" line 56: Variable "VAR.defined" is undefined +make: "cond-undef-lint.mk" line 56: Malformed conditional (${VAR.${DEF}}) make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/cond-undef-lint.mk b/contrib/bmake/unit-tests/cond-undef-lint.mk index 9dfd1bd53252..6fd353dc60e2 100755 --- a/contrib/bmake/unit-tests/cond-undef-lint.mk +++ b/contrib/bmake/unit-tests/cond-undef-lint.mk @@ -1,4 +1,4 @@ -# $NetBSD: cond-undef-lint.mk,v 1.3 2020/11/15 14:58:14 rillig Exp $ +# $NetBSD: cond-undef-lint.mk,v 1.4 2023/06/01 20:56:35 rillig Exp $ # # Tests for defined and undefined variables in .if conditions, in lint mode. # @@ -20,6 +20,8 @@ DEF= defined .endif # Since the condition fails to evaluate, neither of the branches is taken. +# expect+2: Malformed conditional (${UNDEF}) +# expect+1: Variable "UNDEF" is undefined .if ${UNDEF} . error .else @@ -35,6 +37,9 @@ DEF= defined # # TODO: Suppress the error message "Variable VAR. is undefined". That part # of the expression must not be evaluated at all. +# expect+3: Variable "UNDEF" is undefined +# expect+2: Variable "VAR." is undefined +# expect+1: Malformed conditional (${VAR.${UNDEF}}) .if ${VAR.${UNDEF}} . error .else @@ -46,6 +51,8 @@ DEF= defined # TODO: This pattern looks a lot like CFLAGS.${OPSYS}, which is at least # debatable. Or would any practical use of CFLAGS.${OPSYS} be via an indirect # expression, as in the next example? +# expect+2: Variable "VAR.defined" is undefined +# expect+1: Malformed conditional (${VAR.${DEF}}) .if ${VAR.${DEF}} . error .else diff --git a/contrib/bmake/unit-tests/cond1.exp b/contrib/bmake/unit-tests/cond1.exp deleted file mode 100644 index 8b65d782524d..000000000000 --- a/contrib/bmake/unit-tests/cond1.exp +++ /dev/null @@ -1,23 +0,0 @@ -make: "cond1.mk" line 80: warning: extra else -make: "cond1.mk" line 90: warning: extra else -2 is prime -A='other' B='unknown' C='clever' o='no,no' -Passed: - var - ("var") - (var != var) - var != var - !((var != var) && defined(name)) - var == quoted - -1 is not prime -2 is prime -3 is prime -4 is not prime -5 is prime - -make: String comparison operator must be either == or != -make: Bad conditional expression '"0" > 0' in '"0" > 0?OK:No' - -OK -exit status 0 diff --git a/contrib/bmake/unit-tests/cond1.mk b/contrib/bmake/unit-tests/cond1.mk deleted file mode 100644 index 53908c2dacf1..000000000000 --- a/contrib/bmake/unit-tests/cond1.mk +++ /dev/null @@ -1,114 +0,0 @@ -# $NetBSD: cond1.mk,v 1.3 2020/11/15 14:58:14 rillig Exp $ - -# TODO: Convert these tests into tutorial form. -# TODO: Split these tests by topic. -# TODO: Use better variable names and expression values that actually express -# the intended behavior. uname(1) has nothing to do with conditions. - -# hard code these! -TEST_UNAME_S= NetBSD -TEST_UNAME_M= sparc -TEST_MACHINE= i386 - -.if ${TEST_UNAME_S} -Ok=var, -.endif -.if ("${TEST_UNAME_S}") -Ok+=(\"var\"), -.endif -.if (${TEST_UNAME_M} != ${TEST_MACHINE}) -Ok+=(var != var), -.endif -.if ${TEST_UNAME_M} != ${TEST_MACHINE} -Ok+= var != var, -.endif -.if !((${TEST_UNAME_M} != ${TEST_MACHINE}) && defined(X)) -Ok+= !((var != var) && defined(name)), -.endif -# from bsd.obj.mk -MKOBJ?=no -.if ${MKOBJ} == "no" -o= no -Ok+= var == "quoted", -.else -.if defined(notMAKEOBJDIRPREFIX) || defined(norMAKEOBJDIR) -.if defined(notMAKEOBJDIRPREFIX) -o=${MAKEOBJDIRPREFIX}${__curdir} -.else -o= ${MAKEOBJDIR} -.endif -.endif -o= o -.endif - -# repeat the above to check we get the same result -.if ${MKOBJ} == "no" -o2= no -.else -.if defined(notMAKEOBJDIRPREFIX) || defined(norMAKEOBJDIR) -.if defined(notMAKEOBJDIRPREFIX) -o2=${MAKEOBJDIRPREFIX}${__curdir} -.else -o2= ${MAKEOBJDIR} -.endif -.endif -o2= o -.endif - -PRIMES=2 3 5 7 11 -NUMBERS=1 2 3 4 5 - -n=2 -.if ${PRIMES:M$n} == "" -X=not -.else -X= -.endif - -.if ${MACHINE_ARCH} == no-such -A=one -.else -.if ${MACHINE_ARCH} == not-this -.if ${MACHINE_ARCH} == something-else -A=unlikely -.else -A=no -.endif -.endif -A=other -# We expect an extra else warning - we're not skipping here -.else -A=this should be an error -.endif - -.if $X != "" -.if $X == not -B=one -.else -B=other -# We expect an extra else warning - we are skipping here -.else -B=this should be an error -.endif -.else -B=unknown -.endif - -.if "quoted" == quoted -C=clever -.else -C=dim -.endif - -.if defined(nosuch) && ${nosuch:Mx} != "" -# this should not happen -.info nosuch is x -.endif - -all: - @echo "$n is $X prime" - @echo "A='$A' B='$B' C='$C' o='$o,${o2}'" - @echo "Passed:${.newline} ${Ok:S/,/${.newline}/}" - @echo "${NUMBERS:@n@$n is ${("${PRIMES:M$n}" == ""):?not:} prime${.newline}@}" - @echo "${"${DoNotQuoteHere:U0}" > 0:?OK:No}" - @echo "${${NoSuchNumber:U42} > 0:?OK:No}" diff --git a/contrib/bmake/unit-tests/dep-colon-bug-cross-file.exp b/contrib/bmake/unit-tests/dep-colon-bug-cross-file.exp index 855b575c48bc..a8ef9d0707af 100644 --- a/contrib/bmake/unit-tests/dep-colon-bug-cross-file.exp +++ b/contrib/bmake/unit-tests/dep-colon-bug-cross-file.exp @@ -1,4 +1,4 @@ -make: "dep-colon-bug-cross-file.mk" line 31: warning: duplicate script for target "all" ignored -make: "dep-colon-bug-cross-file.mk" line 40: warning: using previous script for "all" defined here +make: "dep-colon-bug-cross-file.mk" line 32: warning: duplicate script for target "all" ignored +make: "dep-colon-bug-cross-file.mk" line 42: warning: using previous script for "all" defined here : pass 1 exit status 0 diff --git a/contrib/bmake/unit-tests/dep-colon-bug-cross-file.mk b/contrib/bmake/unit-tests/dep-colon-bug-cross-file.mk index 57fbf478163c..930358af2871 100644 --- a/contrib/bmake/unit-tests/dep-colon-bug-cross-file.mk +++ b/contrib/bmake/unit-tests/dep-colon-bug-cross-file.mk @@ -1,4 +1,4 @@ -# $NetBSD: dep-colon-bug-cross-file.mk,v 1.4 2020/09/27 09:53:41 rillig Exp $ +# $NetBSD: dep-colon-bug-cross-file.mk,v 1.5 2023/06/01 20:56:35 rillig Exp $ # # Until 2020-09-25, the very last dependency group of a top-level makefile # was not finished properly. This made it possible to add further commands @@ -28,6 +28,7 @@ PASS?= 1 .if ${PASS} == 2 all: +# expect+1: warning: duplicate script for target "all" ignored : pass 2 .endif @@ -37,5 +38,6 @@ PASS= 2 .MAKEFLAGS: -f ${.PARSEDIR:q}/${.PARSEFILE:q} all: +# expect+1: warning: using previous script for "all" defined here : pass 1 .endif diff --git a/contrib/bmake/unit-tests/dep-op-missing.exp b/contrib/bmake/unit-tests/dep-op-missing.exp index 58b9be353eaa..9b42c5080122 100644 --- a/contrib/bmake/unit-tests/dep-op-missing.exp +++ b/contrib/bmake/unit-tests/dep-op-missing.exp @@ -1,4 +1,4 @@ -make: "dep-op-missing.tmp" line 1: Invalid line type +make: "dep-op-missing.tmp" line 1: Invalid line 'target' make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 0 diff --git a/contrib/bmake/unit-tests/dep-var.exp b/contrib/bmake/unit-tests/dep-var.exp index d32aca455ceb..cc229d32e6d4 100755 --- a/contrib/bmake/unit-tests/dep-var.exp +++ b/contrib/bmake/unit-tests/dep-var.exp @@ -1,4 +1,28 @@ -make: Malformed variable expression at "$)" +Var_Parse: ${UNDEF1} (eval-defined) +Global: .ALLTARGETS = all +Global: .ALLTARGETS = all ${DEF2} +Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b +Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b ${UNDEF3} +Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b ${UNDEF3} 1-${INDIRECT_1}-1 +Global: INDIRECT_1 = 2-$${INDIRECT_2}-2 +Global: INDIRECT_2 = 3-$${INDIRECT_3}-3 +Global: INDIRECT_3 = indirect +Global: UNDEF1 = undef1 +Global: DEF2 = def2 +Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b ${UNDEF3} 1-${INDIRECT_1}-1 $$) +Var_Parse: ${:U\$)}: (eval-defined) +Evaluating modifier ${:U...} on value "" (eval-defined, undefined) +Result of ${:U\$)} is "$)" (eval-defined, defined) +Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b ${UNDEF3} 1-${INDIRECT_1}-1 $$) undef1 +Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b ${UNDEF3} 1-${INDIRECT_1}-1 $$) undef1 def2 +Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b ${UNDEF3} 1-${INDIRECT_1}-1 $$) undef1 def2 a-def2-b +Var_Parse: $INDIRECT_2-2-1 $): (parse-only) +Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b ${UNDEF3} 1-${INDIRECT_1}-1 $$) undef1 def2 a-def2-b 1-2-$INDIRECT_2-2-1 +Var_Parse: $): (parse-only) +Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b ${UNDEF3} 1-${INDIRECT_1}-1 $$) undef1 def2 a-def2-b 1-2-$INDIRECT_2-2-1 $) +Global: .MAKEFLAGS = -r -k -d v -d +Global: .MAKEFLAGS = -r -k -d v -d 0 +make: Malformed expression at "$)" def2 a-def2-b 1-2-NDIRECT_2-2-1 diff --git a/contrib/bmake/unit-tests/dep-var.mk b/contrib/bmake/unit-tests/dep-var.mk index 4503424e31ab..8c1636bbdec2 100755 --- a/contrib/bmake/unit-tests/dep-var.mk +++ b/contrib/bmake/unit-tests/dep-var.mk @@ -1,17 +1,19 @@ -# $NetBSD: dep-var.mk,v 1.6 2021/04/04 10:13:09 rillig Exp $ +# $NetBSD: dep-var.mk,v 1.11 2023/12/19 19:33:40 rillig Exp $ # # Tests for variable references in dependency declarations. # # Uh oh, this feels so strange that probably nobody uses it. But it seems to # be the only way to reach the lower half of SuffExpandChildren. -# XXX: The -dv log says: -# Var_Parse: ${UNDEF1} with VARE_UNDEFERR|VARE_WANTRES -# but no error message is generated for this line. -# The variable expression ${UNDEF1} simply expands to an empty string. +.MAKEFLAGS: -dv + +# expect: Var_Parse: ${UNDEF1} (eval-defined) +# Even though undefined expressions should lead to errors, no error message is +# generated for this line. The expression ${UNDEF1} simply expands +# to an empty string. all: ${UNDEF1} -# Using a double dollar in order to circumvent immediate variable expansion +# Using a double dollar in order to circumvent immediate expression expansion # feels like unintended behavior. At least the manual page says nothing at # all about defined or undefined variables in dependency lines. # @@ -20,10 +22,10 @@ all: ${UNDEF1} all: $${DEF2} a-$${DEF2}-b # This variable is not defined at all. -# XXX: The -dv log says: -# Var_Parse: ${UNDEF3} with VARE_UNDEFERR|VARE_WANTRES +# XXX: The -dv log says later when expanding the sources of 'all': +# Var_Parse: ${UNDEF3} (eval-defined) # but no error message is generated for this line, just like for UNDEF1. -# The variable expression ${UNDEF3} simply expands to an empty string. +# The expression ${UNDEF3} simply expands to an empty string. all: $${UNDEF3} # Try out how many levels of indirection are really expanded in dependency @@ -61,7 +63,7 @@ INDIRECT_3= indirect UNDEF1= undef1 DEF2= def2 -# Cover the code in SuffExpandChildren that deals with malformed variable +# Cover the code in SuffExpandChildren that deals with malformed # expressions. # # This seems to be an edge case that never happens in practice, and it would @@ -81,8 +83,14 @@ all: $$$$) # Since 2020-09-13, this generates a parse error in lint mode (-dL), but not # in normal mode since ParseDependency does not handle any errors after # calling Var_Parse. +# expect: Var_Parse: ${:U\$)}: (eval-defined) +# expect: Var_Parse: $INDIRECT_2-2-1 $): (parse-only) +# expect: Var_Parse: $): (parse-only) undef1 def2 a-def2-b 1-2-$$INDIRECT_2-2-1 ${:U\$)}: @echo ${.TARGET:Q} -# XXX: Why is the exit status still 0, even though Parse_Error is called -# with PARSE_FATAL in SuffExpandChildren? +.MAKEFLAGS: -d0 + +# XXX: The exit status is still 0, even though Parse_Error is called with +# PARSE_FATAL in SuffExpandChildren. The exit status is only affected by +# parse errors when they occur in the parsing phase, see Parse_File. diff --git a/contrib/bmake/unit-tests/dep-wildcards.mk b/contrib/bmake/unit-tests/dep-wildcards.mk index 781b149f5a70..b3e2f14a07c3 100644 --- a/contrib/bmake/unit-tests/dep-wildcards.mk +++ b/contrib/bmake/unit-tests/dep-wildcards.mk @@ -1,4 +1,4 @@ -# $NetBSD: dep-wildcards.mk,v 1.3 2020/09/08 05:33:05 rillig Exp $ +# $NetBSD: dep-wildcards.mk,v 1.4 2023/06/21 12:27:50 rillig Exp $ # # Tests for wildcards such as *.c in dependency declarations. @@ -7,3 +7,9 @@ all: ${.PARSEDIR}/dep-*.mk # The :O is necessary since the result of the dependency resolution # does not order the directory entries itself. @printf '%s\n' ${.ALLSRC:T:O} + +# This is not a wildcard rule as implemented by GNU make, as those rules would +# use '%' instead of '*'. Instead, the pattern '*.target' is a file pattern +# in the current working directory. As there are no such files, the target +# list becomes empty, and the source pattern '*.source' is not even expanded. +*.target: *.source diff --git a/contrib/bmake/unit-tests/dep.mk b/contrib/bmake/unit-tests/dep.mk index 54566d43d2a1..53fadc789b13 100644 --- a/contrib/bmake/unit-tests/dep.mk +++ b/contrib/bmake/unit-tests/dep.mk @@ -1,4 +1,4 @@ -# $NetBSD: dep.mk,v 1.3 2021/12/13 23:38:54 rillig Exp $ +# $NetBSD: dep.mk,v 1.4 2023/06/01 07:27:30 rillig Exp $ # # Tests for dependency declarations, such as "target: sources". @@ -15,4 +15,16 @@ only-colon:: # would be another error message. only-colon: + +# Before parse.c 1.158 from 2009-10-07, the parser broke dependency lines at +# the first ';', without parsing expressions as such. It interpreted the +# first ';' as the separator between the dependency and its commands, and the +# '^' as a shell command. +all: for-subst +.for file in ${.PARSEFILE} +for-subst: ${file:S;^;./;g} + @echo ".for with :S;... OK" +.endfor + + all: diff --git a/contrib/bmake/unit-tests/depsrc-ignore.exp b/contrib/bmake/unit-tests/depsrc-ignore.exp index 162f10ddc17b..608671f58ed8 100644 --- a/contrib/bmake/unit-tests/depsrc-ignore.exp +++ b/contrib/bmake/unit-tests/depsrc-ignore.exp @@ -1,8 +1,8 @@ ignore-errors begin false ignore-errors +*** Error code 1 (ignored) ignore-errors end all begin -*** Error code 1 (ignored) false all *** Error code 1 (continuing) diff --git a/contrib/bmake/unit-tests/depsrc-wait.exp b/contrib/bmake/unit-tests/depsrc-wait.exp index d1a60fbaa6e6..36bcb0678151 100644 --- a/contrib/bmake/unit-tests/depsrc-wait.exp +++ b/contrib/bmake/unit-tests/depsrc-wait.exp @@ -1,13 +1,18 @@ ---- a --- echo a a ---- b1 --- echo b1 b1 ---- b --- echo b b ---- x --- echo x x +: Making 3a +: Making 3a +: Making 3a +: Making 3b +: Making 3b +: Making 3b +: Making 3c +: Making 3c +: Making 3c exit status 0 diff --git a/contrib/bmake/unit-tests/depsrc-wait.mk b/contrib/bmake/unit-tests/depsrc-wait.mk index 95b0ea96e0a5..ab974d47c29d 100644 --- a/contrib/bmake/unit-tests/depsrc-wait.mk +++ b/contrib/bmake/unit-tests/depsrc-wait.mk @@ -1,9 +1,15 @@ -# $NetBSD: depsrc-wait.mk,v 1.3 2020/09/07 18:40:32 rillig Exp $ +# $NetBSD: depsrc-wait.mk,v 1.4 2022/05/07 17:49:47 rillig Exp $ # # Tests for the special source .WAIT in dependency declarations, # which adds a sequence point between the nodes to its left and the nodes # to its right. +all: .PHONY + @${MAKE} -r -f ${MAKEFILE} x + @${MAKE} -r -f ${MAKEFILE} three-by-three + + +.if make(x) # Even though the build could run massively parallel, the .WAIT imposes a # strict ordering in this example, which forces the targets to be made in # exactly this order. @@ -19,3 +25,17 @@ b: b1 echo b b1: echo b1 +.endif + + +# There are 3 groups of 3 targets, with .WAIT barriers in between. Each of +# these groups has to be made completely before starting the next group. +# See Makefile, POSTPROC for the postprocessing that takes place. +.if make(three-by-three) +.MAKEFLAGS: -j5 +.MAKE.MODE+= randomize-targets + +three-by-three: .WAIT 3a1 3a2 3a3 .WAIT 3b1 3b2 3b3 .WAIT 3c1 3c2 3c3 .WAIT +3a1 3a2 3a3 3b1 3b2 3b3 3c1 3c2 3c3: + : Making ${.TARGET} +.endif diff --git a/contrib/bmake/unit-tests/deptgt-begin.exp b/contrib/bmake/unit-tests/deptgt-begin.exp index abc80afe9964..db4c7d7dfa13 100644 --- a/contrib/bmake/unit-tests/deptgt-begin.exp +++ b/contrib/bmake/unit-tests/deptgt-begin.exp @@ -1,5 +1,5 @@ -make: "deptgt-begin.mk" line 17: warning: duplicate script for target ".BEGIN" ignored -make: "deptgt-begin.mk" line 8: warning: using previous script for ".BEGIN" defined here +make: "deptgt-begin.mk" line 19: warning: duplicate script for target ".BEGIN" ignored +make: "deptgt-begin.mk" line 9: warning: using previous script for ".BEGIN" defined here : parse time : Making before-begin before .BEGIN. : .BEGIN diff --git a/contrib/bmake/unit-tests/deptgt-begin.mk b/contrib/bmake/unit-tests/deptgt-begin.mk index b71d78f371ed..8b9842641a2d 100644 --- a/contrib/bmake/unit-tests/deptgt-begin.mk +++ b/contrib/bmake/unit-tests/deptgt-begin.mk @@ -1,9 +1,10 @@ -# $NetBSD: deptgt-begin.mk,v 1.5 2020/11/15 22:28:08 rillig Exp $ +# $NetBSD: deptgt-begin.mk,v 1.7 2023/06/01 20:56:35 rillig Exp $ # # Tests for the special target .BEGIN in dependency declarations, # which is a container for commands that are run before any other # commands from the shell lines. +# expect+2: warning: using previous script for ".BEGIN" defined here .BEGIN: : $@ @@ -13,6 +14,7 @@ # add its commands after this. # # There are several ways to resolve this situation, which are detailed below. +# expect+2: warning: duplicate script for target ".BEGIN" ignored .BEGIN: : Making another $@. @@ -25,8 +27,8 @@ before-begin: .PHONY .NOTMAIN # Another way is to define a custom target and make that a .USE dependency. # For the .BEGIN target, .USE dependencies do not work though, since in -# Compat_Run, the .USE and .USEBEFORE nodes are expanded right after the -# .BEGIN target has been run, which is too late. +# Compat_MakeAll, the .USE and .USEBEFORE nodes are expanded right after the +# .BEGIN target has been made, which is too late. .BEGIN: use use: .USE .NOTMAIN : Making $@ from a .USE dependency. @@ -35,8 +37,8 @@ use: .USE .NOTMAIN # .BEGIN target. # # For the .BEGIN target, .USEBEFORE dependencies do not work though, since in -# Compat_Run, the .USE and .USEBEFORE nodes are expanded right after the -# .BEGIN target has been run, which is too late. +# Compat_MakeAll, the .USE and .USEBEFORE nodes are expanded right after the +# .BEGIN target has been made, which is too late. .BEGIN: use-before use-before: .USEBEFORE .NOTMAIN : Making $@ from a .USEBEFORE dependency. diff --git a/contrib/bmake/unit-tests/deptgt-delete_on_error.exp b/contrib/bmake/unit-tests/deptgt-delete_on_error.exp index 9d9f1dc3e5ec..e60aa01351e2 100644 --- a/contrib/bmake/unit-tests/deptgt-delete_on_error.exp +++ b/contrib/bmake/unit-tests/deptgt-delete_on_error.exp @@ -7,10 +7,8 @@ make: *** deptgt-delete_on_error-regular removed make: *** deptgt-delete_on_error-regular-delete removed > deptgt-delete_on_error-phony; false *** Error code 1 (continuing) -make: *** deptgt-delete_on_error-phony removed > deptgt-delete_on_error-phony-delete; false *** Error code 1 (continuing) -make: *** deptgt-delete_on_error-phony-delete removed > deptgt-delete_on_error-precious; false *** Error code 1 (continuing) > deptgt-delete_on_error-precious-delete; false @@ -18,6 +16,7 @@ make: *** deptgt-delete_on_error-phony-delete removed Stop. make: stopped in unit-tests +*** Error code 1 (ignored) Parallel mode > deptgt-delete_on_error-regular; false @@ -47,5 +46,4 @@ make: stopped in unit-tests make: stopped in unit-tests *** Error code 1 (ignored) -*** Error code 1 (ignored) exit status 0 diff --git a/contrib/bmake/unit-tests/deptgt-delete_on_error.mk b/contrib/bmake/unit-tests/deptgt-delete_on_error.mk index e6d0610f4672..2309e67c01a5 100644 --- a/contrib/bmake/unit-tests/deptgt-delete_on_error.mk +++ b/contrib/bmake/unit-tests/deptgt-delete_on_error.mk @@ -1,4 +1,4 @@ - # $NetBSD: deptgt-delete_on_error.mk,v 1.3 2020/10/25 21:31:00 rillig Exp $ +# $NetBSD: deptgt-delete_on_error.mk,v 1.4 2023/06/01 20:56:35 rillig Exp $ # # Tests for the special target .DELETE_ON_ERROR in dependency declarations, # which controls whether the target is deleted if a shell command fails or diff --git a/contrib/bmake/unit-tests/deptgt-end-fail-indirect.mk b/contrib/bmake/unit-tests/deptgt-end-fail-indirect.mk index 29346b8321fe..dc921bcfda2c 100644 --- a/contrib/bmake/unit-tests/deptgt-end-fail-indirect.mk +++ b/contrib/bmake/unit-tests/deptgt-end-fail-indirect.mk @@ -1,10 +1,10 @@ -# $NetBSD: deptgt-end-fail-indirect.mk,v 1.2 2020/12/06 21:22:04 rillig Exp $ +# $NetBSD: deptgt-end-fail-indirect.mk,v 1.3 2022/05/07 08:01:20 rillig Exp $ # # Tests for an error in a dependency of the .END node. # # Before 2020-11-25, an error in the .END target did not print the "Stop." # and exited with status 0. The cause for this was a missing condition in -# Compat_Run in the handling of the .END node. +# Compat_MakeAll in the handling of the .END node. all: : $@ diff --git a/contrib/bmake/unit-tests/deptgt-end-fail.mk b/contrib/bmake/unit-tests/deptgt-end-fail.mk index 57cdc7da8679..c77127f26091 100644 --- a/contrib/bmake/unit-tests/deptgt-end-fail.mk +++ b/contrib/bmake/unit-tests/deptgt-end-fail.mk @@ -1,11 +1,11 @@ -# $NetBSD: deptgt-end-fail.mk,v 1.6 2020/12/07 01:04:07 rillig Exp $ +# $NetBSD: deptgt-end-fail.mk,v 1.7 2022/05/07 08:01:20 rillig Exp $ # # Tests for an errors in the main target, its dependencies, # the .END node and its dependencies. # # Before 2020-11-25, an error in the .END target did not print the "Stop.", # even though this was intended. The cause for this was a missing condition -# in Compat_Run, in the code handling the .END node. +# in Compat_MakeAll, in the code handling the .END node. test: .PHONY diff --git a/contrib/bmake/unit-tests/deptgt-makeflags.exp b/contrib/bmake/unit-tests/deptgt-makeflags.exp index ac8ffc83470d..ea29f76ad464 100644 --- a/contrib/bmake/unit-tests/deptgt-makeflags.exp +++ b/contrib/bmake/unit-tests/deptgt-makeflags.exp @@ -1,4 +1,4 @@ -Global: delete DOLLAR (not found) +Global: ignoring delete 'DOLLAR' as it is not found Command: DOLLAR = $$$$ Global: .MAKEOVERRIDES = VAR DOLLAR CondParser_Eval: ${DOLLAR} != "\$\$" diff --git a/contrib/bmake/unit-tests/deptgt-makeflags.mk b/contrib/bmake/unit-tests/deptgt-makeflags.mk index 26f3f5794354..2f8b00743e3f 100644 --- a/contrib/bmake/unit-tests/deptgt-makeflags.mk +++ b/contrib/bmake/unit-tests/deptgt-makeflags.mk @@ -1,4 +1,4 @@ -# $NetBSD: deptgt-makeflags.mk,v 1.7 2021/11/29 00:17:10 rillig Exp $ +# $NetBSD: deptgt-makeflags.mk,v 1.9 2023/11/19 22:32:44 rillig Exp $ # # Tests for the special target .MAKEFLAGS in dependency declarations, # which adds command line options later, at parse time. @@ -65,9 +65,9 @@ .endif # Next try at defining another newline variable. Since whitespace around the -# variable value is trimmed, two empty variable expressions ${:U} surround the +# variable value is trimmed, two empty expressions ${:U} surround the # literal newline now. This prevents the newline from being skipped during -# parsing. The ':=' assignment operator expands the empty variable +# parsing. The ':=' assignment operator expands the empty # expressions, leaving only the newline as the variable value. # # This is one of the very few ways (maybe even the only one) to inject literal diff --git a/contrib/bmake/unit-tests/deptgt-posix.mk b/contrib/bmake/unit-tests/deptgt-posix.mk index ae41af15ffec..bf29dbfbd627 100644 --- a/contrib/bmake/unit-tests/deptgt-posix.mk +++ b/contrib/bmake/unit-tests/deptgt-posix.mk @@ -1,16 +1,22 @@ -# $NetBSD: deptgt-posix.mk,v 1.2 2022/04/18 15:59:39 sjg Exp $ +# $NetBSD: deptgt-posix.mk,v 1.4 2022/05/07 21:24:52 rillig Exp $ # # Tests for the special target '.POSIX', which enables POSIX mode. # -# As of 2022-04-18, this only means that the variable '%POSIX' is defined and -# that the variables and rules specified by POSIX replace the default ones. -# This is done by loading <posix.mk>, if available. That file is not included -# in NetBSD, but only in the bmake distribution. As of 2022-04-18, POSIX -# support is not complete. +# As of 2022-04-18, when parsing the dependency line '.POSIX', the variable +# '%POSIX' is defined and <posix.mk> is included, if it exists. Other than +# that, POSIX support is still incomplete, the exact set of supported features +# needs to be cross-checked with the POSIX specification. # -# Implementation node: this test needs to be isolated from the usual test -# to prevent unit-tests/posix.mk from interfering with the posix.mk from the -# system directory that this test uses. +# At the point of '.POSIX:', <sys.mk> has been loaded already, unless the +# option '-r' was given. This means that an implementation of <posix.mk> must +# work both with and without the system rules from <sys.mk> being in effect. +# +# Implementation note: this test needs to run isolated from the usual tests +# directory to prevent unit-tests/posix.mk from interfering with the posix.mk +# from the system directory that this test uses; since at least 1997, the +# directive '.include <file>' has been looking in the current directory first +# before searching the file in the system search path, as described in +# https://gnats.netbsd.org/15163. # # See also: # https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html @@ -99,7 +105,8 @@ in-first-line: .PHONY set-up-sysdir check-is-posix run '.POSIX:' # The only allowed lines before switching to POSIX mode are comment lines. -# POSIX defines that empty and blank lines are called comment lines as well. +# POSIX defines comment lines as "blank lines, empty lines, and lines with +# <number-sign> ('#') as the first character". all: after-comment-lines after-comment-lines: .PHONY set-up-sysdir check-is-posix run printf '%s\n' > ${MAIN_MK} \ diff --git a/contrib/bmake/unit-tests/deptgt.exp b/contrib/bmake/unit-tests/deptgt.exp index 0a27f562293d..00d312685de9 100644 --- a/contrib/bmake/unit-tests/deptgt.exp +++ b/contrib/bmake/unit-tests/deptgt.exp @@ -1,17 +1,17 @@ -make: "deptgt.mk" line 10: warning: Extra target ignored -make: "deptgt.mk" line 28: Unassociated shell command ": command3 # parse error, since targets == NULL" -Parsing line 34: ${:U}: empty-source -ParseDependency(: empty-source) -Parsing line 35: : command for empty targets list -Parsing line 36: : empty-source +make: "deptgt.mk" line 11: warning: Extra target '.PHONY' ignored +make: "deptgt.mk" line 30: Unassociated shell command ": command3 # parse error, since targets == NULL" +Parsing line 36: ${:U}: empty-source ParseDependency(: empty-source) Parsing line 37: : command for empty targets list -Parsing line 38: .MAKEFLAGS: -d0 +Parsing line 38: : empty-source +ParseDependency(: empty-source) +Parsing line 39: : command for empty targets list +Parsing line 40: .MAKEFLAGS: -d0 ParseDependency(.MAKEFLAGS: -d0) -make: "deptgt.mk" line 46: Unknown modifier "Z" -make: "deptgt.mk" line 49: warning: Extra target ignored -make: "deptgt.mk" line 52: warning: Extra target (ordinary) ignored -make: "deptgt.mk" line 55: warning: Special and mundane targets don't mix. Mundane ones ignored +make: "deptgt.mk" line 49: Unknown modifier "Z" +make: "deptgt.mk" line 52: warning: Extra target 'ordinary' ignored +make: "deptgt.mk" line 55: warning: Extra target (ordinary) ignored +make: "deptgt.mk" line 58: warning: Special and mundane targets don't mix. Mundane ones ignored make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/deptgt.mk b/contrib/bmake/unit-tests/deptgt.mk index 044644dcbd66..30b8399191bd 100644 --- a/contrib/bmake/unit-tests/deptgt.mk +++ b/contrib/bmake/unit-tests/deptgt.mk @@ -1,4 +1,4 @@ -# $NetBSD: deptgt.mk,v 1.12 2021/12/13 23:38:54 rillig Exp $ +# $NetBSD: deptgt.mk,v 1.16 2023/12/17 09:44:00 rillig Exp $ # # Tests for special targets like .BEGIN or .SUFFIXES in dependency # declarations. @@ -7,6 +7,7 @@ # Just in case anyone tries to compile several special targets in a single # dependency line: That doesn't work, and make immediately rejects it. +# expect+1: warning: Extra target '.PHONY' ignored .SUFFIXES .PHONY: .c.o # The following lines demonstrate how 'targets' is set and reset during @@ -25,10 +26,11 @@ target1 target2: sources # targets := [target1, target2] : command1 # targets == [target1, target2] : command2 # targets == [target1, target2] VAR=value # targets := NULL +# expect+1: Unassociated shell command ": command3 # parse error, since targets == NULL" : command3 # parse error, since targets == NULL # In a dependency declaration, the list of targets can be empty. -# It doesn't matter whether the empty string is generated by a variable +# It doesn't matter whether the empty string is generated by an # expression or whether it is just omitted. .MAKEFLAGS: -dp ${:U}: empty-source @@ -43,15 +45,16 @@ ${:U}: empty-source # expansion would be to use the variable modifier '::=' to modify the # targets. This in turn would be such an extreme and unreliable edge case # that nobody uses it. +# expect+1: Unknown modifier "Z" $$$$$$$${:U:Z}: -# expect+1: warning: Extra target ignored +# expect+1: warning: Extra target 'ordinary' ignored .END ordinary: # expect+1: warning: Extra target (ordinary) ignored .PATH ordinary: -# expect+1: Special and mundane targets don't mix. Mundane ones ignored +# expect+1: warning: Special and mundane targets don't mix. Mundane ones ignored ordinary .PATH: all: diff --git a/contrib/bmake/unit-tests/dir.mk b/contrib/bmake/unit-tests/dir.mk index 36fe2baf978c..956285393489 100644 --- a/contrib/bmake/unit-tests/dir.mk +++ b/contrib/bmake/unit-tests/dir.mk @@ -1,8 +1,10 @@ -# $NetBSD: dir.mk,v 1.9 2021/01/23 10:48:49 rillig Exp $ +# $NetBSD: dir.mk,v 1.11 2023/12/19 19:33:40 rillig Exp $ # # Tests for dir.c. -.MAKEFLAGS: -m / # hide /usr/share/mk from the debug log +# hide /usr/share/mk from the debug log +.SYSPATH: +.SYSPATH: / # Dependency lines may use braces for expansion. # See DirExpandCurly for the implementation. @@ -65,7 +67,7 @@ fetch fetch-post extract extract-post: # The expansions may have duplicates. # When the source of the dependency line is expanded later, each of the -# expanded words will be the same. +# expanded words resolves to the same node. all: dup-{1,1,1,1,1,1,1} dup-1: diff --git a/contrib/bmake/unit-tests/directive-dinclude.exp b/contrib/bmake/unit-tests/directive-dinclude.exp index 5ea0dabb3c7e..8f71e42c0515 100755 --- a/contrib/bmake/unit-tests/directive-dinclude.exp +++ b/contrib/bmake/unit-tests/directive-dinclude.exp @@ -1,4 +1,4 @@ -make: "directive-dinclude-error.inc" line 1: Invalid line type +make: "directive-dinclude-error.inc" line 1: Invalid line 'syntax error' make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/directive-dinclude.mk b/contrib/bmake/unit-tests/directive-dinclude.mk index d968924a6a99..7fccff413cd6 100755 --- a/contrib/bmake/unit-tests/directive-dinclude.mk +++ b/contrib/bmake/unit-tests/directive-dinclude.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-dinclude.mk,v 1.2 2022/01/23 21:48:59 rillig Exp $ +# $NetBSD: directive-dinclude.mk,v 1.3 2023/08/19 10:52:13 rillig Exp $ # # Tests for the .dinclude directive, which includes another file, # silently skipping it if it cannot be opened. This is primarily used for @@ -16,7 +16,7 @@ .dinclude "${MAKEFILE}/subdir" # Errors that are not related to opening the file are still reported. -# expect: make: "directive-dinclude-error.inc" line 1: Invalid line type +# expect: make: "directive-dinclude-error.inc" line 1: Invalid line 'syntax error' _!= echo 'syntax error' > directive-dinclude-error.inc .dinclude "${.CURDIR}/directive-dinclude-error.inc" _!= rm directive-dinclude-error.inc diff --git a/contrib/bmake/unit-tests/directive-elif.exp b/contrib/bmake/unit-tests/directive-elif.exp index 6856494023d7..15dd6bf1430b 100644 --- a/contrib/bmake/unit-tests/directive-elif.exp +++ b/contrib/bmake/unit-tests/directive-elif.exp @@ -1,21 +1,21 @@ -make: "directive-elif.mk" line 47: Unknown directive "elsif" -make: "directive-elif.mk" line 52: This branch is taken. -make: "directive-elif.mk" line 60: Unknown directive "elsif" -make: "directive-elif.mk" line 63: This branch is taken. -make: "directive-elif.mk" line 69: This branch is taken. -make: "directive-elif.mk" line 89: Unknown directive "elsif" -make: "directive-elif.mk" line 90: This misspelling is detected. -make: "directive-elif.mk" line 91: This branch is taken because of the .else. -make: "directive-elif.mk" line 109: What happens on misspelling in a skipped branch? -make: "directive-elif.mk" line 119: else -make: "directive-elif.mk" line 122: What happens on misspelling in a taken branch? -make: "directive-elif.mk" line 124: 1-then -make: "directive-elif.mk" line 125: Unknown directive "elsif" -make: "directive-elif.mk" line 126: 1-elsif -make: "directive-elif.mk" line 127: Unknown directive "elsif" -make: "directive-elif.mk" line 128: 2-elsif -make: "directive-elif.mk" line 134: if-less elif -make: "directive-elif.mk" line 139: warning: extra elif +make: "directive-elif.mk" line 48: Unknown directive "elsif" +make: "directive-elif.mk" line 54: This branch is taken. +make: "directive-elif.mk" line 62: Unknown directive "elsif" +make: "directive-elif.mk" line 66: This branch is taken. +make: "directive-elif.mk" line 73: This branch is taken. +make: "directive-elif.mk" line 94: Unknown directive "elsif" +make: "directive-elif.mk" line 96: This misspelling is detected. +make: "directive-elif.mk" line 98: This branch is taken because of the .else. +make: "directive-elif.mk" line 117: What happens on misspelling in a skipped branch? +make: "directive-elif.mk" line 128: else +make: "directive-elif.mk" line 132: What happens on misspelling in a taken branch? +make: "directive-elif.mk" line 135: 1-then +make: "directive-elif.mk" line 137: Unknown directive "elsif" +make: "directive-elif.mk" line 139: 1-elsif +make: "directive-elif.mk" line 141: Unknown directive "elsif" +make: "directive-elif.mk" line 143: 2-elsif +make: "directive-elif.mk" line 149: if-less elif +make: "directive-elif.mk" line 154: warning: extra elif make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/directive-elif.mk b/contrib/bmake/unit-tests/directive-elif.mk index e7b89beec4e9..d6500cc1e872 100644 --- a/contrib/bmake/unit-tests/directive-elif.mk +++ b/contrib/bmake/unit-tests/directive-elif.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-elif.mk,v 1.7 2020/12/19 19:49:01 rillig Exp $ +# $NetBSD: directive-elif.mk,v 1.8 2023/06/01 20:56:35 rillig Exp $ # # Tests for the .elif directive. # @@ -44,28 +44,32 @@ # Misspelling '.elsif' below an .if branch that is taken. .if 1 # This misspelling is in an active branch and is therefore detected. +# expect+1: Unknown directive "elsif" .elsif 0 # The only thing that make detects here is a misspelled directive, make # doesn't recognize that it was meant to be a conditional directive. # Therefore the branch continues here, even though the '.elsif' condition # evaluates to false. +# expect+1: This branch is taken. . info This branch is taken. .endif # Misspelling '.elsif' below an .if branch that is taken. .if 1 -# As of 2020-12-19, the misspelling is in an active branch and is therefore -# detected. +# The misspelling is in an active branch and is therefore detected. +# expect+1: Unknown directive "elsif" .elsif 1 # Since both conditions evaluate to true, this branch is taken no matter # whether make detects a misspelling or not. +# expect+1: This branch is taken. . info This branch is taken. .endif # Misspelling '.elsif' in a skipped branch below a branch that was taken. .if 1 +# expect+1: This branch is taken. . info This branch is taken. .elif 0 . info This branch is not taken. @@ -86,8 +90,11 @@ # Misspelling '.elsif' in an .else branch that is taken. .if 0 .else +# expect+1: Unknown directive "elsif" .elsif 1 +# expect+1: This misspelling is detected. . info This misspelling is detected. +# expect+1: This branch is taken because of the .else. . info This branch is taken because of the .else. .endif @@ -106,6 +113,7 @@ .endif +# expect+1: What happens on misspelling in a skipped branch? .info What happens on misspelling in a skipped branch? .if 0 . info 0-then @@ -116,26 +124,33 @@ . info XXX: This misspelling is not detected. . info 2-elsif .else +# expect+1: else . info else .endif +# expect+1: What happens on misspelling in a taken branch? .info What happens on misspelling in a taken branch? .if 1 +# expect+1: 1-then . info 1-then +# expect+1: Unknown directive "elsif" .elsif 1 +# expect+1: 1-elsif . info 1-elsif +# expect+1: Unknown directive "elsif" .elsif 2 +# expect+1: 2-elsif . info 2-elsif .else . info else .endif -# Expect: "if-less elif" +# expect+1: if-less elif .elif 0 .if 1 .else -# Expect: "warning: extra elif" +# expect+1: warning: extra elif .elif .endif diff --git a/contrib/bmake/unit-tests/directive-else.exp b/contrib/bmake/unit-tests/directive-else.exp index 17d5571ba74b..992b60e9308b 100644 --- a/contrib/bmake/unit-tests/directive-else.exp +++ b/contrib/bmake/unit-tests/directive-else.exp @@ -1,11 +1,11 @@ make: "directive-else.mk" line 14: The .else directive does not take arguments -make: "directive-else.mk" line 15: ok -make: "directive-else.mk" line 19: ok -make: "directive-else.mk" line 21: The .else directive does not take arguments -make: "directive-else.mk" line 26: if-less else -make: "directive-else.mk" line 32: ok -make: "directive-else.mk" line 33: warning: extra else -make: "directive-else.mk" line 45: The .else directive does not take arguments +make: "directive-else.mk" line 16: ok +make: "directive-else.mk" line 21: ok +make: "directive-else.mk" line 23: The .else directive does not take arguments +make: "directive-else.mk" line 29: if-less else +make: "directive-else.mk" line 36: ok +make: "directive-else.mk" line 38: warning: extra else +make: "directive-else.mk" line 51: The .else directive does not take arguments make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/directive-else.mk b/contrib/bmake/unit-tests/directive-else.mk index 794057110ef7..cda671907217 100644 --- a/contrib/bmake/unit-tests/directive-else.mk +++ b/contrib/bmake/unit-tests/directive-else.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-else.mk,v 1.7 2020/12/14 22:17:11 rillig Exp $ +# $NetBSD: directive-else.mk,v 1.9 2023/11/19 21:47:52 rillig Exp $ # # Tests for the .else directive. # @@ -10,26 +10,31 @@ .if 0 . warning must not be reached -# The .else directive does not take any arguments. +# expect+1: The .else directive does not take arguments .else 123 +# expect+1: ok . info ok .endif .if 1 +# expect+1: ok . info ok -# The .else directive does not take any arguments. +# expect+1: The .else directive does not take arguments .else 123 . warning must not be reached .endif # An .else without a corresponding .if is an error. +# expect+1: if-less else .else # Accidental extra .else directives are detected too. .if 0 . warning must not be reached .else +# expect+1: ok . info ok +# expect+1: warning: extra else .else . info After an extra .else, everything is skipped. .endif @@ -40,8 +45,9 @@ .else # comment .endif -# A variable expression does count as an argument, even if it is empty. +# An expression does count as an argument, even if it is empty. .if 0 +# expect+1: The .else directive does not take arguments .else ${:U} .endif diff --git a/contrib/bmake/unit-tests/directive-endfor.exp b/contrib/bmake/unit-tests/directive-endfor.exp index 7e243a8f67e6..8b77c0b31307 100644 --- a/contrib/bmake/unit-tests/directive-endfor.exp +++ b/contrib/bmake/unit-tests/directive-endfor.exp @@ -1,4 +1,4 @@ -make: "directive-endfor.mk" line 9: for-less endfor +make: "directive-endfor.mk" line 10: for-less endfor make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/directive-endfor.mk b/contrib/bmake/unit-tests/directive-endfor.mk index b0c37f388504..93119156fb89 100644 --- a/contrib/bmake/unit-tests/directive-endfor.mk +++ b/contrib/bmake/unit-tests/directive-endfor.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-endfor.mk,v 1.1 2020/12/30 14:50:08 rillig Exp $ +# $NetBSD: directive-endfor.mk,v 1.2 2023/06/01 20:56:35 rillig Exp $ # # Test for the directive .endfor, which ends a .for loop. # @@ -6,4 +6,5 @@ # directive-for.mk # An .endfor without a corresponding .for is a parse error. +# expect+1: for-less endfor .endfor diff --git a/contrib/bmake/unit-tests/directive-endif.exp b/contrib/bmake/unit-tests/directive-endif.exp index 0de1ecf0bf25..c88cc97c44c5 100644 --- a/contrib/bmake/unit-tests/directive-endif.exp +++ b/contrib/bmake/unit-tests/directive-endif.exp @@ -1,8 +1,8 @@ -make: "directive-endif.mk" line 18: The .endif directive does not take arguments -make: "directive-endif.mk" line 23: The .endif directive does not take arguments -make: "directive-endif.mk" line 33: The .endif directive does not take arguments +make: "directive-endif.mk" line 16: The .endif directive does not take arguments +make: "directive-endif.mk" line 21: The .endif directive does not take arguments +make: "directive-endif.mk" line 32: The .endif directive does not take arguments make: "directive-endif.mk" line 39: The .endif directive does not take arguments -make: "directive-endif.mk" line 45: Unknown directive "endifx" +make: "directive-endif.mk" line 44: Unknown directive "endifx" make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/directive-endif.mk b/contrib/bmake/unit-tests/directive-endif.mk index 10dd6ce22ce8..5e01382af5f2 100644 --- a/contrib/bmake/unit-tests/directive-endif.mk +++ b/contrib/bmake/unit-tests/directive-endif.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-endif.mk,v 1.5 2020/12/14 21:56:17 rillig Exp $ +# $NetBSD: directive-endif.mk,v 1.7 2023/06/01 20:56:35 rillig Exp $ # # Tests for the .endif directive. # @@ -8,18 +8,16 @@ # See also: # Cond_EvalLine -# TODO: Implementation - .MAKEFLAGS: -dL -# Error: .endif does not take arguments .if 0 -# Since 2020-12-15, complain about the extra text after the 'endif'. +# Since 2020-12-15: +# expect+1: The .endif directive does not take arguments .endif 0 -# Error: .endif does not take arguments .if 1 -# Since 2020-12-15, complain about the extra text after the 'endif'. +# Since 2020-12-15: +# expect+1: The .endif directive does not take arguments .endif 1 # Comments are allowed after an '.endif'. @@ -29,21 +27,19 @@ # Only whitespace and comments are allowed after an '.endif', but nothing # else. .if 1 -# Since 2020-12-15, complain about the extra text after the 'endif'. +# Since 2020-12-15: +# expect+1: The .endif directive does not take arguments .endif0 # Only whitespace and comments are allowed after an '.endif', but nothing # else. .if 1 -# Since 2020-12-15, complain about the extra text after the 'endif'. +# Since 2020-12-15: +# expect+1: The .endif directive does not take arguments .endif/ -# After an '.endif', no other letter must occur. This 'endifx' is not -# parsed as an 'endif', therefore another '.endif' must follow to balance -# the directives. +# After an '.endif', no other letter must occur. .if 1 +# expect+1: Unknown directive "endifx" .endifx -.endif # to close the preceding '.if' - -all: - @:; +.endif # to close the preceding '.if' diff --git a/contrib/bmake/unit-tests/directive-error.exp b/contrib/bmake/unit-tests/directive-error.exp index bad12326a514..8ce33160e67f 100644 --- a/contrib/bmake/unit-tests/directive-error.exp +++ b/contrib/bmake/unit-tests/directive-error.exp @@ -1,4 +1,4 @@ -make: "directive-error.mk" line 13: message +make: "directive-error.mk" line 14: message make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/directive-error.mk b/contrib/bmake/unit-tests/directive-error.mk index 135db2159dd2..f35a9da3a018 100644 --- a/contrib/bmake/unit-tests/directive-error.mk +++ b/contrib/bmake/unit-tests/directive-error.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-error.mk,v 1.5 2021/01/27 00:02:38 rillig Exp $ +# $NetBSD: directive-error.mk,v 1.6 2023/06/01 20:56:35 rillig Exp $ # # Tests for the .error directive, which prints an error message and exits # immediately, unlike other "fatal" parse errors, which continue to parse @@ -10,4 +10,5 @@ # Before parse.c 1.532 from 2021-01-27, the ".error" issued an irrelevant # message saying "parsing warnings being treated as errors". .MAKEFLAGS: -W +# expect+1: message .error message diff --git a/contrib/bmake/unit-tests/directive-export-gmake.exp b/contrib/bmake/unit-tests/directive-export-gmake.exp index 39a9383953dd..c37d3b2d8591 100644 --- a/contrib/bmake/unit-tests/directive-export-gmake.exp +++ b/contrib/bmake/unit-tests/directive-export-gmake.exp @@ -1 +1,6 @@ -exit status 0 +make: "directive-export-gmake.mk" line 71: Invalid line 'export VAR=${:U1}', expanded to 'export VAR=1' +make: "directive-export-gmake.mk" line 85: 16:00:00 +make: "directive-export-gmake.mk" line 92: Variable/Value missing from "export" +make: Fatal errors encountered -- cannot continue +make: stopped in unit-tests +exit status 1 diff --git a/contrib/bmake/unit-tests/directive-export-gmake.mk b/contrib/bmake/unit-tests/directive-export-gmake.mk index d94cd9debf64..de79470bf305 100644 --- a/contrib/bmake/unit-tests/directive-export-gmake.mk +++ b/contrib/bmake/unit-tests/directive-export-gmake.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-export-gmake.mk,v 1.3 2020/11/17 20:16:44 rillig Exp $ +# $NetBSD: directive-export-gmake.mk,v 1.9 2023/12/17 09:44:00 rillig Exp $ # # Tests for the export directive (without leading dot), as in GNU make. @@ -60,5 +60,47 @@ export VAR=an ${UNDEF} variable . error .endif -all: - @:; + +# The body of the .for loop expands to 'export VAR=${:U1}', and the 'export' +# directive is only recognized if the line does not contain a ':', to allow +# 'export' to be a regular target. +.for value in 1 +# XXX: The ':' in this line is inside an expression and should thus not be +# interpreted as a dependency operator. +# expect+1: Invalid line 'export VAR=${:U1}', expanded to 'export VAR=1' +export VAR=${value} +.endfor + + +# The 'export' directive expands expressions, but the expressions must not +# contain a ':', due to the overly strict parser. The indirect expressions +# may contain a ':', though. +# +# As a side effect, this test demonstrates that the 'export' directive exports +# the environment variable immediately, other than the '.export' directive, +# which defers that action if the variable value contains a '$'. +INDIRECT_TZ= ${:UAmerica/Los_Angeles} +export TZ=${INDIRECT_TZ} +# expect+1: 16:00:00 +.info ${%T:L:localtime=86400} + + +# The '=' must be present in the unexpanded line, it cannot be generated by +# an expression. +EQ= = +# expect+1: Variable/Value missing from "export" +export EQ_VAR${EQ}eq-value +.if ${:!env!:MEQ_VAR=*} +. error +.endif + + +# The variable name must be given directly, it is not expanded. The name of +# the exported variable thus starts with a '$', and that name may be filtered +# out by the platform. +INDIRECT_NAME= I_NAME +INDIRECT_VALUE= indirect value +export ${INDIRECT_NAME}=${INDIRECT_VALUE} +.if ${:!env!:MI_NAME=*} +. error +.endif diff --git a/contrib/bmake/unit-tests/directive-export.exp b/contrib/bmake/unit-tests/directive-export.exp index 39a9383953dd..774a814570e3 100644 --- a/contrib/bmake/unit-tests/directive-export.exp +++ b/contrib/bmake/unit-tests/directive-export.exp @@ -1 +1,4 @@ +make: "directive-export.mk" line 56: 00:00:00 +make: "directive-export.mk" line 61: 00:00:00 +make: "directive-export.mk" line 64: 16:00:00 exit status 0 diff --git a/contrib/bmake/unit-tests/directive-export.mk b/contrib/bmake/unit-tests/directive-export.mk index 942d4b371bbd..08109814bcfd 100644 --- a/contrib/bmake/unit-tests/directive-export.mk +++ b/contrib/bmake/unit-tests/directive-export.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-export.mk,v 1.8 2021/02/16 19:01:18 rillig Exp $ +# $NetBSD: directive-export.mk,v 1.10 2023/11/19 09:45:19 rillig Exp $ # # Tests for the .export directive. # @@ -35,10 +35,33 @@ VAR= value $$ ${INDIRECT} .export ${:U} -# Trigger the "This isn't going to end well" in ExportVarEnv. +# Before a child process is started, whether for the '!=' assignment operator +# or for the ':sh' modifier, all variables that were marked for being exported +# are expanded and then exported. If expanding such a variable requires +# running a child command, the marked-as-exported variables would need to be +# exported first, ending in an endless loop. To avoid this endless loop, +# don't export the variables while preparing a child process, see +# ExportVarEnv. EMPTY_SHELL= ${:sh} .export EMPTY_SHELL # only marked for export at this point _!= :;: # Force the variable to be actually exported. +# If the '.export' directive exports a variable whose value contains a '$', +# the actual export action is deferred until a subprocess is started, assuming +# that only subprocesses access the environment variables. The ':localtime' +# modifier depends on the 'TZ' environment variable, without any subprocess. +export TZ=${UTC} +# expect+1: 00:00:00 +.info ${%T:L:localtime=86400} +INDIRECT_TZ= ${:UAmerica/Los_Angeles} +TZ= ${INDIRECT_TZ} +.export TZ +# expect+1: 00:00:00 +.info ${%T:L:localtime=86400} +_!= echo 'force exporting the environment variables' +# expect+1: 16:00:00 +.info ${%T:L:localtime=86400} + + all: diff --git a/contrib/bmake/unit-tests/directive-for-break.exp b/contrib/bmake/unit-tests/directive-for-break.exp new file mode 100644 index 000000000000..64941448141c --- /dev/null +++ b/contrib/bmake/unit-tests/directive-for-break.exp @@ -0,0 +1,5 @@ +make: "directive-for-break.mk" line 45: break outside of for loop +make: "directive-for-break.mk" line 65: The .break directive does not take arguments +make: Fatal errors encountered -- cannot continue +make: stopped in unit-tests +exit status 1 diff --git a/contrib/bmake/unit-tests/directive-for-break.mk b/contrib/bmake/unit-tests/directive-for-break.mk new file mode 100644 index 000000000000..d9290d38c215 --- /dev/null +++ b/contrib/bmake/unit-tests/directive-for-break.mk @@ -0,0 +1,66 @@ +# $NetBSD: directive-for-break.mk,v 1.5 2023/06/01 20:56:35 rillig Exp $ +# +# Tests for .break in .for loops, which immediately terminates processing of +# the surrounding .for loop. + + +# .break terminates the loop early. +# This is usually done within a conditional. +.for i in 1 2 3 4 5 6 7 8 +. if $i == 3 +I= $i +. break +I= unreached +. endif +.endfor +.if $I != "3" +. error +.endif + + +# The .break only breaks out of the immediately surrounding .for loop, any +# other .for loops are continued normally. +.for outer in o1 o2 o3 +. for inner in i1 i2 i3 +. if ${outer} == o2 && ${inner} == i2 +. break +. endif +COMBINED+= ${outer}-${inner} +. endfor +.endfor +# Only o2-i2 and o2-i3 are missing. +.if ${COMBINED} != "o1-i1 o1-i2 o1-i3 o2-i1 o3-i1 o3-i2 o3-i3" +. error +.endif + + +# A .break outside the context of a .for loop is an error. +.if $I == 0 +# No parse error, even though the .break occurs outside a .for loop, since +# lines from inactive branches are only parsed as far as necessary to see +# whether they belong to an .if/.elif/.else/.endif chain. +. break +.else +# expect+1: break outside of for loop +. break +.endif + + +# Since cond.c 1.335 from 2022-09-02 and before cond.c 1.338 from 2022-09-23, +# the following paragraph generated the wrong error message '4294967294 open +# conditionals'. +.if 1 +. if 2 +. for var in value +. if 3 +. break +. endif +. endfor +. endif +.endif + + +.for i in 1 +# expect+1: The .break directive does not take arguments +. break 1 +.endfor diff --git a/contrib/bmake/unit-tests/directive-for-empty.exp b/contrib/bmake/unit-tests/directive-for-empty.exp new file mode 100644 index 000000000000..5cc3ac846b36 --- /dev/null +++ b/contrib/bmake/unit-tests/directive-for-empty.exp @@ -0,0 +1,27 @@ +make: "directive-for-empty.mk" line 22: 2 +make: "directive-for-empty.mk" line 38: Missing argument for ".error" +make: "directive-for-empty.mk" line 38: Missing argument for ".error" +make: "directive-for-empty.mk" line 38: Missing argument for ".error" +For: end for 1 +For: loop body with i = value: +# The identifier 'empty' can only be used in conditions such as .if, .ifdef or +# .elif. In other lines the string 'empty(' must be preserved. +CPPFLAGS+= -Dmessage="empty(i)" +# There may be whitespace between 'empty' and '('. +.if ! empty (i) +. error +.endif +# Even in conditions, the string 'empty(' is not always a function call, it +# can occur in a string literal as well. +.if "empty\(i)" != "empty(i)" +. error +.endif +# In comments like 'empty(i)', the text must be preserved as well. +# +# Conditions, including function calls to 'empty', can not only occur in +# condition directives, they can also occur in the modifier ':?', see +# varmod-ifelse.mk. +CPPFLAGS+= -Dmacro="${empty(i):?empty:not-empty}" +make: Fatal errors encountered -- cannot continue +make: stopped in unit-tests +exit status 1 diff --git a/contrib/bmake/unit-tests/directive-for-empty.mk b/contrib/bmake/unit-tests/directive-for-empty.mk new file mode 100644 index 000000000000..1c4cb0f1ad27 --- /dev/null +++ b/contrib/bmake/unit-tests/directive-for-empty.mk @@ -0,0 +1,124 @@ +# $NetBSD: directive-for-empty.mk,v 1.3 2023/11/19 21:47:52 rillig Exp $ +# +# Tests for .for loops containing conditions of the form 'empty(var:...)'. +# +# When a .for loop is expanded, expressions in the body of the loop +# are replaced with expressions containing the variable values. This +# replacement is a bit naive but covers most of the practical cases. The one +# popular exception is the condition 'empty(var:Modifiers)', which does not +# look like an expression and is thus not replaced. +# +# See also: +# https://gnats.netbsd.org/43821 + + +# In the body of the .for loop, the expression '${i:M*2*}' is replaced with +# '${:U11:M*2*}', '${:U12:M*2*}', '${:U13:M*2*}', one after another. This +# replacement creates the impression that .for variables were real variables, +# when in fact they aren't. +.for i in 11 12 13 +. if ${i:M*2*} +# expect+1: 2 +.info 2 +. endif +.endfor + + +# In conditions, the function call to 'empty' does not look like an +# expression, therefore it is not replaced. Since there is no global variable +# named 'i', this expression makes for a leaky abstraction. If the .for +# variables were real variables, calling 'empty' would work on them as well. +.for i in 11 12 13 +# Asking for an empty iteration variable does not make sense as the .for loop +# splits the iteration items into words, and such a word cannot be empty. +. if empty(i) +# expect+3: Missing argument for ".error" +# expect+2: Missing argument for ".error" +# expect+1: Missing argument for ".error" +. error # due to the leaky abstraction +. endif +# The typical way of using 'empty' with variables from .for loops is pattern +# matching using the modifiers ':M' or ':N'. +. if !empty(i:M*2*) +. if ${i} != "12" +. error +. endif +. endif +.endfor + + +# The idea of replacing every occurrences of 'empty(i' in the body of a .for +# loop would be naive and require many special cases, as there are many cases +# that need to be considered when deciding whether the token 'empty' is a +# function call or not, as demonstrated by the following examples. For +# expressions like '${i:Modifiers}', this is simpler as a single +# dollar almost always starts an expression. For counterexamples and +# edge cases, see directive-for-escape.mk. Adding another such tricky detail +# is out of the question. +.MAKEFLAGS: -df +.for i in value +# The identifier 'empty' can only be used in conditions such as .if, .ifdef or +# .elif. In other lines the string 'empty(' must be preserved. +CPPFLAGS+= -Dmessage="empty(i)" +# There may be whitespace between 'empty' and '('. +.if ! empty (i) +. error +.endif +# Even in conditions, the string 'empty(' is not always a function call, it +# can occur in a string literal as well. +.if "empty\(i)" != "empty(i)" +. error +.endif +# In comments like 'empty(i)', the text must be preserved as well. +# +# Conditions, including function calls to 'empty', can not only occur in +# condition directives, they can also occur in the modifier ':?', see +# varmod-ifelse.mk. +CPPFLAGS+= -Dmacro="${empty(i):?empty:not-empty}" +.endfor +.MAKEFLAGS: -d0 + + +# An idea to work around the above problems is to collect the variables from +# the .for loops in a separate scope. To match the current behavior, there +# has to be one scope per included file. There may be .for loops using the +# same variable name in files that include each other: +# +# outer.mk: .for i in outer +# . info $i # outer +# . include "inner.mk" +# inner.mk: . info $i # (undefined) +# . for i in inner +# . info $i # inner +# . endfor +# . info $i # (undefined) +# outer.mk: . info $i # outer +# .endfor +# +# This might be regarded another leaky abstraction, but it is in fact useful +# that variables from .for loops can only affect expressions in the current +# file. If variables from .for loops were implemented as global variables, +# they might interact between files. +# +# To emulate this exact behavior for the function 'empty', each file in the +# stack of included files needs its own scope that is independent from the +# other files. +# +# Another tricky detail are nested .for loops in a single file that use the +# same variable name. These are generally avoided by developers, as they +# would be difficult to understand for humans as well. Technically, they are +# possible though. Assuming there are two nested .for loops, both using the +# variable 'i'. When the inner .for loop ends, the inner 'i' needs to be +# removed from the scope, which would need to make the outer 'i' visible +# again. This would suggest to use one variable scope per .for loop. +# +# Using a separate scope has the benefit that Var_Parse already allows for +# a custom scope to be passed as parameter. This would have another side +# effect though. There are several modifiers that actually modify variables, +# and these modifications happen in the scope that is passed to Var_Parse. +# This would mean that the combination of a .for variable and the modifiers +# '::=', '::+=', '::?=', '::!=' and ':_' would lead to different behavior than +# before. + +# TODO: Add code that demonstrates the current interaction between variables +# from .for loops and the modifiers mentioned above. diff --git a/contrib/bmake/unit-tests/directive-for-errors.exp b/contrib/bmake/unit-tests/directive-for-errors.exp index da5eee473ec2..115a6af5b069 100644 --- a/contrib/bmake/unit-tests/directive-for-errors.exp +++ b/contrib/bmake/unit-tests/directive-for-errors.exp @@ -1,22 +1,17 @@ -make: "directive-for-errors.mk" line 7: Unknown directive "fori" -make: "directive-for-errors.mk" line 8: warning: -make: "directive-for-errors.mk" line 9: for-less endfor -make: "directive-for-errors.mk" line 19: Unknown directive "for" -make: "directive-for-errors.mk" line 20: warning: -make: "directive-for-errors.mk" line 21: for-less endfor -make: "directive-for-errors.mk" line 37: Dollar $ 1 1 and backslash 2 2 2. -make: "directive-for-errors.mk" line 37: Dollar $ 3 3 and backslash 4 4 4. -make: "directive-for-errors.mk" line 43: no iteration variables in for -make: "directive-for-errors.mk" line 47: warning: Should not be reached. -make: "directive-for-errors.mk" line 48: for-less endfor -make: "directive-for-errors.mk" line 53: Wrong number of words (5) in .for substitution list with 3 variables -make: "directive-for-errors.mk" line 64: missing `in' in for -make: "directive-for-errors.mk" line 66: warning: Should not be reached. -make: "directive-for-errors.mk" line 67: for-less endfor -make: "directive-for-errors.mk" line 73: Unknown modifier "Z" -make: "directive-for-errors.mk" line 74: warning: Should not be reached. -make: "directive-for-errors.mk" line 74: warning: Should not be reached. -make: "directive-for-errors.mk" line 74: warning: Should not be reached. +make: "directive-for-errors.mk" line 9: Unknown directive "fori" +make: "directive-for-errors.mk" line 10: warning: <> +make: "directive-for-errors.mk" line 11: for-less endfor +make: "directive-for-errors.mk" line 25: Unknown directive "for" +make: "directive-for-errors.mk" line 26: warning: <> +make: "directive-for-errors.mk" line 27: for-less endfor +make: "directive-for-errors.mk" line 44: invalid character '$' in .for loop variable name +make: "directive-for-errors.mk" line 52: no iteration variables in for +make: "directive-for-errors.mk" line 64: Wrong number of words (5) in .for substitution list with 3 variables +make: "directive-for-errors.mk" line 78: missing `in' in for +make: "directive-for-errors.mk" line 89: Unknown modifier "Z" +make: "directive-for-errors.mk" line 90: warning: Should not be reached. +make: "directive-for-errors.mk" line 90: warning: Should not be reached. +make: "directive-for-errors.mk" line 90: warning: Should not be reached. make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/directive-for-errors.mk b/contrib/bmake/unit-tests/directive-for-errors.mk index 602ecbf32e4e..94362847cdfd 100644 --- a/contrib/bmake/unit-tests/directive-for-errors.mk +++ b/contrib/bmake/unit-tests/directive-for-errors.mk @@ -1,45 +1,54 @@ -# $NetBSD: directive-for-errors.mk,v 1.3 2021/04/04 10:13:09 rillig Exp $ +# $NetBSD: directive-for-errors.mk,v 1.9 2023/12/19 19:33:40 rillig Exp $ # # Tests for error handling in .for loops. + # A .for directive must be followed by whitespace, everything else results # in a parse error. +# expect+1: Unknown directive "fori" .fori in 1 2 3 -. warning ${i} +. warning <${i}> .endfor +# expect-2: warning: <> +# expect-2: for-less endfor + # A slash is not whitespace, therefore this is not parsed as a .for loop. # # XXX: The error message is misleading though. As of 2020-12-31, it says -# "Unknown directive "for"", but that directive is actually known. This is +# 'Unknown directive "for"', but that directive is actually known. This is # because ForEval does not detect the .for loop as such, so parsing # continues in ParseLine > ParseDependencyLine > ParseDependency > # ParseDependencyTargets > ParseErrorNoDependency, and there the directive # name is parsed a bit differently. +# expect+1: Unknown directive "for" .for/i in 1 2 3 -. warning ${i} +. warning <${i}> .endfor +# expect-2: warning: <> +# expect-2: for-less endfor -# As of 2020-12-31, the variable name can be an arbitrary word, it just needs -# to be separated by whitespace. Even '$' and '\' are valid variable names, -# which is not useful in practice. -# -# The '$$' is not replaced with the values '1' or '3' from the .for loop, -# instead it is kept as-is, and when the .info directive expands its argument, -# each '$$' gets replaced with a single '$'. The "long variable expression" -# ${$} gets replaced though, even though this would be a parse error everywhere -# outside a .for loop. + +# Before for.c 1.173 from 2023-05-08, the variable name could be an arbitrary +# word, it only needed to be separated by whitespace. Even '$' and '\' were +# valid variable names, which was not useful in practice. # -# The '\' on the other hand is treated as a normal variable name. +# The '$$' was not replaced with the values '1' or '3' from the .for loop, +# instead it was kept as-is, and when the .info directive expanded its +# argument, each '$$' got replaced with a single '$'. The "long +# expression" ${$} got replaced though, even though this would be a parse +# error everywhere outside a .for loop. ${:U\$}= dollar # see whether the "variable" '$' is local ${:U\\}= backslash # see whether the "variable" '\' is local +# expect+1: invalid character '$' in .for loop variable name .for $ \ in 1 2 3 4 . info Dollar $$ ${$} $($) and backslash $\ ${\} $(\). .endfor # If there are no variables, there is no point in expanding the .for loop -# since this would end up in an endless loop, each time consuming 0 of the -# 3 values. +# since this would end up in an endless loop, consuming 0 of the 3 values in +# each iteration. +# expect+1: no iteration variables in for .for in 1 2 3 # XXX: This should not be reached. It should be skipped, as already done # when the number of values is not a multiple of the number of variables, @@ -47,29 +56,39 @@ ${:U\\}= backslash # see whether the "variable" '\' is local . warning Should not be reached. .endfor + # There are 3 variables and 5 values. These 5 values cannot be split evenly # among the variables, therefore the loop is not expanded at all, it is -# rather skipped. +# skipped instead. +# expect+1: Wrong number of words (5) in .for substitution list with 3 variables .for a b c in 1 2 3 4 5 . warning Should not be reached. .endfor + # The list of values after the 'in' may be empty, no matter if this emptiness -# comes from an empty expansion or even from a syntactically empty line. +# comes from an expanded expression or from a syntactically empty line. .for i in . info Would be reached if there were items to loop over. .endfor + # A missing 'in' should parse the .for loop but skip the body. -.for i : k +# expect+1: missing `in' in for +.for i over k # XXX: As of 2020-12-31, this line is reached once. . warning Should not be reached. .endfor + # A malformed modifier should be detected and skip the body of the loop. # # XXX: As of 2020-12-31, Var_Subst doesn't report any errors, therefore # the loop body is expanded as if no error had happened. +# expect+1: Unknown modifier "Z" .for i in 1 2 ${:U3:Z} 4 . warning Should not be reached. .endfor +# expect-2: warning: Should not be reached. +# expect-3: warning: Should not be reached. +# expect-4: warning: Should not be reached. diff --git a/contrib/bmake/unit-tests/directive-for-escape.exp b/contrib/bmake/unit-tests/directive-for-escape.exp index 5fa4ae1ed877..6c84b7780e84 100644 --- a/contrib/bmake/unit-tests/directive-for-escape.exp +++ b/contrib/bmake/unit-tests/directive-for-escape.exp @@ -1,57 +1,76 @@ For: end for 1 -For: loop body: +For: loop body with chars = !"#$%&'()*+,-./0-9:;<=>?@A-Z[\]_^a-z{|}~: . info ${:U!"#$%&'()*+,-./0-9\:;<=>?@A-Z[\\]_^a-z{|\}~} -make: Unclosed variable expression, expecting '}' for modifier "U!"" of variable "" with value "!"" +make: Unclosed expression, expecting '}' for modifier "U!"" of variable "" with value "!"" make: "directive-for-escape.mk" line 19: !" For: end for 1 -For: loop body: +For: loop body with chars = !"\\#$%&'()*+,-./0-9:;<=>?@A-Z[\]_^a-z{|}~: . info ${:U!"\\\\#$%&'()*+,-./0-9\:;<=>?@A-Z[\\]_^a-z{|\}~} -make: Unclosed variable expression, expecting '}' for modifier "U!"\\\\" of variable "" with value "!"\\" -make: "directive-for-escape.mk" line 29: !"\\ +make: Unclosed expression, expecting '}' for modifier "U!"\\\\" of variable "" with value "!"\\" +make: "directive-for-escape.mk" line 30: !"\\ For: end for 1 -For: loop body: +For: loop body with i = $: . info ${:U\$} -make: "directive-for-escape.mk" line 43: $ -For: loop body: +make: "directive-for-escape.mk" line 45: $ +For: loop body with i = ${V}: . info ${:U${V}} -make: "directive-for-escape.mk" line 43: value -For: loop body: +make: "directive-for-escape.mk" line 45: value +For: loop body with i = ${V:=-with-modifier}: . info ${:U${V:=-with-modifier}} -make: "directive-for-escape.mk" line 43: value-with-modifier -For: loop body: +make: "directive-for-escape.mk" line 45: value-with-modifier +For: loop body with i = $(V): . info ${:U$(V)} -make: "directive-for-escape.mk" line 43: value -For: loop body: +make: "directive-for-escape.mk" line 45: value +For: loop body with i = $(V:=-with-modifier): . info ${:U$(V:=-with-modifier)} -make: "directive-for-escape.mk" line 43: value-with-modifier +make: "directive-for-escape.mk" line 45: value-with-modifier For: end for 1 -For: loop body: +For: loop body with i = $: +. info ${:U\$} +make: "directive-for-escape.mk" line 60: $ +For: loop body with i = ${V}: +. info ${:U${V}} +make: "directive-for-escape.mk" line 60: value +For: loop body with i = ${V:=-with-modifier}: +. info ${:U${V:=-with-modifier}} +make: "directive-for-escape.mk" line 60: value-with-modifier +For: loop body with i = $(V): +. info ${:U$(V)} +make: "directive-for-escape.mk" line 60: value +For: loop body with i = $(V:=-with-modifier): +. info ${:U$(V:=-with-modifier)} +make: "directive-for-escape.mk" line 60: value-with-modifier +For: end for 1 +For: loop body with i = ${UNDEF:U\$\$: +# ${:U\${UNDEF\:U\\$\\$} +For: loop body with i = {{}}: +# ${:U{{\}\}} +For: loop body with i = end}: +# ${:Uend\}} +For: end for 1 +For: loop body with i = ${UNDEF:U\$\$: . info ${:U\${UNDEF\:U\\$\\$} -make: "directive-for-escape.mk" line 72: ${UNDEF:U\backslash$ -For: loop body: +make: "directive-for-escape.mk" line 115: ${UNDEF:U\backslash$ +For: loop body with i = {{}}: . info ${:U{{\}\}} -make: "directive-for-escape.mk" line 72: {{}} -For: loop body: +make: "directive-for-escape.mk" line 115: {{}} +For: loop body with i = end}: . info ${:Uend\}} -make: "directive-for-escape.mk" line 72: end} +make: "directive-for-escape.mk" line 115: end} For: end for 1 -For: loop body: +For: loop body with i = begin<${UNDEF:Ufallback:N{{{}}}}>end: . info ${:Ubegin<${UNDEF:Ufallback:N{{{}}}}>end} -make: "directive-for-escape.mk" line 84: begin<fallback>end +make: "directive-for-escape.mk" line 136: begin<fallback>end For: end for 1 -For: loop body: +For: loop body with i = $: . info ${:U\$} -make: "directive-for-escape.mk" line 92: $ +make: "directive-for-escape.mk" line 145: $ +make: "directive-for-escape.mk" line 154: invalid character ':' in .for loop variable name For: end for 1 -For: loop body: -. info ${NUMBERS} ${:Ureplaced} -make: "directive-for-escape.mk" line 100: one two three replaced +make: "directive-for-escape.mk" line 164: invalid character '}' in .for loop variable name For: end for 1 -For: loop body: -. info ${:Ureplaced} -make: "directive-for-escape.mk" line 110: replaced For: end for 1 -For: loop body: +For: loop body with i = inner: . info . $$i: ${:Uinner} . info . $${i}: ${:Uinner} . info . $${i:M*}: ${:Uinner:M*} @@ -62,85 +81,89 @@ For: loop body: . info . $${i2}: ${i2} . info . $${i,}: ${i,} . info . adjacent: ${:Uinner}${:Uinner}${:Uinner:M*}${:Uinner} -make: "directive-for-escape.mk" line 118: . $i: inner -make: "directive-for-escape.mk" line 119: . ${i}: inner -make: "directive-for-escape.mk" line 120: . ${i:M*}: inner -make: "directive-for-escape.mk" line 121: . $(i): inner -make: "directive-for-escape.mk" line 122: . $(i:M*): inner -make: "directive-for-escape.mk" line 123: . ${i${:U}}: outer -make: "directive-for-escape.mk" line 124: . ${i\}}: inner} -make: "directive-for-escape.mk" line 125: . ${i2}: two -make: "directive-for-escape.mk" line 126: . ${i,}: comma -make: "directive-for-escape.mk" line 127: . adjacent: innerinnerinnerinner -For: end for 1 -For: loop body: -. info eight $$$$$$$$ and no cents. -. info eight ${:Udollar}${:Udollar}${:Udollar}${:Udollar} and no cents. -make: "directive-for-escape.mk" line 135: eight $$$$ and no cents. -make: "directive-for-escape.mk" line 136: eight dollardollardollardollar and no cents. -make: "directive-for-escape.mk" line 145: eight and no cents. -For: end for 1 -make: "directive-for-escape.mk" line 152: newline in .for value -make: "directive-for-escape.mk" line 152: newline in .for value -For: loop body: +make: "directive-for-escape.mk" line 173: . $i: inner +make: "directive-for-escape.mk" line 174: . ${i}: inner +make: "directive-for-escape.mk" line 175: . ${i:M*}: inner +make: "directive-for-escape.mk" line 176: . $(i): inner +make: "directive-for-escape.mk" line 177: . $(i:M*): inner +make: "directive-for-escape.mk" line 178: . ${i${:U}}: outer +make: "directive-for-escape.mk" line 179: . ${i\}}: inner} +make: "directive-for-escape.mk" line 180: . ${i2}: two +make: "directive-for-escape.mk" line 181: . ${i,}: comma +make: "directive-for-escape.mk" line 182: . adjacent: innerinnerinnerinner +make: "directive-for-escape.mk" line 201: invalid character '$' in .for loop variable name +For: end for 1 +make: "directive-for-escape.mk" line 213: eight and no cents. +For: end for 1 +make: "directive-for-escape.mk" line 226: newline in .for value +make: "directive-for-escape.mk" line 226: newline in .for value +For: loop body with i = " +": . info short: ${:U" "} . info long: ${:U" "} -make: "directive-for-escape.mk" line 153: short: " " -make: "directive-for-escape.mk" line 154: long: " " +make: "directive-for-escape.mk" line 227: short: " " +make: "directive-for-escape.mk" line 228: long: " " For: end for 1 -For: loop body: +For: loop body with i = " +": For: end for 1 -Parse_PushInput: .for loop in directive-for-escape.mk, line 167 -make: "directive-for-escape.mk" line 167: newline in .for value - in .for loop from directive-for-escape.mk:167 with i = " +Parse_PushInput: .for loop in directive-for-escape.mk, line 244 +make: "directive-for-escape.mk" line 244: newline in .for value + in .for loop from directive-for-escape.mk:244 with i = " " -For: loop body: +For: loop body with i = " +": : ${:U" "} SetFilenameVars: ${.PARSEDIR} = <some-dir> ${.PARSEFILE} = `directive-for-escape.mk' -Parsing line 168: : ${:U" "} +Parsing line 245: : ${:U" "} ParseDependency(: " ") -ParseEOF: returning to file directive-for-escape.mk, line 170 +ParseEOF: returning to file directive-for-escape.mk, line 247 SetFilenameVars: ${.PARSEDIR} = <some-dir> ${.PARSEFILE} = `directive-for-escape.mk' -Parsing line 170: .MAKEFLAGS: -d0 +Parsing line 247: .MAKEFLAGS: -d0 ParseDependency(.MAKEFLAGS: -d0) For: end for 1 -For: loop body: +For: loop body with i = #: # ${:U#} -For: loop body: +For: loop body with i = \\#: # ${:U\\\\#} For: end for 1 -For: loop body: +For: loop body with i = $: # ${:U\$} -For: loop body: +For: loop body with i = $i: # ${:U$i} -For: loop body: +For: loop body with i = $(i): # ${:U$(i)} -For: loop body: +For: loop body with i = ${i}: # ${:U${i}} -For: loop body: +For: loop body with i = $$: # ${:U$$} -For: loop body: +For: loop body with i = $$$$: # ${:U$$$$} -For: loop body: +For: loop body with i = ${:U\$\$}: # ${:U${:U\$\$}} For: end for 1 -For: loop body: +For: loop body with i = ${.TARGET}: # ${:U${.TARGET}} -For: loop body: +For: loop body with i = ${.TARGET}: # ${:U${.TARGET}} -For: loop body: +For: loop body with i = $${.TARGET}: # ${:U$${.TARGET\}} -For: loop body: +For: loop body with i = $${.TARGET}: # ${:U$${.TARGET\}} For: end for 1 -For: loop body: +For: loop body with i = (((: # ${:U(((} -For: loop body: +For: loop body with i = {{{: # ${:U{{{} -For: loop body: +For: loop body with i = ))): # ${:U)))} -For: loop body: +For: loop body with i = }}}: # ${:U\}\}\}} +For: end for 1 +For: loop body with , = 1: +# $$i $i +# VAR= $$i $i ${a:S,from${:U1}to,} +VAR= $$i $i ${a:S,from${:U1}to,} make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/directive-for-escape.mk b/contrib/bmake/unit-tests/directive-for-escape.mk index 03a7a16b6a7b..16df5b1db4e3 100644 --- a/contrib/bmake/unit-tests/directive-for-escape.mk +++ b/contrib/bmake/unit-tests/directive-for-escape.mk @@ -1,9 +1,8 @@ -# $NetBSD: directive-for-escape.mk,v 1.15 2022/01/27 20:15:14 rillig Exp $ +# $NetBSD: directive-for-escape.mk,v 1.23 2023/11/19 22:32:44 rillig Exp $ # # Test escaping of special characters in the iteration values of a .for loop. # These values get expanded later using the :U variable modifier, and this -# escaping and unescaping must pass all characters and strings effectively -# unmodified. +# escaping and unescaping must pass all characters and strings unmodified. .MAKEFLAGS: -df @@ -12,12 +11,14 @@ # This could be considered a bug. ASCII= !"\#$$%&'()*+,-./0-9:;<=>?@A-Z[\]_^a-z{|}~ + # XXX: As of 2020-12-31, the '#' is not preserved in the expanded body of # the loop. Not only would it need the escaping for the variable modifier # ':U' but also the escaping for the line-end comment. .for chars in ${ASCII} . info ${chars} .endfor +# expect-2: !" # As of 2020-12-31, using 2 backslashes before be '#' would treat the '#' # as comment character. Using 3 backslashes doesn't help either since @@ -28,6 +29,7 @@ ASCII.2020-12-31= !"\\\#$$%&'()*+,-./0-9:;<=>?@A-Z[\]_^a-z{|}~ .for chars in ${ASCII.2020-12-31} . info ${chars} .endfor +# expect-2: !"\\ # Cover the code in ExprLen. # @@ -42,47 +44,98 @@ VALUES= $$ $${V} $${V:=-with-modifier} $$(V) $$(V:=-with-modifier) .for i in ${VALUES} . info $i .endfor +# expect: . info ${:U\$} +# expect-3: $ +# expect: . info ${:U${V}} +# expect-5: value +# expect: . info ${:U${V:=-with-modifier}} +# expect-7: value-with-modifier +# expect: . info ${:U$(V)} +# expect-9: value +# expect: . info ${:U$(V:=-with-modifier)} +# expect-11: value-with-modifier +# +# Providing the loop items directly has the same effect. +.for i in $$ $${V} $${V:=-with-modifier} $$(V) $$(V:=-with-modifier) +. info $i +.endfor +# expect: . info ${:U\$} +# expect-3: $ +# expect: . info ${:U${V}} +# expect-5: value +# expect-6: value-with-modifier +# expect-7: value +# expect-8: value-with-modifier # Try to cover the code for nested '{}' in ExprLen, without success. # -# The value of the variable VALUES is not meant to be a variable expression. +# The value of the variable VALUES is not meant to be an expression. # Instead, it is meant to represent literal text, the only escaping mechanism # being that each '$' is written as '$$'. +VALUES= $${UNDEF:U\$$\$$ {{}} end} # # The .for loop splits ${VALUES} into 3 words, at the space characters, since # the '$$' is an ordinary character and the spaces are not escaped. # Word 1 is '${UNDEF:U\$\$' # Word 2 is '{{}}' # Word 3 is 'end}' -# The first iteration expands the body of the .for loop to: -# expect: . info ${:U\${UNDEF\:U\\$\\$} -# The modifier ':U' unescapes the '\$' to a simple '$'. -# The modifier ':U' unescapes the '\:' to a simple ':'. -# The modifier ':U' unescapes the '\\' to a simple '\'. -# The modifier ':U' resolves the expression '$\' to the word 'backslash', due -# to the following variable definition. +# +# Each of these words is now inserted in the body of the .for loop. +.for i in ${VALUES} +# $i +.endfor +# +# When these words are injected into the body of the .for loop, each inside a +# '${:U...}' expression, the result is: +# +# expect: For: loop body with i = ${UNDEF:U\$\$: +# expect: # ${:U\${UNDEF\:U\\$\\$} +# expect: For: loop body with i = {{}}: +# expect: # ${:U{{\}\}} +# expect: For: loop body with i = end}: +# expect: # ${:Uend\}} +# expect: For: end for 1 +# +# The first of these expressions is the most interesting one, due to its many +# special characters. This expression is properly balanced: +# +# Text Meaning Explanation +# \$ $ escaped +# { { ordinary text +# UNDEF UNDEF ordinary text +# \: : escaped +# U U ordinary text +# \\ \ escaped +# $\ (expr) an expression, the variable name is '\' +# \$ $ escaped +# +# To make the expression '$\' visible, define it to an actual word: ${:U\\}= backslash -# FIXME: There was no expression '$\' in the original text of the previous -# line, that's a surprise in the parser. -# The modifier ':U' unescapes the '\$' to a simple '$'. -# expect+4: ${UNDEF:U\backslash$ -VALUES= $${UNDEF:U\$$\$$ {{}} end} -# XXX: Where in the code does the '\$\$' get converted into a single '\$'? .for i in ${VALUES} . info $i .endfor +# +# expect-3: ${UNDEF:U\backslash$ +# expect-4: {{}} +# expect-5: end} +# +# FIXME: There was no expression '$\' in the original text of the variable +# 'VALUES', that's a surprise in the parser. + # Second try to cover the code for nested '{}' in ExprLen. # -# XXX: It is wrong that ExprLen requires the braces to be balanced. +# XXX: It is not the job of ExprLen to parse an expression, it is naive to +# expect ExprLen to get all the details right in just a few lines of code. # Each variable modifier has its own inconsistent way of parsing nested -# variable expressions, braces and parentheses. (Compare ':M', ':S', and +# expressions, braces and parentheses. (Compare ':M', ':S', and # ':D' for details.) The only sensible thing to do is therefore to let # Var_Parse do all the parsing work. VALUES= begin<$${UNDEF:Ufallback:N{{{}}}}>end .for i in ${VALUES} . info $i .endfor +# expect-2: begin<fallback>end # A single trailing dollar doesn't happen in practice. # The dollar sign is correctly passed through to the body of the .for loop. @@ -91,21 +144,23 @@ VALUES= begin<$${UNDEF:Ufallback:N{{{}}}}>end .for i in ${:U\$} . info ${i} .endfor +# expect-2: $ -# As of 2020-12-31, the name of the iteration variable can even contain -# colons, which then affects variable expressions having this exact modifier. -# This is clearly an unintended side effect of the implementation. +# Before for.c 1.173 from 2023-05-08, the name of the iteration variable +# could contain colons, which affected expressions having this exact +# modifier. This possibility was neither intended nor documented. NUMBERS= one two three +# expect+1: invalid character ':' in .for loop variable name .for NUMBERS:M*e in replaced . info ${NUMBERS} ${NUMBERS:M*e} .endfor -# As of 2020-12-31, the name of the iteration variable can contain braces, -# which gets even more surprising than colons, since it allows to replace -# sequences of variable expressions. There is no practical use case for -# this, though. +# Before for.c 1.173 from 2023-05-08, the name of the iteration variable +# could contain braces, which allowed to replace sequences of +# expressions. This possibility was neither intended nor documented. BASENAME= one EXT= .c +# expect+1: invalid character '}' in .for loop variable name .for BASENAME}${EXT in replaced . info ${BASENAME}${EXT} .endfor @@ -126,22 +181,35 @@ i,= comma . info . $${i,}: ${i,} . info . adjacent: $i${i}${i:M*}$i .endfor +# expect-11: . $i: inner +# expect-11: . ${i}: inner +# expect-11: . ${i:M*}: inner +# expect-11: . $(i): inner +# expect-11: . $(i:M*): inner +# expect-11: . ${i${:U}}: outer +# expect-11: . ${i\}}: inner} +# expect-11: . ${i2}: two +# expect-11: . ${i,}: comma +# expect-11: . adjacent: innerinnerinnerinner -# The variable name can be a single '$' since there is no check on valid -# variable names. ForLoop_SubstVarShort skips "stupid" variable names though, -# but ForLoop_SubstVarLong naively parses the body of the loop, substituting -# each '${$}' with an actual 'dollar'. +# Before for.c 1.173 from 2023-05-08, the variable name could be a single '$' +# since there was no check on valid variable names. ForLoop_SubstVarShort +# skipped "stupid" variable names though, but ForLoop_SubstVarLong naively +# parsed the body of the loop, substituting each '${$}' with an actual +# '${:Udollar}'. +# expect+1: invalid character '$' in .for loop variable name .for $ in dollar . info eight $$$$$$$$ and no cents. . info eight ${$}${$}${$}${$} and no cents. .endfor # Outside a .for loop, '${$}' is interpreted differently. The outer '$' starts -# a variable expression. The inner '$' is followed by a '}' and is thus a +# an expression. The inner '$' is followed by a '}' and is thus a # silent syntax error, the '$' is skipped. The variable name is thus '', and # since since there is never a variable named '', the whole expression '${$}' # evaluates to an empty string. closing-brace= } # guard against an ${closing-brace}= <closing-brace> # alternative interpretation +# expect+1: eight and no cents. .info eight ${$}${$}${$}${$} and no cents. # What happens if the values from the .for loop contain a literal newline? @@ -149,10 +217,18 @@ ${closing-brace}= <closing-brace> # alternative interpretation # body of the .for loop, where it was then interpreted as a literal newline, # leading to syntax errors such as "Unclosed variable expression" in the upper # line and "Invalid line type" in the lower line. +# +# The error message occurs in the line of the .for loop since that's the place +# where the body of the .for loop is constructed, and at this point the +# newline character gets replaced with a plain space. +# expect+2: newline in .for value +# expect+1: newline in .for value .for i in "${.newline}" . info short: $i . info long: ${i} .endfor +# expect-3: short: " " +# expect-3: long: " " # No error since the newline character is not actually used. .for i in "${.newline}" @@ -164,6 +240,7 @@ ${closing-brace}= <closing-brace> # alternative interpretation # loop is assembled, and at that point, ForLoop.nextItem had already been # advanced. .MAKEFLAGS: -dp +# expect+1: newline in .for value .for i in "${.newline}" : $i .endfor @@ -195,6 +272,22 @@ ${closing-brace}= <closing-brace> # alternative interpretation .for i in ((( {{{ ))) }}} # $i .endfor -.MAKEFLAGS: -d0 -all: + +# When generating the body of a .for loop, recognizing the expressions is done +# using simple heuristics. These can go wrong in ambiguous cases like this. +# The variable name ',' is unusual as it is not a pronounceable name, but the +# same principle applies for other names as well. In this case, the text '$,' +# is replaced with the expression '${:U1}', even though the text does not +# represent an expression. +.for , in 1 +# $$i $i +# VAR= $$i $i ${a:S,from$,to,} +VAR= $$i $i ${a:S,from$,to,} +.endfor +# expect: # $$i $i +# expect: # VAR= $$i $i ${a:S,from${:U1}to,} +# expect: VAR= $$i $i ${a:S,from${:U1}to,} +# +# When the above variable is evaluated, make will complain about the +# unfinished modifier ':S', as it is missing a comma. diff --git a/contrib/bmake/unit-tests/directive-for-generating-endif.exp b/contrib/bmake/unit-tests/directive-for-generating-endif.exp index 5f57f89c250f..ecdeb0962202 100755 --- a/contrib/bmake/unit-tests/directive-for-generating-endif.exp +++ b/contrib/bmake/unit-tests/directive-for-generating-endif.exp @@ -1,7 +1,7 @@ -make: "directive-for-generating-endif.mk" line 21: if-less endif -make: "directive-for-generating-endif.mk" line 21: if-less endif -make: "directive-for-generating-endif.mk" line 21: if-less endif -make: "directive-for-generating-endif.mk" line 26: 3 open conditionals +make: "directive-for-generating-endif.mk" line 24: if-less endif +make: "directive-for-generating-endif.mk" line 24: if-less endif +make: "directive-for-generating-endif.mk" line 24: if-less endif +make: "directive-for-generating-endif.mk" line 30: 3 open conditionals make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/directive-for-generating-endif.mk b/contrib/bmake/unit-tests/directive-for-generating-endif.mk index b4d709551003..3079ad3353c2 100755 --- a/contrib/bmake/unit-tests/directive-for-generating-endif.mk +++ b/contrib/bmake/unit-tests/directive-for-generating-endif.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-for-generating-endif.mk,v 1.1 2020/08/29 18:50:25 rillig Exp $ +# $NetBSD: directive-for-generating-endif.mk,v 1.2 2023/06/01 20:56:35 rillig Exp $ # # Test whether a .for loop can be used to generate multiple .endif # directives to close nested .if directives. Depending on the exact @@ -18,8 +18,12 @@ . if 2 . if 3 .for i in 3 2 1 +# expect+3: if-less endif +# expect+2: if-less endif +# expect+1: if-less endif .endif .endfor all: @:; +# expect+1: 3 open conditionals diff --git a/contrib/bmake/unit-tests/directive-for-if.exp b/contrib/bmake/unit-tests/directive-for-if.exp index 85bfc484856b..f30171f4db87 100644 --- a/contrib/bmake/unit-tests/directive-for-if.exp +++ b/contrib/bmake/unit-tests/directive-for-if.exp @@ -1,6 +1,6 @@ -make: "directive-for-if.mk" line 48: if-less endif -make: "directive-for-if.mk" line 48: if-less endif -make: "directive-for-if.mk" line 48: if-less endif +make: "directive-for-if.mk" line 51: if-less endif +make: "directive-for-if.mk" line 51: if-less endif +make: "directive-for-if.mk" line 51: if-less endif VAR1 VAR3 make: Fatal errors encountered -- cannot continue diff --git a/contrib/bmake/unit-tests/directive-for-if.mk b/contrib/bmake/unit-tests/directive-for-if.mk index 8d73e8ae8c4d..f5a20279cc97 100644 --- a/contrib/bmake/unit-tests/directive-for-if.mk +++ b/contrib/bmake/unit-tests/directive-for-if.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-for-if.mk,v 1.1 2021/08/30 17:08:13 rillig Exp $ +# $NetBSD: directive-for-if.mk,v 1.3 2023/11/19 21:47:52 rillig Exp $ # # Test for a .for directive that contains an .if directive. # @@ -45,6 +45,9 @@ # expanded to their bare textual value. .for directive in if ifdef ifndef . ${directive} "1" != "0" +# expect+3: if-less endif +# expect+2: if-less endif +# expect+1: if-less endif . endif .endfor # In 2021, the above code does not generate an error message, even though the @@ -68,7 +71,7 @@ _!= echo "${var}" 1>&2; echo # In 2005, '.info' was not invented yet. .endfor # Before for.c 1.39 from 2008-12-21, a common workaround was to surround the -# variable expression from the .for loop with '"'. Such a string literal +# expression from the .for loop with '"'. Such a string literal # has been allowed since cond.c 1.23 from 2004-04-13. Between that commit and # the one from 2008, the parser would still get confused if the value from the # .for loop contained '"', which was effectively a code injection. diff --git a/contrib/bmake/unit-tests/directive-for-lines.exp b/contrib/bmake/unit-tests/directive-for-lines.exp index 7aeaaa4a7002..857b4829083b 100644 --- a/contrib/bmake/unit-tests/directive-for-lines.exp +++ b/contrib/bmake/unit-tests/directive-for-lines.exp @@ -1,9 +1,9 @@ -make: "directive-for-lines.mk" line 23: expect 23 -make: "directive-for-lines.mk" line 23: expect 23 -make: "directive-for-lines.mk" line 30: expect 30 -make: "directive-for-lines.mk" line 23: expect 23 -make: "directive-for-lines.mk" line 23: expect 23 -make: "directive-for-lines.mk" line 30: expect 30 +make: "directive-for-lines.mk" line 27: expect 23 +make: "directive-for-lines.mk" line 27: expect 23 +make: "directive-for-lines.mk" line 36: expect 30 +make: "directive-for-lines.mk" line 27: expect 23 +make: "directive-for-lines.mk" line 27: expect 23 +make: "directive-for-lines.mk" line 36: expect 30 make: no target to make. make: stopped in unit-tests diff --git a/contrib/bmake/unit-tests/directive-for-lines.mk b/contrib/bmake/unit-tests/directive-for-lines.mk index 96d659426882..cae4e0a38897 100644 --- a/contrib/bmake/unit-tests/directive-for-lines.mk +++ b/contrib/bmake/unit-tests/directive-for-lines.mk @@ -1,9 +1,9 @@ -# $NetBSD: directive-for-lines.mk,v 1.3 2020/12/19 12:40:00 rillig Exp $ +# $NetBSD: directive-for-lines.mk,v 1.5 2023/06/01 20:56:35 rillig Exp $ # # Tests for the line numbers that are reported in .for loops. # -# Between 2007-01-01 (git 4d3c468f96e1080e, parse.c 1.127) and 2020-12-19 -# (parse.c 1.494), the line numbers for the .info directives and error +# Since parse.c 1.127 from 2007-01-01 and before parse.c 1.494 from +# 2020-12-19, the line numbers for the .info directives and error # messages inside .for loops had been wrong since ParseGetLine skipped empty # lines, even when collecting the lines for the .for loop body. @@ -20,6 +20,10 @@ VAR= \ multi-line +# expect+4: expect 23 +# expect+3: expect 23 +# expect+2: expect 23 +# expect+1: expect 23 .info expect 23 .endfor @@ -27,6 +31,8 @@ VAR= \ # comment \ # continued comment +# expect+2: expect 30 +# expect+1: expect 30 .info expect 30 .endfor diff --git a/contrib/bmake/unit-tests/directive-for-null.mk b/contrib/bmake/unit-tests/directive-for-null.mk index a374f508dd55..fb2d440ee1ba 100644 --- a/contrib/bmake/unit-tests/directive-for-null.mk +++ b/contrib/bmake/unit-tests/directive-for-null.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-for-null.mk,v 1.1 2020/12/19 16:00:17 rillig Exp $ +# $NetBSD: directive-for-null.mk,v 1.3 2022/06/12 15:03:27 rillig Exp $ # # Test for parsing a .for loop that accidentally contains a null byte. # @@ -9,11 +9,15 @@ # make: "(stdin)" line 3: Zero byte read from file # # The one about "end of file" might be misleading but is due to the -# implementation. On both errors and EOF, ParseGetLine returns NULL. +# implementation. On both errors and EOF, ParseRawLine returns NULL. # # The one about the "zero byte" in line 3 is surprising since the only # line that contains a null byte is line 2. all: .PHONY - @printf '%s\n' '.for i in 1 2 3' 'VAR=value' '.endfor' | tr 'l' '\0' \ + @printf '%s\n' \ + '.for i in 1 2 3' \ + 'VAR=value' \ + '.endfor' \ + | tr 'l' '\0' \ | ${MAKE} -f - diff --git a/contrib/bmake/unit-tests/directive-for.exp b/contrib/bmake/unit-tests/directive-for.exp index dda487917e68..0d0313c4e7b0 100755 --- a/contrib/bmake/unit-tests/directive-for.exp +++ b/contrib/bmake/unit-tests/directive-for.exp @@ -1,42 +1,42 @@ -make: "directive-for.mk" line 108: outer -make: "directive-for.mk" line 133: a:\ a:\file.txt -make: "directive-for.mk" line 133: d:\\ -make: "directive-for.mk" line 133: d:\\file.txt -make: "directive-for.mk" line 140: ( ( ( -make: "directive-for.mk" line 140: [ [ [ -make: "directive-for.mk" line 140: { { { -make: "directive-for.mk" line 140: ) ) ) -make: "directive-for.mk" line 140: ] ] ] -make: "directive-for.mk" line 140: } } } -make: "directive-for.mk" line 140: (()) (()) (()) -make: "directive-for.mk" line 140: [[]] [[]] [[]] -make: "directive-for.mk" line 140: {{}} {{}} {{}} -make: "directive-for.mk" line 140: )( )( )( -make: "directive-for.mk" line 140: ][ ][ ][ -make: "directive-for.mk" line 140: }{ }{ }{ -make: "directive-for.mk" line 148: outer value value -make: "directive-for.mk" line 148: outer "quoted" \"quoted\" -make: "directive-for.mk" line 154: Unknown modifier "Z" -make: "directive-for.mk" line 155: XXX: Not reached word1 -make: "directive-for.mk" line 155: XXX: Not reached word3 -make: "directive-for.mk" line 160: no iteration variables in for -make: "directive-for.mk" line 162: Missing argument for ".error" -make: "directive-for.mk" line 163: for-less endfor -make: "directive-for.mk" line 187: 1 open conditional -make: "directive-for.mk" line 203: for-less endfor -make: "directive-for.mk" line 204: if-less endif -make: "directive-for.mk" line 212: if-less endif +make: "directive-for.mk" line 117: outer +make: "directive-for.mk" line 135: a:\ a:\file.txt +make: "directive-for.mk" line 135: d:\\ +make: "directive-for.mk" line 135: d:\\file.txt +make: "directive-for.mk" line 146: ( ( ( +make: "directive-for.mk" line 146: [ [ [ +make: "directive-for.mk" line 146: { { { +make: "directive-for.mk" line 146: ) ) ) +make: "directive-for.mk" line 146: ] ] ] +make: "directive-for.mk" line 146: } } } +make: "directive-for.mk" line 146: (()) (()) (()) +make: "directive-for.mk" line 146: [[]] [[]] [[]] +make: "directive-for.mk" line 146: {{}} {{}} {{}} +make: "directive-for.mk" line 146: )( )( )( +make: "directive-for.mk" line 146: ][ ][ ][ +make: "directive-for.mk" line 146: }{ }{ }{ +make: "directive-for.mk" line 166: invalid character ':' in .for loop variable name +make: "directive-for.mk" line 173: invalid character '$' in .for loop variable name +make: "directive-for.mk" line 185: invalid character '$' in .for loop variable name +make: "directive-for.mk" line 210: Unknown modifier "Z" +make: "directive-for.mk" line 211: XXX: Should not reach word1 +make: "directive-for.mk" line 211: XXX: Should not reach before--after +make: "directive-for.mk" line 211: XXX: Should not reach word3 +make: "directive-for.mk" line 219: no iteration variables in for +make: "directive-for.mk" line 245: 1 open conditional +make: "directive-for.mk" line 261: for-less endfor +make: "directive-for.mk" line 262: if-less endif +make: "directive-for.mk" line 270: if-less endif +For: new loop 2 +For: end for 2 For: end for 1 -For: loop body: +For: loop body with outer = o: .\ for inner in i .\ endfor -make: "directive-for.mk" line 229: Unexpected end of file in .for loop -For: loop body: -.\ - endfor -make: "directive-for.mk" line 227: for-less endfor +For: end for 1 +For: loop body with inner = i: +make: "directive-for.mk" line 318: newline-item=(a) make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/directive-for.mk b/contrib/bmake/unit-tests/directive-for.mk index 572c4d6a5c92..becc314226dc 100755 --- a/contrib/bmake/unit-tests/directive-for.mk +++ b/contrib/bmake/unit-tests/directive-for.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-for.mk,v 1.13 2022/01/15 12:35:18 rillig Exp $ +# $NetBSD: directive-for.mk,v 1.24 2023/12/06 22:28:20 rillig Exp $ # # Tests for the .for directive. # @@ -8,11 +8,13 @@ # .for _FILE_ in values # .for .FILE. in values # .for _f_ in values - -# Using the .for loop, lists of values can be produced. -# In simple cases, the :@var@${var}@ variable modifier can be used to -# achieve the same effects. # +# See also: +# varmod-loop.mk The ':@var@...@' modifier + +# A typical use case for a .for loop is to populate a variable with a list of +# values depending on other variables. In simple cases, the same effect can +# be achieved using the ':@var@${var}@' modifier. .undef NUMBERS .for num in 1 2 3 NUMBERS+= ${num} @@ -21,8 +23,9 @@ NUMBERS+= ${num} . error .endif + # The .for loop also works for multiple iteration variables. -# This is something that the variable modifier :@ cannot do. +# This is something that the modifier :@ cannot do as easily. .for name value in VARNAME value NAME2 value2 ${name}= ${value} .endfor @@ -30,12 +33,12 @@ ${name}= ${value} . error .endif + # The .for loop splits the items at whitespace, taking quotes into account, -# just like the :M or :S variable modifiers. -# -# Until 2012-06-03, it had split the items exactly at whitespace, without -# taking the quotes into account. This had resulted in 10 words. +# just like the :M or :S modifiers. # +# Until 2012-06-03, the .for loop had split the items exactly at whitespace, +# without taking the quotes into account. This had resulted in 10 words. .undef WORDS .for var in one t\ w\ o "three three" 'four four' `five six` WORDS+= counted @@ -44,16 +47,19 @@ WORDS+= counted . error .endif + # In the body of the .for loop, the iteration variables can be accessed # like normal variables, even though they are not really variables. # -# Instead, the expression ${var} is transformed into ${:U1}, ${:U2} and so -# on, before the loop body is evaluated. +# Instead, before interpreting the body of the .for loop, the body is +# generated by replacing each expression ${var} with ${:U1}, ${:U2} and so +# on. # -# A notable effect of this implementation technique is that the .for +# A noticeable effect of this implementation technique is that the .for # iteration variables and the normal global variables live in separate -# namespaces and do not influence each other. -# +# namespaces and do not influence each other. The "scope" of the .for loop +# variables is restricted to the current makefile, it does not reach over to +# any included makefiles. var= value before var2= value before .for var var2 in 1 2 3 4 @@ -66,9 +72,8 @@ var2= value before .endif # Everything from the paragraph above also applies if the loop body is -# empty, even if there is no actual iteration since the loop items are -# also empty. -# +# empty. In this particular example, the items to be iterated are empty as +# well. var= value before var2= value before .for var var2 in ${:U} @@ -80,13 +85,15 @@ var2= value before . warning After the .for loop, var2 must still have its original value. .endif -# Until 2008-12-21, the values of the iteration variables were simply -# inserted as plain text and then parsed as usual, which made it possible -# to achieve all kinds of strange effects. +# Before for.c 1.39 from 2008-12-21, the values of the iteration variables +# were simply inserted as plain text and then parsed as usual, which made it +# possible to achieve all kinds of strange effects, such as generating '.if' +# directives or inserting '$' characters in random places, thereby changing +# how following '$' are interpreted. # -# Before that date, the .for loop expanded to: +# Before that date, the .for loop below expanded to: # EXPANSION+= value -# Since that date, the .for loop expands to: +# Since that date, the .for loop below expands to: # EXPANSION${:U+}= value # EXPANSION= before @@ -102,13 +109,16 @@ EXPANSION${plus}= value .endif # When the outer .for loop is expanded, it sees the expression ${i} and -# expands it. The inner loop then has nothing more to expand. +# expands it. The inner loop then only sees the expression ${:Uouter} and +# has nothing more to expand. .for i in outer . for i in inner +# expect+1: outer . info ${i} . endfor .endfor + # From https://gnats.netbsd.org/29985. # # Until 2008-12-21, the .for loop was expanded by replacing the variable @@ -121,17 +131,13 @@ EXPANSION${plus}= value # like "a:\ a:\file.txt" that ended in a single backslash. Since then, the # variable values have been replaced with expressions of the form ${:U...}, # which are not interpreted as code anymore. -# -# As of 2020-09-22, a comment in for.c says that it may be possible to -# produce an "unwanted substitution", but there is no demonstration code yet. -# -# The above changes prevent a backslash at the end of a word from being -# interpreted as part of the code. Because of this, the trailingBackslash -# hack in Var_Subst is no longer needed and as of 2020-09-22, has been -# removed. .for path in a:\ a:\file.txt d:\\ d:\\file.txt . info ${path} .endfor +# expect-2: a:\ a:\file.txt +# expect-3: d:\\ +# expect-4: d:\\file.txt + # Ensure that braces and parentheses are properly escaped by the .for loop. # Each line must print the same word 3 times. @@ -139,28 +145,80 @@ EXPANSION${plus}= value .for v in ( [ { ) ] } (()) [[]] {{}} )( ][ }{ . info $v ${v} $(v) .endfor +# expect-02: ( ( ( +# expect-03: [ [ [ +# expect-04: { { { +# expect-05: ) ) ) +# expect-06: ] ] ] +# expect-07: } } } +# expect-08: (()) (()) (()) +# expect-09: [[]] [[]] [[]] +# expect-10: {{}} {{}} {{}} +# expect-11: )( )( )( +# expect-12: ][ ][ ][ +# expect-13: }{ }{ }{ -# As of 2020-10-25, the variable names may contain arbitrary characters, -# except for whitespace. This allows for creative side effects. Hopefully -# nobody is misusing this "feature". +# Before 2023-05-09, the variable names could contain arbitrary characters, +# except for whitespace, allowing for creative side effects, as usual for +# arbitrary code injection. var= outer +# expect+1: invalid character ':' in .for loop variable name .for var:Q in value "quoted" -. info ${var} ${var:Q} ${var:Q:Q} +. info <${var}> <${var:Q}> <${var:Q:Q}> +.endfor + +# Before 2023-05-09, when variable names could contain '$', the short +# expression '$$' was preserved, the long expressions were substituted. +# expect+1: invalid character '$' in .for loop variable name +.for $ in value +. info <$$> <${$}> <$($)> +.endfor + + +# https://gnats.netbsd.org/53146 mentions the idea of using a dynamic +# variable name in .for loops, based on some other variable. The .for loops +# are already tricky enough to understand in detail, even without this +# possibility, therefore the variable names are restricted to using harmless +# characters only. +INDIRECT= direct +# expect+1: invalid character '$' in .for loop variable name +.for $(INDIRECT) in value +# If the variable name could be chosen dynamically, the iteration variable +# might have been 'direct', thereby expanding the expression '${direct}'. +. info <$(INDIRECT)> <$(direct)> <$($(INDIRECT))> +.endfor + + +# Regular global variables and the "variables" from the .for loop don't +# interfere with each other. In the following snippet, the variable 'DIRECT' +# is used both as a global variable, as well as an iteration variable in the +# .for loop. The expression '${INDIRECT}' refers to the global variable, not +# to the one from the .for loop. +DIRECT= global +INDIRECT= ${DIRECT} +.for DIRECT in iteration +. if "${DIRECT} ${INDIRECT}" != "iteration global" +. error +. endif .endfor # XXX: A parse error or evaluation error in the items of the .for loop -# should skip the whole loop. As of 2020-12-27, the loop is expanded twice. -.for var in word1 ${:Uword2:Z} word3 -. info XXX: Not reached ${var} +# should skip the whole loop. As of 2023-05-09, the loop is expanded as +# usual. +# expect+1: Unknown modifier "Z" +.for var in word1 before-${:Uword2:Z}-after word3 +. info XXX: Should not reach ${var} .endfor +# expect-2: XXX: Should not reach word1 +# expect-3: XXX: Should not reach before--after +# expect-4: XXX: Should not reach word3 # An empty list of variables to the left of the 'in' is a parse error. .for in value # expect+0: no iteration variables in for -# XXX: The loop body is evaluated once, even with the parse error above. -. error # expect+0: Missing argument for ".error" -.endfor # expect+0: for-less endfor +. error +.endfor # An empty list of iteration values to the right of the 'in' is accepted. # Unlike in the shell, it is not a parse error. @@ -214,12 +272,19 @@ var= outer .endif # no 'if-less endif' -# When make parses a .for loop, it assumes that there is no line break between -# the '.' and the 'for' or 'endfor', as there is no practical reason to break -# the line at this point. When make scans the outer .for loop, it does not -# recognize the inner directives as such. When make scans the inner .for -# loop, it recognizes the '.\n for' but does not recognize the '.\n endfor', -# as LK_FOR_BODY preserves the backslash-newline sequences. +# Before for.c 1.172 from 2023-05-08, when make parsed a .for loop, it +# assumed that there was no line continuation between the '.' and the 'for' +# or 'endfor', as there is no practical reason to break the line at this +# point. +# +# When make scanned the outer .for loop, it did not recognize the inner .for +# loop as such and instead treated it as an unknown directive. The body of +# the outer .for loop thus ended above the '.endfor'. +# +# When make scanned the inner .for loop, it did not recognize the inner +# .endfor as such, which led to a parse error 'Unexpected end of file in .for +# loop' from the '.endfor' line, followed by a second parse error 'for-less +# .endfor' from the '.\\n endfor' line. .MAKEFLAGS: -df .for outer in o .\ @@ -228,3 +293,28 @@ var= outer endfor .endfor .MAKEFLAGS: -d0 + + +# When there is a variable definition 'scope=cmdline' from the command line +# (which has higher precedence than global variables) and a .for loop iterates +# over a variable of the same name, the expression '${scope}' expands to the +# value from the .for loop. This is because when the body of the .for loop is +# expanded, the expression '${scope}' is textually replaced with ${:Uloop}', +# without resolving any other variable names (ForLoop_SubstBody). Later, when +# the body of the .for loop is actually interpreted, the body text doesn't +# contain the word 'scope' anymore. +.MAKEFLAGS: scope=cmdline +.for scope in loop +. if ${scope} != "loop" +. error +. endif +.endfor + + +# Since at least 1993, iteration stops at the first newline. +# Back then, the .newline variable didn't exist, therefore it was unlikely +# that a newline ever occurred. +.for var in a${.newline}b${.newline}c +. info newline-item=(${var}) +.endfor +# expect-2: newline-item=(a) diff --git a/contrib/bmake/unit-tests/directive-hyphen-include.exp b/contrib/bmake/unit-tests/directive-hyphen-include.exp index d0835fe464b1..308a444890d5 100755 --- a/contrib/bmake/unit-tests/directive-hyphen-include.exp +++ b/contrib/bmake/unit-tests/directive-hyphen-include.exp @@ -1,4 +1,4 @@ -make: "directive-hyphen-include-error.inc" line 1: Invalid line type +make: "directive-hyphen-include-error.inc" line 1: Invalid line 'syntax error' make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/directive-hyphen-include.mk b/contrib/bmake/unit-tests/directive-hyphen-include.mk index fbfbeb200d4f..de3b68ae52b3 100755 --- a/contrib/bmake/unit-tests/directive-hyphen-include.mk +++ b/contrib/bmake/unit-tests/directive-hyphen-include.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-hyphen-include.mk,v 1.2 2022/01/23 21:48:59 rillig Exp $ +# $NetBSD: directive-hyphen-include.mk,v 1.3 2023/08/19 10:52:13 rillig Exp $ # # Tests for the .-include directive, which includes another file, # silently skipping it if it cannot be opened. @@ -15,7 +15,7 @@ .-include "${MAKEFILE}/subdir" # Errors that are not related to opening the file are still reported. -# expect: make: "directive-hyphen-include-error.inc" line 1: Invalid line type +# expect: make: "directive-hyphen-include-error.inc" line 1: Invalid line 'syntax error' _!= echo 'syntax error' > directive-hyphen-include-error.inc .-include "${.CURDIR}/directive-hyphen-include-error.inc" _!= rm directive-hyphen-include-error.inc diff --git a/contrib/bmake/unit-tests/directive-if.exp b/contrib/bmake/unit-tests/directive-if.exp index 5682df501e9c..34ba63d034dd 100644 --- a/contrib/bmake/unit-tests/directive-if.exp +++ b/contrib/bmake/unit-tests/directive-if.exp @@ -1,18 +1,18 @@ -make: "directive-if.mk" line 13: 0 evaluates to false. -make: "directive-if.mk" line 17: 1 evaluates to true. -make: "directive-if.mk" line 41: Unknown directive "ifx" -make: "directive-if.mk" line 43: This is not conditional. -make: "directive-if.mk" line 45: if-less else -make: "directive-if.mk" line 47: This is not conditional. -make: "directive-if.mk" line 49: if-less endif -make: "directive-if.mk" line 53: Malformed conditional () -make: "directive-if.mk" line 63: Quotes in plain words are probably a mistake. -make: "directive-if.mk" line 72: Don't do this, always put a space after a directive. +make: "directive-if.mk" line 14: 0 evaluates to false. +make: "directive-if.mk" line 19: 1 evaluates to true. +make: "directive-if.mk" line 43: Unknown directive "ifx" +make: "directive-if.mk" line 45: This is not conditional. +make: "directive-if.mk" line 47: if-less else +make: "directive-if.mk" line 49: This is not conditional. +make: "directive-if.mk" line 51: if-less endif +make: "directive-if.mk" line 55: Malformed conditional () +make: "directive-if.mk" line 66: Quotes in plain words are probably a mistake. make: "directive-if.mk" line 76: Don't do this, always put a space after a directive. -make: "directive-if.mk" line 82: Don't do this, always put a space around comparison operators. -make: "directive-if.mk" line 88: Don't do this, always put a space after a directive. -make: "directive-if.mk" line 92: Don't do this, always put a space after a directive. -make: "directive-if.mk" line 100: Unknown directive "ifn" +make: "directive-if.mk" line 81: Don't do this, always put a space after a directive. +make: "directive-if.mk" line 88: Don't do this, always put a space around comparison operators. +make: "directive-if.mk" line 95: Don't do this, always put a space after a directive. +make: "directive-if.mk" line 100: Don't do this, always put a space after a directive. +make: "directive-if.mk" line 108: Unknown directive "ifn" make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/directive-if.mk b/contrib/bmake/unit-tests/directive-if.mk index 1acd5c958008..7a68c0041415 100644 --- a/contrib/bmake/unit-tests/directive-if.mk +++ b/contrib/bmake/unit-tests/directive-if.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-if.mk,v 1.11 2022/01/23 21:48:59 rillig Exp $ +# $NetBSD: directive-if.mk,v 1.12 2023/06/01 20:56:35 rillig Exp $ # # Tests for the .if directive. # @@ -10,10 +10,12 @@ .if 0 . error .else +# expect+1: 0 evaluates to false. . info 0 evaluates to false. .endif .if 1 +# expect+1: 1 evaluates to true. . info 1 evaluates to true. .else . error @@ -60,6 +62,7 @@ # though, which are kept. The quotes need not be balanced. The next space # ends the word, and the remaining " || 1" is parsed as "or true". .if ${:Uplain"""""} == plain""""" || 1 +# expect+1: Quotes in plain words are probably a mistake. . info Quotes in plain words are probably a mistake. # XXX: Accepting quotes in plain words is probably a mistake as well. .else @@ -69,26 +72,31 @@ .if0 . error .else +# expect+1: Don't do this, always put a space after a directive. . info Don't do this, always put a space after a directive. .endif .if${:U-3} +# expect+1: Don't do this, always put a space after a directive. . info Don't do this, always put a space after a directive. .else . error .endif .if${:U-3}>-4 +# expect+1: Don't do this, always put a space around comparison operators. . info Don't do this, always put a space around comparison operators. .else . error .endif .if(1) +# expect+1: Don't do this, always put a space after a directive. . info Don't do this, always put a space after a directive. .endif .if!0 +# expect+1: Don't do this, always put a space after a directive. . info Don't do this, always put a space after a directive. .endif diff --git a/contrib/bmake/unit-tests/directive-ifmake.exp b/contrib/bmake/unit-tests/directive-ifmake.exp index bf4ded97911f..e607726fd87c 100644 --- a/contrib/bmake/unit-tests/directive-ifmake.exp +++ b/contrib/bmake/unit-tests/directive-ifmake.exp @@ -1,10 +1,10 @@ -make: "directive-ifmake.mk" line 13: ok: positive condition works -make: "directive-ifmake.mk" line 24: ok: negation works -make: "directive-ifmake.mk" line 33: ok: double negation works -make: "directive-ifmake.mk" line 40: ok: both mentioned -make: "directive-ifmake.mk" line 47: ok: only those mentioned -make: "directive-ifmake.mk" line 57: Targets can even be added at parse time. -make: "directive-ifmake.mk" line 75: ok +make: "directive-ifmake.mk" line 14: ok: positive condition works +make: "directive-ifmake.mk" line 26: ok: negation works +make: "directive-ifmake.mk" line 36: ok: double negation works +make: "directive-ifmake.mk" line 44: ok: both mentioned +make: "directive-ifmake.mk" line 52: ok: only those mentioned +make: "directive-ifmake.mk" line 63: Targets can even be added at parse time. +make: "directive-ifmake.mk" line 82: ok : first : second : late-target diff --git a/contrib/bmake/unit-tests/directive-ifmake.mk b/contrib/bmake/unit-tests/directive-ifmake.mk index a1ff3aef6825..fa0a56c60030 100644 --- a/contrib/bmake/unit-tests/directive-ifmake.mk +++ b/contrib/bmake/unit-tests/directive-ifmake.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-ifmake.mk,v 1.10 2022/02/09 21:09:24 rillig Exp $ +# $NetBSD: directive-ifmake.mk,v 1.12 2023/11/19 21:47:52 rillig Exp $ # # Tests for the .ifmake directive, which provides a shortcut for asking # whether a certain target is requested to be made from the command line. @@ -10,6 +10,7 @@ # This is the most basic form. .ifmake first +# expect+1: ok: positive condition works . info ok: positive condition works .else . warning positive condition fails @@ -21,6 +22,7 @@ .ifmake !first . warning unexpected .else +# expect+1: ok: negation works . info ok: negation works .endif @@ -30,6 +32,7 @@ # exclamation mark were part of the name instead, the name would be '!!first', # and such a target was not requested to be made. .ifmake !!first +# expect+1: ok: double negation works . info ok: double negation works .else . warning double negation fails @@ -37,6 +40,7 @@ # Multiple targets can be combined using the && and || operators. .ifmake first && second +# expect+1: ok: both mentioned . info ok: both mentioned .else . warning && does not work as expected @@ -44,6 +48,7 @@ # Negation also works in complex conditions. .ifmake first && !unmentioned +# expect+1: ok: only those mentioned . info ok: only those mentioned .else . warning && with ! does not work as expected @@ -54,6 +59,7 @@ # possible to extend the targets to be made. .MAKEFLAGS: late-target .ifmake late-target +# expect+1: Targets can even be added at parse time. . info Targets can even be added at parse time. .else . info No, targets cannot be added at parse time anymore. @@ -69,9 +75,10 @@ . error .endif -# A condition that consists of a variable expression only (without any +# A condition that consists of an expression only (without any # comparison operator) can be used with .if and the other .ifxxx directives. .ifmake ${:Ufirst} +# expect+1: ok . info ok .else . error diff --git a/contrib/bmake/unit-tests/directive-ifndef.exp b/contrib/bmake/unit-tests/directive-ifndef.exp index c653f6344429..d018e78616bc 100644 --- a/contrib/bmake/unit-tests/directive-ifndef.exp +++ b/contrib/bmake/unit-tests/directive-ifndef.exp @@ -1,2 +1,2 @@ -make: "directive-ifndef.mk" line 10: guarded section +make: "directive-ifndef.mk" line 14: guarded section exit status 0 diff --git a/contrib/bmake/unit-tests/directive-ifndef.mk b/contrib/bmake/unit-tests/directive-ifndef.mk index bf509ef8075e..44eec55b4a87 100644 --- a/contrib/bmake/unit-tests/directive-ifndef.mk +++ b/contrib/bmake/unit-tests/directive-ifndef.mk @@ -1,12 +1,16 @@ -# $NetBSD: directive-ifndef.mk,v 1.6 2020/10/24 08:46:08 rillig Exp $ +# $NetBSD: directive-ifndef.mk,v 1.9 2023/10/19 18:24:33 rillig Exp $ # # Tests for the .ifndef directive, which can be used for multiple-inclusion # guards. In contrast to C, where #ifndef and #define nicely line up the # macro name, there is no such syntax in make. Therefore, it is more # common to use .if !defined(GUARD) instead. +# +# See also: +# directive-include-guard.mk .ifndef GUARD GUARD= # defined +# expect+1: guarded section . info guarded section .endif @@ -20,5 +24,64 @@ GUARD= # defined . info guarded section .endif + +# The '.ifndef' directive can be used with multiple arguments, even negating +# them. Since these conditions are confusing for humans, they should be +# replaced with easier-to-understand plain '.if' directives. +DEFINED= +.ifndef UNDEFINED && UNDEFINED +.else +. error +.endif +.ifndef UNDEFINED && DEFINED +. error +.endif +.ifndef DEFINED && DEFINED +. error +.endif +.ifndef !UNDEFINED && !UNDEFINED +. error +.endif +.ifndef !UNDEFINED && !DEFINED +. error +.endif +.ifndef !DEFINED && !DEFINED +.else +. error +.endif + + +# The negation from the 'if-not-defined' directive only applies to bare words, +# but not to numbers, quoted strings or expressions. Those are evaluated +# without extra negation, just like in a plain '.if' directive. +.ifndef 0 +. error +.endif +.ifndef 1 +.else +. error +.endif +.ifndef "" +. error +.endif +.ifndef "word" +.else +. error +.endif +.ifndef ${:UUNDEFINED} +.else +. error +.endif +.ifndef ${:UDEFINED} +. error +.endif +.ifndef ${:U0} +. error +.endif +.ifndef ${:U1} +.else +. error +.endif + + all: - @:; diff --git a/contrib/bmake/unit-tests/directive-include-fatal.exp b/contrib/bmake/unit-tests/directive-include-fatal.exp index c8ca97a0fd5f..cae0fc97a59d 100755 --- a/contrib/bmake/unit-tests/directive-include-fatal.exp +++ b/contrib/bmake/unit-tests/directive-include-fatal.exp @@ -1,4 +1,4 @@ -make: "directive-include-fatal.mk" line 13: Malformed conditional (${UNDEF}) +make: "directive-include-fatal.mk" line 14: Malformed conditional (${UNDEF}) make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/directive-include-fatal.mk b/contrib/bmake/unit-tests/directive-include-fatal.mk index 6744f9e80e5c..d4ed26f2a4aa 100755 --- a/contrib/bmake/unit-tests/directive-include-fatal.mk +++ b/contrib/bmake/unit-tests/directive-include-fatal.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-include-fatal.mk,v 1.3 2021/02/01 22:16:57 rillig Exp $ +# $NetBSD: directive-include-fatal.mk,v 1.4 2023/06/01 20:56:35 rillig Exp $ # # Test for the .include directive combined with fatal errors. # @@ -10,6 +10,7 @@ # the "fatals" counter. # Using an undefined variable in a condition generates a fatal error. +# expect+1: Malformed conditional (${UNDEF}) .if ${UNDEF} .endif diff --git a/contrib/bmake/unit-tests/directive-include-guard.exp b/contrib/bmake/unit-tests/directive-include-guard.exp new file mode 100644 index 000000000000..70d23a19fe7c --- /dev/null +++ b/contrib/bmake/unit-tests/directive-include-guard.exp @@ -0,0 +1,104 @@ +Parse_PushInput: file variable-ifndef.tmp, line 1 +Skipping 'variable-ifndef.tmp' because 'VARIABLE_IFNDEF' is defined +Parse_PushInput: file variable-ifndef-reuse.tmp, line 1 +Skipping 'variable-ifndef-reuse.tmp' because 'VARIABLE_IFNDEF' is defined +Parse_PushInput: file variable-ifndef-zero.tmp, line 1 +Parse_PushInput: file variable-ifndef-zero.tmp, line 1 +Parse_PushInput: file variable-ifndef-one.tmp, line 1 +Parse_PushInput: file variable-ifndef-one.tmp, line 1 +Parse_PushInput: file comments.tmp, line 1 +Skipping 'comments.tmp' because 'COMMENTS' is defined +Parse_PushInput: file variable-if.tmp, line 1 +Skipping 'variable-if.tmp' because 'VARIABLE_IF' is defined +Parse_PushInput: file variable-if-reuse.tmp, line 1 +Skipping 'variable-if-reuse.tmp' because 'VARIABLE_IF' is defined +Parse_PushInput: file variable-if-triple-negation.tmp, line 1 +Parse_PushInput: file variable-if-triple-negation.tmp, line 1 +Parse_PushInput: file variable-if-spaced.tmp, line 1 +Parse_PushInput: file variable-if-spaced.tmp, line 1 +Parse_PushInput: file variable-if-parenthesized.tmp, line 1 +Parse_PushInput: file variable-if-parenthesized.tmp, line 1 +Parse_PushInput: file variable-ifdef-negated.tmp, line 1 +Parse_PushInput: file variable-ifdef-negated.tmp, line 1 +Parse_PushInput: file variable-name-mismatch.tmp, line 1 +Parse_PushInput: file variable-name-mismatch.tmp, line 1 +Parse_PushInput: file variable-ifndef-parenthesized.tmp, line 1 +Parse_PushInput: file variable-ifndef-parenthesized.tmp, line 1 +Parse_PushInput: file variable-name-exclamation.tmp, line 1 +Parse_PushInput: file variable-name-exclamation.tmp, line 1 +Parse_PushInput: file variable-name-exclamation-middle.tmp, line 1 +Parse_PushInput: file variable-name-exclamation-middle.tmp, line 1 +Parse_PushInput: file variable-name-parentheses.tmp, line 1 +Parse_PushInput: file variable-name-parentheses.tmp, line 1 +Parse_PushInput: file variable-ifndef-plus.tmp, line 1 +Parse_PushInput: file variable-ifndef-plus.tmp, line 1 +Parse_PushInput: file variable-if-plus.tmp, line 1 +Parse_PushInput: file variable-if-plus.tmp, line 1 +Parse_PushInput: file variable-ifndef-indirect.tmp, line 1 +Parse_PushInput: file variable-ifndef-indirect.tmp, line 1 +Parse_PushInput: file variable-if-indirect.tmp, line 1 +Parse_PushInput: file variable-if-indirect.tmp, line 1 +Parse_PushInput: file variable-assign-indirect.tmp, line 1 +Skipping 'variable-assign-indirect.tmp' because 'VARIABLE_ASSIGN_INDIRECT' is defined +Parse_PushInput: file variable-assign-late.tmp, line 1 +Skipping 'variable-assign-late.tmp' because 'VARIABLE_ASSIGN_LATE' is defined +Parse_PushInput: file variable-assign-nested.tmp, line 1 +Parse_PushInput: .for loop in variable-assign-nested.tmp, line 3 +Skipping 'variable-assign-nested.tmp' because 'VARIABLE_ASSIGN_NESTED' is defined +Parse_PushInput: file variable-already-defined.tmp, line 1 +Skipping 'variable-already-defined.tmp' because 'VARIABLE_ALREADY_DEFINED' is defined +Parse_PushInput: file variable-defined-then-undefined.tmp, line 1 +Parse_PushInput: file variable-defined-then-undefined.tmp, line 1 +Parse_PushInput: file variable-two-times.tmp, line 1 +Parse_PushInput: file variable-two-times.tmp, line 1 +Parse_PushInput: file variable-clash.tmp, line 1 +Skipping 'variable-clash.tmp' because 'VARIABLE_IF' is defined +Parse_PushInput: file variable-swapped.tmp, line 1 +Parse_PushInput: file variable-swapped.tmp, line 1 +Parse_PushInput: file variable-undef-between.tmp, line 1 +Parse_PushInput: file variable-undef-between.tmp, line 1 +Parse_PushInput: file variable-undef-inside.tmp, line 1 +Parse_PushInput: file variable-undef-inside.tmp, line 1 +Parse_PushInput: file variable-not-defined.tmp, line 1 +Parse_PushInput: file variable-not-defined.tmp, line 1 +Parse_PushInput: file elif.tmp, line 1 +Parse_PushInput: file elif.tmp, line 1 +Parse_PushInput: file elif-reuse.tmp, line 1 +Parse_PushInput: file elif-reuse.tmp, line 1 +Parse_PushInput: file else.tmp, line 1 +Parse_PushInput: file else.tmp, line 1 +Parse_PushInput: file else-reuse.tmp, line 1 +Parse_PushInput: file else-reuse.tmp, line 1 +Parse_PushInput: file inner-if-elif-else.tmp, line 1 +Skipping 'inner-if-elif-else.tmp' because 'INNER_IF_ELIF_ELSE' is defined +Parse_PushInput: file target.tmp, line 1 +Skipping 'target.tmp' because '__target.tmp__' is defined +Parse_PushInput: file target-sys.tmp, line 1 +Skipping 'target-sys.tmp' because '__<target-sys.tmp>__' is defined +Parse_PushInput: file target-indirect.tmp, line 1 +Skipping 'target-indirect.tmp' because 'target-indirect.tmp' is defined +Parse_PushInput: file target-indirect-PARSEFILE.tmp, line 1 +Skipping 'target-indirect-PARSEFILE.tmp' because '__target-indirect-PARSEFILE.tmp__' is defined +Parse_PushInput: file target-indirect-PARSEFILE2.tmp, line 1 +Skipping 'target-indirect-PARSEFILE2.tmp' because '__target-indirect-PARSEFILE2.tmp__' is defined +Parse_PushInput: file subdir/target-indirect-PARSEFILE.tmp, line 1 +Skipping 'subdir/target-indirect-PARSEFILE.tmp' because '__target-indirect-PARSEFILE.tmp__' is defined +Parse_PushInput: file target-indirect-PARSEDIR-PARSEFILE.tmp, line 1 +Skipping 'target-indirect-PARSEDIR-PARSEFILE.tmp' because '__target-indirect-PARSEDIR-PARSEFILE.tmp__' is defined +Parse_PushInput: file subdir/target-indirect-PARSEDIR-PARSEFILE.tmp, line 1 +Skipping 'subdir/target-indirect-PARSEDIR-PARSEFILE.tmp' because '__subdir/target-indirect-PARSEDIR-PARSEFILE.tmp__' is defined +Parse_PushInput: file target-unguarded.tmp, line 1 +Parse_PushInput: file target-unguarded.tmp, line 1 +Parse_PushInput: file target-plus.tmp, line 1 +Parse_PushInput: file target-plus.tmp, line 1 +Parse_PushInput: file target-already-defined.tmp, line 1 +Skipping 'target-already-defined.tmp' because 'target-already-defined' is defined +Parse_PushInput: file target-name-exclamation.tmp, line 1 +Parse_PushInput: file target-name-exclamation.tmp, line 1 +Parse_PushInput: file target-name-parenthesized.tmp, line 1 +Parse_PushInput: file target-name-parenthesized.tmp, line 1 +Parse_PushInput: file target-call-parenthesized.tmp, line 1 +Parse_PushInput: file target-call-parenthesized.tmp, line 1 +Parse_PushInput: file multiline.tmp, line 1 +Skipping 'multiline.tmp' because 'MULTILINE' is defined +exit status 0 diff --git a/contrib/bmake/unit-tests/directive-include-guard.mk b/contrib/bmake/unit-tests/directive-include-guard.mk new file mode 100644 index 000000000000..85c0242c2009 --- /dev/null +++ b/contrib/bmake/unit-tests/directive-include-guard.mk @@ -0,0 +1,638 @@ +# $NetBSD: directive-include-guard.mk,v 1.16 2023/12/17 14:07:22 rillig Exp $ +# +# Tests for multiple-inclusion guards in makefiles. +# +# A file that is guarded by a multiple-inclusion guard has one of the +# following forms: +# +# .ifndef GUARD_VARIABLE +# .endif +# +# .if !defined(GUARD_VARIABLE) +# .endif +# +# .if !target(guard-target) +# .endif +# +# When such a file is included for the second or later time, and the guard +# variable or the guard target is defined, the file is skipped completely, as +# including it would not have any effect, not even on the special variable +# '.MAKE.MAKEFILES', as that variable skips duplicate pathnames. +# +# See also: +# https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html + +# Each of the following test cases creates a temporary file named after the +# test case and writes some lines of text to that file. That file is then +# included twice, to see whether the second '.include' is skipped. + + +# This is the canonical form of a variable-based multiple-inclusion guard. +CASES+= variable-ifndef +LINES.variable-ifndef= \ + '.ifndef VARIABLE_IFNDEF' \ + 'VARIABLE_IFNDEF=' \ + '.endif' +# expect: Parse_PushInput: file variable-ifndef.tmp, line 1 +# expect: Skipping 'variable-ifndef.tmp' because 'VARIABLE_IFNDEF' is defined + +# A file that reuses a guard from a previous file (or whose guard is defined +# for any other reason) is only processed once, to see whether it is guarded. +# Its content is skipped, therefore the syntax error is not detected. +CASES+= variable-ifndef-reuse +LINES.variable-ifndef-reuse= \ + '.ifndef VARIABLE_IFNDEF' \ + 'syntax error' \ + '.endif' +# expect: Parse_PushInput: file variable-ifndef-reuse.tmp, line 1 +# expect: Skipping 'variable-ifndef-reuse.tmp' because 'VARIABLE_IFNDEF' is defined + +# The guard variable cannot be a number, as numbers are interpreted +# differently from bare words. +CASES+= variable-ifndef-zero +LINES.variable-ifndef-zero= \ + '.ifndef 0e0' \ + 'syntax error' \ + '.endif' +# expect: Parse_PushInput: file variable-ifndef-zero.tmp, line 1 +# expect: Parse_PushInput: file variable-ifndef-zero.tmp, line 1 + +# The guard variable cannot be a number, as numbers are interpreted +# differently from bare words. +CASES+= variable-ifndef-one +LINES.variable-ifndef-one= \ + '.ifndef 1' \ + '.endif' +# expect: Parse_PushInput: file variable-ifndef-one.tmp, line 1 +# expect: Parse_PushInput: file variable-ifndef-one.tmp, line 1 + +# Comments and empty lines do not affect the multiple-inclusion guard. +CASES+= comments +LINES.comments= \ + '\# comment' \ + '' \ + '.ifndef COMMENTS' \ + '\# comment' \ + 'COMMENTS=\#comment' \ + '.endif' \ + '\# comment' +# expect: Parse_PushInput: file comments.tmp, line 1 +# expect: Skipping 'comments.tmp' because 'COMMENTS' is defined + +# An alternative form uses the 'defined' function. It is more verbose than +# the canonical form but avoids the '.ifndef' directive, as that directive is +# not commonly used. +CASES+= variable-if +LINES.variable-if= \ + '.if !defined(VARIABLE_IF)' \ + 'VARIABLE_IF=' \ + '.endif' +# expect: Parse_PushInput: file variable-if.tmp, line 1 +# expect: Skipping 'variable-if.tmp' because 'VARIABLE_IF' is defined + +# A file that reuses a guard from a previous file (or whose guard is defined +# for any other reason) is only processed once, to see whether it is guarded. +# Its content is skipped, therefore the syntax error is not detected. +CASES+= variable-if-reuse +LINES.variable-if-reuse= \ + '.if !defined(VARIABLE_IF)' \ + 'syntax error' \ + '.endif' +# expect: Parse_PushInput: file variable-if-reuse.tmp, line 1 +# expect: Skipping 'variable-if-reuse.tmp' because 'VARIABLE_IF' is defined + +# Triple negation is so uncommon that it's not recognized, even though it has +# the same effect as a single negation. +CASES+= variable-if-triple-negation +LINES.variable-if-triple-negation= \ + '.if !!!defined(VARIABLE_IF_TRIPLE_NEGATION)' \ + 'VARIABLE_IF_TRIPLE_NEGATION=' \ + '.endif' +# expect: Parse_PushInput: file variable-if-triple-negation.tmp, line 1 +# expect: Parse_PushInput: file variable-if-triple-negation.tmp, line 1 + +# If the guard variable is enclosed in spaces, it does not have an effect, as +# that form is not common in practice. +CASES+= variable-if-spaced +LINES.variable-if-spaced= \ + '.if !defined( VARIABLE_IF_SPACED )' \ + 'VARIABLE_IF_SPACED=' \ + '.endif' +# expect: Parse_PushInput: file variable-if-spaced.tmp, line 1 +# expect: Parse_PushInput: file variable-if-spaced.tmp, line 1 + +# If the guard variable condition is enclosed in parentheses, it does not have +# an effect, as that form is not common in practice. +CASES+= variable-if-parenthesized +LINES.variable-if-parenthesized= \ + '.if (!defined(VARIABLE_IF_PARENTHESIZED))' \ + 'VARIABLE_IF_PARENTHESIZED=' \ + '.endif' +# expect: Parse_PushInput: file variable-if-parenthesized.tmp, line 1 +# expect: Parse_PushInput: file variable-if-parenthesized.tmp, line 1 + +# A conditional other than '.if' or '.ifndef' does not guard the file, even if +# it is otherwise equivalent to the above accepted forms. +CASES+= variable-ifdef-negated +LINES.variable-ifdef-negated= \ + '.ifdef !VARIABLE_IFDEF_NEGATED' \ + 'VARIABLE_IFDEF_NEGATED=' \ + '.endif' +# expect: Parse_PushInput: file variable-ifdef-negated.tmp, line 1 +# expect: Parse_PushInput: file variable-ifdef-negated.tmp, line 1 + +# The variable names in the '.if' and the assignment must be the same. +CASES+= variable-name-mismatch +LINES.variable-name-mismatch= \ + '.ifndef VARIABLE_NAME_MISMATCH' \ + 'VARIABLE_NAME_DIFFERENT=' \ + '.endif' +# expect: Parse_PushInput: file variable-name-mismatch.tmp, line 1 +# expect: Parse_PushInput: file variable-name-mismatch.tmp, line 1 + +# If the guard variable condition is enclosed in parentheses, it does not have +# an effect, as that form is not common in practice. +CASES+= variable-ifndef-parenthesized +LINES.variable-ifndef-parenthesized= \ + '.ifndef (VARIABLE_IFNDEF_PARENTHESIZED)' \ + 'VARIABLE_IFNDEF_PARENTHESIZED=' \ + '.endif' +# expect: Parse_PushInput: file variable-ifndef-parenthesized.tmp, line 1 +# expect: Parse_PushInput: file variable-ifndef-parenthesized.tmp, line 1 + +# The variable name '!VARNAME' cannot be used in an '.ifndef' directive, as +# the '!' would be a negation. It is syntactically valid in a '.if !defined' +# condition, but this case is so uncommon that the guard mechanism doesn't +# accept '!' in the guard variable name. Furthermore, when defining the +# variable, the character '!' has to be escaped, to prevent it from being +# interpreted as the '!' dependency operator. +CASES+= variable-name-exclamation +LINES.variable-name-exclamation= \ + '.if !defined(!VARIABLE_NAME_EXCLAMATION)' \ + '${:U!}VARIABLE_NAME_EXCLAMATION=' \ + '.endif' +# expect: Parse_PushInput: file variable-name-exclamation.tmp, line 1 +# expect: Parse_PushInput: file variable-name-exclamation.tmp, line 1 + +# In general, a variable name can contain a '!' in the middle, as that +# character is interpreted as an ordinary character in conditions as well as +# on the left side of a variable assignment. For guard variable names, the +# '!' is not supported in any place, though. +CASES+= variable-name-exclamation-middle +LINES.variable-name-exclamation-middle= \ + '.ifndef VARIABLE_NAME!MIDDLE' \ + 'VARIABLE_NAME!MIDDLE=' \ + '.endif' +# expect: Parse_PushInput: file variable-name-exclamation-middle.tmp, line 1 +# expect: Parse_PushInput: file variable-name-exclamation-middle.tmp, line 1 + +# A variable name can contain balanced parentheses, at least in conditions and +# on the left side of a variable assignment. There are enough places in make +# where parentheses or braces are handled inconsistently to make this naming +# choice a bad idea, therefore these characters are not allowed in guard +# variable names. +CASES+= variable-name-parentheses +LINES.variable-name-parentheses= \ + '.ifndef VARIABLE_NAME(&)PARENTHESES' \ + 'VARIABLE_NAME(&)PARENTHESES=' \ + '.endif' +# expect: Parse_PushInput: file variable-name-parentheses.tmp, line 1 +# expect: Parse_PushInput: file variable-name-parentheses.tmp, line 1 + +# The guard condition must consist of only the guard variable, nothing else. +CASES+= variable-ifndef-plus +LINES.variable-ifndef-plus= \ + '.ifndef VARIABLE_IFNDEF_PLUS && VARIABLE_IFNDEF_SECOND' \ + 'VARIABLE_IFNDEF_PLUS=' \ + 'VARIABLE_IFNDEF_SECOND=' \ + '.endif' +# expect: Parse_PushInput: file variable-ifndef-plus.tmp, line 1 +# expect: Parse_PushInput: file variable-ifndef-plus.tmp, line 1 + +# The guard condition must consist of only the guard variable, nothing else. +CASES+= variable-if-plus +LINES.variable-if-plus= \ + '.if !defined(VARIABLE_IF_PLUS) && !defined(VARIABLE_IF_SECOND)' \ + 'VARIABLE_IF_PLUS=' \ + 'VARIABLE_IF_SECOND=' \ + '.endif' +# expect: Parse_PushInput: file variable-if-plus.tmp, line 1 +# expect: Parse_PushInput: file variable-if-plus.tmp, line 1 + +# The variable name in an '.ifndef' guard must be given directly, it must not +# contain any '$' expression. +CASES+= variable-ifndef-indirect +LINES.variable-ifndef-indirect= \ + '.ifndef $${VARIABLE_IFNDEF_INDIRECT:L}' \ + 'VARIABLE_IFNDEF_INDIRECT=' \ + '.endif' +# expect: Parse_PushInput: file variable-ifndef-indirect.tmp, line 1 +# expect: Parse_PushInput: file variable-ifndef-indirect.tmp, line 1 + +# The variable name in an '.if' guard must be given directly, it must not +# contain any '$' expression. +CASES+= variable-if-indirect +LINES.variable-if-indirect= \ + '.if !defined($${VARIABLE_IF_INDIRECT:L})' \ + 'VARIABLE_IF_INDIRECT=' \ + '.endif' +# expect: Parse_PushInput: file variable-if-indirect.tmp, line 1 +# expect: Parse_PushInput: file variable-if-indirect.tmp, line 1 + +# The variable name in the guard condition must only contain alphanumeric +# characters and underscores. The place where the guard variable is defined +# is more flexible, as long as the variable is defined at the point where the +# file is included the next time. +CASES+= variable-assign-indirect +LINES.variable-assign-indirect= \ + '.ifndef VARIABLE_ASSIGN_INDIRECT' \ + '$${VARIABLE_ASSIGN_INDIRECT:L}=' \ + '.endif' +# expect: Parse_PushInput: file variable-assign-indirect.tmp, line 1 +# expect: Skipping 'variable-assign-indirect.tmp' because 'VARIABLE_ASSIGN_INDIRECT' is defined + +# The time at which the guard variable is defined doesn't matter, as long as +# it is defined at the point where the file is included the next time. +CASES+= variable-assign-late +LINES.variable-assign-late= \ + '.ifndef VARIABLE_ASSIGN_LATE' \ + 'VARIABLE_ASSIGN_LATE_OTHER=' \ + 'VARIABLE_ASSIGN_LATE=' \ + '.endif' +# expect: Parse_PushInput: file variable-assign-late.tmp, line 1 +# expect: Skipping 'variable-assign-late.tmp' because 'VARIABLE_ASSIGN_LATE' is defined + +# The time at which the guard variable is defined doesn't matter, as long as +# it is defined at the point where the file is included the next time. +CASES+= variable-assign-nested +LINES.variable-assign-nested= \ + '.ifndef VARIABLE_ASSIGN_NESTED' \ + '. if 1' \ + '. for i in once' \ + 'VARIABLE_ASSIGN_NESTED=' \ + '. endfor' \ + '. endif' \ + '.endif' +# expect: Parse_PushInput: file variable-assign-nested.tmp, line 1 +# expect: Skipping 'variable-assign-nested.tmp' because 'VARIABLE_ASSIGN_NESTED' is defined + +# If the guard variable is defined before the file is included for the first +# time, the file is considered guarded as well. In such a case, the parser +# skips almost all lines, as they are irrelevant, but the structure of the +# top-level '.if/.endif' conditional can be determined reliably enough to +# decide whether the file is guarded. +CASES+= variable-already-defined +LINES.variable-already-defined= \ + '.ifndef VARIABLE_ALREADY_DEFINED' \ + 'VARIABLE_ALREADY_DEFINED=' \ + '.endif' +VARIABLE_ALREADY_DEFINED= +# expect: Parse_PushInput: file variable-already-defined.tmp, line 1 +# expect: Skipping 'variable-already-defined.tmp' because 'VARIABLE_ALREADY_DEFINED' is defined + +# If the guard variable is defined before the file is included the first time, +# the file is processed but its content is skipped. If that same guard +# variable is undefined when the file is included the second time, the file is +# processed as usual. +CASES+= variable-defined-then-undefined +LINES.variable-defined-then-undefined= \ + '.ifndef VARIABLE_DEFINED_THEN_UNDEFINED' \ + '.endif' +VARIABLE_DEFINED_THEN_UNDEFINED= +UNDEF_BETWEEN.variable-defined-then-undefined= \ + VARIABLE_DEFINED_THEN_UNDEFINED +# expect: Parse_PushInput: file variable-defined-then-undefined.tmp, line 1 +# expect: Parse_PushInput: file variable-defined-then-undefined.tmp, line 1 + +# The whole file content must be guarded by a single '.if' conditional, not by +# several, as each of these conditionals would require its separate guard. +# This case is not expected to occur in practice, as the two parts would +# rather be split into separate files. +CASES+= variable-two-times +LINES.variable-two-times= \ + '.ifndef VARIABLE_TWO_TIMES_1' \ + 'VARIABLE_TWO_TIMES_1=' \ + '.endif' \ + '.ifndef VARIABLE_TWO_TIMES_2' \ + 'VARIABLE_TWO_TIMES_2=' \ + '.endif' +# expect: Parse_PushInput: file variable-two-times.tmp, line 1 +# expect: Parse_PushInput: file variable-two-times.tmp, line 1 + +# When multiple files use the same guard variable name, the optimization of +# skipping the file affects each of these files. +# +# Choosing unique guard names is the responsibility of the makefile authors. +# A typical pattern of guard variable names is '${PROJECT}_${DIR}_${FILE}_MK'. +# System-provided files typically start the guard names with '_'. +CASES+= variable-clash +LINES.variable-clash= \ + ${LINES.variable-if} +# expect: Parse_PushInput: file variable-clash.tmp, line 1 +# expect: Skipping 'variable-clash.tmp' because 'VARIABLE_IF' is defined + +# The conditional must come before the assignment, otherwise the conditional +# is useless, as it always evaluates to false. +CASES+= variable-swapped +LINES.variable-swapped= \ + 'SWAPPED=' \ + '.ifndef SWAPPED' \ + '. error' \ + '.endif' +# expect: Parse_PushInput: file variable-swapped.tmp, line 1 +# expect: Parse_PushInput: file variable-swapped.tmp, line 1 + +# If the guard variable is undefined between the first and the second time the +# file is included, the guarded file is included again. +CASES+= variable-undef-between +LINES.variable-undef-between= \ + '.ifndef VARIABLE_UNDEF_BETWEEN' \ + 'VARIABLE_UNDEF_BETWEEN=' \ + '.endif' +UNDEF_BETWEEN.variable-undef-between= \ + VARIABLE_UNDEF_BETWEEN +# expect: Parse_PushInput: file variable-undef-between.tmp, line 1 +# expect: Parse_PushInput: file variable-undef-between.tmp, line 1 + +# If the guard variable is undefined while the file is included the first +# time, the guard does not have an effect, and the file is included again. +CASES+= variable-undef-inside +LINES.variable-undef-inside= \ + '.ifndef VARIABLE_UNDEF_INSIDE' \ + 'VARIABLE_UNDEF_INSIDE=' \ + '.undef VARIABLE_UNDEF_INSIDE' \ + '.endif' +# expect: Parse_PushInput: file variable-undef-inside.tmp, line 1 +# expect: Parse_PushInput: file variable-undef-inside.tmp, line 1 + +# If the file does not define the guard variable, the guard does not have an +# effect, and the file is included again. +CASES+= variable-not-defined +LINES.variable-not-defined= \ + '.ifndef VARIABLE_NOT_DEFINED' \ + '.endif' +# expect: Parse_PushInput: file variable-not-defined.tmp, line 1 +# expect: Parse_PushInput: file variable-not-defined.tmp, line 1 + +# The outermost '.if' must not have an '.elif' branch. +CASES+= elif +LINES.elif= \ + '.ifndef ELIF' \ + 'ELIF=' \ + '.elif 1' \ + '.endif' +# expect: Parse_PushInput: file elif.tmp, line 1 +# expect: Parse_PushInput: file elif.tmp, line 1 + +# When a file with an '.if/.elif/.endif' conditional at the top level is +# included, it is never optimized, as one of its branches is taken. +CASES+= elif-reuse +LINES.elif-reuse= \ + '.ifndef ELIF' \ + 'syntax error' \ + '.elif 1' \ + '.endif' +# expect: Parse_PushInput: file elif-reuse.tmp, line 1 +# expect: Parse_PushInput: file elif-reuse.tmp, line 1 + +# The outermost '.if' must not have an '.else' branch. +CASES+= else +LINES.else= \ + '.ifndef ELSE' \ + 'ELSE=' \ + '.else' \ + '.endif' +# expect: Parse_PushInput: file else.tmp, line 1 +# expect: Parse_PushInput: file else.tmp, line 1 + +# When a file with an '.if/.else/.endif' conditional at the top level is +# included, it is never optimized, as one of its branches is taken. +CASES+= else-reuse +LINES.else-reuse= \ + '.ifndef ELSE' \ + 'syntax error' \ + '.else' \ + '.endif' +# expect: Parse_PushInput: file else-reuse.tmp, line 1 +# expect: Parse_PushInput: file else-reuse.tmp, line 1 + +# The inner '.if' directives may have an '.elif' or '.else', and it doesn't +# matter which of their branches are taken. +CASES+= inner-if-elif-else +LINES.inner-if-elif-else= \ + '.ifndef INNER_IF_ELIF_ELSE' \ + 'INNER_IF_ELIF_ELSE=' \ + '. if 0' \ + '. elif 0' \ + '. else' \ + '. endif' \ + '. if 0' \ + '. elif 1' \ + '. else' \ + '. endif' \ + '. if 1' \ + '. elif 1' \ + '. else' \ + '. endif' \ + '.endif' +# expect: Parse_PushInput: file inner-if-elif-else.tmp, line 1 +# expect: Skipping 'inner-if-elif-else.tmp' because 'INNER_IF_ELIF_ELSE' is defined + +# The guard can also be a target instead of a variable. Using a target as a +# guard has the benefit that a target cannot be undefined once it is defined. +# The target should be declared '.NOTMAIN'. Since the target names are +# usually chosen according to a pattern that doesn't interfere with real +# target names, they don't need to be declared '.PHONY' as they don't generate +# filesystem operations. +CASES+= target +LINES.target= \ + '.if !target(__target.tmp__)' \ + '__target.tmp__: .NOTMAIN' \ + '.endif' +# expect: Parse_PushInput: file target.tmp, line 1 +# expect: Skipping 'target.tmp' because '__target.tmp__' is defined + +# When used for system files, the target name may include '<' and '>', for +# symmetry with the '.include <sys.mk>' directive. The characters '<' and '>' +# are ordinary characters. +CASES+= target-sys +LINES.target-sys= \ + '.if !target(__<target-sys.tmp>__)' \ + '__<target-sys.tmp>__: .NOTMAIN' \ + '.endif' +# expect: Parse_PushInput: file target-sys.tmp, line 1 +# expect: Skipping 'target-sys.tmp' because '__<target-sys.tmp>__' is defined + +# The target name may include variable references. These references are +# expanded as usual. Due to the current implementation, the expressions are +# evaluated twice: Once for checking whether the condition evaluates to true, +# and once for determining the guard name. This double evaluation should not +# matter in practice, as guard expressions are expected to be simple, +# deterministic and without side effects. +CASES+= target-indirect +LINES.target-indirect= \ + '.if !target($${target-indirect.tmp:L})' \ + 'target-indirect.tmp: .NOTMAIN' \ + '.endif' +# expect: Parse_PushInput: file target-indirect.tmp, line 1 +# expect: Skipping 'target-indirect.tmp' because 'target-indirect.tmp' is defined + +# A common form of guard target is __${.PARSEFILE}__. This form can only be +# used if all files using this form have unique basenames. To get a robust +# pattern based on the same idea, use __${.PARSEDIR}/${.PARSEFILE}__ instead. +# This form does not work when the basename contains whitespace characters, as +# it is not possible to define a target with whitespace, not even by cheating. +CASES+= target-indirect-PARSEFILE +LINES.target-indirect-PARSEFILE= \ + '.if !target(__$${.PARSEFILE}__)' \ + '__$${.PARSEFILE}__: .NOTMAIN' \ + '.endif' +# expect: Parse_PushInput: file target-indirect-PARSEFILE.tmp, line 1 +# expect: Skipping 'target-indirect-PARSEFILE.tmp' because '__target-indirect-PARSEFILE.tmp__' is defined + +# Two files with different basenames can both use the same syntactic pattern +# for the target guard name, as the expressions expand to different strings. +CASES+= target-indirect-PARSEFILE2 +LINES.target-indirect-PARSEFILE2= \ + '.if !target(__$${.PARSEFILE}__)' \ + '__$${.PARSEFILE}__: .NOTMAIN' \ + '.endif' +# expect: Parse_PushInput: file target-indirect-PARSEFILE2.tmp, line 1 +# expect: Skipping 'target-indirect-PARSEFILE2.tmp' because '__target-indirect-PARSEFILE2.tmp__' is defined + +# Using plain .PARSEFILE without .PARSEDIR leads to name clashes. The include +# guard is the same as in the test case 'target-indirect-PARSEFILE', as the +# guard name only contains the basename but not the directory name. So even +# without defining the guard target, the file is considered guarded. +CASES+= subdir/target-indirect-PARSEFILE +LINES.subdir/target-indirect-PARSEFILE= \ + '.if !target(__$${.PARSEFILE}__)' \ + '.endif' +# expect: Parse_PushInput: file subdir/target-indirect-PARSEFILE.tmp, line 1 +# expect: Skipping 'subdir/target-indirect-PARSEFILE.tmp' because '__target-indirect-PARSEFILE.tmp__' is defined + +# Another common form of guard target is __${.PARSEDIR}/${.PARSEFILE}__ +# or __${.PARSEDIR:tA}/${.PARSEFILE}__ to be truly unique. +CASES+= target-indirect-PARSEDIR-PARSEFILE +LINES.target-indirect-PARSEDIR-PARSEFILE= \ + '.if !target(__$${.PARSEDIR}/$${.PARSEFILE}__)' \ + '__$${.PARSEDIR}/$${.PARSEFILE}__: .NOTMAIN' \ + '.endif' +# expect: Parse_PushInput: file target-indirect-PARSEDIR-PARSEFILE.tmp, line 1 +# expect: Skipping 'target-indirect-PARSEDIR-PARSEFILE.tmp' because '__target-indirect-PARSEDIR-PARSEFILE.tmp__' is defined +# The actual target starts with '__${.OBJDIR}/', see the .rawout file, but the +# string '${.OBJDIR}/' gets stripped in post processing. + +# Using the combination of '.PARSEDIR' and '.PARSEFILE', a file in a +# subdirectory gets a different guard target name than the previous one. +CASES+= subdir/target-indirect-PARSEDIR-PARSEFILE +LINES.subdir/target-indirect-PARSEDIR-PARSEFILE= \ + '.if !target(__$${.PARSEDIR}/$${.PARSEFILE}__)' \ + '__$${.PARSEDIR}/$${.PARSEFILE}__: .NOTMAIN' \ + '.endif' +# expect: Parse_PushInput: file subdir/target-indirect-PARSEDIR-PARSEFILE.tmp, line 1 +# expect: Skipping 'subdir/target-indirect-PARSEDIR-PARSEFILE.tmp' because '__subdir/target-indirect-PARSEDIR-PARSEFILE.tmp__' is defined +# The actual target starts with '__${.OBJDIR}/', see the .rawout file, but the +# string '${.OBJDIR}/' gets stripped in post processing. + +# If the guard target is not defined when including the file the next time, +# the file is processed again. +CASES+= target-unguarded +LINES.target-unguarded= \ + '.if !target(target-unguarded)' \ + '.endif' +# expect: Parse_PushInput: file target-unguarded.tmp, line 1 +# expect: Parse_PushInput: file target-unguarded.tmp, line 1 + +# The guard condition must consist of only the guard target, nothing else. +CASES+= target-plus +LINES.target-plus= \ + '.if !target(target-plus) && 1' \ + 'target-plus: .NOTMAIN' \ + '.endif' +# expect: Parse_PushInput: file target-plus.tmp, line 1 +# expect: Parse_PushInput: file target-plus.tmp, line 1 + +# If the guard target is defined before the file is included the first time, +# the file is read once and then considered guarded. +CASES+= target-already-defined +LINES.target-already-defined= \ + '.if !target(target-already-defined)' \ + 'target-already-defined: .NOTMAIN' \ + '.endif' +target-already-defined: .NOTMAIN +# expect: Parse_PushInput: file target-already-defined.tmp, line 1 +# expect: Skipping 'target-already-defined.tmp' because 'target-already-defined' is defined + +# A target name cannot contain the character '!'. In the condition, the '!' +# is syntactically valid, but in the dependency declaration line, the '!' is +# interpreted as the '!' dependency operator, no matter whether it occurs at +# the beginning or in the middle of a target name. Escaping it as '${:U!}' +# doesn't work, as the whole line is first expanded and then scanned for the +# dependency operator. Escaping it as '\!' doesn't work either, even though +# the '\' escapes the '!' from being a dependency operator, but when reading +# the target name, the '\' is kept, resulting in the target name +# '\!target-name-exclamation' instead of '!target-name-exclamation'. +CASES+= target-name-exclamation +LINES.target-name-exclamation= \ + '.if !target(!target-name-exclamation)' \ + '\!target-name-exclamation: .NOTMAIN' \ + '.endif' +# expect: Parse_PushInput: file target-name-exclamation.tmp, line 1 +# expect: Parse_PushInput: file target-name-exclamation.tmp, line 1 + +# If the guard target name is enclosed in spaces, it does not have an effect, +# as that form is not common in practice. +CASES+= target-name-parenthesized +LINES.target-name-parenthesized= \ + '.if !target( target-name-parenthesized )' \ + 'target-name-parenthesized: .NOTMAIN' \ + '.endif' +# expect: Parse_PushInput: file target-name-parenthesized.tmp, line 1 +# expect: Parse_PushInput: file target-name-parenthesized.tmp, line 1 + +# If the guard target condition is enclosed in parentheses, it does not have +# an effect, as that form is not common in practice. +CASES+= target-call-parenthesized +LINES.target-call-parenthesized= \ + '.if (!target(target-call-parenthesized))' \ + 'target-call-parenthesized: .NOTMAIN' \ + '.endif' +# expect: Parse_PushInput: file target-call-parenthesized.tmp, line 1 +# expect: Parse_PushInput: file target-call-parenthesized.tmp, line 1 + +# If the '.if' or '.ifndef' directive spans more than a single line, it is +# still recognized as a guard condition. This case is entirely uncommon, but +# at the point where the guard condition is checked, line continuations have +# already been converted to spaces. +CASES+= multiline +LINES.multiline= \ + '.\' \ + ' ifndef \' \ + ' MULTILINE' \ + 'MULTILINE=' \ + '.endif' +# expect: Parse_PushInput: file multiline.tmp, line 1 +# expect: Skipping 'multiline.tmp' because 'MULTILINE' is defined + + +# Now run all test cases by including each of the files twice and looking at +# the debug output. The files that properly guard against multiple inclusion +# generate a 'Skipping' line, the others repeat the 'Parse_PushInput' line. +# +# Some debug output lines are suppressed in the .exp file, see ./Makefile. +.for i in ${CASES} +. for fname in $i.tmp +_:= ${fname:H:N.:@dir@${:!mkdir -p ${dir}!}@} +_!= printf '%s\n' ${LINES.$i} > ${fname} +.MAKEFLAGS: -dp +.include "${.CURDIR}/${fname}" +.undef ${UNDEF_BETWEEN.$i:U} +.include "${.CURDIR}/${fname}" +.MAKEFLAGS: -d0 +_!= rm ${fname} +_:= ${fname:H:N.:@dir@${:!rmdir ${dir}!}@} +. endfor +.endfor + +all: diff --git a/contrib/bmake/unit-tests/directive-include.exp b/contrib/bmake/unit-tests/directive-include.exp index 0ddf40a75d2d..de94b751b33a 100755 --- a/contrib/bmake/unit-tests/directive-include.exp +++ b/contrib/bmake/unit-tests/directive-include.exp @@ -2,12 +2,12 @@ CondParser_Eval: ${.MAKE.MAKEFILES:T} != "${.PARSEFILE} null" Comparing "directive-include.mk null" != "directive-include.mk null" CondParser_Eval: ${.MAKE.MAKEFILES:T} != "${.PARSEFILE} null" Comparing "directive-include.mk null" != "directive-include.mk null" -make: "directive-include.mk" line 25: Could not find nonexistent.mk -make: "directive-include.mk" line 47: Could not find " -make: "directive-include.mk" line 52: Unknown modifier "Z" -make: "directive-include.mk" line 52: Could not find nonexistent.mk -make: "directive-include.mk" line 57: Cannot open /nonexistent -make: "directive-include.mk" line 62: Invalid line type +make: "directive-include.mk" line 26: Could not find nonexistent.mk +make: "directive-include.mk" line 49: Could not find " +make: "directive-include.mk" line 56: Unknown modifier "Z" +make: "directive-include.mk" line 56: Could not find nonexistent.mk +make: "directive-include.mk" line 61: Cannot open /nonexistent +make: "directive-include.mk" line 66: Invalid line 'include' make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/directive-include.mk b/contrib/bmake/unit-tests/directive-include.mk index edf27d02483e..2517b4be6930 100755 --- a/contrib/bmake/unit-tests/directive-include.mk +++ b/contrib/bmake/unit-tests/directive-include.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-include.mk,v 1.11 2022/01/15 12:35:18 rillig Exp $ +# $NetBSD: directive-include.mk,v 1.13 2023/08/19 10:52:14 rillig Exp $ # # Tests for the .include directive, which includes another file. @@ -22,6 +22,7 @@ . error .endif +# expect+1: Could not find nonexistent.mk .include "nonexistent.mk" .include "/dev/null" # size 0 # including a directory technically succeeds, but shouldn't. @@ -44,11 +45,14 @@ DEV= null # would be empty, and the closing '"' would be in the trailing part of the # line, which is ignored as of 2021-12-03. DQUOT= " +# expect+1: Could not find " .include "${DQUOT}" # When the expression in a filename cannot be evaluated, the failing # expression is skipped and the file is included nevertheless. # FIXME: Add proper error handling, no file must be included here. +# expect+2: Could not find nonexistent.mk +# expect+1: Unknown modifier "Z" .include "nonexistent${:U123:Z}.mk" # The traditional include directive is seldom used. @@ -58,7 +62,7 @@ include /nonexistent # comment sinclude /nonexistent # comment include ${:U/dev/null} # comment include /dev/null /dev/null -# expect+1: Invalid line type +# expect+1: Invalid line 'include' include # XXX: trailing whitespace in diagnostic, missing quotes around filename diff --git a/contrib/bmake/unit-tests/directive-info.exp b/contrib/bmake/unit-tests/directive-info.exp index 70def02441d1..397d9d31ef38 100644 --- a/contrib/bmake/unit-tests/directive-info.exp +++ b/contrib/bmake/unit-tests/directive-info.exp @@ -1,15 +1,15 @@ -make: "directive-info.mk" line 11: begin .info tests -make: "directive-info.mk" line 12: Unknown directive "inf" -make: "directive-info.mk" line 13: Missing argument for ".info" -make: "directive-info.mk" line 14: message -make: "directive-info.mk" line 15: indented message -make: "directive-info.mk" line 16: Unknown directive "information" -make: "directive-info.mk" line 17: Unknown directive "information" -make: "directive-info.mk" line 22: Missing argument for ".info" -make: "directive-info.mk" line 23: Missing argument for ".info" -make: "directive-info.mk" line 26: Unknown directive "info-message" -make: "directive-info.mk" line 27: no-target: no-source -make: "directive-info.mk" line 35: expect line 35 for multi-line message +make: "directive-info.mk" line 12: begin .info tests +make: "directive-info.mk" line 14: Unknown directive "inf" +make: "directive-info.mk" line 16: Missing argument for ".info" +make: "directive-info.mk" line 18: message +make: "directive-info.mk" line 20: indented message +make: "directive-info.mk" line 22: Unknown directive "information" +make: "directive-info.mk" line 24: Unknown directive "information" +make: "directive-info.mk" line 30: Missing argument for ".info" +make: "directive-info.mk" line 32: Missing argument for ".info" +make: "directive-info.mk" line 36: Unknown directive "info-message" +make: "directive-info.mk" line 38: no-target: no-source +make: "directive-info.mk" line 47: expect line 35 for multi-line message make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/directive-info.mk b/contrib/bmake/unit-tests/directive-info.mk index 54f6a0f5aad0..ab550555d44f 100644 --- a/contrib/bmake/unit-tests/directive-info.mk +++ b/contrib/bmake/unit-tests/directive-info.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-info.mk,v 1.9 2022/01/08 20:21:34 rillig Exp $ +# $NetBSD: directive-info.mk,v 1.11 2023/06/01 20:56:35 rillig Exp $ # # Tests for the .info directive. # @@ -8,22 +8,33 @@ # TODO: Implementation +# expect+1: begin .info tests .info begin .info tests +# expect+1: Unknown directive "inf" .inf # misspelled -.info # "Missing argument" +# expect+1: Missing argument for ".info" +.info +# expect+1: message .info message +# expect+1: indented message .info indented message +# expect+1: Unknown directive "information" .information +# expect+1: Unknown directive "information" .information message # Accepted before 2020-12-13 01:07:54. .info.man: # not a message, but possibly a suffix rule # Even if lines would have trailing whitespace, this would be trimmed by -# ParseGetLine. +# ParseRawLine. +# expect+1: Missing argument for ".info" .info +# expect+1: Missing argument for ".info" .info # comment .info: message # This is a dependency declaration. +# expect+1: Unknown directive "info-message" .info-message # This is an unknown directive. +# expect+1: no-target: no-source .info no-target: no-source # This is a .info directive, not a dependency. # See directive.mk for more tests of this kind. @@ -32,9 +43,7 @@ # number of completely read lines. For the following multi-line directive, # this meant that the reported line number was the one of the last line, not # of the first line. +# expect+1: expect line 35 for multi-line message .info expect line 35 for\ multi$\ -line message - -all: - @:; diff --git a/contrib/bmake/unit-tests/directive-misspellings.exp b/contrib/bmake/unit-tests/directive-misspellings.exp index e51d8473b305..a00615926740 100644 --- a/contrib/bmake/unit-tests/directive-misspellings.exp +++ b/contrib/bmake/unit-tests/directive-misspellings.exp @@ -1,45 +1,45 @@ -make: "directive-misspellings.mk" line 12: Unknown directive "dinclud" -make: "directive-misspellings.mk" line 14: Unknown directive "dincludx" -make: "directive-misspellings.mk" line 15: .include filename must be delimited by '"' or '<' -make: "directive-misspellings.mk" line 17: Unknown directive "erro" -make: "directive-misspellings.mk" line 18: Unknown directive "errox" -make: "directive-misspellings.mk" line 22: Unknown directive "expor" -make: "directive-misspellings.mk" line 24: Unknown directive "exporx" -make: "directive-misspellings.mk" line 25: Unknown directive "exports" -make: "directive-misspellings.mk" line 27: Unknown directive "export-en" -make: "directive-misspellings.mk" line 30: Unknown directive "export-environment" -make: "directive-misspellings.mk" line 32: Unknown directive "export-litera" -make: "directive-misspellings.mk" line 34: Unknown directive "export-literax" -make: "directive-misspellings.mk" line 35: Unknown directive "export-literally" -make: "directive-misspellings.mk" line 37: Unknown directive "-includ" -make: "directive-misspellings.mk" line 39: Unknown directive "-includx" -make: "directive-misspellings.mk" line 40: .include filename must be delimited by '"' or '<' -make: "directive-misspellings.mk" line 42: Unknown directive "includ" -make: "directive-misspellings.mk" line 43: Could not find file -make: "directive-misspellings.mk" line 44: Unknown directive "includx" -make: "directive-misspellings.mk" line 45: .include filename must be delimited by '"' or '<' -make: "directive-misspellings.mk" line 47: Unknown directive "inf" -make: "directive-misspellings.mk" line 48: msg -make: "directive-misspellings.mk" line 49: Unknown directive "infx" -make: "directive-misspellings.mk" line 50: Unknown directive "infos" -make: "directive-misspellings.mk" line 52: Unknown directive "sinclud" -make: "directive-misspellings.mk" line 54: Unknown directive "sincludx" -make: "directive-misspellings.mk" line 55: .include filename must be delimited by '"' or '<' -make: "directive-misspellings.mk" line 57: Unknown directive "unde" -make: "directive-misspellings.mk" line 59: Unknown directive "undex" -make: "directive-misspellings.mk" line 60: Unknown directive "undefs" -make: "directive-misspellings.mk" line 62: Unknown directive "unexpor" -make: "directive-misspellings.mk" line 64: Unknown directive "unexporx" -make: "directive-misspellings.mk" line 65: Unknown directive "unexports" -make: "directive-misspellings.mk" line 67: Unknown directive "unexport-en" -make: "directive-misspellings.mk" line 69: The directive .unexport-env does not take arguments -make: "directive-misspellings.mk" line 70: Unknown directive "unexport-enx" -make: "directive-misspellings.mk" line 71: Unknown directive "unexport-envs" -make: "directive-misspellings.mk" line 73: Unknown directive "warn" -make: "directive-misspellings.mk" line 74: Unknown directive "warnin" -make: "directive-misspellings.mk" line 75: warning: msg -make: "directive-misspellings.mk" line 76: Unknown directive "warninx" -make: "directive-misspellings.mk" line 77: Unknown directive "warnings" +make: "directive-misspellings.mk" line 13: Unknown directive "dinclud" +make: "directive-misspellings.mk" line 16: Unknown directive "dincludx" +make: "directive-misspellings.mk" line 18: .include filename must be delimited by '"' or '<' +make: "directive-misspellings.mk" line 21: Unknown directive "erro" +make: "directive-misspellings.mk" line 23: Unknown directive "errox" +make: "directive-misspellings.mk" line 28: Unknown directive "expor" +make: "directive-misspellings.mk" line 31: Unknown directive "exporx" +make: "directive-misspellings.mk" line 33: Unknown directive "exports" +make: "directive-misspellings.mk" line 36: Unknown directive "export-en" +make: "directive-misspellings.mk" line 40: Unknown directive "export-environment" +make: "directive-misspellings.mk" line 43: Unknown directive "export-litera" +make: "directive-misspellings.mk" line 46: Unknown directive "export-literax" +make: "directive-misspellings.mk" line 48: Unknown directive "export-literally" +make: "directive-misspellings.mk" line 51: Unknown directive "-includ" +make: "directive-misspellings.mk" line 54: Unknown directive "-includx" +make: "directive-misspellings.mk" line 56: .include filename must be delimited by '"' or '<' +make: "directive-misspellings.mk" line 59: Unknown directive "includ" +make: "directive-misspellings.mk" line 61: Could not find file +make: "directive-misspellings.mk" line 63: Unknown directive "includx" +make: "directive-misspellings.mk" line 65: .include filename must be delimited by '"' or '<' +make: "directive-misspellings.mk" line 68: Unknown directive "inf" +make: "directive-misspellings.mk" line 70: msg +make: "directive-misspellings.mk" line 72: Unknown directive "infx" +make: "directive-misspellings.mk" line 74: Unknown directive "infos" +make: "directive-misspellings.mk" line 77: Unknown directive "sinclud" +make: "directive-misspellings.mk" line 80: Unknown directive "sincludx" +make: "directive-misspellings.mk" line 82: .include filename must be delimited by '"' or '<' +make: "directive-misspellings.mk" line 85: Unknown directive "unde" +make: "directive-misspellings.mk" line 88: Unknown directive "undex" +make: "directive-misspellings.mk" line 90: Unknown directive "undefs" +make: "directive-misspellings.mk" line 93: Unknown directive "unexpor" +make: "directive-misspellings.mk" line 96: Unknown directive "unexporx" +make: "directive-misspellings.mk" line 98: Unknown directive "unexports" +make: "directive-misspellings.mk" line 101: Unknown directive "unexport-en" +make: "directive-misspellings.mk" line 104: The directive .unexport-env does not take arguments +make: "directive-misspellings.mk" line 106: Unknown directive "unexport-enx" +make: "directive-misspellings.mk" line 108: Unknown directive "unexport-envs" +make: "directive-misspellings.mk" line 111: Unknown directive "warn" +make: "directive-misspellings.mk" line 113: Unknown directive "warnin" +make: "directive-misspellings.mk" line 115: warning: msg +make: "directive-misspellings.mk" line 117: Unknown directive "warninx" +make: "directive-misspellings.mk" line 119: Unknown directive "warnings" make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/directive-misspellings.mk b/contrib/bmake/unit-tests/directive-misspellings.mk index 5f479f03b7f1..0014076d041f 100644 --- a/contrib/bmake/unit-tests/directive-misspellings.mk +++ b/contrib/bmake/unit-tests/directive-misspellings.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-misspellings.mk,v 1.3 2020/12/13 01:10:22 rillig Exp $ +# $NetBSD: directive-misspellings.mk,v 1.4 2023/06/01 20:56:35 rillig Exp $ # # Tests for misspelled directives. # @@ -9,71 +9,111 @@ # ".information" were aliases to ".info" since the code for these diagnostic # directives just skipped any letters following the "error", "warn" or "info". +# expect+1: Unknown directive "dinclud" .dinclud "file" .dinclude "file" +# expect+1: Unknown directive "dincludx" .dincludx "file" +# expect+1: .include filename must be delimited by '"' or '<' .dincludes "file" # XXX: the 's' is not meant to be a filename +# expect+1: Unknown directive "erro" .erro msg +# expect+1: Unknown directive "errox" .errox msg # no .error since that would exit immediately # no .errors since that would exit immediately, even with the typo +# expect+1: Unknown directive "expor" .expor varname .export varname +# expect+1: Unknown directive "exporx" .exporx varname +# expect+1: Unknown directive "exports" .exports varname # Accepted before 2020-12-13 01:07:54. +# expect+1: Unknown directive "export-en" .export-en # Accepted before 2020-12-13 01:07:54. .export-env .export-env extra argument # XXX: undetected extra argument +# expect+1: Unknown directive "export-environment" .export-environment # Accepted before 2020-12-13 01:07:54. +# expect+1: Unknown directive "export-litera" .export-litera varname # Accepted before 2020-12-13 01:07:54. .export-literal varname +# expect+1: Unknown directive "export-literax" .export-literax varname # Accepted before 2020-12-13 01:07:54. +# expect+1: Unknown directive "export-literally" .export-literally varname # Accepted before 2020-12-13 01:07:54. +# expect+1: Unknown directive "-includ" .-includ "file" .-include "file" +# expect+1: Unknown directive "-includx" .-includx "file" +# expect+1: .include filename must be delimited by '"' or '<' .-includes "file" # XXX: the 's' is not meant to be a filename +# expect+1: Unknown directive "includ" .includ "file" +# expect+1: Could not find file .include "file" +# expect+1: Unknown directive "includx" .includx "file" +# expect+1: .include filename must be delimited by '"' or '<' .includex "file" # XXX: the 's' is not meant to be a filename +# expect+1: Unknown directive "inf" .inf msg +# expect+1: msg .info msg +# expect+1: Unknown directive "infx" .infx msg +# expect+1: Unknown directive "infos" .infos msg # Accepted before 2020-12-13 01:07:54. +# expect+1: Unknown directive "sinclud" .sinclud "file" .sinclude "file" +# expect+1: Unknown directive "sincludx" .sincludx "file" +# expect+1: .include filename must be delimited by '"' or '<' .sincludes "file" # XXX: the 's' is not meant to be a filename +# expect+1: Unknown directive "unde" .unde varname .undef varname +# expect+1: Unknown directive "undex" .undex varname +# expect+1: Unknown directive "undefs" .undefs varname # Accepted before 2020-12-13 01:07:54. +# expect+1: Unknown directive "unexpor" .unexpor varname .unexport varname +# expect+1: Unknown directive "unexporx" .unexporx varname +# expect+1: Unknown directive "unexports" .unexports varname # Accepted before 2020-12-12 18:00:18. +# expect+1: Unknown directive "unexport-en" .unexport-en # Accepted before 2020-12-12 18:11:42. .unexport-env +# expect+1: The directive .unexport-env does not take arguments .unexport-env extra argument # Accepted before 2020-12-12 18:00:18. +# expect+1: Unknown directive "unexport-enx" .unexport-enx # Accepted before 2020-12-12 18:00:18. +# expect+1: Unknown directive "unexport-envs" .unexport-envs # Accepted before 2020-12-12 18:00:18. +# expect+1: Unknown directive "warn" .warn msg +# expect+1: Unknown directive "warnin" .warnin msg +# expect+1: warning: msg .warning msg +# expect+1: Unknown directive "warninx" .warninx msg +# expect+1: Unknown directive "warnings" .warnings msg # Accepted before 2020-12-13 01:07:54. - -all: diff --git a/contrib/bmake/unit-tests/directive-sinclude.exp b/contrib/bmake/unit-tests/directive-sinclude.exp index ffdfefca0d4f..5e8ecd710dc6 100755 --- a/contrib/bmake/unit-tests/directive-sinclude.exp +++ b/contrib/bmake/unit-tests/directive-sinclude.exp @@ -1,4 +1,4 @@ -make: "directive-include-error.inc" line 1: Invalid line type +make: "directive-include-error.inc" line 1: Invalid line 'syntax error' make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/directive-sinclude.mk b/contrib/bmake/unit-tests/directive-sinclude.mk index a935ea2c068f..58912c644a7e 100755 --- a/contrib/bmake/unit-tests/directive-sinclude.mk +++ b/contrib/bmake/unit-tests/directive-sinclude.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-sinclude.mk,v 1.4 2022/01/23 21:48:59 rillig Exp $ +# $NetBSD: directive-sinclude.mk,v 1.5 2023/08/19 10:52:14 rillig Exp $ # # Tests for the .sinclude directive, which includes another file, # silently skipping it if it cannot be opened. @@ -15,7 +15,7 @@ .sinclude "${MAKEFILE}/subdir" # Errors that are not related to opening the file are still reported. -# expect: make: "directive-include-error.inc" line 1: Invalid line type +# expect: make: "directive-include-error.inc" line 1: Invalid line 'syntax error' _!= echo 'syntax error' > directive-include-error.inc .sinclude "${.CURDIR}/directive-include-error.inc" _!= rm directive-include-error.inc diff --git a/contrib/bmake/unit-tests/directive-undef.exp b/contrib/bmake/unit-tests/directive-undef.exp index 20df58a8dc73..f3957a990e18 100644 --- a/contrib/bmake/unit-tests/directive-undef.exp +++ b/contrib/bmake/unit-tests/directive-undef.exp @@ -1,6 +1,6 @@ -make: "directive-undef.mk" line 29: The .undef directive requires an argument -make: "directive-undef.mk" line 86: Unknown modifier "Z" -make: "directive-undef.mk" line 102: warning: UT_EXPORTED is still listed in .MAKE.EXPORTED even though spaceit is not exported anymore. +make: "directive-undef.mk" line 30: The .undef directive requires an argument +make: "directive-undef.mk" line 88: Unknown modifier "Z" +make: "directive-undef.mk" line 105: warning: UT_EXPORTED is still listed in .MAKE.EXPORTED even though spaceit is not exported anymore. make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/directive-undef.mk b/contrib/bmake/unit-tests/directive-undef.mk index 5ac7d939c71e..ef047fefe177 100644 --- a/contrib/bmake/unit-tests/directive-undef.mk +++ b/contrib/bmake/unit-tests/directive-undef.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-undef.mk,v 1.12 2022/03/26 12:44:57 rillig Exp $ +# $NetBSD: directive-undef.mk,v 1.13 2023/06/01 20:56:35 rillig Exp $ # # Tests for the .undef directive. # @@ -26,6 +26,7 @@ # to delete the variable with the empty name, which never exists; see # varname-empty.mk. Since var.c 1.737 from 2020-12-19, .undef complains # about a missing argument. +# expect+1: The .undef directive requires an argument .undef @@ -83,6 +84,7 @@ ${DOLLAR}= dollar # # As of var.c 1.762, this doesn't happen though because the error handling # in Var_Parse and Var_Subst is not done properly. +# expect+1: Unknown modifier "Z" .undef ${VARNAMES:L:Z} @@ -99,6 +101,7 @@ UT_EXPORTED= exported-value . error .endif .if ${.MAKE.EXPORTED:MUT_EXPORTED} +# expect+1: warning: UT_EXPORTED is still listed in .MAKE.EXPORTED even though spaceit is not exported anymore. . warning UT_EXPORTED is still listed in .MAKE.EXPORTED even though $\ it is not exported anymore. .endif diff --git a/contrib/bmake/unit-tests/directive-unexport-env.exp b/contrib/bmake/unit-tests/directive-unexport-env.exp index 22528c31c3a1..663034cee12c 100644 --- a/contrib/bmake/unit-tests/directive-unexport-env.exp +++ b/contrib/bmake/unit-tests/directive-unexport-env.exp @@ -1,9 +1,9 @@ -make: "directive-unexport-env.mk" line 13: Unknown directive "unexport-en" -make: "directive-unexport-env.mk" line 15: Unknown directive "unexport-environment" +make: "directive-unexport-env.mk" line 14: Unknown directive "unexport-en" +make: "directive-unexport-env.mk" line 17: Unknown directive "unexport-environment" Global: UT_EXPORTED = value Global: UT_UNEXPORTED = value Global: .MAKE.EXPORTED = UT_EXPORTED -make: "directive-unexport-env.mk" line 21: The directive .unexport-env does not take arguments +make: "directive-unexport-env.mk" line 24: The directive .unexport-env does not take arguments Var_Parse: ${.MAKE.EXPORTED:O:u} (eval) Evaluating modifier ${.MAKE.EXPORTED:O} on value "UT_EXPORTED" Result of ${.MAKE.EXPORTED:O} is "UT_EXPORTED" diff --git a/contrib/bmake/unit-tests/directive-unexport-env.mk b/contrib/bmake/unit-tests/directive-unexport-env.mk index e9620684dfcb..e56e47865011 100644 --- a/contrib/bmake/unit-tests/directive-unexport-env.mk +++ b/contrib/bmake/unit-tests/directive-unexport-env.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-unexport-env.mk,v 1.8 2022/01/23 16:09:38 rillig Exp $ +# $NetBSD: directive-unexport-env.mk,v 1.9 2023/06/01 20:56:35 rillig Exp $ # # Tests for the .unexport-env directive. # @@ -10,14 +10,17 @@ # TODO: Implementation +# expect+1: Unknown directive "unexport-en" .unexport-en # misspelled .unexport-env # ok +# expect+1: Unknown directive "unexport-environment" .unexport-environment # misspelled .MAKEFLAGS: -dv UT_EXPORTED= value UT_UNEXPORTED= value .export UT_EXPORTED +# expect+1: The directive .unexport-env does not take arguments .unexport-env UT_EXPORTED UT_UNEXPORTED .MAKEFLAGS: -d0 diff --git a/contrib/bmake/unit-tests/directive-unexport.exp b/contrib/bmake/unit-tests/directive-unexport.exp index d59fb4713259..b084daf5d147 100644 --- a/contrib/bmake/unit-tests/directive-unexport.exp +++ b/contrib/bmake/unit-tests/directive-unexport.exp @@ -1,5 +1,5 @@ -make: "directive-unexport.mk" line 18: UT_A=a UT_B=b UT_C=c -make: "directive-unexport.mk" line 19: UT_A UT_B UT_C -make: "directive-unexport.mk" line 27: UT_A=a UT_B=b UT_C=c -make: "directive-unexport.mk" line 28: +make: "directive-unexport.mk" line 19: UT_A=a UT_B=b UT_C=c +make: "directive-unexport.mk" line 21: UT_A UT_B UT_C +make: "directive-unexport.mk" line 30: UT_A=a UT_B=b UT_C=c +make: "directive-unexport.mk" line 31: exit status 0 diff --git a/contrib/bmake/unit-tests/directive-unexport.mk b/contrib/bmake/unit-tests/directive-unexport.mk index efc103efedf6..e759fe3e35f2 100644 --- a/contrib/bmake/unit-tests/directive-unexport.mk +++ b/contrib/bmake/unit-tests/directive-unexport.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-unexport.mk,v 1.7 2020/12/13 01:07:54 rillig Exp $ +# $NetBSD: directive-unexport.mk,v 1.8 2023/06/01 20:56:35 rillig Exp $ # # Tests for the .unexport directive. # @@ -15,7 +15,9 @@ UT_C= c .export UT_A UT_B UT_C # Show the exported variables and their values. +# expect+1: UT_A=a UT_B=b UT_C=c .info ${:!env|sort|grep '^UT_'!} +# expect+1: UT_A UT_B UT_C .info ${.MAKE.EXPORTED} # XXX: Now try to unexport all of them. The variables are still exported @@ -24,6 +26,7 @@ UT_C= c *= asterisk .unexport * +# expect+1: UT_A=a UT_B=b UT_C=c .info ${:!env|sort|grep '^UT_'!} .info ${.MAKE.EXPORTED} diff --git a/contrib/bmake/unit-tests/directive-warning.exp b/contrib/bmake/unit-tests/directive-warning.exp index 932b88a151e2..6fbeed91df0f 100644 --- a/contrib/bmake/unit-tests/directive-warning.exp +++ b/contrib/bmake/unit-tests/directive-warning.exp @@ -1,11 +1,11 @@ -make: "directive-warning.mk" line 9: Unknown directive "warn" make: "directive-warning.mk" line 10: Unknown directive "warn" -make: "directive-warning.mk" line 11: Unknown directive "warnin" -make: "directive-warning.mk" line 12: Unknown directive "warnin" -make: "directive-warning.mk" line 13: Missing argument for ".warning" -make: "directive-warning.mk" line 14: warning: message -make: "directive-warning.mk" line 15: Unknown directive "warnings" -make: "directive-warning.mk" line 16: Unknown directive "warnings" +make: "directive-warning.mk" line 12: Unknown directive "warn" +make: "directive-warning.mk" line 14: Unknown directive "warnin" +make: "directive-warning.mk" line 16: Unknown directive "warnin" +make: "directive-warning.mk" line 18: Missing argument for ".warning" +make: "directive-warning.mk" line 19: warning: message +make: "directive-warning.mk" line 21: Unknown directive "warnings" +make: "directive-warning.mk" line 23: Unknown directive "warnings" make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/directive-warning.mk b/contrib/bmake/unit-tests/directive-warning.mk index 9d5cec1ff0b8..bf0683f8911f 100644 --- a/contrib/bmake/unit-tests/directive-warning.mk +++ b/contrib/bmake/unit-tests/directive-warning.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-warning.mk,v 1.7 2022/01/23 16:09:38 rillig Exp $ +# $NetBSD: directive-warning.mk,v 1.9 2023/12/17 09:44:00 rillig Exp $ # # Tests for the .warning directive. # @@ -6,13 +6,20 @@ # produced the wrong error message "Unknown directive". Since parse.c 1.503 # from 2020-12-19, the correct "Missing argument" is produced. +# expect+1: Unknown directive "warn" .warn # misspelled +# expect+1: Unknown directive "warn" .warn message # misspelled +# expect+1: Unknown directive "warnin" .warnin # misspelled +# expect+1: Unknown directive "warnin" .warnin message # misspelled +# expect+1: Missing argument for ".warning" .warning # "Missing argument" -.warning message # expect+0: message +.warning message # expect+0: warning: message +# expect+1: Unknown directive "warnings" .warnings # misspelled +# expect+1: Unknown directive "warnings" .warnings messages # Accepted before 2020-12-13 01:07:54. all: .PHONY diff --git a/contrib/bmake/unit-tests/directive.exp b/contrib/bmake/unit-tests/directive.exp index d7d918fb24f3..cad8a9bb97e0 100644 --- a/contrib/bmake/unit-tests/directive.exp +++ b/contrib/bmake/unit-tests/directive.exp @@ -1,14 +1,14 @@ make: "directive.mk" line 10: Unknown directive "indented" make: "directive.mk" line 12: Unknown directive "indented" make: "directive.mk" line 14: Unknown directive "indented" -make: "directive.mk" line 21: Unknown directive "info" +make: "directive.mk" line 19: Unknown directive "" Global: .info = # (empty) Global: .info = value -make: "directive.mk" line 33: := value +make: "directive.mk" line 31: := value Global: .MAKEFLAGS = -r -k -d v -d Global: .MAKEFLAGS = -r -k -d v -d 0 -make: "directive.mk" line 42: Invalid line type -make: "directive.mk" line 45: Invalid line type +make: "directive.mk" line 40: Invalid line 'target-without-colon' +make: "directive.mk" line 43: Invalid line 'target-without-colon another-target' make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/directive.mk b/contrib/bmake/unit-tests/directive.mk index 365a070f8f30..61938360dfc7 100644 --- a/contrib/bmake/unit-tests/directive.mk +++ b/contrib/bmake/unit-tests/directive.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive.mk,v 1.6 2022/01/23 16:09:38 rillig Exp $ +# $NetBSD: directive.mk,v 1.9 2023/11/19 22:32:44 rillig Exp $ # # Tests for the preprocessing directives, such as .if or .info. @@ -13,11 +13,9 @@ # expect+1: Unknown directive "indented" . indented tab -# Directives must be written directly, not indirectly via variable +# Directives must be written directly, not indirectly via # expressions. -# FIXME: The error message is misleading because it shows the expanded text of -# the line, while the parser works on the unexpanded line. -# expect+1: Unknown directive "info" +# expect+1: Unknown directive "" .${:Uinfo} directives cannot be indirect # There is no directive called '.target', therefore this is parsed as a @@ -38,8 +36,8 @@ # Not even the space after the '.info' can change anything about this. .${:Uinfo} : source -# expect+1: Invalid line type +# expect+1: Invalid line 'target-without-colon' target-without-colon -# expect+1: Invalid line type +# expect+1: Invalid line 'target-without-colon another-target' target-without-colon another-target diff --git a/contrib/bmake/unit-tests/doterror.mk b/contrib/bmake/unit-tests/doterror.mk index d46fb3581a25..0f3698ad5cf2 100644 --- a/contrib/bmake/unit-tests/doterror.mk +++ b/contrib/bmake/unit-tests/doterror.mk @@ -1,4 +1,4 @@ -# $NetBSD: doterror.mk,v 1.2 2020/10/24 08:34:59 rillig Exp $ +# $NetBSD: doterror.mk,v 1.3 2023/06/01 20:56:35 rillig Exp $ .BEGIN: @@ -17,4 +17,3 @@ happy: sad: @echo and now: $@; exit 1 - diff --git a/contrib/bmake/unit-tests/error.exp b/contrib/bmake/unit-tests/error.exp index 3adc099a4625..e782664498bf 100644 --- a/contrib/bmake/unit-tests/error.exp +++ b/contrib/bmake/unit-tests/error.exp @@ -1,6 +1,6 @@ -make: "error.mk" line 6: just FYI -make: "error.mk" line 7: warning: this could be serious -make: "error.mk" line 8: this is fatal +make: "error.mk" line 7: just FYI +make: "error.mk" line 9: warning: this could be serious +make: "error.mk" line 11: this is fatal make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/error.mk b/contrib/bmake/unit-tests/error.mk index 0029b3bc6aa9..2383e60da6fb 100644 --- a/contrib/bmake/unit-tests/error.mk +++ b/contrib/bmake/unit-tests/error.mk @@ -1,10 +1,13 @@ -# $NetBSD: error.mk,v 1.3 2020/11/03 17:38:45 rillig Exp $ +# $NetBSD: error.mk,v 1.4 2023/06/01 20:56:35 rillig Exp $ # # Demonstrate that the .error directive exits immediately, without # continuing parsing until the end of the file. +# expect+1: just FYI .info just FYI +# expect+1: warning: this could be serious .warning this could be serious +# expect+1: this is fatal .error this is fatal .info this is not reached because of the .error above diff --git a/contrib/bmake/unit-tests/escape.exp b/contrib/bmake/unit-tests/escape.exp index 6238e27b0191..ff9c8b7cf811 100644 --- a/contrib/bmake/unit-tests/escape.exp +++ b/contrib/bmake/unit-tests/escape.exp @@ -1,5 +1,4 @@ var-1bs -printf "%s=:%s:\n" VAR1BS 111\\111; printf "%s=:%s:\n" VAR1BSa 111\\aaa; printf "%s=:%s:\n" VAR1BSA 111\\aaa; printf "%s=:%s:\n" VAR1BSda 111\\\$\{a\}; printf "%s=:%s:\n" VAR1BSdA 111\\\$\{A\}; printf "%s=:%s:\n" VAR1BSc 111\#\ backslash\ escapes\ comment\ char,\ so\ this\ is\ part\ of\ the\ value; printf "%s=:%s:\n" VAR1BSsc 111\\\ ; VAR1BS=:111\111: VAR1BSa=:111\aaa: VAR1BSA=:111\aaa: @@ -8,25 +7,22 @@ VAR1BSdA=:111\${A}: VAR1BSc=:111# backslash escapes comment char, so this is part of the value: VAR1BSsc=:111\ : var-2bs -printf "%s=:%s:\n" VAR2BS 222\\\\222; printf "%s=:%s:\n" VAR2BSa 222\\\\aaa; printf "%s=:%s:\n" VAR2BSA 222\\\\aaa; printf "%s=:%s:\n" VAR2BSda 222\\\\\$\{a\}; printf "%s=:%s:\n" VAR2BSdA 222\\\\\$\{A\}; printf "%s=:%s:\n" VAR2BSc 222\\\\; printf "%s=:%s:\n" VAR2BSsc 222\\\\; -VAR2BS=:222\\222: -VAR2BSa=:222\\aaa: -VAR2BSA=:222\\aaa: -VAR2BSda=:222\\${a}: -VAR2BSdA=:222\\${A}: -VAR2BSc=:222\\: -VAR2BSsc=:222\\: -var-1bsnl -printf "%s=:%s:\n" VAR1BSNL 111\ 111; printf "%s=:%s:\n" VAR1BSNLa 111\ aaa; printf "%s=:%s:\n" VAR1BSNLA 111\ aaa; printf "%s=:%s:\n" VAR1BSNLda 111\ \$\{a\}; printf "%s=:%s:\n" VAR1BSNLdA 111\ \$\{A\}; printf "%s=:%s:\n" VAR1BSNLc 111; printf "%s=:%s:\n" VAR1BSNLsc 111; -VAR1BSNL=:111 111: -VAR1BSNLa=:111 aaa: -VAR1BSNLA=:111 aaa: -VAR1BSNLda=:111 ${a}: -VAR1BSNLdA=:111 ${A}: -VAR1BSNLc=:111: -VAR1BSNLsc=:111: +VAR2.BS=:222\\222: +VAR2.BS.a=:222\\aaa: +VAR2.BS.A=:222\\aaa: +VAR2.BS.d.a=:222\\${a}: +VAR2.BS.d.A=:222\\${A}: +VAR2.BS.c=:222\\: +VAR2.BS.s.c=:222\\: +var-1bs-nl +VAR1.BS-NL=:111 111: +VAR1.BS-NL.a=:111 aaa: +VAR1.BS-NL.A=:111 aaa: +VAR1.BS-NL.d-a=:111 ${a}: +VAR1.BS-NL.d-A=:111 ${A}: +VAR1.BS-NL.c=:111: +VAR1.BS-NL.s-c=:111: var-2bsnl -printf "%s=:%s:\n" VAR2BSNL 222\\\\; printf "%s=:%s:\n" VAR2BSNLa 222\\\\; printf "%s=:%s:\n" VAR2BSNLA 222\\\\; printf "%s=:%s:\n" VAR2BSNLda 222\\\\; printf "%s=:%s:\n" VAR2BSNLdA 222\\\\; printf "%s=:%s:\n" VAR2BSNLc 222\\\\; printf "%s=:%s:\n" VAR2BSNLsc 222\\\\; VAR2BSNL=:222\\: VAR2BSNLa=:222\\: VAR2BSNLA=:222\\: @@ -35,7 +31,6 @@ VAR2BSNLdA=:222\\: VAR2BSNLc=:222\\: VAR2BSNLsc=:222\\: var-3bsnl -printf "%s=:%s:\n" VAR3BSNL 333\\\\\ 333=; printf "%s=:%s:\n" VAR3BSNLa 333\\\\\ aaa=; printf "%s=:%s:\n" VAR3BSNLA 333\\\\\ aaa=; printf "%s=:%s:\n" VAR3BSNLda 333\\\\\ \$\{a\}=; printf "%s=:%s:\n" VAR3BSNLdA 333\\\\\ \$\{A\}=; printf "%s=:%s:\n" VAR3BSNLc 333\\\\; printf "%s=:%s:\n" VAR3BSNLsc 333\\\\; VAR3BSNL=:333\\ 333=: VAR3BSNLa=:333\\ aaa=: VAR3BSNLA=:333\\ aaa=: @@ -44,7 +39,6 @@ VAR3BSNLdA=:333\\ ${A}=: VAR3BSNLc=:333\\: VAR3BSNLsc=:333\\: var-1bsnl-space -printf "%s=:%s:\n" VAR1BSNL00 first\ line; printf "%s=:%s:\n" VAR1BSNL0 first\ line\ no\ space\ on\ second\ line; printf "%s=:%s:\n" VAR1BSNLs first\ line\ one\ space\ on\ second\ line; printf "%s=:%s:\n" VAR1BSNLss first\ line\ two\ spaces\ on\ second\ line; printf "%s=:%s:\n" VAR1BSNLt first\ line\ one\ tab\ on\ second\ line; printf "%s=:%s:\n" VAR1BSNLtt first\ line\ two\ tabs\ on\ second\ line; printf "%s=:%s:\n" VAR1BSNLxx first\ line\ many\ spaces\ and\ tabs\ \[\ \ \ \ \]\ on\ second\ line; VAR1BSNL00=:first line: VAR1BSNL0=:first line no space on second line: VAR1BSNLs=:first line one space on second line: diff --git a/contrib/bmake/unit-tests/escape.mk b/contrib/bmake/unit-tests/escape.mk index 8bdd3ad2ab49..a363a19f1946 100644 --- a/contrib/bmake/unit-tests/escape.mk +++ b/contrib/bmake/unit-tests/escape.mk @@ -1,4 +1,4 @@ -# $NetBSD: escape.mk,v 1.14 2020/11/03 17:38:45 rillig Exp $ +# $NetBSD: escape.mk,v 1.15 2023/10/19 18:24:33 rillig Exp $ # # Test backslash escaping. @@ -53,7 +53,7 @@ should continue the comment. \ __printvars: .USE .MADE @echo ${.TARGET} - ${.ALLSRC:@v@ printf "%s=:%s:\n" ${v:Q} ${${v}:Q}; @} + @${.ALLSRC:@v@ printf "%s=:%s:\n" ${v:Q} ${${v}:Q}; @} # Embedded backslash in variable should be taken literally. # @@ -83,7 +83,8 @@ all: var-2bs var-2bs: .PHONY __printvars VAR2BS VAR2BSa VAR2BSA VAR2BSda VAR2BSdA \ VAR2BSc VAR2BSsc -# Backslash-newline in a variable setting is replaced by a single space. +# In a variable assignment, when the sequence <backslash><newline> occurs at +# the end of a physical line, it is replaced with a single space. # VAR1BSNL= 111\ 111 diff --git a/contrib/bmake/unit-tests/export-env.mk b/contrib/bmake/unit-tests/export-env.mk index 1605b1a71d61..80653f4bb3c9 100644 --- a/contrib/bmake/unit-tests/export-env.mk +++ b/contrib/bmake/unit-tests/export-env.mk @@ -1,4 +1,4 @@ -# $NetBSD: export-env.mk,v 1.4 2020/10/24 08:50:17 rillig Exp $ +# $NetBSD: export-env.mk,v 1.5 2023/06/01 20:56:35 rillig Exp $ # our normal .export, subsequent changes affect the environment UT_TEST= this @@ -21,7 +21,3 @@ UT_LIT= literal ${UT_TEST} all: @echo make:; ${UT_TEST UT_ENV UT_EXP UT_LIT:L:@v@echo $v=${$v};@} @echo env:; ${UT_TEST UT_ENV UT_EXP UT_LIT:L:@v@echo $v=$${$v};@} - - - - diff --git a/contrib/bmake/unit-tests/export.mk b/contrib/bmake/unit-tests/export.mk index bab08ee3ea23..38670eaaaf48 100644 --- a/contrib/bmake/unit-tests/export.mk +++ b/contrib/bmake/unit-tests/export.mk @@ -1,4 +1,4 @@ -# $NetBSD: export.mk,v 1.11 2021/12/05 14:57:36 rillig Exp $ +# $NetBSD: export.mk,v 1.12 2022/09/09 18:36:15 sjg Exp $ UT_TEST= export UT_FOO= foo${BAR} @@ -40,7 +40,7 @@ BAR= bar is ${UT_FU} .MAKE.EXPORTED+= UT_ZOO UT_TEST -FILTER_CMD?= egrep -v '^(MAKEFLAGS|MALLOC_.*|PATH|PWD|SHLVL|_|&)=' +FILTER_CMD?= ${EGREP} -v '^(MAKEFLAGS|MALLOC_.*|PATH|PWD|SHLVL|_|&)=' all: @env | ${FILTER_CMD} | sort diff --git a/contrib/bmake/unit-tests/forloop.exp b/contrib/bmake/unit-tests/forloop.exp deleted file mode 100644 index 422711b41247..000000000000 --- a/contrib/bmake/unit-tests/forloop.exp +++ /dev/null @@ -1,20 +0,0 @@ -make: "forloop.mk" line 14: x=one -make: "forloop.mk" line 14: x="two and three" -make: "forloop.mk" line 14: x=four -make: "forloop.mk" line 14: x="five" -make: "forloop.mk" line 20: x=-I/this -make: "forloop.mk" line 20: x=-I"This or that" -make: "forloop.mk" line 20: x=-Ithat -make: "forloop.mk" line 20: x="-DTHIS=\"this and that\"" -make: "forloop.mk" line 27: cfl=-I/this -I"This or that" -Ithat "-DTHIS=\"this and that\"" -make: "forloop.mk" line 41: newline-item=(a) -make: "forloop.mk" line 47: a=one b="two and three" -make: "forloop.mk" line 47: a=four b="five" -make: "forloop.mk" line 47: a=ONE b="TWO AND THREE" -make: "forloop.mk" line 47: a=FOUR b="FIVE" -We expect an error next: -make: "forloop.mk" line 46: Wrong number of words (9) in .for substitution list with 2 variables -make: Fatal errors encountered -- cannot continue -make: stopped in unit-tests -OK -exit status 0 diff --git a/contrib/bmake/unit-tests/forloop.mk b/contrib/bmake/unit-tests/forloop.mk deleted file mode 100644 index cef05cbe4c61..000000000000 --- a/contrib/bmake/unit-tests/forloop.mk +++ /dev/null @@ -1,53 +0,0 @@ -# $NetBSD: forloop.mk,v 1.7 2020/11/03 17:37:57 rillig Exp $ - -all: for-loop - -LIST= one "two and three" four "five" - -.if make(for-fail) -for-fail: - -XTRA_LIST= xtra -.else - -. for x in ${LIST} -. info x=$x -. endfor - -CFL= -I/this -I"This or that" -Ithat "-DTHIS=\"this and that\"" -cfl= -. for x in ${CFL} -. info x=$x -. if empty(cfl) -cfl= $x -. else -cfl+= $x -. endif -. endfor -. info cfl=${cfl} - -. if ${cfl} != ${CFL} -. error ${.newline}${cfl} != ${.newline}${CFL} -. endif - -. for a b in ${EMPTY} -. info a=$a b=$b -. endfor - -# Since at least 1993, iteration stops at the first newline. -# Back then, the .newline variable didn't exist, therefore it was unlikely -# that a newline ever occurred. -. for var in a${.newline}b${.newline}c -. info newline-item=(${var}) -. endfor - -.endif # for-fail - -.for a b in ${LIST} ${LIST:tu} ${XTRA_LIST} -. info a=$a b=$b -.endfor - -for-loop: - @echo We expect an error next: - @(cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} for-fail) && \ - { echo "Oops that should have failed!"; exit 1; } || echo OK diff --git a/contrib/bmake/unit-tests/forsubst.exp b/contrib/bmake/unit-tests/forsubst.exp deleted file mode 100644 index 0a98c00aff30..000000000000 --- a/contrib/bmake/unit-tests/forsubst.exp +++ /dev/null @@ -1,2 +0,0 @@ -.for with :S;... OK -exit status 0 diff --git a/contrib/bmake/unit-tests/forsubst.mk b/contrib/bmake/unit-tests/forsubst.mk deleted file mode 100644 index 9f293ab7f94e..000000000000 --- a/contrib/bmake/unit-tests/forsubst.mk +++ /dev/null @@ -1,22 +0,0 @@ -# $NetBSD: forsubst.mk,v 1.3 2020/11/03 17:59:27 rillig Exp $ -# -# The parser used to break dependency lines at ';' without regard for -# substitution patterns. Back then, the first ';' was interpreted as the -# separator between the dependency and its commands. This (perhaps coupled -# with the new handling of .for variables in ${:U<value>...) caused -# interesting results for lines like: -# -# .for file in ${LIST} -# for-subst: ${file:S;^;${here}/;g} -# .endfor -# -# See the commit to unit-tests/forsubst (without the .mk) from 2009-10-07. - -all: for-subst - -here := ${.PARSEDIR} -# this should not run foul of the parser -.for file in ${.PARSEFILE} -for-subst: ${file:S;^;${here}/;g} - @echo ".for with :S;... OK" -.endfor diff --git a/contrib/bmake/unit-tests/hanoi-include.mk b/contrib/bmake/unit-tests/hanoi-include.mk index 3b9438bf2169..f243af83d1df 100644 --- a/contrib/bmake/unit-tests/hanoi-include.mk +++ b/contrib/bmake/unit-tests/hanoi-include.mk @@ -1,41 +1,49 @@ -# $NetBSD: hanoi-include.mk,v 1.2 2022/01/08 22:13:43 rillig Exp $ +# $NetBSD: hanoi-include.mk,v 1.5 2023/10/19 18:24:33 rillig Exp $ # -# Implements the Towers of Hanoi puzzle, thereby demonstrating a bunch of -# more or less useful programming techniques: +# Implements the Towers of Hanoi puzzle, demonstrating a bunch of more or less +# useful programming techniques: # -# * default assignment using the ?= assignment operator -# * including the same file recursively (rather unusual) -# * extracting the current value of a variable using the .for loop -# * using shell commands for calculations since make is a text processor -# * using the :: dependency operator for adding commands to a target -# * on-the-fly variable assignment expressions using the ::= modifier +# * default assignment using the ?= assignment operator +# * including the same file recursively (rather unusual) +# * extracting the current value of a variable using the .for loop +# * using the :: dependency operator for adding commands to a target +# * on-the-fly variable assignment expressions using the ::= modifier # # usage: -# env N=3 make -f hanoi-include.mk -# endless loop: -# make -f hanoi-include.mk N=3 +# env N=3 make -r -f hanoi-include.mk +# +# Specifying N in the command line instead of in the environment would produce +# an endless loop, since variables from the command line cannot be overridden +# by global variables: +# make -r -f hanoi-include.mk N=3 N?= 5 # Move this number of disks ... FROM?= A # ... from this stack ... VIA?= B # ... via this stack ... TO?= C # ... to this stack. -.if $N == 1 +# Since make has no built-in arithmetic functions, convert N to a list of +# words and use the built-in word counting instead. +.if ${N:[#]} == 1 +N:= count ${:U:${:Urange=$N}} # 'count' + one word for every disk +.endif + +.if ${N:[#]} == 2 . for from to in ${FROM} ${TO} all:: @echo "Move the upper disk from stack ${from} to stack ${to}." . endfor .else -_:= ${N::!=expr $N - 1} ${TMP::=${VIA}} ${VIA::=${TO}} ${TO::=${TMP}} +_:= ${N::=${N:[1..-2]}} ${TMP::=${VIA}} ${VIA::=${TO}} ${TO::=${TMP}} . include "${.PARSEDIR}/${.PARSEFILE}" -_:= ${N::!=expr $N + 1} ${TMP::=${VIA}} ${VIA::=${TO}} ${TO::=${TMP}} +_:= ${N::+=D} ${TMP::=${VIA}} ${VIA::=${TO}} ${TO::=${TMP}} . for from to in ${FROM} ${TO} all:: @echo "Move the upper disk from stack ${from} to stack ${to}." . endfor -_:= ${N::!=expr $N - 1} ${TMP::=${VIA}} ${VIA::=${FROM}} ${FROM::=${TMP}} +_:= ${N::=${N:[1..-2]}} ${TMP::=${VIA}} ${VIA::=${FROM}} ${FROM::=${TMP}} . include "${.PARSEDIR}/${.PARSEFILE}" -_:= ${N::!=expr $N + 1} ${TMP::=${VIA}} ${VIA::=${FROM}} ${FROM::=${TMP}} +_:= ${N::+=D} ${TMP::=${VIA}} ${VIA::=${FROM}} ${FROM::=${TMP}} .endif diff --git a/contrib/bmake/unit-tests/include-main.exp b/contrib/bmake/unit-tests/include-main.exp index e677826373c1..fcc38247109f 100644 --- a/contrib/bmake/unit-tests/include-main.exp +++ b/contrib/bmake/unit-tests/include-main.exp @@ -1,17 +1,17 @@ -make: "include-main.mk" line 14: main-before-ok -make: "include-main.mk" line 21: main-before-for-ok -make: "include-sub.mk" line 4: sub-before-ok -make: "include-sub.mk" line 14: sub-before-for-ok +make: "include-main.mk" line 15: main-before-ok +make: "include-main.mk" line 23: main-before-for-ok +make: "include-sub.inc" line 4: sub-before-ok +make: "include-sub.inc" line 14: sub-before-for-ok Parsing line 5: . info subsub-ok -make: "include-subsub.mk" line 5: subsub-ok - in .for loop from include-sub.mk:31 with i = include - in .for loop from include-sub.mk:30 with i = nested - in .for loop from include-sub.mk:29 with i = deeply - in include-main.mk:27 +make: "include-subsub.inc" line 5: subsub-ok + in .for loop from include-sub.inc:31 with i = include + in .for loop from include-sub.inc:30 with i = nested + in .for loop from include-sub.inc:29 with i = deeply + in include-main.mk:29 Parsing line 6: .MAKEFLAGS: -d0 ParseDependency(.MAKEFLAGS: -d0) -make: "include-sub.mk" line 38: sub-after-ok -make: "include-sub.mk" line 45: sub-after-for-ok -make: "include-main.mk" line 30: main-after-ok -make: "include-main.mk" line 37: main-after-for-ok +make: "include-sub.inc" line 38: sub-after-ok +make: "include-sub.inc" line 45: sub-after-for-ok +make: "include-main.mk" line 33: main-after-ok +make: "include-main.mk" line 41: main-after-for-ok exit status 0 diff --git a/contrib/bmake/unit-tests/include-main.mk b/contrib/bmake/unit-tests/include-main.mk index 9a4c6630506b..373bbdea1721 100644 --- a/contrib/bmake/unit-tests/include-main.mk +++ b/contrib/bmake/unit-tests/include-main.mk @@ -1,4 +1,4 @@ -# $NetBSD: include-main.mk,v 1.7 2022/01/08 23:41:43 rillig Exp $ +# $NetBSD: include-main.mk,v 1.9 2023/06/01 20:56:35 rillig Exp $ # # Until 2020-09-05, the .INCLUDEDFROMFILE magic variable did not behave # as described in the manual page. @@ -11,6 +11,7 @@ # properly handle nested includes and even .for loops. .if !defined(.INCLUDEDFROMFILE) +# expect+1: main-before-ok . info main-before-ok .else . warning main-before-fail(${.INCLUDEDFROMFILE}) @@ -18,15 +19,17 @@ .for i in once . if !defined(.INCLUDEDFROMFILE) +# expect+1: main-before-for-ok . info main-before-for-ok . else . warning main-before-for-fail(${.INCLUDEDFROMFILE}) . endif .endfor -.include "include-sub.mk" +.include "include-sub.inc" .if !defined(.INCLUDEDFROMFILE) +# expect+1: main-after-ok . info main-after-ok .else . warning main-after-fail(${.INCLUDEDFROMFILE}) @@ -34,6 +37,7 @@ .for i in once . if !defined(.INCLUDEDFROMFILE) +# expect+1: main-after-for-ok . info main-after-for-ok . else . warning main-after-for-fail(${.INCLUDEDFROMFILE}) diff --git a/contrib/bmake/unit-tests/include-sub.mk b/contrib/bmake/unit-tests/include-sub.inc index 57d2aafe9d1d..f26f14c9d84f 100644 --- a/contrib/bmake/unit-tests/include-sub.mk +++ b/contrib/bmake/unit-tests/include-sub.inc @@ -1,4 +1,4 @@ -# $NetBSD: include-sub.mk,v 1.9 2022/01/08 23:41:43 rillig Exp $ +# $NetBSD: include-sub.inc,v 1.1 2023/01/19 23:26:14 rillig Exp $ .if ${.INCLUDEDFROMFILE} == "include-main.mk" . info sub-before-ok @@ -29,7 +29,7 @@ .for i in deeply . for i in nested . for i in include -.include "include-subsub.mk" +.include "include-subsub.inc" . endfor . endfor .endfor diff --git a/contrib/bmake/unit-tests/include-subsub.inc b/contrib/bmake/unit-tests/include-subsub.inc new file mode 100644 index 000000000000..79a6a3770090 --- /dev/null +++ b/contrib/bmake/unit-tests/include-subsub.inc @@ -0,0 +1,9 @@ +# $NetBSD: include-subsub.inc,v 1.1 2023/01/19 23:26:14 rillig Exp $ + +.if ${.INCLUDEDFROMFILE} == "include-sub.inc" +.MAKEFLAGS: -dp +. info subsub-ok +.MAKEFLAGS: -d0 +.else +. warning subsub-fail(${.INCLUDEDFROMFILE}) +.endif diff --git a/contrib/bmake/unit-tests/include-subsub.mk b/contrib/bmake/unit-tests/include-subsub.mk deleted file mode 100644 index 476d75f79556..000000000000 --- a/contrib/bmake/unit-tests/include-subsub.mk +++ /dev/null @@ -1,9 +0,0 @@ -# $NetBSD: include-subsub.mk,v 1.4 2021/01/26 23:44:56 rillig Exp $ - -.if ${.INCLUDEDFROMFILE} == "include-sub.mk" -.MAKEFLAGS: -dp -. info subsub-ok -.MAKEFLAGS: -d0 -.else -. warning subsub-fail(${.INCLUDEDFROMFILE}) -.endif diff --git a/contrib/bmake/unit-tests/job-output-null.exp b/contrib/bmake/unit-tests/job-output-null.exp index 631d4862af44..628ec54a1a6b 100644 --- a/contrib/bmake/unit-tests/job-output-null.exp +++ b/contrib/bmake/unit-tests/job-output-null.exp @@ -1,4 +1,6 @@ -1 -2a +1 trailing +2a trailing +2b trailing +2c trailing 3a without newline, 3b without newline. exit status 0 diff --git a/contrib/bmake/unit-tests/job-output-null.mk b/contrib/bmake/unit-tests/job-output-null.mk index 1efd9c667980..04786dba4096 100644 --- a/contrib/bmake/unit-tests/job-output-null.mk +++ b/contrib/bmake/unit-tests/job-output-null.mk @@ -1,11 +1,11 @@ -# $NetBSD: job-output-null.mk,v 1.3 2021/09/12 10:26:49 rillig Exp $ +# $NetBSD: job-output-null.mk,v 1.4 2022/09/03 08:03:27 rillig Exp $ # # Test how null bytes in the output of a command are handled. Make processes # them using null-terminated strings, which may cut off some of the output. # -# As of 2021-04-15, make handles null bytes from the child process -# inconsistently. It's an edge case though since typically the child -# processes output text. +# Before job.c 1.454 from 2022-09-03, make handled null bytes in the output +# from the child process inconsistently. It's an edge case though since +# typically the child processes output text. # Note: The printf commands used in this test must only use a single format # string, without parameters. This is because it is implementation-dependent @@ -16,30 +16,40 @@ # NetBSD /bin/ksh 3 x write("fmt") (via /bin/printf) # Bash 5 3 x write("fmt") # -# In the latter case the output may arrive in parts, which in this test makes -# a crucial difference since the outcome of the test depends on whether there -# is a '\n' in each of the blocks from the output. +# In the latter case the output may arrive in 1 to 3 parts, depending on the +# exact timing, which in this test makes a crucial difference since before +# job.c 1.454 from 2022-09-03, the outcome of the test depended on whether +# there was a '\n' in each of the blocks from the output. Depending on the +# exact timing, the output of that test varied, its possible values were '2a', +# '2a 2b', '2a 2c', '2a 2b 2c'. .MAKEFLAGS: -j1 # force jobs mode all: .PHONY - # The null byte from the command output is kept as-is. - # See CollectOutput, which looks like it intended to replace these - # null bytes with simple spaces. + # The null byte from the command output is replaced with a single + # space by CollectOutput. @printf '1\0trailing\n' + # expect: 1 trailing # Give the parent process a chance to see the above output, but not # yet the output from the next printf command. @sleep 1 - # All null bytes from the command output are kept as-is. + # Each null byte from the command output is replaced with a single + # space. @printf '2a\0trailing\n''2b\0trailing\n''2c\0trailing\n' + # expect: 2a trailing + # expect: 2b trailing + # expect: 2c trailing @sleep 1 - # The null bytes are replaced with spaces since they are not followed - # by a newline. + # Each null byte from the command output is replaced with a single + # space. Because there is no trailing newline in the output, these + # null bytes were replaced with spaces even before job.c 1.454 from + # 2022-09-03, unlike in the cases above. # # The three null bytes in a row test whether this output is # compressed to a single space like in DebugFailedTarget. It isn't. @printf '3a\0without\0\0\0newline, 3b\0without\0\0\0newline.' + # expect: 3a without newline, 3b without newline. diff --git a/contrib/bmake/unit-tests/jobs-error-indirect.exp b/contrib/bmake/unit-tests/jobs-error-indirect.exp index 5c5a3801f4f6..79843a235666 100644 --- a/contrib/bmake/unit-tests/jobs-error-indirect.exp +++ b/contrib/bmake/unit-tests/jobs-error-indirect.exp @@ -2,7 +2,7 @@ false *** [indirect] Error code 1 make: stopped in unit-tests -1 error +make: 1 error make: stopped in unit-tests exit status 2 diff --git a/contrib/bmake/unit-tests/jobs-error-nested-make.exp b/contrib/bmake/unit-tests/jobs-error-nested-make.exp index 88c32ab8d1f6..2baf893c6623 100644 --- a/contrib/bmake/unit-tests/jobs-error-nested-make.exp +++ b/contrib/bmake/unit-tests/jobs-error-nested-make.exp @@ -3,7 +3,7 @@ false *** [nested] Error code 1 make: stopped in unit-tests -1 error +make: 1 error make: stopped in unit-tests diff --git a/contrib/bmake/unit-tests/jobs-error-nested.exp b/contrib/bmake/unit-tests/jobs-error-nested.exp index f96b5d016777..873613d40d48 100644 --- a/contrib/bmake/unit-tests/jobs-error-nested.exp +++ b/contrib/bmake/unit-tests/jobs-error-nested.exp @@ -3,13 +3,13 @@ false *** [nested] Error code 1 make: stopped in unit-tests -1 error +make: 1 error make: stopped in unit-tests *** [all] Error code 2 make: stopped in unit-tests -1 error +make: 1 error make: stopped in unit-tests exit status 2 diff --git a/contrib/bmake/unit-tests/lint.mk b/contrib/bmake/unit-tests/lint.mk index 5db417639d0b..431143c644ee 100755 --- a/contrib/bmake/unit-tests/lint.mk +++ b/contrib/bmake/unit-tests/lint.mk @@ -1,4 +1,4 @@ -# $NetBSD: lint.mk,v 1.4 2021/01/30 13:50:18 rillig Exp $ +# $NetBSD: lint.mk,v 1.5 2023/11/19 21:47:52 rillig Exp $ # # Demonstrates stricter checks that are only enabled in lint mode, using the # option -dL. @@ -6,7 +6,7 @@ # Before main.c 1.421 from 2020-11-01, make exited successfully even though # the error message had been issued as PARSE_FATAL. This was because back # then, make checked for parse errors only after parsing each top-level -# makefile, in Parse_File. After that, when expanding variable expressions +# makefile, in Parse_File. After that, when expanding expressions # in shell commands, the parse errors were not checked again. # Ouch: as of 2020-08-03, the variable is malformed and parsing stops diff --git a/contrib/bmake/unit-tests/make-exported.mk b/contrib/bmake/unit-tests/make-exported.mk index 58cb15183b8d..363ea2733a47 100755 --- a/contrib/bmake/unit-tests/make-exported.mk +++ b/contrib/bmake/unit-tests/make-exported.mk @@ -1,4 +1,4 @@ -# $NetBSD: make-exported.mk,v 1.6 2020/10/05 19:27:48 rillig Exp $ +# $NetBSD: make-exported.mk,v 1.7 2022/09/09 18:36:15 sjg Exp $ # # As of 2020-08-09, the code in Var_Export is shared between the .export # directive and the .MAKE.EXPORTED variable. This leads to non-obvious @@ -22,4 +22,4 @@ UT_VAR= ${UNEXPANDED} .MAKE.EXPORTED= -literal UT_VAR all: - @env | sort | egrep '^UT_|make-exported-value' || true + @env | sort | ${EGREP} '^UT_|make-exported-value' || true diff --git a/contrib/bmake/unit-tests/meta-ignore.inc b/contrib/bmake/unit-tests/meta-ignore.inc new file mode 100644 index 000000000000..ed74f4d79017 --- /dev/null +++ b/contrib/bmake/unit-tests/meta-ignore.inc @@ -0,0 +1,63 @@ +# $NetBSD: meta-ignore.inc,v 1.2 2023/02/25 19:30:32 sjg Exp $ + +# common logic for testing .MAKE.META.IGNORE_* + +# we want a directory outside of .OBJDIR to drop a file +# that our meta file refers to. +# Note: these tests will not work if TMPDIR is /tmp or /var/tmp +# or a subdir thereof +IGNORE:= ${TMPDIR}/ignore +OBJ:= ${TMPDIR}/obj + +# this is always ignored so make sure it isn't used above +TMPDIR= /tmp/nothanks + +all: one two three + +setup: + @mkdir -p ${IGNORE} ${OBJ} + @echo > ${IGNORE}/check + @rm -f ${OBJ}/check-ignore + +makefile:= ${.INCLUDEDFROMDIR}/${.INCLUDEDFROMFILE} +TEST:= ${.INCLUDEDFROMFILE:R:C,.*meta-,,:S,-,_,g:tu} + +DESC.one= Initialize check-ignore.meta +DESC.two= Use .MAKE.META.${TEST} - check-ignore is up to date +DESC.three= Skip .MAKE.META.${TEST} - check-ignore is out of date + +# just in case someone runs us with -jN +.ORDER: one two three +one two three: .MAKE setup + @echo "${DESC.${.TARGET}}"; \ + ${MAKE} -C ${.CURDIR} -f ${makefile} check-ignore parent=${.TARGET} + +.if make(check-ignore) +.MAKEFLAGS: -dM +.MAKE.MODE = meta verbose silent=yes +.OBJDIR: ${OBJ} +.if ${parent} == "two" +.if ${TEST} == "IGNORE_PATHS" +# this is a prefix list - any path that matches +# one of these prefixes will be ignored +.MAKE.META.IGNORE_PATHS = ${IGNORE} +.elif ${TEST} == "IGNORE_PATTERNS" +# more flexible but more expensive +# this example is equivalent to M*/ignore/* +# a match means ignore +.MAKE.META.IGNORE_PATTERNS = */ignore/* +.elif ${TEST} == "IGNORE_FILTER" +# this is the most flexible, but also most expensive +# if this expands to nothing - ignore the path +.MAKE.META.IGNORE_FILTER = N${IGNORE}/* +.endif +.endif + +# : < just reads from ${IGNORE}/check +# so that our filemon trace will have a reference to it +# we ensure it is always newer than the target. +check-ignore: .META .NOPATH + @: < ${IGNORE}/check > ${.TARGET} + @sleep 1; echo ${.TARGET} > ${IGNORE}/check + +.endif diff --git a/contrib/bmake/unit-tests/moderrs.exp b/contrib/bmake/unit-tests/moderrs.exp index 9d8bd308c36c..6b41241b6800 100644 --- a/contrib/bmake/unit-tests/moderrs.exp +++ b/contrib/bmake/unit-tests/moderrs.exp @@ -9,13 +9,13 @@ make: Unknown modifier "Z" VAR:Z=before-inner}-after unclosed-direct: -want: Unclosed variable expression, expecting '}' for modifier "S,V,v," of variable "VAR" with value "Thevariable" -make: Unclosed variable expression, expecting '}' for modifier "S,V,v," of variable "VAR" with value "Thevariable" +want: Unclosed expression, expecting '}' for modifier "S,V,v," of variable "VAR" with value "Thevariable" +make: Unclosed expression, expecting '}' for modifier "S,V,v," of variable "VAR" with value "Thevariable" VAR:S,V,v,=Thevariable unclosed-indirect: -want: Unclosed variable expression after indirect modifier, expecting '}' for variable "VAR" -make: Unclosed variable expression after indirect modifier, expecting '}' for variable "VAR" +want: Unclosed expression after indirect modifier, expecting '}' for variable "VAR" +make: Unclosed expression after indirect modifier, expecting '}' for variable "VAR" VAR:S,V,v,=Thevariable unfinished-indirect: @@ -33,7 +33,7 @@ make: Unfinished modifier for "UNDEF" ('@' missing) 1 2 3 loop-close: -make: Unclosed variable expression, expecting '}' for modifier "@var@${var}}...@" of variable "UNDEF" with value "1}... 2}... 3}..." +make: Unclosed expression, expecting '}' for modifier "@var@${var}}...@" of variable "UNDEF" with value "1}... 2}... 3}..." 1}... 2}... 3}... 1}... 2}... 3}... @@ -67,7 +67,7 @@ make: Unfinished modifier for "VAR" (',' missing) 4: make: Unfinished modifier for "VAR" (',' missing) 5: -make: Unclosed variable expression, expecting '}' for modifier "S,from,to," of variable "VAR" with value "TheVariable" +make: Unclosed expression, expecting '}' for modifier "S,from,to," of variable "VAR" with value "TheVariable" 6: TheVariable 7: TheVariable @@ -82,7 +82,7 @@ make: Unfinished modifier for "VAR" (',' missing) 4: make: Unfinished modifier for "VAR" (',' missing) 5: -make: Unclosed variable expression, expecting '}' for modifier "C,from,to," of variable "VAR" with value "TheVariable" +make: Unclosed expression, expecting '}' for modifier "C,from,to," of variable "VAR" with value "TheVariable" 6: TheVariable 7: TheVariable @@ -124,13 +124,13 @@ make: Unknown modifier "__" mod-sysv-parse: make: Unknown modifier "3" -make: Unclosed variable expression, expecting '}' for modifier "3" of variable "FIB" with value "" +make: Unclosed expression, expecting '}' for modifier "3" of variable "FIB" with value "" make: Unknown modifier "3=" -make: Unclosed variable expression, expecting '}' for modifier "3=" of variable "FIB" with value "" +make: Unclosed expression, expecting '}' for modifier "3=" of variable "FIB" with value "" make: Unknown modifier "3=x3" -make: Unclosed variable expression, expecting '}' for modifier "3=x3" of variable "FIB" with value "" +make: Unclosed expression, expecting '}' for modifier "3=x3" of variable "FIB" with value "" 1 1 2 x3 5 8 1x3 21 34 diff --git a/contrib/bmake/unit-tests/moderrs.mk b/contrib/bmake/unit-tests/moderrs.mk index ffd920314c5d..bde263af4079 100644 --- a/contrib/bmake/unit-tests/moderrs.mk +++ b/contrib/bmake/unit-tests/moderrs.mk @@ -1,4 +1,4 @@ -# $NetBSD: moderrs.mk,v 1.30 2021/06/21 08:28:37 rillig Exp $ +# $NetBSD: moderrs.mk,v 1.31 2023/11/19 22:32:44 rillig Exp $ # # various modifier error tests @@ -34,11 +34,11 @@ mod-unknown-indirect: print-header print-footer @echo 'VAR:${MOD_UNKN}=before-${VAR:${MOD_UNKN}:inner}-after' unclosed-direct: print-header print-footer - @echo 'want: Unclosed variable expression, expecting $'}$' for modifier "S,V,v," of variable "VAR" with value "Thevariable"' + @echo 'want: Unclosed expression, expecting $'}$' for modifier "S,V,v," of variable "VAR" with value "Thevariable"' @echo VAR:S,V,v,=${VAR:S,V,v, unclosed-indirect: print-header print-footer - @echo 'want: Unclosed variable expression after indirect modifier, expecting $'}$' for variable "VAR"' + @echo 'want: Unclosed expression after indirect modifier, expecting $'}$' for variable "VAR"' @echo VAR:${MOD_TERM},=${VAR:${MOD_S} unfinished-indirect: print-header print-footer diff --git a/contrib/bmake/unit-tests/modmatch.exp b/contrib/bmake/unit-tests/modmatch.exp deleted file mode 100644 index fcaf6c02ed69..000000000000 --- a/contrib/bmake/unit-tests/modmatch.exp +++ /dev/null @@ -1,17 +0,0 @@ -LIB=a X_LIBS:M${LIB${LIB:tu}} is "/tmp/liba.a" -LIB=a X_LIBS:M*/lib${LIB}.a is "/tmp/liba.a" -LIB=a X_LIBS:M*/lib${LIB}.a:tu is "/TMP/LIBA.A" -LIB=b X_LIBS:M${LIB${LIB:tu}} is "" -LIB=b X_LIBS:M*/lib${LIB}.a is "" -LIB=b X_LIBS:M*/lib${LIB}.a:tu is "" -LIB=c X_LIBS:M${LIB${LIB:tu}} is "" -LIB=c X_LIBS:M*/lib${LIB}.a is "" -LIB=c X_LIBS:M*/lib${LIB}.a:tu is "" -LIB=d X_LIBS:M${LIB${LIB:tu}} is "/tmp/libd.a" -LIB=d X_LIBS:M*/lib${LIB}.a is "/tmp/libd.a" -LIB=d X_LIBS:M*/lib${LIB}.a:tu is "/TMP/LIBD.A" -LIB=e X_LIBS:M${LIB${LIB:tu}} is "/tmp/libe.a" -LIB=e X_LIBS:M*/lib${LIB}.a is "/tmp/libe.a" -LIB=e X_LIBS:M*/lib${LIB}.a:tu is "/TMP/LIBE.A" -Mscanner=OK -exit status 0 diff --git a/contrib/bmake/unit-tests/modmatch.mk b/contrib/bmake/unit-tests/modmatch.mk deleted file mode 100644 index 7dcacf09da6d..000000000000 --- a/contrib/bmake/unit-tests/modmatch.mk +++ /dev/null @@ -1,30 +0,0 @@ -# $NetBSD: modmatch.mk,v 1.9 2020/10/24 08:50:17 rillig Exp $ -# -# Tests for the :M and :S modifiers. - -X= a b c d e - -.for x in $X -LIB${x:tu}= /tmp/lib$x.a -.endfor - -X_LIBS= ${LIBA} ${LIBD} ${LIBE} - -LIB?= a - -var= head -res= no -.if !empty(var:M${:Uhead\:tail:C/:.*//}) -res= OK -.endif - -all: show-libs - -show-libs: - @for x in $X; do ${.MAKE} -f ${MAKEFILE} show LIB=$$x; done - @echo "Mscanner=${res}" - -show: - @echo 'LIB=${LIB} X_LIBS:M$${LIB$${LIB:tu}} is "${X_LIBS:M${LIB${LIB:tu}}}"' - @echo 'LIB=${LIB} X_LIBS:M*/lib$${LIB}.a is "${X_LIBS:M*/lib${LIB}.a}"' - @echo 'LIB=${LIB} X_LIBS:M*/lib$${LIB}.a:tu is "${X_LIBS:M*/lib${LIB}.a:tu}"' diff --git a/contrib/bmake/unit-tests/modmisc.exp b/contrib/bmake/unit-tests/modmisc.exp index 10475e65ee0f..f243511ab491 100644 --- a/contrib/bmake/unit-tests/modmisc.exp +++ b/contrib/bmake/unit-tests/modmisc.exp @@ -6,7 +6,6 @@ path='/bin':'/tmp':'/':'/no/such/dir' path_/usr/xbin=/opt/xbin/ paths=/bin /tmp / /no/such/dir /opt/xbin PATHS=/BIN /TMP / /NO/SUCH/DIR /OPT/XBIN -The answer is 42 S: C: @: diff --git a/contrib/bmake/unit-tests/modmisc.mk b/contrib/bmake/unit-tests/modmisc.mk index 9ace35c15162..4868abef92f1 100644 --- a/contrib/bmake/unit-tests/modmisc.mk +++ b/contrib/bmake/unit-tests/modmisc.mk @@ -1,4 +1,4 @@ -# $NetBSD: modmisc.mk,v 1.52 2020/12/20 19:29:06 rillig Exp $ +# $NetBSD: modmisc.mk,v 1.53 2023/06/16 07:20:45 rillig Exp $ # # miscellaneous modifier tests @@ -15,14 +15,10 @@ MOD_HOMES= S,/home/,/homes/, MOD_OPT= @d@$${exists($$d):?$$d:$${d:S,/usr,/opt,}}@ MOD_SEP= S,:, ,g -all: modvar modvarloop modsysv emptyvar undefvar +all: modvar modvarloop emptyvar undefvar all: mod-quote all: mod-break-many-words -# See also sysv.mk. -modsysv: - @echo "The answer is ${libfoo.a:L:libfoo.a=42}" - # Demonstrates modifiers that are given indirectly from a variable. modvar: @echo "path='${path}'" @@ -60,6 +56,6 @@ undefvar: mod-quote: @echo $@: new${.newline:Q}${.newline:Q}line -# Cover the bmake_realloc in Str_Words. +# Cover the bmake_realloc in Substring_Words. mod-break-many-words: @echo $@: ${UNDEF:U:range=500:[#]} diff --git a/contrib/bmake/unit-tests/opt-debug-file.exp b/contrib/bmake/unit-tests/opt-debug-file.exp index 712686f60b3c..8bdaca612310 100644 --- a/contrib/bmake/unit-tests/opt-debug-file.exp +++ b/contrib/bmake/unit-tests/opt-debug-file.exp @@ -1,6 +1,6 @@ -make: "opt-debug-file.mk" line 43: This goes to stderr only, once. -make: "opt-debug-file.mk" line 45: This goes to stderr only, once. -make: "opt-debug-file.mk" line 47: This goes to stderr, and in addition to the debug log. +make: "opt-debug-file.mk" line 44: This goes to stderr only, once. +make: "opt-debug-file.mk" line 47: This goes to stderr only, once. +make: "opt-debug-file.mk" line 50: This goes to stderr, and in addition to the debug log. CondParser_Eval: ${:!cat opt-debug-file.debuglog!:Maddition:[#]} != 1 Comparing 1.000000 != 1.000000 make: Missing delimiter for modifier ':S' diff --git a/contrib/bmake/unit-tests/opt-debug-file.mk b/contrib/bmake/unit-tests/opt-debug-file.mk index b878c2bcf734..e6c23c4faa1a 100644 --- a/contrib/bmake/unit-tests/opt-debug-file.mk +++ b/contrib/bmake/unit-tests/opt-debug-file.mk @@ -1,4 +1,4 @@ -# $NetBSD: opt-debug-file.mk,v 1.8 2022/01/11 19:47:34 rillig Exp $ +# $NetBSD: opt-debug-file.mk,v 1.10 2023/11/19 21:47:52 rillig Exp $ # # Tests for the -dF command line option, which redirects the debug log # to a file instead of writing it to stderr. @@ -18,7 +18,7 @@ VAR= value ${:Uexpanded} # Make sure that the debug logging file contains some logging. DEBUG_OUTPUT:= ${:!cat opt-debug-file.debuglog!} # Grmbl. Because of the := operator in the above line, the variable -# value contains ${:Uexpanded}. This variable expression is expanded +# value contains ${:Uexpanded}. This expression is expanded # when it is used in the condition below. Therefore, be careful when storing # untrusted input in variables. #.MAKEFLAGS: -dc -dFstderr @@ -40,10 +40,13 @@ DEBUG_OUTPUT:= ${:!cat opt-debug-file.debuglog!} # See Parse_Error. .MAKEFLAGS: -dFstdout +# expect+1: This goes to stderr only, once. . info This goes to stderr only, once. .MAKEFLAGS: -dFstderr +# expect+1: This goes to stderr only, once. . info This goes to stderr only, once. .MAKEFLAGS: -dFopt-debug-file.debuglog +# expect+1: This goes to stderr, and in addition to the debug log. . info This goes to stderr, and in addition to the debug log. .MAKEFLAGS: -dFstderr -d0c .if ${:!cat opt-debug-file.debuglog!:Maddition:[#]} != 1 diff --git a/contrib/bmake/unit-tests/opt-debug-for.exp b/contrib/bmake/unit-tests/opt-debug-for.exp index ea811b9bfcf5..a8f63b85fec3 100644 --- a/contrib/bmake/unit-tests/opt-debug-for.exp +++ b/contrib/bmake/unit-tests/opt-debug-for.exp @@ -1,22 +1,22 @@ For: new loop 2 For: end for 2 For: end for 1 -For: loop body: +For: loop body with outer = a: . for inner in 1 2 VAR.${:Ua}${inner}= value . endfor For: end for 1 -For: loop body: +For: loop body with inner = 1: VAR.${:Ua}${:U1}= value -For: loop body: +For: loop body with inner = 2: VAR.${:Ua}${:U2}= value -For: loop body: +For: loop body with outer = b: . for inner in 1 2 VAR.${:Ub}${inner}= value . endfor For: end for 1 -For: loop body: +For: loop body with inner = 1: VAR.${:Ub}${:U1}= value -For: loop body: +For: loop body with inner = 2: VAR.${:Ub}${:U2}= value exit status 0 diff --git a/contrib/bmake/unit-tests/opt-debug-graph1.exp b/contrib/bmake/unit-tests/opt-debug-graph1.exp index 64dcece5f026..26777a671119 100644 --- a/contrib/bmake/unit-tests/opt-debug-graph1.exp +++ b/contrib/bmake/unit-tests/opt-debug-graph1.exp @@ -21,6 +21,7 @@ .MAKE = <details omitted> .MAKE.DEPENDFILE = <details omitted> .MAKE.GID = <details omitted> +.MAKE.JOBS.C = <details omitted> .MAKE.LEVEL = <details omitted> .MAKE.MAKEFILES = <details omitted> .MAKE.MAKEFILE_PREFERENCE = <details omitted> diff --git a/contrib/bmake/unit-tests/opt-debug-graph2.exp b/contrib/bmake/unit-tests/opt-debug-graph2.exp index 89e10b181c2c..a5a51413fd38 100644 --- a/contrib/bmake/unit-tests/opt-debug-graph2.exp +++ b/contrib/bmake/unit-tests/opt-debug-graph2.exp @@ -55,6 +55,7 @@ all : made-target error-target aborted-target .MAKE = <details omitted> .MAKE.DEPENDFILE = <details omitted> .MAKE.GID = <details omitted> +.MAKE.JOBS.C = <details omitted> .MAKE.LEVEL = <details omitted> .MAKE.MAKEFILES = <details omitted> .MAKE.MAKEFILE_PREFERENCE = <details omitted> diff --git a/contrib/bmake/unit-tests/opt-debug-graph3.exp b/contrib/bmake/unit-tests/opt-debug-graph3.exp index 36706145eb14..ff88400668fa 100644 --- a/contrib/bmake/unit-tests/opt-debug-graph3.exp +++ b/contrib/bmake/unit-tests/opt-debug-graph3.exp @@ -55,6 +55,7 @@ all : made-target error-target aborted-target .MAKE = <details omitted> .MAKE.DEPENDFILE = <details omitted> .MAKE.GID = <details omitted> +.MAKE.JOBS.C = <details omitted> .MAKE.LEVEL = <details omitted> .MAKE.MAKEFILES = <details omitted> .MAKE.MAKEFILE_PREFERENCE = <details omitted> diff --git a/contrib/bmake/unit-tests/opt-debug-hash.exp b/contrib/bmake/unit-tests/opt-debug-hash.exp index b239399ec44d..194b08daa5f2 100644 --- a/contrib/bmake/unit-tests/opt-debug-hash.exp +++ b/contrib/bmake/unit-tests/opt-debug-hash.exp @@ -1,4 +1,4 @@ -make: "opt-debug-hash.mk" line 11: Missing argument for ".error" +make: "opt-debug-hash.mk" line 12: Missing argument for ".error" make: Fatal errors encountered -- cannot continue HashTable targets: size=16 numEntries=0 maxchain=0 HashTable Global variables: size=16 numEntries=<entries> maxchain=3 diff --git a/contrib/bmake/unit-tests/opt-debug-hash.mk b/contrib/bmake/unit-tests/opt-debug-hash.mk index 8b757ff3f290..a1b21e145bf0 100644 --- a/contrib/bmake/unit-tests/opt-debug-hash.mk +++ b/contrib/bmake/unit-tests/opt-debug-hash.mk @@ -1,4 +1,4 @@ -# $NetBSD: opt-debug-hash.mk,v 1.3 2022/01/22 18:59:24 rillig Exp $ +# $NetBSD: opt-debug-hash.mk,v 1.4 2023/06/01 20:56:35 rillig Exp $ # # Tests for the -dh command line option, which adds debug logging for # hash tables. Even more detailed logging is available by compiling @@ -8,4 +8,5 @@ # Force a parse error, to demonstrate the newline character in the diagnostic # that had been missing before parse.c 1.655 from 2022-01-22. +# expect+1: Missing argument for ".error" .error diff --git a/contrib/bmake/unit-tests/opt-debug-jobs.mk b/contrib/bmake/unit-tests/opt-debug-jobs.mk index f3732df7e25d..ac63bb9c5e86 100644 --- a/contrib/bmake/unit-tests/opt-debug-jobs.mk +++ b/contrib/bmake/unit-tests/opt-debug-jobs.mk @@ -1,4 +1,4 @@ -# $NetBSD: opt-debug-jobs.mk,v 1.5 2020/11/12 21:54:52 rillig Exp $ +# $NetBSD: opt-debug-jobs.mk,v 1.6 2023/11/19 21:47:52 rillig Exp $ # # Tests for the -dj command line option, which adds debug logging about # running jobs in multiple shells. @@ -11,7 +11,7 @@ all: # Only the actual command is logged. - # To see the evaluation of the variable expressions, use -dv. + # To see the evaluation of the expressions, use -dv. : ${:Uexpanded} expression # Undefined variables expand to empty strings. diff --git a/contrib/bmake/unit-tests/opt-debug-lint.exp b/contrib/bmake/unit-tests/opt-debug-lint.exp index 05b341b30dae..5a6510bd029a 100644 --- a/contrib/bmake/unit-tests/opt-debug-lint.exp +++ b/contrib/bmake/unit-tests/opt-debug-lint.exp @@ -1,8 +1,10 @@ -make: "opt-debug-lint.mk" line 19: Variable "X" is undefined -make: "opt-debug-lint.mk" line 41: Variable "UNDEF" is undefined -make: "opt-debug-lint.mk" line 61: Missing delimiter ':' after modifier "L" -make: "opt-debug-lint.mk" line 61: Missing delimiter ':' after modifier "P" -make: "opt-debug-lint.mk" line 69: Unknown modifier "${" +make: "opt-debug-lint.mk" line 21: Variable "X" is undefined +make: "opt-debug-lint.mk" line 21: Malformed conditional ($X) +make: "opt-debug-lint.mk" line 45: Variable "UNDEF" is undefined +make: "opt-debug-lint.mk" line 45: Malformed conditional (${UNDEF}) +make: "opt-debug-lint.mk" line 67: Missing delimiter ':' after modifier "L" +make: "opt-debug-lint.mk" line 67: Missing delimiter ':' after modifier "P" +make: "opt-debug-lint.mk" line 76: Unknown modifier "${" make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/opt-debug-lint.mk b/contrib/bmake/unit-tests/opt-debug-lint.mk index 155e1a3de3be..042bfd51d35b 100644 --- a/contrib/bmake/unit-tests/opt-debug-lint.mk +++ b/contrib/bmake/unit-tests/opt-debug-lint.mk @@ -1,7 +1,7 @@ -# $NetBSD: opt-debug-lint.mk,v 1.14 2021/03/14 10:57:12 rillig Exp $ +# $NetBSD: opt-debug-lint.mk,v 1.16 2023/11/19 21:47:52 rillig Exp $ # # Tests for the -dL command line option, which runs additional checks -# to catch common mistakes, such as unclosed variable expressions. +# to catch common mistakes, such as unclosed expressions. .MAKEFLAGS: -dL @@ -16,6 +16,8 @@ # # See also: # cond-undef-lint.mk +# expect+2: Malformed conditional ($X) +# expect+1: Variable "X" is undefined .if $X . error .endif @@ -38,6 +40,8 @@ # hoping for the caller to print an error message. This resulted in the # well-known "Malformed conditional" error message, even though the # conditional was well-formed and the only error was an undefined variable. +# expect+2: Malformed conditional (${UNDEF}) +# expect+1: Variable "UNDEF" is undefined .if ${UNDEF} . error .endif @@ -58,6 +62,8 @@ ${UNDEF}: ${UNDEF} # Since 2020-10-03, in lint mode the variable modifier must be separated # by colons. See varparse-mod.mk. +# expect+2: Missing delimiter ':' after modifier "L" +# expect+1: Missing delimiter ':' after modifier "P" .if ${value:LPL} != "value" . error .endif @@ -66,6 +72,7 @@ ${UNDEF}: ${UNDEF} # variable modifier had to be separated by colons. This was wrong though # since make always fell back trying to parse the indirect modifier as a # SysV modifier. +# expect+1: Unknown modifier "${" .if ${value:${:UL}PL} != "LPL}" # FIXME: "LPL}" is unexpected here. . error ${value:${:UL}PL} .endif @@ -84,7 +91,7 @@ ${UNDEF}: ${UNDEF} # # Before var.c 1.856 from 2021-03-14, this regular expression was then # compiled even though that was not necessary for checking the syntax at the -# level of variable expressions. The unexpanded '$' then resulted in a wrong +# level of expressions. The unexpanded '$' then resulted in a wrong # error message. # # This only happened in lint mode since in default mode the early check for diff --git a/contrib/bmake/unit-tests/opt-debug-loud.mk b/contrib/bmake/unit-tests/opt-debug-loud.mk index 38a3c7d7a8e1..5ea1f90ff7be 100644 --- a/contrib/bmake/unit-tests/opt-debug-loud.mk +++ b/contrib/bmake/unit-tests/opt-debug-loud.mk @@ -1,4 +1,4 @@ -# $NetBSD: opt-debug-loud.mk,v 1.4 2020/10/05 19:27:48 rillig Exp $ +# $NetBSD: opt-debug-loud.mk,v 1.5 2023/12/19 19:33:40 rillig Exp $ # # Tests for the -dl command line option, which prints the commands before # running them, ignoring the command line option for silent mode (-s) as @@ -8,8 +8,8 @@ .MAKEFLAGS: -dl -s .SILENT: -# The -dl command line option does not affect commands that are run during -# variable expansion, such as :!cmd! or :sh. +# The -dl command line option does not affect commands that are run when +# evaluating expressions and their modifiers, such as :!cmd! or :sh. .if ${:!echo word!} != "word" . error .endif diff --git a/contrib/bmake/unit-tests/opt-debug-parse.exp b/contrib/bmake/unit-tests/opt-debug-parse.exp index 0e11024647a1..811c6b45dce5 100644 --- a/contrib/bmake/unit-tests/opt-debug-parse.exp +++ b/contrib/bmake/unit-tests/opt-debug-parse.exp @@ -1,26 +1,26 @@ Parse_PushInput: .for loop in opt-debug-parse.mk, line 16 SetFilenameVars: ${.PARSEDIR} = <some-dir> ${.PARSEFILE} = `opt-debug-parse.mk' -Parsing line 20: .info trace with multi-line .for loop head -make: "opt-debug-parse.mk" line 20: trace with multi-line .for loop head +Parsing line 21: .info trace with multi-line .for loop head +make: "opt-debug-parse.mk" line 21: trace with multi-line .for loop head in .for loop from opt-debug-parse.mk:16 with var = value -ParseEOF: returning to file opt-debug-parse.mk, line 22 +ParseEOF: returning to file opt-debug-parse.mk, line 23 SetFilenameVars: ${.PARSEDIR} = <some-dir> ${.PARSEFILE} = `opt-debug-parse.mk' -Parsing line 25: .include "/dev/null" +Parsing line 26: .include "/dev/null" Parse_PushInput: file /dev/null, line 1 SetFilenameVars: ${.PARSEDIR} = <some-dir> ${.PARSEFILE} = `null' SetFilenameVars: ${.INCLUDEDFROMDIR} = <some-dir> ${.INCLUDEDFROMFILE} = `opt-debug-parse.mk' -ParseEOF: returning to file opt-debug-parse.mk, line 26 +ParseEOF: returning to file opt-debug-parse.mk, line 27 SetFilenameVars: ${.PARSEDIR} = <some-dir> ${.PARSEFILE} = `opt-debug-parse.mk' -Parse_PushInput: .for loop in opt-debug-parse.mk, line 30 +Parse_PushInput: .for loop in opt-debug-parse.mk, line 31 SetFilenameVars: ${.PARSEDIR} = <some-dir> ${.PARSEFILE} = `opt-debug-parse.mk' -Parsing line 31: .info trace -make: "opt-debug-parse.mk" line 31: trace - in .for loop from opt-debug-parse.mk:30 with a = 1, b = 2, c = 3 -Parsing line 31: .info trace -make: "opt-debug-parse.mk" line 31: trace - in .for loop from opt-debug-parse.mk:30 with a = 4, b = 5, c = 6 -ParseEOF: returning to file opt-debug-parse.mk, line 33 +Parsing line 34: .info trace +make: "opt-debug-parse.mk" line 34: trace + in .for loop from opt-debug-parse.mk:31 with a = 1, b = 2, c = 3 +Parsing line 34: .info trace +make: "opt-debug-parse.mk" line 34: trace + in .for loop from opt-debug-parse.mk:31 with a = 4, b = 5, c = 6 +ParseEOF: returning to file opt-debug-parse.mk, line 36 SetFilenameVars: ${.PARSEDIR} = <some-dir> ${.PARSEFILE} = `opt-debug-parse.mk' -Parsing line 35: .MAKEFLAGS: -d0 +Parsing line 38: .MAKEFLAGS: -d0 ParseDependency(.MAKEFLAGS: -d0) exit status 0 diff --git a/contrib/bmake/unit-tests/opt-debug-parse.mk b/contrib/bmake/unit-tests/opt-debug-parse.mk index 9517bb62b976..347537015b52 100644 --- a/contrib/bmake/unit-tests/opt-debug-parse.mk +++ b/contrib/bmake/unit-tests/opt-debug-parse.mk @@ -1,4 +1,4 @@ -# $NetBSD: opt-debug-parse.mk,v 1.7 2022/02/09 21:09:24 rillig Exp $ +# $NetBSD: opt-debug-parse.mk,v 1.8 2023/06/01 20:56:35 rillig Exp $ # # Tests for the -dp command line option, which adds debug logging about # makefile parsing. @@ -17,6 +17,7 @@ var \ in \ value +# expect+1: trace with multi-line .for loop head .info trace with multi-line .for loop head .endfor @@ -28,6 +29,8 @@ # In .for loops with multiple variables, the variable details are included in # the stack trace, just as with a single variable. .for a b c in 1 2 3 ${:U4 5 6} +# expect+2: trace +# expect+1: trace .info trace .endfor diff --git a/contrib/bmake/unit-tests/opt-debug-var.mk b/contrib/bmake/unit-tests/opt-debug-var.mk index 5b0c5648ab55..9017f18e81d3 100644 --- a/contrib/bmake/unit-tests/opt-debug-var.mk +++ b/contrib/bmake/unit-tests/opt-debug-var.mk @@ -1,4 +1,4 @@ -# $NetBSD: opt-debug-var.mk,v 1.2 2022/01/23 16:09:38 rillig Exp $ +# $NetBSD: opt-debug-var.mk,v 1.3 2023/11/19 21:47:52 rillig Exp $ # # Tests for the -dv command line option, which adds debug logging about # variable assignment and evaluation. @@ -15,7 +15,7 @@ SUBST:= value .if defined(ASSIGNED) .endif -# The usual form of variable expressions is ${VAR}. The form $(VAR) is used +# The usual form of expressions is ${VAR}. The form $(VAR) is used # less often as it can be visually confused with the shell construct for # capturing the output of a subshell, which looks the same. # diff --git a/contrib/bmake/unit-tests/opt-define.mk b/contrib/bmake/unit-tests/opt-define.mk index 7c4bbc179316..f508a9b1592f 100644 --- a/contrib/bmake/unit-tests/opt-define.mk +++ b/contrib/bmake/unit-tests/opt-define.mk @@ -1,4 +1,4 @@ -# $NetBSD: opt-define.mk,v 1.3 2022/01/23 16:09:38 rillig Exp $ +# $NetBSD: opt-define.mk,v 1.4 2022/06/12 14:27:06 rillig Exp $ # # Tests for the -D command line option, which defines global variables to the # value 1, like in the C preprocessor. @@ -19,10 +19,22 @@ VAR= overwritten .endif # The variable can be undefined. If the variable had been defined in the -# "Internal" scope instead, undefining it would have no effect. +# "Internal" or in the "Command" scope instead, undefining it would have no +# effect. .undef VAR .if defined(VAR) . error .endif +# The C preprocessor allows to define a macro with a specific value. Make +# behaves differently, it defines a variable with the name 'VAR=value' and the +# value 1. +.MAKEFLAGS: -DVAR=value +.if defined(VAR) +. error +.endif +.if ${VAR=value} != "1" +. error +.endif + all: .PHONY diff --git a/contrib/bmake/unit-tests/opt-env.exp b/contrib/bmake/unit-tests/opt-env.exp index b2e9ea85bafd..39a9383953dd 100644 --- a/contrib/bmake/unit-tests/opt-env.exp +++ b/contrib/bmake/unit-tests/opt-env.exp @@ -1,5 +1 @@ -make: "opt-env.mk" line 13: Malformed conditional (${FROM_ENV} != value-from-env) -make: "opt-env.mk" line 20: value-from-mk - -make: stopped in unit-tests -exit status 1 +exit status 0 diff --git a/contrib/bmake/unit-tests/opt-jobs-no-action.mk b/contrib/bmake/unit-tests/opt-jobs-no-action.mk index 19d82c5bf4b8..fe720c9e0e61 100644 --- a/contrib/bmake/unit-tests/opt-jobs-no-action.mk +++ b/contrib/bmake/unit-tests/opt-jobs-no-action.mk @@ -1,4 +1,4 @@ -# $NetBSD: opt-jobs-no-action.mk,v 1.9 2021/04/04 09:58:51 rillig Exp $ +# $NetBSD: opt-jobs-no-action.mk,v 1.10 2022/05/08 06:51:27 rillig Exp $ # # Tests for the combination of the options -j and -n, which prints the # commands instead of actually running them. @@ -21,7 +21,7 @@ # The shell attributes are handled by Job_ParseShell. # The shell attributes 'quiet' and 'echo' don't need a trailing newline, # this is handled by the [0] != '\0' checks in Job_ParseShell. -# The '\#' is handled by ParseGetLine. +# The '\#' is handled by ParseRawLine. # The '\n' is handled by Str_Words in Job_ParseShell. # The '$$' is handled by Var_Subst in ParseDependencyLine. .SHELL: \ diff --git a/contrib/bmake/unit-tests/opt-jobs.mk b/contrib/bmake/unit-tests/opt-jobs.mk index 7d54d08a8421..ce84e47e91e1 100644 --- a/contrib/bmake/unit-tests/opt-jobs.mk +++ b/contrib/bmake/unit-tests/opt-jobs.mk @@ -1,8 +1,54 @@ -# $NetBSD: opt-jobs.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $ +# $NetBSD: opt-jobs.mk,v 1.5 2023/09/10 16:25:32 sjg Exp $ # -# Tests for the -j command line option. +# Tests for the -j command line option, which creates the targets in parallel. -# TODO: Implementation -all: - @:; +# The option '-j <integer>' specifies the number of targets that can be made +# in parallel. +ARGS= 0 1 2 8 08 017 0x10 -5 1000 +EXPECT.0= argument '0' to option '-j' must be a positive number (exit 2) +EXPECT.1= 1 +EXPECT.2= 2 +EXPECT.8= 8 +EXPECT.08= argument '08' to option '-j' must be a positive number (exit 2) +EXPECT.017= 15 +EXPECT.0x10= 16 +EXPECT.-5= argument '-5' to option '-j' must be a positive number (exit 2) +EXPECT.1000= 1000 + +.for arg in ${ARGS} +OUTPUT!= ${MAKE} -r -f /dev/null -j ${arg} -v .MAKE.JOBS 2>&1 || echo "(exit $$?)" +. if ${OUTPUT:[2..-1]} != ${EXPECT.${arg}} +. warning ${arg}:${.newline} have: ${OUTPUT:[2..-1]}${.newline} want: ${EXPECT.${arg}} +. endif +.endfor + + +# The options '-j <float>' and '-j <integer>C' multiply the given number with +# the number of available CPUs. +ARGS= 0.0 0C 0.0C .00001 .00001C 1C 1CPUs 1.2 .5e1C 07.5C 08.5C +EXPECT.0.0= argument '0.0' to option '-j' must be a positive number (exit 2) +EXPECT.0C= <integer> # rounded up to 1C +EXPECT.0.0C= argument '0.0C' to option '-j' must be a positive number (exit 2) +EXPECT..00001= argument '.00001' to option '-j' must be a positive number (exit 2) +EXPECT..00001C= argument '.00001C' to option '-j' must be a positive number (exit 2) +EXPECT.1C= <integer> +EXPECT.1CPUs= <integer> +EXPECT.1.2= <integer> +EXPECT..5e1C= <integer> # unlikely to occur in practice +EXPECT.07.5C= <integer> +EXPECT.08.5C= argument '08.5C' to option '-j' must be a positive number (exit 2) + +.if ${.MAKE.JOBS.C} == "yes" +. for arg in ${ARGS} +OUTPUT!= ${MAKE} -r -f /dev/null -j ${arg} -v .MAKE.JOBS 2>&1 || echo "(exit $$?)" +. if ${OUTPUT:C,^[0-9]+$,numeric,W} == numeric +OUTPUT= <integer> +. endif +. if ${OUTPUT:[2..-1]} != ${EXPECT.${arg}} +. warning ${arg}:${.newline} have: ${OUTPUT:[2..-1]}${.newline} want: ${EXPECT.${arg}} +. endif +. endfor +.endif + +all: .PHONY diff --git a/contrib/bmake/unit-tests/opt-query.exp b/contrib/bmake/unit-tests/opt-query.exp index 38025dcf4d3a..0ba62780d844 100644 --- a/contrib/bmake/unit-tests/opt-query.exp +++ b/contrib/bmake/unit-tests/opt-query.exp @@ -1,2 +1,24 @@ +Making commands: command during parsing -exit status 1 +commands: query status 1 + +Making opt-query-file.out-of-date in compat mode: +opt-query-file.out-of-date in compat mode: query status 1 + +Making opt-query-file.up-to-date in compat mode: +`opt-query-file.up-to-date' is up to date. +opt-query-file.up-to-date in compat mode: query status 0 + +Making phony in compat mode: +phony in compat mode: query status 1 + +Making opt-query-file.out-of-date in jobs mode: +opt-query-file.out-of-date in jobs mode: query status 1 + +Making opt-query-file.up-to-date in jobs mode: +opt-query-file.up-to-date in jobs mode: query status 0 + +Making phony in jobs mode: +phony in jobs mode: query status 1 + +exit status 0 diff --git a/contrib/bmake/unit-tests/opt-query.mk b/contrib/bmake/unit-tests/opt-query.mk index 0a7d5219a8fe..3554d69afad6 100644 --- a/contrib/bmake/unit-tests/opt-query.mk +++ b/contrib/bmake/unit-tests/opt-query.mk @@ -1,4 +1,4 @@ -# $NetBSD: opt-query.mk,v 1.4 2020/11/09 20:50:56 rillig Exp $ +# $NetBSD: opt-query.mk,v 1.7 2022/08/18 05:37:05 rillig Exp $ # # Tests for the -q command line option. # @@ -6,7 +6,57 @@ # None of the commands in the targets are run, not even those that are # prefixed with '+'. -.MAKEFLAGS: -q +# This test consists of several parts: +# +# main Delegates to the actual tests. +# +# commands Ensures that none of the targets is made. +# +# variants Ensures that the up-to-date status is correctly +# reported in both compat and jobs mode, and for several +# kinds of make targets. +PART?= main + +.if ${PART} == "main" + +all: .PHONY variants cleanup + +_!= touch -f opt-query-file.up-to-date + +variants: .PHONY + +. for target in commands + @echo 'Making ${target}': + @${MAKE} -r -f ${MAKEFILE} -q ${mode:Mjobs:%=-j1} ${target} PART=commands \ + && echo "${target}: query status $$?" \ + || echo "${target}: query status $$?" + @echo +. endfor + +. for mode in compat jobs +. for target in opt-query-file.out-of-date opt-query-file.up-to-date phony + @echo 'Making ${target} in ${mode} mode': + @${MAKE} -r -f ${MAKEFILE} -q ${mode:Mjobs:%=-j1} ${target} PART=variants \ + && echo "${target} in ${mode} mode: query status $$?" \ + || echo "${target} in ${mode} mode: query status $$?" + @echo +. endfor +. endfor + +# Between 1994 and before 2022-08-17, the exit status for '-q' was always 1, +# the cause for that exit code varied over time though. +# +# expect: opt-query-file.out-of-date in compat mode: query status 1 +# expect: opt-query-file.up-to-date in compat mode: query status 0 +# expect: phony in compat mode: query status 1 +# expect: opt-query-file.out-of-date in jobs mode: query status 1 +# expect: opt-query-file.up-to-date in jobs mode: query status 0 +# expect: phony in jobs mode: query status 1 + +cleanup: .PHONY + @rm -f opt-query-file.up-to-date + +.elif ${PART} == "commands" # This command cannot be prevented from being run since it is used at parse # time, and any later variable assignments may depend on its result. @@ -18,9 +68,18 @@ @+echo '$@: run always' # None of these commands are run. -all: +commands: @echo '$@: hidden command' @+echo '$@: run always' - -# The exit status 1 is because the "all" target has to be made, that is, +# The exit status 1 is because the "commands" target has to be made, that is, # it is not up-to-date. + +.elif ${PART} == "variants" + +opt-query-file.out-of-date: ${MAKEFILE} +opt-query-file.up-to-date: ${MAKEFILE} +phony: .PHONY + +.else +. error Invalid part '${PART}' +.endif diff --git a/contrib/bmake/unit-tests/opt-version.mk b/contrib/bmake/unit-tests/opt-version.mk index 51a4e8a1a0aa..cdba9180ec01 100644 --- a/contrib/bmake/unit-tests/opt-version.mk +++ b/contrib/bmake/unit-tests/opt-version.mk @@ -1,8 +1,8 @@ -# $NetBSD: opt-version.mk,v 1.1 2021/12/23 11:05:59 rillig Exp $ +# $NetBSD: opt-version.mk,v 1.2 2022/05/08 07:27:50 rillig Exp $ # -# Tests for the command line option '--version', which outputs the version -# number of make. NetBSD's make does not have a version number, but the bmake -# distribution created from it has. +# Tests for the command line option '--version', which may be expected to +# output the version number of make. NetBSD's make does not have a version +# number, but the bmake distribution created from it has. # As of 2021-12-23, the output is a single empty line since the '--' does not # end the command line options. Command line parsing then continues as if diff --git a/contrib/bmake/unit-tests/opt-warnings-as-errors.exp b/contrib/bmake/unit-tests/opt-warnings-as-errors.exp index 1db56b753bed..87d1db249a20 100644 --- a/contrib/bmake/unit-tests/opt-warnings-as-errors.exp +++ b/contrib/bmake/unit-tests/opt-warnings-as-errors.exp @@ -1,6 +1,6 @@ -make: "opt-warnings-as-errors.mk" line 12: warning: message 1 +make: "opt-warnings-as-errors.mk" line 13: warning: message 1 make: parsing warnings being treated as errors -make: "opt-warnings-as-errors.mk" line 13: warning: message 2 +make: "opt-warnings-as-errors.mk" line 15: warning: message 2 parsing continues make: Fatal errors encountered -- cannot continue make: stopped in unit-tests diff --git a/contrib/bmake/unit-tests/opt-warnings-as-errors.mk b/contrib/bmake/unit-tests/opt-warnings-as-errors.mk index c29343f960a7..3896dad10f1a 100644 --- a/contrib/bmake/unit-tests/opt-warnings-as-errors.mk +++ b/contrib/bmake/unit-tests/opt-warnings-as-errors.mk @@ -1,4 +1,4 @@ -# $NetBSD: opt-warnings-as-errors.mk,v 1.5 2021/01/27 00:02:38 rillig Exp $ +# $NetBSD: opt-warnings-as-errors.mk,v 1.6 2023/06/01 20:56:35 rillig Exp $ # # Tests for the -W command line option, which turns warnings into errors. # @@ -9,7 +9,9 @@ .MAKEFLAGS: -W +# expect+1: warning: message 1 .warning message 1 +# expect+1: warning: message 2 .warning message 2 _!= echo 'parsing continues' 1>&2 diff --git a/contrib/bmake/unit-tests/opt-x-reduce-exported.exp b/contrib/bmake/unit-tests/opt-x-reduce-exported.exp index 39a9383953dd..99570f2c30cb 100644 --- a/contrib/bmake/unit-tests/opt-x-reduce-exported.exp +++ b/contrib/bmake/unit-tests/opt-x-reduce-exported.exp @@ -1 +1,5 @@ +ordinary: +BEFORE=before +submake: +BEFORE=before exit status 0 diff --git a/contrib/bmake/unit-tests/opt-x-reduce-exported.mk b/contrib/bmake/unit-tests/opt-x-reduce-exported.mk index 7ee8e7c7eff0..a42a85d21a53 100644 --- a/contrib/bmake/unit-tests/opt-x-reduce-exported.mk +++ b/contrib/bmake/unit-tests/opt-x-reduce-exported.mk @@ -1,8 +1,20 @@ -# $NetBSD: opt-x-reduce-exported.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $ +# $NetBSD: opt-x-reduce-exported.mk,v 1.3 2022/05/08 07:27:50 rillig Exp $ # -# Tests for the -x command line option. +# Tests for the -X command line option, which prevents variables passed on the +# command line from being exported to the environment of child commands. -# TODO: Implementation +# The variable 'BEFORE' is exported, the variable 'AFTER' isn't. +.MAKEFLAGS: BEFORE=before -X AFTER=after -all: - @:; +all: .PHONY ordinary submake + +ordinary: .PHONY + @echo 'ordinary:' + @env | sort | grep -e '^BEFORE' -e '^AFTER' + +submake: .PHONY + @echo 'submake:' + @${MAKE} -r -f ${MAKEFILE} show-env + +show-env: .PHONY + @env | sort | grep -e '^BEFORE' -e '^AFTER' diff --git a/contrib/bmake/unit-tests/opt.mk b/contrib/bmake/unit-tests/opt.mk index 0931a66d3d15..939d5ec35aeb 100644 --- a/contrib/bmake/unit-tests/opt.mk +++ b/contrib/bmake/unit-tests/opt.mk @@ -1,4 +1,4 @@ -# $NetBSD: opt.mk,v 1.6 2020/11/18 01:06:59 sjg Exp $ +# $NetBSD: opt.mk,v 1.7 2023/02/25 00:07:08 rillig Exp $ # # Tests for the command line options. @@ -7,7 +7,7 @@ all: .IGNORE # The options from the top-level make are passed to the sub-makes via # the environment variable MAKEFLAGS. This is where the " -r -k -d 0" - # comes from. See MainParseArg. + # comes from. See MainParseOption. ${MAKE} -r -f /dev/null -V MAKEFLAGS @echo diff --git a/contrib/bmake/unit-tests/parse-var.mk b/contrib/bmake/unit-tests/parse-var.mk index bd6c59f0e5cb..b35726e76efc 100644 --- a/contrib/bmake/unit-tests/parse-var.mk +++ b/contrib/bmake/unit-tests/parse-var.mk @@ -1,13 +1,129 @@ -# $NetBSD: parse-var.mk,v 1.1 2020/10/04 06:53:15 rillig Exp $ +# $NetBSD: parse-var.mk,v 1.9 2023/11/19 21:47:52 rillig Exp $ +# +# Tests for parsing expressions. +# +# TODO: Add systematic tests for all of the below combinations. +# +# Written form: +# short form +# long form with braces endc == '}' +# long form with parentheses endc == ')' +# indirect modifiers endc == '\0' +# +# Based on: +# undefined variable +# global variable +# command-line variable +# environment variable +# target-local variable +# legacy variable '@F' +# +# VarEvalMode: +# parse +# eval +# eval-undeferr +# eval-keep-dollar +# eval-keep-undef +# eval-keep-dollar-undef +# +# Global mode: +# without -dL +# with -dL +# +# Modifiers: +# no +# yes, stay undefined +# convert to defined +# indirect modifiers, involving changes to VarEvalMode +# +# Error conditions: +# for the short form, EOF after the '$' +# for the short form, each character +# for the long forms, EOF right after '${' +# for the long forms, EOF after the variable name +# for the long forms, EOF after the ':' +# for the long forms, EOF after parsing a modifier +# for the long forms, ':}' +# for each modifier: syntactic error +# for each modifier: evaluation error +# +# Context: +# in a condition, only operand, unquoted +# in a condition, only operand, quoted +# in a condition, left-hand side, unquoted +# in a condition, left-hand side, quoted +# in a condition, right-hand side, unquoted +# in a condition, right-hand side, quoted +# left-hand side of a variable assignment +# right-hand side of a ':=' variable assignment +# right-hand side of a '!=' variable assignment +# shell command in a target +# .info directive +# dependency line +# items in a .for loop +# everywhere else Var_Parse is called +# +# Further influences: +# multi-level evaluations like 'other=${OTHER}' with OTHER='$$ ${THIRD}' +# +# Effects: +# How much does the parsing position advance (pp)? +# What's the value of the expression (return value)? +# What error messages are printed (Parse_Error)? +# What no-effect error messages are printed (Error)? +# What error messages should be printed but aren't? +# What other side effects are there? .MAKEFLAGS: -dL -# In variable assignments, there may be spaces on the left-hand side of the -# assignment, but only if they occur inside variable expressions. +# In variable assignments, there may be spaces in the middle of the left-hand +# side of the assignment, but only if they occur inside expressions. +# Leading spaces (but not tabs) are possible but unusual. +# Trailing spaces are common in some coding styles, others omit them. VAR.${:U param }= value .if ${VAR.${:U param }} != "value" . error .endif -all: - @:; +# Since var.c 1.323 from 2020-07-26 18:11 and until var.c 1.1047 from +# 2023-02-18, the exact way of parsing an expression with subexpressions +# depended on whether the expression was actually evaluated or merely parsed. +# +# If it was evaluated, nested expressions were parsed correctly, parsing each +# modifier according to its exact definition (see varmod.mk). +# +# If the expression was merely parsed but not evaluated (for example, because +# its value would not influence the outcome of the condition, or during the +# first pass of the ':@var@body@' modifier), and the expression contained a +# modifier, and that modifier contained a nested expression, the nested +# expression was not parsed correctly. Instead, make only counted the opening +# and closing delimiters, which failed for nested modifiers with unbalanced +# braces. + +#.MAKEFLAGS: -dcpv +# Keep these braces outside the conditions below, to keep them simple to +# understand. If the expression ${BRACE_PAIR:...} had been replaced with the +# literal ${:U{}}, the '}' would have to be escaped, but not the '{'. This +# asymmetry would have made the example even more complicated to understand. +BRACE_PAIR= {} +# In this test word, the below conditions will replace the '{{}' in the middle +# with the string '<lbraces>'. +BRACE_GROUP= {{{{}}}} + +# The inner ':S' modifier turns the word '{}' into '{{}'. +# The outer ':S' modifier then replaces '{{}' with '<lbraces>'. +# Due to the always-true condition '1', the outer expression is relevant and +# is parsed correctly. +.if 1 && ${BRACE_GROUP:S,${BRACE_PAIR:S,{,{{,},<lbraces>,} +.endif +# Due to the always-false condition '0', the outer expression is irrelevant. +# In this case, in the parts of the outer ':S' modifier, the expression parser +# only counted the braces, and since the inner expression '${BRACE_PAIR:...}' +# contains more '{' than '}', parsing failed with the error message 'Unfinished +# modifier for "BRACE_GROUP"'. Fixed in var.c 1.1047 from 2023-02-18. +.if 0 && ${BRACE_GROUP:S,${BRACE_PAIR:S,{,{{,},<lbraces>,} +.endif +#.MAKEFLAGS: -d0 + + +all: .PHONY diff --git a/contrib/bmake/unit-tests/parse.exp b/contrib/bmake/unit-tests/parse.exp index 5807f9c17e2c..cc8c450d51ac 100644 --- a/contrib/bmake/unit-tests/parse.exp +++ b/contrib/bmake/unit-tests/parse.exp @@ -1,5 +1,6 @@ -make: "parse.mk" line 7: Makefile appears to contain unresolved CVS/RCS/??? merge conflicts -make: "parse.mk" line 14: Makefile appears to contain unresolved CVS/RCS/??? merge conflicts +make: "parse.mk" line 7: Invalid line '<<<<<< old' +make: "parse.mk" line 14: Invalid line '>>>>>> new' +make: "parse.mk" line 25: Invalid line 'one-target ${:U }', expanded to 'one-target ' make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/parse.mk b/contrib/bmake/unit-tests/parse.mk index 9dccc7f5b7ce..80a51f2de11e 100644 --- a/contrib/bmake/unit-tests/parse.mk +++ b/contrib/bmake/unit-tests/parse.mk @@ -1,14 +1,55 @@ -# $NetBSD: parse.mk,v 1.2 2022/01/22 17:10:51 rillig Exp $ +# $NetBSD: parse.mk,v 1.7 2023/08/19 11:09:02 rillig Exp $ # # Test those parts of the parsing that do not belong in any of the other # categories. -# expect+1: Makefile appears to contain unresolved CVS/RCS/??? merge conflicts +# expect+1: Invalid line '<<<<<< old' <<<<<< old # No diagnostic since the following line is parsed as a variable assignment, # even though the variable name is empty. See also varname-empty.mk. ====== middle -# expect+1: Makefile appears to contain unresolved CVS/RCS/??? merge conflicts +# expect+1: Invalid line '>>>>>> new' >>>>>> new + + +# Since parse.c 1.578 from 2021-12-14 and before parse.c 1.681 from +# 2022-07-24, if a line of a makefile could only be a dependency specification +# but didn't contain any of the dependency operators ':', '!', '::' and its +# expansion ended with a space, make read a single byte from the memory beyond +# the expanded line's terminating '\0'. +# +# https://bugs.freebsd.org/265119 +# expect+1: Invalid line 'one-target ${:U }', expanded to 'one-target ' +one-target ${:U } + + +# Since parse.c 1.656 from 2022-01-27 and before parse.c 1.662 from +# 2022-02-05, there was an out-of-bounds read in Parse_IsVar when looking for +# a variable assignment in a dependency line with trailing whitespace. Lines +# without trailing whitespace were not affected. Global variable assignments +# were guaranteed to have no trailing whitespace and were thus not affected. +# +# Try to reproduce some variants that may lead to a crash, depending on the +# memory allocator. To get a crash, the terminating '\0' of the line must be +# the last byte of a memory page. The expression '${:U}' forces this trailing +# whitespace. + +# On FreeBSD x86_64, a crash could in some cases be forced using the following +# line, which has length 47, and if the memory for the expanded line starts at +# 0xXXXX_XXd0, the terminating '\0' may end up at 0xXXXX_Xfff: +Try_to_crash_FreeBSD.xxxxxxxxxxxxxxxxxx: 12345 ${:U} + +# The following line has length 4095 after being expanded, so line[4095] == +# '\0'. If the line is +# allocated on a page boundary and the following page is not mapped, this line +# leads to a segmentation fault. +${:U:range=511:@_@1234567@:ts.}: 12345 ${:U} + +# The following line has length 8191, so line[8191] == '\0'. If the line is +# allocated on a page boundary and the following page is not mapped, this line +# leads to a segmentation fault. +${:U:range=1023:@_@1234567@:ts.}: 12345 ${:U} + +12345: diff --git a/contrib/bmake/unit-tests/recursive.exp b/contrib/bmake/unit-tests/recursive.exp index 36cd1c989532..f63b7a54049e 100644 --- a/contrib/bmake/unit-tests/recursive.exp +++ b/contrib/bmake/unit-tests/recursive.exp @@ -1,5 +1,5 @@ -make: "recursive.mk" line 36: Unclosed variable "MISSING_PAREN" -make: "recursive.mk" line 37: Unclosed variable "MISSING_BRACE" +make: "recursive.mk" line 38: Unclosed variable "MISSING_PAREN" +make: "recursive.mk" line 40: Unclosed variable "MISSING_BRACE" make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/recursive.mk b/contrib/bmake/unit-tests/recursive.mk index 5265cec59a2d..b97c4b37eabb 100644 --- a/contrib/bmake/unit-tests/recursive.mk +++ b/contrib/bmake/unit-tests/recursive.mk @@ -1,4 +1,4 @@ -# $NetBSD: recursive.mk,v 1.5 2021/03/15 12:15:03 rillig Exp $ +# $NetBSD: recursive.mk,v 1.7 2023/10/19 18:24:33 rillig Exp $ # # In -dL mode, a variable may get expanded before it makes sense. # This would stop make from doing anything since the "recursive" error @@ -8,22 +8,23 @@ # whether there are unclosed variables. The variable value is therefore # parsed with VARE_PARSE_ONLY for that purpose. # -# Seen in pkgsrc/x11/libXfixes, and probably many more package that use -# GNU Automake. .MAKEFLAGS: -dL + AM_V_lt= ${am__v_lt_${V}} am__v_lt_= ${am__v_lt_${AM_DEFAULT_VERBOSITY}} am__v_lt_0= --silent am__v_lt_1= -# On 2020-08-06, make reported: "Variable am__v_lt_ is recursive." +# Since parse.c 1.243 from 2020-07-31 and before parse.c 1.249 from +# 2020-08-06, when make ran in -dL mode, it reported: "Variable am__v_lt_ is +# recursive." +# +# Seen in pkgsrc/x11/libXfixes, and probably many more package that use +# GNU Automake. libXfixes_la_LINK= ... ${AM_V_lt} ... -# somewhere later ... -AM_DEFAULT_VERBOSITY= 1 - # The purpose of the -dL flag is to detect unclosed variables. This # can be achieved by just parsing the variable and not evaluating it. @@ -33,6 +34,8 @@ AM_DEFAULT_VERBOSITY= 1 # therefore that's acceptable. In most practical cases, the missing # brace would be detected directly in the line where it is produced. MISSING_BRACE_INDIRECT:= ${:U\${MISSING_BRACE} +# expect+1: Unclosed variable "MISSING_PAREN" UNCLOSED= $(MISSING_PAREN +# expect+1: Unclosed variable "MISSING_BRACE" UNCLOSED= ${MISSING_BRACE UNCLOSED= ${MISSING_BRACE_INDIRECT} diff --git a/contrib/bmake/unit-tests/sh-dots.mk b/contrib/bmake/unit-tests/sh-dots.mk index f85af9025e55..5294a4175b63 100755 --- a/contrib/bmake/unit-tests/sh-dots.mk +++ b/contrib/bmake/unit-tests/sh-dots.mk @@ -1,4 +1,4 @@ -# $NetBSD: sh-dots.mk,v 1.3 2020/10/25 22:04:24 rillig Exp $ +# $NetBSD: sh-dots.mk,v 1.4 2023/11/19 21:47:52 rillig Exp $ # # Tests for the special shell command line "...", which does not run the # commands below it but appends them to the list of commands that are run @@ -29,8 +29,8 @@ commented: .IGNORE ... # Run the below commands later @echo commented delayed ${.TARGET} -# The dots don't have to be written literally, they can also come from a -# variable expression. +# The dots don't have to be written literally, they can also come from an +# expression. indirect: @echo indirect regular ${:U...} diff --git a/contrib/bmake/unit-tests/sh-leading-at.exp b/contrib/bmake/unit-tests/sh-leading-at.exp index 8347fda085f7..8197a0d2b71a 100644 --- a/contrib/bmake/unit-tests/sh-leading-at.exp +++ b/contrib/bmake/unit-tests/sh-leading-at.exp @@ -3,4 +3,5 @@ space after @ echo 'echoed' echoed 3 +whitespace in leading part exit status 0 diff --git a/contrib/bmake/unit-tests/sh-leading-at.mk b/contrib/bmake/unit-tests/sh-leading-at.mk index 9f98005ec088..cff3d4da1263 100644 --- a/contrib/bmake/unit-tests/sh-leading-at.mk +++ b/contrib/bmake/unit-tests/sh-leading-at.mk @@ -1,4 +1,4 @@ -# $NetBSD: sh-leading-at.mk,v 1.5 2020/11/15 20:20:58 rillig Exp $ +# $NetBSD: sh-leading-at.mk,v 1.6 2023/01/19 19:55:27 rillig Exp $ # # Tests for shell commands preceded by an '@', to suppress printing # the command to stdout. @@ -16,3 +16,7 @@ all: # The leading '@' can be repeated. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@echo '3' + + # Since 2023-01-17, the leading '@', '+' and '-' may contain + # whitespace, for compatibility with GNU make. + @ @ @ echo 'whitespace in leading part' diff --git a/contrib/bmake/unit-tests/sh-leading-hyphen.exp b/contrib/bmake/unit-tests/sh-leading-hyphen.exp index 39a9383953dd..50bcbbf9bb71 100644 --- a/contrib/bmake/unit-tests/sh-leading-hyphen.exp +++ b/contrib/bmake/unit-tests/sh-leading-hyphen.exp @@ -1 +1,11 @@ +true +false +*** Error code 1 (ignored) +unknown-command 'needed for needshell in compat.c' +unknown-command: not found +*** Error code 127 (ignored) +unknown-long-option 'needed for needshell in compat.c' +unknown-long-option: not found +*** Error code 127 (ignored) +whitespace in leading part exit status 0 diff --git a/contrib/bmake/unit-tests/sh-leading-hyphen.mk b/contrib/bmake/unit-tests/sh-leading-hyphen.mk index d760abb9afdd..08b50a2ddc42 100644 --- a/contrib/bmake/unit-tests/sh-leading-hyphen.mk +++ b/contrib/bmake/unit-tests/sh-leading-hyphen.mk @@ -1,4 +1,4 @@ -# $NetBSD: sh-leading-hyphen.mk,v 1.3 2020/11/15 20:20:58 rillig Exp $ +# $NetBSD: sh-leading-hyphen.mk,v 1.4 2023/01/19 19:55:27 rillig Exp $ # # Tests for shell commands preceded by a '-', to ignore the exit status of # the command line. @@ -11,4 +11,19 @@ # TODO: Implementation all: - @:; + -true + -false + + # An undefined variable expands to an empty string, without warning. + # This is used in practice for prefixing tool names or for DESTDIR. + # The '-' before 'unknown' is interpreted by make as '.IGNORE' flag. + ${UNDEF}-unknown-command 'needed for needshell in compat.c' + + # Expanding undefined variables may lead to strange error messages + # when the shell interprets single-character options as commands + # instead. + ${UNDEF} --unknown-long-option 'needed for needshell in compat.c' + + # Since 2023-01-17, the leading '@', '+' and '-' may contain + # whitespace, for compatibility with GNU make. + - - - @echo 'whitespace in leading part' diff --git a/contrib/bmake/unit-tests/sh-leading-plus.exp b/contrib/bmake/unit-tests/sh-leading-plus.exp index eb586d29f1c2..8cc26deaacb5 100644 --- a/contrib/bmake/unit-tests/sh-leading-plus.exp +++ b/contrib/bmake/unit-tests/sh-leading-plus.exp @@ -1,4 +1,6 @@ echo 'this command is not run' echo 'this command is run' this command is run +echo 'whitespace in leading part' +whitespace in leading part exit status 0 diff --git a/contrib/bmake/unit-tests/sh-leading-plus.mk b/contrib/bmake/unit-tests/sh-leading-plus.mk index ff57b4a38a7d..83e7e7a15e24 100644 --- a/contrib/bmake/unit-tests/sh-leading-plus.mk +++ b/contrib/bmake/unit-tests/sh-leading-plus.mk @@ -1,4 +1,4 @@ -# $NetBSD: sh-leading-plus.mk,v 1.4 2020/11/09 20:50:56 rillig Exp $ +# $NetBSD: sh-leading-plus.mk,v 1.5 2023/01/19 19:55:27 rillig Exp $ # # Tests for shell commands preceded by a '+', to run them even if # the command line option -n is given. @@ -8,3 +8,7 @@ all: @echo 'this command is not run' @+echo 'this command is run' + + # Since 2023-01-17, the leading '@', '+' and '-' may contain + # whitespace, for compatibility with GNU make. + + + + @echo 'whitespace in leading part' diff --git a/contrib/bmake/unit-tests/shell-sh.mk b/contrib/bmake/unit-tests/shell-sh.mk index b3d4f18bbac9..5f7b04716ee1 100644 --- a/contrib/bmake/unit-tests/shell-sh.mk +++ b/contrib/bmake/unit-tests/shell-sh.mk @@ -1,9 +1,9 @@ -# $NetBSD: shell-sh.mk,v 1.1 2020/10/03 14:39:36 rillig Exp $ +# $NetBSD: shell-sh.mk,v 1.2 2023/12/24 16:48:30 sjg Exp $ # # Tests for using a bourne shell for running the commands. # This is the default shell, so there's nothing surprising. -.SHELL: name="sh" path="sh" +.SHELL: name="sh" all: : normal diff --git a/contrib/bmake/unit-tests/suff-main-several.exp b/contrib/bmake/unit-tests/suff-main-several.exp index 4ffb86e65fa0..4391610be742 100644 --- a/contrib/bmake/unit-tests/suff-main-several.exp +++ b/contrib/bmake/unit-tests/suff-main-several.exp @@ -86,6 +86,7 @@ ParseDependency(.MAKEFLAGS: -d0 -dg1) .MAKE = <details omitted> .MAKE.DEPENDFILE = <details omitted> .MAKE.GID = <details omitted> +.MAKE.JOBS.C = <details omitted> .MAKE.LEVEL = <details omitted> .MAKE.MAKEFILES = <details omitted> .MAKE.MAKEFILE_PREFERENCE = <details omitted> diff --git a/contrib/bmake/unit-tests/suff-transform-debug.exp b/contrib/bmake/unit-tests/suff-transform-debug.exp index 737fb0484718..5d632a22f80a 100644 --- a/contrib/bmake/unit-tests/suff-transform-debug.exp +++ b/contrib/bmake/unit-tests/suff-transform-debug.exp @@ -12,6 +12,7 @@ .MAKE = <details omitted> .MAKE.DEPENDFILE = <details omitted> .MAKE.GID = <details omitted> +.MAKE.JOBS.C = <details omitted> .MAKE.LEVEL = <details omitted> .MAKE.MAKEFILES = <details omitted> .MAKE.MAKEFILE_PREFERENCE = <details omitted> diff --git a/contrib/bmake/unit-tests/unexport.mk b/contrib/bmake/unit-tests/unexport.mk index 4363aaac3eee..4bcc5b21ca02 100644 --- a/contrib/bmake/unit-tests/unexport.mk +++ b/contrib/bmake/unit-tests/unexport.mk @@ -1,4 +1,4 @@ -# $NetBSD: unexport.mk,v 1.5 2020/10/24 08:50:17 rillig Exp $ +# $NetBSD: unexport.mk,v 1.6 2023/10/19 18:24:33 rillig Exp $ # pick up a bunch of exported vars FILTER_CMD= grep ^UT_ @@ -10,7 +10,7 @@ UT_TEST= unexport # Until 2020-08-08, Var_UnExport had special handling for '\n', that code # was not reachable though. At that point, backslash-newline has already -# been replaced with a simple space, and variables are not yet expanded. +# been replaced with a simple space, and expressions are not yet expanded. UT_BEFORE_NL= before UT_AFTER_NL= after .export UT_BEFORE_NL UT_AFTER_NL diff --git a/contrib/bmake/unit-tests/var-eval-short.exp b/contrib/bmake/unit-tests/var-eval-short.exp index f574a6444e1b..14e3d372f198 100644 --- a/contrib/bmake/unit-tests/var-eval-short.exp +++ b/contrib/bmake/unit-tests/var-eval-short.exp @@ -1,26 +1,26 @@ -make: "var-eval-short.mk" line 44: In the :@ modifier of "", the variable name "${FAIL}" must not contain a dollar -make: "var-eval-short.mk" line 44: Malformed conditional (0 && ${:Uword:@${FAIL}@expr@}) -make: "var-eval-short.mk" line 84: Invalid time value at "${FAIL}}" -make: "var-eval-short.mk" line 84: Malformed conditional (0 && ${:Uword:gmtime=${FAIL}}) -make: "var-eval-short.mk" line 98: Invalid time value at "${FAIL}}" -make: "var-eval-short.mk" line 98: Malformed conditional (0 && ${:Uword:localtime=${FAIL}}) +make: "var-eval-short.mk" line 46: In the :@ modifier of "", the variable name "${FAIL}" must not contain a dollar +make: "var-eval-short.mk" line 46: Malformed conditional (0 && ${:Uword:@${FAIL}@expr@}) CondParser_Eval: 0 && ${0:?${FAIL}then:${FAIL}else} Var_Parse: ${0:?${FAIL}then:${FAIL}else} (parse-only) Parsing modifier ${0:?...} +Var_Parse: ${FAIL}then:${FAIL}else} (parse-only) Modifier part: "${FAIL}then" +Var_Parse: ${FAIL}else} (parse-only) Modifier part: "${FAIL}else" Result of ${0:?${FAIL}then:${FAIL}else} is "" (parse-only, defined) -Parsing line 163: DEFINED= defined +Parsing line 167: DEFINED= defined Global: DEFINED = defined CondParser_Eval: 0 && ${DEFINED:L:?${FAIL}then:${FAIL}else} Var_Parse: ${DEFINED:L:?${FAIL}then:${FAIL}else} (parse-only) Parsing modifier ${DEFINED:L} Result of ${DEFINED:L} is "defined" (parse-only, regular) Parsing modifier ${DEFINED:?...} +Var_Parse: ${FAIL}then:${FAIL}else} (parse-only) Modifier part: "${FAIL}then" +Var_Parse: ${FAIL}else} (parse-only) Modifier part: "${FAIL}else" Result of ${DEFINED:?${FAIL}then:${FAIL}else} is "defined" (parse-only, regular) -Parsing line 166: .MAKEFLAGS: -d0 +Parsing line 170: .MAKEFLAGS: -d0 ParseDependency(.MAKEFLAGS: -d0) Global: .MAKEFLAGS = -r -k -d cpv -d Global: .MAKEFLAGS = -r -k -d cpv -d 0 diff --git a/contrib/bmake/unit-tests/var-eval-short.mk b/contrib/bmake/unit-tests/var-eval-short.mk index a099b6871d1e..2b25d82e96b8 100644 --- a/contrib/bmake/unit-tests/var-eval-short.mk +++ b/contrib/bmake/unit-tests/var-eval-short.mk @@ -1,4 +1,4 @@ -# $NetBSD: var-eval-short.mk,v 1.8 2021/12/27 18:54:19 rillig Exp $ +# $NetBSD: var-eval-short.mk,v 1.11 2023/10/19 18:24:33 rillig Exp $ # # Tests for each variable modifier to ensure that they only do the minimum # necessary computations. If the result of the expression is irrelevant, @@ -18,7 +18,7 @@ FAIL= ${:!echo unexpected 1>&2!} # is ignored as well. To do that, it is necessary to step through the code of # each modifier. -# TODO: Test the modifiers in the same order as they appear in ApplyModifier. +# TODO: Test the modifiers in the same order as they occur in ApplyModifier. .if 0 && ${FAIL} .endif @@ -41,6 +41,8 @@ FAIL= ${:!echo unexpected 1>&2!} # after the loop, when undefining the temporary global loop variable. # Since var.c 1.907 from 2021-04-04, a '$' is no longer allowed in the # variable name. +# expect+2: In the :@ modifier of "", the variable name "${FAIL}" must not contain a dollar +# expect+1: Malformed conditional (0 && ${:Uword:@${FAIL}@expr@}) .if 0 && ${:Uword:@${FAIL}@expr@} .endif @@ -79,8 +81,9 @@ DEFINED= # defined .if 0 && ${:Uword:E} .endif -# As of 2021-03-14, the error 'Invalid time value: ${FAIL}}' is ok since -# ':gmtime' does not expand its argument. +# Before var.c 1.1050 from 2023-05-09, the ':gmtime' modifier produced the +# error message 'Invalid time value: ${FAIL}}' since it did not expand its +# argument. .if 0 && ${:Uword:gmtime=${FAIL}} .endif @@ -93,8 +96,9 @@ DEFINED= # defined .if 0 && ${value:L} .endif -# As of 2021-03-14, the error 'Invalid time value: ${FAIL}}' is ok since -# ':localtime' does not expand its argument. +# Before var.c 1.1050 from 2023-05-09, the ':localtime' modifier produced the +# error message 'Invalid time value: ${FAIL}}' since it did not expand its +# argument. .if 0 && ${:Uword:localtime=${FAIL}} .endif diff --git a/contrib/bmake/unit-tests/var-op-append.mk b/contrib/bmake/unit-tests/var-op-append.mk index 420ee376b75d..e16b89139cc1 100644 --- a/contrib/bmake/unit-tests/var-op-append.mk +++ b/contrib/bmake/unit-tests/var-op-append.mk @@ -1,7 +1,20 @@ -# $NetBSD: var-op-append.mk,v 1.9 2021/04/04 10:13:09 rillig Exp $ +# $NetBSD: var-op-append.mk,v 1.12 2023/11/02 05:46:26 rillig Exp $ # -# Tests for the += variable assignment operator, which appends to a variable, -# creating it if necessary. +# Tests for the '+=' variable assignment operator, which appends to a +# variable, creating it if necessary. +# +# See also +# var-op.mk +# +# Standards +# The '+=' variable assignment operator is planned to be added in +# POSIX.1-202x. +# +# This implementation does not support the immediate-expansion macros +# specified in POSIX.1-202x. All variables are delayed-expansion. +# +# History +# The '+=' variable assignment operator was added before 1993-03-21. # Appending to an undefined variable is possible. # The variable is created, and no extra space is added before the value. @@ -26,7 +39,7 @@ VAR+= # empty # '+=' assignment operator. As far as possible, the '+' is interpreted as # part of the assignment operator. # -# See Parse_Var +# See Parse_Var, AdjustVarassignOp. C++= value .if ${C+} != "value" || defined(C++) . error @@ -43,4 +56,33 @@ VAR.${:U\$\$\$\$\$\$\$\$}+= dollars . error .endif + +# Appending to an environment variable in the global scope creates a global +# variable of the same name, taking its initial value from the environment +# variable. After the assignment, the environment variable is left as-is, +# the value of the global variable is not synced back to the environment +# variable. +export ENV_PLUS_GLOBAL=from-env-value +ENV_PLUS_GLOBAL+= appended-value +.if ${ENV_PLUS_GLOBAL} != "from-env-value appended-value" +. error +.endif +EXPORTED!= echo "$$ENV_PLUS_GLOBAL" +.if ${EXPORTED} != "from-env-value" +. error +.endif + +# Appending to an environment variable in the command line scope ignores the +# environment variable. +export ENV_PLUS_COMMAND=from-env-value +.MAKEFLAGS: ENV_PLUS_COMMAND+=appended-command +.if ${ENV_PLUS_COMMAND} != "appended-command" +. error ${ENV_PLUS_COMMAND} +.endif +EXPORTED!= echo "$$ENV_PLUS_GLOBAL" +.if ${EXPORTED} != "from-env-value" +. error +.endif + + all: diff --git a/contrib/bmake/unit-tests/var-op-assign.exp b/contrib/bmake/unit-tests/var-op-assign.exp index 73e580403d78..5fad47ca67c4 100644 --- a/contrib/bmake/unit-tests/var-op-assign.exp +++ b/contrib/bmake/unit-tests/var-op-assign.exp @@ -1,6 +1,6 @@ this will be evaluated later -make: "var-op-assign.mk" line 59: Invalid line type -make: "var-op-assign.mk" line 93: Parsing still continues until here. +make: "var-op-assign.mk" line 60: Invalid line 'VARIABLE NAME= variable value' +make: "var-op-assign.mk" line 95: Parsing still continues until here. make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/var-op-assign.mk b/contrib/bmake/unit-tests/var-op-assign.mk index 18ecf8d0d5ed..a900c28a918d 100644 --- a/contrib/bmake/unit-tests/var-op-assign.mk +++ b/contrib/bmake/unit-tests/var-op-assign.mk @@ -1,4 +1,4 @@ -# $NetBSD: var-op-assign.mk,v 1.8 2021/03/15 19:15:04 rillig Exp $ +# $NetBSD: var-op-assign.mk,v 1.11 2023/11/19 21:47:52 rillig Exp $ # # Tests for the = variable assignment operator, which overwrites an existing # variable or creates it. @@ -56,6 +56,7 @@ VAR= ${:! echo 'this will be evaluated later' 1>&2 !} # In a variable assignment, the variable name must consist of a single word. # The following line therefore generates a parse error. +# expect+1: Invalid line 'VARIABLE NAME= variable value' VARIABLE NAME= variable value # But if the whitespace appears inside parentheses or braces, everything is @@ -65,7 +66,7 @@ VARIABLE NAME= variable value # neither contain parentheses nor braces. This is only a side-effect from # the implementation of the parser, which cheats when parsing a variable # name. It only counts parentheses and braces instead of properly parsing -# nested variable expressions such as VAR.${param}. +# nested expressions such as VAR.${param}. # VAR(spaces in parentheses)= () VAR{spaces in braces}= {} @@ -90,6 +91,7 @@ VARNAME_BRACES= VAR{spaces in braces} # unexpected variable values. # # Therefore, just output an info message. +# expect+1: Parsing still continues until here. .info Parsing still continues until here. all: diff --git a/contrib/bmake/unit-tests/var-op-default.mk b/contrib/bmake/unit-tests/var-op-default.mk index ca4fbcc27c88..9d07ddf39e41 100644 --- a/contrib/bmake/unit-tests/var-op-default.mk +++ b/contrib/bmake/unit-tests/var-op-default.mk @@ -1,4 +1,4 @@ -# $NetBSD: var-op-default.mk,v 1.3 2020/12/07 21:35:43 rillig Exp $ +# $NetBSD: var-op-default.mk,v 1.5 2023/11/19 22:32:44 rillig Exp $ # # Tests for the ?= variable assignment operator, which only assigns # if the variable is still undefined. @@ -45,7 +45,7 @@ i?= default # and 'VAR.${param}' expand to 'VAR.param', and the second '?=' assignment # has no effect. # -# Since 2000.05.11.07.43.42 it has been possible to use nested variable +# Since 2000.05.11.07.43.42 it has been possible to use nested # expressions in variable names, which made make much more versatile. # On 2008.03.31.00.12.21, this particular case of the '?=' operator has been # fixed. Before, the '?=' operator had not expanded the variable name @@ -61,8 +61,8 @@ VAR.${:Uparam}?= not used # Now demonstrate that the variable name is indeed expanded exactly once. # This is tricky to measure correctly since there are many inconsistencies -# in and around the code that expands variable expressions in the various -# places where variable expressions can occur. If in doubt, enable the +# in and around the code that expands expressions in the various +# places where expressions can occur. If in doubt, enable the # following debug flags to see what happens: #.MAKEFLAGS: -dcpv EXPAND_NAME= EXPAND.$$$$ # The full variable name is EXPAND.$$ diff --git a/contrib/bmake/unit-tests/var-op-expand.exp b/contrib/bmake/unit-tests/var-op-expand.exp index a4ba53942cf7..5ea4e6b6954c 100644 --- a/contrib/bmake/unit-tests/var-op-expand.exp +++ b/contrib/bmake/unit-tests/var-op-expand.exp @@ -1,7 +1,7 @@ -make: "var-op-expand.mk" line 265: Unknown modifier "s,value,replaced," -make: "var-op-expand.mk" line 268: warning: XXX Neither branch should be taken. -make: "var-op-expand.mk" line 273: Unknown modifier "s,value,replaced," -make: "var-op-expand.mk" line 274: warning: XXX Neither branch should be taken. +make: "var-op-expand.mk" line 274: Unknown modifier "s,value,replaced," +make: "var-op-expand.mk" line 278: warning: XXX Neither branch should be taken. +make: "var-op-expand.mk" line 283: Unknown modifier "s,value,replaced," +make: "var-op-expand.mk" line 285: warning: XXX Neither branch should be taken. make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/var-op-expand.mk b/contrib/bmake/unit-tests/var-op-expand.mk index 1d905aeb3757..76b90bf72b56 100644 --- a/contrib/bmake/unit-tests/var-op-expand.mk +++ b/contrib/bmake/unit-tests/var-op-expand.mk @@ -1,4 +1,4 @@ -# $NetBSD: var-op-expand.mk,v 1.16 2021/12/28 10:47:00 rillig Exp $ +# $NetBSD: var-op-expand.mk,v 1.19 2023/11/19 21:47:52 rillig Exp $ # # Tests for the := variable assignment operator, which expands its # right-hand side. @@ -20,9 +20,9 @@ VAR:= value # When a ':=' assignment is performed, its right-hand side is evaluated and # expanded as far as possible. Contrary to other situations, '$$' and -# variable expressions based on undefined variables are preserved though. +# expressions based on undefined variables are preserved though. # -# Whether a variable expression is undefined or not is determined at the end +# Whether an expression is undefined or not is determined at the end # of evaluating the expression. The consequence is that ${:Ufallback} expands # to "fallback"; initially this expression is undefined since it is based on # the variable named "", which is guaranteed to be never defined, but at the @@ -37,7 +37,7 @@ VAR:= $$ $$$$ $$$$$$$$ .endif -# reference to a variable containing a literal dollar sign +# reference to a variable containing literal dollar signs REF= $$ $$$$ $$$$$$$$ VAR:= ${REF} REF= too late @@ -49,6 +49,9 @@ REF= too late # reference to an undefined variable .undef UNDEF VAR:= <${UNDEF}> +.if ${VAR} != "<>" +. error +.endif UNDEF= after .if ${VAR} != "<after>" . error @@ -68,6 +71,9 @@ REF= too late # expression with an indirect modifier referring to an undefined variable .undef UNDEF VAR:= ${:${UNDEF}} +.if ${VAR} != "" +. error +.endif UNDEF= Uwas undefined .if ${VAR} != "was undefined" . error @@ -99,6 +105,9 @@ UNDEF= Uwas undefined REF2= <${REF3}> REF= ${REF2} VAR:= ${REF} +.if ${VAR} != "<>" +. error +.endif REF3= too late .if ${VAR} != "<too late>" . error @@ -265,12 +274,14 @@ indirect:= ${INDIRECT:tl} .if ${indirect} != " ok " . error .else +# expect+1: warning: XXX Neither branch should be taken. . warning XXX Neither branch should be taken. .endif LATER= uppercase-value later= lowercase-value # expect+1: Unknown modifier "s,value,replaced," .if ${indirect} != "uppercase-replaced ok uppercase-sysv" +# expect+1: warning: XXX Neither branch should be taken. . warning XXX Neither branch should be taken. .else . error diff --git a/contrib/bmake/unit-tests/var-op-shell.exp b/contrib/bmake/unit-tests/var-op-shell.exp index 0e9bd2cbc35a..0837cd4f832e 100644 --- a/contrib/bmake/unit-tests/var-op-shell.exp +++ b/contrib/bmake/unit-tests/var-op-shell.exp @@ -1,8 +1,8 @@ -make: "var-op-shell.mk" line 31: warning: "echo "failed"; false" returned non-zero status -make: "var-op-shell.mk" line 37: warning: "false" returned non-zero status -make: "var-op-shell.mk" line 59: warning: "kill $$" exited on a signal +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 62: warning: "kill $$" exited on a signal /bin/no/such/command: not found -make: "var-op-shell.mk" line 65: warning: "/bin/no/such/command" returned non-zero status +make: "var-op-shell.mk" line 69: warning: "/bin/no/such/command" returned non-zero status stderr Capturing the output of command "echo '$$$$'" Global: OUTPUT = $$$$ diff --git a/contrib/bmake/unit-tests/var-op-shell.mk b/contrib/bmake/unit-tests/var-op-shell.mk index bd2a48f17cc4..4441efaf4a90 100644 --- a/contrib/bmake/unit-tests/var-op-shell.mk +++ b/contrib/bmake/unit-tests/var-op-shell.mk @@ -1,4 +1,4 @@ -# $NetBSD: var-op-shell.mk,v 1.6 2022/01/10 20:32:29 rillig Exp $ +# $NetBSD: var-op-shell.mk,v 1.8 2024/01/05 23:36:45 rillig Exp $ # # Tests for the != variable assignment operator, which runs its right-hand # side through the shell. @@ -28,12 +28,14 @@ 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 .if ${OUTPUT} != "failed" . error .endif # A command with empty output may fail as well. +# expect+1: warning: "false" returned non-zero status OUTPUT!= false .if ${OUTPUT} != "" . error @@ -56,12 +58,14 @@ OUTPUT!= echo "before"; false; echo "after" # This should result in a warning about "exited on a signal". # This used to be kill -14 (SIGALRM), but that stopped working on # Darwin18 after recent update. +# expect+1: warning: "kill $$" exited on a signal OUTPUT!= kill $$$$ .if ${OUTPUT} != "" . error .endif # A nonexistent command produces a non-zero exit status. +# expect+1: warning: "/bin/no/such/command" returned non-zero status OUTPUT!= /bin/no/such/command .if ${OUTPUT} != "" . error @@ -87,4 +91,22 @@ OUTPUT!= echo '$$$$$$$$' OUTPUT!= echo '$$$$$$$$' .MAKEFLAGS: -d0 + +# Since main.c 1.607 from 2024-01-05, long shell commands are not run directly +# via '$shell -c $command', they are first written to a temporary file that is +# then fed to the shell via '$shell $tmpfile'. +OUTPUT_SHORT!= echo "$$0" +OUTPUT_LONG!= echo "$$0" || : ${:U:range=1000} +# When running '$shell -c $command', '$0' in the shell evaluates to the name +# of the shell. +.if ${OUTPUT_SHORT} != ${.SHELL:T} +. error +.endif +# When running '$shell $tmpfile', '$0' in the shell evaluates to the name of +# the temporary file. +.if !${OUTPUT_LONG:M*/make*} +. error +.endif + + all: diff --git a/contrib/bmake/unit-tests/var-readonly.exp b/contrib/bmake/unit-tests/var-readonly.exp new file mode 100644 index 000000000000..ae266753ee71 --- /dev/null +++ b/contrib/bmake/unit-tests/var-readonly.exp @@ -0,0 +1,4 @@ +Global: ignoring delete 'N' as it is read-only +Global: .MAKEFLAGS = -r -k -d v -d +Global: .MAKEFLAGS = -r -k -d v -d 0 +exit status 0 diff --git a/contrib/bmake/unit-tests/var-readonly.mk b/contrib/bmake/unit-tests/var-readonly.mk new file mode 100644 index 000000000000..e9ff6f38819f --- /dev/null +++ b/contrib/bmake/unit-tests/var-readonly.mk @@ -0,0 +1,27 @@ +# $NetBSD: var-readonly.mk,v 1.4 2023/12/20 08:42:10 rillig Exp $ + +# the answer +N = 42 +.READONLY: N +# this should be ignored +N = 666 +.if ${N} != 42 +.error N ($N) should be 42 +.endif + +# undef should fail +.MAKEFLAGS: -dv +.undef N +.ifndef N +.error N should not be undef'd +.endif +.MAKEFLAGS: -d0 + +.NOREADONLY: N +# now we can change it +N = 69 +.if ${N} == 42 +.error N should not be 42 +.endif + +all: diff --git a/contrib/bmake/unit-tests/var-recursive.exp b/contrib/bmake/unit-tests/var-recursive.exp index 44c381f94ff9..5415dc93a53d 100644 --- a/contrib/bmake/unit-tests/var-recursive.exp +++ b/contrib/bmake/unit-tests/var-recursive.exp @@ -1,19 +1,19 @@ -make: "var-recursive.mk" line 20: still there -Variable DIRECT is recursive. - in var-recursive.mk:21 +make: "var-recursive.mk" line 21: still there +make: Variable DIRECT is recursive. + in var-recursive.mk:22 make: stopped in unit-tests -Variable INDIRECT1 is recursive. - in var-recursive.mk:28 +make: Variable INDIRECT1 is recursive. + in var-recursive.mk:29 make: stopped in unit-tests -make: "var-recursive.mk" line 35: ok -Variable V is recursive. - in var-recursive.mk:43 +make: "var-recursive.mk" line 37: ok +make: Variable V is recursive. + in var-recursive.mk:45 make: stopped in unit-tests : OK -In a command near "var-recursive.mk" line 55: Variable VAR is recursive. +In a command near "var-recursive.mk" line 57: make[1]: Variable VAR is recursive. make: stopped in unit-tests exit status 0 diff --git a/contrib/bmake/unit-tests/var-recursive.mk b/contrib/bmake/unit-tests/var-recursive.mk index 1825c8a63120..72231656673c 100644 --- a/contrib/bmake/unit-tests/var-recursive.mk +++ b/contrib/bmake/unit-tests/var-recursive.mk @@ -1,6 +1,6 @@ -# $NetBSD: var-recursive.mk,v 1.4 2022/01/29 10:21:26 rillig Exp $ +# $NetBSD: var-recursive.mk,v 1.6 2023/11/19 21:47:52 rillig Exp $ # -# Tests for variable expressions that refer to themselves and thus +# Tests for expressions that refer to themselves and thus # cannot be evaluated. TESTS= direct indirect conditional short target @@ -17,6 +17,7 @@ all: .elif ${TEST} == direct DIRECT= ${DIRECT} # Defining a recursive variable is not yet an error. +# expect+1: still there . info still there # Therefore this line is printed. . info ${DIRECT} # But expanding the variable is an error. @@ -32,6 +33,7 @@ INDIRECT2= ${INDIRECT1} # The variable refers to itself, but only in the branch of a condition that # is never satisfied and is thus not evaluated. CONDITIONAL= ${1:?ok:${CONDITIONAL}} +# expect+1: ok . info ${CONDITIONAL} .elif ${TEST} == short diff --git a/contrib/bmake/unit-tests/var-scope-cmdline.exp b/contrib/bmake/unit-tests/var-scope-cmdline.exp index a1227a1dd1f2..c663a9069a9f 100644 --- a/contrib/bmake/unit-tests/var-scope-cmdline.exp +++ b/contrib/bmake/unit-tests/var-scope-cmdline.exp @@ -1,4 +1,4 @@ -make: "var-scope-cmdline.mk" line 67: global -make: "var-scope-cmdline.mk" line 76: makeflags +make: "var-scope-cmdline.mk" line 72: global +make: "var-scope-cmdline.mk" line 82: makeflags makeflags exit status 0 diff --git a/contrib/bmake/unit-tests/var-scope-cmdline.mk b/contrib/bmake/unit-tests/var-scope-cmdline.mk index 1f4a3e700253..5c0f246a0a22 100644 --- a/contrib/bmake/unit-tests/var-scope-cmdline.mk +++ b/contrib/bmake/unit-tests/var-scope-cmdline.mk @@ -1,4 +1,4 @@ -# $NetBSD: var-scope-cmdline.mk,v 1.1 2022/01/23 16:25:54 rillig Exp $ +# $NetBSD: var-scope-cmdline.mk,v 1.4 2023/11/19 21:47:52 rillig Exp $ # # Tests for variables specified on the command line. # @@ -55,15 +55,20 @@ # temporary loop variable after finishing the loop. It was probably not # intended back then that a side effect of this seemingly simple change was # that both global and cmdline variables could now be undefined at will as a -# side effect of evaluating a variable expression. As of 2021-02-23, this is +# side effect of evaluating an expression. As of 2021-02-23, this is # still possible. # # Most cmdline variables are set at the very beginning, when parsing the # command line arguments. Using the special target '.MAKEFLAGS', it is # possible to set cmdline variables at any later time. +# +# See also: +# varcmd.mk +# varname-makeflags.mk # A normal global variable, without any cmdline variable nearby. VAR= global +# expect+1: global .info ${VAR} # The global variable is "overridden" by simply deleting it and then @@ -73,6 +78,7 @@ VAR= global # # See varmod-loop.mk for a non-obvious way to undefine a cmdline variable. .MAKEFLAGS: VAR=makeflags +# expect+1: makeflags .info ${VAR} # If Var_SetWithFlags should ever forget to delete the global variable, diff --git a/contrib/bmake/unit-tests/var-scope-local-legacy.exp b/contrib/bmake/unit-tests/var-scope-local-legacy.exp index 39a9383953dd..33ce145fb8fd 100644 --- a/contrib/bmake/unit-tests/var-scope-local-legacy.exp +++ b/contrib/bmake/unit-tests/var-scope-local-legacy.exp @@ -1 +1,6 @@ +: LEN4=undef_ +: XY=undef_ +: AF=undef_ +: %D=undef_ %F=undef_ +: @D=global-value_ @F=all_ exit status 0 diff --git a/contrib/bmake/unit-tests/var-scope-local-legacy.mk b/contrib/bmake/unit-tests/var-scope-local-legacy.mk index e519d63e7c51..70bc20fd9848 100644 --- a/contrib/bmake/unit-tests/var-scope-local-legacy.mk +++ b/contrib/bmake/unit-tests/var-scope-local-legacy.mk @@ -1,8 +1,35 @@ -# $NetBSD: var-scope-local-legacy.mk,v 1.1 2022/01/23 16:25:54 rillig Exp $ +# $NetBSD: var-scope-local-legacy.mk,v 1.3 2023/12/17 14:07:22 rillig Exp $ # # Tests for legacy target-local variables, such as ${<F} or ${@D}. -# TODO: Implementation -all: - @:; +# In the global or command line scopes, the legacy forms are not recognized, +# as the target-specific variables are not available either. The expressions +# are retained so that they can be resolved later, in the target scope. +.if "${@D}" != "\${@D}" +. error +.endif + +# It's possible to define variables of the legacy name in the global or +# command line scope, and they override the target-local variables, leading to +# unnecessary confusion. +@D= global-value +.if "${@D}" != "global-value" +. error +.endif + + +all: .PHONY + # Only variables of length 2 can be legacy, this one cannot. + : LEN4=${LEN4:Uundef}_ + # The second character of the name must be 'D' or 'F'. + : XY=${XY:Uundef}_ + # The first character must name one of the 7 predefined local + # variables, 'A' is not such a character. + : AF=${AF:Uundef}_ + # The variable '.MEMBER' is undefined, therefore '%D' and '%F' are + # undefined as well. + : %D=${%D:Uundef}_ %F=${%F:Uundef}_ + # The directory name of the target is shadowed by the global variable, + # it would be '.' otherwise. The basename is 'all'. + : @D=${@D:Uundef}_ @F=${@F:Uundef}_ diff --git a/contrib/bmake/unit-tests/var-scope-local.exp b/contrib/bmake/unit-tests/var-scope-local.exp index 403bf83884f7..eddf5985a0ed 100644 --- a/contrib/bmake/unit-tests/var-scope-local.exp +++ b/contrib/bmake/unit-tests/var-scope-local.exp @@ -1,21 +1,71 @@ -Global: .ALLTARGETS = one -Global: .ALLTARGETS = one two +Global: .ALLTARGETS = all target-rule.ext dir/subdir/target-rule.ext target-rule.ir-gen-from dir/subdir/target-rule-dir.ir-gen-from inference-rule.ir-to dir/subdir/inference-rule.ir-to inference-rule.ir-from dir/subdir/inference-rule.ir-from inference-rule-chain.ir-to dir/subdir/inference-rule-chain.ir-to inference-rule-chain.ir-gen-from dir/subdir/inference-rule-chain.ir-gen-from one +Global: .ALLTARGETS = all target-rule.ext dir/subdir/target-rule.ext target-rule.ir-gen-from dir/subdir/target-rule-dir.ir-gen-from inference-rule.ir-to dir/subdir/inference-rule.ir-to inference-rule.ir-from dir/subdir/inference-rule.ir-from inference-rule-chain.ir-to dir/subdir/inference-rule-chain.ir-to inference-rule-chain.ir-gen-from dir/subdir/inference-rule-chain.ir-gen-from one two Var_Parse: ${.MAKE.TARGET_LOCAL_VARIABLES} (eval) -Var_SetExpand: variable name "" expands to empty string, with value "three" - ignored -Var_SetExpand: variable name "" expands to empty string, with value "three" - ignored +one: ignoring ' = three' as the variable name '' expands to empty +two: ignoring ' = three' as the variable name '' expands to empty Global: one two = # (empty) Global: one two = three Global: .MAKEFLAGS = -r -k -d v -d Global: .MAKEFLAGS = -r -k -d v -d 0 +target-rule.ext: @ = <target-rule.ext> +target-rule.ext: % = <undefined> +target-rule.ext: ? = <> +target-rule.ext: < = <undefined> +target-rule.ext: * = <target-rule.ext> +dir/subdir/target-rule.ext: @ = <dir/subdir/target-rule.ext> +dir/subdir/target-rule.ext: % = <undefined> +dir/subdir/target-rule.ext: ? = <> +dir/subdir/target-rule.ext: < = <undefined> +dir/subdir/target-rule.ext: * = <dir/subdir/target-rule.ext> +target-rule.ir-gen-from: @ = <target-rule.ir-gen-from> +target-rule.ir-gen-from: % = <undefined> +target-rule.ir-gen-from: ? = <> +target-rule.ir-gen-from: < = <undefined> +target-rule.ir-gen-from: * = <target-rule> +dir/subdir/target-rule-dir.ir-gen-from: @ = <dir/subdir/target-rule-dir.ir-gen-from> +dir/subdir/target-rule-dir.ir-gen-from: % = <undefined> +dir/subdir/target-rule-dir.ir-gen-from: ? = <> +dir/subdir/target-rule-dir.ir-gen-from: < = <undefined> +dir/subdir/target-rule-dir.ir-gen-from: * = <dir/subdir/target-rule-dir> +inference-rule.ir-to: @ = <inference-rule.ir-to> +inference-rule.ir-to: % = <undefined> +inference-rule.ir-to: ? = <inference-rule.ir-from> +inference-rule.ir-to: < = <inference-rule.ir-from> +inference-rule.ir-to: * = <inference-rule> +dir/subdir/inference-rule.ir-to: @ = <dir/subdir/inference-rule.ir-to> +dir/subdir/inference-rule.ir-to: % = <undefined> +dir/subdir/inference-rule.ir-to: ? = <dir/subdir/inference-rule.ir-from> +dir/subdir/inference-rule.ir-to: < = <dir/subdir/inference-rule.ir-from> +dir/subdir/inference-rule.ir-to: * = <dir/subdir/inference-rule> +inference-rule-chain.ir-from: @ = <inference-rule-chain.ir-from> +inference-rule-chain.ir-from: % = <undefined> +inference-rule-chain.ir-from: ? = <inference-rule-chain.ir-gen-from> +inference-rule-chain.ir-from: < = <inference-rule-chain.ir-gen-from> +inference-rule-chain.ir-from: * = <inference-rule-chain> +inference-rule-chain.ir-to: @ = <inference-rule-chain.ir-to> +inference-rule-chain.ir-to: % = <undefined> +inference-rule-chain.ir-to: ? = <inference-rule-chain.ir-from> +inference-rule-chain.ir-to: < = <inference-rule-chain.ir-from> +inference-rule-chain.ir-to: * = <inference-rule-chain> +dir/subdir/inference-rule-chain.ir-from: @ = <dir/subdir/inference-rule-chain.ir-from> +dir/subdir/inference-rule-chain.ir-from: % = <undefined> +dir/subdir/inference-rule-chain.ir-from: ? = <dir/subdir/inference-rule-chain.ir-gen-from> +dir/subdir/inference-rule-chain.ir-from: < = <dir/subdir/inference-rule-chain.ir-gen-from> +dir/subdir/inference-rule-chain.ir-from: * = <dir/subdir/inference-rule-chain> +dir/subdir/inference-rule-chain.ir-to: @ = <dir/subdir/inference-rule-chain.ir-to> +dir/subdir/inference-rule-chain.ir-to: % = <undefined> +dir/subdir/inference-rule-chain.ir-to: ? = <dir/subdir/inference-rule-chain.ir-from> +dir/subdir/inference-rule-chain.ir-to: < = <dir/subdir/inference-rule-chain.ir-from> +dir/subdir/inference-rule-chain.ir-to: * = <dir/subdir/inference-rule-chain> : Making var-scope-local.c out of nothing. : Making var-scope-local.o from var-scope-local.c. : Making basename "var-scope-local.o" in "." from "var-scope-local.c" in ".". -: Making var-scope-local-assign.o with VAR="local". -: Making var-scope-local-append.o with VAR="local to var-scope-local-append.o". -: Making var-scope-local-append-global.o with VAR="global+local". -: Making var-scope-local-default.o with VAR="global". -: Making var-scope-local-subst.o with VAR="global+local". -: Making var-scope-local-shell.o with VAR="output". -: var-scope-local-use.o uses .USE VAR="global" +Making var-scope-local-assign.o with make 'local' and env 'local'. +Making var-scope-local-append.o with make 'local to var-scope-local-append.o' and env 'local to var-scope-local-append.o'. +Making var-scope-local-append-global.o with make 'global+local' and env 'global+local'. +Making var-scope-local-default.o with make 'global' and env 'global'. +Making var-scope-local-subst.o with make 'global+local' and env 'global+local'. +Making var-scope-local-shell.o with make 'output' and env 'output'. +Making .USE var-scope-local-use.o with make 'global' and env 'global'. : all overwritten exit status 0 diff --git a/contrib/bmake/unit-tests/var-scope-local.mk b/contrib/bmake/unit-tests/var-scope-local.mk index ed1362444504..7a031373e7da 100644 --- a/contrib/bmake/unit-tests/var-scope-local.mk +++ b/contrib/bmake/unit-tests/var-scope-local.mk @@ -1,4 +1,4 @@ -# $NetBSD: var-scope-local.mk,v 1.5 2022/02/09 21:09:24 rillig Exp $ +# $NetBSD: var-scope-local.mk,v 1.11 2024/03/05 23:07:58 rillig Exp $ # # Tests for target-local variables, such as ${.TARGET} or $@. These variables # are relatively short-lived as they are created just before making the @@ -12,6 +12,64 @@ .MAIN: all +# Target-local variables in a target rule +# +# In target rules, '$*' only strips the extension off the pathname if the +# extension is listed in '.SUFFIXES'. +# +# expect: target-rule.ext: * = <target-rule.ext> +all: target-rule.ext dir/subdir/target-rule.ext +target-rule.ext dir/subdir/target-rule.ext: .PHONY + @echo '$@: @ = <${@:Uundefined}>' + @echo '$@: % = <${%:Uundefined}>' + @echo '$@: ? = <${?:Uundefined}>' + @echo '$@: < = <${<:Uundefined}>' + @echo '$@: * = <${*:Uundefined}>' + +.SUFFIXES: .ir-gen-from .ir-from .ir-to + +# In target rules, '$*' strips the extension off the pathname of the target +# if the extension is listed in '.SUFFIXES'. +# +# expect: target-rule.ir-gen-from: * = <target-rule> +all: target-rule.ir-gen-from dir/subdir/target-rule-dir.ir-gen-from +target-rule.ir-gen-from dir/subdir/target-rule-dir.ir-gen-from: + @echo '$@: @ = <${@:Uundefined}>' + @echo '$@: % = <${%:Uundefined}>' + @echo '$@: ? = <${?:Uundefined}>' + @echo '$@: < = <${<:Uundefined}>' + @echo '$@: * = <${*:Uundefined}>' + +.ir-from.ir-to: + @echo '$@: @ = <${@:Uundefined}>' + @echo '$@: % = <${%:Uundefined}>' + @echo '$@: ? = <${?:Uundefined}>' + @echo '$@: < = <${<:Uundefined}>' + @echo '$@: * = <${*:Uundefined}>' +.ir-gen-from.ir-from: + @echo '$@: @ = <${@:Uundefined}>' + @echo '$@: % = <${%:Uundefined}>' + @echo '$@: ? = <${?:Uundefined}>' + @echo '$@: < = <${<:Uundefined}>' + @echo '$@: * = <${*:Uundefined}>' + +# Target-local variables in an inference rule +all: inference-rule.ir-to dir/subdir/inference-rule.ir-to +inference-rule.ir-from: .PHONY +dir/subdir/inference-rule.ir-from: .PHONY + +# Target-local variables in a chain of inference rules +all: inference-rule-chain.ir-to dir/subdir/inference-rule-chain.ir-to +inference-rule-chain.ir-gen-from: .PHONY +dir/subdir/inference-rule-chain.ir-gen-from: .PHONY + +# The run-time 'check' directives from above happen after the parse-time +# 'check' directives from below. +# +# expect-reset + +# Deferred evaluation during parsing +# # The target-local variables can be used in expressions, just like other # variables. When these expressions are evaluated outside of a target, these # expressions are not yet expanded, instead their text is preserved, to allow @@ -20,8 +78,8 @@ # # Conditions from .if directives are evaluated in the scope of the command # line, which means that variables from the command line, from the global -# scope and from the environment are resolved, in this order (but see the -# command line option '-e'). In that phase, expressions involving +# scope and from the environment are resolved, in this precedence order (but +# see the command line option '-e'). In that phase, expressions involving # target-local variables need to be preserved, including the exact names of # the variables. # @@ -49,7 +107,7 @@ .if $(@) != "\$\(@)" . error .endif -# If the variable expression contains modifiers, the behavior depends on the +# If the expression contains modifiers, the behavior depends on the # actual modifiers. The modifier ':M' keeps the expression in the state # 'undefined'. Since the expression is still undefined after evaluating all # the modifiers, the value of the expression is discarded and the expression @@ -77,17 +135,21 @@ .endif +# Custom local variables +# # Additional target-local variables may be defined in dependency lines. .MAKEFLAGS: -dv # In the following line, the ':=' may either be interpreted as an assignment # operator or as the dependency operator ':', followed by an empty variable # name and the assignment operator '='. It is the latter since in an -# assignment, the left-hand side must be at most a single word. The empty -# variable name is expanded twice, once for 'one' and once for 'two'. -# expect: Var_SetExpand: variable name "" expands to empty string, with value "three" - ignored -# expect: Var_SetExpand: variable name "" expands to empty string, with value "three" - ignored +# assignment, the left-hand side must be a single word or empty. +# +# The empty variable name is expanded twice, once for 'one' and once for +# 'two'. +# expect: one: ignoring ' = three' as the variable name '' expands to empty +# expect: two: ignoring ' = three' as the variable name '' expands to empty one two:=three -# If the two targets to the left are generated by a variable expression, the +# If the two targets to the left are generated by an expression, the # line is parsed as a variable assignment since its left-hand side is a single # word. # expect: Global: one two = three @@ -137,13 +199,14 @@ var-scope-local-append-global.o \ var-scope-local-default.o \ var-scope-local-subst.o \ var-scope-local-shell.o: - : Making ${.TARGET} with VAR="${VAR}". + @echo "Making ${.TARGET} with make '"${VAR:Q}"' and env '$$VAR'." # Target-local variables are enabled by default. Force them to be enabled # just in case a test above has disabled them. .MAKE.TARGET_LOCAL_VARIABLES= yes VAR= global +.export VAR # If the sources of a dependency line look like a variable assignment, make # treats them as such. There is only a single variable assignment per @@ -151,7 +214,7 @@ VAR= global # irrelevant. # # expect-reset -# expect: : Making var-scope-local-assign.o with VAR="local". +# expect: Making var-scope-local-assign.o with make 'local' and env 'local'. var-scope-local-assign.o: VAR= local # Assignments using '+=' do *not* look up the global value, instead they only @@ -161,9 +224,9 @@ var-scope-local-append.o: VAR+= local # behaves as expected. Note that the expression '${.TARGET}' is not resolved # when parsing the dependency line, its evaluation is deferred until the # target is actually made. -# expect: : Making var-scope-local-append.o with VAR="local to var-scope-local-append.o". +# expect: Making var-scope-local-append.o with make 'local to var-scope-local-append.o' and env 'local to var-scope-local-append.o'. var-scope-local-append.o: VAR += to ${.TARGET} -# To access the value of a global variable, use a variable expression. This +# To access the value of a global variable, use an expression. This # expression is expanded before parsing the whole dependency line. Since the # expansion happens to the right of the dependency operator ':', the expanded # text does not influence parsing of the dependency line. Since the expansion @@ -171,7 +234,7 @@ var-scope-local-append.o: VAR += to ${.TARGET} # not influence the parsing of the variable assignment. The effective # variable assignment, after expanding the whole line first, is thus # 'VAR= global+local'. -# expect: : Making var-scope-local-append-global.o with VAR="global+local". +# expect: Making var-scope-local-append-global.o with make 'global+local' and env 'global+local'. var-scope-local-append-global.o: VAR= ${VAR}+local var-scope-local-default.o: VAR ?= first @@ -179,7 +242,7 @@ var-scope-local-default.o: VAR ?= second # XXX: '?=' does look at the global variable. That's a long-standing # inconsistency between the assignment operators '+=' and '?='. See # Var_AppendExpand and VarAssign_Eval. -# expect: : Making var-scope-local-default.o with VAR="global". +# expect: Making var-scope-local-default.o with make 'global' and env 'global'. # Using the variable assignment operator ':=' provides another way of # accessing a global variable and extending it with local modifications. The @@ -187,7 +250,7 @@ var-scope-local-default.o: VAR ?= second # dependency line as a whole. After that, the parser sees the variable # assignment as 'VAR := ${VAR}+local' and searches for the variable 'VAR' in # the usual scopes, picking up the variable from the global scope. -# expect: : Making var-scope-local-subst.o with VAR="global+local". +# expect: Making var-scope-local-subst.o with make 'global+local' and env 'global+local'. var-scope-local-subst.o: VAR := $${VAR}+local # The variable assignment operator '!=' assigns the output of the shell @@ -199,38 +262,9 @@ var-scope-local-shell.o: VAR != echo output # While VAR=use will be set for a .USE node, it will never be seen since only # the ultimate target's context is searched; the variable assignments from the # .USE target are not copied to the ultimate target's. -# expect: : var-scope-local-use.o uses .USE VAR="global" +# expect: Making .USE var-scope-local-use.o with make 'global' and env 'global'. a_use: .USE VAR=use - : ${.TARGET} uses .USE VAR="${VAR}" + @echo "Making .USE ${.TARGET} with make '"${VAR:Q}"' and env '$$VAR'." all: var-scope-local-use.o var-scope-local-use.o: a_use - - -# Since parse.c 1.656 from 2022-01-27 and before parse.c 1.662 from -# 2022-02-05, there was an out-of-bounds read in Parse_IsVar when looking for -# a variable assignment in a dependency line with trailing whitespace. Lines -# without trailing whitespace were not affected. Global variable assignments -# were guaranteed to have no trailing whitespace and were thus not affected. -# -# Try to reproduce some variants that may lead to a crash, depending on the -# memory allocator. To get a crash, the terminating '\0' of the line must be -# the last byte of a memory page. The expression '${:U}' forces this trailing -# whitespace. - -# On FreeBSD x86_64, a crash could in some cases be forced using the following -# line, which has length 47, so the terminating '\0' may end up at an address -# of the form 0xXXXX_XXXX_XXXX_Xfff: -Try_to_crash_FreeBSD.xxxxxxxxxxxxxxxxxx: 12345 ${:U} - -# The following line has length 4095, so line[4095] == '\0'. If the line is -# allocated on a page boundary and the following page is not mapped, this line -# leads to a segmentation fault. -${:U:range=511:@_@1234567@:ts.}: 12345 ${:U} - -# The following line has length 8191, so line[8191] == '\0'. If the line is -# allocated on a page boundary and the following page is not mapped, this line -# leads to a segmentation fault. -${:U:range=1023:@_@1234567@:ts.}: 12345 ${:U} - -12345: diff --git a/contrib/bmake/unit-tests/varcmd.mk b/contrib/bmake/unit-tests/varcmd.mk index 12739df30926..ec0cf96ed75c 100644 --- a/contrib/bmake/unit-tests/varcmd.mk +++ b/contrib/bmake/unit-tests/varcmd.mk @@ -1,4 +1,4 @@ -# $NetBSD: varcmd.mk,v 1.6 2021/02/16 19:43:09 rillig Exp $ +# $NetBSD: varcmd.mk,v 1.7 2023/04/07 05:54:16 rillig Exp $ # # Test behaviour of recursive make and vars set on command line. # @@ -12,6 +12,10 @@ # be rewritten to make it clear why there is a difference and why this is # actually intended. Removing that large block of code makes only this test # and vardebug.mk fail, which is not enough. +# +# See also: +# var-scope-cmdline.mk +# varname-makeflags.mk FU= fu FOO?= foo diff --git a/contrib/bmake/unit-tests/vardebug.exp b/contrib/bmake/unit-tests/vardebug.exp index 19e5c9c9fdd0..a0aa6a301800 100644 --- a/contrib/bmake/unit-tests/vardebug.exp +++ b/contrib/bmake/unit-tests/vardebug.exp @@ -1,13 +1,13 @@ -Global: delete FROM_CMDLINE (not found) +Global: ignoring delete 'FROM_CMDLINE' as it is not found Command: FROM_CMDLINE = # (empty) Global: .MAKEOVERRIDES = FROM_CMDLINE Global: VAR = added Global: VAR = overwritten Global: delete VAR -Global: delete VAR (not found) -Var_SetExpand: variable name "${:U}" expands to empty string, with value "empty name" - ignored -Var_AppendExpand: variable name "${:U}" expands to empty string, with value "empty name" - ignored -Global: FROM_CMDLINE = overwritten ignored! +Global: ignoring delete 'VAR' as it is not found +Global: ignoring ' = empty name' as the variable name '${:U}' expands to empty +Global: ignoring ' += empty name' as the variable name '${:U}' expands to empty +Global: ignoring 'FROM_CMDLINE = overwritten' due to a command line variable of the same name Global: VAR = 1 Global: VAR = 1 2 Global: VAR = 1 2 3 @@ -54,14 +54,14 @@ Var_Parse: ${:Uvariable:unknown} (eval-defined) Evaluating modifier ${:U...} on value "" (eval-defined, undefined) Result of ${:Uvariable} is "variable" (eval-defined, defined) Evaluating modifier ${:u...} on value "variable" (eval-defined, defined) -make: "vardebug.mk" line 44: Unknown modifier "unknown" +make: "vardebug.mk" line 63: Unknown modifier "unknown" Result of ${:unknown} is error (eval-defined, defined) -make: "vardebug.mk" line 44: Malformed conditional (${:Uvariable:unknown}) +make: "vardebug.mk" line 63: Malformed conditional (${:Uvariable:unknown}) Var_Parse: ${UNDEFINED} (eval-defined) -make: "vardebug.mk" line 53: Malformed conditional (${UNDEFINED}) -Global: delete .SHELL (not found) +make: "vardebug.mk" line 73: Malformed conditional (${UNDEFINED}) +Global: ignoring delete '.SHELL' as it is not found Command: .SHELL = </path/to/shell> -Command: .SHELL = overwritten ignored (read-only) +Command: ignoring '.SHELL = overwritten' as it is read-only Global: .MAKEFLAGS = -r -k -d v -d Global: .MAKEFLAGS = -r -k -d v -d 0 make: Fatal errors encountered -- cannot continue diff --git a/contrib/bmake/unit-tests/vardebug.mk b/contrib/bmake/unit-tests/vardebug.mk index 4a16a7f2797f..b9b094772b54 100644 --- a/contrib/bmake/unit-tests/vardebug.mk +++ b/contrib/bmake/unit-tests/vardebug.mk @@ -1,32 +1,46 @@ -# $NetBSD: vardebug.mk,v 1.7 2021/02/04 21:42:47 rillig Exp $ +# $NetBSD: vardebug.mk,v 1.9 2023/12/20 09:46:00 rillig Exp $ # # Demonstrates the debugging output for var.c. .MAKEFLAGS: -dv FROM_CMDLINE= +# expect: Global: VAR = added VAR= added # VarAdd +# expect: Global: VAR = overwritten VAR= overwritten # Var_Set -.undef VAR # Var_Delete (found) -.undef VAR # Var_Delete (not found) +# expect: Global: delete VAR +.undef VAR +# expect: Global: ignoring delete 'VAR' as it is not found +.undef VAR # The variable with the empty name cannot be set at all. +# expect: Global: ignoring ' = empty name' as the variable name '${:U}' expands to empty ${:U}= empty name # Var_Set +# expect: Global: ignoring ' += empty name' as the variable name '${:U}' expands to empty ${:U}+= empty name # Var_Append FROM_CMDLINE= overwritten # Var_Set (ignored) +# expect: Global: VAR = 1 VAR= 1 +# expect: Global: VAR = 1 2 VAR+= 2 +# expect: Global: VAR = 1 2 3 VAR+= 3 +# expect: Pattern for ':M' is "[2]" +# expect: Result of ${VAR:M[2]} is "2" .if ${VAR:M[2]} # ModifyWord_Match .endif -.if ${VAR:N[2]} # ModifyWord_NoMatch (no debug output) +# expect: Pattern for ':N' is "[2]" +# expect: Result of ${VAR:N[2]} is "1 3" +.if ${VAR:N[2]} # ModifyWord_NoMatch .endif .if ${VAR:S,2,two,} # ParseModifierPart .endif +# expect: Result of ${VAR:Q} is "1\ 2\ 3" .if ${VAR:Q} # VarQuote .endif @@ -34,13 +48,18 @@ VAR+= 3 .endif # ApplyModifiers, "Got ..." +# expect: Result of ${:Mvalu[e]} is "value" (eval-defined, defined) .if ${:Uvalue:${:UM*e}:Mvalu[e]} .endif +# expect: Global: delete VAR .undef ${:UVAR} # Var_Delete # When ApplyModifiers results in an error, this appears in the debug log # as "is error", without surrounding quotes. +# expect: Result of ${:unknown} is error (eval-defined, defined) +# expect+2: Malformed conditional (${:Uvariable:unknown}) +# expect+1: Unknown modifier "unknown" .if ${:Uvariable:unknown} .endif @@ -50,15 +69,14 @@ VAR+= 3 # There is a specialized error message for "Undefined variable", but as of # 2020-08-08, that is not covered by any unit tests. It might even be # unreachable. +# expect+1: Malformed conditional (${UNDEFINED}) .if ${UNDEFINED} .endif # By default, .SHELL is not defined and thus can be set. As soon as it is # accessed, it is initialized in the command line scope (during VarFind), # where it is set to read-only. Assigning to it is ignored. +# expect: Command: ignoring '.SHELL = overwritten' as it is read-only .MAKEFLAGS: .SHELL=overwritten .MAKEFLAGS: -d0 - -all: - @: diff --git a/contrib/bmake/unit-tests/varmisc.exp b/contrib/bmake/unit-tests/varmisc.exp index f56f72d0ab9c..61e6a49963a0 100644 --- a/contrib/bmake/unit-tests/varmisc.exp +++ b/contrib/bmake/unit-tests/varmisc.exp @@ -17,12 +17,9 @@ false FALSE do not evaluate or expand :? if discarding is set -year=2016 month=04 day=01 -date=20160401 Version=123.456.789 == 123456789 Literal=3.4.5 == 3004005 We have target specific vars -MAN= make.1 save-dollars: 0 = $ save-dollars: 1 = $$ save-dollars: 2 = $$ @@ -54,7 +51,7 @@ make: Unclosed variable "UNCLOSED" make: Unclosed variable "UNCLOSED" make: Unclosed variable "PATTERN" -make: Unclosed variable expression, expecting '}' for modifier "M${PATTERN" of variable "UNCLOSED" with value "" +make: Unclosed expression, expecting '}' for modifier "M${PATTERN" of variable "UNCLOSED" with value "" make: Unclosed variable "param" make: Unclosed variable "UNCLOSED." diff --git a/contrib/bmake/unit-tests/varmisc.mk b/contrib/bmake/unit-tests/varmisc.mk index 81818f3fb8bb..f6a0e4da2d88 100644 --- a/contrib/bmake/unit-tests/varmisc.mk +++ b/contrib/bmake/unit-tests/varmisc.mk @@ -1,10 +1,10 @@ -# $Id: varmisc.mk,v 1.25 2021/12/07 00:03:11 sjg Exp $ -# $NetBSD: varmisc.mk,v 1.32 2021/12/05 10:02:51 rillig Exp $ +# $Id: varmisc.mk,v 1.26 2023/11/25 01:39:31 sjg Exp $ +# $NetBSD: varmisc.mk,v 1.33 2023/10/19 18:24:33 rillig Exp $ # # Miscellaneous variable tests. all: unmatched_var_paren D_true U_true D_false U_false Q_lhs Q_rhs NQ_none \ - strftime cmpv manok + cmpv all: save-dollars all: export-appended all: parse-dynamic @@ -47,13 +47,6 @@ NQ_none: @echo do not evaluate or expand :? if discarding @echo ${VSET:U${1:L:?${True}:${False}}} -April1= 1459494000 - -# slightly contorted syntax to use utc via variable -strftime: - @echo ${year=%Y month=%m day=%d:L:gmtime=1459494000} - @echo date=${%Y%m%d:L:${gmtime=${April1}:L}} - # big jumps to handle 3 digits per step M_cmpv.units= 1 1000 1000000 M_cmpv= S,., ,g:_:range:@i@+ $${_:[-$$i]} \* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh @@ -66,17 +59,6 @@ cmpv: @echo Literal=3.4.5 == ${3.4.5:L:${M_cmpv}} @echo We have ${${.TARGET:T}.only} -# catch mishandling of nested variables in .for loop -MAN= -MAN1= make.1 -.for s in 1 2 -. if defined(MAN$s) && !empty(MAN$s) -MAN+= ${MAN$s} -. endif -.endfor - -manok: - @echo MAN=${MAN} # Test parsing of boolean values. # begin .MAKE.SAVE_DOLLARS; see Var_SetWithFlags and ParseBoolean. @@ -131,10 +113,10 @@ VAR.${PARAM}+= 2 .if ${VAR.+} != "1 2" . error "${VAR.+}" .endif -.for param in + ! ? +.for param in : + ! ? VAR.${param}= ${param} .endfor -.if ${VAR.+} != "+" || ${VAR.!} != "!" || ${VAR.?} != "?" +.if ${VAR.${:U\:}} != ":" || ${VAR.+} != "+" || ${VAR.!} != "!" || ${VAR.?} != "?" . error "${VAR.+}" "${VAR.!}" "${VAR.?}" .endif diff --git a/contrib/bmake/unit-tests/varmod-assign-shell.exp b/contrib/bmake/unit-tests/varmod-assign-shell.exp index 7bb41108cb62..b7c6cd223f24 100644 --- a/contrib/bmake/unit-tests/varmod-assign-shell.exp +++ b/contrib/bmake/unit-tests/varmod-assign-shell.exp @@ -1,4 +1,4 @@ -make: "varmod-assign-shell.mk" line 27: warning: "echo output; false" returned non-zero status +make: "varmod-assign-shell.mk" line 28: warning: "echo output; false" returned non-zero status Global: _ = # (empty) Var_Parse: ${ASSIGNED::!=echo output; ${:Ufalse}} (eval-keep-dollar-and-undefined) Evaluating modifier ${ASSIGNED::...} on value "previous" (eval-keep-dollar-and-undefined, regular) diff --git a/contrib/bmake/unit-tests/varmod-assign-shell.mk b/contrib/bmake/unit-tests/varmod-assign-shell.mk index d03692942d5b..6158bac14eaa 100644 --- a/contrib/bmake/unit-tests/varmod-assign-shell.mk +++ b/contrib/bmake/unit-tests/varmod-assign-shell.mk @@ -1,4 +1,4 @@ -# $NetBSD: varmod-assign-shell.mk,v 1.4 2022/01/10 20:32:29 rillig Exp $ +# $NetBSD: varmod-assign-shell.mk,v 1.5 2023/06/01 20:56:35 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,6 +24,7 @@ # assignment operator '!=' is another unnecessary inconsistency. DIRECT= previous +# expect+1: warning: "echo output; false" returned non-zero status DIRECT!= echo output; false ASSIGNED= previous diff --git a/contrib/bmake/unit-tests/varmod-assign.exp b/contrib/bmake/unit-tests/varmod-assign.exp index 1ad388418ab5..f258f92ea05b 100644 --- a/contrib/bmake/unit-tests/varmod-assign.exp +++ b/contrib/bmake/unit-tests/varmod-assign.exp @@ -12,6 +12,31 @@ Var_Parse: ${${VARNAME}} != "assigned-value" (eval-defined) Var_Parse: ${VARNAME}} != "assigned-value" (eval-defined) Global: .MAKEFLAGS = -r -k -d v -d Global: .MAKEFLAGS = -r -k -d v -d 0 +Var_Parse: ${CMD_CMD_VAR::=new-value} || ${CMD_GLOBAL_VAR::=new-value} || ${CMD_ENV_VAR::=new-value} || "${CMD_NEW_VAR::=new-value}" (eval-defined) +Evaluating modifier ${CMD_CMD_VAR::...} on value "cmd-value" +Modifier part: "new-value" +Command: CMD_CMD_VAR = new-value +Global: .MAKEOVERRIDES = FIRST LAST LAST LAST APPENDED RAN RAN RAN IT1 THEN1 IE2 ELSE2 CMD_CMD_VAR CMD_CMD_VAR +Result of ${CMD_CMD_VAR::=new-value} is "" +Var_Parse: ${CMD_GLOBAL_VAR::=new-value} || ${CMD_ENV_VAR::=new-value} || "${CMD_NEW_VAR::=new-value}" (eval-defined) +Evaluating modifier ${CMD_GLOBAL_VAR::...} on value "global-value" +Modifier part: "new-value" +Global: CMD_GLOBAL_VAR = new-value +Result of ${CMD_GLOBAL_VAR::=new-value} is "" +Var_Parse: ${CMD_ENV_VAR::=new-value} || "${CMD_NEW_VAR::=new-value}" (eval-defined) +Evaluating modifier ${CMD_ENV_VAR::...} on value "env-value" +Modifier part: "new-value" +Global: CMD_ENV_VAR = new-value +Result of ${CMD_ENV_VAR::=new-value} is "" +Var_Parse: ${CMD_NEW_VAR::=new-value}" (eval) +Evaluating modifier ${CMD_NEW_VAR::...} on value "" (eval, undefined) +Modifier part: "new-value" +Global: ignoring delete 'CMD_NEW_VAR' as it is not found +Command: CMD_NEW_VAR = new-value +Global: .MAKEOVERRIDES = FIRST LAST LAST LAST APPENDED RAN RAN RAN IT1 THEN1 IE2 ELSE2 CMD_CMD_VAR CMD_CMD_VAR CMD_NEW_VAR +Result of ${CMD_NEW_VAR::=new-value} is "" (eval, undefined) +Global: .MAKEFLAGS = -r -k -d v -d 0 -d v -d +Global: .MAKEFLAGS = -r -k -d v -d 0 -d v -d 0 make: Bad modifier ":" for variable "" mod-assign-empty: value} make: Bad modifier ":" for variable "" @@ -25,4 +50,11 @@ make: Unfinished modifier for "ASSIGN" ('}' missing) ok=word make: " echo word; false " returned non-zero status err=previous +Command: TARGET_CMD_VAR = cmd-value +Global: TARGET_GLOBAL_VAR = global-value +target: TARGET_TARGET_VAR = target-value +target: TARGET_TARGET_VAR = new-value +Global: TARGET_GLOBAL_VAR = new-value +Global: TARGET_ENV_VAR = new-value +target: TARGET_NEW_VAR = new-value exit status 0 diff --git a/contrib/bmake/unit-tests/varmod-assign.mk b/contrib/bmake/unit-tests/varmod-assign.mk index a6236253068d..f7112c47c935 100644 --- a/contrib/bmake/unit-tests/varmod-assign.mk +++ b/contrib/bmake/unit-tests/varmod-assign.mk @@ -1,40 +1,46 @@ -# $NetBSD: varmod-assign.mk,v 1.15 2022/02/09 21:09:24 rillig Exp $ +# $NetBSD: varmod-assign.mk,v 1.19 2024/01/07 11:42:22 rillig Exp $ # # Tests for the obscure ::= variable modifiers, which perform variable # assignments during evaluation, just like the = operator in C. +.if !make(target) + all: mod-assign-empty all: mod-assign-parse all: mod-assign-shell-error -# The modifier '::?=' applies the assignment operator '?=' 3 times. The +# In the following loop expression, +# the '::?=' modifier applies the assignment operator '?=' 3 times. The # operator '?=' only has an effect for the first time, therefore the variable # FIRST ends up with the value 1. .if "${1 2 3:L:@i@${FIRST::?=$i}@} first=${FIRST}" != " first=1" . error .endif -# The modifier '::=' applies the assignment operator '=' 3 times. The +# In the following loop expression, +# the modifier '::=' applies the assignment operator '=' 3 times. The # operator '=' overwrites the previous value, therefore the variable LAST ends # up with the value 3. .if "${1 2 3:L:@i@${LAST::=$i}@} last=${LAST}" != " last=3" . error .endif -# The modifier '::+=' applies the assignment operator '+=' 3 times. The +# In the following loop expression, +# the modifier '::+=' applies the assignment operator '+=' 3 times. The # operator '+=' appends 3 times to the variable, therefore the variable # APPENDED ends up with the value "1 2 3". .if "${1 2 3:L:@i@${APPENDED::+=$i}@} appended=${APPENDED}" != " appended=1 2 3" . error .endif -# The modifier '::!=' applies the assignment operator '!=' 3 times. Just as +# In the following loop expression, +# the modifier '::!=' applies the assignment operator '!=' 3 times. Just as # with the modifier '::=', the last value is stored in the RAN variable. .if "${1 2 3:L:@i@${RAN::!=${i:%=echo '<%>';}}@} ran=${RAN}" != " ran=<3>" . error .endif -# The assignments were performed as part of .if conditions and thus happened +# When a '::=' modifier is evaluated as part of an .if condition, it happens # in the command line scope. .if "${FIRST}, ${LAST}, ${APPENDED}, ${RAN}" != "1, 3, 1 2 3, <3>" . error @@ -116,7 +122,7 @@ APPEND.dollar= $${APPEND.indirect} .endif -# The assignment modifier can be used in a variable expression that is +# The assignment modifier can be used in an expression that is # enclosed in parentheses. In such a case, parsing stops at the first ')', # not at the first '}'. VAR= previous @@ -149,3 +155,54 @@ ${VARNAME}= initial-value # Sets 'VAR.${param}' to 'expanded'. . error .endif .MAKEFLAGS: -d0 + + +# Conditional directives are evaluated in command line scope. An assignment +# modifier that creates a new variable creates it in the command line scope. +# Existing variables are updated in their previous scope, and environment +# variables are created in the global scope, as in other situations. +.MAKEFLAGS: CMD_CMD_VAR=cmd-value +CMD_GLOBAL_VAR=global-value +export CMD_ENV_VAR=env-value +.MAKEFLAGS: -dv +# expect-reset +# expect: Command: CMD_CMD_VAR = new-value +# expect: Global: CMD_GLOBAL_VAR = new-value +# expect: Global: CMD_ENV_VAR = new-value +# expect: Global: ignoring delete 'CMD_NEW_VAR' as it is not found +# expect: Command: CMD_NEW_VAR = new-value +.if ${CMD_CMD_VAR::=new-value} \ + || ${CMD_GLOBAL_VAR::=new-value} \ + || ${CMD_ENV_VAR::=new-value} \ + || "${CMD_NEW_VAR::=new-value}" +. error +.endif +.MAKEFLAGS: -d0 + +# Run the 'target' test in a separate sub-make, with reduced debug logging. +all: run-target +run-target: .PHONY + @${MAKE} -r -f ${MAKEFILE} -dv target 2>&1 | grep ': TARGET_' + +.else # make(target) + +# The commands of a target are evaluated in target scope. An assignment +# modifier that creates a new variable creates it in the target scope. +# Existing variables are updated in their previous scope, and environment +# variables are created in the global scope, as in other situations. +# +# expect: target: TARGET_TARGET_VAR = new-value +# expect: Global: TARGET_GLOBAL_VAR = new-value +# expect: Global: TARGET_ENV_VAR = new-value +# expect: target: TARGET_NEW_VAR = new-value +.MAKEFLAGS: TARGET_CMD_VAR=cmd-value +TARGET_GLOBAL_VAR=global-value +export TARGET_ENV_VAR=env-value +target: .PHONY TARGET_TARGET_VAR=target-value + : ${TARGET_TARGET_VAR::=new-value} + : ${TARGET_CMD_VAR::=new-value} + : ${TARGET_GLOBAL_VAR::=new-value} + : ${TARGET_ENV_VAR::=new-value} + : ${TARGET_NEW_VAR::=new-value} + +.endif diff --git a/contrib/bmake/unit-tests/varmod-defined.exp b/contrib/bmake/unit-tests/varmod-defined.exp index b44d58c657aa..d82a292292a4 100644 --- a/contrib/bmake/unit-tests/varmod-defined.exp +++ b/contrib/bmake/unit-tests/varmod-defined.exp @@ -14,7 +14,7 @@ Modifier part: "${8_DOLLARS}" ModifyWords: split "$$$$$$$$" into 1 word Global: var = $$$$$$$$ Var_Parse: ${8_DOLLARS} (eval-keep-undefined) -ModifyWord_Loop: in "$$$$$$$$", replace "var" with "${8_DOLLARS}" to "$$$$" +ModifyWord_Loop: expand "${8_DOLLARS}" to "$$$$" Global: delete var Result of ${VAR:@var@${8_DOLLARS}@} is "$$$$" (eval-keep-dollar-and-undefined, regular) Global: VAR = $$$$ diff --git a/contrib/bmake/unit-tests/varmod-defined.mk b/contrib/bmake/unit-tests/varmod-defined.mk index ab5d708cf73f..2ee9def9e164 100644 --- a/contrib/bmake/unit-tests/varmod-defined.mk +++ b/contrib/bmake/unit-tests/varmod-defined.mk @@ -1,4 +1,4 @@ -# $NetBSD: varmod-defined.mk,v 1.12 2021/11/30 23:52:19 rillig Exp $ +# $NetBSD: varmod-defined.mk,v 1.16 2023/11/19 21:47:52 rillig Exp $ # # Tests for the :D variable modifier, which returns the given string # if the variable is defined. It is closely related to the :U modifier. @@ -46,10 +46,10 @@ DEF= defined . error .endif -# Like in several other places in variable expressions, when +# Like in several other places in expressions, when # ApplyModifier_Defined calls Var_Parse, double dollars lead to a parse # error that is silently ignored. This makes all dollar signs disappear, -# except for the last, which is a well-formed variable expression. +# except for the last, which is a well-formed expression. # .if ${DEF:D$$$$$${DEF}} != "defined" . error @@ -58,7 +58,7 @@ DEF= defined # Any other text is written without any further escaping. In contrast # to the :M modifier, parentheses and braces do not need to be nested. # Instead, the :D modifier is implemented sanely by parsing nested -# expressions as such, without trying any shortcuts. See ApplyModifier_Match +# expressions as such, without trying any shortcuts. See ParseModifier_Match # for an inferior variant. # .if ${DEF:D!&((((} != "!&((((" @@ -104,5 +104,13 @@ VAR:= ${VAR:D${8_DOLLARS}} VAR:= ${VAR:@var@${8_DOLLARS}@} .MAKEFLAGS: -d0 -all: - @:; + +# Before var.c 1.1030 from 2022-08-24, the following expression caused an +# out-of-bounds read when parsing the indirect ':U' modifier. +M_U_backslash:= ${:UU\\} +.if ${:${M_U_backslash}} != "\\" +. error +.endif + + +all: .PHONY diff --git a/contrib/bmake/unit-tests/varmod-edge.exp b/contrib/bmake/unit-tests/varmod-edge.exp index d9db72b2e2ef..c2477f16e950 100644 --- a/contrib/bmake/unit-tests/varmod-edge.exp +++ b/contrib/bmake/unit-tests/varmod-edge.exp @@ -1,27 +1,27 @@ -make: "varmod-edge.mk" line 166: ok M-paren -make: "varmod-edge.mk" line 166: ok M-mixed -make: "varmod-edge.mk" line 166: ok M-unescape -make: Unclosed variable expression, expecting '}' for modifier "U*)" of variable "" with value "*)" -make: "varmod-edge.mk" line 166: ok M-nest-mix -make: "varmod-edge.mk" line 166: ok M-nest-brk -make: "varmod-edge.mk" line 166: ok M-pat-err -make: "varmod-edge.mk" line 166: ok M-bsbs -make: "varmod-edge.mk" line 166: ok M-bs1-par -make: "varmod-edge.mk" line 166: ok M-bs2-par -make: "varmod-edge.mk" line 166: ok M-128 -make: "varmod-edge.mk" line 166: ok eq-ext -make: "varmod-edge.mk" line 166: ok eq-q -make: "varmod-edge.mk" line 166: ok eq-bs +make: "varmod-edge.mk" line 184: ok M-paren +make: "varmod-edge.mk" line 184: ok M-mixed +make: "varmod-edge.mk" line 184: ok M-unescape +make: Unclosed expression, expecting '}' for modifier "U*)" of variable "" with value "*)" +make: "varmod-edge.mk" line 184: ok M-nest-mix +make: "varmod-edge.mk" line 184: ok M-nest-brk +make: "varmod-edge.mk" line 184: ok M-pat-err +make: "varmod-edge.mk" line 184: ok M-bsbs +make: "varmod-edge.mk" line 184: ok M-bs1-par +make: "varmod-edge.mk" line 184: ok M-bs2-par +make: "varmod-edge.mk" line 184: ok M-128 +make: "varmod-edge.mk" line 184: ok eq-ext +make: "varmod-edge.mk" line 184: ok eq-q +make: "varmod-edge.mk" line 184: ok eq-bs make: Unfinished modifier for "INP.eq-esc" ('=' missing) -make: "varmod-edge.mk" line 166: ok eq-esc -make: "varmod-edge.mk" line 166: ok colon -make: "varmod-edge.mk" line 165: Unknown modifier ":" -make: "varmod-edge.mk" line 165: Unknown modifier ":" -make: "varmod-edge.mk" line 166: ok colons -make: "varmod-edge.mk" line 175: Unknown modifier "Z" -make: "varmod-edge.mk" line 175: Malformed conditional (${:Z}) +make: "varmod-edge.mk" line 184: ok eq-esc +make: "varmod-edge.mk" line 184: ok colon +make: "varmod-edge.mk" line 167: Unknown modifier ":" +make: "varmod-edge.mk" line 167: Unknown modifier ":" +make: "varmod-edge.mk" line 184: ok colons +make: "varmod-edge.mk" line 195: Unknown modifier "Z" +make: "varmod-edge.mk" line 195: Malformed conditional (${:Z}) make: Unfinished modifier for "" (',' missing) -make: "varmod-edge.mk" line 188: Malformed conditional (${:S,}) +make: "varmod-edge.mk" line 209: Malformed conditional (${:S,}) make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/varmod-edge.mk b/contrib/bmake/unit-tests/varmod-edge.mk index 762053d281a3..91220d99e47d 100644 --- a/contrib/bmake/unit-tests/varmod-edge.mk +++ b/contrib/bmake/unit-tests/varmod-edge.mk @@ -1,4 +1,4 @@ -# $NetBSD: varmod-edge.mk,v 1.16 2021/02/23 15:56:30 rillig Exp $ +# $NetBSD: varmod-edge.mk,v 1.19 2023/11/19 22:06:15 rillig Exp $ # # Tests for edge cases in variable modifiers. # @@ -16,7 +16,7 @@ MOD.M-paren= ${INP.M-paren:M(*)} EXP.M-paren= (parentheses) () # The first closing brace matches the opening parenthesis. -# The second closing brace actually ends the variable expression. +# The second closing brace actually ends the expression. # # XXX: This is unexpected but rarely occurs in practice. TESTS+= M-mixed @@ -40,7 +40,7 @@ EXP.M-unescape= \(\{}\): # as open_parens + open_braces == closing_parens + closing_braces. This # means that ( and } form a matching pair. # -# Nested variable expressions are not parsed as such. Instead, only the +# Nested expressions are not parsed as such. Instead, only the # parentheses and braces are counted. This leads to a parse error since # the nested expression is not "${:U*)}" but only "${:U*)", which is # missing the closing brace. The expression is evaluated anyway. @@ -51,7 +51,7 @@ TESTS+= M-nest-mix INP.M-nest-mix= (parentheses) MOD.M-nest-mix= ${INP.M-nest-mix:M${:U*)}} EXP.M-nest-mix= (parentheses)} -# make: Unclosed variable expression, expecting '}' for modifier "U*)" of variable "" with value "*)" +# make: Unclosed expression, expecting '}' for modifier "U*)" of variable "" with value "*)" # In contrast to parentheses and braces, the brackets are not counted # when the :M modifier is parsed since Makefile variables only take the @@ -162,7 +162,25 @@ MOD.colons= ${INP.colons::::} EXP.colons= # empty .for test in ${TESTS} +# expect+2: Unknown modifier ":" +# expect+1: Unknown modifier ":" . if ${MOD.${test}} == ${EXP.${test}} +# expect+16: ok M-paren +# expect+15: ok M-mixed +# expect+14: ok M-unescape +# expect+13: ok M-nest-mix +# expect+12: ok M-nest-brk +# expect+11: ok M-pat-err +# expect+10: ok M-bsbs +# expect+09: ok M-bs1-par +# expect+08: ok M-bs2-par +# expect+07: ok M-128 +# expect+06: ok eq-ext +# expect+05: ok eq-q +# expect+04: ok eq-bs +# expect+03: ok eq-esc +# expect+02: ok colon +# expect+01: ok colons . info ok ${test} . else . warning error in ${test}: expected "${EXP.${test}}", got "${MOD.${test}}" @@ -172,6 +190,8 @@ EXP.colons= # empty # Even in expressions based on an unnamed variable, there may be errors. # XXX: The error message should mention the variable name of the expression, # even though that name is empty in this case. +# expect+2: Malformed conditional (${:Z}) +# expect+1: Unknown modifier "Z" .if ${:Z} . error .else @@ -185,6 +205,7 @@ EXP.colons= # empty # modifier for (',' missing)", having two spaces in a row. # # XXX: The error message should report the filename:lineno. +# expect+1: Malformed conditional (${:S,}) .if ${:S,} . error .else diff --git a/contrib/bmake/unit-tests/varmod-gmtime.exp b/contrib/bmake/unit-tests/varmod-gmtime.exp index fdc9a2170e2f..bbb8bd547bd5 100644 --- a/contrib/bmake/unit-tests/varmod-gmtime.exp +++ b/contrib/bmake/unit-tests/varmod-gmtime.exp @@ -1,13 +1,13 @@ -make: "varmod-gmtime.mk" line 57: Invalid time value at "${:U1593536400}} != "mtime=11593536400}"" -make: "varmod-gmtime.mk" line 57: Malformed conditional (${%Y:L:gmtime=${:U1593536400}} != "mtime=11593536400}") -make: "varmod-gmtime.mk" line 67: Invalid time value at "-1} != """ -make: "varmod-gmtime.mk" line 67: Malformed conditional (${:L:gmtime=-1} != "") -make: "varmod-gmtime.mk" line 76: Invalid time value at " 1} != """ -make: "varmod-gmtime.mk" line 76: Malformed conditional (${:L:gmtime= 1} != "") -make: "varmod-gmtime.mk" line 119: Invalid time value at "10000000000000000000000000000000} != """ -make: "varmod-gmtime.mk" line 119: Malformed conditional (${:L:gmtime=10000000000000000000000000000000} != "") -make: "varmod-gmtime.mk" line 130: Invalid time value at "error} != """ -make: "varmod-gmtime.mk" line 130: Malformed conditional (${:L:gmtime=error} != "") +make: "varmod-gmtime.mk" line 61: Invalid time value "-1" +make: "varmod-gmtime.mk" line 61: Malformed conditional (${:L:gmtime=-1} != "") +make: "varmod-gmtime.mk" line 72: Invalid time value " 1" +make: "varmod-gmtime.mk" line 72: Malformed conditional (${:L:gmtime= 1} != "") +make: "varmod-gmtime.mk" line 120: Invalid time value "10000000000000000000000000000000" +make: "varmod-gmtime.mk" line 120: Malformed conditional (${:L:gmtime=10000000000000000000000000000000} != "") +make: "varmod-gmtime.mk" line 133: Invalid time value "error" +make: "varmod-gmtime.mk" line 133: Malformed conditional (${:L:gmtime=error} != "") +make: "varmod-gmtime.mk" line 144: Invalid time value "100000S,1970,bad," +make: "varmod-gmtime.mk" line 144: Malformed conditional (${%Y:L:gmtime=100000S,1970,bad,} != "bad") make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/varmod-gmtime.mk b/contrib/bmake/unit-tests/varmod-gmtime.mk index cb3d4e7eb241..c30f5edbecc2 100644 --- a/contrib/bmake/unit-tests/varmod-gmtime.mk +++ b/contrib/bmake/unit-tests/varmod-gmtime.mk @@ -1,7 +1,10 @@ -# $NetBSD: varmod-gmtime.mk,v 1.10 2021/01/19 05:26:34 rillig Exp $ +# $NetBSD: varmod-gmtime.mk,v 1.21 2023/11/19 21:47:52 rillig Exp $ # # Tests for the :gmtime variable modifier, which formats a timestamp # using strftime(3) in UTC. +# +# See also: +# varmod-localtime.mk .if ${TZ:Uundefined} != "undefined" # see unit-tests/Makefile . error @@ -41,20 +44,9 @@ .endif -# As of 2020-08-16, it is not possible to pass the seconds via a -# variable expression. This is because parsing of the :gmtime -# modifier stops at the '$' and returns to ApplyModifiers. -# -# There, a colon would be skipped but not a dollar. -# Parsing therefore continues at the '$' of the ${:U159...}, looking -# for an ordinary variable modifier. -# -# At this point, the ${:U} is expanded and interpreted as a variable -# modifier, which results in the error message "Unknown modifier '1'". -# -# If ApplyModifier_Gmtime were to pass its argument through -# ParseModifierPart, this would work. -.if ${%Y:L:gmtime=${:U1593536400}} != "mtime=11593536400}" +# Before var.c 1.1050 from 2023-05-09, it was not possible to pass the +# seconds via an expression. +.if ${%Y:L:gmtime=${:U1593536400}} != "2020" . error .endif @@ -64,6 +56,8 @@ # 1970. Going back 50 years in the past is not a practical use case for # make. Therefore, since var.c 1.631, negative time stamps produce a # parse error. +# expect+2: Invalid time value "-1" +# expect+1: Malformed conditional (${:L:gmtime=-1} != "") .if ${:L:gmtime=-1} != "" . error .else @@ -73,8 +67,12 @@ # Spaces were allowed before var.c 1.631 from 2020-10-31 21:40:20, not # because it would make sense but just as a side-effect from using strtoul. +# expect+2: Invalid time value " 1" +# expect+1: Malformed conditional (${:L:gmtime= 1} != "") .if ${:L:gmtime= 1} != "" . error +.else +. error .endif @@ -115,7 +113,10 @@ # ULONG_MAX, which got converted to -1. This resulted in a time stamp of # the second before 1970. # -# Since var.c 1.631, the overflow is detected and produces a parse error. +# Since var.c 1.631 from 2020-10-31, the overflow is detected and produces a +# parse error. +# expect+2: Invalid time value "10000000000000000000000000000000" +# expect+1: Malformed conditional (${:L:gmtime=10000000000000000000000000000000} != "") .if ${:L:gmtime=10000000000000000000000000000000} != "" . error .else @@ -127,11 +128,61 @@ # stopped after the '=', and the remaining string was parsed for more variable # modifiers. Because of the unknown modifier 'e' from the 'error', the whole # variable value was discarded and thus not printed. +# expect+2: Invalid time value "error" +# expect+1: Malformed conditional (${:L:gmtime=error} != "") .if ${:L:gmtime=error} != "" . error .else . error .endif +# Before var.c 1.1050 from 2023-05-09, the timestamp could be directly +# followed by the next modifier, without a ':' separator. This was the same +# bug as for the ':L' and ':P' modifiers. +# expect+2: Invalid time value "100000S,1970,bad," +# expect+1: Malformed conditional (${%Y:L:gmtime=100000S,1970,bad,} != "bad") +.if ${%Y:L:gmtime=100000S,1970,bad,} != "bad" +. error +.endif + + +# Before var.c 1.1062 from 2023-08-19, ':gmtime' but not ':localtime' reported +# wrong values for '%s', depending on the operating system and the timezone. +export TZ=UTC +.for t in ${%s:L:gmtime} ${%s:L:localtime} +TIMESTAMPS+= $t +.endfor +export TZ=Europe/Berlin +.for t in ${%s:L:gmtime} ${%s:L:localtime} +TIMESTAMPS+= $t +.endfor +export TZ=UTC +.for t in ${%s:L:gmtime} ${%s:L:localtime} +TIMESTAMPS+= $t +.endfor +export TZ=America/Los_Angeles +.for t in ${%s:L:gmtime} ${%s:L:localtime} +TIMESTAMPS+= $t +.endfor +export TZ=UTC +.for t in ${%s:L:gmtime} ${%s:L:localtime} +TIMESTAMPS+= $t +.endfor +.for a b in ${TIMESTAMPS:[1]} ${TIMESTAMPS:@t@$t $t@} ${TIMESTAMPS:[-1]} +. if $a > $b +. warning timestamp $a > $b +. endif +.endfor + + +.if ${year=%Y month=%m day=%d:L:gmtime=1459494000} != "year=2016 month=04 day=01" +. error +.endif +# Slightly contorted syntax to convert a UTC timestamp from an expression to a +# formatted timestamp. +.if ${%Y%m%d:L:${gmtime=${:U1459494000}:L}} != "20160401" +. error +.endif + all: diff --git a/contrib/bmake/unit-tests/varmod-head.exp b/contrib/bmake/unit-tests/varmod-head.exp index 651844439f5f..39a9383953dd 100644 --- a/contrib/bmake/unit-tests/varmod-head.exp +++ b/contrib/bmake/unit-tests/varmod-head.exp @@ -1,11 +1 @@ -head (dirname) of 'a/b/c' is 'a/b' -head (dirname) of 'def' is '.' -head (dirname) of 'a.b.c' is '.' -head (dirname) of 'a.b/c' is 'a.b' -head (dirname) of 'a' is '.' -head (dirname) of 'a.a' is '.' -head (dirname) of '.gitignore' is '.' -head (dirname) of 'a' is '.' -head (dirname) of 'a.a' is '.' -head (dirname) of 'trailing/' is 'trailing' exit status 0 diff --git a/contrib/bmake/unit-tests/varmod-head.mk b/contrib/bmake/unit-tests/varmod-head.mk index 66347b4bce61..f1a135cb328d 100644 --- a/contrib/bmake/unit-tests/varmod-head.mk +++ b/contrib/bmake/unit-tests/varmod-head.mk @@ -1,9 +1,64 @@ -# $NetBSD: varmod-head.mk,v 1.4 2020/12/20 22:57:40 rillig Exp $ +# $NetBSD: varmod-head.mk,v 1.5 2022/07/10 21:11:49 rillig Exp $ # # Tests for the :H variable modifier, which returns the dirname of # each of the words in the variable value. -all: -.for path in a/b/c def a.b.c a.b/c a a.a .gitignore a a.a trailing/ - @echo "head (dirname) of '"${path:Q}"' is '"${path:H:Q}"'" -.endfor +.if ${:U a/b/c :H} != "a/b" +. error +.endif + +.if ${:U def :H} != "." +. error +.endif + +.if ${:U a.b.c :H} != "." +. error +.endif + +.if ${:U a.b/c :H} != "a.b" +. error +.endif + +.if ${:U a :H} != "." +. error +.endif + +.if ${:U a.a :H} != "." +. error +.endif + +.if ${:U .gitignore :H} != "." +. error +.endif + +.if ${:U trailing/ :H} != "trailing" +. error +.endif + +.if ${:U /abs/dir/file :H} != "/abs/dir" +. error +.endif + +.if ${:U rel/dir/file :H} != "rel/dir" +. error +.endif + +# The head of "/" was an empty string before 2020.07.20.14.50.41, leading to +# the output "before after", with two spaces. Since 2020.07.20.14.50.41, the +# output is "before after", discarding the empty word. +.if ${:U before/ / after/ :H} == "before after" +# OK +.elif ${:U before/ / after/ :H} == "before after" +# No '.info' to keep the file compatible with old make versions. +_!= echo "The modifier ':H' generates an empty word." 1>&2; echo +.else +. error +.endif + +# An empty list is split into a single empty word. +# The dirname of this empty word is ".". +.if ${:U :H} != "." +. error +.endif + +all: .PHONY diff --git a/contrib/bmake/unit-tests/varmod-ifelse.exp b/contrib/bmake/unit-tests/varmod-ifelse.exp index 7134c71b8d39..653fe104ddaa 100644 --- a/contrib/bmake/unit-tests/varmod-ifelse.exp +++ b/contrib/bmake/unit-tests/varmod-ifelse.exp @@ -1,32 +1,51 @@ -make: Bad conditional expression 'variable expression == "literal"' in 'variable expression == "literal"?bad:bad' -make: "varmod-ifelse.mk" line 27: Malformed conditional (${${:Uvariable expression} == "literal":?bad:bad}) -make: Bad conditional expression ' == ""' in ' == ""?bad-assign:bad-assign' -make: Bad conditional expression ' == ""' in ' == ""?bad-cond:bad-cond' -make: "varmod-ifelse.mk" line 44: Malformed conditional (${${UNDEF} == "":?bad-cond:bad-cond}) -make: Bad conditional expression '1 == == 2' in '1 == == 2?yes:no' -make: "varmod-ifelse.mk" line 66: Malformed conditional (${1 == == 2:?yes:no} != "") +make: Bad conditional expression 'bare words == "literal"' before '?bad:bad' +make: "varmod-ifelse.mk" line 28: Malformed conditional (${${:Ubare words} == "literal":?bad:bad}) +make: Bad conditional expression ' == ""' before '?bad-assign:bad-assign' +make: Bad conditional expression ' == ""' before '?bad-cond:bad-cond' +make: "varmod-ifelse.mk" line 46: Malformed conditional (${${UNDEF} == "":?bad-cond:bad-cond}) +make: Bad conditional expression '1 == == 2' before '?yes:no' +make: "varmod-ifelse.mk" line 69: Malformed conditional (${1 == == 2:?yes:no} != "") CondParser_Eval: "${1 == == 2:?yes:no}" != "" CondParser_Eval: 1 == == 2 Comparing 1.000000 == 0.000000 -make: Bad conditional expression '1 == == 2' in '1 == == 2?yes:no' +make: Bad conditional expression '1 == == 2' before '?yes:no' Comparing "" != "" -make: "varmod-ifelse.mk" line 92: warning: Oops, the parse error should have been propagated. -CondParser_Eval: ${ ${:U\$}{VAR} == value :?ok:bad} != "ok" -CondParser_Eval: ${VAR} == value +make: "varmod-ifelse.mk" line 96: warning: Oops, the parse error should have been propagated. +CondParser_Eval: ${ ${:U\$}{VAR} == value:?ok:bad} != "ok" +CondParser_Eval: ${VAR} == value Comparing "value" == "value" Comparing "ok" != "ok" -make: "varmod-ifelse.mk" line 153: no. -make: "varmod-ifelse.mk" line 154: String comparison operator must be either == or != -make: Bad conditional expression 'string == "literal" || no >= 10' in 'string == "literal" || no >= 10?yes:no' -make: "varmod-ifelse.mk" line 154: . -make: Bad conditional expression 'string == "literal" && >= 10' in 'string == "literal" && >= 10?yes:no' -make: "varmod-ifelse.mk" line 159: . -make: Bad conditional expression 'string == "literal" || >= 10' in 'string == "literal" || >= 10?yes:no' -make: "varmod-ifelse.mk" line 160: . -make: "varmod-ifelse.mk" line 167: true -make: "varmod-ifelse.mk" line 169: false -make: Bad conditional expression ' ' in ' ?true:false' -make: "varmod-ifelse.mk" line 171: +make: "varmod-ifelse.mk" line 158: no. +make: "varmod-ifelse.mk" line 162: Comparison with '>=' requires both operands 'no' and '10' to be numeric +make: Bad conditional expression 'string == "literal" || no >= 10' before '?yes:no' +make: "varmod-ifelse.mk" line 162: . +make: Bad conditional expression 'string == "literal" && >= 10' before '?yes:no' +make: "varmod-ifelse.mk" line 169: . +make: Bad conditional expression 'string == "literal" || >= 10' before '?yes:no' +make: "varmod-ifelse.mk" line 172: . +make: "varmod-ifelse.mk" line 180: <true> +make: "varmod-ifelse.mk" line 183: <false> +make: Bad conditional expression ' ' before '?true:false' +make: "varmod-ifelse.mk" line 186: <> +CondParser_Eval: 0 && ${1:?${:Uthen0:S,}},,}:${:Uelse0:S,}},,}} != "not evaluated" +CondParser_Eval: 1 && ${0:?${:Uthen1:S,}},,}:${:Uelse1:S,}},,}} != "else1" +CondParser_Eval: 0 +Comparing "else1" != "else1" +CondParser_Eval: 2 && ${1:?${:Uthen2:S,}},,}:${:Uelse2:S,}},,}} != "then2" +CondParser_Eval: 1 +Comparing "then2" != "then2" +CondParser_Eval: ${DELAYED} == "one" +Comparing "two" == "one" +make: "varmod-ifelse.mk" line 282: no +CondParser_Eval: ${DELAYED} == "two" +Comparing "two" == "two" +make: "varmod-ifelse.mk" line 284: yes +CondParser_Eval: ${DELAYED} == "one" +Comparing "two" == "one" +make: "varmod-ifelse.mk" line 287: no +CondParser_Eval: ${DELAYED} == "two" +Comparing "two" == "two" +make: "varmod-ifelse.mk" line 290: yes make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/varmod-ifelse.mk b/contrib/bmake/unit-tests/varmod-ifelse.mk index 37e8f620d883..5c8b55d92717 100644 --- a/contrib/bmake/unit-tests/varmod-ifelse.mk +++ b/contrib/bmake/unit-tests/varmod-ifelse.mk @@ -1,4 +1,4 @@ -# $NetBSD: varmod-ifelse.mk,v 1.18 2022/01/15 20:16:55 rillig Exp $ +# $NetBSD: varmod-ifelse.mk,v 1.26 2023/12/10 20:12:28 rillig Exp $ # # Tests for the ${cond:?then:else} variable modifier, which evaluates either # the then-expression or the else-expression, depending on the condition. @@ -13,18 +13,19 @@ # The variable name of the expression is expanded and then taken as the # condition. In the below example it becomes: # -# variable expression == "literal" +# bare words == "literal" # # This confuses the parser, which expects an operator instead of the bare # word "expression". If the name were expanded lazily, everything would be # fine since the condition would be: # -# ${:Uvariable expression} == "literal" +# ${:Ubare words} == "literal" # # Evaluating the variable name lazily would require additional code in # Var_Parse and ParseVarname, it would be more useful and predictable # though. -.if ${${:Uvariable expression} == "literal":?bad:bad} +# expect+1: Malformed conditional (${${:Ubare words} == "literal":?bad:bad}) +.if ${${:Ubare words} == "literal":?bad:bad} . error .else . error @@ -41,6 +42,7 @@ COND:= ${${UNDEF} == "":?bad-assign:bad-assign} # "Undefined variable" error message is generated. # The difference to the ':=' variable assignment is the additional # "Malformed conditional" error message. +# expect+1: Malformed conditional (${${UNDEF} == "":?bad-cond:bad-cond}) .if ${${UNDEF} == "":?bad-cond:bad-cond} . error .else @@ -59,10 +61,11 @@ COND:= ${${UNDEF} == "":?bad-assign:bad-assign} # This line generates 2 error messages. The first comes from evaluating the # malformed conditional "1 == == 2", which is reported as "Bad conditional -# expression" by ApplyModifier_IfElse. The variable expression containing that +# expression" by ApplyModifier_IfElse. The expression containing that # conditional therefore returns a parse error from Var_Parse, and this parse # error propagates to CondEvalExpression, where the "Malformed conditional" # comes from. +# expect+1: Malformed conditional (${1 == == 2:?yes:no} != "") .if ${1 == == 2:?yes:no} != "" . error .else @@ -76,7 +79,7 @@ COND:= ${${UNDEF} == "":?bad-assign:bad-assign} # XXX: The left-hand side is enclosed in quotes. This results in Var_Parse # being called without VARE_UNDEFERR. When ApplyModifier_IfElse # returns AMR_CLEANUP as result, Var_Parse returns varUndefined since the -# value of the variable expression is still undefined. CondParser_String is +# value of the expression is still undefined. CondParser_String is # then supposed to do proper error handling, but since varUndefined is local # to var.c, it cannot distinguish this return value from an ordinary empty # string. The left-hand side of the comparison is therefore just an empty @@ -89,15 +92,16 @@ COND:= ${${UNDEF} == "":?bad-assign:bad-assign} .if "${1 == == 2:?yes:no}" != "" . error .else +# expect+1: warning: Oops, the parse error should have been propagated. . warning Oops, the parse error should have been propagated. .endif .MAKEFLAGS: -d0 -# As of 2020-12-10, the variable "name" is first expanded, and the result of -# this expansion is then taken as the condition. To force the variable +# As of 2020-12-10, the variable "VAR" is first expanded, and the result of +# this expansion is then taken as the condition. To force the # expression in the condition to be evaluated at exactly the right point, # the '$' of the intended '${VAR}' escapes from the parser in form of the -# expression ${:U\$}. Because of this escaping, the variable "name" and thus +# expression ${:U\$}. Because of this escaping, the variable "VAR" and thus # the condition ends up as "${VAR} == value", just as intended. # # This hack does not work for variables from .for loops since these are @@ -106,7 +110,7 @@ COND:= ${${UNDEF} == "":?bad-assign:bad-assign} # from the parser of the .for loop body. See ForLoop_SubstVarLong. .MAKEFLAGS: -dc VAR= value -.if ${ ${:U\$}{VAR} == value :?ok:bad} != "ok" +.if ${ ${:U\$}{VAR} == value:?ok:bad} != "ok" . error .endif .MAKEFLAGS: -d0 @@ -133,7 +137,7 @@ VAR= value # When parsing such an expression, the parser used to be strict. It first # evaluated the left-hand side of the operator '&&' and then started parsing # the right-hand side 'no >= 10'. The word 'no' is obviously a string -# literal, not enclosed in quotes, which is ok, even on the left-hand side of +# literal, not enclosed in quotes, which is OK, even on the left-hand side of # the comparison operator, but only because this is a condition in the # modifier ':?'. In an ordinary directive '.if', this would be a parse error. # For strings, only the comparison operators '==' and '!=' are defined, @@ -150,13 +154,21 @@ VAR= value # instead of just saying that the whole condition is bad. STRING= string NUMBER= no # not really a number +# expect+1: no. .info ${${STRING} == "literal" && ${NUMBER} >= 10:?yes:no}. +# expect+3: Comparison with '>=' requires both operands 'no' and '10' to be numeric +# expect: make: Bad conditional expression 'string == "literal" || no >= 10' before '?yes:no' +# expect+1: . .info ${${STRING} == "literal" || ${NUMBER} >= 10:?yes:no}. # The following situation occasionally occurs with MKINET6 or similar # variables. NUMBER= # empty, not really a number either +# expect: make: Bad conditional expression 'string == "literal" && >= 10' before '?yes:no' +# expect+1: . .info ${${STRING} == "literal" && ${NUMBER} >= 10:?yes:no}. +# expect: make: Bad conditional expression 'string == "literal" || >= 10' before '?yes:no' +# expect+1: . .info ${${STRING} == "literal" || ${NUMBER} >= 10:?yes:no}. # CondParser_LeafToken handles [0-9-+] specially, treating them as a number. @@ -164,8 +176,132 @@ PLUS= + ASTERISK= * EMPTY= # empty # "true" since "+" is not the empty string. -.info ${${PLUS} :?true:false} +# expect+1: <true> +.info <${${PLUS} :?true:false}> # "false" since the variable named "*" is not defined. -.info ${${ASTERISK} :?true:false} +# expect+1: <false> +.info <${${ASTERISK} :?true:false}> # syntax error since the condition is completely blank. -.info ${${EMPTY} :?true:false} +# expect+1: <> +.info <${${EMPTY} :?true:false}> + + +# Since the condition of the '?:' modifier is expanded before being parsed and +# evaluated, it is common practice to enclose expressions in quotes, to avoid +# producing syntactically invalid conditions such as ' == value'. This only +# works if the expanded values neither contain quotes nor backslashes. For +# strings containing quotes or backslashes, the '?:' modifier should not be +# used. +PRIMES= 2 3 5 7 11 +.if ${1 2 3 4 5:L:@n@$n:${ ("${PRIMES:M$n}" != "") :?prime:not_prime}@} != \ + "1:not_prime 2:prime 3:prime 4:not_prime 5:prime" +. error +.endif + +# When parsing the modifier ':?', there are 3 possible cases: +# +# 1. The whole expression is only parsed. +# 2. The expression is parsed and the 'then' branch is evaluated. +# 3. The expression is parsed and the 'else' branch is evaluated. +# +# In all of these cases, the expression must be parsed in the same way, +# especially when one of the branches contains unbalanced '{}' braces. +# +# At 2020-01-01, the expressions from the 'then' and 'else' branches were +# parsed differently, depending on whether the branch was taken or not. When +# the branch was taken, the parser recognized that in the modifier ':S,}},,', +# the '}}' were ordinary characters. When the branch was not taken, the +# parser only counted balanced '{' and '}', ignoring any escaping or other +# changes in the interpretation. +# +# In var.c 1.285 from 2020-07-20, the parsing of the expressions changed so +# that in both cases the expression is parsed in the same way, taking the +# unbalanced braces in the ':S' modifiers into account. This change was not +# on purpose, the commit message mentioned 'has the same effect', which was a +# wrong assumption. +# +# In var.c 1.323 from 2020-07-26, the unintended fix from var.c 1.285 was +# reverted, still not knowing about the difference between regular parsing and +# balanced-mode parsing. +# +# In var.c 1.1028 from 2022-08-08, there was another attempt at fixing this +# inconsistency in parsing, but since that broke parsing of the modifier ':@', +# it was reverted in var.c 1.1029 from 2022-08-23. +# +# In var.c 1.1047 from 2023-02-18, the inconsistency in parsing was finally +# fixed. The modifier ':@' now parses the body in balanced mode, while +# everywhere else the modifier parts have their subexpressions parsed in the +# same way, no matter whether they are evaluated or not. +# +# The modifiers ':@' and ':?' are similar in that they conceptually contain +# text to be evaluated later or conditionally, still they parse that text +# differently. The crucial difference is that the body of the modifier ':@' +# is always parsed using balanced mode. The modifier ':?', on the other hand, +# must parse both of its branches in the same way, no matter whether they are +# evaluated or not. Since balanced mode and standard mode are incompatible, +# it's impossible to use balanced mode in the modifier ':?'. +.MAKEFLAGS: -dc +.if 0 && ${1:?${:Uthen0:S,}},,}:${:Uelse0:S,}},,}} != "not evaluated" +# At 2020-01-07, the expression evaluated to 'then0,,}}', even though it was +# irrelevant as the '0' had already been evaluated to 'false'. +. error +.endif +.if 1 && ${0:?${:Uthen1:S,}},,}:${:Uelse1:S,}},,}} != "else1" +. error +.endif +.if 2 && ${1:?${:Uthen2:S,}},,}:${:Uelse2:S,}},,}} != "then2" +# At 2020-01-07, the whole expression evaluated to 'then2,,}}' instead of the +# expected 'then2'. The 'then' branch of the ':?' modifier was parsed +# normally, parsing and evaluating the ':S' modifier, thereby treating the +# '}}' as ordinary characters and resulting in 'then2'. The 'else' branch was +# parsed in balanced mode, ignoring that the inner '}}' were ordinary +# characters. The '}}' were thus interpreted as the end of the 'else' branch +# and the whole expression. This left the trailing ',,}}', which together +# with the 'then2' formed the result 'then2,,}}'. +. error +.endif + + +# Since the condition is taken from the variable name of the expression, not +# from its value, it is evaluated early. It is possible though to construct +# conditions that are evaluated lazily, at exactly the right point. There is +# no way to escape a '$' directly in the variable name, but there are +# alternative ways to bring a '$' into the condition. +# +# In an indirect condition using the ':U' modifier, each '$', ':' and +# '}' must be escaped as '\$', '\:' and '\}', respectively, but '{' must +# not be escaped. +# +# In an indirect condition using a separate variable, each '$' must be +# escaped as '$$'. +# +# These two forms allow the variables to contain arbitrary characters, as the +# condition parser does not see them. +DELAYED= two +# expect+1: no +.info ${ ${:U \${DELAYED\} == "one"}:?yes:no} +# expect+1: yes +.info ${ ${:U \${DELAYED\} == "two"}:?yes:no} +INDIRECT_COND1= $${DELAYED} == "one" +# expect+1: no +.info ${ ${INDIRECT_COND1}:?yes:no} +INDIRECT_COND2= $${DELAYED} == "two" +# expect+1: yes +.info ${ ${INDIRECT_COND2}:?yes:no} + + +.MAKEFLAGS: -d0 + + +# In the modifier parts for the 'then' and 'else' branches, subexpressions are +# parsed in by inspecting the actual modifiers. In 2008, 2015, 2020, 2022 and +# 2023, the exact parsing algorithm switched a few times, counting balanced +# braces instead of proper subexpressions, which meant that unbalanced braces +# were parsed differently, depending on whether the branch was active or not. +BRACES= }}} +NO= ${0:?${BRACES:S,}}},yes,}:${BRACES:S,}}},no,}} +YES= ${1:?${BRACES:S,}}},yes,}:${BRACES:S,}}},no,}} +BOTH= <${YES}> <${NO}> +.if ${BOTH} != "<yes> <no>" +. error +.endif diff --git a/contrib/bmake/unit-tests/varmod-indirect.exp b/contrib/bmake/unit-tests/varmod-indirect.exp index 46fa1af7a8cb..ecf52033ee4b 100644 --- a/contrib/bmake/unit-tests/varmod-indirect.exp +++ b/contrib/bmake/unit-tests/varmod-indirect.exp @@ -1,20 +1,20 @@ make: "varmod-indirect.mk" line 19: Unknown modifier "${" make: "varmod-indirect.mk" line 52: Unknown modifier "${" -make: "varmod-indirect.mk" line 53: warning: FIXME: this expression should have resulted in a parse error rather than returning the unparsed portion of the expression. -make: "varmod-indirect.mk" line 140: before -make: "varmod-indirect.mk" line 140: after -make: "varmod-indirect.mk" line 146: before -make: "varmod-indirect.mk" line 146: after -make: "varmod-indirect.mk" line 152: before -make: "varmod-indirect.mk" line 152: after -make: "varmod-indirect.mk" line 156: Unknown modifier "Z" -make: "varmod-indirect.mk" line 157: before -make: "varmod-indirect.mk" line 157: after -Parsing line 166: _:= before ${UNDEF} after +make: "varmod-indirect.mk" line 54: warning: FIXME: this expression should have resulted in a parse error rather than returning the unparsed portion of the expression. +make: "varmod-indirect.mk" line 143: before +make: "varmod-indirect.mk" line 143: after +make: "varmod-indirect.mk" line 151: before +make: "varmod-indirect.mk" line 151: after +make: "varmod-indirect.mk" line 159: before +make: "varmod-indirect.mk" line 159: after +make: "varmod-indirect.mk" line 164: Unknown modifier "Z" +make: "varmod-indirect.mk" line 167: before +make: "varmod-indirect.mk" line 167: after +Parsing line 176: _:= before ${UNDEF} after Global: _ = # (empty) Var_Parse: ${UNDEF} after (eval-keep-dollar-and-undefined) Global: _ = before ${UNDEF} after -Parsing line 169: _:= before ${UNDEF:${:US,a,a,}} after +Parsing line 179: _:= before ${UNDEF:${:US,a,a,}} after Var_Parse: ${UNDEF:${:US,a,a,}} after (eval-keep-dollar-and-undefined) Indirect modifier "S,a,a," from "${:US,a,a,}" Evaluating modifier ${UNDEF:S...} on value "" (eval-keep-dollar-and-undefined, undefined) @@ -23,18 +23,18 @@ Modifier part: "a" ModifyWords: split "" into 1 word Result of ${UNDEF:S,a,a,} is "" (eval-keep-dollar-and-undefined, undefined) Global: _ = before ${UNDEF:S,a,a,} after -Parsing line 179: _:= before ${UNDEF:${:U}} after +Parsing line 189: _:= before ${UNDEF:${:U}} after Var_Parse: ${UNDEF:${:U}} after (eval-keep-dollar-and-undefined) Indirect modifier "" from "${:U}" Global: _ = before ${UNDEF:} after -Parsing line 184: _:= before ${UNDEF:${:UZ}} after +Parsing line 195: _:= before ${UNDEF:${:UZ}} after Var_Parse: ${UNDEF:${:UZ}} after (eval-keep-dollar-and-undefined) Indirect modifier "Z" from "${:UZ}" Evaluating modifier ${UNDEF:Z} on value "" (eval-keep-dollar-and-undefined, undefined) -make: "varmod-indirect.mk" line 184: Unknown modifier "Z" +make: "varmod-indirect.mk" line 195: Unknown modifier "Z" Result of ${UNDEF:Z} is error (eval-keep-dollar-and-undefined, undefined) Global: _ = before ${UNDEF:Z} after -Parsing line 186: .MAKEFLAGS: -d0 +Parsing line 197: .MAKEFLAGS: -d0 ParseDependency(.MAKEFLAGS: -d0) Global: .MAKEFLAGS = -r -k -d 0 -d pv -d Global: .MAKEFLAGS = -r -k -d 0 -d pv -d 0 diff --git a/contrib/bmake/unit-tests/varmod-indirect.mk b/contrib/bmake/unit-tests/varmod-indirect.mk index 082efb035c74..99e7215aa639 100644 --- a/contrib/bmake/unit-tests/varmod-indirect.mk +++ b/contrib/bmake/unit-tests/varmod-indirect.mk @@ -1,4 +1,4 @@ -# $NetBSD: varmod-indirect.mk,v 1.11 2022/01/15 12:35:18 rillig Exp $ +# $NetBSD: varmod-indirect.mk,v 1.18 2024/02/04 10:03:10 rillig Exp $ # # Tests for indirect variable modifiers, such as in ${VAR:${M_modifiers}}. # These can be used for very basic purposes like converting a string to either @@ -11,9 +11,9 @@ # To apply a modifier indirectly via another variable, the whole -# modifier must be put into a single variable expression. +# modifier must be put into a single expression. # The following expression generates a parse error since its indirect -# modifier contains more than a sole variable expression. +# modifier contains more than a sole expression. # # expect+1: Unknown modifier "${" .if ${value:L:${:US}${:U,value,replacement,}} != "S,value,replacement,}" @@ -50,6 +50,7 @@ # expect+2: Unknown modifier "${" #.MAKEFLAGS: -dvc .if ${value:L:${:UM*}S,value,replaced,} == "M*S,value,replaced,}" +# expect+1: warning: FIXME: this expression should have resulted in a parse error rather than returning the unparsed portion of the expression. . warning FIXME: this expression should have resulted in a parse $\ error rather than returning the unparsed portion of the $\ expression. @@ -70,20 +71,20 @@ .endif -# The nested variable expression expands to "tu", and this is interpreted as +# The nested expression expands to "tu", and this is interpreted as # a variable modifier for the value "Upper", resulting in "UPPER". .if ${Upper:L:${:Utu}} != "UPPER" . error .endif -# The nested variable expression expands to "tl", and this is interpreted as +# The nested expression expands to "tl", and this is interpreted as # a variable modifier for the value "Lower", resulting in "lower". .if ${Lower:L:${:Utl}} != "lower" . error .endif -# The nested variable expression is ${1 != 1:?Z:tl}, consisting of the +# The nested expression is ${1 != 1:?Z:tl}, consisting of the # condition "1 != 1", the then-branch "Z" and the else-branch "tl". Since # the condition evaluates to false, the then-branch is ignored (it would # have been an unknown modifier anyway) and the ":tl" modifier is applied. @@ -132,28 +133,37 @@ M_NoPrimes= ${PRIMES:${M_ListToSkip}} .MAKEFLAGS: -d0 -# In contrast to the .if conditions, the .for loop allows undefined variable +# In contrast to the .if conditions, the .for loop allows undefined # expressions. These expressions expand to empty strings. # An undefined expression without any modifiers expands to an empty string. .for var in before ${UNDEF} after +# expect+2: before +# expect+1: after . info ${var} .endfor # An undefined expression with only modifiers that keep the expression # undefined expands to an empty string. .for var in before ${UNDEF:${:US,a,a,}} after +# expect+2: before +# expect+1: after . info ${var} .endfor # Even in an indirect modifier based on an undefined variable, the value of # the expression in Var_Parse is a simple empty string. .for var in before ${UNDEF:${:U}} after +# expect+2: before +# expect+1: after . info ${var} .endfor # An error in an indirect modifier. +# expect+1: Unknown modifier "Z" .for var in before ${UNDEF:${:UZ}} after +# expect+2: before +# expect+1: after . info ${var} .endfor @@ -162,10 +172,10 @@ M_NoPrimes= ${PRIMES:${M_ListToSkip}} # a variable assignment using ':='. .MAKEFLAGS: -dpv -# The undefined variable expression is kept as-is. +# The undefined expression is kept as-is. _:= before ${UNDEF} after -# The undefined variable expression is kept as-is. +# The undefined expression is kept as-is. _:= before ${UNDEF:${:US,a,a,}} after # XXX: The subexpression ${:U} is fully defined, therefore it is expanded. @@ -179,8 +189,9 @@ _:= before ${UNDEF:${:US,a,a,}} after _:= before ${UNDEF:${:U}} after # XXX: This expands to ${UNDEF:Z}, which will behave differently if the -# variable '_' is used in a context where the variable expression ${_} is +# variable '_' is used in a context where the expression ${_} is # parsed but not evaluated. +# expect+1: Unknown modifier "Z" _:= before ${UNDEF:${:UZ}} after .MAKEFLAGS: -d0 @@ -190,7 +201,7 @@ _:= before ${UNDEF:${:UZ}} after # When evaluating indirect modifiers, these modifiers may expand to ':tW', # which modifies the interpretation of the expression value. This modified # interpretation only lasts until the end of the indirect modifier, it does -# not influence the outer variable expression. +# not influence the outer expression. .if ${1 2 3:L:tW:[#]} != 1 # direct :tW applies to the :[#] . error .endif @@ -202,7 +213,7 @@ _:= before ${UNDEF:${:UZ}} after # When evaluating indirect modifiers, these modifiers may expand to ':ts*', # which modifies the interpretation of the expression value. This modified # interpretation only lasts until the end of the indirect modifier, it does -# not influence the outer variable expression. +# not influence the outer expression. # # In this first expression, the direct ':ts*' has no effect since ':U' does not # treat the expression value as a list of words but as a single word. It has @@ -244,4 +255,28 @@ _:= before ${UNDEF:${:UZ}} after . error .endif -all: + +# In parse-only mode, the indirect modifiers must not be evaluated. +# +# Before var.c 1.1098 from 2024-02-04, the expression for an indirect modifier +# was partially evaluated (only the variable value, without applying any +# modifiers) and then interpreted as modifiers to the main expression. +# +# The expression ${:UZ} starts with the value "", and in parse-only mode, the +# modifier ':UZ' does not modify the expression value. This results in an +# empty string for the indirect modifiers, generating no warning. +.if 0 && ${VAR:${:UZ}} +.endif +# The expression ${M_invalid} starts with the value "Z", which is an unknown +# modifier. Trying to apply this unknown modifier generated a warning. +M_invalid= Z +.if 0 && ${VAR:${M_invalid}} +.endif +# The ':S' modifier does not change the expression value in parse-only mode, +# keeping the "Z", which is then skipped in parse-only mode. +.if 0 && ${VAR:${M_invalid:S,^,N*,:ts:}} +.endif +# The ':@' modifier does not change the expression value in parse-only mode, +# keeping the "Z", which is then skipped in parse-only mode. +.if 0 && ${VAR:${M_invalid:@m@N*$m@:ts:}} +.endif diff --git a/contrib/bmake/unit-tests/varmod-l-name-to-value.mk b/contrib/bmake/unit-tests/varmod-l-name-to-value.mk index 354622cf098b..e87e68967544 100644 --- a/contrib/bmake/unit-tests/varmod-l-name-to-value.mk +++ b/contrib/bmake/unit-tests/varmod-l-name-to-value.mk @@ -1,4 +1,4 @@ -# $NetBSD: varmod-l-name-to-value.mk,v 1.7 2020/10/24 08:46:08 rillig Exp $ +# $NetBSD: varmod-l-name-to-value.mk,v 1.8 2023/11/19 21:47:52 rillig Exp $ # # Tests for the :L modifier, which returns the variable name as the new value. @@ -28,7 +28,7 @@ .endif # Between 2020-09-22 (var.c 1.527) and 2020-09-30 (var.c 1.553), there was -# a bug in the evaluation of variable expressions. Indirect modifiers like +# a bug in the evaluation of expressions. Indirect modifiers like # the below :L did not update the definedness of the enclosing expression. # This resulted in a wrong "Malformed conditional". .if ${value:${:UL}} == "" diff --git a/contrib/bmake/unit-tests/varmod-localtime.exp b/contrib/bmake/unit-tests/varmod-localtime.exp index 494f160b766e..a7c3ff6ab932 100644 --- a/contrib/bmake/unit-tests/varmod-localtime.exp +++ b/contrib/bmake/unit-tests/varmod-localtime.exp @@ -1,13 +1,13 @@ -make: "varmod-localtime.mk" line 57: Invalid time value at "${:U1593536400}} != "mtime=11593536400}"" -make: "varmod-localtime.mk" line 57: Malformed conditional (${%Y:L:localtime=${:U1593536400}} != "mtime=11593536400}") -make: "varmod-localtime.mk" line 67: Invalid time value at "-1} != """ -make: "varmod-localtime.mk" line 67: Malformed conditional (${:L:localtime=-1} != "") -make: "varmod-localtime.mk" line 76: Invalid time value at " 1} != """ -make: "varmod-localtime.mk" line 76: Malformed conditional (${:L:localtime= 1} != "") -make: "varmod-localtime.mk" line 119: Invalid time value at "10000000000000000000000000000000} != """ -make: "varmod-localtime.mk" line 119: Malformed conditional (${:L:localtime=10000000000000000000000000000000} != "") -make: "varmod-localtime.mk" line 130: Invalid time value at "error} != """ -make: "varmod-localtime.mk" line 130: Malformed conditional (${:L:localtime=error} != "") +make: "varmod-localtime.mk" line 61: Invalid time value "-1" +make: "varmod-localtime.mk" line 61: Malformed conditional (${:L:localtime=-1} != "") +make: "varmod-localtime.mk" line 72: Invalid time value " 1" +make: "varmod-localtime.mk" line 72: Malformed conditional (${:L:localtime= 1} != "") +make: "varmod-localtime.mk" line 120: Invalid time value "10000000000000000000000000000000" +make: "varmod-localtime.mk" line 120: Malformed conditional (${:L:localtime=10000000000000000000000000000000} != "") +make: "varmod-localtime.mk" line 133: Invalid time value "error" +make: "varmod-localtime.mk" line 133: Malformed conditional (${:L:localtime=error} != "") +make: "varmod-localtime.mk" line 144: Invalid time value "100000S,1970,bad," +make: "varmod-localtime.mk" line 144: Malformed conditional (${%Y:L:localtime=100000S,1970,bad,} != "bad") make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/varmod-localtime.mk b/contrib/bmake/unit-tests/varmod-localtime.mk index ffa09a0bc5fc..f6fcc61a7fa6 100644 --- a/contrib/bmake/unit-tests/varmod-localtime.mk +++ b/contrib/bmake/unit-tests/varmod-localtime.mk @@ -1,7 +1,10 @@ -# $NetBSD: varmod-localtime.mk,v 1.8 2021/01/19 05:26:34 rillig Exp $ +# $NetBSD: varmod-localtime.mk,v 1.14 2023/11/19 21:47:52 rillig Exp $ # # Tests for the :localtime variable modifier, which formats a timestamp # using strftime(3) in local time. +# +# See also: +# varmod-gmtime.mk .if ${TZ:Uno:NEurope/Berlin:NUTC-1} != "" # see unit-tests/Makefile . error @@ -41,20 +44,9 @@ .endif -# As of 2020-08-16, it is not possible to pass the seconds via a -# variable expression. This is because parsing of the :localtime -# modifier stops at the '$' and returns to ApplyModifiers. -# -# There, a colon would be skipped but not a dollar. -# Parsing therefore continues at the '$' of the ${:U159...}, looking -# for an ordinary variable modifier. -# -# At this point, the ${:U} is expanded and interpreted as a variable -# modifier, which results in the error message "Unknown modifier '1'". -# -# If ApplyModifier_Localtime were to pass its argument through -# ParseModifierPart, this would work. -.if ${%Y:L:localtime=${:U1593536400}} != "mtime=11593536400}" +# Before var.c 1.1050 from 2023-05-09, it was not possible to pass the +# seconds via an expression. +.if ${%Y:L:localtime=${:U1593536400}} != "2020" . error .endif @@ -64,6 +56,8 @@ # 1970. Going back 50 years in the past is not a practical use case for # make. Therefore, since var.c 1.631, negative time stamps produce a # parse error. +# expect+2: Invalid time value "-1" +# expect+1: Malformed conditional (${:L:localtime=-1} != "") .if ${:L:localtime=-1} != "" . error .else @@ -73,8 +67,12 @@ # Spaces were allowed before var.c 1.631 from 2020-10-31 21:40:20, not # because it would make sense but just as a side-effect from using strtoul. +# expect+2: Invalid time value " 1" +# expect+1: Malformed conditional (${:L:localtime= 1} != "") .if ${:L:localtime= 1} != "" . error +.else +. error .endif @@ -115,7 +113,10 @@ # ULONG_MAX, which got converted to -1. This resulted in a time stamp of # the second before 1970. # -# Since var.c 1.631, the overflow is detected and produces a parse error. +# Since var.c 1.631 from 2020-10-31, the overflow is detected and produces a +# parse error. +# expect+2: Invalid time value "10000000000000000000000000000000" +# expect+1: Malformed conditional (${:L:localtime=10000000000000000000000000000000} != "") .if ${:L:localtime=10000000000000000000000000000000} != "" . error .else @@ -127,11 +128,21 @@ # stopped after the '=', and the remaining string was parsed for more variable # modifiers. Because of the unknown modifier 'e' from the 'error', the whole # variable value was discarded and thus not printed. +# expect+2: Invalid time value "error" +# expect+1: Malformed conditional (${:L:localtime=error} != "") .if ${:L:localtime=error} != "" . error .else . error .endif +# Before var.c 1.1050 from 2023-05-09, the timestamp could be directly +# followed by the next modifier, without a ':' separator. This was the same +# bug as for the ':L' and ':P' modifiers. +# expect+2: Invalid time value "100000S,1970,bad," +# expect+1: Malformed conditional (${%Y:L:localtime=100000S,1970,bad,} != "bad") +.if ${%Y:L:localtime=100000S,1970,bad,} != "bad" +. error +.endif all: diff --git a/contrib/bmake/unit-tests/varmod-loop-delete.exp b/contrib/bmake/unit-tests/varmod-loop-delete.exp index aac86ee39061..47a2f74545a3 100644 --- a/contrib/bmake/unit-tests/varmod-loop-delete.exp +++ b/contrib/bmake/unit-tests/varmod-loop-delete.exp @@ -1,4 +1,4 @@ -make: "varmod-loop-delete.mk" line 19: Cannot delete variable "VAR" while it is used +make: "varmod-loop-delete.mk" line 20: Cannot delete variable "VAR" while it is used make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/varmod-loop-delete.mk b/contrib/bmake/unit-tests/varmod-loop-delete.mk index ed145b59ba0f..1ec6d361949d 100644 --- a/contrib/bmake/unit-tests/varmod-loop-delete.mk +++ b/contrib/bmake/unit-tests/varmod-loop-delete.mk @@ -1,4 +1,4 @@ -# $NetBSD: varmod-loop-delete.mk,v 1.2 2021/12/05 15:51:33 rillig Exp $ +# $NetBSD: varmod-loop-delete.mk,v 1.3 2023/06/01 20:56:35 rillig Exp $ # # Tests for the variable modifier ':@', which as a side effect allows to # delete an arbitrary variable. @@ -16,6 +16,7 @@ VAR= ${:U:@VAR@@} rest of the value # In an assignment, the scope is 'Global'. Since the variable 'VAR' is # defined in the global scope, it deletes itself. +# expect+1: Cannot delete variable "VAR" while it is used EVAL:= ${VAR} .if ${EVAL} != " rest of the value" . error diff --git a/contrib/bmake/unit-tests/varmod-loop-varname.exp b/contrib/bmake/unit-tests/varmod-loop-varname.exp index 4f0379d5ea0a..2060b51c31df 100644 --- a/contrib/bmake/unit-tests/varmod-loop-varname.exp +++ b/contrib/bmake/unit-tests/varmod-loop-varname.exp @@ -1,11 +1,11 @@ -make: "varmod-loop-varname.mk" line 16: In the :@ modifier of "", the variable name "${:Ubar:S,b,v,}" must not contain a dollar -make: "varmod-loop-varname.mk" line 16: Malformed conditional (${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@} != "+one+ +two+ +three+") -make: "varmod-loop-varname.mk" line 85: In the :@ modifier of "1 2 3", the variable name "v$" must not contain a dollar -make: "varmod-loop-varname.mk" line 85: Malformed conditional (${1 2 3:L:@v$@($v)@} != "(1) (2) (3)") -make: "varmod-loop-varname.mk" line 90: In the :@ modifier of "1 2 3", the variable name "v$$" must not contain a dollar -make: "varmod-loop-varname.mk" line 90: Malformed conditional (${1 2 3:L:@v$$@($v)@} != "() () ()") -make: "varmod-loop-varname.mk" line 95: In the :@ modifier of "1 2 3", the variable name "v$$$" must not contain a dollar -make: "varmod-loop-varname.mk" line 95: Malformed conditional (${1 2 3:L:@v$$$@($v)@} != "() () ()") +make: "varmod-loop-varname.mk" line 18: In the :@ modifier of "", the variable name "${:Ubar:S,b,v,}" must not contain a dollar +make: "varmod-loop-varname.mk" line 18: Malformed conditional (${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@} != "+one+ +two+ +three+") +make: "varmod-loop-varname.mk" line 89: In the :@ modifier of "1 2 3", the variable name "v$" must not contain a dollar +make: "varmod-loop-varname.mk" line 89: Malformed conditional (${1 2 3:L:@v$@($v)@} != "(1) (2) (3)") +make: "varmod-loop-varname.mk" line 96: In the :@ modifier of "1 2 3", the variable name "v$$" must not contain a dollar +make: "varmod-loop-varname.mk" line 96: Malformed conditional (${1 2 3:L:@v$$@($v)@} != "() () ()") +make: "varmod-loop-varname.mk" line 103: In the :@ modifier of "1 2 3", the variable name "v$$$" must not contain a dollar +make: "varmod-loop-varname.mk" line 103: Malformed conditional (${1 2 3:L:@v$$$@($v)@} != "() () ()") make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/varmod-loop-varname.mk b/contrib/bmake/unit-tests/varmod-loop-varname.mk index 91f8a4876466..6f7436f277da 100644 --- a/contrib/bmake/unit-tests/varmod-loop-varname.mk +++ b/contrib/bmake/unit-tests/varmod-loop-varname.mk @@ -1,4 +1,4 @@ -# $NetBSD: varmod-loop-varname.mk,v 1.4 2021/12/05 15:01:04 rillig Exp $ +# $NetBSD: varmod-loop-varname.mk,v 1.6 2023/11/19 21:47:52 rillig Exp $ # # Tests for the first part of the variable modifier ':@var@...@', which # contains the variable name to use during the loop. @@ -13,6 +13,8 @@ # dynamically. There was no practical use-case for this. # Since var.c 1.907 from 2021-04-04, a '$' is no longer allowed in the # variable name. +# expect+2: In the :@ modifier of "", the variable name "${:Ubar:S,b,v,}" must not contain a dollar +# expect+1: Malformed conditional (${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@} != "+one+ +two+ +three+") .if ${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@} != "+one+ +two+ +three+" . error .else @@ -82,16 +84,22 @@ RES3= 3 # There's no point in allowing a dollar sign in that position. # Since var.c 1.907 from 2021-04-04, a '$' is no longer allowed in the # variable name. +# expect+2: In the :@ modifier of "1 2 3", the variable name "v$" must not contain a dollar +# expect+1: Malformed conditional (${1 2 3:L:@v$@($v)@} != "(1) (2) (3)") .if ${1 2 3:L:@v$@($v)@} != "(1) (2) (3)" . error .else . error .endif +# expect+2: In the :@ modifier of "1 2 3", the variable name "v$$" must not contain a dollar +# expect+1: Malformed conditional (${1 2 3:L:@v$$@($v)@} != "() () ()") .if ${1 2 3:L:@v$$@($v)@} != "() () ()" . error .else . error .endif +# expect+2: In the :@ modifier of "1 2 3", the variable name "v$$$" must not contain a dollar +# expect+1: Malformed conditional (${1 2 3:L:@v$$$@($v)@} != "() () ()") .if ${1 2 3:L:@v$$$@($v)@} != "() () ()" . error .else @@ -104,7 +112,7 @@ RES3= 3 # # As of 2020-10-18, the :@ modifier is implemented by actually setting a # variable in the scope of the expression and deleting it again after the -# loop. This is different from the .for loops, which substitute the variable +# loop. This is different from the .for loops, which substitute the # expression with ${:Uvalue}, leading to different unwanted side effects. # # To make the behavior more predictable, the :@ modifier should restore the diff --git a/contrib/bmake/unit-tests/varmod-loop.exp b/contrib/bmake/unit-tests/varmod-loop.exp index bbe0037673b3..356946f63a9b 100644 --- a/contrib/bmake/unit-tests/varmod-loop.exp +++ b/contrib/bmake/unit-tests/varmod-loop.exp @@ -1,10 +1,10 @@ -Parsing line 78: USE_8_DOLLARS= ${:U1:@var@${8_DOLLARS}@} ${8_DOLLARS} $$$$$$$$ +Parsing line 91: USE_8_DOLLARS= ${:U1:@var@${8_DOLLARS}@} ${8_DOLLARS} $$$$$$$$ CondParser_Eval: ${USE_8_DOLLARS} != "\$\$\$\$ \$\$\$\$ \$\$\$\$" Comparing "$$$$ $$$$ $$$$" != "$$$$ $$$$ $$$$" -Parsing line 83: SUBST_CONTAINING_LOOP:= ${USE_8_DOLLARS} +Parsing line 96: SUBST_CONTAINING_LOOP:= ${USE_8_DOLLARS} CondParser_Eval: ${SUBST_CONTAINING_LOOP} != "\$\$ \$\$\$\$ \$\$\$\$" Comparing "$$ $$$$ $$$$" != "$$ $$$$ $$$$" -Parsing line 108: .MAKEFLAGS: -d0 +Parsing line 121: .MAKEFLAGS: -d0 ParseDependency(.MAKEFLAGS: -d0) :varname-overwriting-target: :x1y x2y x3y: :: mod-loop-dollar:1: @@ -13,4 +13,10 @@ mod-loop-dollar:$3$: mod-loop-dollar:$${word}$$: mod-loop-dollar:$$5$$: mod-loop-dollar:$$${word}$$$: +: t=$(( ${t:-0} + 1 )) +: dollar=end +: backslash=\ end +: dollar=$ at=@ backslash=\ end +: dollar=$$ at=@@ backslash=\\ end +: dollar=$$ at=@@ backslash=\\ end exit status 0 diff --git a/contrib/bmake/unit-tests/varmod-loop.mk b/contrib/bmake/unit-tests/varmod-loop.mk index 82046ff95d79..64cc6ca85043 100644 --- a/contrib/bmake/unit-tests/varmod-loop.mk +++ b/contrib/bmake/unit-tests/varmod-loop.mk @@ -1,6 +1,20 @@ -# $NetBSD: varmod-loop.mk,v 1.18 2021/12/05 15:20:13 rillig Exp $ +# $NetBSD: varmod-loop.mk,v 1.24 2023/11/19 21:47:52 rillig Exp $ # -# Tests for the :@var@...${var}...@ variable modifier. +# Tests for the expression modifier ':@var@body@', which replaces each word of +# the expression with the expanded body, which may contain references to the +# variable 'var'. For example, '${1 2 3:L:@word@<${word}>@}' encloses each +# word in angle quotes, resulting in '<1> <2> <3>'. +# +# The variable name can be chosen freely, except that it must not contain a +# '$'. For simplicity and readability, variable names should only use the +# characters 'A-Za-z0-9'. +# +# The body may contain subexpressions in the form '${...}' or '$(...)'. These +# subexpressions differ from everywhere else in makefiles in that the parser +# only scans '${...}' for balanced '{' and '}', likewise for '$(...)'. Any +# other '$' is left as-is during parsing. Later, when the body is expanded +# for each word, each '$$' is interpreted as a single '$', and the remaining +# '$' are interpreted as expressions, like when evaluating a regular variable. # Force the test results to be independent of the default value of this # setting, which is 'yes' for NetBSD's usr.bin/make but 'no' for the bmake @@ -19,7 +33,6 @@ varname-overwriting-target: @echo :$@: :${:U1 2 3:@\@@x${@}y@}: :$@: - # Demonstrate that it is possible to generate dollar signs using the # :@ modifier. # @@ -39,7 +52,7 @@ mod-loop-dollar: # # As of 2020-10-18, the :@ modifier is implemented by actually setting a # variable in the scope of the expression and deleting it again after the -# loop. This is different from the .for loops, which substitute the variable +# loop. This is different from the .for loops, which substitute the # expression with ${:Uvalue}, leading to different unwanted side effects. # # To make the behavior more predictable, the :@ modifier should restore the @@ -98,7 +111,7 @@ SUBST_CONTAINING_LOOP:= ${USE_8_DOLLARS} # The variable SUBST_CONTAINING_LOOP therefore gets assigned the raw value # "$$$$ $$$$$$$$ $$$$$$$$". # -# The variable expression in the condition then expands this raw stored value +# The expression in the condition then expands this raw stored value # once, resulting in "$$ $$$$ $$$$". The effects from VARE_KEEP_DOLLAR no # longer take place since they had only been active during the evaluation of # the variable assignment. @@ -186,4 +199,48 @@ CMDLINE= global # needed for deleting the environment . error # 'CMDLINE' is gone now from all scopes .endif + +# In the loop body text of the ':@' modifier, a literal '$' is written as '$$', +# not '\$'. In the following example, each '$$' turns into a single '$', +# except for '$i', which is replaced with the then-current value '1' of the +# iteration variable. +# +# See parse-var.mk, keyword 'BRACE_GROUP'. +all: varmod-loop-literal-dollar +varmod-loop-literal-dollar: .PHONY + : ${:U1:@i@ t=$$(( $${t:-0} + $i ))@} + + +# When parsing the loop body, each '\$', '\@' and '\\' is unescaped to '$', +# '@' and '\', respectively; all other backslashes are retained. +# +# In practice, the '$' is not escaped as '\$', as there is a second round of +# unescaping '$$' to '$' later when the loop body is expanded after setting the +# iteration variable. +# +# After the iteration variable has been set, the loop body is expanded with +# this unescaping, regardless of whether .MAKE.SAVE_DOLLARS is set or not: +# $$ a literal '$' +# $x, ${var}, $(var) a nested expression +# any other character itself +all: escape-modifier +escape-modifier: .PHONY + # In the first round, '\$ ' is unescaped to '$ ', and since the + # variable named ' ' is not defined, the expression '$ ' expands to an + # empty string. + # expect: : dollar=end + : ${:U1:@i@ dollar=\$ end@} + + # Like in other modifiers, '\ ' is preserved, since ' ' is not one of + # the characters that _must_ be escaped. + # expect: : backslash=\ end + : ${:U1:@i@ backslash=\ end@} + + # expect: : dollar=$ at=@ backslash=\ end + : ${:U1:@i@ dollar=\$\$ at=\@ backslash=\\ end@} + # expect: : dollar=$$ at=@@ backslash=\\ end + : ${:U1:@i@ dollar=\$\$\$\$ at=\@\@ backslash=\\\\ end@} + # expect: : dollar=$$ at=@@ backslash=\\ end + : ${:U1:@i@ dollar=$$$$ at=\@\@ backslash=\\\\ end@} + all: .PHONY diff --git a/contrib/bmake/unit-tests/varmod-match-escape.exp b/contrib/bmake/unit-tests/varmod-match-escape.exp index 25cf6c0719d4..9a8f9ccf6082 100755 --- a/contrib/bmake/unit-tests/varmod-match-escape.exp +++ b/contrib/bmake/unit-tests/varmod-match-escape.exp @@ -30,10 +30,12 @@ Pattern for ':M' is ":\:" ModifyWords: split ": :: :\:" into 3 words Result of ${VALUES:M${:U\:}\:} is "::" Comparing ":" != "::" -make: "varmod-match-escape.mk" line 42: warning: XXX: Oops +make: "varmod-match-escape.mk" line 43: warning: XXX: Oops Global: .MAKEFLAGS = -r -k -d cv -d Global: .MAKEFLAGS = -r -k -d cv -d 0 -make: "varmod-match-escape.mk" line 67: Dollar followed by nothing +make: "varmod-match-escape.mk" line 69: Dollar followed by nothing +make: "varmod-match-escape.mk" line 110: warning: Unfinished character list in pattern '[A-]' of modifier ':M' +make: "varmod-match-escape.mk" line 110: warning: Unfinished character list in pattern '[^A-]' of modifier ':M' make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/varmod-match-escape.mk b/contrib/bmake/unit-tests/varmod-match-escape.mk index 5ac69f964a68..1da3918fe1a5 100755 --- a/contrib/bmake/unit-tests/varmod-match-escape.mk +++ b/contrib/bmake/unit-tests/varmod-match-escape.mk @@ -1,8 +1,8 @@ -# $NetBSD: varmod-match-escape.mk,v 1.7 2021/04/03 11:08:40 rillig Exp $ +# $NetBSD: varmod-match-escape.mk,v 1.12 2023/11/19 21:47:52 rillig Exp $ # # As of 2020-08-01, the :M and :N modifiers interpret backslashes differently, -# depending on whether there was a variable expression somewhere before the -# first backslash or not. See ApplyModifier_Match, "copy = true". +# depending on whether there was an expression somewhere before the +# first backslash or not. See ParseModifier_Match, "copy = true". # # Apart from the different and possibly confusing debug output, there is no # difference in behavior. When parsing the modifier text, only \{, \} and \: @@ -18,27 +18,28 @@ SPECIALS= \: : \\ * \* .endif # And now both cases combined: A single modifier with both an escaped ':' -# as well as a variable expression that expands to a ':'. +# as well as an expression that expands to a ':'. # -# XXX: As of 2020-11-01, when an escaped ':' occurs before the variable +# XXX: As of 2020-11-01, when an escaped ':' occurs before the # expression, the whole modifier text is subject to unescaping '\:' to ':', -# before the variable expression is expanded. This means that the '\:' in -# the variable expression is expanded as well, turning ${:U\:} into a simple +# before the expression is expanded. This means that the '\:' in +# the expression is expanded as well, turning ${:U\:} into a simple # ${:U:}, which silently expands to an empty string, instead of generating # an error message. # # XXX: As of 2020-11-01, the modifier on the right-hand side of the -# comparison is parsed differently though. First, the variable expression +# comparison is parsed differently though. First, the expression # is parsed, resulting in ':' and needSubst=true. After that, the escaped # ':' is seen, and this time, copy=true is not executed but stays copy=false. # Therefore the escaped ':' is kept as-is, and the final pattern becomes # ':\:'. # -# If ApplyModifier_Match had used the same parsing algorithm as Var_Subst, +# If ParseModifier_Match had used the same parsing algorithm as Var_Subst, # both patterns would end up as '::'. # VALUES= : :: :\: .if ${VALUES:M\:${:U\:}} != ${VALUES:M${:U\:}\:} +# expect+1: warning: XXX: Oops . warning XXX: Oops .endif @@ -52,7 +53,7 @@ VALUES= : :: :\: .endif # XXX: As of 2020-11-01, unlike all other variable modifiers, '\$' is not -# parsed as an escaped '$'. Instead, ApplyModifier_Match first scans for +# parsed as an escaped '$'. Instead, ParseModifier_Match first scans for # the ':' at the end of the modifier, which results in the pattern '\$'. # No unescaping takes place since the pattern neither contained '\:' nor # '\{' nor '\}'. But the text is expanded, and a lonely '$' at the end @@ -64,6 +65,7 @@ VALUES= : :: :\: # In lint mode, the case of a lonely '$' is covered with an error message. .MAKEFLAGS: -dL +# expect+1: Dollar followed by nothing .if ${:U\$:M\$} != "" . error .endif @@ -75,12 +77,41 @@ VALUES= : :: :\: # # TODO: Str_Match("a-z]", "[a-z]") # TODO: Str_Match("012", "[0-]]") -# TODO: Str_Match("0]", "[0-]]") -# TODO: Str_Match("1]", "[0-]]") # TODO: Str_Match("[", "[[]") # TODO: Str_Match("]", "[]") # TODO: Str_Match("]", "[[-]]") +# Demonstrate an inconsistency between positive and negative character lists +# when the range ends with the character ']'. +# +# 'A' begins the range, 'B' is in the middle of the range, ']' ends the range, +# 'a' is outside the range. +WORDS= A A] A]] B B] B]] ] ]] ]]] a a] a]] +# The ']' is part of the character range and at the same time ends the +# character list. +EXP.[A-]= A B ] +# The first ']' is part of the character range and at the same time ends the +# character list. +EXP.[A-]]= A] B] ]] +# The first ']' is part of the character range and at the same time ends the +# character list. +EXP.[A-]]]= A]] B]] ]]] +# For negative character lists, the ']' ends the character range but does not +# end the character list. +# XXX: This is unnecessarily inconsistent but irrelevant in practice as there +# is no practical need for a character range that ends at ']'. +EXP.[^A-]= a +EXP.[^A-]]= a +EXP.[^A-]]]= a] + +.for pattern in [A-] [A-]] [A-]]] [^A-] [^A-]] [^A-]]] +# expect+2: warning: Unfinished character list in pattern '[A-]' of modifier ':M' +# expect+1: warning: Unfinished character list in pattern '[^A-]' of modifier ':M' +. if ${WORDS:M${pattern}} != ${EXP.${pattern}} +. warning ${pattern}: ${WORDS:M${pattern}} != ${EXP.${pattern}} +. endif +.endfor + # In brackets, the backslash is just an ordinary character. # Outside brackets, it is an escape character for a few special characters. # TODO: Str_Match("\\", "[\\-]]") diff --git a/contrib/bmake/unit-tests/varmod-match.exp b/contrib/bmake/unit-tests/varmod-match.exp index e4ad3ed113f3..e4e0783a7b15 100644 --- a/contrib/bmake/unit-tests/varmod-match.exp +++ b/contrib/bmake/unit-tests/varmod-match.exp @@ -1,16 +1,14 @@ -CondParser_Eval: ${NUMBERS:M[A-Z]*} != "One Two Three Four" -Comparing "One Two Three Four" != "One Two Three Four" -CondParser_Eval: ${NUMBERS:M[^A-Z]*} != "five six seven" -Comparing "five six seven" != "five six seven" -CondParser_Eval: ${NUMBERS:M[^s]*[ex]} != "One Three five" -Comparing "One Three five" != "One Three five" -CondParser_Eval: ${:U****************:M****************b} -CondParser_Eval: ${:Ua \$ sign:M*$$*} != "\$" -Comparing "$" != "$" -CondParser_Eval: ${:Ua \$ sign any-asterisk:M*\$*} != "any-asterisk" -Comparing "any-asterisk" != "any-asterisk" -make: "varmod-match.mk" line 146: Unknown modifier "]" -make: "varmod-match.mk" line 146: Malformed conditional (${ ${:U\:} ${:U\:\:} :L:M[:]} != ":") +make: "varmod-match.mk" line 289: warning: Unfinished character list in pattern 'a[' of modifier ':M' +make: "varmod-match.mk" line 297: warning: Unfinished character list in pattern 'a[^' of modifier ':M' +make: "varmod-match.mk" line 305: warning: Unfinished character list in pattern '[-x1-3' of modifier ':M' +make: "varmod-match.mk" line 313: warning: Unfinished character list in pattern '*[-x1-3' of modifier ':M' +make: "varmod-match.mk" line 322: warning: Unfinished character list in pattern '[^-x1-3' of modifier ':M' +make: "varmod-match.mk" line 336: warning: Unfinished character list in pattern '?[\' of modifier ':M' +make: "varmod-match.mk" line 344: warning: Unfinished character range in pattern '[x-' of modifier ':M' +make: "varmod-match.mk" line 356: warning: Unfinished character range in pattern '[^x-' of modifier ':M' +make: "varmod-match.mk" line 364: warning: Unfinished character list in pattern '[' of modifier ':M' +make: "varmod-match.mk" line 364: Unknown modifier "]" +make: "varmod-match.mk" line 364: Malformed conditional (${ ${:U\:} ${:U\:\:} :L:M[:]} != ":") make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/varmod-match.mk b/contrib/bmake/unit-tests/varmod-match.mk index adea273e530a..d93d1839192d 100644 --- a/contrib/bmake/unit-tests/varmod-match.mk +++ b/contrib/bmake/unit-tests/varmod-match.mk @@ -1,87 +1,96 @@ -# $NetBSD: varmod-match.mk,v 1.8 2022/03/27 18:39:01 rillig Exp $ +# $NetBSD: varmod-match.mk,v 1.20 2023/12/17 23:19:02 rillig Exp $ # -# Tests for the :M variable modifier, which filters words that match the +# Tests for the ':M' modifier, which keeps only those words that match the # given pattern. # -# See ApplyModifier_Match and ModifyWord_Match for the implementation. +# Table of contents +# +# 1. Pattern characters '*', '?' and '\' +# 2. Character lists and character ranges +# 3. Parsing and escaping +# 4. Interaction with other modifiers +# 5. Performance +# 6. Error handling +# 7. Historical bugs +# +# See ApplyModifier_Match, ParseModifier_Match, ModifyWord_Match and +# Str_Match. -.MAKEFLAGS: -dc -NUMBERS= One Two Three Four five six seven +# 1. Pattern characters '*', '?' and '\' +# +# * matches 0 or more characters +# ? matches 1 character +# \x matches the character 'x' -# Only keep words that start with an uppercase letter. -.if ${NUMBERS:M[A-Z]*} != "One Two Three Four" +# The pattern is anchored both at the beginning and at the end of the word. +# Since the pattern 'e' does not contain any pattern matching characters, it +# matches exactly the word 'e', twice. +.if ${a c e aa cc ee e f g:L:Me} != "e e" . error .endif -# Only keep words that start with a character other than an uppercase letter. -.if ${NUMBERS:M[^A-Z]*} != "five six seven" +# The pattern character '?' matches exactly 1 character, the pattern character +# '*' matches 0 or more characters. The whole pattern matches all words that +# start with 's' and have 3 or more characters. +.if ${One Two Three Four five six seven:L:Ms??*} != "six seven" . error .endif -# Only keep words that don't start with s and at the same time end with -# either of [ex]. -# -# This test case ensures that the negation from the first character class -# does not propagate to the second character class. -.if ${NUMBERS:M[^s]*[ex]} != "One Three five" +# Ensure that a pattern without placeholders only matches itself. +.if ${a aa aaa b ba baa bab:L:Ma} != "a" . error .endif -# Before 2020-06-13, this expression took quite a long time in Str_Match, -# calling itself 601080390 times for 16 asterisks. -.if ${:U****************:M****************b} +# Ensure that a pattern that ends with '*' is properly anchored at the +# beginning. +.if ${a aa aaa b ba baa bab:L:Ma*} != "a aa aaa" +. error .endif -# To match a dollar sign in a word, double it. -# -# This is different from the :S and :C variable modifiers, where a '$' -# has to be escaped as '\$'. -.if ${:Ua \$ sign:M*$$*} != "\$" +# Ensure that a pattern that starts with '*' is properly anchored at the end. +.if ${a aa aaa b ba baa bab:L:M*a} != "a aa aaa ba baa" . error .endif -# In the :M modifier, '\$' does not escape a dollar. Instead it is -# interpreted as a backslash followed by whatever expression the -# '$' starts. -# -# This differs from the :S, :C and several other variable modifiers. -${:U*}= asterisk -.if ${:Ua \$ sign any-asterisk:M*\$*} != "any-asterisk" +# Test the fast code path for '*' followed by a regular character. +.if ${:U file.c file.*c file.h file\.c :M*.c} != "file.c file\\.c" +. error +.endif +# Ensure that the fast code path correctly handles the backslash. +.if ${:U file.c file.*c file.h file\.c :M*\.c} != "file.c file\\.c" +. error +.endif +# Ensure that the fast code path correctly handles '\*'. +.if ${:U file.c file.*c file.h file\.c :M*\*c} != "file.*c" +. error +.endif +# Ensure that the partial match '.c' doesn't confuse the fast code path. +.if ${:U file.c.cc file.cc.cc file.cc.c :M*.cc} != "file.c.cc file.cc.cc" +. error +.endif +# Ensure that the substring '.cc' doesn't confuse the fast code path for '.c'. +.if ${:U file.c.cc file.cc.cc file.cc.c :M*.c} != "file.cc.c" . error .endif -# TODO: ${VAR:M(((}}}} -# TODO: ${VAR:M{{{)))} -# TODO: ${VAR:M${UNBALANCED}} -# TODO: ${VAR:M${:U(((\}\}\}}} -.MAKEFLAGS: -d0 - -# Special characters: -# * matches 0 or more arbitrary characters -# ? matches a single arbitrary character -# \ starts an escape sequence, only outside ranges -# [ starts a set for matching a single character -# ] ends a set for matching a single character -# - in a set, forms a range of characters -# ^ as the first character in a set, negates the set -# ( during parsing of the pattern, starts a nesting level -# ) during parsing of the pattern, ends a nesting level -# { during parsing of the pattern, starts a nesting level -# } during parsing of the pattern, ends a nesting level -# : during parsing of the pattern, finishes the pattern -# $ during parsing of the pattern, starts a nested expression -# # in a line except a shell command, starts a comment -# -# Pattern parts: -# * matches 0 or more arbitrary characters -# ? matches exactly 1 arbitrary character -# \x matches exactly the character 'x' -# [...] matches exactly 1 character from the set -# [^...] matches exactly 1 character outside the set -# [a-z] matches exactly 1 character from the range 'a' to 'z' +# 2. Character lists and character ranges # +# [...] matches 1 character from the listed characters +# [^...] matches 1 character from the unlisted characters +# [a-z] matches 1 character from the range 'a' to 'z' +# [z-a] matches 1 character from the range 'a' to 'z' + +# Only keep words that start with an uppercase letter. +.if ${One Two Three Four five six seven:L:M[A-Z]*} != "One Two Three Four" +. error +.endif + +# Only keep words that start with a character other than an uppercase letter. +.if ${One Two Three Four five six seven:L:M[^A-Z]*} != "five six seven" +. error +.endif # [] matches never .if ${ ab a[]b a[b a b :L:M[]} != "" @@ -125,6 +134,82 @@ ${:U*}= asterisk . error .endif +# [\] matches a single backslash; no escaping takes place in +# character ranges +# Without the 'b' in the below words, the backslash would end a word and thus +# influence how the string is split into words. +WORDS= a\b a[\]b ab a\\b +.if ${WORDS:Ma[\]b} != "a\\b" +. error +.endif + +# [[-]] May look like it would match a single '[', '\' or ']', but +# the inner ']' has two roles: it is the upper bound of the +# character range as well as the closing character of the +# character list. The outer ']' is just a regular character. +WORDS= [ ] [] \] ]] +.if ${WORDS:M[[-]]} != "[] \\] ]]" +. error +.endif + +# [b[-]a] +# Same as for '[[-]]': the character list stops at the first +# ']', and the 'a]' is treated as a literal string. +WORDS= [a \a ]a []a \]a ]]a [a] \a] ]a] ba] +.if ${WORDS:M[b[-]a]} != "[a] \\a] ]a] ba]" +. error +.endif + +# [-] Matches a single '-' since the '-' only becomes part of a +# character range if it is preceded and followed by another +# character. +WORDS= - -] +.if ${WORDS:M[-]} != "-" +. error +.endif + +# Only keep words that don't start with s and at the same time end with +# either of [ex]. +# +# This test case ensures that the negation from the first character list +# '[^s]' does not propagate to the second character list '[ex]'. +.if ${One Two Three Four five six seven:L:M[^s]*[ex]} != "One Three five" +. error +.endif + + +# 3. Parsing and escaping +# +# * matches 0 or more characters +# ? matches 1 character +# \ outside a character list, escapes the following character +# [ starts a character list for matching 1 character +# ] ends a character list for matching 1 character +# - in a character list, forms a character range +# ^ at the beginning of a character list, negates the list +# ( while parsing the pattern, starts a nesting level +# ) while parsing the pattern, ends a nesting level +# { while parsing the pattern, starts a nesting level +# } while parsing the pattern, ends a nesting level +# : while parsing the pattern, terminates the pattern +# $ while parsing the pattern, starts a nested expression +# # in a line except a shell command, starts a comment + +# The pattern can come from an expression. For single-letter +# variables, either the short form or the long form can be used, just as +# everywhere else. +PRIMES= 2 3 5 7 11 +n= 2 +.if ${PRIMES:M$n} != "2" +. error +.endif +.if ${PRIMES:M${n}} != "2" +. error +.endif +.if ${PRIMES:M${:U2}} != "2" +. error +.endif + # : terminates the pattern .if ${ A * :L:M:} != "" . error @@ -140,39 +225,32 @@ ${:U*}= asterisk . error .endif -# [:] matches never since the ':' starts the next modifier -# expect+2: Unknown modifier "]" -# expect+1: Malformed conditional (${ ${:U\:} ${:U\:\:} :L:M[:]} != ":") -.if ${ ${:U\:} ${:U\:\:} :L:M[:]} != ":" -. error -.else +# To match a dollar sign in a word, double it. +# +# This is different from the :S and :C modifiers, where a '$' has to be +# escaped as '\$'. +.if ${:Ua \$ sign:M*$$*} != "\$" . error .endif -# [\] matches exactly a backslash; no escaping takes place in -# character ranges -# Without the 'a' in the below expressions, the backslash would end a word and -# thus influence how the string is split into words. -.if ${ ${:U\\a} ${:U\\\\a} :L:M[\]a} != "\\a" +# In the :M modifier, '\$' does not escape a dollar. Instead it is +# interpreted as a backslash followed by whatever expression the +# '$' starts. +# +# This differs from the :S, :C and several other modifiers. +${:U*}= asterisk +.if ${:Ua \$ sign any-asterisk:M*\$*} != "any-asterisk" . error .endif -#.MAKEFLAGS: -dcv -# -# Incomplete patterns: -# [ matches TODO -# [x matches TODO -# [^ matches TODO -# [- matches TODO -# [xy matches TODO -# [^x matches TODO -# [\ matches TODO -# -# [x- matches exactly 'x', doesn't match 'x-' -# [^x- matches TODO -# \ matches never +# TODO: ${VAR:M(((}}}} +# TODO: ${VAR:M{{{)))} +# TODO: ${VAR:M${UNBALANCED}} +# TODO: ${VAR:M${:U(((\}\}\}}} +# 4. Interaction with other modifiers + # The modifier ':tW' prevents splitting at whitespace. Even leading and # trailing whitespace is preserved. .if ${ plain string :L:tW:M*} != " plain string " @@ -184,3 +262,119 @@ ${:U*}= asterisk .if ${ plain string :L:M*} != "plain string" . error .endif + + +# 5. Performance + +# Before 2020-06-13, this expression called Str_Match 601,080,390 times. +# Since 2020-06-13, this expression calls Str_Match 1 time. +.if ${:U****************:M****************b} +.endif + +# Before 2023-06-22, this expression called Str_Match 2,621,112 times. +# Adding another '*?' to the pattern called Str_Match 20,630,572 times. +# Adding another '*?' to the pattern called Str_Match 136,405,672 times. +# Adding another '*?' to the pattern called Str_Match 773,168,722 times. +# Adding another '*?' to the pattern called Str_Match 3,815,481,072 times. +# Since 2023-06-22, Str_Match no longer backtracks. +.if ${:U..................................................b:M*?*?*?*?*?a} +.endif + + +# 6. Error handling + +# [ Incomplete empty character list, never matches. +WORDS= a a[ +# expect+1: warning: Unfinished character list in pattern 'a[' of modifier ':M' +.if ${WORDS:Ma[} != "" +. error +.endif + +# [^ Incomplete negated empty character list, matches any single +# character. +WORDS= a a[ aX +# expect+1: warning: Unfinished character list in pattern 'a[^' of modifier ':M' +.if ${WORDS:Ma[^} != "a[ aX" +. error +.endif + +# [-x1-3 Incomplete character list, matches those elements that can be +# parsed without lookahead. +WORDS= - + x xx 0 1 2 3 4 [x1-3 +# expect+1: warning: Unfinished character list in pattern '[-x1-3' of modifier ':M' +.if ${WORDS:M[-x1-3} != "- x 1 2 3" +. error +.endif + +# *[-x1-3 Incomplete character list after a wildcard, matches those +# words that end with one of the characters from the list. +WORDS= - + x xx 0 1 2 3 4 00 01 10 11 000 001 010 011 100 101 110 111 [x1-3 +# expect+1: warning: Unfinished character list in pattern '*[-x1-3' of modifier ':M' +.if ${WORDS:M*[-x1-3} != "- x xx 1 2 3 01 11 001 011 101 111 [x1-3" +. warning ${WORDS:M*[-x1-3} +.endif + +# [^-x1-3 +# Incomplete negated character list, matches any character +# except those elements that can be parsed without lookahead. +WORDS= - + x xx 0 1 2 3 4 [x1-3 +# expect+1: warning: Unfinished character list in pattern '[^-x1-3' of modifier ':M' +.if ${WORDS:M[^-x1-3} != "+ 0 4" +. error +.endif + +# [\ Incomplete character list containing a single '\'. +# +# A word can only end with a backslash if the preceding +# character is a backslash as well; in all other cases the final +# backslash would escape the following space, making the space +# part of the word. Only the very last word of a string can be +# '\', as there is no following space that could be escaped. +WORDS= \\ \a ${:Ux\\} +PATTERN= ${:U?[\\} +# expect+1: warning: Unfinished character list in pattern '?[\' of modifier ':M' +.if ${WORDS:M${PATTERN}} != "\\\\ x\\" +. error +.endif + +# [x- Incomplete character list containing an incomplete character +# range, matches only the 'x'. +WORDS= [x- x x- y +# expect+1: warning: Unfinished character range in pattern '[x-' of modifier ':M' +.if ${WORDS:M[x-} != "x" +. error +.endif + +# [^x- Incomplete negated character list containing an incomplete +# character range; matches each word that does not have an 'x' +# at the position of the character list. +# +# XXX: Even matches strings that are longer than a single +# character. +WORDS= [x- x x- y yyyyy +# expect+1: warning: Unfinished character range in pattern '[^x-' of modifier ':M' +.if ${WORDS:M[^x-} != "[x- y yyyyy" +. error +.endif + +# [:] matches never since the ':' starts the next modifier +# expect+3: warning: Unfinished character list in pattern '[' of modifier ':M' +# expect+2: Unknown modifier "]" +# expect+1: Malformed conditional (${ ${:U\:} ${:U\:\:} :L:M[:]} != ":") +.if ${ ${:U\:} ${:U\:\:} :L:M[:]} != ":" +. error +.else +. error +.endif + + +# 7. Historical bugs + +# Before var.c 1.1031 from 2022-08-24, the following expressions caused an +# out-of-bounds read beyond the indirect ':M' modifiers. +.if ${:U:${:UM\\}} # The ':M' pattern need not be unescaped, the +. error # resulting pattern is '\', it never matches +.endif # anything. +.if ${:U:${:UM\\\:\\}} # The ':M' pattern must be unescaped, the +. error # resulting pattern is ':\', it never matches +.endif # anything. diff --git a/contrib/bmake/unit-tests/varmod-mtime.exp b/contrib/bmake/unit-tests/varmod-mtime.exp new file mode 100644 index 000000000000..039173feddc3 --- /dev/null +++ b/contrib/bmake/unit-tests/varmod-mtime.exp @@ -0,0 +1,14 @@ +make: "varmod-mtime.mk" line 47: Invalid argument '123x' for modifier ':mtime' +make: "varmod-mtime.mk" line 47: Malformed conditional (${no/such/file:L:mtime=123x}) +make: "varmod-mtime.mk" line 70: Cannot determine mtime for 'no/such/file1': <ENOENT> +make: "varmod-mtime.mk" line 70: Cannot determine mtime for 'no/such/file2': <ENOENT> +make: "varmod-mtime.mk" line 70: Malformed conditional (${no/such/file1 no/such/file2:L:mtime=error}) +make: "varmod-mtime.mk" line 81: Invalid argument 'errorhandler-no' for modifier ':mtime' +make: "varmod-mtime.mk" line 81: Malformed conditional (${MAKEFILE:mtime=errorhandler-no} > 0) +make: "varmod-mtime.mk" line 90: Invalid argument 'warn' for modifier ':mtime' +make: "varmod-mtime.mk" line 90: Malformed conditional (${MAKEFILE:mtime=warn} > 0) +make: "varmod-mtime.mk" line 115: Unknown modifier "mtim" +make: "varmod-mtime.mk" line 115: Malformed conditional (${anything:L:mtim}) +make: Fatal errors encountered -- cannot continue +make: stopped in unit-tests +exit status 1 diff --git a/contrib/bmake/unit-tests/varmod-mtime.mk b/contrib/bmake/unit-tests/varmod-mtime.mk new file mode 100644 index 000000000000..298756e152c1 --- /dev/null +++ b/contrib/bmake/unit-tests/varmod-mtime.mk @@ -0,0 +1,125 @@ +# $NetBSD: varmod-mtime.mk,v 1.9 2023/12/17 14:07:22 rillig Exp $ +# +# Tests for the ':mtime' variable modifier, which maps each word of the +# expression to that file's modification time. + +# Note: strftime() uses mktime() for %s and mktime() assumes localtime +# so this should match time() +start:= ${%s:L:localtime} # see varmod-gmtime.mk, keyword '%s' + + +# Ensure that this makefile exists and has a modification time. If the file +# didn't exist, the ':mtime' modifier would return the current time. +.if ${MAKEFILE:mtime} >= ${start} +. error +.endif + + +# For a file that doesn't exist, the ':mtime' modifier returns the current +# time, without an error or warning message. The returned timestamp differs +# from the 'now' that is used when updating the timestamps in archives or for +# touching files using the '-t' option, which is taken once when make is +# started. +not_found_mtime:= ${no/such/file:L:mtime} +.if ${not_found_mtime} < ${start} +. error +.endif + + +# The ':mtime' modifier accepts a timestamp in seconds as an optional +# argument. This timestamp is used as a fallback in case the file's time +# cannot be determined, without any error or warning message. +.if ${no/such/file:L:mtime=0} != "0" +. error +.endif + + +# The fallback timestamp must start with a digit, and it is interpreted as a +# decimal integer. +.if ${no/such/file:L:mtime=00042} != "42" +. error +.endif + + +# The fallback timestamp must only be an integer, without trailing characters. +# expect+2: Invalid argument '123x' for modifier ':mtime' +# expect+1: Malformed conditional (${no/such/file:L:mtime=123x}) +.if ${no/such/file:L:mtime=123x} +. error +.else +. error +.endif + + +# The timestamp of a newly created file must be at least as great as the +# timestamp when parsing of this makefile started. +COOKIE= ${TMPDIR:U/tmp}/varmod-mtime.cookie +_!= touch ${COOKIE} +.if ${COOKIE:mtime=0} < ${start} +. error ${COOKIE:mtime=0} < ${start} +.endif +_!= rm -f ${COOKIE} + + +# If the optional argument of the ':mtime' modifier is the word 'error', the +# modifier fails with an error message, once for each affected file. +# +# expect+3: Cannot determine mtime for 'no/such/file1': <ENOENT> +# expect+2: Cannot determine mtime for 'no/such/file2': <ENOENT> +# expect+1: Malformed conditional (${no/such/file1 no/such/file2:L:mtime=error}) +.if ${no/such/file1 no/such/file2:L:mtime=error} +. error +.else +. error +.endif + + +# Only the word 'error' is a special argument to the ':mtime' modifier, all +# other words result in a parse error. +# expect+2: Invalid argument 'errorhandler-no' for modifier ':mtime' +# expect+1: Malformed conditional (${MAKEFILE:mtime=errorhandler-no} > 0) +.if ${MAKEFILE:mtime=errorhandler-no} > 0 +.else +. error +.endif + + +# Only the word 'error' can be used as a fallback argument to the modifier. +# expect+2: Invalid argument 'warn' for modifier ':mtime' +# expect+1: Malformed conditional (${MAKEFILE:mtime=warn} > 0) +.if ${MAKEFILE:mtime=warn} > 0 +. error +.else +. error +.endif + + +# Ensure that the fallback for a missing modification time is indeed the +# current time, and not any later time. +end:= ${%s:L:gmtime} +.if ${not_found_mtime} > ${end} +. error +.endif + + +# If the expression is irrelevant, the ':mtime' modifier is only parsed, it +# does not perform any filesystem operations. +.if 0 && ${no/such/file:L:mtime=error} +. error +.endif + + +# If there is a typo in the modifier name, it does not match. +# expect+2: Unknown modifier "mtim" +# expect+1: Malformed conditional (${anything:L:mtim}) +.if ${anything:L:mtim} +. error +.else +. error +.endif + + +# An empty word list results in an empty mtime list. +.if ${:U:mtime} != "" +. error +.endif diff --git a/contrib/bmake/unit-tests/varmod-no-match.mk b/contrib/bmake/unit-tests/varmod-no-match.mk index 2acb27e2e727..c03b4bf94e70 100644 --- a/contrib/bmake/unit-tests/varmod-no-match.mk +++ b/contrib/bmake/unit-tests/varmod-no-match.mk @@ -1,9 +1,97 @@ -# $NetBSD: varmod-no-match.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $ +# $NetBSD: varmod-no-match.mk,v 1.3 2023/02/26 06:08:06 rillig Exp $ # -# Tests for the :N variable modifier, which filters words that do not match -# the given pattern. +# Tests for the expression modifier ':N', which filters words that do not +# match the given pattern. + + +# Keep all words except for 'two'. +.if ${:U one two three :Ntwo} != "one three" +. error +.endif + +# Keep all words except those starting with 't'. +# See varmod-match.mk for the details of pattern matching. +.if ${:U one two three four six :Nt*} != "one four six" +. error +.endif + + +# Idiom: normalize whitespace +# +# The modifier ':N' can be used with an empty pattern. As that pattern never +# matches a word, the only effect is that the string is split into words and +# then joined again, thereby normalizing whitespace around and between the +# words. And even though the 'N' in ':N' might serve as a mnemonic for +# "normalize whitespace", this idiom is not used in practice, resorting to the +# much more common ':M*' to "select all words" instead. +.if ${:U :N} != "" +. error +.endif +.if ${:U one two three :N} != "one two three" +. error +.endif +.if ${:U one two three :M*} != "one two three" +. error +.endif + + +# Idiom: single-word expression equals any of several words or patterns +# +# If an expression is guaranteed to consist of a single word, the modifier +# ':N' can be chained to compare the expression to several words or even +# patterns in a sequence. If one of the patterns matches, the final +# expression will be the empty string. +# +.if ${:U word :None:Ntwo:Nthree} != "" +# good +.else +. error +.endif +.if ${:U two :None:Ntwo:Nthree} != "" +. error +.else +# good +.endif +# +# The modifier ':N' is seldom used in general since positive matches with ':M' +# are easier to grasp. Chaining the ':N' modifier is even more difficult to +# grasp due to the many negations involved. +# +# The final '!= ""' adds to the confusion because at first glance, the +# condition may look like '${VAR} != ""', which for a single-word variable is +# always true. +# +# The '!= ""' can be omitted if the expression cannot have the numeric value +# 0, which is common in practice. In that form, each ':N' can be pronounced +# as 'neither' or 'nor', which makes the expression sound more natural. +# +.if ${:U word :None:Ntwo:Nthree} +# good +.else +. error +.endif +.if ${:U two :None:Ntwo:Nthree} +. error +.else +# good +.endif +# +# Replacing the '${...} != ""' with '!empty(...)' doesn't improve the +# situation as the '!' adds another level of negations, and the word 'empty' +# is a negation on its own, thereby creating a triple negation. Furthermore, +# due to the '!empty', the expression to be evaluated no longer starts with +# '$' and is thus more difficult to spot quickly. +# +.if !empty(:U word :None:Ntwo:Nthree) +# good +.else +. error +.endif +.if !empty(:U two :None:Ntwo:Nthree) +. error +.else +# good +.endif -# TODO: Implementation all: - @:; diff --git a/contrib/bmake/unit-tests/varmod-order-numeric.mk b/contrib/bmake/unit-tests/varmod-order-numeric.mk index 542894c53942..62212bd265ad 100644 --- a/contrib/bmake/unit-tests/varmod-order-numeric.mk +++ b/contrib/bmake/unit-tests/varmod-order-numeric.mk @@ -1,4 +1,4 @@ -# $NetBSD: varmod-order-numeric.mk,v 1.7 2022/02/09 21:09:24 rillig Exp $ +# $NetBSD: varmod-order-numeric.mk,v 1.8 2022/09/27 19:18:45 rillig Exp $ # # Tests for the variable modifiers ':On', which returns the words, sorted in # ascending numeric order, and for ':Orn' and ':Onr', which additionally @@ -50,4 +50,10 @@ MIXED_BASE= 0 010 0x7 9 . error ${MIXED_BASE:On} .endif +# The measurement units for suffixes are k, M, G, but not T. +# The string '3T' evaluates to 3, the string 'x' evaluates as '0'. +.if ${4 3T 2M x:L:On} != "x 3T 4 2M" +. error +.endif + all: diff --git a/contrib/bmake/unit-tests/varmod-order-shuffle.mk b/contrib/bmake/unit-tests/varmod-order-shuffle.mk index 16121d7e498f..e9898600355a 100644 --- a/contrib/bmake/unit-tests/varmod-order-shuffle.mk +++ b/contrib/bmake/unit-tests/varmod-order-shuffle.mk @@ -1,4 +1,4 @@ -# $NetBSD: varmod-order-shuffle.mk,v 1.7 2021/08/03 04:46:49 rillig Exp $ +# $NetBSD: varmod-order-shuffle.mk,v 1.8 2023/02/26 06:08:06 rillig Exp $ # # Tests for the :Ox variable modifier, which returns the words of the # variable, shuffled. @@ -6,8 +6,9 @@ # The variable modifier :Ox is available since 2005-06-01. # # As of 2020-08-16, make uses random(3) seeded by the current time in seconds. -# This makes the random numbers completely predictable since there is no other -# part of make that uses random numbers. +# This makes the random numbers completely predictable since the only other +# part of make that uses random numbers is the 'randomize-targets' mode, which +# is off by default. # # Tags: probabilistic diff --git a/contrib/bmake/unit-tests/varmod-order.exp b/contrib/bmake/unit-tests/varmod-order.exp index 46dc45e9f6d6..12d0bff75157 100644 --- a/contrib/bmake/unit-tests/varmod-order.exp +++ b/contrib/bmake/unit-tests/varmod-order.exp @@ -1,24 +1,26 @@ make: Bad modifier ":OX" for variable "WORDS" -make: "varmod-order.mk" line 14: Undefined variable "${WORDS:OX" +make: "varmod-order.mk" line 16: Undefined variable "${WORDS:OX" make: Bad modifier ":OxXX" for variable "WORDS" -make: "varmod-order.mk" line 17: Undefined variable "${WORDS:Ox" -make: Unclosed variable expression, expecting '}' for modifier "O" of variable "WORDS" with value "eight five four nine one seven six ten three two" -make: Unclosed variable expression, expecting '}' for modifier "On" of variable "NUMBERS" with value "1 2 3 4 5 6 7 8 9 10" -make: Unclosed variable expression, expecting '}' for modifier "Onr" of variable "NUMBERS" with value "10 9 8 7 6 5 4 3 2 1" +make: "varmod-order.mk" line 21: Undefined variable "${WORDS:Ox" +make: Unclosed expression, expecting '}' for modifier "O" of variable "WORDS" with value "eight five four nine one seven six ten three two" +make: Unclosed expression, expecting '}' for modifier "On" of variable "NUMBERS" with value "1 2 3 4 5 6 7 8 9 10" +make: Unclosed expression, expecting '}' for modifier "Onr" of variable "NUMBERS" with value "10 9 8 7 6 5 4 3 2 1" make: Bad modifier ":Oxn" for variable "NUMBERS" -make: "varmod-order.mk" line 29: Malformed conditional (${NUMBERS:Oxn}) +make: "varmod-order.mk" line 33: Malformed conditional (${NUMBERS:Oxn}) make: Bad modifier ":On_typo" for variable "NUMBERS" -make: "varmod-order.mk" line 39: Malformed conditional (${NUMBERS:On_typo}) +make: "varmod-order.mk" line 44: Malformed conditional (${NUMBERS:On_typo}) make: Bad modifier ":Onr_typo" for variable "NUMBERS" -make: "varmod-order.mk" line 48: Malformed conditional (${NUMBERS:Onr_typo}) +make: "varmod-order.mk" line 54: Malformed conditional (${NUMBERS:Onr_typo}) make: Bad modifier ":Orn_typo" for variable "NUMBERS" -make: "varmod-order.mk" line 57: Malformed conditional (${NUMBERS:Orn_typo}) +make: "varmod-order.mk" line 64: Malformed conditional (${NUMBERS:Orn_typo}) make: Bad modifier ":Onn" for variable "NUMBERS" -make: "varmod-order.mk" line 68: Malformed conditional (${NUMBERS:Onn}) +make: "varmod-order.mk" line 76: Malformed conditional (${NUMBERS:Onn}) make: Bad modifier ":Onrr" for variable "NUMBERS" -make: "varmod-order.mk" line 77: Malformed conditional (${NUMBERS:Onrr}) +make: "varmod-order.mk" line 86: Malformed conditional (${NUMBERS:Onrr}) make: Bad modifier ":Orrn" for variable "NUMBERS" -make: "varmod-order.mk" line 86: Malformed conditional (${NUMBERS:Orrn}) +make: "varmod-order.mk" line 96: Malformed conditional (${NUMBERS:Orrn}) +make: Bad modifier ":On=Off" for variable "SWITCH" +make: "varmod-order.mk" line 111: Malformed conditional (${SWITCH:On=Off} != "Off") make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/varmod-order.mk b/contrib/bmake/unit-tests/varmod-order.mk index c6028fc10abd..67919543a93e 100644 --- a/contrib/bmake/unit-tests/varmod-order.mk +++ b/contrib/bmake/unit-tests/varmod-order.mk @@ -1,4 +1,4 @@ -# $NetBSD: varmod-order.mk,v 1.8 2022/01/15 12:35:18 rillig Exp $ +# $NetBSD: varmod-order.mk,v 1.11 2023/06/01 20:56:35 rillig Exp $ # # Tests for the :O variable modifier and its variants, which either sort the # words of the value or shuffle them. @@ -11,9 +11,13 @@ NUMBERS= 8 5 4 9 1 7 6 10 3 2 # in English alphabetical order .endif # Unknown modifier "OX" +# FIXME: The error message is wrong. +# expect+1: Undefined variable "${WORDS:OX" _:= ${WORDS:OX} # Unknown modifier "OxXX" +# FIXME: The error message is wrong. +# expect+1: Undefined variable "${WORDS:Ox" _:= ${WORDS:OxXX} # Missing closing brace, to cover the error handling code. @@ -36,6 +40,7 @@ _:= ${NUMBERS:Onr # TODO: Add line number information to the "Bad modifier" diagnostic. # # expect: make: Bad modifier ":On_typo" for variable "NUMBERS" +# expect+1: Malformed conditional (${NUMBERS:On_typo}) .if ${NUMBERS:On_typo} . error .else @@ -45,6 +50,7 @@ _:= ${NUMBERS:Onr # Extra characters after ':Onr' are detected and diagnosed. # # expect: make: Bad modifier ":Onr_typo" for variable "NUMBERS" +# expect+1: Malformed conditional (${NUMBERS:Onr_typo}) .if ${NUMBERS:Onr_typo} . error .else @@ -54,6 +60,7 @@ _:= ${NUMBERS:Onr # Extra characters after ':Orn' are detected and diagnosed. # # expect: make: Bad modifier ":Orn_typo" for variable "NUMBERS" +# expect+1: Malformed conditional (${NUMBERS:Orn_typo}) .if ${NUMBERS:Orn_typo} . error .else @@ -65,6 +72,7 @@ _:= ${NUMBERS:Onr # not make sense. # # expect: make: Bad modifier ":Onn" for variable "NUMBERS" +# expect+1: Malformed conditional (${NUMBERS:Onn}) .if ${NUMBERS:Onn} . error .else @@ -74,6 +82,7 @@ _:= ${NUMBERS:Onr # Repeating the 'r' is not supported as well, for the same reasons as above. # # expect: make: Bad modifier ":Onrr" for variable "NUMBERS" +# expect+1: Malformed conditional (${NUMBERS:Onrr}) .if ${NUMBERS:Onrr} . error .else @@ -83,10 +92,26 @@ _:= ${NUMBERS:Onr # Repeating the 'r' is not supported as well, for the same reasons as above. # # expect: make: Bad modifier ":Orrn" for variable "NUMBERS" +# expect+1: Malformed conditional (${NUMBERS:Orrn}) .if ${NUMBERS:Orrn} . error .else . error .endif + +# If a modifier that starts with ':O' is not one of the known sort or shuffle +# forms, it is a parse error. Several other modifiers such as ':H' or ':u' +# fall back to the SysV modifier, for example, ':H=new' is not the standard +# ':H' modifier but instead replaces a trailing 'H' with 'new' in each word. +# There is no such fallback for the ':O' modifiers. +SWITCH= On +# expect: make: Bad modifier ":On=Off" for variable "SWITCH" +# expect+1: Malformed conditional (${SWITCH:On=Off} != "Off") +.if ${SWITCH:On=Off} != "Off" +. error +.else +. error +.endif + all: diff --git a/contrib/bmake/unit-tests/varmod-path.mk b/contrib/bmake/unit-tests/varmod-path.mk index ebbf755ddbec..25d4e3899b99 100644 --- a/contrib/bmake/unit-tests/varmod-path.mk +++ b/contrib/bmake/unit-tests/varmod-path.mk @@ -1,4 +1,4 @@ -# $NetBSD: varmod-path.mk,v 1.3 2020/08/23 08:10:49 rillig Exp $ +# $NetBSD: varmod-path.mk,v 1.4 2023/05/10 15:53:32 rillig Exp $ # # Tests for the :P variable modifier, which looks up the path for a given # target. @@ -7,11 +7,12 @@ # as of 2020-08-23 it is nevertheless resolved to a path. This is probably # unintended. # -# The real target is located in a subdirectory, and its full path is returned. -# If it had been in the current directory, the difference between its path and -# its name would not be visible. +# In this test, the real target is located in a subdirectory, and its full +# path is returned. If it had been in the current directory, the difference +# between its path and its name would not be visible. # -# The enoent target does not exist, therefore the target name is returned. +# The enoent target does not exist, therefore the plain name of the target +# is returned. .MAIN: all @@ -20,7 +21,8 @@ _!= mkdir varmod-path.subdir _!= > varmod-path.subdir/varmod-path.phony _!= > varmod-path.subdir/varmod-path.real -# To have an effect, this .PATH declaration must be after the directory is created. +# To have an effect, this .PATH declaration must be processed after the +# directory has been created. .PATH: varmod-path.subdir varmod-path.phony: .PHONY diff --git a/contrib/bmake/unit-tests/varmod-quote-dollar.exp b/contrib/bmake/unit-tests/varmod-quote-dollar.exp index 4346401c5a9d..f12b0280e6f7 100644 --- a/contrib/bmake/unit-tests/varmod-quote-dollar.exp +++ b/contrib/bmake/unit-tests/varmod-quote-dollar.exp @@ -1,2 +1,4 @@ !"#$$%&'()*+,-./09:;<=>?@AZ[\]^_`az{|}~ +!"#$$%&'()*+,-./09:;<=>?@AZ[\]^_`az{|}~ + !"#$$%&'()*+,-./09:;<=>?@AZ[\]^_`az{|}~ exit status 0 diff --git a/contrib/bmake/unit-tests/varmod-quote-dollar.mk b/contrib/bmake/unit-tests/varmod-quote-dollar.mk index 3316b04bed1e..8e68282c536d 100644 --- a/contrib/bmake/unit-tests/varmod-quote-dollar.mk +++ b/contrib/bmake/unit-tests/varmod-quote-dollar.mk @@ -1,10 +1,17 @@ -# $NetBSD: varmod-quote-dollar.mk,v 1.3 2022/01/22 17:10:51 rillig Exp $ +# $NetBSD: varmod-quote-dollar.mk,v 1.4 2022/05/08 10:14:40 rillig Exp $ # # Tests for the :q variable modifier, which quotes the string for the shell # and doubles dollar signs, to prevent them from being interpreted by a # child process of make. +# The newline and space characters at the beginning of this string are passed +# to the child make. When the child make parses the variable assignment, it +# discards the leading space characters. ASCII_CHARS= ${.newline} !"\#$$%&'()*+,-./09:;<=>?@AZ[\]^_`az{|}~ all: - @${MAKE} -r -f /dev/null CHARS=${ASCII_CHARS:q} -V CHARS + @${MAKE} -r -f /dev/null \ + CHARS=${ASCII_CHARS:q} \ + TWICE=${ASCII_CHARS:q}${ASCII_CHARS:q} \ + -V CHARS \ + -V TWICE diff --git a/contrib/bmake/unit-tests/varmod-range.exp b/contrib/bmake/unit-tests/varmod-range.exp index f4ada11ebde6..9b0dad40a78e 100644 --- a/contrib/bmake/unit-tests/varmod-range.exp +++ b/contrib/bmake/unit-tests/varmod-range.exp @@ -1,13 +1,14 @@ -make: "varmod-range.mk" line 53: Invalid number "x}Rest" != "Rest"" for ':range' modifier -make: "varmod-range.mk" line 53: Malformed conditional ("${:U:range=x}Rest" != "Rest") -make: "varmod-range.mk" line 62: Unknown modifier "x0" -make: "varmod-range.mk" line 62: Malformed conditional ("${:U:range=0x0}Rest" != "Rest") -make: "varmod-range.mk" line 78: Unknown modifier "rang" -make: "varmod-range.mk" line 78: Malformed conditional ("${a b c:L:rang}Rest" != "Rest") -make: "varmod-range.mk" line 85: Unknown modifier "rango" -make: "varmod-range.mk" line 85: Malformed conditional ("${a b c:L:rango}Rest" != "Rest") -make: "varmod-range.mk" line 92: Unknown modifier "ranger" -make: "varmod-range.mk" line 92: Malformed conditional ("${a b c:L:ranger}Rest" != "Rest") +make: "varmod-range.mk" line 43: Malformed conditional (${:range=5} != "") +make: "varmod-range.mk" line 67: Invalid number "x}Rest" != "Rest"" for ':range' modifier +make: "varmod-range.mk" line 67: Malformed conditional ("${:U:range=x}Rest" != "Rest") +make: "varmod-range.mk" line 78: Unknown modifier "x0" +make: "varmod-range.mk" line 78: Malformed conditional ("${:U:range=0x0}Rest" != "Rest") +make: "varmod-range.mk" line 96: Unknown modifier "rang" +make: "varmod-range.mk" line 96: Malformed conditional ("${a b c:L:rang}Rest" != "Rest") +make: "varmod-range.mk" line 105: Unknown modifier "rango" +make: "varmod-range.mk" line 105: Malformed conditional ("${a b c:L:rango}Rest" != "Rest") +make: "varmod-range.mk" line 114: Unknown modifier "ranger" +make: "varmod-range.mk" line 114: Malformed conditional ("${a b c:L:ranger}Rest" != "Rest") make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/varmod-range.mk b/contrib/bmake/unit-tests/varmod-range.mk index d63525248e58..920001096054 100644 --- a/contrib/bmake/unit-tests/varmod-range.mk +++ b/contrib/bmake/unit-tests/varmod-range.mk @@ -1,4 +1,4 @@ -# $NetBSD: varmod-range.mk,v 1.7 2020/11/01 14:36:25 rillig Exp $ +# $NetBSD: varmod-range.mk,v 1.10 2023/12/17 14:07:22 rillig Exp $ # # Tests for the :range variable modifier, which generates sequences # of integers from the given range. @@ -7,7 +7,7 @@ # modword.mk # The :range modifier generates a sequence of integers, one number per -# word of the variable expression's value. +# word of the expression's value. .if ${a b c:L:range} != "1 2 3" . error .endif @@ -19,20 +19,32 @@ .endif # The :range modifier takes the number of words from the value of the -# variable expression. If that expression is undefined, the range is +# expression. If that expression is undefined, the range is # undefined as well. This should not come as a surprise. .if "${:range}" != "" . error .endif +# An empty expression results in a sequence of a single number, even though +# the expression contains 0 words. +.if ${:U:range} != "1" +. error +.endif + # The :range modifier can be given a parameter, which makes the generated -# range independent from the value or the name of the variable expression. -# -# XXX: As of 2020-09-27, the :range=... modifier does not turn the undefined -# expression into a defined one. This looks like an oversight. +# range independent from the value or the name of the expression. .if "${:range=5}" != "" . error .endif +# XXX: As of 2023-12-17, the ':range=n' modifier does not turn the undefined +# expression into a defined one, even though it does not depend on the value +# of the expression. This looks like an oversight. +# expect+1: Malformed conditional (${:range=5} != "") +.if ${:range=5} != "" +. error +.else +. error +.endif # Negative ranges don't make sense. # As of 2020-11-01, they are accepted though, using up all available memory. @@ -50,6 +62,8 @@ # # Since 2020-11-01, the parser issues a more precise "Invalid number" error # instead. +# expect+2: Invalid number "x}Rest" != "Rest"" for ':range' modifier +# expect+1: Malformed conditional ("${:U:range=x}Rest" != "Rest") .if "${:U:range=x}Rest" != "Rest" . error .else @@ -59,6 +73,8 @@ # The upper limit of the range must always be given in decimal. # This parse error stops at the 'x', trying to parse it as a variable # modifier. +# expect+2: Unknown modifier "x0" +# expect+1: Malformed conditional ("${:U:range=0x0}Rest" != "Rest") .if "${:U:range=0x0}Rest" != "Rest" . error .else @@ -75,6 +91,8 @@ #.endif # modifier name too short +# expect+2: Unknown modifier "rang" +# expect+1: Malformed conditional ("${a b c:L:rang}Rest" != "Rest") .if "${a b c:L:rang}Rest" != "Rest" . error .else @@ -82,6 +100,8 @@ .endif # misspelled modifier name +# expect+2: Unknown modifier "rango" +# expect+1: Malformed conditional ("${a b c:L:rango}Rest" != "Rest") .if "${a b c:L:rango}Rest" != "Rest" . error .else @@ -89,6 +109,8 @@ .endif # modifier name too long +# expect+2: Unknown modifier "ranger" +# expect+1: Malformed conditional ("${a b c:L:ranger}Rest" != "Rest") .if "${a b c:L:ranger}Rest" != "Rest" . error .else diff --git a/contrib/bmake/unit-tests/varmod-remember.mk b/contrib/bmake/unit-tests/varmod-remember.mk index 403811759672..e92b2d2c4012 100644 --- a/contrib/bmake/unit-tests/varmod-remember.mk +++ b/contrib/bmake/unit-tests/varmod-remember.mk @@ -1,30 +1,62 @@ -# $NetBSD: varmod-remember.mk,v 1.6 2021/03/14 17:27:27 rillig Exp $ +# $NetBSD: varmod-remember.mk,v 1.9 2023/02/09 22:21:57 rillig Exp $ # -# Tests for the :_ modifier, which saves the current variable value +# Tests for the :_ modifier, which saves the current expression value # in the _ variable or another, to be used later again. -.if ${1 2 3:L:_:@var@${_}@} != "1 2 3 1 2 3 1 2 3" + +# The ':_' modifier is typically used in situations where the value of an +# expression is needed at the same time as a sequence of numbers. In these +# cases, the value of the expression is saved in the temporary variable '_', +# from where it is taken later in the same expression. +ABC= ${A B C:L:_:range:@i@$i=${_:[$i]}@} +DEF= ${D E F:L:_:range:@i@$i=${_:[$i]}@} +GHI= ${G H I:L:_:range:@i@$i=${_:[$i]}@} + +ABC.global:= ${ABC} # is evaluated in the global scope +.if ${ABC.global} != "1=A 2=B 3=C" +. error +.endif + +.if ${DEF} != "1=D 2=E 3=F" # is evaluated in the command line scope +. error +.endif + +# Before var.c 1.1040 from 2023-02-09, the temporary variable '_' was placed +# in the scope of the current evaluation, which meant that after the first +# ':_' modifier had been evaluated in command line scope, all further +# evaluations in global scope could not overwrite the variable '_' anymore, +# as the command line scope takes precedence over the global scope. +# The expression ${GHI} therefore evaluated to '1=D 2=E 3=F', reusing the +# value of '_' from the previous evaluation in command line scope. +GHI.global:= ${GHI} # is evaluated in the global scope +.if ${GHI.global} != "1=G 2=H 3=I" . error .endif + # In the parameterized form, having the variable name on the right side of -# the = assignment operator is confusing. In almost all other situations -# the variable name is on the left-hand side of the = operator. Luckily -# this modifier is only rarely needed. +# the = assignment operator looks confusing. In almost all other situations, +# the variable name is on the left-hand side of the = operator, therefore +# '_=SAVED' looks like it would copy 'SAVED' to '_'. Luckily, this modifier +# is only rarely needed. .if ${1 2 3:L:@var@${var:_=SAVED:}@} != "1 2 3" . error .elif ${SAVED} != "3" . error .endif -# The ':_' modifier takes a variable name as optional argument. This variable -# name can refer to other variables, though this was rather an implementation -# oversight than an intended feature. The variable name stops at the first -# '}' or ')' and thus cannot use the usual form ${VARNAME} of long variable -# names. + +# The ':_' modifier takes a variable name as optional argument. Before var.c +# 1.867 from 2021-03-14, this variable name could refer to other variables, +# such as in 'VAR.$p'. It was not possible to refer to 'VAR.${param}' though, +# as that form caused a parse error. The cause for the parse error in +# '${...:_=VAR.${param}}' is that the variable name is parsed in an ad-hoc +# manner, stopping at the first ':', ')' or '}', without taking any nested +# expressions into account. Due to this inconsistency that short expressions +# are possible but long expressions aren't, the name of the temporary variable +# is no longer expanded. # -# Because of all these edge-casey conditions, this "feature" has been removed -# in var.c 1.867 from 2021-03-14. +# TODO: Warn about the unusual variable name '$S'. S= INDIRECT_VARNAME .if ${value:L:@var@${var:_=$S}@} != "value" . error @@ -32,4 +64,15 @@ S= INDIRECT_VARNAME . error .endif + +# When a variable using ':_' refers to another variable that also uses ':_', +# the value of the temporary variable '_' from the inner expression leaks into +# the evaluation of the outer expression. If the expressions were evaluated +# independently, the last word of the result would be outer_='outer' instead. +INNER= ${inner:L:_:@i@$i inner_='$_'@} +OUTER= ${outer:L:_:@o@$o ${INNER} outer_='$_'@} +.if ${OUTER} != "outer inner inner_='inner' outer_='inner'" +.endif + + all: diff --git a/contrib/bmake/unit-tests/varmod-subst-regex.mk b/contrib/bmake/unit-tests/varmod-subst-regex.mk index 197691d73aad..c1ffc4580d3a 100644 --- a/contrib/bmake/unit-tests/varmod-subst-regex.mk +++ b/contrib/bmake/unit-tests/varmod-subst-regex.mk @@ -1,4 +1,4 @@ -# $NetBSD: varmod-subst-regex.mk,v 1.7 2021/06/21 08:17:39 rillig Exp $ +# $NetBSD: varmod-subst-regex.mk,v 1.11 2023/12/18 11:13:51 rillig Exp $ # # Tests for the :C,from,to, variable modifier. @@ -10,7 +10,7 @@ all: mod-regex-limits all: mod-regex-errors all: unmatched-subexpression -# The variable expression expands to 4 words. Of these words, none matches +# The expression expands to 4 words. Of these words, none matches # the regular expression "a b" since these words don't contain any # whitespace. .if ${:Ua b b c:C,a b,,} != "a b b c" @@ -18,7 +18,7 @@ all: unmatched-subexpression .endif # Using the '1' modifier does not change anything. The '1' modifier just -# means to apply at most 1 replacement in the whole variable expression. +# means to apply at most 1 replacement in the whole expression. .if ${:Ua b b c:C,a b,,1} != "a b b c" . error .endif @@ -84,9 +84,54 @@ all: unmatched-subexpression . error .endif + +# Like the ':S' modifier, the ':C' modifier matches on an expression +# that contains no words at all, but only if the regular expression matches an +# empty string, for example, when the regular expression is anchored at the +# beginning or the end of the word. An unanchored regular expression that +# matches the empty string is uncommon in practice, as it would match before +# each character of the word. +.if "<${:U:S,,unanchored,}> <${:U:C,.?,unanchored,}>" != "<> <unanchored>" +. error +.endif +.if "<${:U:S,^,prefix,}> <${:U:C,^,prefix,}>" != "<prefix> <prefix>" +. error +.endif +.if "<${:U:S,$,suffix,}> <${:U:C,$,suffix,}>" != "<suffix> <suffix>" +. error +.endif +.if "<${:U:S,^$,whole,}> <${:U:C,^$,whole,}>" != "<whole> <whole>" +. error +.endif +.if "<${:U:S,,unanchored,g}> <${:U:C,.?,unanchored,g}>" != "<> <unanchored>" +. error +.endif +.if "<${:U:S,^,prefix,g}> <${:U:C,^,prefix,g}>" != "<prefix> <prefix>" +. error +.endif +.if "<${:U:S,$,suffix,g}> <${:U:C,$,suffix,g}>" != "<suffix> <suffix>" +. error +.endif +.if "<${:U:S,^$,whole,g}> <${:U:C,^$,whole,g}>" != "<whole> <whole>" +. error +.endif +.if "<${:U:S,,unanchored,W}> <${:U:C,.?,unanchored,W}>" != "<> <unanchored>" +. error +.endif +.if "<${:U:S,^,prefix,W}> <${:U:C,^,prefix,W}>" != "<prefix> <prefix>" +. error +.endif +.if "<${:U:S,$,suffix,W}> <${:U:C,$,suffix,W}>" != "<suffix> <suffix>" +. error +.endif +.if "<${:U:S,^$,whole,W}> <${:U:C,^$,whole,W}>" != "<whole> <whole>" +. error +.endif + + # Multiple asterisks form an invalid regular expression. This produces an # error message and (as of 2020-08-28) stops parsing in the middle of the -# variable expression. The unparsed part of the expression is then copied +# expression. The unparsed part of the expression is then copied # verbatim to the output, which is unexpected and can lead to strange shell # commands being run. mod-regex-compile-error: @@ -101,7 +146,7 @@ mod-regex-limits: @echo $@:22-missing:${:U1 23 456:C,(.).,\2\2,:Q} @echo $@:22-ok:${:U1 23 456:C,(.)(.),\2\2,:Q} # The :C modifier only handles single-digit capturing groups, - # which is more than enough for daily use. + # which is enough for all practical use cases. @echo $@:capture:${:UabcdefghijABCDEFGHIJrest:C,(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.),\9\8\7\6\5\4\3\2\1\0\10\11\12,} mod-regex-errors: @@ -109,7 +154,7 @@ mod-regex-errors: # If the replacement pattern produces a parse error because of an # unknown modifier, the parse error is ignored in ParseModifierPart - # and the faulty variable expression expands to "". + # and the faulty expression expands to "". @echo $@: ${word:L:C,.*,x${:U:Z}y,W} # In regular expressions with alternatives, not all capturing groups are diff --git a/contrib/bmake/unit-tests/varmod-subst.mk b/contrib/bmake/unit-tests/varmod-subst.mk index 763535ff835a..2903d36445f8 100644 --- a/contrib/bmake/unit-tests/varmod-subst.mk +++ b/contrib/bmake/unit-tests/varmod-subst.mk @@ -1,4 +1,4 @@ -# $NetBSD: varmod-subst.mk,v 1.9 2021/09/06 21:18:55 rillig Exp $ +# $NetBSD: varmod-subst.mk,v 1.14 2023/12/18 11:13:51 rillig Exp $ # # Tests for the :S,from,to, variable modifier. @@ -9,83 +9,118 @@ all: mod-subst-dollar WORDS= sequences of letters +# The empty pattern never matches anything, except if it is anchored at the +# beginning or the end of the word. .if ${WORDS:S,,,} != ${WORDS} -. warning The empty pattern matches something. +. error .endif +# The :S modifier flag '1' is applied exactly once. .if ${WORDS:S,e,*,1} != "s*quences of letters" -. warning The :S modifier flag '1' is not applied exactly once. +. error .endif +# The :S modifier flag '1' is applied to the first occurrence, no matter if +# the occurrence is in the first word or not. .if ${WORDS:S,f,*,1} != "sequences o* letters" -. warning The :S modifier flag '1' is only applied to the first word,\ - not to the first occurrence. +. error .endif +# The :S modifier replaces every first match per word. .if ${WORDS:S,e,*,} != "s*quences of l*tters" -. warning The :S modifier does not replace every first match per word. +. error .endif +# The :S modifier flag 'g' replaces every occurrence. .if ${WORDS:S,e,*,g} != "s*qu*nc*s of l*tt*rs" -. warning The :S modifier flag 'g' does not replace every occurrence. +. error .endif +# The '^' in the search pattern anchors the pattern at the beginning of each +# word, thereby matching a prefix. .if ${WORDS:S,^sequ,occurr,} != "occurrences of letters" -. warning The :S modifier fails for a short match anchored at the start. +. error .endif +# The :S modifier with a '^' anchor replaces the whole word if that word is +# exactly the pattern. .if ${WORDS:S,^of,with,} != "sequences with letters" -. warning The :S modifier fails for an exact match anchored at the start. +. error .endif +# The :S modifier does not match if the pattern is longer than the word. .if ${WORDS:S,^office,does not match,} != ${WORDS} -. warning The :S modifier matches a too long pattern anchored at the start. +. warning .endif +# The '$' in the search pattern anchors the pattern at the end of each word, +# thereby matching a suffix. .if ${WORDS:S,f$,r,} != "sequences or letters" -. warning The :S modifier fails for a short match anchored at the end. +. error .endif +# The :S modifier with a '$' anchor replaces at most one occurrence per word. .if ${WORDS:S,s$,,} != "sequence of letter" -. warning The :S modifier fails to replace one occurrence per word. +. error .endif +# The :S modifier with a '$' anchor replaces the whole word if that word is +# exactly the pattern. .if ${WORDS:S,of$,,} != "sequences letters" -. warning The :S modifier fails for an exact match anchored at the end. +. error .endif +# The :S modifier with a '$' anchor and a pattern that is longer than a word +# cannot match that word. .if ${WORDS:S,eof$,,} != ${WORDS} -. warning The :S modifier matches a too long pattern anchored at the end. +. warning .endif +# The :S modifier with the '^' and '$' anchors matches an exact word. .if ${WORDS:S,^of$,,} != "sequences letters" -. warning The :S modifier does not match a word anchored at both ends. +. error .endif +# The :S modifier with the '^' and '$' anchors does not match a word that +# starts with the pattern but is longer than the pattern. .if ${WORDS:S,^o$,,} != ${WORDS} -. warning The :S modifier matches a prefix anchored at both ends. +. error .endif +# The :S modifier with the '^' and '$' anchors does not match a word that ends +# with the pattern but is longer than the pattern. .if ${WORDS:S,^f$,,} != ${WORDS} -. warning The :S modifier matches a suffix anchored at both ends. +. error .endif +# The :S modifier with the '^' and '$' anchors does not match a word if the +# pattern ends with the word but is longer than the word. .if ${WORDS:S,^eof$,,} != ${WORDS} -. warning The :S modifier matches a too long prefix anchored at both ends. +. error .endif +# The :S modifier with the '^' and '$' anchors does not match a word if the +# pattern starts with the word but is longer than the word. .if ${WORDS:S,^office$,,} != ${WORDS} -. warning The :S modifier matches a too long suffix anchored at both ends. +. error .endif +# Except for the '^' and '$' anchors, the pattern does not contain any special +# characters, so the '*' from the pattern would only match a literal '*' in a +# word. .if ${WORDS:S,*,replacement,} != ${WORDS} -. error The '*' seems to be interpreted as a wildcard of some kind. +. error .endif +# Except for the '^' and '$' anchors, the pattern does not contain any special +# characters, so the '.' from the pattern would only match a literal '.' in a +# word. .if ${WORDS:S,.,replacement,} != ${WORDS} -. error The '.' seems to be interpreted as a wildcard of some kind. +. error .endif +# The '&' in the replacement is a placeholder for the text matched by the +# pattern. .if ${:Uvalue:S,^val,&,} != "value" . error .endif @@ -99,6 +134,55 @@ WORDS= sequences of letters . error .endif + +# When a word is replaced with nothing, the remaining words are separated by a +# single space, not two. +.if ${1 2 3:L:S,2,,} != "1 3" +. error +.endif + + +# In an empty expression, the ':S' modifier matches a single time, but only if +# the search string is empty and anchored at either the beginning or the end +# of the word. +.if ${:U:S,,out-of-nothing,} != "" +. error +.endif +.if ${:U:S,^,out-of-nothing,} != "out-of-nothing" +. error +.endif +.if ${:U:S,$,out-of-nothing,} != "out-of-nothing" +. error +.endif +.if ${:U:S,^$,out-of-nothing,} != "out-of-nothing" +. error +.endif +.if ${:U:S,,out-of-nothing,g} != "" +. error +.endif +.if ${:U:S,^,out-of-nothing,g} != "out-of-nothing" +. error +.endif +.if ${:U:S,$,out-of-nothing,g} != "out-of-nothing" +. error +.endif +.if ${:U:S,^$,out-of-nothing,g} != "out-of-nothing" +. error +.endif +.if ${:U:S,,out-of-nothing,W} != "" +. error +.endif +.if ${:U:S,^,out-of-nothing,W} != "out-of-nothing" +. error +.endif +.if ${:U:S,$,out-of-nothing,W} != "out-of-nothing" +. error +.endif +.if ${:U:S,^$,out-of-nothing,W} != "out-of-nothing" +. error +.endif + + mod-subst: @echo $@: @echo :${:Ua b b c:S,a b,,:Q}: diff --git a/contrib/bmake/unit-tests/varmod-sysv.exp b/contrib/bmake/unit-tests/varmod-sysv.exp index 59275857f98a..6a3728c3c0fc 100644 --- a/contrib/bmake/unit-tests/varmod-sysv.exp +++ b/contrib/bmake/unit-tests/varmod-sysv.exp @@ -1,5 +1,5 @@ make: Unfinished modifier for "word214" ('=' missing) -make: "varmod-sysv.mk" line 214: Malformed conditional (${word214:L:from${:D=}to}) +make: "varmod-sysv.mk" line 215: Malformed conditional (${word214:L:from${:D=}to}) word modifier result '' = "" suffix = "suffix" diff --git a/contrib/bmake/unit-tests/varmod-sysv.mk b/contrib/bmake/unit-tests/varmod-sysv.mk index 712c1731717b..0f92e1df7032 100644 --- a/contrib/bmake/unit-tests/varmod-sysv.mk +++ b/contrib/bmake/unit-tests/varmod-sysv.mk @@ -1,4 +1,4 @@ -# $NetBSD: varmod-sysv.mk,v 1.14 2021/04/12 16:09:57 rillig Exp $ +# $NetBSD: varmod-sysv.mk,v 1.16 2023/11/19 21:47:52 rillig Exp $ # # Tests for the variable modifier ':from=to', which replaces the suffix # "from" with "to". It can also use '%' as a wildcard. @@ -49,7 +49,7 @@ . error .endif -# In the modifier ':from=to', both parts can contain variable expressions. +# In the modifier ':from=to', both parts can contain expressions. .if ${one two:L:${:Uone}=${:U1}} != "1 two" . error .endif @@ -69,7 +69,7 @@ .endif # The replacement string can contain spaces, thereby changing the number -# of words in the variable expression. +# of words in the expression. .if ${In:L:%=% ${:Uthe Sun}} != "In the Sun" . error .endif @@ -206,11 +206,12 @@ . error .endif -# This is not a SysV modifier since the nested variable expression expands +# This is not a SysV modifier since the nested expression expands # to an empty string. The '=' in it should be irrelevant during parsing. # XXX: As of 2020-12-05, this expression generates an "Unfinished modifier" # error, while the correct error message would be "Unknown modifier" since # there is no modifier named "fromto". +# expect+1: Malformed conditional (${word214:L:from${:D=}to}) .if ${word214:L:from${:D=}to} . error .endif @@ -220,7 +221,7 @@ # "fromto}...". The next modifier is a SysV modifier. ApplyModifier_SysV # parses the modifier as "from${:D=}to", ending at the '}'. Next, the two # parts of the modifier are parsed using ParseModifierPart, which scans -# differently, properly handling nested variable expressions. The two parts +# differently, properly handling nested expressions. The two parts # are now "fromto}..." and "replaced". .if "${:Ufromto\}...:from${:D=}to}...=replaced}" != "replaced" . error diff --git a/contrib/bmake/unit-tests/varmod-to-abs.exp b/contrib/bmake/unit-tests/varmod-to-abs.exp index 426b4d39744f..4506d5ea8175 100644 --- a/contrib/bmake/unit-tests/varmod-to-abs.exp +++ b/contrib/bmake/unit-tests/varmod-to-abs.exp @@ -1,5 +1,5 @@ -make: "varmod-to-abs.mk" line 18: does-not-exist.c make: "varmod-to-abs.mk" line 19: does-not-exist.c +make: "varmod-to-abs.mk" line 21: does-not-exist.c cached_realpath: varmod-to-abs.mk -> varmod-to-abs.mk -make: "varmod-to-abs.mk" line 23: varmod-to-abs.mk +make: "varmod-to-abs.mk" line 26: varmod-to-abs.mk exit status 0 diff --git a/contrib/bmake/unit-tests/varmod-to-abs.mk b/contrib/bmake/unit-tests/varmod-to-abs.mk index 7f23318487e3..bc4722068988 100644 --- a/contrib/bmake/unit-tests/varmod-to-abs.mk +++ b/contrib/bmake/unit-tests/varmod-to-abs.mk @@ -1,4 +1,4 @@ -# $NetBSD: varmod-to-abs.mk,v 1.5 2020/11/15 05:48:17 rillig Exp $ +# $NetBSD: varmod-to-abs.mk,v 1.6 2023/06/01 20:56:35 rillig Exp $ # # Tests for the :tA variable modifier, which returns the absolute path for # each of the words in the variable value. @@ -15,11 +15,14 @@ # keeping the cache, just like the GNode for global variables. .MAKEFLAGS: -dd does-not-exist.c= /dev/null +# expect+1: does-not-exist.c .info ${does-not-exist.c:L:tA} +# expect+1: does-not-exist.c .info ${does-not-exist.c:L:tA} # The output of the following line is modified by the global _SED_CMDS in # unit-tests/Makefile. See the .rawout file for the truth. +# expect+1: varmod-to-abs.mk .info ${MAKEFILE:tA} .MAKEFLAGS: -d0 diff --git a/contrib/bmake/unit-tests/varmod-to-lower.mk b/contrib/bmake/unit-tests/varmod-to-lower.mk index 19d3406054b7..44116fd3eee2 100644 --- a/contrib/bmake/unit-tests/varmod-to-lower.mk +++ b/contrib/bmake/unit-tests/varmod-to-lower.mk @@ -1,7 +1,7 @@ -# $NetBSD: varmod-to-lower.mk,v 1.5 2020/11/15 20:20:58 rillig Exp $ +# $NetBSD: varmod-to-lower.mk,v 1.6 2022/11/29 23:54:55 rillig Exp $ # -# Tests for the :tl variable modifier, which returns the words in the -# variable value, converted to lowercase. +# Tests for the :tl variable modifier, which converts the expression value +# to lowercase. # # TODO: What about non-ASCII characters? ISO-8859-1, UTF-8? @@ -17,5 +17,10 @@ . error .endif -all: - @:; +# The ':tl' modifier works on the whole string, without splitting it into +# words. +.if ${:Umultiple spaces:tl} != "multiple spaces" +. error +.endif + +all: .PHONY diff --git a/contrib/bmake/unit-tests/varmod-to-separator.exp b/contrib/bmake/unit-tests/varmod-to-separator.exp index bfcfa3ebc103..a7d4ddb20147 100644 --- a/contrib/bmake/unit-tests/varmod-to-separator.exp +++ b/contrib/bmake/unit-tests/varmod-to-separator.exp @@ -1,25 +1,25 @@ -make: "varmod-to-separator.mk" line 153: Invalid character number at "400:tu}" -make: "varmod-to-separator.mk" line 153: Malformed conditional (${WORDS:[1..3]:ts\400:tu}) -make: "varmod-to-separator.mk" line 167: Invalid character number at "100:tu}" -make: "varmod-to-separator.mk" line 167: Malformed conditional (${WORDS:[1..3]:ts\x100:tu}) +make: "varmod-to-separator.mk" line 155: Invalid character number at "400:tu}" +make: "varmod-to-separator.mk" line 155: Malformed conditional (${WORDS:[1..3]:ts\400:tu}) +make: "varmod-to-separator.mk" line 171: Invalid character number at "100:tu}" +make: "varmod-to-separator.mk" line 171: Malformed conditional (${WORDS:[1..3]:ts\x100:tu}) make: Bad modifier ":ts\-300" for variable "WORDS" -make: "varmod-to-separator.mk" line 174: Malformed conditional (${WORDS:[1..3]:ts\-300:tu}) +make: "varmod-to-separator.mk" line 179: Malformed conditional (${WORDS:[1..3]:ts\-300:tu}) make: Bad modifier ":ts\8" for variable "1 2 3" -make: "varmod-to-separator.mk" line 182: Malformed conditional (${1 2 3:L:ts\8:tu}) +make: "varmod-to-separator.mk" line 188: Malformed conditional (${1 2 3:L:ts\8:tu}) make: Bad modifier ":ts\100L" for variable "1 2 3" -make: "varmod-to-separator.mk" line 189: Malformed conditional (${1 2 3:L:ts\100L}) +make: "varmod-to-separator.mk" line 196: Malformed conditional (${1 2 3:L:ts\100L}) make: Bad modifier ":ts\x40g" for variable "1 2 3" -make: "varmod-to-separator.mk" line 196: Malformed conditional (${1 2 3:L:ts\x40g}) +make: "varmod-to-separator.mk" line 204: Malformed conditional (${1 2 3:L:ts\x40g}) make: Bad modifier ":tx" for variable "WORDS" -make: "varmod-to-separator.mk" line 205: Malformed conditional (${WORDS:tx}) +make: "varmod-to-separator.mk" line 214: Malformed conditional (${WORDS:tx}) make: Bad modifier ":ts\X" for variable "WORDS" -make: "varmod-to-separator.mk" line 213: Malformed conditional (${WORDS:ts\X}) +make: "varmod-to-separator.mk" line 223: Malformed conditional (${WORDS:ts\X}) make: Bad modifier ":t\X" for variable "WORDS" -make: "varmod-to-separator.mk" line 221: Malformed conditional (${WORDS:t\X} != "anything") +make: "varmod-to-separator.mk" line 232: Malformed conditional (${WORDS:t\X} != "anything") make: Bad modifier ":ts\69" for variable "" -make: "varmod-to-separator.mk" line 237: Malformed conditional (${:Ua b:ts\69}) -make: "varmod-to-separator.mk" line 246: Invalid character number at "1F60E}" -make: "varmod-to-separator.mk" line 246: Malformed conditional (${:Ua b:ts\x1F60E}) +make: "varmod-to-separator.mk" line 249: Malformed conditional (${:Ua b:ts\69}) +make: "varmod-to-separator.mk" line 258: Invalid character number at "1F60E}" +make: "varmod-to-separator.mk" line 258: Malformed conditional (${:Ua b:ts\x1F60E}) make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/varmod-to-separator.mk b/contrib/bmake/unit-tests/varmod-to-separator.mk index bf960639f831..57a7bd84ec44 100644 --- a/contrib/bmake/unit-tests/varmod-to-separator.mk +++ b/contrib/bmake/unit-tests/varmod-to-separator.mk @@ -1,4 +1,4 @@ -# $NetBSD: varmod-to-separator.mk,v 1.11 2022/02/09 21:09:24 rillig Exp $ +# $NetBSD: varmod-to-separator.mk,v 1.13 2023/11/19 21:47:52 rillig Exp $ # # Tests for the :ts variable modifier, which joins the words of the variable # using an arbitrary character as word separator. @@ -39,7 +39,7 @@ WORDS= one two three four five six # quote though, or other special characters like dollar or backslash. # # This example also demonstrates that the closing brace is not interpreted -# as a separator, but as the closing delimiter of the whole variable +# as a separator, but as the closing delimiter of the whole # expression. .if ${WORDS:tu:ts} != "ONETWOTHREEFOURFIVESIX" . warning Colon as separator does not work. @@ -150,6 +150,8 @@ WORDS= one two three four five six # for an unsigned character though. # # Since 2020-11-01, these out-of-bounds values are rejected. +# expect+2: Invalid character number at "400:tu}" +# expect+1: Malformed conditional (${WORDS:[1..3]:ts\400:tu}) .if ${WORDS:[1..3]:ts\400:tu} . warning The separator \400 is accepted even though it is out of bounds. .else @@ -164,6 +166,8 @@ WORDS= one two three four five six # The hexadecimal number must be in the range of an unsigned char. # # Since 2020-11-01, these out-of-bounds values are rejected. +# expect+2: Invalid character number at "100:tu}" +# expect+1: Malformed conditional (${WORDS:[1..3]:ts\x100:tu}) .if ${WORDS:[1..3]:ts\x100:tu} . warning The separator \x100 is accepted even though it is out of bounds. .else @@ -171,6 +175,7 @@ WORDS= one two three four five six .endif # Negative numbers are not allowed for the separator character. +# expect+1: Malformed conditional (${WORDS:[1..3]:ts\-300:tu}) .if ${WORDS:[1..3]:ts\-300:tu} . warning The separator \-300 is accepted even though it is negative. .else @@ -179,6 +184,7 @@ WORDS= one two three four five six # The character number is interpreted as octal number by default. # The digit '8' is not an octal digit though. +# expect+1: Malformed conditional (${1 2 3:L:ts\8:tu}) .if ${1 2 3:L:ts\8:tu} . warning The separator \8 is accepted even though it is not octal. .else @@ -186,6 +192,7 @@ WORDS= one two three four five six .endif # Trailing characters after the octal character number are rejected. +# expect+1: Malformed conditional (${1 2 3:L:ts\100L}) .if ${1 2 3:L:ts\100L} . warning The separator \100L is accepted even though it contains an 'L'. .else @@ -193,6 +200,7 @@ WORDS= one two three four five six .endif # Trailing characters after the hexadecimal character number are rejected. +# expect+1: Malformed conditional (${1 2 3:L:ts\x40g}) .if ${1 2 3:L:ts\x40g} . warning The separator \x40g is accepted even though it contains a 'g'. .else @@ -202,6 +210,7 @@ WORDS= one two three four five six # In the :t modifier, the :t must be followed by any of A, l, s, u. # expect: make: Bad modifier ":tx" for variable "WORDS" +# expect+1: Malformed conditional (${WORDS:tx}) .if ${WORDS:tx} . error .else @@ -210,6 +219,7 @@ WORDS= one two three four five six # The word separator can only be a single character. # expect: make: Bad modifier ":ts\X" for variable "WORDS" +# expect+1: Malformed conditional (${WORDS:ts\X}) .if ${WORDS:ts\X} . error .else @@ -218,6 +228,7 @@ WORDS= one two three four five six # After the backslash, only n, t, an octal number, or x and a hexadecimal # number are allowed. +# expect+1: Malformed conditional (${WORDS:t\X} != "anything") .if ${WORDS:t\X} != "anything" . info This line is not reached. .endif @@ -234,6 +245,7 @@ WORDS= one two three four five six # 2016.02.27.16.20.06, the result was '1E2', since 2016.03.07.20.20.35 make no # longer accepts this escape and complains. # expect: make: Bad modifier ":ts\69" for variable "" +# expect+1: Malformed conditional (${:Ua b:ts\69}) .if ${:Ua b:ts\69} . error .else diff --git a/contrib/bmake/unit-tests/varmod-undefined.mk b/contrib/bmake/unit-tests/varmod-undefined.mk index e06fc73244ab..fd56ffd35e30 100644 --- a/contrib/bmake/unit-tests/varmod-undefined.mk +++ b/contrib/bmake/unit-tests/varmod-undefined.mk @@ -1,4 +1,4 @@ -# $NetBSD: varmod-undefined.mk,v 1.7 2020/11/15 20:20:58 rillig Exp $ +# $NetBSD: varmod-undefined.mk,v 1.9 2023/11/19 21:47:52 rillig Exp $ # # Tests for the :U variable modifier, which returns the given string # if the variable is undefined. @@ -19,17 +19,17 @@ .endif # .endfor -# The variable expressions in the text of the :U modifier may be arbitrarily +# The expressions in the text of the :U modifier may be arbitrarily # nested. .if ${:U${:Unested}${${${:Udeeply}}}} != nested . error .endif -# The nested variable expressions may contain braces, and these braces don't +# The nested expressions may contain braces, and these braces don't # need to match pairwise. In the following example, the :S modifier uses '{' # as delimiter, which confuses both editors and humans because the opening -# and # closing braces don't match anymore. It's syntactically valid though. +# and closing braces don't match anymore. It's syntactically valid though. # For more similar examples, see varmod-subst.mk, mod-subst-delimiter. .if ${:U${:Uvalue:S{a{X{}} != vXlue diff --git a/contrib/bmake/unit-tests/varmod.exp b/contrib/bmake/unit-tests/varmod.exp index e36c4ded9b47..9ba0cb1d278b 100644 --- a/contrib/bmake/unit-tests/varmod.exp +++ b/contrib/bmake/unit-tests/varmod.exp @@ -1,8 +1,8 @@ -make: "varmod.mk" line 42: To escape a dollar, use \$, not $$, at "$$:L} != """ -make: "varmod.mk" line 42: Invalid variable name ':', at "$:L} != """ -make: "varmod.mk" line 47: Dollar followed by nothing -make: "varmod.mk" line 56: Missing delimiter ':' after modifier "P" -make: "varmod.mk" line 57: Missing argument for ".error" +make: "varmod.mk" line 101: To escape a dollar, use \$, not $$, at "$$:L} != """ +make: "varmod.mk" line 101: Invalid variable name ':', at "$:L} != """ +make: "varmod.mk" line 107: Dollar followed by nothing +make: "varmod.mk" line 117: Missing delimiter ':' after modifier "P" +make: "varmod.mk" line 119: Missing argument for ".error" make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/varmod.mk b/contrib/bmake/unit-tests/varmod.mk index 21ddf9103251..45707ab9b886 100644 --- a/contrib/bmake/unit-tests/varmod.mk +++ b/contrib/bmake/unit-tests/varmod.mk @@ -1,11 +1,68 @@ -# $NetBSD: varmod.mk,v 1.5 2020/12/19 22:33:11 rillig Exp $ +# $NetBSD: varmod.mk,v 1.10 2024/02/03 00:20:23 sjg Exp $ # # Tests for variable modifiers, such as :Q, :S,from,to or :Ufallback. +# +# See also: +# varparse-errors.mk + +# As of 2022-08-06, the possible behaviors during parsing are: +# +# * `strict`: the parsing style used by most modifiers: +# * either uses `ParseModifierPart` or parses the modifier literal +# * other modifiers may follow, separated by a ':' +# +# * `greedy`: calls `ParseModifierPart` with `ch->endc`; this means +# that no further modifiers are parsed in that expression. +# +# * `no-colon`: after parsing this modifier, the following modifier +# does not need to be separated by a colon. +# Omitting this colon is bad style. +# +# * `individual`: parsing this modifier does not follow the common +# pattern of calling `ParseModifierPart`. +# +# The SysV column says whether a parse error in the modifier falls back +# trying the `:from=to` System V modifier. +# +# | **Operator** | **Behavior** | **Remarks** | **SysV** | +# |--------------|--------------|--------------------|----------| +# | `!` | no-colon | | no | +# | `:=` | greedy | | yes | +# | `?:` | greedy | | no | +# | `@` | no-colon | | no | +# | `C` | no-colon | | no | +# | `D` | individual | custom parser | N/A | +# | `E` | strict | | yes | +# | `H` | strict | | yes | +# | `L` | no-colon | | N/A | +# | `M` | individual | custom parser | N/A | +# | `N` | individual | custom parser | N/A | +# | `O` | strict | only literal value | no | +# | `P` | no-colon | | N/A | +# | `Q` | strict | | yes | +# | `R` | strict | | yes | +# | `S` | no-colon | | N/A | +# | `T` | strict | | N/A | +# | `U` | individual | custom parser | N/A | +# | `[` | strict | | no | +# | `_` | individual | strcspn | yes | +# | `gmtime` | strict | only literal value | yes | +# | `hash` | strict | | N/A | +# | `localtime` | strict | only literal value | yes | +# | `q` | strict | | yes | +# | `range` | strict | | N/A | +# | `sh` | strict | | N/A | +# | `t` | strict | | no | +# | `u` | strict | | yes | +# | `from=to` | greedy | SysV, fallback | N/A | + +# These tests assume +.MAKE.SAVE_DOLLARS = yes DOLLAR1= $$ DOLLAR2= ${:U\$} -# To get a single '$' sign in the value of a variable expression, it has to +# To get a single '$' sign in the value of an expression, it has to # be written as '$$' in a literal variable value. # # See Var_Parse, where it calls Var_Subst. @@ -39,21 +96,26 @@ DOLLAR2= ${:U\$} # For compatibility, make does not print these error messages in normal mode. # Should it? .MAKEFLAGS: -dL +# expect+2: To escape a dollar, use \$, not $$, at "$$:L} != """ +# expect+1: Invalid variable name ':', at "$:L} != """ .if ${$$:L} != "" . error .endif # A '$' followed by nothing is an error as well. +# expect+1: Dollar followed by nothing .if ${:Uword:@word@${word}$@} != "word" . error .endif # The variable modifier :P does not fall back to the SysV modifier. # Therefore the modifier :P=RE generates a parse error. -# XXX: The .error should not be reached since the variable expression is +# XXX: The .error should not be reached since the expression is # malformed, and this error should be propagated up to Cond_EvalLine. VAR= STOP +# expect+1: Missing delimiter ':' after modifier "P" .if ${VAR:P=RE} != "STORE" +# expect+1: Missing argument for ".error" . error .endif diff --git a/contrib/bmake/unit-tests/varname-dollar.exp b/contrib/bmake/unit-tests/varname-dollar.exp index c880e82f0170..4f7c2ebbdf12 100644 --- a/contrib/bmake/unit-tests/varname-dollar.exp +++ b/contrib/bmake/unit-tests/varname-dollar.exp @@ -1,5 +1,5 @@ -make: "varname-dollar.mk" line 16: dollar is $. -make: "varname-dollar.mk" line 17: dollar in braces is . -make: "varname-dollar.mk" line 25: dollar is $. -make: "varname-dollar.mk" line 26: dollar in braces is dollar. +make: "varname-dollar.mk" line 17: dollar is $. +make: "varname-dollar.mk" line 19: dollar in braces is . +make: "varname-dollar.mk" line 28: dollar is $. +make: "varname-dollar.mk" line 30: dollar in braces is dollar. exit status 0 diff --git a/contrib/bmake/unit-tests/varname-dollar.mk b/contrib/bmake/unit-tests/varname-dollar.mk index d1db9f833306..e60c9dd43e8f 100644 --- a/contrib/bmake/unit-tests/varname-dollar.mk +++ b/contrib/bmake/unit-tests/varname-dollar.mk @@ -1,4 +1,4 @@ -# $NetBSD: varname-dollar.mk,v 1.3 2020/08/19 05:40:06 rillig Exp $ +# $NetBSD: varname-dollar.mk,v 1.4 2023/06/01 20:56:35 rillig Exp $ # # Tests for the expression "$$", which looks as if it referred to a variable, # but simply expands to a single '$' sign. @@ -13,7 +13,9 @@ DOLLAR= $$ # At this point, the variable '$' is not defined. Therefore the second line # returns an empty string. +# expect+1: dollar is $. .info dollar is $$. +# expect+1: dollar in braces is . .info dollar in braces is ${${DOLLAR}}. # Now overwrite the '$' variable to see whether '$$' really expands to that @@ -22,7 +24,9 @@ ${DOLLAR}= dollar # At this point, the variable '$' is defined, therefore its value is printed # in the second .info directive. +# expect+1: dollar is $. .info dollar is $$. +# expect+1: dollar in braces is dollar. .info dollar in braces is ${${DOLLAR}}. all: diff --git a/contrib/bmake/unit-tests/varname-dot-make-jobs.exp b/contrib/bmake/unit-tests/varname-dot-make-jobs.exp index 1308f9116240..a899c5d38418 100644 --- a/contrib/bmake/unit-tests/varname-dot-make-jobs.exp +++ b/contrib/bmake/unit-tests/varname-dot-make-jobs.exp @@ -4,5 +4,5 @@ undefined 5 --- echo --- 20 -00000000000000000000000000000001 +1 exit status 0 diff --git a/contrib/bmake/unit-tests/varname-dot-make-jobs.mk b/contrib/bmake/unit-tests/varname-dot-make-jobs.mk index af5eebfe7498..5ed62c180eed 100644 --- a/contrib/bmake/unit-tests/varname-dot-make-jobs.mk +++ b/contrib/bmake/unit-tests/varname-dot-make-jobs.mk @@ -1,4 +1,4 @@ -# $NetBSD: varname-dot-make-jobs.mk,v 1.3 2022/01/26 22:47:03 rillig Exp $ +# $NetBSD: varname-dot-make-jobs.mk,v 1.5 2023/09/10 16:25:32 sjg Exp $ # # Tests for the special .MAKE.JOBS variable, which is defined in jobs mode # only. There it contains the number of jobs that may run in parallel. @@ -15,10 +15,29 @@ all: @${MAKE} -r -f ${MAKEFILE} echo -j20 @${MAKE} -r -f ${MAKEFILE} echo -j00000000000000000000000000000001 +.if !make(echo) && ${.MAKE.JOBS.C} == "yes" +# These results will not be static, we need NCPU +# to compute expected results. +all: jC + +NCPU!= ${MAKE} -r -f /dev/null -jC -V .MAKE.JOBS + +# If -j arg is floating point or ends in C; +# .MAKE.JOBS is a multiple of _SC_NPROCESSORS_ONLN +# No news is good news here. +jCvals ?= 1 1.2 2 + +jC: + @for j in ${jCvals}; do \ + e=`echo "${NCPU} * $$j" | bc | sed 's/\.[0-9]*//'`; \ + g=`${MAKE} -r -f /dev/null -V .MAKE.JOBS -j$${j}C`; \ + test $$g = $$e || echo "$$g != $$e"; \ + done + +.endif + # expect: undefined # expect: 1 # expect: 5 # expect: 20 -# The value of .MAKE.JOBS is the exact text given in the command line, not the -# canonical number. This doesn't have practical consequences though. -# expect: 00000000000000000000000000000001 +# expect: 1 diff --git a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_filter.exp b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_filter.exp index 39a9383953dd..045d26dc080e 100644 --- a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_filter.exp +++ b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_filter.exp @@ -1 +1,11 @@ +Initialize check-ignore.meta +Building <tmpdir>/obj/check-ignore +Skipping meta for .END: .SPECIAL +Use .MAKE.META.IGNORE_FILTER - check-ignore is up to date +`check-ignore' is up to date. +Skipping meta for .END: .SPECIAL +Skip .MAKE.META.IGNORE_FILTER - check-ignore is out of date +<tmpdir>/obj/check-ignore.meta: <line>: file '<tmpdir>/ignore/check' is newer than the target... +Building <tmpdir>/obj/check-ignore +Skipping meta for .END: .SPECIAL exit status 0 diff --git a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_filter.mk b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_filter.mk index c41aec4acdf8..0adf6a202857 100644 --- a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_filter.mk +++ b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_filter.mk @@ -1,8 +1,5 @@ -# $NetBSD: varname-dot-make-meta-ignore_filter.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $ +# $NetBSD: varname-dot-make-meta-ignore_filter.mk,v 1.3 2023/02/23 05:20:45 sjg Exp $ # # Tests for the special .MAKE.META.IGNORE_FILTER variable. -# TODO: Implementation - -all: - @:; +.include "meta-ignore.inc" diff --git a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_paths.exp b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_paths.exp index 39a9383953dd..161d09c2eff4 100644 --- a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_paths.exp +++ b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_paths.exp @@ -1 +1,11 @@ +Initialize check-ignore.meta +Building <tmpdir>/obj/check-ignore +Skipping meta for .END: .SPECIAL +Use .MAKE.META.IGNORE_PATHS - check-ignore is up to date +`check-ignore' is up to date. +Skipping meta for .END: .SPECIAL +Skip .MAKE.META.IGNORE_PATHS - check-ignore is out of date +<tmpdir>/obj/check-ignore.meta: <line>: file '<tmpdir>/ignore/check' is newer than the target... +Building <tmpdir>/obj/check-ignore +Skipping meta for .END: .SPECIAL exit status 0 diff --git a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_paths.mk b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_paths.mk index 4ae34f51608b..2c58849af0be 100644 --- a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_paths.mk +++ b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_paths.mk @@ -1,8 +1,5 @@ -# $NetBSD: varname-dot-make-meta-ignore_paths.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $ +# $NetBSD: varname-dot-make-meta-ignore_paths.mk,v 1.3 2023/02/23 05:20:45 sjg Exp $ # # Tests for the special .MAKE.META.IGNORE_PATHS variable. -# TODO: Implementation - -all: - @:; +.include "meta-ignore.inc" diff --git a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_patterns.exp b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_patterns.exp index 39a9383953dd..ebc1c0c6261c 100644 --- a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_patterns.exp +++ b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_patterns.exp @@ -1 +1,11 @@ +Initialize check-ignore.meta +Building <tmpdir>/obj/check-ignore +Skipping meta for .END: .SPECIAL +Use .MAKE.META.IGNORE_PATTERNS - check-ignore is up to date +`check-ignore' is up to date. +Skipping meta for .END: .SPECIAL +Skip .MAKE.META.IGNORE_PATTERNS - check-ignore is out of date +<tmpdir>/obj/check-ignore.meta: <line>: file '<tmpdir>/ignore/check' is newer than the target... +Building <tmpdir>/obj/check-ignore +Skipping meta for .END: .SPECIAL exit status 0 diff --git a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_patterns.mk b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_patterns.mk index ea9fc49f1718..d3d6e065857d 100644 --- a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_patterns.mk +++ b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_patterns.mk @@ -1,8 +1,5 @@ -# $NetBSD: varname-dot-make-meta-ignore_patterns.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $ +# $NetBSD: varname-dot-make-meta-ignore_patterns.mk,v 1.3 2023/02/23 05:20:45 sjg Exp $ # # Tests for the special .MAKE.META.IGNORE_PATTERNS variable. -# TODO: Implementation - -all: - @:; +.include "meta-ignore.inc" diff --git a/contrib/bmake/unit-tests/varname-dot-make-mode.exp b/contrib/bmake/unit-tests/varname-dot-make-mode.exp index 39a9383953dd..fa033e718b0c 100644 --- a/contrib/bmake/unit-tests/varname-dot-make-mode.exp +++ b/contrib/bmake/unit-tests/varname-dot-make-mode.exp @@ -1 +1,31 @@ +randomize compat mode: +: Making a +: Making a +: Making a +: Making b +: Making b +: Making b +: Making c +: Making c +: Making c +randomize jobs mode (-j1): +: Making a +: Making a +: Making a +: Making b +: Making b +: Making b +: Making c +: Making c +: Making c +randomize jobs mode (-j5): +: Making a +: Making a +: Making a +: Making b +: Making b +: Making b +: Making c +: Making c +: Making c exit status 0 diff --git a/contrib/bmake/unit-tests/varname-dot-make-mode.mk b/contrib/bmake/unit-tests/varname-dot-make-mode.mk index ee75a54ebd74..169aa17cdc36 100644 --- a/contrib/bmake/unit-tests/varname-dot-make-mode.mk +++ b/contrib/bmake/unit-tests/varname-dot-make-mode.mk @@ -1,8 +1,41 @@ -# $NetBSD: varname-dot-make-mode.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $ +# $NetBSD: varname-dot-make-mode.mk,v 1.3 2022/05/07 17:49:47 rillig Exp $ # # Tests for the special .MAKE.MODE variable. -# TODO: Implementation +# TODO: test .MAKE.MODE "meta", or see meta mode tests. +# TODO: test .MAKE.MODE "compat" -all: - @:; + +# See Makefile, POSTPROC for the postprocessing that takes place. +# See the .rawout file for the raw output before stripping the digits. +all: .PHONY make-mode-randomize-targets + + +# By adding the word "randomize-targets" to the variable .MAKE.MODE, the +# targets are not made in declaration order, but rather in random order. This +# mode helps to find undeclared dependencies between files. +# +# History +# Added on 2022-05-07. +# +# See also +# https://gnats.netbsd.org/45226 +make-mode-randomize-targets: .PHONY + @echo "randomize compat mode:" + @${MAKE} -r -f ${MAKEFILE} randomize-targets + + @echo "randomize jobs mode (-j1):" + @${MAKE} -r -f ${MAKEFILE} -j1 randomize-targets + + @echo "randomize jobs mode (-j5):" + @${MAKE} -r -f ${MAKEFILE} -j5 randomize-targets | grep '^:' + +.if make(randomize-targets) +randomize-targets: .WAIT a1 a2 a3 .WAIT b1 b2 b3 .WAIT c1 c2 c3 .WAIT +a1 a2 a3 b1 b2 b3 c1 c2 c3: + : Making ${.TARGET} + +# .MAKE.MODE is evaluated after parsing all files, so it suffices to switch +# the mode after defining the targets. +.MAKE.MODE+= randomize-targets +.endif diff --git a/contrib/bmake/unit-tests/varname-dot-makeflags.exp b/contrib/bmake/unit-tests/varname-dot-makeflags.exp index dbf96469f86b..8004ab40a363 100644 --- a/contrib/bmake/unit-tests/varname-dot-makeflags.exp +++ b/contrib/bmake/unit-tests/varname-dot-makeflags.exp @@ -1,3 +1,10 @@ -echo "$MAKEFLAGS" - -r -k -d 00000 -D VARNAME WITH SPACES +make: "varname-dot-makeflags.mk" line 11: MAKEFLAGS=<undefined> +make: "varname-dot-makeflags.mk" line 13: .MAKEFLAGS=< -r -k> +make: "varname-dot-makeflags.mk" line 15: .MAKEOVERRIDES=<> +make: "varname-dot-makeflags.mk" line 21: MAKEFLAGS=<undefined> +make: "varname-dot-makeflags.mk" line 23: .MAKEFLAGS=< -r -k -D VARNAME -r> +make: "varname-dot-makeflags.mk" line 25: .MAKEOVERRIDES=< VAR> +runtime: MAKEFLAGS=< -r -k -D VARNAME -r VAR=value> +runtime: .MAKEFLAGS=< -r -k -D VARNAME -r> +runtime: .MAKEOVERRIDES=< VAR> exit status 0 diff --git a/contrib/bmake/unit-tests/varname-dot-makeflags.mk b/contrib/bmake/unit-tests/varname-dot-makeflags.mk index 10d1903022cb..ffb09decb70e 100644 --- a/contrib/bmake/unit-tests/varname-dot-makeflags.mk +++ b/contrib/bmake/unit-tests/varname-dot-makeflags.mk @@ -1,15 +1,39 @@ -# $NetBSD: varname-dot-makeflags.mk,v 1.1 2020/12/01 20:37:30 rillig Exp $ +# $NetBSD: varname-dot-makeflags.mk,v 1.8 2023/06/01 20:56:35 rillig Exp $ # # Tests for the special .MAKEFLAGS variable, which collects almost all # command line arguments and passes them on to any child processes via # the environment variable MAKEFLAGS (without leading '.'). +# +# See also: +# varname-dot-makeoverrides.mk + +# expect+1: MAKEFLAGS=<undefined> +.info MAKEFLAGS=<${MAKEFLAGS:Uundefined}> +# expect+1: .MAKEFLAGS=< -r -k> +.info .MAKEFLAGS=<${.MAKEFLAGS}> +# expect+1: .MAKEOVERRIDES=<> +.info .MAKEOVERRIDES=<${.MAKEOVERRIDES:Uundefined}> + +# Append an option with argument, a plain option and a variable assignment. +.MAKEFLAGS: -DVARNAME -r VAR=value + +# expect+1: MAKEFLAGS=<undefined> +.info MAKEFLAGS=<${MAKEFLAGS:Uundefined}> +# expect+1: .MAKEFLAGS=< -r -k -D VARNAME -r> +.info .MAKEFLAGS=<${.MAKEFLAGS}> +# expect+1: .MAKEOVERRIDES=< VAR> +.info .MAKEOVERRIDES=<${.MAKEOVERRIDES}> -# When options are parsed, the option and its argument are appended as -# separate words to .MAKEFLAGS. Special characters in the option argument -# are not quoted though. It seems to have not been necessary at least from -# 1993 until 2020. -.MAKEFLAGS: -d00000 -D"VARNAME WITH SPACES" +# The environment variable 'MAKEFLAGS' is not available to child processes +# when parsing the makefiles. This is different from exported variables, +# which are already available during parse time. +.if ${:!echo "\${MAKEFLAGS-undef}"!} != "undef" +. error +.endif -all: - echo "$$MAKEFLAGS" - @:; +# After parsing, the environment variable 'MAKEFLAGS' is set based on the +# special variables '.MAKEFLAGS' and '.MAKEOVERRIDES'. +runtime: + @echo '$@: MAKEFLAGS=<'${MAKEFLAGS:Q}'>' + @echo '$@: .MAKEFLAGS=<'${.MAKEFLAGS:Q}'>' + @echo '$@: .MAKEOVERRIDES=<'${.MAKEOVERRIDES:Q}'>' diff --git a/contrib/bmake/unit-tests/varname-dot-makeoverrides.exp b/contrib/bmake/unit-tests/varname-dot-makeoverrides.exp index 39a9383953dd..78c0296f8d76 100644 --- a/contrib/bmake/unit-tests/varname-dot-makeoverrides.exp +++ b/contrib/bmake/unit-tests/varname-dot-makeoverrides.exp @@ -1 +1,8 @@ +all: overrides=<> +make -f varname-dot-makeoverrides.mk stage_1 VAR=value +stage_1: overrides=< VAR> +make -f varname-dot-makeoverrides.mk stage_2 +stage_2: overrides=< VAR> +make -f varname-dot-makeoverrides.mk stage_3 +stage_3: overrides=< VAR> exit status 0 diff --git a/contrib/bmake/unit-tests/varname-dot-makeoverrides.mk b/contrib/bmake/unit-tests/varname-dot-makeoverrides.mk index a897f4667175..f3f3897f8aa4 100644 --- a/contrib/bmake/unit-tests/varname-dot-makeoverrides.mk +++ b/contrib/bmake/unit-tests/varname-dot-makeoverrides.mk @@ -1,8 +1,23 @@ -# $NetBSD: varname-dot-makeoverrides.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $ +# $NetBSD: varname-dot-makeoverrides.mk,v 1.5 2023/02/25 06:54:08 rillig Exp $ # -# Tests for the special .MAKE.MAKEOVERRIDES variable. - -# TODO: Implementation +# Tests for the special .MAKEOVERRIDES variable, which lists the names of the +# variables that are passed on to child processes via the MAKEFLAGS +# environment variable. +# +# See also: +# varname-dot-makeflags.mk all: - @:; + @echo '$@: overrides=<'${.MAKEOVERRIDES:Uundefined:Q}'>' + ${MAKE} -f ${MAKEFILE} stage_1 VAR=value + +stage_1: + @echo '$@: overrides=<'${.MAKEOVERRIDES:Q}'>' + ${MAKE} -f ${MAKEFILE} stage_2 + +stage_2: + @echo '$@: overrides=<'${.MAKEOVERRIDES:Q}'>' + ${MAKE} -f ${MAKEFILE} stage_3 + +stage_3: + @echo '$@: overrides=<'${.MAKEOVERRIDES:Q}'>' diff --git a/contrib/bmake/unit-tests/varname-dot-newline.exp b/contrib/bmake/unit-tests/varname-dot-newline.exp index 13943539bf3b..684fb5799752 100644 --- a/contrib/bmake/unit-tests/varname-dot-newline.exp +++ b/contrib/bmake/unit-tests/varname-dot-newline.exp @@ -1,4 +1,5 @@ -make: "varname-dot-newline.mk" line 16: The .newline variable can be overwritten. Just don't do that. first second +backslash newline: <\ +> exit status 0 diff --git a/contrib/bmake/unit-tests/varname-dot-newline.mk b/contrib/bmake/unit-tests/varname-dot-newline.mk index 0565d244f298..1940dc2a990d 100644 --- a/contrib/bmake/unit-tests/varname-dot-newline.mk +++ b/contrib/bmake/unit-tests/varname-dot-newline.mk @@ -1,23 +1,31 @@ -# $NetBSD: varname-dot-newline.mk,v 1.4 2020/10/24 08:46:08 rillig Exp $ +# $NetBSD: varname-dot-newline.mk,v 1.6 2023/01/26 20:48:18 sjg Exp $ # -# Tests for the special .newline variable. +# Tests for the special .newline variable, which contains a single newline +# character (U+000A). + + +# https://austingroupbugs.net/view.php?id=1549 proposes: +# > After all macro expansion is complete, when an escaped <newline> is +# > found in a command line in a makefile, the command line that is executed +# > shall contain the <backslash>, the <newline>, and the next line, except +# > that the first character of the next line shall not be included if it is +# > a <tab>. # -# Contrary to the special variable named "" that is used in expressions like -# ${:Usome-value}, the variable ".newline" is not protected against -# modification. Nobody exploits that though. +# The above quote assumes that each resulting <newline> character has a "next +# line", but that's not how the .newline variable works. +BACKSLASH_NEWLINE:= \${.newline} + + +# Check that .newline is read-only NEWLINE:= ${.newline} .newline= overwritten -.if ${.newline} == ${NEWLINE} -. info The .newline variable cannot be overwritten. Good. -.else -. info The .newline variable can be overwritten. Just don't do that. +.if ${.newline} != ${NEWLINE} +. error The .newline variable can be overwritten. It should be read-only. .endif -# Restore the original value. -.newline= ${NEWLINE} - all: @echo 'first${.newline}second' + @echo 'backslash newline: <${BACKSLASH_NEWLINE}>' diff --git a/contrib/bmake/unit-tests/varname-dot-parsedir.exp b/contrib/bmake/unit-tests/varname-dot-parsedir.exp index c0bc56f41d6e..4ac953c813cd 100644 --- a/contrib/bmake/unit-tests/varname-dot-parsedir.exp +++ b/contrib/bmake/unit-tests/varname-dot-parsedir.exp @@ -1,5 +1,5 @@ -make: "varname-dot-parsedir.mk" line 28: At this point, .PARSEDIR is undefined. -make: "<normalized>" line 34: The location can be faked in some cases. -make: "varname-dot-parsedir.mk" line 38: The location is no longer fake. +make: "varname-dot-parsedir.mk" line 37: At this point, .PARSEDIR is undefined. +make: "<normalized>" line 43: The location can be faked in some cases. +make: "varname-dot-parsedir.mk" line 48: The location is no longer fake. At run time, .PARSEDIR is undefined. exit status 0 diff --git a/contrib/bmake/unit-tests/varname-dot-parsedir.mk b/contrib/bmake/unit-tests/varname-dot-parsedir.mk index 7c74419ddd10..525fdbd5636f 100644 --- a/contrib/bmake/unit-tests/varname-dot-parsedir.mk +++ b/contrib/bmake/unit-tests/varname-dot-parsedir.mk @@ -1,7 +1,15 @@ -# $NetBSD: varname-dot-parsedir.mk,v 1.6 2020/10/24 08:50:17 rillig Exp $ +# $NetBSD: varname-dot-parsedir.mk,v 1.8 2023/06/21 07:30:50 rillig Exp $ # # Tests for the special .PARSEDIR variable, which contains the directory part # of the file that is currently parsed. +# +# See also +# varname-dot-includedfromdir.mk +# varname-dot-includedfromfile.mk +# varname-dot-parsefile.mk +# +# History +# .PARSEDIR and .PARSEFILE were added on 1999-08-09. # The .PARSEDIR may be absolute or relative, therefore there is not much that # can be tested here. @@ -25,6 +33,7 @@ # # The .rawout file contains the full path to the current directory. # In the .out file, it is filtered out. +# expect+1: At this point, .PARSEDIR is undefined. .info At this point, .PARSEDIR is undefined. # There is absolutely no point in faking the location of the file that is @@ -35,6 +44,7 @@ # After including another file, .PARSEDIR is reset. .include "/dev/null" +# expect+1: The location is no longer fake. .info The location is no longer fake. all: diff --git a/contrib/bmake/unit-tests/varname-dot-parsefile.exp b/contrib/bmake/unit-tests/varname-dot-parsefile.exp index b61f01c01ab7..651666ebcf24 100644 --- a/contrib/bmake/unit-tests/varname-dot-parsefile.exp +++ b/contrib/bmake/unit-tests/varname-dot-parsefile.exp @@ -1,5 +1,5 @@ -make: "varname-dot-parsefile.mk" line 23: At this point, .PARSEFILE is undefined. -make: "<normalized>" line 29: The location can be faked in some cases. -make: "varname-dot-parsefile.mk" line 33: The location is no longer fake. +make: "varname-dot-parsefile.mk" line 32: At this point, .PARSEFILE is undefined. +make: "<normalized>" line 38: The location can be faked in some cases. +make: "varname-dot-parsefile.mk" line 43: The location is no longer fake. At run time, .PARSEFILE is undefined. exit status 0 diff --git a/contrib/bmake/unit-tests/varname-dot-parsefile.mk b/contrib/bmake/unit-tests/varname-dot-parsefile.mk index 17b48a5f77ec..0a6ed3c378e0 100644 --- a/contrib/bmake/unit-tests/varname-dot-parsefile.mk +++ b/contrib/bmake/unit-tests/varname-dot-parsefile.mk @@ -1,7 +1,15 @@ -# $NetBSD: varname-dot-parsefile.mk,v 1.5 2020/10/24 08:50:17 rillig Exp $ +# $NetBSD: varname-dot-parsefile.mk,v 1.7 2023/06/21 07:30:50 rillig Exp $ # # Tests for the special .PARSEFILE variable, which contains the basename part # of the file that is currently parsed. +# +# See also +# varname-dot-includedfromdir.mk +# varname-dot-includedfromfile.mk +# varname-dot-parsedir.mk +# +# History +# .PARSEDIR and .PARSEFILE were added on 1999-08-09. .if ${.PARSEFILE} != "varname-dot-parsefile.mk" . error @@ -20,6 +28,7 @@ # The variable .PARSEFILE is indirectly used by the .info directive, # via PrintLocation. +# expect+1: At this point, .PARSEFILE is undefined. .info At this point, .PARSEFILE is undefined. # There is absolutely no point in faking the location of the file that is @@ -30,6 +39,7 @@ # After including another file, .PARSEFILE is reset. .include "/dev/null" +# expect+1: The location is no longer fake. .info The location is no longer fake. all: diff --git a/contrib/bmake/unit-tests/varname-dot-shell.exp b/contrib/bmake/unit-tests/varname-dot-shell.exp index 800e8a375761..22c2afe218a9 100755 --- a/contrib/bmake/unit-tests/varname-dot-shell.exp +++ b/contrib/bmake/unit-tests/varname-dot-shell.exp @@ -1,26 +1,26 @@ Parsing line 10: ORIG_SHELL:= ${.SHELL} Global: ORIG_SHELL = # (empty) Var_Parse: ${.SHELL} (eval-keep-dollar-and-undefined) -Global: delete .SHELL (not found) +Global: ignoring delete '.SHELL' as it is not found Command: .SHELL = (details omitted) Global: ORIG_SHELL = (details omitted) Parsing line 12: .SHELL= overwritten -Global: .SHELL = overwritten +Global: ignoring '.SHELL = overwritten' due to a command line variable of the same name CondParser_Eval: ${.SHELL} != ${ORIG_SHELL} Var_Parse: ${.SHELL} != ${ORIG_SHELL} (eval-defined) Var_Parse: ${ORIG_SHELL} (eval-defined) Comparing "(details omitted)" != "(details omitted)" Parsing line 19: .MAKEFLAGS: .SHELL+=appended ParseDependency(.MAKEFLAGS: .SHELL+=appended) -Ignoring append to .SHELL since it is read-only +Command: ignoring '.SHELL += appended' as it is read-only CondParser_Eval: ${.SHELL} != ${ORIG_SHELL} Var_Parse: ${.SHELL} != ${ORIG_SHELL} (eval-defined) Var_Parse: ${ORIG_SHELL} (eval-defined) Comparing "(details omitted)" != "(details omitted)" Parsing line 27: .undef .SHELL -Global: delete .SHELL +Global: ignoring delete '.SHELL' as it is not found Parsing line 28: .SHELL= newly overwritten -Global: .SHELL = newly overwritten +Global: ignoring '.SHELL = newly overwritten' due to a command line variable of the same name CondParser_Eval: ${.SHELL} != ${ORIG_SHELL} Var_Parse: ${.SHELL} != ${ORIG_SHELL} (eval-defined) Var_Parse: ${ORIG_SHELL} (eval-defined) diff --git a/contrib/bmake/unit-tests/varname-dot-suffixes.exp b/contrib/bmake/unit-tests/varname-dot-suffixes.exp index 186b5f06c227..230ba36d56ed 100644 --- a/contrib/bmake/unit-tests/varname-dot-suffixes.exp +++ b/contrib/bmake/unit-tests/varname-dot-suffixes.exp @@ -1,20 +1,20 @@ -Global: delete .SUFFIXES (not found) +Global: ignoring delete '.SUFFIXES' as it is not found Global: .MAKEFLAGS = -r -k -d v -d Global: .MAKEFLAGS = -r -k -d v -d 0 -Global: .SUFFIXES = set ignored (read-only) -Global: .SUFFIXES = append ignored (read-only) +Global: ignoring '.SUFFIXES = set' as it is read-only +Global: ignoring '.SUFFIXES = append' as it is read-only Global: _ = # (empty) Var_Parse: ${.SUFFIXES::=assign} (eval-keep-dollar-and-undefined) Evaluating modifier ${.SUFFIXES::...} on value ".c .o .1 .err .tar.gz" (eval-keep-dollar-and-undefined, regular) Modifier part: "assign" -Global: .SUFFIXES = assign ignored (read-only) +Global: ignoring '.SUFFIXES = assign' as it is read-only Result of ${.SUFFIXES::=assign} is "" (eval-keep-dollar-and-undefined, regular) Global: _ = # (empty) Var_Parse: ${preserve:L:_=.SUFFIXES} (eval-keep-dollar-and-undefined) Evaluating modifier ${preserve:L} on value "" (eval-keep-dollar-and-undefined, undefined) Result of ${preserve:L} is "preserve" (eval-keep-dollar-and-undefined, defined) Evaluating modifier ${preserve:_...} on value "preserve" (eval-keep-dollar-and-undefined, defined) -Global: .SUFFIXES = preserve ignored (read-only) +Global: ignoring '.SUFFIXES = preserve' as it is read-only Result of ${preserve:_=.SUFFIXES} is "preserve" (eval-keep-dollar-and-undefined, defined) Global: _ = preserve Global: .MAKEFLAGS = -r -k -d v -d 0 -d v -d @@ -26,13 +26,13 @@ Evaluating modifier ${1 2:@...} on value "1 2" (eval-defined, defined) Modifier part: ".SUFFIXES" Modifier part: "${.SUFFIXES}" ModifyWords: split "1 2" into 2 words -Command: .SUFFIXES = 1 ignored (read-only) +Command: ignoring '.SUFFIXES = 1' as it is read-only Var_Parse: ${.SUFFIXES} (eval-defined) -ModifyWord_Loop: in "1", replace ".SUFFIXES" with "${.SUFFIXES}" to ".c .o .1 .err .tar.gz" -Command: .SUFFIXES = 2 ignored (read-only) +ModifyWord_Loop: expand "${.SUFFIXES}" to ".c .o .1 .err .tar.gz" +Command: ignoring '.SUFFIXES = 2' as it is read-only Var_Parse: ${.SUFFIXES} (eval-defined) -ModifyWord_Loop: in "2", replace ".SUFFIXES" with "${.SUFFIXES}" to ".c .o .1 .err .tar.gz" -Command: delete .SUFFIXES (not found) +ModifyWord_Loop: expand "${.SUFFIXES}" to ".c .o .1 .err .tar.gz" +Command: ignoring delete '.SUFFIXES' as it is not found Result of ${1 2:@.SUFFIXES@${.SUFFIXES}@} is ".c .o .1 .err .tar.gz .c .o .1 .err .tar.gz" (eval-defined, defined) Global: .MAKEFLAGS = -r -k -d v -d 0 -d v -d 0 -d v -d Global: .MAKEFLAGS = -r -k -d v -d 0 -d v -d 0 -d v -d 0 diff --git a/contrib/bmake/unit-tests/varname-dot-suffixes.mk b/contrib/bmake/unit-tests/varname-dot-suffixes.mk index f9f995fcd845..27521f621cb0 100644 --- a/contrib/bmake/unit-tests/varname-dot-suffixes.mk +++ b/contrib/bmake/unit-tests/varname-dot-suffixes.mk @@ -1,4 +1,4 @@ -# $NetBSD: varname-dot-suffixes.mk,v 1.3 2022/04/15 09:33:20 rillig Exp $ +# $NetBSD: varname-dot-suffixes.mk,v 1.5 2023/12/20 09:03:09 rillig Exp $ # # Tests for the special "variable" .SUFFIXES, which lists the suffixes that # have been registered for use in suffix transformation rules. Suffixes are @@ -51,7 +51,7 @@ # Deleting .SUFFIXES has no effect since there is no actual variable of that # name. .MAKEFLAGS: -dv -# expect: Global: delete .SUFFIXES (not found) +# expect: Global: ignoring delete '.SUFFIXES' as it is not found .undef .SUFFIXES .MAKEFLAGS: -d0 .if ${.SUFFIXES} != ".c .o .1 .err .tar.gz" @@ -61,13 +61,13 @@ # The list of suffixes can only be modified using dependency declarations, any # attempt at setting the variable named '.SUFFIXES' is rejected. .MAKEFLAGS: -dv -# expect: Global: .SUFFIXES = set ignored (read-only) +# expect: Global: ignoring '.SUFFIXES = set' as it is read-only .SUFFIXES= set -# expect: Global: .SUFFIXES = append ignored (read-only) +# expect: Global: ignoring '.SUFFIXES = append' as it is read-only .SUFFIXES+= append -# expect: Global: .SUFFIXES = assign ignored (read-only) +# expect: Global: ignoring '.SUFFIXES = assign' as it is read-only _:= ${.SUFFIXES::=assign} -# expect: Global: .SUFFIXES = preserve ignored (read-only) +# expect: Global: ignoring '.SUFFIXES = preserve' as it is read-only _:= ${preserve:L:_=.SUFFIXES} .MAKEFLAGS: -d0 @@ -94,10 +94,9 @@ _:= ${preserve:L:_=.SUFFIXES} # the name would be '.SUFFIXES.', furthermore the name of the iteration # variable is typically in singular form. .MAKEFLAGS: -dv -# expect: Command: .SUFFIXES = 1 ignored (read-only) -# expect: Command: .SUFFIXES = 2 ignored (read-only) -# XXX: Missing space after ':' -# expect: Command: delete .SUFFIXES (not found) +# expect: Command: ignoring '.SUFFIXES = 1' as it is read-only +# expect: Command: ignoring '.SUFFIXES = 2' as it is read-only +# expect: Command: ignoring delete '.SUFFIXES' as it is not found .if ${1 2:L:@.SUFFIXES@${.SUFFIXES}@} != ".c .o .1 .err .tar.gz .c .o .1 .err .tar.gz" . error .endif diff --git a/contrib/bmake/unit-tests/varname-empty.exp b/contrib/bmake/unit-tests/varname-empty.exp index a861ba378cef..2165784933e4 100644 --- a/contrib/bmake/unit-tests/varname-empty.exp +++ b/contrib/bmake/unit-tests/varname-empty.exp @@ -1,22 +1,22 @@ -Var_SetExpand: variable name "${:U}" expands to empty string, with value "cmdline-u" - ignored -Var_SetExpand: variable name "" expands to empty string, with value "cmdline-plain" - ignored +Command: ignoring ' = cmdline-u' as the variable name '${:U}' expands to empty +Command: ignoring ' = cmdline-plain' as the variable name '' expands to empty Global: .CURDIR = <curdir> Var_Parse: ${MAKE_OBJDIR_CHECK_WRITABLE} (eval) Global: .TARGETS = # (empty) Internal: MAKEFILE = varname-empty.mk Global: .MAKE.MAKEFILES = varname-empty.mk Global: .PARSEFILE = varname-empty.mk -Global: delete .INCLUDEDFROMDIR (not found) -Global: delete .INCLUDEDFROMFILE (not found) -Var_SetExpand: variable name "" expands to empty string, with value "default" - ignored -Var_SetExpand: variable name "" expands to empty string, with value "assigned" - ignored -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 +Global: ignoring delete '.INCLUDEDFROMDIR' as it is not found +Global: ignoring delete '.INCLUDEDFROMFILE' as it is not found +Global: ignoring ' = default' as the variable name '' expands to empty +Global: ignoring ' = assigned' as the variable name '' expands to empty +Global: ignoring ' = appended' as the variable name is empty +Global: ignoring ' = ' as the variable name '' expands to empty +Global: ignoring ' = subst' as the variable name '' expands to empty 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 +Global: ignoring ' = shell-output' as the variable name '' expands to empty +Global: ignoring ' = assigned indirectly' as the variable name '${:U}' expands to empty +Global: ignoring ' += appended indirectly' as the variable name '${:U}' expands to empty Global: .MAKEFLAGS = -r -d v -d Global: .MAKEFLAGS = -r -d v -d 0 out: fallback diff --git a/contrib/bmake/unit-tests/varname-empty.mk b/contrib/bmake/unit-tests/varname-empty.mk index f077d2ec07b4..e018a5d44894 100755 --- a/contrib/bmake/unit-tests/varname-empty.mk +++ b/contrib/bmake/unit-tests/varname-empty.mk @@ -1,9 +1,9 @@ -# $NetBSD: varname-empty.mk,v 1.9 2021/04/04 10:13:09 rillig Exp $ +# $NetBSD: varname-empty.mk,v 1.10 2023/11/19 21:47:52 rillig Exp $ # # Tests for the special variable with the empty name. # # There is no variable named "" at all, and this fact is used a lot in -# variable expressions of the form ${:Ufallback}. These expressions are +# expressions of the form ${:Ufallback}. These expressions are # based on the variable named "" and use the :U modifier to assign a # fallback value to the expression (but not to the variable). # diff --git a/contrib/bmake/unit-tests/varname-make_print_var_on_error-jobs.mk b/contrib/bmake/unit-tests/varname-make_print_var_on_error-jobs.mk index 10a9647fbd1e..b422f25ff12e 100644 --- a/contrib/bmake/unit-tests/varname-make_print_var_on_error-jobs.mk +++ b/contrib/bmake/unit-tests/varname-make_print_var_on_error-jobs.mk @@ -1,9 +1,9 @@ -# $NetBSD: varname-make_print_var_on_error-jobs.mk,v 1.3 2021/02/04 21:33:14 rillig Exp $ +# $NetBSD: varname-make_print_var_on_error-jobs.mk,v 1.4 2023/11/19 22:32:44 rillig Exp $ # # Tests for the special MAKE_PRINT_VAR_ON_ERROR variable, which prints the # values of selected variables on error. # -# The variable .ERROR_CMD contains all commands of the target, with variable +# The variable .ERROR_CMD contains all commands of the target, with # expressions expanded, just as they were printed to the shell command file. # # The commands in .ERROR_CMD are space-separated. Since each command usually diff --git a/contrib/bmake/unit-tests/varname-makeflags.exp b/contrib/bmake/unit-tests/varname-makeflags.exp index 39a9383953dd..c1354177ca47 100644 --- a/contrib/bmake/unit-tests/varname-makeflags.exp +++ b/contrib/bmake/unit-tests/varname-makeflags.exp @@ -1 +1,21 @@ +spaces_stage_0: MAKEFLAGS=< -r -k > +spaces_stage_0: env MAKEFLAGS=< -r -k > +spaces_stage_1: MAKEFLAGS=< -r -k -d 00000 -D VARNAME WITH SPACES > +spaces_stage_1: env MAKEFLAGS=< -r -k -d 00000 -D VARNAME WITH SPACES > +dollars_stage_0: MAKEFLAGS=< -r -k > +dollars_stage_1: env MAKEFLAGS=< -r -k DOLLARS=\$\{varname\}> +dollars_stage_1: MAKEFLAGS=< -r -k DOLLARS=\{varname\}> +dollars_stage_1: MAKEFLAGS:q=< -r -k DOLLARS=\{varname\}> +dollars_stage_2: env MAKEFLAGS=< -r -k DOLLARS=> +dollars_stage_2: dollars=<> +dollars_stage_2: MAKEFLAGS=< -r -k DOLLARS=> +dollars_stage_3: env MAKEFLAGS=< -r -k DOLLARS=> +dollars_stage_3: dollars=<> +dollars_stage_3: MAKEFLAGS=< -r -k DOLLARS=> +append_stage_0: MAKEFLAGS=< -r -k > +append_stage_1: MAKEFLAGS=< -r -k -D before-0 -D after-0 VAR0=value> +append_stage_2: MAKEFLAGS=< -r -k -D before-0 -D after-0 -D before-1 -D after-1 VAR0=value VAR1=value> +append_stage_3: MAKEFLAGS=< -r -k -D before-0 -D after-0 -D before-1 -D after-1 -D before-2 -D after-2 VAR0=value VAR1=value VAR2=value> +override_stage_1: run MAKEFLAGS=< -r -k STAGE=1 VAR=value> +override_stage_2: STAGE=<2> VAR=<value> exit status 0 diff --git a/contrib/bmake/unit-tests/varname-makeflags.mk b/contrib/bmake/unit-tests/varname-makeflags.mk index f7840c2eb7a5..4173c5a92095 100644 --- a/contrib/bmake/unit-tests/varname-makeflags.mk +++ b/contrib/bmake/unit-tests/varname-makeflags.mk @@ -1,44 +1,182 @@ -# $NetBSD: varname-makeflags.mk,v 1.5 2022/01/16 18:16:06 sjg Exp $ +# $NetBSD: varname-makeflags.mk,v 1.8 2023/06/01 07:27:30 rillig Exp $ # -# Tests for the special MAKEFLAGS variable, which is basically just a normal -# environment variable. It is closely related to .MAKEFLAGS but captures the -# state of .MAKEFLAGS at the very beginning of make, before any makefiles are -# read. +# Tests for the environment variable 'MAKEFLAGS', from which additional +# command line arguments are read before the actual command line arguments. +# +# After reading the makefiles and before making the targets, the arguments +# that were collected in '.MAKEFLAGS' and '.MAKEOVERRIDES' are written back to +# the environment variable 'MAKEFLAGS'. + +all: spaces_stage_0 dollars_stage_0 append_stage_0 override_stage_0 -# TODO: Implementation -.MAKEFLAGS: -d0 +.if !make(*stage*) # The unit tests are run with an almost empty environment. In particular, -# the variable MAKEFLAGS is not set. The '.MAKEFLAGS:' above also doesn't -# influence the environment variable MAKEFLAGS, therefore it is still -# undefined at this point. -.if ${MAKEFLAGS:Uundefined} != "undefined" -. error -.endif +# the variable MAKEFLAGS is not set. +. if ${MAKEFLAGS:Uundefined} != "undefined" +. error +. endif # The special variable .MAKEFLAGS is influenced though. # See varname-dot-makeflags.mk for more details. -.if ${.MAKEFLAGS} != " -r -k -d 0" -. error -.endif +. if ${.MAKEFLAGS} != " -r -k" +. error +. endif # In POSIX mode, the environment variable MAKEFLAGS can contain letters only, # for compatibility. These letters are exploded to form regular options. OUTPUT!= env MAKEFLAGS=ikrs ${MAKE} -f /dev/null -v .MAKEFLAGS -.if ${OUTPUT} != " -i -k -r -s -V .MAKEFLAGS" -. error -.endif +. if ${OUTPUT} != " -i -k -r -s -V .MAKEFLAGS" +. error +. endif # As soon as there is a single non-alphabetic character in the environment # variable MAKEFLAGS, it is no longer split. In this example, the word # "d0ikrs" is treated as a target, but the option '-v' prevents any targets # from being built. OUTPUT!= env MAKEFLAGS=d0ikrs ${MAKE} -r -f /dev/null -v .MAKEFLAGS -.if ${OUTPUT} != " -r -V .MAKEFLAGS" -. error ${OUTPUT} +. if ${OUTPUT} != " -r -V .MAKEFLAGS" +. error ${OUTPUT} +. endif + +.endif + + +# When options are parsed, the option and its argument are appended as +# separate words to the MAKEFLAGS for the child processes. Special characters +# in the option arguments are not quoted though. +spaces_stage_0: + @echo '$@: MAKEFLAGS=<'${MAKEFLAGS:Q}'>' + @echo "$@: env MAKEFLAGS=<$$MAKEFLAGS>" + @${MAKE} -f ${MAKEFILE} spaces_stage_1 -d00000 -D"VARNAME WITH SPACES" + +# At this point, the 'VARNAME WITH SPACES' is no longer recognizable as a +# single command line argument. In practice, variable names don't contain +# spaces. +spaces_stage_1: + @echo '$@: MAKEFLAGS=<'${MAKEFLAGS:Q}'>' + @echo "$@: env MAKEFLAGS=<$$MAKEFLAGS>" + + +# Demonstrate that '$' characters are altered when they are passed on to child +# make processes via MAKEFLAGS. +dollars_stage_0: + @echo '$@: MAKEFLAGS=<'${MAKEFLAGS:Q}'>' + + # The '$$$$' becomes a literal '$$' when building the '${MAKE}' + # command line, making the actual argument 'DOLLARS=$${varname}'. + # At this stage, MAKEFLAGS is not yet involved. + @${MAKE} -f ${MAKEFILE} dollars_stage_1 DOLLARS='$$$${varname}' + +.if make(dollars_stage_1) +# At this point, the variable 'DOLLARS' contains '$${varname}', which +# evaluates to a literal '$' followed by '{varname}'. +. if ${DOLLARS} != "\${varname}" +. error +. endif .endif +dollars_stage_1: + # At this point, the stage 1 make provides the environment variable + # 'MAKEFLAGS' to its child processes, even if the child process is not + # another make. + # + # expect: dollars_stage_1: env MAKEFLAGS=< -r -k DOLLARS=\$\{varname\}> + # + # The 'DOLLARS=\$\{varname\}' assignment is escaped so that the stage + # 2 make will see it as a single word. + @echo "$@: env MAKEFLAGS=<$$MAKEFLAGS>" + # At this point, evaluating the environment variable 'MAKEFLAGS' leads + # to strange side effects as the string '\$\{varname\}' is interpreted + # as: + # + # \ a literal string of a single backslash + # $\ the value of the variable named '\' + # {varname\} a literal string + # + # Since the variable named '\' is not defined, the resulting value is + # '\{varname\}'. Make doesn't handle isolated '$' characters in + # strings well, instead each '$' has to be part of a '$$' or be part + # of a subexpression like '${VAR}'. + @echo '$@: MAKEFLAGS=<'${MAKEFLAGS:Q}'>' + + # The modifier ':q' preserves a '$$' in an expression value instead of + # expanding it to a single '$', but it's already too late, as that + # modifier applies after the expression has been evaluated. Except + # for debug logging, there is no way to process strings that contain + # isolated '$'. + @echo '$@: MAKEFLAGS:q=<'${MAKEFLAGS:q}'>' + + @${MAKE} -f ${MAKEFILE} dollars_stage_2 + +.if make(dollars_stage_2) +# At this point, the variable 'DOLLARS' contains '${varname}', and since +# 'varname' is undefined, that expression evaluates to an empty string. +. if ${DOLLARS} != "" +. error +. endif +varname= varvalue +. if ${DOLLARS} != "varvalue" +. error +. endif +. undef varname +.endif +dollars_stage_2: + @echo "$@: env MAKEFLAGS=<$$MAKEFLAGS>" + @echo '$@: dollars=<'${DOLLARS:Q}'>' + @echo '$@: MAKEFLAGS=<'${MAKEFLAGS:Q}'>' + @${MAKE} -f ${MAKEFILE} dollars_stage_3 + +dollars_stage_3: + @echo "$@: env MAKEFLAGS=<$$MAKEFLAGS>" + @echo '$@: dollars=<'${DOLLARS:Uundefined:Q}'>' + @echo '$@: MAKEFLAGS=<'${MAKEFLAGS:Q}'>' + + +# Demonstrates in which exact order the MAKEFLAGS are built from the parent +# MAKEFLAGS and the flags from the command line, in particular that variable +# assignments are passed at the end, after the options. +append_stage_0: + @echo '$@: MAKEFLAGS=<'${MAKEFLAGS:Q}'>' + @${MAKE} -Dbefore-0 -f ${MAKEFILE} append_stage_1 VAR0=value -Dafter-0 + +append_stage_1: + @echo '$@: MAKEFLAGS=<'${MAKEFLAGS:Q}'>' + @${MAKE} -Dbefore-1 -f ${MAKEFILE} append_stage_2 VAR1=value -Dafter-1 + +append_stage_2: + @echo '$@: MAKEFLAGS=<'${MAKEFLAGS:Q}'>' + @${MAKE} -Dbefore-2 -f ${MAKEFILE} append_stage_3 VAR2=value -Dafter-2 + +append_stage_3: + @echo '$@: MAKEFLAGS=<'${MAKEFLAGS:Q}'>' + + +# Demonstrates the implementation details of 'MAKEFLAGS', in particular that +# it is an environment variable rather than a global variable. +override_stage_0: + @${MAKE} -f ${MAKEFILE} STAGE=1 VAR=value override_stage_1 + +.if make(override_stage_1) +# While parsing the makefiles, 'MAKEFLAGS' is the value of the environment +# variable, in this case provided by stage 0. +. if ${MAKEFLAGS:M*} != "-r -k" +. error +. endif +MAKEFLAGS= overridden # temporarily override it +. if ${MAKEFLAGS} != "overridden" +. error +. endif +.undef MAKEFLAGS # make the environment variable visible again +. if ${MAKEFLAGS:M*} != "-r -k" +. error +. endif +.endif +override_stage_1: + @echo '$@: run MAKEFLAGS=<'${MAKEFLAGS:Q}'>' + @${MAKE} -f ${MAKEFILE} STAGE=2 override_stage_2 -all: +override_stage_2: + @echo '$@: STAGE=<${STAGE}> VAR=<${VAR}>' diff --git a/contrib/bmake/unit-tests/varname.exp b/contrib/bmake/unit-tests/varname.exp index 942532b654d5..640f228f8a51 100644 --- a/contrib/bmake/unit-tests/varname.exp +++ b/contrib/bmake/unit-tests/varname.exp @@ -5,13 +5,13 @@ Var_Parse: ${VARNAME} (eval) Global: VAR((( = 3 open parentheses Var_Parse: ${VAR(((}}}}" != "3 open parentheses}}}" (eval) Global: .ALLTARGETS = VAR(((=) -make: "varname.mk" line 30: No closing parenthesis in archive specification -make: "varname.mk" line 30: Error in archive specification: "VAR" +make: "varname.mk" line 32: No closing parenthesis in archive specification +make: "varname.mk" line 32: Error in archive specification: "VAR" Var_Parse: ${:UVAR\(\(\(}= try2 (eval-defined) Evaluating modifier ${:U...} on value "" (eval-defined, undefined) Result of ${:UVAR\(\(\(} is "VAR\(\(\(" (eval-defined, defined) Global: .ALLTARGETS = VAR(((=) VAR\(\(\(= -make: "varname.mk" line 35: Invalid line type +make: "varname.mk" line 38: Invalid line '${:UVAR\(\(\(}= try2', expanded to 'VAR\(\(\(= try2' Var_Parse: ${VARNAME} (eval) Global: VAR((( = try3 Global: .MAKEFLAGS = -r -k -d v -d diff --git a/contrib/bmake/unit-tests/varname.mk b/contrib/bmake/unit-tests/varname.mk index e86fd9176a2a..cad0a10fe563 100644 --- a/contrib/bmake/unit-tests/varname.mk +++ b/contrib/bmake/unit-tests/varname.mk @@ -1,4 +1,4 @@ -# $NetBSD: varname.mk,v 1.10 2022/02/09 21:09:24 rillig Exp $ +# $NetBSD: varname.mk,v 1.14 2023/11/19 21:47:52 rillig Exp $ # # Tests for special variables, such as .MAKE or .PARSEDIR. # And for variable names in general. @@ -12,7 +12,7 @@ VAR{{{}}}= 3 braces . error .endif -# In variable expressions, the parser works differently. It doesn't treat +# In expressions, the parser works differently. It doesn't treat # braces and parentheses equally, therefore the first closing brace already # marks the end of the variable name. VARNAME= VAR((( @@ -27,11 +27,14 @@ ${VARNAME}= 3 open parentheses # This is not a variable assignment since the parentheses and braces are not # balanced. At the end of the line, there are still 3 levels open, which # means the variable name is not finished. +# expect+2: Error in archive specification: "VAR" +# expect+1: No closing parenthesis in archive specification ${:UVAR(((}= try1 # On the left-hand side of a variable assignments, the backslash is not parsed # as an escape character, therefore the parentheses still count to the nesting # level, which at the end of the line is still 3. Therefore this is not a # variable assignment as well. +# expect+1: Invalid line '${:UVAR\(\(\(}= try2', expanded to 'VAR\(\(\(= try2' ${:UVAR\(\(\(}= try2 # To assign to a variable with an arbitrary name, the variable name has to # come from an external source, not the text that is parsed in the assignment diff --git a/contrib/bmake/unit-tests/varparse-dynamic.exp b/contrib/bmake/unit-tests/varparse-dynamic.exp index a2ff29413167..caf8424fa91a 100644 --- a/contrib/bmake/unit-tests/varparse-dynamic.exp +++ b/contrib/bmake/unit-tests/varparse-dynamic.exp @@ -1,5 +1,5 @@ -make: "varparse-dynamic.mk" line 8: Malformed conditional (${.TARGEX}) -make: "varparse-dynamic.mk" line 10: Malformed conditional (${.TARGXX}) +make: "varparse-dynamic.mk" line 9: Malformed conditional (${.TARGEX}) +make: "varparse-dynamic.mk" line 12: Malformed conditional (${.TARGXX}) make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/varparse-dynamic.mk b/contrib/bmake/unit-tests/varparse-dynamic.mk index d4d165017a7f..40f43b049b13 100644 --- a/contrib/bmake/unit-tests/varparse-dynamic.mk +++ b/contrib/bmake/unit-tests/varparse-dynamic.mk @@ -1,12 +1,14 @@ -# $NetBSD: varparse-dynamic.mk,v 1.5 2021/02/22 20:38:55 rillig Exp $ +# $NetBSD: varparse-dynamic.mk,v 1.8 2023/11/19 22:32:44 rillig Exp $ # Before 2020-07-27, there was an off-by-one error in Var_Parse that skipped # the last character in the variable name. -# To trigger the bug, the variable must not be defined. +# To trigger the bug, the variable had to be undefined. .if ${.TARGET} # exact match, may be undefined .endif +# expect+1: Malformed conditional (${.TARGEX}) .if ${.TARGEX} # 1 character difference, must be defined .endif +# expect+1: Malformed conditional (${.TARGXX}) .if ${.TARGXX} # 2 characters difference, must be defined .endif @@ -22,7 +24,7 @@ .endif # If a dynamic variable is expanded in a non-local scope, the expression -# based on this variable is not expanded. But there may be nested variable +# based on this variable is not expanded. But there may be nested # expressions in the modifiers, and these are kept unexpanded as well. .if ${.TARGET:M${:Ufallback}} != "\${.TARGET:M\${:Ufallback}}" . error @@ -30,6 +32,3 @@ .if ${.TARGET:M${UNDEF}} != "\${.TARGET:M\${UNDEF}}" . error .endif - -all: - @: diff --git a/contrib/bmake/unit-tests/varparse-errors.exp b/contrib/bmake/unit-tests/varparse-errors.exp index e47127447cda..4193bea181c9 100644 --- a/contrib/bmake/unit-tests/varparse-errors.exp +++ b/contrib/bmake/unit-tests/varparse-errors.exp @@ -1,11 +1,25 @@ make: "varparse-errors.mk" line 38: Unknown modifier "Z" -make: "varparse-errors.mk" line 46: Unknown modifier "Z" +make: "varparse-errors.mk" line 47: Unknown modifier "Z" make: Bad modifier ":OX" for variable "" -make: "varparse-errors.mk" line 68: Undefined variable "${:U:OX" +make: "varparse-errors.mk" line 71: Undefined variable "${:U:OX" make: Bad modifier ":OX" for variable "" make: Bad modifier ":OX" for variable "" -make: "varparse-errors.mk" line 68: Undefined variable "${:U:OX" +make: "varparse-errors.mk" line 71: Undefined variable "${:U:OX" make: Bad modifier ":OX" for variable "" +make: Unclosed expression, expecting '}' for modifier "Q" of variable "" with value "" +make: Unclosed expression, expecting '}' for modifier "sh" of variable "" with value "" +make: Unclosed expression, expecting '}' for modifier "tA" of variable "" with value "" +make: Unclosed expression, expecting '}' for modifier "tsX" of variable "" with value "" +make: Unclosed expression, expecting '}' for modifier "ts" of variable "" with value "" +make: Unclosed expression, expecting '}' for modifier "ts\040" of variable "" with value "" +make: Unclosed expression, expecting '}' for modifier "u" of variable "" with value "" +make: Unclosed expression, expecting '}' for modifier "H" of variable "" with value "." +make: Unclosed expression, expecting '}' for modifier "[1]" of variable "" with value "" +make: Unclosed expression, expecting '}' for modifier "hash" of variable "" with value "b2af338b" +make: Unclosed expression, expecting '}' for modifier "range" of variable "" with value "1" +make: Unclosed expression, expecting '}' for modifier "_" of variable "" with value "" +make: Unclosed expression, expecting '}' for modifier "gmtime" of variable "" with value "<timestamp>" +make: Unclosed expression, expecting '}' for modifier "localtime" of variable "" with value "<timestamp>" make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/contrib/bmake/unit-tests/varparse-errors.mk b/contrib/bmake/unit-tests/varparse-errors.mk index 51a403fa898f..fc94d9dd3d18 100644 --- a/contrib/bmake/unit-tests/varparse-errors.mk +++ b/contrib/bmake/unit-tests/varparse-errors.mk @@ -1,12 +1,11 @@ -# $NetBSD: varparse-errors.mk,v 1.5 2022/01/24 22:59:49 rillig Exp $ +# $NetBSD: varparse-errors.mk,v 1.11 2023/11/19 22:32:44 rillig Exp $ -# Tests for parsing and evaluating all kinds of variable expressions. +# Tests for parsing and evaluating all kinds of expressions. # # This is the basis for redesigning the error handling in Var_Parse and # Var_Subst, collecting typical and not so typical use cases. # # See also: -# VarParseResult # Var_Parse # Var_Subst @@ -18,13 +17,13 @@ INDIRECT= An ${:Uindirect} value. REF_UNDEF= A reference to an ${UNDEF}undefined variable. -ERR_UNCLOSED= An ${UNCLOSED variable expression. +ERR_UNCLOSED= An ${UNCLOSED expression. ERR_BAD_MOD= An ${:Uindirect:Z} expression with an unknown modifier. ERR_EVAL= An evaluation error ${:Uvalue:C,.,\3,}. -# In a conditional, a variable expression that is not enclosed in quotes is +# In a conditional, an expression that is not enclosed in quotes is # expanded using the mode VARE_UNDEFERR. # The variable itself must be defined. # It may refer to undefined variables though. @@ -35,6 +34,7 @@ ERR_EVAL= An evaluation error ${:Uvalue:C,.,\3,}. # As of 2020-12-01, errors in the variable name are silently ignored. # Since var.c 1.754 from 2020-12-20, unknown modifiers at parse time result # in an error message and a non-zero exit status. +# expect+1: Unknown modifier "Z" VAR.${:U:Z}= unknown modifier in the variable name .if ${VAR.} != "unknown modifier in the variable name" . error @@ -43,6 +43,7 @@ VAR.${:U:Z}= unknown modifier in the variable name # As of 2020-12-01, errors in the variable name are silently ignored. # Since var.c 1.754 from 2020-12-20, unknown modifiers at parse time result # in an error message and a non-zero exit status. +# expect+1: Unknown modifier "Z" VAR.${:U:Z}post= unknown modifier with text in the variable name .if ${VAR.post} != "unknown modifier with text in the variable name" . error @@ -65,7 +66,26 @@ VAR.${:U:Z}post= unknown modifier with text in the variable name # #.MAKEFLAGS: -dv IND= ${:OX} +# expect+2: Undefined variable "${:U:OX" +# expect+1: Undefined variable "${:U:OX" _:= ${:U:OX:U${IND}} ${:U:OX:U${IND}} #.MAKEFLAGS: -d0 -all: + +# Before var.c 1.032 from 2022-08-24, make complained about 'Unknown modifier' +# or 'Bad modifier' when in fact the modifier was entirely correct, it was +# just not delimited by either ':' or '}' but instead by '\0'. +UNCLOSED:= ${:U:Q +UNCLOSED:= ${:U:sh +UNCLOSED:= ${:U:tA +UNCLOSED:= ${:U:tsX +UNCLOSED:= ${:U:ts +UNCLOSED:= ${:U:ts\040 +UNCLOSED:= ${:U:u +UNCLOSED:= ${:U:H +UNCLOSED:= ${:U:[1] +UNCLOSED:= ${:U:hash +UNCLOSED:= ${:U:range +UNCLOSED:= ${:U:_ +UNCLOSED:= ${:U:gmtime +UNCLOSED:= ${:U:localtime diff --git a/contrib/bmake/unit-tests/varparse-mod.mk b/contrib/bmake/unit-tests/varparse-mod.mk index 0b4cbf6ca40a..c5fa6f5ece71 100644 --- a/contrib/bmake/unit-tests/varparse-mod.mk +++ b/contrib/bmake/unit-tests/varparse-mod.mk @@ -1,6 +1,6 @@ -# $NetBSD: varparse-mod.mk,v 1.1 2020/10/02 20:34:59 rillig Exp $ +# $NetBSD: varparse-mod.mk,v 1.2 2023/11/19 21:47:52 rillig Exp $ -# Tests for parsing variable expressions with modifiers. +# Tests for parsing expressions with modifiers. # As of 2020-10-02, the below condition does not result in a parse error. # The condition contains two separate mistakes. The first mistake is that @@ -8,7 +8,7 @@ # there is a stray '}' at the end of the whole condition. # # As of 2020-10-02, the actual parse result of this condition is a single -# variable expression with 2 modifiers. The first modifier is +# expression with 2 modifiers. The first modifier is # ":!echo "\$VAR"} !". Afterwards, the parser optionally skips a ':' (at the # bottom of ApplyModifiers) and continues with the next modifier, in this case # "= "value"", which is interpreted as a SysV substitution modifier with an diff --git a/contrib/bmake/unit-tests/varparse-undef-partial.mk b/contrib/bmake/unit-tests/varparse-undef-partial.mk index 27f44d79b31a..9a5704265086 100644 --- a/contrib/bmake/unit-tests/varparse-undef-partial.mk +++ b/contrib/bmake/unit-tests/varparse-undef-partial.mk @@ -1,7 +1,7 @@ -# $NetBSD: varparse-undef-partial.mk,v 1.3 2020/11/04 05:10:01 rillig Exp $ +# $NetBSD: varparse-undef-partial.mk,v 1.5 2024/01/07 11:39:04 rillig Exp $ # When an undefined variable is expanded in a ':=' assignment, only the -# initial '$' of the variable expression is skipped by the parser, while +# initial '$' of the expression is skipped by the parser, while # the remaining expression is evaluated. In edge cases this can lead to # a completely different interpretation of the partially expanded text. @@ -11,11 +11,10 @@ PARAM= :Q # The expression ${VAR.${PARAM}} refers to the variable named "VAR.:Q", # with the ":Q" being part of the name. This variable is not defined, -# therefore the initial '$' of that whole expression is skipped by the -# parser (see Var_Subst, the Buf_AddByte in the else branch) and the rest -# of the expression is expanded as usual. +# therefore the initial '$' of that whole expression is skipped by the parser +# (see VarSubstExpr) and the rest of the expression is expanded as usual. # -# The resulting variable expression is ${VAR.:Q}, which means that the +# The resulting expression is ${VAR.:Q}, which means that the # interpretation of the ":Q" has changed from being part of the variable # name to being a variable modifier. This is a classical code injection. EVAL:= ${LIST} @@ -37,7 +36,7 @@ ${:UVAR.\:Q}= var-dot with parameter :Q # In contrast to the previous line, evaluating the original LIST again now # produces a different result since the variable named "VAR.:Q" is now # defined. It is expanded as usual, interpreting the ":Q" as part of the -# variable name, as would be expected from reading the variable expression. +# variable name, as would be expected from reading the expression. EVAL:= ${LIST} .if ${EVAL} != "defined var-dot with parameter :Q end" . error ${EVAL} diff --git a/contrib/bmake/unit-tests/varquote.exp b/contrib/bmake/unit-tests/varquote.exp deleted file mode 100644 index 63107bfd34f5..000000000000 --- a/contrib/bmake/unit-tests/varquote.exp +++ /dev/null @@ -1,3 +0,0 @@ --fdebug-prefix-map=$NETBSDSRCDIR=/usr/src -fdebug-regex-map=/usr/src/(.*)/obj$=/usr/obj/\1 --fdebug-prefix-map=$NETBSDSRCDIR=/usr/src -fdebug-regex-map=/usr/src/(.*)/obj$=/usr/obj/\1 -exit status 0 diff --git a/contrib/bmake/unit-tests/varquote.mk b/contrib/bmake/unit-tests/varquote.mk deleted file mode 100644 index 3d5e8a7f32e9..000000000000 --- a/contrib/bmake/unit-tests/varquote.mk +++ /dev/null @@ -1,14 +0,0 @@ -# $NetBSD: varquote.mk,v 1.5 2021/12/28 10:47:00 rillig Exp $ -# -# Test VAR:q modifier - -.if !defined(REPROFLAGS) -REPROFLAGS+= -fdebug-prefix-map=\$$NETBSDSRCDIR=/usr/src -REPROFLAGS+= -fdebug-regex-map='/usr/src/(.*)/obj$$=/usr/obj/\1' -all: - @${MAKE} -f ${MAKEFILE} REPROFLAGS=${REPROFLAGS:S/\$/&&/g:Q} - @${MAKE} -f ${MAKEFILE} REPROFLAGS=${REPROFLAGS:q} -.else -all: - @printf "%s %s\n" ${REPROFLAGS} -.endif |