automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FYI: ignore #comments in values


From: Alexandre Duret-Lutz
Subject: FYI: ignore #comments in values
Date: Sat, 29 Nov 2003 19:02:24 +0100
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3 (gnu/linux)

I'm checking this in.

2003-11-29  Alexandre Duret-Lutz  <address@hidden>

        * lib/Automake/VarDef.pm (value): Rename as ...
        (raw_value): ... this.
        (value): New method, strip # and \\\n.
        (dump): Use raw_value.
        * lib/Automake/Variable.pm (output): Use raw_value.
        (value_as_list): Simplify, now that backslash and comments
        are already removed.
        * tests/txinfo22.test: Make sure Automake isn't confused
        by comments in variables.

Index: lib/Automake/VarDef.pm
===================================================================
RCS file: /cvs/automake/automake/lib/Automake/VarDef.pm,v
retrieving revision 1.3
diff -u -r1.3 VarDef.pm
--- lib/Automake/VarDef.pm      12 Aug 2003 17:52:09 -0000      1.3
+++ lib/Automake/VarDef.pm      29 Nov 2003 17:56:31 -0000
@@ -38,17 +38,20 @@
 
   # Create a VarDef for a definition such as
   # | # any comment
-  # | foo = bar
+  # | foo = bar # more comment
   # in Makefile.am
   my $loc = new Automake::Location 'Makefile.am:2';
-  my $def = new Automake::VarDef ('foo', 'bar', '# any comment',
+  my $def = new Automake::VarDef ('foo', 'bar # more comment',
+                                  '# any comment',
                                   $loc, '', VAR_MAKEFILE, VAR_ASIS);
 
   # Appending to a definition.
   $def->append ('value to append', 'comment to append');
 
   # Accessors.
-  my $value    = $def->value;
+  my $value    = $def->value;  # with trailing `#' comments and
+                               # continuation ("\\\n") omitted.
+  my $value    = $def->raw_value; # the real value, as passed to new().
   my $comment  = $def->comment;
   my $location = $def->location;
   my $type     = $def->type;
@@ -202,6 +205,18 @@
 sub value ($)
 {
   my ($self) = @_;
+  my $val = $self->raw_value;
+  # Strip anything past `#'.  `#' characters cannot be escaped
+  # in Makefiles, so we don't have to be smart.
+  $val =~ s/#.*$//s;
+  # Strip backslashes.
+  $val =~ s/\\$/ /mg;
+  return $val;
+}
+
+sub raw_value ($)
+{
+  my ($self) = @_;
   return $self->{'value'};
 }
 
@@ -289,7 +304,7 @@
 
   my $where = $self->location->dump;
   my $comment = $self->comment;
-  my $value = $self->value;
+  my $value = $self->raw_value;
   my $type = $self->type;
 
   return "{
Index: lib/Automake/Variable.pm
===================================================================
RCS file: /cvs/automake/automake/lib/Automake/Variable.pm,v
retrieving revision 1.23
diff -u -r1.23 Variable.pm
--- lib/Automake/Variable.pm    24 Nov 2003 22:13:42 -0000      1.23
+++ lib/Automake/Variable.pm    29 Nov 2003 17:56:32 -0000
@@ -500,7 +500,7 @@
 
       $res .= $def->comment;
 
-      my $val = $def->value;
+      my $val = $def->raw_value;
       my $equals = $def->type eq ':' ? ':=' : '=';
       my $str = $cond->subst_string;
 
@@ -569,8 +569,6 @@
   my $onceflag;
   foreach my $vcond ($self->conditions->conds)
     {
-      my $val = $self->rdef ($vcond)->value;
-
       if ($vcond->true_when ($cond))
        {
          # If there is more than one definitions of $var matching
@@ -581,16 +579,8 @@
            if $onceflag;
          $onceflag = 1;
 
-         # Strip backslashes
-         $val =~ s/\\(\n|$)/ /g;
-
-         foreach (split (' ', $val))
-           {
-             # If a comment seen, just leave.
-             last if /^#/;
-
-             push (@result, $_);
-           }
+         my $val = $self->rdef ($vcond)->value;
+         push @result, split (' ', $val);
        }
     }
   return @result;
@@ -1259,7 +1249,7 @@
 Typically you should do C<$cond->merge ($parent_cond)> to recompute
 the C<$full_cond> associated to C<@result>.  C<&fun_collect> may
 return a list of items, that will be used as the result of
-C<Automake::Variable::traverse_recursively> (the top-level, or it's
+C<Automake::Variable::traverse_recursively> (the top-level, or its
 recursive calls).
 
 =cut
@@ -1314,8 +1304,8 @@
        {
          # If $val is a variable (i.e. ${foo} or $(bar), not a filename),
          # handle the sub variable recursively.
-         # (Backslashes between bracklets, before `}' and `)' are required
-         # only of Emacs's indentation.)
+         # (Backslashes before `}' and `)' within brackets are here to
+         # please Emacs's indentation.)
          if ($val =~ /^\$\{([^\}]*)\}$/ || $val =~ /^\$\(([^\)]*)\)$/)
            {
              my $subvarname = $1;
Index: tests/txinfo22.test
===================================================================
RCS file: /cvs/automake/automake/tests/txinfo22.test,v
retrieving revision 1.1
diff -u -r1.1 txinfo22.test
--- tests/txinfo22.test 5 Aug 2003 09:25:17 -0000       1.1
+++ tests/txinfo22.test 29 Nov 2003 17:56:33 -0000
@@ -20,6 +20,8 @@
 
 # Make sure the user can override TEXINFO_TEX.
 # Report from Tom Tromey.
+# Also make sure Automake ignores in-line comments when using variables,
+# but preserve them in the output.
 
 required='makeinfo tex'
 . ./defs || exit 1
@@ -31,11 +33,14 @@
 AC_OUTPUT
 END
 
+# Use a slash in the comment, because automake takes the dirname
+# of TEXINFO_TEX to compute $(am__TEXINFO_TEX_DIR)...
 cat > Makefile.am << 'END'
-TEXINFO_TEX = tex/texinfo.tex
+TEXINFO_TEX = $(srcdir)/tex/texinfo.tex    # some comment w/ a slash
 info_TEXINFOS = main.texi
 sure_it_exists:
        test -f $(TEXINFO_TEX)
+       test -d "$(am__TEXINFO_TEX_DIR)"
 END
 
 cat > main.texi << 'END'
@@ -62,3 +67,4 @@
 ./configure
 $MAKE sure_it_exists
 $MAKE distcheck
+grep 'TEXINFO_TEX = .* # some comment w/ a slash' Makefile

-- 
Alexandre Duret-Lutz





reply via email to

[Prev in Thread] Current Thread [Next in Thread]