From 80aee7903d5caf22b219bb3dcd42cfc71fb65e9e Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 5 Nov 2017 05:11:04 +0000 Subject: runruby.rb: support run.gdb by --debugger option git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60661 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- tool/runruby.rb | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/tool/runruby.rb b/tool/runruby.rb index d91f6e3bf8..dc2cced1d0 100755 --- a/tool/runruby.rb +++ b/tool/runruby.rb @@ -23,7 +23,13 @@ while arg = ARGV[0] # obsolete switch do nothing when re =~ "debugger" require 'shellwords' - precommand.concat(value ? (Shellwords.shellwords(value) unless value == "no") : %w"gdb --args") + case value + when nil + debugger = :gdb + when "no" + else + debugger = Shellwords.shellwords(value) + end and precommand |= [:debugger] when re =~ "precommand" require 'shellwords' precommand.concat(Shellwords.shellwords(value)) @@ -37,19 +43,28 @@ end unless defined?(File.realpath) def File.realpath(*args) - Dir.chdir(expand_path(*args)) do - Dir.pwd + 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) end end end srcdir ||= File.realpath('..', File.dirname(__FILE__)) -archdir ||= '.' +begin + conffile = File.realpath('rbconfig.rb', archdir) +rescue Errno::ENOENT => e + abort "#$0: rbconfig.rb not found, use --archdir option" +end -abs_archdir = File.expand_path(archdir) +abs_archdir = File.dirname(conffile) +archdir ||= abs_archdir $:.unshift(abs_archdir) -config = File.read(conffile = File.join(abs_archdir, 'rbconfig.rb')) +config = File.read(conffile) config.sub!(/^(\s*)RUBY_VERSION\b.*(\sor\s*)\n.*\n/, '') config = Module.new {module_eval(config, conffile)}::RbConfig::CONFIG @@ -106,12 +121,16 @@ end ENV.update env -if ENV['RUNRUBY_USE_GDB'] == 'true' - if File.exist?('run.gdb') - precommand = %w'gdb -x run.gdb --args' - else - precommand = %w'gdb --args' +if debugger or ENV['RUNRUBY_USE_GDB'] == 'true' + if debugger == :gdb + 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' end + precommand[precommand.index(:debugger), 1] = debugger end cmd = [runner || ruby] -- cgit v1.2.3