[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FYI: Use Automake::ChannelDefs and Getopt::Long in aclocal
From: |
Alexandre Duret-Lutz |
Subject: |
FYI: Use Automake::ChannelDefs and Getopt::Long in aclocal |
Date: |
Thu, 04 Nov 2004 23:19:32 +0100 |
User-agent: |
Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux) |
I'm checking this in, this brings the code of aclocal closer to
that of automake.
A bonus side-effect is that the tests/defs.in chunk will cause
the test suite to fails Perl warnings such as those reported
by Ralf (which the aclocal.in chunk fixes).
>>> "Ralf" == Ralf Wildenhues <address@hidden> writes:
Ralf> Also with HEAD (of today):
Ralf> Use of uninitialized value in hash element at
/tmp/build/tests/.././aclocal line 428, <GEN100> line 141.
Ralf> Use of uninitialized value in string eq at /tmp/build/tests/.././aclocal
line 430, <GEN100> line 141.
Ralf> Use of uninitialized value in string eq at /tmp/build/tests/.././aclocal
line 430, <GEN100> line 141.
Ralf> [...]
Ralf> Occurs reproducably with the three tests
Ralf> make check VERBOSE=x TESTS=gettext.test\ gettext2.test\ subcond.test
2004-11-04 Alexandre Duret-Lutz <address@hidden>
* aclocal.in: Use Automake::ChannelDefs, and adjust all output
to be done via `fatal', `msg', `verb', or `prog_error'.
(version): New function.
(parse_arguments): Rewrite using Getopt::Long, call &version, and
honor -W and --warning.
($verbose): Remove.
(trace_used_macros): Do not trace the first arguments of macros
for which we do not need it. This caused failures because of
unexpected newlines in the output.
* doc/automake.texi (aclocal options): Document -W and --warning.
* tests/defs.in (ACLOCAL): Always use -Werror, to catch Perl
warnings about uninitialized variables.
Index: NEWS
===================================================================
RCS file: /cvs/automake/automake/NEWS,v
retrieving revision 1.289
diff -u -r1.289 NEWS
--- NEWS 10 Oct 2004 15:52:00 -0000 1.289
+++ NEWS 4 Nov 2004 22:16:53 -0000
@@ -13,6 +13,8 @@
- Preprocessed assembler (*.S) compilation now honnors CPPFLAGS,
AM_CPPFLAGS and per-target _CPPFLAGS, and supports dependency
tracking, unlike non-preprocessed assembler (*.s).
+
+ - aclocal now also supports -Wmumble and -Wno-mumble options.
New in 1.9:
Index: aclocal.in
===================================================================
RCS file: /cvs/automake/automake/aclocal.in,v
retrieving revision 1.110
diff -u -r1.110 aclocal.in
--- aclocal.in 3 Nov 2004 21:40:25 -0000 1.110
+++ aclocal.in 4 Nov 2004 22:16:53 -0000
@@ -40,6 +40,7 @@
use Automake::General;
use Automake::Configure_ac;
use Automake::Channels;
+use Automake::ChannelDefs;
use Automake::XFile;
use Automake::FileUtils;
use File::Basename;
@@ -94,9 +95,6 @@
# Map file names to included files (transitively closed).
my %file_includes = ();
-# How much to say.
-my $verbose = 0;
-
# Matches a macro definition.
# AC_DEFUN([macroname], ...)
# or
@@ -122,9 +120,9 @@
foreach my $key (keys %map)
{
# FIXME: should print line number of acinclude.m4.
- warn ("aclocal: warning: macro `$key' defined in "
- . "acinclude.m4 but never used\n")
- if $map{$key} eq 'acinclude.m4' && ! $macro_seen{$key};
+ msg ('syntax', "warning: macro `$key' defined in "
+ . "acinclude.m4 but never used")
+ if $map{$key} eq 'acinclude.m4' && ! exists $macro_seen{$key};
}
}
@@ -150,8 +148,7 @@
{
if (! opendir (DIR, $m4dir))
{
- print STDERR "aclocal: couldn't open directory `$m4dir': $!\n";
- exit 1;
+ fatal "couldn't open directory `$m4dir': $!";
}
# We reverse the directory contents so that foo2.m4 gets
@@ -181,7 +178,7 @@
}
$search .= "return \$found;\n};\n";
eval $search;
- die "internal error: address@hidden search is $search" if $@;
+ prog_error "address@hidden search is $search" if $@;
}
################################################################
@@ -197,7 +194,7 @@
# complain when we trace for macro usage later.
return unless defined $map{$macro};
- print STDERR "aclocal: saw macro $macro\n" if $verbose;
+ verb "saw macro $macro";
$macro_seen{$macro} = 1;
&add_file ($map{$macro});
}
@@ -251,8 +248,8 @@
# Macro not found, but AM_ prefix found.
# Make this just a warning, because we do not know whether
# the macro is actually used (it could be called conditionally).
- warn ("aclocal:$file:$line: warning: "
- . "macro `$2' not found in library\n");
+ msg ('unsupported', "$file:$line",
+ "warning: macro `$2' not found in library");
}
}
@@ -294,11 +291,7 @@
unshift @file_order, $file;
- if (! -e $file)
- {
- print STDERR "$where: file `$file' does not exist\n";
- exit 1;
- }
+ fatal "$where: file `$file' does not exist" if ! -e $file;
my $fh = new Automake::XFile $file;
my $contents = '';
@@ -310,23 +303,23 @@
next if /^##/;
$contents .= $_;
+ my $line = $_;
- while (/$ac_defun_rx/go)
+ while ($line =~ /$ac_defun_rx/go)
{
if (! defined $1)
{
- print STDERR "$file:$.: warning: underquoted definition of $2\n";
- print STDERR " run info '(automake)Extending aclocal'\n"
- . " or see http://sources.redhat.com/automake/"
- . "automake.html#Extending-aclocal\n"
+ msg ('syntax', "$file:$.", "warning: underquoted definition of $2"
+ . "\n run info '(automake)Extending aclocal'\n"
+ . " or see http://sources.redhat.com/automake/"
+ . "automake.html#Extending-aclocal")
unless $underquoted_manual_once;
$underquoted_manual_once = 1;
}
my $macro = $1 || $2;
if (! defined $map{$macro})
{
- print STDERR "aclocal: found macro $macro in $file: $.\n"
- if $verbose;
+ verb "found macro $macro in $file: $.";
$map{$macro} = $file;
}
else
@@ -336,12 +329,11 @@
# extremely unpopular. It causes actual problems which
# are hard to work around, especially when you must
# mix-and-match tool versions.
- print STDERR "aclocal: ignoring macro $macro in $file: $.\n"
- if $verbose;
+ verb "ignoring macro $macro in $file: $.";
}
}
- while (/$m4_include_rx/go)
+ while ($line =~ /$m4_include_rx/go)
{
my $ifile = $1 || $2;
# m4_include is relative to the directory of the file which
@@ -389,8 +381,7 @@
{
next unless exists $files{$ifile};
delete $files{$ifile};
- print STDERR "$ifile is already included by $file\n"
- if $verbose;
+ verb "$ifile is already included by $file";
}
}
return %files;
@@ -409,12 +400,16 @@
# All candidate files.
$traces .= join (' ', grep { exists $files{$_} } @file_order) . " ";
# All candidate macros.
- $traces .= join (' ', map { "--trace='$_:\$f:\$n:\$1'" } ('AC_DEFUN',
- 'AC_DEFUN_ONCE',
- 'AU_DEFUN',
- keys %macro_seen));
+ $traces .= join (' ',
+ (map { "--trace='$_:\$f::\$n::\$1'" } ('AC_DEFUN',
+ 'AC_DEFUN_ONCE',
+ 'AU_DEFUN')),
+ # Do not trace $1 for all other macros as we do
+ # not need it and it might contains harmful
+ # characters (like newlines).
+ (map { "--trace='$_:\$f::\$n'" } (keys %macro_seen)));
- print STDERR "aclocal: running $traces $configure_ac\n" if $verbose;
+ verb "running $traces $configure_ac";
my $tracefh = new Automake::XFile ("$traces $configure_ac |");
@@ -423,9 +418,9 @@
while ($_ = $tracefh->getline)
{
chomp;
- my ($file, $macro, $arg1) = split (/:/);
+ my ($file, $macro, $arg1) = split (/::/);
- $traced{$macro} = 1 if $macro_seen{$macro};
+ $traced{$macro} = 1 if exists $macro_seen{$macro};
$map_traced_defs{$arg1} = $file
if ($macro eq 'AC_DEFUN'
@@ -536,11 +531,11 @@
&& $greatest_mtime < mtime ($output_file)
&& $output eq contents ($output_file))
{
- print STDERR "aclocal: $output_file unchanged\n" if $verbose;
+ verb "$output_file unchanged";
return;
}
- print STDERR "aclocal: writing $output_file\n" if $verbose;
+ verb "writing $output_file";
my $out = new Automake::XFile "> $output_file";
print $out $output;
@@ -554,79 +549,93 @@
{
my ($status) = @_;
- print "Usage: aclocal [OPTIONS] ...\n\n";
- print "\
+ print "Usage: aclocal [OPTIONS] ...
+
Generate `aclocal.m4' by scanning `configure.ac' or `configure.in'
- --acdir=DIR directory holding config files
- --help print this help, then exit
- -I DIR add directory to search list for .m4 files
- --force always update output file
- --output=FILE put output in FILE (default aclocal.m4)
- --print-ac-dir print name of directory holding m4 files
- --verbose don't be silent
- --version print version number, then exit
+Options:
+ --acdir=DIR directory holding config files (for debugging)
+ --force always update output file
+ --help print this help, then exit
+ -I DIR add directory to search list for .m4 files
+ --output=FILE put output in FILE (default aclocal.m4)
+ --print-ac-dir print name of directory holding m4 files, then exit
+ --verbose don't be silent
+ --version print version number, then exit
+ -W, --warnings=CATEGORY report the warnings falling in CATEGORY
+
+Warning categories include:
+ `syntax' dubious syntactic constructs (default)
+ `unsupported' unknown macros (default)
+ `all' all the warnings (default)
+ `no-CATEGORY' turn off warnings in CATEGORY
+ `none' turn off all the warnings
+ `error' treat warnings as errors
Report bugs to <address@hidden>.\n";
exit $status;
}
+# Print version and exit.
+sub version()
+{
+ print "\
+aclocal (GNU $PACKAGE) $VERSION
+Written by Tom Tromey <address@hidden>
+ and Alexandre Duret-Lutz <address@hidden>
+Copyright (C) 2004 Free Software Foundation, Inc.
+This is free software; see the source for copying conditions. There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.";
+ exit 0;
+}
+
# Parse command line.
-sub parse_arguments (@)
+sub parse_arguments ()
{
- my @arglist = @_;
my @dirlist;
my $print_and_exit = 0;
- while (@arglist)
- {
- if ($arglist[0] =~ /^--acdir=(.+)$/)
- {
- $acdir = $1;
- }
- elsif ($arglist[0] =~/^--output=(.+)$/)
- {
- $output_file = $1;
- }
- elsif ($arglist[0] eq '-I')
- {
- shift (@arglist);
- push (@dirlist, $arglist[0]);
- }
- elsif ($arglist[0] eq '--print-ac-dir')
- {
- $print_and_exit = 1;
- }
- elsif ($arglist[0] eq '--force')
- {
- $force_output = 1;
- }
- elsif ($arglist[0] eq '--verbose')
- {
- ++$verbose;
- }
- elsif ($arglist[0] eq '--version')
- {
- print "aclocal (GNU $PACKAGE) $VERSION\n";
- print "Written by Tom Tromey <address@hidden>\n";
- print " and Alexandre Duret-Lutz <address@hidden>\n\n";
- print "Copyright (C) 2004 Free Software Foundation, Inc.\n";
- print "This is free software; see the source for copying conditions.
There is NO\n";
- print "warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.\n";
- exit 0;
- }
- elsif ($arglist[0] eq '--help')
- {
- &usage (0);
- }
- else
- {
- print STDERR "aclocal: unrecognized option -- `$arglist[0]'\nTry
`aclocal --help' for more information.\n";
- exit 1;
- }
+ my %cli_options =
+ (
+ 'acdir=s' => \$acdir,
+ 'force' => \$force_output,
+ 'I=s' => address@hidden,
+ 'output=s' => \$output_file,
+ 'print_ac_dir' => \$print_and_exit,
+ 'verbose' => sub { setup_channel 'verb', silent => 0; },
+ 'W|warnings:s' => \&parse_warnings,
+ );
+ use Getopt::Long;
+ Getopt::Long::config ("bundling", "pass_through");
+
+ # See if --version or --help is used. We want to process these before
+ # anything else because the GNU Coding Standards require us to
+ # `exit 0' after processing these options, and we can't guarantee this
+ # if we treat other options first. (Handling other options first
+ # could produce error diagnostics, and in this condition it is
+ # confusing if Automake does `exit 0'.)
+ my %cli_options_1st_pass =
+ (
+ 'version' => \&version,
+ 'help' => sub { usage(0); },
+ # Recognize all other options (and their arguments) but do nothing.
+ map { $_ => sub {} } (keys %cli_options)
+ );
+ my @ARGV_backup = @ARGV;
+ Getopt::Long::GetOptions %cli_options_1st_pass
+ or exit 1;
+ @ARGV = @ARGV_backup;
+
+ # Now *really* process the options. This time we know
+ # that --help and --version are not present.
+ Getopt::Long::GetOptions %cli_options
+ or exit 1;
- shift (@arglist);
+ if (@ARGV)
+ {
+ fatal ("unrecognized option `$ARGV[0]'\n"
+ . "Try `$0 --help' for more information.");
}
if ($print_and_exit)
@@ -670,7 +679,8 @@
################################################################
-my @dirlist = parse_arguments (@ARGV);
+parse_WARNINGS; # Parse the WARNINGS environment variable.
+my @dirlist = parse_arguments;
$configure_ac = require_configure_ac;
scan_m4_files (@dirlist);
scan_configure;
Index: doc/automake.texi
===================================================================
RCS file: /cvs/automake/automake/doc/automake.texi,v
retrieving revision 1.64
diff -u -r1.64 automake.texi
--- doc/automake.texi 1 Nov 2004 09:55:35 -0000 1.64
+++ doc/automake.texi 4 Nov 2004 22:16:55 -0000
@@ -1602,6 +1602,32 @@
@item --version
@opindex --version
Print the version number of Automake and exit.
+
address@hidden -W CATEGORY
address@hidden address@hidden
address@hidden -W
address@hidden --warnings
+Output warnings falling in @var{category}. @var{category} can be
+one of:
address@hidden @samp
address@hidden syntax
+dubious syntactic constructs, underquoted macros, unused macros, etc.
address@hidden unsupported
+unknown macros
address@hidden all
+all the warnings, this is the default
address@hidden none
+turn off all the warnings
address@hidden error
+treat warnings as errors
address@hidden table
+
+All warnings are output by default.
+
address@hidden WARNINGS
+The environment variable @samp{WARNINGS} is honored in the same
+way as it is for @command{automake} (@pxref{Invoking Automake}).
+
@end table
@node Macro search path
Index: tests/defs.in
===================================================================
RCS file: /cvs/automake/automake/tests/defs.in,v
retrieving revision 1.32
diff -u -r1.32 defs.in
--- tests/defs.in 3 Nov 2004 21:49:39 -0000 1.32
+++ tests/defs.in 4 Nov 2004 22:16:55 -0000
@@ -74,7 +74,9 @@
test -z "$AUTOHEADER" && AUTOHEADER="@AUTOHEADER@"
test -z "$AUTOUPDATE" && AUTOUPDATE=autoupdate
test -z "$MISSING" && MISSING=`pwd`/../lib/missing
-test -z "$ACLOCAL" && ACLOCAL="address@hidden@"
+# Use -Werror because this also turns some Perl warnings into error.
+# (Tests for which this is inappropriate should use -Wno-error.)
+test -z "$ACLOCAL" && ACLOCAL="address@hidden@ -Werror"
# See how Automake should be run. We put --foreign as the default
# strictness to avoid having to create lots and lots of files. A test
# can override this by specifying a different strictness. Use -Wall
@@ -264,6 +266,8 @@
# Use `-I $srcdir/../m4' in addition to `--acdir=$srcdir/../m4', because the
# other `-I' directories added for libtool and gettext might contain
# files from an old version of Automake that we don't want to use.
+# Use `-Wno-syntax' because we do not want our test suite to fail because
+# some third-party .m4 file is underquoted.
aclocaldir='@prefix@/share/aclocal'
extra_includes=""
if [ -f $aclocaldir/dirlist ] ; then
@@ -282,7 +286,7 @@
fi
done
test "x$libtool_found" = "xyes" || exit 77
- ACLOCAL="$ACLOCAL -I $srcdir/../m4 $extra_includes -I $aclocaldir"
+ ACLOCAL="$ACLOCAL -Wno-syntax -I $srcdir/../m4 $extra_includes -I
$aclocaldir"
;;
*gettext* )
gettext_found=no
@@ -292,7 +296,7 @@
fi
done
test "x$gettext_found" = "xyes" || exit 77
- ACLOCAL="$ACLOCAL -I $srcdir/../m4 $extra_includes -I $aclocaldir"
+ ACLOCAL="$ACLOCAL -Wno-syntax -I $srcdir/../m4 $extra_includes -I
$aclocaldir"
;;
esac
--
Alexandre Duret-Lutz
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- FYI: Use Automake::ChannelDefs and Getopt::Long in aclocal,
Alexandre Duret-Lutz <=