cocoapods-mtxx-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 (67) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +22 -0
  3. data/README.md +11 -0
  4. data/lib/cocoapods-mtxx-bin/command/bin/archive.rb +206 -0
  5. data/lib/cocoapods-mtxx-bin/command/bin/auto.rb +212 -0
  6. data/lib/cocoapods-mtxx-bin/command/bin/code.rb +232 -0
  7. data/lib/cocoapods-mtxx-bin/command/bin/imy.rb +45 -0
  8. data/lib/cocoapods-mtxx-bin/command/bin/init.rb +94 -0
  9. data/lib/cocoapods-mtxx-bin/command/bin/initHotKey.rb +70 -0
  10. data/lib/cocoapods-mtxx-bin/command/bin/install.rb +44 -0
  11. data/lib/cocoapods-mtxx-bin/command/bin/lib/lint.rb +67 -0
  12. data/lib/cocoapods-mtxx-bin/command/bin/repo/push.rb +115 -0
  13. data/lib/cocoapods-mtxx-bin/command/bin/repo/update.rb +42 -0
  14. data/lib/cocoapods-mtxx-bin/command/bin/repo.rb +14 -0
  15. data/lib/cocoapods-mtxx-bin/command/bin/spec/create.rb +73 -0
  16. data/lib/cocoapods-mtxx-bin/command/bin/spec/lint.rb +109 -0
  17. data/lib/cocoapods-mtxx-bin/command/bin/spec.rb +13 -0
  18. data/lib/cocoapods-mtxx-bin/command/bin/update.rb +154 -0
  19. data/lib/cocoapods-mtxx-bin/command/bin.rb +65 -0
  20. data/lib/cocoapods-mtxx-bin/command.rb +1 -0
  21. data/lib/cocoapods-mtxx-bin/config/config.rb +166 -0
  22. data/lib/cocoapods-mtxx-bin/config/config_asker.rb +60 -0
  23. data/lib/cocoapods-mtxx-bin/config/config_builder.rb +216 -0
  24. data/lib/cocoapods-mtxx-bin/config/config_hot_key.rb +103 -0
  25. data/lib/cocoapods-mtxx-bin/config/config_hot_key_asker.rb +57 -0
  26. data/lib/cocoapods-mtxx-bin/gem_version.rb +9 -0
  27. data/lib/cocoapods-mtxx-bin/helpers/Info.plist +0 -0
  28. data/lib/cocoapods-mtxx-bin/helpers/build_helper.rb +167 -0
  29. data/lib/cocoapods-mtxx-bin/helpers/build_utils.rb +64 -0
  30. data/lib/cocoapods-mtxx-bin/helpers/framework.rb +86 -0
  31. data/lib/cocoapods-mtxx-bin/helpers/framework_builder.rb +551 -0
  32. data/lib/cocoapods-mtxx-bin/helpers/library.rb +54 -0
  33. data/lib/cocoapods-mtxx-bin/helpers/library_builder.rb +90 -0
  34. data/lib/cocoapods-mtxx-bin/helpers/sources_helper.rb +35 -0
  35. data/lib/cocoapods-mtxx-bin/helpers/spec_creator.rb +170 -0
  36. data/lib/cocoapods-mtxx-bin/helpers/spec_files_helper.rb +80 -0
  37. data/lib/cocoapods-mtxx-bin/helpers/spec_source_creator.rb +304 -0
  38. data/lib/cocoapods-mtxx-bin/helpers/upload_helper.rb +104 -0
  39. data/lib/cocoapods-mtxx-bin/helpers.rb +5 -0
  40. data/lib/cocoapods-mtxx-bin/native/acknowledgements.rb +27 -0
  41. data/lib/cocoapods-mtxx-bin/native/analyzer.rb +85 -0
  42. data/lib/cocoapods-mtxx-bin/native/file_accessor.rb +28 -0
  43. data/lib/cocoapods-mtxx-bin/native/gen.rb +79 -0
  44. data/lib/cocoapods-mtxx-bin/native/installation_options.rb +25 -0
  45. data/lib/cocoapods-mtxx-bin/native/installer.rb +135 -0
  46. data/lib/cocoapods-mtxx-bin/native/linter.rb +26 -0
  47. data/lib/cocoapods-mtxx-bin/native/path_source.rb +33 -0
  48. data/lib/cocoapods-mtxx-bin/native/pod_source_installer.rb +19 -0
  49. data/lib/cocoapods-mtxx-bin/native/pod_target_installer.rb +94 -0
  50. data/lib/cocoapods-mtxx-bin/native/podfile.rb +91 -0
  51. data/lib/cocoapods-mtxx-bin/native/podfile_env.rb +37 -0
  52. data/lib/cocoapods-mtxx-bin/native/podfile_generator.rb +201 -0
  53. data/lib/cocoapods-mtxx-bin/native/podspec_finder.rb +25 -0
  54. data/lib/cocoapods-mtxx-bin/native/resolver.rb +238 -0
  55. data/lib/cocoapods-mtxx-bin/native/sandbox_analyzer.rb +34 -0
  56. data/lib/cocoapods-mtxx-bin/native/source.rb +35 -0
  57. data/lib/cocoapods-mtxx-bin/native/sources_manager.rb +19 -0
  58. data/lib/cocoapods-mtxx-bin/native/specification.rb +31 -0
  59. data/lib/cocoapods-mtxx-bin/native/target_validator.rb +41 -0
  60. data/lib/cocoapods-mtxx-bin/native/validator.rb +40 -0
  61. data/lib/cocoapods-mtxx-bin/native.rb +25 -0
  62. data/lib/cocoapods-mtxx-bin/source_provider_hook.rb +53 -0
  63. data/lib/cocoapods-mtxx-bin.rb +2 -0
  64. data/lib/cocoapods_plugin.rb +2 -0
  65. data/spec/command/bin_spec.rb +12 -0
  66. data/spec/spec_helper.rb +50 -0
  67. metadata +182 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f6a43466bec9d2783b0662dc91356c06bcff374abf6e16dce5247f77361497fd
4
+ data.tar.gz: 2b29833245427d506a3ffe97ac9a556213e98ca3f17c01474961d8a092bbe532
5
+ SHA512:
6
+ metadata.gz: 8f9fa97150e04f2d8e15735ee3c0625c658cb87acee32e13a362859ef9fb3dd0fdc1e1686adefcc8ece5835d81eae853d124d2b332d2080884ecbc414a5185bc
7
+ data.tar.gz: c3f6cc48d93c9917b9293f6b12d439038f22f38c53f09ec53942e99d8b5430d9407c62a26d1c41ea2ccb9a46a27f7bdaee15152a73fc2e729dad84da54eec04e
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2021 Jensen <zys2@meitu.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,11 @@
1
+ # cocoapods-mtxx-bin
2
+
3
+ A description of cocoapods-mtxx-bin.
4
+
5
+ ## Installation
6
+
7
+ $ sudo gem install cocoapods-mtxx-bin
8
+
9
+ ## Usage
10
+
11
+ $ pod bin --help
@@ -0,0 +1,206 @@
1
+ require 'cocoapods-mtxx-bin/native/podfile'
2
+ require 'cocoapods/command/gen'
3
+ require 'cocoapods/generate'
4
+ require 'cocoapods-mtxx-bin/helpers/framework_builder'
5
+ require 'cocoapods-mtxx-bin/helpers/library_builder'
6
+ require 'cocoapods-mtxx-bin/helpers/build_helper'
7
+ require 'cocoapods-mtxx-bin/helpers/spec_source_creator'
8
+ require 'cocoapods-mtxx-bin/config/config_builder'
9
+ require 'cocoapods-mtxx-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 或 .framework(目前仅支持静态 framework )'
19
+ self.description = <<-DESC
20
+ 将组件归档为 .a 或 .framework ,仅支持iOS平台
21
+
22
+ 此静态 framework 不包含依赖组件的 symbol
23
+
24
+ 目前仅支持 .framework,.a 尚未验证是否可以
25
+ DESC
26
+
27
+ def self.options
28
+ [
29
+ ['--all-make', '对该组件的依赖库,全部制作为二进制组件'],
30
+ ['--code-dependencies', '使用源码依赖'],
31
+ ['--no-clean', '保留构建中间产物'],
32
+ ['--sources', '私有源地址,多个用分号区分'],
33
+ ['--framework-output', '输出framework文件'],
34
+ ['--no-zip', '不压缩静态库 为 zip'],
35
+ ['--configuration', 'Build the specified configuration (e.g. Debug). Defaults to Release'],
36
+ ['--env', "该组件上传的环境 %w[dev debug_iphoneos release_iphoneos]"]
37
+ ].concat(Pod::Command::Gen.options).concat(super).uniq
38
+ end
39
+
40
+ self.arguments = [
41
+ CLAide::Argument.new('NAME.podspec', false)
42
+ ]
43
+
44
+ def initialize(argv)
45
+ @podspec = argv.shift_argument
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
+ # 加载podspec
69
+ @spec = Specification.from_file(spec_file)
70
+ # 如果有 default_subspecs 报错提示
71
+ raise Informative, "#{@spec.root.name} (#{@spec.root.version}) 有default_subspecs:#{@spec.default_subspecs},请注释掉重新执行命令!" unless @spec.default_subspecs.empty?
72
+ # 生成xcode工程
73
+ generate_project
74
+ # 构建当前库
75
+ build_root_spec
76
+
77
+ sources_sepc = Array.new
78
+ sources_sepc << @spec
79
+ # 如果有 --all-make 选项,则打包依赖组件
80
+
81
+ sources_sepc.concat(build_dependencies) if @all_make
82
+
83
+ # 返回所有打包二进制组件的podspec
84
+ sources_sepc
85
+ end
86
+
87
+ # 构建当前库
88
+ def build_root_spec
89
+ builder = CBin::Build::Helper.new(@spec,
90
+ @platform,
91
+ @framework_output,
92
+ @zip,
93
+ @spec,
94
+ CBin::Config::Builder.instance.white_pod_list.include?(@spec.name),
95
+ @config,
96
+ @installers.size > 0 ? @installers[0] : nil)
97
+ builder.build
98
+ builder.clean_workspace if @clean && !@all_make
99
+ end
100
+
101
+ # 构建依赖库
102
+ def build_dependencies
103
+ @build_finshed = true
104
+ #如果没要求,就清空依赖库数据
105
+ sources_sepc = []
106
+ @@missing_binary_specs.uniq.each do |spec|
107
+ next if spec.name.include?('/') # 过滤subspec
108
+ next if spec.name == @spec.name # 过滤当前库
109
+ #过滤白名单
110
+ next if CBin::Config::Builder.instance.white_pod_list.include?(spec.name)
111
+ #过滤 git
112
+ if spec.source[:git] && spec.source[:git]
113
+ spec_git = spec.source[:git]
114
+ spec_git_res = false
115
+ CBin::Config::Builder.instance.ignore_git_list.each do |ignore_git|
116
+ spec_git_res = spec_git.include?(ignore_git)
117
+ break if spec_git_res
118
+ end
119
+ next if spec_git_res
120
+ end
121
+ UI.warn "#{spec.name}.podspec 带有 vendored_frameworks 字段,请检查是否有效!!!" if spec.attributes_hash['vendored_frameworks']
122
+ UI.warn "#{spec.name}.podspec 带有 vendored_libraries 字段,请检查是否有效!!!" if spec.attributes_hash['vendored_libraries']
123
+ next if (spec.attributes_hash['vendored_frameworks'] || spec.attributes_hash['vendored_libraries']) && @spec.name != spec.name
124
+ next if (spec.attributes_hash['ios.vendored_frameworks'] || spec.attributes_hash['ios.vendored_libraries']) && @spec.name != spec.name
125
+ #获取没有制作二进制版本的spec集合
126
+ sources_sepc << spec
127
+ end
128
+
129
+ fail_build_specs = []
130
+ sources_sepc.uniq.each do |spec|
131
+ begin
132
+ builder = CBin::Build::Helper.new(spec,
133
+ @platform,
134
+ @framework_output,
135
+ @zip,
136
+ @spec,
137
+ false ,
138
+ @config,
139
+ nil )
140
+ builder.build
141
+ rescue Object => exception
142
+ UI.puts exception
143
+ fail_build_specs << spec
144
+ end
145
+ end
146
+
147
+ if fail_build_specs.any?
148
+ fail_build_specs.uniq.each do |spec|
149
+ UI.warn "【#{spec.name} | #{spec.version}】组件二进制版本编译失败 ."
150
+ end
151
+ end
152
+ sources_sepc - fail_build_specs
153
+ end
154
+
155
+ # 解析器传过来的
156
+ def Archive.missing_binary_specs(missing_binary_specs)
157
+ @@missing_binary_specs = missing_binary_specs unless @build_finshed
158
+ end
159
+
160
+ private
161
+
162
+ # 生成xcode工程
163
+ def generate_project
164
+ Podfile.execute_with_bin_plugin do
165
+ Podfile.execute_with_use_binaries(!@code_dependencies) do
166
+ argvs = [
167
+ "--sources=#{sources_option(@code_dependencies, @sources)},https:\/\/cdn.cocoapods.org",
168
+ "--gen-directory=#{CBin::Config::Builder.instance.gen_dir}",
169
+ '--clean',
170
+ *@additional_args
171
+ ]
172
+
173
+ podfile= File.join(Pathname.pwd, "Podfile")
174
+ if File.exist?(podfile)
175
+ argvs += ['--use-podfile']
176
+ argvs += ["--podfile-path=#{podfile}"]
177
+ end
178
+
179
+ argvs << spec_file if spec_file
180
+
181
+ gen = Pod::Command::Gen.new(CLAide::ARGV.new(argvs))
182
+ gen.validate!
183
+ @installers = gen.run
184
+ end
185
+ end
186
+ end
187
+
188
+ # 查找podspec
189
+ def spec_file
190
+ @spec_file ||= begin
191
+ if @podspec
192
+ find_spec_file(@podspec)
193
+ else
194
+ if code_spec_files.empty?
195
+ raise Informative, '当前目录下没有找到可用源码 podspec.'
196
+ end
197
+
198
+ spec_file = code_spec_files.first
199
+ spec_file
200
+ end
201
+ end
202
+ end
203
+ end
204
+ end
205
+ end
206
+ end
@@ -0,0 +1,212 @@
1
+ require 'cocoapods-mtxx-bin/command/bin/auto'
2
+ require 'cocoapods-mtxx-bin/helpers/upload_helper'
3
+
4
+ module Pod
5
+ class Command
6
+ class Bin < Command
7
+ class Auto < Bin
8
+ self.summary = '一键打包二进制并上传'
9
+ self.description = <<-DESC
10
+ 生成二进制文件并上传至文件服务器,生成二进制 podspec 并上传至二进制私有源
11
+ DESC
12
+
13
+ self.arguments = [
14
+ CLAide::Argument.new('NAME.podspec', false)
15
+ ]
16
+ def self.options
17
+ [
18
+ ['--push-source-podspec', '上传源码 podspec '],
19
+ ['--code-dependencies', '使用源码依赖'],
20
+ ['--allow-prerelease', '允许使用 prerelease 的版本'],
21
+ ['--no-clean', '保留构建中间产物'],
22
+ ['--framework-output', '输出framework文件'],
23
+ ['--no-zip', '不压缩静态 framework 为 zip'],
24
+ ['--all-make', '对该组件的依赖库,全部制作为二进制组件'],
25
+ ['--configuration', 'Build the specified configuration (e.g. Release ). Defaults to Debug'],
26
+ ['--env', "该组件上传的环境 %w[dev debug_iphoneos release_iphoneos]"]
27
+ ].concat(Pod::Command::Gen.options).concat(super).uniq
28
+ end
29
+
30
+ def initialize(argv)
31
+
32
+ @env = argv.option('env') || 'dev'
33
+ CBin.config.set_configuration_env(@env)
34
+
35
+ # @podspec = argv.shift_argument || find_podspec
36
+ @podspec = argv.shift_argument
37
+
38
+ @push_source_podspec = argv.flag?('push-source-podspec')
39
+ @code_dependencies = argv.flag?('code-dependencies')
40
+ @allow_prerelease = argv.flag?('allow-prerelease')
41
+ @framework_output = argv.flag?('framework-output', false)
42
+ @clean = argv.flag?('clean', true)
43
+ @zip = argv.flag?('zip', true)
44
+ @all_make = argv.flag?('all-make', false)
45
+ @verbose = argv.flag?('verbose', false)
46
+ @sources = argv.option('sources', 'https://cdn.cocoapods.org')
47
+ @config = argv.option('configuration', 'Release')
48
+
49
+ super
50
+
51
+ # !!! 这一行加载在 super 的后面,否则会出现问题,切记 !!!
52
+ @additional_args = argv.remainder!
53
+ end
54
+
55
+ def validate!
56
+ super
57
+ raise Informative, '当前目录下没有 podspec 文件' if @podspec.nil? && code_spec_files.size == 0
58
+ raise Informative, '当前目录有多个 podspec 文件,请指定具体的 podspec 文件' if @podspec.nil? && code_spec_files.size > 1
59
+ end
60
+
61
+ def run
62
+ @podspec = find_podspec unless @podspec
63
+ @specification = Specification.from_file(@podspec)
64
+
65
+ # 归档.a或.framework
66
+ sources_sepc = run_archive
67
+
68
+ fail_push_specs = []
69
+ sources_sepc.uniq.each do |spec|
70
+ begin
71
+ # 上传所有打包好的二进制文件及podspec
72
+ fail_push_specs << spec unless CBin::Upload::Helper.new(spec,@code_dependencies,@sources).upload
73
+ rescue Object => exception
74
+ UI.puts exception
75
+ fail_push_specs << spec
76
+ end
77
+ end
78
+
79
+ if fail_push_specs.any?
80
+ fail_push_specs.uniq.each do |spec|
81
+ UI.warn "【#{spec.name} | #{spec.version}】组件spec push失败 ."
82
+ end
83
+ end
84
+
85
+ success_specs = sources_sepc - fail_push_specs
86
+ if success_specs.any?
87
+ auto_success = ""
88
+ success_specs.uniq.each do |spec|
89
+ auto_success += "#{spec.name} | #{spec.version}\n"
90
+ UI.message "【 #{spec.name} | #{spec.version} 】二进制组件制作完成".green
91
+ end
92
+ UI.message auto_success
93
+ ENV['auto_success'] = auto_success
94
+ end
95
+ #pod repo update
96
+ UI.title("Updating Spec Repositories\n".yellow) do
97
+ Pod::Command::Bin::Repo::Update.new(CLAide::ARGV.new([])).run
98
+ end
99
+
100
+ # 上传源码podspec
101
+ UI.title("Pushing source podspec for #{@specification.name}") do
102
+ Pod::Command::Bin::Repo::Push.new(CLAide::ARGV.new([@podspec, '--loose-options'])).run
103
+ end if @push_source_podspec
104
+
105
+ end
106
+
107
+ #制作二进制包
108
+ def run_archive
109
+ argvs = [
110
+ "--sources=#{sources_option(@code_dependencies, @sources)},https:\/\/cdn.cocoapods.org"
111
+ ]
112
+
113
+ argvs += @additional_args unless @additional_args.nil?
114
+
115
+ argvs << @podspec if @podspec
116
+ argvs.delete(Array.new)
117
+
118
+ unless @clean
119
+ argvs += ['--no-clean']
120
+ end
121
+ if @code_dependencies
122
+ argvs += ['--code-dependencies']
123
+ end
124
+ if @verbose
125
+ argvs += ['--verbose']
126
+ end
127
+ if @allow_prerelease
128
+ argvs += ['--allow-prerelease']
129
+ end
130
+ if @framework_output
131
+ argvs += ['--framework-output']
132
+ end
133
+ if @all_make
134
+ argvs += ['--all-make']
135
+ end
136
+ # if @env
137
+ # argvs += ["--env=#{@env}"]
138
+ # end
139
+ argvs += ["--configuration=#{@config}"]
140
+
141
+ archive = Pod::Command::Bin::Archive.new(CLAide::ARGV.new(argvs))
142
+ archive.validate!
143
+ sources_sepc = archive.run
144
+ sources_sepc
145
+ end
146
+
147
+ def code_podsepc_extname
148
+ '.podsepc'
149
+ end
150
+
151
+ def binary_podsepc_json
152
+ "#{@specification.name}.binary.podspec.json"
153
+ end
154
+
155
+ def binary_template_podsepc
156
+ "#{@specification.name}.binary-template.podspec"
157
+ end
158
+
159
+ def template_spec_file
160
+ @template_spec_file ||= begin
161
+ if @template_podspec
162
+ find_spec_file(@template_podspec)
163
+ else
164
+ binary_template_spec_file
165
+ end
166
+ end
167
+ end
168
+
169
+ def spec_file
170
+ @spec_file ||= begin
171
+ if @podspec
172
+ find_spec_file(@podspec) || @podspec
173
+ else
174
+ if code_spec_files.empty?
175
+ raise Informative, '当前目录下没有找到可用源码 podspec.'
176
+ end
177
+
178
+ spec_file = if @binary
179
+ code_spec = Pod::Specification.from_file(code_spec_files.first)
180
+ if template_spec_file
181
+ template_spec = Pod::Specification.from_file(template_spec_file)
182
+ end
183
+ create_binary_spec_file(code_spec, template_spec)
184
+ else
185
+ code_spec_files.first
186
+ end
187
+ spec_file
188
+ end
189
+ end
190
+ end
191
+
192
+ #Dir.glob 可替代
193
+ def find_podspec
194
+ name = nil
195
+ Pathname.pwd.children.each do |child|
196
+ # puts child
197
+ if File.file?(child)
198
+ if child.extname == '.podspec'
199
+ name = File.basename(child)
200
+ unless name.include?("binary-template")
201
+ return name
202
+ end
203
+ end
204
+ end
205
+ end
206
+ return name
207
+ end
208
+
209
+ end
210
+ end
211
+ end
212
+ 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