Sun Jul 19 17:24:22 2020 UTC ()
make(1): demonstrate off-by-one bug in :C modifier


(rillig)
diff -r1.15 -r1.16 src/usr.bin/make/unit-tests/modmisc.exp
diff -r1.13 -r1.14 src/usr.bin/make/unit-tests/modmisc.mk

cvs diff -r1.15 -r1.16 src/usr.bin/make/unit-tests/modmisc.exp (switch to unified diff)

--- src/usr.bin/make/unit-tests/modmisc.exp 2020/07/19 15:16:22 1.15
+++ src/usr.bin/make/unit-tests/modmisc.exp 2020/07/19 17:24:22 1.16
@@ -1,54 +1,64 @@ @@ -1,54 +1,64 @@
1path=':/bin:/tmp::/:.:/no/such/dir:.' 1path=':/bin:/tmp::/:.:/no/such/dir:.'
2path='/bin:/tmp:/:/no/such/dir' 2path='/bin:/tmp:/:/no/such/dir'
3path='/bin:/tmp:/:/no/such/dir' 3path='/bin:/tmp:/:/no/such/dir'
4path='/bin':'/tmp':'/':'/no/such/dir' 4path='/bin':'/tmp':'/':'/no/such/dir'
5path='/bin':'/tmp':'/':'/no/such/dir' 5path='/bin':'/tmp':'/':'/no/such/dir'
6path_/usr/xbin=/opt/xbin/ 6path_/usr/xbin=/opt/xbin/
7paths=/bin /tmp / /no/such/dir /opt/xbin 7paths=/bin /tmp / /no/such/dir /opt/xbin
8PATHS=/BIN /TMP / /NO/SUCH/DIR /OPT/XBIN 8PATHS=/BIN /TMP / /NO/SUCH/DIR /OPT/XBIN
9The answer is 42 9The answer is 42
10dirname of 'a/b/c def a.b.c a.b/c a a.a .gitignore a a.a' is 'a/b . . a.b . . . . .' 10dirname of 'a/b/c def a.b.c a.b/c a a.a .gitignore a a.a' is 'a/b . . a.b . . . . .'
11basename of 'a/b/c def a.b.c a.b/c a a.a .gitignore a a.a' is 'c def a.b.c c a a.a .gitignore a a.a' 11basename of 'a/b/c def a.b.c a.b/c a a.a .gitignore a a.a' is 'c def a.b.c c a a.a .gitignore a a.a'
12suffix of 'a/b/c def a.b.c a.b/c a a.a .gitignore a a.a' is 'c b/c a gitignore a' 12suffix of 'a/b/c def a.b.c a.b/c a a.a .gitignore a a.a' is 'c b/c a gitignore a'
13root of 'a/b/c def a.b.c a.b/c a a.a .gitignore a a.a' is 'a/b/c def a.b a a a a a' 13root of 'a/b/c def a.b.c a.b/c a a.a .gitignore a a.a' is 'a/b/c def a.b a a a a a'
14S: 14S:
15C: 15C:
16@: 16@:
17S:empty 17S:empty
18C:empty 18C:empty
19@: 19@:
20:a b b c: 20:a b b c:
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: (details omitted) 28make: RE substitution error: (details omitted)
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:w1d2d3w w2i3w w1i2d3 2i${RES3}w w1d2d3 2i${RES3} 1i${RES2}w: 34mod-at-resolve:w1d2d3w w2i3w w1i2d3 2i${RES3}w w1d2d3 2i${RES3} 1i${RES2}w:
35mod-at-dollar:(1) (2) (3). 35mod-at-dollar:(1) (2) (3).
36mod-at-dollar:(1) (2) (3). 36mod-at-dollar:(1) (2) (3).
37mod-at-dollar:() () (). 37mod-at-dollar:() () ().
38mod-subst-dollar:$1: 38mod-subst-dollar:$1:
39mod-subst-dollar:$2: 39mod-subst-dollar:$2:
40mod-subst-dollar:$3: 40mod-subst-dollar:$3:
41mod-subst-dollar:$4: 41mod-subst-dollar:$4:
42mod-subst-dollar:$5: 42mod-subst-dollar:$5:
43mod-subst-dollar:$6: 43mod-subst-dollar:$6:
44mod-subst-dollar:$7: 44mod-subst-dollar:$7:
45mod-subst-dollar:$8: 45mod-subst-dollar:$8:
46mod-subst-dollar:U8: 46mod-subst-dollar:U8:
47mod-subst-dollar:$$$$: 47mod-subst-dollar:$$$$:
48mod-loop-dollar:1: 48mod-loop-dollar:1:
49mod-loop-dollar:${word}: 49mod-loop-dollar:${word}:
50mod-loop-dollar:$3$: 50mod-loop-dollar:$3$:
51mod-loop-dollar:$${word}$: 51mod-loop-dollar:$${word}$:
52mod-loop-dollar:$$5$$: 52mod-loop-dollar:$$5$$:
53mod-loop-dollar:$$${word}$$: 53mod-loop-dollar:$$${word}$$:
 54mod-C-limits:00-ok:1 2323 45456
 55mod-C-limits:11-missing:1 6
 56mod-C-limits:11-ok:1 22 446
 57make: No subexpression \2
 58make: No subexpression \2
 59make: No subexpression \2
 60make: No subexpression \2
 61mod-C-limits:22-missing:1 6
 62mod-C-limits:22-missing:1 6
 63mod-C-limits:22-ok:1 33 556
