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.
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 ...
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
# 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;
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);
}
}
}
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;
}
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
sub parse_arguments ()
{
my $print_and_exit = 0;
+ my $diff_command;
my %cli_options =
(
@automake_includes = ();
@system_includes = ($_[1])
},
+ 'diff:s' => \$diff_command,
+ 'dry-run' => \$dry_run,
'force' => \$force_output,
'I=s' => \@user_includes,
'install' => \$install,
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"
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;
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.
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
}
-=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 ($!)
# Propagate exit codes.
fatal ('',
"$command failed with exit status: $status",
- exit_code => $status);
+ exit_code => $status)
+ unless $status == $expected;
}
elsif (WIFSIGNALED ($?))
{
}
-=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;
}
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
./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