Module Name:    src
Committed By:   rillig
Date:           Sun Sep 13 19:46:23 UTC 2020

Modified Files:
        src/usr.bin/make: cond.c nonints.h var.c
        src/usr.bin/make/unit-tests: opt-debug-lint.exp

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

This only has an effect in lint mode right now.


To generate a diff of this commit:
cvs rdiff -u -r1.145 -r1.146 src/usr.bin/make/cond.c
cvs rdiff -u -r1.120 -r1.121 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.516 -r1.517 src/usr.bin/make/var.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/opt-debug-lint.exp

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/cond.c
diff -u src/usr.bin/make/cond.c:1.145 src/usr.bin/make/cond.c:1.146
--- src/usr.bin/make/cond.c:1.145	Sun Sep 13 18:27:39 2020
+++ src/usr.bin/make/cond.c	Sun Sep 13 19:46:23 2020
@@ -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 @@ typedef struct {
     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 @@ CondParser_String(CondParser *par, Boole
     Boolean qt;
     const char *start;
     VarEvalFlags eflags;
+    VarParseErrors errors;
 
     Buf_Init(&buf, 0);
     str = NULL;
@@ -454,9 +461,11 @@ CondParser_String(CondParser *par, Boole
 		     (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 @@ CondEvalExpression(const struct If *info
     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;

Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.120 src/usr.bin/make/nonints.h:1.121
--- src/usr.bin/make/nonints.h:1.120	Sun Sep 13 19:16:22 2020
+++ src/usr.bin/make/nonints.h	Sun Sep 13 19:46:23 2020
@@ -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 @@ typedef enum {
      *
      * 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 *);

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.516 src/usr.bin/make/var.c:1.517
--- src/usr.bin/make/var.c:1.516	Sun Sep 13 19:28:46 2020
+++ src/usr.bin/make/var.c	Sun Sep 13 19:46:23 2020
@@ -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 @@ Var_Parse(const char **pp, GNode *ctxt, 
 	    *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;

Index: src/usr.bin/make/unit-tests/opt-debug-lint.exp
diff -u src/usr.bin/make/unit-tests/opt-debug-lint.exp:1.2 src/usr.bin/make/unit-tests/opt-debug-lint.exp:1.3
--- src/usr.bin/make/unit-tests/opt-debug-lint.exp:1.2	Sun Sep 13 19:28:46 2020
+++ src/usr.bin/make/unit-tests/opt-debug-lint.exp	Sun Sep 13 19:46:23 2020
@@ -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

Reply via email to