automake-patches
[Top][All Lists]
Advanced

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

[PATCH] Use ‘use warnings’ instead of -w on #! lines.


From: Zack Weinberg
Subject: [PATCH] Use ‘use warnings’ instead of -w on #! lines.
Date: Sat, 12 Sep 2020 11:10:11 -0400

Some downstream redistributors for Autoconf wish to use
‘/usr/bin/env perl’ as the #! line for the installed Perl scripts.
This does not work with command-line options on the #! line, as the
kernel doesn’t support supplying more than one argument to a #!
interpreter (this limitation is universal across Unixes that
support #!, as far as I know).

In order to make their lives easier, we (Autoconf, the project)
wish to remove -w from all our #! lines and instead add
‘use warnings;’ to all the scripts *and* all the .pm files.
(The -w command line option turns on warnings globally, but
‘use warnings’ only turns on warnings for the current lexical
scope.)  Since some of the .pm files used by Autoconf are shared
with Automake, this patch makes the necessary changes in Automake
-- for internal consistency, I did it to to *all* of Automake’s
perl scripts and modules, not just the ones shared with Autoconf.

The ‘use warnings’ directive was added to Perl in version
5.6.0 (aka 5.006) so there is no change to the minimum Perl
requirement.

At the same time, I rationalized the order of ‘use’ directives.
All the scripts and modules now ‘use’ other modules in the
following order:

 - use 5.006; use strict; use warnings FATAL => 'all'; in that
   order.  If a file was not already use-ing one of these three,
   it was added.  Despite the dire cautions about turning
   warnings into errors in the Perl manual, I think it’s the
   correct thing to do for these scripts.

 - The BEGIN block that adds the installation directory for the
   Automake:: modules to @INC (scripts only).

 - All stdlib modules whose name begins with a capital letter,
   in ASCII sort order.

 - All Automake:: modules.  I did not sort these directives
   because it was not clear to me whether there might be order
   dependencies.

 - ‘use vars qw (...)’, if any, last.

‘use foo qw (...)’ and @ISA lists have also been sorted into
ASCII sort order.  (@EXPORT lists, which often follow immediately
after @ISA lists, have *not* been sorted, as these appear to have
been organized semantically in many cases.)  qw delimiters have
been normalized to round parentheses with a space between the qw
and the open paren.  ‘require Exporter’ has been replaced by
‘use Exporter’ and it’s been sorted with the rest of the stdlib
modules.

Finally, unnecessary imports of Carp, DynaLoader, and
File::Basename have been removed from Automake/XFile.pm.
(This happened to catch my eye while doing all of the above
work, because it’s the only place that mentions DynaLoader.
I did not do a comprehensive check for unnecessary imports.)

No new test failures on x86-64-linux are observed.
---
 bin/aclocal.in                 | 11 +++++++----
 bin/automake.in                | 11 +++++++----
 lib/Automake/ChannelDefs.pm    | 25 +++++++++++++------------
 lib/Automake/Channels.pm       |  7 ++++---
 lib/Automake/Condition.pm      | 12 +++++++-----
 lib/Automake/Config.in         |  6 ++++--
 lib/Automake/Configure_ac.pm   |  8 +++++---
 lib/Automake/DisjConditions.pm |  4 +++-
 lib/Automake/FileUtils.pm      |  6 ++++--
 lib/Automake/General.pm        |  4 +++-
 lib/Automake/Getopt.pm         | 10 ++++++----
 lib/Automake/Item.pm           |  3 +++
 lib/Automake/ItemDef.pm        |  2 ++
 lib/Automake/Language.pm       |  2 ++
 lib/Automake/Location.pm       |  2 ++
 lib/Automake/Options.pm        |  6 ++++--
 lib/Automake/Rule.pm           |  9 ++++++---
 lib/Automake/RuleDef.pm        |  9 ++++++---
 lib/Automake/VarDef.pm         |  9 ++++++---
 lib/Automake/Variable.pm       |  8 +++++---
 lib/Automake/Version.pm        |  2 ++
 lib/Automake/Wrap.pm           | 10 ++++++----
 lib/Automake/XFile.pm          | 19 ++++++++-----------
 23 files changed, 115 insertions(+), 70 deletions(-)

diff --git a/bin/aclocal.in b/bin/aclocal.in
index b61fed818..c968bd710 100644
--- a/bin/aclocal.in
+++ b/bin/aclocal.in
@@ -1,4 +1,4 @@
-#!@PERL@ -w
+#!@PERL@
 # aclocal - create aclocal.m4 by scanning configure.ac      -*- perl -*-
 # @configure_input@
 # Copyright (C) 1996-2020 Free Software Foundation, Inc.
@@ -19,13 +19,18 @@
 # Written by Tom Tromey <tromey@redhat.com>, and
 # Alexandre Duret-Lutz <adl@gnu.org>.
 
+use 5.006;
+use strict;
+use warnings FATAL => 'all';
+
 BEGIN
 {
   unshift (@INC, '@datadir@/@PACKAGE@-@APIVERSION@')
     unless $ENV{AUTOMAKE_UNINSTALLED};
 }
 
-use strict;
+use File::Basename;
+use File::Path ();
 
 use Automake::Config;
 use Automake::General;
@@ -34,8 +39,6 @@ use Automake::Channels;
 use Automake::ChannelDefs;
 use Automake::XFile;
 use Automake::FileUtils;
-use File::Basename;
-use File::Path ();
 
 # Some globals.
 
diff --git a/bin/automake.in b/bin/automake.in
index c12078711..1e4ccc8df 100644
--- a/bin/automake.in
+++ b/bin/automake.in
@@ -1,4 +1,4 @@
-#!@PERL@ -w
+#!@PERL@
 # automake - create Makefile.in from Makefile.am            -*- perl -*-
 # @configure_input@
 # Copyright (C) 1994-2020 Free Software Foundation, Inc.
@@ -22,7 +22,9 @@
 
 package Automake;
 
+use 5.006;
 use strict;
+use warnings FATAL => 'all';
 
 BEGIN
 {
@@ -39,6 +41,10 @@ BEGIN
   $ENV{'SHELL'} = '@SHELL@' if exists $ENV{'DJDIR'};
 }
 
+use Carp;
+use File::Basename;
+use File::Spec;
+
 use Automake::Config;
 BEGIN
 {
@@ -66,9 +72,6 @@ use Automake::Rule;
 use Automake::RuleDef;
 use Automake::Wrap 'makefile_wrap';
 use Automake::Language;
-use File::Basename;
-use File::Spec;
-use Carp;
 
 ## ----------------------- ##
 ## Subroutine prototypes.  ##
diff --git a/lib/Automake/ChannelDefs.pm b/lib/Automake/ChannelDefs.pm
index 2ee6dd8ef..37c5a2715 100644
--- a/lib/Automake/ChannelDefs.pm
+++ b/lib/Automake/ChannelDefs.pm
@@ -15,17 +15,6 @@
 
 package Automake::ChannelDefs;
 
-use Automake::Config;
-BEGIN
-{
-  if ($perl_threads)
-    {
-      require threads;
-      import threads;
-    }
-}
-use Automake::Channels;
-
 =head1 NAME
 
 Automake::ChannelDefs - channel definitions for Automake and helper functions
@@ -57,10 +46,22 @@ shorthand function to output on specific channels.
 
 use 5.006;
 use strict;
+use warnings FATAL => 'all';
+
 use Exporter;
 
-use vars qw (@ISA @EXPORT);
+use Automake::Channels;
+use Automake::Config;
+BEGIN
+{
+  if ($perl_threads)
+    {
+      require threads;
+      import threads;
+    }
+}
 
+use vars qw (@EXPORT @ISA);
 @ISA = qw (Exporter);
 @EXPORT = qw (&prog_error &error &fatal &verb
              &switch_warning &parse_WARNINGS &parse_warnings);
diff --git a/lib/Automake/Channels.pm b/lib/Automake/Channels.pm
index 5fb01f550..7cc7ffdf6 100644
--- a/lib/Automake/Channels.pm
+++ b/lib/Automake/Channels.pm
@@ -68,12 +68,13 @@ etc.) that can also be overridden on a per-message basis.
 
 use 5.006;
 use strict;
-use Exporter;
+use warnings FATAL => 'all';
+
 use Carp;
+use Exporter;
 use File::Basename;
 
-use vars qw (@ISA @EXPORT %channels $me);
-
+use vars qw (@EXPORT @ISA %channels $me);
 @ISA = qw (Exporter);
 @EXPORT = qw ($exit_code $warnings_are_errors
              &reset_local_duplicates &reset_global_duplicates
diff --git a/lib/Automake/Condition.pm b/lib/Automake/Condition.pm
index 764411691..072602afe 100644
--- a/lib/Automake/Condition.pm
+++ b/lib/Automake/Condition.pm
@@ -17,12 +17,14 @@ package Automake::Condition;
 
 use 5.006;
 use strict;
-use Carp;
+use warnings FATAL => 'all';
 
-require Exporter;
-use vars '@ISA', '@EXPORT_OK';
-@ISA = qw/Exporter/;
-@EXPORT_OK = qw/TRUE FALSE reduce_and reduce_or/;
+use Carp;
+use Exporter;
+
+use vars qw (@EXPORT_OK @ISA);
+@ISA = qw (Exporter);
+@EXPORT_OK = qw (TRUE FALSE reduce_and reduce_or);
 
 =head1 NAME
 
diff --git a/lib/Automake/Config.in b/lib/Automake/Config.in
index f79b8cd40..d44e0ab94 100644
--- a/lib/Automake/Config.in
+++ b/lib/Automake/Config.in
@@ -16,10 +16,12 @@
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 package Automake::Config;
-use strict;
 
 use 5.006;
-require Exporter;
+use strict;
+use warnings FATAL => 'all';
+
+use Exporter;
 
 our @ISA = qw (Exporter);
 our @EXPORT = qw ($APIVERSION $PACKAGE $PACKAGE_BUGREPORT $VERSION
diff --git a/lib/Automake/Configure_ac.pm b/lib/Automake/Configure_ac.pm
index d60191b88..0d9b465e6 100644
--- a/lib/Automake/Configure_ac.pm
+++ b/lib/Automake/Configure_ac.pm
@@ -22,12 +22,14 @@ package Automake::Configure_ac;
 
 use 5.006;
 use strict;
+use warnings FATAL => 'all';
+
 use Exporter;
-use Automake::Channels;
+
 use Automake::ChannelDefs;
+use Automake::Channels;
 
-use vars qw (@ISA @EXPORT);
-
+use vars qw (@EXPORT @ISA);
 @ISA = qw (Exporter);
 @EXPORT = qw (&find_configure_ac &require_configure_ac);
 
diff --git a/lib/Automake/DisjConditions.pm b/lib/Automake/DisjConditions.pm
index dbe311ebc..af9d1a955 100644
--- a/lib/Automake/DisjConditions.pm
+++ b/lib/Automake/DisjConditions.pm
@@ -17,8 +17,10 @@ package Automake::DisjConditions;
 
 use 5.006;
 use strict;
+use warnings FATAL => 'all';
+
 use Carp;
-use Automake::Condition qw/TRUE FALSE/;
+use Automake::Condition qw (TRUE FALSE);
 
 =head1 NAME
 
diff --git a/lib/Automake/FileUtils.pm b/lib/Automake/FileUtils.pm
index 40e236d4d..65f9216df 100644
--- a/lib/Automake/FileUtils.pm
+++ b/lib/Automake/FileUtils.pm
@@ -36,14 +36,16 @@ This perl module provides various general purpose file 
handling functions.
 
 use 5.006;
 use strict;
+use warnings FATAL => 'all';
+
 use Exporter;
 use File::stat;
 use IO::File;
+
 use Automake::Channels;
 use Automake::ChannelDefs;
 
-use vars qw (@ISA @EXPORT);
-
+use vars qw (@EXPORT @ISA);
 @ISA = qw (Exporter);
 @EXPORT = qw (&contents
              &find_file &mtime
diff --git a/lib/Automake/General.pm b/lib/Automake/General.pm
index dbb2138b6..ea7032cd1 100644
--- a/lib/Automake/General.pm
+++ b/lib/Automake/General.pm
@@ -17,10 +17,12 @@ package Automake::General;
 
 use 5.006;
 use strict;
+use warnings FATAL => 'all';
+
 use Exporter;
 use File::Basename;
 
-use vars qw (@ISA @EXPORT);
+use vars qw (@EXPORT @ISA);
 
 @ISA = qw (Exporter);
 @EXPORT = qw (&uniq &none $me);
diff --git a/lib/Automake/Getopt.pm b/lib/Automake/Getopt.pm
index f8dc0acaf..5d7d57bae 100644
--- a/lib/Automake/Getopt.pm
+++ b/lib/Automake/Getopt.pm
@@ -33,14 +33,16 @@ line options in conformance to the GNU Coding standards.
 use 5.006;
 use strict;
 use warnings FATAL => 'all';
+
+use Carp qw (confess croak);
 use Exporter ();
 use Getopt::Long ();
-use Automake::ChannelDefs qw/fatal/;
-use Carp qw/croak confess/;
 
-use vars qw (@ISA @EXPORT);
+use Automake::ChannelDefs qw (fatal);
+
+use vars qw (@EXPORT @ISA);
 @ISA = qw (Exporter);
-@EXPORT= qw/getopt/;
+@EXPORT = qw (getopt);
 
 =item C<parse_options (%option)>
 
diff --git a/lib/Automake/Item.pm b/lib/Automake/Item.pm
index 85e114d9d..aee23e778 100644
--- a/lib/Automake/Item.pm
+++ b/lib/Automake/Item.pm
@@ -17,7 +17,10 @@ package Automake::Item;
 
 use 5.006;
 use strict;
+use warnings FATAL => 'all';
+
 use Carp;
+
 use Automake::ChannelDefs;
 use Automake::DisjConditions;
 
diff --git a/lib/Automake/ItemDef.pm b/lib/Automake/ItemDef.pm
index debcaa521..995fb11eb 100644
--- a/lib/Automake/ItemDef.pm
+++ b/lib/Automake/ItemDef.pm
@@ -17,6 +17,8 @@ package Automake::ItemDef;
 
 use 5.006;
 use strict;
+use warnings FATAL => 'all';
+
 use Carp;
 
 =head1 NAME
diff --git a/lib/Automake/Language.pm b/lib/Automake/Language.pm
index 4d5fa8056..b85e0fa54 100644
--- a/lib/Automake/Language.pm
+++ b/lib/Automake/Language.pm
@@ -17,8 +17,10 @@ package Automake::Language;
 
 use 5.006;
 use strict;
+use warnings FATAL => 'all';
 
 use Class::Struct ();
+
 Class::Struct::struct (
        # Short name of the language (c, f77...).
        'name' => "\$",
diff --git a/lib/Automake/Location.pm b/lib/Automake/Location.pm
index 8e4d1c79f..611cd0220 100644
--- a/lib/Automake/Location.pm
+++ b/lib/Automake/Location.pm
@@ -16,6 +16,8 @@
 package Automake::Location;
 
 use 5.006;
+use strict;
+use warnings FATAL => 'all';
 
 =head1 NAME
 
diff --git a/lib/Automake/Options.pm b/lib/Automake/Options.pm
index 59e29c583..5e20a3410 100644
--- a/lib/Automake/Options.pm
+++ b/lib/Automake/Options.pm
@@ -17,14 +17,16 @@ package Automake::Options;
 
 use 5.006;
 use strict;
+use warnings FATAL => 'all';
+
 use Exporter;
+
 use Automake::Config;
 use Automake::ChannelDefs;
 use Automake::Channels;
 use Automake::Version;
 
-use vars qw (@ISA @EXPORT);
-
+use vars qw (@EXPORT @ISA);
 @ISA = qw (Exporter);
 @EXPORT = qw (option global_option
               set_option set_global_option
diff --git a/lib/Automake/Rule.pm b/lib/Automake/Rule.pm
index 35e7b273f..0227a85d1 100644
--- a/lib/Automake/Rule.pm
+++ b/lib/Automake/Rule.pm
@@ -17,7 +17,10 @@ package Automake::Rule;
 
 use 5.006;
 use strict;
+use warnings FATAL => 'all';
+
 use Carp;
+use Exporter;
 
 use Automake::Item;
 use Automake::RuleDef;
@@ -26,9 +29,9 @@ use Automake::Channels;
 use Automake::Options;
 use Automake::Condition qw (TRUE FALSE);
 use Automake::DisjConditions;
-require Exporter;
-use vars '@ISA', '@EXPORT', '@EXPORT_OK';
-@ISA = qw/Automake::Item Exporter/;
+
+use vars qw (@EXPORT @EXPORT_OK @ISA);
+@ISA = qw (Automake::Item Exporter);
 @EXPORT = qw (reset register_suffix_rule next_in_suffix_chain
              suffixes rules $KNOWN_EXTENSIONS_PATTERN
              depend %dependencies %actions register_action
diff --git a/lib/Automake/RuleDef.pm b/lib/Automake/RuleDef.pm
index d44f10819..091a78c50 100644
--- a/lib/Automake/RuleDef.pm
+++ b/lib/Automake/RuleDef.pm
@@ -17,13 +17,16 @@ package Automake::RuleDef;
 
 use 5.006;
 use strict;
+use warnings FATAL => 'all';
+
 use Carp;
+use Exporter;
+
 use Automake::ChannelDefs;
 use Automake::ItemDef;
 
-require Exporter;
-use vars '@ISA', '@EXPORT';
-@ISA = qw/Automake::ItemDef Exporter/;
+use vars qw (@EXPORT @ISA);
+@ISA = qw (Automake::ItemDef Exporter);
 @EXPORT = qw (&RULE_AUTOMAKE &RULE_USER);
 
 =head1 NAME
diff --git a/lib/Automake/VarDef.pm b/lib/Automake/VarDef.pm
index d258a8573..adeb6e299 100644
--- a/lib/Automake/VarDef.pm
+++ b/lib/Automake/VarDef.pm
@@ -17,13 +17,16 @@ package Automake::VarDef;
 
 use 5.006;
 use strict;
+use warnings FATAL => 'all';
+
 use Carp;
+use Exporter;
+
 use Automake::ChannelDefs;
 use Automake::ItemDef;
 
-require Exporter;
-use vars '@ISA', '@EXPORT';
-@ISA = qw/Automake::ItemDef Exporter/;
+use vars qw (@ISA @EXPORT);
+@ISA = qw (Automake::ItemDef Exporter);
 @EXPORT = qw (&VAR_AUTOMAKE &VAR_CONFIGURE &VAR_MAKEFILE
              &VAR_ASIS &VAR_PRETTY &VAR_SILENT &VAR_SORTED);
 
diff --git a/lib/Automake/Variable.pm b/lib/Automake/Variable.pm
index 363a3e0ed..4ec0dd4b0 100644
--- a/lib/Automake/Variable.pm
+++ b/lib/Automake/Variable.pm
@@ -17,7 +17,10 @@ package Automake::Variable;
 
 use 5.006;
 use strict;
+use warnings FATAL => 'all';
+
 use Carp;
+use Exporter;
 
 use Automake::Channels;
 use Automake::ChannelDefs;
@@ -29,9 +32,8 @@ use Automake::DisjConditions;
 use Automake::General 'uniq';
 use Automake::Wrap 'makefile_wrap';
 
-require Exporter;
-use vars '@ISA', '@EXPORT', '@EXPORT_OK';
-@ISA = qw/Automake::Item Exporter/;
+use vars qw (@EXPORT @EXPORT_OK @ISA);
+@ISA = qw (Automake::Item Exporter);
 @EXPORT = qw (err_var msg_var msg_cond_var reject_var
              var rvar vardef rvardef
              variables
diff --git a/lib/Automake/Version.pm b/lib/Automake/Version.pm
index c2722c061..16cdfb699 100644
--- a/lib/Automake/Version.pm
+++ b/lib/Automake/Version.pm
@@ -17,6 +17,8 @@ package Automake::Version;
 
 use 5.006;
 use strict;
+use warnings FATAL => 'all';
+
 use Automake::ChannelDefs;
 
 =head1 NAME
diff --git a/lib/Automake/Wrap.pm b/lib/Automake/Wrap.pm
index 0640cc9a2..c821b8b99 100644
--- a/lib/Automake/Wrap.pm
+++ b/lib/Automake/Wrap.pm
@@ -17,11 +17,13 @@ package Automake::Wrap;
 
 use 5.006;
 use strict;
+use warnings FATAL => 'all';
 
-require Exporter;
-use vars '@ISA', '@EXPORT_OK';
-@ISA = qw/Exporter/;
-@EXPORT_OK = qw/wrap makefile_wrap/;
+use Exporter;
+
+use vars qw (@EXPORT_OK @ISA);
+@ISA = qw (Exporter);
+@EXPORT_OK = qw (wrap makefile_wrap);
 
 =head1 NAME
 
diff --git a/lib/Automake/XFile.pm b/lib/Automake/XFile.pm
index 7d54404f0..5284faa5d 100644
--- a/lib/Automake/XFile.pm
+++ b/lib/Automake/XFile.pm
@@ -71,23 +71,20 @@ and C<getlines> methods to translate C<\r\n> to C<\n>.
 
 use 5.006;
 use strict;
-use vars qw($VERSION @EXPORT @EXPORT_OK $AUTOLOAD @ISA);
-use Carp;
+use warnings FATAL => 'all';
+
 use Errno;
+use Exporter;
 use IO::File;
-use File::Basename;
+
 use Automake::ChannelDefs;
-use Automake::Channels qw(msg);
+use Automake::Channels qw (msg);
 use Automake::FileUtils;
 
-require Exporter;
-require DynaLoader;
-
-@ISA = qw(IO::File Exporter DynaLoader);
-
-$VERSION = "1.2";
-
+use vars qw ($AUTOLOAD @EXPORT @EXPORT_OK @ISA $VERSION);
+@ISA = qw(Exporter IO::File);
 @EXPORT = @IO::File::EXPORT;
+$VERSION = "1.2";
 
 eval {
   # Make all Fcntl O_XXX and LOCK_XXX constants available for importing
-- 
2.28.0




reply via email to

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