automake-patches
[Top][All Lists]
Advanced

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

FYI: Automake::Conditional{,Set}::human


From: Alexandre Duret-Lutz
Subject: FYI: Automake::Conditional{,Set}::human
Date: Wed, 20 Nov 2002 23:03:02 +0100
User-agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/20.7 (i386-debian-linux-gnu)

Bruce Korb once complained (or if he didn't I'm sure he forgot) that
diagnostics containing strings like `FOO_TRUE BAR_FALSE' were too
cryptic.  Indeed the user only see things like `if FOO' or `if !BAR'
in his/her Makefile.am.  So I'm installing the following patch which
introduces a "human" representation for conditionals: e.g. `FOO and !BAR'.

2002-11-20  Alexandre Duret-Lutz  <address@hidden>

        * automake.in (conditional_ambiguous_p, macro_define, rule_define,
        require_variables): Use ->human instead of ->string.
        * lib/Automake/Conditional.pm (string): Don't sort conditions, they
        are already sorted.
        (_to_human, human): New functions.
        * lib/Automake/ConditionalSet.pm (human): New function.
        * tests/cond27.test, tests/library3.test, tests/pluseq5.test,
        tests/pluseq9.test: Adjust.

Index: automake.in
===================================================================
RCS file: /cvs/automake/automake/automake.in,v
retrieving revision 1.1391
diff -u -r1.1391 automake.in
--- automake.in 20 Nov 2002 20:12:48 -0000      1.1391
+++ automake.in 20 Nov 2002 21:53:03 -0000
@@ -6074,20 +6074,19 @@
       my $message;
       if ($vcond eq $cond)
        {
-         return ("$var multiply defined in condition ". $cond->string,
+         return ("$var multiply defined in condition " . $cond->human,
                  $vcond);
        }
       elsif ($vcond->true_when ($cond))
        {
-         return ("$var was already defined in condition "
-                 . $vcond->string . ", "
-                 . "which implies condition ". $cond->string, $vcond);
+         return ("$var was already defined in condition " . $vcond->human
+                 . ", which implies condition ". $cond->human, $vcond);
        }
       elsif ($cond->true_when ($vcond))
        {
          return ("$var was already defined in condition "
-                 . $vcond->string . ", "
-                  . "which is implied by condition " . $cond->string, $vcond);
+                 . $vcond->human . ", which is implied by condition "
+                 . $cond->human, $vcond);
        }
     }
   return ('', '');
@@ -6295,8 +6294,7 @@
              err ($where,
                   "Cannot apply `+=' because `$var' is not defined "
                   . "in\nthe following conditions:\n  "
-                  . join ("\n  ",
-                          map { $_->string } $undef_cond->conds)
+                  . join ("\n  ", map { $_->human } $undef_cond->conds)
                   . "\nEither define `$var' in these conditions,"
                   . " or use\n`+=' in the same conditions as"
                   . " the definitions.");
@@ -6321,7 +6319,7 @@
        {
          verb ("refusing to override the user definition of:\n"
                . macro_dump ($var)
-               ."with `$cond->string' => `$value'");
+               ."with `$cond->human' => `$value'");
        }
       else
        {
@@ -7324,7 +7322,8 @@
       my $oldowner  = $target_owner{$target}{$cond};
 
       # Don't mention true conditions in diagnostics.
-      my $condmsg = $cond == TRUE ? " in condition `" . $cond->string . "'" : 
'';
+      my $condmsg =
+       $cond == TRUE ? " in condition `" . $cond->human . "'" : '';
 
       if ($owner == TARGET_USER)
        {
@@ -8933,7 +8932,7 @@
       if (! $undef_cond->true)
        {
          $text .= ("in the following conditions:\n  "
-                   . join ("\n  ", map { $_->string } $undef_cond->conds));
+                   . join ("\n  ", map { $_->human } $undef_cond->conds));
        }
 
       ++$res;
Index: lib/Automake/Conditional.pm
===================================================================
RCS file: /cvs/automake/automake/lib/Automake/Conditional.pm,v
retrieving revision 1.6
diff -u -r1.6 Conditional.pm
--- lib/Automake/Conditional.pm 20 Nov 2002 20:12:50 -0000      1.6
+++ lib/Automake/Conditional.pm 20 Nov 2002 21:53:05 -0000
@@ -57,6 +57,10 @@
   #  "COND1_TRUE COND2_FALSE"
   my $str = $cond->string;
 
+  # Return the list of conditions as a human readable string:
+  #  "COND1 and !COND2"
+  my $str = $cond->human;
+
   # Return the list of conditions as a AC_SUBST-style string:
   #  "@COND1_TRUE@@COND2_FALSE@"
   my $subst = $cond->subst_string;
@@ -296,9 +300,50 @@
     }
   else
     {
-      $res = join (' ', sort $self->conds);
+      $res = join (' ', $self->conds);
     }
   $self->{'string'} = $res;
