Module Name:    src
Committed By:   rillig
Date:           Mon Apr 19 23:51:42 UTC 2021

Modified Files:
        src/usr.bin/make: cond.c
        src/usr.bin/make/unit-tests: varmod-ifelse.exp varmod-ifelse.mk

Log Message:
make: do not complain when skipping the condition 'no >= 10'

Seen in external/bsd/tmux when building with Clang.  See
varmod-ifelse.mk for the detailed story.


To generate a diff of this commit:
cvs rdiff -u -r1.261 -r1.262 src/usr.bin/make/cond.c
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/varmod-ifelse.exp
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/make/unit-tests/varmod-ifelse.mk

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.261 src/usr.bin/make/cond.c:1.262
--- src/usr.bin/make/cond.c:1.261	Sun Apr  4 11:56:43 2021
+++ src/usr.bin/make/cond.c	Mon Apr 19 23:51:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.261 2021/04/04 11:56:43 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.262 2021/04/19 23:51:42 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.261 2021/04/04 11:56:43 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.262 2021/04/19 23:51:42 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -854,7 +854,7 @@ CondParser_LeafToken(CondParser *par, bo
 	arglen = ParseFuncArg(par, &cp, doEval, NULL, &arg);
 	cp1 = cp;
 	cpp_skip_whitespace(&cp1);
-	if (*cp1 == '=' || *cp1 == '!')
+	if (*cp1 == '=' || *cp1 == '!' || *cp1 == '<' || *cp1 == '>')
 		return CondParser_Comparison(par, doEval);
 	par->p = cp;
 

Index: src/usr.bin/make/unit-tests/varmod-ifelse.exp
diff -u src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.9 src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.10
--- src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.9	Mon Apr 19 23:43:14 2021
+++ src/usr.bin/make/unit-tests/varmod-ifelse.exp	Mon Apr 19 23:51:42 2021
@@ -15,8 +15,8 @@ CondParser_Eval: ${ ${:U\$}{VAR} == valu
 CondParser_Eval: ${VAR} == value 
 lhs = "value", rhs = "value", op = ==
 lhs = "ok", rhs = "ok", op = !=
-make: Bad conditional expression 'string == "literal" && no >= 10' in 'string == "literal" && no >= 10?yes:no'
-make: "varmod-ifelse.mk" line 153: .
+make: "varmod-ifelse.mk" line 153: no.
+make: "varmod-ifelse.mk" line 154: String comparison operator must be either == or !=
 make: Bad conditional expression 'string == "literal" || no >= 10' in 'string == "literal" || no >= 10?yes:no'
 make: "varmod-ifelse.mk" line 154: .
 make: Bad conditional expression 'string == "literal" &&  >= 10' in 'string == "literal" &&  >= 10?yes:no'

Index: src/usr.bin/make/unit-tests/varmod-ifelse.mk
diff -u src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.15 src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.16
--- src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.15	Mon Apr 19 23:43:14 2021
+++ src/usr.bin/make/unit-tests/varmod-ifelse.mk	Mon Apr 19 23:51:42 2021
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-ifelse.mk,v 1.15 2021/04/19 23:43:14 rillig Exp $
+# $NetBSD: varmod-ifelse.mk,v 1.16 2021/04/19 23:51:42 rillig Exp $
 #
 # Tests for the ${cond:?then:else} variable modifier, which evaluates either
 # the then-expression or the else-expression, depending on the condition.
@@ -140,14 +140,14 @@ VAR=	value
 # therefore parsing stopped at the '>', producing the 'Bad conditional
 # expression'.
 #
-# TODO: make should at least describe the part of the condition that is
-#  wrong. In this case it is probably the "no >= 10".  Ideally that should
-#  not matter though since the left-hand side of the '&&' evaluates to false,
-#  thus the right-hand side only needs to be parsed, not evaluated.  Since
-#  this is the modifier ':?', which expands subexpressions before parsing
-#  the condition, the "no >= 10" is probably a parse error since it "can be
-#  seen at compile-time" that the operand types of '>=' don't match.  Only
-#  that the concept of "compile-time" does not really apply here.
+# Ideally, the conditional expression would not be expanded before parsing
+# it.  This would allow to write the conditions exactly as seen below.  That
+# change has a high chance of breaking _some_ existing code and would need
+# to be thoroughly tested.
+#
+# Since cond.c 1.262 from 2021-04-20, make reports a more specific error
+# message in situations like these, pointing directly to the specific problem
+# instead of just saying that the whole condition is bad.
 STRING=		string
 NUMBER=		no		# not really a number
 .info ${${STRING} == "literal" && ${NUMBER} >= 10:?yes:no}.

Reply via email to