Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make make(1): replace global preserveUndefined with ...
details: https://anonhg.NetBSD.org/src/rev/511b1e7400c3
branches: trunk
changeset: 979406:511b1e7400c3
user: rillig <rillig%NetBSD.org@localhost>
date: Mon Dec 28 00:46:24 2020 +0000
description:
make(1): replace global preserveUndefined with VARE_KEEP_UNDEF
Controlling the expansion of variable expressions using a global
variable and a VARE flag was inconsistent.
Converting the global variable into a flag had to prerequisites:
1. The unintended duplicate variable assignment had to be fixed, as
done in parse.c 1.520 from 2020-12-27. Without this fix, it would have
been necessary to add more flags to Var_Exists and Var_SetWithFlags, and
this would have become too complex.
2. There had to be a unit test demonstrating that VARE_KEEP_DOLLAR only
applies to the top-level expression and is not passed to the
subexpressions, while VARE_KEEP_UNDEF applies to all subexpressions as
well. This test is in var-op-expand.mk 1.10 from 2020-12-28, at least
for the ':@word@' modifier. In ParseModifierPartSubst, VARE_KEEP_UNDEF
is not passed down either, in the same way.
diffstat:
usr.bin/make/enum.h | 13 ++++++-
usr.bin/make/main.c | 5 +-
usr.bin/make/make.h | 17 +--------
usr.bin/make/nonints.h | 17 +++++++-
usr.bin/make/parse.c | 10 ++---
usr.bin/make/unit-tests/varmod-defined.exp | 18 ++++----
usr.bin/make/unit-tests/varmod-indirect.exp | 52 +++++++++++++-------------
usr.bin/make/unit-tests/varname-dot-shell.exp | 2 +-
usr.bin/make/var.c | 11 +++--
9 files changed, 76 insertions(+), 69 deletions(-)
diffs (truncated from 313 to 300 lines):
diff -r 4ec254e80847 -r 511b1e7400c3 usr.bin/make/enum.h
--- a/usr.bin/make/enum.h Mon Dec 28 00:19:41 2020 +0000
+++ b/usr.bin/make/enum.h Mon Dec 28 00:46:24 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: enum.h,v 1.12 2020/09/25 15:54:50 rillig Exp $ */
+/* $NetBSD: enum.h,v 1.13 2020/12/28 00:46:24 rillig Exp $ */
/*
Copyright (c) 2020 Roland Illig <rillig%NetBSD.org@localhost>
@@ -130,6 +130,17 @@
ENUM__JOIN_STR_1(v3)))
/* Declare the necessary data structures for calling Enum_FlagsToString
+ * for an enum with 4 flags. */
+#define ENUM_FLAGS_RTTI_4(typnam, v1, v2, v3, v4) \
+ ENUM__FLAGS_RTTI(typnam, \
+ ENUM__SPECS_2( \
+ ENUM__SPEC_2(v1, v2), \
+ ENUM__SPEC_2(v3, v4)), \
+ ENUM__JOIN_2( \
+ ENUM__JOIN_STR_2(v1, v2), \
+ ENUM__JOIN_STR_2(v3, v4)))
+
+/* Declare the necessary data structures for calling Enum_FlagsToString
* for an enum with 6 flags. */
#define ENUM_FLAGS_RTTI_6(typnam, v1, v2, v3, v4, v5, v6) \
ENUM__FLAGS_RTTI(typnam, \
diff -r 4ec254e80847 -r 511b1e7400c3 usr.bin/make/main.c
--- a/usr.bin/make/main.c Mon Dec 28 00:19:41 2020 +0000
+++ b/usr.bin/make/main.c Mon Dec 28 00:46:24 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.505 2020/12/27 11:47:04 rillig Exp $ */
+/* $NetBSD: main.c,v 1.506 2020/12/28 00:46:24 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
#include "trace.h"
/* "@(#)main.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.505 2020/12/27 11:47:04 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.506 2020/12/28 00:46:24 rillig Exp $");
#if defined(MAKE_NATIVE) && !defined(lint)
__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
"The Regents of the University of California. "
@@ -125,7 +125,6 @@
static int maxJobTokens; /* -j argument */
Boolean enterFlagObj; /* -w and objdir != srcdir */
-Boolean preserveUndefined;
static int jp_0 = -1, jp_1 = -1; /* ends of parent job pipe */
Boolean doing_depend; /* Set while reading .depend */
static Boolean jobsRunning; /* TRUE if the jobs might be running */
diff -r 4ec254e80847 -r 511b1e7400c3 usr.bin/make/make.h
--- a/usr.bin/make/make.h Mon Dec 28 00:19:41 2020 +0000
+++ b/usr.bin/make/make.h Mon Dec 28 00:46:24 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: make.h,v 1.239 2020/12/23 14:05:32 rillig Exp $ */
+/* $NetBSD: make.h,v 1.240 2020/12/28 00:46:24 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -496,21 +496,6 @@
/* The time at the start of this whole process */
extern time_t now;
-/*
- * If FALSE (the default behavior), undefined subexpressions in a variable
- * expression are discarded. If TRUE (only during variable assignments using
- * the ':=' assignment operator, no matter how deeply nested), they are
- * preserved and possibly expanded later when the variable from the
- * subexpression has been defined.
- *
- * Example for a ':=' assignment:
- * CFLAGS = $(.INCLUDES)
- * CFLAGS := -I.. $(CFLAGS)
- * # If .INCLUDES (an undocumented special variable, by the way) is
- * # still undefined, the updated CFLAGS becomes "-I.. $(.INCLUDES)".
- */
-extern Boolean preserveUndefined;
-
/* The list of directories to search when looking for targets (set by the
* special target .PATH). */
extern SearchPath dirSearchPath;
diff -r 4ec254e80847 -r 511b1e7400c3 usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h Mon Dec 28 00:19:41 2020 +0000
+++ b/usr.bin/make/nonints.h Mon Dec 28 00:46:24 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nonints.h,v 1.185 2020/12/27 14:02:12 rillig Exp $ */
+/* $NetBSD: nonints.h,v 1.186 2020/12/28 00:46:24 rillig Exp $ */
/*-
* Copyright (c) 1988, 1989, 1990, 1993
@@ -302,7 +302,20 @@
* See also preserveUndefined, which preserves subexpressions that are
* based on undefined variables; maybe that can be converted to a flag
* as well. */
- VARE_KEEP_DOLLAR = 1 << 2
+ VARE_KEEP_DOLLAR = 1 << 2,
+
+ /*
+ * Keep undefined variables as-is instead of expanding them to an
+ * empty string.
+ *
+ * Example for a ':=' assignment:
+ * CFLAGS = $(.INCLUDES)
+ * CFLAGS := -I.. $(CFLAGS)
+ * # If .INCLUDES (an undocumented special variable, by the
+ * # way) is still undefined, the updated CFLAGS becomes
+ * # "-I.. $(.INCLUDES)".
+ */
+ VARE_KEEP_UNDEF = 1 << 3
} VarEvalFlags;
typedef enum VarSetFlags {
diff -r 4ec254e80847 -r 511b1e7400c3 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c Mon Dec 28 00:19:41 2020 +0000
+++ b/usr.bin/make/parse.c Mon Dec 28 00:46:24 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.520 2020/12/27 22:29:37 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.521 2020/12/28 00:46:24 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -117,7 +117,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.520 2020/12/27 22:29:37 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.521 2020/12/28 00:46:24 rillig Exp $");
/* types and constants */
@@ -1929,7 +1929,6 @@
{
const char *avalue;
char *evalue;
- Boolean savedPreserveUndefined = preserveUndefined;
/*
* make sure that we set the variable the first time to nothing
@@ -1938,9 +1937,8 @@
if (!Var_Exists(name, ctxt))
Var_Set(name, "", ctxt);
- preserveUndefined = TRUE;
- (void)Var_Subst(uvalue, ctxt, VARE_WANTRES | VARE_KEEP_DOLLAR, &evalue);
- preserveUndefined = savedPreserveUndefined;
+ (void)Var_Subst(uvalue, ctxt,
+ VARE_WANTRES | VARE_KEEP_DOLLAR | VARE_KEEP_UNDEF, &evalue);
/* TODO: handle errors */
avalue = evalue;
diff -r 4ec254e80847 -r 511b1e7400c3 usr.bin/make/unit-tests/varmod-defined.exp
--- a/usr.bin/make/unit-tests/varmod-defined.exp Mon Dec 28 00:19:41 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-defined.exp Mon Dec 28 00:46:24 2020 +0000
@@ -1,22 +1,22 @@
Global:8_DOLLARS = $$$$$$$$
Global:VAR =
-Var_Parse: ${8_DOLLARS} with VARE_WANTRES|VARE_KEEP_DOLLAR
+Var_Parse: ${8_DOLLARS} with VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF
Global:VAR = $$$$$$$$
-Var_Parse: ${VAR:D${8_DOLLARS}} with VARE_WANTRES|VARE_KEEP_DOLLAR
-Applying ${VAR:D...} to "$$$$$$$$" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, none)
-Var_Parse: ${8_DOLLARS}} with VARE_WANTRES|VARE_KEEP_DOLLAR
-Result of ${VAR:D${8_DOLLARS}} is "$$$$$$$$" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, none)
+Var_Parse: ${VAR:D${8_DOLLARS}} with VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF
+Applying ${VAR:D...} to "$$$$$$$$" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, none)
+Var_Parse: ${8_DOLLARS}} with VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF
+Result of ${VAR:D${8_DOLLARS}} is "$$$$$$$$" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, none)
Global:VAR = $$$$$$$$
-Var_Parse: ${VAR:@var@${8_DOLLARS}@} with VARE_WANTRES|VARE_KEEP_DOLLAR
-Applying ${VAR:@...} to "$$$$$$$$" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, none)
+Var_Parse: ${VAR:@var@${8_DOLLARS}@} with VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF
+Applying ${VAR:@...} to "$$$$$$$$" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, none)
Modifier part: "var"
Modifier part: "${8_DOLLARS}"
ModifyWords: split "$$$$$$$$" into 1 words
Global:var = $$$$$$$$
-Var_Parse: ${8_DOLLARS} with VARE_WANTRES
+Var_Parse: ${8_DOLLARS} with VARE_WANTRES|VARE_KEEP_UNDEF
ModifyWord_Loop: in "$$$$$$$$", replace "var" with "${8_DOLLARS}" to "$$$$"
Global:delete var
-Result of ${VAR:@var@${8_DOLLARS}@} is "$$$$" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, none)
+Result of ${VAR:@var@${8_DOLLARS}@} is "$$$$" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, none)
Global:VAR = $$$$
Global:.MAKEFLAGS = -r -k -d v -d
Global:.MAKEFLAGS = -r -k -d v -d 0
diff -r 4ec254e80847 -r 511b1e7400c3 usr.bin/make/unit-tests/varmod-indirect.exp
--- a/usr.bin/make/unit-tests/varmod-indirect.exp Mon Dec 28 00:19:41 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-indirect.exp Mon Dec 28 00:46:24 2020 +0000
@@ -10,45 +10,45 @@
make: "varmod-indirect.mk" line 125: after
ParseReadLine (134): '_:= before ${UNDEF} after'
Global:_ =
-Var_Parse: ${UNDEF} after with VARE_WANTRES|VARE_KEEP_DOLLAR
+Var_Parse: ${UNDEF} after with VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF
Global:_ = before ${UNDEF} after
ParseReadLine (137): '_:= before ${UNDEF:${:US,a,a,}} after'
-Var_Parse: ${UNDEF:${:US,a,a,}} after with VARE_WANTRES|VARE_KEEP_DOLLAR
-Var_Parse: ${:US,a,a,}} after with VARE_WANTRES|VARE_KEEP_DOLLAR
-Applying ${:U...} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF)
-Result of ${:US,a,a,} is "S,a,a," (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF|VEF_DEF)
+Var_Parse: ${UNDEF:${:US,a,a,}} after with VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF
+Var_Parse: ${:US,a,a,}} after with VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF
+Applying ${:U...} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VEF_UNDEF)
+Result of ${:US,a,a,} is "S,a,a," (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VEF_UNDEF|VEF_DEF)
Indirect modifier "S,a,a," from "${:US,a,a,}"
-Applying ${UNDEF:S...} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF)
+Applying ${UNDEF:S...} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VEF_UNDEF)
Modifier part: "a"
Modifier part: "a"
ModifyWords: split "" into 1 words
-Result of ${UNDEF:S,a,a,} is "" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF)
-Var_Parse: ${:US,a,a,}} after with VARE_WANTRES|VARE_KEEP_DOLLAR
-Applying ${:U...} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF)
-Result of ${:US,a,a,} is "S,a,a," (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF|VEF_DEF)
+Result of ${UNDEF:S,a,a,} is "" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VEF_UNDEF)
+Var_Parse: ${:US,a,a,}} after with VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF
+Applying ${:U...} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VEF_UNDEF)
+Result of ${:US,a,a,} is "S,a,a," (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VEF_UNDEF|VEF_DEF)
Global:_ = before ${UNDEF:S,a,a,} after
ParseReadLine (147): '_:= before ${UNDEF:${:U}} after'
-Var_Parse: ${UNDEF:${:U}} after with VARE_WANTRES|VARE_KEEP_DOLLAR
-Var_Parse: ${:U}} after with VARE_WANTRES|VARE_KEEP_DOLLAR
-Applying ${:U} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF)
-Result of ${:U} is "" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF|VEF_DEF)
+Var_Parse: ${UNDEF:${:U}} after with VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF
+Var_Parse: ${:U}} after with VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF
+Applying ${:U} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VEF_UNDEF)
+Result of ${:U} is "" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VEF_UNDEF|VEF_DEF)
Indirect modifier "" from "${:U}"
-Var_Parse: ${:U}} after with VARE_WANTRES|VARE_KEEP_DOLLAR
-Applying ${:U} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF)
-Result of ${:U} is "" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF|VEF_DEF)
+Var_Parse: ${:U}} after with VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF
+Applying ${:U} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VEF_UNDEF)
+Result of ${:U} is "" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VEF_UNDEF|VEF_DEF)
Global:_ = before ${UNDEF:} after
ParseReadLine (152): '_:= before ${UNDEF:${:UZ}} after'
-Var_Parse: ${UNDEF:${:UZ}} after with VARE_WANTRES|VARE_KEEP_DOLLAR
-Var_Parse: ${:UZ}} after with VARE_WANTRES|VARE_KEEP_DOLLAR
-Applying ${:U...} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF)
-Result of ${:UZ} is "Z" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF|VEF_DEF)
+Var_Parse: ${UNDEF:${:UZ}} after with VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF
+Var_Parse: ${:UZ}} after with VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF
+Applying ${:U...} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VEF_UNDEF)
+Result of ${:UZ} is "Z" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VEF_UNDEF|VEF_DEF)
Indirect modifier "Z" from "${:UZ}"
-Applying ${UNDEF:Z} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF)
+Applying ${UNDEF:Z} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VEF_UNDEF)
make: "varmod-indirect.mk" line 152: Unknown modifier 'Z'
-Result of ${UNDEF:Z} is error (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF)
-Var_Parse: ${:UZ}} after with VARE_WANTRES|VARE_KEEP_DOLLAR
-Applying ${:U...} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF)
-Result of ${:UZ} is "Z" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF|VEF_DEF)
+Result of ${UNDEF:Z} is error (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VEF_UNDEF)
+Var_Parse: ${:UZ}} after with VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF
+Applying ${:U...} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VEF_UNDEF)
+Result of ${:UZ} is "Z" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VEF_UNDEF|VEF_DEF)
Global:_ = before ${UNDEF:Z} after
ParseReadLine (154): '.MAKEFLAGS: -d0'
ParseDoDependency(.MAKEFLAGS: -d0)
diff -r 4ec254e80847 -r 511b1e7400c3 usr.bin/make/unit-tests/varname-dot-shell.exp
--- a/usr.bin/make/unit-tests/varname-dot-shell.exp Mon Dec 28 00:19:41 2020 +0000
+++ b/usr.bin/make/unit-tests/varname-dot-shell.exp Mon Dec 28 00:46:24 2020 +0000
@@ -1,6 +1,6 @@
ParseReadLine (10): 'ORIG_SHELL:= ${.SHELL}'
Global:ORIG_SHELL =
-Var_Parse: ${.SHELL} with VARE_WANTRES|VARE_KEEP_DOLLAR
+Var_Parse: ${.SHELL} with VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF
Global:delete .SHELL (not found)
Command:.SHELL = (details omitted)
Global:ORIG_SHELL = (details omitted)
diff -r 4ec254e80847 -r 511b1e7400c3 usr.bin/make/var.c
--- a/usr.bin/make/var.c Mon Dec 28 00:19:41 2020 +0000
+++ b/usr.bin/make/var.c Mon Dec 28 00:46:24 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.773 2020/12/27 16:31:58 rillig Exp $ */
+/* $NetBSD: var.c,v 1.774 2020/12/28 00:46:24 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.773 2020/12/27 16:31:58 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.774 2020/12/28 00:46:24 rillig Exp $");
typedef enum VarFlags {
VAR_NONE = 0,
@@ -243,8 +243,9 @@
} SepBuf;
-ENUM_FLAGS_RTTI_3(VarEvalFlags,
- VARE_UNDEFERR, VARE_WANTRES, VARE_KEEP_DOLLAR);
+ENUM_FLAGS_RTTI_4(VarEvalFlags,
+ VARE_UNDEFERR, VARE_WANTRES, VARE_KEEP_DOLLAR,
Home |
Main Index |
Thread Index |
Old Index