Class: Pod::PodTarget

Inherits:
Target
  • Object
show all
Defined in:
lib/cocoapods/target/pod_target.rb

Overview

Stores the information relative to the target used to compile a single Pod. A pod can have one or more activated spec, subspecs and test specs.

Constant Summary

Constants inherited from Target

Target::DEFAULT_BUILD_CONFIGURATIONS, Target::DEFAULT_NAME, Target::DEFAULT_VERSION

Instance Attribute Summary collapse

Attributes inherited from Target

#application_extension_api_only, #archs, #build_library_for_distribution, #build_settings, #platform, #sandbox, #user_build_configurations

Instance Method Summary collapse

Methods inherited from Target

#bridge_support_path, #build_as_dynamic?, #build_as_dynamic_framework?, #build_as_dynamic_library?, #build_as_framework?, #build_as_library?, #build_as_static?, #build_as_static_framework?, #build_as_static_library?, #dummy_source_path, #framework_name, #info_plist_path, #inspect, #mark_application_extension_api_only, #mark_build_library_for_distribution, #module_map_path_to_write, #name, output_extension_for_resource, #prepare_artifacts_script_path, #product_basename, #product_name, #product_type, #requires_frameworks?, resource_extension_compilable?, #static_framework?, #static_library_name, #support_files_dir, #umbrella_header_path, #umbrella_header_path_to_write, #xcconfig_path

Constructor Details

#initialize(sandbox, build_type, user_build_configurations, archs, platform, specs, target_definitions, file_accessors = [], scope_suffix = nil, swift_version = nil) ⇒ PodTarget

Initialize a new instance

Parameters:

  • sandbox (Sandbox)

    @see Target#sandbox

  • build_type (BuildType)

    @see Target#build_type

  • user_build_configurations (Hash{String=>Symbol})

    @see Target#user_build_configurations

  • archs (Array<String>)

    @see Target#archs

  • platform (Platform)

    @see Target#platform

  • specs (Array<Specification>)

    @see #specs

  • target_definitions (Array<TargetDefinition>)

    @see #target_definitions

  • file_accessors (Array<Sandbox::FileAccessor>) (defaults to: [])

    @see #file_accessors

  • scope_suffix (String) (defaults to: nil)

    @see #scope_suffix

  • swift_version (String) (defaults to: nil)

    @see #swift_version


137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/cocoapods/target/pod_target.rb', line 137

def initialize(sandbox, build_type, user_build_configurations, archs, platform, specs, target_definitions,
               file_accessors = [], scope_suffix = nil, swift_version = nil)
  super(sandbox, build_type, user_build_configurations, archs, platform)
  raise "Can't initialize a PodTarget without specs!" if specs.nil? || specs.empty?
  raise "Can't initialize a PodTarget without TargetDefinition!" if target_definitions.nil? || target_definitions.empty?
  raise "Can't initialize a PodTarget with an empty string scope suffix!" if scope_suffix == ''
  @specs = specs.dup.freeze
  @target_definitions = target_definitions
  @file_accessors = file_accessors
  @scope_suffix = scope_suffix
  @swift_version = swift_version
  all_specs_by_type = @specs.group_by(&:spec_type)
  @library_specs = all_specs_by_type[:library] || []
  @test_specs = all_specs_by_type[:test] || []
  @app_specs = all_specs_by_type[:app] || []
  @build_headers = Sandbox::HeadersStore.new(sandbox, 'Private', :private)
  self.dependent_targets = []
  self.test_dependent_targets_by_spec_name = Hash[test_specs.map { |ts| [ts.name, []] }]
  self.app_dependent_targets_by_spec_name = Hash[app_specs.map { |as| [as.name, []] }]
  @test_app_hosts_by_spec = {}
  @build_config_cache = {}
  @test_spec_build_settings_by_config = create_test_build_settings_by_config
  @app_spec_build_settings_by_config = create_app_build_settings_by_config
end

Instance Attribute Details

#app_dependent_targets_by_spec_nameHash{String=>Array<PodTarget>}

Returns all target dependencies by app spec name.

Returns:

  • (Hash{String=>Array<PodTarget>})

    all target dependencies by app spec name.


88
89
90
# File 'lib/cocoapods/target/pod_target.rb', line 88

def app_dependent_targets_by_spec_name
  @app_dependent_targets_by_spec_name
end

#app_dependent_targets_by_spec_name_by_configObject

Returns the value of attribute app_dependent_targets_by_spec_name_by_config


89
90
91
# File 'lib/cocoapods/target/pod_target.rb', line 89

def app_dependent_targets_by_spec_name_by_config
  @app_dependent_targets_by_spec_name_by_config
end

#app_spec_build_settingsHash{String => BuildSettings} (readonly)

Returns the app spec build settings for this target.

Returns:

  • (Hash{String => BuildSettings})

    the app spec build settings for this target.


117
118
119
# File 'lib/cocoapods/target/pod_target.rb', line 117

def app_spec_build_settings
  @app_spec_build_settings
end

#app_spec_build_settings_by_configObject (readonly)

Returns the value of attribute app_spec_build_settings_by_config


118
119
120
# File 'lib/cocoapods/target/pod_target.rb', line 118

def app_spec_build_settings_by_config
  @app_spec_build_settings_by_config
end

#app_specsArray<Specification> (readonly)

Returns All of the specs within this target that are app specs. Subset of #specs.

Returns:

  • (Array<Specification>)

    All of the specs within this target that are app specs. Subset of #specs.


26
27
28
# File 'lib/cocoapods/target/pod_target.rb', line 26

def app_specs
  @app_specs
end

#build_headersHeadersStore (readonly)

Returns the header directory for the target.

Returns:

  • (HeadersStore)

    the header directory for the target.


47
48
49
# File 'lib/cocoapods/target/pod_target.rb', line 47

def build_headers
  @build_headers
end

#dependent_targetsArray<PodTarget>

Returns the targets that this target has a dependency upon.

Returns:

  • (Array<PodTarget>)

    the targets that this target has a dependency upon.


52
53
54
# File 'lib/cocoapods/target/pod_target.rb', line 52

def dependent_targets
  @dependent_targets
end

#dependent_targets_by_configObject

Returns the value of attribute dependent_targets_by_config


53
54
55
# File 'lib/cocoapods/target/pod_target.rb', line 53

def dependent_targets_by_config
  @dependent_targets_by_config
end

#file_accessorsArray<Sandbox::FileAccessor> (readonly)

Returns the file accessors for the specifications of this target.

Returns:


36
37
38
# File 'lib/cocoapods/target/pod_target.rb', line 36

def file_accessors
  @file_accessors
end

#library_specsArray<Specification> (readonly)

Returns All of the specs within this target that are library specs. Subset of #specs.

Returns:

  • (Array<Specification>)

    All of the specs within this target that are library specs. Subset of #specs.


21
22
23
# File 'lib/cocoapods/target/pod_target.rb', line 21

def library_specs
  @library_specs
end

#scope_suffixString (readonly)

Note:

This affects the value returned by #configuration_build_dir and accessors relying on this as #build_product_path.

