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): replace warning + error with just an e...



details:   https://anonhg.NetBSD.org/src/rev/f22094ba0659
branches:  trunk
changeset: 1018099:f22094ba0659
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Jan 21 23:32:28 2021 +0000

description:
make(1): replace warning + error with just an error in conditionals

Before, there was a "warning" for comparing strings using '<', which was
wrong.  That warning was then followed by an error, after parsing the
whole conditional.  This was only because it was easier to implement.

Replace the warning with an actual error.  This only affects
conditionals in .if lines, the conditionals in the :? modifier such as
${"A" < "B":?smaller:greater} still print 2 errors.

diffstat:

 usr.bin/make/cond.c                          |  25 +++++++++++++------------
 usr.bin/make/unit-tests/cond-cmp-numeric.exp |   6 ++----
 usr.bin/make/unit-tests/cond-cmp-string.exp  |  12 ++++--------
 usr.bin/make/unit-tests/cond-token-plain.exp |   3 +--
 usr.bin/make/unit-tests/cond1.exp            |   2 +-
 5 files changed, 21 insertions(+), 27 deletions(-)

diffs (139 lines):

diff -r e9be44d2bcf4 -r f22094ba0659 usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Thu Jan 21 23:25:08 2021 +0000
+++ b/usr.bin/make/cond.c       Thu Jan 21 23:32:28 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.251 2021/01/21 23:25:08 rillig Exp $        */
+/*     $NetBSD: cond.c,v 1.252 2021/01/21 23:32:28 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -95,7 +95,7 @@
 #include "dir.h"
 
 /*     "@(#)cond.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: cond.c,v 1.251 2021/01/21 23:25:08 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.252 2021/01/21 23:32:28 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -603,12 +603,13 @@
 }
 
 static Token
-EvalCompareStr(const char *lhs, ComparisonOp op, const char *rhs)
+EvalCompareStr(CondParser *par, const char *lhs,
+              ComparisonOp op, const char *rhs)
 {
        if (op != EQ && op != NE) {
-               Parse_Error(PARSE_WARNING,
+               Parse_Error(PARSE_FATAL,
                    "String comparison operator must be either == or !=");
-               /* The PARSE_FATAL follows in CondEvalExpression. */
+               par->printedError = TRUE;
                return TOK_ERROR;
        }
 
@@ -619,8 +620,8 @@
 
 /* Evaluate a comparison, such as "${VAR} == 12345". */
 static Token
-EvalCompare(const char *lhs, Boolean lhsQuoted, ComparisonOp op,
-           const char *rhs, Boolean rhsQuoted)
+EvalCompare(CondParser *par, const char *lhs, Boolean lhsQuoted,
+           ComparisonOp op, const char *rhs, Boolean rhsQuoted)
 {
        double left, right;
 
@@ -628,7 +629,7 @@
                if (TryParseNumber(lhs, &left) && TryParseNumber(rhs, &right))
                        return ToToken(EvalCompareNum(left, op, right));
 
-       return EvalCompareStr(lhs, op, rhs);
+       return EvalCompareStr(par, lhs, op, rhs);
 }
 
 static Boolean
@@ -700,9 +701,9 @@
        CondParser_SkipWhitespace(par);
 
        if (par->p[0] == '\0') {
-               Parse_Error(PARSE_WARNING,
-                           "Missing right-hand-side of operator");
-               /* The PARSE_FATAL follows in CondEvalExpression. */
+               Parse_Error(PARSE_FATAL,
+                   "Missing right-hand-side of operator '%s'", opname[op]);
+               par->printedError = TRUE;
                goto done_lhs;
        }
 
@@ -715,7 +716,7 @@
                goto done_rhs;
        }
 
-       t = EvalCompare(lhs.str, lhsQuoted, op, rhs.str, rhsQuoted);
+       t = EvalCompare(par, lhs.str, lhsQuoted, op, rhs.str, rhsQuoted);
 
 done_rhs:
        FStr_Done(&rhs);
diff -r e9be44d2bcf4 -r f22094ba0659 usr.bin/make/unit-tests/cond-cmp-numeric.exp
--- a/usr.bin/make/unit-tests/cond-cmp-numeric.exp      Thu Jan 21 23:25:08 2021 +0000
+++ b/usr.bin/make/unit-tests/cond-cmp-numeric.exp      Thu Jan 21 23:32:28 2021 +0000
@@ -1,9 +1,7 @@
 CondParser_Eval: !(${:UINF} > 1e100)
