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.

Constant Summary

Constants inherited from Target

Target::DEFAULT_VERSION

Instance Attribute Summary collapse

Attributes inherited from Target

#archs, #host_requires_frameworks, #native_target, #sandbox, #user_build_configurations

Instance Method Summary collapse

Methods inherited from Target

#bridge_support_path, #dummy_source_path, #framework_name, #info_plist_path, #inspect, #name, #product_basename, #product_name, #product_type, #requires_frameworks?, #static_framework?, #static_library_name, #support_files_dir, #umbrella_header_path, #xcconfig_path

Constructor Details

#initialize(specs, target_definitions, sandbox, scope_suffix = nil) ⇒ PodTarget

Returns a new instance of PodTarget

Parameters:

  • specs (Array<Specification>)

    @see #specs

  • target_definitions (Array<TargetDefinition>)

    @see #target_definitions

  • sandbox (Sandbox)

    @see #sandbox

  • scope_suffix (String) (defaults to: nil)

    @see #scope_suffix



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/cocoapods/target/pod_target.rb', line 46

def initialize(specs, target_definitions, sandbox, scope_suffix = nil)
  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 only abstract TargetDefinitions" if target_definitions.all?(&:abstract?)
  raise "Can't initialize a PodTarget with an empty string scope suffix!" if scope_suffix == ''
  super()
  @specs = specs.dup.freeze
  @test_specs, @non_test_specs = @specs.partition(&:test_specification?)
  @target_definitions = target_definitions
  @sandbox = sandbox
  @scope_suffix = scope_suffix
  @build_headers  = Sandbox::HeadersStore.new(sandbox, 'Private', :private)
  @file_accessors = []
  @resource_bundle_targets = []
  @test_resource_bundle_targets = []
  @test_native_targets = []
  @dependent_targets = []
  @test_dependent_targets = []
  @build_config_cache = {}
end

Instance Attribute Details

#build_headersHeadersStore (readonly)

Returns the header directory for the target.

Returns:

  • (HeadersStore)

    the header directory for the target.



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

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.



29
30
31
# File 'lib/cocoapods/target/pod_target.rb', line 29

def dependent_targets
  @dependent_targets
end

#file_accessorsArray<Sandbox::FileAccessor>

Returns the file accessors for the specifications of this target.

Returns:



156
157
158
# File 'lib/cocoapods/target/pod_target.rb', line 156

def file_accessors
  @file_accessors
end

#non_test_specsArray<Specification> (readonly)

Returns All of the specs within this target that are not test specs.

Returns:

  • (Array<Specification>)

    All of the specs within this target that are not test specs.



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

def non_test_specs
  @non_test_specs
end

#platformPlatform

Note:

The deployment target for the pod target is the maximum of all the deployment targets for the current platform of the target (or the minimum required to support the current installation strategy, if higher).

Returns the platform for this target.

Returns:

  • (Platform)

    the platform for this target.



120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/cocoapods/target/pod_target.rb', line 120

def platform
  @platform ||= begin
    platform_name = target_definitions.first.platform.name
    default = Podfile::TargetDefinition::PLATFORM_DEFAULTS[platform_name]
    deployment_target = specs.map do |spec|
      Version.new(spec.deployment_target(platform_name) || default)
    end.max
    if platform_name == :ios && requires_frameworks?
      minimum = Version.new('8.0')
      deployment_target = [deployment_target, minimum].max
    end
    Platform.new(platform_name, deployment_target)
  end
end

#resource_bundle_targetsArray<PBXNativeTarget> (readonly)

Returns the resource bundle targets belonging to this target.

Returns:

  • (Array<PBXNativeTarget>)

    the resource bundle targets belonging to this target.



160
161
162
# File 'lib/cocoapods/target/pod_target.rb', line 160

def resource_bundle_targets
  @resource_bundle_targets
end

#scope_suffixString (readonly)

Note:

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

