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, report undefined variabl...



details:   https://anonhg.NetBSD.org/src/rev/551bd417927f
branches:  trunk
changeset: 938724:551bd417927f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Sep 13 20:21:24 2020 +0000

description:
make(1): in lint mode, report undefined variables in conditions

diffstat:

 usr.bin/make/unit-tests/opt-debug-lint.exp |   1 +
 usr.bin/make/unit-tests/opt-debug-lint.mk  |  11 ++++++++++-
 usr.bin/make/var.c                         |  24 +++++++++++++++++++-----
 3 files changed, 30 insertions(+), 6 deletions(-)

diffs (80 lines):

diff -r 1fe7827f5a8f -r 551bd417927f usr.bin/make/unit-tests/opt-debug-lint.exp
--- a/usr.bin/make/unit-tests/opt-debug-lint.exp        Sun Sep 13 20:04:26 2020 +0000
+++ b/usr.bin/make/unit-tests/opt-debug-lint.exp        Sun Sep 13 20:21:24 2020 +0000
@@ -1,4 +1,5 @@
 make: "opt-debug-lint.mk" line 18: Variable "X" is undefined
+make: "opt-debug-lint.mk" line 40: Variable "UNDEF" is undefined
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1
diff -r 1fe7827f5a8f -r 551bd417927f usr.bin/make/unit-tests/opt-debug-lint.mk
--- a/usr.bin/make/unit-tests/opt-debug-lint.mk Sun Sep 13 20:04:26 2020 +0000
+++ b/usr.bin/make/unit-tests/opt-debug-lint.mk Sun Sep 13 20:21:24 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: opt-debug-lint.mk,v 1.2 2020/09/13 19:28:46 rillig Exp $
+# $NetBSD: opt-debug-lint.mk,v 1.3 2020/09/13 20:21:24 rillig Exp $
 #
 # Tests for the -dL command line option, which runs additional checks
 # to catch common mistakes, such as unclosed variable expressions.
@@ -32,5 +32,14 @@
 .  error
 .endif
 
+# Since 2020-09-13, Var_Parse properly reports errors for undefined variables,
+# but only in lint mode.  Before, it had only silently returned var_Error,
+# hoping for the caller to print an error message.  This resulted in the
+# well-known "Malformed conditional" error message, even though the
+# conditional was well-formed and the only error was an undefined variable.
+.if ${UNDEF}
+.  error
+.endif
+
 all:
        @:;
diff -r 1fe7827f5a8f -r 551bd417927f usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Sep 13 20:04:26 2020 +0000
+++ b/usr.bin/make/var.c        Sun Sep 13 20:21:24 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.517 2020/09/13 19:46:23 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.518 2020/09/13 20:21:24 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.517 2020/09/13 19:46:23 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.518 2020/09/13 20:21:24 rillig Exp $");
 
 #define VAR_DEBUG_IF(cond, fmt, ...)   \
     if (!(DEBUG(VAR) && (cond)))       \
@@ -3560,11 +3560,25 @@
                    free(varname);
                    *out_val = pstr;
                    return VPE_OK;
-               } else {
+               }
+
+               if ((eflags & VARE_UNDEFERR) && DEBUG(LINT)) {
+                   Parse_Error(PARSE_FATAL, "Variable \"%s\" is undefined",
+                               varname);
                    free(varname);
-                   *out_val = eflags & VARE_UNDEFERR ? var_Error : varNoError;
-                   return eflags & VARE_UNDEFERR ? VPE_UNDEF_SILENT : VPE_OK;
+                   *out_val = var_Error;
+                   return VPE_UNDEF_MSG;
                }
+
+               if (eflags & VARE_UNDEFERR) {
+                   free(varname);
+                   *out_val = var_Error;
+                   return VPE_UNDEF_SILENT;
+               }
+
+               free(varname);
+               *out_val = varNoError;
+               return VPE_OK;
            }
 
            /* The variable expression is based on an undefined variable.



Home | Main Index | Thread Index | Old Index