* aclocal.in (usage, parse_arguments): New --dry-run and --diff
authorAlexandre Duret-Lutz <adl@gnu.org>
Sun, 6 Feb 2005 12:33:32 +0000 (12:33 +0000)
committerAlexandre Duret-Lutz <adl@gnu.org>
Sun, 6 Feb 2005 12:33:32 +0000 (12:33 +0000)
options.
(install_file, write_aclocal): Honor --dry-run and --diff.
* doc/automake.texi (aclocal options): Document --dry-run and --diff.
(Serials): Mention --diff.
* lib/Automake/FileUtils.pm (handle_exec_errors): Accept an
$expected_exit_code argument.
(xsystem): Take a list of arguments, not a string.
* tests/acloca18.test: Use --dry-run and --diff.
Suggested by Paul Eggert.

ChangeLog
NEWS
aclocal.in
doc/automake.texi
lib/Automake/FileUtils.pm
tests/acloca18.test

index c9cfae5..c568d7d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2005-02-06  Alexandre Duret-Lutz  <adl@gnu.org>
 
+       * aclocal.in (usage, parse_arguments): New --dry-run and --diff
+       options.
+       (install_file, write_aclocal): Honor --dry-run and --diff.
+       * doc/automake.texi (aclocal options): Document --dry-run and --diff.
+       (Serials): Mention --diff.
+       * lib/Automake/FileUtils.pm (handle_exec_errors): Accept an
+       $expected_exit_code argument.
+       (xsystem): Take a list of arguments, not a string.
+       * tests/acloca18.test: Use --dry-run and --diff.
+       Suggested by Paul Eggert.
+
        * doc/automake.texi (aclocal options, Macro search path,
        Extending aclocal, Local Macros, Serials, Future of aclocal): Make
        these subsection of ...
diff --git a/NEWS b/NEWS
index f821127..b27779a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,9 @@ New in 1.9a:
     specified with the first -I flag.  This option also uses #serial
     lines in M4 files to upgrade local macros.
 
+    The new aclocal options --dry-run and --diff help to review changes
+    before they are installed.
+
   - Per-target flags are now correctly handled in link rules.
 
     For instance maude_CFLAGS correctly overrides AM_CFLAGS; likewise
index 5667cd1..c155c7c 100644 (file)
@@ -62,6 +62,12 @@ my @system_includes = ('@datadir@/aclocal');
 # Whether we should copy M4 file in $user_includes[0].
 my $install = 0;
 
+# --diff
+my @diff_command;
+
+# --dry-run
+my $dry_run = 0;
+
 # configure.ac or configure.in.
 my $configure_ac;
 
@@ -170,18 +176,34 @@ sub reset_maps ()
 sub install_file ($$)
 {
   my ($src, $dest) = @_;
+  my $diff_dest = $dest;
 
   if ($force_output
       || !exists $file_contents{$dest}
       || $file_contents{$src} ne $file_contents{$dest})
     {
-      if (system ('cp', $src, $dest))
+      if (-e $dest)
        {
-         error ("error while copying `$src' to `$dest'");
+         msg 'note', "overwriting `$dest' with `$src'";
        }
       else
        {
-         msg 'note', "installing `$dest'";
+         msg 'note', "installing `$dest' from `$src'";
+         $diff_dest = '/dev/null';
+       }
+
+      if (@diff_command)
+       {
+         my @cmd = (@diff_command, $diff_dest, $src);
+         $! = 0;
+         verb "running: @cmd";
+         my $res = system (@cmd);
+         Automake::FileUtils::handle_exec_errors "@cmd", 1
+           if $res;
+       }
+      elsif (!$dry_run)
+       {
+         xsystem ('cp', $src, $dest);
        }
     }
 }
@@ -742,8 +764,11 @@ $output";
 
   verb "writing $output_file";
 
-  my $out = new Automake::XFile "> $output_file";
-  print $out $output;
+  if (!$dry_run)
+    {
+      my $out = new Automake::XFile "> $output_file";
+      print $out $output;
+    }
   return 1;
 }
 
@@ -760,6 +785,9 @@ Generate `aclocal.m4' by scanning `configure.ac' or `configure.in'
 
 Options:
       --acdir=DIR           directory holding config files (for debugging)
+      --diff[=COMMAND]      run COMMAND [diff -u] on M4 files that would be
+                              changed (implies --install and --dry-run)
+      --dry-run             pretend to, but do not actually update any file
       --force               always update output file
       --help                print this help, then exit
   -I DIR                    add directory to search list for .m4 files
@@ -802,6 +830,7 @@ EOF
 sub parse_arguments ()
 {
   my $print_and_exit = 0;
+  my $diff_command;
 
   my %cli_options =
     (
@@ -811,6 +840,8 @@ sub parse_arguments ()
                               @automake_includes = ();
                               @system_includes = ($_[1])
                             },
+     'diff:s'          => \$diff_command,
+     'dry-run'         => \$dry_run,
      'force'           => \$force_output,
      'I=s'             => \@user_includes,
      'install'          => \$install,
@@ -875,6 +906,14 @@ sub parse_arguments ()
       exit 0;
     }
 
