Module Name: src
Committed By: sjg
Date: Thu Feb 9 07:34:15 UTC 2023
Modified Files:
src/usr.bin/make: var.c
src/usr.bin/make/unit-tests: varmod-remember.mk
Log Message:
make: ApplyModifier_Remember always use SCOPE_GLOBAL
Conditionals evaluate vars with SCOPE_CMDLINE, if :_
is used within a conditional expression and is thus
set in SCOPE_CMDLINE, it breaks any use of :_ in SCOPE_GLOBAL.
The simplest solution is for :_ to always use SCOPE_GLOBAL
Reviewed by: rillig
To generate a diff of this commit:
cvs rdiff -u -r1.1039 -r1.1040 src/usr.bin/make/var.c
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/varmod-remember.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.1039 src/usr.bin/make/var.c:1.1040
--- src/usr.bin/make/var.c:1.1039 Thu Jan 26 20:48:17 2023
+++ src/usr.bin/make/var.c Thu Feb 9 07:34:15 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.1039 2023/01/26 20:48:17 sjg Exp $ */
+/* $NetBSD: var.c,v 1.1040 2023/02/09 07:34:15 sjg 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.1039 2023/01/26 20:48:17 sjg Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1040 2023/02/09 07:34:15 sjg Exp $");
/*
* Variables are defined using one of the VAR=value assignments. Their
@@ -3578,7 +3578,7 @@ ApplyModifier_Remember(const char **pp,
*pp = mod + 1;
if (Expr_ShouldEval(expr))
- Var_Set(expr->scope, name.str, Expr_Str(expr));
+ Var_Set(SCOPE_GLOBAL, name.str, Expr_Str(expr));
FStr_Done(&name);
return AMR_OK;
Index: src/usr.bin/make/unit-tests/varmod-remember.mk
diff -u src/usr.bin/make/unit-tests/varmod-remember.mk:1.6 src/usr.bin/make/unit-tests/varmod-remember.mk:1.7
--- src/usr.bin/make/unit-tests/varmod-remember.mk:1.6 Sun Mar 14 17:27:27 2021
+++ src/usr.bin/make/unit-tests/varmod-remember.mk Thu Feb 9 07:34:15 2023
@@ -1,8 +1,14 @@
-# $NetBSD: varmod-remember.mk,v 1.6 2021/03/14 17:27:27 rillig Exp $
+# $NetBSD: varmod-remember.mk,v 1.7 2023/02/09 07:34:15 sjg Exp $
#
# Tests for the :_ modifier, which saves the current variable value
# in the _ variable or another, to be used later again.
+# this should result in "1=A 2=B 3=C"
+ABC= ${A B C:L:_:range:@i@$i=${_:[$i]}@}
+
+# we compare this with a repeat later
+x:= ${ABC}
+
.if ${1 2 3:L:_:@var@${_}@} != "1 2 3 1 2 3 1 2 3"
. error
.endif
@@ -32,4 +38,10 @@ S= INDIRECT_VARNAME
. error
.endif
+# we *should* get the same result as for $x above
+X:= ${ABC}
+.if $X != $x
+. error
+.endif
+
all: