automake-patches
[Top][All Lists]
Advanced

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

FYI: -W and --warnings in AUTOMAKE_OPTIONS (Was: Re: monstro-patch: mach


From: Alexandre Duret-Lutz
Subject: FYI: -W and --warnings in AUTOMAKE_OPTIONS (Was: Re: monstro-patch: machinery to enable/disable warning/error categories)
Date: 16 Jul 2002 23:13:25 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

>>> "adl" == Alexandre Duret-Lutz <address@hidden> writes:

>>> "Tom" == Tom Tromey <address@hidden> writes:
 >>>>>>> "adl" == Alexandre Duret-Lutz <address@hidden> writes:
 adl> This means we need a way to save/restore the set of enabled
 adl> warnings (AUTOMAKE_OPTIONS can differs from one Makefile.am to
 adl> the other).  I'll add this to my TODO list.

 Tom> Is it a good idea to let them vary between Makefile.ams?
 Tom> That is the first question.  I think it probably is.  You might need a
 Tom> hack in one particular place but then want stricter checking
 Tom> everywhere else.
 Tom> But what do you think?

 adl> I agree.

 adl> Besides, unless we restrict these options to appear in
 adl> AM_INIT_AUTOMAKE (i.e. not in AUTOMAKE_OPTIONS), I think
 adl> ensuring that warnings do not vary between Makefile.ams is as
 adl> much work as allowing them to vary.

I'm checking in this.

2002-07-16  Alexandre Duret-Lutz  <address@hidden>

        * lib/Automake/Channels.pm (dup_channel_setup,
        drop_channel_setup): New functions.
        (@EXPORT): Add them.
        * automake.in (generate_makefile): Call dup_channel_setup and
        drop_channel_setup.
        (process_option_list): Recognize --warnings and -W options.
        * automake.texi (Options): Document them.
        * tests/pluseq5.test: Check that -Wno-obsolete will disable the
        warning.
        * tests/warnopts.test: New file.
        * tests/Makefile.am (TESTS): Add warnopts.test.

Index: automake.in
===================================================================
RCS file: /cvs/automake/automake/automake.in,v
retrieving revision 1.1328
diff -u -r1.1328 automake.in
--- automake.in 12 Jul 2002 08:00:56 -0000      1.1328
+++ automake.in 16 Jul 2002 21:42:18 -0000
@@ -1527,6 +1527,9 @@
     # Reset all the Makefile.am related variables.
     &initialize_per_input;
 
+    # Any warning setting now local to this Makefile.am.
+    &dup_channel_setup;
+
     # Name of input file ("Makefile.am") and output file
     # ("Makefile.in").  These have no directory components.
     $am_file_name = basename ($makefile) . '.am';
@@ -1689,6 +1692,9 @@
     print $gm_file $output_header;
     print $gm_file $output_rules;
     print $gm_file $output_trailer;
+
+    # Back out any warning setting.
+    &drop_channel_setup;
 }
 
 ################################################################
@@ -1834,6 +1840,14 @@
              err ($where, "require version $_, but have $VERSION",
                   uniq_scope => US_GLOBAL);
                return 1;
+           }
+       }
+      elsif (/^(?:--warnings=|-W)(.*)$/)
+       {
+         foreach my $cat (split (',', $1))
+           {
+             msg 'unsupported', $where, "unknown warning category `$cat'"
+               if switch_warning $cat;
            }
        }
       else
Index: automake.texi
===================================================================
RCS file: /cvs/automake/automake/automake.texi,v
retrieving revision 1.290
diff -u -r1.290 automake.texi
--- automake.texi       12 Jul 2002 08:00:57 -0000      1.290
+++ automake.texi       16 Jul 2002 21:42:35 -0000
@@ -4289,12 +4289,21 @@
 A version number (e.g. @samp{0.30}) can be specified.  If Automake is not
 newer than the version specified, creation of the @file{Makefile.in}
 will be suppressed.
+
address@hidden @address@hidden or @address@hidden
address@hidden Option, warnings
+These options behave exactly like their command-line counterpart
+(@pxref{Invoking Automake}).  This allows you to enable or disable some
+warning categories on a per-file basis.  You can also setup some warnings
+for your entire project; for instance try @code{AM_INIT_AUTOMAKE([-Wall])}
+in your @file{configure.in}.
+
 @end table
 
 Unrecognized options are diagnosed by @code{automake}.
 
 If you want an option to apply to all the files in the tree, you can use
-the @code{AM_AUTOMAKE_OPTIONS} macro in @file{configure.in}.
+the @code{AM_INIT_AUTOMAKE} macro in @file{configure.in}.
 @xref{Macros}.
 
 
Index: lib/Automake/Channels.pm
===================================================================
RCS file: /cvs/automake/automake/lib/Automake/Channels.pm,v
retrieving revision 1.1
diff -u -r1.1 Channels.pm
--- lib/Automake/Channels.pm    6 Jul 2002 10:21:35 -0000       1.1
+++ lib/Automake/Channels.pm    16 Jul 2002 21:42:36 -0000
@@ -67,6 +67,7 @@
                  &reset_local_duplicates &reset_global_duplicates
                  &register_channel &msg &exists_channel &channel_type
                  &setup_channel &setup_channel_type
