Skip to content

Commit b9e2bbe

Browse files
committed
[build] fix bazel execution module
1 parent e729e16 commit b9e2bbe

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

rake_tasks/bazel.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
require 'pp'
1+
# frozen_string_literal: true
2+
3+
require 'English'
24
require 'open3'
5+
require 'Rake'
36

47
module Bazel
58
def self.execute(kind, args, target, &block)
@@ -11,27 +14,25 @@ def self.execute(kind, args, target, &block)
1114
end
1215

1316
cmd = %w[bazel] + [kind, target] + (args || [])
17+
cmd_out = ''
18+
cmd_exit_code = 0
1419

1520
if SeleniumRake::Checks.windows?
16-
cmd = cmd + ["2>&1"]
21+
cmd += ['2>&1']
1722
cmd_line = cmd.join(' ')
1823
cmd_out = `#{cmd_line}`.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
19-
cmd_exit_code = $?.success?
24+
puts cmd_out if verbose
25+
cmd_exit_code = $CHILD_STATUS
2026
else
2127
Open3.popen2e(*cmd) do |stdin, stdouts, wait|
2228
is_running = true
2329
stdin.close
24-
cmd_out = ''
2530
while is_running
2631
begin
27-
pipes = IO.select([stdouts])
28-
if pipes.empty?
29-
is_running = false
30-
else
31-
line = stdouts.readpartial(512)
32-
cmd_out << line
33-
STDOUT.print line if verbose
34-
end
32+
stdouts.wait_readable
33+
line = stdouts.readpartial(512)
34+
cmd_out += line
35+
$stdout.print line if verbose
3536
rescue EOFError
3637
is_running = false
3738
end
@@ -40,13 +41,12 @@ def self.execute(kind, args, target, &block)
4041
end
4142
end
4243

43-
puts cmd_out if verbose
44-
45-
raise "#{cmd.join(' ')} failed with exit code: #{cmd_exit_code}" unless cmd_exit_code
44+
raise "#{cmd.join(' ')} failed with exit code: #{cmd_exit_code}" if cmd_exit_code != 0
4645

4746
block&.call(cmd_out)
48-
out_artifact = Regexp.last_match(1) if cmd_out =~ %r{\s+(bazel-bin/\S+)}
47+
return unless cmd_out =~ %r{\s+(bazel-bin/\S+)}
4948

49+
out_artifact = Regexp.last_match(1)
5050
puts "#{target} -> #{out_artifact}" if out_artifact
5151
out_artifact
5252
end

0 commit comments

Comments
 (0)