11require 'fourflusher'
2+ require 'xcpretty'
23
34CONFIGURATION = "Release"
45PLATFORMS = { 'iphonesimulator' => 'iOS' ,
@@ -15,7 +16,10 @@ def build_for_iosish_platform(sandbox,
1516 target ,
1617 device ,
1718 simulator ,
18- bitcode_enabled )
19+ bitcode_enabled ,
20+ custom_build_options = [ ] , # Array<String>
21+ custom_build_options_simulator = [ ] # Array<String>
22+ )
1923
2024 deployment_target = target . platform . deployment_target . to_s
2125
@@ -26,8 +30,11 @@ def build_for_iosish_platform(sandbox,
2630 if bitcode_enabled
2731 other_options += [ 'BITCODE_GENERATION_MODE=bitcode' ]
2832 end
29- xcodebuild ( sandbox , target_label , device , deployment_target , other_options )
30- xcodebuild ( sandbox , target_label , simulator , deployment_target , other_options + [ 'ARCHS=x86_64' , 'ONLY_ACTIVE_ARCH=NO' ] )
33+
34+ is_succeed , _ = xcodebuild ( sandbox , target_label , device , deployment_target , other_options + custom_build_options )
35+ exit 1 unless is_succeed
36+ is_succeed , _ = xcodebuild ( sandbox , target_label , simulator , deployment_target , other_options + [ 'ARCHS=x86_64' , 'ONLY_ACTIVE_ARCH=NO' ] + custom_build_options_simulator )
37+ exit 1 unless is_succeed
3138
3239 # paths
3340 root_name = target . pod_name
@@ -80,10 +87,14 @@ def build_for_iosish_platform(sandbox,
8087 device_dsym = "#{ device_framework_path } .dSYM"
8188 if File . exist? device_dsym
8289 # lipo the simulator dsym
83- tmp_lipoed_binary_path = "#{ output_path } /#{ module_name } .draft"
84- lipo_log = `lipo -create -output #{ tmp_lipoed_binary_path } #{ device_dsym } /Contents/Resources/DWARF/#{ module_name } #{ simulator_framework_path } .dSYM/Contents/Resources/DWARF/#{ module_name } `
85- puts lipo_log unless File . exist? ( tmp_lipoed_binary_path )
86- FileUtils . mv tmp_lipoed_binary_path , "#{ device_framework_path } .dSYM/Contents/Resources/DWARF/#{ module_name } " , :force => true
90+ simulator_dsym = "#{ simulator_framework_path } .dSYM"
91+ if File . exist? simulator_dsym
92+ tmp_lipoed_binary_path = "#{ output_path } /#{ module_name } .draft"
93+ lipo_log = `lipo -create -output #{ tmp_lipoed_binary_path } #{ device_dsym } /Contents/Resources/DWARF/#{ module_name } #{ simulator_dsym } /Contents/Resources/DWARF/#{ module_name } `
94+ puts lipo_log unless File . exist? ( tmp_lipoed_binary_path )
95+ FileUtils . mv tmp_lipoed_binary_path , "#{ device_framework_path } .dSYM/Contents/Resources/DWARF/#{ module_name } " , :force => true
96+ end
97+ # move
8798 FileUtils . mv device_dsym , output_path , :force => true
8899 end
89100
@@ -98,7 +109,23 @@ def xcodebuild(sandbox, target, sdk='macosx', deployment_target=nil, other_optio
98109 platform = PLATFORMS [ sdk ]
99110 args += Fourflusher ::SimControl . new . destination ( :oldest , platform , deployment_target ) unless platform . nil?
100111 args += other_options
101- Pod ::Executable . execute_command 'xcodebuild' , args , true
112+ log = `xcodebuild #{ args . join ( " " ) } 2>&1`
113+ exit_code = $?. exitstatus # Process::Status
114+ is_succeed = ( exit_code == 0 )
115+
116+ if !is_succeed
117+ begin
118+ # 64 represent command invalid. http://www.manpagez.com/man/3/sysexits/
119+ raise "shouldn't be handle by xcpretty" if exit_code == 64
120+ printer = XCPretty ::Printer . new ( { :formatter => XCPretty ::Simple , :colorize => 'auto' } )
121+ log . each_line do |line |
122+ printer . pretty_print ( line )
123+ end
124+ rescue
125+ puts log
126+ end
127+ end
128+ [ is_succeed , log ]
102129end
103130
104131
@@ -117,7 +144,7 @@ class Prebuild
117144 # [Pathname] output_path
118145 # output path for generated frameworks
119146 #
120- def self . build ( sandbox_root_path , target , output_path , bitcode_enabled = false )
147+ def self . build ( sandbox_root_path , target , output_path , bitcode_enabled = false , custom_build_options = [ ] , custom_build_options_simulator = [ ] )
121148
122149 return unless not target == nil
123150
@@ -127,8 +154,8 @@ def self.build(sandbox_root_path, target, output_path, bitcode_enabled = false)
127154
128155 # -- build the framework
129156 case target . platform . name
130- when :ios then build_for_iosish_platform ( sandbox , build_dir , output_path , target , 'iphoneos' , 'iphonesimulator' , bitcode_enabled )
131- when :osx then xcodebuild ( sandbox , target . label )
157+ when :ios then build_for_iosish_platform ( sandbox , build_dir , output_path , target , 'iphoneos' , 'iphonesimulator' , bitcode_enabled , custom_build_options , custom_build_options_simulator )
158+ when :osx then xcodebuild ( sandbox , target . label , 'macosx' , nil , custom_build_options )
132159 # when :tvos then build_for_iosish_platform(sandbox, build_dir, target, 'appletvos', 'appletvsimulator')
133160 # when :watchos then build_for_iosish_platform(sandbox, build_dir, target, 'watchos', 'watchsimulator')
134161 else raise "Unsupported platform for '#{ target . name } ': '#{ target . platform . name } '" end
0 commit comments