Commit 163794e0 authored by Marius Rackwitz's avatar Marius Rackwitz

[PodVariantSet] Take default_subspecs into account

Eventhough this complicates the algorithm, this is supposed to make the generated labels overall more intuitive and consistent in face of changes to declared dependencies.
parent 501eb182
require 'set'
module Pod module Pod
class Installer class Installer
class Analyzer class Analyzer
...@@ -90,15 +92,43 @@ module Pod ...@@ -90,15 +92,43 @@ module Pod
# @return [Hash<PodVariant, String>] # @return [Hash<PodVariant, String>]
# #
def scope_by_specs def scope_by_specs
root_spec = variants.first.root_spec
default_specs = Set.new([root_spec] + root_spec.default_subspecs.map do |subspec_name|
root_spec.subspec_by_name("#{root_spec.name}/#{subspec_name}")
end)
grouped_variants = group_by(&:specs) grouped_variants = group_by(&:specs)
all_spec_variants = grouped_variants.map { |set| set.variants.first.specs } all_spec_variants = grouped_variants.map { |set| set.variants.first.specs }
common_specs = all_spec_variants.reduce(all_spec_variants.first, &:&) common_specs = all_spec_variants.map(&:to_set).flatten.inject(&:&)
omit_common_specs = common_specs.any? && common_specs.proper_superset?(default_specs)
scope_if_necessary(grouped_variants.map(&:scope_by_build_type)) do |variant| scope_if_necessary(grouped_variants.map(&:scope_by_build_type)) do |variant|
subspecs = variant.specs - common_specs specs = variant.specs.to_set
subspec_names = subspecs.map do |spec|
spec.root? ? 'root' : spec.name.split('/')[1..-1].join('_') # The current variant contains all default specs
omit_default_specs = default_specs.any? && default_specs.subset?(specs)
if omit_default_specs
specs -= default_specs
end
# There are common specs, which are different from the default specs
if omit_common_specs
specs -= common_specs
end
spec_names = specs.map do |spec|
spec.root? ? '.root' : spec.name.split('/')[1..-1].join('_')
end.sort end.sort
subspec_names.empty? ? nil : subspec_names.join('-') if spec_names.empty?
omit_common_specs ? '.common' : nil
else
if omit_common_specs
spec_names.unshift('.common')
elsif omit_default_specs
spec_names.unshift('.default')
end
spec_names.reduce('') do |acc, name|
"#{acc}#{acc.empty? || name[0] == '.' ? '' : '-'}#{name}"
end
end
end end
end end
......
...@@ -90,7 +90,11 @@ module Pod ...@@ -90,7 +90,11 @@ module Pod
# #
def label def label
if scoped? if scoped?
"#{root_spec.name}-#{scope_suffix}" if scope_suffix[0] == '.'
"#{root_spec.name}#{scope_suffix}"
else
"#{root_spec.name}-#{scope_suffix}"
end
else else
root_spec.name root_spec.name
end end
......
...@@ -6,6 +6,7 @@ module Pod ...@@ -6,6 +6,7 @@ module Pod
before do before do
@root_spec = fixture_spec('matryoshka/matryoshka.podspec') @root_spec = fixture_spec('matryoshka/matryoshka.podspec')
@default_subspec = @root_spec.subspec_by_name('matryoshka/Outer') @default_subspec = @root_spec.subspec_by_name('matryoshka/Outer')
@inner_subspec = @root_spec.subspec_by_name('matryoshka/Outer/Inner')
@foo_subspec = @root_spec.subspec_by_name('matryoshka/Foo') @foo_subspec = @root_spec.subspec_by_name('matryoshka/Foo')
@bar_subspec = @root_spec.subspec_by_name('matryoshka/Bar') @bar_subspec = @root_spec.subspec_by_name('matryoshka/Bar')
end end
...@@ -43,11 +44,10 @@ module Pod ...@@ -43,11 +44,10 @@ module Pod
it 'returns scopes by subspec names if they qualify' do it 'returns scopes by subspec names if they qualify' do
variants = PodVariantSet.new([ variants = PodVariantSet.new([
PodVariant.new([@root_spec, @default_subspec], Platform.ios), PodVariant.new([@foo_subspec], Platform.ios),
PodVariant.new([@root_spec, @default_subspec, @foo_subspec], Platform.ios), PodVariant.new([@bar_subspec], Platform.ios),
PodVariant.new([@root_spec, @default_subspec, @bar_subspec], Platform.ios),
]) ])
variants.scope_suffixes.values.should == [nil, 'Foo', 'Bar'] variants.scope_suffixes.values.should == %w(Foo Bar)
end end
it 'returns scopes by subspec names if they qualify and handle partial root spec presence well' do it 'returns scopes by subspec names if they qualify and handle partial root spec presence well' do
...@@ -55,53 +55,82 @@ module Pod ...@@ -55,53 +55,82 @@ module Pod
PodVariant.new([@foo_subspec], Platform.ios), PodVariant.new([@foo_subspec], Platform.ios),
PodVariant.new([@root_spec, @bar_subspec], Platform.ios), PodVariant.new([@root_spec, @bar_subspec], Platform.ios),
]) ])
variants.scope_suffixes.values.should == %w(Foo Bar-root) variants.scope_suffixes.values.should == %w(Foo .root-Bar)
end
it 'allows to differentiate between an exclusive variant with a specific subspec and ' \
'an inclusive variant with the default subspecs plus a non-default subspec' do
variants = PodVariantSet.new([
PodVariant.new([@foo_subspec], Platform.ios),
PodVariant.new([@root_spec, @default_subspec, @foo_subspec], Platform.ios),
])
variants.scope_suffixes.values.should == %w(Foo .default-Foo)
end
it 'omits default specs' do
variants = PodVariantSet.new([
PodVariant.new([@root_spec, @default_subspec], Platform.ios),
PodVariant.new([@root_spec, @default_subspec, @foo_subspec], Platform.ios),
PodVariant.new([@root_spec, @default_subspec, @bar_subspec], Platform.ios),
])
variants.scope_suffixes.values.should == [nil, '.default-Foo', '.default-Bar']
end
it 'omits common specs' do
variants = PodVariantSet.new([
PodVariant.new([@root_spec, @default_subspec, @inner_subspec], Platform.ios),
PodVariant.new([@root_spec, @default_subspec, @inner_subspec, @foo_subspec], Platform.ios),
PodVariant.new([@root_spec, @default_subspec, @inner_subspec, @bar_subspec], Platform.ios),
])
variants.scope_suffixes.values.should == %w(.common .common-Foo .common-Bar)
end end
it 'returns scopes by platform names and subspec names if they qualify' do it 'returns scopes by platform names and subspec names if they qualify' do
variants = PodVariantSet.new([ variants = PodVariantSet.new([
PodVariant.new([@root_spec], Platform.ios), PodVariant.new([@root_spec, @default_subspec], Platform.ios),
PodVariant.new([@root_spec], Platform.osx), PodVariant.new([@root_spec, @default_subspec], Platform.osx),
PodVariant.new([@root_spec, @foo_subspec], Platform.ios), PodVariant.new([@root_spec, @default_subspec, @foo_subspec], Platform.ios),
PodVariant.new([@root_spec, @bar_subspec], Platform.osx), PodVariant.new([@root_spec, @default_subspec, @bar_subspec], Platform.osx),
]) ])
variants.scope_suffixes.values.should == %w( variants.scope_suffixes.values.should == %w(
iOS iOS
OSX OSX
Foo .default-Foo
Bar .default-Bar
) )
end end
it 'returns scopes by versioned platform names and subspec names if they qualify' do it 'returns scopes by versioned platform names and subspec names if they qualify' do
variants = PodVariantSet.new([ variants = PodVariantSet.new([
PodVariant.new([@root_spec], Platform.new(:ios, '7.0')), PodVariant.new([@root_spec, @default_subspec], Platform.new(:ios, '7.0')),
PodVariant.new([@root_spec], Platform.ios), PodVariant.new([@root_spec, @default_subspec], Platform.ios),
PodVariant.new([@root_spec], Platform.osx), PodVariant.new([@root_spec, @default_subspec, @foo_subspec], Platform.ios),
PodVariant.new([@root_spec, @bar_subspec], Platform.osx), PodVariant.new([@root_spec, @default_subspec], Platform.osx),
PodVariant.new([@root_spec, @default_subspec, @foo_subspec], Platform.osx),
PodVariant.new([@root_spec, @default_subspec, @bar_subspec], Platform.osx),
]) ])
variants.scope_suffixes.values.should == %w( variants.scope_suffixes.values.should == %w(
iOS7.0 iOS7.0
iOS iOS
OSX OSX
Bar .default-Foo-iOS
.default-Foo-OSX
.default-Bar
) )
end end
it 'returns scopes by built types, versioned platform names and subspec names' do it 'returns scopes by built types, versioned platform names and subspec names' do
variants = PodVariantSet.new([ variants = PodVariantSet.new([
PodVariant.new([@root_spec], Platform.new(:ios, '7.0')), PodVariant.new([@root_spec, @default_subspec], Platform.new(:ios, '7.0')),
PodVariant.new([@root_spec], Platform.ios), PodVariant.new([@root_spec, @default_subspec], Platform.ios),
PodVariant.new([@root_spec], Platform.osx, true), PodVariant.new([@root_spec, @default_subspec], Platform.osx, true),
PodVariant.new([@root_spec, @foo_subspec], Platform.ios), PodVariant.new([@root_spec, @default_subspec, @foo_subspec], Platform.osx, true),
PodVariant.new([@root_spec, @foo_subspec], Platform.osx, true),
]) ])
variants.scope_suffixes.values.should == %w( variants.scope_suffixes.values.should == %w(
library-iOS7.0 library-iOS7.0
library-iOS library-iOS
framework framework
Foo-library .default-Foo
Foo-framework
) )
end end
end end
......
...@@ -131,11 +131,17 @@ module Pod ...@@ -131,11 +131,17 @@ module Pod
#--------------------------------------# #--------------------------------------#
it 'generates the model to represent the target definitions' do it 'generates the model to represent the target definitions' do
target = @analyzer.analyze.targets.first result = @analyzer.analyze
target, test_target = result.targets
test_target.pod_targets.map(&:name).sort.should == %w(
libextobjc-EXTKeyPathCoding-EXTSynthesize
).sort
target.pod_targets.map(&:name).sort.should == %w( target.pod_targets.map(&:name).sort.should == %w(
JSONKit JSONKit
AFNetworking AFNetworking
libextobjc libextobjc-EXTKeyPathCoding
SVPullToRefresh SVPullToRefresh
).sort ).sort
target.support_files_dir.should == config.sandbox.target_support_files_dir('Pods-SampleProject') target.support_files_dir.should == config.sandbox.target_support_files_dir('Pods-SampleProject')
......
...@@ -38,6 +38,13 @@ module Pod ...@@ -38,6 +38,13 @@ module Pod
@pod_target.scoped.first.label.should == 'BananaLib-Pods' @pod_target.scoped.first.label.should == 'BananaLib-Pods'
end end
it 'returns its label' do
@pod_target.label.should == 'BananaLib'
@pod_target.scoped.first.label.should == 'BananaLib-Pods'
spec_scoped_pod_target = @pod_target.scoped.first.tap { |t| t.stubs(:scope_suffix).returns('.default-GreenBanana') }
spec_scoped_pod_target.label.should == 'BananaLib.default-GreenBanana'
end
it 'returns the name of its product' do it 'returns the name of its product' do
@pod_target.product_name.should == 'libBananaLib.a' @pod_target.product_name.should == 'libBananaLib.a'
@pod_target.scoped.first.product_name.should == 'libBananaLib-Pods.a' @pod_target.scoped.first.product_name.should == 'libBananaLib-Pods.a'
......
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