Module Name:    src
Committed By:   rillig
Date:           Sun Feb  4 10:03:10 UTC 2024

Modified Files:
        src/usr.bin/make: var.c
        src/usr.bin/make/unit-tests: varmod-indirect.exp varmod-indirect.mk

Log Message:
make: do not evaluate indirect modifiers in parse-only mode

Discovered by sjg.


To generate a diff of this commit:
cvs rdiff -u -r1.1097 -r1.1098 src/usr.bin/make/var.c
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/make/unit-tests/varmod-indirect.exp
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/make/unit-tests/varmod-indirect.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.1097 src/usr.bin/make/var.c:1.1098
--- src/usr.bin/make/var.c:1.1097	Sun Feb  4 09:56:24 2024
+++ src/usr.bin/make/var.c	Sun Feb  4 10:03:10 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.1097 2024/02/04 09:56:24 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.1098 2024/02/04 10:03:10 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1097 2024/02/04 09:56:24 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1098 2024/02/04 10:03:10 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -3863,7 +3863,7 @@ ApplyModifiersIndirect(ModChain *ch, con
 	DEBUG3(VAR, "Indirect modifier \"%s\" from \"%.*s\"\n",
 	    mods.str, (int)(p - *pp), *pp);
 
-	if (mods.str[0] != '\0') {
+	if (ModChain_ShouldEval(ch) && mods.str[0] != '\0') {
 		const char *modsp = mods.str;
 		ApplyModifiers(expr, &modsp, '\0', '\0');
 		if (Expr_Str(expr) == var_Error || *modsp != '\0') {

Index: src/usr.bin/make/unit-tests/varmod-indirect.exp
diff -u src/usr.bin/make/unit-tests/varmod-indirect.exp:1.26 src/usr.bin/make/unit-tests/varmod-indirect.exp:1.27
--- src/usr.bin/make/unit-tests/varmod-indirect.exp:1.26	Sun Feb  4 09:56:24 2024
+++ src/usr.bin/make/unit-tests/varmod-indirect.exp	Sun Feb  4 10:03:10 2024
@@ -38,12 +38,6 @@ 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
-make: "varmod-indirect.mk" line 275: Unknown modifier "Z"
-make: "varmod-indirect.mk" line 275: Malformed conditional (0 && ${VAR:${M_invalid}})
-make: "varmod-indirect.mk" line 282: Unknown modifier "Z"
-make: "varmod-indirect.mk" line 282: Malformed conditional (0 && ${VAR:${M_invalid:S,^,N*,:ts:}})
-make: "varmod-indirect.mk" line 288: Unknown modifier "Z"
-make: "varmod-indirect.mk" line 288: Malformed conditional (0 && ${VAR:${M_invalid:@m@N*$m@:ts:}})
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/varmod-indirect.mk
diff -u src/usr.bin/make/unit-tests/varmod-indirect.mk:1.17 src/usr.bin/make/unit-tests/varmod-indirect.mk:1.18
--- src/usr.bin/make/unit-tests/varmod-indirect.mk:1.17	Sun Feb  4 09:56:24 2024
+++ src/usr.bin/make/unit-tests/varmod-indirect.mk	Sun Feb  4 10:03:10 2024
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-indirect.mk,v 1.17 2024/02/04 09:56:24 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
@@ -258,7 +258,7 @@ _:=	before ${UNDEF:${:UZ}} after
 
 # In parse-only mode, the indirect modifiers must not be evaluated.
 #
-# Before var.c TODO from 2024-02-04, the expression for an indirect modifier
+# 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.
 #
@@ -270,20 +270,13 @@ _:=	before ${UNDEF:${:UZ}} after
 # 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
-# expect+2: Unknown modifier "Z"
-# expect+1: Malformed conditional (0 && ${VAR:${M_invalid}})
 .if 0 && ${VAR:${M_invalid}}
 .endif
-# The expression ${M_invalid} starts with the value "Z", and if its modifiers
-# were evaluated, would result in "N*Z", which is a valid modifier.  The
-# modifiers were not applied though, keeping the invalid value "Z".
-# expect+2: Unknown modifier "Z"
-# expect+1: Malformed conditional (0 && ${VAR:${M_invalid:S,^,N*,:ts:}})
+# 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".
-# expect+2: Unknown modifier "Z"
-# expect+1: Malformed conditional (0 && ${VAR:${M_invalid:@m@N*$m@:ts:}})
+# keeping the "Z", which is then skipped in parse-only mode.
 .if 0 && ${VAR:${M_invalid:@m@N*$m@:ts:}}
 .endif

Reply via email to