+  if (defined $diff_command)
+    {
+      $diff_command = 'diff -u' if $diff_command eq '';
+      @diff_command = split (' ', $diff_command);
+      $install = 1;
+      $dry_run = 1;
+    }
+
   if ($install && !@user_includes)
     {
       fatal ("--install should copy macros in the directory indicated by the"
@@ -934,6 +973,7 @@ while (1)
     last if $exit_code;
     my %macro_traced = trace_used_macros;
     last if write_aclocal ($output_file, keys %macro_traced);
+    last if $dry_run;
   }
 check_acinclude;
 
index f2951d6..4e77e11 100644 (file)
@@ -1646,6 +1646,17 @@ just as @code{autoconf}.  Its location can be overridden using the
 Look for the macro files in @var{dir} instead of the installation
 directory.  This is typically used for debugging.
 
+@item --diff[=@var{command}]
+@opindex --diff
+Run @var{command} on M4 file that would be installed or overwritten
+by @code{--install}.  The default @var{command} is @code{diff -u}.
+This option implies @code{--install} and @code{--dry-run}.
+
+@item --dry-run
+@opindex --dry-run
+Do not actually overwrite (or create) @file{aclocal.m4} and M4
+files installed by @code{--install}.
+
 @item --help
 @opindex --help
 Print a summary of the command line options and exit.
@@ -2196,13 +2207,16 @@ macro in @file{m4/thirdparty.m4}, in this case overriding the old
 version.  MyPackage just had its macro updated as a side effect of
 running @command{aclocal}.
 
+If you are leery of letting @command{aclocal} update your local macro,
+you can run @code{aclocal -I m4 --diff} to review the changes
+@code{aclocal -I m4 --install} would perform on these macros.
 
-The @code{--force} option of @command{aclocal} has absolutely no
-effect on the files installed by @code{--install}.  For instance you
-have modified your local macros, do not expect @code{--install
---force} to replace the local macros by their system-wide versions.
-If you want to do so, simply erase the local macros you want to
-revert, and run @code{aclocal -I m4 --install}.
+Finally, note that the @code{--force} option of @command{aclocal} has
+absolutely no effect on the files installed by @code{--install}.  For
+instance you have modified your local macros, do not expect
+@code{--install --force} to replace the local macros by their
+system-wide versions.  If you want to do so, simply erase the local
+macros you want to revert, and run @code{aclocal -I m4 --install}.
 
 
 @node Future of aclocal
index f527e6b..fec2ff6 100644 (file)
@@ -207,18 +207,18 @@ sub up_to_date_p ($@)
 }
 
 
-=item C<handle_exec_errors ($command)>
+=item C<handle_exec_errors ($command, [$expected_exit_code = 0])>
 
 Display an error message for C<$command>, based on the content of
-C<$?> and C<$!>.
+C<$?> and C<$!>.  Be quiet if the command exited normally
+with C<$expected_exit_code>.
 
 =cut
 
-# handle_exec_errors ($COMMAND)
-# -----------------------------
-sub handle_exec_errors ($)
+sub handle_exec_errors ($;$)
 {
-  my ($command) = @_;
+  my ($command, $expected) = @_;
+  $expected = 0 unless defined $expected;
 
   $command = (split (' ', $command))[0];
   if ($!)
@@ -235,7 +235,8 @@ sub handle_exec_errors ($)
          # Propagate exit codes.
          fatal ('',
                 "$command failed with exit status: $status",
-                exit_code => $status);
+                exit_code => $status)
+           unless $status == $expected;
        }
       elsif (WIFSIGNALED ($?))
        {
@@ -272,24 +273,22 @@ sub xqx ($)
 }
 
 
-=item C<xsystem ($command)>
+=item C<xsystem (@argv)>
 
-Same as C<system>, but fails on errors, and reports the C<$command>
+Same as C<system>, but fails on errors, and reports the C<@argv>
 in verbose mode.
 
 =cut
 
-# xsystem ($COMMAND)
-# ------------------
-sub xsystem ($)
+sub xsystem (@)
 {
-  my ($command) = @_;
+  my (@command) = @_;
 
-  verb "running: $command";
+  verb "running: @command";
 
   $! = 0;
-  handle_exec_errors $command
-    if system $command;
+  handle_exec_errors "@command"
+    if system @command;
 }
 
 
index 362d8ba..f6f732c 100755 (executable)
@@ -75,6 +75,13 @@ grep macro23 foo
 
 ACLOCAL_TESTSUITE_FLAGS='-I 4 -I 1 -I 2 -I 3'
 rm -f foo
+$ACLOCAL --install --dry-run
+$AUTOCONF
+./configure
+grep macro12 foo
+grep macro23 foo
+
+rm -f foo
 $ACLOCAL --install
 $AUTOCONF
 ./configure
@@ -93,3 +100,15 @@ $AUTOCONF
 ./configure
 grep macro14 foo
 grep macro21 foo
+
+
+mkdir dirlist-test
+cat >dirlist-test/m1.m4 <<EOF
+#serial 456
+AC_DEFUN([AM_MACRO1], [echo macro1d >> foo])
+AC_DEFUN([AM_MACRO2], [echo macro2d >> foo])
+EOF
+rm -f foo
+$ACLOCAL --diff=diff >output
+cat output
+grep '#serial 456' output