Module Name: src Committed By: rillig Date: Tue Jan 14 21:23:17 UTC 2025
Modified Files: src/usr.bin/make: parse.c src/usr.bin/make/unit-tests: dep-var.exp dep-var.mk deptgt.exp directive-export-impl.exp suff.exp varname.exp Log Message: make: simplify parsing of dependency lines The evaluation modes that allow or deny undefined variables have the same effect in this case, as Var_Subst does not return an error marker. To generate a diff of this commit: cvs rdiff -u -r1.736 -r1.737 src/usr.bin/make/parse.c cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/dep-var.exp cvs rdiff -u -r1.12 -r1.13 src/usr.bin/make/unit-tests/dep-var.mk cvs rdiff -u -r1.20 -r1.21 src/usr.bin/make/unit-tests/deptgt.exp \ src/usr.bin/make/unit-tests/directive-export-impl.exp cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/suff.exp cvs rdiff -u -r1.23 -r1.24 src/usr.bin/make/unit-tests/varname.exp Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/parse.c diff -u src/usr.bin/make/parse.c:1.736 src/usr.bin/make/parse.c:1.737 --- src/usr.bin/make/parse.c:1.736 Thu Oct 31 09:12:13 2024 +++ src/usr.bin/make/parse.c Tue Jan 14 21:23:17 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.736 2024/10/31 09:12:13 rillig Exp $ */ +/* $NetBSD: parse.c,v 1.737 2025/01/14 21:23:17 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -105,7 +105,7 @@ #include "pathnames.h" /* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: parse.c,v 1.736 2024/10/31 09:12:13 rillig Exp $"); +MAKE_RCSID("$NetBSD: parse.c,v 1.737 2025/01/14 21:23:17 rillig Exp $"); /* Detects a multiple-inclusion guard in a makefile. */ typedef enum { @@ -2839,7 +2839,6 @@ FindSemicolon(char *p) static void ParseDependencyLine(char *line) { - VarEvalMode emode; char *expanded_line; const char *shellcmd = NULL; @@ -2852,41 +2851,7 @@ ParseDependencyLine(char *line) } } - /* - * We now know it's a dependency line, so it needs to have all - * variables expanded before being parsed. - * - * XXX: Ideally the dependency line would first be split into - * its left-hand side, dependency operator and right-hand side, - * and then each side would be expanded on its own. This would - * allow for the left-hand side to allow only defined variables - * and to allow variables on the right-hand side to be undefined - * as well. - * - * Parsing the line first would also prevent that targets - * generated from expressions are interpreted as the - * dependency operator, such as in "target${:U\:} middle: source", - * in which the middle is interpreted as a source, not a target. - */ - - /* - * In lint mode, allow undefined variables to appear in dependency - * lines. - * - * Ideally, only the right-hand side would allow undefined variables - * since it is common to have optional dependencies. Having undefined - * variables on the left-hand side is more unusual though. Since - * both sides are expanded in a single pass, there is not much choice - * what to do here. - * - * In normal mode, it does not matter whether undefined variables are - * allowed or not since as of 2020-09-14, Var_Parse does not print - * any parse errors in such a case. It simply returns the special - * empty string var_Error, which cannot be detected in the result of - * Var_Subst. - */ - emode = opts.strict ? VARE_EVAL : VARE_EVAL_DEFINED; - expanded_line = Var_Subst(line, SCOPE_CMDLINE, emode); + expanded_line = Var_Subst(line, SCOPE_CMDLINE, VARE_EVAL); /* TODO: handle errors */ /* Need a fresh list for the target nodes */ Index: src/usr.bin/make/unit-tests/dep-var.exp diff -u src/usr.bin/make/unit-tests/dep-var.exp:1.9 src/usr.bin/make/unit-tests/dep-var.exp:1.10 --- src/usr.bin/make/unit-tests/dep-var.exp:1.9 Sat Jan 11 21:21:33 2025 +++ src/usr.bin/make/unit-tests/dep-var.exp Tue Jan 14 21:23:17 2025 @@ -1,4 +1,4 @@ -Var_Parse: ${UNDEF1} (eval-defined) +Var_Parse: ${UNDEF1} (eval) Global: .ALLTARGETS = all Global: .ALLTARGETS = all ${DEF2} Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b @@ -10,7 +10,7 @@ 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) +Var_Parse: ${:U\$)}: (eval) Evaluating modifier ${:U...} on value "" (eval, undefined) Result of ${:U\$)} is "$)" (eval, defined) Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b ${UNDEF3} 1-${INDIRECT_1}-1 $$) undef1 Index: src/usr.bin/make/unit-tests/dep-var.mk diff -u src/usr.bin/make/unit-tests/dep-var.mk:1.12 src/usr.bin/make/unit-tests/dep-var.mk:1.13 --- src/usr.bin/make/unit-tests/dep-var.mk:1.12 Sun Jun 2 15:31:26 2024 +++ src/usr.bin/make/unit-tests/dep-var.mk Tue Jan 14 21:23:17 2025 @@ -1,4 +1,4 @@ -# $NetBSD: dep-var.mk,v 1.12 2024/06/02 15:31:26 rillig Exp $ +# $NetBSD: dep-var.mk,v 1.13 2025/01/14 21:23:17 rillig Exp $ # # Tests for variable references in dependency declarations. # @@ -7,10 +7,8 @@ .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. +# In a dependency line, an undefined expressions expands to an empty string. +# expect: Var_Parse: ${UNDEF1} (eval) all: ${UNDEF1} # Using a double dollar in order to circumvent immediate expression expansion @@ -21,11 +19,7 @@ all: ${UNDEF1} # is defined, so everything's fine. all: $${DEF2} a-$${DEF2}-b -# This variable is not defined at all. -# 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 expression ${UNDEF3} simply expands to an empty string. +# This variable is neither defined now nor later. all: $${UNDEF3} # Try out how many levels of indirection are really expanded in dependency @@ -83,14 +77,10 @@ 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: ${:U\$)}: (eval) # expect: Var_Parse: $INDIRECT_2-2-1 $): (parse) # expect: Var_Parse: $): (parse) undef1 def2 a-def2-b 1-2-$$INDIRECT_2-2-1 ${:U\$)}: @echo ${.TARGET:Q} .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. Index: src/usr.bin/make/unit-tests/deptgt.exp diff -u src/usr.bin/make/unit-tests/deptgt.exp:1.20 src/usr.bin/make/unit-tests/deptgt.exp:1.21 --- src/usr.bin/make/unit-tests/deptgt.exp:1.20 Fri Jan 10 23:00:38 2025 +++ src/usr.bin/make/unit-tests/deptgt.exp Tue Jan 14 21:23:17 2025 @@ -8,8 +8,8 @@ ParseDependency(: empty-source) Parsing deptgt.mk:39: : command for empty targets list Parsing deptgt.mk:40: .MAKEFLAGS: -d0 ParseDependency(.MAKEFLAGS: -d0) -Var_Parse: ${UNDEF}: depsrc-${UNDEF} (eval-defined) -Var_Parse: ${UNDEF} (eval-defined) +Var_Parse: ${UNDEF}: depsrc-${UNDEF} (eval) +Var_Parse: ${UNDEF} (eval) Global: .ALLTARGETS = target1 target2 sources empty-source deptgt- Global: .ALLTARGETS = target1 target2 sources empty-source deptgt- depsrc- Global: .MAKEFLAGS = -r -k -d p -d 0 -d v -d Index: src/usr.bin/make/unit-tests/directive-export-impl.exp diff -u src/usr.bin/make/unit-tests/directive-export-impl.exp:1.20 src/usr.bin/make/unit-tests/directive-export-impl.exp:1.21 --- src/usr.bin/make/unit-tests/directive-export-impl.exp:1.20 Sat Jan 11 21:21:33 2025 +++ src/usr.bin/make/unit-tests/directive-export-impl.exp Tue Jan 14 21:23:17 2025 @@ -3,7 +3,7 @@ Global: UT_VAR = <${REF}> Parsing directive-export-impl.mk:28: .export UT_VAR Global: .MAKE.EXPORTED = UT_VAR Parsing directive-export-impl.mk:32: : ${UT_VAR:N*} -Var_Parse: ${UT_VAR:N*} (eval-defined) +Var_Parse: ${UT_VAR:N*} (eval) Var_Parse: ${REF}> (eval) Evaluating modifier ${UT_VAR:N...} on value "<>" Pattern for ':N' is "*" @@ -26,7 +26,7 @@ Var_Parse: ${REF}> (eval) Result of ${:!echo "\$UT_VAR"!} is "<>" (eval, defined) Comparing "<>" != "<>" Parsing directive-export-impl.mk:50: : ${UT_VAR:N*} -Var_Parse: ${UT_VAR:N*} (eval-defined) +Var_Parse: ${UT_VAR:N*} (eval) Var_Parse: ${REF}> (eval) Evaluating modifier ${UT_VAR:N...} on value "<>" Pattern for ':N' is "*" Index: src/usr.bin/make/unit-tests/suff.exp diff -u src/usr.bin/make/unit-tests/suff.exp:1.2 src/usr.bin/make/unit-tests/suff.exp:1.3 --- src/usr.bin/make/unit-tests/suff.exp:1.2 Sun Jan 12 23:10:30 2025 +++ src/usr.bin/make/unit-tests/suff.exp Tue Jan 14 21:23:17 2025 @@ -4,8 +4,8 @@ defining transformation from `.from' to inserting ".from" (1) at end of list inserting ".to" (2) at end of list transformation .from.to complete -Var_Parse: ${.PREFIX}${.ARCHIVE}.additional (eval-defined) -Var_Parse: ${.ARCHIVE}.additional (eval-defined) +Var_Parse: ${.PREFIX}${.ARCHIVE}.additional (eval) +Var_Parse: ${.ARCHIVE}.additional (eval) Global: .ALLTARGETS = step1 edge-case.to everything ${.PREFIX}${.ARCHIVE}.additional Global: .ALLTARGETS = step1 edge-case.to everything ${.PREFIX}${.ARCHIVE}.additional edge-case.from Global: .ALLTARGETS = step1 edge-case.to everything ${.PREFIX}${.ARCHIVE}.additional edge-case.from edge-case.additional Index: src/usr.bin/make/unit-tests/varname.exp diff -u src/usr.bin/make/unit-tests/varname.exp:1.23 src/usr.bin/make/unit-tests/varname.exp:1.24 --- src/usr.bin/make/unit-tests/varname.exp:1.23 Sat Jan 11 21:21:34 2025 +++ src/usr.bin/make/unit-tests/varname.exp Tue Jan 14 21:23:17 2025 @@ -7,7 +7,7 @@ Var_Parse: ${VAR(((}}}}" != "3 open pare Global: .ALLTARGETS = VAR(((=) make: "varname.mk" line 32: Missing ')' in archive specification make: "varname.mk" line 32: Error in archive specification: "VAR" -Var_Parse: ${:UVAR\(\(\(}= try2 (eval-defined) +Var_Parse: ${:UVAR\(\(\(}= try2 (eval) Evaluating modifier ${:U...} on value "" (eval, undefined) Result of ${:UVAR\(\(\(} is "VAR\(\(\(" (eval, defined) Global: .ALLTARGETS = VAR(((=) VAR\(\(\(=