Sat Jul 4 17:41:04 2020 UTC ()
make(1): expand the test for variable expansion in the :@ modifier


(rillig)
diff -r1.254 -r1.255 src/usr.bin/make/var.c
diff -r1.11 -r1.12 src/usr.bin/make/unit-tests/modmisc.exp
diff -r1.10 -r1.11 src/usr.bin/make/unit-tests/modmisc.mk

cvs diff -r1.254 -r1.255 src/usr.bin/make/var.c (expand / switch to unified diff)

--- src/usr.bin/make/var.c 2020/07/04 17:10:33 1.254
+++ src/usr.bin/make/var.c 2020/07/04 17:41:04 1.255
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: var.c,v 1.254 2020/07/04 17:10:33 rillig Exp $ */ 1/* $NetBSD: var.c,v 1.255 2020/07/04 17:41:04 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -59,34 +59,34 @@ @@ -59,34 +59,34 @@
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE. 68 * SUCH DAMAGE.
69 */ 69 */
70 70
71#ifndef MAKE_NATIVE 71#ifndef MAKE_NATIVE
72static char rcsid[] = "$NetBSD: var.c,v 1.254 2020/07/04 17:10:33 rillig Exp $"; 72static char rcsid[] = "$NetBSD: var.c,v 1.255 2020/07/04 17:41:04 rillig Exp $";
73#else 73#else
74#include <sys/cdefs.h> 74#include <sys/cdefs.h>
75#ifndef lint 75#ifndef lint
76#if 0 76#if 0
77static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94"; 77static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
78#else 78#else
79__RCSID("$NetBSD: var.c,v 1.254 2020/07/04 17:10:33 rillig Exp $"); 79__RCSID("$NetBSD: var.c,v 1.255 2020/07/04 17:41:04 rillig Exp $");
80#endif 80#endif
81#endif /* not lint */ 81#endif /* not lint */
82#endif 82#endif
83 83
84/*- 84/*-
85 * var.c -- 85 * var.c --
86 * Variable-handling functions 86 * Variable-handling functions
87 * 87 *
88 * Interface: 88 * Interface:
89 * Var_Set Set the value of a variable in the given 89 * Var_Set Set the value of a variable in the given
90 * context. The variable is created if it doesn't 90 * context. The variable is created if it doesn't
91 * yet exist. The value and variable name need not 91 * yet exist. The value and variable name need not
92 * be preserved. 92 * be preserved.
@@ -1727,26 +1727,31 @@ VarModify(GNode *ctx, Var_Parse_State *v @@ -1727,26 +1727,31 @@ VarModify(GNode *ctx, Var_Parse_State *v
1727 addSpace = FALSE; 1727 addSpace = FALSE;
1728 1728
1729 if (vpstate->oneBigWord) { 1729 if (vpstate->oneBigWord) {
1730 /* fake what brk_string() would do if there were only one word */ 1730 /* fake what brk_string() would do if there were only one word */
1731 ac = 1; 1731 ac = 1;
1732 av = bmake_malloc((ac + 1) * sizeof(char *)); 1732 av = bmake_malloc((ac + 1) * sizeof(char *));
1733 as = bmake_strdup(str); 1733 as = bmake_strdup(str);
1734 av[0] = as; 1734 av[0] = as;
1735 av[1] = NULL; 1735 av[1] = NULL;
1736 } else { 1736 } else {
1737 av = brk_string(str, &ac, FALSE, &as); 1737 av = brk_string(str, &ac, FALSE, &as);
1738 } 1738 }
1739 1739
 1740 if (DEBUG(VAR)) {
 1741 fprintf(debug_file, "VarModify: split \"%s\" into %d words\n",
 1742 str, ac);
 1743 }
 1744
1740 for (i = 0; i < ac; i++) 1745 for (i = 0; i < ac; i++)
1741 addSpace = modProc(ctx, vpstate, av[i], addSpace, &buf, datum); 1746 addSpace = modProc(ctx, vpstate, av[i], addSpace, &buf, datum);
1742 1747
1743 free(as); 1748 free(as);
1744 free(av); 1749 free(av);
1745 1750
1746 return Buf_Destroy(&buf, FALSE); 1751 return Buf_Destroy(&buf, FALSE);
1747} 1752}
1748 1753
1749 1754
1750static int 1755static int
1751VarWordCompare(const void *a, const void *b) 1756VarWordCompare(const void *a, const void *b)
1752{ 1757{

cvs diff -r1.11 -r1.12 src/usr.bin/make/unit-tests/modmisc.exp (expand / switch to unified diff)

--- src/usr.bin/make/unit-tests/modmisc.exp 2020/07/04 17:10:33 1.11
+++ src/usr.bin/make/unit-tests/modmisc.exp 2020/07/04 17:41:04 1.12
@@ -21,15 +21,15 @@ C:empty @@ -21,15 +21,15 @@ C:empty
21:a b b c: 21:a b b c:
22: b c: 22: b c:
23:a c: 23:a c:
24:x__ 3 x__ 3: 24:x__ 3 x__ 3:
25:a b b c: 25:a b b c:
26:a b b c: 26:a b b c:
27: b c: 27: b c:
28make: RE substitution error: repetition-operator operand invalid 28make: RE substitution error: repetition-operator operand invalid
29make: Unclosed substitution for (, missing) 29make: Unclosed substitution for (, missing)
30:C,word,____,:Q}: 30:C,word,____,:Q}:
31:a c: 31:a c:
32:x__ 3 x__ 3: 32:x__ 3 x__ 3:
33:+one+ +two+ +three+: 33:+one+ +two+ +three+:
34mod-at-resolve:w1a2w w1b2w w1a2 1b${RES2}w: 34mod-at-resolve:w1d2d3w w2i3w w1i2d3 2i${RES3}w w1d2d3 2i${RES3} 1i${RES2}w:
35exit status 0 35exit status 0

