From: Akim Demaille Date: Thu, 29 Aug 2002 08:03:10 +0000 (+0000) Subject: * lib/Autom4te/General.pm (&xqx): New. X-Git-Tag: AUTOCONF-2.53c~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a364aa42bab685ac58c5c263afd032d9defac8ab;p=thirdparty%2Fautoconf.git * lib/Autom4te/General.pm (&xqx): New. (&xsystem): Use WIFEXITED and WEXITSTATUS instead of decoding $? by hand, which is not portable. (&error): New. * bin/autom4te.in: Use them. Use &error instead of die. * tests/m4sugar.at (m4_warn, m4_require: circular dependencies): Adjust. --- diff --git a/ChangeLog b/ChangeLog index c76fd415d..2b7f26542 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2002-08-29 Akim Demaille + + * lib/Autom4te/General.pm (&xqx): New. + (&xsystem): Use WIFEXITED and WEXITSTATUS instead of decoding $? by + hand, which is not portable. + (&error): New. + * bin/autom4te.in: Use them. + Use &error instead of die. + * tests/m4sugar.at (m4_warn, m4_require: circular dependencies): + Adjust. + 2002-08-17 Paul Eggert * lib/autoconf/fortran.m4 (AC_PROG_F77): Remove fc from the diff --git a/bin/autom4te.in b/bin/autom4te.in index 963a7bfaa..75174f44a 100644 --- a/bin/autom4te.in +++ b/bin/autom4te.in @@ -278,7 +278,7 @@ my $freeze = 0; # $M4. my $m4 = $ENV{"M4"} || '@M4@'; # Some non-GNU m4's don't reject the --help option, so give them /dev/null. -die "$me: need GNU m4 1.4 or later: $m4\n" +error "need GNU m4 1.4 or later: $m4" if system "$m4 --help &1 | grep reload-state >/dev/null"; # Set some high recursion limit as the default limit, 250, has already @@ -443,7 +443,7 @@ sub load_configuration () } elsif ($type eq 'end-language:') { - die "$me: $autom4te_cfg:$.: end-language mismatch: $lang\n" + error "$autom4te_cfg:$.: end-language mismatch: $lang" if $lang ne lc $words[0]; } elsif ($type eq 'args:') @@ -452,7 +452,7 @@ sub load_configuration () } else { - die "$me: $autom4te_cfg:$.: unknown directive: $type\n"; + error "$autom4te_cfg:$.: unknown directive: $type"; } } } @@ -477,7 +477,7 @@ sub parse_args () foreach (@language) { - die "$me: unknown language: $_\n" + error "unknown language: $_" unless exists $language{lc $_}; unshift @ARGV, @{$language{lc $_}}; } @@ -510,8 +510,8 @@ sub parse_args () "F|freeze" => \$freeze, ); - die "$me: too few arguments -Try `$me --help' for more information.\n" + error "too few arguments +Try `$me --help' for more information." unless @ARGV; # Freezing: @@ -519,7 +519,7 @@ Try `$me --help' for more information.\n" # And it implies melting: there is risk not to update properly using # old frozen files, and worse yet: we could load a frozen file and # refreeze it! A sort of caching :) - die "$me: cannot freeze and trace\n" + error "cannot freeze and trace" if $freeze && @trace; $melt = 1 if $freeze; @@ -612,29 +612,22 @@ sub handle_m4 ($@) # # We don't output directly to the cache files, to avoid problems # when we are interrupted (that leaves corrupted files). - my $command = ("$m4" - . join (' --include=', '', @include) - . " --define=m4_warnings=$m4_warnings" - . ' --debug=aflq' - . " --error-output=$tcache" . $req->id . "t" - . join (' --trace=', '', sort @macro) - . " @ARGV" - . ' $ocache" . $req->id . "t"); - verbose "running: $command"; - system $command; - if ($?) - { - verbose "$m4: failed with exit status: " . ($? >> 8) . "\n"; - exit $? >> 8; - } + xsystem ("$m4" + . join (' --include=', '', @include) + . " --define=m4_warnings=$m4_warnings" + . ' --debug=aflq' + . " --error-output=$tcache" . $req->id . "t" + . join (' --trace=', '', sort @macro) + . " @ARGV" + . ' $ocache" . $req->id . "t"); # Everything went ok: preserve the outputs. foreach my $file (map { $_ . $req->id } ($tcache, $ocache)) { use File::Copy; move ("${file}t", "$file") - or die "$me: cannot not rename ${file}t as $file: $!\n"; + or error "cannot not rename ${file}t as $file: $!"; } } @@ -710,7 +703,7 @@ sub handle_output ($$) { $out->open($output, O_CREAT | O_WRONLY | O_TRUNC, oct ($mode)); } - die "$me: cannot create $output: $!\n" + error "cannot create $output: $!" unless $out; my $in = new Autom4te::XFile ($ocache . $req->id); @@ -837,7 +830,7 @@ sub trace_format_to_m4 ($) } elsif (/^(\$.)/) { - die "$me: invalid escape: $1\n"; + error "invalid escape: $1"; } else { @@ -1062,21 +1055,14 @@ sub freeze ($) # When processing the file with diversion disabled, there must be no # output but comments and empty lines. - my $command = ("$m4" - . ' --fatal-warning' - . join (' --include=', '', @include) - . ' --define=divert' - . " @ARGV" - . ' > 8) . "\n"; - exit $? >> 8; - } if ($result) { print STDERR "$me: freezing produced output:\n$result"; @@ -1085,19 +1071,12 @@ sub freeze ($) # If freezing produces output, something went wrong: a bad `divert', # or an improper paren etc. - $command = ("$m4" - . ' --fatal-warning' - . join (' --include=', '', @include) - . " --freeze-state=$output" - . " @ARGV" - . ' > 8) . "\n"; - exit $? >> 8; - } + xsystem ("$m4" + . ' --fatal-warning' + . join (' --include=', '', @include) + . " --freeze-state=$output" + . " @ARGV" + . ' close; unlink ($from) - or die "$me: cannot not remove $from: $!\n"; + or die "cannot not remove $from: $!"; return; } @@ -417,7 +433,7 @@ sub update_file ($$) # File didn't change, so don't update its mod time. print STDERR "$me: `$to' is unchanged\n"; unlink ($from) - or die "$me: cannot not remove $from: $!\n"; + or error "cannot not remove $from: $!"; return } @@ -425,15 +441,15 @@ sub update_file ($$) { # Back up and install the new one. move ("$to", "$to$SIMPLE_BACKUP_SUFFIX") - or die "$me: cannot not backup $to: $!\n"; + or error "cannot not backup $to: $!"; move ("$from", "$to") - or die "$me: cannot not rename $from as $to: $!\n"; + or error "cannot not rename $from as $to: $!"; print STDERR "$me: `$to' is updated\n"; } else { move ("$from", "$to") - or die "$me: cannot not rename $from as $to: $!\n"; + or error "cannot not rename $from as $to: $!"; print STDERR "$me: `$to' is created\n"; } } @@ -448,20 +464,41 @@ sub verbose (@) } +# xqx ($COMMAND) +# -------------- +# Same as `qx' (but in scalar context), but fails on errors. +sub xqx ($) +{ + use POSIX qw (WIFEXITED WEXITSTATUS); + + my ($command) = @_; + + verbose "running: $command"; + my $res = `$command`; + + error ((split (' ', $command))[0] + . " failed with exit status: " + . WEXITSTATUS ($?)) + if WIFEXITED ($?) && WEXITSTATUS ($?) != 0; + + return $res; +} + + # xsystem ($COMMAND) # ------------------ sub xsystem ($) { + use POSIX qw (WEXITSTATUS); + my ($command) = @_; verbose "running: $command"; (system $command) == 0 - or croak ("$me: " - . (split (' ', $command))[0] + or error ((split (' ', $command))[0] . " failed with exit status: " - . ($? >> 8) - . "\n"); + . WEXITSTATUS ($?)); } diff --git a/man/autom4te.1 b/man/autom4te.1 index c52f50946..b284621a3 100644 --- a/man/autom4te.1 +++ b/man/autom4te.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.28. -.TH AUTOM4TE "1" "July 2002" "autom4te 2.53c" "User Commands" +.TH AUTOM4TE "1" "August 2002" "autom4te 2.53c" "User Commands" .SH NAME autom4te \- Generate files and scripts thanks to M4 .SH SYNOPSIS diff --git a/tests/m4sugar.at b/tests/m4sugar.at index 563310c0b..cc2b25b9b 100644 --- a/tests/m4sugar.at +++ b/tests/m4sugar.at @@ -2,7 +2,7 @@ AT_BANNER([M4sugar.]) -# Copyright 2000, 2001 Free Software Foundation, Inc. +# Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -61,10 +61,13 @@ AT_CHECK_M4SUGAR([-o- -Wnone,bar -f], 0, [], [script.4s:2: warning: bar ]) -AT_CHECK_M4SUGAR([-o- -Wnone,bar,error -f], 1, [], -[script.4s:2: error: bar +AT_CHECK_M4SUGAR([-o- -Wnone,bar,error -f], 1, [], [stderr]) +# The error message contains the path to m4, which might change. +AT_CHECK([sed 's/^autom4te.*failed/autom4te: m4 failed/' stderr], 0, +[[script.4s:2: error: bar script.4s:2: the top level -]) +autom4te: m4 failed with exit status: 1 +]]) AT_CLEANUP @@ -93,7 +96,8 @@ m4_init baz ]]) -AT_DATA_M4SUGAR([experr], +# Expected stderr. +AT_DATA_M4SUGAR([expout], [[script.4s:11: error: m4_require: circular dependency of foo script.4s:11: foo is required by... script.4s:5: bar is expanded from... @@ -102,9 +106,12 @@ script.4s:2: foo is expanded from... script.4s:11: foo is required by... script.4s:8: baz is expanded from... script.4s:11: the top level +autom4te: m4 failed with exit status: 1 ]]) -AT_CHECK_M4SUGAR([], 1, [], experr) +AT_CHECK_M4SUGAR([], 1, [], stderr) +# The error message contains the path to m4, which might change. +AT_CHECK([sed 's/^autom4te.*failed/autom4te: m4 failed/' stderr], 0, [expout]) AT_CLEANUP