Returns the suffix used for this target when deduplicated. May be `nil`.

Returns:

  • (String)

    the suffix used for this target when deduplicated. May be `nil`.


43
44
45
# File 'lib/cocoapods/target/pod_target.rb', line 43

def scope_suffix
  @scope_suffix
end

#specsArray<Specification> (readonly)

Returns the spec, subspecs and test specs of the target.

Returns:

  • (Array<Specification>)

    the spec, subspecs and test specs of the target.


11
12
13
# File 'lib/cocoapods/target/pod_target.rb', line 11

def specs
  @specs
end

#swift_versionString (readonly)

Returns the Swift version for this target.

Returns:

  • (String)

    the Swift version for this target.


122
123
124
# File 'lib/cocoapods/target/pod_target.rb', line 122

def swift_version
  @swift_version
end

#target_definitionsArray<TargetDefinition> (readonly)

Returns the target definitions of the Podfile that generated this target.

Returns:

  • (Array<TargetDefinition>)

    the target definitions of the Podfile that generated this target.


31
32
33
# File 'lib/cocoapods/target/pod_target.rb', line 31

def target_definitions
  @target_definitions
end

#test_app_hosts_by_specHash{Specification => (Specification,PodTarget)}

Returns tuples of app specs and pod targets by test spec.

Returns:


108
109
110
# File 'lib/cocoapods/target/pod_target.rb', line 108

def test_app_hosts_by_spec
  @test_app_hosts_by_spec
end

#test_dependent_targets_by_spec_nameHash{String=>Array<PodTarget>}

Returns all target dependencies by test spec name.

Returns:

  • (Hash{String=>Array<PodTarget>})

    all target dependencies by test spec name.


68
69
70
# File 'lib/cocoapods/target/pod_target.rb', line 68

def test_dependent_targets_by_spec_name
  @test_dependent_targets_by_spec_name
end

#test_dependent_targets_by_spec_name_by_configObject

Returns the value of attribute test_dependent_targets_by_spec_name_by_config


69
70
71
# File 'lib/cocoapods/target/pod_target.rb', line 69

def test_dependent_targets_by_spec_name_by_config
  @test_dependent_targets_by_spec_name_by_config
end

#test_spec_build_settingsHash{String => BuildSettings} (readonly)

Returns the test spec build settings for this target.

Returns:

  • (Hash{String => BuildSettings})

    the test spec build settings for this target.


112
113
114
# File 'lib/cocoapods/target/pod_target.rb', line 112

def test_spec_build_settings
  @test_spec_build_settings
end

#test_spec_build_settings_by_configObject (readonly)

Returns the value of attribute test_spec_build_settings_by_config


113
114
115
# File 'lib/cocoapods/target/pod_target.rb', line 113

def test_spec_build_settings_by_config
  @test_spec_build_settings_by_config
end

#test_specsArray<Specification> (readonly)

Returns All of the test specs within this target. Subset of #specs.

Returns:

  • (Array<Specification>)

    All of the test specs within this target. Subset of #specs.


16
17
18
# File 'lib/cocoapods/target/pod_target.rb', line 16

def test_specs
  @test_specs
end

Instance Method Details

#all_filesArray<FileAccessor>

Returns The list of all files tracked.

Returns:

  • (Array<FileAccessor>)

    The list of all files tracked.


208
209
210
# File 'lib/cocoapods/target/pod_target.rb', line 208

def all_files
  Sandbox::FileAccessor.all_files(file_accessors)
end

#app_host_dependent_targets_for_spec(spec, configuration: nil) ⇒ Array<PodTarget>

Returns the app host dependent targets for the given spec.

Parameters:

  • spec (Specification)

    the spec to return app host dependencies for

  • configuration (String) (defaults to: nil)

    the configuration to retrieve the app host dependent targets for.

Returns:

  • (Array<PodTarget>)

    the app host dependent targets for the given spec.


611
612
613
614
615
616
617
618
619
620
# File 'lib/cocoapods/target/pod_target.rb', line 611

def app_host_dependent_targets_for_spec(spec, configuration: nil)
  return [] unless spec.test_specification? && spec.consumer(platform).test_type == :unit
  app_host_info = test_app_hosts_by_spec[spec]
  if app_host_info.nil?
    []
  else
    app_spec, app_target = *app_host_info
    app_target.dependent_targets_for_app_spec(app_spec, :configuration => configuration)
  end
end

#app_host_target_label(test_spec) ⇒ (String,String)

Returns a tuple, where the first item is the PodTarget#label of the pod target that defines the app host, and the second item is the target name of the app host.

Parameters:

  • test_spec (Specification)

    the test spec to use for producing the app host target label.

Returns:

  • ((String,String))

    a tuple, where the first item is the PodTarget#label of the pod target that defines the app host, and the second item is the target name of the app host


593
594
595
596
597
598
599
600
601
# File 'lib/cocoapods/target/pod_target.rb', line 593

def app_host_target_label(test_spec)
  app_spec, app_target = test_app_hosts_by_spec[test_spec]

  if app_spec
    [app_target.name, app_target.app_target_label(app_spec)]
  elsif test_spec.consumer(platform).requires_app_host?
    [name, "AppHost-#{label}-#{label_for_test_type(test_spec.test_type)}-Tests"]
  end
end

#app_spec_consumersArray<Specification::Consumer>

Returns the test specification consumers for the target.

Returns:

  • (Array<Specification::Consumer>)

    the test specification consumers for the target.


300
301
302
# File 'lib/cocoapods/target/pod_target.rb', line 300

def app_spec_consumers
  app_specs.map { |app_spec| app_spec.consumer(platform) }
end

#app_target_label(app_spec) ⇒ String

Returns The derived name of the app target.

Parameters:

  • app_spec (Specification)

    The app spec to use for producing the app label.

Returns:

  • (String)

    The derived name of the app target.


583
584
585
# File 'lib/cocoapods/target/pod_target.rb', line 583

def app_target_label(app_spec)
  "#{label}-#{subspec_label(app_spec)}"
end

#build_product_path(dir = BuildSettings::CONFIGURATION_BUILD_DIR_VARIABLE) ⇒ String

Returns The absolute path to the build product.

Parameters:

  • dir (String) (defaults to: BuildSettings::CONFIGURATION_BUILD_DIR_VARIABLE)

    @see #configuration_build_dir

Returns:

  • (String)

    The absolute path to the build product


966
967
968
# File 'lib/cocoapods/target/pod_target.rb', line 966

def build_product_path(dir = BuildSettings::CONFIGURATION_BUILD_DIR_VARIABLE)
  "#{configuration_build_dir(dir)}/#{product_name}"
end

#build_settings_by_config_for_spec(spec) ⇒ Object


1028
1029
1030
1031
1032
1033
1034
# File 'lib/cocoapods/target/pod_target.rb', line 1028

def build_settings_by_config_for_spec(spec)
  case spec.spec_type
  when :test then test_spec_build_settings_by_config[spec.name]
  when :app  then app_spec_build_settings_by_config[spec.name]
  else            build_settings
  end || raise(ArgumentError, "No build settings for #{spec}")
