Skip to content

Commit

Permalink
Merge pull request #605 from dnkoutso/no_default_subspecs
Browse files Browse the repository at this point in the history
Allow specifying no default subspecs
  • Loading branch information
dnkoutso authored Dec 4, 2019
2 parents fe19e73 + 066ceef commit 5a3a871
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

##### Enhancements

* Allow specifying no default subspec.
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#584](https://github.com/CocoaPods/Core/issues/584)

* Add `code_coverage` support for scheme DSL.
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#603](https://github.com/CocoaPods/Core/pull/603)
Expand Down
12 changes: 10 additions & 2 deletions lib/cocoapods-core/specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,17 @@ def subspec_by_name(relative_name, raise_if_missing = true, include_non_library_
end
end

# @return [Array<String>] the name of the default subspecs if provided.
# @return [Array<String>, Symbol] the name(s) of the default subspecs if provided or :none for no default subspecs.
#
def default_subspecs
# TODO: remove singular form and update the JSON specs.
Array(attributes_hash['default_subspecs'] || attributes_hash['default_subspec'])
value = Array(attributes_hash['default_subspecs'] || attributes_hash['default_subspec'])
first = value.first
if first == :none || first == 'none'
first.to_sym
else
value
end
end

# Returns the dependencies on subspecs.
Expand All @@ -367,6 +373,8 @@ def default_subspecs
def subspec_dependencies(platform = nil)
specs = if default_subspecs.empty?
subspecs.compact.reject(&:non_library_specification?)
elsif default_subspecs == :none
[]
else
default_subspecs.map do |subspec_name|
root.subspec_by_name("#{name}/#{subspec_name}")
Expand Down
21 changes: 14 additions & 7 deletions lib/cocoapods-core/specification/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1669,9 +1669,12 @@ def app_spec(name = 'App', &block)
# @!method default_subspecs=(subspec_array)
#
# An array of subspecs names that should be used as preferred dependency.
# If not specified a specifications requires all its subspecs as
# If not specified, a specification requires all of its subspecs as
# dependencies.
#
# You may use the value `:none` to specify that none of the subspecs are
# required to compile this pod and that all subspecs are optional.
#
# ---
#
# A Pod should make available the full library by default. Users can
Expand All @@ -1687,17 +1690,21 @@ def app_spec(name = 'App', &block)
# spec.default_subspec = 'Core'
#
# @example
#
# spec.default_subspecs = 'Core', 'UI'
#
# @param [Array<String>] subspec_names
# @example
#
# spec.default_subspecs = :none
#
# @param [Array<String>, String, Symbol] subspec_names
# An array of subspec names that should be inherited as
# dependency.
#
attribute :default_subspecs,
:container => Array,
:singularize => true,
:multi_platform => false,
:root_only => true
root_attribute :default_subspecs,
:container => Array,
:types => [Array, String, Symbol],
:singularize => true

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

Expand Down
4 changes: 2 additions & 2 deletions lib/cocoapods-core/specification/dsl/attribute_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module AttributeSupport
# multi-platform, they don't have inheritance, and they never have a
# default value.
#
# @param [String] name
# @param [Symbol, String] name
# The name of the attribute.
#
# @param [Hash] options
Expand All @@ -36,7 +36,7 @@ def root_attribute(name, options = {})
# Regular attributes in general support inheritance and multi-platform
# values, so resolving them for a given specification is not trivial.
#
# @param [String] name
# @param [Symbol, String] name
# The name of the attribute.
#
# @param [Hash] options
Expand Down
5 changes: 5 additions & 0 deletions spec/specification/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ module Pod
@spec.default_subspecs = 'Preferred-Subspec1', 'Preferred-Subspec2'
@spec.attributes_hash['default_subspecs'].should == %w(Preferred-Subspec1 Preferred-Subspec2)
end

it 'should allow you to specify an empty preferred set of dependencies' do
@spec.default_subspecs = :none
@spec.attributes_hash['default_subspecs'].should == :none
end
end

#-----------------------------------------------------------------------------#
Expand Down
30 changes: 30 additions & 0 deletions spec/specification/json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,36 @@ module Pod
]
end

it 'can load default subspecs from hash' do
hash = {
'name' => 'BananaLib',
'version' => '1.0',
'default_subspecs' => 'BananaLibSubSpec',
'subspecs' => [
{
'name' => 'BananaLibSubSpec',
},
],
}
result = Specification.from_hash(hash)
result.default_subspecs.should == ['BananaLibSubSpec']
end

it 'can load no default subspecs from hash' do
hash = {
'name' => 'BananaLib',
'version' => '1.0',
'default_subspecs' => 'none',
'subspecs' => [
{
'name' => 'BananaLibSubSpec',
},
],
}
result = Specification.from_hash(hash)
result.default_subspecs.should == :none
end

it 'can load test specification from 1.3.0 hash format' do
hash = {
'name' => 'BananaLib',
Expand Down
11 changes: 11 additions & 0 deletions spec/specification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,12 @@ module Pod
spec.default_subspecs.should == %w(Subspec1)
end

it 'supports the specification of the default subspecs as a symbol' do
spec = @spec.dup
spec.default_subspecs = :none
spec.default_subspecs.should == :none
end

it 'returns the dependencies on its subspecs' do
@spec.subspec_dependencies.sort.should == [
Dependency.new('Pod/Subspec', '1.0'),
Expand All @@ -444,6 +450,11 @@ module Pod
]
end

it 'returns no default subspecs if none is specified' do
@spec.default_subspecs = :none
@spec.subspec_dependencies.should.be.empty
end

it 'returns a dependency on a default subspecs if it is specified' do
@spec.default_subspecs = 'Subspec', 'SubspeciOS'
@spec.subspec_dependencies.should == [
Expand Down

0 comments on commit 5a3a871

Please sign in to comment.