cocoapods-meitu-bin 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +20 -0
  3. data/README.md +56 -0
  4. data/lib/cocoapods-meitu-bin/command/bin/archive.rb +206 -0
  5. data/lib/cocoapods-meitu-bin/command/bin/auto.rb +212 -0
  6. data/lib/cocoapods-meitu-bin/command/bin/build_all.rb +345 -0
  7. data/lib/cocoapods-meitu-bin/command/bin/header_files_specifications.rb +262 -0
  8. data/lib/cocoapods-meitu-bin/command/bin/init.rb +72 -0
  9. data/lib/cocoapods-meitu-bin/command/bin/install.rb +44 -0
  10. data/lib/cocoapods-meitu-bin/command/bin/lib/lint.rb +67 -0
  11. data/lib/cocoapods-meitu-bin/command/bin/lock/dependency.rb +89 -0
  12. data/lib/cocoapods-meitu-bin/command/bin/lock/spec_repo.rb +105 -0
  13. data/lib/cocoapods-meitu-bin/command/bin/lock/version.rb +68 -0
  14. data/lib/cocoapods-meitu-bin/command/bin/lock.rb +36 -0
  15. data/lib/cocoapods-meitu-bin/command/bin/output_source.rb +146 -0
  16. data/lib/cocoapods-meitu-bin/command/bin/repo/push.rb +88 -0
  17. data/lib/cocoapods-meitu-bin/command/bin/repo/update.rb +42 -0
  18. data/lib/cocoapods-meitu-bin/command/bin/repo.rb +14 -0
  19. data/lib/cocoapods-meitu-bin/command/bin/source/add.rb +148 -0
  20. data/lib/cocoapods-meitu-bin/command/bin/source/delete.rb +59 -0
  21. data/lib/cocoapods-meitu-bin/command/bin/source/list.rb +46 -0
  22. data/lib/cocoapods-meitu-bin/command/bin/source.rb +30 -0
  23. data/lib/cocoapods-meitu-bin/command/bin/spec/create.rb +73 -0
  24. data/lib/cocoapods-meitu-bin/command/bin/spec/lint.rb +109 -0
  25. data/lib/cocoapods-meitu-bin/command/bin/spec.rb +13 -0
  26. data/lib/cocoapods-meitu-bin/command/bin/update.rb +154 -0
  27. data/lib/cocoapods-meitu-bin/command/bin/upload.rb +175 -0
  28. data/lib/cocoapods-meitu-bin/command/bin.rb +69 -0
  29. data/lib/cocoapods-meitu-bin/command.rb +1 -0
  30. data/lib/cocoapods-meitu-bin/config/config.rb +149 -0
  31. data/lib/cocoapods-meitu-bin/config/config_asker.rb +57 -0
  32. data/lib/cocoapods-meitu-bin/config/config_builder.rb +216 -0
  33. data/lib/cocoapods-meitu-bin/gem_version.rb +9 -0
  34. data/lib/cocoapods-meitu-bin/helpers/Info.plist +0 -0
  35. data/lib/cocoapods-meitu-bin/helpers/buildAll/bin_helper.rb +97 -0
  36. data/lib/cocoapods-meitu-bin/helpers/buildAll/builder.rb +434 -0
  37. data/lib/cocoapods-meitu-bin/helpers/buildAll/podspec_util.rb +140 -0
  38. data/lib/cocoapods-meitu-bin/helpers/buildAll/zip_file_helper.rb +87 -0
  39. data/lib/cocoapods-meitu-bin/helpers/build_helper.rb +167 -0
  40. data/lib/cocoapods-meitu-bin/helpers/build_utils.rb +64 -0
  41. data/lib/cocoapods-meitu-bin/helpers/framework.rb +86 -0
  42. data/lib/cocoapods-meitu-bin/helpers/framework_builder.rb +551 -0
  43. data/lib/cocoapods-meitu-bin/helpers/library.rb +54 -0
  44. data/lib/cocoapods-meitu-bin/helpers/library_builder.rb +90 -0
  45. data/lib/cocoapods-meitu-bin/helpers/pod_size_helper.rb +54 -0
  46. data/lib/cocoapods-meitu-bin/helpers/sources_helper.rb +35 -0
  47. data/lib/cocoapods-meitu-bin/helpers/spec_creator.rb +170 -0
  48. data/lib/cocoapods-meitu-bin/helpers/spec_files_helper.rb +80 -0
  49. data/lib/cocoapods-meitu-bin/helpers/spec_source_creator.rb +304 -0
  50. data/lib/cocoapods-meitu-bin/helpers/upload_helper.rb +104 -0
  51. data/lib/cocoapods-meitu-bin/helpers.rb +5 -0
  52. data/lib/cocoapods-meitu-bin/native/acknowledgements.rb +27 -0
  53. data/lib/cocoapods-meitu-bin/native/analyzer.rb +109 -0
  54. data/lib/cocoapods-meitu-bin/native/file_accessor.rb +28 -0
  55. data/lib/cocoapods-meitu-bin/native/gen.rb +79 -0
  56. data/lib/cocoapods-meitu-bin/native/installation_options.rb +28 -0
  57. data/lib/cocoapods-meitu-bin/native/installer.rb +259 -0
  58. data/lib/cocoapods-meitu-bin/native/linter.rb +26 -0
  59. data/lib/cocoapods-meitu-bin/native/lockfile.rb +85 -0
  60. data/lib/cocoapods-meitu-bin/native/path_source.rb +33 -0
  61. data/lib/cocoapods-meitu-bin/native/pod_source_installer.rb +19 -0
  62. data/lib/cocoapods-meitu-bin/native/pod_target_installer.rb +87 -0
  63. data/lib/cocoapods-meitu-bin/native/podfile.rb +99 -0
  64. data/lib/cocoapods-meitu-bin/native/podfile_env.rb +38 -0
  65. data/lib/cocoapods-meitu-bin/native/podfile_generator.rb +201 -0
  66. data/lib/cocoapods-meitu-bin/native/podspec_finder.rb +25 -0
  67. data/lib/cocoapods-meitu-bin/native/resolver.rb +299 -0
  68. data/lib/cocoapods-meitu-bin/native/sandbox_analyzer.rb +34 -0
  69. data/lib/cocoapods-meitu-bin/native/source.rb +35 -0
  70. data/lib/cocoapods-meitu-bin/native/sources_manager.rb +21 -0
  71. data/lib/cocoapods-meitu-bin/native/specification.rb +31 -0
  72. data/lib/cocoapods-meitu-bin/native/target_validator.rb +41 -0
  73. data/lib/cocoapods-meitu-bin/native/validator.rb +40 -0
  74. data/lib/cocoapods-meitu-bin/native.rb +26 -0
  75. data/lib/cocoapods-meitu-bin/source_provider_hook.rb +68 -0
  76. data/lib/cocoapods-meitu-bin.rb +2 -0
  77. data/lib/cocoapods_plugin.rb +11 -0
  78. data/spec/command/bin_spec.rb +12 -0
  79. data/spec/spec_helper.rb +50 -0
  80. metadata +201 -0
