Class: Pod::Installer::Xcode::PodsProjectGenerator::PodTargetIntegrator

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-kz/native/pod_target_integrator.rb

Instance Method Summary collapse

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

  kz_pod_target = target.weakRef_kz_pod_target
  if kz_pod_target&.have_same_root
    # 如果产物相同,极大可能为sub pod模式,xcframework有相同处理指令,导致并发执行rsync报错
    # 这里延迟0.2秒可以极大减少这种错误产生
    script_content = File.read(target.copy_xcframeworks_script_path)
    new_script_content = script_content.sub(/(install_xcframework "\$\{PODS_ROOT})/, "sleep 0.2\n\\1")
    File.write(target.copy_xcframeworks_script_path, new_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