automake-patches
[Top][All Lists]
Advanced

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

Re: aclocal --diff on Tru64


From: Alexandre Duret-Lutz
Subject: Re: aclocal --diff on Tru64
Date: Fri, 04 Aug 2006 10:42:48 +0200
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/22.0.50 (gnu/linux)

On second though I'm less happy the "global" empty file.  The
reason is that we can use --diff='diff -u' or any other tools
that shows the filename in its output, and such a global file
would look weird.

It occurred to me that there is a simpler approach that does not
require any configury magic, and no new command lines options.
Create an empty file like Ralf did in his first patch, but do
that on any architecture, and use the actual destination file
name instead of some hard-coded one.  I believe that doing so
should make sense to any kind of tool one might want to use
with --diff=xxx.

I'm checking this in.

2006-08-04  Alexandre Duret-Lutz  <address@hidden>

        * aclocal.in (install_file): Cannot use /dev/null while diffing
        new files, because Tru64's diff do not handle /dev/null.  So
        create an empty destination file before running diff on a new
        file, and erase it afterward.  Fall back to using /dev/null only
        if we cannot create this file.
        Report and initial patch from Ralf Wildenhues.
        (unlink_tmp): New function.
        * test/acloca18.test: Make sure the empty file has been erased.

Index: aclocal.in
===================================================================
RCS file: /cvs/automake/automake/aclocal.in,v
retrieving revision 1.138
diff -u -r1.138 aclocal.in
--- aclocal.in  21 Apr 2006 19:02:29 -0000      1.138
+++ aclocal.in  4 Aug 2006 08:42:18 -0000
@@ -144,9 +144,25 @@
 # Autoconf version
 # Set by trace_used_macros.
 my $ac_version;
+
+# If set, names a temporary file that must be erased on abnormal exit.
+my $erase_me;
 
 ################################################################
 
+# Erase temporary file ERASE_ME.
+sub unlink_tmp
+{
+  if (defined $erase_me && -e $erase_me && !unlink ($erase_me))
+    {
+      fatal "could not remove `$erase_me': $!";
+    }
+  undef $erase_me;
+}
+
+$SIG{'INT'} = $SIG{'TERM'} = $SIG{'QUIT'} = $SIG{'HUP'} = 'unlink_tmp';
+END { unlink_tmp }
+
 # Check macros in acinclude.m4.  If one is not used, warn.
 sub check_acinclude ()
 {
@@ -180,7 +196,7 @@
 sub install_file ($$)
 {
   my ($src, $dest) = @_;
-  my $diff_dest = $dest;
+  my $diff_dest;
 
   if ($force_output
       || !exists $file_contents{$dest}
@@ -189,21 +205,48 @@
       if (-e $dest)
        {
          msg 'note', "overwriting `$dest' with `$src'";
+         $diff_dest = $dest;
        }
       else
        {
          msg 'note', "installing `$dest' from `$src'";
-         $diff_dest = '/dev/null';
        }
 
       if (@diff_command)
        {
+         if (! defined $diff_dest)
+           {
+             # $dest does not exist.  We create an empty one just to
+             # run diff, and we erase it afterward.  Using the real
+             # the destination file (rather than a temporary file) is
+             # good when diff is run with options that display the
+             # file name.
+             #
+             # If creating $dest fails, fall back to /dev/null.  At
+             # least one diff implementation (Tru64's) cannot deal
+             # with /dev/null.  However working around this is not
+             # worth the trouble since nobody run aclocal on a
+             # read-only tree anyway.
+             $erase_me = $dest;
+             my $f = new IO::File "> $dest";
+             if (! defined $f)
+               {
+                 undef $erase_me;
+                 $diff_dest = '/dev/null';
+               }
+             else
+               {
+                 $diff_dest = $dest;
+                 $f->close;
+               }
+           }
          my @cmd = (@diff_command, $diff_dest, $src);
          $! = 0;
          verb "running: @cmd";
          my $res = system (@cmd);
          Automake::FileUtils::handle_exec_errors "@cmd", 1
            if $res;
+         unlink_tmp;
        }
       elsif (!$dry_run)
        {
Index: tests/acloca18.test
===================================================================
RCS file: /cvs/automake/automake/tests/acloca18.test,v
retrieving revision 1.3
diff -u -r1.3 acloca18.test
--- tests/acloca18.test 14 May 2005 20:28:53 -0000      1.3
+++ tests/acloca18.test 4 Aug 2006 08:42:18 -0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-# Copyright (C) 2005  Free Software Foundation, Inc.
+# Copyright (C) 2005, 2006  Free Software Foundation, Inc.
 #
 # This file is part of GNU Automake.
 #
@@ -109,6 +109,9 @@
 AC_DEFUN([AM_MACRO2], [echo macro2d >> foo])
 EOF
 rm -f foo
-$ACLOCAL --diff=diff >output
+$ACLOCAL --diff=diff >output 2>stderr
+cat stderr
 cat output
 grep '#serial 456' output
+test ! -f 4/m1.m4
+grep 'installing.*4/m1.m4' stderr
-- 
Alexandre Duret-Lutz

Shared books are happy books.     http://www.bookcrossing.com/friend/gadl





reply via email to

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