class Gym::BuildCommandGenerator

Responsible for building the fully working xcodebuild command

Public Class Methods

actions() click to toggle source
# File lib/gym/generators/build_command_generator.rb, line 48
def actions
  config = Gym.config

  actions = []
  actions << :clean if config[:clean]
  actions << :archive unless Gym.project.library? || Gym.project.framework?
  actions << :build if Gym.project.library? || Gym.project.framework?

  actions
end
archive_path() click to toggle source
# File lib/gym/generators/build_command_generator.rb, line 115
def archive_path
  Gym.cache[:archive_path] ||= Gym.config[:archive_path]
  unless Gym.cache[:archive_path]
    file_name = [Gym.config[:output_name], Time.now.strftime("%F %H.%M.%S")] # e.g. 2015-08-07 14.49.12
    Gym.cache[:archive_path] = File.join(build_path, file_name.join(" ") + ".xcarchive")
  end

  if File.extname(Gym.cache[:archive_path]) != ".xcarchive"
    Gym.cache[:archive_path] += ".xcarchive"
  end
  return Gym.cache[:archive_path]
end
build_path() click to toggle source

The path where archive will be created

# File lib/gym/generators/build_command_generator.rb, line 103
def build_path
  unless Gym.cache[:build_path]
    Gym.cache[:build_path] = Gym.config[:build_path]
    unless Gym.cache[:build_path]
      day = Time.now.strftime("%F") # e.g. 2015-08-07
      Gym.cache[:build_path] = File.expand_path("~/Library/Developer/Xcode/Archives/#{day}/")
    end
    FileUtils.mkdir_p Gym.cache[:build_path]
  end
  Gym.cache[:build_path]
end
generate() click to toggle source
# File lib/gym/generators/build_command_generator.rb, line 7
def generate
  parts = prefix
  parts << "xcodebuild"
  parts += options
  parts += actions
  parts += suffix
  parts += pipe

  parts
end
options() click to toggle source
# File lib/gym/generators/build_command_generator.rb, line 31
def options
  config = Gym.config

  options = []
  options += project_path_array
  options << "-sdk '#{config[:sdk]}'" if config[:sdk]
  options << "-toolchain '#{config[:toolchain]}'" if config[:toolchain]
  options << "-destination '#{config[:destination]}'" if config[:destination]
  options << "-xcconfig '#{config[:xcconfig]}'" if config[:xcconfig]
  options << "-archivePath #{archive_path.shellescape}"
  options << "-derivedDataPath '#{config[:derived_data_path]}'" if config[:derived_data_path]
  options << "-resultBundlePath '#{result_bundle_path}'" if config[:result_bundle]
  options << config[:xcargs] if config[:xcargs]

  options
end
pipe() click to toggle source
# File lib/gym/generators/build_command_generator.rb, line 65
def pipe
  pipe = []
  pipe << "| tee #{xcodebuild_log_path.shellescape}"
  unless Gym.config[:disable_xcpretty]
    formatter = Gym.config[:xcpretty_formatter]
    pipe << "| xcpretty"
    pipe << " --test" if Gym.config[:xcpretty_test_format]
    pipe << " --no-color" if Helper.colors_disabled?
    pipe << " --formatter " if formatter
    pipe << formatter if formatter
    report_output_junit = Gym.config[:xcpretty_report_junit]
    report_output_html = Gym.config[:xcpretty_report_html]
    report_output_json = Gym.config[:xcpretty_report_json]
    if report_output_junit
      pipe << " --report junit --output "
      pipe << report_output_junit.shellescape
    elsif report_output_html
      pipe << " --report html --output "
      pipe << report_output_html.shellescape
    elsif report_output_json
      pipe << " --report json-compilation-database --output "
      pipe << report_output_json.shellescape
    end
  end
  pipe << "> /dev/null" if Gym.config[:suppress_xcode_output]

  pipe
end
prefix() click to toggle source
# File lib/gym/generators/build_command_generator.rb, line 18
def prefix
  ["set -o pipefail &&"]
end
project_path_array() click to toggle source

Path to the project or workspace as parameter This will also include the scheme (if given) @return [Array] The array with all the components to join

# File lib/gym/generators/build_command_generator.rb, line 25
def project_path_array
  proj = Gym.project.xcodebuild_parameters
  return proj if proj.count > 0
  UI.user_error!("No project/workspace found")
end
result_bundle_path() click to toggle source
# File lib/gym/generators/build_command_generator.rb, line 128
def result_bundle_path
  unless Gym.cache[:result_bundle_path]
    Gym.cache[:result_bundle_path] = File.join(Gym.config[:output_directory], Gym.config[:output_name]) + ".result"
  end
  return Gym.cache[:result_bundle_path]
end
suffix() click to toggle source
# File lib/gym/generators/build_command_generator.rb, line 59
def suffix
  suffix = []
  suffix << "CODE_SIGN_IDENTITY=#{Gym.config[:codesigning_identity].shellescape}" if Gym.config[:codesigning_identity]
  suffix
end
xcodebuild_log_path() click to toggle source
# File lib/gym/generators/build_command_generator.rb, line 94
def xcodebuild_log_path
  file_name = "#{Gym.project.app_name}-#{Gym.config[:scheme]}.log"
  containing = File.expand_path(Gym.config[:buildlog_path])
  FileUtils.mkdir_p(containing)

  return File.join(containing, file_name)
end