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

ruby-changes:27321

From: nobu <ko1@a...>
Date: Fri, 22 Feb 2013 11:41:48 +0900 (JST)
Subject: [ruby-changes:27321] nobu:r39373 (trunk): * tool/mkrunnable.rb: refactor and multiarch support.

nobu	2013-02-22 11:37:51 +0900 (Fri, 22 Feb 2013)

  New Revision: 39373

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

  Log:
    * tool/mkrunnable.rb: refactor and multiarch support.

  Modified files:
    trunk/tool/mkrunnable.rb

Index: tool/mkrunnable.rb
===================================================================
--- tool/mkrunnable.rb	(revision 39372)
+++ tool/mkrunnable.rb	(revision 39373)
@@ -15,15 +15,6 @@ else https://github.com/ruby/ruby/blob/trunk/tool/mkrunnable.rb#L15
   include FileUtils
 end
 
-def relative_from(path, base)
-  dir = File.join(path, "")
-  if File.expand_path(dir) == File.expand_path(dir, base)
-    path
-  else
-    File.join(base, path)
-  end
-end
-
 module Mswin
   def ln_safe(src, dest, *opt)
     cmd = ["mklink", dest.tr("/", "\\"), src.tr("/", "\\")]
@@ -49,16 +40,57 @@ if /mingw|mswin/ =~ CROSS_COMPILING https://github.com/ruby/ruby/blob/trunk/tool/mkrunnable.rb#L40
   extend Mswin
 end
 
-config = RbConfig::CONFIG
+def clean_path(path)
+  path = "#{path}/".gsub(/(\A|\/)(?:\.\/)+/, '\1').tr_s('/', '/')
+  nil while path.sub!(/[^\/]+\/\.\.\//, '')
+  path
+end
+
+def relative_path_from(path, base)
+  path = clean_path(path)
+  base = clean_path(base)
+  path, base = [path, base].map{|s|s.split("/")}
+  until path.empty? or base.empty? or path[0] != base[0]
+      path.shift
+      base.shift
+  end
+  path, base = [path, base].map{|s|s.join("/")}
+  if /(\A|\/)\.\.\// =~ base
+    File.expand_path(path)
+  else
+    base.gsub!(/[^\/]+/, '..')
+    File.join(base, path)
+  end
+end
+
+def ln_relative(src, dest)
+  parent = File.dirname(dest)
+  File.directory?(parent) or mkdir_p(parent)
+  ln_safe(relative_path_from(src, parent), dest)
+end
+
+def ln_dir_relative(src, dest)
+  parent = File.dirname(dest)
+  File.directory?(parent) or mkdir_p(parent)
+  ln_dir_safe(relative_path_from(src, parent), dest)
+end
+
+config = RbConfig::MAKEFILE_CONFIG.merge("prefix" => ".", "exec_prefix" => ".")
+config.each_value {|s| RbConfig.expand(s, config)}
 srcdir = config["srcdir"] ||= File.dirname(__FILE__)
 top_srcdir = config["top_srcdir"] ||= File.dirname(srcdir)
 extout = ARGV[0] || config["EXTOUT"]
 version = config["ruby_version"]
 arch = config["arch"]
-bindir = File.basename(config["bindir"])
-libdir = File.basename(config["libdir"])
-archdir = File.join(extout, arch)
-[bindir, libdir, archdir].each do |dir|
+bindir = config["bindir"]
+libdirname = config["libdirname"]
+libdir = config[libdirname || "libdir"]
+vendordir = config["vendordir"]
+rubylibdir = config["rubylibdir"]
+rubyarchdir = config["rubyarchdir"]
+archdir = "#{extout}/#{arch}"
+rubylibs = [vendordir, rubylibdir, rubyarchdir]
+[bindir, libdir, archdir].uniq.each do |dir|
   File.directory?(dir) or mkdir_p(dir)
 end
 
@@ -69,29 +101,16 @@ goruby_install_name = "go" + ruby_instal https://github.com/ruby/ruby/blob/trunk/tool/mkrunnable.rb#L101
 [ruby_install_name, rubyw_install_name, goruby_install_name].map do |ruby|
   ruby += exeext
   if ruby and !ruby.empty?
-    ln_safe("../#{ruby}", "#{bindir}/#{ruby}")
+    ln_relative(ruby, "#{bindir}/#{ruby}")
   end
 end
 libruby = config.values_at("LIBRUBY_A", "LIBRUBY_SO")
 libruby.concat(config["LIBRUBY_ALIASES"].split)
-libruby.each {|lib|ln_safe("../#{lib}", "#{libdir}/#{lib}")}
-if File.expand_path(extout) == extout
-  ln_dir_safe(extout, "#{libdir}/ruby")
-else
-  ln_dir_safe(File.join("..", extout), "#{libdir}/ruby")
-  cur = "#{extout}/".gsub(/(\A|\/)(?:\.\/)+/, '\1').tr_s('/', '/')
-  nil while cur.sub!(/[^\/]+\/\.\.\//, '')
-  if /(\A|\/)\.\.\// =~ cur
-    cur = nil
-  else
-    cur.gsub!(/[^\/]+/, '..')
-  end
-end
-if cur
-  ln_safe(File.join("..", cur, "rbconfig.rb"), File.join(archdir, "rbconfig.rb"))
-else
-  ln_safe(File.expand_path("rbconfig.rb"), File.join(archdir, "rbconfig.rb"))
-end
-ln_dir_safe("common", File.join(extout, version))
-ln_dir_safe(File.join("..", arch), File.join(extout, "common", arch))
-ln_dir_safe(relative_from(File.join(top_srcdir, "lib"), ".."), File.join(extout, "vendor_ruby"))
+libruby.each {|lib|ln_relative(lib, "#{libdir}/#{lib}")}
+ln_dir_relative("#{extout}/common", rubylibdir)
+rubyarchdir.sub!(rubylibdir, "#{extout}/common")
+vendordir.sub!(rubylibdir, "#{extout}/common")
+ln_dir_relative(archdir, rubyarchdir)
+vendordir.sub!(rubyarchdir, archdir)
+ln_dir_relative("#{top_srcdir}/lib", vendordir)
+ln_relative("rbconfig.rb", "#{archdir}/rbconfig.rb")

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

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