cocoapods-imy-bin 0.2.8 → 0.3.1.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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cocoapods-imy-bin/command/bin.rb +0 -1
  3. data/lib/cocoapods-imy-bin/command/bin/archive.rb +41 -4
  4. data/lib/cocoapods-imy-bin/command/bin/auto.rb +22 -15
  5. data/lib/cocoapods-imy-bin/command/bin/dup.rb +78 -0
  6. data/lib/cocoapods-imy-bin/config/config.rb +1 -1
  7. data/lib/cocoapods-imy-bin/config/config_builder.rb +39 -2
  8. data/lib/cocoapods-imy-bin/gem_version.rb +1 -1
  9. data/lib/cocoapods-imy-bin/helpers.rb +1 -0
  10. data/lib/cocoapods-imy-bin/helpers/Info.plist +0 -0
  11. data/lib/cocoapods-imy-bin/helpers/build_helper.rb +15 -7
  12. data/lib/cocoapods-imy-bin/helpers/build_utils.rb +63 -0
  13. data/lib/cocoapods-imy-bin/helpers/framework.rb +25 -2
  14. data/lib/cocoapods-imy-bin/helpers/framework_builder.rb +153 -56
  15. data/lib/cocoapods-imy-bin/helpers/sources_helper.rb +5 -2
  16. data/lib/cocoapods-imy-bin/helpers/spec_source_creator.rb +65 -8
  17. data/lib/cocoapods-imy-bin/helpers/upload_helper.rb +8 -3
  18. data/lib/cocoapods-imy-bin/native.rb +4 -0
  19. data/lib/cocoapods-imy-bin/native/analyzer.rb +2 -0
  20. data/lib/cocoapods-imy-bin/native/file_accessor.rb +28 -0
  21. data/lib/cocoapods-imy-bin/native/installer.rb +22 -2
  22. data/lib/cocoapods-imy-bin/native/pod_target_installer.rb +94 -0
  23. data/lib/cocoapods-imy-bin/native/podfile_generator.rb +11 -2
  24. data/lib/cocoapods-imy-bin/native/target_validator.rb +41 -0
  25. data/lib/cocoapods-imy-bin/native/validator.rb +1 -38
  26. data/lib/cocoapods-imy-bin/source_provider_hook.rb +35 -23
  27. metadata +12 -12
  28. data/lib/cocoapods-imy-bin/command/bin/local.rb +0 -156
  29. data/lib/cocoapods-imy-bin/helpers/local/loca_llibrary.rb +0 -57
  30. data/lib/cocoapods-imy-bin/helpers/local/local_build_helper.rb +0 -146
  31. data/lib/cocoapods-imy-bin/helpers/local/local_framework.rb +0 -65
  32. data/lib/cocoapods-imy-bin/helpers/local/local_framework_builder.rb +0 -174
  33. data/lib/cocoapods-imy-bin/helpers/local/local_library_builder.rb +0 -92
@@ -7,6 +7,8 @@ module CBin
7
7
  attr_reader :resources_path
8
8
  attr_reader :root_path
9
9
  attr_reader :versions_path
10
+ attr_reader :swift_module_path
11
+ attr_reader :fwk_path
10
12
 
11
13
  def initialize(name, platform)
12
14
  @name = name
@@ -22,8 +24,24 @@ module CBin
22
24
  end
23
25
 
24
26
  def delete_resources
25
- Pathname.new(@resources_path).rmtree
26
- (Pathname.new(@fwk_path) + Pathname.new('Resources')).delete
27
+ Pathname.new(@resources_path).rmtree if File.exist? (@resources_path)
28
+ (Pathname.new(@fwk_path) + Pathname.new('Resources')).delete if File.exist?(Pathname.new(@fwk_path) + Pathname.new('Resources'))
29
+ end
30
+
31
+ def remove_current_version
32
+ FileUtils.rm_f(File.join(@fwk_path,@name))
33
+ FileUtils.rm_f(File.join(@fwk_path,"Headers"))
34
+ FileUtils.rm_f(File.join(@fwk_path,"Resources"))
35
+
36
+ FileUtils.cp_r("#{@versions_path}/.", @fwk_path)
37
+ # FileUtils.remove_dir(@versions_path)
38
+ FileUtils.remove_dir("#{@fwk_path}/Versions")
39
+
40
+ # current_version_path = @versions_path + Pathname.new('../Current')
41
+ # `ln -sf A #{current_version_path}`
42
+ # `ln -sf Versions/Current/Headers #{@fwk_path}/`
43
+ # `ln -sf Versions/Current/Resources #{@fwk_path}/`
44
+ # `ln -sf Versions/Current/#{@name} #{@fwk_path}/`
27
45
  end
