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,22 +291,26 @@ module Pod ...@@ -291,22 +291,26 @@ module Pod
distinct_targets = specs_by_target.each_with_object({}) do |dependency, hash| distinct_targets = specs_by_target.each_with_object({}) do |dependency, hash|
target_definition, dependent_specs = *dependency target_definition, dependent_specs = *dependency
dependent_specs.group_by(&:root).each do |root_spec, specs| 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] ||= {}
(hash[root_spec][pod_variant] ||= []) << target_definition (hash[root_spec][pod_variant] ||= []) << target_definition
end end
end end
pod_targets = distinct_targets.flat_map do |_, target_definitions_by_variant| pod_targets = distinct_targets.flat_map do |_root, target_definitions_by_variant|
if target_definitions_by_variant.count > 1 # Frameworks and libraries can safely co-exist
# There are different sets of subspecs or the spec is used across different platforms target_definitions_by_variant.group_by { |k, _| k.requires_frameworks? }.flat_map do |_, array|
suffixes = scope_suffixes_for_variants(target_definitions_by_variant.keys) if array.count > 1
target_definitions_by_variant.flat_map do |variant, target_definitions| # There are different sets of subspecs or the spec is used across different platforms
generate_pod_target(target_definitions, variant.specs, :scope_suffix => suffixes[variant]) 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 = *array.first
generate_pod_target(target_definitions, variant.specs)
end end
else
variant, target_definitions = *target_definitions_by_variant.first
generate_pod_target(target_definitions, variant.specs)
end end
end end
else else
......
...@@ -11,6 +11,11 @@ module Pod ...@@ -11,6 +11,11 @@ module Pod
# #
attr_accessor :platform 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 # @return [Specification] the root specification
# #
def root_spec def root_spec
...@@ -19,10 +24,12 @@ module Pod ...@@ -19,10 +24,12 @@ module Pod
# @param [Array<String>] specs @see #specs # @param [Array<String>] specs @see #specs
# @param [Platform] platform @see #platform # @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.specs = specs
self.platform = platform self.platform = platform
self.requires_frameworks = requires_frameworks
end end
# @return [Bool] whether the {PodVariant} is equal to another taking all # @return [Bool] whether the {PodVariant} is equal to another taking all
...@@ -31,7 +38,8 @@ module Pod ...@@ -31,7 +38,8 @@ module Pod
def ==(other) def ==(other)
self.class == other.class && self.class == other.class &&
specs == other.specs && specs == other.specs &&
platform == other.platform platform == other.platform &&
requires_frameworks == other.requires_frameworks
end end
alias_method :eql?, :== alias_method :eql?, :==
...@@ -41,7 +49,7 @@ module Pod ...@@ -41,7 +49,7 @@ module Pod
# #
# @!visibility private # @!visibility private
def hash def hash
[specs, platform].hash [specs, platform, requires_frameworks].hash
end end
end end
end end
......
...@@ -286,6 +286,33 @@ module Pod ...@@ -286,6 +286,33 @@ module Pod
} }
end 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 it "doesn't deduplicate targets when deduplication is disabled" do
podfile = Pod::Podfile.new do podfile = Pod::Podfile.new do
install! 'cocoapods', :deduplicate_targets => false 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