Returns used as suffix in the label

Returns:

  • (String)

    used as suffix in the label



24
25
26
# File 'lib/cocoapods/target/pod_target.rb', line 24

def scope_suffix
  @scope_suffix
end

#specsArray<Specification> (readonly)

Returns the spec and subspecs for the target.

Returns:

  • (Array<Specification>)

    the spec and subspecs for the target.



8
9
10
# File 'lib/cocoapods/target/pod_target.rb', line 8

def specs
  @specs
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.



13
14
15
# File 'lib/cocoapods/target/pod_target.rb', line 13

def target_definitions
  @target_definitions
end

#test_dependent_targetsArray<PodTarget>

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

Returns:

  • (Array<PodTarget>)

    the targets that this target has a test dependency upon.



34
35
36
# File 'lib/cocoapods/target/pod_target.rb', line 34

def test_dependent_targets
  @test_dependent_targets
end

#test_native_targetsObject

return [Array<PBXNativeTarget>] the test target generated in the Pods project for

this library or `nil` if there is no test target created.


39
40
41
# File 'lib/cocoapods/target/pod_target.rb', line 39

def test_native_targets
  @test_native_targets
end

#test_resource_bundle_targetsArray<PBXNativeTarget> (readonly)

Returns the resource bundle test targets belonging to this target.

Returns:

  • (Array<PBXNativeTarget>)

    the resource bundle test targets belonging to this target.



164
165
166
# File 'lib/cocoapods/target/pod_target.rb', line 164

def test_resource_bundle_targets
  @test_resource_bundle_targets
end

#test_specsArray<Specification> (readonly)

Returns All of the test specs within this target.

Returns:

  • (Array<Specification>)

    All of the test specs within this target.



239
240
241
# File 'lib/cocoapods/target/pod_target.rb', line 239

def test_specs
  @test_specs
end

Instance Method Details

#all_dependent_targetsArray<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.

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.



509
510
511
# File 'lib/cocoapods/target/pod_target.rb', line 509

def all_dependent_targets
  [self, *recursive_dependent_targets, *recursive_test_dependent_targets].uniq
end

#app_host_label(test_type) ⇒ String

Returns The label of the app host label to use given the platform and test type.

Parameters:

  • test_type (Symbol)

    The test type to use for producing the test label.

Returns:

  • (String)

    The label of the app host label to use given the platform and test type.



417
418
419
# File 'lib/cocoapods/target/pod_target.rb', line 417

def app_host_label(test_type)
  "AppHost-#{Platform.string_name(platform.symbolic_name)}-#{test_type.capitalize}-Tests"
end

#build_product_path(dir = Generator::XCConfig::XCConfigHelper::CONFIGURATION_BUILD_DIR_VARIABLE) ⇒ String

Returns The absolute path to the build product

Parameters:

  • dir (String) (defaults to: Generator::XCConfig::XCConfigHelper::CONFIGURATION_BUILD_DIR_VARIABLE)

    @see #configuration_build_dir

Returns:

  • (String)

    The absolute path to the build product



586
587
588
# File 'lib/cocoapods/target/pod_target.rb', line 586

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

#configuration_build_dir(dir = Generator::XCConfig::XCConfigHelper::CONFIGURATION_BUILD_DIR_VARIABLE) ⇒ String

Returns The absolute path to the configuration build dir