end

#build_settings_for_spec(spec, configuration: nil) ⇒ BuildSettings::PodTargetSettings

Returns The build settings for the given spec.

Parameters:

  • spec (Specification)

    the specification to return build settings for.

  • configuration (String) (defaults to: nil)

    the configuration to scope the build settings.

Returns:

Raises:

  • (ArgumentError)

1022
1023
1024
1025
1026
# File 'lib/cocoapods/target/pod_target.rb', line 1022

def build_settings_for_spec(spec, configuration: nil)
  raise ArgumentError, 'Must give configuration' unless configuration
  configuration = user_build_configurations[configuration] if user_build_configurations.key?(configuration)
  build_settings_by_config_for_spec(spec)[configuration] || raise(ArgumentError, "No build settings for #{spec} (configuration #{configuration.inspect}) (known configurations #{config_variants})")
end

#configuration_build_dir(dir = BuildSettings::CONFIGURATION_BUILD_DIR_VARIABLE) ⇒ String

Returns The absolute path to the configuration build dir.

Parameters:

  • dir (String) (defaults to: BuildSettings::CONFIGURATION_BUILD_DIR_VARIABLE)

    The directory (which might be a variable) relative to which the returned path should be. This must be used if the $CONFIGURATION_BUILD_DIR is modified.

Returns:

  • (String)

    The absolute path to the configuration build dir


957
958
959
# File 'lib/cocoapods/target/pod_target.rb', line 957

def configuration_build_dir(dir = BuildSettings::CONFIGURATION_BUILD_DIR_VARIABLE)
  "#{dir}/#{label}"
end

#contains_app_specifications?Boolean

Returns Whether the target has any tests specifications.

Returns:

  • (Boolean)

    Whether the target has any tests specifications.


378
379
380
# File 'lib/cocoapods/target/pod_target.rb', line 378

def contains_app_specifications?
  !app_specs.empty?
end

#contains_script_phases?Boolean

Returns Whether the target contains any script phases.

Returns:

  • (Boolean)

    Whether the target contains any script phases.


366
367
368
# File 'lib/cocoapods/target/pod_target.rb', line 366

def contains_script_phases?
  !script_phases.empty?
end

#contains_test_specifications?Boolean

Returns Whether the target has any tests specifications.

Returns:

  • (Boolean)

    Whether the target has any tests specifications.


372
373
374
# File 'lib/cocoapods/target/pod_target.rb', line 372

def contains_test_specifications?
  !test_specs.empty?
end

#copy_dsyms_script_input_files_pathPathname

Returns The absolute path of the copy dSYM script phase input file list.

Returns:

  • (Pathname)

    The absolute path of the copy dSYM script phase input file list.


761
762
763
# File 'lib/cocoapods/target/pod_target.rb', line 761

def copy_dsyms_script_input_files_path
  support_files_dir + "#{label}-copy-dsyms-input-files.xcfilelist"
end

#copy_dsyms_script_output_files_pathPathname

Returns The absolute path of the copy dSYM script phase output file list.

Returns:

  • (Pathname)

    The absolute path of the copy dSYM script phase output file list.


767
768
769
# File 'lib/cocoapods/target/pod_target.rb', line 767

def copy_dsyms_script_output_files_path
  support_files_dir + "#{label}-copy-dsyms-output-files.xcfilelist"
end

#copy_dsyms_script_pathPathname

Returns The absolute path of the copy dSYMs script.

Returns:

  • (Pathname)

    The absolute path of the copy dSYMs script.


755
756
757
# File 'lib/cocoapods/target/pod_target.rb', line 755

def copy_dsyms_script_path
  support_files_dir + "#{label}-copy-dsyms.sh"
end

#copy_resources_script_input_files_path_for_spec(spec) ⇒ Pathname

Returns The absolute path of the copy resources script input file list for the given spec.

Parameters:

  • spec (Specification)

    The spec this copy resources script path is for.

Returns:

  • (Pathname)

    The absolute path of the copy resources script input file list for the given spec.


656
657
658
# File 'lib/cocoapods/target/pod_target.rb', line 656

def copy_resources_script_input_files_path_for_spec(spec)
  support_files_dir + "#{non_library_spec_label(spec)}-resources-input-files.xcfilelist"
end

#copy_resources_script_output_files_path_for_spec(spec) ⇒ Pathname

Returns The absolute path of the copy resources script output file list for the given spec.

Parameters:

  • spec (Specification)

    The spec this copy resources script path is for.

Returns:

  • (Pathname)

    The absolute path of the copy resources script output file list for the given spec.


665
666
667
# File 'lib/cocoapods/target/pod_target.rb', line 665

def copy_resources_script_output_files_path_for_spec(spec)
  support_files_dir + "#{non_library_spec_label(spec)}-resources-output-files.xcfilelist"
end

#copy_resources_script_path_for_spec(spec) ⇒ Pathname

Returns The absolute path of the copy resources script for the given spec.

Parameters:

  • spec (Specification)

    The spec this copy resources script path is for.

Returns:

  • (Pathname)

    The absolute path of the copy resources script for the given spec.


647
648
649
# File 'lib/cocoapods/target/pod_target.rb', line 647

def copy_resources_script_path_for_spec(spec)
  support_files_dir + "#{non_library_spec_label(spec)}-resources.sh"
end

#copy_xcframeworks_script_input_files_pathString

Returns The path of the copy xcframeworks input files file list.

Returns:

  • (String)

    The path of the copy xcframeworks input files file list


704
705
706
# File 'lib/cocoapods/target/pod_target.rb', line 704

def copy_xcframeworks_script_input_files_path
  support_files_dir + "#{label}-xcframeworks-input-files.xcfilelist"
end

#copy_xcframeworks_script_output_files_pathString

Returns The path of the copy xcframeworks output files file list.

Returns:

  • (String)

    The path of the copy xcframeworks output files file list


710
711
712
# File 'lib/cocoapods/target/pod_target.rb', line 710

def copy_xcframeworks_script_output_files_path
  support_files_dir + "#{label}-xcframeworks-output-files.xcfilelist"
end

#copy_xcframeworks_script_pathPathname

Returns The absolute path of the copy xcframeworks script.

Returns:

  • (Pathname)

    The absolute path of the copy xcframeworks script.


698
699
700
# File 'lib/cocoapods/target/pod_target.rb', line 698

def copy_xcframeworks_script_path
  support_files_dir + "#{label}-xcframeworks.sh"
end

#defines_module?Boolean

Note:

Static library targets can temporarily opt in to this behavior by setting `DEFINES_MODULE = YES` in their specification's `pod_target_xcconfig`.

Returns Whether the target defines a “module” (and thus will need a module map and umbrella header).

Returns:

  • (Boolean)

    Whether the target defines a “module” (and thus will need a module map and umbrella header).


338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/cocoapods/target/pod_target.rb', line 338

