Class: Pod::PodTarget
- 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.
Instance Attribute Summary collapse
-
#build_headers ⇒ HeadersStore
readonly
The header directory for the target.
-
#file_accessors ⇒ Array<Sandbox::FileAccessor>
The file accessors for the specifications of this target.
-
#resource_bundle_targets ⇒ Array<PBXTarget>
readonly
The resource bundle targets belonging to this target.
-
#scoped ⇒ Array<PodTarget>
readonly
A scoped copy for each target definition.
-
#specs ⇒ Array<Specification>
readonly
The spec and subspecs for the target.
-
#target_definitions ⇒ Array<PBXNativeTarget>
readonly
The target definitions of the Podfile that generated this target.
Attributes inherited from Target
#archs, #host_requires_frameworks, #native_target, #sandbox, #user_build_configurations
Instance Method Summary collapse
-
#configuration_build_dir ⇒ String
The configuration build dir, relevant if the target is integrated as framework.
-
#dependencies ⇒ Array<String>
The names of the Pods on which this target depends.
-
#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.
-
#inhibit_warnings? ⇒ Bool
Checks if warnings should be inhibited for this pod.
-
#initialize(specs, target_definitions, sandbox, scoped = false) ⇒ PodTarget
constructor
A new instance of PodTarget.
-
#label ⇒ String
The label for the target.
-
#platform ⇒ Platform
The platform for this target.
-
#pod_name ⇒ String
The name of the Pod that this target refers to.
-
#podfile ⇒ Podfile
The podfile which declares the dependency.
-
#product_module_name ⇒ 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.
-
#resources_bundle_target_label(bundle_name) ⇒ String
The derived name of the resource bundle target.
-
#root_spec ⇒ Specification
The root specification for the target.
-
#scoped? ⇒ Bool
Whether the target needs to be scoped by target definition, because the spec is used with different subspec sets across them.
-
#should_build? ⇒ Bool
A target should not be build if it has no source files.
-
#spec_consumers ⇒ Array<Specification::Consumer>
The specification consumers for the target.
-
#uses_swift? ⇒ Boolean
Whether the target uses Swift code.
Methods inherited from Target
#bridge_support_path, #dummy_source_path, #framework_name, #info_plist_path, #inspect, #module_map_path, #name, #prefix_header_path, #product_basename, #product_name, #product_type, #requires_frameworks?, #static_library_name, #support_files_dir, #umbrella_header_path, #xcconfig_path, #xcconfig_prefix, #xcconfig_private_path
Constructor Details
#initialize(specs, target_definitions, sandbox, scoped = false) ⇒ PodTarget
Returns a new instance of PodTarget.
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cocoapods/target/pod_target.rb', line 41 def initialize(specs, target_definitions, sandbox, scoped = false) 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? super() @specs = specs @target_definitions = target_definitions @sandbox = sandbox @scoped = scoped @build_headers = Sandbox::HeadersStore.new(sandbox, 'Private') @file_accessors = [] @resource_bundle_targets = [] end |
Instance Attribute Details
#build_headers ⇒ HeadersStore (readonly)
Returns the header directory for the target.
17 18 19 |
# File 'lib/cocoapods/target/pod_target.rb', line 17 def build_headers @build_headers end |
#file_accessors ⇒ Array<Sandbox::FileAccessor>
Returns the file accessors for the specifications of this target.
100 101 102 |
# File 'lib/cocoapods/target/pod_target.rb', line 100 def file_accessors @file_accessors end |
#resource_bundle_targets ⇒ Array<PBXTarget> (readonly)
Returns the resource bundle targets belonging to this target.
104 105 106 |
# File 'lib/cocoapods/target/pod_target.rb', line 104 def resource_bundle_targets @resource_bundle_targets end |
#scoped ⇒ Array<PodTarget> (readonly)
Returns a scoped copy for each target definition.
33 34 35 |
# File 'lib/cocoapods/target/pod_target.rb', line 33 def scoped @scoped end |
#specs ⇒ Array<Specification> (readonly)
Returns the spec and subspecs for the target.
8 9 10 |
# File 'lib/cocoapods/target/pod_target.rb', line 8 def specs @specs end |
#target_definitions ⇒ Array<PBXNativeTarget> (readonly)
Returns 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 |
Instance Method Details
#configuration_build_dir ⇒ String
Returns The configuration build dir, relevant if the target is integrated as framework.
213 214 215 216 217 218 219 |
# File 'lib/cocoapods/target/pod_target.rb', line 213 def configuration_build_dir if scoped? "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/#{target_definitions.first.label}" else '$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)' end end |
#dependencies ⇒ Array<String>
Returns The names of the Pods on which this target depends.
155 156 157 158 159 |
# File 'lib/cocoapods/target/pod_target.rb', line 155 def dependencies spec_consumers.flat_map do |consumer| consumer.dependencies.map { |dep| Specification.root_name(dep.name) } end.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.
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/cocoapods/target/pod_target.rb', line 170 def include_in_build_config?(target_definition, configuration_name) whitelists = target_definition_dependencies(target_definition).map do |dependency| target_definition.pod_whitelisted_for_configuration?(dependency.name, configuration_name) end.uniq if whitelists.empty? return true elsif whitelists.count == 1 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 |
#inhibit_warnings? ⇒ Bool
Checks if warnings should be inhibited for this pod.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/cocoapods/target/pod_target.rb', line 191 def inhibit_warnings? whitelists = target_definitions.map do |target_definition| target_definition.inhibits_warnings_for_pod?(root_spec.name) end.uniq if whitelists.empty? return false elsif whitelists.count == 1 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.' return podfile.root_target_definitions.first.inhibits_warnings_for_pod?(root_spec.name) end end |
#label ⇒ String
Returns the label for the target.
69 70 71 72 73 74 75 |
# File 'lib/cocoapods/target/pod_target.rb', line 69 def label if scoped? "#{target_definitions.first.label}-#{root_spec.name}" else root_spec.name end end |
#platform ⇒ Platform
Returns the platform for this target.
79 80 81 |
# File 'lib/cocoapods/target/pod_target.rb', line 79 def platform @platform ||= target_definitions.first.platform end |
#pod_name ⇒ String
Returns The name of the Pod that this target refers to.
139 140 141 |
# File 'lib/cocoapods/target/pod_target.rb', line 139 def pod_name root_spec.name end |
#podfile ⇒ Podfile
Returns The podfile which declares the dependency.
85 86 87 |
# File 'lib/cocoapods/target/pod_target.rb', line 85 def podfile target_definitions.first.podfile end |
#product_module_name ⇒ String
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.
93 94 95 |
# File 'lib/cocoapods/target/pod_target.rb', line 93 def product_module_name root_spec.module_name end |
#resources_bundle_target_label(bundle_name) ⇒ String
Returns The derived name of the resource bundle target.
148 149 150 |
# File 'lib/cocoapods/target/pod_target.rb', line 148 def resources_bundle_target_label(bundle_name) "#{label}-#{bundle_name}" end |
#root_spec ⇒ Specification
Returns The root specification for the target.
133 134 135 |
# File 'lib/cocoapods/target/pod_target.rb', line 133 def root_spec specs.first.root end |
#scoped? ⇒ Bool
For frameworks the target products of Pod::PodTargets are named after their specs. The namespacing cannot directly happen in the product name itself, because this must be equal to the module name and this will be used in source code, which should stay agnostic over the dependency manager. We need namespacing because multiple targets can exist for the same podspec and their products should not collide. This duplication is needed when multiple user targets have the same dependency, but they require different sets of subspecs or they are on different platforms.
Returns whether the target needs to be scoped by target definition, because the spec is used with different subspec sets across them.
34 35 36 |
# File 'lib/cocoapods/target/pod_target.rb', line 34 def scoped @scoped end |
#should_build? ⇒ Bool
A target should not be build if it has no source files.
110 111 112 113 114 |
# File 'lib/cocoapods/target/pod_target.rb', line 110 def should_build? source_files = file_accessors.flat_map(&:source_files) source_files -= file_accessors.flat_map(&:headers) !source_files.empty? end |
#spec_consumers ⇒ Array<Specification::Consumer>
Returns the specification consumers for the target.
119 120 121 |
# File 'lib/cocoapods/target/pod_target.rb', line 119 def spec_consumers specs.map { |spec| spec.consumer(platform) } end |
#uses_swift? ⇒ Boolean
Returns Whether the target uses Swift code.
125 126 127 128 129 |
# File 'lib/cocoapods/target/pod_target.rb', line 125 def uses_swift? file_accessors.any? do |file_accessor| file_accessor.source_files.any? { |sf| sf.extname == '.swift' } end end |