Parameters:

  • dir (String) (defaults to: Generator::XCConfig::XCConfigHelper::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



577
578
579
# File 'lib/cocoapods/target/pod_target.rb', line 577

def configuration_build_dir(dir = Generator::XCConfig::XCConfigHelper::CONFIGURATION_BUILD_DIR_VARIABLE)
  "#{dir}/#{label}"
end

#contains_script_phases?Boolean

Returns Whether the target contains any script phases.

Returns:

  • (Boolean)

    Whether the target contains any script phases.



220
221
222
# File 'lib/cocoapods/target/pod_target.rb', line 220

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.



233
234
235
# File 'lib/cocoapods/target/pod_target.rb', line 233

def contains_test_specifications?
  !test_specs.empty?
end

#copy_resources_script_path_for_test_type(test_type) ⇒ Pathname

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

Parameters:

  • test_type (Symbol)

    The test type this embed frameworks script path is for.

Returns:

  • (Pathname)

    The absolute path of the copy resources script for the given test type.



426
427
428
# File 'lib/cocoapods/target/pod_target.rb', line 426

def copy_resources_script_path_for_test_type(test_type)
  support_files_dir + "#{test_target_label(test_type)}-resources.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).



204
205
206
207
208
209
210
# File 'lib/cocoapods/target/pod_target.rb', line 204

def defines_module?
  return @defines_module if defined?(@defines_module)
  return @defines_module = true if uses_swift? || requires_frameworks?
  return @defines_module = true if target_definitions.any? { |td| td.build_pod_as_module?(pod_name) }

  @defines_module = non_test_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.



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

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

#embed_frameworks_script_path_for_test_type(test_type) ⇒ Pathname

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

Parameters:

  • test_type (Symbol)

    The test type this embed frameworks script path is for.

Returns:

  • (Pathname)

    The absolute path of the embed frameworks script for the given test type.



435
436
437
# File 'lib/cocoapods/target/pod_target.rb', line 435

def embed_frameworks_script_path_for_test_type(test_type)
  support_files_dir + "#{test_target_label(test_type)}-frameworks.sh"
end

#framework_paths(include_test_spec_paths = true) ⇒ Array<Hash{Symbol => [String]}>

Returns the framework paths associated with this target. By default all paths include the framework paths that are part of test specifications.

Parameters:

  • include_test_spec_paths (Boolean) (defaults to: true)

    Whether to include framework paths from test specifications or not.

Returns:

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

    The vendored and non vendored framework paths this target depends upon.



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/cocoapods/target/pod_target.rb', line 260

def framework_paths(include_test_spec_paths = true)
  @framework_paths ||= {}
  return @framework_paths[include_test_spec_paths] if @framework_paths.key?(include_test_spec_paths)
  @framework_paths[include_test_spec_paths] = begin
    accessors = file_accessors
    accessors = accessors.reject { |a| a.spec.test_specification? } unless include_test_spec_paths
    frameworks = []
    accessors.flat_map(&:vendored_dynamic_artifacts).map do |framework_path|
      relative_path_to_sandbox = framework_path.relative_path_from(sandbox.root)
      framework = { :name => framework_path.basename.to_s,
                    :input_path => "${PODS_ROOT}/#{relative_path_to_sandbox}",
                    :output_path => "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/#{framework_path.basename}" }
      # 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}")
      if dsym_path.exist?
        framework[:dsym_name] = dsym_name
        framework[:dsym_input_path] = "${PODS_ROOT}/#{relative_path_to_sandbox}.dSYM"
        framework[:dsym_output_path] = "${DWARF_DSYM_FOLDER_PATH}/#{dsym_name}"
      end
      frameworks << framework
    end
    if should_build? && requires_frameworks? && !static_framework?
      frameworks << { :name => product_name,
                      :input_path => build_product_path('${BUILT_PRODUCTS_DIR}'),
                      :output_path => "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/#{product_name}" }
    end
    frameworks
  end
end

#header_search_paths(include_test_dependent_targets = false) ⇒ Array<String>

Returns The set of header search paths this target uses.

Parameters:

  • include_test_dependent_targets (Boolean) (defaults to: false)

    whether to include header search paths for test dependent targets

Returns:

  • (Array<String>)

    The set of header search paths this target uses.



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

def header_search_paths(include_test_dependent_targets = false)
  header_search_paths = []
  header_search_paths.concat(build_headers.search_paths(platform, nil, false))
  header_search_paths.concat(sandbox.public_headers.search_paths(platform, pod_name, uses_modular_headers?))
  dependent_targets = recursive_dependent_targets
  dependent_targets += recursive_test_dependent_targets if include_test_dependent_targets
  dependent_targets.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

#include_in_build_config?(target_definition, configuration_name) ⇒ Boolean

Checks if the target should be included in the build configuration with the given name of a given target definition.

Parameters:

  • target_definition (TargetDefinition)

    The target definition to check.

  • configuration_name (String)

    The name of the build configuration.

Returns:

  • (Boolean)


522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
# File 'lib/cocoapods/target/pod_target.rb', line 522

def include_in_build_config?(target_definition, configuration_name)
  key = [target_definition.label, configuration_name]
  if @build_config_cache.key?(key)
    return @build_config_cache[key]
  end

  whitelists = target_definition_dependencies(target_definition).map do |dependency|
    target_definition.pod_whitelisted_for_configuration?(dependency.name, configuration_name)
  end.uniq

  if whitelists.empty?
    @build_config_cache[key] = true
  elsif whitelists.count == 1
    @build_config_cache[key] = whitelists.first
  else
    raise Informative, "The subspecs of `#{pod_name}` are linked to " \
      "different build configurations for the `#{target_definition}` " \
      'target. CocoaPods does not currently support subspecs across ' \
      'different build configurations.'
  end
end

#info_plist_path_for_test_type(test_type) ⇒ Pathname

Returns The absolute path of the Info.plist for the given test type.

Parameters:

  • test_type (Symbol)

    The test type this Info.plist path is for.

Returns:

  • (Pathname)

    The absolute path of the Info.plist for the given test type.



444
445
446
# File 'lib/cocoapods/target/pod_target.rb', line 444

def info_plist_path_for_test_type(test_type)
  support_files_dir + "#{test_target_label(test_type)}-Info.plist"
end

#inhibit_warnings?Bool

Checks if warnings should be inhibited for this pod.

Returns:

  • (Bool)


548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
# File 'lib/cocoapods/target/pod_target.rb', line 548

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(&:label)}), 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.'
    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.



