Class: Pod::Installer
- Inherits:
-
Object
show all
- Defined in:
- lib/cocoapods-meitu-bin/native/analyzer.rb,
lib/cocoapods-meitu-bin/native/installer.rb,
lib/cocoapods-meitu-bin/native/sandbox_analyzer.rb,
lib/cocoapods-meitu-bin/native/target_validator.rb,
lib/cocoapods-meitu-bin/native/installation_options.rb,
lib/cocoapods-meitu-bin/native/pod_source_installer.rb,
lib/cocoapods-meitu-bin/native/pod_target_installer.rb
Defined Under Namespace
Classes: Analyzer, InstallationOptions, PodSourceInstaller, Xcode
Instance Method Summary
collapse
Instance Method Details
#cost_time_hash ⇒ Object
43
44
45
46
47
|
# File 'lib/cocoapods-meitu-bin/native/installer.rb', line 43
def cost_time_hash
@cost_time_hash ||= begin
Hash.new
end
end
|
#create_analyzer(plugin_sources = nil) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/cocoapods-meitu-bin/native/installer.rb', line 16
def create_analyzer(plugin_sources = nil)
if PodUpdateConfig.is_podfile_lock_nil
@lockfile = nil
else
if !lockfile.nil? && lockfile.internal_data.empty?
@lockfile = Lockfile.from_file(config.lockfile_path) if config.lockfile_path
end
podfile.use_source_pods.each do |name|
if !lockfile.nil? && lockfile.internal_data && lockfile.internal_data['EXTERNAL SOURCES']
lockfile.internal_data['EXTERNAL SOURCES'].delete(name)
end
if !lockfile.nil? && lockfile.internal_data && lockfile.internal_data['CHECKOUT OPTIONS']
lockfile.internal_data['CHECKOUT OPTIONS'].delete(name)
end
end
end
mtxx_create_analyzer(plugin_sources)
end
|
#create_pod_installer(pod_name) ⇒ Object
281
282
283
284
285
|
# File 'lib/cocoapods-meitu-bin/native/installer.rb', line 281
def create_pod_installer(pod_name)
installer = old_create_pod_installer(pod_name)
installer.installation_options = installation_options
installer
end
|
#download_dependencies ⇒ Object
117
118
119
120
121
|
# File 'lib/cocoapods-meitu-bin/native/installer.rb', line 117
def download_dependencies
start_time = Time.now
old_download_dependencies
cost_time_hash['download_dependencies'] = Time.now - start_time
end
|
#install_pod_sources ⇒ Object
288
289
290
291
292
293
294
|
# File 'lib/cocoapods-meitu-bin/native/installer.rb', line 288
def install_pod_sources
if installation_options.install_with_multi_threads
install_pod_sources_with_multiple_threads
else
old_install_pod_sources
end
end
|
#install_pod_sources_with_multiple_threads ⇒ Object
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
|
# File 'lib/cocoapods-meitu-bin/native/installer.rb', line 297
def install_pod_sources_with_multiple_threads
@installed_specs = []
pods_to_install = sandbox_state.added | sandbox_state.changed
title_options = { :verbose_prefix => '-> '.green }
thread_count = installation_options.multi_threads_count
Parallel.each(root_specs.sort_by(&:name), in_threads: thread_count) do |spec|
if pods_to_install.include?(spec.name)
if sandbox_state.changed.include?(spec.name) && sandbox.manifest
current_version = spec.version
previous_version = sandbox.manifest.version(spec.name)
has_changed_version = current_version != previous_version
current_repo = analysis_result.specs_by_source.detect { |key, values| break key if values.map(&:name).include?(spec.name) }
current_repo &&= (Pod::TrunkSource::TRUNK_REPO_NAME if current_repo.name == Pod::TrunkSource::TRUNK_REPO_NAME) || current_repo.url || current_repo.name
previous_spec_repo = sandbox.manifest.spec_repo(spec.name)
has_changed_repo = !previous_spec_repo.nil? && current_repo && !current_repo.casecmp(previous_spec_repo).zero?
title = "Installing #{spec.name} #{spec.version}"
title << " (was #{previous_version} and source changed to `#{current_repo}` from `#{previous_spec_repo}`)" if has_changed_version && has_changed_repo
title << " (was #{previous_version})" if has_changed_version && !has_changed_repo
title << " (source changed to `#{current_repo}` from `#{previous_spec_repo}`)" if !has_changed_version && has_changed_repo
else
title = "Installing #{spec}"
end
UI.titled_section(title.green, title_options) do
install_source_of_pod(spec.name)
end
else
UI.section("Using #{spec}", title_options[:verbose_prefix]) do
create_pod_installer(spec.name)
end
end
end
end
|
#integrate ⇒ Object
133
134
135
136
137
|
# File 'lib/cocoapods-meitu-bin/native/installer.rb', line 133
def integrate
start_time = Time.now
old_integrate
cost_time_hash['integrate'] = Time.now - start_time
end
|
#mtxx_create_analyzer ⇒ Object
15
|
# File 'lib/cocoapods-meitu-bin/native/installer.rb', line 15
alias mtxx_create_analyzer create_analyzer
|
#old_create_pod_installer ⇒ Object
280
|
# File 'lib/cocoapods-meitu-bin/native/installer.rb', line 280
alias old_create_pod_installer create_pod_installer
|
#old_download_dependencies ⇒ Object
116
|
# File 'lib/cocoapods-meitu-bin/native/installer.rb', line 116
alias old_download_dependencies download_dependencies
|
#old_install_pod_sources ⇒ Object
287
|
# File 'lib/cocoapods-meitu-bin/native/installer.rb', line 287
alias old_install_pod_sources install_pod_sources
|
#old_integrate ⇒ Object
132
|
# File 'lib/cocoapods-meitu-bin/native/installer.rb', line 132
alias old_integrate integrate
|
#old_perform_post_install_actions ⇒ Object
159
|
# File 'lib/cocoapods-meitu-bin/native/installer.rb', line 159
alias old_perform_post_install_actions perform_post_install_actions
|
#old_prepare ⇒ Object
51
|
# File 'lib/cocoapods-meitu-bin/native/installer.rb', line 51
alias old_prepare prepare
|
#old_resolve_dependencies ⇒ Object
59
|
# File 'lib/cocoapods-meitu-bin/native/installer.rb', line 59
alias old_resolve_dependencies resolve_dependencies
|
#old_validate_targets ⇒ Object
124
|
# File 'lib/cocoapods-meitu-bin/native/installer.rb', line 124
alias old_validate_targets validate_targets
|
#perform_post_install_actions ⇒ Object
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
# File 'lib/cocoapods-meitu-bin/native/installer.rb', line 160
def perform_post_install_actions
start_time = Time.now
old_perform_post_install_actions
source_pods = []
bin_pods = []
@pod_targets.map do |target|
target.uses_swift?
if target.should_build?
source_pods << target
else
bin_pods << target
end
end
cost_time_hash['perform_post_install_actions'] = Time.now - start_time
print_source_bin_statistics(source_pods,bin_pods)
print_cost_time
CBin::PodSize.print_pods
if PodUpdateConfig.is_mtxx
begin
data = {
"meitu_bin_version" => CBin::VERSION,
"large_pod_hash" => PodUpdateConfig.large_pod_hash
}
all_time = 0
cost_time_hash.each do |key, value|
time = ('%.1f' % value).to_f
data[key] = time
all_time = all_time + time
end
data["pod_time"] = all_time
binary_rate = bin_pods.size.to_f / @pod_targets.size.to_f
data["binary_rate"] = ('%.2f' % binary_rate).to_f
data["source_count"] = source_pods.size
data["binary_count"] = bin_pods.size
data["targets_count"] = @pod_targets.size
source = "unknown user"
if ENV['NODE_NAME']
source = ENV['NODE_NAME']
else
source = `git config user.email`
source = source.gsub("\n", "")
end
data_json = {
"subject" => "MTXX pod time profiler",
"type" => "pod_time_profiler",
"source" => source,
"data" => data
}
begin
Timeout.timeout(3) do
json_data = [data_json].to_json
api_url = "http://event-adapter-internal.prism.cloud.meitu-int.com/api/v1/http/send/batch"
= { "Content-Type" => "application/json" }
uri = URI(api_url)
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.path, )
request.body = json_data
response = http.request(request)
if ENV['MEITU_USE_POD_SOURCE'] == '1'
puts "pod_time_profiler: Response code: #{response.code}"
puts "pod_time_profiler: data_json: #{data_json}"
end
end
rescue Timeout::Error
puts "pod_time_profiler: 上报pod操作操作已超时"
end
rescue => error
puts "pod_time_profiler: 上报pod 耗时统计失败,失败原因:#{error}"
end
end
end
|
#prepare ⇒ Object
52
53
54
55
56
|
# File 'lib/cocoapods-meitu-bin/native/installer.rb', line 52
def prepare
start_time = Time.now
old_prepare
cost_time_hash['prepare'] = Time.now - start_time
end
|
#print_cost_time ⇒ Object
267
268
269
270
271
272
273
274
275
276
277
278
|
# File 'lib/cocoapods-meitu-bin/native/installer.rb', line 267
def print_cost_time
prefix = 'pod_time_profiler:'
UI.title "#{prefix} pod执行耗时:".green do
UI.info "#{prefix} ———————————————————————————————————————————————".green
UI.info "#{prefix} |#{'Stage'.center(30)}|#{'Time(s)'.center(15)}|".green
UI.info "#{prefix} ———————————————————————————————————————————————".green
cost_time_hash.each do |key, value|
UI.info "#{prefix} |#{key.center(30)}|#{('%.3f' % value).to_s.center(15)}|".green
end
UI.info "#{prefix} ———————————————————————————————————————————————".green
end
end
|
#print_source_bin_statistics(source_pods, bin_pods) ⇒ Object
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
# File 'lib/cocoapods-meitu-bin/native/installer.rb', line 238
def print_source_bin_statistics(source_pods,bin_pods)
UI.puts "\npod_time_profiler: 总共有 #{@pod_targets.size} 个Pod库,二进制有 #{bin_pods.size} 个,源码有 #{source_pods.size} 个".green
begin
file_path = (Pod::Config.instance.installation_root + 'source_pods_size.txt').to_s
if File.exist?(file_path)
File.delete(file_path) rescue nil
end
File.open(file_path, 'w') { |f| f << source_pods.size.to_s }
rescue => e
UI.puts "pod_time_profiler: 写入二进制个数日志失败:#{e}".red
end
if ENV['statistics_bin'] == '1'
UI.puts "二进制库:".green
UI.puts bin_pods
end
if ENV['MEITU_USE_POD_SOURCE'] == '1'
UI.puts "源码库:".green
source_pods.each do |pod|
UI.puts "pod_time_profiler: #{pod.name}"
end
end
end
|
#resolve_dependencies ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/cocoapods-meitu-bin/native/installer.rb', line 60
def resolve_dependencies
start_time = Time.now
list = PodUpdateConfig.pods
if list && !list.empty?
self.update = { :pods => list }
end
if PodUpdateConfig.lockfile
self.instance_variable_set("@lockfile",PodUpdateConfig.lockfile)
end
if PodUpdateConfig.is_clear
self.instance_variable_set("@lockfile",PodUpdateConfig.lockfile)
end
plugin_sources = run_source_provider_hooks
analyzer = create_analyzer(plugin_sources)
UI.section 'Updating local specs repositories' do
analyzer.update_repositories
end if repo_update? && PodUpdateConfig.repo_update
UI.section 'Analyzing dependencies' do
analyze(analyzer)
excluded_names = PodUpdateConfig.external_source
.map { |s| s[:name] || s['name'] }
.compact
.uniq
if excluded_names
filtered_pod_targets = @pod_targets.select do |pod_target|
excluded_names.include?(pod_target.pod_name)
end
filtered_pod_targets.each do |pod_target|
UI.puts "pod_time_profiler: predownloaded_pods_binary: #{pod_target.pod_name}".green
sandbox.predownloaded_pods.delete(pod_target.pod_name)
end
end
validate_build_configurations
end
UI.section 'Verifying no changes' do
verify_no_podfile_changes!
verify_no_lockfile_changes!
end if deployment?
cost_time_hash['prepare'] = PodUpdateConfig.prepare_time
cost_time_hash['resolve_dependencies'] = Time.now - start_time
analyzer
end
|
#validate_targets ⇒ Object
125
126
127
128
129
|
# File 'lib/cocoapods-meitu-bin/native/installer.rb', line 125
def validate_targets
start_time = Time.now
old_validate_targets
cost_time_hash['validate_targets'] = Time.now - start_time
end
|
#write_lockfiles ⇒ Object
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'lib/cocoapods-meitu-bin/native/installer.rb', line 140
def write_lockfiles
start_time = Time.now
@lockfile = generate_lockfile
UI.message "- Writing Lockfile in #{UI.path config.lockfile_path}" do
@lockfile.write_to_disk(config.lockfile_path)
end
UI.message "- Writing Manifest in #{UI.path sandbox.manifest_path}" do
@lockfile.write_to_disk(sandbox.manifest_path)
end
cost_time_hash['write_lockfiles'] = Time.now - start_time
end
|