cocoapods-lhj-bin 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +22 -0
  3. data/README.md +11 -0
  4. data/lib/cocoapods-lhj-bin.rb +2 -0
  5. data/lib/cocoapods-lhj-bin/command.rb +1 -0
  6. data/lib/cocoapods-lhj-bin/command/bin.rb +59 -0
  7. data/lib/cocoapods-lhj-bin/command/bin/archive.rb +233 -0
  8. data/lib/cocoapods-lhj-bin/command/bin/auto.rb +198 -0
  9. data/lib/cocoapods-lhj-bin/command/bin/code.rb +232 -0
  10. data/lib/cocoapods-lhj-bin/command/bin/dup.rb +78 -0
  11. data/lib/cocoapods-lhj-bin/command/bin/init.rb +69 -0
  12. data/lib/cocoapods-lhj-bin/command/bin/initHotKey.rb +70 -0
  13. data/lib/cocoapods-lhj-bin/command/bin/install.rb +44 -0
  14. data/lib/cocoapods-lhj-bin/command/bin/lhj.rb +46 -0
  15. data/lib/cocoapods-lhj-bin/command/bin/lib/lint.rb +69 -0
  16. data/lib/cocoapods-lhj-bin/command/bin/repo/update.rb +43 -0
  17. data/lib/cocoapods-lhj-bin/command/bin/spec/create.rb +73 -0
  18. data/lib/cocoapods-lhj-bin/command/bin/spec/push.rb +115 -0
  19. data/lib/cocoapods-lhj-bin/command/bin/update.rb +153 -0
  20. data/lib/cocoapods-lhj-bin/config/config.rb +137 -0
  21. data/lib/cocoapods-lhj-bin/config/config_asker.rb +57 -0
  22. data/lib/cocoapods-lhj-bin/config/config_builder.rb +216 -0
  23. data/lib/cocoapods-lhj-bin/config/config_hot_key.rb +103 -0
  24. data/lib/cocoapods-lhj-bin/config/config_hot_key_asker.rb +57 -0
  25. data/lib/cocoapods-lhj-bin/gem_version.rb +9 -0
  26. data/lib/cocoapods-lhj-bin/helpers.rb +5 -0
  27. data/lib/cocoapods-lhj-bin/helpers/Info.plist +0 -0
  28. data/lib/cocoapods-lhj-bin/helpers/build_helper.rb +158 -0
  29. data/lib/cocoapods-lhj-bin/helpers/build_utils.rb +93 -0
  30. data/lib/cocoapods-lhj-bin/helpers/framework.rb +85 -0
  31. data/lib/cocoapods-lhj-bin/helpers/framework_builder.rb +444 -0
  32. data/lib/cocoapods-lhj-bin/helpers/library.rb +54 -0
  33. data/lib/cocoapods-lhj-bin/helpers/library_builder.rb +90 -0
  34. data/lib/cocoapods-lhj-bin/helpers/sources_helper.rb +36 -0
  35. data/lib/cocoapods-lhj-bin/helpers/spec_creator.rb +168 -0
  36. data/lib/cocoapods-lhj-bin/helpers/spec_files_helper.rb +75 -0
  37. data/lib/cocoapods-lhj-bin/helpers/spec_source_creator.rb +227 -0
  38. data/lib/cocoapods-lhj-bin/helpers/upload_helper.rb +87 -0
  39. data/lib/cocoapods-lhj-bin/native.rb +19 -0
  40. data/lib/cocoapods-lhj-bin/native/acknowledgements.rb +27 -0
  41. data/lib/cocoapods-lhj-bin/native/analyzer.rb +55 -0
  42. data/lib/cocoapods-lhj-bin/native/file_accessor.rb +28 -0
  43. data/lib/cocoapods-lhj-bin/native/installation_options.rb +25 -0
  44. data/lib/cocoapods-lhj-bin/native/installer.rb +135 -0
  45. data/lib/cocoapods-lhj-bin/native/linter.rb +26 -0
  46. data/lib/cocoapods-lhj-bin/native/path_source.rb +33 -0
  47. data/lib/cocoapods-lhj-bin/native/pod_source_installer.rb +19 -0
  48. data/lib/cocoapods-lhj-bin/native/pod_target_installer.rb +94 -0
  49. data/lib/cocoapods-lhj-bin/native/podfile.rb +91 -0
  50. data/lib/cocoapods-lhj-bin/native/podfile_env.rb +37 -0
  51. data/lib/cocoapods-lhj-bin/native/podfile_generator.rb +199 -0
  52. data/lib/cocoapods-lhj-bin/native/podspec_finder.rb +25 -0
  53. data/lib/cocoapods-lhj-bin/native/resolver.rb +230 -0
  54. data/lib/cocoapods-lhj-bin/native/sandbox_analyzer.rb +34 -0
  55. data/lib/cocoapods-lhj-bin/native/source.rb +35 -0
  56. data/lib/cocoapods-lhj-bin/native/sources_manager.rb +20 -0
  57. data/lib/cocoapods-lhj-bin/native/specification.rb +31 -0
  58. data/lib/cocoapods-lhj-bin/native/target_validator.rb +41 -0
  59. data/lib/cocoapods-lhj-bin/native/validator.rb +40 -0
  60. data/lib/cocoapods-lhj-bin/source_provider_hook.rb +66 -0
  61. data/lib/cocoapods_plugin.rb +2 -0
  62. data/spec/command/bin_spec.rb +12 -0
  63. data/spec/spec_helper.rb +50 -0
  64. metadata +177 -0
