1
- require 'open3'
1
+ require 'childprocess'
2
+ require 'java'
2
3
require 'rake-tasks/checks'
3
4
4
5
module Buck
5
6
6
7
def self . download
7
8
@@buck_bin ||= (
8
9
if File . exist? ( '.nobuckcheck' ) && present? ( 'buck' )
9
- return "buck"
10
+ return [ "buck" ]
10
11
end
11
12
12
13
version = File . open ( '.buckversion' ) . first . chomp
@@ -16,7 +17,7 @@ def self.download
16
17
out_hash = File . exist? ( out ) ? Digest ::MD5 . file ( out ) . hexdigest : nil
17
18
18
19
if cached_hash == out_hash
19
- return "python #{ out } "
20
+ return [ "python" , out ]
20
21
end
21
22
22
23
url = "https://github.com/SeleniumHQ/buck/releases/download/buck-release-#{ version } /buck.pex"
@@ -34,45 +35,53 @@ def self.download
34
35
35
36
ant . get ( 'src' => url , 'dest' => out , 'verbose' => true )
36
37
File . chmod ( 0755 , out )
37
- "python #{ out } "
38
+ [ "python" , out ]
38
39
)
39
40
end
40
41
41
42
def self . buck_cmd
42
43
@@buck_cmd ||= (
43
- lambda { |command , target , &block |
44
+ lambda { |command , args , &block |
45
+ args ||= [ ]
44
46
buck = Buck ::download
45
47
46
- cmd = "#{ buck } #{ command } #{ target } "
48
+ buck . push ( command )
49
+ buck . push ( *args )
47
50
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
52
57
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 )
56
61
end
57
- err += line
62
+ @output += b
58
63
end
59
64
60
- while line = stdout . gets
61
- output += line
65
+ def output
66
+ @ output
62
67
end
68
+ }
63
69
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
68
76
end
77
+ proc . start
78
+ proc . wait
69
79
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
72
81
raise "Buck build failed"
73
82
end
74
83
75
- block . call ( output . to_s ) if block
84
+ block . call ( proc . io . stdout . output ) if block
76
85
}
77
86
)
78
87
0 commit comments