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): negate discardUndefined to preserveUnd...



details:   https://anonhg.NetBSD.org/src/rev/79fb0c896b83
branches:  trunk
changeset: 942026:79fb0c896b83
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Nov 04 04:49:32 2020 +0000

description:
make(1): negate discardUndefined to preserveUndefined

diffstat:

 usr.bin/make/main.c                          |   8 +++-----
 usr.bin/make/make.h                          |  13 +++++++------
 usr.bin/make/parse.c                         |  21 +++++++++++++++------
 usr.bin/make/unit-tests/cmdline-undefined.mk |  12 ++++++------
 usr.bin/make/var.c                           |  11 ++++++++---
 5 files changed, 39 insertions(+), 26 deletions(-)

diffs (176 lines):

diff -r bbedc5b78bfa -r 79fb0c896b83 usr.bin/make/main.c
--- a/usr.bin/make/main.c       Wed Nov 04 04:47:56 2020 +0000
+++ b/usr.bin/make/main.c       Wed Nov 04 04:49:32 2020 +0000
@@ -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 @@
 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 @@
                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
diff -r bbedc5b78bfa -r 79fb0c896b83 usr.bin/make/make.h
--- a/usr.bin/make/make.h       Wed Nov 04 04:47:56 2020 +0000
+++ b/usr.bin/make/make.h       Wed Nov 04 04:49:32 2020 +0000
@@ -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 @@
                                 * 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 @@
  *     # 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. */
diff -r bbedc5b78bfa -r 79fb0c896b83 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Wed Nov 04 04:47:56 2020 +0000
+++ b/usr.bin/make/parse.c      Wed Nov 04 04:49:32 2020 +0000
@@ -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 @@
 {
     const char *avalue = uvalue;
     char *evalue;
-    Boolean savedDiscardUndefined = discardUndefined;
-
-    discardUndefined = FALSE;
+    Boolean savedPreserveUndefined = preserveUndefined;
+
+    /* 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 @@
 
     (void)Var_Subst(uvalue, ctxt, VARE_WANTRES|VARE_ASSIGN, &evalue);
     /* TODO: handle errors */
-    discardUndefined = savedDiscardUndefined;
+    preserveUndefined = savedPreserveUndefined;
     avalue = evalue;
     Var_Set(name, avalue, ctxt);
 
diff -r bbedc5b78bfa -r 79fb0c896b83 usr.bin/make/unit-tests/cmdline-undefined.mk
--- a/usr.bin/make/unit-tests/cmdline-undefined.mk      Wed Nov 04 04:47:56 2020 +0000
+++ b/usr.bin/make/unit-tests/cmdline-undefined.mk      Wed Nov 04 04:49:32 2020 +0000
@@ -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}.'
diff -r bbedc5b78bfa -r 79fb0c896b83 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Wed Nov 04 04:47:56 2020 +0000
+++ b/usr.bin/make/var.c        Wed Nov 04 04:49:32 2020 +0000
@@ -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 @@
            /* 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



Home | Main Index | Thread Index | Old Index