+  return $res;
+}
+
+=item C<$cond-E<gt>human>
+
+Build a human readable string which denotes the conditional.
+
+For instance using the C<$cond> definition from L<SYNOPSYS>,
+C<$cond-E<gt>string> will return C<"COND1 and !COND2">.
+
+=cut
+
+sub _to_human ($ )
+{
+  my ($s) = @_;
+  if ($s =~ /^(.*)_(TRUE|FALSE)$/)
+    {
+      return (($2 eq 'FALSE') ? '!' : '') . $1;
+    }
+  else
+    {
+      return $s;
+    }
+}
+
+sub human ($ )
+{
+  my ($self) = @_;
+
+  return $self->{'human'} if defined $self->{'human'};
+
+  my $res = '';
+  if ($self->false)
+    {
+      $res = 'FALSE';
+    }
+  else
+    {
+      $res = join (' and ', map { _to_human $_ } $self->conds);
+    }
+  $self->{'human'} = $res;
   return $res;
 }
 
Index: lib/Automake/ConditionalSet.pm
===================================================================
RCS file: /cvs/automake/automake/lib/Automake/ConditionalSet.pm,v
retrieving revision 1.7
diff -u -r1.7 ConditionalSet.pm
--- lib/Automake/ConditionalSet.pm      20 Nov 2002 20:12:50 -0000      1.7
+++ lib/Automake/ConditionalSet.pm      20 Nov 2002 21:53:07 -0000
@@ -37,8 +37,13 @@
   if ($set->false) { ... }
 
   # Return a string representing the ConditionalSet.
+  #   "COND1_TRUE COND2_FALSE | COND3_FALSE"
   my $str = $set->string;
 
+  # Return a human readable string representing the ConditionalSet.
+  #   "(COND1 and !COND2) or (!COND3)"
+  my $str = $set->human;
+
   # Build a new ConditionalSet from the permuation of all
   # subconditions appearing in $set.
   my $perm = $set->permutations;
@@ -225,6 +230,39 @@
     }
 
   $self->{'string'} = $res;
+  return $res;
+}
+
+=item C<$cond-E<gt>human>
+
+Build a human readable string which denotes the C<ConditionalSet>.
+
+=cut
+
+sub human ($ )
+{
+  my ($self) = @_;
+
+  return $self->{'human'} if defined $self->{'human'};
+
+  my $res = '';
+  if ($self->false)
+    {
+      $res = 'FALSE';
+    }
+  else
+    {
+      my @c = $self->conds;
+      if (1 == @c)
+       {
+         $res = $self->human;
+       }
+      else
+       {
+         $res = '(' . join (') or (', map { $_->human } $self->conds) . ')';
+       }
+    }
+  $self->{'human'} = $res;
   return $res;
 }
 
Index: tests/cond27.test
===================================================================
RCS file: /cvs/automake/automake/tests/cond27.test,v
retrieving revision 1.1
diff -u -r1.1 cond27.test
--- tests/cond27.test   30 Sep 2002 18:08:07 -0000      1.1
+++ tests/cond27.test   20 Nov 2002 21:53:07 -0000
@@ -39,5 +39,5 @@
 $ACLOCAL
 $AUTOMAKE 2>stderr && exit 1
 cat stderr
