From a21146a57503dcda22c6764afe6f67e9be5468ac Mon Sep 17 00:00:00 2001 From: yugui Date: Wed, 28 Jan 2009 09:23:03 +0000 Subject: merges r21764 and r21765 from trunk into ruby_1_9_1. * Makefile.in, win32/Makefile.sub (RMDIRS): remove directory and parents. * Makefile.in, win32/Makefile.sub (distclean-rdoc): added to remove temprary rdoc. * Makefile.in, win32/Makefile.sub (distclean): removes extout directory. * Makefile.in, win32/Makefile.sub (clean-ext): skips non-existent directories. * common.mk (clean, distclean): cleans rdoc. * common.mk (clean-extout): removes extout directory. * configure.in (RMDIRS, RMALL): added to clean extout. * lib/fileutils.rb (FileUtils#rmdir): added :parents option. * lib/mkmf.rb (create_makefile): cleans installed files at clean instead of distclean. * lib/mkmf.rb (create_makefile): added clean-so and clean-rb. * lib/mkmf.rb (def init_mkmf): added DISTCLEANDIRS. * lib/un.rb (rmdir): added -p option. * tool/rmdirs, win32/rmdirs.bat: removes directory and the parents. * win32/rm.bat: added -r option. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@21833 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/fileutils.rb | 15 +++++++++--- lib/mkmf.rb | 74 +++++++++++++++++++++++++++++++++++++------------------- lib/un.rb | 4 ++- 3 files changed, 64 insertions(+), 29 deletions(-) (limited to 'lib') diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 56fb19beb2..774c0dec8a 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -258,15 +258,24 @@ module FileUtils def rmdir(list, options = {}) fu_check_options options, OPT_TABLE['rmdir'] list = fu_list(list) - fu_output_message "rmdir #{list.join ' '}" if options[:verbose] + parents = options[:parents] + fu_output_message "rmdir #{parents ? '-p ' : ''}#{list.join ' '}" if options[:verbose] return if options[:noop] list.each do |dir| - Dir.rmdir dir.sub(%r, '') + begin + Dir.rmdir(dir = dir.sub(%r, '')) + if parents + until (parent = File.dirname(dir)) == '.' or parent == dir + Dir.rmdir(dir) + end + end + rescue Errno::ENOTEMPTY, Errno::ENOENT + end end end module_function :rmdir - OPT_TABLE['rmdir'] = [:noop, :verbose] + OPT_TABLE['rmdir'] = [:parents, :noop, :verbose] # # Options: force noop verbose diff --git a/lib/mkmf.rb b/lib/mkmf.rb index e3fd6ea619..1d46f6c299 100644 --- a/lib/mkmf.rb +++ b/lib/mkmf.rb @@ -1407,6 +1407,7 @@ ruby = #{$ruby} RUBY = $(ruby#{sep}) RM = #{config_string('RM', &possible_command) || '$(RUBY) -run -e rm -- -f'} RM_RF = #{'$(RUBY) -run -e rm -- -rf'} +RMDIRS = #{config_string('RMDIRS', &possible_command) || '$(RUBY) -run -e rmdir -- -p'} MAKEDIRS = #{config_string('MAKEDIRS', &possible_command) || '@$(RUBY) -run -e mkdir -- -p'} INSTALL = #{config_string('INSTALL', &possible_command) || '@$(RUBY) -run -e install -- -vp'} INSTALL_PROG = #{config_string('INSTALL_PROG') || '$(INSTALL) -m 0755'} @@ -1606,7 +1607,8 @@ def create_makefile(target, srcprefix = nil) origdef ||= '' if $extout and $INSTALLFILES - $distcleanfiles.concat($INSTALLFILES.collect {|files, dir|File.join(dir, files.sub(/\A\.\//, ''))}) + $cleanfiles.concat($INSTALLFILES.collect {|files, dir|File.join(dir, files.sub(/\A\.\//, ''))}) + $distcleandirs.concat($INSTALLFILES.collect {|files, dir| dir}) end if $extmk and not $extconf_h @@ -1626,6 +1628,7 @@ DEFFILE = #{deffile} CLEANFILES = #{$cleanfiles.join(' ')} DISTCLEANFILES = #{$distcleanfiles.join(' ')} +DISTCLEANDIRS = #{$distcleandirs.join(' ')} extout = #{$extout} extout_prefix = #{$extout_prefix} @@ -1652,6 +1655,18 @@ all: #{$extout ? "install" : target ? "$(DLLIB)" : "Makefile"} static: $(STATIC_LIB)#{$extout ? " install-rb" : ""} " mfile.print CLEANINGS + fsep = config_string('BUILD_FILE_SEPARATOR') {|s| s unless s == "/"} + if fsep + fseprepl = proc {|s| + s = s.gsub("/", fsep) + s = s.gsub(/(\$\(\w+)(\))/) {$1+sep+$2} + s = s.gsub(/(\$\{\w+)(\})/) {$1+sep+$2} + } + sep = ":/=#{fsep}" + else + fseprepl = proc {|s| s} + sep = "" + end dirs = [] mfile.print "install: install-so install-rb\n\n" sodir = (dir = "$(RUBYARCHDIR)").dup @@ -1660,18 +1675,13 @@ static: $(STATIC_LIB)#{$extout ? " install-rb" : ""} f = "$(DLLIB)" dest = "#{dir}/#{f}" mfile.puts dir, "install-so: #{dest}" - unless $extout + if $extout + mfile.print "clean-so::\n" + mfile.print "\t@-$(RM) #{fseprepl[dest]}\n" + mfile.print "\t@-$(RMDIRS) #{fseprepl[dir]}\n" + else mfile.print "#{dest}: #{f}\n" - if (sep = config_string('BUILD_FILE_SEPARATOR')) - f.gsub!("/", sep) - dir.gsub!("/", sep) - sep = ":/="+sep - f.gsub!(/(\$\(\w+)(\))/) {$1+sep+$2} - f.gsub!(/(\$\{\w+)(\})/) {$1+sep+$2} - dir.gsub!(/(\$\(\w+)(\))/) {$1+sep+$2} - dir.gsub!(/(\$\{\w+)(\})/) {$1+sep+$2} - end - mfile.print "\t$(INSTALL_PROG) #{f} #{dir}\n" + mfile.print "\t$(INSTALL_PROG) #{fseprepl[f]} #{fseprepl[dir]}\n" if defined?($installed_list) mfile.print "\t@echo #{dir}/#{File.basename(f)}>>$(INSTALLED_LIST)\n" end @@ -1683,35 +1693,41 @@ static: $(STATIC_LIB)#{$extout ? " install-rb" : ""} mfile.print("install-rb-default: pre-install-rb-default\n") mfile.print("pre-install-rb: Makefile\n") mfile.print("pre-install-rb-default: Makefile\n") - fsep = config_string('BUILD_FILE_SEPARATOR') {|s| s unless s == "/"} - sep = fsep ? ":/=#{fsep}" : "" for sfx, i in [["-default", [["lib/**/*.rb", "$(RUBYLIBDIR)", "lib"]]], ["", $INSTALLFILES]] files = install_files(mfile, i, nil, srcprefix) or next for dir, *files in files unless dirs.include?(dir) dirs << dir mfile.print "pre-install-rb#{sfx}: #{dir}\n" - end if $nmake + end for f in files dest = "#{dir}/#{File.basename(f)}" mfile.print("install-rb#{sfx}: #{dest}\n") mfile.print("#{dest}: #{f}\n") - mfile.print("\t$(MAKEDIRS) $(@D)\n") unless $nmake mfile.print("\t$(#{$extout ? 'COPY' : 'INSTALL_DATA'}) ") - if fsep - f = f.gsub("/", fsep) - f = f.gsub(/(\$\(\w+)(\))/) {$1+sep+$2} - f = f.gsub(/(\$\{\w+)(\})/) {$1+sep+$2} - end - mfile.print("#{f} $(@D#{sep})\n") + mfile.print("#{fseprepl[f]} $(@D#{sep})\n") if defined?($installed_list) and !$extout mfile.print("\t@echo #{dest}>>$(INSTALLED_LIST)\n") end + if $extout + mfile.print("clean-rb#{sfx}::\n") + mfile.print("\t@-$(RM) #{fseprepl[dest]}\n") + end + end + end + if $extout + dirs.uniq! + dirs.reverse! + unless dirs.empty? + mfile.print("clean-rb#{sfx}::\n") + for dir in dirs + mfile.print("\t@-$(RMDIRS) #{fseprepl[dir]}\n") + end end end end dirs.unshift(sodir) if target and !dirs.include?(sodir) - dirs.each {|d| mfile.print "#{d}:\n\t$(MAKEDIRS) $@\n" if $nmake || d == sodir} + dirs.each {|d| mfile.print "#{d}:\n\t$(MAKEDIRS) $@\n"} mfile.print <<-SITEINSTALL @@ -1823,6 +1839,7 @@ def init_mkmf(config = CONFIG) $cleanfiles = config_string('CLEANFILES') {|s| Shellwords.shellwords(s)} || [] $cleanfiles << "mkmf.log" $distcleanfiles = config_string('DISTCLEANFILES') {|s| Shellwords.shellwords(s)} || [] + $distcleandirs = config_string('DISTCLEANDIRS') {|s| Shellwords.shellwords(s)} || [] $extout ||= nil $extout_prefix ||= nil @@ -1917,12 +1934,19 @@ MAIN_DOES_NOTHING = config_string('MAIN_DOES_NOTHING') || 'int main() {return 0; sep = config_string('BUILD_FILE_SEPARATOR') {|s| ":/=#{s}" if sep != "/"} || "" CLEANINGS = " -clean: +clean-rb-default:: +clean-rb:: +clean-so:: +clean: clean-so clean-rb-default clean-rb \t\t@-$(RM) $(CLEANLIBS#{sep}) $(CLEANOBJS#{sep}) $(CLEANFILES#{sep}) -distclean: clean +distclean-rb-default:: +distclean-rb:: +distclean-so:: +distclean: clean distclean-so distclean-rb-default distclean-rb \t\t@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log \t\t@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES#{sep}) +\t\t@-$(RMDIRS) $(DISTCLEANDIRS#{sep}) realclean: distclean " diff --git a/lib/un.rb b/lib/un.rb index 3dcdbede4a..42afeacc4e 100644 --- a/lib/un.rb +++ b/lib/un.rb @@ -158,11 +158,13 @@ end # # ruby -run -e rmdir -- [OPTION] DIR # +# -p remove DIRECTORY and its ancestors. # -v verbose # def rmdir - setup do |argv, options| + setup("p") do |argv, options| + options[:parents] = true if options.delete :p FileUtils.rmdir argv, options end end -- cgit v1.2.3