@@ -0,0 +1,551 @@
1
+ # copy from https://github.com/CocoaPods/cocoapods-packager
2
+
3
+ require 'cocoapods-meitu-bin/helpers/framework.rb'
4
+ require 'English'
5
+ require 'cocoapods-meitu-bin/config/config_builder'
6
+ require 'shellwords'
7
+
8
+ module CBin
9
+ class Framework
10
+ class Builder
11
+ include Pod
12
+ #Debug下还待完成
13
+ def initialize(spec, installer, platform, source_dir, isRootSpec = true, build_model="Release")
14
+ @spec = spec
15
+ @source_dir = source_dir
16
+ @installer = installer
17
+ @platform = platform
18
+ @build_model = build_model
19
+ @isRootSpec = isRootSpec
20
+
21
+ @file_accessors = @installer.pod_targets.select { |t| t.pod_name == @spec.name }.flat_map(&:file_accessors) if installer
22
+ end
23
+
24
+ # 利用xcodebuild打包
25
+ def build
26
+ defines = compile
27
+ build_sim_libraries(defines)
28
+
29
+ defines
30
+ end
31
+
32
+ def lipo_create(defines)
33
+ # 合并静态库
34
+ merge_static_libs
35
+ # 拷贝资源文件
36
+ copy_all_resources
37
+ # 拷贝swiftmodule
38
+ copy_swiftmodules
39
+ # # 拷贝vendored_libraries
40
+ # copy_vendored_libraries
41
+ # 拷贝vendored_frameworks
42
+ copy_vendored_frameworks
43
+ # # 拷贝动态库
44
+ # copy_dynamic_libs
45
+ # # 拷贝xcframework
46
+ # copy_xcframeworks
47
+ # 拷贝最终产物
48
+ copy_target_product
49
+ # 返回Framework目录
50
+ framework
51
+ end
52
+
53
+ private
54
+
55
+ # 拷贝最终产物
56
+ def copy_target_product
57
+ framework
58
+ fwk = "#{build_device_dir}/#{framework_name}.framework"
59
+ `cp -r #{fwk} #{framework.root_path}`
60
+ end
61
+
62
+ # 拷贝xcframework
63
+ def copy_xcframeworks
64
+ xcframeworks = vendored_xcframeworks
65
+ unless xcframeworks.empty?
66
+ des_dir = dynamic_libs_des_dir
67
+ FileUtils.mkdir(des_dir) unless File.exist?(des_dir)
68
+ xcframeworks.map { |xcf| `cp -r #{xcf} #{des_dir}` }
69
+ end
70
+ end
71
+
72
+ # 拷贝动态库
73
+ def copy_dynamic_libs
74
+ dynamic_libs = vendored_dynamic_libraries
75
+ if dynamic_libs && dynamic_libs.size > 0
76
+ des_dir = dynamic_libs_des_dir
77
+ FileUtils.mkdir(des_dir) unless File.exist?(des_dir)
78
+ dynamic_libs.map { |lib| `cp -r #{lib} #{des_dir}` }
79
+ end
80
+ end
81
+
82
+ # 拷贝vendored_frameworks
83
+ def copy_vendored_frameworks
84
+ fwks = vendored_frameworks
85
+ unless fwks.empty?
86
+ des_dir = dynamic_libs_des_dir
87
+ FileUtils.mkdir(des_dir) unless File.exist?(des_dir)
88
+ fwks.map { |fwk| `cp -r #{fwk} #{des_dir}` }
89
+ end
90
+ end
91
+
92
+ # 拷贝vendored_libraries
93
+ def copy_vendored_libraries
94
+ libs = vendored_libraries
95
+ unless libs.empty?
96
+ des_dir = vendored_libraries_dir
97
+ FileUtils.mkdir(des_dir) unless File.exist?(des_dir)
98
+ libs.map { |lib| `cp -r #{lib} #{des_dir}` }
99
+ end
100
+ end
101
+
102
+ # 拷贝swiftmodule
103
+ def copy_swiftmodules
104
+ swift_module = "#{build_device_dir}/#{framework_name}.framework/Modules/#{framework_name}.swiftmodule"
105
+ if File.exist?(swift_module)
106
+ src_swift = "#{build_sim_dir}/#{framework_name}.framework/Modules/#{framework_name}.swiftmodule"
107
+ `cp -af #{src_swift}/* #{swift_module}`
108
+ `cp -af #{src_swift}/Project/* #{swift_module}/Project`
109
+ end
110
+ end
111
+
112
+ # 拷贝资源文件
113
+ def copy_all_resources
114
+ # 拷贝resource_bundles
115
+ copy_resource_bundles
116
+ # 拷贝resources/resource
117
+ copy_other_resources
118
+ end
119
+
120
+ # 拷贝resource_bundles
121
+ def copy_resource_bundles
122
+ bundles = resource_bundles
123
+ return if bundles.size == 0
124
+ des_dir = resources_des_dir
125
+ FileUtils.mkdir(des_dir) unless File.exist?(des_dir)
126
+ bundles.map { |bundle| `cp -r #{bundle} #{des_dir}` }
127
+ end
128
+
129
+ # 拷贝resources/resource
130
+ def copy_other_resources
131
+ resources = other_resources
132
+ return if resources.size == 0
133
+ des_dir = resources_des_dir
134
+ FileUtils.mkdir(des_dir) unless File.exist?(des_dir)
135
+ resources.map { |res| `cp -r #{res} #{des_dir}` }
136
+ end
137
+
138
+ # 获取podspec中的resource_bundles
139
+ def resource_bundles
140
+ return [] if @file_accessors.nil?
141
+ resource_bundles = @file_accessors.flat_map(&:resource_bundles)
142
+ return [] if resource_bundles.nil? || resource_bundles.size == 0
143
+ resource_bundles.compact.flat_map(&:keys).map { |key| "#{build_device_dir}/#{key}.bundle" }
144
+ end
145
+
146
+ # 获取podspec中resource/resources
147
+ def other_resources
148
+ return [] if @file_accessors.nil?
149
+ resources = @file_accessors.flat_map(&:resources)
150
+ return [] if resources.nil? || resources.size == 0
151
+ resources.compact.reject { |res| reject_resource_ext.include?(res.extname) }.map(&:to_s)
152
+ end
153
+
154
+ # 需要排除的资源文件后缀
155
+ def reject_resource_ext
156
+ %w[.xcdatamodeld .xcdatamodel .xcmappingmodel .xib .storyboard]
157
+ end
158
+
159
+ # 合并静态库
160
+ def merge_static_libs
161
+ # 合并真机静态库
162
+ merge_static_libs_for_device if @isRootSpec
163
+ # 合并模拟器静态库
164
+ merge_static_libs_for_sim if @isRootSpec
165
+ # 合并真机和模拟器
166
+ merge_device_sim
167
+ end
168
+
169
+ # 合并真机和模拟器
170
+ def merge_device_sim
171
+ libs = static_libs_in_sandbox + static_libs_in_sandbox(build_sim_dir)
172
+ output = "#{build_device_dir}/#{framework_name}.framework/#{framework_name}"
173
+ `lipo -create -output #{output} #{libs.join(' ')}` unless libs.empty?
174
+ end
175
+
176
+ # 合并真机静态库
177
+ def merge_static_libs_for_device
178
+ static_libs = static_libs_in_sandbox + vendored_static_libraries
179
+ return if static_libs.empty?
180
+ libs = ios_architectures.map do |arch|
181
+ library = "#{build_device_dir}/package-#{framework_name}-#{arch}.a"
182
+ `libtool -arch_only #{arch} -static -o #{library} #{static_libs.join(' ')}`
183
+ library
184
+ end
185
+ output = "#{build_device_dir}/#{framework_name}.framework/#{framework_name}"
186
+ `lipo -create -output #{output} #{libs.join(' ')}` if libs.size > 0
187
+ end
188
+
189
+ # 合并模拟器静态库
190
+ def merge_static_libs_for_sim
191
+ static_libs = static_libs_in_sandbox(build_sim_dir) + vendored_static_libraries
192
+ return if static_libs.empty?
193
+ libs = ios_architectures_sim.map do |arch|
194
+ library = "#{build_sim_dir}/package-#{framework_name}-#{arch}.a"
195
+ `libtool -arch_only #{arch} -static -o #{library} #{static_libs.join(' ')}`
196
+ library
197
+ end
198
+ output = "#{build_sim_dir}/#{framework_name}.framework/#{framework_name}"
199
+ `lipo -create -output #{output} #{libs.join(' ')}` if libs.size > 0
200
+ end
201
+
202
+ # 存放资源的目录
203
+ def resources_des_dir
204
+ "#{build_device_dir}/#{framework_name}.framework/resources"
205
+ end
206
+
207
+ # 存放动态库的目录
208
+ def dynamic_libs_des_dir
209
+ "#{build_device_dir}/#{framework_name}.framework/fwks"
210
+ end
211
+
212
+ # 存放vendored_libraries的目录
213
+ def vendored_libraries_dir
214
+ "#{build_device_dir}/#{framework_name}.framework/libs"
215
+ end
216
+
217
+ # 真机路径
218
+ def build_device_dir
219
+ 'build-device'
220
+ end
221
+
222
+ # 模拟器路径
223
+ def build_sim_dir
224
+ 'build-simulator'
225
+ end
226
+
227
+ # 获取vendored_libraries
228
+ def vendored_libraries
229
+ return [] if @file_accessors.nil?
230
+ libs = @file_accessors.flat_map(&:vendored_libraries) || []
231
+ libs.compact.map(&:to_s)
232
+ end
233
+
234
+ # 获取vendored_frameworks
235
+ def vendored_frameworks
236
+ return [] if @file_accessors.nil?
237
+ fwks = @file_accessors.flat_map(&:vendored_frameworks) || []
238
+ fwks.compact.map(&:to_s)
239
+ end
240
+
241
+ # 获取静态库
242
+ def vendored_static_libraries
243
+ return [] if @file_accessors.nil?
244
+ file_accessors = @file_accessors
245
+ # libs = file_accessors.flat_map(&:vendored_static_frameworks).map { |f| f + f.basename('.*') } || []
246
+ # libs += file_accessors.flat_map(&:vendored_static_libraries)
247
+ libs = file_accessors.flat_map(&:vendored_static_libraries) || []
248
+ @vendored_static_libraries = libs.compact.map(&:to_s)
249
+ @vendored_static_libraries
250
+ end
251
+
252
+ # 获取动态库
253
+ def vendored_dynamic_libraries
254
+ return [] if @file_accessors.nil?
255
+ file_accessors = @file_accessors
256
+ libs = file_accessors.flat_map(&:vendored_dynamic_frameworks) || []
257
+ libs += file_accessors.flat_map(&:vendored_dynamic_libraries)
258
+ @vendored_dynamic_libraries = libs.compact.map(&:to_s)
259
+ @vendored_dynamic_libraries
260
+ end
261
+
262
+ # 获取xcframework
263
+ def vendored_xcframeworks
264
+ return [] if @file_accessors.nil?
265
+ xcframeworks = @file_accessors.flat_map(&:vendored_xcframeworks) || []
266
+ xcframeworks.compact.map(&:to_s)
267
+ end
268
+
269
+ # 获取静态库
270
+ def static_libs_in_sandbox(build_dir = build_device_dir)
271
+ Dir.glob("#{build_dir}/#{framework_name}.framework/#{framework_name}")
272
+ end
273
+
274
+ # 最终生成的framework的name
275
+ # 先判断是否有module_name,再判断是否有header_dir,如果都没有,使用name
276
+ def framework_name
277
+ @spec.module_name
278
+ end
279
+
280
+ # 真机CPU架构
281
+ def ios_architectures
282
+ archs = %w[arm64]
283
+ vendored_static_libraries.each do |library|
284
+ archs = `lipo -info #{library}`.split & archs
285
+ end
286
+ archs
287
+ end
288
+
289
+ # 模拟器CPU架构
290
+ def ios_architectures_sim
291
+ archs = %w[x86_64]
292
+ vendored_static_libraries.each do |library|
293
+ archs = `lipo -info #{library}`.split & archs
294
+ end
295
+ archs
296
+ end
297
+
298
+ # 真机编译(只支持 arm64)
299
+ def compile
300
+ defines = "GCC_PREPROCESSOR_DEFINITIONS='$(inherited)' GCC_WARN_INHIBIT_ALL_WARNINGS=YES -quiet"
301
+ # defines = "GCC_PREPROCESSOR_DEFINITIONS='$(inherited)' -quiet"
302
+ unless @spec.consumer(@platform).compiler_flags.empty?
303
+ defines += ' '
304
+ defines += @spec.consumer(@platform).compiler_flags.join(' ')
305
+ end
306
+
307
+ options = "ARCHS=\'#{ios_architectures.join(' ')}\' OTHER_CFLAGS=\'-fembed-bitcode -Qunused-arguments\'"
308
+ xcodebuild(defines, options, build_device_dir, @build_model)
309
+
310
+ defines
311
+ end
312
+
313
+ # 模拟器编译(只支持 x86-64)
314
+ def build_sim_libraries(defines)
315
+ if @platform.name == :ios
316
+ options = "-sdk iphonesimulator ARCHS=\'#{ios_architectures_sim.join(' ')}\'"
317
+ xcodebuild(defines, options, build_sim_dir, @build_model)
318
+ end
319
+ end
320
+
321
+ def target_name
322
+ # 区分多平台,如配置了多平台,会带上平台的名字
323
+ # 如libwebp-iOS
324
+ if @spec.available_platforms.count > 1
325
+ name = "#{@spec.name}-#{Platform.string_name(@spec.consumer(@platform).platform_name)}"
326
+ return name if @installer && @installer.pod_targets.map { |pod| pod.name }.include?(name)
327
+ @spec.name
328
+ else
329
+ @spec.name
330
+ end
331
+ end
332
+
333
+ # 调用 xcodebuild 编译
334
+ def xcodebuild(defines = '', args = '', build_dir = 'build', build_model = 'Release')
335
+ unless File.exist?("Pods.xcodeproj") #cocoapods-generate v2.0.0
336
+ command = "xcodebuild #{defines} #{args} CONFIGURATION_BUILD_DIR=#{File.join(File.expand_path("..", build_dir), File.basename(build_dir))} clean build -configuration #{build_model} -target #{target_name} -project ./Pods/Pods.xcodeproj"
337
+ else
338
+ command = "xcodebuild #{defines} #{args} CONFIGURATION_BUILD_DIR=#{build_dir} clean build -configuration #{build_model} -target #{target_name} -project ./Pods.xcodeproj"
339
+ end
340
+
341
+ UI.info "#{command}"
342
+ output = `#{command}`.lines.to_a
343
+
344
+ if $CHILD_STATUS.exitstatus != 0
345
+ log_file = File.join(Dir.pwd, "build_error.log")
346
+ error_msg = <<~EOF
347
+ 😈 可恶,编译失败了~ 😈
348
+ 请查看下面的报错信息或者打开 #{log_file} 查看
349
+ 编译命令:
350
+ #{command}
351
+ 报错信息:
352
+ #{output.map { |line| " #{line}" }.join}
353
+ EOF
354
+ FileUtils.rm_f(log_file) if File.exist?(log_file)
355
+ file = File.new(log_file, "w+")
356
+ file.puts(error_msg)
357
+ file.close
358
+
359
+ raise Informative, error_msg
360
+
361
+ Process.exit
362
+ end
363
+ end
364
+
365
+ def framework
366
+ @framework ||= begin
367
+ framework = Framework.new(framework_name, @platform.name.to_s)
368
+ framework.make
369
+ framework
370
+ end
371
+ end
372
+
373
+ # ---------- 以下方法无用 -------------
374
+
375
+ def is_debug_model
376
+ @build_model == "Debug"
377
+ end
378
+
379
+ def build_static_library_for_ios(output)
380
+ static_libs = static_libs_in_sandbox('build') + static_libs_in_sandbox('build-simulator') + @vendored_libraries
381
+ # if is_debug_model
382
+ ios_architectures.map do |arch|
383
+ static_libs += static_libs_in_sandbox("build-#{arch}") + @vendored_libraries
384
+ end
385
+ ios_architectures_sim do |arch|
386
+ static_libs += static_libs_in_sandbox("build-#{arch}") + @vendored_libraries
387
+ end
388
+ # end
389
+
390
+ build_path = Pathname("build")
391
+ build_path.mkpath unless build_path.exist?
392
+
393
+ # if is_debug_model
394
+ libs = (ios_architectures + ios_architectures_sim) .map do |arch|
395
+ # library = "build-#{arch}/lib#{target_name}.a"
396
+ library = "build-#{arch}/#{target_name}.framework/#{target_name}"
397
+ library
398
+ end
399
+ # else
400
+ # libs = ios_architectures.map do |arch|
401
+ # library = "build/package-#{@spec.name}-#{arch}.a"
402
+ # # libtool -arch_only arm64 -static -o build/package-armv64.a build/libIMYFoundation.a build-simulator/libIMYFoundation.a
403
+ # # 从liBFoundation.a 文件中,提取出 arm64 架构的文件,命名为build/package-armv64.a
404
+ # UI.message "libtool -arch_only #{arch} -static -o #{library} #{static_libs.join(' ')}"
405
+ # `libtool -arch_only #{arch} -static -o #{library} #{static_libs.join(' ')}`
406
+ # library
407
+ # end
408
+ # end
409
+
410
+ UI.message "lipo -create -output #{output} #{libs.join(' ')}"
411
+ `lipo -create -output #{output} #{libs.join(' ')}`
412
+ end
413
+
414
+ def cp_to_source_dir
415
+ framework_name = "#{@spec.name}.framework"
416
+ target_dir = File.join(CBin::Config::Builder.instance.zip_dir,framework_name)
417
+ FileUtils.rm_rf(target_dir) if File.exist?(target_dir)
418
+
419
+ zip_dir = CBin::Config::Builder.instance.zip_dir
420
+ FileUtils.mkdir_p(zip_dir) unless File.exist?(zip_dir)
421
+
422
+ `cp -fa #{framework.root_path}/#{framework_name} #{target_dir}`
423
+ end
424
+
425
+ def copy_headers
426
+ #走 podsepc中的public_headers
427
+ public_headers = Array.new
428
+
429
+ #by slj 如果没有头文件,去 "Headers/Public"拿
430
+ # if public_headers.empty?
431
+ spec_header_dir = "./Headers/Public/#{@spec.name}"
432
+ unless File.exist?(spec_header_dir)
433
+ spec_header_dir = "./Pods/Headers/Public/#{@spec.name}"
434
+ end
435
+ return unless File.exist?(spec_header_dir)
436
+ # raise "copy_headers #{spec_header_dir} no exist " unless File.exist?(spec_header_dir)
437
+ Dir.chdir(spec_header_dir) do
438
+ headers = Dir.glob('*.h')
439
+ headers.each do |h|
440
+ public_headers << Pathname.new(File.join(Dir.pwd,h))
441
+ end
442
+ end
443
+ # end
444
+
445
+ # UI.message "Copying public headers #{public_headers.map(&:basename).map(&:to_s)}"
446
+
447
+ public_headers.each do |h|
448
+ `ditto #{h} #{framework.headers_path}/#{h.basename}`
449
+ end
450
+
451
+ # If custom 'module_map' is specified add it to the framework distribution
452
+ # otherwise check if a header exists that is equal to 'spec.name', if so
453
+ # create a default 'module_map' one using it.
454
+ if !@spec.module_map.nil?
455
+ module_map_file = @file_accessor.module_map
456
+ if Pathname(module_map_file).exist?
457
+ module_map = File.read(module_map_file)
458
+ end
459
+ elsif public_headers.map(&:basename).map(&:to_s).include?("#{@spec.name}.h")
460
+ module_map = <<-MAP
461
+ framework module #{@spec.name} {
462
+ umbrella header "#{@spec.name}.h"
463
+
464
+ export *
465
+ module * { export * }
466
+ }
467
+ MAP
468
+ end
469
+
470
+ unless module_map.nil?
471
+ UI.message "Writing module map #{module_map}"
472
+ unless framework.module_map_path.exist?
473
+ framework.module_map_path.mkpath
474
+ end
475
+ File.write("#{framework.module_map_path}/module.modulemap", module_map)
476
+ end
477
+ end
478
+
479
+ def copy_license
480
+ UI.section "Copying license #{@spec}" do
481
+ license_file = @spec.license[:file] || 'LICENSE'
482
+ `cp "#{license_file}" .` if Pathname(license_file).exist?
483
+ end
484
+ end
485
+
486
+ # def copy_resources
487
+ # UI.section "copy_resources #{@spec}" do
488
+ # resource_dir = './build/*.bundle'
489
+ # resource_dir = './build-armv7/*.bundle' if File.exist?('./build-armv7')
490
+ # resource_dir = './build-arm64/*.bundle' if File.exist?('./build-arm64')
491
+ #
492
+ # bundles = Dir.glob(resource_dir)
493
+ #
494
+ # bundle_names = [@spec, *@spec.recursive_subspecs].flat_map do |spec|
495
+ # consumer = spec.consumer(@platform)
496
+ # consumer.resource_bundles.keys +
497
+ # consumer.resources.map do |r|
498
+ # File.basename(r, '.bundle') if File.extname(r) == 'bundle'
499
+ # end
500
+ # end.compact.uniq
501
+ #
502
+ # bundles.select! do |bundle|
503
+ # bundle_name = File.basename(bundle, '.bundle')
504
+ # bundle_names.include?(bundle_name)
505
+ # end
506
+ #
507
+ # if bundles.count > 0
508
+ # UI.message "Copying bundle files #{bundles}"
509
+ # bundle_files = bundles.join(' ')
510
+ # `cp -rp #{bundle_files} #{framework.resources_path} 2>&1`
511
+ # end
512
+ #
513
+ # real_source_dir = @source_dir
514
+ # unless @isRootSpec
515
+ # spec_source_dir = File.join(Dir.pwd,"#{@spec.name}")
516
+ # unless File.exist?(spec_source_dir)
517
+ # spec_source_dir = File.join(Dir.pwd,"Pods/#{@spec.name}")
518
+ # end
519
+ # raise "copy_resources #{spec_source_dir} no exist " unless File.exist?(spec_source_dir)
520
+ #
521
+ # real_source_dir = spec_source_dir
522
+ # end
523
+ # resources = [@spec, *@spec.recursive_subspecs].flat_map do |spec|
524
+ # expand_paths(real_source_dir, spec.consumer(@platform).resources)
525
+ # end.compact.uniq
526
+ #
527
+ # if resources.count == 0 && bundles.count == 0
528
+ # framework.delete_resources
529
+ # return
530
+ # end
531
+ #
532
+ # if resources.count > 0
533
+ # #把 路径转义。 避免空格情况下拷贝失败
534
+ # escape_resource = []
535
+ # resources.each do |source|
536
+ # escape_resource << Shellwords.join(source)
537
+ # end
538
+ # UI.message "Copying resources #{escape_resource}"
539
+ # `cp -rp #{escape_resource.join(' ')} #{framework.resources_path}`
540
+ # end
541
+ # end
542
+ # end
543
+
544
+ def expand_paths(source_dir, path_specs)
545
+ path_specs.map do |path_spec|
546
+ Dir.glob(File.join(source_dir, path_spec))
547
+ end
548
+ end
549
+ end
550
+ end
551
+ end
@@ -0,0 +1,54 @@
1
+ # copy from https://github.com/CocoaPods/cocoapods-packager
2
+
3
+ module CBin
4
+ class Library
5
+ attr_reader :headers_path
6
+ attr_reader :resources_path
7
+ attr_reader :root_path
8
+ attr_reader :versions_path
9
+ attr_reader :name_path
10
+
11
+ def initialize(name, platform, version)
12
+ @name = name
13
+ @platform = platform
14
+ @version = version
15
+ end
16
+
17
+ def make
18
+ make_root
19
+ make_library
20
+ make_headers
21
+ make_resources
22
+ end
23
+
24
+ def delete_resources
25
+ Pathname.new(@resources_path).rmtree
26
+ (Pathname.new(@fwk_path) + Pathname.new('Resources')).delete
27
+ end
28
+
29
+ private
30
+
31
+ def make_library
32
+ @name_path = CBin::Config::Builder.instance.library_name_version(@name,@version)
33
+ @fwk_path = @root_path + Pathname.new(@name_path)
34
+ @fwk_path.mkdir unless @fwk_path.exist?
35
+
36
+ @versions_path = @fwk_path
37
+ end
38
+
39
+ def make_headers
40
+ @headers_path = @versions_path + Pathname.new('Headers')
41
+ @headers_path.mkpath unless @headers_path.exist?
42
+ end
43
+
44
+ def make_resources
45
+ @resources_path = @versions_path + Pathname.new('Resources')
46
+ @resources_path.mkpath unless @resources_path.exist?
47
+ end
48
+
49
+ def make_root
50
+ @root_path = Pathname.new(@platform)
51
+ @root_path.mkpath unless @root_path.exist?
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,90 @@
1
+
2
+ # copy from https://github.com/CocoaPods/cocoapods-packager
3
+
4
+ require 'cocoapods-meitu-bin/helpers/framework.rb'
5
+ require 'cocoapods-meitu-bin/helpers/library.rb'
6
+
7
+ require 'English'
8
+
9
+ module CBin
10
+ class Library
11
+ class Builder
12
+ include Pod
13
+
14
+ def initialize(spec, file_accessor, platform, source_dir,framework_path)
15
+ @spec = spec
16
+ @source_dir = source_dir
17
+ @file_accessor = file_accessor
18
+ @platform = platform
19
+ @framework = framework_path
20
+ @source_files = "#{@source_dir}/#{library.name_path}"
21
+ @source_zip_file = "#{@source_files}.zip"
22
+ end
23
+
24
+ def build
25
+ UI.section("Building static library #{@spec}") do
26
+
27
+ clean_source_dir
28
+
29
+ copy_headers
30
+ copy_library
31
+ copy_resources
32
+
33
+ cp_to_source_dir
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def clean_source_dir
40
+ FileUtils.rm_rf(@source_files) if File.exist?(@source_files)
41
+ FileUtils.rm_rf(@source_zip_file) if File.exist?(@source_zip_file)
42
+ end
43
+
44
+ def cp_to_source_dir
45
+ target_dir = library.versions_path
46
+ dest_file = "#{@source_dir}/#{library.name_path}"
47
+ FileUtils.rm_rf(dest_file) if File.exist?(dest_file)
48
+
49
+ `cp -fa #{target_dir} #{dest_file}/`
50
+ end
51
+
52
+ def copy_headers
53
+ FileUtils.cp_r(framework.headers_path,library.versions_path) if File.exist?(framework.headers_path)
54
+ end
55
+
56
+ def copy_library
57
+ src_file = "#{framework.versions_path}/#{@spec.name}"
58
+ unless File.exist?(src_file)
59
+ raise Informative, "framework没有文件:#{src_file}"
60
+ end
61
+
62
+ dest_file = "#{library.versions_path}/#{@spec.name}"
63
+ rename_dest_file = "#{library.versions_path}/lib#{@spec.name}.a"
64
+ FileUtils.cp_r(src_file,dest_file)
65
+ File.rename(dest_file, rename_dest_file ) if File.exist?(dest_file)
66
+ end
67
+
68
+ def copy_resources
69
+ FileUtils.cp_r(framework.resources_path,library.versions_path) if File.exist?(framework.resources_path)
70
+ end
71
+
72
+
73
+ def framework
74
+ @framework ||= begin
75
+ framework = Framework.new(@spec.name, @platform.name.to_s)
76
+ framework.make
77
+ framework
78
+ end
79
+ end
80
+
81
+ def library
82
+ @library ||= begin
83
+ library = Library.new(@spec.name, @platform.name.to_s,@spec.version)
84
+ library.make
85
+ library
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end