On 06/02/2012 09:18 AM, Stefano Lattarini wrote:
>
> I've also pushed the attached patch as a follow-up, to fix a regression
> revealed by the more comprehensive tests in 'ng/master'.
> 
Yikes, the commit was botched :-/  I've amended it and pushed, thus
*rewriting the last commit of the 'ng/master' branch*.  I hope nobody
had already pulled that...

Sorry for the mess-up,
  Stefano
>From 3155551c638623bfe42f7f6b7c15f66d712956c4 Mon Sep 17 00:00:00 2001
Message-Id: <3155551c638623bfe42f7f6b7c15f66d712956c4.1338623016.git.stefano.lattar...@gmail.com>
From: Stefano Lattarini <[email protected]>
Date: Thu, 31 May 2012 17:52:51 +0200
Subject: [PATCH] [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 <[email protected]>
---
 lib/Automake/VarDef.pm |    9 ++++++++-
 t/backslash-tricks.sh  |    6 ++++++
 t/comment8.sh          |    7 ++++++-
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/lib/Automake/VarDef.pm b/lib/Automake/VarDef.pm
index 93ca49c..6bb9fa6 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 dea9e39..e236183 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 3ed31e7..58b5cd3 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
-- 
1.7.9.5

Reply via email to