From: Stefano Lattarini Date: Thu, 31 May 2012 15:52:51 +0000 (+0200) Subject: [ng] vars: recognize escaped '#' correctly in a variable definition X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3155551c638623bfe42f7f6b7c15f66d712956c4;p=thirdparty%2Fautomake.git [ng] vars: recognize escaped '#' correctly in a variable definition Regression revealed by a failure in test 't/backslash-tricks.sh', and caused by the recent merge of the 'ng/var-simplify' branch. It is worth noting that this change has a collateral effect: comments placed after the variable definition *must* now be separated with one or more spaces from said definition: # This won't work, and will produce a subtly broken Makefile foo = val# comment foo += val2 # Please do this instead foo = val # comment foo += val2 We believe that supporting the use of escaped '#' characters in variable definitions is more important than supporting the fringe case above. * lib/Automake/VarDef.pm (raw_value): Fix processing of stored value to account for escaped '#' characters. (value): Add a FIXME comment about a statement that is not strictly true anymore now that we assume GNU make. * t/backslash-tricks.sh: Extend a bit. * t/comment8.sh: Relax a bit, by placing spaces between the variable's definitions and the comments on the same line. Extend in another respect, to watch against a regression introduced by the first draft of this commit. Signed-off-by: Stefano Lattarini --- diff --git a/lib/Automake/VarDef.pm b/lib/Automake/VarDef.pm index 93ca49cc5..6bb9fa69b 100644 --- a/lib/Automake/VarDef.pm +++ b/lib/Automake/VarDef.pm @@ -173,6 +173,8 @@ sub value ($) # Strip anything past '#'. '#' characters cannot be escaped # in Makefiles, so we don't have to be smart. + # FIXME: Actually, '#' *can* be escaped in GNU make ... + # FIXME: Should we adapt our code? $val =~ s/#.*$//s; # Strip backslashes. $val =~ s/\\$/ /mg; @@ -197,7 +199,12 @@ sub raw_value ($) # VAR = foo # com bar # Furthermore keeping '#' would not be portable if the variable is # output on multiple lines. - map { s/ ?#.*// } @values; + # But we have to preserve escaped '#', so that a definition line: + # hash = \# + # remains possible. To make our life easier, we just assume that + # any tailed comment must be separated with whitespace from the + # actual variable value. + map { s/^#.*//; s/[ \t]+#.*// } @values; return join (' ', @values); } diff --git a/t/backslash-tricks.sh b/t/backslash-tricks.sh index dea9e3906..e236183fd 100755 --- a/t/backslash-tricks.sh +++ b/t/backslash-tricks.sh @@ -48,6 +48,11 @@ var4 = $(var3) var5 = ok \ # ko +var6 = \# \ +\#\\\\\# seen # not seen + +var6 += \# \# # again not seen + .PHONY: test test: test -z '$(var1)' @@ -57,6 +62,7 @@ test: # Use '[', not 'test', here, so that spurious comments # are ensured to cause syntax errors. [ $(var5) = ok ] + test '$(var6)' = '# #\\# seen # #' # Yes, this file ends with a backslash-newline. So what? \ diff --git a/t/comment8.sh b/t/comment8.sh index 3ed31e7c7..58b5cd3d7 100755 --- a/t/comment8.sh +++ b/t/comment8.sh @@ -26,7 +26,7 @@ AC_OUTPUT EOF cat > Makefile.am << 'EOF' -VAR = valA# comA ## com C +VAR = valA # comA ## com C VAR += valB # comB if COND1 VAR += val1 # com1 @@ -35,10 +35,15 @@ VAR += valC if COND2 VAR += val2 # com2 endif COND2 +VAR2 = # this will be happily ignored +VAR2 += x +VAR2 += # this will be happily ignored too +VAR2 += y .PHONY: test test: is $(VAR) == valA valB val1 valC val2 + is $(VAR2) == x y EOF $ACLOCAL