var-eval-short.mk revision 1.17 1 # $NetBSD: var-eval-short.mk,v 1.17 2025/01/11 20:54:45 rillig Exp $
2 #
3 # Tests for each variable modifier to ensure that they only do the minimum
4 # necessary computations. If the result of the expression is irrelevant,
5 # the modifier should only be parsed. The modifier should not be evaluated,
6 # but if it is evaluated for simplicity of the code (such as ':ts'), it must
7 # not have any observable side effects.
8 #
9 # See also:
10 # var.c, the comment starting with 'The ApplyModifier functions'
11 # ParseModifierPart, for evaluating nested expressions
12 # cond-short.mk
13
14 FAIL= ${:!echo unexpected 1>&2!}
15
16 # The following tests only ensure that nested expressions are not evaluated.
17 # They cannot ensure that any unexpanded text returned from ParseModifierPart
18 # is ignored as well. To do that, it is necessary to step through the code of
19 # each modifier.
20
21 # TODO: Test the modifiers in the same order as they occur in ApplyModifier.
22
23 .if 0 && ${FAIL}
24 .endif
25
26 .if 0 && ${VAR::=${FAIL}}
27 .elif defined(VAR)
28 . error
29 .endif
30
31 .if 0 && ${${FAIL}:?then:else}
32 .endif
33
34 .if 0 && ${1:?${FAIL}:${FAIL}}
35 .endif
36
37 .if 0 && ${0:?${FAIL}:${FAIL}}
38 .endif
39
40 # Before var.c 1.870 from 2021-03-14, the expression ${FAIL} was evaluated
41 # after the loop, when undefining the temporary global loop variable.
42 # Since var.c 1.907 from 2021-04-04, a '$' is no longer allowed in the
43 # variable name.
44 # expect+1: In the :@ modifier, the variable name "${FAIL}" must not contain a dollar
45 .if 0 && ${:Uword:@${FAIL}@expr@}
46 .endif
47
48 .if 0 && ${:Uword:@var@${FAIL}@}
49 .endif
50
51 # Before var.c 1.877 from 2021-03-14, the modifier ':[...]' did not expand
52 # the nested expression ${FAIL} and then tried to parse the unexpanded text,
53 # which failed since '$' is not a valid range character.
54 .if 0 && ${:Uword:[${FAIL}]}
55 .endif
56
57 # Before var.c 1.867 from 2021-03-14, the modifier ':_' defined the variable
58 # even though the whole expression should have only been parsed, not
59 # evaluated.
60 .if 0 && ${:Uword:_=VAR}
61 .elif defined(VAR)
62 . error
63 .endif
64
65 # Before var.c 1.856 from 2021-03-14, the modifier ':C' did not expand the
66 # nested expression ${FAIL}, which is correct, and then tried to compile the
67 # unexpanded text as a regular expression, which is unnecessary since the
68 # right-hand side of the '&&' cannot influence the outcome of the condition.
69 # Compiling the regular expression then failed both because of the '{FAIL}',
70 # which is not a valid repetition of the form '{1,5}', and because of the
71 # '****', which are repeated repetitions as well.
72 # '${FAIL}'
73 .if 0 && ${:Uword:C,${FAIL}****,,}
74 .endif
75
76 DEFINED= # defined
77 .if 0 && ${DEFINED:D${FAIL}}
78 .endif
79
80 .if 0 && ${:Uword:E}
81 .endif
82
83 # Before var.c 1.1050 from 2023-05-09, the ':gmtime' modifier produced the
84 # error message 'Invalid time value: ${FAIL}}' since it did not expand its
85 # argument.
86 .if 0 && ${:Uword:gmtime=${FAIL}}
87 .endif
88
89 .if 0 && ${:Uword:H}
90 .endif
91
92 .if 0 && ${:Uword:hash}
93 .endif
94
95 .if 0 && ${value:L}
96 .endif
97
98 # Before var.c 1.1050 from 2023-05-09, the ':localtime' modifier produced the
99 # error message 'Invalid time value: ${FAIL}}' since it did not expand its
100 # argument.
101 .if 0 && ${:Uword:localtime=${FAIL}}
102 .endif
103
104 .if 0 && ${:Uword:M${FAIL}}
105 .endif
106
107 .if 0 && ${:Uword:N${FAIL}}
108 .endif
109
110 .if 0 && ${:Uword:O}
111 .endif
112
113 .if 0 && ${:Uword:Ox}
114 .endif
115
116 .if 0 && ${:Uword:P}
117 .endif
118
119 .if 0 && ${:Uword:Q}
120 .endif
121
122 .if 0 && ${:Uword:q}
123 .endif
124
125 .if 0 && ${:Uword:R}
126 .endif
127
128 .if 0 && ${:Uword:range}
129 .endif
130
131 .if 0 && ${:Uword:S,${FAIL},${FAIL},}
132 .endif
133
134 .if 0 && ${:Uword:sh}
135 .endif
136
137 .if 0 && ${:Uword:T}
138 .endif
139
140 .if 0 && ${:Uword:ts/}
141 .endif
142
143 .if 0 && ${:U${FAIL}}
144 .endif
145
146 .if 0 && ${:Uword:u}
147 .endif
148
149 .if 0 && ${:Uword:word=replacement}
150 .endif
151
152 # Before var.c 1.875 from 2021-03-14, Var_Parse returned "${FAIL}else" for the
153 # irrelevant right-hand side of the condition, even though this was not
154 # necessary. Since the return value from Var_Parse is supposed to be ignored
155 # anyway, and since it is actually ignored in an overly complicated way,
156 # an empty string suffices.
157 .MAKEFLAGS: -dcpv
158 .if 0 && ${0:?${FAIL}then:${FAIL}else}
159 .endif
160
161 # The ':L' is applied before the ':?' modifier, giving the expression a name
162 # and a value, just to see whether this value gets passed through or whether
163 # the parse-only mode results in an empty string (only visible in the debug
164 # log). As of var.c 1.875 from 2021-03-14, the value of the variable gets
165 # through, even though an empty string would suffice.
166 DEFINED= defined
167 .if 0 && ${DEFINED:L:?${FAIL}then:${FAIL}else}
168 .endif
169 .MAKEFLAGS: -d0
170
171 all:
172