Module: Pod::PodGenerate::Patches::ProjectWriterPatch::IncrementalAndParallelSave
- Defined in:
- lib/cocoapods-podgenerate/patches/project_writer_patch.rb
Instance Method Summary collapse
-
#initialize(sandbox, projects, pod_target_installation_results, installation_options) ⇒ Object
初始化:调用原始构造器后,计算所有项目的初始 SHA256 摘要.
-
#save_projects(projects) ⇒ Object
增量 + 并行保存项目.
-
#write! ⇒ Object
并行清理、重建 scheme、然后增量保存所有项目.
Instance Method Details
#initialize(sandbox, projects, pod_target_installation_results, installation_options) ⇒ Object
初始化:调用原始构造器后,计算所有项目的初始 SHA256 摘要
54 55 56 57 58 59 |
# File 'lib/cocoapods-podgenerate/patches/project_writer_patch.rb', line 54 def initialize(sandbox, projects, pod_target_installation_results, ) super @project_digests = {} # project.object_id => SHA256 摘要 @sort_needed = {} # project.object_id => 是否需要排序 compute_initial_digests end |
#save_projects(projects) ⇒ Object
增量 + 并行保存项目
流程:
1. 过滤: 跳过 pbxproj 内容未变的项目(SHA256 摘要比对)
2. 排序: 对需要保存的项目调用 sort(:groups_position => :below)
3. 保存: 多项目并行写入(每个 xcodeproj 独立目录)
【Bug 修复 L1】只有当 old_digest 和 current_digest 都非 nil 且相等时才跳过。如果任一为 nil(例如文件不可读),一律重新保存以确保项目完整性。
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 114 115 116 117 118 119 120 121 122 |
# File 'lib/cocoapods-podgenerate/patches/project_writer_patch.rb', line 87 def save_projects(projects) to_save = projects.select do |project| old = @project_digests[project.object_id] cur = digest_pbxproj(project) if old && cur && old == cur Pod::UI. "- Skipping unchanged project #{UI.path project.path}" false else true end end return if to_save.empty? # 排序(串行 — sort 操作轻量,并行开销反而更大) to_save.each { |p| p.sort(:groups_position => :below) if needs_sort?(p) } # 并行保存 if to_save.size > 1 Pod::UI. "- Saving #{to_save.size} projects in parallel" threads = to_save.map do |project| Thread.new do Pod::UI. "- Writing Xcode project file to #{UI.path project.path}" project.save update_digest(project) rescue StandardError => e Pod::UI.warn "[cocoapods-podgenerate] Parallel save error: #{e.}" end end threads.each(&:join) else project = to_save.first Pod::UI. "- Writing Xcode project file to #{UI.path project.path}" project.save update_digest(project) end end |
#write! ⇒ Object
并行清理、重建 scheme、然后增量保存所有项目
流程:
1. 并行清理每个项目的空 groups
2. 并行重建 scheme(将 test target 附加到 library target)
3. 执行 post-install hooks(yield)
4. SHA256 增量判断 + 并行保存
68 69 70 71 72 73 |
# File 'lib/cocoapods-podgenerate/patches/project_writer_patch.rb', line 68 def write! parallel_cleanup_projects(@projects) parallel_recreate_user_schemes(@projects) yield if block_given? save_projects(@projects) end |