def defines_module?
  return @defines_module if defined?(@defines_module)
  return @defines_module = true if uses_swift? || build_as_framework?

  explicit_target_definitions = target_definitions.select { |td| td.dependencies.any? { |d| d.root_name == pod_name } }
  tds_by_answer = explicit_target_definitions.group_by { |td| td.build_pod_as_module?(pod_name) }

  if tds_by_answer.size > 1
    UI.warn "Unable to determine whether to build `#{label}` as a module due to a conflict " \
      "between the following target definitions:\n\t- #{tds_by_answer.map do |a, td|
                                                          "`#{td.to_sentence}` #{a ? "requires `#{label}` as a module" : "does not require `#{label}` as a module"}"
                                                        end.join("\n\t- ")}\n\n" \
      "Defaulting to skip building `#{label}` as a module."
  elsif tds_by_answer.keys.first == true || target_definitions.all? { |td| td.build_pod_as_module?(pod_name) }
    return @defines_module = true
  end

  @defines_module = library_specs.any? { |s| s.consumer(platform).pod_target_xcconfig['DEFINES_MODULE'] == 'YES' }
end

#dependenciesArray<String>

Returns The names of the Pods on which this target depends.

Returns:

  • (Array<String>)

    The names of the Pods on which this target depends.


792
793
794
795
796
# File 'lib/cocoapods/target/pod_target.rb', line 792

def dependencies
  spec_consumers.flat_map do |consumer|
    consumer.dependencies.map { |dep| Specification.root_name(dep.name) }
  end.uniq
end

#dependent_targets_for_app_spec(app_spec, configuration: nil) ⇒ Array<PodTarget>

Returns the canonical list of dependent targets this target has a dependency upon. This list includes the target itself as well as its recursive dependent and app dependent targets.

Parameters:

  • app_spec (Specification)

    the app spec to scope dependencies for

  • configuration (String) (defaults to: nil)

    the configuration to retrieve the app dependent targets for.

Returns:

  • (Array<PodTarget>)

    the canonical list of dependent targets this target has a dependency upon. This list includes the target itself as well as its recursive dependent and app dependent targets.


920
921
922
# File 'lib/cocoapods/target/pod_target.rb', line 920

def dependent_targets_for_app_spec(app_spec, configuration: nil)
  [self, *recursive_dependent_targets(:configuration => configuration), *recursive_app_dependent_targets(app_spec, :configuration => configuration)].uniq
end

#dependent_targets_for_test_spec(test_spec, configuration: nil) ⇒ Array<PodTarget>

Returns the canonical list of dependent targets this target has a dependency upon. This list includes the target itself as well as its recursive dependent and test dependent targets.

Parameters:

  • test_spec (Specification)

    the test spec to scope dependencies for

  • configuration (String) (defaults to: nil)

    the configuration to retrieve the test dependent targets for.

Returns:

  • (Array<PodTarget>)

    the canonical list of dependent targets this target has a dependency upon. This list includes the target itself as well as its recursive dependent and test dependent targets.


873
874
875
# File 'lib/cocoapods/target/pod_target.rb', line 873

def dependent_targets_for_test_spec(test_spec, configuration: nil)
  [self, *recursive_dependent_targets(:configuration => configuration), *recursive_test_dependent_targets(test_spec, :configuration => configuration)].uniq
end

#deployment_target_for_non_library_spec(spec) ⇒ String

Returns The deployment target to use for the non library spec. If the non library spec explicitly specifies one then this is the one used otherwise the one that was determined by the analyzer is used.

Parameters:

  • spec (Specification)

    The non library spec to calculate the deployment target for.

Returns:

  • (String)

    The deployment target to use for the non library spec. If the non library spec explicitly specifies one then this is the one used otherwise the one that was determined by the analyzer is used.

Raises:

  • (ArgumentError)

468
469
470
471
# File 'lib/cocoapods/target/pod_target.rb', line 468

def deployment_target_for_non_library_spec(spec)
  raise ArgumentError, 'Must be a non library spec.' unless spec.non_library_specification?
  spec.deployment_target(platform.name.to_s) || platform.deployment_target.to_s
end

#embed_frameworks_script_input_files_path_for_spec(spec) ⇒ Pathname

Returns The absolute path of the embed frameworks script input file list for the given spec.

Parameters:

  • spec (Specification)

    The spec this embed frameworks script path is for.

Returns:

  • (Pathname)

    The absolute path of the embed frameworks script input file list for the given spec.


683
684
685
# File 'lib/cocoapods/target/pod_target.rb', line 683

def embed_frameworks_script_input_files_path_for_spec(spec)
  support_files_dir + "#{non_library_spec_label(spec)}-frameworks-input-files.xcfilelist"
end

#embed_frameworks_script_output_files_path_for_spec(spec) ⇒ Pathname

Returns The absolute path of the embed frameworks script output file list for the given spec.

Parameters:

  • spec (Specification)

    The spec this embed frameworks script path is for.

Returns:

  • (Pathname)

    The absolute path of the embed frameworks script output file list for the given spec.


692
693
694
# File 'lib/cocoapods/target/pod_target.rb', line 692

def embed_frameworks_script_output_files_path_for_spec(spec)
  support_files_dir + "#{non_library_spec_label(spec)}-frameworks-output-files.xcfilelist"
end

#embed_frameworks_script_path_for_spec(spec) ⇒ Pathname

Returns The absolute path of the embed frameworks script for the given spec.

Parameters:

  • spec (Specification)

    The spec this embed frameworks script path is for.

Returns:

  • (Pathname)

    The absolute path of the embed frameworks script for the given spec.


674
675
676
# File 'lib/cocoapods/target/pod_target.rb', line 674

def embed_frameworks_script_path_for_spec(spec)
  support_files_dir + "#{non_library_spec_label(spec)}-frameworks.sh"
end

#framework_pathsHash{String=>Array<Xcode::FrameworkPaths>}

Returns The vendored and non vendored framework paths this target depends upon keyed by spec name. For the root spec and subspecs the framework path of the target itself is included.

Returns:

  • (Hash{String=>Array<Xcode::FrameworkPaths>})

    The vendored and non vendored framework paths this target depends upon keyed by spec name. For the root spec and subspecs the framework path of the target itself is included.


386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/cocoapods/target/pod_target.rb', line 386

def framework_paths
  @framework_paths ||= begin
    file_accessors.each_with_object({}) do |file_accessor, hash|
      frameworks = file_accessor.vendored_dynamic_artifacts.map do |framework_path|
        relative_path_to_sandbox = framework_path.relative_path_from(sandbox.root)
        framework_source = "${PODS_ROOT}/#{relative_path_to_sandbox}"
        # Until this can be configured, assume the dSYM file uses the file name as the framework.
        # See https://github.com/CocoaPods/CocoaPods/issues/1698
        dsym_name = "#{framework_path.basename}.dSYM"
        dsym_path = Pathname.new("#{framework_path.dirname}/#{dsym_name}")
        dsym_source = if dsym_path.exist?
                        "${PODS_ROOT}/#{relative_path_to_sandbox}.dSYM"
                      end
        dirname = framework_path.dirname
        bcsymbolmap_paths = if dirname.exist?
                              Dir.chdir(dirname) do
                                Dir.glob('*.bcsymbolmap').map do |bcsymbolmap_file_name|
                                  bcsymbolmap_path = dirname + bcsymbolmap_file_name
                                  "${PODS_ROOT}/#{bcsymbolmap_path.relative_path_from(sandbox.root)}"
                                end
                              end
                            end
        Xcode::FrameworkPaths.new(framework_source, dsym_source, bcsymbolmap_paths)
      end
      if file_accessor.spec.library_specification? && should_build? && build_as_dynamic_framework?
        frameworks << Xcode::FrameworkPaths.new(build_product_path('${BUILT_PRODUCTS_DIR}'))
      end
      hash[file_accessor.spec.name] = frameworks
    end
  end
