Class: Pod::Installer::Xcode::PodsProjectGenerator::PodTargetIntegrator
- Inherits:
-
Object
- Object
- Pod::Installer::Xcode::PodsProjectGenerator::PodTargetIntegrator
- Defined in:
- lib/cocoapods-kz/native/pod_target_integrator.rb
Instance Method Summary collapse
- #add_copy_xcframeworks_script_phase(native_target) ⇒ Object
-
#kz_lock_xcframework_rsync(script_content) ⇒ Object
保留 CocoaPods 原始 rsync 命令,仅在执行前插入 destination 级别的文件锁。 不同 destination 可并行复制;同一 destination 的多个脚本会串行执行。.
Instance Method Details
#add_copy_xcframeworks_script_phase(native_target) ⇒ Object
9 10 11 12 13 14 15 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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/cocoapods-kz/native/pod_target_integrator.rb', line 9 def add_copy_xcframeworks_script_phase(native_target) script_path = "${PODS_ROOT}/#{target.copy_xcframeworks_script_path.relative_path_from(target.sandbox.root)}" input_paths_by_config = {} output_paths_by_config = {} xcframeworks = target.xcframeworks.values.flatten # XCFramework 的输出目录由 xcframework.target_name 决定,不能只根据 # have_same_root 判断是否冲突:首个同名 target 或其他 root pod 也可能复制到 # 同一个 destination。所有 Copy XCFramework 脚本都加 destination 级别的锁; # 不同 destination 的复制仍可并行。 unless xcframeworks.empty? script_content = File.read(target.copy_xcframeworks_script_path) File.write(target.copy_xcframeworks_script_path, kz_lock_xcframework_rsync(script_content)) end if use_input_output_paths? && !xcframeworks.empty? input_file_list_path = target.copy_xcframeworks_script_input_files_path input_file_list_relative_path = "${PODS_ROOT}/#{input_file_list_path.relative_path_from(target.sandbox.root)}" input_paths_key = UserProjectIntegrator::TargetIntegrator::XCFileListConfigKey.new(input_file_list_path, input_file_list_relative_path) input_paths = input_paths_by_config[input_paths_key] = [script_path] framework_paths = xcframeworks.map { |xcf| "${PODS_ROOT}/#{xcf.path.relative_path_from(target.sandbox.root)}" } input_paths.concat framework_paths output_file_list_path = target.copy_xcframeworks_script_output_files_path output_file_list_relative_path = "${PODS_ROOT}/#{output_file_list_path.relative_path_from(target.sandbox.root)}" output_paths_key = UserProjectIntegrator::TargetIntegrator::XCFileListConfigKey.new(output_file_list_path, output_file_list_relative_path) output_paths_by_config[output_paths_key] = xcframeworks.map do |xcf| "#{Target::BuildSettings::XCFRAMEWORKS_BUILD_DIR_VARIABLE}/#{xcf.target_name}/#{xcf.name}.framework" end end if xcframeworks.empty? UserProjectIntegrator::TargetIntegrator.remove_copy_xcframeworks_script_phase_from_target(native_target) else if target_installation_result.target.scope_suffix output_paths_by_config.each do |key, value| if value && value.count > 0 need_remove_paths = [] value.each do |path| if $global_output_paths_avoid_duplicate.include?(path) need_remove_paths.append(path) else $global_output_paths_avoid_duplicate.append(path) end end need_remove_paths.each do |need_remove_path| value.delete(need_remove_path) end if need_remove_paths.count > 0 end end end UserProjectIntegrator::TargetIntegrator.create_or_update_copy_xcframeworks_script_phase_to_target( native_target, script_path, input_paths_by_config, output_paths_by_config) end end |
#kz_lock_xcframework_rsync(script_content) ⇒ Object
保留 CocoaPods 原始 rsync 命令,仅在执行前插入 destination 级别的文件锁。 不同 destination 可并行复制;同一 destination 的多个脚本会串行执行。
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/cocoapods-kz/native/pod_target_integrator.rb', line 70 def kz_lock_xcframework_rsync(script_content) lock_marker = '# COCOAPODS_KZ_XCFRAMEWORK_RSYNC_LOCK' return script_content if script_content.include?(lock_marker) rsync_pattern = /^([ \t]*)(rsync\s+--delete\b[^\r\n]*)$/ match = rsync_pattern.match(script_content) unless match raise 'Unable to locate the XCFramework rsync command for the copy lock patch.' end indent = match[1] rsync_command = match[2] locked_command = [ "#{indent}#{lock_marker}", "#{indent}# Serialize only copies that share the same XCFramework destination.", "#{indent}local lock_file=\"${PODS_XCFRAMEWORKS_BUILD_DIR}/.cocoapods-kz-xcframeworks-$(printf '%s' \"${destination}\" | shasum -a 256 | awk '{print $1}').lock\"", "#{indent}/usr/bin/lockf -k -w \"${lock_file}\" #{rsync_command}", ].join("\n") script_content.sub(rsync_pattern, locked_command) end |