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_settings, #host_requires_frameworks, #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, #module_map_path_to_write, #name, #product_basename, #product_name, #product_type, #requires_frameworks?, #static_framework?, #static_library_name, #support_files_dir, #umbrella_header_path, #umbrella_header_path_to_write, #xcconfig_path

Constructor Details

#initialize(sandbox, host_requires_frameworks, user_build_configurations, archs, platform, specs, target_definitions, file_accessors = [], scope_suffix = nil, build_type: Target::BuildType.infer_from_spec(specs.first, :host_requires_frameworks => host_requires_frameworks)) ⇒ PodTarget

Initialize a new instance


86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/cocoapods/target/pod_target.rb', line 86

def initialize(sandbox, host_requires_frameworks, user_build_configurations, archs, platform, specs,
               target_definitions, file_accessors = [], scope_suffix = nil,
               build_type: Target::BuildType.infer_from_spec(specs.first, :host_requires_frameworks => host_requires_frameworks))
  super(sandbox, host_requires_frameworks, user_build_configurations, archs, platform, :build_type => build_type)
  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
  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)
  @dependent_targets = []
  @test_dependent_targets_by_spec_name = {}
  @app_dependent_targets_by_spec_name = {}
  @test_app_hosts_by_spec_name = {}
  @build_config_cache = {}
  @test_spec_build_settings = create_test_build_settings
  @app_spec_build_settings = create_app_build_settings
end

Instance Attribute Details

#app_dependent_targets_by_spec_nameHash{String=>Array<PodTarget>}


59
60
61
# File 'lib/cocoapods/target/pod_target.rb', line 59

def app_dependent_targets_by_spec_name
  @app_dependent_targets_by_spec_name
end

#app_spec_build_settingsHash{String => BuildSettings} (readonly)


71
72
73
# File 'lib/cocoapods/target/pod_target.rb', line 71

def app_spec_build_settings
  @app_spec_build_settings
end

#app_specsArray<Specification> (readonly)


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

def app_specs
  @app_specs
end

#build_headersHeadersStore (readonly)


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

def build_headers
  @build_headers
end

#dependent_targetsArray<PodTarget>


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

def dependent_targets
  @dependent_targets
end

#file_accessorsArray<Sandbox::FileAccessor> (readonly)


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

def file_accessors
  @file_accessors
end

#library_specsArray<Specification> (readonly)


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

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


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

def scope_suffix
  @scope_suffix
end

#specsArray<Specification> (readonly)


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

def specs
  @specs
end

#target_definitionsArray<TargetDefinition> (readonly)


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

def target_definitions
  @target_definitions
end

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


63
64
65
# File 'lib/cocoapods/target/pod_target.rb', line 63

def test_app_hosts_by_spec_name
  @test_app_hosts_by_spec_name
end

#test_dependent_targets_by_spec_nameHash{String=>Array<PodTarget>}


55
56
57
# File 'lib/cocoapods/target/pod_target.rb', line 55

def test_dependent_targets_by_spec_name
  @test_dependent_targets_by_spec_name
end

#test_spec_build_settingsHash{String => BuildSettings} (readonly)


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

def test_spec_build_settings
  @test_spec_build_settings
end

#test_specsArray<Specification> (readonly)


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

def test_specs
  @test_specs
end

Instance Method Details

#all_filesArray<FileAccessor>


158
159
160
# File 'lib/cocoapods/target/pod_target.rb', line 158

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

#app_host_dependent_targets_for_spec(spec) ⇒ Array<PodTarget>


561
562
563
564
565
566
567
568
569
570
# File 'lib/cocoapods/target/pod_target.rb', line 561

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

#app_host_target_label(test_spec) ⇒ (String,String)


546
547
548
549
550
551
552
553
554
# File 'lib/cocoapods/target/pod_target.rb', line 546

def app_host_target_label(test_spec)
  app_spec, app_target = test_app_hosts_by_spec_name[test_spec.name]

  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>


276
277
278
# File 'lib/cocoapods/target/pod_target.rb', line 276

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

#app_target_label(app_spec) ⇒ String


536
537
538
# File 'lib/cocoapods/target/pod_target.rb', line 536

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

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


797
798
799
# File 'lib/cocoapods/target/pod_target.rb', line 797

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

#build_settings_for_spec(spec) ⇒ BuildSettings::PodTargetSettings


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

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

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


788
789
790
# File 'lib/cocoapods/target/pod_target.rb', line 788

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

#contains_app_specifications?Boolean


354
355
356
# File 'lib/cocoapods/target/pod_target.rb', line 354

def contains_app_specifications?
  !app_specs.empty?
end

#contains_script_phases?Boolean


342
343
344
# File 'lib/cocoapods/target/pod_target.rb', line 342

def contains_script_phases?
  !script_phases.empty?
end

#contains_test_specifications?Boolean


348
349
350
# File 'lib/cocoapods/target/pod_target.rb', line 348

def contains_test_specifications?
  !test_specs.empty?
end

#copy_resources_script_input_files_path_for_spec(spec) ⇒ Pathname


606
607
608
# File 'lib/cocoapods/target/pod_target.rb', line 606

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


615
616
617
# File 'lib/cocoapods/target/pod_target.rb', line 615

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


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

def copy_resources_script_path_for_spec(spec)
  support_files_dir + "#{non_library_spec_label(spec)}-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).


314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/cocoapods/target/pod_target.rb', line 314

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>


667
668
669
670
671
# File 'lib/cocoapods/target/pod_target.rb', line 667

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) ⇒ Array<PodTarget>


751
752
753
# File 'lib/cocoapods/target/pod_target.rb', line 751

def dependent_targets_for_app_spec(app_spec)
  [self, *recursive_dependent_targets, *recursive_app_dependent_targets(app_spec)].uniq
end

#dependent_targets_for_test_spec(test_spec) ⇒ Array<PodTarget>


718
719
720
# File 'lib/cocoapods/target/pod_target.rb', line 718

def dependent_targets_for_test_spec(test_spec)
  [self, *recursive_dependent_targets, *recursive_test_dependent_targets(test_spec)].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.

Raises:

  • (ArgumentError)

421
422
423
424
# File 'lib/cocoapods/target/pod_target.rb', line 421

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


633
634
635
# File 'lib/cocoapods/target/pod_target.rb', line 633

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


642
643
644
# File 'lib/cocoapods/target/pod_target.rb', line 642

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


624
625
626
# File 'lib/cocoapods/target/pod_target.rb', line 624

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

#framework_pathsHash{String=>Array<FrameworkPaths>}


362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# File 'lib/cocoapods/target/pod_target.rb', line 362

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
        FrameworkPaths.new(framework_source, dsym_source, bcsymbolmap_paths)
      end
      if file_accessor.spec.library_specification? && should_build? && build_as_dynamic_framework?
        frameworks << 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}


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

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) ⇒ Array<String>


826
827
828
829
830
831
832
833
834
835
836
837
# File 'lib/cocoapods/target/pod_target.rb', line 826

def header_search_paths(include_dependent_targets_for_test_spec: nil, include_dependent_targets_for_app_spec: nil, include_private_headers: true)
  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
  dependent_targets += recursive_test_dependent_targets(include_dependent_targets_for_test_spec) if include_dependent_targets_for_test_spec
  dependent_targets += recursive_app_dependent_targets(include_dependent_targets_for_app_spec) if include_dependent_targets_for_app_spec
  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


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

def headers_sandbox
  Pathname.new(pod_name)
end

#info_plist_entriesHash


499
500
501
# File 'lib/cocoapods/target/pod_target.rb', line 499

def info_plist_entries
  root_spec.info_plist
end

#info_plist_path_for_spec(spec) ⇒ Pathname


651
652
653
# File 'lib/cocoapods/target/pod_target.rb', line 651

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.


759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
# File 'lib/cocoapods/target/pod_target.rb', line 759

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


148
149
150
151
152
153
154
# File 'lib/cocoapods/target/pod_target.rb', line 148

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.


454
455
456
457
458
459
460
461
462
463
# File 'lib/cocoapods/target/pod_target.rb', line 454

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


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

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


572
573
574
575
576
577
578
# File 'lib/cocoapods/target/pod_target.rb', line 572

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


473
474
475
# File 'lib/cocoapods/target/pod_target.rb', line 473

def pod_name
  root_spec.name
end

#pod_target_srcrootString


803
804
805
# File 'lib/cocoapods/target/pod_target.rb', line 803

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

#podfilePodfile


225
226
227
# File 'lib/cocoapods/target/pod_target.rb', line 225

def podfile
  target_definitions.first.podfile
end

#prefix_header_pathPathname


493
494
495
# File 'lib/cocoapods/target/pod_target.rb', line 493

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

#prefix_header_path_for_spec(spec) ⇒ Pathname


660
661
662
# File 'lib/cocoapods/target/pod_target.rb', line 660

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

#product_module_nameString


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

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.


435
436
437
438
439
440
441
442
443
444
# File 'lib/cocoapods/target/pod_target.rb', line 435

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.