end

#header_mappings_by_file_accessorHash{FileAccessor => Hash}

Returns Hash of file accessors by header mappings.

Returns:

  • (Hash{FileAccessor => Hash})

    Hash of file accessors by header mappings.


220
221
222
223
224
225
226
227
# File 'lib/cocoapods/target/pod_target.rb', line 220

def header_mappings_by_file_accessor
  valid_accessors = file_accessors.reject { |fa| fa.spec.non_library_specification? }
  Hash[valid_accessors.map do |file_accessor|
    # Private headers will always end up in Pods/Headers/Private/PodA/*.h
    # This will allow for `""` imports to work.
    [file_accessor, header_mappings(file_accessor, file_accessor.headers)]
  end]
end

#header_search_paths(include_dependent_targets_for_test_spec: nil, include_dependent_targets_for_app_spec: nil, include_private_headers: true, configuration: nil) ⇒ Array<String>

Returns The set of header search paths this target uses.

Parameters:

  • include_dependent_targets_for_test_spec (Boolean) (defaults to: nil)

    whether to include header search paths for test dependent targets

  • include_dependent_targets_for_app_spec (Boolean) (defaults to: nil)

    whether to include header search paths for app dependent targets

  • include_private_headers (Boolean) (defaults to: true)

    whether to include header search paths for private headers of this target

  • configuration (String) (defaults to: nil)

    the configuration to return header search paths for or `nil` for all configurations.

Returns:

  • (Array<String>)

    The set of header search paths this target uses.


998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
# File 'lib/cocoapods/target/pod_target.rb', line 998

def header_search_paths(include_dependent_targets_for_test_spec: nil, include_dependent_targets_for_app_spec: nil,
                        include_private_headers: true, configuration: nil)
  header_search_paths = []
  header_search_paths.concat(build_headers.search_paths(platform, nil, false)) if include_private_headers
  header_search_paths.concat(sandbox.public_headers.search_paths(platform, pod_name, uses_modular_headers?))
  dependent_targets = recursive_dependent_targets(:configuration => configuration)
  if include_dependent_targets_for_test_spec
    dependent_targets += recursive_test_dependent_targets(include_dependent_targets_for_test_spec, :configuration => configuration)
  end
  if include_dependent_targets_for_app_spec
    dependent_targets += recursive_app_dependent_targets(include_dependent_targets_for_app_spec, :configuration => configuration)
  end
  dependent_targets.uniq.each do |dependent_target|
    header_search_paths.concat(sandbox.public_headers.search_paths(platform, dependent_target.pod_name, defines_module? && dependent_target.uses_modular_headers?(false)))
  end
  header_search_paths.uniq
end

#headers_sandboxPathname

Returns the pathname for headers in the sandbox.

Returns:

  • (Pathname)

    the pathname for headers in the sandbox.


214
215
216
# File 'lib/cocoapods/target/pod_target.rb', line 214

def headers_sandbox
  Pathname.new(pod_name)
end

#info_plist_entriesHash

Returns the additional entries to add to the generated Info.plist.

Returns:

  • (Hash)

    the additional entries to add to the generated Info.plist


546
547
548
# File 'lib/cocoapods/target/pod_target.rb', line 546

def info_plist_entries
  root_spec.info_plist
end

#info_plist_path_for_spec(spec) ⇒ Pathname

Returns The absolute path of the Info.plist for the given spec.

Parameters:

Returns:

  • (Pathname)

    The absolute path of the Info.plist for the given spec.


776
777
778
# File 'lib/cocoapods/target/pod_target.rb', line 776

def info_plist_path_for_spec(spec)
  support_files_dir + "#{non_library_spec_label(spec)}-Info.plist"
end

#inhibit_warnings?Bool

Checks if warnings should be inhibited for this pod.

Returns:

  • (Bool)

928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
# File 'lib/cocoapods/target/pod_target.rb', line 928

def inhibit_warnings?
  return @inhibit_warnings if defined? @inhibit_warnings
  whitelists = target_definitions.map do |target_definition|
    target_definition.inhibits_warnings_for_pod?(root_spec.name)
  end.uniq

  if whitelists.empty?
    @inhibit_warnings = false
    false
  elsif whitelists.count == 1
    @inhibit_warnings = whitelists.first
    whitelists.first
  else
    UI.warn "The pod `#{pod_name}` is linked to different targets " \
      "(#{target_definitions.map { |td| "`#{td.name}`" }.to_sentence}), which contain different " \
      'settings to inhibit warnings. CocoaPods does not currently ' \
      'support different settings and will fall back to your preference ' \
      'set in the root target definition.'
    @inhibit_warnings = podfile.root_target_definitions.first.inhibits_warnings_for_pod?(root_spec.name)
  end
end

#labelString

Returns the label for the target.

Returns:

  • (String)

    the label for the target.


198
199
200
201
202
203
204
# File 'lib/cocoapods/target/pod_target.rb', line 198

def label
  if scope_suffix.nil? || scope_suffix[0] == '.'
    "#{root_spec.name}#{scope_suffix}"
  else
    "#{root_spec.name}-#{scope_suffix}"
  end
end

#label_for_test_type(test_type) ⇒ String

Returns the label to use for the given test type. This is used to generate native target names for test specs.

Parameters:

  • test_type (Symbol)

    The test type to map to provided by the test specification DSL.

Returns:

  • (String)

    The native product type to use.


501
502
503
504
505
506
507
508
509
510
# File 'lib/cocoapods/target/pod_target.rb', line 501

def label_for_test_type(test_type)
  case test_type
  when :unit
    'Unit'
  when :ui
    'UI'
  else
    raise ArgumentError, "Unknown test type `#{test_type}`."
  end
end

#module_map_pathPathname

Returns the absolute path of the LLVM module map file that defines the module structure for the compiler.

Returns:

  • (Pathname)

    the absolute path of the LLVM module map file that defines the module structure for the compiler.


527
528
529
530
531
532
533
534
535
536
# File 'lib/cocoapods/target/pod_target.rb', line 527

def module_map_path
  basename = "#{label}.modulemap"
  if build_as_framework?
    super
  elsif file_accessors.any?(&:module_map)
    build_headers.root + product_module_name + basename
  else
    sandbox.public_headers.root + product_module_name + basename
  end
end

#non_library_spec_label(spec) ⇒ Object


622
623
624
625
626
627
628
# File 'lib/cocoapods/target/pod_target.rb', line 622

