Module Name: src
Committed By: rillig
Date: Wed Nov 4 04:49:33 UTC 2020
Modified Files:
src/usr.bin/make: main.c make.h parse.c var.c
src/usr.bin/make/unit-tests: cmdline-undefined.mk
Log Message:
make(1): negate discardUndefined to preserveUndefined
To generate a diff of this commit:
cvs rdiff -u -r1.422 -r1.423 src/usr.bin/make/main.c
cvs rdiff -u -r1.182 -r1.183 src/usr.bin/make/make.h
cvs rdiff -u -r1.423 -r1.424 src/usr.bin/make/parse.c
cvs rdiff -u -r1.656 -r1.657 src/usr.bin/make/var.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/cmdline-undefined.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/main.c
diff -u src/usr.bin/make/main.c:1.422 src/usr.bin/make/main.c:1.423
--- src/usr.bin/make/main.c:1.422 Wed Nov 4 03:37:51 2020
+++ src/usr.bin/make/main.c Wed Nov 4 04:49:32 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.422 2020/11/04 03:37:51 rillig Exp $ */
+/* $NetBSD: main.c,v 1.423 2020/11/04 04:49:32 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -118,7 +118,7 @@
#include "trace.h"
/* "@(#)main.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.422 2020/11/04 03:37:51 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.423 2020/11/04 04:49:32 rillig Exp $");
#if defined(MAKE_NATIVE) && !defined(lint)
__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
"The Regents of the University of California. "
@@ -138,7 +138,7 @@ Boolean deleteOnError; /* .DELETE_ON_E
static int maxJobTokens; /* -j argument */
Boolean enterFlagObj; /* -w and objdir != srcdir */
-Boolean discardUndefined;
+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 */
@@ -640,8 +640,6 @@ rearg:
argc -= arginc;
}
- discardUndefined = TRUE;
-
/*
* See if the rest of the arguments are variable assignments and
* perform them if so. Else take them to be targets and stuff them
Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.182 src/usr.bin/make/make.h:1.183
--- src/usr.bin/make/make.h:1.182 Wed Nov 4 03:37:51 2020
+++ src/usr.bin/make/make.h Wed Nov 4 04:49:32 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: make.h,v 1.182 2020/11/04 03:37:51 rillig Exp $ */
+/* $NetBSD: make.h,v 1.183 2020/11/04 04:49:32 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -445,10 +445,11 @@ extern time_t now; /* The time at the s
* process */
/*
- * If TRUE (default behavior), undefined subexpressions in a variable
- * expression are discarded. If FALSE (only in variable assignments using the
- * ':=' assignment operator), they are preserved and possibly expanded later
- * when the variable from the subexpression has been defined.
+ * If FALSE (the default behavior), undefined subexpressions in a variable
+ * expression are discarded. If TRUE (only during variable assignments using
+ * the ':=' assignment operator, in the top-level expansion), they are
+ * preserved and possibly expanded later when the variable from the
+ * subexpression has been defined.
*
* Example for a ':=' assignment:
* CFLAGS = $(.INCLUDES)
@@ -456,7 +457,7 @@ extern time_t now; /* The time at the s
* # If .INCLUDES (an undocumented special variable, by the way) is
* # still undefined, the updated CFLAGS becomes "-I.. $(.INCLUDES)".
*/
-extern Boolean discardUndefined;
+extern Boolean preserveUndefined;
extern SearchPath *sysIncPath; /* The system include path. */
extern SearchPath *defSysIncPath; /* The default system include path. */
Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.423 src/usr.bin/make/parse.c:1.424
--- src/usr.bin/make/parse.c:1.423 Wed Nov 4 03:37:51 2020
+++ src/usr.bin/make/parse.c Wed Nov 4 04:49:32 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.423 2020/11/04 03:37:51 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.424 2020/11/04 04:49:32 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.423 2020/11/04 03:37:51 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.424 2020/11/04 04:49:32 rillig Exp $");
/* types and constants */
@@ -1919,9 +1919,18 @@ VarAssign_EvalSubst(const char *name, co
{
const char *avalue = uvalue;
char *evalue;
- Boolean savedDiscardUndefined = discardUndefined;
+ Boolean savedPreserveUndefined = preserveUndefined;
- discardUndefined = FALSE;
+ /* TODO: Can this assignment to preserveUndefined be moved further down
+ * to the actually interesting Var_Subst call, without affecting any
+ * edge cases?
+ *
+ * It might affect the implicit expansion of the variable name in the
+ * Var_Exists and Var_Set calls, even though it's unlikely that anyone
+ * cared about this edge case when adding this code. In addition,
+ * variable assignments should not refer to any undefined variables in
+ * the variable name. */
+ preserveUndefined = TRUE;
/*
* make sure that we set the variable the first time to nothing
@@ -1932,7 +1941,7 @@ VarAssign_EvalSubst(const char *name, co
(void)Var_Subst(uvalue, ctxt, VARE_WANTRES|VARE_ASSIGN, &evalue);
/* TODO: handle errors */
- discardUndefined = savedDiscardUndefined;
+ preserveUndefined = savedPreserveUndefined;
avalue = evalue;
Var_Set(name, avalue, ctxt);
Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.656 src/usr.bin/make/var.c:1.657
--- src/usr.bin/make/var.c:1.656 Wed Nov 4 04:24:57 2020
+++ src/usr.bin/make/var.c Wed Nov 4 04:49:32 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.656 2020/11/04 04:24:57 rillig Exp $ */
+/* $NetBSD: var.c,v 1.657 2020/11/04 04:49:32 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -130,7 +130,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.656 2020/11/04 04:24:57 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.657 2020/11/04 04:49:32 rillig Exp $");
#define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1)
#define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2)
@@ -3991,9 +3991,14 @@ Var_Subst(const char *str, GNode *ctxt,
/* TODO: handle errors */
if (val == var_Error || val == varUndefined) {
- if (discardUndefined) {
+ if (!preserveUndefined) {
p = nested_p;
} else if ((eflags & VARE_UNDEFERR) || val == var_Error) {
+ /* XXX: This condition is wrong. If val == var_Error,
+ * this doesn't necessarily mean there was an undefined
+ * variable. It could equally well be a parse error; see
+ * unit-tests/varmod-order.exp. */
+
/*
* If variable is undefined, complain and skip the
* variable. The complaint will stop us from doing anything
Index: src/usr.bin/make/unit-tests/cmdline-undefined.mk
diff -u src/usr.bin/make/unit-tests/cmdline-undefined.mk:1.1 src/usr.bin/make/unit-tests/cmdline-undefined.mk:1.2
--- src/usr.bin/make/unit-tests/cmdline-undefined.mk:1.1 Wed Nov 4 04:24:57 2020
+++ src/usr.bin/make/unit-tests/cmdline-undefined.mk Wed Nov 4 04:49:33 2020
@@ -1,13 +1,13 @@
-# $NetBSD: cmdline-undefined.mk,v 1.1 2020/11/04 04:24:57 rillig Exp $
+# $NetBSD: cmdline-undefined.mk,v 1.2 2020/11/04 04:49:33 rillig Exp $
#
# Tests for undefined variable expressions in the command line.
all:
- # When the command line is parsed during the initial call of
- # MainParseArgs, discardUndefined is still FALSE, therefore preserving
- # undefined subexpressions. This makes sense because at that early
- # stage, almost no variables are defined. On the other hand, the '='
- # assignment operator does not expand its right-hand side anyway.
+ # When the command line is parsed, variable assignments using the
+ # '=' assignment operator do get their variable name expanded
+ # (which probably occurs rarely in practice, if at all), but their
+ # variable value is not expanded, as usual.
+ #
@echo 'The = assignment operator'
@${.MAKE} -f ${MAKEFILE} print-undefined \
CMDLINE='Undefined is $${UNDEFINED}.'