@@ -0,0 +1,57 @@
1
+ require 'yaml'
2
+ require 'cocoapods-lhj-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 lhj.
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,9 @@
1
+ module CBin
2
+ VERSION = '0.0.1'
3
+ end
4
+
5
+ module Pod
6
+ def self.match_version?(*version)
7
+ Gem::Dependency.new('', *version).match?('', Pod::VERSION)
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ require 'cocoapods-lhj-bin/helpers/sources_helper'
2
+ require 'cocoapods-lhj-bin/helpers/spec_creator'
3
+ require 'cocoapods-lhj-bin/helpers/spec_files_helper'
4
+ require 'cocoapods-lhj-bin/helpers/spec_source_creator'
5
+ require 'cocoapods-lhj-bin/helpers/build_utils'
@@ -0,0 +1,158 @@
1
+ # copy from https://github.com/CocoaPods/cocoapods-packager
2
+
3
+ require 'cocoapods-lhj-bin/native/podfile'
4
+ require 'cocoapods/command/gen'
5
+ require 'cocoapods/generate'
6
+ require 'cocoapods-lhj-bin/helpers/framework_builder'
7
+ require 'cocoapods-lhj-bin/helpers/library_builder'
8
+ require 'cocoapods-lhj-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
+ build_static_framework
40
+ unless @skip_archive
41
+ unless CBin::Build::Utils.is_framework(@spec)
42
+ build_static_library
43
+ zip_static_library
44
+ else
45
+ zip_static_framework
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+ def build_static_framework
54
+ source_dir = Dir.pwd
55
+ file_accessor = Sandbox::FileAccessor.new(Pathname.new('.').expand_path, @spec.consumer(@platform))
56
+ Dir.chdir(workspace_directory) do
57
+ builder = CBin::Framework::Builder.new(@spec, file_accessor, @platform, source_dir, @isRootSpec, @build_model )
58
+ @@build_defines = builder.build if @isRootSpec
59
+ begin
60
+ @framework_path = builder.lipo_build(@@build_defines) unless @skip_archive
61
+ rescue
62
+ @skip_archive = true
63
+ end
64
+ end
65
+ end
66
+
67
+ def build_static_library
68
+ source_dir = zip_dir
69
+ file_accessor = Sandbox::FileAccessor.new(Pathname.new('.').expand_path, @spec.consumer(@platform))
70
+ Dir.chdir(workspace_directory) do
71
+ builder = CBin::Library::Builder.new(@spec, file_accessor, @platform, source_dir,@framework_path)
72
+ builder.build
73
+ end
74
+ end
75
+
76
+ def zip_static_framework
77
+ Dir.chdir(File.join(workspace_directory, @framework_path.root_path)) do
78
+ output_name = File.join(zip_dir, framework_name_zip)
79
+ unless File.exist?(framework_name)
80
+ UI.puts "没有需要压缩的 framework 文件:#{framework_name}"
81
+ return
82
+ end
83
+
84
+ UI.puts "Compressing #{framework_name} into #{output_name}"
85
+ `zip --symlinks -r #{output_name} #{framework_name}`
86
+ end
87
+ end
88
+
89
+ def zip_static_library
90
+ Dir.chdir(zip_dir) do
91
+ output_library = "#{library_name}.zip"
92
+ unless File.exist?(library_name)
93
+ raise Informative, "没有需要压缩的 library 文件:#{library_name}"
94
+ end
95
+
96
+ UI.puts "Compressing #{library_name} into #{output_library}"
97
+
98
+ `zip --symlinks -r #{output_library} #{library_name}`
99
+ end
100
+
101
+ end
102
+
103
+
104
+ def clean_workspace
105
+ UI.puts 'Cleaning workspace'
106
+
107
+ FileUtils.rm_rf(gen_name)
108
+ Dir.chdir(zip_dir) do
109
+ FileUtils.rm_rf(framework_name) if @zip
110
+ FileUtils.rm_rf(library_name)
111
+ FileUtils.rm_rf(framework_name) unless @framework_output
112
+ FileUtils.rm_rf("#{framework_name}.zip") unless @framework_output
113
+ end
114
+ end
115
+
116
+ def framework_name
117
+ CBin::Config::Builder.instance.framework_name(@spec)
118
+ end
119
+
120
+ def framework_name_zip
121
+ CBin::Config::Builder.instance.framework_name_version(@spec) + ".zip"
122
+ end
123
+
124
+ def library_name
125
+ CBin::Config::Builder.instance.library_name(@spec)
126
+ end
127
+
128
+ def workspace_directory
129
+ File.expand_path("#{gen_name}/#{@rootSpec.name}")
130
+ end
131
+
132
+ def zip_dir
133
+ CBin::Config::Builder.instance.zip_dir
134
+ end
135
+
136
+ def gen_name
137
+ CBin::Config::Builder.instance.gen_dir
138
+ end
139
+
140
+
141
+ def spec_file
142
+ @spec_file ||= begin
143
+ if @podspec
144
+ find_spec_file(@podspec)
145
+ else
146
+ if code_spec_files.empty?
147
+ raise Informative, '当前目录下没有找到可用源码 podspec.'
148
+ end
149
+
150
+ spec_file = code_spec_files.first
151
+ spec_file
152
+ end
153
+ end
154
+ end
155
+
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,93 @@
1
+ require 'yaml'
2
+ require 'cocoapods'
3
+ require 'cocoapods-lhj-bin/config/config'
4
+
5
+ module CBin
6
+ class Build
7
+ class Utils
8
+ def Utils.is_framework(spec)
9
+ return true
10
+ # if Utils.uses_frameworks?
11
+ # return true
12
+ # end
13
+ # return Utils.is_swift_module(spec)
14
+ end
15
+
16
+ def Utils.spec_header_dir(spec)
17
+
18
+ header_dir = "./Headers/Public/#{spec.name}"
19
+ header_dir = "./Pods/Headers/Public/#{spec.name}" unless File.exist?(header_dir)
20
+
21
+ unless File.exist?(header_dir)
22
+ # 一些库名称中使用了中划线如AAA-BBB,public header中库名称会默认处理成下划线AAA_BBB
23
+ module_name = spec.name.gsub("-", "_")
24
+ header_dir = "./Pods/Headers/Public/#{module_name}"
25
+ end
26
+
27
+ # 暂时只支持:ios
28
+ consumer = Pod::Specification::Consumer.new(spec, :ios)
29
+ unless consumer.header_dir.nil?
30
+ header_dir = File.join(header_dir, consumer.header_dir)
31
+ end
32
+
33
+ header_dir
34
+ end
35
+
36
+ def Utils.spec_module_dir(spec)
37
+ if spec.module_name.nil?
38
+ module_dir = "./Headers/Public/#{spec.name}"
39
+ module_dir = "./Pods/Headers/Public/#{spec.name}" unless File.exist?(module_dir)
40
+ unless File.exist?(module_dir)
41
+ # 一些库名称中使用了中划线如AAA-BBB,public header中库名称会默认处理成下划线AAA_BBB
42
+ module_name = spec.name.gsub("-", "_")
43
+ module_dir = "./Pods/Headers/Public/#{module_name}"
44
+ end
45
+ else
46
+ module_dir = "./Headers/Public/#{spec.module_name}"
47
+ module_dir = "./Pods/Headers/Public/#{spec.module_name}" unless File.exist?(module_dir)
48
+ end
49
+
50
+ module_dir
51
+ end
52
+
53
+ def Utils.is_swift_module(spec)
54
+
55
+ is_framework = false
56
+ dir = File.join(CBin::Config::Builder.instance.gen_dir, CBin::Config::Builder.instance.target_name)
57
+ #auto 走这里
58
+ if File.exist?(dir)
59
+ Dir.chdir(dir) do
60
+ spec_module_dir = Utils.spec_module_dir(spec)
61
+ return false unless File.exist?(spec_module_dir)
62
+ is_framework = File.exist?(File.join(spec_module_dir, "#{spec.name}-umbrella.h"))
63
+ end
64
+ end
65
+
66
+ if $ARGV[1] == "local"
67
+ is_framework = File.exist?(File.join(CBin::Config::Builder.instance.xcode_build_dir, "#{spec.name}.framework"))
68
+ unless is_framework
69
+ is_framework = File.exist?(File.join(CBin::Config::Builder.instance.xcode_BuildProductsPath_dir, "#{spec.name}","Swift Compatibility Header"))
70
+ end
71
+ end
72
+
73
+ is_framework
74
+ end
75
+
76
+ def Utils.uses_frameworks?
77
+ uses_frameworks = false
78
+ Pod::Config.instance.podfile.target_definitions.each do |key,value|
79
+ if key != "Pods"
80
+ uses_frameworks = value.uses_frameworks?
81
+ if uses_frameworks
82
+ break;
83
+ end
84
+ end
85
+ end
86
+
87
+ return uses_frameworks
88
+ end
89
+
90
+ end
91
+
92
+ end
93
+ 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,444 @@
1
+ # copy from https://github.com/CocoaPods/cocoapods-packager
2
+
3
+ require 'cocoapods-lhj-bin/helpers/framework'
4
+ require 'cocoapods-lhj-bin/helpers/build_utils'
5
+ require 'English'
6
+ require 'cocoapods-lhj-bin/config/config_builder'
7
+ require 'shellwords'
8
+
9
+ module CBin
10
+ class Framework
11
+ class Builder
12
+ include Pod
13
+ #Debug下还待完成
14
+ def initialize(spec, file_accessor, platform, source_dir, isRootSpec = true, build_model="Debug")
15
+ @spec = spec
16
+ @source_dir = source_dir
17
+ @file_accessor = file_accessor
18
+ @platform = platform
19
+ @build_model = build_model
20
+ @isRootSpec = isRootSpec
21
+ #vendored_static_frameworks 只有 xx.framework 需要拼接为 xx.framework/xx by slj
22
+ vendored_static_frameworks = file_accessor.vendored_static_frameworks.map do |framework|
23
+ path = framework
24
+ extn = File.extname path
25
+ if extn.downcase == '.framework'
26
+ path = File.join(path,File.basename(path, extn))
27
+ end
28
+ path
29
+ end
30
+
31
+ @vendored_libraries = (vendored_static_frameworks + file_accessor.vendored_static_libraries).map(&:to_s)
32
+ end
33
+
34
+ def build
35
+ defines = compile
36
+ build_sim_libraries(defines)
37
+
38
+ defines
39
+ end
40
+
41
+ def lipo_build(defines)
42
+
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
+ #
47
+ # # build_sim_libraries(defines)
48
+ # output = framework.versions_path + Pathname.new(@spec.name)
49
+ #
50
+ # build_static_library_for_ios(output)
51
+ #
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
79
+ # end
80
+
81
+ framework
82
+ end
83
+
84
+ private
85
+
86
+ def cp_to_source_dir
87
+ # 删除Versions 软链接
88
+ framework.remove_current_version if CBin::Build::Utils.is_swift_module(@spec)
89
+
90
+ framework_name = "#{@spec.name}.framework"
91
+ target_dir = File.join(CBin::Config::Builder.instance.zip_dir,framework_name)
92
+ FileUtils.rm_rf(target_dir) if File.exist?(target_dir)
93
+
94
+ zip_dir = CBin::Config::Builder.instance.zip_dir
95
+ FileUtils.mkdir_p(zip_dir) unless File.exist?(zip_dir)
96
+
97
+ `cp -fa #{@platform}/#{framework_name} #{target_dir}`
98
+ end
99
+
100
+ #模拟器,目前只支持 debug x86-64
101
+ def build_sim_libraries(defines)
102
+ UI.message 'Building simulator libraries'
103
+
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)
108
+ end
109
+
110
+ end
111
+
112
+
113
+ def static_libs_in_sandbox(build_dir = 'build')
114
+ file = Dir.glob("#{build_dir}/lib#{target_name}.a")
115
+ unless file
116
+ UI.warn "file no find = #{build_dir}/lib#{target_name}.a"
117
+ end
118
+ file
119
+ end
120
+
121
+ def build_static_library_for_ios(output)
122
+ UI.message "Building ios libraries with archs #{ios_architectures}"
123
+ static_libs = static_libs_in_sandbox('build') + static_libs_in_sandbox('build-simulator') + @vendored_libraries
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
130
+ end
131
+
132
+ build_path = Pathname("build")
133
+ build_path.mkpath unless build_path.exist?
134
+
135
+ libs = (ios_architectures + ios_architectures_sim) .map do |arch|
136
+ library = "build-#{arch}/lib#{@spec.name}.a"
137
+ library
138
+ end
139
+
140
+ UI.message "lipo -create -output #{output} #{libs.join(' ')}"
141
+ `lipo -create -output #{output} #{libs.join(' ')}`
142
+ end
143
+
144
+ def ios_build_options
145
+ "ARCHS=\'#{ios_architectures.join(' ')}\' OTHER_CFLAGS=\'-fembed-bitcode -Qunused-arguments\'"
146
+ end
147
+
148
+ def ios_architectures
149
+ # >armv7
150
+ # iPhone4
151
+ # iPhone4S
152
+ # >armv7s 去掉
153
+ # iPhone5
154
+ # iPhone5C
155
+ # >arm64
156
+ # iPhone5S(以上)
157
+ # >i386
158
+ # iphone5,iphone5s以下的模拟器
159
+ # >x86_64
160
+ # iphone6以上的模拟器
161
+ archs = %w[arm64]
162
+ # archs = %w[x86_64 arm64 armv7s i386]
163
+ # @vendored_libraries.each do |library|
164
+ # archs = `lipo -info #{library}`.split & archs
165
+ # end
166
+ archs
167
+ end
168
+
169
+ def ios_architectures_sim
170
+
171
+ archs = %w[x86_64]
172
+ # TODO 处理是否需要 i386
173
+ archs
174
+ end
175
+
176
+ def compile
177
+ defines = "GCC_PREPROCESSOR_DEFINITIONS='$(inherited)'"
178
+ defines += ' '
179
+ defines += @spec.consumer(@platform).compiler_flags.join(' ')
180
+
181
+ options = ios_build_options
182
+ # if is_debug_model
183
+ archs = ios_architectures
184
+ # archs = %w[arm64 armv7 armv7s]
185
+ archs.map do |arch|
186
+ xcodebuild(defines, "ARCHS=\'#{arch}\' OTHER_CFLAGS=\'-fembed-bitcode -Qunused-arguments\'","build-#{arch}",@build_model)
187
+ end
188
+ # else
189
+ # xcodebuild(defines,options)
190
+ # end
191
+
192
+ defines
193
+ end
194
+
195
+ def is_debug_model
196
+ @build_model == "Debug"
197
+ end
198
+
199
+ def target_name
200
+ #区分多平台,如配置了多平台,会带上平台的名字
201
+ # 如libwebp-iOS
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
207
+ end
208
+
209
+ def xcodebuild(defines = '', args = '', build_dir = 'build', build_model = 'Debug')
210
+
211
+ unless File.exist?("Pods.xcodeproj") #cocoapods-generate v2.0.0
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"
213
+ else
214
+ command = "xcodebuild #{defines} #{args} CONFIGURATION_BUILD_DIR=#{build_dir} clean build -configuration #{build_model} -target #{target_name} -project ./Pods.xcodeproj 2>&1"
215
+ end
216
+
217
+ UI.message "command = #{command}"
218
+ output = `#{command}`.lines.to_a
219
+
220
+ if $CHILD_STATUS.exitstatus != 0
221
+ raise <<~EOF
222
+ Build command failed: #{command}
223
+ Output:
224
+ #{output.map { |line| " #{line}" }.join}
225
+ EOF
226
+
227
+ Process.exit
228
+ end
229
+ end
230
+
231
+ def copy_headers
232
+ #走 podsepc中的public_headers
233
+ public_headers = Array.new
234
+
235
+ #by slj 如果没有头文件,去 "Headers/Public"拿
236
+ # if public_headers.empty?
237
+ spec_header_dir = "./Headers/Public/#{@spec.name}"
238
+ unless File.exist?(spec_header_dir)
239
+ spec_header_dir = "./Pods/Headers/Public/#{@spec.name}"
240
+ end
241
+ raise "copy_headers #{spec_header_dir} no exist " unless File.exist?(spec_header_dir)
242
+ Dir.chdir(spec_header_dir) do
243
+ headers = Dir.glob('*.h')
244
+ headers.each do |h|
245
+ public_headers << Pathname.new(File.join(Dir.pwd,h))
246
+ end
247
+ end
248
+ # end
249
+
250
+ # UI.message "Copying public headers #{public_headers.map(&:basename).map(&:to_s)}"
251
+
252
+ public_headers.each do |h|
253
+ `ditto #{h} #{framework.headers_path}/#{h.basename}`
254
+ end
255
+
256
+ # If custom 'module_map' is specified add it to the framework distribution
257
+ # otherwise check if a header exists that is equal to 'spec.name', if so
258
+ # create a default 'module_map' one using it.
259
+ if !@spec.module_map.nil?
260
+ module_map_file = @file_accessor.module_map
261
+ if Pathname(module_map_file).exist?
262
+ module_map = File.read(module_map_file)
263
+ end
264
+ elsif public_headers.map(&:basename).map(&:to_s).include?("#{@spec.name}-umbrella.h")
265
+ module_map = <<-MAP
266
+ framework module #{@spec.name} {
267
+ umbrella header "#{@spec.name}-umbrella.h"
268
+
269
+ export *
270
+ module * { export * }
271
+ }
272
+ MAP
273
+ end
274
+
275
+ unless module_map.nil?
276
+ UI.message "Writing module map #{module_map}"
277
+ unless framework.module_map_path.exist?
278
+ framework.module_map_path.mkpath
279
+ end
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)
297
+ end
298
+ end
299
+
300
+ def copy_swift_header
301
+
302
+ end
303
+
304
+ def copy_license
305
+ UI.message 'Copying license'
306
+ license_file = @spec.license[:file] || 'LICENSE'
307
+ `cp "#{license_file}" .` if Pathname(license_file).exist?
308
+ end
309
+
310
+ def copy_resources
311
+ resource_dir = './build/*.bundle'
312
+ resource_dir = './build-armv7/*.bundle' if File.exist?('./build-armv7')
313
+ resource_dir = './build-arm64/*.bundle' if File.exist?('./build-arm64')
314
+
315
+ bundles = Dir.glob(resource_dir)
316
+
317
+ bundle_names = [@spec, *@spec.recursive_subspecs].flat_map do |spec|
318
+ consumer = spec.consumer(@platform)
319
+ consumer.resource_bundles.keys +
320
+ consumer.resources.map do |r|
321
+ File.basename(r, '.bundle') if File.extname(r) == 'bundle'
322
+ end
323
+ end.compact.uniq
324
+
325
+ bundles.select! do |bundle|
326
+ bundle_name = File.basename(bundle, '.bundle')
327
+ bundle_names.include?(bundle_name)
328
+ end
329
+
330
+ if bundles.count > 0
331
+ UI.message "Copying bundle files #{bundles}"
332
+ bundle_files = bundles.join(' ')
333
+ `cp -rp #{bundle_files} #{framework.resources_path} 2>&1`
334
+ end
335
+
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
346
+ end
347
+
348
+ resources = [@spec, *@spec.recursive_subspecs].flat_map do |spec|
349
+ expand_paths(real_source_dir, spec.consumer(@platform).resources)
350
+ end.compact.uniq
351
+
352
+ if resources.count == 0 && bundles.count == 0
353
+ framework.delete_resources
354
+ return
355
+ end
356
+
357
+ if resources.count > 0
358
+ #把 路径转义。 避免空格情况下拷贝失败
359
+ escape_resource = []
360
+ resources.each do |source|
361
+ escape_resource << Shellwords.join(source)
362
+ end
363
+ UI.message "Copying resources #{escape_resource}"
364
+ `cp -rp #{escape_resource.join(' ')} #{framework.resources_path}`
365
+ end
366
+ end
367
+
368
+ def expand_paths(source_dir, path_specs)
369
+ path_specs.map do |path_spec|
370
+ Dir.glob(File.join(source_dir, path_spec))
371
+ end
372
+ end
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
+
433
+ def framework
434
+ @framework ||= begin
435
+ framework = Framework.new(@spec.name, @platform.name.to_s)
436
+ framework.make
437
+ framework
438
+ end
439
+ end
440
+
441
+
442
+ end
443
+ end
444
+ end