cocoapods-lhj-bin 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,87 @@
1
+ require 'cocoapods-lhj-bin/native/podfile'
2
+ require 'cocoapods/command/gen'
3
+ require 'cocoapods/generate'
4
+ require 'cocoapods-lhj-bin/helpers/framework_builder'
5
+ require 'cocoapods-lhj-bin/helpers/library_builder'
6
+ require 'cocoapods-lhj-bin/helpers/sources_helper'
7
+ require 'cocoapods-lhj-bin/command/bin/spec/push'
8
+
9
+ module CBin
10
+ class Upload
11
+ class Helper
12
+ include CBin::SourcesHelper
13
+
14
+ def initialize(spec, code_dependencies,sources)
15
+ @spec = spec
16
+ @code_dependencies = code_dependencies
17
+ @sources = sources
18
+ end
19
+
20
+ def upload
21
+ Dir.chdir(CBin::Config::Builder.instance.root_dir) do
22
+ # 创建binary-template.podsepc
23
+ # 上传二进制文件
24
+ # 上传二进制 podspec
25
+ res_zip = curl_zip
26
+ if res_zip
27
+ filename = spec_creator
28
+ push_binary_repo(filename)
29
+ end
30
+ res_zip
31
+ end
32
+ end
33
+
34
+ def spec_creator
35
+ spec_creator = CBin::SpecificationSource::Creator.new(@spec)
36
+ spec_creator.create
37
+ spec_creator.write_spec_file
38
+ spec_creator.filename
39
+ end
40
+
41
+ #推送二进制
42
+ # curl http://ci.xxx:9192/frameworks -F "name=IMYFoundation" -F "version=7.7.4.2" -F "annotate=IMYFoundation_7.7.4.2_log" -F "file=@bin-zip/bin_IMYFoundation_7.7.4.2.zip"
43
+ def curl_zip
44
+ zip_file = "#{CBin::Config::Builder.instance.library_file(@spec)}.zip"
45
+ res = File.exist?(zip_file)
46
+ unless res
47
+ zip_file = CBin::Config::Builder.instance.framework_zip_file(@spec) + ".zip"
48
+ res = File.exist?(zip_file)
49
+ end
50
+ if res
51
+ command = "curl #{CBin.config.binary_upload_url} -F \"name=#{@spec.name}\" -F \"version=#{@spec.version}\" -F \"annotate=#{@spec.name}_#{@spec.version}_log\" -F \"file=@#{zip_file}\""
52
+ print <<EOF
53
+ 上传二进制文件
54
+ #{command}
55
+ EOF
56
+ upload_result = `#{command}`
57
+ puts "#{upload_result}"
58
+ end
59
+
60
+ res
61
+ end
62
+
63
+
64
+ # 上传二进制 podspec
65
+ def push_binary_repo(binary_podsepc_json)
66
+ argvs = [
67
+ "#{binary_podsepc_json}",
68
+ "--binary",
69
+ "--sources=#{sources_option(@code_dependencies, @sources)},https:\/\/cdn.cocoapods.org",
70
+ "--skip-import-validation",
71
+ "--use-libraries",
72
+ "--allow-warnings",
73
+ "--verbose",
74
+ "--code-dependencies"
75
+ ]
76
+ if @verbose
77
+ argvs += ['--verbose']
78
+ end
79
+
80
+ push = Pod::Command::Bin::Repo::Push.new(CLAide::ARGV.new(argvs))
81
+ push.validate!
82
+ push.run
83
+ end
84
+
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,19 @@
1
+ require 'cocoapods'
2
+ require 'cocoapods-lhj-bin/native/podfile'
3
+ require 'cocoapods-lhj-bin/native/installation_options'
4
+ require 'cocoapods-lhj-bin/native/specification'
5
+ require 'cocoapods-lhj-bin/native/path_source'
6
+ require 'cocoapods-lhj-bin/native/analyzer'
7
+ require 'cocoapods-lhj-bin/native/installer'
8
+ require 'cocoapods-lhj-bin/native/podfile_generator'
9
+ require 'cocoapods-lhj-bin/native/pod_source_installer'
10
+ require 'cocoapods-lhj-bin/native/linter'
11
+ require 'cocoapods-lhj-bin/native/resolver'
12
+ require 'cocoapods-lhj-bin/native/source'
13
+ require 'cocoapods-lhj-bin/native/validator'
14
+ require 'cocoapods-lhj-bin/native/acknowledgements'
15
+ require 'cocoapods-lhj-bin/native/sandbox_analyzer'
16
+ require 'cocoapods-lhj-bin/native/podspec_finder'
17
+ require 'cocoapods-lhj-bin/native/file_accessor'
18
+ require 'cocoapods-lhj-bin/native/pod_target_installer'
19
+ require 'cocoapods-lhj-bin/native/target_validator'
@@ -0,0 +1,27 @@
1
+
2
+
3
+ module Pod
4
+ module Generator
5
+ class Acknowledgements
6
+ def license_text(spec)
7
+ return nil unless spec.license
8
+
9
+ text = spec.license[:text]
10
+ unless text
11
+ if license_file = spec.license[:file]
12
+ license_path = file_accessor(spec).root + license_file
13
+ if File.exist?(license_path)
14
+ text = IO.read(license_path)
15
+ else
16
+ # UI.warn "Unable to read the license file `#{license_file}` " \
17
+ # "for the spec `#{spec}`"
18
+ end
19
+ elsif license_file = file_accessor(spec).license
20
+ text = IO.read(license_file)
21
+ end
22
+ end
23
+ text
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,55 @@
1
+
2
+
3
+ require 'parallel'
4
+ require 'cocoapods'
5
+
6
+ module Pod
7
+ class Installer
8
+ class Analyzer
9
+ # > 1.6.0
10
+ # all_specs[dep.name] 为 nil 会崩溃
11
+ # 主要原因是 all_specs 分析错误
12
+ # 查看 source 是否正确
13
+ #
14
+ # def dependencies_for_specs(specs, platform, all_specs)
15
+ # return [] if specs.empty? || all_specs.empty?
16
+
17
+ # dependent_specs = Set.new
18
+
19
+ # specs.each do |s|
20
+ # s.dependencies(platform).each do |dep|
21
+ # all_specs[dep.name].each do |spec|
22
+ # dependent_specs << spec
23
+ # end
24
+ # end
25
+ # end
26
+
27
+ # dependent_specs - specs
28
+ # end
29
+
30
+ # > 1.5.3 版本
31
+ # rewrite update_repositories
32
+ #
33
+ alias old_update_repositories update_repositories
34
+ def update_repositories
35
+ if installation_options.update_source_with_multi_processes
36
+ # 并发更新私有源
37
+ # 这里多线程会导致 pod update 额外输出 --verbose 的内容
38
+ # 不知道为什么?
39
+ Parallel.each(sources.uniq(&:url), in_processes: 4) do |source|
40
+ if source.git?
41
+ config.sources_manager.update(source.name, true)
42
+ else
43
+ UI.message "Skipping `#{source.name}` update because the repository is not a git source repository."
44
+ end
45
+ end
46
+ @specs_updated = true
47
+ else
48
+ old_update_repositories
49
+ end
50
+ end
51
+
52
+
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,28 @@
1
+ require 'macho'
2
+ require 'cocoapods'
3
+
4
+ module Pod
5
+ class Sandbox
6
+ class FileAccessor
7
+
8
+ # swift动态库 需要设置为true
9
+ def dynamic_binary?(binary)
10
+ @cached_dynamic_binary_results ||= {}
11
+ return @cached_dynamic_binary_results[binary] unless @cached_dynamic_binary_results[binary].nil?
12
+ return false unless binary.file?
13
+
14
+ @cached_dynamic_binary_results[binary] = MachO.open(binary).dylib?
15
+ rescue MachO::MachOError
16
+ @cached_dynamic_binary_results[binary] = true
17
+
18
+ end
19
+
20
+ # def expanded_paths(patterns, options = {})
21
+ # return [] if patterns.empty?
22
+ # path_list.glob(patterns, options).flatten.compact.uniq
23
+ # end
24
+
25
+ #-----------------------------------------------------------------------#
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+
2
+ require 'cocoapods'
3
+
4
+ module Pod
5
+ class Installer
6
+ class InstallationOptions
7
+ def self.env_option(key, default = true)
8
+ option key, ENV[key.to_s].nil? ? default : ENV[key.to_s] == 'true'
9
+ end
10
+
11
+ # 不同 source 存在相同 spec 名时,默认不警告
12
+ defaults.delete('warn_for_multiple_pod_sources')
13
+ env_option :warn_for_multiple_pod_sources, false
14
+
15
+ # 是否警告不安全 source (如 http )
16
+ env_option :warn_for_unsecure_source, false
17
+
18
+ # 是否多线程执行 install_pod_sources
19
+ env_option :install_with_multi_threads, true
20
+
21
+ # 是否多进程执行 update_repositories
22
+ env_option :update_source_with_multi_processes, true
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,135 @@
1
+ require 'cocoapods/installer/project_cache/target_metadata'
2
+ require 'parallel'
3
+ require 'cocoapods'
4
+ require 'xcodeproj'
5
+ require 'cocoapods-lhj-bin/native/pod_source_installer'
6
+
7
+ module Pod
8
+ class Installer
9
+ alias old_create_pod_installer create_pod_installer
10
+ def create_pod_installer(pod_name)
11
+ installer = old_create_pod_installer(pod_name)
12
+ installer.installation_options = installation_options
13
+ installer
14
+ end
15
+
16
+ alias old_install_pod_sources install_pod_sources
17
+ def install_pod_sources
18
+ if installation_options.install_with_multi_threads
19
+ if Pod.match_version?('~> 1.4.0')
20
+ install_pod_sources_for_version_in_1_4_0
21
+ elsif Pod.match_version?('~> 1.5')
22
+ install_pod_sources_for_version_above_1_5_0
23
+ else
24
+ old_install_pod_sources
25
+ end
26
+ else
27
+ old_install_pod_sources
28
+ end
29
+ end
30
+
31
+ # rewrite install_pod_sources
32
+ def install_pod_sources_for_version_in_1_4_0
33
+ @installed_specs = []
34
+ pods_to_install = sandbox_state.added | sandbox_state.changed
35
+ title_options = { verbose_prefix: '-> '.green }
36
+ Parallel.each(root_specs.sort_by(&:name), in_threads: 4) do |spec|
37
+ if pods_to_install.include?(spec.name)
38
+ if sandbox_state.changed.include?(spec.name) && sandbox.manifest
39
+ previous = sandbox.manifest.version(spec.name)
40
+ title = "Installing #{spec.name} #{spec.version} (was #{previous})"
41
+ else
42
+ title = "Installing #{spec}"
43
+ end
44
+ UI.titled_section(title.green, title_options) do
45
+ install_source_of_pod(spec.name)
46
+ end
47
+ else
48
+ UI.titled_section("Using #{spec}", title_options) do
49
+ create_pod_installer(spec.name)
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ def install_pod_sources_for_version_above_1_5_0
56
+ @installed_specs = []
57
+ pods_to_install = sandbox_state.added | sandbox_state.changed
58
+ title_options = { verbose_prefix: '-> '.green }
59
+ # 多进程下载,多线程时 log 会显著交叉,多进程好点,但是多进程需要利用文件锁对 cache 进行保护
60
+ # in_processes: 10
61
+ Parallel.each(root_specs.sort_by(&:name), in_threads: 4) do |spec|
62
+ if pods_to_install.include?(spec.name)
63
+ if sandbox_state.changed.include?(spec.name) && sandbox.manifest
64
+ current_version = spec.version
65
+ previous_version = sandbox.manifest.version(spec.name)
66
+ has_changed_version = current_version != previous_version
67
+ current_repo = analysis_result.specs_by_source.detect do |key, values|
68
+ break key if values.map(&:name).include?(spec.name)
69
+ end
70
+ current_repo &&= current_repo.url || current_repo.name
71
+ previous_spec_repo = sandbox.manifest.spec_repo(spec.name)
72
+ has_changed_repo = !previous_spec_repo.nil? && current_repo && (current_repo != previous_spec_repo)
73
+ title = "Installing #{spec.name} #{spec.version}"
74
+ if has_changed_version && has_changed_repo
75
+ title += " (was #{previous_version} and source changed to `#{current_repo}` from `#{previous_spec_repo}`)"
76
+ end
77
+ if has_changed_version && !has_changed_repo
78
+ title += " (was #{previous_version})"
79
+ end
80
+ if !has_changed_version && has_changed_repo
81
+ title += " (source changed to `#{current_repo}` from `#{previous_spec_repo}`)"
82
+ end
83
+ else
84
+ title = "Installing #{spec}"
85
+ end
86
+ UI.titled_section(title.green, title_options) do
87
+ install_source_of_pod(spec.name)
88
+ end
89
+ else
90
+ UI.titled_section("Using #{spec}", title_options) do
91
+ create_pod_installer(spec.name)
92
+ end
93
+ end
94
+ end
95
+ end
96
+
97
+ alias old_write_lockfiles write_lockfiles
98
+ def write_lockfiles
99
+ old_write_lockfiles
100
+ if File.exist?('Podfile_local')
101
+
102
+ project = Xcodeproj::Project.open(config.sandbox.project_path)
103
+ #获取主group
104
+ group = project.main_group
105
+ group.set_source_tree('SOURCE_ROOT')
106
+ #向group中添加 文件引用
107
+ file_ref = group.new_reference(config.sandbox.root + '../Podfile_local')
108
+ #podfile_local排序
109
+ podfile_local_group = group.children.last
110
+ group.children.pop
111
+ group.children.unshift(podfile_local_group)
112
+ #保存
113
+ project.save
114
+ end
115
+ end
116
+ end
117
+
118
+ module Downloader
119
+ class Cache
120
+ # 多线程锁
121
+ @@lock = Mutex.new
122
+
123
+ # 后面如果要切到进程的话,可以在 cache root 里面新建一个文件
124
+ # 利用这个文件 lock
125
+ # https://stackoverflow.com/questions/23748648/using-fileflock-as-ruby-global-lock-mutex-for-processes
126
+
127
+ # rmtree 在多进程情况下可能 Directory not empty @ dir_s_rmdir 错误
128
+ # old_ensure_matching_version 会移除不是同一个 CocoaPods 版本的组件缓存
129
+ alias old_ensure_matching_version ensure_matching_version
130
+ def ensure_matching_version
131
+ @@lock.synchronize { old_ensure_matching_version }
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,26 @@
1
+
2
+
3
+ require 'cocoapods-lhj-bin/native/specification'
4
+
5
+ module Pod
6
+ class Specification
7
+ class Linter
8
+ # !@group Lint steps
9
+
10
+ # Checks that the spec's root name matches the filename.
11
+ #
12
+ # @return [void]
13
+ #
14
+ def validate_root_name
15
+ if spec.root.name && file
16
+ acceptable_names = Specification::VALID_EXTNAME.map { |extname| "#{spec.root.name}#{extname}" }
17
+ names_match = acceptable_names.include?(file.basename.to_s)
18
+ unless names_match
19
+ results.add_error('name', 'The name of the spec should match the ' \
20
+ 'name of the file.')
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,33 @@
1
+
2
+
3
+ require 'cocoapods-lhj-bin/native/specification'
4
+
5
+ module Pod
6
+ module ExternalSources
7
+ # Provides support for fetching a specification file from a path local to
8
+ # the machine running the installation.
9
+ #
10
+ class PathSource < AbstractExternalSource
11
+ def normalized_podspec_path(declared_path)
12
+ extension = File.extname(declared_path)
13
+
14
+ if extension == '.podspec' || extension == '.json'
15
+ path_with_ext = declared_path
16
+ else
17
+ # 默认先从 binary podspec 找起,因为 binary podspec 的 subspec 可能比 code podspec 多
18
+ # 这里可能出现 code subspec 和 binary subspec 对应不上的情况,导致 lint 失败
19
+ # 所以不要在 code podspec 同一目录下保留 binary podspec
20
+ path_with_ext = Specification::VALID_EXTNAME
21
+ .map { |extname| "#{declared_path}/#{name}#{extname}" }
22
+ .find { |file| File.exist?(file) } || "#{declared_path}/#{name}.podspec"
23
+ end
24
+
25
+ UI.message "获取的 podspec 路径为 `#{path_with_ext}`"
26
+
27
+ podfile_dir = File.dirname(podfile_path || '')
28
+
29
+ File.expand_path(path_with_ext, podfile_dir)
30
+ end
31
+ end
32
+ end
33
+ end