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): add test for combining the :@ and :? v...
details: https://anonhg.NetBSD.org/src/rev/96c09d8b6d73
branches: trunk
changeset: 956479:96c09d8b6d73
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Oct 31 12:34:03 2020 +0000
description:
make(1): add test for combining the :@ and :? variable modifiers
diffstat:
usr.bin/make/unit-tests/varmod-loop.mk | 25 ++++++++++++++++++++++---
usr.bin/make/var.c | 8 ++++----
2 files changed, 26 insertions(+), 7 deletions(-)
diffs (88 lines):
diff -r 2edb56575709 -r 96c09d8b6d73 usr.bin/make/unit-tests/varmod-loop.mk
--- a/usr.bin/make/unit-tests/varmod-loop.mk Sat Oct 31 12:22:43 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-loop.mk Sat Oct 31 12:34:03 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-loop.mk,v 1.4 2020/10/18 21:12:13 rillig Exp $
+# $NetBSD: varmod-loop.mk,v 1.5 2020/10/31 12:34:03 rillig Exp $
#
# Tests for the :@var@...${var}...@ variable modifier.
@@ -13,16 +13,20 @@
# Therefore, in -dL mode, this is forbidden, see lint.mk.
mod-loop-varname:
@echo :${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@:Q}:
- # ":::" is a very creative variable name, unlikely in practice
+
+ # ":::" is a very creative variable name, unlikely in practice.
# The expression ${\:\:\:} would not work since backslashes can only
# be escaped in the modifiers, but not in the variable name.
@echo :${:U1 2 3:@:::@x${${:U\:\:\:}}y@}:
+
# "@@" is another creative variable name.
@echo :${:U1 2 3:@\@\@@x${@@}y@}:
+
# Even "@" works as a variable name since the variable is installed
# in the "current" scope, which in this case is the one from the
# target.
@echo :$@: :${:U1 2 3:@\@@x${@}y@}: :$@:
+
# In extreme cases, even the backslash can be used as variable name.
# It needs to be doubled though.
@echo :${:U1 2 3:@\\@x${${:Ux:S,x,\\,}}y@}:
@@ -70,7 +74,7 @@
# It may happen that there are nested :@ modifiers that use the same name for
# for the loop variable. These modifiers influence each other.
#
-# As of 2020-10-18, the :@ modifier is implemented by actually setting an
+# As of 2020-10-18, the :@ modifier is implemented by actually setting a
# variable in the context of the expression and deleting it again after the
# loop. This is different from the .for loops, which substitute the variable
# expression with ${:Uvalue}, leading to different unwanted side effects.
@@ -81,3 +85,18 @@
.if ${:U1 2 3:@i@$i${:Ua b c:@i@$i@}${i:Uu}@} != "1a b cu 2a b cu 3a b cu"
. error
.endif
+
+# During the loop, the variable is actually defined and nonempty.
+# If the loop were implemented in the same way as the .for loop, the variable
+# would be neither defined nor nonempty since all expressions of the form
+# ${var} would have been replaced with ${:Uword} before evaluating them.
+.if defined(var)
+. error
+.endif
+.if ${:Uword:@var@${defined(var):?def:undef} ${empty(var):?empty:nonempty}@} \
+ != "def nonempty"
+. error
+.endif
+.if defined(var)
+. error
+.endif
diff -r 2edb56575709 -r 96c09d8b6d73 usr.bin/make/var.c
--- a/usr.bin/make/var.c Sat Oct 31 12:22:43 2020 +0000
+++ b/usr.bin/make/var.c Sat Oct 31 12:34:03 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.617 2020/10/31 12:22:43 rillig Exp $ */
+/* $NetBSD: var.c,v 1.618 2020/10/31 12:34:03 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -129,7 +129,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.617 2020/10/31 12:22:43 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.618 2020/10/31 12:34:03 rillig Exp $");
#define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1)
#define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2)
@@ -1465,8 +1465,8 @@
(void)Var_Subst(args->str, args->ctx, args->eflags, &s);
/* TODO: handle errors */
- VAR_DEBUG4("ModifyWord_Loop: in \"%s\", replace \"%s\" with \"%s\" "
- "to \"%s\"\n",
+ VAR_DEBUG4("ModifyWord_Loop: "
+ "in \"%s\", replace \"%s\" with \"%s\" to \"%s\"\n",
word, args->tvar, args->str, s);
if (s[0] == '\n' || Buf_EndsWith(&buf->buf, '\n'))
Home |
Main Index |
Thread Index |
Old Index