Skip to content

Commit d201e37

Browse files
committed
Add childprocess to the jruby-complete jar
There were cases where using popen3 caused the build to hang. In order to avoid this, we "simply" need to bundle childprocess and use that instead.
1 parent f929a92 commit d201e37

File tree

3 files changed

+34
-25
lines changed

3 files changed

+34
-25
lines changed

rake-tasks/buck.rb

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
require 'open3'
1+
require 'childprocess'
2+
require 'java'
23
require 'rake-tasks/checks'
34

45
module Buck
56

67
def self.download
78
@@buck_bin ||= (
89
if File.exist?('.nobuckcheck') && present?('buck')
9-
return "buck"
10+
return ["buck"]
1011
end
1112

1213
version = File.open('.buckversion').first.chomp
@@ -16,7 +17,7 @@ def self.download
1617
out_hash = File.exist?(out) ? Digest::MD5.file(out).hexdigest : nil
1718

1819
if cached_hash == out_hash
19-
return "python #{out}"
20+
return ["python", out]
2021
end
2122

2223
url = "https://github.com/SeleniumHQ/buck/releases/download/buck-release-#{version}/buck.pex"
@@ -34,45 +35,53 @@ def self.download
3435

3536
ant.get('src' => url, 'dest' => out, 'verbose' => true)
3637
File.chmod(0755, out)
37-
"python #{out}"
38+
["python", out]
3839
)
3940
end
4041

4142
def self.buck_cmd
4243
@@buck_cmd ||= (
43-
lambda { |command, target, &block|
44+
lambda { |command, args, &block|
45+
args ||= []
4446
buck = Buck::download
4547

46-
cmd = "#{buck} #{command} #{target}"
48+
buck.push(command)
49+
buck.push(*args)
4750

48-
output = ''
49-
err = ''
50-
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
51-
stdin.close
51+
pump_class = Class.new(Java::java.io.OutputStream) {
52+
attr_writer :stream
53+
54+
def initialize
55+
@output = ''
56+
end
5257

53-
while line = stderr.gets
54-
if command == 'build' || command == 'publish' || command == 'test'
55-
puts line
58+
def write(b)
59+
if @stream
60+
@stream.write(b)
5661
end
57-
err += line
62+
@output += b
5863
end
5964

60-
while line = stdout.gets
61-
output += line
65+
def output
66+
@output
6267
end
68+
}
6369

64-
# In jruby, wait_thr always appears to be nil. *sigh*
65-
# if !wait_thr.value.success?
66-
# raise "Unable to execute command: " + err.to_s
67-
# end
70+
err = ''
71+
proc = ChildProcess.build(*buck)
72+
proc.io.stdout = pump_class.new()
73+
proc.io.stderr = pump_class.new()
74+
if command == 'build' || command == 'publish' || command == 'test'
75+
proc.io.stderr.stream = $stdout
6876
end
77+
proc.start
78+
proc.wait
6979

70-
# Because we can't get the exit code, hackily parse the output
71-
if err.index('FAILED') != nil
80+
if proc.exit_code != 0
7281
raise "Buck build failed"
7382
end
7483

75-
block.call(output.to_s) if block
84+
block.call(proc.io.stdout.output) if block
7685
}
7786
)
7887

third_party/jruby/VERSION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
JRuby: JRuby: jruby 1.6.0.dev @ 2011-01-04 e1fe932
2-
Bundled gems: json_pure, albacore, rspec (2.4.0), rake, ci_reporter, rubyzip
2+
Bundled gems: childprocess, json_pure, albacore, rspec (2.4.0), rake, ci_reporter, rubyzip
33

4-
How to update the jar: https://gist.github.com/733501
4+
How to update the jar: https://gist.github.com/733501

third_party/jruby/jruby-complete.jar

2.71 MB
Binary file not shown.

0 commit comments

Comments
 (0)