class Fastlane::Helper::XamarinBuildHelper

Public Class Methods

bash(command, disable_log, file_log) click to toggle source
# File lib/fastlane/plugin/incloud_xamarin_build/helper/xamarin_build_helper.rb, line 7
def self.bash(command, disable_log, file_log)
  @logger = Logging.logger['fastlane-plugin-incloud_xamarin_build']

  @logger.debug "starting bash process with command: #{command}"
  UI.message "#{command}"

  if disable_log
    if file_log
      filename = incloud_xamarin_build_#{SecureRandom.urlsafe_base64}.log"
      @logger.debug "Logging to #{filename}"
      stderr_str, exit_status = Open3.capture2("#{command} > #{filename}")
    else
      stderr_str, exit_status = Open3.capture2("#{command} > /dev/null")
    end

    if exit_status != 0
      UI.error(stderr_str)
      raise "None 0 result for #{command}: #{exit_status}"
    end
  else
    Open3.popen3(command) do |_stdin, stdout, stderr, wait_thr|
      error = []
      t1 = Thread.start do
        stdout.each { |line| UI.command_output(line) }
      end
      t2 = Thread.start do
        stderr.each { |line| error << line }
      end
      exit_status = wait_thr.value
      t1.join
      t2.join
      if exit_status != 0
        error.each { |e| @logger.error(e) }
        raise "None 0 result for #{command}: #{exit_status}"
      end
    end
  end
end