+                  &dup_channel_setup &drop_channel_setup
                  US_GLOBAL US_LOCAL
                  UP_NONE UP_TEXT UP_LOC_TEXT);
 
@@ -489,6 +490,39 @@
       setup_channel $channel, %opts
        if $channels{$channel}{'type'} eq $type;
     }
+}
+
+=item C<dup_channel_setup ()>, C<drop_channel_setup ()>
+
+Sometimes it is necessary to make temporary modifications to channels.
+For instance one may want to disable a warning while processing a
+particular file, and then restore the initial setup.  These two
+functions make it easy: C<dup_channel_setup ()> saves a copy of the
+current configuration for later restoration by
+C<drop_channel_setup ()>.
+
+You can think of this as a stack of configurations whose first entry
+is the active one.  C<dup_channel_setup ()> duplicates the first
+entry, while C<drop_channel_setup ()> just deletes it.
+
+=cut
+
+our @_saved_channels = ();
+
+sub dup_channel_setup ()
+{
+  my %channels_copy;
+  foreach my $k1 (keys %channels)
+    {
+      $channels_copy{$k1} = {%{$channels{$k1}}};
+    }
+  push @_saved_channels, \%channels_copy;
+}
+
+sub drop_channel_setup ()
+{
+  my $saved = pop @_saved_channels;
+  %channels = %$saved;
 }
 
 =back
Index: tests/Makefile.am
===================================================================
RCS file: /cvs/automake/automake/tests/Makefile.am,v
retrieving revision 1.417
diff -u -r1.417 Makefile.am
--- tests/Makefile.am   12 Jul 2002 08:00:57 -0000      1.417
+++ tests/Makefile.am   16 Jul 2002 21:42:36 -0000
@@ -394,6 +394,7 @@
 vpath.test \
 vtexi.test \
 vtexi2.test \
+warnopts.test \
 werror.test \
 whoami.test \
 xsource.test \
Index: tests/pluseq5.test
===================================================================
RCS file: /cvs/automake/automake/tests/pluseq5.test,v
retrieving revision 1.4
diff -u -r1.4 pluseq5.test
--- tests/pluseq5.test  9 Jul 2002 20:46:19 -0000       1.4
+++ tests/pluseq5.test  16 Jul 2002 21:42:38 -0000
@@ -34,3 +34,12 @@
 # By the way, Automake should suggest using AM_CPPFLAGS,
 # because INCLUDES is an obsolete name.
 grep AM_CPPFLAGS stderr || exit 1
+
+# A way to suppress the obsolete warning is to use
+# -Wno-obsolete:
+echo 'AUTOMAKE_OPTIONS = -Wno-obsolete' >> Makefile.am
+$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
Index: tests/warnopts.test
===================================================================
RCS file: tests/warnopts.test
diff -N tests/warnopts.test
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ tests/warnopts.test 16 Jul 2002 21:42:38 -0000
@@ -0,0 +1,54 @@
+#! /bin/sh
+
+# Make sure that we can enable or disable warnings on a per-file basis.
+
+. $srcdir/defs || exit 1
+
+set -e
+
+
+cat >>configure.in <<END
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+mkdir sub
+
+# These two Makefile contain the same errors, but have different
+# warnings disabled.
+
+cat >Makefile.am <<END
+AUTOMAKE_OPTIONS = -Wno-obsolete
+INCLUDES = -Ifoo
+foo_SOURCES = unused
+SUBDIRS = sub
+END
+
+cat >sub/Makefile.am <<END
+AUTOMAKE_OPTIONS = -Wno-unused
+INCLUDES = -Ifoo
+foo_SOURCES = unused
+END
+
+$ACLOCAL
+$AUTOMAKE 2>stderr && exit 1
+cat stderr
+# The expected diagnostic is
+#   Makefile.am:3: unused variable: `foo_SOURCES'
+#   sub/Makefile.am:2: `INCLUDES' is the old name for `AM_CPPFLAGS'
+grep '^Makefile.am:.*foo_SOURCES' stderr
+grep '^sub/Makefile.am:.*INCLUDES' stderr
+grep '^sub/Makefile.am:.*foo_SOURCES' stderr && exit 1
+grep '^Makefile.am:.*INCLUDES' stderr && exit 1
+# Only two lines of warnings.
+test `wc -l < stderr` = 2
+
+# If we add a global -Wnone, all warnings should disappear.
+cat >configure.in <<END
+AC_INIT([warnopts], [1.0])
+AM_INIT_AUTOMAKE([-Wnone])
+AC_CONFIG_FILES([Makefile sub/Makefile])
+AC_OUTPUT
+END
+$ACLOCAL
+$AUTOMAKE

-- 
Alexandre Duret-Lutz




reply via email to

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