2004-02-09 03:48:55 -05:00
|
|
|
#!./miniruby
|
|
|
|
|
2016-07-02 17:01:04 -04:00
|
|
|
# Used by "make runruby", configure, and by hand to run a locally-built Ruby
|
|
|
|
# with correct environment variables and arguments.
|
|
|
|
|
2009-02-06 21:57:15 -05:00
|
|
|
show = false
|
|
|
|
precommand = []
|
2017-11-05 16:13:17 -05:00
|
|
|
srcdir = File.realpath('..', File.dirname(__FILE__))
|
2004-02-09 03:48:55 -05:00
|
|
|
while arg = ARGV[0]
|
|
|
|
break ARGV.shift if arg == '--'
|
2017-11-05 16:13:17 -05:00
|
|
|
case arg
|
|
|
|
when '-C', /\A-C(.+)/m
|
|
|
|
ARGV.shift
|
|
|
|
Dir.chdir($1 || ARGV.shift)
|
|
|
|
next
|
|
|
|
end
|
2004-02-09 03:48:55 -05:00
|
|
|
/\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
|
2009-02-06 22:31:04 -05:00
|
|
|
when re =~ "cpu"
|
|
|
|
precommand << "arch" << "-arch" << value
|
2004-02-09 03:48:55 -05:00
|
|
|
when re =~ "extout"
|
|
|
|
extout = value
|
2007-03-05 20:21:48 -05:00
|
|
|
when re =~ "pure"
|
2010-08-02 23:05:39 -04:00
|
|
|
# obsolete switch do nothing
|
2007-03-05 20:21:48 -05:00
|
|
|
when re =~ "debugger"
|
2009-02-06 21:57:15 -05:00
|
|
|
require 'shellwords'
|
2017-11-05 01:11:04 -04:00
|
|
|
case value
|
|
|
|
when nil
|
|
|
|
debugger = :gdb
|
2018-07-09 13:49:21 -04:00
|
|
|
when "lldb"
|
|
|
|
debugger = :lldb
|
2017-11-05 01:11:04 -04:00
|
|
|
when "no"
|
|
|
|
else
|
|
|
|
debugger = Shellwords.shellwords(value)
|
|
|
|
end and precommand |= [:debugger]
|
2009-02-06 21:57:15 -05:00
|
|
|
when re =~ "precommand"
|
|
|
|
require 'shellwords'
|
|
|
|
precommand.concat(Shellwords.shellwords(value))
|
|
|
|
when re =~ "show"
|
|
|
|
show = true
|
2017-11-05 16:13:17 -05:00
|
|
|
when re =~ "chdir"
|
|
|
|
Dir.chdir(value)
|
2004-02-09 03:48:55 -05:00
|
|
|
else
|
|
|
|
break
|
|
|
|
end
|
|
|
|
ARGV.shift
|
|
|
|
end
|
|
|
|
|
2012-06-08 03:19:38 -04:00
|
|
|
unless defined?(File.realpath)
|
|
|
|
def File.realpath(*args)
|
2017-11-05 01:11:04 -04:00
|
|
|
path = expand_path(*args)
|
|
|
|
if File.stat(path).directory?
|
|
|
|
Dir.chdir(path) {Dir.pwd}
|
|
|
|
else
|
|
|
|
dir, base = File.split(path)
|
|
|
|
File.join(Dir.chdir(dir) {Dir.pwd}, base)
|
2012-06-08 03:19:38 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-05 01:11:04 -04:00
|
|
|
begin
|
|
|
|
conffile = File.realpath('rbconfig.rb', archdir)
|
|
|
|
rescue Errno::ENOENT => e
|
2017-11-05 16:13:17 -05:00
|
|
|
# retry if !archdir and ARGV[0] and File.directory?(archdir = ARGV.shift)
|
2017-11-05 01:11:04 -04:00
|
|
|
abort "#$0: rbconfig.rb not found, use --archdir option"
|
|
|
|
end
|
2004-02-09 03:48:55 -05:00
|
|
|
|
2017-11-05 01:11:04 -04:00
|
|
|
abs_archdir = File.dirname(conffile)
|
|
|
|
archdir ||= abs_archdir
|
2005-06-23 10:56:40 -04:00
|
|
|
$:.unshift(abs_archdir)
|
|
|
|
|
2017-11-05 01:11:04 -04:00
|
|
|
config = File.read(conffile)
|
2015-06-13 21:46:22 -04:00
|
|
|
config.sub!(/^(\s*)RUBY_VERSION\b.*(\sor\s*)\n.*\n/, '')
|
2009-04-30 08:25:23 -04:00
|
|
|
config = Module.new {module_eval(config, conffile)}::RbConfig::CONFIG
|
2005-06-23 10:56:40 -04:00
|
|
|
|
2004-02-09 03:48:55 -05:00
|
|
|
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
|
|
|
|
|
2007-03-05 20:21:48 -05:00
|
|
|
libs = [abs_archdir]
|
2009-02-07 19:41:49 -05:00
|
|
|
extout ||= config["EXTOUT"]
|
2004-02-09 03:48:55 -05:00
|
|
|
if extout
|
2012-06-08 03:19:38 -04:00
|
|
|
abs_extout = File.expand_path(extout, abs_archdir)
|
2009-02-07 19:41:49 -05:00
|
|
|
libs << File.expand_path("common", abs_extout) << File.expand_path(config['arch'], abs_extout)
|
2004-02-09 03:48:55 -05:00
|
|
|
end
|
2007-03-05 20:21:48 -05:00
|
|
|
libs << File.expand_path("lib", srcdir)
|
2004-02-09 03:48:55 -05:00
|
|
|
config["bindir"] = abs_archdir
|
2008-12-27 10:44:51 -05:00
|
|
|
|
2017-06-08 16:58:03 -04:00
|
|
|
env = {
|
|
|
|
# Test with the smallest possible machine stack sizes.
|
|
|
|
# These values are clamped to machine-dependent minimum values in vm_core.h
|
|
|
|
'RUBY_THREAD_MACHINE_STACK_SIZE' => '1',
|
|
|
|
'RUBY_FIBER_MACHINE_STACK_SIZE' => '1',
|
|
|
|
}
|
2008-12-27 10:44:51 -05:00
|
|
|
|
2017-09-17 00:14:51 -04:00
|
|
|
runner = File.join(abs_archdir, "exe/ruby#{config['EXEEXT']}")
|
2017-05-26 03:02:51 -04:00
|
|
|
runner = nil unless File.exist?(runner)
|
2017-09-09 18:08:01 -04:00
|
|
|
abs_ruby = runner || File.expand_path(ruby)
|
|
|
|
env["RUBY"] = abs_ruby
|
2017-10-21 09:17:54 -04:00
|
|
|
env["GEM_PATH"] = env["GEM_HOME"] = File.expand_path(".bundle", srcdir)
|
2017-09-09 18:08:01 -04:00
|
|
|
env["BUNDLE_RUBY"] = abs_ruby
|
|
|
|
env["BUNDLE_GEM"] = "#{abs_ruby} -rrubygems #{srcdir}/bin/gem --backtrace"
|
2017-09-15 13:42:00 -04:00
|
|
|
env["PATH"] = [File.dirname(abs_ruby), abs_archdir, ENV["PATH"]].compact.join(File::PATH_SEPARATOR)
|
2004-02-09 03:48:55 -05:00
|
|
|
|
2010-08-02 23:05:39 -04:00
|
|
|
if e = ENV["RUBYLIB"]
|
2004-02-09 03:48:55 -05:00
|
|
|
libs |= e.split(File::PATH_SEPARATOR)
|
|
|
|
end
|
2008-12-27 10:44:51 -05:00
|
|
|
env["RUBYLIB"] = $:.replace(libs).join(File::PATH_SEPARATOR)
|
2004-02-09 03:48:55 -05:00
|
|
|
|
2004-12-07 13:26:46 -05:00
|
|
|
libruby_so = File.join(abs_archdir, config['LIBRUBY_SO'])
|
|
|
|
if File.file?(libruby_so)
|
|
|
|
if e = config['LIBPATHENV'] and !e.empty?
|
2008-12-27 10:44:51 -05:00
|
|
|
env[e] = [abs_archdir, ENV[e]].compact.join(File::PATH_SEPARATOR)
|
2004-12-07 13:26:46 -05:00
|
|
|
end
|
2017-05-26 03:02:51 -04:00
|
|
|
unless runner
|
|
|
|
if e = config['PRELOADENV']
|
|
|
|
e = nil if e.empty?
|
|
|
|
e ||= "LD_PRELOAD" if /linux/ =~ RUBY_PLATFORM
|
|
|
|
end
|
|
|
|
if e
|
|
|
|
env[e] = [libruby_so, ENV[e]].compact.join(File::PATH_SEPARATOR)
|
|
|
|
end
|
2004-12-07 13:26:46 -05:00
|
|
|
end
|
2004-02-09 03:48:55 -05:00
|
|
|
end
|
|
|
|
|
2008-12-27 10:44:51 -05:00
|
|
|
ENV.update env
|
|
|
|
|
2017-11-05 01:11:04 -04:00
|
|
|
if debugger or ENV['RUNRUBY_USE_GDB'] == 'true'
|
2017-11-07 06:21:09 -05:00
|
|
|
if debugger == :gdb or !debugger
|
2017-11-05 01:11:04 -04:00
|
|
|
debugger = %w'gdb'
|
|
|
|
if File.exist?(gdb = 'run.gdb') or
|
|
|
|
File.exist?(gdb = File.join(abs_archdir, 'run.gdb'))
|
|
|
|
debugger.push('-x', gdb)
|
|
|
|
end
|
|
|
|
debugger << '--args'
|
2017-10-21 05:24:59 -04:00
|
|
|
end
|
2018-07-09 13:49:21 -04:00
|
|
|
if debugger == :lldb
|
|
|
|
debugger = %w'lldb --'
|
|
|
|
end
|
|
|
|
|
2017-11-07 06:21:09 -05:00
|
|
|
if idx = precommand.index(:debugger)
|
|
|
|
precommand[idx, 1] = debugger
|
|
|
|
else
|
|
|
|
precommand.concat(debugger)
|
|
|
|
end
|
2017-10-21 05:24:59 -04:00
|
|
|
end
|
|
|
|
|
2017-05-29 02:39:42 -04:00
|
|
|
cmd = [runner || ruby]
|
2007-03-05 20:21:48 -05:00
|
|
|
cmd.concat(ARGV)
|
2009-02-06 21:57:15 -05:00
|
|
|
cmd.unshift(*precommand) unless precommand.empty?
|
2008-12-27 10:44:51 -05:00
|
|
|
|
2009-02-06 21:57:15 -05:00
|
|
|
if show
|
|
|
|
require 'shellwords'
|
|
|
|
env.each {|k,v| puts "#{k}=#{v}"}
|
|
|
|
puts Shellwords.join(cmd)
|
|
|
|
end
|
2008-12-27 10:44:51 -05:00
|
|
|
|
2017-05-29 02:39:42 -04:00
|
|
|
exec(*cmd, close_others: false)
|