Skip to content

Commit 9a02fb8

Browse files
committed
Do not capture stderr with raw_sh, only stdout
* Both can be captured in a single string with `:err => :out`.
1 parent 57e7eea commit 9a02fb8

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

tool/jt.rb

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def find_graal_javacmd_and_options
131131
options = ['--no-bootclasspath']
132132
elsif graal_home
133133
graal_home = File.expand_path(graal_home, TRUFFLERUBY_DIR)
134-
output, _ = mx('-v', '-p', graal_home, 'vm', '-version', :err => :out, capture: true)
134+
output = mx('-v', '-p', graal_home, 'vm', '-version', capture: true, :err => :out)
135135
command_line = output.lines.select { |line| line.include? '-version' }
136136
if command_line.size == 1
137137
command_line = command_line[0]
@@ -323,11 +323,11 @@ def raw_sh(*args)
323323
elsif timeout
324324
result = system_timeout(timeout, *args)
325325
elsif capture
326-
if options.delete(:out) == :err
327-
err, status = Open3.capture2e(*args)
328-
out = ""
326+
if options.delete(:err) == :out
327+
out, status = Open3.capture2e(*args)
329328
else
330-
out, err, status = Open3.capture3(*args)
329+
out = IO.popen(args) { |io| io.read }
330+
status = $?
331331
end
332332
result = status.success?
333333
else
@@ -336,7 +336,7 @@ def raw_sh(*args)
336336

337337
if result
338338
if capture
339-
[out, err]
339+
out
340340
else
341341
true
342342
end
@@ -348,7 +348,6 @@ def raw_sh(*args)
348348

349349
if capture
350350
$stderr.puts out
351-
$stderr.puts err
352351
end
353352

354353
if status && status.exitstatus
@@ -794,7 +793,7 @@ def pr_clean(*args)
794793
puts "Open PRs: #{open_prs}"
795794

