class XCJobs::Xcodebuild

Attributes

build_dir[RW]
configuration[RW]
coverage[RW]
description[RW]
destinations[R]
formatter[RW]
hide_shell_script_environment[RW]
name[RW]
project[RW]
provisioning_profile[RW]
provisioning_profile_name[R]
provisioning_profile_uuid[R]
scheme[RW]
sdk[RW]
signing_identity[RW]
target[RW]
unsetenv_others[RW]
workspace[RW]

Public Class Methods

new(name) click to toggle source
# File lib/xcjobs/xcodebuild.rb, line 33
def initialize(name)
  $stdout.sync = $stderr.sync = true

  @name = name
  @destinations = []
  @only_testings = []
  @skip_testings = []
  @build_options = {}
  @build_settings = {}
  @unsetenv_others = false
  @description = Rake.application.last_description # nil or given from "desc"
end

Public Instance Methods

add_build_option(option, value) click to toggle source
# File lib/xcjobs/xcodebuild.rb, line 87
def add_build_option(option, value)
  @build_options[option] = value
end
add_build_setting(setting, value) click to toggle source
# File lib/xcjobs/xcodebuild.rb, line 91
def add_build_setting(setting, value)
  @build_settings[setting] = value
end
add_destination(destination) click to toggle source
# File lib/xcjobs/xcodebuild.rb, line 75
def add_destination(destination)
  @destinations << destination
end
add_only_testing(only_testing) click to toggle source
# File lib/xcjobs/xcodebuild.rb, line 79
def add_only_testing(only_testing)
  @only_testings << only_testing
end
add_skip_testing(skip_testing) click to toggle source
# File lib/xcjobs/xcodebuild.rb, line 83
def add_skip_testing(skip_testing)
  @skip_testings << skip_testing
end
after_action(&block) click to toggle source
# File lib/xcjobs/xcodebuild.rb, line 66
def after_action(&block)
  @after_action = block
end
before_action(&block) click to toggle source
# File lib/xcjobs/xcodebuild.rb, line 62
def before_action(&block)
  @before_action = block
end
coverage_enabled() click to toggle source
# File lib/xcjobs/xcodebuild.rb, line 58
def coverage_enabled
  @coverage
end
provisioning_profile=(provisioning_profile) click to toggle source
# File lib/xcjobs/xcodebuild.rb, line 70
def provisioning_profile=(provisioning_profile)
  @provisioning_profile = provisioning_profile
  @provisioning_profile_path, @provisioning_profile_uuid, @provisioning_profile_name = XCJobs::Helper.extract_provisioning_profile(provisioning_profile)
end

Private Instance Methods

options() click to toggle source
# File lib/xcjobs/xcodebuild.rb, line 142
def options
  [].tap do |opts|
    opts.concat(['-project', project]) if project
    opts.concat(['-target', target]) if target
    opts.concat(['-workspace', workspace]) if workspace
    opts.concat(['-scheme', scheme]) if scheme
    opts.concat(['-sdk', sdk]) if sdk
    opts.concat(['-configuration', configuration]) if configuration
    opts.concat(['-enableCodeCoverage', 'YES']) if coverage_enabled
    opts.concat(['-derivedDataPath', build_dir]) if build_dir
    opts.concat(['-hideShellScriptEnvironment']) if hide_shell_script_environment

    @destinations.each do |destination|
      opts.concat(['-destination', destination])
    end

    @only_testings.each do |only_testing|
      opts.concat(["-only-testing:#{only_testing}"])
    end
    @skip_testings.each do |skip_testing|
      opts.concat(["-skip-testing:#{skip_testing}"])
    end

    @build_options.each do |option, value|
      opts.concat([option, value])
    end
    @build_settings.each do |setting, value|
      opts << "#{setting}=#{value}"
    end
  end
end
run(cmd) click to toggle source
# File lib/xcjobs/xcodebuild.rb, line 97
def run(cmd)
  @before_action.call if @before_action

  if @formatter
    puts (cmd + ['|', @formatter]).join(" ")
  else
    puts cmd.join(" ")
  end

  env = { "NSUnbufferedIO" => "YES" }
  options = { unsetenv_others: unsetenv_others }

  if @formatter
    Open3.pipeline_r([env] + cmd + [options], [@formatter]) do |stdout, wait_thrs|
      output = []
      while line = stdout.gets
        puts line
        output << line
      end

      status = wait_thrs.first.value
      if status.success?
        @after_action.call(output, status) if @after_action
      else
        fail "xcodebuild failed (exited with status: #{status.exitstatus})"
      end
    end
  else
    Open3.popen2e(env, *cmd, options) do |stdin, stdout_err, wait_thr|
      output = []
      while line = stdout_err.gets
        puts line
        output << line
      end

      status = wait_thr.value
      if status.success?
        @after_action.call(output, status) if @after_action
      else
        fail "xcodebuild failed (exited with status: #{status.exitstatus})"
      end
    end
  end
end