module Pod class JxedtPrebuildInstaller < Installer # rubocop:disable Metrics/ClassLength def installation_options # Skip integrating user targets for prebuild Pods project. @installation_options ||= Pod::Installer::InstallationOptions.new( super.to_h.merge(:integrate_targets => false) ) end def generate_pods_index_project! return unless Jxedt.config.create_index_project? Pod::UI.puts "-----------------------------------------" Pod::UI.puts "🚖 正在生成Pods-Index.xcodeproj,可以直接把工程拖入workspace来查看源码或进行二进制调试" Pod::UI.puts "-----------------------------------------" # 生成index project开始标识 sandbox.index_project_create_stage = true # 获取缓存 cache_analysis_result = analyze_project_cache # 获取缓存中需要生成的pod_targets,并拷贝一份新的,不修改原来的值 pod_targets_to_generate = cache_analysis_result.pod_targets_to_generate.map do |target| target_to_copy = target.clone target_to_copy.binary_index_enabled = true # 修改标识,用于修改Target的productName target_to_copy end # 调用生成project的方法,aggregate_targets传空数组 create_and_save_projects(pod_targets_to_generate, [], cache_analysis_result.build_configurations, cache_analysis_result.project_object_version) # 恢复sandbox标识 sandbox.index_project_create_stage = false end def resolve_dependencies analyzer = super self.analysis_result.specifications.each do |spec| # keep all file in pods preserve_paths = spec.attributes_hash["preserve_paths"] || [] preserve_paths = [preserve_paths] if preserve_paths.kind_of?(String) preserve_paths += ['_Prebuild'] spec.attributes_hash["preserve_paths"] = preserve_paths end analyzer end end end module Pod class Installer # Cleans up the sandbox directory by removing stale target support files and headers. # class SandboxDirCleaner alias_method :old_sandbox_project_dir_names, :sandbox_project_dir_names def sandbox_project_dir_names project_dir_names = old_sandbox_project_dir_names if sandbox.is_a?(Pod::JxedtPrebuildSandbox) # 如果允许生成Pods-Index.xcodeproj,排除这个文件 project_dir_names.reject! { |d| d.basename.to_s =~ /#{sandbox.index_project_name}$/ } if Jxedt.config.create_index_project? end project_dir_names end end end class PodTarget < Target attr_accessor :binary_index_enabled # Target的PRODUCT_NAME写入逻辑可以查看`PodTargetInstaller` # settings['PRODUCT_NAME'] = target.product_basename # settings['PRODUCT_MODULE_NAME'] = target.product_module_name # # 所以插件采用的方式是修改`product_basename`来改变Pods-Index.xcodeproj的名称 # alias_method :old_product_basename, :product_basename def product_basename if binary_index_enabled # 在后面添加'_Source'改变PRODUCT_NAME return "#{old_product_basename}_Source" end old_product_basename end end end