Module Name:    src
Committed By:   rillig
Date:           Mon Sep 14 07:04:56 UTC 2020

Modified Files:
        src/usr.bin/make: var.c
        src/usr.bin/make/unit-tests: cond-undef-lint.exp

Log Message:
make(1): don't require nested variables to be defined in conditions

This code only applies to lint mode (-dL) for now.  After a test phase
and a thorough check for possible side effects, it will be activated in
normal mode, too.  Having this code in lint mode is required to run
src/build.sh, which relies a lot on using variables with undefined
nested variables in conditions.

In the default mode, any errors about nested undefined variables are not
printed since in Var_Subst, oldVars is true.  Therefore, it is not urgent
to properly handle these nested variables correctly there.


To generate a diff of this commit:
cvs rdiff -u -r1.519 -r1.520 src/usr.bin/make/var.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/cond-undef-lint.exp

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.519 src/usr.bin/make/var.c:1.520
--- src/usr.bin/make/var.c:1.519	Sun Sep 13 21:03:14 2020
+++ src/usr.bin/make/var.c	Mon Sep 14 07:04:56 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.519 2020/09/13 21:03:14 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.520 2020/09/14 07:04:56 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -121,7 +121,7 @@
 #include    "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.519 2020/09/13 21:03:14 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.520 2020/09/14 07:04:56 rillig Exp $");
 
 #define VAR_DEBUG_IF(cond, fmt, ...)	\
     if (!(DEBUG(VAR) && (cond)))	\
@@ -3618,7 +3618,10 @@ Var_Parse(const char **pp, GNode *ctxt, 
      */
     nstr = Buf_GetAll(&v->val, NULL);
     if (strchr(nstr, '$') != NULL && (eflags & VARE_WANTRES)) {
-	nstr = Var_Subst(nstr, ctxt, eflags);
+        VarEvalFlags nested_eflags = eflags;
+        if (DEBUG(LINT))
+            nested_eflags &= ~(unsigned)VARE_UNDEFERR;
+	nstr = Var_Subst(nstr, ctxt, nested_eflags);
 	*freePtr = nstr;
     }
 

Index: src/usr.bin/make/unit-tests/cond-undef-lint.exp
diff -u src/usr.bin/make/unit-tests/cond-undef-lint.exp:1.1 src/usr.bin/make/unit-tests/cond-undef-lint.exp:1.2
--- src/usr.bin/make/unit-tests/cond-undef-lint.exp:1.1	Mon Sep 14 06:44:50 2020
+++ src/usr.bin/make/unit-tests/cond-undef-lint.exp	Mon Sep 14 07:04:56 2020
@@ -2,7 +2,6 @@ make: "cond-undef-lint.mk" line 20: Vari
 make: "cond-undef-lint.mk" line 35: Variable "UNDEF" is undefined
 make: "cond-undef-lint.mk" line 35: Variable "VAR." is undefined
 make: "cond-undef-lint.mk" line 42: Variable "VAR.defined" is undefined
-make: "cond-undef-lint.mk" line 66: Variable "NESTED_UNDEF" is undefined
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Reply via email to