automake-patches
[Top][All Lists]
Advanced

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

FYI: Buffered warnings.


From: Alexandre Duret-Lutz
Subject: FYI: Buffered warnings.
Date: 23 Aug 2002 14:15:41 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

The issue is that since AUTOMAKE_OPTIONS allows diabling or enabling 
warning for the current file, we shouldn't print any warning before
AUTOMAKE_OPTIONS has been processed.

This doesn't look like a very sound constrain to put on the
developer.  Currently we already got it wrong in a few place: the
leading-`_'-not-portable and `%'-rule-not-portable warnings are
output while the Makefile.am is read, before AUTOMAKE_OPTIONS is
processed, so there is no easy way to disable these locally.

(This is why I moved leading-`_'-not-portable to &check_typos in
my PR/347 patch -- but that was a bad idea anyway, I'll explain
why when I repost the patch.)

I'm installing the following patch, which augments Channels.pm
with the capability to buffer messages, and use this to buffer
warnings until AUTOMAKE_OPTIONS has been processed.  This way we
don't have to care.  Warnings can be issued anywhere, they will
be processed when it's ok.

There will be a check for this in the test case of the new
PR/347 patch.

2002-08-23  Alexandre Duret-Lutz  <address@hidden>

        * lib/Automake/Channels.pm (buffering, backlog): New variables.
        (buffer_messages, flush_messages): New functions.
        (@EXPORT): Add buffer_messages and flush_messages.
        * automake.in (generate_makefile): Call buffer_messages and
        flush_messages to buffer warnings until AUTOMAKE_OPTIONS has
        been read.

Index: automake.in
===================================================================
RCS file: /cvs/automake/automake/automake.in,v
retrieving revision 1.1340
diff -u -r1.1340 automake.in
--- automake.in 22 Aug 2002 22:57:52 -0000      1.1340
+++ automake.in 23 Aug 2002 11:28:58 -0000
@@ -1529,6 +1529,10 @@
 
     # Any warning setting now local to this Makefile.am.
     &dup_channel_setup;
+    # AUTOMAKE_OPTIONS can contains -W flags to disable or enable
+    # warnings for this file.  So hold any warning issued before
+    # we have processed AUTOMAKE_OPTIONS.
+    &buffer_messages ('warning');
 
     # Name of input file ("Makefile.am") and output file
     # ("Makefile.in").  These have no directory components.
@@ -1549,9 +1553,13 @@
     &read_main_am_file ($makefile . '.am');
     if (&handle_options)
     {
-       # Fatal error.  Just return, so we can continue with next file.
-       return;
+      # Process buffered warnings.
+      &flush_messages;
+      # Fatal error.  Just return, so we can continue with next file.
+      return;
     }
+    # Process buffered warnings.
+    &flush_messages;
 
     # There are a few install-related variables that you should not define.
     foreach my $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
Index: lib/Automake/Channels.pm
===================================================================
RCS file: /cvs/automake/automake/lib/Automake/Channels.pm,v
retrieving revision 1.2
diff -u -r1.2 Channels.pm
--- lib/Automake/Channels.pm    16 Jul 2002 21:46:59 -0000      1.2
+++ lib/Automake/Channels.pm    23 Aug 2002 11:29:07 -0000
@@ -68,6 +68,7 @@
                  &register_channel &msg &exists_channel &channel_type
                  &setup_channel &setup_channel_type
                   &dup_channel_setup &drop_channel_setup
+                 &buffer_messages &flush_messages
                  US_GLOBAL US_LOCAL
                  UP_NONE UP_TEXT UP_LOC_TEXT);
 
@@ -429,6 +430,10 @@
 
 =cut
 
+# See buffer_messages() and flush_messages() below.
+our %buffering = ();           # The map of channel types to buffer.
+our @backlog = ();             # The buffer of messages.
+
 sub msg ($$;$%)
 {
   my ($channel, $location, $message, %options) = @_;
@@ -444,6 +449,12 @@
   my %opts = %{$channels{$channel}};
   _merge_options (%opts, %options);
 
+  if (exists $buffering{$opts{'type'}})
+    {
+      push @backlog, address@hidden;
+      return;
+    }
+
   # Print the message if needed.
   if (_print_message ($location, $message, %opts))
     {
@@ -523,6 +535,46 @@
 {
   my $saved = pop @_saved_channels;
   %channels = %$saved;
+}
+
+=item C<buffer_messages (@types)>, C<flush_messages ()>
+
+By default, when C<msg> is called, messages are processed immediately.
+
+Sometimes it is necessary to delay the output of messages.
+For instance you might want to make diagnostics before
+channels have been completly configured.
+
+After C<buffer_messages(@types)> has been called, messages sent with
+C<msg> to a channel whose type is listed in C<@types> will be stored in a
+list for later processing.
+
+This backlog of messages is processed when C<flush_messages> is
+called, with the current channel options (not the options in effect,
+at the time of C<msg>).  So for instance if some channel was silenced
+in the meantime, messages to this channels will not be print.
+
+C<flush_messages> cancels the effect of C<buffer_messages>.  Following
+calls to C<msg> are processed immediately as usual.
+
+=cut
+
+sub buffer_messages (@)
+{
+  foreach my $type (@_)
+    {
+      $buffering{$type} = 1;
+    }
+}
+
+sub flush_messages ()
+{
+  %buffering = ();
+  foreach my $args (@backlog)
+    {
+      &msg (@$args);
+    }
+  @backlog = ();
 }
 
 =back

-- 
Alexandre Duret-Lutz





reply via email to

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