cocoapods-binary-matchup 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,226 @@
1
+ require 'fourflusher'
2
+ require 'xcpretty'
3
+
4
+ CONFIGURATION = "Debug"
5
+ PLATFORMS = { 'iphonesimulator' => 'iOS',
6
+ 'appletvsimulator' => 'tvOS',
7
+ 'watchsimulator' => 'watchOS' }
8
+
9
+ # Build specific target to framework file
10
+ # @param [PodTarget] target
11
+ # a specific pod target
12
+ #
13
+ def build_for_iosish_platform(sandbox,
14
+ build_dir,
15
+ output_path,
16
+ target,
17
+ device,
18
+ simulator,
19
+ bitcode_enabled,
20
+ custom_build_options = [], # Array<String>
21
+ custom_build_options_simulator = [] # Array<String>
22
+ )
23
+
24
+ deployment_target = target.platform.deployment_target.to_s
25
+
26
+ target_label = target.label # name with platform if it's used in multiple platforms
27
+ Pod::UI.puts "Prebuilding #{target_label}..."
28
+
29
+ other_options = []
30
+ # bitcode enabled
31
+ other_options += ['BITCODE_GENERATION_MODE=bitcode'] if bitcode_enabled
32
+ # make less arch to iphone simulator for faster build
33
+ custom_build_options_simulator += ['ARCHS=x86_64', 'ONLY_ACTIVE_ARCH=NO'] if simulator == 'iphonesimulator'
34
+
35
+ is_succeed, _ = xcodebuild(sandbox, target_label, device, deployment_target, other_options + custom_build_options)
36
+ exit 1 unless is_succeed
37
+ if Pod::Podfile::DSL.simulator_build_enabled
38
+ is_succeed, _ = xcodebuild(sandbox, target_label, simulator, deployment_target, other_options + custom_build_options_simulator)
39
+ exit 1 unless is_succeed
40
+ end
41
+
42
+ # paths
43
+ target_name = target.name # equals target.label, like "AFNeworking-iOS" when AFNetworking is used in multiple platforms.
44
+ module_name = target.product_module_name
45
+ device_framework_path = "#{build_dir}/#{CONFIGURATION}-#{device}/#{target_name}/#{module_name}.framework"
46
+ device_binary = device_framework_path + "/#{module_name}"
47
+
48
+ tmp_lipoed_binary_path = "#{build_dir}/#{target_name}"
49
+ lipo_log = `lipo -create -output #{tmp_lipoed_binary_path} #{device_binary}`
50
+
51
+ if Pod::Podfile::DSL.simulator_build_enabled
52
+ simulator_framework_path = "#{build_dir}/#{CONFIGURATION}-#{simulator}/#{target_name}/#{module_name}.framework"
53
+ simulator_binary = simulator_framework_path + "/#{module_name}"
54
+ return unless File.file?(device_binary) && File.file?(simulator_binary)
55
+ else
56
+ return unless File.file?(device_binary)
57
+ end
58
+
59
+ puts lipo_log unless File.exist?(tmp_lipoed_binary_path)
60
+ FileUtils.mv tmp_lipoed_binary_path, device_binary, :force => true
61
+
62
+ # collect the swiftmodule file for various archs.
63
+ device_swiftmodule_path = device_framework_path + "/Modules/#{module_name}.swiftmodule"
64
+ if File.exist?(device_swiftmodule_path) && Pod::Podfile::DSL.simulator_build_enabled
65
+ simulator_framework_path = "#{build_dir}/#{CONFIGURATION}-#{simulator}/#{target_name}/#{module_name}.framework"
66
+ simulator_swiftmodule_path = simulator_framework_path + "/Modules/#{module_name}.swiftmodule"
67
+ FileUtils.cp_r simulator_swiftmodule_path + "/.", device_swiftmodule_path
68
+ end
69
+
70
+ # combine the generated swift headers
71
+ # (In xcode 10.2, the generated swift headers vary for each archs)
72
+ # https://github.com/leavez/cocoapods-binary/issues/58
73
+ if Pod::Podfile::DSL.simulator_build_enabled
74
+ device_generated_swift_header_path = device_framework_path + "/Headers/#{module_name}-Swift.h"
75
+ device_header = File.read(device_generated_swift_header_path)
76
+ simulator_generated_swift_header_path = simulator_framework_path + "/Headers/#{module_name}-Swift.h"
77
+ if File.exist? simulator_generated_swift_header_path
78
+
79
+ simulator_header = File.read(simulator_generated_swift_header_path)
80
+ # https://github.com/Carthage/Carthage/issues/2718#issuecomment-473870461
81
+ combined_header_content = %Q{
82
+ #if TARGET_OS_SIMULATOR // merged by cocoapods-binary
83
+
84
+ #{simulator_header}
85
+
86
+ #else // merged by cocoapods-binary
87
+
88
+ #{device_header}
89
+
90
+ #endif // merged by cocoapods-binary
91
+ }
92
+ File.write(device_generated_swift_header_path, combined_header_content.strip)
93
+ end
94
+ else
95
+ device_generated_swift_header_path = device_framework_path + "/Headers/#{module_name}-Swift.h"
96
+ if File.exist?(device_generated_swift_header_path)
97
+ device_header = File.read(device_generated_swift_header_path)
98
+ combined_header_content = %Q{
99
+ #if TARGET_OS_SIMULATOR // merged by cocoapods-binary
100
+
101
+ #else // merged by cocoapods-binary
102
+
103
+ #{device_header}
104
+
105
+ #endif // merged by cocoapods-binary
106
+ }
107
+ File.write(device_generated_swift_header_path, combined_header_content.strip)
108
+ end
109
+ end
110
+
111
+ # handle the dSYM files
112
+ # device_dsym = "#{device_framework_path}.dSYM"
113
+ # if File.exist? device_dsym
114
+ # # lipo the simulator dsym
115
+ # simulator_dsym = "#{simulator_framework_path}.dSYM"
116
+ # if File.exist? simulator_dsym
117
+ # tmp_lipoed_binary_path = "#{output_path}/#{module_name}.draft"
118
+ # lipo_log = `lipo -create -output #{tmp_lipoed_binary_path} #{device_dsym}/Contents/Resources/DWARF/#{module_name} #{simulator_dsym}/Contents/Resources/DWARF/#{module_name}`
119
+ # puts lipo_log unless File.exist?(tmp_lipoed_binary_path)
120
+ # FileUtils.mv tmp_lipoed_binary_path, "#{device_framework_path}.dSYM/Contents/Resources/DWARF/#{module_name}", :force => true
121
+ # end
122
+ # # move
123
+ # FileUtils.mv device_dsym, output_path, :force => true
124
+ # end
125
+
126
+ # output
127
+ output_path.mkpath unless output_path.exist?
128
+ FileUtils.mv device_framework_path, output_path, :force => true
129
+
130
+ end
131
+
132
+ def xcodebuild(sandbox, target, sdk='macosx', deployment_target=nil, other_options=[])
133
+ args = %W(-project #{sandbox.project_path.realdirpath} -scheme #{target} -configuration #{CONFIGURATION} -sdk #{sdk} )
134
+ platform = PLATFORMS[sdk]
135
+ args += Fourflusher::SimControl.new.destination(:oldest, platform, deployment_target) unless platform.nil?
136
+ args += other_options
137
+ log = `xcodebuild #{args.join(" ")} 2>&1`
138
+ exit_code = $?.exitstatus # Process::Status
139
+ is_succeed = (exit_code == 0)
140
+
141
+ if !is_succeed
142
+ begin
143
+ if log.include?('** BUILD FAILED **')
144
+ # use xcpretty to print build log
145
+ # 64 represent command invalid. http://www.manpagez.com/man/3/sysexits/
146
+ printer = XCPretty::Printer.new({:formatter => XCPretty::Simple, :colorize => 'auto'})
147
+ log.each_line do |line|
148
+ printer.pretty_print(line)
149
+ end
150
+ else
151
+ raise "shouldn't be handle by xcpretty"
152
+ end
153
+ rescue
154
+ puts log.red
155
+ end
156
+ end
157
+ [is_succeed, log]
158
+ end
159
+
160
+
161
+
162
+ module Pod
163
+ class Prebuild
164
+
165
+ # Build the frameworks with sandbox and targets
166
+ #
167
+ # @param [String] sandbox_root_path
168
+ # The sandbox root path where the targets project place
169
+ #
170
+ # [PodTarget] target
171
+ # The pod targets to build
172
+ #
173
+ # [Pathname] output_path
174
+ # output path for generated frameworks
175
+ #
176
+ def self.build(sandbox_root_path, target, output_path, bitcode_enabled = false, custom_build_options=[], custom_build_options_simulator=[])
177
+
178
+ return if target.nil?
179
+
180
+ sandbox_root = Pathname(sandbox_root_path)
181
+ sandbox = Pod::Sandbox.new(sandbox_root)
182
+ build_dir = self.build_dir(sandbox_root)
183
+
184
+ # -- build the framework
185
+ case target.platform.name
186
+ when :ios then build_for_iosish_platform(sandbox, build_dir, output_path, target, 'iphoneos', 'iphonesimulator', bitcode_enabled, custom_build_options, custom_build_options_simulator)
187
+ when :osx then xcodebuild(sandbox, target.label, 'macosx', nil, custom_build_options)
188
+ # when :tvos then build_for_iosish_platform(sandbox, build_dir, target, 'appletvos', 'appletvsimulator')
189
+ when :watchos then build_for_iosish_platform(sandbox, build_dir, output_path, target, 'watchos', 'watchsimulator', true, custom_build_options, custom_build_options_simulator)
190
+ else raise "Unsupported platform for '#{target.name}': '#{target.platform.name}'" end
191
+
192
+ raise Pod::Informative, 'The build directory was not found in the expected location.' unless build_dir.directory?
193
+
194
+ # # --- copy the vendored libraries and framework
195
+ # frameworks = build_dir.children.select{ |path| File.extname(path) == ".framework" }
196
+ # Pod::UI.puts "Built #{frameworks.count} #{'frameworks'.pluralize(frameworks.count)}"
197
+
198
+ # pod_target = target
199
+ # consumer = pod_target.root_spec.consumer(pod_target.platform.name)
200
+ # file_accessor = Pod::Sandbox::FileAccessor.new(sandbox.pod_dir(pod_target.pod_name), consumer)
201
+ # frameworks += file_accessor.vendored_libraries
202
+ # frameworks += file_accessor.vendored_frameworks
203
+
204
+ # frameworks.uniq!
205
+
206
+ # frameworks.each do |framework|
207
+ # FileUtils.mkdir_p destination
208
+ # FileUtils.cp_r framework, destination, :remove_destination => true
209
+ # end
210
+ # build_dir.rmtree if build_dir.directory?
211
+ end
212
+
213
+ def self.remove_build_dir(sandbox_root)
214
+ path = build_dir(sandbox_root)
215
+ path.rmtree if path.exist?
216
+ end
217
+
218
+ private
219
+
220
+ def self.build_dir(sandbox_root)
221
+ # don't know why xcode chose this folder
222
+ sandbox_root.parent + 'build'
223
+ end
224
+
225
+ end
226
+ end
@@ -0,0 +1,12 @@
1
+ # attr_accessor for class variable.
2
+ # usage:
3
+ #
4
+ # ```
5
+ # class Pod
6
+ # class_attr_accessor :is_prebuild_stage
7
+ # end
8
+ # ```
9
+ #
10
+ def class_attr_accessor(symbol)
11
+ self.class.send(:attr_accessor, symbol)
12
+ end
@@ -0,0 +1 @@
1
+ require 'cocoapods-binary-matchup/gem_version'
@@ -0,0 +1,2 @@
1
+ require 'cocoapods-binary-matchup/Main'
2
+
@@ -0,0 +1,50 @@
1
+ require 'pathname'
2
+ ROOT = Pathname.new(File.expand_path('../../', __FILE__))
3
+ $:.unshift((ROOT + 'lib').to_s)
4
+ $:.unshift((ROOT + 'spec').to_s)
5
+
6
+ require 'bundler/setup'
7
+ require 'bacon'
8
+ require 'mocha-on-bacon'
9
+ require 'pretty_bacon'
10
+ require 'pathname'
11
+ require 'cocoapods'
12
+
13
+ Mocha::Configuration.prevent(:stubbing_non_existent_method)
14
+
15
+ require 'cocoapods_plugin'
16
+
17
+ #-----------------------------------------------------------------------------#
18
+
19
+ module Pod
20
+
21
+ # Disable the wrapping so the output is deterministic in the tests.
22
+ #
23
+ UI.disable_wrap = true
24
+
25
+ # Redirects the messages to an internal store.
26
+ #
27
+ module UI
28
+ @output = ''
29
+ @warnings = ''
30
+
31
+ class << self
32
+ attr_accessor :output
33
+ attr_accessor :warnings
34
+
35
+ def puts(message = '')
36
+ @output << "#{message}\n"
37
+ end
38
+
39
+ def warn(message = '', actions = [])
40
+ @warnings << "#{message}\n"
41
+ end
42
+
43
+ def print(message)
44
+ @output << message
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ #-----------------------------------------------------------------------------#
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-binary-matchup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - leavez
@@ -92,7 +92,30 @@ email:
92
92
  executables: []
93
93
  extensions: []
94
94
  extra_rdoc_files: []
95
- files: []
95
+ files:
96
+ - ".gitignore"
97
+ - ".travis.yml"
98
+ - Gemfile
99
+ - LICENSE.txt
100
+ - README.md
101
+ - Rakefile
102
+ - cocoapods-binary-matchup-0.0.1.gem
103
+ - cocoapods-binary-matchup.gemspec
104
+ - lib/cocoapods-binary-matchup/Integration.rb
105
+ - lib/cocoapods-binary-matchup/Integration_cache.rb
106
+ - lib/cocoapods-binary-matchup/Main.rb
107
+ - lib/cocoapods-binary-matchup/Prebuild.rb
108
+ - lib/cocoapods-binary-matchup/gem_version.rb
109
+ - lib/cocoapods-binary-matchup/helper/feature_switches.rb
110
+ - lib/cocoapods-binary-matchup/helper/passer.rb
111
+ - lib/cocoapods-binary-matchup/helper/podfile_options.rb
112
+ - lib/cocoapods-binary-matchup/helper/prebuild_sandbox.rb
113
+ - lib/cocoapods-binary-matchup/helper/target_checker.rb
114
+ - lib/cocoapods-binary-matchup/rome/build_framework.rb
115
+ - lib/cocoapods-binary-matchup/tool/tool.rb
116
+ - lib/cocoapods-binary.rb
117
+ - lib/cocoapods_plugin.rb
118
+ - spec/spec_helper.rb
96
119
  homepage: https://github.com/omiapp/cocoapod_binary_matchup
97
120
  licenses:
98
121
  - MIT
@@ -115,4 +138,5 @@ rubygems_version: 3.6.9
115
138
  specification_version: 4
116
139
  summary: A CocoaPods plugin to integrate pods in form of prebuilt frameworks, not
117
140
  source code, by adding just one flag in podfile. Speed up compiling dramatically.
118
- test_files: []
141
+ test_files:
142
+ - spec/spec_helper.rb