28
46
 
29
47
  private
@@ -36,11 +54,16 @@ module CBin
36
54
  `ln -sf Versions/Current/#{@name} #{@fwk_path}/`
37
55
  end
38
56
 
57
+
58
+
39
59
  def make_framework
40
60
  @fwk_path = @root_path + Pathname.new(@name + '.framework')
41
61
  @fwk_path.mkdir unless @fwk_path.exist?
42
62
 
43
63
  @module_map_path = @fwk_path + Pathname.new('Modules')
64
+ @swift_module_path = @module_map_path + Pathname.new(@name + '.swiftmodule')
65
+
66
+
44
67
  @versions_path = @fwk_path + Pathname.new('Versions/A')
45
68
  end
46
69
 
@@ -4,13 +4,14 @@ require 'cocoapods-imy-bin/helpers/framework.rb'
4
4
  require 'English'
5
5
  require 'cocoapods-imy-bin/config/config_builder'
6
6
  require 'shellwords'
7
+ require 'cocoapods-imy-bin/helpers/build_utils'
7
8
 
8
9
  module CBin
9
10
  class Framework
10
11
  class Builder
11
12
  include Pod
12
13
  #Debug下还待完成
13
- def initialize(spec, file_accessor, platform, source_dir, isRootSpec = true, build_model="Release")
14
+ def initialize(spec, file_accessor, platform, source_dir, isRootSpec = true, build_model="Debug")
14
15
  @spec = spec
15
16
  @source_dir = source_dir
16
17
  @file_accessor = file_accessor
@@ -38,26 +39,54 @@ module CBin
38
39
  end
39
40
 
40
41
  def lipo_build(defines)
41
- UI.section("Building static Library #{@spec}") do
42
- # defines = compile
43
42
 
44
- # build_sim_libraries(defines)
45
- output = framework.versions_path + Pathname.new(@spec.name)
43
+ if CBin::Build::Utils.is_swift_module(@spec) || !CBin::Build::Utils.uses_frameworks?
44
+ UI.section("Building static Library #{@spec}") do
45
+ # defines = compile
46
46
 
47
- build_static_library_for_ios(output)
47
+ # build_sim_libraries(defines)
48
+ output = framework.versions_path + Pathname.new(@spec.name)
48
49
 
49
- copy_headers
50
- copy_license
51
- copy_resources
50
+ build_static_library_for_ios(output)
52
51
 
53
- cp_to_source_dir
52
+ copy_headers
53
+ copy_license
54
+ copy_resources
55
+
56
+ cp_to_source_dir
57
+ end
58
+ else
59
+ # begin
60
+ UI.section("Building framework #{@spec}") do
61
+ # defines = compile
62
+
63
+ # build_sim_libraries(defines)
64
+ output = framework.fwk_path + Pathname.new(@spec.name)
65
+
66
+ copy_static_framework_dir_for_ios
67
+
68
+ build_static_framework_machO_for_ios(output)
69
+
70
+ # copy_license
71
+ copy_framework_resources
72
+
73
+ #cp_to_source_dir#
74
+
75
+ # rescue Object => exception
76
+ # UI.puts exception
77
+ # end
78
+ end
54
79
  end
80
+
55
81
  framework
56
82
  end
57
83
 
58
84
  private
59
85
 
60
86
  def cp_to_source_dir
87
+ # 删除Versions 软链接
88
+ framework.remove_current_version if CBin::Build::Utils.is_swift_module(@spec)
89
+
61
90
  framework_name = "#{@spec.name}.framework"
