Class: Pod::Podfile::TargetDefinition
- Inherits:
-
Object
- Object
- Pod::Podfile::TargetDefinition
- Defined in:
- lib/cocoapods-core/podfile/target_definition.rb
Overview
The TargetDefinition stores the information of a CocoaPods static library. The target definition can be linked with one or more targets of the user project.
Target definitions can be nested and by default inherit the dependencies of the parent.
Attributes collapse
- PLATFORM_DEFAULTS =
————————————–#
{ :ios => '4.3', :osx => '10.6', :tvos => '9.0', :watchos => '2.0' }.freeze
Representations collapse
- HASH_KEYS =
Returns The keys used by the hash representation of the target definition.
%w( name platform podspecs exclusive link_with link_with_first_target inhibit_warnings user_project_path build_configurations dependencies children configuration_pod_whitelist uses_frameworks inheritance abstract swift_version ).freeze
Instance Attribute Summary collapse
-
#children ⇒ Array<TargetDefinition>
readonly
The children target definitions.
-
#parent ⇒ TargetDefinition, Podfile
readonly
The parent target definition or the Podfile if the receiver is root.
Attributes collapse
-
#abstract=(abstract) ⇒ void
Sets whether this target definition is abstract.
-
#abstract? ⇒ Boolean
Whether this target definition is abstract.
-
#all_whitelisted_configurations ⇒ Array<String>
Unique list of all configurations for which pods have been whitelisted.
-
#build_configurations ⇒ Hash{String => symbol}
A hash where the keys are the name of the build configurations and the values a symbol that represents their type (‘:debug` or `:release`).
-
#build_configurations=(hash) ⇒ Hash{String => Symbol}, void
Sets the build configurations for this target.
-
#exclusive? ⇒ Bool
Returns whether the target definition should inherit the dependencies of the parent.
-
#inheritance ⇒ String
The inheritance mode for this target definition.
-
#inheritance=(inheritance) ⇒ void
Sets the inheritance mode for this target definition.
-
#inhibit_all_warnings=(flag) ⇒ void
Sets whether the target definition should inhibit the warnings during compilation for all pods.
-
#inhibits_warnings_for_pod?(pod_name) ⇒ Bool
Whether the target definition should inhibit warnings for a single pod.
-
#matches_platform?(target_definition) ⇒ Boolean
Whether this target definition matches the platform of ‘target_definition`.
-
#name ⇒ String
The path of the project this target definition should link with.
-
#name=(name) ⇒ void
Sets the path of the user project this target definition should link with.
-
#platform ⇒ Platform
The platform of the target definition.
-
#pod_whitelisted_for_configuration?(pod_name, configuration_name) ⇒ Bool
Whether a specific pod should be linked to the target when building for a specific configuration.
-
#set_inhibit_warnings_for_pod(pod_name, should_inhibit) ⇒ void
Inhibits warnings for a specific pod during compilation.
-
#set_platform(name, target = nil) ⇒ void
Sets the platform of the target definition.
-
#set_platform!(name, target = nil) ⇒ void
Sets the platform of the target definition.
-
#store_pod(name, *requirements) ⇒ void
Stores the dependency for a Pod with the given name.
-
#store_podspec(options = nil) ⇒ void
Stores the podspec whose dependencies should be included by the target.
-
#swift_version ⇒ String
The Swift version that the target definition should use.
-
#swift_version=(version) ⇒ void
Sets the Swift version that the target definition should use.
-
#use_frameworks!(flag = true) ⇒ void
Sets whether the target definition should build a framework.
-
#user_project_path ⇒ String
The path of the project this target definition should link with.
-
#user_project_path=(path) ⇒ void
Sets the path of the user project this target definition should link with.
-
#uses_frameworks? ⇒ Bool
Whether the target definition should build a framework.
-
#whitelist_pod_for_configuration(pod_name, configuration_name) ⇒ void
Whitelists a pod for a specific configuration.
Representations collapse
-
.from_hash(hash, parent) ⇒ TargetDefinition
Configures a new target definition from the given hash.
-
#to_hash ⇒ Hash
The hash representation of the target definition.
Instance Method Summary collapse
-
#dependencies ⇒ Array<Dependency>
The list of the dependencies of the target definition including the inherited ones.
-
#empty? ⇒ Bool
Whether the target definition has at least one dependency, excluding inherited ones.
-
#initialize(name, parent, internal_hash = nil) ⇒ TargetDefinition
constructor
A new instance of TargetDefinition.
-
#inspect ⇒ String
A string representation suitable for debug.
-
#label ⇒ String
(also: #to_s)
The label of the target definition according to its name.
-
#non_inherited_dependencies ⇒ Array
The list of the dependencies of the target definition, excluding inherited ones.
-
#podfile ⇒ Podfile
The podfile that contains the specification for this target definition.
-
#recursive_children ⇒ Array<TargetDefinition>
The targets definition descending from this one.
-
#root ⇒ TargetDefinition
The root target definition.
-
#root? ⇒ Bool
Whether the target definition is root.
-
#targets_to_inherit_search_paths ⇒ Array<TargetDefinition>
The targets from which this target definition should inherit only search paths.
Constructor Details
#initialize(name, parent, internal_hash = nil) ⇒ TargetDefinition
Returns a new instance of TargetDefinition.
22 23 24 25 26 27 28 29 30 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 22 def initialize(name, parent, internal_hash = nil) @internal_hash = internal_hash || {} @parent = parent @children = [] self.name ||= name if parent.is_a?(TargetDefinition) parent.children << self end end |
Instance Attribute Details
#children ⇒ Array<TargetDefinition>
Returns the children target definitions.
34 35 36 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 34 def children @children end |
#parent ⇒ TargetDefinition, Podfile (readonly)
Returns the parent target definition or the Podfile if the receiver is root.
14 15 16 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 14 def parent @parent end |
Class Method Details
.from_hash(hash, parent) ⇒ TargetDefinition
Configures a new target definition from the given hash.
617 618 619 620 621 622 623 624 625 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 617 def self.from_hash(hash, parent) internal_hash = hash.dup children_hashes = internal_hash.delete('children') || [] definition = TargetDefinition.new(nil, parent, internal_hash) children_hashes.each do |child_hash| TargetDefinition.from_hash(child_hash, definition) end definition end |
Instance Method Details
#abstract=(abstract) ⇒ void
This method returns an undefined value.
Sets whether this target definition is abstract.
166 167 168 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 166 def abstract=(abstract) set_hash_value('abstract', abstract) end |
#abstract? ⇒ Boolean
Returns whether this target definition is abstract.
155 156 157 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 155 def abstract? get_hash_value('abstract', root?) end |
#all_whitelisted_configurations ⇒ Array<String>
Returns unique list of all configurations for which pods have been whitelisted.
440 441 442 443 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 440 def all_whitelisted_configurations parent_configurations = (root? || inheritance == 'none') ? [] : parent.all_whitelisted_configurations (configuration_pod_whitelist.keys + parent_configurations).uniq end |
#build_configurations ⇒ Hash{String => symbol}
Returns A hash where the keys are the name of the build configurations and the values a symbol that represents their type (‘:debug` or `:release`).
264 265 266 267 268 269 270 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 264 def build_configurations if root? get_hash_value('build_configurations') else get_hash_value('build_configurations') || parent.build_configurations end end |
#build_configurations=(hash) ⇒ Hash{String => Symbol}, void
Sets the build configurations for this target.
280 281 282 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 280 def build_configurations=(hash) set_hash_value('build_configurations', hash) unless hash.empty? end |
#dependencies ⇒ Array<Dependency>
Returns The list of the dependencies of the target definition including the inherited ones.
69 70 71 72 73 74 75 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 69 def dependencies if exclusive? non_inherited_dependencies else non_inherited_dependencies + parent.dependencies end end |
#empty? ⇒ Bool
Returns Whether the target definition has at least one dependency, excluding inherited ones.
101 102 103 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 101 def empty? non_inherited_dependencies.empty? end |
#exclusive? ⇒ Bool
A target is always ‘exclusive` if it is root.
A target is always ‘exclusive` if the `platform` does not match the parent’s ‘platform`.
Returns whether the target definition should inherit the dependencies of the parent.
211 212 213 214 215 216 217 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 211 def exclusive? if root? true else !matches_platform?(parent) || (inheritance != 'complete') end end |
#inheritance ⇒ String
Returns the inheritance mode for this target definition.
174 175 176 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 174 def inheritance get_hash_value('inheritance', 'complete') end |
#inheritance=(inheritance) ⇒ void
This method returns an undefined value.
Sets the inheritance mode for this target definition.
188 189 190 191 192 193 194 195 196 197 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 188 def inheritance=(inheritance) inheritance = inheritance.to_s unless %w(none search_paths complete).include?(inheritance) raise Informative, "Unrecognized inheritance option `#{inheritance}` specified for target `#{name}`." end if root? raise Informative, 'Cannot set inheritance for the root target definition.' end set_hash_value('inheritance', inheritance) end |
#inhibit_all_warnings=(flag) ⇒ void
This method returns an undefined value.
Sets whether the target definition should inhibit the warnings during compilation for all pods.
310 311 312 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 310 def inhibit_all_warnings=(flag) raw_inhibit_warnings_hash['all'] = flag end |
#inhibits_warnings_for_pod?(pod_name) ⇒ Bool
Whether the target definition should inhibit warnings for a single pod. If inhibit_all_warnings is true, it will return true for any asked pod.
290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 290 def inhibits_warnings_for_pod?(pod_name) if Array(inhibit_warnings_hash['not_for_pods']).include?(pod_name) false elsif inhibit_warnings_hash['all'] true elsif !root? && parent.inhibits_warnings_for_pod?(pod_name) true else Array(inhibit_warnings_hash['for_pods']).include? pod_name end end |
#inspect ⇒ String
Returns A string representation suitable for debug.
122 123 124 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 122 def inspect "#<#{self.class} label=#{label}>" end |
#label ⇒ String Also known as: to_s
Returns The label of the target definition according to its name.
108 109 110 111 112 113 114 115 116 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 108 def label if root? && name == 'Pods' 'Pods' elsif exclusive? || parent.nil? "Pods-#{name}" else "#{parent.label}-#{name}" end end |
#matches_platform?(target_definition) ⇒ Boolean
Returns whether this target definition matches the platform of ‘target_definition`.
226 227 228 229 230 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 226 def matches_platform?(target_definition) return false unless target_definition return true if target_definition.platform == platform !target_definition.platform && target_definition.abstract? end |
#name ⇒ String
Returns the path of the project this target definition should link with.
135 136 137 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 135 def name get_hash_value('name') end |
#name=(name) ⇒ void
This method returns an undefined value.
Sets the path of the user project this target definition should link with.
147 148 149 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 147 def name=(name) set_hash_value('name', name) end |
#non_inherited_dependencies ⇒ Array
Returns The list of the dependencies of the target definition, excluding inherited ones.
94 95 96 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 94 def non_inherited_dependencies pod_dependencies.concat(podspec_dependencies) end |
#platform ⇒ Platform
If no deployment target has been specified a default value is provided.
Returns the platform of the target definition.
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 454 def platform name_or_hash = get_hash_value('platform') if name_or_hash if name_or_hash.is_a?(Hash) name = name_or_hash.keys.first.to_sym target = name_or_hash.values.first else name = name_or_hash.to_sym end target ||= PLATFORM_DEFAULTS[name] Platform.new(name, target) else parent.platform unless root? end end |
#pod_whitelisted_for_configuration?(pod_name, configuration_name) ⇒ Bool
Build configurations are case compared case-insensitively in CocoaPods.
Whether a specific pod should be linked to the target when building for a specific configuration. If a pod has not been explicitly whitelisted for any configuration, it is implicitly whitelisted.
403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 403 def pod_whitelisted_for_configuration?(pod_name, configuration_name) found = false configuration_pod_whitelist.each do |configuration, pods| if pods.include?(pod_name) found = true if configuration.downcase == configuration_name.to_s.downcase return true end end end !found && (root? || (inheritance != 'none' && parent.pod_whitelisted_for_configuration?(pod_name, configuration_name))) end |
#podfile ⇒ Podfile
Returns The podfile that contains the specification for this target definition.
62 63 64 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 62 def podfile root.parent end |
#recursive_children ⇒ Array<TargetDefinition>
Returns the targets definition descending from this one.
39 40 41 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 39 def recursive_children (children + children.map(&:recursive_children)).flatten end |
#root ⇒ TargetDefinition
Returns The root target definition.
51 52 53 54 55 56 57 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 51 def root if root? self else parent.root end end |
#root? ⇒ Bool
Returns Whether the target definition is root.
45 46 47 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 45 def root? parent.is_a?(Podfile) || parent.nil? end |
#set_inhibit_warnings_for_pod(pod_name, should_inhibit) ⇒ void
This method returns an undefined value.
Inhibits warnings for a specific pod during compilation.
324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 324 def set_inhibit_warnings_for_pod(pod_name, should_inhibit) hash_key = case should_inhibit when true 'for_pods' when false 'not_for_pods' when nil return else raise ArgumentError, "Got `#{should_inhibit.inspect}`, should be a boolean" end raw_inhibit_warnings_hash[hash_key] ||= [] raw_inhibit_warnings_hash[hash_key] << pod_name end |
#set_platform(name, target = nil) ⇒ void
This method returns an undefined value.
Sets the platform of the target definition.
482 483 484 485 486 487 488 489 490 491 492 493 494 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 482 def set_platform(name, target = nil) unless [:ios, :osx, :tvos, :watchos].include?(name) raise StandardError, "Unsupported platform `#{name}`. Platform " \ 'must be `:ios`, `:osx`, `:tvos`, or `:watchos`.' end if target value = { name.to_s => target } else value = name.to_s end set_hash_value('platform', value) end |
#set_platform!(name, target = nil) ⇒ void
This method returns an undefined value.
Sets the platform of the target definition.
504 505 506 507 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 504 def set_platform!(name, target = nil) raise StandardError, "The target `#{label}` already has a platform set." if get_hash_value('platform') set_platform(name, target) end |
#store_pod(name, *requirements) ⇒ void
This needs urgently a rename.
The dependencies are stored as an array. To simplify the YAML representation if they have requirements they are represented as a Hash, otherwise only the String of the name is added to the array.
This method returns an undefined value.
Stores the dependency for a Pod with the given name.
528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 528 def store_pod(name, *requirements) return if parse_subspecs(name, requirements) # This parse method must be called first parse_inhibit_warnings(name, requirements) parse_configuration_whitelist(name, requirements) if requirements && !requirements.empty? pod = { name => requirements } else pod = name end get_hash_value('dependencies', []) << pod nil end |
#store_podspec(options = nil) ⇒ void
This urgently needs a rename.
The storage of this information is optimized for YAML readability.
This method returns an undefined value.
Stores the podspec whose dependencies should be included by the target.
560 561 562 563 564 565 566 567 568 569 570 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 560 def store_podspec( = nil) if unless .keys.all? { |key| [:name, :path].include?(key) } raise StandardError, 'Unrecognized options for the podspec ' \ "method `#{}`" end get_hash_value('podspecs', []) << else get_hash_value('podspecs', []) << { :autodetect => true } end end |
#swift_version ⇒ String
Returns the Swift version that the target definition should use.
379 380 381 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 379 def swift_version get_hash_value('swift_version') end |
#swift_version=(version) ⇒ void
This method returns an undefined value.
Sets the Swift version that the target definition should use.
372 373 374 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 372 def swift_version=(version) set_hash_value('swift_version', version) end |
#targets_to_inherit_search_paths ⇒ Array<TargetDefinition>
Returns the targets from which this target definition should inherit only search paths.
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 80 def targets_to_inherit_search_paths can_inherit = !root? && matches_platform?(parent) if inheritance == 'search_paths' # && can_inherit parent.targets_to_inherit_search_paths << parent elsif can_inherit parent.targets_to_inherit_search_paths else [] end end |
#to_hash ⇒ Hash
Returns The hash representation of the target definition.
602 603 604 605 606 607 608 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 602 def to_hash hash = internal_hash.dup unless children.empty? hash['children'] = children.map(&:to_hash) end hash end |
#use_frameworks!(flag = true) ⇒ void
This method returns an undefined value.
Sets whether the target definition should build a framework.
348 349 350 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 348 def use_frameworks!(flag = true) set_hash_value('uses_frameworks', flag) end |
#user_project_path ⇒ String
Returns the path of the project this target definition should link with.
237 238 239 240 241 242 243 244 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 237 def user_project_path path = get_hash_value('user_project_path') if path Pathname(path).sub_ext('.xcodeproj').to_path else parent.user_project_path unless root? end end |
#user_project_path=(path) ⇒ void
This method returns an undefined value.
Sets the path of the user project this target definition should link with.
254 255 256 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 254 def user_project_path=(path) set_hash_value('user_project_path', path) end |
#uses_frameworks? ⇒ Bool
Returns whether the target definition should build a framework.
355 356 357 358 359 360 361 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 355 def uses_frameworks? if internal_hash['uses_frameworks'].nil? root? ? false : parent.uses_frameworks? else get_hash_value('uses_frameworks') end end |
#whitelist_pod_for_configuration(pod_name, configuration_name) ⇒ void
Build configurations are stored as a String.
This method returns an undefined value.
Whitelists a pod for a specific configuration. If a pod is whitelisted for any configuration, it will only be linked with the target in the configuration(s) specified. If it is not whitelisted for any configuration, it is implicitly included in all configurations.
431 432 433 434 435 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 431 def whitelist_pod_for_configuration(pod_name, configuration_name) configuration_name = configuration_name.to_s list = raw_configuration_pod_whitelist[configuration_name] ||= [] list << pod_name end |