From: Stefano Lattarini Date: Thu, 15 Mar 2012 15:50:40 +0000 (+0100) Subject: aclocal: create local directory where to install m4 files X-Git-Tag: v1.11.3b~6^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a75a1a52679feed85a181dcf514e32e17117157b;p=thirdparty%2Fautomake.git aclocal: create local directory where to install m4 files Fixes automake bug#8168 and bug#10816. A call like "aclocal -I m4 --install" used to fail if the 'm4' directory wasn't pre-existing. This could be particularly annoying when running in a checked-out version from a VCS like git, which doesn't allow empty directories to be tracked. * aclocal.in (File::Path): New import. (scan_m4_dirs): Don't die if the first directory of type FT_USER doesn't exist and the '--install' option was given; that directory will be created later ... (install_file): ... here. Change signature of this function: now it takes as second argument the destination directory rather than the destination file. Crate the destination directory if it doesn't already exist. In verbose mode, tell what is being copied where. (write_aclocal): Update to the changes in 'install_file'. * NEWS, THANKS: Update. * tests/aclocal-install-fail.test: New test. * tests/aclocal-install-mkdir.test: Likewise. * tests/aclocal-no-install-no-mkdir.test: Likewise. * tests/aclocal-verbose-install.test: Likewise. * tests/list-of-tests.mk: Add them. Signed-off-by: Stefano Lattarini --- diff --git a/NEWS b/NEWS index b998ce401..2b5f68f4d 100644 --- a/NEWS +++ b/NEWS @@ -122,6 +122,10 @@ New in 1.11.0a: optional space between the -I, -L and -l options and their respective arguments, for better POSIX compliance. + - If "aclocal --install" is used, and the first directory specified with + '-I' is non-existent, aclocal will now create it before trying to copy + files in it. + Bugs fixed in 1.11.0a: * Bugs introduced by 1.11.2: diff --git a/THANKS b/THANKS index 83631268b..d7b36585f 100644 --- a/THANKS +++ b/THANKS @@ -73,6 +73,7 @@ Dave Brolley brolley@redhat.com Dave Korn dave.korn.cygwin@googlemail.com Dave Morrison dave@bnl.gov David A. Swierczek swiercze@mr.med.ge.com +David A. Wheeler dwheeler@dwheeler.com David Byron dbyron@dbyron.com Davyd Madeley davyd@fugro-fsi.com.au David Pashley david@davidpashley.com @@ -149,6 +150,7 @@ Janos Farkas chexum@shadow.banki.hu Jared Davis abiword@aiksaurus.com Jason Duell jcduell@lbl.gov Jason Molenda crash@cygnus.co.jp +Javier Jardón jjardon@gnome.org Jeff Bailey Jbailey@phn.ca Jeff Garzik jgarzik@pobox.com Jeff Squyres jsquyres@lam-mpi.org diff --git a/aclocal.in b/aclocal.in index ed1d8d90f..ca1573222 100644 --- a/aclocal.in +++ b/aclocal.in @@ -7,9 +7,7 @@ eval 'case $# in 0) exec @PERL@ -S "$0";; *) exec @PERL@ -S "$0" "$@";; esac' # aclocal - create aclocal.m4 by scanning configure.ac -# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, -# 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, -# Inc. +# Copyright (C) 1996-2012 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 @@ -45,6 +43,7 @@ use Automake::FileUtils; use File::Basename; use File::stat; use Cwd; +use File::Path (); # Some globals. @@ -181,6 +180,17 @@ sub unlink_tmp $SIG{'INT'} = $SIG{'TERM'} = $SIG{'QUIT'} = $SIG{'HUP'} = 'unlink_tmp'; END { unlink_tmp } +sub xmkdir_p ($) +{ + my $dir = shift; + local $@ = undef; + return + if -d $dir or eval { File::Path::mkpath $dir }; + chomp $@; + $@ =~ s/\s+at\s.*\bline\s\d+.*$//; + fatal "could not create directory '$dir': $@"; +} + # Check macros in acinclude.m4. If one is not used, warn. sub check_acinclude () { @@ -210,12 +220,15 @@ sub reset_maps () undef &search; } -# install_file ($SRC, $DEST) +# install_file ($SRC, $DESTDIR) sub install_file ($$) { - my ($src, $dest) = @_; + my ($src, $destdir) = @_; + my $dest = $destdir . "/" . basename ($src); my $diff_dest; + verb "installing $src to $dest"; + if ($force_output || !exists $file_contents{$dest} || $file_contents{$src} ne $file_contents{$dest}) @@ -268,6 +281,7 @@ sub install_file ($$) } elsif (!$dry_run) { + xmkdir_p ($destdir); xsystem ('cp', $src, $dest); } } @@ -307,6 +321,7 @@ sub list_compare (\@\@) # -------------------------- # Scan all M4 files installed in @DIRS for new macro definitions. # Register each file as of type $TYPE (one of the FT_* constants). +my $first_user_m4dir = 1; sub scan_m4_dirs ($@) { my ($type, @dirlist) = @_; @@ -315,7 +330,16 @@ sub scan_m4_dirs ($@) { if (! opendir (DIR, $m4dir)) { - fatal "couldn't open directory `$m4dir': $!"; + if ($install && $type == FT_USER && $first_user_m4dir) + { + # We will try to create this directory later, so don't + # complain if it doesn't exist. + # TODO: maybe we should avoid complaining only if errno + # is ENONENT? + $first_user_m4dir = 0; + next; + } + fatal "couldn't open directory '$m4dir': $!"; } # We reverse the directory contents so that foo2.m4 gets @@ -773,9 +797,7 @@ sub write_aclocal ($@) my $dest; for my $ifile (@{$file_includes{$file}}, $file) { - $dest = "$user_includes[0]/" . basename $ifile; - verb "installing $ifile to $dest"; - install_file ($ifile, $dest); + install_file ($ifile, $user_includes[0]); } $installed = 1; } diff --git a/tests/aclocal-install-fail.test b/tests/aclocal-install-fail.test new file mode 100755 index 000000000..cf493aa81 --- /dev/null +++ b/tests/aclocal-install-fail.test @@ -0,0 +1,65 @@ +#! /bin/sh +# Copyright (C) 2012 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 +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Check that "aclocal --install" fails when it should. +# FIXME: this is a good candidate for a conversion to TAP. + +am_create_testdir=empty +required=ro-dir +. ./defs || Exit 1 + +set -e + +cat > configure.in < sys-acdir/my-defs.m4 < a-regular-file +mkdir unwritable-dir +chmod a-w unwritable-dir + +$ACLOCAL -I a-regular-file --install 2>stderr \ + && { cat stderr >&2; Exit 1; } +cat stderr >&2 +$EGREP '(mkdir:|directory ).*a-regular-file' stderr +test ! -f aclocal.m4 + +$ACLOCAL --install -I unwritable-dir/sub 2>stderr \ + && { cat stderr >&2; Exit 1; } +cat stderr >&2 +$EGREP '(mkdir:|directory ).*unwritable-dir/sub' stderr +test ! -f aclocal.m4 + +$ACLOCAL -I unwritable-dir --install 2>stderr \ + && { cat stderr >&2; Exit 1; } +cat stderr >&2 +$EGREP '(cp:|copy ).*unwritable-dir' stderr +test ! -f aclocal.m4 + +# Sanity check. +mkdir m4 +$ACLOCAL -I m4 --install && test -f aclocal.m4 \ + || fatal_ "aclocal failed also when expected to succeed" + +: diff --git a/tests/aclocal-install-mkdir.test b/tests/aclocal-install-mkdir.test new file mode 100755 index 000000000..54e97ab60 --- /dev/null +++ b/tests/aclocal-install-mkdir.test @@ -0,0 +1,72 @@ +#! /bin/sh +# Copyright (C) 2012 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 +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Check that "aclocal --install" creates the local m4 directory if +# necessary. +# FIXME: this is a good candidate for a conversion to TAP. + +am_create_testdir=empty +. ./defs || Exit 1 + +set -e + +cat > configure.in < sys-acdir/my-defs.m4 <. + +# Check that aclocal does not create a non-existent local m4 directory +# if the '--install' option is not given. + +am_create_testdir=empty +. ./defs || Exit 1 + +set -e + +cat > configure.in < sys-acdir/my-defs.m4 <. + +# Check verbose messages by `aclocal --install'. + +am_create_testdir=empty +. ./defs || Exit 1 + +set -e + +cat > configure.in < sys-acdir/bar.m4 < sys-acdir/quux.m4 < foodir/bar.m4 + +$ACLOCAL --system-acdir=sys-acdir --install --verbose -I foodir 2>stderr \ + || { cat stderr >&2; Exit 1; } +cat stderr >&2 +grep ' installing .*sys-acdir/bar\.m4.* to .*foodir/bar\.m4' stderr +grep ' installing .*sys-acdir/quux\.m4.* to .*foodir/quux\.m4' stderr +grep ' overwriting .*foodir/bar\.m4.* with .*sys-acdir/bar\.m4' stderr +grep ' installing .*foodir/quux\.m4.* from .*sys-acdir/quux\.m4' stderr + +# Sanity checks. +ls -l foodir +grep MY_MACRO_BAR foodir/bar.m4 +grep MY_MACRO_QUUX foodir/quux.m4 + +: diff --git a/tests/list-of-tests.mk b/tests/list-of-tests.mk index b5a604cd0..f9109c060 100644 --- a/tests/list-of-tests.mk +++ b/tests/list-of-tests.mk @@ -64,6 +64,10 @@ aclocal-path-install.test \ aclocal-path-install-serial.test \ aclocal-path-nonexistent.test \ aclocal-path-precedence.test \ +aclocal-install-fail.test \ +aclocal-install-mkdir.test \ +aclocal-no-install-no-mkdir.test \ +aclocal-verbose-install.test \ acoutnoq.test \ acoutpt.test \ acoutpt2.test \