62
91
  target_dir = File.join(CBin::Config::Builder.instance.zip_dir,framework_name)
63
92
  FileUtils.rm_rf(target_dir) if File.exist?(target_dir)
@@ -72,14 +101,10 @@ module CBin
72
101
  def build_sim_libraries(defines)
73
102
  UI.message 'Building simulator libraries'
74
103
 
75
- if is_debug_model
76
- # archs = %w[i386 x86_64]
77
- archs = ios_architectures_sim
78
- archs.map do |arch|
79
- xcodebuild(defines, "-sdk iphonesimulator ARCHS=\'#{arch}\' ", "build-#{arch}","Debug")
80
- end
81
- else
82
- xcodebuild(defines, "-sdk iphonesimulator ", 'build-simulator', "Release")
104
+ # archs = %w[i386 x86_64]
105
+ archs = ios_architectures_sim
106
+ archs.map do |arch|
107
+ xcodebuild(defines, "-sdk iphonesimulator ARCHS=\'#{arch}\' ", "build-#{arch}",@build_model)
83
108
  end
84
109
 
85
110
  end
@@ -96,32 +121,20 @@ module CBin
96
121
  def build_static_library_for_ios(output)
97
122
  UI.message "Building ios libraries with archs #{ios_architectures}"
98
123
  static_libs = static_libs_in_sandbox('build') + static_libs_in_sandbox('build-simulator') + @vendored_libraries
99
- if is_debug_model
100
- ios_architectures.map do |arch|
101
- static_libs += static_libs_in_sandbox("build-#{arch}") + @vendored_libraries
102
- end
103
- ios_architectures_sim do |arch|
104
- static_libs += static_libs_in_sandbox("build-#{arch}") + @vendored_libraries
105
- end
124
+
125
+ ios_architectures.map do |arch|
126
+ static_libs += static_libs_in_sandbox("build-#{arch}") + @vendored_libraries
127
+ end
128
+ ios_architectures_sim do |arch|
129
+ static_libs += static_libs_in_sandbox("build-#{arch}") + @vendored_libraries
106
130
  end
107
131
 
108
132
  build_path = Pathname("build")
109
133
  build_path.mkpath unless build_path.exist?
110
134
 
111
- if is_debug_model
112
- libs = (ios_architectures + ios_architectures_sim) .map do |arch|
113
- library = "build-#{arch}/lib#{@spec.name}.a"
114
- library
115
- end
116
- else
117
- libs = ios_architectures.map do |arch|
118
- library = "build/package-#{@spec.name}-#{arch}.a"
119
- # libtool -arch_only arm64 -static -o build/package-armv64.a build/libIMYFoundation.a build-simulator/libIMYFoundation.a
120
- # 从liBFoundation.a 文件中,提取出 arm64 架构的文件,命名为build/package-armv64.a
121
- UI.message "libtool -arch_only #{arch} -static -o #{library} #{static_libs.join(' ')}"
122
- `libtool -arch_only #{arch} -static -o #{library} #{static_libs.join(' ')}`
123
- library
124
- end
135
+ libs = (ios_architectures + ios_architectures_sim) .map do |arch|
136
+ library = "build-#{arch}/lib#{@spec.name}.a"
137
+ library
125
138
  end
126
139
 
127
140
  UI.message "lipo -create -output #{output} #{libs.join(' ')}"
@@ -166,15 +179,15 @@ module CBin
166
179
  defines += @spec.consumer(@platform).compiler_flags.join(' ')
167
180
 
168
181
  options = ios_build_options
169
- if is_debug_model
182
+ # if is_debug_model
170
183
  archs = ios_architectures
171
184
  # archs = %w[arm64 armv7 armv7s]
172
185
  archs.map do |arch|
173
186
  xcodebuild(defines, "ARCHS=\'#{arch}\' OTHER_CFLAGS=\'-fembed-bitcode -Qunused-arguments\'","build-#{arch}",@build_model)
174
187
  end