-grep USE_FOO_TRUE stderr && exit 1
-grep USE_FOO_FALSE stderr
+grep ' USE_FOO' stderr && exit 1
+grep '!USE_FOO' stderr
Index: tests/library3.test
===================================================================
RCS file: /cvs/automake/automake/tests/library3.test,v
retrieving revision 1.1
diff -u -r1.1 library3.test
--- tests/library3.test 19 Nov 2002 20:02:40 -0000      1.1
+++ tests/library3.test 20 Nov 2002 21:53:08 -0000
@@ -54,6 +54,6 @@
 $ACLOCAL
 $AUTOMAKE 2>stderr && exit 1
 cat stderr
-grep '^Makefile.am:.*:   A_FALSE C_FALSE D_FALSE$' stderr
+grep '^Makefile.am:.*:   !A and !C and !D$' stderr
 # Is there only one missing condition?
 test `grep ':  ' stderr | wc -l` = 1 || exit 1
Index: tests/pluseq5.test
===================================================================
RCS file: /cvs/automake/automake/tests/pluseq5.test,v
retrieving revision 1.6
diff -u -r1.6 pluseq5.test
--- tests/pluseq5.test  8 Sep 2002 13:07:55 -0000       1.6
+++ tests/pluseq5.test  20 Nov 2002 21:53:08 -0000
@@ -40,12 +40,12 @@
 #
 # Makefile.am:4: Cannot apply `+=' because `INCLUDES' is not defined in
 # Makefile.am:4: the following conditions:
-# Makefile.am:4:   CHECK_FALSE
+# Makefile.am:4:   !CHECK
 # Makefile.am:4: Either define `INCLUDES' in these conditions, or use
 # Makefile.am:4: `+=' in the same conditions as the definitions.
 
-# Is CHECK_FALSE mentioned?
-grep ':.*CHECK_FALSE$' stderr || exit 1
+# Is !CHECK mentioned?
+grep ':.*!CHECK$' stderr || exit 1
 # Is there only one missing condition?
 test `grep ':  ' stderr | wc -l` = 1 || exit 1
 
@@ -59,5 +59,5 @@
 $AUTOMAKE 2>stderr && exit 1
 cat stderr
 grep AM_CPPFLAGS stderr && exit 1
-# CHECK_FALSE should still be mentioned.
-grep ':.*CHECK_FALSE$' stderr || exit 1
+# !CHECK should still be mentioned.
+grep ':.*!CHECK$' stderr || exit 1
Index: tests/pluseq9.test
===================================================================
RCS file: /cvs/automake/automake/tests/pluseq9.test,v
retrieving revision 1.4
diff -u -r1.4 pluseq9.test
--- tests/pluseq9.test  19 Nov 2002 20:02:40 -0000      1.4
+++ tests/pluseq9.test  20 Nov 2002 21:53:08 -0000
@@ -61,7 +61,7 @@
 #
 # Makefile.am:19: Cannot apply `+=' because `B' is not defined in
 # Makefile.am:19: the following conditions:
-# Makefile.am:19:   COND1_FALSE COND3_FALSE
+# Makefile.am:19:   !COND1 and !COND3
 # Makefile.am:19: Either define `B' in these conditions, or use
 # Makefile.am:19: `+=' in the same conditions as the definitions.
 #
@@ -69,7 +69,7 @@
 # COND1_FALSE (merging the last two conditions), so we'll support
 # this case in the check too.
 
-grep ':   COND1_FALSE COND3_FALSE$' stderr || exit 1
+grep ':   !COND1 and !COND3$' stderr || exit 1
 # Make sure there is exactly one missing condition.
 test `grep ':  ' stderr | wc -l` = 1 || exit 1
 

-- 
Alexandre Duret-Lutz





reply via email to

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