cocoapods-meitu-bin 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +20 -0
- data/README.md +56 -0
- data/lib/cocoapods-meitu-bin/command/bin/archive.rb +206 -0
- data/lib/cocoapods-meitu-bin/command/bin/auto.rb +212 -0
- data/lib/cocoapods-meitu-bin/command/bin/build_all.rb +345 -0
- data/lib/cocoapods-meitu-bin/command/bin/header_files_specifications.rb +262 -0
- data/lib/cocoapods-meitu-bin/command/bin/init.rb +72 -0
- data/lib/cocoapods-meitu-bin/command/bin/install.rb +44 -0
- data/lib/cocoapods-meitu-bin/command/bin/lib/lint.rb +67 -0
- data/lib/cocoapods-meitu-bin/command/bin/lock/dependency.rb +89 -0
- data/lib/cocoapods-meitu-bin/command/bin/lock/spec_repo.rb +105 -0
- data/lib/cocoapods-meitu-bin/command/bin/lock/version.rb +68 -0
- data/lib/cocoapods-meitu-bin/command/bin/lock.rb +36 -0
- data/lib/cocoapods-meitu-bin/command/bin/output_source.rb +146 -0
- data/lib/cocoapods-meitu-bin/command/bin/repo/push.rb +88 -0
- data/lib/cocoapods-meitu-bin/command/bin/repo/update.rb +42 -0
- data/lib/cocoapods-meitu-bin/command/bin/repo.rb +14 -0
- data/lib/cocoapods-meitu-bin/command/bin/source/add.rb +148 -0
- data/lib/cocoapods-meitu-bin/command/bin/source/delete.rb +59 -0
- data/lib/cocoapods-meitu-bin/command/bin/source/list.rb +46 -0
- data/lib/cocoapods-meitu-bin/command/bin/source.rb +30 -0
- data/lib/cocoapods-meitu-bin/command/bin/spec/create.rb +73 -0
- data/lib/cocoapods-meitu-bin/command/bin/spec/lint.rb +109 -0
- data/lib/cocoapods-meitu-bin/command/bin/spec.rb +13 -0
- data/lib/cocoapods-meitu-bin/command/bin/update.rb +154 -0
- data/lib/cocoapods-meitu-bin/command/bin/upload.rb +175 -0
- data/lib/cocoapods-meitu-bin/command/bin.rb +69 -0
- data/lib/cocoapods-meitu-bin/command.rb +1 -0
- data/lib/cocoapods-meitu-bin/config/config.rb +149 -0
- data/lib/cocoapods-meitu-bin/config/config_asker.rb +57 -0
- data/lib/cocoapods-meitu-bin/config/config_builder.rb +216 -0
- data/lib/cocoapods-meitu-bin/gem_version.rb +9 -0
- data/lib/cocoapods-meitu-bin/helpers/Info.plist +0 -0
- data/lib/cocoapods-meitu-bin/helpers/buildAll/bin_helper.rb +97 -0
- data/lib/cocoapods-meitu-bin/helpers/buildAll/builder.rb +434 -0
- data/lib/cocoapods-meitu-bin/helpers/buildAll/podspec_util.rb +140 -0
- data/lib/cocoapods-meitu-bin/helpers/buildAll/zip_file_helper.rb +87 -0
- data/lib/cocoapods-meitu-bin/helpers/build_helper.rb +167 -0
- data/lib/cocoapods-meitu-bin/helpers/build_utils.rb +64 -0
- data/lib/cocoapods-meitu-bin/helpers/framework.rb +86 -0
- data/lib/cocoapods-meitu-bin/helpers/framework_builder.rb +551 -0
- data/lib/cocoapods-meitu-bin/helpers/library.rb +54 -0
- data/lib/cocoapods-meitu-bin/helpers/library_builder.rb +90 -0
- data/lib/cocoapods-meitu-bin/helpers/pod_size_helper.rb +54 -0
- data/lib/cocoapods-meitu-bin/helpers/sources_helper.rb +35 -0
- data/lib/cocoapods-meitu-bin/helpers/spec_creator.rb +170 -0
- data/lib/cocoapods-meitu-bin/helpers/spec_files_helper.rb +80 -0
- data/lib/cocoapods-meitu-bin/helpers/spec_source_creator.rb +304 -0
- data/lib/cocoapods-meitu-bin/helpers/upload_helper.rb +104 -0
- data/lib/cocoapods-meitu-bin/helpers.rb +5 -0
- data/lib/cocoapods-meitu-bin/native/acknowledgements.rb +27 -0
- data/lib/cocoapods-meitu-bin/native/analyzer.rb +109 -0
- data/lib/cocoapods-meitu-bin/native/file_accessor.rb +28 -0
- data/lib/cocoapods-meitu-bin/native/gen.rb +79 -0
- data/lib/cocoapods-meitu-bin/native/installation_options.rb +28 -0
- data/lib/cocoapods-meitu-bin/native/installer.rb +259 -0
- data/lib/cocoapods-meitu-bin/native/linter.rb +26 -0
- data/lib/cocoapods-meitu-bin/native/lockfile.rb +85 -0
- data/lib/cocoapods-meitu-bin/native/path_source.rb +33 -0
- data/lib/cocoapods-meitu-bin/native/pod_source_installer.rb +19 -0
- data/lib/cocoapods-meitu-bin/native/pod_target_installer.rb +87 -0
- data/lib/cocoapods-meitu-bin/native/podfile.rb +99 -0
- data/lib/cocoapods-meitu-bin/native/podfile_env.rb +38 -0
- data/lib/cocoapods-meitu-bin/native/podfile_generator.rb +201 -0
- data/lib/cocoapods-meitu-bin/native/podspec_finder.rb +25 -0
- data/lib/cocoapods-meitu-bin/native/resolver.rb +299 -0
- data/lib/cocoapods-meitu-bin/native/sandbox_analyzer.rb +34 -0
- data/lib/cocoapods-meitu-bin/native/source.rb +35 -0
- data/lib/cocoapods-meitu-bin/native/sources_manager.rb +21 -0
- data/lib/cocoapods-meitu-bin/native/specification.rb +31 -0
- data/lib/cocoapods-meitu-bin/native/target_validator.rb +41 -0
- data/lib/cocoapods-meitu-bin/native/validator.rb +40 -0
- data/lib/cocoapods-meitu-bin/native.rb +26 -0
- data/lib/cocoapods-meitu-bin/source_provider_hook.rb +68 -0
- data/lib/cocoapods-meitu-bin.rb +2 -0
- data/lib/cocoapods_plugin.rb +11 -0
- data/spec/command/bin_spec.rb +12 -0
- data/spec/spec_helper.rb +50 -0
- metadata +201 -0
@@ -0,0 +1,104 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
# copy from https://github.com/CocoaPods/cocoapods-packager
|
4
|
+
|
5
|
+
require 'cocoapods-meitu-bin/native/podfile'
|
6
|
+
require 'cocoapods/command/gen'
|
7
|
+
require 'cocoapods/generate'
|
8
|
+
require 'cocoapods-meitu-bin/helpers/framework_builder'
|
9
|
+
require 'cocoapods-meitu-bin/helpers/library_builder'
|
10
|
+
require 'cocoapods-meitu-bin/helpers/sources_helper'
|
11
|
+
require 'cocoapods-meitu-bin/command/bin/repo/push'
|
12
|
+
require 'json'
|
13
|
+
|
14
|
+
module CBin
|
15
|
+
class Upload
|
16
|
+
class Helper
|
17
|
+
include CBin::SourcesHelper
|
18
|
+
|
19
|
+
def initialize(spec,code_dependencies,sources)
|
20
|
+
@spec = spec
|
21
|
+
@code_dependencies = code_dependencies
|
22
|
+
@sources = sources
|
23
|
+
end
|
24
|
+
|
25
|
+
# 创建binary-template.podsepc
|
26
|
+
# 上传二进制文件
|
27
|
+
# 上传二进制 podspec
|
28
|
+
def upload
|
29
|
+
Dir.chdir(CBin::Config::Builder.instance.root_dir) do
|
30
|
+
# 上传zip包
|
31
|
+
res_zip = curl_zip
|
32
|
+
if res_zip
|
33
|
+
# 创建二进制podspec
|
34
|
+
filename = spec_creator
|
35
|
+
# 上传二进制 podspec
|
36
|
+
push_binary_repo(filename)
|
37
|
+
end
|
38
|
+
res_zip
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# 创建二进制podspec
|
43
|
+
def spec_creator
|
44
|
+
spec_creator = CBin::SpecificationSource::Creator.new(@spec)
|
45
|
+
# 创建二进制podspec
|
46
|
+
spec_creator.create
|
47
|
+
# 将二进制podspec写入文件
|
48
|
+
spec_creator.write_spec_file
|
49
|
+
# 返回二进制podspec文件路径
|
50
|
+
spec_creator.filename
|
51
|
+
end
|
52
|
+
|
53
|
+
# 推送二进制
|
54
|
+
# 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"
|
55
|
+
def curl_zip
|
56
|
+
# output_name = File.join(CBin::Config::Builder.instance.zip_dir, CBin::Config::Builder.instance.framework_name_zip)
|
57
|
+
zip_file = "#{CBin::Config::Builder.instance.library_file(@spec)}.zip"
|
58
|
+
res = File.exist?(zip_file)
|
59
|
+
unless res
|
60
|
+
zip_file = CBin::Config::Builder.instance.framework_zip_file(@spec) + ".zip"
|
61
|
+
res = File.exist?(zip_file)
|
62
|
+
end
|
63
|
+
if res
|
64
|
+
Pod::UI.title "Uploading binary zip file #{@spec.name} (#{@spec.version})" do
|
65
|
+
command = "curl -F \"name=#{@spec.module_name}\" -F \"version=#{@spec.version}\" -F \"file=@#{zip_file}\" #{CBin.config.binary_upload_url_str}"
|
66
|
+
Pod::UI.info "#{command}"
|
67
|
+
json = `#{command}`
|
68
|
+
Pod::UI.info json
|
69
|
+
error_code = JSON.parse(json)["error_code"]
|
70
|
+
if error_code == 0
|
71
|
+
Pod::UI.info "#{@spec.name} (#{@spec.version}) 上传成功".green
|
72
|
+
else
|
73
|
+
Pod::UI.info "#{@spec.name} (#{@spec.version}) 上传失败".red
|
74
|
+
raise Informative, "#{@spec.name} (#{@spec.version}) 上传失败"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
res
|
79
|
+
end
|
80
|
+
|
81
|
+
# 上传二进制 podspec
|
82
|
+
def push_binary_repo(binary_podsepc_json)
|
83
|
+
argvs = [
|
84
|
+
"#{binary_podsepc_json}",
|
85
|
+
"--binary",
|
86
|
+
"--sources=#{sources_option(@code_dependencies, @sources)},https:\/\/cdn.cocoapods.org",
|
87
|
+
"--skip-import-validation",
|
88
|
+
"--use-libraries",
|
89
|
+
"--allow-warnings",
|
90
|
+
"--verbose",
|
91
|
+
"--code-dependencies"
|
92
|
+
]
|
93
|
+
if @verbose
|
94
|
+
argvs += ['--verbose']
|
95
|
+
end
|
96
|
+
|
97
|
+
push = Pod::Command::Bin::Repo::Push.new(CLAide::ARGV.new(argvs))
|
98
|
+
push.validate!
|
99
|
+
push.run
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
require 'cocoapods-meitu-bin/helpers/sources_helper'
|
2
|
+
require 'cocoapods-meitu-bin/helpers/spec_creator'
|
3
|
+
require 'cocoapods-meitu-bin/helpers/spec_files_helper'
|
4
|
+
require 'cocoapods-meitu-bin/helpers/spec_source_creator'
|
5
|
+
require 'cocoapods-meitu-bin/helpers/build_utils'
|
@@ -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,109 @@
|
|
1
|
+
|
2
|
+
require 'parallel'
|
3
|
+
require 'cocoapods'
|
4
|
+
|
5
|
+
module Pod
|
6
|
+
class Installer
|
7
|
+
class Analyzer
|
8
|
+
alias old_fetch_external_sources fetch_external_sources
|
9
|
+
def fetch_external_sources(podfile_state)
|
10
|
+
verify_no_pods_with_different_sources!
|
11
|
+
deps = dependencies_to_fetch(podfile_state)
|
12
|
+
pods = pods_to_fetch(podfile_state)
|
13
|
+
return if deps.empty?
|
14
|
+
UI.section 'Fetching external sources' do
|
15
|
+
if installation_options.install_with_multi_threads
|
16
|
+
thread_count = installation_options.multi_threads_count
|
17
|
+
Parallel.each(deps.sort, in_threads: thread_count) do |dependency|
|
18
|
+
fetch_external_source(dependency, !pods.include?(dependency.root_name))
|
19
|
+
end
|
20
|
+
else
|
21
|
+
deps.sort.each do |dependency|
|
22
|
+
fetch_external_source(dependency, !pods.include?(dependency.root_name))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# > 1.6.0
|
29
|
+
# all_specs[dep.name] 为 nil 会崩溃
|
30
|
+
# 主要原因是 all_specs 分析错误
|
31
|
+
# 查看 source 是否正确
|
32
|
+
#
|
33
|
+
# def dependencies_for_specs(specs, platform, all_specs)
|
34
|
+
# return [] if specs.empty? || all_specs.empty?
|
35
|
+
|
36
|
+
# dependent_specs = Set.new
|
37
|
+
|
38
|
+
# specs.each do |s|
|
39
|
+
# s.dependencies(platform).each do |dep|
|
40
|
+
# all_specs[dep.name].each do |spec|
|
41
|
+
# dependent_specs << spec
|
42
|
+
# end
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
|
46
|
+
# dependent_specs - specs
|
47
|
+
# end
|
48
|
+
|
49
|
+
# > 1.5.3 版本
|
50
|
+
# rewrite update_repositories
|
51
|
+
#
|
52
|
+
alias old_update_repositories update_repositories
|
53
|
+
def update_repositories
|
54
|
+
if installation_options.update_source_with_multi_threads
|
55
|
+
# 并发更新私有源
|
56
|
+
# 这里多线程会导致 pod update 额外输出 --verbose 的内容
|
57
|
+
# 不知道为什么?
|
58
|
+
thread_count = installation_options.multi_threads_count
|
59
|
+
Parallel.each(sources.uniq(&:url), in_threads: thread_count) do |source|
|
60
|
+
if source.updateable?
|
61
|
+
sources_manager.update(source.name, true)
|
62
|
+
else
|
63
|
+
UI.message "Skipping `#{source.name}` update because the repository is not an updateable repository."
|
64
|
+
end
|
65
|
+
end
|
66
|
+
@specs_updated = true
|
67
|
+
else
|
68
|
+
old_update_repositories
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# 解决 dep.name = xxx/binary 时,all_specs[dep.name] 返回nil,导致调用 each 方法报错
|
73
|
+
alias old_dependencies_for_specs dependencies_for_specs
|
74
|
+
def dependencies_for_specs(specs, platform, all_specs)
|
75
|
+
dependent_specs = {
|
76
|
+
:debug => Set.new,
|
77
|
+
:release => Set.new,
|
78
|
+
}
|
79
|
+
|
80
|
+
podfile = Pod::Config.instance.podfile
|
81
|
+
|
82
|
+
if !specs.empty? && !all_specs.empty?
|
83
|
+
specs.each do |s|
|
84
|
+
s.dependencies(platform).each do |dep|
|
85
|
+
# use_binary = podfile.use_binaries? && !podfile.use_source_pods.include?(dep.root_name)
|
86
|
+
# key = use_binary ? dep.root_name : dep.name
|
87
|
+
all_specs[dep.name].each do |spec|
|
88
|
+
if spec.non_library_specification?
|
89
|
+
if s.test_specification? && spec.name == s.consumer(platform).app_host_name && spec.app_specification?
|
90
|
+
# This needs to be handled separately, since we _don't_ want to treat this as a "normal" dependency
|
91
|
+
next
|
92
|
+
end
|
93
|
+
raise Informative, "`#{s}` depends upon `#{spec}`, which is a `#{spec.spec_type}` spec."
|
94
|
+
end
|
95
|
+
|
96
|
+
dependent_specs.each do |config, set|
|
97
|
+
next unless s.dependency_whitelisted_for_configuration?(dep, config)
|
98
|
+
set << spec
|
99
|
+
end
|
100
|
+
end unless all_specs[dep.name].nil? # 解决 dep.name = xxx/binary 时,all_specs[dep.name]返回的是nil,导致调用 each 方法报错
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
Hash[dependent_specs.map { |k, v| [k, (v - specs).group_by(&:root)] }].freeze
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
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,79 @@
|
|
1
|
+
|
2
|
+
# hook cocoapods-generate的Gen类和Installer类
|
3
|
+
|
4
|
+
module Pod
|
5
|
+
class Command
|
6
|
+
class Gen < Command
|
7
|
+
|
8
|
+
alias old_run run
|
9
|
+
|
10
|
+
def run
|
11
|
+
UI.puts "[pod gen] Running with #{configuration.to_s.gsub("\n", " \n")}" if configuration.pod_config.verbose?
|
12
|
+
|
13
|
+
# this is done here rather than in the installer so we only update sources once,
|
14
|
+
# even if there are multiple podspecs
|
15
|
+
update_sources if configuration.repo_update?
|
16
|
+
|
17
|
+
installers = []
|
18
|
+
Generate::PodfileGenerator.new(configuration).podfiles_by_spec.each do |spec, podfile|
|
19
|
+
installer = Generate::Installer.new(configuration, spec, podfile).install!
|
20
|
+
installers << installer
|
21
|
+
end
|
22
|
+
|
23
|
+
remove_warnings(UI.warnings)
|
24
|
+
|
25
|
+
installers
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module Pod
|
32
|
+
module Generate
|
33
|
+
class Installer
|
34
|
+
|
35
|
+
alias old_install! install!
|
36
|
+
|
37
|
+
def install!
|
38
|
+
UI.title "Generating #{spec.name} in #{UI.path install_directory}" do
|
39
|
+
clean! if configuration.clean?
|
40
|
+
install_directory.mkpath
|
41
|
+
|
42
|
+
UI.message 'Creating stub application' do
|
43
|
+
create_app_project
|
44
|
+
end
|
45
|
+
|
46
|
+
UI.message 'Writing Podfile' do
|
47
|
+
podfile.defined_in_file.open('w') { |f| f << podfile.to_yaml }
|
48
|
+
end
|
49
|
+
|
50
|
+
installer = nil
|
51
|
+
UI.section 'Installing...' do
|
52
|
+
configuration.pod_config.with_changes(installation_root: install_directory, podfile: podfile,
|
53
|
+
lockfile: configuration.lockfile, sandbox: nil,
|
54
|
+
sandbox_root: install_directory + 'Pods',
|
55
|
+
podfile_path: podfile.defined_in_file,
|
56
|
+
silent: !configuration.pod_config.verbose?, verbose: false,
|
57
|
+
lockfile_path: nil) do
|
58
|
+
installer = ::Pod::Installer.new(configuration.pod_config.sandbox, podfile, configuration.lockfile)
|
59
|
+
installer.use_default_plugins = configuration.use_default_plugins
|
60
|
+
installer.install!
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
UI.section 'Performing post-installation steps' do
|
65
|
+
should_perform_post_install = if installer.respond_to?(:generated_aggregate_targets) # CocoaPods 1.7.0
|
66
|
+
!installer.generated_aggregate_targets.empty?
|
67
|
+
else
|
68
|
+
true
|
69
|
+
end
|
70
|
+
perform_post_install_steps(open_app_project, installer) if should_perform_post_install
|
71
|
+
end
|
72
|
+
|
73
|
+
print_post_install_message
|
74
|
+
installer
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,28 @@
|
|
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, false
|
20
|
+
|
21
|
+
# 是否多进程执行 update_repositories
|
22
|
+
env_option :update_source_with_multi_threads, false
|
23
|
+
|
24
|
+
# 并发执行个数
|
25
|
+
option :multi_threads_count, 4
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,259 @@
|
|
1
|
+
require 'cocoapods/installer/project_cache/target_metadata.rb'
|
2
|
+
require 'parallel'
|
3
|
+
require 'cocoapods'
|
4
|
+
require 'xcodeproj'
|
5
|
+
require 'cocoapods-meitu-bin/native/pod_source_installer'
|
6
|
+
require 'cocoapods-meitu-bin/helpers/pod_size_helper'
|
7
|
+
|
8
|
+
module Pod
|
9
|
+
class Installer
|
10
|
+
alias mtxx_create_analyzer create_analyzer
|
11
|
+
def create_analyzer(plugin_sources = nil)
|
12
|
+
# 修复MBox下即使存在Podfile.lock依赖分析依然很慢的问题
|
13
|
+
if !lockfile.nil? && lockfile.internal_data.empty?
|
14
|
+
@lockfile = Lockfile.from_file(config.lockfile_path) if config.lockfile_path
|
15
|
+
end
|
16
|
+
mtxx_create_analyzer(plugin_sources)
|
17
|
+
end
|
18
|
+
|
19
|
+
def cost_time_hash
|
20
|
+
@cost_time_hash ||= begin
|
21
|
+
Hash.new
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# TODO: 不知道为啥无法hook
|
26
|
+
# 准备
|
27
|
+
alias old_prepare prepare
|
28
|
+
def prepare
|
29
|
+
start_time = Time.now
|
30
|
+
old_prepare
|
31
|
+
cost_time_hash['prepare'] = Time.now - start_time
|
32
|
+
end
|
33
|
+
|
34
|
+
# 依赖分析
|
35
|
+
alias old_resolve_dependencies resolve_dependencies
|
36
|
+
def resolve_dependencies
|
37
|
+
start_time = Time.now
|
38
|
+
analyzer = old_resolve_dependencies
|
39
|
+
cost_time_hash['resolve_dependencies'] = Time.now - start_time
|
40
|
+
analyzer
|
41
|
+
end
|
42
|
+
|
43
|
+
# 依赖下载
|
44
|
+
alias old_download_dependencies download_dependencies
|
45
|
+
def download_dependencies
|
46
|
+
start_time = Time.now
|
47
|
+
old_download_dependencies
|
48
|
+
cost_time_hash['download_dependencies'] = Time.now - start_time
|
49
|
+
end
|
50
|
+
|
51
|
+
# 验证target
|
52
|
+
alias old_validate_targets validate_targets
|
53
|
+
def validate_targets
|
54
|
+
start_time = Time.now
|
55
|
+
old_validate_targets
|
56
|
+
cost_time_hash['validate_targets'] = Time.now - start_time
|
57
|
+
end
|
58
|
+
|
59
|
+
# 集成
|
60
|
+
alias old_integrate integrate
|
61
|
+
def integrate
|
62
|
+
start_time = Time.now
|
63
|
+
old_integrate
|
64
|
+
cost_time_hash['integrate'] = Time.now - start_time
|
65
|
+
end
|
66
|
+
|
67
|
+
# 写入lock文件
|
68
|
+
def write_lockfiles
|
69
|
+
start_time = Time.now
|
70
|
+
@lockfile = generate_lockfile
|
71
|
+
|
72
|
+
UI.message "- Writing Lockfile in #{UI.path config.lockfile_path}" do
|
73
|
+
# No need to invoke Sandbox#update_changed_file here since this logic already handles checking if the
|
74
|
+
# contents of the file are the same.
|
75
|
+
@lockfile.write_to_disk(config.lockfile_path)
|
76
|
+
end
|
77
|
+
|
78
|
+
UI.message "- Writing Manifest in #{UI.path sandbox.manifest_path}" do
|
79
|
+
# No need to invoke Sandbox#update_changed_file here since this logic already handles checking if the
|
80
|
+
# contents of the file are the same.
|
81
|
+
@lockfile.write_to_disk(sandbox.manifest_path)
|
82
|
+
end
|
83
|
+
cost_time_hash['write_lockfiles'] = Time.now - start_time
|
84
|
+
end
|
85
|
+
|
86
|
+
# 执行post install
|
87
|
+
alias old_perform_post_install_actions perform_post_install_actions
|
88
|
+
def perform_post_install_actions
|
89
|
+
start_time = Time.now
|
90
|
+
old_perform_post_install_actions
|
91
|
+
cost_time_hash['perform_post_install_actions'] = Time.now - start_time
|
92
|
+
# 打印有多少个源码库,多少二进制库
|
93
|
+
print_source_bin_statistics
|
94
|
+
# 打印耗时
|
95
|
+
print_cost_time
|
96
|
+
# 打印大小大于阈值的库
|
97
|
+
CBin::PodSize.print_pods
|
98
|
+
end
|
99
|
+
|
100
|
+
# 打印有多少个源码库,多少二进制库
|
101
|
+
def print_source_bin_statistics
|
102
|
+
source_pods = []
|
103
|
+
bin_pods = []
|
104
|
+
@pod_targets.map do |target|
|
105
|
+
if target.should_build?
|
106
|
+
source_pods << target
|
107
|
+
else
|
108
|
+
bin_pods << target
|
109
|
+
end
|
110
|
+
end
|
111
|
+
UI.puts "\n总共有 #{@pod_targets.size} 个Pod库,二进制有 #{bin_pods.size} 个,源码有 #{source_pods.size} 个".green
|
112
|
+
# 打印二进制库
|
113
|
+
if ENV['statistics_bin'] == '1'
|
114
|
+
UI.puts "二进制库:".green
|
115
|
+
UI.puts bin_pods
|
116
|
+
end
|
117
|
+
# 打印源码库
|
118
|
+
if ENV['statistics_source'] == '1'
|
119
|
+
UI.puts "源码库:".green
|
120
|
+
UI.puts source_pods
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# 打印耗时
|
125
|
+
def print_cost_time
|
126
|
+
prefix = 'pod_time_profiler:'
|
127
|
+
UI.title "#{prefix} pod执行耗时:".green do
|
128
|
+
UI.info "#{prefix} ———————————————————————————————————————————————".green
|
129
|
+
UI.info "#{prefix} |#{'Stage'.center(30)}|#{'Time(s)'.center(15)}|".green
|
130
|
+
UI.info "#{prefix} ———————————————————————————————————————————————".green
|
131
|
+
cost_time_hash.each do |key, value|
|
132
|
+
UI.info "#{prefix} |#{key.center(30)}|#{('%.3f' % value).to_s.center(15)}|".green
|
133
|
+
end
|
134
|
+
UI.info "#{prefix} ———————————————————————————————————————————————".green
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
alias old_create_pod_installer create_pod_installer
|
139
|
+
def create_pod_installer(pod_name)
|
140
|
+
installer = old_create_pod_installer(pod_name)
|
141
|
+
installer.installation_options = installation_options
|
142
|
+
installer
|
143
|
+
end
|
144
|
+
|
145
|
+
alias old_install_pod_sources install_pod_sources
|
146
|
+
def install_pod_sources
|
147
|
+
if installation_options.install_with_multi_threads
|
148
|
+
install_pod_sources_with_multiple_threads
|
149
|
+
else
|
150
|
+
old_install_pod_sources
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
# 多线程下载
|
155
|
+
def install_pod_sources_with_multiple_threads
|
156
|
+
@installed_specs = []
|
157
|
+
pods_to_install = sandbox_state.added | sandbox_state.changed
|
158
|
+
title_options = { :verbose_prefix => '-> '.green }
|
159
|
+
thread_count = installation_options.multi_threads_count
|
160
|
+
Parallel.each(root_specs.sort_by(&:name), in_threads: thread_count) do |spec|
|
161
|
+
if pods_to_install.include?(spec.name)
|
162
|
+
if sandbox_state.changed.include?(spec.name) && sandbox.manifest
|
163
|
+
current_version = spec.version
|
164
|
+
previous_version = sandbox.manifest.version(spec.name)
|
165
|
+
has_changed_version = current_version != previous_version
|
166
|
+
current_repo = analysis_result.specs_by_source.detect { |key, values| break key if values.map(&:name).include?(spec.name) }
|
167
|
+
current_repo &&= (Pod::TrunkSource::TRUNK_REPO_NAME if current_repo.name == Pod::TrunkSource::TRUNK_REPO_NAME) || current_repo.url || current_repo.name
|
168
|
+
previous_spec_repo = sandbox.manifest.spec_repo(spec.name)
|
169
|
+
has_changed_repo = !previous_spec_repo.nil? && current_repo && !current_repo.casecmp(previous_spec_repo).zero?
|
170
|
+
title = "Installing #{spec.name} #{spec.version}"
|
171
|
+
title << " (was #{previous_version} and source changed to `#{current_repo}` from `#{previous_spec_repo}`)" if has_changed_version && has_changed_repo
|
172
|
+
title << " (was #{previous_version})" if has_changed_version && !has_changed_repo
|
173
|
+
title << " (source changed to `#{current_repo}` from `#{previous_spec_repo}`)" if !has_changed_version && has_changed_repo
|
174
|
+
else
|
175
|
+
title = "Installing #{spec}"
|
176
|
+
end
|
177
|
+
UI.titled_section(title.green, title_options) do
|
178
|
+
install_source_of_pod(spec.name)
|
179
|
+
end
|
180
|
+
else
|
181
|
+
UI.section("Using #{spec}", title_options[:verbose_prefix]) do
|
182
|
+
create_pod_installer(spec.name)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
# alias old_write_lockfiles write_lockfiles
|
189
|
+
# def write_lockfiles
|
190
|
+
# old_write_lockfiles
|
191
|
+
# if File.exist?('Podfile_local')
|
192
|
+
#
|
193
|
+
# project = Xcodeproj::Project.open(config.sandbox.project_path)
|
194
|
+
# #获取主group
|
195
|
+
# group = project.main_group
|
196
|
+
# group.set_source_tree('SOURCE_ROOT')
|
197
|
+
# #向group中添加 文件引用
|
198
|
+
# file_ref = group.new_reference(config.sandbox.root + '../Podfile_local')
|
199
|
+
# #podfile_local排序
|
200
|
+
# podfile_local_group = group.children.last
|
201
|
+
# group.children.pop
|
202
|
+
# group.children.unshift(podfile_local_group)
|
203
|
+
# #保存
|
204
|
+
# project.save
|
205
|
+
# end
|
206
|
+
# end
|
207
|
+
end
|
208
|
+
|
209
|
+
module Downloader
|
210
|
+
class Cache
|
211
|
+
require 'cocoapods-meitu-bin/helpers/pod_size_helper'
|
212
|
+
# 多线程锁
|
213
|
+
@@lock = Mutex.new
|
214
|
+
|
215
|
+
# 后面如果要切到进程的话,可以在 cache root 里面新建一个文件
|
216
|
+
# 利用这个文件 lock
|
217
|
+
# https://stackoverflow.com/questions/23748648/using-fileflock-as-ruby-global-lock-mutex-for-processes
|
218
|
+
|
219
|
+
# rmtree 在多进程情况下可能 Directory not empty @ dir_s_rmdir 错误
|
220
|
+
# old_ensure_matching_version 会移除不是同一个 CocoaPods 版本的组件缓存
|
221
|
+
alias old_ensure_matching_version ensure_matching_version
|
222
|
+
def ensure_matching_version
|
223
|
+
@@lock.synchronize do
|
224
|
+
version_file = root + 'VERSION'
|
225
|
+
# version = version_file.read.strip if version_file.file?
|
226
|
+
|
227
|
+
# root.rmtree if version != Pod::VERSION && root.exist?
|
228
|
+
root.mkpath
|
229
|
+
|
230
|
+
version_file.open('w') { |f| f << Pod::VERSION }
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
def uncached_pod(request)
|
235
|
+
in_tmpdir do |target|
|
236
|
+
result, podspecs = download(request, target)
|
237
|
+
result.location = nil
|
238
|
+
|
239
|
+
# 记录下载大小大于阈值的库及大小
|
240
|
+
if File.exist?(target.to_s)
|
241
|
+
dir_size = `du -sk #{target.to_s}`.strip().split(' ')[0]
|
242
|
+
CBin::PodSize.add_pod({:name => request.name, :size => dir_size})
|
243
|
+
end
|
244
|
+
|
245
|
+
podspecs.each do |name, spec|
|
246
|
+
destination = path_for_pod(request, :name => name, :params => result.checkout_options)
|
247
|
+
copy_and_clean(target, destination, spec)
|
248
|
+
write_spec(spec, path_for_spec(request, :name => name, :params => result.checkout_options))
|
249
|
+
if request.name == name
|
250
|
+
result.location = destination
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
result
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
require 'cocoapods-meitu-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
|