175
- else
176
- xcodebuild(defines,options)
177
- end
188
+ # else
189
+ # xcodebuild(defines,options)
190
+ # end
178
191
 
179
192
  defines
180
193
  end
@@ -186,14 +199,14 @@ module CBin
186
199
  def target_name
187
200
  #区分多平台,如配置了多平台,会带上平台的名字
188
201
  # 如libwebp-iOS
189
- # if @spec.available_platforms.count > 1
190
- # "#{@spec.name}-#{Platform.string_name(@spec.consumer(@platform).platform_name)}"
191
- # else
192
- @spec.name
193
- # end
202
+ if @spec.available_platforms.count > 1
203
+ "#{@spec.name}-#{Platform.string_name(@spec.consumer(@platform).platform_name)}"
204
+ else
205
+ @spec.name
206
+ end
194
207
  end
195
208
 
196
- def xcodebuild(defines = '', args = '', build_dir = 'build',build_model = 'Debug')
209
+ def xcodebuild(defines = '', args = '', build_dir = 'build', build_model = 'Debug')
197
210
 
198
211
  unless File.exist?("Pods.xcodeproj") #cocoapods-generate v2.0.0
199
212
  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 2>&1"
@@ -248,10 +261,10 @@ module CBin
248
261
  if Pathname(module_map_file).exist?
249
262
  module_map = File.read(module_map_file)
250
263
  end
251
- elsif public_headers.map(&:basename).map(&:to_s).include?("#{@spec.name}.h")
264
+ elsif public_headers.map(&:basename).map(&:to_s).include?("#{@spec.name}-umbrella.h")
252
265
  module_map = <<-MAP
253
266
  framework module #{@spec.name} {
254
- umbrella header "#{@spec.name}.h"
267
+ umbrella header "#{@spec.name}-umbrella.h"
255
268
 
256
269
  export *
257
270
  module * { export * }
@@ -265,9 +278,29 @@ module CBin
265
278
  framework.module_map_path.mkpath
266
279
  end
267
280
  File.write("#{framework.module_map_path}/module.modulemap", module_map)
281
+
282
+ # unless framework.swift_module_path.exist?
283
+ # framework.swift_module_path.mkpath
284
+ # end
285
+ # todo 所有架构的swiftModule拷贝到 framework.swift_module_path
286
+ archs = ios_architectures + ios_architectures_sim
287
+ archs.map do |arch|
288
+ swift_module = "build-#{arch}/#{@spec.name}.swiftmodule"
289
+ if File.directory?(swift_module)
290
+ FileUtils.cp_r("#{swift_module}/.", framework.swift_module_path)
291
+ end
292
+ end
293
+ swift_Compatibility_Header = "build-#{archs.first}/Swift\ Compatibility\ Header/#{@spec.name}-Swift.h"
294
+ FileUtils.cp(swift_Compatibility_Header,framework.headers_path) if File.exist?(swift_Compatibility_Header)
295
+ info_plist_file = File.join(File.dirname(__FILE__),"info.plist")
296
+ FileUtils.cp(info_plist_file,framework.fwk_path)
268
297
  end
269
298
  end
270
299
 
300
+ def copy_swift_header
301
+
302
+ end
303
+
271
304
  def copy_license
272
305
  UI.message 'Copying license'
273
306
  license_file = @spec.license[:file] || 'LICENSE'
@@ -300,13 +333,18 @@ module CBin
300
333
  `cp -rp #{bundle_files} #{framework.resources_path} 2>&1`
301
334
  end
302
335
 
303
- spec_source_dir = File.join(Dir.pwd,"#{@spec.name}")
304
- unless File.exist?(spec_source_dir)
305
- spec_source_dir = File.join(Dir.pwd,"Pods/#{@spec.name}")
336
+ real_source_dir = @source_dir
337
+ unless @isRootSpec
338
+ spec_source_dir = File.join(Dir.pwd,"#{@spec.name}")
339
+ unless File.exist?(spec_source_dir)
340
+ spec_source_dir = File.join(Dir.pwd,"Pods/#{@spec.name}")
341
+ end
342
+ raise "copy_resources #{spec_source_dir} no exist " unless File.exist?(spec_source_dir)
343
+
344
+ spec_source_dir = File.join(Dir.pwd,"#{@spec.name}")
345
+ real_source_dir = spec_source_dir
306
346
  end
