class Pod::Installer::Xcode::PodsProjectGenerator::PodTargetIntegrator

This class is responsible for integrating a pod target. This includes integrating the test targets included by each pod target.

Attributes

target_installation_result[R]

@return [TargetInstallationResult] the installation result of the target that should be integrated.

Public Class Methods

new(target_installation_result) click to toggle source

Initialize a new instance

@param [TargetInstallationResult] target_installation_result @see target_installation_result

# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_integrator.rb, line 17
def initialize(target_installation_result)
  @target_installation_result = target_installation_result
end

Public Instance Methods

inspect() click to toggle source

@return [String] a string representation suitable for debugging.

# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_integrator.rb, line 39
def inspect
  "#<#{self.class} for target `#{target.label}'>"
end
integrate!() click to toggle source

Integrates the pod target.

@return [void]

# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_integrator.rb, line 25
def integrate!
  UI.section(integration_message) do
    target_installation_result.test_specs_by_native_target.each do |test_native_target, test_specs|
      add_embed_frameworks_script_phase(test_native_target)
      add_copy_resources_script_phase(test_native_target)
      UserProjectIntegrator::TargetIntegrator.create_or_update_user_script_phases(script_phases_for_specs(test_specs), test_native_target)
    end
    specs = target.non_test_specs
    UserProjectIntegrator::TargetIntegrator.create_or_update_user_script_phases(script_phases_for_specs(specs), target_installation_result.native_target)
  end
end

Private Instance Methods

add_copy_resources_script_phase(native_target) click to toggle source

Find or create a 'Copy Pods Resources' build phase

@return [void]

# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_integrator.rb, line 52
def add_copy_resources_script_phase(native_target)
  test_type = target.test_type_for_product_type(native_target.symbol_type)
  script_path = "${PODS_ROOT}/#{target.copy_resources_script_path_for_test_type(test_type).relative_path_from(target.sandbox.root)}"
  resource_paths = target.all_dependent_targets.flat_map do |dependent_target|
    spec_paths_to_include = dependent_target == target ? dependent_target.specs.map(&:name) : dependent_target.non_test_specs.map(&:name)
    dependent_target.resource_paths.values_at(*spec_paths_to_include).flatten.compact
  end
  input_paths = []
  output_paths = []
  unless resource_paths.empty?
    resource_paths_flattened = resource_paths.flatten.uniq
    input_paths = [script_path, *resource_paths_flattened]
    output_paths = UserProjectIntegrator::TargetIntegrator.resource_output_paths(resource_paths_flattened)
  end
  UserProjectIntegrator::TargetIntegrator.validate_input_output_path_limit(input_paths, output_paths)
  UserProjectIntegrator::TargetIntegrator.create_or_update_copy_resources_script_phase_to_target(native_target, script_path, input_paths, output_paths)
end
add_embed_frameworks_script_phase(native_target) click to toggle source

Find or create a 'Embed Pods Frameworks' Copy Files Build Phase

@return [void]

# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_integrator.rb, line 74
def add_embed_frameworks_script_phase(native_target)
  test_type = target.test_type_for_product_type(native_target.symbol_type)
  script_path = "${PODS_ROOT}/#{target.embed_frameworks_script_path_for_test_type(test_type).relative_path_from(target.sandbox.root)}"
  framework_paths = target.all_dependent_targets.flat_map do |dependent_target|
    spec_paths_to_include = dependent_target == target ? dependent_target.specs.map(&:name) : dependent_target.non_test_specs.map(&:name)
    dependent_target.framework_paths.values_at(*spec_paths_to_include).flatten.compact.uniq
  end
  input_paths = []
  output_paths = []
  unless framework_paths.empty?
    input_paths = [script_path, *framework_paths.flat_map { |fw| [fw[:input_path], fw[:dsym_input_path]] }.compact]
    output_paths = framework_paths.flat_map { |fw| [fw[:output_path], fw[:dsym_output_path]] }.compact
  end
  UserProjectIntegrator::TargetIntegrator.validate_input_output_path_limit(input_paths, output_paths)
  UserProjectIntegrator::TargetIntegrator.create_or_update_embed_frameworks_script_phase_to_target(native_target, script_path, input_paths, output_paths)
end
integration_message() click to toggle source

@return [String] the message that should be displayed for the target

integration.
# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_integrator.rb, line 94
def integration_message
  "Integrating target `#{target.name}`"
end
script_phases_for_specs(specs) click to toggle source

@param [Array<Specification] specs

the specs to return script phrases from.

@return [Array<Hash<Symbol=>String>] an array of all combined script phases from the specs.

# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_integrator.rb, line 109
def script_phases_for_specs(specs)
  specs.flat_map { |spec| spec.consumer(target.platform).script_phases }
end
target() click to toggle source

@return [PodTarget] the target part of the installation result.

# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_integrator.rb, line 100
def target
  target_installation_result.target
end