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): in lint mode, allow undefined variable...
details: https://anonhg.NetBSD.org/src/rev/a7f6172a33c2
branches: trunk
changeset: 944017:a7f6172a33c2
user: rillig <rillig%NetBSD.org@localhost>
date: Mon Sep 14 21:23:58 2020 +0000
description:
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.
diffstat:
usr.bin/make/parse.c | 40 +++++++++++++++++++++++++++---
usr.bin/make/unit-tests/opt-debug-lint.mk | 7 ++++-
2 files changed, 41 insertions(+), 6 deletions(-)
diffs (82 lines):
diff -r 3c0602ca18ea -r a7f6172a33c2 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c Mon Sep 14 20:43:44 2020 +0000
+++ b/usr.bin/make/parse.c Mon Sep 14 21:23:58 2020 +0000
@@ -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 @@
/*
* 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
diff -r 3c0602ca18ea -r a7f6172a33c2 usr.bin/make/unit-tests/opt-debug-lint.mk
--- a/usr.bin/make/unit-tests/opt-debug-lint.mk Mon Sep 14 20:43:44 2020 +0000
+++ b/usr.bin/make/unit-tests/opt-debug-lint.mk Mon Sep 14 21:23:58 2020 +0000
@@ -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:
@:;
Home |
Main Index |
Thread Index |
Old Index