307
- raise "copy_resources #{spec_source_dir} no exist " unless File.exist?(spec_source_dir)
308
347
 
309
- real_source_dir = @isRootSpec ? @source_dir : spec_source_dir
310
348
  resources = [@spec, *@spec.recursive_subspecs].flat_map do |spec|
311
349
  expand_paths(real_source_dir, spec.consumer(@platform).resources)
312
350
  end.compact.uniq
@@ -333,6 +371,65 @@ module CBin
333
371
  end
334
372
  end
335
373
 
374
+ #---------------------------------swift--------------------------------------#
375
+ # lipo -create .a
376
+ def build_static_framework_machO_for_ios(output)
377
+ UI.message "Building ios framework with archs #{ios_architectures}"
378
+
379
+ static_libs = static_libs_in_sandbox('build') + @vendored_libraries
380
+ ios_architectures.map do |arch|
381
+ static_libs += static_libs_in_sandbox("build-#{arch}") + @vendored_libraries
382
+ end
383
+
384
+ ios_architectures_sim do |arch|
385
+ static_libs += static_libs_in_sandbox("build-#{arch}") + @vendored_libraries
386
+ end
387
+
388
+ build_path = Pathname("build")
389
+ build_path.mkpath unless build_path.exist?
390
+
391
+ libs = (ios_architectures + ios_architectures_sim) .map do |arch|
392
+ library = "build-#{arch}/#{@spec.name}.framework/#{@spec.name}"
393
+ library
394
+ end
395
+
396
+ UI.message "lipo -create -output #{output} #{libs.join(' ')}"
397
+ `lipo -create -output #{output} #{libs.join(' ')}`
398
+ end
399
+
400
+ def copy_static_framework_dir_for_ios
401
+
402
+ archs = ios_architectures + ios_architectures_sim
403
+ framework_dir = "build-#{ios_architectures_sim.first}/#{@spec.name}.framework"
404
+ framework_dir = "build-#{ios_architectures.first}/#{@spec.name}.framework" unless File.exist?(framework_dir)
405
+ unless File.exist?(framework_dir)
406
+ raise "#{framework_dir} path no exist"
407
+ end
408
+ File.join(Dir.pwd, "build-#{ios_architectures_sim.first}/#{@spec.name}.framework")
409
+ FileUtils.cp_r(framework_dir, framework.root_path)
410
+
411
+ # todo 所有架构的swiftModule拷贝到 framework.swift_module_path
412
+ archs.map do |arch|
413
+ swift_module = "build-#{arch}/#{@spec.name}.framework/Modules/#{@spec.name}.swiftmodule"
414
+ if File.directory?(swift_module)
415
+ FileUtils.cp_r("#{swift_module}/.", framework.swift_module_path)
416
+ end
417
+ end
418
+
419
+ # 删除Versions 软链接
420
+ framework.remove_current_version
421
+ end
422
+
423
+ def copy_framework_resources
424
+ resources = Dir.glob("#{framework.fwk_path + Pathname.new('Resources')}/*")
425
+ if resources.count == 0
426
+ framework.delete_resources
427
+ end
428
+ end
429
+
430
+
431
+ #---------------------------------getter and setter--------------------------------------#
432
+
336
433
  def framework
337
434
  @framework ||= begin
338
435
  framework = Framework.new(@spec.name, @platform.name.to_s)
@@ -21,8 +21,11 @@ module CBin
21
21
  # 只允许二进制的 specification subspec 比源码的 specification subspec 多
22
22
  #
23
23
  def valid_sources(code_dependencies = false)
24
- sources = [binary_source, code_source]
25
- sources.reverse! if code_dependencies
24
+ sources = [code_source]
25
+ unless code_dependencies
26
+ sources << binary_source
27
+ sources.reverse!
28
+ end
26
29
  sources
27
30
  end
28
31
 
@@ -20,12 +20,12 @@ module CBin
20
20
  end
