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, improve error handling f...



details:   https://anonhg.NetBSD.org/src/rev/61d8f7ea3710
branches:  trunk
changeset: 938715:61d8f7ea3710
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Sep 13 19:28:46 2020 +0000

description:
make(1): in lint mode, improve error handling for undefined variables

It's a first step for improving the error message that make prints.

diffstat:

 usr.bin/make/unit-tests/opt-debug-lint.exp |   6 ++++-
 usr.bin/make/unit-tests/opt-debug-lint.mk  |  31 ++++++++++++++++++++++++++++-
 usr.bin/make/var.c                         |  10 +++++---
 3 files changed, 40 insertions(+), 7 deletions(-)

diffs (83 lines):

diff -r 021055538b5a -r 61d8f7ea3710 usr.bin/make/unit-tests/opt-debug-lint.exp
--- a/usr.bin/make/unit-tests/opt-debug-lint.exp        Sun Sep 13 19:16:22 2020 +0000
+++ b/usr.bin/make/unit-tests/opt-debug-lint.exp        Sun Sep 13 19:28:46 2020 +0000
@@ -1,1 +1,5 @@
-exit status 0
+make: "opt-debug-lint.mk" line 18: Variable "X" is undefined
+make: "opt-debug-lint.mk" line 18: Malformed conditional ($X)
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff -r 021055538b5a -r 61d8f7ea3710 usr.bin/make/unit-tests/opt-debug-lint.mk
--- a/usr.bin/make/unit-tests/opt-debug-lint.mk Sun Sep 13 19:16:22 2020 +0000
+++ b/usr.bin/make/unit-tests/opt-debug-lint.mk Sun Sep 13 19:28:46 2020 +0000
@@ -1,9 +1,36 @@
-# $NetBSD: opt-debug-lint.mk,v 1.1 2020/09/05 06:20:51 rillig Exp $
+# $NetBSD: opt-debug-lint.mk,v 1.2 2020/09/13 19:28:46 rillig Exp $
 #
 # Tests for the -dL command line option, which runs additional checks
 # to catch common mistakes, such as unclosed variable expressions.
  
-# TODO: Implementation
+.MAKEFLAGS: -dL
+
+# Since 2020-09-13, undefined variables that are used on the left-hand side
+# of a condition at parse time get a proper error message.  Before, the
+# error message was "Malformed conditional" only, which was wrong and
+# misleading.  The form of the condition is totally fine, it's the evaluation
+# that fails.
+#
+# TODO: Get rid of the "Malformed conditional" error message.
+# As long as the first error message is only printed in lint mode, it can
+# get tricky to keep track of the actually printed error messages and those
+# that still need to be printed.  That's probably a solvable problem though.
+.if $X
+.  error
+.endif
+
+# The dynamic variables like .TARGET are treated specially.  It does not make
+# sense to expand them in the global scope since they will never be defined
+# there under normal circumstances.  Therefore they expand to a string that
+# will later be expanded correctly, when the variable is evaluated again in
+# the scope of an actual target.
+#
+# Even though the "@" variable is not defined at this point, this is not an
+# error.  In all practical cases, this is no problem.  This particular test
+# case is made up and unrealistic.
+.if $@ != "\$(.TARGET)"
+.  error
+.endif
 
 all:
        @:;
diff -r 021055538b5a -r 61d8f7ea3710 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Sep 13 19:16:22 2020 +0000
+++ b/usr.bin/make/var.c        Sun Sep 13 19:28:46 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.515 2020/09/13 19:16:22 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.516 2020/09/13 19:28:46 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.515 2020/09/13 19:16:22 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.516 2020/09/13 19:28:46 rillig Exp $");
 
 #define VAR_DEBUG_IF(cond, fmt, ...)   \
     if (!(DEBUG(VAR) && (cond)))       \
@@ -3489,8 +3489,10 @@
        if (v == NULL) {
            *pp += 2;
 
-           *out_val = ShortVarValue(start[1], ctxt, eflags);
-           return eflags & VARE_UNDEFERR ? VPE_UNDEF_SILENT : VPE_OK;
+           *out_val = ShortVarValue(startc, ctxt, eflags);
+           if (DEBUG(LINT) && *out_val == var_Error)
+               Parse_Error(PARSE_FATAL, "Variable \"%s\" is undefined", name);
+           return eflags & VARE_UNDEFERR ? VPE_UNDEF_MSG : VPE_OK;
        } else {
            haveModifier = FALSE;
            p = start + 1;



Home | Main Index | Thread Index | Old Index