Skip to content

Commit 87d024f

Browse files
committed
Merge branch 'custom_options' into 0.4.4
2 parents 786d0bd + 0af792f commit 87d024f

File tree

4 files changed

+71
-12
lines changed

4 files changed

+71
-12
lines changed

cocoapods-binary.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
2020

2121
spec.add_dependency "cocoapods", ">= 1.5.0", "< 2.0"
2222
spec.add_dependency "fourflusher", "~> 2.0"
23+
spec.add_dependency "xcpretty", "~> 0.3.0"
2324

2425
spec.add_development_dependency 'bundler', '~> 1.3'
2526
spec.add_development_dependency 'rake'

lib/cocoapods-binary/Main.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,32 @@ def keep_source_code_for_prebuilt_frameworks!
2424
DSL.dont_remove_source_code = true
2525
end
2626

27+
# Add custom xcodebuild option to the prebuiling aciton
28+
#
29+
# You may use this for your special demands. For example: the default archs in dSYMs
30+
# of prebuilt frameworks is 'arm64 armv7 x86_64', and no 'i386' for 32bit simulator.
31+
# It may generate a warning when building for a 32bit simulator. You may add following
32+
# to your podfile
33+
#
34+
# ` set_custom_xcodebuild_options_for_prebuilt_frameworks :simulator => "ARCHS=$(ARCHS_STANDARD)" `
35+
#
36+
# @options String or Hash
37+
#
38+
# If is a String, it will apply for device and simulator. Use it just like in the commandline.
39+
# If is a Hash, it should be like this: { :device => "XXXXX", :simulator => "XXXXX" }
40+
#
41+
def set_custom_xcodebuild_options_for_prebuilt_frameworks(options)
42+
if options.kind_of? Hash
43+
DSL.custom_build_options = [ options[:device] ] unless options[:device].nil?
44+
DSL.custom_build_options_simulator = [ options[:simulator] ] unless options[:simulator].nil?
45+
elsif options.kind_of? String
46+
DSL.custom_build_options = [options]
47+
DSL.custom_build_options_simulator = [options]
48+
else
49+
raise "Wrong type."
50+
end
51+
end
52+
2753
private
2854
class_attr_accessor :prebuild_all
2955
prebuild_all = false
@@ -33,6 +59,11 @@ def keep_source_code_for_prebuilt_frameworks!
3359

3460
class_attr_accessor :dont_remove_source_code
3561
dont_remove_source_code = false
62+
63+
class_attr_accessor :custom_build_options
64+
class_attr_accessor :custom_build_options_simulator
65+
self.custom_build_options = []
66+
self.custom_build_options_simulator = []
3667
end
3768
end
3869
end

lib/cocoapods-binary/Prebuild.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def prebuild_frameworks!
130130

131131
output_path = sandbox.framework_folder_path_for_pod_name(target.name)
132132
output_path.mkpath unless output_path.exist?
133-
Pod::Prebuild.build(sandbox_path, target, output_path, bitcode_enabled)
133+
Pod::Prebuild.build(sandbox_path, target, output_path, bitcode_enabled, Podfile::DSL.custom_build_options, Podfile::DSL.custom_build_options_simulator)
134134

135135
# save the resource paths for later installing
136136
if target.static_framework? and !target.resource_paths.empty?

lib/cocoapods-binary/rome/build_framework.rb

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'fourflusher'
2+
require 'xcpretty'
23

34
CONFIGURATION = "Release"
45
PLATFORMS = { '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]
102129
end
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

Comments
 (0)