2004-02-09 11:48:55 +03:00
|
|
|
#!./miniruby
|
|
|
|
|
2016-07-03 00:01:04 +03:00
|
|
|
# Used by "make runruby", configure, and by hand to run a locally-built Ruby
|
|
|
|
# with correct environment variables and arguments.
|
|
|
|
|
2009-02-07 05:57:15 +03:00
|
|
|
show = false
|
|
|
|
precommand = []
|
2017-11-06 00:13:17 +03:00
|
|
|
srcdir = File.realpath('..', File.dirname(__FILE__))
|
2019-06-05 05:03:57 +03:00
|
|
|
case
|
|
|
|
when ENV['RUNRUBY_USE_GDB'] == 'true'
|
|
|
|
debugger = :gdb
|
|
|
|
when ENV['RUNRUBY_USE_LLDB'] == 'true'
|
|
|
|
debugger = :lldb
|
|
|
|
end
|
2004-02-09 11:48:55 +03:00
|
|
|
while arg = ARGV[0]
|
|
|
|
break ARGV.shift if arg == '--'
|
2017-11-06 00:13:17 +03:00
|
|
|
case arg
|
|
|
|
when '-C', /\A-C(.+)/m
|
|
|
|
ARGV.shift
|
|
|
|
Dir.chdir($1 || ARGV.shift)
|
|
|
|
next
|
|
|
|
end
|
2004-02-09 11:48:55 +03: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-07 06:31:04 +03:00
|
|
|
when re =~ "cpu"
|
|
|
|
precommand << "arch" << "-arch" << value
|
2004-02-09 11:48:55 +03:00
|
|
|
when re =~ "extout"
|
|
|
|
extout = value
|
2007-03-06 04:21:48 +03:00
|
|
|
when re =~ "pure"
|
2010-08-03 07:05:39 +04:00
|
|
|
# obsolete switch do nothing
|
2007-03-06 04:21:48 +03:00
|
|
|
when re =~ "debugger"
|
2009-02-07 05:57:15 +03:00
|
|
|
require 'shellwords'
|
2017-11-05 08:11:04 +03:00
|
|
|
case value
|
|
|
|
when nil
|
|
|
|
debugger = :gdb
|
2018-07-09 20:49:21 +03:00
|
|
|
when "lldb"
|
|
|
|
debugger = :lldb
|
2017-11-05 08:11:04 +03:00
|
|
|
when "no"
|
|
|
|
else
|
|
|
|
debugger = Shellwords.shellwords(value)
|
|
|
|
end and precommand |= [:debugger]
|
2009-02-07 05:57:15 +03:00
|
|
|
when re =~ "precommand"
|
|
|
|
require 'shellwords'
|
|
|
|
precommand.concat(Shellwords.shellwords(value))
|
|
|
|
when re =~ "show"
|
|
|
|
show = true
|
2017-11-06 00:13:17 +03:00
|
|
|
when re =~ "chdir"
|
|
|
|
Dir.chdir(value)
|
2004-02-09 11:48:55 +03:00
|
|
|
else
|
|
|
|
break
|
|
|
|
end
|
|
|
|
ARGV.shift
|
|
|
|
end
|
|
|
|
|
2012-06-08 11:19:38 +04:00
|
|
|
unless defined?(File.realpath)
|
|
|
|
def File.realpath(*args)
|
2017-11-05 08:11:04 +03: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 11:19:38 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-05 08:11:04 +03:00
|
|
|
begin
|
|
|
|
conffile = File.realpath('rbconfig.rb', archdir)
|
|
|
|
rescue Errno::ENOENT => e
|
2017-11-06 00:13:17 +03:00
|
|
|
# retry if !archdir and ARGV[0] and File.directory?(archdir = ARGV.shift)
|
2017-11-05 08:11:04 +03:00
|
|
|
abort "#$0: rbconfig.rb not found, use --archdir option"
|
|
|
|
end
|
2004-02-09 11:48:55 +03:00
|
|
|
|
2017-11-05 08:11:04 +03:00
|
|
|
abs_archdir = File.dirname(conffile)
|
|
|
|
archdir ||= abs_archdir
|
2005-06-23 18:56:40 +04:00
|
|
|
$:.unshift(abs_archdir)
|
|
|
|
|
2017-11-05 08:11:04 +03:00
|
|
|
config = File.read(conffile)
|
2015-06-14 04:46:22 +03:00
|
|
|
config.sub!(/^(\s*)RUBY_VERSION\b.*(\sor\s*)\n.*\n/, '')
|
2009-04-30 16:25:23 +04:00
|
|
|
config = Module.new {module_eval(config, conffile)}::RbConfig::CONFIG
|
2005-06-23 18:56:40 +04:00
|
|
|
|
2020-06-21 04:34:07 +03:00
|
|
|
install_name = config["RUBY_INSTALL_NAME"]+config['EXEEXT']
|
|
|
|
ruby = File.join(archdir, install_name)
|
2004-02-09 11:48:55 +03:00
|
|
|
unless File.exist?(ruby)
|
|
|
|
abort "#{ruby} is not found.\nTry `make' first, then `make test', please.\n"
|
|
|
|
end
|
|
|
|
|
2007-03-06 04:21:48 +03:00
|
|
|
libs = [abs_archdir]
|
2009-02-08 03:41:49 +03:00
|
|
|
extout ||= config["EXTOUT"]
|
2004-02-09 11:48:55 +03:00
|
|
|
if extout
|
2012-06-08 11:19:38 +04:00
|
|
|
abs_extout = File.expand_path(extout, abs_archdir)
|
2009-02-08 03:41:49 +03:00
|
|
|
libs << File.expand_path("common", abs_extout) << File.expand_path(config['arch'], abs_extout)
|
2004-02-09 11:48:55 +03:00
|
|
|
end
|
2007-03-06 04:21:48 +03:00
|
|
|
libs << File.expand_path("lib", srcdir)
|
2004-02-09 11:48:55 +03:00
|
|
|
config["bindir"] = abs_archdir
|
2008-12-27 18:44:51 +03:00
|
|
|
|
2017-06-08 23:58:03 +03: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 18:44:51 +03:00
|
|
|
|
2020-06-21 04:34:07 +03:00
|
|
|
runner = File.join(abs_archdir, "exe/#{install_name}")
|
2017-05-26 10:02:51 +03:00
|
|
|
runner = nil unless File.exist?(runner)
|
2017-09-10 01:08:01 +03:00
|
|
|
abs_ruby = runner || File.expand_path(ruby)
|
|
|
|
env["RUBY"] = abs_ruby
|
2017-10-21 16:17:54 +03:00
|
|
|
env["GEM_PATH"] = env["GEM_HOME"] = File.expand_path(".bundle", srcdir)
|
Fix some bundler specs (#2380)
* These seem to consistenly pass already
* Show actual command when running `make test-bundler`
Current the setup command that installs the necessary gems for testing
bundler was printed, but not the actual command that runs the tests.
That was a bit confusing.
* Borrow trick from setproctitle specs
* A title that long doesn't get set sometimes
No idea why, but the test doesn't need that the title is that long.
* Fix most gem helper spec ruby-core failures
* Fix the rest of the gem helper failures
* Fix version spec by improving the assertion
* Remove unnecessary `BUNDLE_RUBY` environment var
We can use `RUBY` when necessary, and `BUNDLE_RUBY` is not a good name
because bundler considers `BUNDLE_*` variables as settings.
* Rename `BUNDLE_GEM` to `GEM_COMMAND`
This is more descriptive I think, and also friendlier for bundler
because `BUNDLE_` env variables are interpreted by bundler as settings,
and this is not a bundler setting.
This fixes one bundler spec failure in config specs against ruby-core.
* Fix quality spec when run in core
Use the proper path helper.
* Fix dummy lib builder to never load default gems
If a dummy library is named as a default gem, when requiring the library
from its executable, the default gem would be loaded when running from
core, because in core all default gems share path with bundler, and thus
they are always in the $LOAD_PATH. We fix the issue by loading lib
relatively inside dummy lib executables.
* More exact assertions
Sometimes I have the problem that I do some "print debugging" inside
specs, and suddently the spec passes. This happens when the assertion is
too relaxed, and the things I print make it match, specially when they
are simple strings like "1.0" than can be easily be part of gem paths
that I print for debugging.
I fix this by making a more exact assertion.
* Detect the correct shebang when ENV["RUBY"] is set
* Relax assertion
So that the spec passes even if another paths containing "ext" are in
the load path. This works to fix a ruby-core issue, but it's a better
assertion in general. We just want to know that the extension path was
added.
* Use folder structure independent path helper
It should fix this spec for ruby-core.
* Fix the last failing spec on ruby-core
* Skip `bundle open <default_gem>` spec when no default gems
2019-08-20 03:46:31 +03:00
|
|
|
env["GEM_COMMAND"] = "#{abs_ruby} -rrubygems #{srcdir}/bin/gem --backtrace"
|
2017-09-15 20:42:00 +03:00
|
|
|
env["PATH"] = [File.dirname(abs_ruby), abs_archdir, ENV["PATH"]].compact.join(File::PATH_SEPARATOR)
|
2004-02-09 11:48:55 +03:00
|
|
|
|
2010-08-03 07:05:39 +04:00
|
|
|
if e = ENV["RUBYLIB"]
|
2004-02-09 11:48:55 +03:00
|
|
|
libs |= e.split(File::PATH_SEPARATOR)
|
|
|
|
end
|
2008-12-27 18:44:51 +03:00
|
|
|
env["RUBYLIB"] = $:.replace(libs).join(File::PATH_SEPARATOR)
|
2004-02-09 11:48:55 +03:00
|
|
|
|
2004-12-07 21:26:46 +03: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 18:44:51 +03:00
|
|
|
env[e] = [abs_archdir, ENV[e]].compact.join(File::PATH_SEPARATOR)
|
2004-12-07 21:26:46 +03:00
|
|
|
end
|
2017-05-26 10:02:51 +03: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 21:26:46 +03:00
|
|
|
end
|
2004-02-09 11:48:55 +03:00
|
|
|
end
|
|
|
|
|
2008-12-27 18:44:51 +03:00
|
|
|
ENV.update env
|
|
|
|
|
2019-06-05 05:03:57 +03:00
|
|
|
if debugger
|
|
|
|
case debugger
|
|
|
|
when :gdb, nil
|
2019-06-05 05:01:23 +03:00
|
|
|
debugger = %W'gdb -x #{srcdir}/.gdbinit'
|
2017-11-05 08:11:04 +03:00
|
|
|
if File.exist?(gdb = 'run.gdb') or
|
|
|
|
File.exist?(gdb = File.join(abs_archdir, 'run.gdb'))
|
|
|
|
debugger.push('-x', gdb)
|
|
|
|
end
|
|
|
|
debugger << '--args'
|
2019-06-05 05:03:57 +03:00
|
|
|
when :lldb
|
2019-06-05 05:03:19 +03:00
|
|
|
debugger = ['lldb', '-O', "command script import #{srcdir}/misc/lldb_cruby.py"]
|
|
|
|
if File.exist?(lldb = 'run.lldb') or
|
|
|
|
File.exist?(lldb = File.join(abs_archdir, 'run.lldb'))
|
|
|
|
debugger.push('-s', lldb)
|
|
|
|
end
|
|
|
|
debugger << '--'
|
2018-07-09 20:49:21 +03:00
|
|
|
end
|
|
|
|
|
2017-11-07 14:21:09 +03:00
|
|
|
if idx = precommand.index(:debugger)
|
|
|
|
precommand[idx, 1] = debugger
|
|
|
|
else
|
|
|
|
precommand.concat(debugger)
|
|
|
|
end
|
2017-10-21 12:24:59 +03:00
|
|
|
end
|
|
|
|
|
2017-05-29 09:39:42 +03:00
|
|
|
cmd = [runner || ruby]
|
2007-03-06 04:21:48 +03:00
|
|
|
cmd.concat(ARGV)
|
2009-02-07 05:57:15 +03:00
|
|
|
cmd.unshift(*precommand) unless precommand.empty?
|
2008-12-27 18:44:51 +03:00
|
|
|
|
2009-02-07 05:57:15 +03:00
|
|
|
if show
|
|
|
|
require 'shellwords'
|
|
|
|
env.each {|k,v| puts "#{k}=#{v}"}
|
|
|
|
puts Shellwords.join(cmd)
|
|
|
|
end
|
2008-12-27 18:44:51 +03:00
|
|
|
|
2017-05-29 09:39:42 +03:00
|
|
|
exec(*cmd, close_others: false)
|