cocoapods-bin-forest 1.0.0

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 (63) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +22 -0
  3. data/README.md +1 -0
  4. data/lib/cocoapods-bin-forest/command/bin/archive.rb +198 -0
  5. data/lib/cocoapods-bin-forest/command/bin/auto.rb +199 -0
  6. data/lib/cocoapods-bin-forest/command/bin/code.rb +232 -0
  7. data/lib/cocoapods-bin-forest/command/bin/imy.rb +46 -0
  8. data/lib/cocoapods-bin-forest/command/bin/init.rb +69 -0
  9. data/lib/cocoapods-bin-forest/command/bin/initHotKey.rb +70 -0
  10. data/lib/cocoapods-bin-forest/command/bin/install.rb +44 -0
  11. data/lib/cocoapods-bin-forest/command/bin/lib/lint.rb +69 -0
  12. data/lib/cocoapods-bin-forest/command/bin/repo/update.rb +43 -0
  13. data/lib/cocoapods-bin-forest/command/bin/spec/create.rb +73 -0
  14. data/lib/cocoapods-bin-forest/command/bin/spec/push.rb +114 -0
  15. data/lib/cocoapods-bin-forest/command/bin/update.rb +157 -0
  16. data/lib/cocoapods-bin-forest/command/bin.rb +57 -0
  17. data/lib/cocoapods-bin-forest/command.rb +2 -0
  18. data/lib/cocoapods-bin-forest/config/config.rb +137 -0
  19. data/lib/cocoapods-bin-forest/config/config_asker.rb +57 -0
  20. data/lib/cocoapods-bin-forest/config/config_builder.rb +216 -0
  21. data/lib/cocoapods-bin-forest/config/config_hot_key.rb +103 -0
  22. data/lib/cocoapods-bin-forest/config/config_hot_key_asker.rb +57 -0
  23. data/lib/cocoapods-bin-forest/gem_version.rb +10 -0
  24. data/lib/cocoapods-bin-forest/helpers/Info.plist +0 -0
  25. data/lib/cocoapods-bin-forest/helpers/build_helper.rb +158 -0
  26. data/lib/cocoapods-bin-forest/helpers/build_utils.rb +94 -0
  27. data/lib/cocoapods-bin-forest/helpers/framework.rb +85 -0
  28. data/lib/cocoapods-bin-forest/helpers/framework_builder.rb +351 -0
  29. data/lib/cocoapods-bin-forest/helpers/library.rb +54 -0
  30. data/lib/cocoapods-bin-forest/helpers/library_builder.rb +90 -0
  31. data/lib/cocoapods-bin-forest/helpers/sources_helper.rb +36 -0
  32. data/lib/cocoapods-bin-forest/helpers/spec_creator.rb +170 -0
  33. data/lib/cocoapods-bin-forest/helpers/spec_files_helper.rb +77 -0
  34. data/lib/cocoapods-bin-forest/helpers/spec_source_creator.rb +234 -0
  35. data/lib/cocoapods-bin-forest/helpers/upload_helper.rb +91 -0
  36. data/lib/cocoapods-bin-forest/helpers.rb +5 -0
  37. data/lib/cocoapods-bin-forest/native/acknowledgements.rb +27 -0
  38. data/lib/cocoapods-bin-forest/native/analyzer.rb +55 -0
  39. data/lib/cocoapods-bin-forest/native/file_accessor.rb +28 -0
  40. data/lib/cocoapods-bin-forest/native/installation_options.rb +25 -0
  41. data/lib/cocoapods-bin-forest/native/installer.rb +135 -0
  42. data/lib/cocoapods-bin-forest/native/linter.rb +26 -0
  43. data/lib/cocoapods-bin-forest/native/path_source.rb +33 -0
  44. data/lib/cocoapods-bin-forest/native/pod_source_installer.rb +22 -0
  45. data/lib/cocoapods-bin-forest/native/pod_target_installer.rb +94 -0
  46. data/lib/cocoapods-bin-forest/native/podfile.rb +91 -0
  47. data/lib/cocoapods-bin-forest/native/podfile_env.rb +37 -0
  48. data/lib/cocoapods-bin-forest/native/podfile_generator.rb +200 -0
  49. data/lib/cocoapods-bin-forest/native/podspec_finder.rb +25 -0
  50. data/lib/cocoapods-bin-forest/native/resolver.rb +230 -0
  51. data/lib/cocoapods-bin-forest/native/sandbox_analyzer.rb +34 -0
  52. data/lib/cocoapods-bin-forest/native/source.rb +35 -0
  53. data/lib/cocoapods-bin-forest/native/sources_manager.rb +20 -0
  54. data/lib/cocoapods-bin-forest/native/specification.rb +31 -0
  55. data/lib/cocoapods-bin-forest/native/target_validator.rb +41 -0
  56. data/lib/cocoapods-bin-forest/native/validator.rb +40 -0
  57. data/lib/cocoapods-bin-forest/native.rb +23 -0
  58. data/lib/cocoapods-bin-forest/source_provider_hook.rb +54 -0
  59. data/lib/cocoapods-imy-bin.rb +2 -0
  60. data/lib/cocoapods_plugin.rb +3 -0
  61. data/spec/command/bin_spec.rb +12 -0
  62. data/spec/spec_helper.rb +50 -0
  63. metadata +178 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 07e8a7c880d263b64252315d80240d0014a5dda7c3bccb972a86a6740f11c4d3
4
+ data.tar.gz: b988fbe69be18477b12d41584bb29bc01caea4cca9c427d7e57c6fe26ac3c20b
5
+ SHA512:
6
+ metadata.gz: 576786a009cc98a620df6399ca9ad1f9e9b266db21e26546dabdc51d4f2a4bc3b75825fec899d398ee6d8572903231b79efbeadc8075f7eaece90e928d991112
7
+ data.tar.gz: 4924cdb20abf86ae2fba7d1d977b12fcbb887d1fb0b395ec7414ec1151811e24e490069494ffcf43d021960737cc6dc2ba1767a6325f236cc9238746b8f3bd1d
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2018 tripleCC <triplec.linux@gmail.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,198 @@
1
+ require 'cocoapods-bin-forest/native/podfile'
2
+ require 'cocoapods/command/gen'
3
+ require 'cocoapods/generate'
4
+ require 'cocoapods-bin-forest/helpers/framework_builder'
5
+ require 'cocoapods-bin-forest/helpers/library_builder'
6
+ require 'cocoapods-bin-forest/helpers/build_helper'
7
+ require 'cocoapods-bin-forest/helpers/spec_source_creator'
8
+ require 'cocoapods-bin-forest/config/config_builder'
9
+ require 'cocoapods-bin-forest/command/bin/lib/lint'
10
+
11
+ module Pod
12
+ class Command
13
+ class Bin < Command
14
+ class Archive < Bin
15
+
16
+ @@missing_binary_specs = []
17
+
18
+ self.summary = '将组件归档为静态库 .a.'
19
+ self.description = <<-DESC
20
+ 将组件归档为静态库 framework,仅支持 iOS 平台
21
+ 此静态 framework 不包含依赖组件的 symbol
22
+ DESC
23
+
24
+ def self.options
25
+ [
26
+ ['--all-make', '对该组件的依赖库,全部制作为二进制组件'],
27
+ ['--code-dependencies', '使用源码依赖'],
28
+ ['--no-clean', '保留构建中间产物'],
29
+ ['--sources', '私有源地址,多个用分号区分'],
30
+ ['--framework-output', '输出framework文件'],
31
+ ['--no-zip', '不压缩静态库 为 zip'],
32
+ ['--configuration', 'Build the specified configuration (e.g. Debug). Defaults to Release'],
33
+ ['--env', "该组件上传的环境 %w[dev debug_iphoneos release_iphoneos]"]
34
+ ].concat(Pod::Command::Gen.options).concat(super).uniq
35
+ end
36
+
37
+ self.arguments = [
38
+ CLAide::Argument.new('NAME.podspec', false)
39
+ ]
40
+
41
+ def initialize(argv)
42
+ @env = argv.option('env') || 'dev'
43
+ CBin.config.set_configuration_env(@env)
44
+ UI.warn "====== cocoapods-bin-forest #{CBin::VERSION} 版本 ======== \n "
45
+ UI.warn "====== #{@env} 环境 ======== \n "
46
+
47
+ @code_dependencies = argv.flag?('code-dependencies')
48
+ @framework_output = argv.flag?('framework-output', false )
49
+ @clean = argv.flag?('no-clean', false)
50
+ @zip = argv.flag?('zip', true)
51
+ @all_make = argv.flag?('all-make', false )
52
+ @sources = argv.option('sources') || []
53
+ @platform = Platform.new(:ios)
54
+
55
+ @config = argv.option('configuration', 'Release')
56
+
57
+ @framework_path
58
+ super
59
+
60
+ @additional_args = argv.remainder!
61
+ @build_finshed = false
62
+ end
63
+
64
+ def run
65
+ #清除之前的缓存
66
+ zip_dir = CBin::Config::Builder.instance.zip_dir
67
+ FileUtils.rm_rf(zip_dir) if File.exist?(zip_dir)
68
+
69
+ @spec = Specification.from_file(spec_file)
70
+ generate_project
71
+
72
+ source_specs = Array.new
73
+ source_specs.concat(build_root_spec)
74
+ source_specs.concat(build_dependencies) if @all_make
75
+
76
+ source_specs
77
+ end
78
+
79
+ def build_root_spec
80
+ source_specs = []
81
+ builder = CBin::Build::Helper.new(@spec,
82
+ @platform,
83
+ @framework_output,
84
+ @zip,
85
+ @spec,
86
+ CBin::Config::Builder.instance.white_pod_list.include?(@spec.name),
87
+ @config)
88
+ builder.build
89
+ builder.clean_workspace if @clean && !@all_make
90
+ source_specs << @spec unless CBin::Config::Builder.instance.white_pod_list.include?(@spec.name)
91
+
92
+ source_specs
93
+ end
94
+
95
+ def build_dependencies
96
+ @build_finshed = true
97
+ #如果没要求,就清空依赖库数据
98
+ source_specs = []
99
+ @@missing_binary_specs.uniq.each do |spec|
100
+ next if spec.name.include?('/')
101
+ next if spec.name == @spec.name
102
+ #过滤白名单
103
+ next if CBin::Config::Builder.instance.white_pod_list.include?(spec.name)
104
+ #过滤 git
105
+ if spec.source[:git] && spec.source[:git]
106
+ spec_git = spec.source[:git]
107
+ spec_git_res = false
108
+ CBin::Config::Builder.instance.ignore_git_list.each do |ignore_git|
109
+ spec_git_res = spec_git.include?(ignore_git)
110
+ break if spec_git_res
111
+ end
112
+ next if spec_git_res
113
+ end
114
+ UI.warn "#{spec.name}.podspec 带有 vendored_frameworks 字段,请检查是否有效!!!" if spec.attributes_hash['vendored_frameworks']
115
+ next if spec.attributes_hash['vendored_frameworks'] && @spec.name != spec.name #过滤带有vendored_frameworks的
116
+ next if spec.attributes_hash['ios.vendored_frameworks'] && @spec.name != spec.name #过滤带有vendored_frameworks的
117
+ #获取没有制作二进制版本的spec集合
118
+ source_specs << spec
119
+ end
120
+
121
+ fail_build_specs = []
122
+ source_specs.uniq.each do |spec|
123
+ begin
124
+ builder = CBin::Build::Helper.new(spec,
125
+ @platform,
126
+ @framework_output,
127
+ @zip,
128
+ @spec,
129
+ false ,
130
+ @config)
131
+ builder.build
132
+ rescue Object => exception
133
+ UI.puts exception
134
+ fail_build_specs << spec
135
+ end
136
+ end
137
+
138
+ if fail_build_specs.any?
139
+ fail_build_specs.uniq.each do |spec|
140
+ UI.warn "【#{spec.name} | #{spec.version}】组件二进制版本编译失败 ."
141
+ end
142
+ end
143
+ source_specs - fail_build_specs
144
+ end
145
+
146
+ # 解析器传过来的
147
+ def Archive.missing_binary_specs(missing_binary_specs)
148
+ @@missing_binary_specs = missing_binary_specs unless @build_finshed
149
+ end
150
+
151
+ private
152
+
153
+ def generate_project
154
+ Podfile.execute_with_bin_plugin do
155
+ Podfile.execute_with_use_binaries(!@code_dependencies) do
156
+ argvs = [
157
+ "--sources=#{sources_option(@code_dependencies, @sources)}",
158
+ "--gen-directory=#{CBin::Config::Builder.instance.gen_dir}",
159
+ '--clean',
160
+ *@additional_args
161
+ ]
162
+
163
+ podfile= File.join(Pathname.pwd, "Podfile")
164
+ if File.exist?(podfile)
165
+ argvs += ['--use-podfile']
166
+ end
167
+
168
+ argvs << spec_file if spec_file
169
+
170
+ gen = Pod::Command::Gen.new(CLAide::ARGV.new(argvs))
171
+ gen.validate!
172
+ gen.run
173
+ end
174
+ end
175
+ end
176
+
177
+
178
+ def spec_file
179
+ @spec_file ||= begin
180
+ if @podspec
181
+ find_spec_file(@podspec)
182
+ else
183
+ if code_spec_files.empty?
184
+ raise Informative, '当前目录下没有找到可用源码 podspec.'
185
+ end
186
+
187
+ spec_file = code_spec_files.first
188
+ spec_file
189
+ end
190
+ end
191
+ end
192
+
193
+
194
+
195
+ end
196
+ end
197
+ end
198
+ end
@@ -0,0 +1,199 @@
1
+
2
+ require 'cocoapods-bin-forest/command/bin/auto'
3
+ require 'cocoapods-bin-forest/helpers/upload_helper'
4
+
5
+ module Pod
6
+ class Command
7
+ class Bin < Command
8
+ class Auto < Bin
9
+ self.summary = '打开 workspace 工程.'
10
+
11
+ self.arguments = [
12
+ CLAide::Argument.new('NAME.podspec', false)
13
+ ]
14
+ def self.options
15
+ [
16
+ ['--code-dependencies', '使用源码依赖'],
17
+ ['--allow-prerelease', '允许使用 prerelease 的版本'],
18
+ ['--no-clean', '保留构建中间产物'],
19
+ ['--framework-output', '输出framework文件'],
20
+ ['--no-zip', '不压缩静态 framework 为 zip'],
21
+ ['--all-make', '对该组件的依赖库,全部制作为二进制组件'],
22
+ ['--configuration', 'Build the specified configuration (e.g. Release ). Defaults to Debug'],
23
+ ['--env', "该组件上传的环境 %w[dev debug_iphoneos release_iphoneos]"]
24
+ ].concat(Pod::Command::Gen.options).concat(super).uniq
25
+ end
26
+
27
+ def initialize(argv)
28
+
29
+ @env = argv.option('env') || 'dev'
30
+ CBin.config.set_configuration_env(@env)
31
+
32
+ @podspec = argv.shift_argument || find_podspec
33
+ @specification = Specification.from_file(@podspec)
34
+
35
+ @code_dependencies = argv.flag?('code-dependencies')
36
+ @allow_prerelease = argv.flag?('allow-prerelease')
37
+ @framework_output = argv.flag?('framework-output', false )
38
+ @clean = argv.flag?('clean', true)
39
+ @zip = argv.flag?('zip', true)
40
+ @all_make = argv.flag?('all-make', false )
41
+ @verbose = argv.flag?('verbose',true)
42
+
43
+ @config = argv.option('configuration', 'Debug')
44
+ @additional_args = argv.remainder!
45
+
46
+ super
47
+ end
48
+
49
+ def validate!
50
+ help! "未找到 podspec文件" unless @podspec
51
+ super
52
+ end
53
+
54
+ def run
55
+ @specification = Specification.from_file(@podspec)
56
+
57
+ source_specs = run_archive
58
+
59
+ fail_push_specs = []
60
+ source_specs.uniq.each do |spec|
61
+ begin
62
+ fail_push_specs << spec unless CBin::Upload::Helper.new(spec,@code_dependencies,@sources).upload
63
+ rescue Object => exception
64
+ UI.puts exception
65
+ fail_push_specs << spec
66
+ end
67
+ end
68
+
69
+ if fail_push_specs.any?
70
+ fail_push_specs.uniq.each do |spec|
71
+ UI.warn "【#{spec.name} | #{spec.version}】组件spec push失败 ."
72
+ end
73
+ end
74
+
75
+ success_specs = source_specs - fail_push_specs
76
+ if success_specs.any?
77
+ auto_success = ""
78
+ success_specs.uniq.each do |spec|
79
+ auto_success += "#{spec.name} | #{spec.version}\n"
80
+ UI.warn "===【 #{spec.name} | #{spec.version} 】二进制组件制作完成 !!! "
81
+ end
82
+ puts "============== auto_success"
83
+ puts auto_success
84
+ ENV['auto_success'] = auto_success
85
+ end
86
+ #pod repo update
87
+ UI.section("\nUpdating Spec Repositories\n".yellow) do
88
+ Pod::Command::Bin::Repo::Update.new(CLAide::ARGV.new([])).run
89
+ end
90
+
91
+ end
92
+
93
+ #制作二进制包
94
+
95
+ def run_archive
96
+ argvs = [
97
+ "--sources=#{sources_option(@code_dependencies, @sources)},https:\/\/cdn.cocoapods.org",
98
+ @additional_args
99
+ ]
100
+
101
+ argvs << spec_file if spec_file
102
+ argvs.delete(Array.new)
103
+
104
+ unless @clean
105
+ argvs += ['--no-clean']
106
+ end
107
+ if @code_dependencies
108
+ argvs += ['--code-dependencies']
109
+ end
110
+ if @verbose
111
+ argvs += ['--verbose']
112
+ end
113
+ if @allow_prerelease
114
+ argvs += ['--allow-prerelease']
115
+ end
116
+ if @framework_output
117
+ argvs += ['--framework-output']
118
+ end
119
+ if @all_make
120
+ argvs += ['--all-make']
121
+ end
122
+ if @env
123
+ argvs += ["--env=#{@env}"]
124
+ end
125
+ argvs += ["--configuration=#{@config}"]
126
+
127
+ archive = Pod::Command::Bin::Archive.new(CLAide::ARGV.new(argvs))
128
+ archive.validate!
129
+ source_specs = archive.run
130
+ source_specs
131
+ end
132
+
133
+
134
+ def code_podsepc_extname
135
+ '.podsepc'
136
+ end
137
+
138
+ def binary_podsepc_json
139
+ "#{@specification.name}.binary.podspec.json"
140
+ end
141
+
142
+ def binary_template_podsepc
143
+ "#{@specification.name}.binary-template.podspec"
144
+ end
145
+
146
+ def template_spec_file
147
+ @template_spec_file ||= begin
148
+ if @template_podspec
149
+ find_spec_file(@template_podspec)
150
+ else
151
+ binary_template_spec_file
152
+ end
153
+ end
154
+ end
155
+
156
+ def spec_file
157
+ @spec_file ||= begin
158
+ if @podspec
159
+ find_spec_file(@podspec) || @podspec
160
+ else
161
+ if code_spec_files.empty?
162
+ raise Informative, '当前目录下没有找到可用源码 podspec.'
163
+ end
164
+
165
+ spec_file = if @binary
166
+ code_spec = Pod::Specification.from_file(code_spec_files.first)
167
+ if template_spec_file
168
+ template_spec = Pod::Specification.from_file(template_spec_file)
169
+ end
170
+ create_binary_spec_file(code_spec, template_spec)
171
+ else
172
+ code_spec_files.first
173
+ end
174
+ spec_file
175
+ end
176
+ end
177
+ end
178
+
179
+ #Dir.glob 可替代
180
+ def find_podspec
181
+ name = nil
182
+ Pathname.pwd.children.each do |child|
183
+ puts child
184
+ if File.file?(child)
185
+ if child.extname == '.podspec'
186
+ name = File.basename(child)
187
+ unless name.include?("binary-template")
188
+ return name
189
+ end
190
+ end
191
+ end
192
+ end
193
+ return name
194
+ end
195
+
196
+ end
197
+ end
198
+ end
199
+ end
@@ -0,0 +1,232 @@
1
+
2
+ module Pod
3
+ class Command
4
+ class Bin < Command
5
+ class Code < Bin
6
+ self.summary = '通过将二进制对应源码放置在临时目录中,让二进制出现断点时可以跳到对应的源码,方便调试。'
7
+
8
+ self.description = <<-DESC
9
+ 通过将二进制对应源码放置在临时目录中,让二进制出现断点时可以跳到对应的源码,方便调试。
10
+ 在不删除二进制的情况下为某个组件添加源码调试能力,多个组件名称用空格分隔
11
+ DESC
12
+
13
+ self.arguments = [
14
+ CLAide::Argument.new('NAME', false)
15
+ ]
16
+ def self.options
17
+ [
18
+ ['--all-clean', '删除所有已经下载的源码'],
19
+ ['--clean', '删除所有指定下载的源码'],
20
+ ['--list', '展示所有一级下载的源码以及其大小'],
21
+ ['--source', '源码路径,本地路径,会去自动链接本地源码']
22
+ ]
23
+ end
24
+
25
+ def initialize(argv)
26
+ @codeSource = argv.option('source') || nil
27
+ @names = argv.arguments! unless argv.arguments.empty?
28
+ @list = argv.flag?('list', false )
29
+ @all_clean = argv.flag?('all-clean', false )
30
+ @clean = argv.flag?('clean', false )
31
+
32
+ @config = Pod::Config.instance
33
+
34
+ super
35
+ end
36
+
37
+
38
+ def run
39
+
40
+ podfile_lock = File.join(Pathname.pwd,"Podfile.lock")
41
+ raise "podfile.lock,不存在,请先pod install/update" unless File.exist?(podfile_lock)
42
+ @lockfile ||= Lockfile.from_file(Pathname.new(podfile_lock) )
43
+
44
+ if @list
45
+ list
46
+ elsif @clean
47
+ clean
48
+ elsif @all_clean
49
+ all_clean
50
+ elsif @names
51
+ add
52
+ end
53
+
54
+ if @list && @clean && @names
55
+ raise "请选择您要执行的命令。"
56
+ end
57
+ end
58
+
59
+ #==========================begin add ==============
60
+
61
+ def add
62
+ if @names == nil
63
+ raise "请输入要调试组件名,多个组件名称用空格分隔"
64
+ end
65
+
66
+ @names.each do |name|
67
+ lib_file = get_lib_path(name)
68
+ unless File.exist?(lib_file)
69
+ raise "找不到 #{lib_file}"
70
+ end
71
+ UI.puts "#{lib_file}"
72
+
73
+ target_path = @codeSource || download_source(name)
74
+
75
+ link(lib_file,target_path,name)
76
+ end
77
+ end
78
+
79
+ #下载源码到本地
80
+ def download_source(name)
81
+ target_path = File.join(source_root, name)
82
+ UI.puts target_path
83
+ FileUtils.rm_rf(target_path)
84
+
85
+ find_dependency = find_dependency(name)
86
+
87
+ spec = fetch_external_source(find_dependency, @config.podfile,@config.lockfile, @config.sandbox,true )
88
+
89
+ download_request = Pod::Downloader::Request.new(:name => name, :spec => spec)
90
+ Downloader.download(download_request, Pathname.new(target_path), :can_cache => true)
91
+
92
+ target_path
93
+ end
94
+
95
+ #找出依赖
96
+ def find_dependency (name)
97
+ find_dependency = nil
98
+ @config.podfile.dependencies.each do |dependency|
99
+ if dependency.root_name.downcase == name.downcase
100
+ find_dependency = dependency
101
+ break
102
+ end
103
+ end
104
+ find_dependency
105
+ end
106
+
107
+ # 获取external_source 下的仓库
108
+ # @return spec
109
+ def fetch_external_source(dependency ,podfile , lockfile, sandbox,use_lockfile_options)
110
+ source = ExternalSources.from_dependency(dependency, podfile.defined_in_file, true)
111
+ source.fetch(sandbox)
112
+ end
113
+
114
+
115
+ #==========================link begin ==============
116
+
117
+ #链接,.a文件位置, 源码目录,工程名=IMYFoundation
118
+ def link(lib_file,target_path,basename)
119
+ dir = (`dwarfdump "#{lib_file}" | grep "AT_comp_dir" | head -1 | cut -d \\" -f2 `)
120
+ sub_path = "#{basename}/bin-archive/#{basename}"
121
+ dir = dir.gsub(sub_path, "").chomp
122
+ # UI.puts "dir = #{dir}"
123
+
124
+ unless File.exist?(dir)
125
+ # UI.puts "不存在 = #{dir}"
126
+ begin
127
+ FileUtils.mkdir_p(dir)
128
+ rescue SystemCallError
129
+ #判断用户目录是否存在
130
+ array = dir.split('/')
131
+ if array.length > 3
132
+ root_path = '/' + array[1] + '/' + array[2]
133
+ unless File.exist?(root_path)
134
+ raise "由于权限不足,请手动创建#{root_path} 后重试"
135
+ end
136
+ end
137
+ end
138
+ end
139
+
140
+ if Pathname.new(lib_file).extname == ".a"
141
+ FileUtils.rm_rf(File.join(dir,basename))
142
+ `ln -s #{target_path} #{dir}`
143
+ else
144
+ FileUtils.rm_rf(File.join(dir,basename))
145
+ `ln -s #{target_path} #{dir}/#{basename}`
146
+ end
147
+
148
+ check(lib_file,dir,basename)
149
+ end
150
+
151
+ def check(lib_file,dir,basename)
152
+ file = `dwarfdump "#{lib_file}" | grep -E "DW_AT_decl_file.*#{basename}.*\\.m|\\.c" | head -1 | cut -d \\" -f2`
153
+ if File.exist?(file)
154
+ raise "#{file} 不存在 请检测代码源是否正确~"
155
+ end
156
+ UI.puts "link successfully!"
157
+ UI.puts "view linked source at path: #{dir}"
158
+ end
159
+
160
+ def get_lib_path(name)
161
+ dir = Pathname.new(File.join(Pathname.pwd,"Pods",name))
162
+ lib_name = "lib#{name}.a"
163
+ lib_path = File.join(dir,lib_name)
164
+
165
+ unless File.exist?(lib_path)
166
+ lib_path = File.join(dir.children.first,lib_name)
167
+ end
168
+
169
+ lib_path
170
+ end
171
+
172
+ #源码地址
173
+ # def get_gitlib_iOS_path(name)
174
+ # "git@gitlab.xxx.com:iOS/#{name}.git"
175
+ # end
176
+ #要转换的地址,Github-iOS默认都是静态库
177
+ # def git_gitlib_iOS_path
178
+ # 'git@gitlab.xxx.com:Github-iOS/'
179
+ # end
180
+
181
+
182
+ #要转换的地址,Github-iOS默认都是静态库
183
+ # def http_gitlib_GitHub_iOS_path
184
+ # 'https://gitlab.xxx.com/Github-iOS/'
185
+ # end
186
+
187
+ #要转换的地址,iOS默认都是静态库
188
+ # def http_gitlib_iOS_path
189
+ # 'https://gitlab.xxx.com/iOS/'
190
+ # end
191
+
192
+ #==========================list begin ==============
193
+
194
+ def list
195
+ Dir.entries(source_root).each do |sub|
196
+ UI.puts "- #{sub}" unless sub.include?('.')
197
+ end
198
+ UI.puts "加载完成"
199
+ end
200
+
201
+
202
+ #==========================clean begin ==============
203
+ def all_clean
204
+ FileUtils.rm_rf(source_root) if File.directory?(source_root)
205
+ UI.puts "清理完成 #{source_root}"
206
+ end
207
+
208
+ def clean
209
+ raise "请输入要删除的组件库" if @names.nil?
210
+ @names.each do |name|
211
+ full_path = File.join(source_root,name)
212
+ if File.directory?(full_path)
213
+ FileUtils.rm_rf(full_path)
214
+ else
215
+ UI.puts "找不到 #{full_path}".yellow
216
+ end
217
+ end
218
+ UI.puts "清理完成 #{@names.to_s}"
219
+ end
220
+
221
+ private
222
+
223
+ def source_root
224
+ dir = File.join(@config.cache_root,"Source")
225
+ FileUtils.mkdir_p(dir) unless File.exist? dir
226
+ dir
227
+ end
228
+
229
+ end
230
+ end
231
+ end
232
+ end