From 7eaf5f45ea6ca6ad52af82ebb0585c5626658fc0 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Wed, 8 Dec 2004 22:00:50 +0000 Subject: [PATCH] * lib/Automake/FileUtils.pm (dir_has_case_matching_file, reset_dir_cache): New functions. * automake.in (handle_dist, require_file_internal): Use them, so that CHANGELOG is not confused with ChangeLog on case-insensitive case-preserving file systems. * tests/hfs.test: New file. * tests/Makefile.am (TESTS): Add hfs.test. --- ChangeLog | 13 ++++++++- THANKS | 1 + automake.in | 7 ++--- lib/Automake/FileUtils.pm | 56 +++++++++++++++++++++++++++++++++++++-- tests/Makefile.am | 1 + tests/Makefile.in | 1 + tests/hfs.test | 39 +++++++++++++++++++++++++++ 7 files changed, 112 insertions(+), 6 deletions(-) create mode 100755 tests/hfs.test diff --git a/ChangeLog b/ChangeLog index 5cc55f0ed..cb3cedb4e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2004-12-08 Peter O'Gorman + Alexandre Duret-Lutz + + * lib/Automake/FileUtils.pm (dir_has_case_matching_file, + reset_dir_cache): New functions. + * automake.in (handle_dist, require_file_internal): Use them, so + that CHANGELOG is not confused with ChangeLog on case-insensitive + case-preserving file systems. + * tests/hfs.test: New file. + * tests/Makefile.am (TESTS): Add hfs.test. + 2004-12-08 Paul Eggert * lib/mdate-sh: Don't use "set - x`$ls_command /`", as zsh mishandles @@ -5,7 +16,7 @@ . Don't use "set - x"; plain "set x" is enough, and simplifies debugging. -2004-11-15 Toshio Kuratomi +2004-12-05 Toshio Kuratomi * lib/py-compile: Add --destdir switch to py-compile that takes a path argument that is not compiled into the file when byte compiling. diff --git a/THANKS b/THANKS index d13d6a825..6bc07be0f 100644 --- a/THANKS +++ b/THANKS @@ -202,6 +202,7 @@ Peter Eisentraut peter_e@gmx.net Peter Gavin pgavin@debaser.kicks-ass.org Peter Mattis petm@scam.XCF.Berkeley.EDU Peter Muir iyhi@yahoo.com +Peter O'Gorman peter@pogma.com Peter Seiderer seiderer123@ciselant.de Petter Reinholdtsen pere@hungry.com Phil Edwards phil@jaj.com diff --git a/automake.in b/automake.in index 4a085ef41..84aa4c8be 100755 --- a/automake.in +++ b/automake.in @@ -3505,7 +3505,7 @@ sub handle_dist () } foreach my $cfile (@common_files) { - if (-f ($relative_dir . "/" . $cfile) + if (dir_has_case_matching_file ($relative_dir, $cfile) # The file might be absent, but if it can be built it's ok. || rule $cfile) { @@ -3514,7 +3514,7 @@ sub handle_dist () # Don't use `elsif' here because a file might meaningfully # appear in both directories. - if ($check_aux && -f "$config_aux_dir/$cfile") + if ($check_aux && dir_has_case_matching_file ($config_aux_dir, $cfile)) { &push_dist_common ("$config_aux_dir/$cfile") } @@ -6925,7 +6925,7 @@ sub require_file_internal ($$$@) { $dangling_sym = 1; } - elsif (-f $fullfile) + elsif (dir_has_case_matching_file ($dir, $file)) { $found_it = 1; maybe_push_required_file ($dir, $file, $fullfile); @@ -6989,6 +6989,7 @@ sub require_file_internal ($$$@) $suppress = 0; $trailer = "\n error while copying"; } + reset_dir_cache ($dir); } if (! maybe_push_required_file (dirname ($fullfile), diff --git a/lib/Automake/FileUtils.pm b/lib/Automake/FileUtils.pm index bb8304e99..2c9cba375 100644 --- a/lib/Automake/FileUtils.pm +++ b/lib/Automake/FileUtils.pm @@ -1,4 +1,4 @@ -# Copyright (C) 2003 Free Software Foundation, Inc. +# Copyright (C) 2003, 2004 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 @@ -44,7 +44,7 @@ use vars qw (@ISA @EXPORT); @EXPORT = qw (&contents &find_file &mtime &update_file &up_to_date_p - &xsystem &xqx); + &xsystem &xqx &dir_has_case_matching_file &reset_dir_cache); =item C @@ -310,6 +310,58 @@ sub contents ($) } +=item C + +Return true iff $DIR contains a filename that matches $FILENAME case +insensitively. + +We need to be cautious on case-insensitive case-preserving file +systems (e.g. Mac OS X's HFS+). On such systems C<-f 'Foo'> and C<-f +'foO'> answer the same thing. Hence if a package distributes its own +F file, but has no F file, automake would still +try to distribute F (because it thinks it exists) in +addition to F, although it is impossible for these two +files to be in the same directory (the two filenames designate the +same file). + +=cut + +use vars '%_directory_cache'; +sub dir_has_case_matching_file ($$) +{ + # Note that print File::Spec->case_tolerant returns 0 even on MacOS + # X (with Perl v5.8.1-RC3 at least), so do not try to shortcut this + # function using that. + + my ($dirname, $filename) = @_; + return 0 unless -f "$dirname/$filename"; + + # The file appears to exist, however it might be a mirage if the + # system is case insensitive. Let's browse the directory and check + # whether the file is really in. We maintain a cache of directories + # so Automake doesn't spend all its time reading the same directory + # again and again. + if (!exists $_directory_cache{$dirname}) + { + error "failed to open directory `$dirname'" + unless opendir (DIR, $dirname); + $_directory_cache{$dirname} = { map { $_ => 1 } readdir (DIR) }; + closedir (DIR); + } + return exists $_directory_cache{$dirname}{$filename}; +} + +=item C + +Clear C's cache for C<$dirname>. + +=cut + +sub reset_dir_cache ($) +{ + delete $_directory_cache{$_[0]}; +} + 1; # for require ### Setup "GNU" style for perl-mode and cperl-mode. diff --git a/tests/Makefile.am b/tests/Makefile.am index 62adf6302..527c19e26 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -248,6 +248,7 @@ gnits2.test \ gnits3.test \ header.test \ help.test \ +hfs.test \ hosts.test \ implicit.test \ include.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index 11bfe1f8c..79f0e885b 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -367,6 +367,7 @@ gnits2.test \ gnits3.test \ header.test \ help.test \ +hfs.test \ hosts.test \ implicit.test \ include.test \ diff --git a/tests/hfs.test b/tests/hfs.test new file mode 100755 index 000000000..9e3748f1b --- /dev/null +++ b/tests/hfs.test @@ -0,0 +1,39 @@ +#! /bin/sh +# Copyright (C) 2004 Free Software Foundation, Inc. +# +# This file is part of GNU Automake. +# +# GNU Automake 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. +# +# GNU Automake 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 Automake; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + + +# Automake should not think that ChangeLog == CHANGELOG on +# case-preserving case-insensitive filesystems (such as HFS+, on +# Darwin). +# Report from Peter O'Gorman. + +. ./defs +set -e + +echo AC_OUTPUT >>configure.in + +: >CHANGELOG +echo 'EXTRA_DIST = CHANGELOG' >Makefile.am + +$ACLOCAL +$AUTOCONF +$AUTOMAKE +./configure +$MAKE distcheck -- 2.47.2