module FIR::BuildIpa

Public Instance Methods

build_ipa(*args, options) click to toggle source
# File lib/fir/util/build_ipa.rb, line 6
def build_ipa(*args, options)
  initialize_build_common_options(args, options)

  @build_tmp_dir = Dir.mktmpdir
  @build_cmd     = initialize_ipa_build_cmd(args, options)

  logger_info_and_run_build_command

  output_ipa_and_dsym
  publish_build_app(options) if options.publish?
  upload_build_dsym_mapping_file if options.mapping?

  logger_info_blank_line
end

Private Instance Methods

archive_ipa(apps) click to toggle source
# File lib/fir/util/build_ipa.rb, line 65
def archive_ipa(apps)
  logger.info 'Archiving......'
  logger_info_dividing_line

  @xcrun_cmd = "xcrun -sdk iphoneos PackageApplication -v #{apps.join(' ')} -o #{@temp_ipa}"
  puts @xcrun_cmd if $DEBUG
  logger.info `#{@xcrun_cmd}`
end
check_archived_ipa_is_exist() click to toggle source
# File lib/fir/util/build_ipa.rb, line 74
def check_archived_ipa_is_exist
  unless File.exist?(@temp_ipa)
    logger.error 'Archive failed'
    exit 1
  end
end
check_ios_scheme(scheme_name) click to toggle source
# File lib/fir/util/build_ipa.rb, line 145
def check_ios_scheme(scheme_name)
  if scheme_name.blank?
    logger.error 'Must provide a scheme by `-S` option when build a workspace'
    exit 1
  end
end
check_no_output_app(apps) click to toggle source
# File lib/fir/util/build_ipa.rb, line 152
def check_no_output_app(apps)
  if apps.length == 0
    logger.error 'Builded has no output app, Can not be packaged'
    exit 1
  end
end
initialize_ipa_build_cmd(args, options) click to toggle source
# File lib/fir/util/build_ipa.rb, line 23
def initialize_ipa_build_cmd(args, options)
  @configuration = options[:configuration]
  @target_name   = options[:target]
  @scheme_name   = options[:scheme]
  @profile_name  = options[:profile]
  @destination   = options[:destination]

  build_cmd =  'xcodebuild build -sdk iphoneos'
  build_cmd += initialize_xcode_build_path(options)
  build_cmd += " -configuration '#{@configuration}'" unless @configuration.blank?
  build_cmd += " -target '#{@target_name}'" unless @target_name.blank?
  build_cmd += " -destination '#{@destination}'" unless @destination.blank?
  build_cmd += " -exportProvisioningProfile '#{@profile_name}'" unless @profile_name.blank?
  build_cmd += " #{ipa_custom_settings(args)} 2>&1"
  build_cmd
end
initialize_xcode_build_path(options) click to toggle source
# File lib/fir/util/build_ipa.rb, line 111
def initialize_xcode_build_path(options)
  if options.workspace?
    workspace = check_and_find_ios_xcworkspace(@build_dir)
    check_ios_scheme(@scheme_name)

    return " -workspace '#{workspace}' -scheme '#{@scheme_name}'"
  else
    project = check_and_find_ios_xcodeproj(@build_dir)

    return " -project '#{project}'"
  end
end
ipa_custom_settings(args) click to toggle source
# File lib/fir/util/build_ipa.rb, line 40
def ipa_custom_settings(args)
  custom_settings = split_assignment_array_to_hash(args)

  setting_str =  convert_hash_to_assignment_string(custom_settings)
  setting_str += " TARGET_BUILD_DIR='#{@build_tmp_dir}'" unless custom_settings['TARGET_BUILD_DIR']
  setting_str += " CONFIGURATION_BUILD_DIR='#{@build_tmp_dir}'" unless custom_settings['CONFIGURATION_BUILD_DIR']
  setting_str += " DWARF_DSYM_FOLDER_PATH='#{@output_path}'" unless custom_settings['DWARF_DSYM_FOLDER_PATH']
  setting_str
end
output_ipa_and_dsym() click to toggle source
# File lib/fir/util/build_ipa.rb, line 50
def output_ipa_and_dsym
  apps = Dir["#{@build_tmp_dir}/*.app"].sort_by(&:size)
  check_no_output_app(apps)

  @temp_ipa = "#{@build_tmp_dir}/#{Time.now.to_i}.ipa"
  archive_ipa(apps)

  check_archived_ipa_is_exist
  rename_ipa_and_dsym

  FileUtils.rm_rf(@build_tmp_dir) unless $DEBUG

  logger.info 'Build Success'
end
rename_ipa_and_dsym() click to toggle source
# File lib/fir/util/build_ipa.rb, line 81
def rename_ipa_and_dsym
  ipa_info  = FIR.ipa_info(@temp_ipa)
  dsym_name = "#{@output_path}/#{ipa_info[:name]}.app.dSYM"

  if @name.blank?
    @ipa_name = "#{ipa_info[:name]}-#{ipa_info[:version]}-build-#{ipa_info[:build]}"
  else
    @ipa_name = @name
  end

  @builded_app_path = "#{@output_path}/#{@ipa_name}.ipa"

  FileUtils.mv(@temp_ipa, @builded_app_path, force: true)
  if File.exist?(dsym_name)
    FileUtils.mv(dsym_name, "#{@output_path}/#{@ipa_name}.app.dSYM", force: true)
  end
end
upload_build_dsym_mapping_file() click to toggle source
# File lib/fir/util/build_ipa.rb, line 99
def upload_build_dsym_mapping_file
  logger_info_blank_line

  @app_info     = ipa_info(@builded_app_path)
  @mapping_file = Dir["#{@output_path}/#{@ipa_name}.app.dSYM/Contents/Resources/DWARF/*"].first

  mapping @mapping_file, proj:    @proj,
                         build:   @app_info[:build],
                         version: @app_info[:version],
                         token:   @token
end