From d640f9dc9d0eb38d3719f86fb2bdb4e3fa1b3902 Mon Sep 17 00:00:00 2001 From: Igor Makarov Date: Fri, 23 Jul 2021 16:08:39 +0300 Subject: [PATCH] allow storing custom build for dependency --- .../podfile/target_definition.rb | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/lib/cocoapods-core/podfile/target_definition.rb b/lib/cocoapods-core/podfile/target_definition.rb index 9d0307322..80bcee633 100644 --- a/lib/cocoapods-core/podfile/target_definition.rb +++ b/lib/cocoapods-core/podfile/target_definition.rb @@ -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. # @@ -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 @@ -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 } @@ -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. @@ -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] Hash with configuration name as key, @@ -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. #