automake-patches
[Top][All Lists]
Advanced

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

aclocal --dry-run and --diff


From: Alexandre Duret-Lutz
Subject: aclocal --dry-run and --diff
Date: Sun, 06 Feb 2005 13:19:54 +0100
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3.50 (gnu/linux)

I'm checking this in.

2005-02-06  Alexandre Duret-Lutz  <address@hidden>

        * 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.

Index: NEWS
===================================================================
RCS file: /cvs/automake/automake/NEWS,v
retrieving revision 1.297
diff -u -r1.297 NEWS
--- NEWS        31 Jan 2005 23:41:05 -0000      1.297
+++ NEWS        6 Feb 2005 12:19:07 -0000
@@ -24,6 +24,9 @@
     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: aclocal.in
===================================================================
RCS file: /cvs/automake/automake/aclocal.in,v
retrieving revision 1.125
diff -u -r1.125 aclocal.in
--- aclocal.in  6 Feb 2005 10:22:28 -0000       1.125
+++ aclocal.in  6 Feb 2005 12:19:07 -0000
@@ -62,6 +62,12 @@
 # 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 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 @@
 
   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 @@
 
 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 @@
 sub parse_arguments ()
 {
   my $print_and_exit = 0;
+  my $diff_command;
 
   my %cli_options =
     (
@@ -811,6 +840,8 @@
                               @automake_includes = ();
                               @system_includes = ($_[1])
                             },
+     'diff:s'          => \$diff_command,
+     'dry-run'         => \$dry_run,
      'force'           => \$force_output,
      'I=s'             => address@hidden,
      'install'          => \$install,
@@ -875,6 +906,14 @@
       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 && address@hidden)
     {
       fatal ("--install should copy macros in the directory indicated by the"
@@ -934,6 +973,7 @@
     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: doc/automake.texi
===================================================================
RCS file: /cvs/automake/automake/doc/automake.texi,v
retrieving revision 1.93
diff -u -r1.93 automake.texi
--- doc/automake.texi   6 Feb 2005 10:32:59 -0000       1.93
+++ doc/automake.texi   6 Feb 2005 12:19:11 -0000
@@ -1646,6 +1646,17 @@
 Look for the macro files in @var{dir} instead of the installation
 directory.  This is typically used for debugging.
 
address@hidden address@hidden
address@hidden --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}.
+
address@hidden --dry-run
address@hidden --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 @@
 version.  MyPackage just had its macro updated as a side effect of
 running @command{aclocal}.
 
-
-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}.
+If you are leery of letting @command{aclocal} update your local macro,
+you can run @code{aclocal -I m4 --diff} to review the changes
address@hidden -I m4 --install} would perform on these macros.
+
+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
address@hidden --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: lib/Automake/FileUtils.pm
===================================================================
RCS file: /cvs/automake/automake/lib/Automake/FileUtils.pm,v
retrieving revision 1.6
diff -u -r1.6 FileUtils.pm
--- lib/Automake/FileUtils.pm   24 Jan 2005 17:03:54 -0000      1.6
+++ lib/Automake/FileUtils.pm   6 Feb 2005 12:19:11 -0000
@@ -207,18 +207,18 @@
 }
 
 
-=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 @@
          # 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 @@
 }
 
 
-=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: tests/acloca18.test
===================================================================
RCS file: /cvs/automake/automake/tests/acloca18.test,v
retrieving revision 1.1
diff -u -r1.1 acloca18.test
--- tests/acloca18.test 31 Jan 2005 23:41:10 -0000      1.1
+++ tests/acloca18.test 6 Feb 2005 12:19:11 -0000
@@ -75,6 +75,13 @@
 
 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 @@
 ./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

-- 
Alexandre Duret-Lutz





reply via email to

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