Commit ef1a511e authored by Marius Rackwitz's avatar Marius Rackwitz

[Analyzer] Don't deduplicate PodTargets whose transitive dependencies can't be deduplicated

parent 65c77adb
......@@ -289,7 +289,7 @@ module Pod
(hash[root_spec][[specs, target_definition.platform]] ||= []) << target_definition
end
distinct_targets.values.flat_map do |targets_by_distinctors|
pod_targets = distinct_targets.flat_map do |_, targets_by_distinctors|
if targets_by_distinctors.count > 1
# There are different sets of subspecs or the spec is used across different platforms
targets_by_distinctors.map do |distinctor, target_definitions|
......@@ -301,6 +301,17 @@ module Pod
generate_pod_target(target_definitions, specs)
end
end
# A `PodTarget` can't be deduplicated if any of its
# transitive dependencies can't be deduplicated.
pod_targets.flat_map do |target|
dependent_targets = transitive_dependencies_for_pod_target(target, pod_targets)
if dependent_targets.any?(&:scoped?)
target.scoped
else
target
end
end
else
specs_by_target.flat_map do |target_definition, specs|
grouped_specs = specs.group_by.group_by(&:root).values.uniq
......@@ -311,6 +322,34 @@ module Pod
end
end
# Finds the names of the Pods on which the given target _transitively_
# depends.
#
# @note: This is implemented in the analyzer, because we don't have to
# care about the requirements after dependency resolution.
#
# @param [PodTarget] pod_target
# The pod target, whose dependencies should be returned.
#
# @param [Array<PodTarget>] targets
# All pod targets, which are integrated alongside.
#
# @return [Array<PodTarget>]
#
def transitive_dependencies_for_pod_target(pod_target, targets)
if targets.any?
dependent_targets = pod_target.dependencies.flat_map do |dep|
targets.select { |t| t.pod_name == dep }
end
remaining_targets = targets - dependent_targets
dependent_targets + dependent_targets.flat_map do |target|
transitive_dependencies_for_pod_target(target, remaining_targets)
end
else
[]
end
end
# Create a target for each spec group
#
# @param [TargetDefinitions] target_definitions
......
......@@ -9,6 +9,10 @@ module SpecHelper
fixture_copy_path + "#{fixture_name}.xcodeproj"
end
def self.test_repo_url
'https://github.com/CocoaPods/test_repo.git'
end
module Fixture
ROOT = ::ROOT + 'spec/fixtures'
......
......@@ -114,6 +114,69 @@ module Pod
target.platform.to_s.should == 'iOS 6.0'
end
describe 'deduplication' do
before do
repos = [fixture('spec-repos/test_repo'), fixture('spec-repos/master')]
aggregate = Pod::Source::Aggregate.new(repos)
Pod::SourcesManager.stubs(:aggregate).returns(aggregate)
aggregate.sources.first.stubs(:url).returns(SpecHelper.test_repo_url)
end
it 'deduplicate targets if possible' do
podfile = Pod::Podfile.new do
source SpecHelper.test_repo_url
platform :ios, '6.0'
xcodeproj 'SampleProject/SampleProject'
pod 'BananaLib'
pod 'monkey'
target 'TestRunner' do
pod 'BananaLib'
pod 'monkey'
end
end
analyzer = Pod::Installer::Analyzer.new(config.sandbox, podfile)
analyzer.analyze
analyzer.analyze.targets.flat_map { |at| at.pod_targets.map { |pt| "#{at.name}/#{pt.name}" } }.sort.should == %w(
Pods/BananaLib
Pods/monkey
Pods-TestRunner/BananaLib
Pods-TestRunner/monkey
).sort
end
it "doesn't deduplicate targets, where transitive dependencies can't be deduplicated" do
podfile = Pod::Podfile.new do
source SpecHelper.test_repo_url
platform :ios, '6.0'
xcodeproj 'SampleProject/SampleProject'
pod 'BananaLib'
pod 'monkey'
target 'TestRunner' do
pod 'BananaLib'
pod 'monkey'
end
target 'CLITool' do
platform :osx, '10.10'
pod 'monkey'
end
end
analyzer = Pod::Installer::Analyzer.new(config.sandbox, podfile)
analyzer.analyze
analyzer.analyze.targets.flat_map { |at| at.pod_targets.map { |pt| "#{at.name}/#{pt.name}" } }.sort.should == %w(
Pods/Pods-BananaLib
Pods/Pods-monkey
Pods-TestRunner/Pods-TestRunner-BananaLib
Pods-TestRunner/Pods-monkey
Pods-CLITool/Pods-CLITool-monkey
).sort
end
end
it 'generates the integration library appropriately if the installation will not integrate' do
config.integrate_targets = false
target = @analyzer.analyze.targets.first
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment