cocoapods-imy-hycan-bin 0.1.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 (66) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +22 -0
  3. data/README.md +44 -0
  4. data/lib/cocoapods-imy-bin.rb +2 -0
  5. data/lib/cocoapods-imy-bin/command.rb +2 -0
  6. data/lib/cocoapods-imy-bin/command/bin.rb +61 -0
  7. data/lib/cocoapods-imy-bin/command/bin/archive.rb +229 -0
  8. data/lib/cocoapods-imy-bin/command/bin/auto.rb +199 -0
  9. data/lib/cocoapods-imy-bin/command/bin/code.rb +479 -0
  10. data/lib/cocoapods-imy-bin/command/bin/dup.rb +78 -0
  11. data/lib/cocoapods-imy-bin/command/bin/imy.rb +46 -0
  12. data/lib/cocoapods-imy-bin/command/bin/init.rb +69 -0
  13. data/lib/cocoapods-imy-bin/command/bin/initHotKey.rb +70 -0
  14. data/lib/cocoapods-imy-bin/command/bin/install.rb +48 -0
  15. data/lib/cocoapods-imy-bin/command/bin/lib/lint.rb +69 -0
  16. data/lib/cocoapods-imy-bin/command/bin/repo/update.rb +43 -0
  17. data/lib/cocoapods-imy-bin/command/bin/spec/create.rb +73 -0
  18. data/lib/cocoapods-imy-bin/command/bin/spec/push.rb +114 -0
  19. data/lib/cocoapods-imy-bin/command/bin/update.rb +154 -0
  20. data/lib/cocoapods-imy-bin/config/config.rb +137 -0
  21. data/lib/cocoapods-imy-bin/config/config_asker.rb +57 -0
  22. data/lib/cocoapods-imy-bin/config/config_builder.rb +216 -0
  23. data/lib/cocoapods-imy-bin/config/config_hot_key.rb +103 -0
  24. data/lib/cocoapods-imy-bin/config/config_hot_key_asker.rb +57 -0
  25. data/lib/cocoapods-imy-bin/gem_version.rb +10 -0
  26. data/lib/cocoapods-imy-bin/helpers.rb +5 -0
  27. data/lib/cocoapods-imy-bin/helpers/Info.plist +0 -0
  28. data/lib/cocoapods-imy-bin/helpers/build_helper.rb +158 -0
  29. data/lib/cocoapods-imy-bin/helpers/build_utils.rb +63 -0
  30. data/lib/cocoapods-imy-bin/helpers/framework.rb +85 -0
  31. data/lib/cocoapods-imy-bin/helpers/framework_builder.rb +444 -0
  32. data/lib/cocoapods-imy-bin/helpers/library.rb +54 -0
  33. data/lib/cocoapods-imy-bin/helpers/library_builder.rb +90 -0
  34. data/lib/cocoapods-imy-bin/helpers/sources_helper.rb +36 -0
  35. data/lib/cocoapods-imy-bin/helpers/spec_creator.rb +170 -0
  36. data/lib/cocoapods-imy-bin/helpers/spec_files_helper.rb +77 -0
  37. data/lib/cocoapods-imy-bin/helpers/spec_source_creator.rb +228 -0
  38. data/lib/cocoapods-imy-bin/helpers/upload_helper.rb +89 -0
  39. data/lib/cocoapods-imy-bin/native.rb +23 -0
  40. data/lib/cocoapods-imy-bin/native/acknowledgements.rb +27 -0
  41. data/lib/cocoapods-imy-bin/native/analyzer.rb +55 -0
  42. data/lib/cocoapods-imy-bin/native/file_accessor.rb +28 -0
  43. data/lib/cocoapods-imy-bin/native/installation_options.rb +25 -0
  44. data/lib/cocoapods-imy-bin/native/installer.rb +135 -0
  45. data/lib/cocoapods-imy-bin/native/linter.rb +26 -0
  46. data/lib/cocoapods-imy-bin/native/path_source.rb +33 -0
  47. data/lib/cocoapods-imy-bin/native/pod_source_installer.rb +19 -0
  48. data/lib/cocoapods-imy-bin/native/pod_target_installer.rb +94 -0
  49. data/lib/cocoapods-imy-bin/native/podfile.rb +91 -0
  50. data/lib/cocoapods-imy-bin/native/podfile_env.rb +37 -0
  51. data/lib/cocoapods-imy-bin/native/podfile_generator.rb +199 -0
  52. data/lib/cocoapods-imy-bin/native/podspec_finder.rb +25 -0
  53. data/lib/cocoapods-imy-bin/native/resolver.rb +230 -0
  54. data/lib/cocoapods-imy-bin/native/sandbox_analyzer.rb +34 -0
  55. data/lib/cocoapods-imy-bin/native/source.rb +35 -0
  56. data/lib/cocoapods-imy-bin/native/sources_manager.rb +20 -0
  57. data/lib/cocoapods-imy-bin/native/specification.rb +31 -0
  58. data/lib/cocoapods-imy-bin/native/target_validator.rb +41 -0
  59. data/lib/cocoapods-imy-bin/native/validator.rb +40 -0
  60. data/lib/cocoapods-imy-bin/source_provider_hook.rb +66 -0
  61. data/lib/cocoapods/imy/hycan/bin.rb +12 -0
  62. data/lib/cocoapods/imy/hycan/bin/version.rb +9 -0
  63. data/lib/cocoapods_plugin.rb +3 -0
  64. data/spec/command/bin_spec.rb +12 -0
  65. data/spec/spec_helper.rb +50 -0
  66. metadata +180 -0
