MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / execute

Method execute

rake_tasks/bazel.rb:14–60  ·  view source on GitHub ↗
(kind, args, target, &block)

Source from the content-addressed store, hash-verified

12 end
13
14 def self.execute(kind, args, target, &block)
15 verbose = Rake::FileUtilsExt.verbose_flag
16 targets = Array(target)
17
18 if targets.one? && targets.first.end_with?(':run')
19 kind = 'run'
20 targets = [targets.first.delete_suffix(':run')]
21 end
22
23 cmd = ['bazel', kind, *targets, *args]
24 cmd_out = ''
25 cmd_exit_code = 0
26
27 puts "Executing: #{cmd.join(' ')}"
28 if windows?
29 quoted = cmd.map { |a| a.match?(/[\s"]/) ? %("#{a.gsub('"', '\\"')}") : a }
30 cmd_line = "#{quoted.join(' ')} 2>&1"
31 cmd_out = `#{cmd_line}`.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
32 puts cmd_out if verbose
33 cmd_exit_code = $CHILD_STATUS
34 else
35 Open3.popen2e(*cmd) do |stdin, stdouts, wait|
36 is_running = true
37 stdin.close
38 while is_running
39 begin
40 stdouts.wait_readable
41 line = stdouts.readpartial(512)
42 cmd_out += line
43 $stdout.print line if verbose
44 rescue EOFError
45 is_running = false
46 end
47 end
48 cmd_exit_code = wait.value.exitstatus
49 end
50 end
51
52 raise "#{cmd.join(' ')} failed with exit code: #{cmd_exit_code}\nOutput: #{cmd_out}" if cmd_exit_code != 0
53
54 block&.call(cmd_out)
55 return unless cmd_out =~ %r{\s+(bazel-bin/\S+)}
56
57 out_artifact = Regexp.last_match(1)
58 puts "#{targets.join(' ')} -> #{out_artifact}" if out_artifact
59 out_artifact
60 end
61end

Callers

nothing calls this directly

Calls 6

encodeMethod · 0.65
closeMethod · 0.65
printMethod · 0.65
callMethod · 0.65
mapMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected