cocoapods-lhj-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 (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,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
@@ -0,0 +1,78 @@
1
+ require 'cocoapods'
2
+ require 'cocoapods/target/pod_target'
3
+
4
+ module Pod
5
+ class Command
6
+ class Bin < Command
7
+ class Dup < Bin
8
+ self.summary = '在Podfile目录下,查找Pods下同名资源名'
9
+
10
+ self.description = <<-DESC
11
+ 在Podfile目录下,查找Pods下同名资源名
12
+ DESC
13
+
14
+ self.arguments = [
15
+ CLAide::Argument.new('NAME', false)
16
+ ]
17
+ def self.options
18
+ [
19
+ ['--all-clean', '删除所有已经下载的源码'],
20
+ ['--clean', '删除所有指定下载的源码'],
21
+ ['--list', '展示所有一级下载的源码以及其大小'],
22
+ ['--source', '源码路径,本地路径,会去自动链接本地源码']
23
+ ]
24
+ end
25
+
26
+ def initialize(argv)
27
+ @codeSource = argv.option('source') || nil
28
+
29
+ @config = Pod::Config.instance
30
+
31
+ super
32
+ end
33
+
34
+
35
+ def run
36
+ target_definition = Pod::Config.instance.podfile.target_definition_list[1]
37
+
38
+ user_build_configurations = target_definition.build_configurations || Target::DEFAULT_BUILD_CONFIGURATIONS
39
+ aggregateTarget = AggregateTarget.new(Pod::Config.instance.sandbox,
40
+ target_definition.uses_frameworks?,
41
+ user_build_configurations ,
42
+ nil,
43
+ target_definition.platform,
44
+ target_definition,
45
+ Pod::Config.instance.installation_root,
46
+ nil,
47
+ nil ,
48
+ user_build_configurations)
49
+ input_file = aggregateTarget.copy_resources_script_path
50
+ output_pods_suffix_txt = File.join(Pod::Config.instance.project_root,"output_pods_suffix.txt")
51
+ output_pods_uniq_txt = File.join(Pod::Config.instance.project_root,"output_pods_uniq.txt")
52
+ ignore_array = ["bundle","mp3"]
53
+ resources_path = File.join(File.dirname(File.dirname(File.dirname(__FILE__))),"resources")
54
+ shell_file = File.join(resources_path,"Pods-check-deduplication-resources.sh")
55
+ #ruby 调用shell 文件、命令传入
56
+ # stdout shell 脚本输出的文本
57
+ # status 退出的状态
58
+ stdout, status = Open3.capture2('/bin/sh',
59
+ "#{shell_file}",
60
+ "#{input_file}",
61
+ "#{output_pods_suffix_txt}",
62
+ "#{output_pods_uniq_txt}",
63
+ "#{ignore_array}")
64
+
65
+ #重复资源 抛出异常
66
+ if status.to_i != 0
67
+ raise "由于权限不足,请手动创建 后重试"
68
+ else #重复资源,警告
69
+ raise "由于权限不足,请手动创建 后重试"
70
+
71
+ end
72
+ end
73
+
74
+
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,69 @@
1
+ require 'cocoapods-lhj-bin/config/config_asker'
2
+
3
+ module Pod
4
+ class Command
5
+ class Bin < Command
6
+ class Init < Bin
7
+ self.summary = '初始化插件的快捷键.'
8
+ self.description = <<-DESC
9
+ 创建 文件,在其中保存插件需要的配置信息,
10
+ 如快捷键1 快捷键2 所对应执行的命令
11
+ DESC
12
+
13
+ def self.options
14
+ [
15
+ ['--bin-url=URL', '配置文件地址,直接从此地址下载配置文件']
16
+ ].concat(super)
17
+ end
18
+
19
+ def initialize(argv)
20
+ @bin_url = argv.option('bin-url')
21
+ super
22
+ end
23
+
24
+ def run
25
+ if @bin_url.nil?
26
+ config_with_asker
27
+ else
28
+ config_with_url(@bin_url)
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def config_with_url(url)
35
+ require 'open-uri'
36
+
37
+ UI.puts "开始下载配置文件...\n"
38
+ file = open(url)
39
+ contents = YAML.safe_load(file.read)
40
+
41
+ UI.puts "开始同步配置文件...\n"
42
+ CBin.config.sync_config(contents.to_hash)
43
+ UI.puts "设置完成.\n".green
44
+ rescue Errno::ENOENT => e
45
+ raise Informative, "配置文件路径 #{url} 无效,请确认后重试."
46
+ end
47
+
48
+ def config_with_asker
49
+ asker = CBin::Config::Asker.new
50
+ asker.wellcome_message
51
+
52
+ config = {}
53
+ template_hash = CBin.config.template_hash
54
+ template_hash.each do |k, v|
55
+ default = begin
56
+ CBin.config.send(k)
57
+ rescue StandardError
58
+ nil
59
+ end
60
+ config[k] = asker.ask_with_answer(v[:description], default, v[:selection])
61
+ end
62
+
63
+ CBin.config.sync_config(config)
64
+ asker.done_message
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,70 @@
1
+
2
+ require 'cocoapods-lhj-bin/config/config_hot_key_asker'
3
+
4
+ module Pod
5
+ class Command
6
+ class Bin < Command
7
+ class Inithk < Bin
8
+ self.summary = '初始化快捷键配置.'
9
+ self.description = <<-DESC
10
+ 创建 文件,在其中保存插件需要的配置信息,
11
+ 如二进制私有源地址、源码私有源地址等。
12
+ DESC
13
+
14
+ def self.options
15
+ [
16
+ ['--bin-url=URL', '配置文件地址,直接从此地址下载配置文件']
17
+ ].concat(super)
18
+ end
19
+
20
+ def initialize(argv)
21
+ @bin_url = argv.option('bin-url')
22
+ super
23
+ end
24
+
25
+ def run
26
+ if @bin_url.nil?
27
+ config_with_asker
28
+ else
29
+ config_with_url(@bin_url)
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def config_with_url(url)
36
+ require 'open-uri'
37
+
38
+ UI.puts "开始下载配置文件...\n"
39
+ file = open(url)
40
+ contents = YAML.safe_load(file.read)
41
+
42
+ UI.puts "开始同步配置文件...\n"
43
+ CBin.config_hot_key.sync_config(contents.to_hash)
44
+ UI.puts "设置完成.\n".green
45
+ rescue Errno::ENOENT => e
46
+ raise Informative, "配置文件路径 #{url} 无效,请确认后重试."
47
+ end
48
+
49
+ def config_with_asker
50
+ asker = CBin::Config_Hot_Key::Asker.new
51
+ asker.wellcome_message
52
+
53
+ config = {}
54
+ template_hash = CBin.config_hot_key.template_hash
55
+ template_hash.each do |k, v|
56
+ default = begin
57
+ CBin.config_hot_key.send(k)
58
+ rescue StandardError
59
+ nil
60
+ end
61
+ config[k] = asker.ask_with_answer(v[:description], default, v[:selection])
62
+ end
63
+
64
+ CBin.config_hot_key.sync_config(config)
65
+ asker.done_message
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end