1
1
#!/usr/bin/env ruby
2
2
require 'logger'
3
3
require 'open3'
4
+ require 'shellwords'
4
5
require 'tempfile'
5
6
require 'timeout'
6
7
7
8
RUBY = ARGV [ 0 ] || raise ( "Usage: ruby jit_bisect.rb <path_to_ruby> <options>" )
8
- OPTIONS = ARGV [ 1 ] || raise ( "Usage: ruby jit_bisect.rb <path_to_ruby> <options>" )
9
+ OPTIONS = ARGV [ 1 ..]
10
+ raise ( "Usage: ruby jit_bisect.rb <path_to_ruby> -- <options>" ) if OPTIONS . empty?
9
11
TIMEOUT_SEC = 5
10
12
LOGGER = Logger . new ( $stdout)
11
13
@@ -65,7 +67,8 @@ def run_with_jit_list(ruby, options, jit_list)
65
67
temp_file . flush
66
68
temp_file . close
67
69
# Run the JIT with the temporary file
68
- Open3 . capture3 ( "#{ ruby } --zjit-allowed-iseqs=#{ temp_file . path } #{ options } " )
70
+ command = Shellwords . join [ ruby , "--zjit-allowed-iseqs=#{ temp_file . path } " , *options ]
71
+ Open3 . capture3 ( command )
69
72
end
70
73
end
71
74
@@ -77,7 +80,8 @@ def run_with_jit_list(ruby, options, jit_list)
77
80
# Collect the JIT list from the failing Ruby process
78
81
jit_list = nil
79
82
Tempfile . create "jit_list" do |temp_file |
80
- Open3 . capture3 ( "#{ RUBY } --zjit-log-compiled-iseqs=#{ temp_file . path } #{ OPTIONS } " )
83
+ command = Shellwords . join [ RUBY , "--zjit-log-compiled-iseqs=#{ temp_file . path } " , *OPTIONS ]
84
+ Open3 . capture3 ( command )
81
85
jit_list = File . readlines ( temp_file . path ) . map ( &:strip ) . reject ( &:empty? )
82
86
end
83
87
LOGGER . info ( "Starting with JIT list of #{ jit_list . length } items." )
@@ -94,6 +98,7 @@ def run_with_jit_list(ruby, options, jit_list)
94
98
file . puts ( result )
95
99
end
96
100
puts "Run:"
97
- puts "#{ RUBY } --zjit-allowed-iseqs=jitlist.txt #{ OPTIONS } "
101
+ command = Shellwords . join [ RUBY , "--zjit-allowed-iseqs=jitlist.txt" , *OPTIONS ]
102
+ puts command
98
103
puts "Reduced JIT list (available in jitlist.txt):"
99
104
puts result
0 commit comments