varmod-match-escape.mk revision 1.4 1 1.4 rillig # $NetBSD: varmod-match-escape.mk,v 1.4 2020/11/01 19:25:23 rillig Exp $
2 1.1 rillig #
3 1.1 rillig # As of 2020-08-01, the :M and :N modifiers interpret backslashes differently,
4 1.1 rillig # depending on whether there was a variable expression somewhere before the
5 1.1 rillig # first backslash or not. See ApplyModifier_Match, "copy = TRUE".
6 1.1 rillig #
7 1.1 rillig # Apart from the different and possibly confusing debug output, there is no
8 1.1 rillig # difference in behavior. When parsing the modifier text, only \{, \} and \:
9 1.1 rillig # are unescaped, and in the pattern matching these have the same meaning as
10 1.1 rillig # their plain variants '{', '}' and ':'. In the pattern matching from
11 1.1 rillig # Str_Match, only \*, \? or \[ would make a noticeable difference.
12 1.4 rillig
13 1.4 rillig .MAKEFLAGS: -dcv
14 1.4 rillig
15 1.1 rillig SPECIALS= \: : \\ * \*
16 1.1 rillig .if ${SPECIALS:M${:U}\:} != ${SPECIALS:M\:${:U}}
17 1.2 rillig . warning unexpected
18 1.1 rillig .endif
19 1.4 rillig
20 1.4 rillig # And now both cases combined: A single modifier with both an escaped ':'
21 1.4 rillig # as well as a variable expression that expands to a ':'.
22 1.4 rillig #
23 1.4 rillig # XXX: As of 2020-11-01, when an escaped ':' occurs before the variable
24 1.4 rillig # expression, the whole modifier text is subject to unescaping '\:' to ':',
25 1.4 rillig # before the variable expression is expanded. This means that the '\:' in
26 1.4 rillig # the variable expression is expanded as well, turning ${:U\:} into a simple
27 1.4 rillig # ${:U:}, which silently expands to an empty string, instead of generating
28 1.4 rillig # an error message.
29 1.4 rillig #
30 1.4 rillig # XXX: As of 2020-11-01, the modifier on the right-hand side of the
31 1.4 rillig # comparison is parsed differently though. First, the variable expression
32 1.4 rillig # is parsed, resulting in ':' and needSubst=TRUE. After that, the escaped
33 1.4 rillig # ':' is seen, and this time, copy=TRUE is not executed but stays copy=FALSE.
34 1.4 rillig # Therefore the escaped ':' is kept as-is, and the final pattern becomes
35 1.4 rillig # ':\:'.
36 1.4 rillig #
37 1.4 rillig # If ApplyModifier_Match had used the same parsing algorithm as Var_Subst,
38 1.4 rillig # both patterns would end up as '::'.
39 1.4 rillig #
40 1.4 rillig VALUES= : :: :\:
41 1.4 rillig .if ${VALUES:M\:${:U\:}} != ${VALUES:M${:U\:}\:}
42 1.4 rillig . warning XXX: Oops
43 1.4 rillig .endif
44 1.4 rillig
45 1.3 rillig .MAKEFLAGS: -d0
46 1.1 rillig
47 1.1 rillig all:
48 1.1 rillig @:;
49