[前][次][番号順一覧][スレッド一覧]

ruby-changes:9899

From: nobu <ko1@a...>
Date: Mon, 12 Jan 2009 12:40:15 +0900 (JST)
Subject: [ruby-changes:9899] Ruby:r21440 (trunk): * instruby.rb (install_recursive): skips the directory if matched

nobu	2009-01-12 12:39:58 +0900 (Mon, 12 Jan 2009)

  New Revision: 21440

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=21440

  Log:
    * instruby.rb (install_recursive): skips the directory if matched
      to a no_install pattern ending with a file separator.

  Modified files:
    trunk/ChangeLog
    trunk/instruby.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 21439)
+++ ChangeLog	(revision 21440)
@@ -1,3 +1,8 @@
+Mon Jan 12 12:39:56 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* instruby.rb (install_recursive): skips the directory if matched
+	  to a no_install pattern ending with a file separator.
+
 Mon Jan 12 12:33:56 2009  Tanaka Akira  <akr@f...>
 
 	* ext/socket/mkconstants.rb: don't use bytesize because 1.9 dependent.
Index: instruby.rb
===================================================================
--- instruby.rb	(revision 21439)
+++ instruby.rb	(revision 21440)
@@ -159,25 +159,59 @@
   super(dirs, :mode => $dir_mode) unless dirs.empty?
 end
 
+FalseProc = proc {false}
+def path_matcher(pat)
+  if pat and !pat.empty?
+    proc {|f| pat.any? {|n| File.fnmatch?(n, f)}}
+  else
+    FalseProc
+  end
+end
+
 def install_recursive(srcdir, dest, options = {})
   opts = options.clone
   noinst = opts.delete(:no_install)
   glob = opts.delete(:glob) || "*"
-  subpath = srcdir.size..-1
-  Dir.glob("#{srcdir}/**/#{glob}") do |src|
-    case base = File.basename(src)
-    when /\A\#.*\#\z/, /~\z/
-      next
-    end
-    if noinst
-      if Array === noinst
-        next if noinst.any? {|n| File.fnmatch?(n, base)}
+  subpath = (srcdir.size+1)..-1
+  prune = skip = FalseProc
+  if noinst
+    if Array === noinst
+      prune = noinst.grep(/#{File::SEPARATOR}/o).map!{|f| f.chomp(File::SEPARATOR)}
+      skip = noinst.grep(/\A[^#{File::SEPARATOR}]*\z/o)
+    else
+      if noinst.index(File::SEPARATOR)
+        prune = [noinst]
       else
-        next if File.fnmatch?(noinst, base)
+        skip = [noinst]
       end
     end
-    d = dest + src[subpath]
-    if File.directory?(src)
+    skip |= %w"#*# *~ *.old *.bak *.orig *.rej *.diff *.patch *.core"
+    prune = path_matcher(prune)
+    skip = path_matcher(skip)
+  end
+  File.directory?(srcdir) or return rescue return
+  paths = [[srcdir, dest, true]]
+  found = []
+  while file = paths.shift
+    found << file
+    file, d, dir = *file
+    if dir
+      files = []
+      Dir.foreach(file) do |f|
+        src = File.join(file, f)
+        d = File.join(dest, dir = src[subpath])
+        stat = File.lstat(src) rescue next
+        if stat.directory?
+          files << [src, d, true] if /\A\./ !~ f and !prune[dir]
+        else
+          files << [src, d, false] if File.fnmatch?(glob, f) and !skip[f]
+        end
+      end
+      paths.insert(0, *files)
+    end
+  end
+  for src, d, dir in found
+    if dir
       makedirs(d)
     else
       makedirs(File.dirname(d))
@@ -265,9 +299,7 @@
   install?(:ext, :arch, :'ext-arch') do
     puts "installing extension objects"
     makedirs [archlibdir, sitearchlibdir, vendorarchlibdir, archhdrdir]
-    if noinst = CONFIG["no_install_files"] and noinst.empty?
-      noinst = nil
-    end
+    noinst = %w[-*] | (CONFIG["no_install_files"] || "").split
     install_recursive("#{extout}/#{CONFIG['arch']}", archlibdir, :no_install => noinst, :mode => $prog_mode)
     install_recursive("#{extout}/include/#{CONFIG['arch']}", archhdrdir, :glob => "*.h", :mode => $data_mode)
   end
@@ -407,7 +439,7 @@
   end
 end
 
-install?(:local, :comm, :gem) do
+install?(:ext, :comm, :gem) do
   puts "creating default gem directories"
 
   directories = []

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]