forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bazel.rb
60 lines (52 loc) · 1.54 KB
/
bazel.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require 'pp'
require 'open3'
require 'rake/task'
require 'rake_tasks/selenium_rake/checks'
require 'rake_tasks/bazel/task'
require 'rake_tasks/rake/dsl'
module Bazel
class << self
def execute(kind, args, target, &block)
verbose = Rake::FileUtilsExt.verbose_flag
if target.end_with?(":run")
kind = "run"
target = target[0, target.length - 4]
end
cmd = %w[bazel] + [kind, target] + (args || [])
puts cmd.join(" ")
if SeleniumRake::Checks::windows?
cmd = cmd + ["2>&1"]
cmd_line = cmd.join(" ")
cmd_out = `#{cmd_line}`
cmd_exit_code = $?.success?
else
Open3.popen2e(*cmd) do |stdin, stdouts, wait|
is_running = true
stdin.close
cmd_out = ''
while is_running
begin
pipes = IO.select([stdouts])
if pipes.empty?
is_running = false
else
line = stdouts.readpartial(512)
cmd_out << line
STDOUT.print line if verbose
end
rescue EOFError
is_running = false
end
end
cmd_exit_code = wait.value.exitstatus
end
end
puts cmd_out if verbose
raise "#{cmd.join(' ')} failed with exit code: #{cmd_exit_code}" if not cmd_exit_code
block&.call(cmd_out)
out_artifact = Regexp.last_match(1) if cmd_out =~ %r{\s+(bazel-bin/\S+)}
puts "#{target} -> #{out_artifact}" if out_artifact
out_artifact
end
end
end