SHARE
TWEET

Untitled

a guest Oct 21st, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require 'pp'
  2. require 'open3'
  3. require 'rake/task'
  4. require 'rake_tasks/selenium_rake/checks'
  5. require 'rakelib/bazel/task'
  6. require 'rakelib/rake/dsl'
  7.  
  8. module Bazel
  9.   class << self
  10.     def execute(kind, args, target, &block)
  11.       verbose = Rake::FileUtilsExt.verbose_flag
  12.  
  13.       cmd = %w[bazel] + [kind, target] + (args || [])
  14.       puts cmd.join(" ")
  15.  
  16.       if SeleniumRake::Checks::windows?
  17.         cmd = cmd + ["2>&1"]
  18.         cmd_line = cmd.join(" ")
  19.         cmd_out = `#{cmd_line}`
  20.         cmd_exit_code = $?.success?
  21.       else
  22.         Open3.popen2e(*cmd) do |stdin, stdouts, wait|
  23.           is_running = true
  24.           stdin.close
  25.           cmd_out = ''
  26.           while is_running
  27.             begin
  28.               pipes = IO.select([stdouts])
  29.               if pipes.empty?
  30.                 is_running = false
  31.               else
  32.                 line = stdouts.readpartial(512)
  33.                 cmd_out << line
  34.                 STDOUT.print line if verbose
  35.               end
  36.             rescue EOFError
  37.               is_running = false
  38.             end
  39.           end
  40.           cmd_exit_code = wait.value.exitstatus
  41.         end
  42.       end
  43.  
  44.       puts cmd_out if verbose
  45.  
  46.       raise "#{cmd.join(' ')} failed with exit code: #{cmd_exit_code}" if not cmd_exit_code
  47.  
  48.       block&.call(cmd_out)
  49.       out_artifact = Regexp.last_match(1) if cmd_out =~ %r{\s+(bazel-bin/\S+)}
  50.  
  51.       puts "#{target} -> #{out_artifact}" if out_artifact
  52.       out_artifact
  53.     end
  54.   end
  55. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top