Module Name: src
Committed By: rillig
Date: Sun Feb 4 09:56:24 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: in parse-only mode, don't evaluate modifiers
Previously, the ':S', ':ts', ':tA' and ':from=to' modifiers were
evaluated in parse-only mode, unnecessarily. This is only noticeable
when an indirect modifier is evaluated in parse-only mode, which is
another bug that will be fixed in a follow-up commit.
To generate a diff of this commit:
cvs rdiff -u -r1.1096 -r1.1097 src/usr.bin/make/var.c
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/make/unit-tests/varmod-indirect.exp
cvs rdiff -u -r1.16 -r1.17 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.1096 src/usr.bin/make/var.c:1.1097
--- src/usr.bin/make/var.c:1.1096 Sat Feb 3 00:20:23 2024
+++ src/usr.bin/make/var.c Sun Feb 4 09:56:24 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.1096 2024/02/03 00:20:23 sjg Exp $ */
+/* $NetBSD: var.c,v 1.1097 2024/02/04 09:56:24 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.1096 2024/02/03 00:20:23 sjg Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1097 2024/02/04 09:56:24 rillig Exp $");
/*
* Variables are defined using one of the VAR=value assignments. Their
@@ -2274,6 +2274,9 @@ ModifyWords(ModChain *ch,
size_t i;
Substring word;
+ if (!ModChain_ShouldEval(ch))
+ return;
+
if (oneBigWord) {
SepBuf_Init(&result, ch->sep);
/* XXX: performance: Substring_InitStr calls strlen */
@@ -2806,8 +2809,7 @@ ApplyModifier_Mtime(const char **pp, Mod
goto invalid_argument;
*pp = p;
}
- if (ModChain_ShouldEval(ch))
- ModifyWords(ch, ModifyWord_Mtime, &args, ch->oneBigWord);
+ ModifyWords(ch, ModifyWord_Mtime, &args, ch->oneBigWord);
return args.rc;
invalid_argument:
@@ -3552,8 +3554,7 @@ ApplyModifier_WordFunc(const char **pp,
return AMR_UNKNOWN;
(*pp)++;
- if (ModChain_ShouldEval(ch))
- ModifyWords(ch, modifyWord, NULL, ch->oneBigWord);
+ ModifyWords(ch, modifyWord, NULL, ch->oneBigWord);
return AMR_OK;
}
Index: src/usr.bin/make/unit-tests/varmod-indirect.exp
diff -u src/usr.bin/make/unit-tests/varmod-indirect.exp:1.25 src/usr.bin/make/unit-tests/varmod-indirect.exp:1.26
--- src/usr.bin/make/unit-tests/varmod-indirect.exp:1.25 Sun Feb 4 09:29:50 2024
+++ src/usr.bin/make/unit-tests/varmod-indirect.exp Sun Feb 4 09:56:24 2024
@@ -40,8 +40,10 @@ Global: .MAKEFLAGS = -r -k -d 0 -d pv -
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 287: Unknown modifier "Z"
-make: "varmod-indirect.mk" line 287: Malformed conditional (0 && ${VAR:${M_invalid:@m@N*$m@:ts:}})
+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.16 src/usr.bin/make/unit-tests/varmod-indirect.mk:1.17
--- src/usr.bin/make/unit-tests/varmod-indirect.mk:1.16 Sun Feb 4 09:29:50 2024
+++ src/usr.bin/make/unit-tests/varmod-indirect.mk Sun Feb 4 09:56:24 2024
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-indirect.mk,v 1.16 2024/02/04 09:29:50 rillig Exp $
+# $NetBSD: varmod-indirect.mk,v 1.17 2024/02/04 09:56:24 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 1.1097 from 2024-02-04, the expression for an indirect modifier
+# Before var.c TODO 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.
#
@@ -277,7 +277,8 @@ M_invalid= Z
# 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".
-# FIXME: As of var.c 1.1096, the modifier ':S' _is_ actually evaluated.
+# expect+2: Unknown modifier "Z"
+# expect+1: Malformed conditional (0 && ${VAR:${M_invalid:S,^,N*,:ts:}})
.if 0 && ${VAR:${M_invalid:S,^,N*,:ts:}}
.endif
# The ':@' modifier does not change the expression value in parse-only mode,