Module Name: src
Committed By: rillig
Date: Mon Sep 14 21:23:58 UTC 2020
Modified Files:
src/usr.bin/make: parse.c
src/usr.bin/make/unit-tests: opt-debug-lint.mk
Log Message:
make(1): in lint mode, allow undefined variables in dependency lines
This is needed to get past the first few seconds in a src/build.sh run.
The nest obstacle is src/tools/Makefile.gnuhost:30, where the variable
MODULE is undefined even though that file says in line 3 that MODULE is
expected to be set. It has been saying this since 2001, but since make
didn't have the corresponding check enabled, this didn't break the
build.
To generate a diff of this commit:
cvs rdiff -u -r1.319 -r1.320 src/usr.bin/make/parse.c
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/opt-debug-lint.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/parse.c
diff -u src/usr.bin/make/parse.c:1.319 src/usr.bin/make/parse.c:1.320
--- src/usr.bin/make/parse.c:1.319 Mon Sep 14 19:59:47 2020
+++ src/usr.bin/make/parse.c Mon Sep 14 21:23:58 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.319 2020/09/14 19:59:47 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.320 2020/09/14 21:23:58 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.319 2020/09/14 19:59:47 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.320 2020/09/14 21:23:58 rillig Exp $");
/* types and constants */
@@ -3067,10 +3067,40 @@ Parse_File(const char *name, int fd)
/*
* We now know it's a dependency line so it needs to have all
- * variables expanded before being parsed. Tell the variable
- * module to complain if some variable is undefined...
+ * variables expanded before being parsed.
+ *
+ * XXX: Ideally the dependency line would first be split into
+ * its left-hand side, dependency operator and right-hand side,
+ * and then each side would be expanded on its own. This would
+ * allow for the left-hand side to allow only defined variables
+ * and to allow variables on the right-hand side to be undefined
+ * as well.
+ *
+ * Parsing the line first would also prevent that targets
+ * generated from variable expressions are interpreted as the
+ * dependency operator, such as in "target${:U:} middle: source",
+ * in which the middle is interpreted as a source, not a target.
*/
- line = Var_Subst(line, VAR_CMD, VARE_UNDEFERR|VARE_WANTRES);
+ {
+ /* In lint mode, allow undefined variables to appear in
+ * dependency lines.
+ *
+ * Ideally, only the right-hand side would allow undefined
+ * variables since it is common to have no dependencies.
+ * Having undefined variables on the left-hand side is more
+ * unusual though. Since both sides are expanded in a single
+ * pass, there is not much choice what to do here.
+ *
+ * In normal mode, it does not matter whether undefined
+ * variables are allowed or not since as of 2020-09-14,
+ * Var_Parse does not print any parse errors in such a case.
+ * It simply returns the special empty string var_Error,
+ * which cannot be detected in the result of Var_Subst. */
+ VarEvalFlags eflags = DEBUG(LINT)
+ ? VARE_WANTRES
+ : VARE_UNDEFERR|VARE_WANTRES;
+ line = Var_Subst(line, VAR_CMD, eflags);
+ }
/*
* Need a list for the target nodes
Index: src/usr.bin/make/unit-tests/opt-debug-lint.mk
diff -u src/usr.bin/make/unit-tests/opt-debug-lint.mk:1.4 src/usr.bin/make/unit-tests/opt-debug-lint.mk:1.5
--- src/usr.bin/make/unit-tests/opt-debug-lint.mk:1.4 Mon Sep 14 07:13:29 2020
+++ src/usr.bin/make/unit-tests/opt-debug-lint.mk Mon Sep 14 21:23:58 2020
@@ -1,4 +1,4 @@
-# $NetBSD: opt-debug-lint.mk,v 1.4 2020/09/14 07:13:29 rillig Exp $
+# $NetBSD: opt-debug-lint.mk,v 1.5 2020/09/14 21:23:58 rillig Exp $
#
# Tests for the -dL command line option, which runs additional checks
# to catch common mistakes, such as unclosed variable expressions.
@@ -42,5 +42,10 @@
. error
.endif
+# Since 2020-09-14, dependency lines may contain undefined variables.
+# Before, undefined variables were forbidden, but this distinction was not
+# observable from the outside of the function Var_Parse.
+${UNDEF}: ${UNDEF}
+
all:
@:;