Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow storing custom build for dependency #687

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions lib/cocoapods-core/podfile/target_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,18 @@ def inhibits_warnings_for_pod?(pod_name)
end
end

#--------------------------------------#
#
#
# @param [String] pod_name
# the anem of the pod to query build type for.
#
# @return [BuildType] The resolved build type for the pod.
#
def build_type_for_pod(pod_name)
raw_build_types_hash[pod_name] || build_type
end

# Sets whether the target definition should inhibit the warnings during
# compilation for all pods.
#
Expand Down Expand Up @@ -363,6 +375,20 @@ def set_inhibit_warnings_for_pod(pod_name, should_inhibit)
raw_inhibit_warnings_hash[hash_key] << pod_name
end

# Set a custom build type for a specific pod.
#
# @param [String] pod_name
# Name of the pod for which the build type should be set.
#
# @param [BuildType] build_type
# The build type.
#
# @return [void]
#
def set_build_type_for_pod(pod_name, build_type)
raw_build_types_hash[pod_name] = build_type
end

#--------------------------------------#

# The (desired) build type for the pods integrated in this target definition. Defaults to static libraries and can
Expand Down Expand Up @@ -710,6 +736,7 @@ def store_pod(name, *requirements)
parse_modular_headers(name, requirements)
parse_configuration_whitelist(name, requirements)
parse_project_name(name, requirements)
parse_build_type(name, requirements)

if requirements && !requirements.empty?
pod = { name => requirements }
Expand Down Expand Up @@ -824,6 +851,7 @@ def store_script_phase(options)
inheritance
abstract
swift_version
build_types_hash
).freeze

# @return [Hash] The hash representation of the target definition.
Expand Down Expand Up @@ -952,6 +980,11 @@ def raw_configuration_pod_whitelist
end
private :raw_configuration_pod_whitelist

def raw_build_types_hash
get_hash_value('build_types_hash', {})
end
private :raw_build_types_hash

# Returns the configuration_pod_whitelist hash
#
# @return [Hash<String, Array>] Hash with configuration name as key,
Expand Down Expand Up @@ -1065,6 +1098,32 @@ def parse_inhibit_warnings(name, requirements)
requirements.pop if options.empty?
end

# Removes :build from the requirements list, and adds
# the pod's name into internal hash for build type overrides.
#
# @param [String] name The name of the pod
#
# @param [Array] requirements
# If :build is the only key in the hash, the hash
# should be destroyed because it confuses Gem::Dependency.
#
# @return [void]
#
def parse_build_type(name, requirements)
options = requirements.last
return requirements unless options.is_a?(Hash)

build_type_raw = options.delete(:build)
return if build_type_raw.nil?

pod_name = Specification.root_name(name)
build_type_to_store = BuildType.new(:linkage => build_type_raw.fetch(:linkage, build_type.linkage),
:packaging => build_type_raw.fetch(:packaging, build_type.packaging))
set_build_type_for_pod(pod_name, build_type_to_store)

requirements.pop if options.empty?
end

# Removes :modular_headers from the requirements list, and adds
# the pods name into internal hash for modular headers.
#
Expand Down