From 3eb460850bde5cf0d28f8e4b018f0071c93dd723 Mon Sep 17 00:00:00 2001 From: youhui Date: Thu, 29 Jun 2023 19:10:20 +0800 Subject: [PATCH 1/2] Sometimes we don't actively rely on related components in order to push tags quickly, but indirectly through protocols! However, this disconnects references between components, which can be missed when a dependency is needed, so to avoid this, after the dependency, added: virtual => 'true' to mark as virtual dependency. The dependency is not associated with the component when the tag is pushed, but is imported in pod install/update and other cases. This allows for both quick push of the component tag and strong binding between components. Now, we can mark the virtual dependencies like this 'Spec.ios.dependency' MBProgressHUD', '~> 0.5', :virtual => 'true'; we really need this, please help merge into the code, thank you very much --- lib/cocoapods-core/specification/consumer.rb | 6 +++++ lib/cocoapods-core/specification/dsl.rb | 27 ++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/cocoapods-core/specification/consumer.rb b/lib/cocoapods-core/specification/consumer.rb index e469504b..44645322 100644 --- a/lib/cocoapods-core/specification/consumer.rb +++ b/lib/cocoapods-core/specification/consumer.rb @@ -229,6 +229,12 @@ def user_target_xcconfig # def dependencies value = value_for_attribute(:dependencies) + + # install/update will contain virtual_dependencies!! + if $*.first == "update" || $*.first == "install" + value_virtual = value_for_attribute(:virtual_dependencies) + value = value.merge(value_virtual) if value_virtual + end value.map do |name, requirements| Dependency.new(name, requirements) end diff --git a/lib/cocoapods-core/specification/dsl.rb b/lib/cocoapods-core/specification/dsl.rb index 0e4499e3..0673b5bd 100644 --- a/lib/cocoapods-core/specification/dsl.rb +++ b/lib/cocoapods-core/specification/dsl.rb @@ -666,6 +666,22 @@ def deployment_target=(*_args) :container => Hash, :inherited => true + #-----------------------------------------------------------------------# + + # if define virtual to 'ture', the virtual_dependencies will save it instead of dependencies; + + # # @Target + # This is to create a new virtual dependency that will be updated to the virtual dependency + # when pod install/update without affecting the component label push + + #-----------------------------------------------------------------------# + + # # @example + # spec.ios.dependency 'MBProgressHUD', '~> 0.5', :virtual => 'true' + attribute :virtual_dependencies, + :container => Hash, + :inherited => true + # Any dependency on other Pods or to a ‘sub-specification’. # # --- @@ -734,8 +750,15 @@ def dependency(*args) raise Informative, "Unsupported version requirements. #{version_requirements.inspect} is not valid." end - attributes_hash['dependencies'] ||= {} - attributes_hash['dependencies'][name] = version_requirements + #store dependency to virtual_dependencies if has :virtual + virtual_option = (configurations_option&.delete(:virtual)&.to_s&.downcase == 'true') || false + if virtual_option == 'true' + attributes_hash['virtual_dependencies'] ||= {} + attributes_hash['virtual_dependencies'][name] = version_requirements + else + attributes_hash['dependencies'] ||= {} + attributes_hash['dependencies'][name] = version_requirements + end unless whitelisted_configurations.nil? if (extras = whitelisted_configurations - %w(debug release)) && !extras.empty? From c27195f45a5a38d30210a7e6d446961fbdd0812d Mon Sep 17 00:00:00 2001 From: youhui Date: Thu, 29 Jun 2023 19:52:04 +0800 Subject: [PATCH 2/2] fix is_virtual --- lib/cocoapods-core/specification/dsl.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/cocoapods-core/specification/dsl.rb b/lib/cocoapods-core/specification/dsl.rb index 0673b5bd..445466df 100644 --- a/lib/cocoapods-core/specification/dsl.rb +++ b/lib/cocoapods-core/specification/dsl.rb @@ -735,6 +735,12 @@ def dependency(*args) Array(configurations_option.delete(:configurations)).map { |c| c.to_s.downcase } end + virtual_option = version_requirements.find { |option| option.is_a?(Hash) && option.key?(:virtual) } + is_virtual = if virtual_option + version_requirements.delete(virtual_option) + (virtual_option&.delete(:virtual)&.to_s&.downcase == 'true') || false + end + dependency_options = version_requirements.reject { |req| req.is_a?(String) } dependency_options.each do |dependency_option| if dependency_option.is_a?(Hash) @@ -751,8 +757,7 @@ def dependency(*args) end #store dependency to virtual_dependencies if has :virtual - virtual_option = (configurations_option&.delete(:virtual)&.to_s&.downcase == 'true') || false - if virtual_option == 'true' + if is_virtual attributes_hash['virtual_dependencies'] ||= {} attributes_hash['virtual_dependencies'][name] = version_requirements else