def non_library_spec_label(spec)
  case spec.spec_type
  when :test then test_target_label(spec)
  when :app then app_target_label(spec)
  else raise ArgumentError, "Unhandled spec type #{spec.spec_type.inspect} for #{spec.inspect}"
  end
end

#pod_nameString

Returns The name of the Pod that this target refers to.

Returns:

  • (String)

    The name of the Pod that this target refers to.


520
521
522
# File 'lib/cocoapods/target/pod_target.rb', line 520

def pod_name
  root_spec.name
end

#pod_target_srcrootString

Returns The source path of the root for this target relative to `$(PODS_ROOT)`.

Returns:

  • (String)

    The source path of the root for this target relative to `$(PODS_ROOT)`


972
973
974
# File 'lib/cocoapods/target/pod_target.rb', line 972

def pod_target_srcroot
  "${PODS_ROOT}/#{sandbox.pod_dir(pod_name).relative_path_from(sandbox.root)}"
end

#podfilePodfile

Returns The podfile which declares the dependency.

Returns:

  • (Podfile)

    The podfile which declares the dependency.


249
250
251
# File 'lib/cocoapods/target/pod_target.rb', line 249

def podfile
  target_definitions.first.podfile
end

#prefix_header_pathPathname

Returns the absolute path of the prefix header file.

Returns:

  • (Pathname)

    the absolute path of the prefix header file.


540
541
542
# File 'lib/cocoapods/target/pod_target.rb', line 540

def prefix_header_path
  support_files_dir + "#{label}-prefix.pch"
end

#prefix_header_path_for_spec(spec) ⇒ Pathname

Returns the absolute path of the prefix header file for the given spec.

Parameters:

  • spec (Specification)

    The spec this prefix header path is for.

Returns:

  • (Pathname)

    the absolute path of the prefix header file for the given spec.


785
786
787
# File 'lib/cocoapods/target/pod_target.rb', line 785

def prefix_header_path_for_spec(spec)
  support_files_dir + "#{non_library_spec_label(spec)}-prefix.pch"
end

#prepare_artifacts_script_input_files_path_for_spec(spec) ⇒ Pathname

Deprecated.
TODO:

Remove in 2.0

Returns The absolute path of the prepare artifacts script input file list for the given spec.

Parameters:

Returns:

  • (Pathname)

    The absolute path of the prepare artifacts script input file list for the given spec.


736
737
738
# File 'lib/cocoapods/target/pod_target.rb', line 736

def prepare_artifacts_script_input_files_path_for_spec(spec)
  support_files_dir + "#{non_library_spec_label(spec)}-artifacts-input-files.xcfilelist"
end

#prepare_artifacts_script_output_files_path_for_spec(spec) ⇒ Pathname

Deprecated.
TODO:

Remove in 2.0

Returns The absolute path of the prepare artifacts script output file list for the given spec.

Parameters:

Returns:

  • (Pathname)

    The absolute path of the prepare artifacts script output file list for the given spec.


749
750
751
# File 'lib/cocoapods/target/pod_target.rb', line 749

def prepare_artifacts_script_output_files_path_for_spec(spec)
  support_files_dir + "#{non_library_spec_label(spec)}-artifacts-output-files.xcfilelist"
end

#prepare_artifacts_script_path_for_spec(spec) ⇒ Pathname

Deprecated.
TODO:

Remove in 2.0

Returns The absolute path of the prepare artifacts script for the given spec.

Parameters:

Returns:

  • (Pathname)

    The absolute path of the prepare artifacts script for the given spec.


723
724
725
# File 'lib/cocoapods/target/pod_target.rb', line 723

def prepare_artifacts_script_path_for_spec(spec)
  support_files_dir + "#{non_library_spec_label(spec)}-artifacts.sh"
end

#product_module_nameString

Returns The name to use for the source code module constructed for this target, and which will be used to import the module in implementation source files.

Returns:

  • (String)

    The name to use for the source code module constructed for this target, and which will be used to import the module in implementation source files.


267
268
269
# File 'lib/cocoapods/target/pod_target.rb', line 267

def product_module_name
  root_spec.module_name
end

#product_type_for_test_type(test_type) ⇒ Symbol

Returns the corresponding native product type to use given the test type. This is primarily used when creating the native targets in order to produce the correct test bundle target based on the type of tests included.

Parameters:

  • test_type (Symbol)

    The test type to map to provided by the test specification DSL.

Returns:

  • (Symbol)

    The native product type to use.


482
483
484
485
486
487
488
489
490
491
# File 'lib/cocoapods/target/pod_target.rb', line 482

def product_type_for_test_type(test_type)
  case test_type
  when :unit
    :unit_test_bundle
  when :ui
    :ui_test_bundle
  else
    raise ArgumentError, "Unknown test type `#{test_type}`."
  end
end

#project_nameString

Note:

The name is guaranteed to be the same across all target definitions and is validated by the target validator during installation.

Returns the project name derived from the target definitions that integrate this pod. If none is specified then the name of the pod is used by default.

Returns:

  • (String)

    the project name derived from the target definitions that integrate this pod. If none is specified then the name of the pod is used by default.


259
260
261
# File 'lib/cocoapods/target/pod_target.rb', line 259

def project_name
  target_definitions.map { |td| td.project_name_for_pod(pod_name) }.compact.first || pod_name
end

#public_header_mappings_by_file_accessorHash{FileAccessor => Hash}

Returns Hash of file accessors by public header mappings.

Returns:

  • (Hash{FileAccessor => Hash})

    Hash of file accessors by public header mappings.


231
232
233
234
235
236
237
238
# File 'lib/cocoapods/target/pod_target.rb', line 231

def public_header_mappings_by_file_accessor
  valid_accessors = file_accessors.reject { |fa| fa.spec.non_library_specification? }
  Hash[valid_accessors.map do |file_accessor|
    # Public headers on the other hand will be added in Pods/Headers/Public/PodA/PodA/*.h
    # The extra folder is intentional in order for `<>` imports to work.
    [file_accessor, header_mappings(file_accessor, file_accessor.public_headers)]
  end]
end

#recursive_app_dependent_targets(app_spec, configuration: nil) ⇒ Array<PodTarget>

Returns the recursive targets that this target has a app dependency upon.

Parameters:

  • app_spec (Specification)

    the app spec to scope dependencies for

  • configuration (String) (defaults to: nil)

    the configuration to retrieve the app dependent targets for.

Returns:

  • (Array<PodTarget>)

    the recursive targets that this target has a app dependency upon.


886
887
888
889
890
891
892
893
894
895
896
# File 'lib/cocoapods/target/pod_target.rb', line 886

def recursive_app_dependent_targets(app_spec, configuration: nil)
  @recursive_app_dependent_targets ||= {}
  @recursive_app_dependent_targets[app_spec] ||= begin
    hash = Hash[config_variants.map do |config|
      [config, _add_recursive_app_dependent_targets(app_spec, Set.new, :configuration => config).to_a.freeze]
    end]
    hash[nil] = hash.each_value.reduce(Set.new, &:|).to_a.freeze
    hash
  end
  @recursive_app_dependent_targets[app_spec][configuration]