@@ -0,0 +1,479 @@
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
+ # puts @config.inspect
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 "binary: #{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 "download source: #{target_path}"
83
+ FileUtils.rm_rf(target_path)
84
+
85
+ find_dependency = find_dependency(name)
86
+ # puts 'find:'
87
+ # puts find_dependency.inspect
88
+
89
+ podspec = findCodeRepoPath(name)
90
+
91
+ find_dependency.external_source = {
92
+ :podspec => podspec
93
+ }
94
+
95
+ spec = fetch_external_source(find_dependency, @config.podfile,@config.lockfile, @config.sandbox, true)
96
+
97
+ # puts "spec:", spec
98
+
99
+ download_request = Pod::Downloader::Request.new(:name => name, :spec => spec)
100
+ Downloader.download(download_request, Pathname.new(target_path), :can_cache => true)
101
+
102
+ target_path
103
+ end
104
+
105
+ #找出依赖
106
+ def find_dependency (name)
107
+ find_dependency = nil
108
+ @config.podfile.dependencies.each do |dependency|
109
+ if dependency.root_name.downcase == name.downcase
110
+ find_dependency = dependency
111
+ break
112
+ end
113
+ end
114
+ find_dependency
115
+ end
116
+
117
+ # 获取external_source 下的仓库
118
+ # @return spec
119
+ def fetch_external_source(dependency, podfile, lockfile, sandbox, use_lockfile_options)
120
+ source = ExternalSources.from_dependency(dependency, podfile.defined_in_file, true)
121
+ source.fetch(sandbox)
122
+ end
123
+
124
+ # 用xxd自己爬取真实打包时的码源位置
125
+ def readFromStaticFramework (binaryPath, repoName)
126
+
127
+ # if !File.exist?(binaryPath)
128
+ # raise 'binaryPath not exit!'
129
+ # end
130
+
131
+ res = searchByMatchNum(5, binaryPath, repoName)
132
+
133
+ if !res
134
+ res = searchByMatchNum(10, binaryPath, repoName)
135
+ end
136
+
137
+ if !res
138
+ res = searchByMatchNum(20, binaryPath, repoName)
139
+ end
140
+
141
+ # retry 3
142
+ if !res
143
+ raise 'retry 3! Error in find source path'
144
+ end
145
+
146
+ return res
147
+ end
148
+
149
+ def searchByMatchNum(num, binaryPath, repoName)
150
+ repo = repoName
151
+ if repoName.length > 15
152
+ repo = repoName[0, 3]
153
+ repo = 'Pods/' + repo
154
+ else
155
+ repo = '/' + repo + '/'
156
+ end
157
+
158
+ # puts "repo:", "#{repo}"
159
+
160
+ result = `xxd #{binaryPath} | grep '#{repo}' -B #{num}`
161
+ splitArray = result.split(/\n--\n/)
162
+
163
+ firstHit = ''
164
+ lines = []
165
+ if binaryPath.include?('.xcframework')
166
+ firstHit = splitArray[splitArray.length-1]
167
+ lines = firstHit.split(/\n/)
168
+ else
169
+ firstHit = splitArray[0]
170
+ lines = firstHit.split(/\n/)
171
+ end
172
+
173
+ newLines = []
174
+ lines.each do |item|
175
+ newLines.push(item[51, item.length])
176
+ end
177
+
178
+ # puts "newLines:", "#{newLines}"
179
+
180
+ resLine = newLines.join('')
181
+
182
+ prefix = '/Users/'
183
+ surfix = repo
184
+ match = resLine[/#{prefix}(.*?)#{surfix}/, 1]
185
+
186
+ if !match
187
+ return nil
188
+ end
189
+
190
+ if repoName.length > 15
191
+ resLine = prefix + match + "Pods/#{repoName}" # Pods
192
+ else
193
+ resLine = prefix + match + "/#{repoName}"
194
+ end
195
+
196
+
197
+ # puts "ln source:", "#{resLine}"
198
+
199
+ return resLine
200
+ end
201
+ #==========================link begin ==============
202
+
203
+ #链接,.a文件位置, 源码目录,工程名=IMYFoundation
204
+ def link(lib_file,target_path,basename)
205
+ dir = ''
206
+ is_dsym = false
207
+ if lib_file.include?('dSYMs')
208
+ is_dsym = true
209
+ dir = (`dwarfdump "#{lib_file}" | grep "AT_comp_dir" | head -1 | cut -d \\" -f2 `)
210
+ else
211
+ dir = readFromStaticFramework(lib_file, basename)
212
+ end
213
+
214
+ # sub_path = "#{basename}/bin-archive/#{basename}" #change
215
+ # dir = dir.gsub(sub_path, "").chomp #change #change
216
+
217
+ # UI.puts "dir = #{dir}" #change
218
+
219
+ unless File.exist?(dir)
220
+ # UI.puts "不存在 = #{dir}"
221
+ begin
222
+ FileUtils.mkdir_p(dir)
223
+ rescue SystemCallError
224
+ #判断用户目录是否存在
225
+ array = dir.split('/')
226
+ if array.length > 3
227
+ root_path = '/' + array[1] + '/' + array[2]
228
+ unless File.exist?(root_path)
229
+ raise "由于权限不足,请手动创建#{root_path} 后重试 sudo mkdir #{root_path}" #change
230
+ end
231
+ end
232
+ end
233
+ end
234
+
235
+ if is_dsym
236
+ FileUtils.rm_rf(File.join(dir,basename))
237
+ `ln -s #{target_path} #{dir}/#{basename}`
238
+ puts "ln -s #{target_path} #{dir}/#{basename}"
239
+ else
240
+ FileUtils.rm_rf(dir)
241
+ `ln -s #{target_path} #{dir}`
242
+ puts "ln -s #{target_path} #{dir}"
243
+ end
244
+
245
+ check(lib_file,dir,basename)
246
+ end
247
+
248
+ def check(lib_file,dir,basename)
249
+ # file = `dwarfdump "#{lib_file}" | grep -E "DW_AT_decl_file.*#{basename}.*\\.m|\\.c" | head -1 | cut -d \\" -f2`
250
+ # puts 'dir:', dir
251
+ # puts 'basename', basename
252
+ # puts 'lib_file', lib_file
253
+ # if File.exist?(file)
254
+ # raise "#{file} 不存在 请检测代码源是否正确~"
255
+ # end
256
+ UI.puts "link successfully!"
257
+ UI.puts "view linked source at path: #{dir}"
258
+ end
259
+
260
+ def get_lib_path(name)
261
+ dir = Pathname.new(File.join(Pathname.pwd,"Pods",name))
262
+ lib_name = "lib#{name}.a"
263
+ lib_path = File.join(dir,lib_name)
264
+
265
+ unless File.exist?(lib_path)
266
+ if dir.children.first.to_s.include?('.DS_Store')
267
+ lib_path = File.join(dir.children[1],lib_name)
268
+ else
269
+ lib_path = File.join(dir.children.first,lib_name)
270
+ end
271
+ end
272
+
273
+ unless File.exist?(lib_path)
274
+ temp = ''
275
+ dir.children.each do |item|
276
+ if item.basename.to_s.include?('.framework')
277
+ temp = item
278
+ end
279
+ end
280
+ realName = Pathname.new(temp).basename.to_s
281
+ if realName.include?('.framework')
282
+ realName = realName.gsub(/.framework/, '')
283
+ end
284
+ lib_path = File.join(dir, "#{realName}.framework",realName)
285
+ end
286
+
287
+ unless File.exist?(lib_path)
288
+ temp = ''
289
+ dir.children.each do |item|
290
+ if item.basename.to_s.include?('.xcframework')
291
+ temp = item
292
+ end
293
+ end
294
+ realName = Pathname.new(temp).basename.to_s
295
+ if realName.include?('.xcframework')
296
+ realName = realName.gsub(/.xcframework/, '')
297
+ end
298
+
299
+ lib_path = File.join(dir,"#{realName}.xcframework","ios-arm64_i386_x86_64-simulator", "dSYMs", "#{realName}.framework.dSYMs")
300
+
301
+ unless File.exist?(lib_path)
302
+ lib_path = File.join(dir,"#{realName}.xcframework","ios-arm64_x86_64-simulator", "dSYMs", "#{realName}.framework.dSYMs")
303
+ end
304
+
305
+ unless File.exist?(lib_path)
306
+ lib_path = File.join(dir,"#{realName}.xcframework","ios-x86_64-simulator", "dSYMs", "#{realName}.framework.dSYMs")
307
+ end
308
+
309
+ unless File.exist?(lib_path)
310
+ lib_path = File.join(dir,"#{realName}.xcframework","ios-arm64_i386_x86_64-simulator", "#{realName}.framework", realName)
311
+ end
312
+
313
+ unless File.exist?(lib_path)
314
+ lib_path = File.join(dir,"#{realName}.xcframework","ios-arm64_x86_64-simulator", "#{realName}.framework", realName)
315
+ end
316
+
317
+ unless File.exist?(lib_path)
318
+ lib_path = File.join(dir,"#{realName}.xcframework","ios-x86_64-simulator", "#{realName}.framework", realName)
319
+ end
320
+
321
+ end
322
+ lib_path
323
+ end
324
+
325
+ def cocoapodsRepos()
326
+ result = `pod repo list` #Pod::Command::Repo::List.run({})
327
+ groups = result.split(/\n\n/)
328
+
329
+ repos = []
330
+ index = 0
331
+ groups[0, groups.length-1].each do |item|
332
+ temp = item.split(/\n/)
333
+ if index == 0
334
+ lines = temp[1, temp.length-1]
335
+ else
336
+ lines = temp
337
+ end
338
+ key = lines.first
339
+ repo = {}
340
+ lines[1, lines.length-1].each do |value|
341
+ tub = value.split(': ')
342
+ valkey = tub.first.gsub(/- /, '')
343
+ repo[valkey] = tub.last.gsub(/ /, '')
344
+ end
345
+ map = {}
346
+ map[key] = repo
347
+ repos.push(map)
348
+ index += 1
349
+ end
350
+ repos
351
+ end
352
+
353
+ def findCodeRepoPath(podName)
354
+ pathbasename = Pathname.pwd.basename.to_s
355
+ sepcpath = File.join(Pathname.pwd, "..", "#{pathbasename}-build-temp", "bin-spec")
356
+ result = File.join(sepcpath, "#{podName}.podspec.json")
357
+ unless File.exist?(result)
358
+ result = File.join(sepcpath, "#{podName}.podspec")
359
+ end
360
+
361
+ if File.exist?(result)
362
+ return result
363
+ else
364
+
365
+ version = findPodVersion(File.join(Pathname.pwd,"Podfile.lock"), podName)
366
+ if version == nil
367
+ raise "cannot find the versoin of your pod '#{name}''"
368
+ end
369
+
370
+ pathYml = File.join(@config.home_dir, 'bin_dev.yml')
371
+ json = YAML.load(File.open(pathYml))
372
+ repoUrl = json['code_repo_url']
373
+ repos = cocoapodsRepos()
374
+ path = ''
375
+ repos.each do |item|
376
+ val = item.values.first
377
+ if val['URL'] == repoUrl
378
+ path = val['Path']
379
+ end
380
+ end
381
+ puts 'path ==>', path
382
+ if path == ''
383
+ raise 'cannot find correct repo in your cocoapods repos, please run "pod bin init" first!'
384
+ end
385
+ result = File.join(path, podName, version, "#{podName}.podspec.json")
386
+ unless File.exist?(result)
387
+ result = File.join(path, podName, version, "#{podName}.podspec")
388
+ end
389
+ if File.exist?(result)
390
+ return result
391
+ else
392
+ raise 'cannot find your podpsec file in code repod, please run "pod bin push XXX.podspec.json" first!'
393
+ end
394
+ end
395
+ end
396
+
397
+ def findPodVersion(podfilePath, podName)
398
+ podlockMap = YAML.load(File.open(podfilePath))
399
+ pods = podlockMap['PODS']
400
+ pods.each do |pod|
401
+ if pod.class.to_s == 'Hash'
402
+ keyName = pod.keys.first
403
+ repo = keyName.split(' ').first
404
+ version = keyName.split(' ').last
405
+ if repo == podName
406
+ return version.gsub(/\(/, '').gsub(/\)/, '')
407
+ end
408
+ else
409
+ repo = pod.split(' ').first
410
+ version = pod.split(' ').last
411
+ if repo == podName
412
+ return version.gsub(/\(/, '').gsub(/\)/, '')
413
+ end
414
+ end
415
+ end
416
+ return nil
417
+ end
418
+
419
+ #源码地址
420
+ # def get_gitlib_iOS_path(name)
421
+ # "git@gitlab.xxx.com:iOS/#{name}.git"
422
+ # end
423
+ #要转换的地址,Github-iOS默认都是静态库
424
+ # def git_gitlib_iOS_path
425
+ # 'git@gitlab.xxx.com:Github-iOS/'
426
+ # end
427
+
428
+
429
+ #要转换的地址,Github-iOS默认都是静态库
430
+ # def http_gitlib_GitHub_iOS_path
431
+ # 'https://gitlab.xxx.com/Github-iOS/'
432
+ # end
433
+
434
+ #要转换的地址,iOS默认都是静态库
435
+ # def http_gitlib_iOS_path
436
+ # 'https://gitlab.xxx.com/iOS/'
437
+ # end
438
+
439
+ #==========================list begin ==============
440
+
441
+ def list
442
+ Dir.entries(source_root).each do |sub|
443
+ UI.puts "- #{sub}" unless sub.include?('.')
444
+ end
445
+ UI.puts "加载完成"
446
+ end
447
+
448
+
449
+ #==========================clean begin ==============
450
+ def all_clean
451
+ FileUtils.rm_rf(source_root) if File.directory?(source_root)
452
+ UI.puts "清理完成 #{source_root}"
453
+ end
454
+
455
+ def clean
456
+ raise "请输入要删除的组件库" if @names.nil?
457
+ @names.each do |name|
458
+ full_path = File.join(source_root,name)
459
+ if File.directory?(full_path)
460
+ FileUtils.rm_rf(full_path)
461
+ else
462
+ UI.puts "找不到 #{full_path}".yellow
463
+ end
464
+ end
465
+ UI.puts "清理完成 #{@names.to_s}"
466
+ end
467
+
468
+ private
469
+
470
+ def source_root
471
+ dir = File.join(@config.cache_root,"Source")
472
+ FileUtils.mkdir_p(dir) unless File.exist? dir
473
+ dir
474
+ end
475
+
476
+ end
477
+ end
478
+ end
479
+ end