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', :visionos => '1.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 use_modular_headers user_project_path build_configurations project_names dependencies script_phases children configuration_pod_whitelist uses_frameworks swift_version_requirements 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.
-
#build_pod_as_module?(pod_name) ⇒ Boolean
Whether the target definition should use modular headers for a single pod.
-
#build_type ⇒ BuildType
The (desired) build type for the pods integrated in this target definition.
-
#exclusive? ⇒ Boolean
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) ⇒ Boolean
--------------------------------------#.
-
#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) ⇒ Boolean
Whether a specific pod should be linked to the target when building for a specific configuration.
-
#project_name_for_pod(pod_name) ⇒ String
The project name to use for the given pod name or
nil
if none specified. -
#raw_use_modular_headers_hash ⇒ Object
private
--------------------------------------#.
-
#script_phases ⇒ Array<Hash>
The list of the script phases of the target definition.
-
#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.
-
#set_use_modular_headers_for_pod(pod_name, flag) ⇒ void
Use modular headers for a specific pod during compilation.
-
#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.
-
#store_script_phase(options) ⇒ void
Stores the script phase to add for this target definition.
-
#store_swift_version_requirements(*requirements) ⇒ void
Stores the Swift version requirements to be used for this target.
-
#supports_swift_version?(swift_version) ⇒ Boolean
Queries the target if a version of Swift is supported or not.
-
#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.
-
#swift_version_requirements ⇒ Array<String>
The Swift version requirements this target definition enforces.
-
#use_frameworks!(option = true) ⇒ void
Sets whether the target definition's pods should be built as frameworks.
-
#use_modular_headers_for_all_pods=(flag) ⇒ void
Sets whether the target definition should use modular headers for all pods.
-
#use_modular_headers_hash ⇒ Hash<String, Array>
Returns the use_modular_headers hash pre-populated with default values.
-
#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? ⇒ Boolean
Whether the target definition pods should be built as frameworks.
-
#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.
Private helpers collapse
-
#configuration_pod_whitelist ⇒ Hash<String, Array>
private
Returns the configuration_pod_whitelist hash.
-
#get_hash_value(key, base_value = nil) ⇒ Object
private
Returns the value for the given key in the internal hash of the target definition.
-
#inhibit_warnings_hash ⇒ Hash<String, Array>
private
Returns the inhibit_warnings hash pre-populated with default values.
-
#parse_configuration_whitelist(name, requirements) ⇒ void
private
Removes :configurations or :configuration from the requirements list, and adds the pod's name into the internal hash for which pods should be linked in which configuration only.
-
#parse_inhibit_warnings(name, requirements) ⇒ void
private
Removes :inhibit_warnings from the requirements list, and adds the pod's name into internal hash for disabling warnings.
-
#parse_modular_headers(name, requirements) ⇒ void
private
Removes :modular_headers from the requirements list, and adds the pods name into internal hash for modular headers.
-
#parse_project_name(name, requirements) ⇒ void
private
Removes :project_name from the requirements list, and adds the pods name into internal hash.
-
#parse_subspecs(name, requirements) ⇒ Boolean
private
Removes :subspecs and :testspecs from the requirements list, and stores the pods with the given subspecs or test specs as dependencies.
-
#pod_dependencies ⇒ Array<Dependency>
private
The dependencies specified by the user for this target definition.
-
#podspec_dependencies ⇒ Array<Dependency>
private
The dependencies inherited by the podspecs.
-
#podspec_path_from_options(options) ⇒ Pathname
private
The path of the podspec with the given options.
- #raw_configuration_pod_whitelist ⇒ Object private
- #raw_inhibit_warnings_hash ⇒ Object private
- #raw_project_names_hash ⇒ Object private
-
#set_hash_value(key, value) ⇒ void
private
Set a value in the internal hash of the target definition for the given key.
Instance Method Summary collapse
-
#dependencies ⇒ Array<Dependency>
The list of the dependencies of the target definition including the inherited ones.
-
#empty? ⇒ Boolean
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? ⇒ Boolean
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 31 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 22 def initialize(name, parent, internal_hash = nil) @internal_hash = internal_hash || {} @parent = parent @children = [] @label = nil self.name ||= name if parent.is_a?(TargetDefinition) parent.children << self end end |
Instance Attribute Details
#children ⇒ Array<TargetDefinition>
Returns the children target definitions.
35 36 37 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 35 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.
846 847 848 849 850 851 852 853 854 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 846 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.
168 169 170 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 168 def abstract=(abstract) set_hash_value('abstract', abstract) end |
#abstract? ⇒ Boolean
Returns whether this target definition is abstract.
157 158 159 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 157 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.
517 518 519 520 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 517 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
).
269 270 271 272 273 274 275 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 269 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.
285 286 287 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 285 def build_configurations=(hash) set_hash_value('build_configurations', hash) unless hash.empty? end |
#build_pod_as_module?(pod_name) ⇒ Boolean
Whether the target definition should use modular headers for a single pod. If use_modular_headers! is true, it will return true for any asked pod.
564 565 566 567 568 569 570 571 572 573 574 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 564 def build_pod_as_module?(pod_name) if Array(use_modular_headers_hash['not_for_pods']).include?(pod_name) false elsif use_modular_headers_hash['all'] true elsif !root? && parent.build_pod_as_module?(pod_name) true else Array(use_modular_headers_hash['for_pods']).include? pod_name end end |
#build_type ⇒ BuildType
The (desired) build type for the pods integrated in this target definition. Defaults to static libraries and can only be overridden through Pod::Podfile::DSL#use_frameworks!.
373 374 375 376 377 378 379 380 381 382 383 384 385 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 373 def build_type value = get_hash_value('uses_frameworks', root? ? BuildType.static_library : parent.build_type) case value when true, false value ? BuildType.dynamic_framework : BuildType.static_library when Hash BuildType.new(:linkage => value.fetch(:linkage), :packaging => value.fetch(:packaging)) when BuildType value else raise ArgumentError, "Got `#{value.inspect}`, should be a boolean, hash or BuildType." end end |
#configuration_pod_whitelist ⇒ Hash<String, Array> (private)
Returns the configuration_pod_whitelist hash
961 962 963 964 965 966 967 968 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 961 def configuration_pod_whitelist whitelist_hash = raw_configuration_pod_whitelist if exclusive? whitelist_hash else parent.send(:configuration_pod_whitelist).merge(whitelist_hash) { |_, l, r| Array(l).concat(r).uniq } end end |
#dependencies ⇒ Array<Dependency>
Returns The list of the dependencies of the target definition including the inherited ones.
70 71 72 73 74 75 76 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 70 def dependencies if exclusive? non_inherited_dependencies else non_inherited_dependencies + parent.dependencies end end |
#empty? ⇒ Boolean
Returns Whether the target definition has at least one dependency, excluding inherited ones.
102 103 104 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 102 def empty? non_inherited_dependencies.empty? end |
#exclusive? ⇒ Boolean
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.
216 217 218 219 220 221 222 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 216 def exclusive? if root? true else !matches_platform?(parent) || (inheritance != 'complete') end end |
#get_hash_value(key, base_value = nil) ⇒ Object (private)
Returns the value for the given key in the internal hash of the target definition.
906 907 908 909 910 911 912 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 906 def get_hash_value(key, base_value = nil) unless HASH_KEYS.include?(key) raise StandardError, "Unsupported hash key `#{key}`" end internal_hash[key] = base_value if internal_hash[key].nil? internal_hash[key] end |
#inheritance ⇒ String
Returns the inheritance mode for this target definition.
176 177 178 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 176 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.
190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 190 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 if abstract? raise Informative, 'Cannot set inheritance for abstract 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.
337 338 339 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 337 def inhibit_all_warnings=(flag) raw_inhibit_warnings_hash['all'] = flag end |
#inhibit_warnings_hash ⇒ Hash<String, Array> (private)
Returns the inhibit_warnings hash pre-populated with default values.
925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 925 def inhibit_warnings_hash inhibit_hash = raw_inhibit_warnings_hash if exclusive? inhibit_hash else parent_hash = parent.send(:inhibit_warnings_hash).dup if parent_hash['not_for_pods'] # Remove pods that are set to not inhibit inside parent if they are set to inhibit inside current target. parent_hash['not_for_pods'] -= Array(inhibit_hash['for_pods']) end if parent_hash['for_pods'] # Remove pods that are set to inhibit inside parent if they are set to not inhibit inside current target. parent_hash['for_pods'] -= Array(inhibit_hash['for_pods']) end if inhibit_hash['all'] # Clean pods that are set to not inhibit inside parent if inhibit_all_warnings! was set. parent_hash['not_for_pods'] = nil inhibit_hash.delete('all') if parent_hash['all'] end parent_hash.merge(inhibit_hash) do |_, l, r| Array(l).concat(r).uniq end end end |
#inhibits_warnings_for_pod?(pod_name) ⇒ Boolean
--------------------------------------#
317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 317 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.
123 124 125 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 123 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.
109 110 111 112 113 114 115 116 117 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 109 def label @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
.
231 232 233 234 235 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 231 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.
136 137 138 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 136 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.
148 149 150 151 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 148 def name=(name) @label = nil set_hash_value('name', name) end |
#non_inherited_dependencies ⇒ Array
Returns The list of the dependencies of the target definition, excluding inherited ones.
95 96 97 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 95 def non_inherited_dependencies pod_dependencies.concat(podspec_dependencies) end |
#parse_configuration_whitelist(name, requirements) ⇒ void (private)
This method returns an undefined value.
Removes :configurations or :configuration from the requirements list, and adds the pod's name into the internal hash for which pods should be linked in which configuration only.
1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 1129 def parse_configuration_whitelist(name, requirements) = requirements.last return requirements unless .is_a?(Hash) configurations = .delete(:configurations) configurations ||= .delete(:configuration) Array(configurations).each do |configuration| whitelist_pod_for_configuration(name, configuration) end requirements.pop if .empty? end |
#parse_inhibit_warnings(name, requirements) ⇒ void (private)
This method returns an undefined value.
Removes :inhibit_warnings from the requirements list, and adds the pod's name into internal hash for disabling warnings.
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 1057 def parse_inhibit_warnings(name, requirements) = requirements.last return requirements unless .is_a?(Hash) should_inhibit = .delete(:inhibit_warnings) pod_name = Specification.root_name(name) set_inhibit_warnings_for_pod(pod_name, should_inhibit) requirements.pop if .empty? end |
#parse_modular_headers(name, requirements) ⇒ void (private)
This method returns an undefined value.
Removes :modular_headers from the requirements list, and adds the pods name into internal hash for modular headers.
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 1079 def parse_modular_headers(name, requirements) = requirements.last return requirements unless .is_a?(Hash) defines_module = .delete(:modular_headers) pod_name = Specification.root_name(name) set_use_modular_headers_for_pod(pod_name, defines_module) requirements.pop if .empty? end |
#parse_project_name(name, requirements) ⇒ void (private)
This method returns an undefined value.
Removes :project_name from the requirements list, and adds the pods name into internal hash.
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 1101 def parse_project_name(name, requirements) = requirements.last return requirements unless .is_a?(Hash) project_name = .delete(:project_name) pod_name = Specification.root_name(name) raw_project_names_hash[pod_name] = project_name if project_name requirements.pop if .empty? end |
#parse_subspecs(name, requirements) ⇒ Boolean (private)
Removes :subspecs and :testspecs from the requirements list, and stores the pods with the given subspecs or test specs as dependencies.
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 1152 def parse_subspecs(name, requirements) = requirements.last return false unless .is_a?(Hash) subspecs = .delete(:subspecs) test_specs = .delete(:testspecs) app_specs = .delete(:appspecs) subspecs.each do |ss| store_pod("#{name}/#{ss}", *requirements.dup) end if subspecs test_specs.each do |ss| requirements_copy = requirements.map(&:dup) store_pod("#{name}/#{ss}", *requirements_copy) end if test_specs app_specs.each do |as| requirements_copy = requirements.map(&:dup) store_pod("#{name}/#{as}", *requirements_copy) end if app_specs requirements.pop if .empty? !subspecs.nil? end |
#platform ⇒ Platform
If no deployment target has been specified a default value is provided.
Returns the platform of the target definition.
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 621 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_dependencies ⇒ Array<Dependency> (private)
Returns The dependencies specified by the user for this target definition.
973 974 975 976 977 978 979 980 981 982 983 984 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 973 def pod_dependencies pods = get_hash_value('dependencies') || [] pods.map do |name_or_hash| if name_or_hash.is_a?(Hash) name = name_or_hash.keys.first requirements = name_or_hash.values.first Dependency.new(name, *requirements) else Dependency.new(name_or_hash) end end end |
#pod_whitelisted_for_configuration?(pod_name, configuration_name) ⇒ Boolean
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.
480 481 482 483 484 485 486 487 488 489 490 491 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 480 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.
63 64 65 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 63 def podfile root.parent end |
#podspec_dependencies ⇒ Array<Dependency> (private)
The podspec directive is intended to include the dependencies of a spec in the project where it is developed. For this reason the spec, or any of it subspecs, cannot be included in the dependencies. Otherwise it would generate a chicken-and-egg problem.
Returns The dependencies inherited by the podspecs.
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 994 def podspec_dependencies podspecs = get_hash_value('podspecs') || [] podspecs.map do || file = () spec = Specification.from_file(file) subspec_names = [:subspecs] || [:subspec] specs = if subspec_names.blank? [spec] else subspec_names = [subspec_names] if subspec_names.is_a?(String) subspec_names.map { |subspec_name| spec.subspec_by_name("#{spec.name}/#{subspec_name}") } end specs.map do |subspec| all_specs = [subspec, *subspec.recursive_subspecs] all_deps = all_specs.map { |s| s.dependencies(platform) }.flatten all_deps.reject { |dep| dep.root_name == subspec.root.name } end.flatten end.flatten.uniq end |
#podspec_path_from_options(options) ⇒ Pathname (private)
The path of the podspec with the given options.
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 1022 def () if path = [:path] if File.basename(path).include?('.podspec') path_with_ext = path else path_with_ext = "#{path}.podspec" end path_without_tilde = path_with_ext.gsub('~', ENV['HOME']) podfile.defined_in_file.dirname + path_without_tilde elsif name = [:name] name = File.basename(name).include?('.podspec') ? name : "#{name}.podspec" podfile.defined_in_file.dirname + name elsif [:autodetect] glob_pattern = podfile.defined_in_file.dirname + '*.podspec{,.json}' path = Pathname.glob(glob_pattern).first unless path raise Informative, 'Could not locate a podspec in the current directory. '\ 'You can specify the path via the path option.' end path end end |
#project_name_for_pod(pod_name) ⇒ String
When querying for a subspec then use the root pod spec name instead as this is what's stored.
Returns The project name to use for the given pod name or nil
if none specified.
303 304 305 306 307 308 309 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 303 def project_name_for_pod(pod_name) if root? raw_project_names_hash[pod_name] else raw_project_names_hash[pod_name] || parent.project_name_for_pod(pod_name) end end |
#raw_configuration_pod_whitelist ⇒ Object (private)
950 951 952 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 950 def raw_configuration_pod_whitelist get_hash_value('configuration_pod_whitelist', {}) end |
#raw_inhibit_warnings_hash ⇒ Object (private)
914 915 916 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 914 def raw_inhibit_warnings_hash get_hash_value('inhibit_warnings', {}) end |
#raw_project_names_hash ⇒ Object (private)
1112 1113 1114 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 1112 def raw_project_names_hash get_hash_value('project_names', {}) end |
#raw_use_modular_headers_hash ⇒ Object (private)
--------------------------------------#
524 525 526 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 524 def raw_use_modular_headers_hash get_hash_value('use_modular_headers', {}) end |
#recursive_children ⇒ Array<TargetDefinition>
Returns the targets definition descending from this one.
40 41 42 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 40 def recursive_children (children + children.map(&:recursive_children)).flatten end |
#root ⇒ TargetDefinition
Returns The root target definition.
52 53 54 55 56 57 58 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 52 def root if root? self else parent.root end end |
#root? ⇒ Boolean
Returns Whether the target definition is root.
46 47 48 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 46 def root? parent.is_a?(Podfile) || parent.nil? end |
#script_phases ⇒ Array<Hash>
Returns The list of the script phases of the target definition.
293 294 295 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 293 def script_phases get_hash_value('script_phases') || [] end |
#set_hash_value(key, value) ⇒ void (private)
This method returns an undefined value.
Set a value in the internal hash of the target definition for the given key.
886 887 888 889 890 891 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 886 def set_hash_value(key, value) unless HASH_KEYS.include?(key) raise StandardError, "Unsupported hash key `#{key}`" end internal_hash[key] = value 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.
351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 351 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.
649 650 651 652 653 654 655 656 657 658 659 660 661 662 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 649 def set_platform(name, target = nil) name = :osx if name == :macos unless [:ios, :osx, :tvos, :visionos, :watchos].include?(name) raise StandardError, "Unsupported platform `#{name}`. Platform " \ 'must be `:ios`, `:osx`, `:macos`, `:tvos`, :visionos, 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.
672 673 674 675 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 672 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 |
#set_use_modular_headers_for_pod(pod_name, flag) ⇒ void
This method returns an undefined value.
Use modular headers for a specific pod during compilation.
597 598 599 600 601 602 603 604 605 606 607 608 609 610 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 597 def set_use_modular_headers_for_pod(pod_name, flag) hash_key = case flag when true 'for_pods' when false 'not_for_pods' when nil return else raise ArgumentError, "Got `#{flag.inspect}`, should be a boolean" end raw_use_modular_headers_hash[hash_key] ||= [] raw_use_modular_headers_hash[hash_key] << pod_name 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.
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 707 def store_pod(name, *requirements) return if parse_subspecs(name, requirements) # This parse method must be called first parse_inhibit_warnings(name, requirements) parse_modular_headers(name, requirements) parse_configuration_whitelist(name, requirements) parse_project_name(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.
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 741 def store_podspec( = nil) ||= {} unless .keys.all? { |key| [:name, :path, :subspecs, :subspec].include?(key) } raise StandardError, 'Unrecognized options for the podspec ' \ "method `#{}`" end if subspec_name = [:subspec] unless subspec_name.is_a?(String) raise StandardError, "Option `:subspec => #{subspec_name.inspect}` should be a String" end end if subspec_names = [:subspecs] if !subspec_names.is_a?(Array) || !subspec_names.all? { |name| name.is_a? String } raise StandardError, "Option `:subspecs => #{subspec_names.inspect}` " \ 'should be an Array of Strings' end end [:autodetect] = true if !.include?(:name) && !.include?(:path) get_hash_value('podspecs', []) << end |
#store_script_phase(options) ⇒ void
This method returns an undefined value.
Stores the script phase to add for this target definition.
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 774 def store_script_phase() option_keys = .keys unrecognized_keys = option_keys - Specification::ALL_SCRIPT_PHASE_KEYS unless unrecognized_keys.empty? raise StandardError, "Unrecognized options `#{unrecognized_keys}` in shell script `#{[:name]}` within `#{name}` target. " \ "Available options are `#{Specification::ALL_SCRIPT_PHASE_KEYS}`." end missing_required_keys = Specification::SCRIPT_PHASE_REQUIRED_KEYS - option_keys unless missing_required_keys.empty? raise StandardError, "Missing required shell script phase options `#{missing_required_keys.join(', ')}`" end script_phases_hash = get_hash_value('script_phases', []) if script_phases_hash.map { || [:name] }.include?([:name]) raise StandardError, "Script phase with name `#{[:name]}` name already present for target `#{name}`." end [:execution_position] = :any unless .key?(:execution_position) unless Specification::EXECUTION_POSITION_KEYS.include?([:execution_position]) raise StandardError, "Invalid execution position value `#{[:execution_position]}` in shell script `#{[:name]}` within `#{name}` target. " \ "Available options are `#{Specification::EXECUTION_POSITION_KEYS}`." end script_phases_hash << end |
#store_swift_version_requirements(*requirements) ⇒ void
This method returns an undefined value.
Stores the Swift version requirements to be used for this target.
684 685 686 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 684 def store_swift_version_requirements(*requirements) set_hash_value('swift_version_requirements', requirements.flatten.map(&:to_s)) end |
#supports_swift_version?(swift_version) ⇒ Boolean
Queries the target if a version of Swift is supported or not.
452 453 454 455 456 457 458 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 452 def supports_swift_version?(swift_version) if swift_version_requirements.nil? root? || parent.supports_swift_version?(swift_version) else Requirement.create(swift_version_requirements).satisfied_by?(swift_version) end end |
#swift_version ⇒ String
Returns the Swift version that the target definition should use.
435 436 437 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 435 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.
428 429 430 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 428 def swift_version=(version) set_hash_value('swift_version', version) end |
#swift_version_requirements ⇒ Array<String>
Returns the Swift version requirements this target definition enforces.
441 442 443 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 441 def swift_version_requirements get_hash_value('swift_version_requirements') end |
#targets_to_inherit_search_paths ⇒ Array<TargetDefinition>
Returns the targets from which this target definition should inherit only search paths.
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 81 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.
831 832 833 834 835 836 837 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 831 def to_hash hash = internal_hash.dup unless children.empty? hash['children'] = children.map(&:to_hash) end hash end |
#use_frameworks!(option = true) ⇒ void
This method returns an undefined value.
Sets whether the target definition's pods should be built as frameworks.
397 398 399 400 401 402 403 404 405 406 407 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 397 def use_frameworks!(option = true) value = case option when true, false option ? BuildType.dynamic_framework : BuildType.static_library when Hash BuildType.new(:linkage => option.fetch(:linkage), :packaging => :framework) else raise ArgumentError, "Got `#{option.inspect}`, should be a boolean or hash." end set_hash_value('uses_frameworks', value.to_hash) end |
#use_modular_headers_for_all_pods=(flag) ⇒ void
This method returns an undefined value.
Sets whether the target definition should use modular headers for all pods.
583 584 585 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 583 def use_modular_headers_for_all_pods=(flag) raw_use_modular_headers_hash['all'] = flag end |
#use_modular_headers_hash ⇒ Hash<String, Array>
Returns the use_modular_headers hash pre-populated with default values.
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 535 def use_modular_headers_hash raw_hash = raw_use_modular_headers_hash if exclusive? raw_hash else parent_hash = parent.send(:use_modular_headers_hash).dup if parent_hash['not_for_pods'] # Remove pods that are set to not use modular headers inside parent # if they are set to use modular headers inside current target. parent_hash['not_for_pods'] -= Array(raw_hash['for_pods']) end if parent_hash['for_pods'] # Remove pods that are set to use modular headers inside parent if they are set to not use modular headers inside current target. parent_hash['for_pods'] -= Array(raw_hash['for_pods']) end if raw_hash['all'] # Clean pods that are set to not use modular headers inside parent if use_modular_headers! was set. parent_hash['not_for_pods'] = nil end parent_hash.merge(raw_hash) do |_, l, r| Array(l).concat(r).uniq end end end |
#user_project_path ⇒ String
Returns the path of the project this target definition should link with.
242 243 244 245 246 247 248 249 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 242 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.
259 260 261 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 259 def user_project_path=(path) set_hash_value('user_project_path', path) end |
#uses_frameworks? ⇒ Boolean
Returns whether the target definition pods should be built as frameworks.
411 412 413 414 415 416 417 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 411 def uses_frameworks? if internal_hash['uses_frameworks'].nil? root? ? false : parent.uses_frameworks? else build_type.framework? 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.
508 509 510 511 512 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 508 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 |