]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
[ng] vars: recognize escaped '#' correctly in a variable definition
authorStefano Lattarini <stefano.lattarini@gmail.com>
Thu, 31 May 2012 15:52:51 +0000 (17:52 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Sat, 2 Jun 2012 07:38:10 +0000 (09:38 +0200)
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 <stefano.lattarini@gmail.com>
lib/Automake/VarDef.pm
t/backslash-tricks.sh
t/comment8.sh

index 93ca49cc5bea95284bba17bca01f623da8e475fa..6bb9fa69b769110ba6a3855aa7bedca7d7741c69 100644 (file)
@@ -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);
 }
 
index dea9e3906e5d4d6fef294d132dff4d86650c9128..e236183fd355508b913f664cc69803a5350bc58d 100755 (executable)
@@ -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?
 \
index 3ed31e7c7cf2dbbd20452ab03f0d65993f21acc3..58b5cd3d7e645a3cae1f9effa10cf24523eff597 100755 (executable)
@@ -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