cocoapods-binary-matchup 0.0.30 → 0.0.31
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.
- checksums.yaml +4 -4
- data/Gemfile +13 -0
- data/LICENSE.txt +22 -0
- data/README.md +83 -0
- data/Rakefile +13 -0
- data/cocoapods-binary-matchup.gemspec +32 -0
- data/lib/cocoapods-binary-matchup/Integration.rb +287 -0
- data/lib/cocoapods-binary-matchup/Integration_cache.rb +320 -0
- data/lib/cocoapods-binary-matchup/Main.rb +448 -0
- data/lib/cocoapods-binary-matchup/Prebuild.rb +249 -0
- data/lib/cocoapods-binary-matchup/gem_version.rb +3 -0
- data/lib/cocoapods-binary-matchup/helper/feature_switches.rb +109 -0
- data/lib/cocoapods-binary-matchup/helper/passer.rb +41 -0
- data/lib/cocoapods-binary-matchup/helper/podfile_options.rb +122 -0
- data/lib/cocoapods-binary-matchup/helper/prebuild_sandbox.rb +53 -0
- data/lib/cocoapods-binary-matchup/helper/target_checker.rb +49 -0
- data/lib/cocoapods-binary-matchup/rome/build_framework.rb +337 -0
- data/lib/cocoapods-binary-matchup/tool/tool.rb +12 -0
- data/lib/cocoapods-binary.rb +1 -0
- data/lib/cocoapods_plugin.rb +2 -0
- data/spec/plugin_spec.rb +43 -0
- data/spec/spec_helper.rb +50 -0
- metadata +36 -7
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
require 'digest'
|
|
3
|
+
require 'set'
|
|
4
|
+
|
|
5
|
+
module Pod
|
|
6
|
+
|
|
7
|
+
class_attr_accessor :main_deployment_target_name
|
|
8
|
+
|
|
9
|
+
module PrebuildCache
|
|
10
|
+
|
|
11
|
+
class Cache
|
|
12
|
+
|
|
13
|
+
# 类变量用于跟踪依赖关系和失效的pod
|
|
14
|
+
@@dependency_graph = {}
|
|
15
|
+
|
|
16
|
+
# 获取缓存根目录
|
|
17
|
+
def self.cache_root_dir
|
|
18
|
+
cache_dir = File.expand_path("~/.PodCache/#{Pod.main_deployment_target_name}")
|
|
19
|
+
FileUtils.mkdir_p(cache_dir) unless Dir.exist?(cache_dir)
|
|
20
|
+
cache_dir
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# 获取manifest.lock缓存路径
|
|
24
|
+
def self.cached_manifest_path
|
|
25
|
+
File.join(cache_root_dir, 'Manifest.lock')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# 获取特定pod的缓存目录
|
|
29
|
+
def self.cache_dir_for_pod(pod_name)
|
|
30
|
+
File.join(cache_root_dir, pod_name)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# 获取pod的版本信息,优先使用commit hash
|
|
34
|
+
def self.get_pod_version(sandbox, pod_name)
|
|
35
|
+
UI.puts "🔍 starting get pod version: #{pod_name}"
|
|
36
|
+
UI.puts "🔍 get_pod_version sandbox: #{sandbox.manifest_path}"
|
|
37
|
+
checkout_options = sandbox.manifest.checkout_options_for_pod_named(pod_name)
|
|
38
|
+
# 优先使用checkout_options中的检出来源
|
|
39
|
+
if checkout_options
|
|
40
|
+
UI.puts "🔍 get pod checkout version: #{pod_name}"
|
|
41
|
+
if checkout_options[:tag]
|
|
42
|
+
UI.puts "🔍 get pod checkout version tag: #{pod_name}# - #{checkout_options[:tag]}"
|
|
43
|
+
return checkout_options[:tag]
|
|
44
|
+
end
|
|
45
|
+
if checkout_options[:branch]
|
|
46
|
+
UI.puts "🔍 get pod checkout version branch: #{pod_name}# - #{checkout_options[:branch]}"
|
|
47
|
+
return checkout_options[:branch]
|
|
48
|
+
end
|
|
49
|
+
if checkout_options[:commit]
|
|
50
|
+
UI.puts "🔍 get pod checkout version commit: #{pod_name}# - #{checkout_options[:commit]}"
|
|
51
|
+
return checkout_options[:commit]
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# 如果checkout_options中没有版本信息,则使用dependency中的版本信息
|
|
56
|
+
dependency = sandbox.manifest.dependencies.find { |d| d.name == pod_name }
|
|
57
|
+
if dependency
|
|
58
|
+
UI.puts "🔍 get pod dependency version: #{pod_name}"
|
|
59
|
+
external_source = dependency.external_source
|
|
60
|
+
if external_source
|
|
61
|
+
UI.puts "🔍 get pod dependency version podspec: #{external_source}"
|
|
62
|
+
if external_source[:commit]
|
|
63
|
+
UI.puts "🔍 get pod dependency version commit: #{pod_name}# - #{external_source[:commit]}"
|
|
64
|
+
return external_source[:commit]
|
|
65
|
+
end
|
|
66
|
+
if external_source[:branch]
|
|
67
|
+
UI.puts "🔍 get pod dependency version branch: #{pod_name}# - #{external_source[:branch]}"
|
|
68
|
+
return external_source[:branch]
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# 如果checkout_options和dependency中没有版本信息,则使用podspec中的version
|
|
74
|
+
UI.puts "🔍 get pod spec version: #{pod_name}"
|
|
75
|
+
version = sandbox.manifest.version(pod_name).version
|
|
76
|
+
if version
|
|
77
|
+
UI.puts "🔍 get pod spec version: #{pod_name}# - #{version}"
|
|
78
|
+
return version
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# 如果以上都失败,则返回unknown,理论上只要是正常的podfile.lock或者manifest.lock,都不会走到这里
|
|
82
|
+
UI.puts "🔍 get pod version failed: #{pod_name}"
|
|
83
|
+
return "unknown"
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# 检查缓存是否存在
|
|
87
|
+
def self.cache_exists?(pod_name)
|
|
88
|
+
cache_dir = cache_dir_for_pod(pod_name)
|
|
89
|
+
Pod::UI.puts "🔍 cache_exists? #{cache_dir}"
|
|
90
|
+
Dir.exist?(cache_dir) && !Dir.empty?(cache_dir)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# 保存到缓存(如果缓存不存在的话)
|
|
94
|
+
def self.save_to_cache(pod_name, source_dir)
|
|
95
|
+
return unless Dir.exist?(source_dir)
|
|
96
|
+
|
|
97
|
+
# 检查缓存是否已经存在,如果存在则不覆盖
|
|
98
|
+
if cache_exists?(pod_name)
|
|
99
|
+
Pod::UI.puts "📦 Cache already exists for #{pod_name}, skipping save"
|
|
100
|
+
return true
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
cache_dir = cache_dir_for_pod(pod_name)
|
|
104
|
+
|
|
105
|
+
begin
|
|
106
|
+
# 创建缓存目录
|
|
107
|
+
FileUtils.mkdir_p(File.dirname(cache_dir))
|
|
108
|
+
|
|
109
|
+
# 删除旧缓存(如果存在)
|
|
110
|
+
FileUtils.rm_rf(cache_dir) if Dir.exist?(cache_dir)
|
|
111
|
+
|
|
112
|
+
# 拷贝到缓存
|
|
113
|
+
FileUtils.cp_r(source_dir, cache_dir, :remove_destination => true)
|
|
114
|
+
return true
|
|
115
|
+
rescue => e
|
|
116
|
+
Pod::UI.puts "❌ Failed to save #{pod_name} to cache: #{e.message}"
|
|
117
|
+
return false
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# 保存当前manifest.lock到缓存目录
|
|
122
|
+
def self.save_manifest_to_cache(sandbox)
|
|
123
|
+
begin
|
|
124
|
+
# 查找_Prebuild目录中的manifest.lock
|
|
125
|
+
prebuild_manifest = sandbox.root + 'Manifest.lock'
|
|
126
|
+
# 如果存在,复制到缓存目录
|
|
127
|
+
if prebuild_manifest.exist?
|
|
128
|
+
cached_path = cached_manifest_path
|
|
129
|
+
FileUtils.cp(prebuild_manifest, cached_path)
|
|
130
|
+
Pod::UI.puts "💾 save_manifest_to_cache Manifest.lock to cache: #{cached_path}"
|
|
131
|
+
return true
|
|
132
|
+
else
|
|
133
|
+
Pod::UI.puts "⚠️ save_manifest_to_cache Manifest.lock not found in _Prebuild directory"
|
|
134
|
+
return false
|
|
135
|
+
end
|
|
136
|
+
rescue => e
|
|
137
|
+
Pod::UI.puts "❌ save_manifest_to_cache save Manifest.lock to cache failed: #{e.message}"
|
|
138
|
+
return false
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# 清空所有缓存
|
|
143
|
+
def self.clear_all_caches
|
|
144
|
+
begin
|
|
145
|
+
cache_dir = cache_root_dir
|
|
146
|
+
|
|
147
|
+
# 删除除了cached_manifest.lock之外的所有缓存
|
|
148
|
+
Dir.glob("#{cache_dir}/*").each do |path|
|
|
149
|
+
next if File.basename(path) == 'Manifest.lock'
|
|
150
|
+
|
|
151
|
+
if Dir.exist?(path)
|
|
152
|
+
FileUtils.rm_rf(path)
|
|
153
|
+
Pod::UI.puts "🗑️ Cleared cache directory: #{File.basename(path)}"
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
Pod::UI.puts "✅ All pod caches cleared due to dependency changes"
|
|
158
|
+
|
|
159
|
+
rescue => e
|
|
160
|
+
Pod::UI.puts "❌ Error clearing caches: #{e.message}"
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# 验证pod版本一致性(与缓存时的manifest对比)
|
|
165
|
+
def self.validate_pod_version_consistency(pod_name, current_version)
|
|
166
|
+
begin
|
|
167
|
+
manifest_path = cached_manifest_path
|
|
168
|
+
Pod::UI.puts "🔍 validate_pod_version_consistency pod_name: #{pod_name} manifest_path: #{manifest_path}"
|
|
169
|
+
# 如果没有缓存的manifest,认为一致(首次构建)
|
|
170
|
+
unless File.exist?(manifest_path)
|
|
171
|
+
return true
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
# 创建基于缓存manifest的临时sandbox来获取缓存版本
|
|
175
|
+
cached_version = get_cached_pod_version(pod_name, cached_manifest_path)
|
|
176
|
+
|
|
177
|
+
# 对比版本
|
|
178
|
+
if current_version == cached_version
|
|
179
|
+
return true
|
|
180
|
+
else
|
|
181
|
+
Pod::UI.puts "🔄 #{pod_name} version changed: #{cached_version} → #{current_version}"
|
|
182
|
+
return false
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
rescue => e
|
|
186
|
+
Pod::UI.puts "⚠️ Error validating version consistency for #{pod_name}: #{e.message}"
|
|
187
|
+
return false
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
# 从缓存的manifest中获取pod版本(复用get_pod_version的逻辑)
|
|
192
|
+
def self.get_cached_pod_version(pod_name, cached_manifest_path)
|
|
193
|
+
begin
|
|
194
|
+
# 使用缓存目录作为根目录创建PrebuildSandbox
|
|
195
|
+
# 因为Manifest.lock就在cache_root_dir下,可以直接使用
|
|
196
|
+
cache_dir = File.dirname(cached_manifest_path)
|
|
197
|
+
temp_sandbox = Pod::PrebuildSandbox.new(cache_dir)
|
|
198
|
+
|
|
199
|
+
# 复用现有的get_pod_version逻辑
|
|
200
|
+
return get_pod_version(temp_sandbox, pod_name)
|
|
201
|
+
|
|
202
|
+
rescue => e
|
|
203
|
+
Pod::UI.puts "⚠️ Error reading cached version for #{pod_name}: #{e.message}"
|
|
204
|
+
return "unknown"
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
# 获取指定target的反向依赖(哪些targets依赖于它)
|
|
209
|
+
def self.find_reverse_dependencies(target_to_find, all_pod_targets)
|
|
210
|
+
reverse_deps = all_pod_targets.select do |pod_target|
|
|
211
|
+
# 跳过自己
|
|
212
|
+
next false if pod_target.pod_name == target_to_find.pod_name
|
|
213
|
+
# 检查当前pod_target的正向递归依赖中是否包含目标target
|
|
214
|
+
pod_target.recursive_dependent_targets.include?(target_to_find)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
reverse_deps.map { |item| item.pod_name }
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
# 构建简单的依赖关系图(从targets获取)
|
|
221
|
+
def self.build_simple_dependency_graph(target, total_targets)
|
|
222
|
+
return if total_targets.nil? || total_targets.empty?
|
|
223
|
+
|
|
224
|
+
Pod::UI.puts "🔍 Building reverse dependency graph for cache validation..."
|
|
225
|
+
begin
|
|
226
|
+
pod_name = target.pod_name
|
|
227
|
+
@@dependency_graph[pod_name] = []
|
|
228
|
+
dependencies = []
|
|
229
|
+
temp_dependencies = find_reverse_dependencies(target, total_targets)
|
|
230
|
+
if !temp_dependencies.nil?
|
|
231
|
+
dependencies = temp_dependencies
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
@@dependency_graph[pod_name] = dependencies
|
|
235
|
+
rescue => e
|
|
236
|
+
Pod::UI.puts "⚠️ Warning: Error processing target #{target}: #{e.message}"
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
# 删除pod的缓存
|
|
241
|
+
def self.invalidate_pod_cache(pod_name)
|
|
242
|
+
cache_dir = cache_dir_for_pod(pod_name)
|
|
243
|
+
Pod::UI.puts "🗑️ start Removed invalid cache for #{pod_name}"
|
|
244
|
+
if Dir.exist?(cache_dir)
|
|
245
|
+
FileUtils.rm_rf(cache_dir)
|
|
246
|
+
Pod::UI.puts "🗑️ end Removed invalid cache for #{pod_name}"
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
def self.remove_all_invalid_cache(sandbox, all_targets)
|
|
251
|
+
all_targets.each do |target|
|
|
252
|
+
build_simple_dependency_graph(target, all_targets)
|
|
253
|
+
current_version = get_pod_version(sandbox, target.pod_name)
|
|
254
|
+
if validate_pod_version_consistency(target.pod_name, current_version)
|
|
255
|
+
Pod::UI.puts "🔍 validate_pod_version_consistency #{target.pod_name} #{current_version}"
|
|
256
|
+
else
|
|
257
|
+
cascade_invalidate_dependents(target.pod_name)
|
|
258
|
+
Pod::UI.puts "❌ validate_pod_version_consistency #{target.pod_name} #{current_version}"
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
Pod::UI.puts "📊 Dependency graph: #{@@dependency_graph}"
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
# 级联失效依赖当前pod的其他pod
|
|
265
|
+
def self.cascade_invalidate_dependents(invalidated_pod)
|
|
266
|
+
# 查找所有依赖invalidated_pod的pod
|
|
267
|
+
invalidate_pod_cache(invalidated_pod)
|
|
268
|
+
dependenciess = @@dependency_graph[invalidated_pod]
|
|
269
|
+
return if dependenciess.nil? || !dependenciess.any?
|
|
270
|
+
dependenciess.each do |dependent_pod|
|
|
271
|
+
invalidate_pod_cache(dependent_pod)
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
# 重置依赖验证状态并检查manifest一致性
|
|
276
|
+
def self.reset_dependency_validation(sandbox = nil)
|
|
277
|
+
@@dependency_graph.clear
|
|
278
|
+
Pod::UI.puts "🔄 Reset dependency validation state"
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
# 从 ~/.PodCache 恢复缓存到 _prebuild 目录(版本感知版)
|
|
282
|
+
def self.restore_from_pod_cache(pod_name, prebuild_sandbox)
|
|
283
|
+
begin
|
|
284
|
+
Pod::UI.puts "🔍 Checking cache for #{pod_name}"
|
|
285
|
+
|
|
286
|
+
# 获取pod版本信息
|
|
287
|
+
pod_version = get_pod_version(prebuild_sandbox, pod_name)
|
|
288
|
+
|
|
289
|
+
# 检查缓存是否存在
|
|
290
|
+
unless cache_exists?(pod_name)
|
|
291
|
+
Pod::UI.puts "⚠️ No cache found for #{pod_name}"
|
|
292
|
+
return false
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
# 所有验证通过,从缓存恢复
|
|
296
|
+
cache_dir = cache_dir_for_pod(pod_name)
|
|
297
|
+
target_dir = prebuild_sandbox.framework_folder_path_for_pod_name(pod_name)
|
|
298
|
+
|
|
299
|
+
# 确保目标目录存在
|
|
300
|
+
target_dir.parent.mkpath unless target_dir.parent.exist?
|
|
301
|
+
|
|
302
|
+
# 复制缓存到_prebuild
|
|
303
|
+
FileUtils.cp_r(cache_dir, target_dir, :remove_destination => true)
|
|
304
|
+
|
|
305
|
+
# 删除缓存标记文件
|
|
306
|
+
hash_file = target_dir + '.cache_hash'
|
|
307
|
+
hash_file.delete if hash_file.exist?
|
|
308
|
+
|
|
309
|
+
Pod::UI.puts "📦 Successfully restored #{pod_name} (#{pod_version}) from cache"
|
|
310
|
+
return true
|
|
311
|
+
|
|
312
|
+
rescue => e
|
|
313
|
+
Pod::UI.puts "❌ Error restoring from cache: #{e.message}"
|
|
314
|
+
# 出错时也标记为失效
|
|
315
|
+
return false
|
|
316
|
+
end
|
|
317
|
+
end
|
|
318
|
+
end
|
|
319
|
+
end
|
|
320
|
+
end
|