-make: "cond-cmp-numeric.mk" line 11: warning: String comparison operator must be either == or !=
-make: "cond-cmp-numeric.mk" line 11: Malformed conditional (!(${:UINF} > 1e100))
+make: "cond-cmp-numeric.mk" line 11: String comparison operator must be either == or !=
 CondParser_Eval: ${:UNaN} > NaN
-make: "cond-cmp-numeric.mk" line 16: warning: String comparison operator must be either == or !=
-make: "cond-cmp-numeric.mk" line 16: Malformed conditional (${:UNaN} > NaN)
+make: "cond-cmp-numeric.mk" line 16: String comparison operator must be either == or !=
 CondParser_Eval: !(${:UNaN} == NaN)
 lhs = "NaN", rhs = "NaN", op = ==
 CondParser_Eval: 123 ! 123
diff -r e9be44d2bcf4 -r f22094ba0659 usr.bin/make/unit-tests/cond-cmp-string.exp
--- a/usr.bin/make/unit-tests/cond-cmp-string.exp       Thu Jan 21 23:25:08 2021 +0000
+++ b/usr.bin/make/unit-tests/cond-cmp-string.exp       Thu Jan 21 23:32:28 2021 +0000
@@ -2,14 +2,10 @@
 make: "cond-cmp-string.mk" line 42: Malformed conditional ("string" != "str""ing")
 make: "cond-cmp-string.mk" line 49: Malformed conditional (!("value" = "value"))
 make: "cond-cmp-string.mk" line 56: Malformed conditional (!("value" === "value"))
-make: "cond-cmp-string.mk" line 113: warning: String comparison operator must be either == or !=
-make: "cond-cmp-string.mk" line 113: Malformed conditional ("string" < "string")
-make: "cond-cmp-string.mk" line 120: warning: String comparison operator must be either == or !=
-make: "cond-cmp-string.mk" line 120: Malformed conditional ("string" <= "string")
-make: "cond-cmp-string.mk" line 127: warning: String comparison operator must be either == or !=
-make: "cond-cmp-string.mk" line 127: Malformed conditional ("string" > "string")
-make: "cond-cmp-string.mk" line 134: warning: String comparison operator must be either == or !=
-make: "cond-cmp-string.mk" line 134: Malformed conditional ("string" >= "string")
+make: "cond-cmp-string.mk" line 113: String comparison operator must be either == or !=
+make: "cond-cmp-string.mk" line 120: String comparison operator must be either == or !=
+make: "cond-cmp-string.mk" line 127: String comparison operator must be either == or !=
+make: "cond-cmp-string.mk" line 134: String comparison operator must be either == or !=
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1
diff -r e9be44d2bcf4 -r f22094ba0659 usr.bin/make/unit-tests/cond-token-plain.exp
--- a/usr.bin/make/unit-tests/cond-token-plain.exp      Thu Jan 21 23:25:08 2021 +0000
+++ b/usr.bin/make/unit-tests/cond-token-plain.exp      Thu Jan 21 23:32:28 2021 +0000
@@ -39,8 +39,7 @@
 CondParser_Eval: 0${:Ux01}
 make: "cond-token-plain.mk" line 134: Numbers can be composed from literals and variable expressions.
 CondParser_Eval: "" ==
-make: "cond-token-plain.mk" line 140: warning: Missing right-hand-side of operator
-make: "cond-token-plain.mk" line 140: Malformed conditional ("" ==)
+make: "cond-token-plain.mk" line 140: Missing right-hand-side of operator '=='
 CondParser_Eval: == ""
 make: "cond-token-plain.mk" line 148: Malformed conditional (== "")
 CondParser_Eval: \\
diff -r e9be44d2bcf4 -r f22094ba0659 usr.bin/make/unit-tests/cond1.exp
--- a/usr.bin/make/unit-tests/cond1.exp Thu Jan 21 23:25:08 2021 +0000
+++ b/usr.bin/make/unit-tests/cond1.exp Thu Jan 21 23:32:28 2021 +0000
@@ -16,7 +16,7 @@
 4 is not prime
 5 is  prime
 
-make: warning: String comparison operator must be either == or !=
+make: String comparison operator must be either == or !=
 make: Bad conditional expression `"0" > 0' in "0" > 0?OK:No
 
 OK



Home | Main Index | Thread Index | Old Index