Class: Pod::Installer::Xcode::PodsProjectGenerator::PodTargetIntegrator
- Inherits:
-
Object
- Object
- Pod::Installer::Xcode::PodsProjectGenerator::PodTargetIntegrator
- Defined in:
- lib/cocoapods/installer/xcode/pods_project_generator/pod_target_integrator.rb
Overview
This class is responsible for integrating a pod target. This includes integrating the test targets included by each pod target.
Instance Attribute Summary collapse
-
#target_installation_result ⇒ TargetInstallationResult
readonly
The installation result of the target that should be integrated.
-
#use_input_output_paths ⇒ Boolean
(also: #use_input_output_paths?)
readonly
Whether to use input/output paths for build phase scripts.
Integration steps collapse
-
#add_copy_dsyms_script_phase(native_target) ⇒ void
private
Adds a script phase that copies and strips dSYMs that are part of this target.
-
#add_copy_resources_script_phase(native_target, spec) ⇒ void
private
Find or create a 'Copy Pods Resources' build phase.
-
#add_copy_xcframeworks_script_phase(native_target) ⇒ void
private
Find or create a 'Prepare Artifacts' Run Script Build Phase.
-
#add_embed_frameworks_script_phase(native_target, spec) ⇒ void
private
Find or create a 'Embed Pods Frameworks' Run Script Build Phase.
-
#add_on_demand_resources(native_target, app_spec) ⇒ void
private
Adds the ODRs that are related to this app spec.
-
#integration_message ⇒ String
private
The message that should be displayed for the target integration.
-
#script_phases_for_specs(specs) ⇒ Array<Hash<Symbol=>String>] an array of all combined script phases from the specs.
private
Array
String>] an array of all combined script phases from the specs. -
#target ⇒ PodTarget
private
The target part of the installation result.
Instance Method Summary collapse
-
#initialize(target_installation_result, use_input_output_paths: true) ⇒ PodTargetIntegrator
constructor
Initialize a new instance.
-
#inspect ⇒ String
A string representation suitable for debugging.
-
#integrate! ⇒ void
Integrates the pod target.
Constructor Details
#initialize(target_installation_result, use_input_output_paths: true) ⇒ PodTargetIntegrator
Initialize a new instance
23 24 25 26 |
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_integrator.rb', line 23 def initialize(target_installation_result, use_input_output_paths: true) @target_installation_result = target_installation_result @use_input_output_paths = use_input_output_paths end |
Instance Attribute Details
#target_installation_result ⇒ TargetInstallationResult (readonly)
Returns the installation result of the target that should be integrated.
11 12 13 |
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_integrator.rb', line 11 def target_installation_result @target_installation_result end |
#use_input_output_paths ⇒ Boolean (readonly) Also known as: use_input_output_paths?
Returns whether to use input/output paths for build phase scripts.
15 16 17 |
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_integrator.rb', line 15 def use_input_output_paths @use_input_output_paths end |
Instance Method Details
#add_copy_dsyms_script_phase(native_target) ⇒ void (private)
This method returns an undefined value.
Adds a script phase that copies and strips dSYMs that are part of this target. Note this only deals with vendored dSYMs.
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_integrator.rb', line 213 def add_copy_dsyms_script_phase(native_target) script_path = "${PODS_ROOT}/#{target.copy_dsyms_script_path.relative_path_from(target.sandbox.root)}" dsym_paths = PodTargetInstaller.dsym_paths(target) bcsymbolmap_paths = PodTargetInstaller.bcsymbolmap_paths(target) if dsym_paths.empty? && bcsymbolmap_paths.empty? script_phase = native_target.shell_script_build_phases.find do |bp| bp.name && bp.name.end_with?(UserProjectIntegrator::TargetIntegrator::COPY_DSYM_FILES_PHASE_NAME) end native_target.build_phases.delete(script_phase) if script_phase.present? return end phase_name = UserProjectIntegrator::TargetIntegrator::BUILD_PHASE_PREFIX + UserProjectIntegrator::TargetIntegrator::COPY_DSYM_FILES_PHASE_NAME phase = UserProjectIntegrator::TargetIntegrator.create_or_update_shell_script_build_phase(native_target, phase_name) phase.shell_script = %("#{script_path}"\n) input_paths_by_config = {} output_paths_by_config = {} if use_input_output_paths? input_file_list_path = target.copy_dsyms_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] = [] input_paths.concat([dsym_paths, *bcsymbolmap_paths].flatten.compact) output_file_list_path = target.copy_dsyms_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 = output_paths_by_config[output_paths_key] = [] dsym_output_paths = dsym_paths.map { |dsym_path| "${DWARF_DSYM_FOLDER_PATH}/#{File.basename(dsym_path)}" } bcsymbolmap_output_paths = bcsymbolmap_paths.map { |bcsymbolmap_path| "${DWARF_DSYM_FOLDER_PATH}/#{File.basename(bcsymbolmap_path)}" } output_paths.concat([dsym_output_paths, *bcsymbolmap_output_paths].flatten.compact) end UserProjectIntegrator::TargetIntegrator.set_input_output_paths(phase, input_paths_by_config, output_paths_by_config) end |
#add_copy_resources_script_phase(native_target, spec) ⇒ void (private)
This method returns an undefined value.
Find or create a 'Copy Pods Resources' build phase
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_integrator.rb', line 67 def add_copy_resources_script_phase(native_target, spec) script_path = "${PODS_ROOT}/#{target.copy_resources_script_path_for_spec(spec).relative_path_from(target.sandbox.root)}" input_paths_by_config = {} output_paths_by_config = {} dependent_targets = if spec.test_specification? target.dependent_targets_for_test_spec(spec) else target.dependent_targets_for_app_spec(spec) end host_target_spec_names = target.app_host_dependent_targets_for_spec(spec).flat_map do |pt| pt.specs.map(&:name) end.uniq resource_paths = dependent_targets.flat_map do |dependent_target| spec_paths_to_include = dependent_target.library_specs.map(&:name) spec_paths_to_include -= host_target_spec_names spec_paths_to_include << spec.name if dependent_target == target dependent_target.resource_paths.values_at(*spec_paths_to_include).flatten.compact end.uniq if use_input_output_paths? && !resource_paths.empty? input_file_list_path = target.copy_resources_script_input_files_path_for_spec(spec) 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_by_config[input_paths_key] = [script_path] + resource_paths output_file_list_path = target.copy_resources_script_output_files_path_for_spec(spec) 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] = UserProjectIntegrator::TargetIntegrator.resource_output_paths(resource_paths) end if resource_paths.empty? UserProjectIntegrator::TargetIntegrator.remove_copy_resources_script_phase_from_target(native_target) else UserProjectIntegrator::TargetIntegrator.create_or_update_copy_resources_script_phase_to_target( native_target, script_path, input_paths_by_config, output_paths_by_config) end end |
#add_copy_xcframeworks_script_phase(native_target) ⇒ void (private)
This method returns an undefined value.
Find or create a 'Prepare Artifacts' Run Script Build Phase
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_integrator.rb', line 172 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 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 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 |
#add_embed_frameworks_script_phase(native_target, spec) ⇒ void (private)
This method returns an undefined value.
Find or create a 'Embed Pods Frameworks' Run Script Build Phase
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_integrator.rb', line 118 def (native_target, spec) script_path = "${PODS_ROOT}/#{target.(spec).relative_path_from(target.sandbox.root)}" input_paths_by_config = {} output_paths_by_config = {} dependent_targets = if spec.test_specification? target.dependent_targets_for_test_spec(spec) else target.dependent_targets_for_app_spec(spec) end host_target_spec_names = target.app_host_dependent_targets_for_spec(spec).flat_map do |pt| pt.specs.map(&:name) end.uniq framework_paths = dependent_targets.flat_map do |dependent_target| spec_paths_to_include = dependent_target.library_specs.map(&:name) spec_paths_to_include -= host_target_spec_names spec_paths_to_include << spec.name if dependent_target == target dependent_target.framework_paths.values_at(*spec_paths_to_include).flatten.compact end.uniq xcframework_paths = dependent_targets.flat_map do |dependent_target| spec_paths_to_include = dependent_target.library_specs.map(&:name) spec_paths_to_include -= host_target_spec_names spec_paths_to_include << spec.name if dependent_target == target dependent_target.xcframeworks.values_at(*spec_paths_to_include).flatten.compact end.uniq if use_input_output_paths? && !framework_paths.empty? || !xcframework_paths.empty? input_file_list_path = target.(spec) 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_by_config[input_paths_key] = [script_path] + UserProjectIntegrator::TargetIntegrator.(framework_paths, xcframework_paths) output_file_list_path = target.(spec) 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] = UserProjectIntegrator::TargetIntegrator.(framework_paths, xcframework_paths) end if framework_paths.empty? && xcframework_paths.empty? UserProjectIntegrator::TargetIntegrator.(native_target) else UserProjectIntegrator::TargetIntegrator.( native_target, script_path, input_paths_by_config, output_paths_by_config) end end |
#add_on_demand_resources(native_target, app_spec) ⇒ void (private)
This method returns an undefined value.
Adds the ODRs that are related to this app spec. This includes the app spec dependencies as well as the ODRs coming from the app spec itself.
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_integrator.rb', line 263 def add_on_demand_resources(native_target, app_spec) dependent_targets = target.dependent_targets_for_app_spec(app_spec) parent_odr_group = native_target.project.group_for_spec(app_spec.name) # Add ODRs of the app spec dependencies first. dependent_targets.each do |pod_target| file_accessors = pod_target.file_accessors.select do |fa| fa.spec.library_specification? || fa.spec.test_specification? && pod_target.test_app_hosts_by_spec[fa.spec]&.first == app_spec end target_odr_group_name = "#{pod_target.label}-OnDemandResources" UserProjectIntegrator::TargetIntegrator.update_on_demand_resources(target.sandbox, native_target.project, native_target, file_accessors, parent_odr_group, target_odr_group_name) end # Now add the ODRs of our own app spec declaration. file_accessor = target.file_accessors.find { |fa| fa.spec == app_spec } target_odr_group_name = "#{target.subspec_label(app_spec)}-OnDemandResources" UserProjectIntegrator::TargetIntegrator.update_on_demand_resources(target.sandbox, native_target.project, native_target, file_accessor, parent_odr_group, target_odr_group_name) end |
#inspect ⇒ String
Returns a string representation suitable for debugging.
48 49 50 |
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_integrator.rb', line 48 def inspect "#<#{self.class} for target `#{target.label}'>" end |
#integrate! ⇒ void
This method returns an undefined value.
Integrates the pod target.
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_integrator.rb', line 32 def integrate! UI.section() do target_installation_result.non_library_specs_by_native_target.each do |native_target, spec| (native_target, spec) add_copy_resources_script_phase(native_target, spec) add_on_demand_resources(native_target, spec) if spec.app_specification? UserProjectIntegrator::TargetIntegrator.create_or_update_user_script_phases(script_phases_for_specs(spec), native_target) end add_copy_dsyms_script_phase(target_installation_result.native_target) add_copy_xcframeworks_script_phase(target_installation_result.native_target) UserProjectIntegrator::TargetIntegrator.create_or_update_user_script_phases(script_phases_for_specs(target.library_specs), target_installation_result.native_target) end end |
#integration_message ⇒ String (private)
Returns the message that should be displayed for the target integration.
290 291 292 |
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_integrator.rb', line 290 def "Integrating target `#{target.name}`" end |
#script_phases_for_specs(specs) ⇒ Array<Hash<Symbol=>String>] an array of all combined script phases from the specs. (private)
Returns Array
305 306 307 |
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_integrator.rb', line 305 def script_phases_for_specs(specs) Array(specs).flat_map { |spec| spec.consumer(target.platform).script_phases } end |
#target ⇒ PodTarget (private)
Returns the target part of the installation result.
296 297 298 |
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_integrator.rb', line 296 def target target_installation_result.target end |