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): suppress wrong "Malformed conditional"...



details:   https://anonhg.NetBSD.org/src/rev/30f95a3645f2
branches:  trunk
changeset: 943947:30f95a3645f2
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Sep 13 19:46:23 2020 +0000

description:
make(1): suppress wrong "Malformed conditional" for undefined variables

This only has an effect in lint mode right now.

diffstat:

 usr.bin/make/cond.c                        |  18 ++++++++++++++----
 usr.bin/make/nonints.h                     |   7 +++++--
 usr.bin/make/unit-tests/opt-debug-lint.exp |   1 -
 usr.bin/make/var.c                         |  12 +++++++-----
 4 files changed, 26 insertions(+), 12 deletions(-)

diffs (128 lines):

diff -r c87afea9cde4 -r 30f95a3645f2 usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Sun Sep 13 19:28:46 2020 +0000
+++ b/usr.bin/make/cond.c       Sun Sep 13 19:46:23 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.145 2020/09/13 18:27:39 rillig Exp $        */
+/*     $NetBSD: cond.c,v 1.146 2020/09/13 19:46:23 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -93,7 +93,7 @@
 #include "dir.h"
 
 /*     "@(#)cond.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: cond.c,v 1.145 2020/09/13 18:27:39 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.146 2020/09/13 19:46:23 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -142,6 +142,12 @@
     const struct If *if_info;  /* Info for current statement */
     const char *p;             /* The remaining condition to parse */
     Token curr;                        /* Single push-back token used in parsing */
+
+    /* Whether an error message has already been printed for this condition.
+     * The first available error message is usually the most specific one,
+     * therefore it makes sense to suppress the standard "Malformed
+     * conditional" message. */
+    Boolean printedError;
 } CondParser;
 
 static Token CondParser_Expr(CondParser *par, Boolean);
@@ -411,6 +417,7 @@
     Boolean qt;
     const char *start;
     VarEvalFlags eflags;
+    VarParseErrors errors;
 
     Buf_Init(&buf, 0);
     str = NULL;
@@ -454,9 +461,11 @@
                     (doEval ? VARE_WANTRES : 0);
            nested_p = par->p;
            atStart = nested_p == start;
-           (void)Var_Parse(&nested_p, VAR_CMD, eflags, &str, freeIt);
+           errors = Var_Parse(&nested_p, VAR_CMD, eflags, &str, freeIt);
            /* TODO: handle errors */
            if (str == var_Error) {
+               if (errors & VPE_ANY_MSG)
+                   par->printedError = TRUE;
                if (*freeIt) {
                    free(*freeIt);
                    *freeIt = NULL;
@@ -1038,10 +1047,11 @@
     par.if_info = info;
     par.p = cond;
     par.curr = TOK_NONE;
+    par.printedError = FALSE;
 
     rval = CondParser_Eval(&par, value);
 
-    if (rval == COND_INVALID && eprint)
+    if (rval == COND_INVALID && eprint && !par.printedError)
        Parse_Error(PARSE_FATAL, "Malformed conditional (%s)", cond);
 
     return rval;
diff -r c87afea9cde4 -r 30f95a3645f2 usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Sun Sep 13 19:28:46 2020 +0000
+++ b/usr.bin/make/nonints.h    Sun Sep 13 19:46:23 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nonints.h,v 1.120 2020/09/13 19:16:22 rillig Exp $     */
+/*     $NetBSD: nonints.h,v 1.121 2020/09/13 19:46:23 rillig Exp $     */
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -258,7 +258,10 @@
      *
      * This should never happen since it is impossible to say where
      * exactly the evaluation error occurred. */
-    VPE_EVAL_SILENT    = 0x0200
+    VPE_EVAL_SILENT    = 0x0200,
+
+    /* See if a message has already been printed for this error. */
+    VPE_ANY_MSG                = VPE_PARSE_MSG | VPE_UNDEF_MSG | VPE_EVAL_MSG
 } VarParseErrors;
 
 void Var_Delete(const char *, GNode *);
diff -r c87afea9cde4 -r 30f95a3645f2 usr.bin/make/unit-tests/opt-debug-lint.exp
--- a/usr.bin/make/unit-tests/opt-debug-lint.exp        Sun Sep 13 19:28:46 2020 +0000
+++ b/usr.bin/make/unit-tests/opt-debug-lint.exp        Sun Sep 13 19:46:23 2020 +0000
@@ -1,5 +1,4 @@
 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 c87afea9cde4 -r 30f95a3645f2 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Sep 13 19:28:46 2020 +0000
+++ b/usr.bin/make/var.c        Sun Sep 13 19:46:23 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.516 2020/09/13 19:28:46 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.517 2020/09/13 19:46:23 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.516 2020/09/13 19:28:46 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.517 2020/09/13 19:46:23 rillig Exp $");
 
 #define VAR_DEBUG_IF(cond, fmt, ...)   \
     if (!(DEBUG(VAR) && (cond)))       \
@@ -3490,9 +3490,11 @@
            *pp += 2;
 
            *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;
+           if (DEBUG(LINT) && *out_val == var_Error) {
+               Parse_Error(PARSE_FATAL, "Variable \"%s\" is undefined", name);
+               return VPE_UNDEF_MSG;
+           }
+           return eflags & VARE_UNDEFERR ? VPE_UNDEF_SILENT : VPE_OK;
        } else {
            haveModifier = FALSE;
            p = start + 1;



Home | Main Index | Thread Index | Old Index