21
21
 
22
22
  def create
23
- spec = create_from_code_spec
24
-
25
- # Pod::UI.message '生成二进制 podspec 内容: '
26
- # spec.to_pretty_json.split("\n").each do |text|
27
- # Pod::UI.message text
28
- # end
23
+ # spec = nil
24
+ if CBin::Build::Utils.is_framework(@code_spec)
25
+ spec = create_framework_from_code_spec
26
+ else
27
+ spec = create_from_code_spec
28
+ end
29
29
 
30
30
  spec
31
31
  end
@@ -121,12 +121,69 @@ module CBin
121
121
  @spec.vendored_libraries = binary_vendored_libraries
122
122
  @spec.resources = binary_resources if @spec.attributes_hash.keys.include?("resources")
123
123
  @spec.description = <<-EOF
124
- 「 converted automatically by plugin cocoapods-imy-bin @slj 」
124
+ 「 converted automatically by plugin cocoapods-imy-bin @厦门美柚 - slj 」
125
+ #{@spec.description}
126
+ EOF
127
+ @spec
128
+ end
129
+
130
+ def create_framework_from_code_spec
131
+ @spec = code_spec.dup
132
+ # vendored_frameworks | resources | source | source_files | public_header_files
133
+ # license | resource_bundles | vendored_libraries
134
+
135
+ # Project Linkin
136
+ @spec.vendored_frameworks = "#{code_spec.root.name}.framework"
137
+
138
+ # Resources
139
+ extnames = []
140
+ extnames << '*.bundle' if code_spec_consumer.resource_bundles.any?
141
+ if code_spec_consumer.resources.any?
142
+ extnames += code_spec_consumer.resources.map { |r| File.basename(r) }
143
+ end
144
+ if extnames.any?
145
+ @spec.resources = framework_contents('Resources').flat_map { |r| extnames.map { |e| "#{r}/#{e}" } }
146
+ end
147
+
148
+ # Source Location
149
+ @spec.source = binary_source
150
+
151
+ # Source Code
152
+ # @spec.source_files = framework_contents('Headers/*')
153
+ # @spec.public_header_files = framework_contents('Headers/*')
154
+
155
+ # Unused for binary
156
+ spec_hash = @spec.to_hash
157
+ # spec_hash.delete('license')
158
+ spec_hash.delete('resource_bundles')
159
+ spec_hash.delete('exclude_files')
160
+ spec_hash.delete('preserve_paths')
161
+ # 这里不确定 vendored_libraries 指定的时动态/静态库
162
+ # 如果是静态库的话,需要移除,否则就不移除
163
+ # 最好是静态库都独立成 Pod ,cocoapods-package 打静态库去 collect 目标文件时好做过滤
164
+ # 这里统一只对命名后缀 .a 文件做处理
165
+ # spec_hash.delete('vendored_libraries')
166
+ # libraries 只能假设为动态库不做处理了,如果有例外,需要开发者自行处理
167
+ vendored_libraries = spec_hash.delete('vendored_libraries')
168
+ vendored_libraries = Array(vendored_libraries).reject { |l| l.end_with?('.a') }
169
+ if vendored_libraries.any?
170
+ spec_hash['vendored_libraries'] = vendored_libraries
171
+ end
172
+
173
+ # Filter platforms
174
+ platforms = spec_hash['platforms']
175
+ selected_platforms = platforms.select { |k, _v| @platforms.include?(k) }
176
+ spec_hash['platforms'] = selected_platforms.empty? ? platforms : selected_platforms
177
+
178
+ @spec = Pod::Specification.from_hash(spec_hash)
179
+ @spec.description = <<-EOF
180
+ 「 converted automatically by plugin cocoapods-imy-bin @厦门美柚 - slj 」
125
181
  #{@spec.description}
126
- EOF
182
+ EOF
127
183
  @spec
128
184
  end
129
185
 
186
+
130
187
  def binary_source
131
188
  { http: format(CBin.config.binary_download_url, code_spec.root.name, code_spec.version), type: CBin.config.download_file_type }
132
189
  end