module FIR::BuildIpa
Public Instance Methods
build_ipa(*args, options)
click to toggle source
# File lib/fir/util/build_ipa.rb, line 7 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 80 def archive_ipa(apps) logger.info 'Archiving......' logger_info_dividing_line option_plist_path = @optionPlistPath || gen_option_plist @xcrun_cmd = "#{FIR::Config::XCODE_WRAPPER_PATH} -exportArchive" @xcrun_cmd += " -archivePath #{@xcarchive_path}" @xcrun_cmd += " -exportOptionsPlist #{option_plist_path}" @xcrun_cmd += " -exportPath #{@build_dir}/fir_build" 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 95 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 226 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 233 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
find_build_setting()
click to toggle source
Find build setting from xcode project by target and configuration
# File lib/fir/util/build_ipa.rb, line 140 def find_build_setting project = Xcodeproj::Project.open(@xc_project) # find target used_target = project.targets[0] if @target_name project.targets.each do |target| if target.name == @target_name used_target = target end end end # find configuration settings used_target.build_configurations.each do |config| if config.name == @configuration return config.build_settings end end logger.info "configuration '#{@configuration}' not found" end
gen_option_plist()
click to toggle source
# File lib/fir/util/build_ipa.rb, line 102 def gen_option_plist plist = " <plist version=\"1.0\"> <dict> <key>teamID</key> <string>#{@team_id}</string> <key>method</key> <string>#{@export_method}</string> <key>uploadSymbols</key> <true/> <key>compileBitcode</key> <false/> <key>uploadBitcode</key> <false/> </dict> </plist>" logger.info 'Generated plist file for exportOptionsPlist argument' logger.info "{" logger.info " teamID:#{@team_id}" unless @team_id.nil? logger.info " method:#{@export_method}" logger.info " uploadSymbols:true" logger.info " uploadBitcode:false" logger.info "}" begin plist_path = "#{@build_dir}/fir_build/exportOptions.plist" file = File.open(plist_path, "w") file.write(plist) plist_path rescue IOError => e raise e ensure file.close unless file.nil? end end
initialize_ipa_build_cmd(args, options)
click to toggle source
# File lib/fir/util/build_ipa.rb, line 24 def initialize_ipa_build_cmd(args, options) @configuration = options[:configuration] || 'Release' @target_name = options[:target] @scheme_name = options[:scheme] @profile_name = options[:profile] @destination = options[:destination] @export_method = options[:export_method] || 'ad-hoc' @optionPlistPath = options[:optionPlistPath] build_cmd = 'xcodebuild archive -sdk iphoneos' build_cmd += initialize_xcode_build_path(options) build_settings = find_build_setting @team_id = build_settings['DEVELOPMENT_TEAM'] provisioning_profile_id = build_settings['PROVISIONING_PROFILE'] check_ios_scheme(@scheme_name) build_cmd += " -scheme '#{@scheme_name}'" unless @scheme_name.blank? build_cmd += " -configuration '#{@configuration}'" unless @configuration.blank? # build_cmd += " -target '#{@target_name}'" unless @target_name.blank? # xcarchive name for build -exportArchive @xcarchive_name = @scheme_name.nil? ? @target_name : @scheme_name + '.xcarchive' @xcarchive_path = "#{@build_dir}/fir_build/#{@xcarchive_name}" build_cmd += " -archivePath #{@xcarchive_path}" build_cmd += " PROVISIONING_PROFILE='#{provisioning_profile_id}'" 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 194 def initialize_xcode_build_path(options) @xc_workspace = check_and_find_ios_xcworkspace(@build_dir) @xc_project = check_and_find_ios_xcodeproj(@build_dir) if options.workspace? " -workspace '#{@xc_workspace}'" else " -project '#{@xc_project}'" end end
ipa_custom_settings(args)
click to toggle source
# File lib/fir/util/build_ipa.rb, line 56 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 66 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 163 def rename_ipa_and_dsym @temp_ipa = "#{@build_dir}/fir_build/#{@scheme_name}.ipa" ipa_info = FIR.ipa_info(@temp_ipa) 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" dsym_name = " #{@output_path}/#{ipa_info[:name]}.app.dSYM" 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 182 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