796795
sh 'git', 'fetch', Remotes.bitbucket, '--prune' # ensure we have locally only existing remote branches
797-
branches, _ = sh 'git', 'branch', '--remote', '--list', capture: true
796+
branches = sh 'git', 'branch', '--remote', '--list', capture: true
798797
branches_to_delete = branches.
799798
scan(/^ *#{Remotes.bitbucket}\/(github\/pr\/(\d+))$/).
800799
reject { |_, number| open_prs.include? Integer(number) }
@@ -814,7 +813,7 @@ def pr_clean(*args)
814813
def pr_push(*args)
815814
# Fetch PRs on GitHub
816815
fetch = "+refs/pull/*/head:refs/remotes/#{Remotes.github}/pr/*"
817-
out, _err = sh 'git', 'config', '--get-all', "remote.#{Remotes.github}.fetch", capture: true
816+
out = sh 'git', 'config', '--get-all', "remote.#{Remotes.github}.fetch", capture: true
818817
sh 'git', 'config', '--add', "remote.#{Remotes.github}.fetch", fetch unless out.include? fetch
819818
sh 'git', 'fetch', Remotes.github
820819

@@ -823,7 +822,7 @@ def pr_push(*args)
823822
github_pr_branch = "#{Remotes.github}/pr/#{pr_number}"
824823
else
825824
github_pr_branch = begin
826-
out, _err = sh 'git', 'branch', '-r', '--contains', 'HEAD', capture: true
825+
out = sh 'git', 'branch', '-r', '--contains', 'HEAD', capture: true
827826
candidate = out.lines.find { |l| l.strip.start_with? "#{Remotes.github}/pr/" }
828827
candidate && candidate.strip.chomp
829828
end
@@ -868,9 +867,9 @@ def github(dir = TRUFFLERUBY_DIR)
868867
def remote_urls(dir = TRUFFLERUBY_DIR)
869868
@remote_urls ||= Hash.new
870869
@remote_urls[dir] ||= begin
871-
out, _err = raw_sh 'git', '-C', dir, 'remote', capture: true, no_print_cmd: true
870+
out = raw_sh 'git', '-C', dir, 'remote', capture: true, no_print_cmd: true
872871
out.split.map do |remote|
873-
url, _err = raw_sh 'git', '-C', dir, 'config', '--get', "remote.#{remote}.url", capture: true, no_print_cmd: true
872+
url = raw_sh 'git', '-C', dir, 'config', '--get', "remote.#{remote}.url", capture: true, no_print_cmd: true
874873
[remote, url.chomp]
875874
end
876875
end
@@ -1112,7 +1111,7 @@ def test_cexts(*args)
11121111

11131112
sh 'clang', '-c', '-emit-llvm', *openssl_cflags, 'test/truffle/cexts/xopenssl/main.c', '-o', 'test/truffle/cexts/xopenssl/main.bc'
11141113
mx 'build', '--dependencies', 'SULONG_LAUNCHER' # For mx lli
1115-
out, _ = mx('lli', "-Dpolyglot.llvm.libraries=#{openssl_lib}", 'test/truffle/cexts/xopenssl/main.bc', capture: true)
1114+
out = mx('lli', "-Dpolyglot.llvm.libraries=#{openssl_lib}", 'test/truffle/cexts/xopenssl/main.bc', capture: true)
11161115
raise out.inspect unless out == "5d41402abc4b2a76b9719d911017c592\n"
11171116

11181117
when 'minimum', 'method', 'module', 'globals', 'backtraces', 'xopenssl'
@@ -1481,8 +1480,8 @@ def metrics_alloc(*args)
14811480
samples = []
14821481
METRICS_REPS.times do
14831482
log '.', "sampling\n"
1484-
out, err = run_ruby '-J-Dtruffleruby.metrics.memory_used_on_exit=true', '-J-verbose:gc', *args, capture: true, no_print_cmd: true
1485-
samples.push memory_allocated(out+err)
1483+
out = run_ruby '-J-Dtruffleruby.metrics.memory_used_on_exit=true', '-J-verbose:gc', *args, capture: true, :err => :out, no_print_cmd: true
1484+
samples.push memory_allocated(out)
14861485
end
14871486
log "\n", nil
14881487
range = samples.max - samples.min
@@ -1568,12 +1567,12 @@ def metrics_maxrss(*args)
15681567
log '.', "sampling\n"
15691568

15701569
max_rss_in_mb = if LINUX
1571-
out, err = raw_sh('/usr/bin/time', '-v', '--', find_launcher(true), *args, capture: true, no_print_cmd: true)
1572-
err =~ /Maximum resident set size \(kbytes\): (?<max_rss_in_kb>\d+)/m
1570+
out = raw_sh('/usr/bin/time', '-v', '--', find_launcher(true), *args, capture: true, :err => :out, no_print_cmd: true)
1571+
out =~ /Maximum resident set size \(kbytes\): (?<max_rss_in_kb>\d+)/m
15731572
Integer($~[:max_rss_in_kb]) / 1024.0
15741573
elsif MAC
1575-
out, err = raw_sh('/usr/bin/time', '-l', '--', find_launcher(true), *args, capture: true, no_print_cmd: true)
1576-
err =~ /(?<max_rss_in_bytes>\d+)\s+maximum resident set size/m
1574+
out = raw_sh('/usr/bin/time', '-l', '--', find_launcher(true), *args, capture: true, :err => :out, no_print_cmd: true)
1575+
out =~ /(?<max_rss_in_bytes>\d+)\s+maximum resident set size/m
15771576
Integer($~[:max_rss_in_bytes]) / 1024.0 / 1024.0
15781577
else
15791578
raise "Can't measure RSS on this platform."
@@ -1610,9 +1609,9 @@ def metrics_native_instructions(*args)
16101609

16111610
use_json = args.delete '--json'
16121611

1613-
out, err = raw_sh('perf', 'stat', '-e', 'instructions', '--', find_launcher(true), *args, capture: true, no_print_cmd: true)
1612+
out = raw_sh('perf', 'stat', '-e', 'instructions', '--', find_launcher(true), *args, capture: true, :err => :out, no_print_cmd: true)
16141613

1615-
err =~ /(?<instruction_count>[\d,]+)\s+instructions/m
1614+
out =~ /(?<instruction_count>[\d,]+)\s+instructions/m
16161615
instruction_count = $~[:instruction_count].gsub(',', '')
16171616

16181617
log "\n", nil
@@ -1639,9 +1638,9 @@ def metrics_time(*args)
16391638
samples = METRICS_REPS.times.map do
16401639
log '.', "sampling\n"
16411640
start = Time.now
1642-
_, err = run_ruby(*args, capture: true, no_print_cmd: true, :out => :err)
1641+
out = run_ruby(*args, capture: true, no_print_cmd: true, :err => :out)
16431642
finish = Time.now
1644-
get_times(err, (finish - start) * 1000.0)
1643+
get_times(out, (finish - start) * 1000.0)
16451644
end
16461645
log "\n", nil
16471646

@@ -1780,22 +1779,19 @@ def profile(*args)
17801779
run_args = *DEFAULT_PROFILE_OPTIONS + args
17811780

17821781
begin
1783-
profile_data, err = run_ruby(env, *run_args, capture: true)
1784-
$stderr.puts(err) unless err.empty?
1782+
profile_data = run_ruby(env, *run_args, capture: true)
17851783

17861784
profile_data_file = Tempfile.new %w[truffleruby-profile .json]
17871785
profile_data_file.write(profile_data)
17881786
profile_data_file.close
17891787

1790-
flamegraph_data, err = raw_sh "#{repo}/stackcollapse-graalvm.rb", profile_data_file.path, capture: true
1791-
$stderr.puts(err) unless err.empty?
1788+
flamegraph_data = raw_sh "#{repo}/stackcollapse-graalvm.rb", profile_data_file.path, capture: true
17921789

17931790
flamegraph_data_file = Tempfile.new 'truffleruby-flamegraph-data'
17941791
flamegraph_data_file.write(flamegraph_data)
17951792
flamegraph_data_file.close
17961793

1797-
svg_data, err = raw_sh "#{repo}/flamegraph.pl", flamegraph_data_file.path, capture: true
1798-
$stderr.puts(err) unless err.empty?
1794+
svg_data = raw_sh "#{repo}/flamegraph.pl", flamegraph_data_file.path, capture: true
17991795

18001796
Dir.mkdir(PROFILES_DIR) unless Dir.exist?(PROFILES_DIR)
18011797
svg_filename = "#{PROFILES_DIR}/flamegraph_#{Time.now.strftime("%Y%m%d-%H%M%S")}.svg"
@@ -1954,7 +1950,7 @@ def check_filename_length
19541950

19551951
def check_parser
19561952
build('parser')
1957-
diff, _err = sh 'git', 'diff', 'src/main/java/org/truffleruby/parser/parser/RubyParser.java', :err => :out, capture: true
1953+
diff = sh 'git', 'diff', 'src/main/java/org/truffleruby/parser/parser/RubyParser.java', capture: true
19581954
unless diff.empty?
19591955
STDERR.puts "DIFF:"
19601956
STDERR.puts diff

0 commit comments

Comments
 (0)