cocoapods-tdf-bin 0.0.1.1

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 (64) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +22 -0
  3. data/README.md +103 -0
  4. data/lib/cocoapods-tdf-bin.rb +2 -0
  5. data/lib/cocoapods-tdf-bin/command.rb +2 -0
  6. data/lib/cocoapods-tdf-bin/command/bin.rb +57 -0
  7. data/lib/cocoapods-tdf-bin/command/bin/archive.rb +222 -0
  8. data/lib/cocoapods-tdf-bin/command/bin/auto.rb +216 -0
  9. data/lib/cocoapods-tdf-bin/command/bin/code.rb +232 -0
  10. data/lib/cocoapods-tdf-bin/command/bin/imy.rb +46 -0
  11. data/lib/cocoapods-tdf-bin/command/bin/init.rb +69 -0
  12. data/lib/cocoapods-tdf-bin/command/bin/initHotKey.rb +70 -0
  13. data/lib/cocoapods-tdf-bin/command/bin/install.rb +44 -0
  14. data/lib/cocoapods-tdf-bin/command/bin/lib/lint.rb +69 -0
  15. data/lib/cocoapods-tdf-bin/command/bin/repo/update.rb +43 -0
  16. data/lib/cocoapods-tdf-bin/command/bin/spec/create.rb +73 -0
  17. data/lib/cocoapods-tdf-bin/command/bin/spec/push.rb +114 -0
  18. data/lib/cocoapods-tdf-bin/command/bin/update.rb +157 -0
  19. data/lib/cocoapods-tdf-bin/config/config.rb +138 -0
  20. data/lib/cocoapods-tdf-bin/config/config_asker.rb +57 -0
  21. data/lib/cocoapods-tdf-bin/config/config_builder.rb +238 -0
  22. data/lib/cocoapods-tdf-bin/config/config_hot_key.rb +103 -0
  23. data/lib/cocoapods-tdf-bin/config/config_hot_key_asker.rb +57 -0
  24. data/lib/cocoapods-tdf-bin/gem_version.rb +10 -0
  25. data/lib/cocoapods-tdf-bin/helpers.rb +5 -0
  26. data/lib/cocoapods-tdf-bin/helpers/Info.plist +0 -0
  27. data/lib/cocoapods-tdf-bin/helpers/build_helper.rb +162 -0
  28. data/lib/cocoapods-tdf-bin/helpers/build_utils.rb +101 -0
  29. data/lib/cocoapods-tdf-bin/helpers/framework.rb +85 -0
  30. data/lib/cocoapods-tdf-bin/helpers/framework_builder.rb +283 -0
  31. data/lib/cocoapods-tdf-bin/helpers/library.rb +54 -0
  32. data/lib/cocoapods-tdf-bin/helpers/library_builder.rb +90 -0
  33. data/lib/cocoapods-tdf-bin/helpers/sources_helper.rb +36 -0
  34. data/lib/cocoapods-tdf-bin/helpers/spec_creator.rb +168 -0
  35. data/lib/cocoapods-tdf-bin/helpers/spec_files_helper.rb +77 -0
  36. data/lib/cocoapods-tdf-bin/helpers/spec_source_creator.rb +228 -0
  37. data/lib/cocoapods-tdf-bin/helpers/upload_helper.rb +89 -0
  38. data/lib/cocoapods-tdf-bin/native.rb +23 -0
  39. data/lib/cocoapods-tdf-bin/native/acknowledgements.rb +27 -0
  40. data/lib/cocoapods-tdf-bin/native/analyzer.rb +55 -0
  41. data/lib/cocoapods-tdf-bin/native/configuration.rb +26 -0
  42. data/lib/cocoapods-tdf-bin/native/file_accessor.rb +28 -0
  43. data/lib/cocoapods-tdf-bin/native/installation_options.rb +25 -0
  44. data/lib/cocoapods-tdf-bin/native/installer.rb +135 -0
  45. data/lib/cocoapods-tdf-bin/native/linter.rb +26 -0
  46. data/lib/cocoapods-tdf-bin/native/path_source.rb +33 -0
  47. data/lib/cocoapods-tdf-bin/native/pod_source_installer.rb +19 -0
  48. data/lib/cocoapods-tdf-bin/native/pod_target_installer.rb +94 -0
  49. data/lib/cocoapods-tdf-bin/native/podfile.rb +91 -0
  50. data/lib/cocoapods-tdf-bin/native/podfile_env.rb +37 -0
  51. data/lib/cocoapods-tdf-bin/native/podfile_generator.rb +199 -0
  52. data/lib/cocoapods-tdf-bin/native/podspec_finder.rb +25 -0
  53. data/lib/cocoapods-tdf-bin/native/resolver.rb +243 -0
  54. data/lib/cocoapods-tdf-bin/native/sandbox_analyzer.rb +34 -0
  55. data/lib/cocoapods-tdf-bin/native/source.rb +35 -0
  56. data/lib/cocoapods-tdf-bin/native/sources_manager.rb +20 -0
  57. data/lib/cocoapods-tdf-bin/native/specification.rb +31 -0
  58. data/lib/cocoapods-tdf-bin/native/target_validator.rb +41 -0
  59. data/lib/cocoapods-tdf-bin/native/validator.rb +40 -0
  60. data/lib/cocoapods-tdf-bin/source_provider_hook.rb +54 -0
  61. data/lib/cocoapods_plugin.rb +3 -0
  62. data/spec/command/bin_spec.rb +12 -0
  63. data/spec/spec_helper.rb +50 -0
  64. metadata +179 -0