54exit status 0 64exit status 0

cvs diff -r1.13 -r1.14 src/usr.bin/make/unit-tests/modmisc.mk (switch to unified diff)

--- src/usr.bin/make/unit-tests/modmisc.mk 2020/07/19 15:16:22 1.13
+++ src/usr.bin/make/unit-tests/modmisc.mk 2020/07/19 17:24:22 1.14
@@ -1,135 +1,144 @@ @@ -1,135 +1,144 @@
1# $Id: modmisc.mk,v 1.13 2020/07/19 15:16:22 rillig Exp $ 1# $Id: modmisc.mk,v 1.14 2020/07/19 17:24:22 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/,
15MOD_OPT=@d@$${exists($$d):?$$d:$${d:S,/usr,/opt,}}@ 15MOD_OPT=@d@$${exists($$d):?$$d:$${d:S,/usr,/opt,}}@
16MOD_SEP=S,:, ,g 16MOD_SEP=S,:, ,g
17 17
18all: modvar modvarloop modsysv mod-HTE emptyvar undefvar 18all: modvar modvarloop modsysv mod-HTE emptyvar undefvar
19all: mod-S mod-C mod-at-varname mod-at-resolve mod-at-dollar 19all: mod-S mod-C mod-at-varname mod-at-resolve mod-at-dollar
20all: mod-subst-dollar mod-loop-dollar 20all: mod-subst-dollar mod-loop-dollar
 21all: mod-C-limits
