Commit 7b6d2edc authored by Marius Rackwitz's avatar Marius Rackwitz

[Analyzer] Frameworks and libraries can safely co-exist

Edit: Turns out that even though that's true for Xcode in isolation,
this was actually a misconception for CocoaPods. Both build product
types need different auxiliary files and some components of the
installer (e.g. `PodSourceInstaller`) are not ready for such usage.
I decided that the possible win having files de-duplicated across
targets doesn't outweight the added complexity.
parent f8ecc02e
......@@ -291,24 +291,28 @@ module Pod
distinct_targets = specs_by_target.each_with_object({}) do |dependency, hash|
target_definition, dependent_specs = *dependency
dependent_specs.group_by(&:root).each do |root_spec, specs|
pod_variant = PodVariant.new(specs, target_definition.platform)
pod_variant = PodVariant.new(specs, target_definition.platform, target_definition.uses_frameworks?)
hash[root_spec] ||= {}
(hash[root_spec][pod_variant] ||= []) << target_definition
end
end
pod_targets = distinct_targets.flat_map do |_, target_definitions_by_variant|
if target_definitions_by_variant.count > 1
pod_targets = distinct_targets.flat_map do |_root, target_definitions_by_variant|
# Frameworks and libraries can safely co-exist
target_definitions_by_variant.group_by { |k, _| k.requires_frameworks? }.flat_map do |_, array|
if array.count > 1
# There are different sets of subspecs or the spec is used across different platforms
suffixes = scope_suffixes_for_variants(target_definitions_by_variant.keys)
target_definitions_by_variant.flat_map do |variant, target_definitions|
hash = Hash[array]
suffixes = scope_suffixes_for_variants(hash.keys)
hash.flat_map do |variant, target_definitions|
generate_pod_target(target_definitions, variant.specs, :scope_suffix => suffixes[variant])
end
else
variant, target_definitions = *target_definitions_by_variant.first
variant, target_definitions = *array.first
generate_pod_target(target_definitions, variant.specs)
end
end
end
else
dedupe_cache = {}
pod_targets = specs_by_target.flat_map do |target_definition, specs|
......
......@@ -11,6 +11,11 @@ module Pod
#
attr_accessor :platform
# @return [Bool] whether this pod should be built as framework
#
attr_accessor :requires_frameworks
alias_method :requires_frameworks?, :requires_frameworks
# @return [Specification] the root specification
#
def root_spec
......@@ -19,10 +24,12 @@ module Pod
# @param [Array<String>] specs @see #specs
# @param [Platform] platform @see #platform
# @param [Bool] requires_frameworks @see #requires_frameworks?
#
def initialize(specs, platform)
def initialize(specs, platform, requires_frameworks = false)
self.specs = specs
self.platform = platform
self.requires_frameworks = requires_frameworks
end
# @return [Bool] whether the {PodVariant} is equal to another taking all
......@@ -31,7 +38,8 @@ module Pod
def ==(other)
self.class == other.class &&
specs == other.specs &&
platform == other.platform
platform == other.platform &&
requires_frameworks == other.requires_frameworks
end
alias_method :eql?, :==
......@@ -41,7 +49,7 @@ module Pod
#
# @!visibility private
def hash
[specs, platform].hash
[specs, platform, requires_frameworks].hash
end
end
end
......
......@@ -286,6 +286,33 @@ module Pod
}
end
it "doesn't deduplicate targets across different integration modes" do
podfile = Pod::Podfile.new do
source SpecHelper.test_repo_url
platform :ios, '6.0'
xcodeproj 'SampleProject/SampleProject'
target 'SampleProject' do
use_frameworks!
pod 'BananaLib'
target 'TestRunner' do
use_frameworks!(false)
pod 'BananaLib'
end
end
end
analyzer = Pod::Installer::Analyzer.new(config.sandbox, podfile)
result = analyzer.analyze
pod_targets = result.targets.flat_map(&:pod_targets).uniq.sort_by(&:name)
Hash[pod_targets.map { |t| [[t.label, t.requires_frameworks?], t.target_definitions.map(&:label)] }].should == {
['BananaLib', false] => %w(Pods-SampleProject-TestRunner),
['BananaLib', true] => %w(Pods-SampleProject),
['monkey', false] => %w(Pods-SampleProject-TestRunner),
['monkey', true] => %w(Pods-SampleProject),
}
end
it "doesn't deduplicate targets when deduplication is disabled" do
podfile = Pod::Podfile.new do
install! 'cocoapods', :deduplicate_targets => false
......
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