summaryrefslogtreecommitdiff
path: root/tool/runruby.rb
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-05-22 11:48:42 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-05-22 11:48:42 +0000
commita654e0b57b861b7ca7d04d640eb9798c40b2fd53 (patch)
tree659055a68358882dbf54523a88525ce12d3caf8c /tool/runruby.rb
parent58949cf8f3b5df1b410bc71c57b56c1c74ed9092 (diff)
* instruby.rb: moved into tool/.
* mkconfig.rb: ditto. * rubytest.rb: ditto. * runruby.rb: ditto. * common.mk: follows the moves. * configure.in: ditto. * win32/Makefile.sub: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23542 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'tool/runruby.rb')
-rwxr-xr-xtool/runruby.rb95
1 files changed, 95 insertions, 0 deletions
diff --git a/tool/runruby.rb b/tool/runruby.rb
new file mode 100755
index 0000000..d24b748
--- /dev/null
+++ b/tool/runruby.rb
@@ -0,0 +1,95 @@
+#!./miniruby
+
+pure = true
+show = false
+precommand = []
+while arg = ARGV[0]
+ break ARGV.shift if arg == '--'
+ /\A--([-\w]+)(?:=(.*))?\z/ =~ arg or break
+ arg, value = $1, $2
+ re = Regexp.new('\A'+arg.gsub(/\w+\b/, '\&\\w*')+'\z', "i")
+ case
+ when re =~ "srcdir"
+ srcdir = value
+ when re =~ "archdir"
+ archdir = value
+ when re =~ "cpu"
+ precommand << "arch" << "-arch" << value
+ when re =~ "extout"
+ extout = value
+ when re =~ "pure"
+ pure = (value != "no")
+ when re =~ "debugger"
+ require 'shellwords'
+ precommand.concat(value ? (Shellwords.shellwords(value) unless value == "no") : %w"gdb --args")
+ when re =~ "precommand"
+ require 'shellwords'
+ precommand.concat(Shellwords.shellwords(value))
+ when re =~ "show"
+ show = true
+ else
+ break
+ end
+ ARGV.shift
+end
+
+srcdir ||= File.expand_path('..', File.dirname(__FILE__))
+archdir ||= '.'
+
+abs_archdir = File.expand_path(archdir)
+$:.unshift(abs_archdir)
+
+config = File.read(conffile = File.join(abs_archdir, 'rbconfig.rb'))
+config.sub!(/^(\s*)RUBY_VERSION\s*==.*(\sor\s*)$/, '\1true\2')
+config = Module.new {module_eval(config, conffile)}::RbConfig::CONFIG
+
+ruby = File.join(archdir, config["RUBY_INSTALL_NAME"]+config['EXEEXT'])
+unless File.exist?(ruby)
+ abort "#{ruby} is not found.\nTry `make' first, then `make test', please.\n"
+end
+
+libs = [abs_archdir]
+extout ||= config["EXTOUT"]
+if extout
+ abs_extout = File.expand_path(extout)
+ libs << File.expand_path("common", abs_extout) << File.expand_path(config['arch'], abs_extout)
+end
+libs << File.expand_path("lib", srcdir)
+config["bindir"] = abs_archdir
+
+env = {}
+
+env["RUBY"] = File.expand_path(ruby)
+env["PATH"] = [abs_archdir, ENV["PATH"]].compact.join(File::PATH_SEPARATOR)
+
+if pure
+ libs << File.expand_path("ext", srcdir) << "-"
+elsif e = ENV["RUBYLIB"]
+ libs |= e.split(File::PATH_SEPARATOR)
+end
+env["RUBYLIB"] = $:.replace(libs).join(File::PATH_SEPARATOR)
+
+libruby_so = File.join(abs_archdir, config['LIBRUBY_SO'])
+if File.file?(libruby_so)
+ if e = config['LIBPATHENV'] and !e.empty?
+ env[e] = [abs_archdir, ENV[e]].compact.join(File::PATH_SEPARATOR)
+ end
+ if /linux/ =~ RUBY_PLATFORM
+ env["LD_PRELOAD"] = [libruby_so, ENV["LD_PRELOAD"]].compact.join(' ')
+ end
+end
+
+ENV.update env
+
+cmd = [ruby]
+cmd << "-rpurelib.rb" if pure
+cmd.concat(ARGV)
+cmd.unshift(*precommand) unless precommand.empty?
+
+if show
+ require 'shellwords'
+ env.each {|k,v| puts "#{k}=#{v}"}
+ puts Shellwords.join(cmd)
+end
+
+exec(*cmd)