1
1
require 'fourflusher'
2
+ require 'xcpretty'
2
3
3
4
CONFIGURATION = "Release"
4
5
PLATFORMS = { 'iphonesimulator' => 'iOS' ,
@@ -15,7 +16,10 @@ def build_for_iosish_platform(sandbox,
15
16
target ,
16
17
device ,
17
18
simulator ,
18
- bitcode_enabled )
19
+ bitcode_enabled ,
20
+ custom_build_options = [ ] , # Array<String>
21
+ custom_build_options_simulator = [ ] # Array<String>
22
+ )
19
23
20
24
deployment_target = target . platform . deployment_target . to_s
21
25
@@ -26,8 +30,11 @@ def build_for_iosish_platform(sandbox,
26
30
if bitcode_enabled
27
31
other_options += [ 'BITCODE_GENERATION_MODE=bitcode' ]
28
32
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
31
38
32
39
# paths
33
40
root_name = target . pod_name
@@ -80,10 +87,14 @@ def build_for_iosish_platform(sandbox,
80
87
device_dsym = "#{ device_framework_path } .dSYM"
81
88
if File . exist? device_dsym
82
89
# 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
87
98
FileUtils . mv device_dsym , output_path , :force => true
88
99
end
89
100
@@ -98,7 +109,23 @@ def xcodebuild(sandbox, target, sdk='macosx', deployment_target=nil, other_optio
98
109
platform = PLATFORMS [ sdk ]
99
110
args += Fourflusher ::SimControl . new . destination ( :oldest , platform , deployment_target ) unless platform . nil?
100
111
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 ]
102
129
end
103
130
104
131
@@ -117,7 +144,7 @@ class Prebuild
117
144
# [Pathname] output_path
118
145
# output path for generated frameworks
119
146
#
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 = [ ] )
121
148
122
149
return unless not target == nil
123
150
@@ -127,8 +154,8 @@ def self.build(sandbox_root_path, target, output_path, bitcode_enabled = false)
127
154
128
155
# -- build the framework
129
156
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 )
132
159
# when :tvos then build_for_iosish_platform(sandbox, build_dir, target, 'appletvos', 'appletvsimulator')
133
160
# when :watchos then build_for_iosish_platform(sandbox, build_dir, target, 'watchos', 'watchsimulator')
134
161
else raise "Unsupported platform for '#{ target . name } ': '#{ target . platform . name } '" end
0 commit comments