cvs diff -r1.10 -r1.11 src/usr.bin/make/unit-tests/modmisc.mk (expand / switch to unified diff)

--- src/usr.bin/make/unit-tests/modmisc.mk 2020/07/04 17:10:33 1.10
+++ src/usr.bin/make/unit-tests/modmisc.mk 2020/07/04 17:41:04 1.11
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $Id: modmisc.mk,v 1.10 2020/07/04 17:10:33 rillig Exp $ 1# $Id: modmisc.mk,v 1.11 2020/07/04 17:41:04 rillig Exp $
2# 2#
3# miscellaneous modifier tests 3# miscellaneous modifier tests
4 4
5# do not put any dirs in this list which exist on some 5# do not put any dirs in this list which exist on some
6# but not all target systems - an exists() check is below. 6# but not all target systems - an exists() check is below.
7path=:/bin:/tmp::/:.:/no/such/dir:. 7path=:/bin:/tmp::/:.:/no/such/dir:.
8# strip cwd from path. 8# strip cwd from path.
9MOD_NODOT=S/:/ /g:N.:ts: 9MOD_NODOT=S/:/ /g:N.:ts:
10# and decorate, note that $'s need to be doubled. Also note that  10# and decorate, note that $'s need to be doubled. Also note that
11# the modifier_variable can be used with other modifiers. 11# the modifier_variable can be used with other modifiers.
12MOD_NODOTX=S/:/ /g:N.:@d@'$$d'@ 12MOD_NODOTX=S/:/ /g:N.:@d@'$$d'@
13# another mod - pretend it is more interesting 13# another mod - pretend it is more interesting
14MOD_HOMES=S,/home/,/homes/, 14MOD_HOMES=S,/home/,/homes/,
@@ -74,19 +74,22 @@ mod-C: @@ -74,19 +74,22 @@ mod-C:
74 @echo :${:Uword1 word2:C,****,____,g:C,word,____,:Q}: 74 @echo :${:Uword1 word2:C,****,____,g:C,word,____,:Q}:
75 @echo :${:Ua b b c:C,b,,g:Q}: 75 @echo :${:Ua b b c:C,b,,g:Q}:
76 @echo :${:U1 2 3 1 2 3:C,1 2,___,Wg:C,_,x,:Q}: 76 @echo :${:U1 2 3 1 2 3:C,1 2,___,Wg:C,_,x,:Q}:
77 77
78# In the :@ modifier, the name of the loop variable can even be generated 78# In the :@ modifier, the name of the loop variable can even be generated
79# dynamically. There's no practical use-case for this, and hopefully nobody 79# dynamically. There's no practical use-case for this, and hopefully nobody
80# will ever depend on this, but technically it's possible. 80# will ever depend on this, but technically it's possible.
81mod-at-varname: 81mod-at-varname:
82 @echo :${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@:Q}: 82 @echo :${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@:Q}:
83 83
84# The :@ modifier resolves the variables a little more often than expected. 84# The :@ modifier resolves the variables a little more often than expected.
85# In particular, it resolves _all_ variables from the context, and not only 85# In particular, it resolves _all_ variables from the context, and not only
86# the loop variable (in this case v). 86# the loop variable (in this case v).
 87#
 88# The d means direct reference, the i means indirect reference.
87RESOLVE= ${RES1} $${RES1} 89RESOLVE= ${RES1} $${RES1}
88RES1= 1a${RES2} 1b$${RES2} 90RES1= 1d${RES2} 1i$${RES2}
89RES2= 2 91RES2= 2d${RES3} 2i$${RES3}
 92RES3= 3
90 93
91mod-at-resolve: 94mod-at-resolve:
92 @echo $@:${RESOLVE:@v@w${v}w@:Q}: 95 @echo $@:${RESOLVE:@v@w${v}w@:Q}: