cocoapods-fy-bin 0.0.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 (62) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +22 -0
  3. data/README.md +1 -0
  4. data/lib/cocoapods-fy-bin/command/bin/archive.rb +202 -0
  5. data/lib/cocoapods-fy-bin/command/bin/auto.rb +204 -0
  6. data/lib/cocoapods-fy-bin/command/bin/code.rb +232 -0
  7. data/lib/cocoapods-fy-bin/command/bin/imy.rb +46 -0
  8. data/lib/cocoapods-fy-bin/command/bin/init.rb +69 -0
  9. data/lib/cocoapods-fy-bin/command/bin/initHotKey.rb +70 -0
  10. data/lib/cocoapods-fy-bin/command/bin/install.rb +44 -0
  11. data/lib/cocoapods-fy-bin/command/bin/lib/lint.rb +69 -0
  12. data/lib/cocoapods-fy-bin/command/bin/repo/update.rb +43 -0
  13. data/lib/cocoapods-fy-bin/command/bin/spec/create.rb +73 -0
  14. data/lib/cocoapods-fy-bin/command/bin/spec/push.rb +114 -0
  15. data/lib/cocoapods-fy-bin/command/bin/update.rb +154 -0
  16. data/lib/cocoapods-fy-bin/command/bin.rb +59 -0
  17. data/lib/cocoapods-fy-bin/command.rb +2 -0
  18. data/lib/cocoapods-fy-bin/config/config.rb +137 -0
  19. data/lib/cocoapods-fy-bin/config/config_asker.rb +57 -0
  20. data/lib/cocoapods-fy-bin/config/config_builder.rb +228 -0
  21. data/lib/cocoapods-fy-bin/config/config_hot_key.rb +103 -0
  22. data/lib/cocoapods-fy-bin/config/config_hot_key_asker.rb +57 -0
  23. data/lib/cocoapods-fy-bin/gem_version.rb +10 -0
  24. data/lib/cocoapods-fy-bin/helpers/build_helper.rb +164 -0
  25. data/lib/cocoapods-fy-bin/helpers/build_utils.rb +63 -0
  26. data/lib/cocoapods-fy-bin/helpers/framework.rb +94 -0
  27. data/lib/cocoapods-fy-bin/helpers/framework_builder.rb +419 -0
  28. data/lib/cocoapods-fy-bin/helpers/library.rb +54 -0
  29. data/lib/cocoapods-fy-bin/helpers/library_builder.rb +91 -0
  30. data/lib/cocoapods-fy-bin/helpers/sources_helper.rb +36 -0
  31. data/lib/cocoapods-fy-bin/helpers/spec_creator.rb +170 -0
  32. data/lib/cocoapods-fy-bin/helpers/spec_files_helper.rb +77 -0
  33. data/lib/cocoapods-fy-bin/helpers/spec_source_creator.rb +229 -0
  34. data/lib/cocoapods-fy-bin/helpers/upload_helper.rb +97 -0
  35. data/lib/cocoapods-fy-bin/helpers.rb +5 -0
  36. data/lib/cocoapods-fy-bin/native/acknowledgements.rb +27 -0
  37. data/lib/cocoapods-fy-bin/native/analyzer.rb +55 -0
  38. data/lib/cocoapods-fy-bin/native/file_accessor.rb +28 -0
  39. data/lib/cocoapods-fy-bin/native/installation_options.rb +25 -0
  40. data/lib/cocoapods-fy-bin/native/installer.rb +204 -0
  41. data/lib/cocoapods-fy-bin/native/linter.rb +26 -0
  42. data/lib/cocoapods-fy-bin/native/path_source.rb +33 -0
  43. data/lib/cocoapods-fy-bin/native/pod_source_installer.rb +19 -0
  44. data/lib/cocoapods-fy-bin/native/pod_target_installer.rb +94 -0
  45. data/lib/cocoapods-fy-bin/native/podfile.rb +91 -0
  46. data/lib/cocoapods-fy-bin/native/podfile_env.rb +37 -0
  47. data/lib/cocoapods-fy-bin/native/podfile_generator.rb +199 -0
  48. data/lib/cocoapods-fy-bin/native/podspec_finder.rb +25 -0
  49. data/lib/cocoapods-fy-bin/native/resolver.rb +238 -0
  50. data/lib/cocoapods-fy-bin/native/sandbox_analyzer.rb +34 -0
  51. data/lib/cocoapods-fy-bin/native/source.rb +35 -0
  52. data/lib/cocoapods-fy-bin/native/sources_manager.rb +20 -0
  53. data/lib/cocoapods-fy-bin/native/specification.rb +31 -0
  54. data/lib/cocoapods-fy-bin/native/target_validator.rb +41 -0
  55. data/lib/cocoapods-fy-bin/native/validator.rb +40 -0
  56. data/lib/cocoapods-fy-bin/native.rb +23 -0
  57. data/lib/cocoapods-fy-bin/source_provider_hook.rb +55 -0
  58. data/lib/cocoapods-fy-bin.rb +2 -0
  59. data/lib/cocoapods_plugin.rb +3 -0
  60. data/spec/command/bin_spec.rb +12 -0
  61. data/spec/spec_helper.rb +50 -0
  62. metadata +177 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 10b2f2a6df7efa962d991a830ec44831e2be19f9196e944afc54992066f647e3
4
+ data.tar.gz: f7ca5842682ae9ebd59231c208608ece878d97df2ce6af166a0e3233797ee7cd
5
+ SHA512:
6
+ metadata.gz: e3377e6ab124ffe92d9627640dde7c94dc8e3128bf4b11d4246bf52e3702307e9c24bef16447c831f42a23e0f1f7d5cc5a0b55f7f6778317bebeb7a951261129
7
+ data.tar.gz: a681ac3e8b80a19d541d15af2f2eb24224bf7efad88797e21480dc48e0fb0d7f613f2905c8a1cbf39e733622e0dc5856c8d96203907809a5917b585da38c1229
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,202 @@
1
+ require 'cocoapods-fy-bin/native/podfile'
2
+ require 'cocoapods/command/gen'
3
+ require 'cocoapods/generate'
4
+ require 'cocoapods-fy-bin/helpers/framework_builder'
5
+ require 'cocoapods-fy-bin/helpers/library_builder'
6
+ require 'cocoapods-fy-bin/helpers/build_helper'
7
+ require 'cocoapods-fy-bin/helpers/spec_source_creator'
8
+ require 'cocoapods-fy-bin/config/config_builder'
9
+ require 'cocoapods-fy-bin/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
+ ['--archs', "需要二进制组件的架构"]
35
+ ].concat(Pod::Command::Gen.options).concat(super).uniq
36
+ end
37
+
38
+ self.arguments = [
39
+ CLAide::Argument.new('NAME.podspec', false)
40
+ ]
41
+
42
+ def initialize(argv)
43
+ @env = argv.option('env') || 'dev'
44
+ CBin.config.set_configuration_env(@env)
45
+ UI.warn "====== cocoapods-fy-bin #{CBin::VERSION} 版本 ======== \n "
46
+ UI.warn "====== #{@env} 环境 ======== \n "
47
+
48
+ @code_dependencies = argv.flag?('code-dependencies')
49
+ @framework_output = argv.flag?('framework-output', false )
50
+ @clean = argv.flag?('no-clean', false)
51
+ @zip = argv.flag?('zip', true)
52
+ @all_make = argv.flag?('all-make', false )
53
+ @sources = argv.option('sources') || []
54
+ @platform = Platform.new(:ios)
55
+ @archs = argv.option('archs', 'armv7,arm64')
56
+ @config = argv.option('configuration', 'Release')
57
+
58
+ @framework_path
59
+ super
60
+
61
+ @additional_args = argv.remainder!
62
+ @build_finshed = false
63
+ end
64
+
65
+ def run
66
+ #清除之前的缓存
67
+ zip_dir = CBin::Config::Builder.instance.zip_dir
68
+ FileUtils.rm_rf(zip_dir) if File.exist?(zip_dir)
69
+
70
+ @spec = Specification.from_file(spec_file)
71
+ # 生成pod project
72
+ generate_project
73
+ # 编译打包framwwork
74
+ build_root_spec
75
+
76
+ sources_sepc = Array.new
77
+ sources_sepc << @spec
78
+ sources_sepc.concat(build_dependencies) if @all_make
79
+
80
+ sources_sepc
81
+ end
82
+
83
+ def build_root_spec
84
+ builder = CBin::Build::Helper.new(@spec,
85
+ @platform,
86
+ @framework_output,
87
+ @zip,
88
+ @spec,
89
+ @archs,
90
+ CBin::Config::Builder.instance.white_pod_list.include?(@spec.name),
91
+ @config)
92
+ builder.build
93
+ builder.clean_workspace if @clean && !@all_make
94
+ end
95
+
96
+ def build_dependencies
97
+ @build_finshed = true
98
+ #如果没要求,就清空依赖库数据
99
+ sources_sepc = []
100
+ @@missing_binary_specs.uniq.each do |spec|
101
+ next if spec.name.include?('/')
102
+ next if spec.name == @spec.name
103
+ #过滤白名单
104
+ next if CBin::Config::Builder.instance.white_pod_list.include?(spec.name)
105
+ #过滤 git
106
+ if spec.source[:git] && spec.source[:git]
107
+ spec_git = spec.source[:git]
108
+ spec_git_res = false
109
+ CBin::Config::Builder.instance.ignore_git_list.each do |ignore_git|
110
+ spec_git_res = spec_git.include?(ignore_git)
111
+ break if spec_git_res
112
+ end
113
+ next if spec_git_res
114
+ end
115
+ UI.warn "#{spec.name}.podspec 带有 vendored_frameworks 字段,请检查是否有效!!!" if spec.attributes_hash['vendored_frameworks']
116
+ next if spec.attributes_hash['vendored_frameworks'] && @spec.name != spec.name #过滤带有vendored_frameworks的
117
+ next if spec.attributes_hash['ios.vendored_frameworks'] && @spec.name != spec.name #过滤带有vendored_frameworks的
118
+ #获取没有制作二进制版本的spec集合
119
+ sources_sepc << spec
120
+ end
121
+
122
+ fail_build_specs = []
123
+ sources_sepc.uniq.each do |spec|
124
+ begin
125
+ builder = CBin::Build::Helper.new(spec,
126
+ @platform,
127
+ @framework_output,
128
+ @zip,
129
+ @spec,
130
+ false ,
131
+ @config)
132
+ builder.build
133
+ rescue Object => exception
134
+ UI.puts exception
135
+ fail_build_specs << spec
136
+ end
137
+ end
138
+
139
+ if fail_build_specs.any?
140
+ fail_build_specs.uniq.each do |spec|
141
+ UI.warn "【#{spec.name} | #{spec.version}】组件二进制版本编译失败 ."
142
+ end
143
+ end
144
+ sources_sepc - fail_build_specs
145
+ end
146
+
147
+ # 解析器传过来的
148
+ def Archive.missing_binary_specs(missing_binary_specs)
149
+ @@missing_binary_specs = missing_binary_specs unless @build_finshed
150
+ end
151
+
152
+ private
153
+
154
+ def generate_project
155
+ Podfile.execute_with_bin_plugin do
156
+ Podfile.execute_with_use_binaries(!@code_dependencies) do
157
+ argvs = [
158
+ "--sources=#{sources_option(@code_dependencies, @sources)}",
159
+ "--gen-directory=#{CBin::Config::Builder.instance.gen_dir}",
160
+ '--clean',
161
+ *@additional_args
162
+ ]
163
+
164
+ podfile= File.join(Pathname.pwd, "Podfile")
165
+ if File.exist?(podfile)
166
+ argvs += ['--use-podfile']
167
+ end
168
+
169
+ argvs << spec_file if spec_file
170
+
171
+ gen = Pod::Command::Gen.new(CLAide::ARGV.new(argvs))
172
+ gen.validate!
173
+ # 1 通过create_app_project(cocoapods-generate=》xcodeproj)创建.xcodeproj文件
174
+ # 2 创建CocoaPods.podfile.yaml 工作空间.xcworkspace描述文件
175
+ # 3 根据yaml里面podspec路径和插件中HooksManager::source_provider更新依赖等信息 生成工程文件
176
+ gen.run
177
+ end
178
+ end
179
+ end
180
+
181
+
182
+ def spec_file
183
+ @spec_file ||= begin
184
+ if @podspec
185
+ find_spec_file(@podspec)
186
+ else
187
+ if code_spec_files.empty?
188
+ raise Informative, '当前目录下没有找到可用源码 podspec.'
189
+ end
190
+
191
+ spec_file = code_spec_files.first
192
+ spec_file
193
+ end
194
+ end
195
+ end
196
+
197
+
198
+
199
+ end
200
+ end
201
+ end
202
+ end
@@ -0,0 +1,204 @@
1
+
2
+ require 'cocoapods-fy-bin/command/bin/auto'
3
+ require 'cocoapods-fy-bin/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
+ ['--archs', "需要二进制组件的架构"]
25
+ ].concat(Pod::Command::Gen.options).concat(super).uniq
26
+ end
27
+
28
+ def initialize(argv)
29
+
30
+ @env = argv.option('env') || 'dev'
31
+ CBin.config.set_configuration_env(@env)
32
+
33
+ @podspec = argv.shift_argument || find_podspec
34
+ @specification = Specification.from_file(@podspec)
35
+
36
+ @code_dependencies = argv.flag?('code-dependencies')
37
+ @allow_prerelease = argv.flag?('allow-prerelease')
38
+ @framework_output = argv.flag?('framework-output', false )
39
+ @clean = argv.flag?('clean', true)
40
+ @zip = argv.flag?('zip', true)
41
+ @all_make = argv.flag?('all-make', false)
42
+ @verbose = argv.flag?('verbose', true)
43
+ @archs = argv.flag?('archs', 'arm64')
44
+ @config = argv.option('configuration', 'Debug')
45
+ @additional_args = argv.remainder!
46
+
47
+ super
48
+ end
49
+
50
+ def validate!
51
+ help! "未找到 podspec文件" unless @podspec
52
+ super
53
+ end
54
+
55
+ def run
56
+ @specification = Specification.from_file(@podspec)
57
+
58
+ sources_sepc = run_archive
59
+
60
+ fail_push_specs = []
61
+ sources_sepc.uniq.each do |spec|
62
+ begin
63
+ # 上传二进制文件和二进制spec
64
+ fail_push_specs << spec unless CBin::Upload::Helper.new(spec,@code_dependencies,@sources).upload
65
+ rescue Object => exception
66
+ UI.puts exception
67
+ fail_push_specs << spec
68
+ end
69
+ end
70
+
71
+ if fail_push_specs.any?
72
+ fail_push_specs.uniq.each do |spec|
73
+ UI.warn "【#{spec.name} | #{spec.version}】组件spec push失败 ."
74
+ end
75
+ end
76
+
77
+ success_specs = sources_sepc - fail_push_specs
78
+ if success_specs.any?
79
+ auto_success = ""
80
+ success_specs.uniq.each do |spec|
81
+ auto_success += "#{spec.name} | #{spec.version}\n"
82
+ UI.warn "===【 #{spec.name} | #{spec.version} 】二进制组件制作完成 !!! "
83
+ end
84
+ puts "============== auto_success"
85
+ puts auto_success
86
+ ENV['auto_success'] = auto_success
87
+ end
88
+ #pod repo update
89
+ UI.section("\nUpdating Spec Repositories\n".yellow) do
90
+ Pod::Command::Bin::Repo::Update.new(CLAide::ARGV.new([])).run
91
+ end
92
+
93
+ end
94
+
95
+ #制作二进制包
96
+
97
+ def run_archive
98
+ argvs = [
99
+ "--sources=#{sources_option(@code_dependencies, @sources)},https://github.com/CocoaPods/Specs.git,https://gitlab.fuyoukache.com/iosThird/FYSpecs.git,https://gitlab.fuyoukache.com/iosThird/swiftThird/FYSwiftSpecs.git",
100
+ @additional_args
101
+ ]
102
+
103
+ argvs << spec_file if spec_file
104
+ argvs.delete(Array.new)
105
+
106
+ unless @clean
107
+ argvs += ['--no-clean']
108
+ end
109
+ if @code_dependencies
110
+ argvs += ['--code-dependencies']
111
+ end
112
+ if @verbose
113
+ argvs += ['--verbose']
114
+ end
115
+ if @allow_prerelease
116
+ argvs += ['--allow-prerelease']
117
+ end
118
+ if @framework_output
119
+ argvs += ['--framework-output']
120
+ end
121
+ if @all_make
122
+ argvs += ['--all-make']
123
+ end
124
+ if @env
125
+ argvs += ["--env=#{@env}"]
126
+ end
127
+ if @archs
128
+ argvs += ["--archs=#{@archs}"]
129
+ end
130
+ argvs += ["--configuration=#{@config}"]
131
+
132
+ archive = Pod::Command::Bin::Archive.new(CLAide::ARGV.new(argvs))
133
+ archive.validate!
134
+ sources_sepc = archive.run
135
+ sources_sepc
136
+ end
137
+
138
+
139
+ def code_podsepc_extname
140
+ '.podsepc'
141
+ end
142
+
143
+ def binary_podsepc_json
144
+ "#{@specification.name}.binary.podspec.json"
145
+ end
146
+
147
+ def binary_template_podsepc
148
+ "#{@specification.name}.binary-template.podspec"
149
+ end
150
+
151
+ def template_spec_file
152
+ @template_spec_file ||= begin
153
+ if @template_podspec
154
+ find_spec_file(@template_podspec)
155
+ else
156
+ binary_template_spec_file
157
+ end
158
+ end
159
+ end
160
+
161
+ def spec_file
162
+ @spec_file ||= begin
163
+ if @podspec
164
+ find_spec_file(@podspec) || @podspec
165
+ else
166
+ if code_spec_files.empty?
167
+ raise Informative, '当前目录下没有找到可用源码 podspec.'
168
+ end
169
+
170
+ spec_file = if @binary
171
+ code_spec = Pod::Specification.from_file(code_spec_files.first)
172
+ if template_spec_file
173
+ template_spec = Pod::Specification.from_file(template_spec_file)
174
+ end
175
+ create_binary_spec_file(code_spec, template_spec)
176
+ else
177
+ code_spec_files.first
178
+ end
179
+ spec_file
180
+ end
181
+ end
182
+ end
183
+
184
+ #Dir.glob 可替代
185
+ def find_podspec
186
+ name = nil
187
+ Pathname.pwd.children.each do |child|
188
+ puts child
189
+ if File.file?(child)
190
+ if child.extname == '.podspec'
191
+ name = File.basename(child)
192
+ unless name.include?("binary-template")
193
+ return name
194
+ end
195
+ end
196
+ end
197
+ end
198
+ return name
199
+ end
200
+
201
+ end
202
+ end
203
+ end
204
+ 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