91
92
93
94
95
96
97
# File 'lib/cocoapods/target/pod_target.rb', line 91

def label
  if scope_suffix.nil? || scope_suffix[0] == '.'
    "#{root_spec.name}#{scope_suffix}"
  else
    "#{root_spec.name}-#{scope_suffix}"
  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.



383
384
385
386
387
388
389
390
391
392
# File 'lib/cocoapods/target/pod_target.rb', line 383

def module_map_path
  basename = "#{label}.modulemap"
  if requires_frameworks?
    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

#native_target_for_spec(spec) ⇒ PBXNativeTarget

Returns the corresponding native target to use based on the provided specification. This is used to figure out whether to add a source file into the library native target or any of the test native targets.

Parameters:

  • spec (Specification)

    The specification to base from in order to find the native target.

Returns:

  • (PBXNativeTarget)

    the native target to use or `nil` if none is found.



327
328
329
330
331
332
# File 'lib/cocoapods/target/pod_target.rb', line 327

def native_target_for_spec(spec)
  return native_target unless spec.test_specification?
  test_native_targets.find do |native_target|
    native_target.symbol_type == product_type_for_test_type(spec.test_type)
  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.



376
377
378
# File 'lib/cocoapods/target/pod_target.rb', line 376

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)`



592
593
594
# File 'lib/cocoapods/target/pod_target.rb', line 592

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.



141
142
143
# File 'lib/cocoapods/target/pod_target.rb', line 141

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.



450
451
452
# File 'lib/cocoapods/target/pod_target.rb', line 450

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

#prefix_header_path_for_test_type(test_type) ⇒ Pathname

Returns the absolute path of the prefix header file for the given test type.

Parameters:

  • test_type (Symbol)

    The test type prefix header path is for.

Returns:

  • (Pathname)

    the absolute path of the prefix header file for the given test type.



459
460
461
# File 'lib/cocoapods/target/pod_target.rb', line 459

def prefix_header_path_for_test_type(test_type)
  support_files_dir + "#{test_target_label(test_type)}-prefix.pch"
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.



149
150
151
# File 'lib/cocoapods/target/pod_target.rb', line 149

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.



343
344
345
346
347
348
349
350
# File 'lib/cocoapods/target/pod_target.rb', line 343

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

#recursive_dependent_targetsArray<PodTarget>

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

Returns:

  • (Array<PodTarget>)

    the recursive targets that this target has a dependency upon.



475
476
477
478
479
480
481
482
483
484
485
486
487
# File 'lib/cocoapods/target/pod_target.rb', line 475

def recursive_dependent_targets
  @recursive_dependent_targets ||= begin
    targets = dependent_targets.clone

    targets.each do |target|
      target.dependent_targets.each do |t|
        targets.push(t) unless t == self || targets.include?(t)
      end
    end

    targets
  end
end

#recursive_test_dependent_targetsArray<PodTarget>

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

Returns:

  • (Array<PodTarget>)

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



492
493
494
495
496
497
498
499
500
501
502
503
504
# File 'lib/cocoapods/target/pod_target.rb', line 492

def recursive_test_dependent_targets
  @recursive_test_dependent_targets ||= begin
    targets = test_dependent_targets.clone

    targets.each do |target|
      target.test_dependent_targets.each do |t|
        targets.push(t) unless t == self || targets.include?(t)
      end
    end

    targets
  end
end

#resource_paths(include_test_spec_paths = true) ⇒ Array<String>

Returns the resource paths associated with this target. By default all paths include the resource paths that are part of test specifications.

Parameters:

  • include_test_spec_paths (Boolean) (defaults to: true)

    Whether to include resource paths from test specifications or not.

Returns:

  • (Array<String>)

    The resource and resource bundle paths this target depends upon.



300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/cocoapods/target/pod_target.rb', line 300

def resource_paths(include_test_spec_paths = true)
  @resource_paths ||= {}
  return @resource_paths[include_test_spec_paths] if @resource_paths.key?(include_test_spec_paths)
  @resource_paths[include_test_spec_paths] = begin
    accessors = file_accessors
    accessors = accessors.reject { |a| a.spec.test_specification? } unless include_test_spec_paths
    resource_paths = accessors.flat_map do |accessor|
      accessor.resources.flat_map { |res| "${PODS_ROOT}/#{res.relative_path_from(sandbox.project.path.dirname)}" }
    end
    resource_bundles = accessors.flat_map do |accessor|
      prefix = Generator::XCConfig::XCConfigHelper::CONFIGURATION_BUILD_DIR_VARIABLE
      prefix = configuration_build_dir unless accessor.spec.test_specification?
      accessor.resource_bundles.keys.map { |name| "#{prefix}/#{name.shellescape}.bundle" }
    end
    resource_paths + resource_bundles
  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.



399
400
401
# File 'lib/cocoapods/target/pod_target.rb', line 399

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

#root_specSpecification

Returns The root specification for the target.

Returns:



370
371
372
# File 'lib/cocoapods/target/pod_target.rb', line 370

def root_spec
  specs.first.root
end

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

Returns a scoped copy for each target definition.

Parameters:

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

    the cached PodTarget for a previously scoped (specs, target_definition)

Returns:

  • (Array<PodTarget>)

    a scoped copy for each target definition.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/cocoapods/target/pod_target.rb', line 71

def scoped(cache = {})
  target_definitions.map do |target_definition|
    cache_key = [specs, target_definition]
    if cache[cache_key]
      cache[cache_key]
    else
      target = PodTarget.new(specs, [target_definition], sandbox, target_definition.label)
      target.file_accessors = file_accessors
      target.user_build_configurations = user_build_configurations
      target.native_target = native_target
      target.archs = archs
      target.dependent_targets = dependent_targets.flat_map { |pt| pt.scoped(cache) }.select { |pt| pt.target_definitions == [target_definition] }
      target.host_requires_frameworks = host_requires_frameworks
      cache[cache_key] = 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.



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

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.



170
171
172
173
174
175
176
177
178
# File 'lib/cocoapods/target/pod_target.rb', line 170

def should_build?
  return @should_build if defined? @should_build

  return @should_build = true if contains_script_phases?

  source_files = file_accessors.flat_map(&:source_files)
  source_files -= file_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.



183
184
185
# File 'lib/cocoapods/target/pod_target.rb', line 183

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

#spec_swift_versionString

Returns the Swift version within the root spec. Might be `nil` if none is set.

Returns:

  • (String)

    the Swift version within the root spec. Might be `nil` if none is set.



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

def spec_swift_version
  root_spec.swift_version
end

#supported_test_typesArray<Symbol>

Returns All of the test supported types within this target.

Returns:

  • (Array<Symbol>)

    All of the test supported types within this target.



247
248
249
# File 'lib/cocoapods/target/pod_target.rb', line 247

def supported_test_types
  test_specs.map(&:test_type).uniq
end

#swift_versionString

Returns the Swift version for the target. If the pod author has provided a swift version then that is the one returned, otherwise the Swift version is determined by the user targets that include this pod target.

Returns:

  • (String)

    the Swift version for the target. If the pod author has provided a swift version then that is the one returned, otherwise the Swift version is determined by the user targets that include this pod target.



103
104
105
# File 'lib/cocoapods/target/pod_target.rb', line 103

def swift_version
  spec_swift_version || target_definitions.map(&:swift_version).compact.uniq.first
end

#test_specs_by_native_targetHash{Array => Specification}

Returns a hash where the keys are the test native targets and the value an array of all the test specs associated with this native target.

Returns:

  • (Hash{Array => Specification})

    a hash where the keys are the test native targets and the value an array of all the test specs associated with this native target.



227
228
229
# File 'lib/cocoapods/target/pod_target.rb', line 227

def test_specs_by_native_target
  test_specs.group_by { |test_spec| native_target_for_spec(test_spec) }
end

#test_target_label(test_type) ⇒ String

Returns The derived name of the test target.

Parameters:

  • test_type (Symbol)

    The test type to use for producing the test label.

Returns:

  • (String)

    The derived name of the test target.



408
409
410
# File 'lib/cocoapods/target/pod_target.rb', line 408

def test_target_label(test_type)
  "#{label}-#{test_type.capitalize}-Tests"
end

#test_type_for_product_type(product_type) ⇒ Symbol

Returns the corresponding test type given the product type.

Parameters:

  • product_type (Symbol)

    The product type to map to a test type.

Returns:

  • (Symbol)

    The native product type to use.



359
360
361
362
363
364
365
366
# File 'lib/cocoapods/target/pod_target.rb', line 359

def test_type_for_product_type(product_type)
  case product_type
  when :unit_test_bundle
    :unit
  else
    raise Informative, "Unknown product type `#{product_type}`."
  end
end

#uses_swift?Boolean

Returns Whether the target uses Swift code.

Returns:

  • (Boolean)

    Whether the target uses Swift code.



189
190
191
192
193
194
195
196
# File 'lib/cocoapods/target/pod_target.rb', line 189

def uses_swift?
  return @uses_swift if defined? @uses_swift
  @uses_swift = begin
    file_accessors.any? do |file_accessor|
      file_accessor.source_files.any? { |sf| sf.extname == '.swift' }
    end
  end
end

#versionString

Returns The version associated with this target

Returns:

  • (String)

    The version associated with this target



598
599
600
601
# File 'lib/cocoapods/target/pod_target.rb', line 598

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