@@ -0,0 +1,57 @@
1
+ require 'yaml'
2
+ require 'cocoapods-tdf-bin/config/config_hot_key'
3
+
4
+ module CBin
5
+ class Config_Hot_Key
6
+ class Asker
7
+ def show_prompt
8
+ print ' > '.green
9
+ end
10
+
11
+ def ask_with_answer(question, pre_answer, selection)
12
+ print "\n#{question}\n"
13
+
14
+ print_selection_info = lambda {
15
+ print "可选值:[ #{selection.join(' / ')} ]\n" if selection
16
+ }
17
+ print_selection_info.call
18
+ print "旧值:#{pre_answer}\n" unless pre_answer.nil?
19
+
20
+ answer = ''
21
+ loop do
22
+ show_prompt
23
+ answer = STDIN.gets.chomp.strip
24
+
25
+ if answer == '' && !pre_answer.nil?
26
+ answer = pre_answer
27
+ print answer.yellow
28
+ print "\n"
29
+ end
30
+
31
+ next if answer.empty?
32
+ break if !selection || selection.include?(answer)
33
+
34
+ print_selection_info.call
35
+ end
36
+
37
+ answer
38
+ end
39
+
40
+ def wellcome_message
41
+ print <<~EOF
42
+
43
+ 开始设置快捷键 pod bin imy.
44
+ 所有的信息都会保存在 #{CBin.config_hot_key.config_file} 文件中.
45
+ %w[hot_key.yaml]
46
+ 你可以在对应目录下手动添加编辑该文件. 文件包含的配置信息样式如下:
47
+
48
+ #{CBin.config_hot_key.default_config.to_yaml}
49
+ EOF
50
+ end
51
+
52
+ def done_message
53
+ print "\n设置完成.\n".green
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,10 @@
1
+
2
+ module CBin
3
+ VERSION = '0.0.1.1'
4
+ end
5
+
6
+ module Pod
7
+ def self.match_version?(*version)
8
+ Gem::Dependency.new('', *version).match?('', Pod::VERSION)
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ require 'cocoapods-tdf-bin/helpers/sources_helper'
2
+ require 'cocoapods-tdf-bin/helpers/spec_creator'
3
+ require 'cocoapods-tdf-bin/helpers/spec_files_helper'
4
+ require 'cocoapods-tdf-bin/helpers/spec_source_creator'
5
+ require 'cocoapods-tdf-bin/helpers/build_utils'
@@ -0,0 +1,162 @@
1
+ # copy from https://github.com/CocoaPods/cocoapods-packager
2
+
3
+ require 'cocoapods-tdf-bin/native/podfile'
4
+ require 'cocoapods/command/gen'
5
+ require 'cocoapods/generate'
6
+ require 'cocoapods-tdf-bin/helpers/framework_builder'
7
+ require 'cocoapods-tdf-bin/helpers/library_builder'
8
+ require 'cocoapods-tdf-bin/config/config_builder'
9
+
10
+ module CBin
11
+ class Build
12
+ class Helper
13
+ include Pod
14
+ #class var
15
+ @@build_defines = ""
16
+ #Debug下还待完成
17
+ def initialize(spec,
18
+ platform,
19
+ framework_output,
20
+ zip,
21
+ rootSpec,
22
+ skip_archive = false,
23
+ build_model="Release")
24
+ @spec = spec
25
+ @platform = platform
26
+ @build_model = build_model
27
+ @rootSpec = rootSpec
28
+ @isRootSpec = rootSpec.name == spec.name
29
+ @skip_archive = skip_archive
30
+ @framework_output = framework_output
31
+ @zip = zip
32
+
33
+ @framework_path
34
+ end
35
+
36
+ def build
37
+ UI.section("Building static framework #{@spec}") do
38
+
39
+
40
+ unless @skip_archive
41
+ unless CBin::Build::Utils.is_framework(@spec)
42
+ build_static_library
43
+ zip_static_library
44
+ else
45
+ build_static_framework
46
+ zip_static_framework
47
+ end
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+
54
+ def build_static_framework
55
+ source_dir = Dir.pwd
56
+ file_accessor = Sandbox::FileAccessor.new(Pathname.new('.').expand_path, @spec.consumer(@platform))
57
+ Dir.chdir(workspace_directory) do
58
+ builder = CBin::Framework::Builder.new(@spec, file_accessor, @platform, source_dir, @isRootSpec, @build_model )
59
+ @@build_defines = builder.build if @isRootSpec
60
+ begin
61
+ @framework_path = builder.lipo_build(@@build_defines) unless @skip_archive
62
+ rescue
63
+ @skip_archive = true
64
+ end
65
+ end
66
+ end
67
+
68
+ def build_static_library
69
+ source_dir = zip_dir
70
+ file_accessor = Sandbox::FileAccessor.new(Pathname.new('.').expand_path, @spec.consumer(@platform))
71
+ Dir.chdir(workspace_directory) do
72
+ builder = CBin::Library::Builder.new(@spec, file_accessor, @platform, source_dir,@framework_path)
73
+ builder.build
74
+ end
75
+ end
76
+
77
+ def zip_static_framework
78
+ unless @framework_path
79
+ return
80
+ end
81
+ Dir.chdir(zip_dir) do
82
+ output_name = File.join(zip_dir, "#{framework_name}.zip")
83
+ unless File.exist?(framework_name)
84
+ UI.puts "没有需要压缩的 framework 文件:#{framework_name}"
85
+ return
86
+ end
87
+
88
+ UI.puts "Compressing #{framework_name} into #{output_name}"
89
+ `zip --symlinks -r #{output_name} #{framework_name}`
90
+ end
91
+ end
92
+
93
+ def zip_static_library
94
+ Dir.chdir(zip_dir) do
95
+ output_library = "#{library_name}.zip"
96
+ unless File.exist?(library_name)
97
+ raise Informative, "没有需要压缩的 library 文件:#{library_name}"
98
+ end
99
+
100
+ UI.puts "Compressing #{library_name} into #{output_library}"
101
+
102
+ `zip --symlinks -r #{output_library} #{library_name}`
103
+ end
104
+
105
+ end
106
+
107
+
108
+ def clean_workspace
109
+ UI.puts 'Cleaning workspace'
110
+
111
+ FileUtils.rm_rf(gen_name)
112
+ Dir.chdir(zip_dir) do
113
+ FileUtils.rm_rf(framework_name) if @zip
114
+ FileUtils.rm_rf(library_name)
115
+ FileUtils.rm_rf(framework_name) unless @framework_output
116
+ FileUtils.rm_rf("#{framework_name}.zip") unless @framework_output
117
+ end
118
+ end
119
+
120
+ def framework_name
121
+ CBin::Config::Builder.instance.framework_name(@spec)
122
+ end
123
+
124
+ def framework_name_zip
125
+ CBin::Config::Builder.instance.framework_name_version(@spec) + ".zip"
126
+ end
127
+
128
+ def library_name
129
+ CBin::Config::Builder.instance.library_name(@spec)
130
+ end
131
+
132
+ def workspace_directory
133
+ File.expand_path("#{gen_name}/#{@rootSpec.name}")
134
+ end
135
+
136
+ def zip_dir
137
+ CBin::Config::Builder.instance.zip_dir
138
+ end
139
+
140
+ def gen_name
141
+ CBin::Config::Builder.instance.gen_dir
142
+ end
143
+
144
+
145
+ def spec_file
146
+ @spec_file ||= begin
147
+ if @podspec
148
+ find_spec_file(@podspec)
149
+ else
150
+ if code_spec_files.empty?
151
+ raise Informative, '当前目录下没有找到可用源码 podspec.'
152
+ end
153
+
154
+ spec_file = code_spec_files.first
155
+ spec_file
156
+ end
157
+ end
158
+ end
159
+
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,101 @@
1
+ require 'yaml'
2
+ require 'cocoapods-tdf-bin/config/config'
3
+
4
+ module CBin
5
+ class Build
6
+
7
+ class Utils
8
+
9
+ def Utils.is_framework(spec)
10
+ return true
11
+ # if Utils.uses_frameworks?
12
+ # return true
13
+ # end
14
+ #
15
+ # return Utils.is_swift_module(spec)
16
+ end
17
+
18
+ def Utils.spec_header_dir(spec)
19
+
20
+ header_dir = "./Headers/Public/#{spec.name}"
21
+ header_dir = "./Pods/Headers/Public/#{spec.name}" unless File.exist?(header_dir)
22
+
23
+ unless File.exist?(header_dir)
24
+ # 一些库名称中使用了中划线如AAA-BBB,public header中库名称会默认处理成下划线AAA_BBB
25
+ module_name = spec.name.gsub("-", "_")
26
+ header_dir = "./Pods/Headers/Public/#{module_name}"
27
+ end
28
+
29
+ # 暂时只支持:ios
30
+ consumer = Pod::Specification::Consumer.new(spec, :ios)
31
+ unless consumer.header_dir.nil?
32
+ header_dir = File.join(header_dir, consumer.header_dir)
33
+ end
34
+
35
+ header_dir
36
+ end
37
+
38
+ def Utils.spec_module_dir(spec)
39
+ if spec.module_name.nil?
40
+ module_dir = "./Headers/Public/#{spec.name}"
41
+ module_dir = "./Pods/Headers/Public/#{spec.name}" unless File.exist?(module_dir)
42
+ unless File.exist?(module_dir)
43
+ # 一些库名称中使用了中划线如AAA-BBB,public header中库名称会默认处理成下划线AAA_BBB
44
+ module_name = spec.name.gsub("-", "_")
45
+ module_dir = "./Pods/Headers/Public/#{module_name}"
46
+ end
47
+ else
48
+ module_dir = "./Headers/Public/#{spec.module_name}"
49
+ module_dir = "./Pods/Headers/Public/#{spec.module_name}" unless File.exist?(module_dir)
50
+ end
51
+
52
+ module_dir
53
+ end
54
+
55
+ def Utils.is_swift_module(spec)
56
+
57
+ is_framework = false
58
+ dir = File.join(CBin::Config::Builder.instance.gen_dir, CBin::Config::Builder.instance.target_name)
59
+ #auto 走这里
60
+ if File.exist?(dir)
61
+ Dir.chdir(dir) do
62
+ spec_module_dir = Utils.spec_module_dir(spec)
63
+ return false unless File.exist?(spec_module_dir)
64
+ is_framework = File.exist?(File.join(spec_module_dir, "#{spec.name}-umbrella.h"))
65
+ end
66
+ end
67
+
68
+ if $ARGV[1] == "local"
69
+ is_framework = File.exist?(File.join(CBin::Config::Builder.instance.xcode_build_dir, "#{spec.name}.framework"))
70
+ unless is_framework
71
+ is_framework = File.exist?(File.join(CBin::Config::Builder.instance.xcode_BuildProductsPath_dir, "#{spec.name}","Swift Compatibility Header"))
72
+ end
73
+ end
74
+
75
+ is_framework
76
+ end
77
+
78
+ def Utils.uses_frameworks?
79
+ uses_frameworks = false
80
+ # podfile_path = Pod::Config.instance.installation_root.to_s + "/Example/podfile"
81
+ # begin
82
+ # podfile = Pod::Podfile.from_file(podfile_path)
83
+ # rescue
84
+ # podfile = Pod::Config.instance.podfile
85
+ # end
86
+ Pod::Config.instance.podfile.target_definitions.each do |key,value|
87
+ if key != "Pods"
88
+ uses_frameworks = value.uses_frameworks?
89
+ if uses_frameworks
90
+ break ;
91
+ end
92
+ end
93
+ end
94
+
95
+ return uses_frameworks
96
+ end
97
+
98
+ end
99
+
100
+ end
101
+ end
@@ -0,0 +1,85 @@
1
+ # copy from https://github.com/CocoaPods/cocoapods-packager
2
+
3
+ module CBin
4
+ class Framework
5
+ attr_reader :headers_path
6
+ attr_reader :module_map_path
7
+ attr_reader :resources_path
8
+ attr_reader :root_path
9
+ attr_reader :versions_path
10
+ attr_reader :swift_module_path
11
+ attr_reader :fwk_path
12
+
13
+ def initialize(name, platform)
14
+ @name = name
15
+ @platform = platform
16
+ end
17
+
18
+ def make
19
+ make_root
20
+ make_framework
21
+ make_headers
22
+ make_resources
23
+ make_current_version
24
+ end
25
+
26
+ def delete_resources
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}/`
45
+ end
46
+
47
+ private
48
+
49
+ def make_current_version
50
+ current_version_path = @versions_path + Pathname.new('../Current')
51
+ `ln -sf A #{current_version_path}`
52
+ `ln -sf Versions/Current/Headers #{@fwk_path}/`
53
+ `ln -sf Versions/Current/Resources #{@fwk_path}/`
54
+ `ln -sf Versions/Current/#{@name} #{@fwk_path}/`
55
+ end
56
+
57
+
58
+
59
+ def make_framework
60
+ @fwk_path = @root_path + Pathname.new(@name + '.framework')
61
+ @fwk_path.mkdir unless @fwk_path.exist?
62
+
63
+ @module_map_path = @fwk_path + Pathname.new('Modules')
64
+ @swift_module_path = @module_map_path + Pathname.new(@name + '.swiftmodule')
65
+
66
+
67
+ @versions_path = @fwk_path + Pathname.new('Versions/A')
68
+ end
69
+
70
+ def make_headers
71
+ @headers_path = @versions_path + Pathname.new('Headers')
72
+ @headers_path.mkpath unless @headers_path.exist?
73
+ end
74
+
75
+ def make_resources
76
+ @resources_path = @versions_path + Pathname.new('Resources')
77
+ @resources_path.mkpath unless @resources_path.exist?
78
+ end
79
+
80
+ def make_root
81
+ @root_path = Pathname.new(@platform)
82
+ @root_path.mkpath unless @root_path.exist?
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,283 @@
1
+ # copy from https://github.com/CocoaPods/cocoapods-packager
2
+
3
+ require 'cocoapods-tdf-bin/helpers/framework.rb'
4
+ require 'English'
5
+ require 'cocoapods-tdf-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, file_accessor, platform, source_dir, isRootSpec = true, build_model="Debug")
14
+ @spec = spec
15
+ @source_dir = source_dir
16
+ @file_accessor = file_accessor
17
+ @platform = platform
18
+ @build_model = build_model
19
+ @isRootSpec = isRootSpec
20
+ #vendored_static_frameworks 只有 xx.framework 需要拼接为 xx.framework/xx by slj
21
+ vendored_static_frameworks = file_accessor.vendored_static_frameworks.map do |framework|
22
+ path = framework
23
+ extn = File.extname path
24
+ if extn.downcase == '.framework'
25
+ path = File.join(path,File.basename(path, extn))
26
+ end
27
+ path
28
+ end
29
+
30
+ @vendored_libraries = (vendored_static_frameworks + file_accessor.vendored_static_libraries).map(&:to_s)
31
+ end
32
+
33
+ def build
34
+ defines = compile
35
+ build_sim_libraries(defines)
36
+
37
+ defines
38
+ end
39
+
40
+ def lipo_build(defines)
41
+ UI.section("Building static Library #{@spec}") do
42
+
43
+ cp_framework_to_source_dir
44
+ build_static_library_for_ios
45
+
46
+ copy_resources
47
+
48
+ end
49
+ framework
50
+ end
51
+
52
+ private
53
+
54
+ def cp_framework_to_source_dir
55
+ framework_name = "#{@spec.name}.framework"
56
+ framework_dir = "./build-armv7/#{framework_name}" if File.exist?('./build-armv7')
57
+ framework_dir = "./build-arm64/#{framework_name}" if File.exist?('./build-arm64')
58
+ target_dir = File.join(CBin::Config::Builder.instance.zip_dir,framework_name)
59
+
60
+ zip_dir = CBin::Config::Builder.instance.zip_dir
61
+ FileUtils.mkdir_p(zip_dir) unless File.exist?(zip_dir)
62
+
63
+ `cp -fa #{framework_dir} #{target_dir}`
64
+ end
65
+
66
+ def cp_to_source_dir
67
+ framework_name = "#{@spec.name}.framework"
68
+ target_dir = File.join(CBin::Config::Builder.instance.zip_dir,framework_name)
69
+ FileUtils.rm_rf(target_dir) if File.exist?(target_dir)
70
+
71
+ zip_dir = CBin::Config::Builder.instance.zip_dir
72
+ FileUtils.mkdir_p(zip_dir) unless File.exist?(zip_dir)
73
+
74
+ `cp -fa #{@platform}/#{framework_name} #{target_dir}`
75
+ end
76
+
77
+ #模拟器,目前只支持 debug x86-64
78
+ def build_sim_libraries(defines)
79
+ UI.message 'Building simulator libraries'
80
+
81
+ # archs = %w[i386 x86_64]
82
+ archs = ios_architectures_sim
83
+ archs.map do |arch|
84
+ xcodebuild(defines, "-sdk iphonesimulator ARCHS=\'#{arch}\' ", "build-#{arch}",@build_model)
85
+ end
86
+ end
87
+
88
+
89
+ def static_libs_in_sandbox(build_dir = 'build')
90
+ file = Dir.glob("#{build_dir}/lib#{target_name}.a")
91
+ unless file
92
+ UI.warn "file no find = #{build_dir}/lib#{target_name}.a"
93
+ end
94
+ file
95
+ end
96
+
97
+ =begin
98
+ lipo合并 二进制
99
+ =end
100
+ def build_static_library_for_ios
101
+ UI.message "Building ios libraries with archs #{ios_architectures}"
102
+
103
+ framework_name = "#{@spec.name}.framework/#{@spec.name}"
104
+ output = File.join(CBin::Config::Builder.instance.zip_dir,framework_name)
105
+
106
+ build_path = Pathname("build")
107
+ build_path.path unless build_path.exist?
108
+
109
+ # if is_debug_model
110
+ libs = (ios_architectures + ios_architectures_sim) .map do |arch|
111
+ library = "build-#{arch}/#{@spec.name}.framework/#{@spec.name}"
112
+ library
113
+ end
114
+
115
+ UI.message "lipo -create -output #{output} #{libs.join(' ')}"
116
+ `lipo -create -output #{output} #{libs.join(' ')}`
117
+ end
118
+
119
+ def ios_build_options
120
+ "ARCHS=\'#{ios_architectures.join(' ')}\' OTHER_CFLAGS=\'-fembed-bitcode -Qunused-arguments\'"
121
+ end
122
+
123
+ def ios_architectures
124
+ # >armv7
125
+ # iPhone4
126
+ # iPhone4S
127
+ # >armv7s 去掉
128
+ # iPhone5
129
+ # iPhone5C
130
+ # >arm64
131
+ # iPhone5S(以上)
132
+ # >i386
133
+ # iphone5,iphone5s以下的模拟器
134
+ # >x86_64
135
+ # iphone6以上的模拟器
136
+ archs = %w[arm64 armv7]
137
+ # archs = %w[x86_64 arm64 armv7s i386]
138
+ # @vendored_libraries.each do |library|
139
+ # archs = `lipo -info #{library}`.split & archs
140
+ # end
141
+ archs
142
+ end
143
+
144
+ def ios_architectures_sim
145
+
146
+ archs = %w[x86_64]
147
+ archs
148
+ end
149
+
150
+ def compile
151
+ defines = "GCC_PREPROCESSOR_DEFINITIONS='$(inherited)'"
152
+ defines += ' '
153
+ defines += @spec.consumer(@platform).compiler_flags.join(' ')
154
+
155
+ options = ios_build_options
156
+ # if is_debug_model
157
+ archs = ios_architectures
158
+ # archs = %w[arm64 armv7 armv7s]
159
+ archs.map do |arch|
160
+ xcodebuild(defines, "ARCHS=\'#{arch}\' OTHER_CFLAGS=\'-fembed-bitcode -Qunused-arguments\'","build-#{arch}",@build_model)
161
+ end
162
+ # else
163
+ # xcodebuild(defines,options)
164
+ # end
165
+
166
+ defines
167
+ end
168
+
169
+ def is_debug_model
170
+ @build_model == "Debug"
171
+ end
172
+
173
+ def target_name
174
+ #区分多平台,如配置了多平台,会带上平台的名字
175
+ # 如libwebp-iOS
176
+ if @spec.available_platforms.count > 1
177
+ "#{@spec.name}-#{Platform.string_name(@spec.consumer(@platform).platform_name)}"
178
+ else
179
+ @spec.name
180
+ end
181
+ end
182
+
183
+ def xcodebuild(defines = '', args = '', build_dir = 'build', build_model = 'Debug')
184
+
185
+ unless File.exist?("Pods.xcodeproj") #cocoapods-generate v2.0.0
186
+ 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"
187
+ else
188
+ command = "xcodebuild #{defines} #{args} CONFIGURATION_BUILD_DIR=#{build_dir} clean build -configuration #{build_model} -target #{target_name} -project ./Pods.xcodeproj 2>&1"
189
+ end
190
+
191
+ UI.message "command = #{command}"
192
+ output = `#{command}`.lines.to_a
193
+
194
+ if $CHILD_STATUS.exitstatus != 0
195
+ raise <<~EOF
196
+ Build command failed: #{command}
197
+ Output:
198
+ #{output.map { |line| " #{line}" }.join}
199
+ EOF
200
+
201
+ Process.exit
202
+ end
203
+ end
204
+
205
+ def copy_resources
206
+ resource_dir = './build/*.bundle'
207
+ resource_dir = './build-armv7/*.bundle' if File.exist?('./build-armv7')
208
+ resource_dir = './build-arm64/*.bundle' if File.exist?('./build-arm64')
209
+
210
+ framework_name = "#{@spec.name}.framework"
211
+ resource_target_dir = File.join(CBin::Config::Builder.instance.zip_dir,framework_name,"Resources")
212
+
213
+ FileUtils.mkdir_p(resource_target_dir) unless File.exist?(resource_target_dir)
214
+
215
+ bundles = Dir.glob(resource_dir)
216
+
217
+ bundle_names = [@spec, *@spec.recursive_subspecs].flat_map do |spec|
218
+ consumer = spec.consumer(@platform)
219
+ consumer.resource_bundles.keys +
220
+ consumer.resources.map do |r|
221
+ File.basename(r, '.bundle') if File.extname(r) == 'bundle'
222
+ end
223
+ end.compact.uniq
224
+
225
+ bundles.select! do |bundle|
226
+ bundle_name = File.basename(bundle, '.bundle')
227
+ bundle_names.include?(bundle_name)
228
+ end
229
+
230
+ if bundles.count > 0
231
+ UI.message "Copying bundle files #{bundles}"
232
+ bundle_files = bundles.join(' ')
233
+ `cp -rp #{bundle_files} #{resource_target_dir} 2>&1`
234
+ end
235
+
236
+ real_source_dir = @source_dir
237
+ unless @isRootSpec
238
+ spec_source_dir = File.join(Dir.pwd,"#{@spec.name}")
239
+ unless File.exist?(spec_source_dir)
240
+ spec_source_dir = File.join(Dir.pwd,"Pods/#{@spec.name}")
241
+ end
242
+ raise "copy_resources #{spec_source_dir} no exist " unless File.exist?(spec_source_dir)
243
+
244
+ real_source_dir = spec_source_dir
245
+ end
246
+ resources = [@spec, *@spec.recursive_subspecs].flat_map do |spec|
247
+ expand_paths(real_source_dir, spec.consumer(@platform).resources)
248
+ end.compact.uniq
249
+
250
+ if resources.count == 0 && bundles.count == 0
251
+ framework.delete_resources
252
+ return
253
+ end
254
+
255
+ if resources.count > 0
256
+ #把 路径转义。 避免空格情况下拷贝失败
257
+ escape_resource = []
258
+ resources.each do |source|
259
+ escape_resource << Shellwords.join(source)
260
+ end
261
+ UI.message "Copying resources #{escape_resource}"
262
+ `cp -rp #{escape_resource.join(' ')} #{resource_target_dir}`
263
+ end
264
+ end
265
+
266
+ def expand_paths(source_dir, path_specs)
267
+ path_specs.map do |path_spec|
268
+ Dir.glob(File.join(source_dir, path_spec))
269
+ end
270
+ end
271
+
272
+ def framework
273
+ @framework ||= begin
274
+ framework = Framework.new(@spec.name, @platform.name.to_s)
275
+ framework.make
276
+ framework
277
+ end
278
+ end
279
+
280
+
281
+ end
282
+ end
283
+ end