class Pod::Target::BuildSettings
@since 1.5.0
Constants
- CONFIGURATION_BUILD_DIR_VARIABLE
@return [String]
The variable for the configuration build directory used when building pod targets.
- PLURAL_SETTINGS
@return [Set<String>]
The build settings that should be treated as arrays, rather than strings.
Attributes
@return [Set<String>] a set of all the build settings names that will be present in the xcconfig
@return [Target]
The target this build settings object is generating build settings for
Public Class Methods
Initialize a new instance
@param [Target] target
see {#target}
# File lib/cocoapods/target/build_settings.rb, line 157 def initialize(target) @target = target @__memoized = {} end
Private Class Methods
Creates a method that calculates a part of the build settings for the {#target}.
@!visibility private
@param [Symbol,String] method_name
The name of the method to define
@param [Boolean] build_setting
Whether the method name should be added (upcased) to {.build_setting_names}
@param [Boolean] memoized
Whether the method should be memoized
@param [Boolean] sorted
Whether the return value should be sorted
@param [Boolean] uniqued
Whether the return value should be uniqued
@param [Boolean] compacted
Whether the return value should be compacted
@param [Boolean] frozen
Whether the return value should be frozen
@param [Boolean, Symbol] from_search_paths_aggregate_targets
If truthy, the method from {Aggregate} that should be used to concatenate build settings from {::Pod::AggregateTarget#search_paths_aggregate_target}
@param [Symbol] from_pod_targets_to_link
If truthy, the `_to_import` values from `BuildSettings#pod_targets_to_link` will be concatenated
@param [Block] implementation
@macro [attach] define_build_settings_method
@!method $1 The `$1` build setting for the {#target}. The return value from this method will be: `${1--1}`.
# File lib/cocoapods/target/build_settings.rb, line 88 def self.define_build_settings_method(method_name, build_setting: false, memoized: false, sorted: false, uniqued: false, compacted: false, frozen: true, from_search_paths_aggregate_targets: false, from_pod_targets_to_link: false, &implementation) memoized_key = "#{self}##{method_name}".freeze (@build_settings_names ||= Set.new) << method_name.to_s.upcase if build_setting raw_method_name = :"_raw_#{method_name}" define_method(raw_method_name, &implementation) private(raw_method_name) dup_before_freeze = frozen && (from_pod_targets_to_link || from_search_paths_aggregate_targets || uniqued || sorted) define_method(method_name) do if memoized retval = @__memoized.fetch(memoized_key, :not_found) return retval if :not_found != retval end retval = send(raw_method_name) if retval.nil? @__memoized[memoized_key] = retval if memoized return end retval = retval.dup if dup_before_freeze && retval.frozen? retval.concat(pod_targets_to_link.flat_map { |pod_target| pod_target.build_settings.public_send("#{method_name}_to_import") }) if from_pod_targets_to_link retval.concat(search_paths_aggregate_target_pod_target_build_settings.flat_map(&from_search_paths_aggregate_targets)) if from_search_paths_aggregate_targets retval.compact! if compacted retval.uniq! if uniqued retval.sort! if sorted retval.freeze if frozen @__memoized[memoized_key] = retval if memoized retval end end
Public Instance Methods
@param [Array<String>] frameworks
The list of framework names
@return [Array<String>]
the `FRAMEWORK_SEARCH_PATHS` needed to import developer frameworks
# File lib/cocoapods/target/build_settings.rb, line 237 def framework_search_paths_to_import_developer_frameworks(frameworks) if frameworks.include?('XCTest') || frameworks.include?('SenTestingKit') %w[ $(PLATFORM_DIR)/Developer/Library/Frameworks ] else [] end end
# File lib/cocoapods/target/build_settings.rb, line 162 def initialize_copy(other) super @__memoized = {} end
@return [Boolean]
Whether `OTHER_SWIFT_FLAGS` should be generated when the target does not use swift.
# File lib/cocoapods/target/build_settings.rb, line 281 def other_swift_flags_without_swift? false end
Saves the generated xcconfig to the given path
@return [Xcodeproj::Config]
@see xcconfig
@param [String,Pathname] path
The path the xcconfig will be saved to
# File lib/cocoapods/target/build_settings.rb, line 184 def save_as(path) xcconfig.save_as(path) end
Private Instance Methods
@return [Array<String>]
the `LD_RUNPATH_SEARCH_PATHS` needed for dynamically linking the {#target}
@param [Boolean] requires_host_target
@param [Boolean] test_bundle
# File lib/cocoapods/target/build_settings.rb, line 314 def _ld_runpath_search_paths(requires_host_target: false, test_bundle: false) if target.platform.symbolic_name == :osx ["'@executable_path/../Frameworks'", test_bundle ? "'@loader_path/../Frameworks'" : "'@loader_path/Frameworks'"] else paths = [ "'@executable_path/Frameworks'", "'@loader_path/Frameworks'", ] paths << "'@executable_path/../../Frameworks'" if requires_host_target paths end end
@return [Hash<String => String>]
# File lib/cocoapods/target/build_settings.rb, line 358 def add_inherited_to_plural(hash) Hash[hash.map do |key, value| next [key, '$(inherited)'] if value.nil? if PLURAL_SETTINGS.include?(key) raise ArgumentError, "#{key} is a plural setting, cannot have #{value.inspect} as its value" unless value.is_a? Array value = "$(inherited) #{quote_array(value)}" else raise ArgumentError, "#{key} is not a plural setting, cannot have #{value.inspect} as its value" unless value.is_a? String end [key, value] end] end
@param [Hash] xcconfig_values_by_consumer_by_key
@param [#to_s] attribute
The name of the attribute being merged
@return [Hash<String, String>]
# File lib/cocoapods/target/build_settings.rb, line 400 def merged_xcconfigs(xcconfig_values_by_consumer_by_key, attribute) xcconfig_values_by_consumer_by_key.each_with_object({}) do |(key, values_by_consumer), xcconfig| uniq_values = values_by_consumer.values.uniq values_are_bools = uniq_values.all? { |v| v =~ /\A(yes|no)\z/i } if values_are_bools # Boolean build settings if uniq_values.count > 1 UI.warn "Can't merge #{attribute} for pod targets: " \ "#{values_by_consumer.keys.map(&:name)}. Boolean build " \ "setting #{key} has different values." else xcconfig[key] = uniq_values.first end elsif PLURAL_SETTINGS.include? key # Plural build settings xcconfig[key] = uniq_values.join(' ') elsif uniq_values.count > 1 # Singular build settings UI.warn "Can't merge #{attribute} for pod targets: " \ "#{values_by_consumer.keys.map(&:name)}. Singular build " \ "setting #{key} has different values." else xcconfig[key] = uniq_values.first end end end
@return [Array<String>]
@param [Array<String>] array
# File lib/cocoapods/target/build_settings.rb, line 377 def quote_array(array) array.map do |element| case element when /\A([\w-]+?)=(.+)\z/ key = Regexp.last_match(1) value = Regexp.last_match(2) value = %("#{value}") if value =~ /[^\w\d]/ %(#{key}=#{value}) when /[\$\[\]\ ]/ %("#{element}") else element end end.join(' ') end
Filters out pod targets whose `specs` are a subset of another target's.
@param [Array<PodTarget>] pod_targets
@return [Array<PodTarget>]
# File lib/cocoapods/target/build_settings.rb, line 434 def select_maximal_pod_targets(pod_targets) subset_targets = [] pod_targets.uniq.combination(2) do |a, b| if (a.specs - b.specs).empty? subset_targets << a elsif (b.specs - a.specs).empty? subset_targets << b end end pod_targets - subset_targets end
@return [Hash<String => String|Array<String>>]
# File lib/cocoapods/target/build_settings.rb, line 349 def to_h hash = {} self.class.build_settings_names.sort.each do |setting| hash[setting] = public_send(setting.downcase) end hash end