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: only evaluate the ':_' modifier if the ex...
details: https://anonhg.NetBSD.org/src/rev/a54bbd234079
branches: trunk
changeset: 1019574:a54bbd234079
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Mar 14 16:43:30 2021 +0000
description:
make: only evaluate the ':_' modifier if the expression is needed
See var-eval-short.mk:46 for the test demonstrating this change.
Previously, the expression ${:Uword:_=VAR} was evaluated including all
its side effects even though it was in an irrelevant branch of the
condition.
diffstat:
usr.bin/make/unit-tests/var-eval-short.exp | 1 -
usr.bin/make/var.c | 26 ++++++++++++++++----------
2 files changed, 16 insertions(+), 11 deletions(-)
diffs (70 lines):
diff -r 55649470418b -r a54bbd234079 usr.bin/make/unit-tests/var-eval-short.exp
--- a/usr.bin/make/unit-tests/var-eval-short.exp Sun Mar 14 16:03:04 2021 +0000
+++ b/usr.bin/make/unit-tests/var-eval-short.exp Sun Mar 14 16:43:30 2021 +0000
@@ -1,7 +1,6 @@
unexpected
make: Bad modifier ":[${FAIL" for variable ""
make: "var-eval-short.mk" line 43: Malformed conditional (0 && ${:Uword:[${FAIL}]})
-make: "var-eval-short.mk" line 48: Missing argument for ".error"
make: "var-eval-short.mk" line 63: Invalid time value: ${FAIL}}
make: "var-eval-short.mk" line 63: Malformed conditional (0 && ${:Uword:gmtime=${FAIL}})
make: "var-eval-short.mk" line 77: Invalid time value: ${FAIL}}
diff -r 55649470418b -r a54bbd234079 usr.bin/make/var.c
--- a/usr.bin/make/var.c Sun Mar 14 16:03:04 2021 +0000
+++ b/usr.bin/make/var.c Sun Mar 14 16:43:30 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.865 2021/03/14 16:03:04 rillig Exp $ */
+/* $NetBSD: var.c,v 1.866 2021/03/14 16:43:30 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.865 2021/03/14 16:03:04 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.866 2021/03/14 16:43:30 rillig Exp $");
typedef enum VarFlags {
VFL_NONE = 0,
@@ -3418,6 +3418,7 @@
{
Expr *expr = st->expr;
const char *mod = *pp;
+
if (!ModMatchEq(mod, "_", st))
return AMR_UNKNOWN;
@@ -3428,19 +3429,24 @@
* unnecessary, undocumented inconsistency in make.
*/
size_t n = strcspn(mod + 2, ":)}");
- char *name = bmake_strldup(mod + 2, n);
*pp = mod + 2 + n;
- /*
- * FIXME: do not expand the variable name here; it would only
- * work for single-character variable names anyway.
- */
- Var_SetExpand(expr->scope, name, expr->value.str);
- free(name);
+ if (expr->eflags & VARE_WANTRES) {
+ char *name = bmake_strldup(mod + 2, n);
+
+ /*
+ * FIXME: do not expand the variable name here; it
+ * would only work for single-character variable names
+ * anyway.
+ */
+ Var_SetExpand(expr->scope, name, expr->value.str);
+ free(name);
+ }
} else {
*pp = mod + 1;
- Var_Set(expr->scope, "_", expr->value.str);
+ if (expr->eflags & VARE_WANTRES)
+ Var_Set(expr->scope, "_", expr->value.str);
}
return AMR_OK;
}
Home |
Main Index |
Thread Index |
Old Index