Module Name: src
Committed By: rillig
Date: Fri Sep 4 20:28:16 UTC 2020
Modified Files:
src/usr.bin/make: var.c
src/usr.bin/make/unit-tests: cond-func-empty.mk
Log Message:
make(1): add more explanation for undefined variable expressions
To generate a diff of this commit:
cvs rdiff -u -r1.486 -r1.487 src/usr.bin/make/var.c
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/cond-func-empty.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/var.c
diff -u src/usr.bin/make/var.c:1.486 src/usr.bin/make/var.c:1.487
--- src/usr.bin/make/var.c:1.486 Thu Sep 3 18:53:46 2020
+++ src/usr.bin/make/var.c Fri Sep 4 20:28:15 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.486 2020/09/03 18:53:46 rillig Exp $ */
+/* $NetBSD: var.c,v 1.487 2020/09/04 20:28:15 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.486 2020/09/03 18:53:46 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.487 2020/09/04 20:28:15 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: var.c,v 1.486 2020/09/03 18:53:46 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.487 2020/09/04 20:28:15 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -3523,17 +3523,24 @@ Var_Parse(const char * const str, GNode
Buf_Destroy(&namebuf, TRUE);
return (eflags & VARE_UNDEFERR) ? var_Error : varNoError;
}
- } else {
- /*
- * Still need to get to the end of the variable specification,
- * so kludge up a Var structure for the modifications
- */
- v = bmake_malloc(sizeof(Var));
- v->name = varname;
- Buf_Init(&v->val, 1);
- v->flags = VAR_JUNK;
- Buf_Destroy(&namebuf, FALSE);
}
+
+ /* The variable expression is based on an undefined variable.
+ * Most modifiers leave this expression in the "undefined" state
+ * (VAR_JUNK), only some modifiers like :D, :U, :L, :P turn this
+ * undefined expression into a defined expression.
+ *
+ * At the end, after applying all modifiers, if the expression is
+ * still undefined after applying all the modifiers, var_Error is
+ * returned. Until then, the expression needs a variable struct,
+ * for all the modifiers that need access to the variable name,
+ * such as :L or :?.
+ */
+ v = bmake_malloc(sizeof(Var));
+ v->name = varname;
+ Buf_Init(&v->val, 1);
+ v->flags = VAR_JUNK;
+ Buf_Destroy(&namebuf, FALSE);
} else
Buf_Destroy(&namebuf, TRUE);
}
Index: src/usr.bin/make/unit-tests/cond-func-empty.mk
diff -u src/usr.bin/make/unit-tests/cond-func-empty.mk:1.3 src/usr.bin/make/unit-tests/cond-func-empty.mk:1.4
--- src/usr.bin/make/unit-tests/cond-func-empty.mk:1.3 Thu Sep 3 17:13:42 2020
+++ src/usr.bin/make/unit-tests/cond-func-empty.mk Fri Sep 4 20:28:16 2020
@@ -1,4 +1,4 @@
-# $NetBSD: cond-func-empty.mk,v 1.3 2020/09/03 17:13:42 rillig Exp $
+# $NetBSD: cond-func-empty.mk,v 1.4 2020/09/04 20:28:16 rillig Exp $
#
# Tests for the empty() function in .if conditions, which tests a variable
# expression for emptiness.
@@ -29,6 +29,9 @@ WORD= word
# after that the expression is no longer empty. Because the variable
# was undefined in the first place, the expression has the flag VAR_JUNK
# but not VAR_KEEP, therefore it is still considered undefined.
+# Only very few variable modifiers turn an undefined variable expression
+# into a defined variable expression. The :U and :D modifiers belong to
+# that group, but :S doesn't (see VAR_KEEP).
#
# XXX: This is hard to explain to someone who doesn't know these
# implementation details.