end

#recursive_dependent_targets(configuration: nil) ⇒ Array<PodTarget>

Returns all dependent targets of this target. If a configuration is passed then the list can be scoped to a given configuration.

Parameters:

  • configuration (String) (defaults to: nil)

    The configuration to return the dependent targets for or `nil` if all configurations should be included.

Returns:

  • (Array<PodTarget>)

    the recursive targets that this target has a dependency upon.


806
807
808
809
810
811
812
813
814
815
# File 'lib/cocoapods/target/pod_target.rb', line 806

def recursive_dependent_targets(configuration: nil)
  @recursive_dependent_targets ||= begin
    hash = Hash[config_variants.map do |config|
      [config, _add_recursive_dependent_targets(Set.new, :configuration => config).delete(self).to_a.freeze]
    end]
    hash[nil] = hash.each_value.reduce(Set.new, &:|).to_a
    hash
  end
  @recursive_dependent_targets.fetch(configuration) { raise ArgumentError, "No configuration #{configuration} for #{self}, known configurations are #{@recursive_dependent_targets.keys}" }
end

#recursive_test_dependent_targets(test_spec, configuration: nil) ⇒ Array<PodTarget>

Returns the recursive targets that this target has a test dependency upon.

Parameters:

  • test_spec (Specification)

    the test spec to scope dependencies for

  • configuration (String) (defaults to: nil)

    the configuration to retrieve the test dependent targets for.

Returns:

  • (Array<PodTarget>)

    the recursive targets that this target has a test dependency upon.


839
840
841
842
843
844
845
846
847
848
849
# File 'lib/cocoapods/target/pod_target.rb', line 839

def recursive_test_dependent_targets(test_spec, configuration: nil)
  @recursive_test_dependent_targets ||= {}
  @recursive_test_dependent_targets[test_spec] ||= begin
    hash = Hash[config_variants.map do |config|
      [config, _add_recursive_test_dependent_targets(test_spec, Set.new, :configuration => config).to_a.freeze]
    end]
    hash[nil] = hash.each_value.reduce(Set.new, &:|).to_a.freeze
    hash
  end
  @recursive_test_dependent_targets[test_spec][configuration]
end

#resource_pathsHash{String=>Array<String>}

Returns The resource and resource bundle paths this target depends upon keyed by spec name. Resource (not resource bundles) paths can vary depending on the type of spec:

- App specs _always_ get their resource paths added to "Copy Bundle Resources" phase from
  [PodTargetInstaller] therefore their resource paths are never included here.
- Test specs may have their resource paths added to "Copy Bundle Resources" if the target itself is
  built as a framework, which is again checked and handled by PodTargetInstaller. If that is true then
  the resource paths are not included, otherwise they are included and handled via the CocoaPods copy
  resources script phase.
- Library specs _do not_ have per-configuration CocoaPods copy resources script phase and their resource
  paths will be added to "Copy Bundle Resources" phase if the target is built as a framework because
  it supports it. We always include the resource paths for library specs because they are also
  integrated to the user target.

Returns:

  • (Hash{String=>Array<String>})

    The resource and resource bundle paths this target depends upon keyed by spec name. Resource (not resource bundles) paths can vary depending on the type of spec:

    - App specs _always_ get their resource paths added to "Copy Bundle Resources" phase from
      [PodTargetInstaller] therefore their resource paths are never included here.
    - Test specs may have their resource paths added to "Copy Bundle Resources" if the target itself is
      built as a framework, which is again checked and handled by PodTargetInstaller. If that is true then
      the resource paths are not included, otherwise they are included and handled via the CocoaPods copy
      resources script phase.
    - Library specs _do not_ have per-configuration CocoaPods copy resources script phase and their resource
      paths will be added to "Copy Bundle Resources" phase if the target is built as a framework because
      it supports it. We always include the resource paths for library specs because they are also
      integrated to the user target.
    

445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# File 'lib/cocoapods/target/pod_target.rb', line 445

def resource_paths
  @resource_paths ||= begin
    file_accessors.each_with_object({}) do |file_accessor, hash|
      resource_paths = if file_accessor.spec.app_specification? || (file_accessor.spec.test_specification? && build_as_framework?)
                         []
                       else
                         file_accessor.resources.map do |res|
                           "${PODS_ROOT}/#{res.relative_path_from(sandbox.project_path.dirname)}"
                         end
                       end
      prefix = Pod::Target::BuildSettings::CONFIGURATION_BUILD_DIR_VARIABLE
      prefix = configuration_build_dir unless file_accessor.spec.test_specification?
      resource_bundle_paths = file_accessor.resource_bundles.keys.map { |name| "#{prefix}/#{name.shellescape}.bundle" }
      hash[file_accessor.spec.name] = resource_paths + resource_bundle_paths
    end
  end
end

#resources_bundle_target_label(bundle_name) ⇒ String

Returns The derived name of the resource bundle target.

Parameters:

  • bundle_name (String)

    The name of the bundle product, which is given by the spec.

Returns:

  • (String)

    The derived name of the resource bundle target.


555
556
557
# File 'lib/cocoapods/target/pod_target.rb', line 555

def resources_bundle_target_label(bundle_name)
  "#{label}-#{bundle_name}"
end

#root_specSpecification

Returns The root specification for the target.

Returns:


514
515
516
# File 'lib/cocoapods/target/pod_target.rb', line 514

def root_spec
  specs.first.root
end

#scheme_for_spec(spec) ⇒ Hash

Returns The scheme configuration used or empty if none is specified.

Parameters:

  • spec (Specification)

    The spec to return scheme configuration for.

Returns:

  • (Hash)

    The scheme configuration used or empty if none is specified.


635
636
637
638
639
640
# File 'lib/cocoapods/target/pod_target.rb', line 635

def scheme_for_spec(spec)
  return {} if (spec.library_specification? && !spec.root?) || spec.available_platforms.none? do |p|
    p.name == platform.name
  end
  spec.consumer(platform).scheme
end

#scoped(cache = {}) ⇒ Array<PodTarget>

Scopes the current target based on the existing pod targets within the cache.

Parameters:

  • cache (Hash{Array => PodTarget}) (defaults to: {})

    the cached target for a previously scoped target.

Returns:

  • (Array<PodTarget>)

    a scoped copy for each target definition.


169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/cocoapods/target/pod_target.rb', line 169

