From 24fb524bea2301e0e401ca366e3cc4f57601eb88 Mon Sep 17 00:00:00 2001 From: rillig Date: Mon, 19 Apr 2021 23:51:42 +0000 Subject: [PATCH] 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. --- usr.bin/make/cond.c | 6 +++--- usr.bin/make/unit-tests/varmod-ifelse.exp | 4 ++-- usr.bin/make/unit-tests/varmod-ifelse.mk | 18 +++++++++--------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/usr.bin/make/cond.c b/usr.bin/make/cond.c index bcb31e9687c1..5b8146ae17bf 100644 --- a/usr.bin/make/cond.c +++ b/usr.bin/make/cond.c @@ -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, bool doEval) 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; diff --git a/usr.bin/make/unit-tests/varmod-ifelse.exp b/usr.bin/make/unit-tests/varmod-ifelse.exp index 93caf1b32ff5..7f824110dfe0 100644 --- a/usr.bin/make/unit-tests/varmod-ifelse.exp +++ b/usr.bin/make/unit-tests/varmod-ifelse.exp @@ -15,8 +15,8 @@ CondParser_Eval: ${ ${:U\$}{VAR} == value :?ok:bad} != "ok" 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' diff --git a/usr.bin/make/unit-tests/varmod-ifelse.mk b/usr.bin/make/unit-tests/varmod-ifelse.mk index 92ea9994ac2c..08550b4a9306 100644 --- a/usr.bin/make/unit-tests/varmod-ifelse.mk +++ b/usr.bin/make/unit-tests/varmod-ifelse.mk @@ -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}.