235
236
237
# File 'lib/cocoapods/target/pod_target.rb', line 235

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}


181
182
183
184
185
186
187
188
# File 'lib/cocoapods/target/pod_target.rb', line 181

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) ⇒ Array<PodTarget>


728
729
730
731
# File 'lib/cocoapods/target/pod_target.rb', line 728

def recursive_app_dependent_targets(app_spec)
  @recursive_app_dependent_targets ||= {}
  @recursive_app_dependent_targets[app_spec] ||= _add_recursive_app_dependent_targets(app_spec, Set.new).to_a
end

#recursive_dependent_targetsArray<PodTarget>


676
677
678
# File 'lib/cocoapods/target/pod_target.rb', line 676

def recursive_dependent_targets
  @recursive_dependent_targets ||= _add_recursive_dependent_targets(Set.new).delete(self).to_a
end

#recursive_test_dependent_targets(test_spec) ⇒ Array<PodTarget>


695
696
697
698
# File 'lib/cocoapods/target/pod_target.rb', line 695

def recursive_test_dependent_targets(test_spec)
  @recursive_test_dependent_targets ||= {}
  @recursive_test_dependent_targets[test_spec] ||= _add_recursive_test_dependent_targets(test_spec, Set.new).to_a
end

#resource_pathsHash{String=>Array<String>}


398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
# File 'lib/cocoapods/target/pod_target.rb', line 398

def resource_paths
  @resource_paths ||= begin
    file_accessors.each_with_object({}) do |file_accessor, hash|
      resource_paths = if file_accessor.spec.non_library_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


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

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

#root_specSpecification


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

def root_spec
  specs.first.root
end

#scheme_for_spec(spec) ⇒ Hash


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

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.


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
# File 'lib/cocoapods/target/pod_target.rb', line 118

def scoped(cache = {})
  target_definitions.map do |target_definition|
    cache_key = [specs, target_definition]
    cache[cache_key] ||= begin
      target = PodTarget.new(sandbox, host_requires_frameworks, user_build_configurations, archs, platform,
                             specs, [target_definition], file_accessors, target_definition.label,
                             :build_type => build_type)
      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 = scope_dependent_targets[dependent_targets]
      target.test_dependent_targets_by_spec_name = Hash[test_dependent_targets_by_spec_name.map do |spec_name, test_pod_targets|
        [spec_name, scope_dependent_targets[test_pod_targets]]
      end]
      target.app_dependent_targets_by_spec_name = Hash[app_dependent_targets_by_spec_name.map do |spec_name, app_pod_targets|
        [spec_name, scope_dependent_targets[app_pod_targets]]
      end]
      target.test_app_hosts_by_spec_name = Hash[test_app_hosts_by_spec_name.map do |spec_name, (app_host_spec, app_pod_target)|
        [spec_name, [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}>


336
337
338
# File 'lib/cocoapods/target/pod_target.rb', line 336

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.


251
252
253
254
255
256
257
# File 'lib/cocoapods/target/pod_target.rb', line 251

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>


262
263
264
# File 'lib/cocoapods/target/pod_target.rb', line 262

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

#spec_swift_versionsArray<Version>


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

def spec_swift_versions
  root_spec.swift_versions
end

#subspec_label(subspec) ⇒ String

Returns The derived name of the target.

Raises:

  • (ArgumentError)

517
518
519
520
# File 'lib/cocoapods/target/pod_target.rb', line 517

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

#swift_versionString


195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/cocoapods/target/pod_target.rb', line 195

def swift_version
  @swift_version ||= begin
    if spec_swift_versions.empty?
      target_definition_swift_version
    else
      spec_swift_versions.sort.reverse_each.find do |swift_version|
        target_definitions.all? do |td|
          td.supports_swift_version?(swift_version)
        end
      end.to_s
    end
  end
end

#target_definition_swift_versionString


212
213
214
# File 'lib/cocoapods/target/pod_target.rb', line 212

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

#test_spec_consumersArray<Specification::Consumer>


269
270
271
# File 'lib/cocoapods/target/pod_target.rb', line 269

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

#test_target_label(test_spec) ⇒ String


527
528
529
# File 'lib/cocoapods/target/pod_target.rb', line 527

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

#uses_swift?Boolean


282
283
284
285
286
287
288
289
# File 'lib/cocoapods/target/pod_target.rb', line 282

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.


298
299
300
301
302
303
304
305
306
# File 'lib/cocoapods/target/pod_target.rb', line 298

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


809
810
811
812
# File 'lib/cocoapods/target/pod_target.rb', line 809

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