cocoapods-pod-merge 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/cocoapods-pod-merge.rb +4 -0
- data/lib/cocoapods-pod-merge/Main.rb +536 -0
- data/lib/cocoapods-pod-merge/gem_version.rb +6 -0
- data/lib/cocoapods_plugin.rb +11 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 667cc13f8ce1755db714f0e9f4360a1ad1e85900738ca77a3c4a0f5309a5920a
|
4
|
+
data.tar.gz: a9ee7e74826a8f45fd4c388f155d3db527f5dc5b03d50d7da4a73c73484d3bf5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 905f29f02d42a73b4d00bb3ad6549270da9afecd558dcba8261ad81b1a819cfe0d01ac8c8ff15588e3953cf81f5a0a2a3c2b17aec2ba74fe63fc1f0cbd212fd8
|
7
|
+
data.tar.gz: a50062b650a6e11a21fe2308b995eb463e4de0ff0c6cf515676bf261ce628e7b8aa1c3fdc060007d31e54d5f113e27d74fdfc151720079445b02f7e1902909d8
|
@@ -0,0 +1,536 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2019 Grabtaxi Holdings PTE LTE (GRAB), All rights reserved.
|
4
|
+
# Use of this source code is governed by an MIT-style license that can be found in the LICENSE file
|
5
|
+
|
6
|
+
require 'cocoapods'
|
7
|
+
require 'fileutils'
|
8
|
+
require 'json'
|
9
|
+
require 'digest/md5'
|
10
|
+
|
11
|
+
CacheDirectory = 'MergeCache'
|
12
|
+
InstallationDirectory = 'MergedPods'
|
13
|
+
MergeFileName = 'MergeFile'
|
14
|
+
MergeFileSample = %(
|
15
|
+
group 'NetworkingPods' do
|
16
|
+
pod 'AFNetworking'
|
17
|
+
pod 'CocoaAsyncSocket'
|
18
|
+
end
|
19
|
+
|
20
|
+
group 'ImagePods' do
|
21
|
+
pod 'SDWebImage'
|
22
|
+
pod 'FLAnimatedImage'
|
23
|
+
end
|
24
|
+
)
|
25
|
+
PodSpecWriter_Hook = %(
|
26
|
+
post_install do |context|
|
27
|
+
FileUtils.mkdir('Podspecs')
|
28
|
+
context.aggregate_targets[0].specs.each do |spec|
|
29
|
+
podspec = File.new("Podspecs/\#{spec.name.gsub("/", "_")}.json", 'w')
|
30
|
+
podspec.puts(spec.attributes_hash.to_json)
|
31
|
+
podspec.close
|
32
|
+
end
|
33
|
+
context.aggregate_targets[0].target_definition.dependencies.each do |dependency|
|
34
|
+
if dependency.external?
|
35
|
+
if dependency.external_source.key?(:path)
|
36
|
+
path = dependency.external_source[:path]
|
37
|
+
Pod::UI.puts "Creating a copy of external source for merging: \#{dependency.name}".yellow
|
38
|
+
FileUtils.copy_entry path, "Pods/\#{dependency.name}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
)
|
44
|
+
|
45
|
+
module CocoapodsPodMerge
|
46
|
+
class PodMerger
|
47
|
+
def begin(_installer_context)
|
48
|
+
merge_groups = parse_mergefile
|
49
|
+
podfile_info = read_podfile
|
50
|
+
|
51
|
+
unless install_and_merge_required
|
52
|
+
Pod::UI.puts 'The pods are already merged according to the MergeFile, no changes required.'.yellow
|
53
|
+
add_to_gitignore
|
54
|
+
return
|
55
|
+
end
|
56
|
+
|
57
|
+
# Delete existing merged frameworks & cache
|
58
|
+
if File.directory?(InstallationDirectory)
|
59
|
+
FileUtils.rm_rf(InstallationDirectory)
|
60
|
+
end
|
61
|
+
FileUtils.rm_rf(CacheDirectory) if File.directory?(CacheDirectory)
|
62
|
+
|
63
|
+
unless File.directory?(InstallationDirectory)
|
64
|
+
FileUtils.mkdir(InstallationDirectory)
|
65
|
+
end
|
66
|
+
|
67
|
+
merge_groups.each do |group, group_contents|
|
68
|
+
merge(group, group_contents, podfile_info)
|
69
|
+
end
|
70
|
+
|
71
|
+
create_mergefile_lock
|
72
|
+
add_to_gitignore
|
73
|
+
end
|
74
|
+
|
75
|
+
def add_to_gitignore
|
76
|
+
gitignore_file = '.gitignore'
|
77
|
+
|
78
|
+
return unless File.file?(gitignore_file)
|
79
|
+
|
80
|
+
contents = File.read(gitignore_file)
|
81
|
+
cache_folder = contents.scan(/#{CacheDirectory}/)
|
82
|
+
contents += "\n#{CacheDirectory}/" unless cache_folder&.last
|
83
|
+
|
84
|
+
merged_folder = contents.scan(/#{InstallationDirectory}/)
|
85
|
+
contents += "\n#{InstallationDirectory}/" unless merged_folder&.last
|
86
|
+
|
87
|
+
File.open(gitignore_file, 'w') { |file| file.puts contents }
|
88
|
+
end
|
89
|
+
|
90
|
+
def read_podfile
|
91
|
+
unless File.file?('Podfile')
|
92
|
+
abort('You don\'t seem to have a Podfile. What\'s good a Mergefile, without a Podfile?\n\nPlease run pod init to begin.'.red)
|
93
|
+
end
|
94
|
+
|
95
|
+
sources = []
|
96
|
+
platforms = []
|
97
|
+
|
98
|
+
File.open('Podfile', 'r') do |f|
|
99
|
+
f.each_line do |line|
|
100
|
+
next if line.strip.empty?
|
101
|
+
|
102
|
+
unless line.scan(/platform :(.+),/).empty?
|
103
|
+
platforms.append(line.strip)
|
104
|
+
end
|
105
|
+
sources.append(line.strip) unless line.scan(/source '(.+)'/).empty?
|
106
|
+
end
|
107
|
+
end
|
108
|
+
PodfileInfo.new(sources, platforms)
|
109
|
+
end
|
110
|
+
|
111
|
+
def install_and_merge_required
|
112
|
+
mergefile_lock_path = "#{InstallationDirectory}/#{MergeFileName}.lock"
|
113
|
+
return true unless File.file?(mergefile_lock_path)
|
114
|
+
|
115
|
+
current_mergefile_hash = Digest::MD5.hexdigest(File.read(MergeFileName))
|
116
|
+
locked_mergefile_hash = File.read(mergefile_lock_path)
|
117
|
+
current_mergefile_hash.strip != locked_mergefile_hash.strip
|
118
|
+
end
|
119
|
+
|
120
|
+
def create_mergefile_lock
|
121
|
+
mergefile_lock_path = "#{InstallationDirectory}/#{MergeFileName}.lock"
|
122
|
+
current_mergefile_hash = Digest::MD5.hexdigest(File.read(MergeFileName))
|
123
|
+
File.open(mergefile_lock_path, 'w') { |file| file.puts current_mergefile_hash }
|
124
|
+
end
|
125
|
+
|
126
|
+
def parse_mergefile
|
127
|
+
unless File.file?(MergeFileName)
|
128
|
+
sample_mergefile = File.new(MergeFileName, 'w')
|
129
|
+
sample_mergefile.puts(MergeFileSample)
|
130
|
+
sample_mergefile.close
|
131
|
+
abort('You need a MergeFile in your current directory to use cocoapods-pod-merge. A sample one has been created for you.'.green)
|
132
|
+
end
|
133
|
+
merge_groups = {}
|
134
|
+
File.open(MergeFileName, 'r') do |f|
|
135
|
+
parsing_a_group = false
|
136
|
+
group_name = ''
|
137
|
+
f.each_line do |line|
|
138
|
+
next if line.strip.empty?
|
139
|
+
|
140
|
+
line = line.gsub(/\#.+/, '') if line.include?('#') # Remove any comments
|
141
|
+
if parsing_a_group
|
142
|
+
if line.strip == 'end'
|
143
|
+
parsing_a_group = false
|
144
|
+
elsif line.strip.include?('!')
|
145
|
+
merge_groups[group_name]['flags'][line.strip.delete('!')] = true
|
146
|
+
else
|
147
|
+
merge_groups[group_name]['lines'].append(line)
|
148
|
+
line = line.split(',').first
|
149
|
+
title = line.scan(/\'(.+)\'/)
|
150
|
+
title ||= line.scan(/\"(.+)\"/)
|
151
|
+
merge_groups[group_name]['titles'].append(title.last.first.to_s.delete(',').delete("\''").delete('"'))
|
152
|
+
end
|
153
|
+
else
|
154
|
+
unless line.scan(/\'(.+)\'/).last.empty?
|
155
|
+
group_name = line.scan(/\'(.+)\'/).last.first.to_s
|
156
|
+
|
157
|
+
if merge_groups[group_name]
|
158
|
+
abort("Duplicate Group Name: #{group_name}. Please make sure all groups have different names!".red)
|
159
|
+
end
|
160
|
+
|
161
|
+
merge_groups[group_name] = { 'titles' => [], 'lines' => [], 'flags' => {} }
|
162
|
+
parsing_a_group = true
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
merge_groups
|
168
|
+
end
|
169
|
+
|
170
|
+
def merge(merged_framework_name, group_contents, podfile_info)
|
171
|
+
Pod::UI.puts "Preparing to Merge: #{merged_framework_name}"
|
172
|
+
|
173
|
+
pods_to_merge = group_contents['titles']
|
174
|
+
flags = group_contents['flags']
|
175
|
+
public_headers_by_pod = {}
|
176
|
+
frameworks = []
|
177
|
+
prefix_header_contents = []
|
178
|
+
private_header_files = []
|
179
|
+
resources = []
|
180
|
+
script_phases = []
|
181
|
+
compiler_flags = []
|
182
|
+
libraries = []
|
183
|
+
prepare_command = []
|
184
|
+
vendored_libraries = []
|
185
|
+
resource_bundles = {}
|
186
|
+
swift_versions = {}
|
187
|
+
|
188
|
+
# Flags
|
189
|
+
has_dependencies = false
|
190
|
+
mixed_language_group = false
|
191
|
+
|
192
|
+
flags.each do |flag, _|
|
193
|
+
case flag.strip
|
194
|
+
when 'has_dependencies'
|
195
|
+
has_dependencies = true
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
# Download the Pods to be merged
|
200
|
+
Pod::UI.puts 'Downloading Pods in the group'.cyan
|
201
|
+
FileUtils.mkdir CacheDirectory unless File.directory?(CacheDirectory)
|
202
|
+
|
203
|
+
create_cache_podfile(podfile_info, group_contents['lines'])
|
204
|
+
|
205
|
+
Dir.chdir(CacheDirectory) do
|
206
|
+
system('pod install') || raise('Failed to download pods to merge')
|
207
|
+
end
|
208
|
+
|
209
|
+
# Create a directory for the merged framework
|
210
|
+
FileUtils.mkdir("#{InstallationDirectory}/#{merged_framework_name}")
|
211
|
+
FileUtils.mkdir("#{InstallationDirectory}/#{merged_framework_name}/Sources")
|
212
|
+
|
213
|
+
Pod::UI.puts 'Merging Pods'.cyan
|
214
|
+
pods_to_merge.each do |pod|
|
215
|
+
# Capture all resources to specify in the final podspec
|
216
|
+
Pod::UI.puts "\t#{pod.cyan}"
|
217
|
+
|
218
|
+
Dir.chdir("#{CacheDirectory}/Pods/#{pod}") do
|
219
|
+
# Validate the Pod
|
220
|
+
Pod::UI.puts "\t\tValidating Pod".magenta
|
221
|
+
|
222
|
+
unless Dir.glob('**/*.swift').empty? # Make sure the pod is not a Swift or Mixed Pod
|
223
|
+
mixed_language_group = true
|
224
|
+
Pod::UI.puts "\t\tExperimental: ".yellow + "The group #{merged_framework_name} consists of Swift Pods. This can lead to import pollution.".magenta
|
225
|
+
end
|
226
|
+
|
227
|
+
unless Dir.glob('**/*.a').empty? # Log an experimental warning when merging pods with static libraries inside
|
228
|
+
Pod::UI.puts "\t\tExperimental: ".yellow + "#{pod} contains static libraries inside, this can lead to errors or undefined behaviours".magenta
|
229
|
+
end
|
230
|
+
|
231
|
+
unless Dir.glob('**/*.framework').empty? # Make sure the pod does not contain a pre-compiled framework
|
232
|
+
abort('Pods with precompiled frameworks inside cannot be merged.'.red)
|
233
|
+
end
|
234
|
+
|
235
|
+
Pod::UI.puts "\t\tCollecting Public Headers".magenta
|
236
|
+
public_headers_by_pod[pod] = Dir.glob('**/*.h').map { |header| File.basename(header) }
|
237
|
+
|
238
|
+
Dir.glob('**/*.{h,m,mm,swift}').each do |source_file|
|
239
|
+
contents = File.read(source_file)
|
240
|
+
if has_dependencies
|
241
|
+
pods_to_merge.each do |pod|
|
242
|
+
modular_imports = contents.scan(%r{<#{pod}/(.+)>})
|
243
|
+
next unless modular_imports&.last
|
244
|
+
|
245
|
+
Pod::UI.puts "\t\tExperimental: ".yellow + "Found Modular Imports in #{source_file}, fixing this by converting to local #import".magenta
|
246
|
+
contents_with_imports_fixed = contents.gsub(%r{<#{pod}/(.+)>}) do |match|
|
247
|
+
match.gsub(%r{<#{pod}/(.+)>}, "\"#{Regexp.last_match(1)}\"")
|
248
|
+
end
|
249
|
+
File.open(source_file, 'w') { |file| file.puts contents_with_imports_fixed }
|
250
|
+
end
|
251
|
+
else
|
252
|
+
modular_imports = contents.scan(%r{<#{pod}/(.+)>})
|
253
|
+
next unless modular_imports&.last
|
254
|
+
|
255
|
+
Pod::UI.puts "\t\tExperimental: ".yellow + "Found Modular Imports in #{source_file}, fixing this by converting to local #import".magenta
|
256
|
+
contents_with_imports_fixed = contents.gsub(%r{<#{pod}/(.+)>}) do |match|
|
257
|
+
match.gsub(%r{<#{pod}/(.+)>}, "\"#{Regexp.last_match(1)}\"")
|
258
|
+
end
|
259
|
+
File.open(source_file, 'w') { |file| file.puts contents_with_imports_fixed }
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
# Read each pod's podspec, and collect configuration for the final merged podspec
|
265
|
+
Pod::UI.puts "\t\tExtracting Detailed Podspecs".magenta
|
266
|
+
Dir.chdir("#{CacheDirectory}/Podspecs") do
|
267
|
+
info = extract_info_from_podspec(pod, mixed_language_group)
|
268
|
+
frameworks += info.frameworks
|
269
|
+
prefix_header_contents += info.prefix_header_contents
|
270
|
+
private_header_files += info.private_header_files
|
271
|
+
resources += info.resources
|
272
|
+
script_phases += info.script_phases
|
273
|
+
compiler_flags += info.compiler_flags
|
274
|
+
libraries += info.libraries
|
275
|
+
prepare_command += info.prepare_command
|
276
|
+
vendored_libraries += info.vendored_libraries
|
277
|
+
swift_versions[pod] = info.swift_versions.map(&:to_f)
|
278
|
+
resource_bundles = resource_bundles.merge(info.resource_bundles)
|
279
|
+
end
|
280
|
+
|
281
|
+
# Copy over the Pods to be merged
|
282
|
+
Pod::UI.puts "\t\tCopying Sources".magenta
|
283
|
+
Dir.chdir("#{CacheDirectory}/Pods") do
|
284
|
+
FileUtils.copy_entry pod.to_s, "../../#{InstallationDirectory}/#{merged_framework_name}/Sources/#{pod}"
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
# Generate Module Map
|
289
|
+
Pod::UI.puts "\tGenerating module map".magenta
|
290
|
+
unless mixed_language_group
|
291
|
+
generate_module_map(merged_framework_name, public_headers_by_pod)
|
292
|
+
end
|
293
|
+
|
294
|
+
# Verify there's a common Swift language version across the group
|
295
|
+
if mixed_language_group
|
296
|
+
swift_version = swift_versions.each_value.reduce { |final_swift_version, versions| final_swift_version & versions }
|
297
|
+
unless swift_version&.first
|
298
|
+
abort("Could not find a common compatible Swift version across the pods to be merged for group #{merged_framework_name}: #{swift_versions}".red)
|
299
|
+
end
|
300
|
+
Pod::UI.puts "\tUsing Swift Version #{swift_version.first} for the group: #{merged_framework_name}".magenta
|
301
|
+
end
|
302
|
+
|
303
|
+
# Create the local podspec
|
304
|
+
Pod::UI.puts "\tCreating Podspec for the merged framework".magenta
|
305
|
+
create_podspec(merged_framework_name, pods_to_merge, PodspecInfo.new(frameworks.uniq, prefix_header_contents.uniq, private_header_files.uniq, resources.uniq, script_phases.uniq, compiler_flags.uniq, libraries.uniq, prepare_command.uniq, resource_bundles, vendored_libraries.uniq, swift_version), mixed_language_group)
|
306
|
+
|
307
|
+
Pod::UI.puts 'Cleaning up cache'.cyan
|
308
|
+
FileUtils.rm_rf(CacheDirectory)
|
309
|
+
|
310
|
+
Pod::UI.puts 'Merge Complete!'.green
|
311
|
+
end
|
312
|
+
|
313
|
+
def extract_info_from_podspec(pod, mixed_language_group)
|
314
|
+
podspec_file = File.open "#{pod}.json"
|
315
|
+
podspec = JSON.load podspec_file
|
316
|
+
|
317
|
+
frameworks = []
|
318
|
+
prefix_header_contents = []
|
319
|
+
private_header_files = []
|
320
|
+
resources = []
|
321
|
+
script_phases = []
|
322
|
+
compiler_flags = []
|
323
|
+
libraries = []
|
324
|
+
prepare_command = []
|
325
|
+
vendored_libraries = []
|
326
|
+
resource_bundles = {}
|
327
|
+
swift_versions = []
|
328
|
+
|
329
|
+
frameworks += array_wrapped(podspec['frameworks'])
|
330
|
+
compiler_flags += array_wrapped(podspec['compiler_flags'])
|
331
|
+
private_header_files += array_wrapped(podspec['private_header_files']).map { |path| "Sources/#{pod}/#{path}" }
|
332
|
+
prefix_header_contents += array_wrapped(podspec['prefix_header_contents'])
|
333
|
+
resources += array_wrapped(podspec['resource']).map { |path| "Sources/#{pod}/#{path}" }
|
334
|
+
resources += array_wrapped(podspec['resources']).map { |path| "Sources/#{pod}/#{path}" }
|
335
|
+
script_phases += array_wrapped(podspec['script_phases'])
|
336
|
+
libraries += array_wrapped(podspec['library'])
|
337
|
+
libraries += array_wrapped(podspec['libraries'])
|
338
|
+
prepare_command += array_wrapped(podspec['prepare_command'])
|
339
|
+
vendored_libraries += array_wrapped(podspec['vendored_library']).map { |path| "Sources/#{pod}/#{path}" }
|
340
|
+
vendored_libraries += array_wrapped(podspec['vendored_libraries']).map { |path| "Sources/#{pod}/#{path}" }
|
341
|
+
if mixed_language_group
|
342
|
+
swift_versions += array_wrapped(podspec['swift_version'])
|
343
|
+
swift_versions += array_wrapped(podspec['swift_versions'])
|
344
|
+
end
|
345
|
+
|
346
|
+
if podspec['resource_bundles']
|
347
|
+
resource_bundles = resource_bundles.merge(podspec['resource_bundles'])
|
348
|
+
end
|
349
|
+
|
350
|
+
if podspec['resource_bundle']
|
351
|
+
resource_bundles = resource_bundles.merge(podspec['resource_bundle'])
|
352
|
+
end
|
353
|
+
|
354
|
+
resource_bundles.each do |key, paths|
|
355
|
+
paths = paths.map { |path| "Sources/#{pod}/#{path}" }
|
356
|
+
resource_bundles[key] = paths
|
357
|
+
end
|
358
|
+
|
359
|
+
subspecs = array_wrapped(podspec['default_subspec'])
|
360
|
+
subspecs += array_wrapped(podspec['default_subspecs'])
|
361
|
+
|
362
|
+
subspecs.each do |subspec|
|
363
|
+
Pod::UI.puts "\t\tRecursively Collecting Podspecs for Subspec #{pod}/#{subspec}".magenta
|
364
|
+
info = extract_info_from_podspec("#{pod}_#{subspec}", false) # Passing false assuming subspecs will not have a different swift version from the base spec
|
365
|
+
frameworks += info.frameworks
|
366
|
+
prefix_header_contents += info.prefix_header_contents
|
367
|
+
private_header_files += info.private_header_files.map { |path| "Sources/#{pod}/#{path}" }
|
368
|
+
resources += info.resources.map { |path| "Sources/#{pod}/#{path}" }
|
369
|
+
script_phases += info.script_phases
|
370
|
+
compiler_flags += info.compiler_flags
|
371
|
+
libraries += info.libraries
|
372
|
+
prepare_command += info.prepare_command
|
373
|
+
vendored_libraries += info.vendored_libraries
|
374
|
+
if info.resource_bundles
|
375
|
+
resource_bundles = resource_bundles.merge(info.resource_bundles)
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
PodspecInfo.new(frameworks, prefix_header_contents, private_header_files, resources, script_phases, compiler_flags, libraries, prepare_command, resource_bundles, vendored_libraries, swift_versions)
|
380
|
+
end
|
381
|
+
|
382
|
+
def array_wrapped(object)
|
383
|
+
return [] unless object
|
384
|
+
|
385
|
+
return object if object.class == Array
|
386
|
+
return [object] if object.class == String || object.class == Hash
|
387
|
+
end
|
388
|
+
|
389
|
+
def create_cache_podfile(podfile_info, pods)
|
390
|
+
FileUtils.touch("#{CacheDirectory}/Podfile")
|
391
|
+
file = File.new("#{CacheDirectory}/Podfile", 'w')
|
392
|
+
file.puts("require 'json'")
|
393
|
+
podfile_info.sources.each do |source|
|
394
|
+
file.puts source
|
395
|
+
end
|
396
|
+
podfile_info.platforms.each do |platform|
|
397
|
+
file.puts platform
|
398
|
+
end
|
399
|
+
file.puts("install! 'cocoapods', :integrate_targets => false, :lock_pod_sources => false")
|
400
|
+
file.puts("target 'Dummy' do")
|
401
|
+
pods.each do |line|
|
402
|
+
file.puts line.to_s
|
403
|
+
end
|
404
|
+
rescue IOError => e
|
405
|
+
Pod::UI.puts "Error Writing Podfile for group #{pods}: #{e}".red
|
406
|
+
ensure
|
407
|
+
file.puts 'end'
|
408
|
+
file.puts PodSpecWriter_Hook
|
409
|
+
file&.close
|
410
|
+
end
|
411
|
+
|
412
|
+
def generate_module_map(merged_framework_name, public_headers)
|
413
|
+
module_map = File.new("#{InstallationDirectory}/#{merged_framework_name}/Sources/module.modulemap", 'w')
|
414
|
+
module_map.puts("framework module #{merged_framework_name} {")
|
415
|
+
public_headers.each do |pod, headers|
|
416
|
+
module_map.puts("\n\texplicit module #{pod} {")
|
417
|
+
headers.each do |header|
|
418
|
+
module_map.puts("\t\theader \"#{header}\"")
|
419
|
+
end
|
420
|
+
module_map.puts("\t}")
|
421
|
+
end
|
422
|
+
module_map.puts("\n}")
|
423
|
+
module_map.close
|
424
|
+
end
|
425
|
+
|
426
|
+
def create_podspec(merged_framework_name, pods_to_merge, podspec_info, mixed_language_group)
|
427
|
+
frameworks = podspec_info.frameworks
|
428
|
+
prefix_header_contents = podspec_info.prefix_header_contents
|
429
|
+
private_header_files = podspec_info.private_header_files
|
430
|
+
resources = podspec_info.resources
|
431
|
+
script_phases = podspec_info.script_phases
|
432
|
+
compiler_flags = podspec_info.compiler_flags
|
433
|
+
libraries = podspec_info.libraries
|
434
|
+
prepare_command = podspec_info.prepare_command
|
435
|
+
resource_bundles = podspec_info.resource_bundles
|
436
|
+
vendored_libraries = podspec_info.vendored_libraries
|
437
|
+
swift_versions = podspec_info.swift_versions
|
438
|
+
|
439
|
+
mergedPodspec = %(
|
440
|
+
Pod::Spec.new do |s|
|
441
|
+
s.name = '#{merged_framework_name}'
|
442
|
+
s.version = '1.0.0'
|
443
|
+
s.summary = 'Merged Pod generated by cocoapods pod-merge plugin'
|
444
|
+
s.description = 'Merged Framework containing the pods: #{pods_to_merge}'
|
445
|
+
s.homepage = 'https://github.com/grab/cocoapods-pod-merge'
|
446
|
+
s.license = { :type => 'MIT', :text => 'Merged Pods by cocoapods-pod-merge plugin ' }
|
447
|
+
s.author = { 'GrabTaxi Pte Ltd' => 'dummy@grabtaxi.com' }
|
448
|
+
s.source = { :git => 'https://github.com/grab/cocoapods-pod-merge', :tag => '1.0.0' }
|
449
|
+
s.ios.deployment_target = '8.0'
|
450
|
+
s.source_files = 'Sources/**/*.{h,m,mm,swift}'
|
451
|
+
)
|
452
|
+
|
453
|
+
podspec = File.new("#{InstallationDirectory}/#{merged_framework_name}/#{merged_framework_name}.podspec", 'w')
|
454
|
+
podspec.puts(mergedPodspec)
|
455
|
+
|
456
|
+
if mixed_language_group
|
457
|
+
podspec.puts("s.swift_version = #{swift_versions}")
|
458
|
+
else
|
459
|
+
podspec.puts("s.module_map = 'Sources/module.modulemap'")
|
460
|
+
end
|
461
|
+
|
462
|
+
unless resources.empty?
|
463
|
+
podspec.puts("s.resource = #{resources.to_s.delete('[').delete(']')}")
|
464
|
+
end
|
465
|
+
|
466
|
+
unless frameworks.empty?
|
467
|
+
podspec.puts("s.frameworks = #{frameworks.to_s.delete('[').delete(']')}")
|
468
|
+
end
|
469
|
+
|
470
|
+
unless prefix_header_contents.empty?
|
471
|
+
podspec.puts("s.prefix_header_contents = #{prefix_header_contents.to_s.delete('[').delete(']')}")
|
472
|
+
end
|
473
|
+
|
474
|
+
unless private_header_files.empty?
|
475
|
+
podspec.puts("s.private_header_files = #{private_header_files.to_s.delete('[').delete(']')}")
|
476
|
+
end
|
477
|
+
|
478
|
+
unless libraries.empty?
|
479
|
+
podspec.puts("s.libraries = #{libraries.to_s.delete('[').delete(']')}")
|
480
|
+
end
|
481
|
+
|
482
|
+
unless prepare_command.empty?
|
483
|
+
podspec.puts("s.prepare_command = #{prepare_command.to_s.delete('[').delete(']')}")
|
484
|
+
end
|
485
|
+
|
486
|
+
unless resource_bundles.empty?
|
487
|
+
podspec.puts("s.resource_bundles = #{resource_bundles}")
|
488
|
+
end
|
489
|
+
|
490
|
+
unless vendored_libraries.empty?
|
491
|
+
podspec.puts("s.vendored_libraries = #{vendored_libraries.to_s.delete('[').delete(']')}")
|
492
|
+
end
|
493
|
+
|
494
|
+
podspec.puts('end')
|
495
|
+
podspec.close
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
class PodspecInfo
|
500
|
+
attr_accessor :frameworks
|
501
|
+
attr_accessor :prefix_header_contents
|
502
|
+
attr_accessor :private_header_files
|
503
|
+
attr_accessor :resources
|
504
|
+
attr_accessor :script_phases
|
505
|
+
attr_accessor :compiler_flags
|
506
|
+
attr_accessor :libraries
|
507
|
+
attr_accessor :prepare_command
|
508
|
+
attr_accessor :resource_bundles
|
509
|
+
attr_accessor :vendored_libraries
|
510
|
+
attr_accessor :swift_versions
|
511
|
+
|
512
|
+
def initialize(frameworks, prefix_header_contents, private_header_files, resources, script_phases, compiler_flags, libraries, prepare_command, resource_bundles, vendored_libraries, swift_versions)
|
513
|
+
@frameworks = frameworks
|
514
|
+
@prefix_header_contents = prefix_header_contents
|
515
|
+
@private_header_files = private_header_files
|
516
|
+
@resources = resources
|
517
|
+
@script_phases = script_phases
|
518
|
+
@compiler_flags = compiler_flags
|
519
|
+
@libraries = libraries
|
520
|
+
@prepare_command = prepare_command
|
521
|
+
@resource_bundles = resource_bundles
|
522
|
+
@vendored_libraries = vendored_libraries
|
523
|
+
@swift_versions = swift_versions
|
524
|
+
end
|
525
|
+
end
|
526
|
+
|
527
|
+
class PodfileInfo
|
528
|
+
attr_accessor :sources
|
529
|
+
attr_accessor :platforms
|
530
|
+
|
531
|
+
def initialize(sources, platforms)
|
532
|
+
@sources = sources
|
533
|
+
@platforms = platforms
|
534
|
+
end
|
535
|
+
end
|
536
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# Copyright 2019 Grabtaxi Holdings PTE LTE (GRAB), All rights reserved.
|
2
|
+
# Use of this source code is governed by an MIT-style license that can be found in the LICENSE file
|
3
|
+
|
4
|
+
require 'cocoapods-pod-merge/Main'
|
5
|
+
|
6
|
+
module CocoapodsPodMerge
|
7
|
+
Pod::HooksManager.register('cocoapods-pod-merge', :pre_install) do |installer_context|
|
8
|
+
PodMerger.new.begin(installer_context)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cocoapods-pod-merge
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Siddharth Gupta
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Cocoapods plugin to merge your pods into one framework, to reduce dylib
|
42
|
+
loading time on app startup.
|
43
|
+
email:
|
44
|
+
- siddharth.gupta@grabtaxi.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- lib/cocoapods-pod-merge.rb
|
50
|
+
- lib/cocoapods-pod-merge/Main.rb
|
51
|
+
- lib/cocoapods-pod-merge/gem_version.rb
|
52
|
+
- lib/cocoapods_plugin.rb
|
53
|
+
homepage: https://github.com/grab/cocoapods-pod-merge
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
metadata: {}
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubygems_version: 3.0.3
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: Cocoapods plugin to merge your pods into one framework, to reduce dylib loading
|
76
|
+
time on app startup.
|
77
|
+
test_files: []
|