Skip to content

Commit

Permalink
[Specification::DSL] Introduce default_subspecs
Browse files Browse the repository at this point in the history
Closes CocoaPods#2099
  • Loading branch information
kylef committed May 4, 2014
1 parent bef215b commit 2a47f7a
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 38 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -14,6 +14,10 @@
[Joshua Kalpin][Kapin]
[#50](https://github.com/CocoaPods/Core/pull/122)

* Introduce a new spec attribute `default_subspecs`.
[Kyle Fuller][kylef]
[CocoaPods#2099](https://github.com/CocoaPods/CocoaPods/issues/2099)

## 0.32.1
## 0.32.0

Expand Down
14 changes: 8 additions & 6 deletions lib/cocoapods-core/specification.rb
Expand Up @@ -214,23 +214,25 @@ def subspec_by_name(relative_name)
end
end

# @return [String] the name of the default subspec if provided.
# @return [Array] the name of the default subspecs if provided.
#
def default_subspec

This comment has been minimized.

Copy link
@fabiopelosin

fabiopelosin May 4, 2014

Member

This method should go, and should be replaced by the consumer one.

attributes_hash['default_subspec']
def default_subspecs
attributes_hash['default_subspecs']
end

# Returns the dependencies on subspecs.
#
# @note A specification has a dependency on either the
# {#default_subspec} or each of its children subspecs that are
# {#default_subspecs} or each of its children subspecs that are
# compatible with its platform.
#
# @return [Array<Dependency>] the dependencies on subspecs.
#
def subspec_dependencies(platform = nil)
if default_subspec
specs = [root.subspec_by_name("#{name}/#{default_subspec}")]
if default_subspecs

This comment has been minimized.

Copy link
@fabiopelosin

fabiopelosin May 4, 2014

Member

I meant to say that this should be something like consumer(platform).default_subspecs. If platforms is nil it should sue the available_platforms to enumerare and merge them.

specs = default_subspecs.map do |subspec_name|
root.subspec_by_name("#{name}/#{subspec_name}")
end
else
specs = subspecs.compact
end
Expand Down
16 changes: 11 additions & 5 deletions lib/cocoapods-core/specification/dsl.rb
Expand Up @@ -1192,9 +1192,9 @@ def subspec(name, &block)

#------------------#

# @!method default_subspec=(subspec_name)
# @!method default_subspecs=(subspec_array)
#
# The name of the subspec that should be used as preferred dependency.
# An array of subspecs names that should be used as preferred dependency.
# If not specified a specifications requires all its subspecs as
# dependencies.
#
Expand All @@ -1209,13 +1209,19 @@ def subspec(name, &block)
# they trigger dependencies on other libraries).
#
# @example
#
# spec.default_subspec = 'Core'
#
# @param [String] subspec_name
# the name of the subspec that should be inherited as
# @example
# spec.default_subspecs = 'Core', 'UI'
#
# @param [Array<String>] subspec_names
# An array of subspec names that should be inherited as
# dependency.
#
attribute :default_subspec,
attribute :default_subspecs,
:container => Array,
:singularize => true,
:multi_platform => false

#-----------------------------------------------------------------------#
Expand Down
4 changes: 2 additions & 2 deletions lib/cocoapods-core/specification/dsl/deprecations.rb
Expand Up @@ -5,9 +5,9 @@ module DSL
#
module Deprecations
def preferred_dependency=(name)
self.default_subspec = name
self.default_subspecs = [name]
CoreUI.warn "[#{self}] `preferred_dependency` has been renamed "\
"to `default_subspec`."
"to `default_subspecs`."
end

def singleton_method_added(method)
Expand Down
2 changes: 1 addition & 1 deletion spec/specification/dsl/deprecations_spec.rb
Expand Up @@ -9,7 +9,7 @@ module Pod

it 'warns about the renamed `preferred_dependency`' do
@spec.preferred_dependency = 'args'
@spec.attributes_hash['default_subspec'].should == 'args'
@spec.attributes_hash['default_subspecs'].should == %w(args)
CoreUI.warnings.should.match /preferred_dependency.*default_subspec/
end

Expand Down
12 changes: 6 additions & 6 deletions spec/specification/dsl_spec.rb
Expand Up @@ -322,9 +322,9 @@ module Pod
subspec.name.should == 'Spec/Subspec'
end

it 'allows to specify a preferred dependency' do
@spec.default_subspec = 'Preferred-Subspec'
@spec.attributes_hash['default_subspec'].should == 'Preferred-Subspec'
it 'should allow you to specify a preferred set of dependencies' do
@spec.default_subspecs = 'Preferred-Subspec1', 'Preferred-Subspec2'
@spec.attributes_hash['default_subspecs'].should == %w(Preferred-Subspec1 Preferred-Subspec2)
end

end
Expand Down Expand Up @@ -377,9 +377,9 @@ module Pod
spec.should.respond_to(attr.writer_name)
end
singularized.map { |attr| attr.name.to_s }.sort.should == %w(
authors compiler_flags frameworks libraries preserve_paths
resource_bundles resources screenshots vendored_frameworks
vendored_libraries weak_frameworks
authors compiler_flags default_subspecs frameworks libraries
preserve_paths resource_bundles resources screenshots
vendored_frameworks vendored_libraries weak_frameworks
)
end
end
Expand Down
38 changes: 20 additions & 18 deletions spec/specification_spec.rb
Expand Up @@ -147,14 +147,18 @@ module Pod
s.subspec 'SubspecOSX' do |sp|
sp.platform = :osx
end
s.subspec 'SubspeciOS' do |sp|
sp.platform = :ios
end
end
@subspec = @spec.subspecs[0]
@subspec_osx = @spec.subspecs[1]
@subspec_ios = @spec.subspecs[2]
@subsubspec = @subspec.subspecs.first
end

it 'returns the recursive subspecs' do
@spec.recursive_subspecs.sort_by(&:name).should == [@subspec, @subsubspec, @subspec_osx]
@spec.recursive_subspecs.sort_by(&:name).should == [@subspec, @subsubspec, @subspec_osx, @subspec_ios]
end

it 'returns a subspec given the absolute name' do
Expand All @@ -170,34 +174,30 @@ module Pod
lambda { @spec.subspec_by_name('Pod/Nonexistent') }.should.raise Informative
end

it 'returns the default subspec' do
@spec.default_subspec = 'Subspec'
@spec.default_subspec.should == 'Subspec'
it 'returns the default subspecs' do
@spec.default_subspecs = 'Subspec1', 'Subspec2'
@spec.default_subspecs.should == %w(Subspec1 Subspec2)
end

it 'returns the dependencies on its subspecs' do
@spec.subspec_dependencies.sort.should == [
Dependency.new('Pod/Subspec'),
Dependency.new('Pod/SubspecOSX')]
Dependency.new('Pod/SubspecOSX'),
Dependency.new('Pod/SubspeciOS')]
end

it 'returns the dependencies on its subspecs for a given platform' do
@spec.subspec_dependencies(:ios).should == [
Dependency.new('Pod/Subspec')
Dependency.new('Pod/Subspec'),
Dependency.new('Pod/SubspeciOS'),
]
end

it 'returns a dependency on a default subspec if it is specified' do
@spec.default_subspec = 'Subspec'
it 'returns a dependency on a default subspecs if it is specified' do
@spec.default_subspecs = 'Subspec', 'SubspeciOS'
@spec.subspec_dependencies.should == [
Dependency.new('Pod/Subspec')
]
end

it 'returns a dependency on a default subspec for a subspec' do
@subspec.default_subspec = 'Subsubspec'
@subspec.subspec_dependencies.should == [
Dependency.new('Pod/Subspec/Subsubspec')
Dependency.new('Pod/Subspec'),
Dependency.new('Pod/SubspeciOS'),
]
end

Expand All @@ -220,13 +220,15 @@ module Pod
Dependency.new('AFNetworking'),
Dependency.new('MagicalRecord'),
Dependency.new('Pod/Subspec'),
Dependency.new('Pod/SubspecOSX')]
Dependency.new('Pod/SubspecOSX'),
Dependency.new('Pod/SubspeciOS')]
end

it 'returns all the dependencies for a given platform' do
@spec.all_dependencies(:ios).sort.should == [
Dependency.new('AFNetworking'),
Dependency.new('Pod/Subspec')]
Dependency.new('Pod/Subspec'),
Dependency.new('Pod/SubspeciOS')]
end
end

Expand Down

0 comments on commit 2a47f7a

Please sign in to comment.