21 22
22modsysv: 23modsysv:
23 @echo "The answer is ${libfoo.a:L:libfoo.a=42}" 24 @echo "The answer is ${libfoo.a:L:libfoo.a=42}"
24 25
25modvar: 26modvar:
26 @echo "path='${path}'" 27 @echo "path='${path}'"
27 @echo "path='${path:${MOD_NODOT}}'" 28 @echo "path='${path:${MOD_NODOT}}'"
28 @echo "path='${path:S,home,homes,:${MOD_NODOT}}'" 29 @echo "path='${path:S,home,homes,:${MOD_NODOT}}'"
29 @echo "path=${path:${MOD_NODOTX}:ts:}" 30 @echo "path=${path:${MOD_NODOTX}:ts:}"
30 @echo "path=${path:${MOD_HOMES}:${MOD_NODOTX}:ts:}" 31 @echo "path=${path:${MOD_HOMES}:${MOD_NODOTX}:ts:}"
31 32
32.for d in ${path:${MOD_SEP}:N.} /usr/xbin 33.for d in ${path:${MOD_SEP}:N.} /usr/xbin
33path_$d?= ${d:${MOD_OPT}:${MOD_HOMES}}/ 34path_$d?= ${d:${MOD_OPT}:${MOD_HOMES}}/
34paths+= ${d:${MOD_OPT}:${MOD_HOMES}} 35paths+= ${d:${MOD_OPT}:${MOD_HOMES}}
35.endfor 36.endfor
36 37
37modvarloop: 38modvarloop:
38 @echo "path_/usr/xbin=${path_/usr/xbin}" 39 @echo "path_/usr/xbin=${path_/usr/xbin}"
39 @echo "paths=${paths}" 40 @echo "paths=${paths}"
40 @echo "PATHS=${paths:tu}" 41 @echo "PATHS=${paths:tu}"
41 42
42PATHNAMES= a/b/c def a.b.c a.b/c a a.a .gitignore a a.a 43PATHNAMES= a/b/c def a.b.c a.b/c a a.a .gitignore a a.a
43mod-HTE: 44mod-HTE:
44 @echo "dirname of '"${PATHNAMES:Q}"' is '"${PATHNAMES:H:Q}"'" 45 @echo "dirname of '"${PATHNAMES:Q}"' is '"${PATHNAMES:H:Q}"'"
45 @echo "basename of '"${PATHNAMES:Q}"' is '"${PATHNAMES:T:Q}"'" 46 @echo "basename of '"${PATHNAMES:Q}"' is '"${PATHNAMES:T:Q}"'"
46 @echo "suffix of '"${PATHNAMES:Q}"' is '"${PATHNAMES:E:Q}"'" 47 @echo "suffix of '"${PATHNAMES:Q}"' is '"${PATHNAMES:E:Q}"'"
47 @echo "root of '"${PATHNAMES:Q}"' is '"${PATHNAMES:R:Q}"'" 48 @echo "root of '"${PATHNAMES:Q}"' is '"${PATHNAMES:R:Q}"'"
48 49
49# When a modifier is applied to the "" variable, the result is discarded. 50# When a modifier is applied to the "" variable, the result is discarded.
50emptyvar: 51emptyvar:
51 @echo S:${:S,^$,empty,} 52 @echo S:${:S,^$,empty,}
52 @echo C:${:C,^$,empty,} 53 @echo C:${:C,^$,empty,}
53 @echo @:${:@var@${var}@} 54 @echo @:${:@var@${var}@}
54 55
55# The :U modifier turns even the "" variable into something that has a value. 56# The :U modifier turns even the "" variable into something that has a value.
56# The resulting variable is empty, but is still considered to contain a 57# The resulting variable is empty, but is still considered to contain a
57# single empty word. This word can be accessed by the :S and :C modifiers, 58# single empty word. This word can be accessed by the :S and :C modifiers,
58# but not by the :@ modifier since it explicitly skips empty words. 59# but not by the :@ modifier since it explicitly skips empty words.
59undefvar: 60undefvar:
60 @echo S:${:U:S,^$,empty,} 61 @echo S:${:U:S,^$,empty,}
61 @echo C:${:U:C,^$,empty,} 62 @echo C:${:U:C,^$,empty,}
62 @echo @:${:U:@var@empty@} 63 @echo @:${:U:@var@empty@}
63 64
64mod-S: 65mod-S:
65 @echo :${:Ua b b c:S,a b,,:Q}: 66 @echo :${:Ua b b c:S,a b,,:Q}:
66 @echo :${:Ua b b c:S,a b,,1:Q}: 67 @echo :${:Ua b b c:S,a b,,1:Q}:
67 @echo :${:Ua b b c:S,a b,,W:Q}: 68 @echo :${:Ua b b c:S,a b,,W:Q}:
68 @echo :${:Ua b b c:S,b,,g:Q}: 69 @echo :${:Ua b b c:S,b,,g:Q}:
69 @echo :${:U1 2 3 1 2 3:S,1 2,___,Wg:S,_,x,:Q}: 70 @echo :${:U1 2 3 1 2 3:S,1 2,___,Wg:S,_,x,:Q}:
70 71
71mod-C: 72mod-C:
72 @echo :${:Ua b b c:C,a b,,:Q}: 73 @echo :${:Ua b b c:C,a b,,:Q}:
73 @echo :${:Ua b b c:C,a b,,1:Q}: 74 @echo :${:Ua b b c:C,a b,,1:Q}:
74 @echo :${:Ua b b c:C,a b,,W:Q}: 75 @echo :${:Ua b b c:C,a b,,W:Q}:
75 @echo :${:Uword1 word2:C,****,____,g:C,word,____,:Q}: 76 @echo :${:Uword1 word2:C,****,____,g:C,word,____,:Q}:
76 @echo :${:Ua b b c:C,b,,g:Q}: 77 @echo :${:Ua b b c:C,b,,g:Q}:
77 @echo :${:U1 2 3 1 2 3:C,1 2,___,Wg:C,_,x,:Q}: 78 @echo :${:U1 2 3 1 2 3:C,1 2,___,Wg:C,_,x,:Q}:
78 79
79# In the :@ modifier, the name of the loop variable can even be generated 80# In the :@ modifier, the name of the loop variable can even be generated
80# dynamically. There's no practical use-case for this, and hopefully nobody 81# dynamically. There's no practical use-case for this, and hopefully nobody
81# will ever depend on this, but technically it's possible. 82# will ever depend on this, but technically it's possible.
82mod-at-varname: 83mod-at-varname:
83 @echo :${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@:Q}: 84 @echo :${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@:Q}:
84 85
85# The :@ modifier resolves the variables a little more often than expected. 86# The :@ modifier resolves the variables a little more often than expected.
86# In particular, it resolves _all_ variables from the context, and not only 87# In particular, it resolves _all_ variables from the context, and not only
87# the loop variable (in this case v). 88# the loop variable (in this case v).
88# 89#
89# The d means direct reference, the i means indirect reference. 90# The d means direct reference, the i means indirect reference.
90RESOLVE= ${RES1} $${RES1} 91RESOLVE= ${RES1} $${RES1}
91RES1= 1d${RES2} 1i$${RES2} 92RES1= 1d${RES2} 1i$${RES2}
92RES2= 2d${RES3} 2i$${RES3} 93RES2= 2d${RES3} 2i$${RES3}
93RES3= 3 94RES3= 3
94 95
95mod-at-resolve: 96mod-at-resolve:
96 @echo $@:${RESOLVE:@v@w${v}w@:Q}: 97 @echo $@:${RESOLVE:@v@w${v}w@:Q}:
97 98
98# As of 2020-07-19, the variable name of the :@ modifier may end with one 99# As of 2020-07-19, the variable name of the :@ modifier may end with one
99# or two dollar signs, which are silently ignored. There's no point in 100# or two dollar signs, which are silently ignored. There's no point in
100# allowing a dollar sign in that position. 101# allowing a dollar sign in that position.
101mod-at-dollar: 102mod-at-dollar:
102 @echo $@:${1 2 3:L:@v$@($v)@:Q}. 103 @echo $@:${1 2 3:L:@v$@($v)@:Q}.
103 @echo $@:${1 2 3:L:@v$$@($v)@:Q}. 104 @echo $@:${1 2 3:L:@v$$@($v)@:Q}.
104 @echo $@:${1 2 3:L:@v$$$@($v)@:Q}. 105 @echo $@:${1 2 3:L:@v$$$@($v)@:Q}.
105 106
106# No matter how many dollar characters there are, they all get merged 107# No matter how many dollar characters there are, they all get merged
107# into a single dollar by the :S modifier. 108# into a single dollar by the :S modifier.
108mod-subst-dollar: 109mod-subst-dollar:
109 @echo $@:${:U1:S,^,$,:Q}: 110 @echo $@:${:U1:S,^,$,:Q}:
110 @echo $@:${:U2:S,^,$$,:Q}: 111 @echo $@:${:U2:S,^,$$,:Q}:
111 @echo $@:${:U3:S,^,$$$,:Q}: 112 @echo $@:${:U3:S,^,$$$,:Q}:
112 @echo $@:${:U4:S,^,$$$$,:Q}: 113 @echo $@:${:U4:S,^,$$$$,:Q}:
113 @echo $@:${:U5:S,^,$$$$$,:Q}: 114 @echo $@:${:U5:S,^,$$$$$,:Q}:
114 @echo $@:${:U6:S,^,$$$$$$,:Q}: 115 @echo $@:${:U6:S,^,$$$$$$,:Q}:
115 @echo $@:${:U7:S,^,$$$$$$$,:Q}: 116 @echo $@:${:U7:S,^,$$$$$$$,:Q}:
116 @echo $@:${:U8:S,^,$$$$$$$$,:Q}: 117 @echo $@:${:U8:S,^,$$$$$$$$,:Q}:
117# This generates no dollar at all: 118# This generates no dollar at all:
118 @echo $@:${:UU8:S,^,${:U$$$$$$$$},:Q}: 119 @echo $@:${:UU8:S,^,${:U$$$$$$$$},:Q}:
119# Here is an alternative way to generate dollar characters. 120# Here is an alternative way to generate dollar characters.
120# It's unexpectedly complicated though. 121# It's unexpectedly complicated though.
121 @echo $@:${:U:range=5:ts\x24:C,[0-9],,g:Q}: 122 @echo $@:${:U:range=5:ts\x24:C,[0-9],,g:Q}:
122 123
123# Demonstrate that it is possible to generate dollar characters using the 124# Demonstrate that it is possible to generate dollar characters using the
124# :@ modifier. 125# :@ modifier.
125# 126#
126# These are edge cases that could have resulted in a parse error as well 127# These are edge cases that could have resulted in a parse error as well
127# since the $@ at the end could have been interpreted as a variable, which 128# since the $@ at the end could have been interpreted as a variable, which
128# would mean a missing closing @ delimiter. 129# would mean a missing closing @ delimiter.
129mod-loop-dollar: 130mod-loop-dollar:
130 @echo $@:${:U1:@word@${word}$@:Q}: 131 @echo $@:${:U1:@word@${word}$@:Q}:
131 @echo $@:${:U2:@word@$${word}$$@:Q}: 132 @echo $@:${:U2:@word@$${word}$$@:Q}:
132 @echo $@:${:U3:@word@$$${word}$$$@:Q}: 133 @echo $@:${:U3:@word@$$${word}$$$@:Q}:
133 @echo $@:${:U4:@word@$$$${word}$$$$@:Q}: 134 @echo $@:${:U4:@word@$$$${word}$$$$@:Q}:
134 @echo $@:${:U5:@word@$$$$${word}$$$$$@:Q}: 135 @echo $@:${:U5:@word@$$$$${word}$$$$$@:Q}:
135 @echo $@:${:U6:@word@$$$$$${word}$$$$$$@:Q}: 136 @echo $@:${:U6:@word@$$$$$${word}$$$$$$@:Q}:
 137
 138mod-C-limits:
 139 @echo $@:00-ok:${:U1 23 456:C,..,\0\0,:Q}
 140 @echo $@:11-missing:${:U1 23 456:C,..,\1\1,:Q}
 141 @echo $@:11-ok:${:U1 23 456:C,(.).,\1\1,:Q}
 142 @echo $@:22-missing:${:U1 23 456:C,..,\2\2,:Q}
 143 @echo $@:22-missing:${:U1 23 456:C,(.).,\2\2,:Q}
 144 @echo $@:22-ok:${:U1 23 456:C,(.)(.),\2\2,:Q}