From d6138f8b635db0c4cb97aa028904507760071a21 Mon Sep 17 00:00:00 2001 From: Dimitris Koutsogiorgas Date: Wed, 7 Jun 2017 11:01:06 -0700 Subject: [PATCH] Use a cache when figuring out if a pod target is test only --- CHANGELOG.md | 4 ++++ lib/cocoapods/installer/analyzer.rb | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a656a70c6c..6af232ad66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ##### Bug Fixes +* Use a cache when figuring out if a pod target is test only + [Dimitris Koutsogiorgas](https://github.com/dnkoutso) + [#6787](https://github.com/CocoaPods/CocoaPods/pull/6787) + * Do not double add search paths to test xcconfig from parent [Dimitris Koutsogiorgas](https://github.com/dnkoutso) [#6767](https://github.com/CocoaPods/CocoaPods/pull/6767) diff --git a/lib/cocoapods/installer/analyzer.rb b/lib/cocoapods/installer/analyzer.rb index b473d0e48d..110c3e2564 100644 --- a/lib/cocoapods/installer/analyzer.rb +++ b/lib/cocoapods/installer/analyzer.rb @@ -46,6 +46,8 @@ def initialize(sandbox, podfile, lockfile = nil) @update = false @allow_pre_downloads = true @has_dependencies = true + @test_pod_target_analyzer_cache = {} + @test_pod_target_key = Struct.new(:name, :pod_targets) end # Performs the analysis. @@ -430,8 +432,9 @@ def generate_target(target_definition, pod_targets) target.pod_targets = pod_targets.select do |pod_target| target_definition_included = pod_target.target_definitions.include?(target_definition) explicitly_defined_in_target_definition = target_definition.non_inherited_dependencies.map(&:name).include?(pod_target.name) - test_pod_target_only = pod_target_test_only?(pod_target, pod_targets) - target_definition_included && (explicitly_defined_in_target_definition || !test_pod_target_only) + next false unless target_definition_included + next true if explicitly_defined_in_target_definition + !pod_target_test_only?(pod_target, pod_targets) end target @@ -449,9 +452,14 @@ def generate_target(target_definition, pod_targets) # @return [Boolean] if the pod target is only referenced from test dependencies. # def pod_target_test_only?(pod_target, pod_targets) - source = pod_targets.any? { |pt| pt.dependent_targets.map(&:name).include?(pod_target.name) } - test = pod_targets.any? { |pt| pt.test_dependent_targets.map(&:name).include?(pod_target.name) } - !source && test + name = pod_target.name + key = @test_pod_target_key.new(name, pod_targets) + if @test_pod_target_analyzer_cache.key?(key) + return @test_pod_target_analyzer_cache[key] + end + source = pod_targets.any? { |pt| pt.dependent_targets.map(&:name).include?(name) } + test = pod_targets.any? { |pt| pt.test_dependent_targets.map(&:name).include?(name) } + @test_pod_target_analyzer_cache[key] = !source && test end # Setup the pod targets for an aggregate target. Deduplicates resulting