Commit 78e90aa2 authored by Marius Rackwitz's avatar Marius Rackwitz

Deduplicate pod targets

parent 279ff119
......@@ -57,13 +57,19 @@ module Pod
if target.requires_frameworks?
# Framework headers are automatically discoverable by `#import <…>`.
header_search_paths = pod_targets.map { |target| "$PODS_FRAMEWORK_BUILD_PATH/#{target.product_name}/Headers" }
header_search_paths = pod_targets.map do |target|
if target.scoped?
"$PODS_FRAMEWORK_BUILD_PATH/#{target.product_name}/Headers"
else
"$CONFIGURATION_BUILD_DIR/#{target.product_name}/Headers"
end
end
build_settings = {
'PODS_FRAMEWORK_BUILD_PATH' => target.configuration_build_dir,
# Make headers discoverable by `import "…"`
'OTHER_CFLAGS' => '$(inherited) ' + XCConfigHelper.quote(header_search_paths, '-iquote'),
}
if target.pod_targets.any?(&:should_build?)
if target.pod_targets.any? { |t| t.should_build? && t.scoped? }
build_settings['FRAMEWORK_SEARCH_PATHS'] = '$(inherited) "$PODS_FRAMEWORK_BUILD_PATH"'
end
config.merge!(build_settings)
......
......@@ -60,13 +60,13 @@ module Pod
# 'USE_HEADERMAP' => 'NO'
}
if target.requires_frameworks?
if target.requires_frameworks? && target.scoped?
# Only quote the FRAMEWORK_SEARCH_PATHS entry, because it’s a setting that takes multiple values.
# In addition, quoting CONFIGURATION_BUILD_DIR would make it be interpreted as a relative path.
build_settings = {
'PODS_FRAMEWORK_BUILD_PATH' => target.configuration_build_dir,
'CONFIGURATION_BUILD_DIR' => '$PODS_FRAMEWORK_BUILD_PATH',
'FRAMEWORK_SEARCH_PATHS' => '"$PODS_FRAMEWORK_BUILD_PATH"',
'CONFIGURATION_BUILD_DIR' => '$PODS_FRAMEWORK_BUILD_PATH',
}
config.merge!(build_settings)
end
......
......@@ -220,7 +220,7 @@ module Pod
def generate_targets
targets = []
result.specs_by_target.each do |target_definition, specs|
targets << generate_target(target_definition, specs)
targets << generate_target(target_definition, specs, targets.map(&:pod_targets).flatten)
end
targets
end
......@@ -234,9 +234,12 @@ module Pod
# the specifications that need to be installed grouped by the
# given target definition.
#
# @param [Array<PodTarget>] pod_targets
# the pod targets, which were generated so far.
#
# @return [AggregateTarget]
#
def generate_target(target_definition, specs)
def generate_target(target_definition, specs, pod_targets)
target = AggregateTarget.new(target_definition, sandbox)
target.host_requires_frameworks |= target_definition.uses_frameworks?
......@@ -259,7 +262,7 @@ module Pod
end
end
target.pod_targets = generate_pod_targets(target, specs)
target.pod_targets = generate_pod_targets(target, specs, pod_targets)
target
end
......@@ -273,12 +276,29 @@ module Pod
# @param [Array<Specification>] specs
# the specifications that need to be installed.
#
# @param [Array<PodTarget>] pod_targets
# the pod targets, which were generated so far.
#
# @return [Array<PodTarget>]
#
def generate_pod_targets(target, specs)
def generate_pod_targets(target, specs, pod_targets)
grouped_specs = specs.group_by(&:root).values.uniq
grouped_specs.map do |pod_specs|
generate_pod_target(target, pod_specs)
# If there are no or already multiple pod targets with a common root,
# or the one which exists differs in the activated subspec set, then
# we need to generate another pod target
root_spec = pod_specs.first.root
common_root_pod_targets = pod_targets.select { |t| t.root_spec == root_spec }
if common_root_pod_targets.count != 1 || common_root_pod_targets.first.specs != pod_specs
pod_target = generate_pod_target(target, pod_specs)
unless common_root_pod_targets.empty?
common_root_pod_targets.each { |t| t.scoped = true }
pod_target.scoped = true
end
pod_target
else
common_root_pod_targets.first
end
end
end
......
......@@ -130,7 +130,7 @@ module Pod
bundle_target.build_configurations.each do |c|
c.build_settings['PRODUCT_NAME'] = bundle_name
if target.requires_frameworks?
if target.requires_frameworks? && target.scoped?
c.build_settings['CONFIGURATION_BUILD_DIR'] = target.configuration_build_dir
end
end
......
......@@ -3,7 +3,7 @@ module Pod
# A pod can have one or more activated spec/subspecs.
#
class PodTarget < Target
# @return [Specification] the spec for the target.
# @return [Array<Specification>] the spec and subspecs for the target.
#
attr_reader :specs
......@@ -11,6 +11,12 @@ module Pod
#
attr_reader :build_headers
# @return [Bool] whether the target needs to be scoped by target definition,
# because the spec is used with different subspec sets across them.
#
attr_accessor :scoped
alias_method :scoped?, :scoped
# @param [Specification] spec @see spec
# @param [TargetDefinition] target_definition @see target_definition
# @param [Sandbox] sandbox @see sandbox
......@@ -27,7 +33,11 @@ module Pod
# @return [String] the label for the target.
#
def label
"#{target_definition.label}-#{root_spec.name}"
if scoped?
"#{target_definition.label}-#{root_spec.name}"
else
root_spec.name
end
end
# @return [String] The name to use for the source code module constructed
......
......@@ -13,6 +13,11 @@ module Pod
pod 'AFNetworking', '1.0.1'
pod 'SVPullToRefresh', '0.4'
pod 'libextobjc/EXTKeyPathCoding', '0.2.3'
target 'TestRunner' do
pod 'libextobjc/EXTKeyPathCoding', '0.2.3'
pod 'libextobjc/EXTSynthesize', '0.2.3'
end
end
hash = {}
......@@ -44,7 +49,7 @@ module Pod
it 'computes the state of the Podfile respect to the Lockfile' do
state = @analyzer.analyze.podfile_state
state.added.should == %w(AFNetworking libextobjc/EXTKeyPathCoding)
state.added.should == %w(AFNetworking libextobjc/EXTKeyPathCoding libextobjc/EXTSynthesize)
state.changed.should == %w()
state.unchanged.should == %w(JSONKit SVPullToRefresh)
state.deleted.should == %w(NUI)
......@@ -87,12 +92,12 @@ module Pod
#--------------------------------------#
it 'generates the libraries which represent the target definitions' do
it 'generates the model to represent the target definitions' do
target = @analyzer.analyze.targets.first
target.pod_targets.map(&:name).sort.should == [
'Pods-JSONKit',
'Pods-AFNetworking',
'Pods-SVPullToRefresh',
'JSONKit',
'AFNetworking',
'SVPullToRefresh',
'Pods-libextobjc',
].sort
target.support_files_dir.should == config.sandbox.target_support_files_dir('Pods')
......@@ -256,6 +261,7 @@ module Pod
'JSONKit (1.5pre)',
'SVPullToRefresh (0.4)',
'libextobjc/EXTKeyPathCoding (0.2.3)',
'libextobjc/EXTSynthesize (0.2.3)',
]
end
......@@ -275,11 +281,18 @@ module Pod
end
it 'adds the specifications to the correspondent libraries' do
@analyzer.analyze.targets.first.pod_targets.map(&:specs).flatten.map(&:to_s).should == [
@analyzer.analyze.targets[0].pod_targets.map(&:specs).flatten.map(&:to_s).should == [
'AFNetworking (1.0.1)',
'JSONKit (1.5pre)',
'SVPullToRefresh (0.4)',
'libextobjc/EXTKeyPathCoding (0.2.3)',
]
@analyzer.analyze.targets[1].pod_targets.map(&:specs).flatten.map(&:to_s).should == [
'AFNetworking (1.0.1)',
'JSONKit (1.5pre)',
'SVPullToRefresh (0.4)',
'libextobjc/EXTKeyPathCoding (0.2.3)',
'libextobjc/EXTSynthesize (0.2.3)',
]
end
......
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