def scoped(cache = {})
  target_definitions.map do |target_definition|
    cache_key = [specs, target_definition]
    cache[cache_key] ||= begin
      target = PodTarget.new(sandbox, build_type, user_build_configurations, archs, platform, specs,
                             [target_definition], file_accessors, target_definition.label, swift_version)
      scope_dependent_targets = ->(dependent_targets) do
        dependent_targets.flat_map do |pod_target|
          pod_target.scoped(cache).select { |pt| pt.target_definitions == [target_definition] }
        end
      end

      target.dependent_targets_by_config = Hash[dependent_targets_by_config.map { |k, v| [k, scope_dependent_targets[v]] }]
      target.test_dependent_targets_by_spec_name_by_config = Hash[test_dependent_targets_by_spec_name_by_config.map do |spec_name, test_pod_targets_by_config|
        [spec_name, Hash[test_pod_targets_by_config.map { |k, v| [k, scope_dependent_targets[v]] }]]
      end]
      target.app_dependent_targets_by_spec_name_by_config = Hash[app_dependent_targets_by_spec_name_by_config.map do |spec_name, app_pod_targets_by_config|
        [spec_name, Hash[app_pod_targets_by_config.map { |k, v| [k, scope_dependent_targets[v]] }]]
      end]
      target.test_app_hosts_by_spec = Hash[test_app_hosts_by_spec.map do |spec, (app_host_spec, app_pod_target)|
        [spec, [app_host_spec, app_pod_target.scoped(cache).find { |pt| pt.target_definitions == [target_definition] }]]
      end]
      target
    end
  end
end

#script_phasesArray<Hash{Symbol=>String}>

Returns An array of hashes where each hash represents a single script phase.

Returns:

  • (Array<Hash{Symbol=>String}>)

    An array of hashes where each hash represents a single script phase.


360
361
362
# File 'lib/cocoapods/target/pod_target.rb', line 360

def script_phases
  spec_consumers.flat_map(&:script_phases)
end

#should_build?Bool

A target should not be built if it has no source files.

Returns:

  • (Bool)

    Whether or not this target should be built.


275
276
277
278
279
280
281
# File 'lib/cocoapods/target/pod_target.rb', line 275

def should_build?
  return @should_build if defined? @should_build
  accessors = file_accessors.select { |fa| fa.spec.library_specification? }
  source_files = accessors.flat_map(&:source_files)
  source_files -= accessors.flat_map(&:headers)
  @should_build = !source_files.empty?
end

#spec_consumersArray<Specification::Consumer>

Returns the specification consumers for the target.

Returns:

  • (Array<Specification::Consumer>)

    the specification consumers for the target.


286
287
288
# File 'lib/cocoapods/target/pod_target.rb', line 286

def spec_consumers
  specs.map { |spec| spec.consumer(platform) }
end

#spec_swift_versionsArray<Version>

Returns the Swift versions supported. Might be empty if the author has not specified any versions, most likely due to legacy reasons.

Returns:

  • (Array<Version>)

    the Swift versions supported. Might be empty if the author has not specified any versions, most likely due to legacy reasons.


243
244
245
# File 'lib/cocoapods/target/pod_target.rb', line 243

def spec_swift_versions
  root_spec.swift_versions
end

#subspec_label(subspec) ⇒ String

Returns The derived name of the target.

Parameters:

  • subspec (Specification)

    The subspec to use for producing the label.

Returns:

  • (String)

    The derived name of the target.

Raises:

  • (ArgumentError)

564
565
566
567
# File 'lib/cocoapods/target/pod_target.rb', line 564

def subspec_label(subspec)
  raise ArgumentError, 'Must not be a root spec' if subspec.root?
  subspec.name.split('/')[1..-1].join('-').to_s
end

#test_app_hosts_by_spec_nameHash{String => (Specification,PodTarget)}

Deprecated.

Use `test_app_hosts_by_spec` instead.

TODO:

Remove in 2.0

Returns tuples of app specs and pod targets by test spec name.

Returns:


1137
1138
1139
1140
1141
# File 'lib/cocoapods/target/pod_target.rb', line 1137

def test_app_hosts_by_spec_name
  Hash[test_app_hosts_by_spec.map do |spec, value|
    [spec.name, value]
  end]
end

#test_spec_consumersArray<Specification::Consumer>

Returns the test specification consumers for the target.

Returns:

  • (Array<Specification::Consumer>)

    the test specification consumers for the target.


293
294
295
# File 'lib/cocoapods/target/pod_target.rb', line 293

def test_spec_consumers
  test_specs.map { |test_spec| test_spec.consumer(platform) }
end

#test_target_label(test_spec) ⇒ String

Returns The derived name of the test target.

Parameters:

  • test_spec (Specification)

    The test spec to use for producing the test label.

Returns:

  • (String)

    The derived name of the test target.


574
575
576
# File 'lib/cocoapods/target/pod_target.rb', line 574

def test_target_label(test_spec)
  "#{label}-#{label_for_test_type(test_spec.test_type)}-#{subspec_label(test_spec)}"
end

#user_config_names_by_config_typeObject


1036
1037
1038
1039
1040
1041
# File 'lib/cocoapods/target/pod_target.rb', line 1036

def user_config_names_by_config_type
  user_build_configurations.each_with_object({}) do |(user, type), hash|
    hash[type] ||= []
    hash[type] << user
  end.each_value(&:freeze).freeze
end

#uses_swift?Boolean

Returns Whether the target uses Swift code. This excludes source files from non library specs.

Returns:

  • (Boolean)

    Whether the target uses Swift code. This excludes source files from non library specs.


306
307
308
309
310
311
312
313
# File 'lib/cocoapods/target/pod_target.rb', line 306

def uses_swift?
  return @uses_swift if defined? @uses_swift
  @uses_swift = begin
    file_accessors.select { |a| a.spec.library_specification? }.any? do |file_accessor|
      uses_swift_for_spec?(file_accessor.spec)
    end
  end
end

#uses_swift_for_spec?(spec) ⇒ Boolean

Checks whether a specification uses Swift or not.

Parameters:

Returns:

  • (Boolean)

    Whether the target uses Swift code within the requested non library spec.


322
323
324
325
326
327
328
329
330
# File 'lib/cocoapods/target/pod_target.rb', line 322

def uses_swift_for_spec?(spec)
  @uses_swift_for_spec_cache ||= {}
  return @uses_swift_for_spec_cache[spec.name] if @uses_swift_for_spec_cache.key?(spec.name)
  @uses_swift_for_spec_cache[spec.name] = begin
    file_accessor = file_accessors.find { |fa| fa.spec == spec }
    raise "[Bug] Unable to find file accessor for spec `#{spec.inspect}` in pod target `#{label}`" unless file_accessor
    file_accessor.source_files.any? { |sf| sf.extname == '.swift' }
  end
end

#versionString

Returns The version associated with this target.

Returns:

  • (String)

    The version associated with this target


978
979
980
981
# File 'lib/cocoapods/target/pod_target.rb', line 978

def version
  version = root_spec.version
  [version.major, version.minor, version.patch].join('.')
end

#xcframeworksHash{String=>Array<Xcode::XCFramework>}

Returns The vendored xcframeworks this target depends upon keyed by spec name.

Returns:

  • (Hash{String=>Array<Xcode::XCFramework>})

    The vendored xcframeworks this target depends upon keyed by spec name.


421
422
423
424
425
426
427
428
429
430
# File 'lib/cocoapods/target/pod_target.rb', line 421

def xcframeworks
  @xcframeworks ||= begin
    file_accessors.each_with_object({}) do |file_accessor, hash|
      frameworks = file_accessor.vendored_xcframeworks.map do |framework_path|
        Xcode::XCFramework.new(framework_path)
      end
      hash[file_accessor.spec.name] = frameworks
    end
  end
end