Skip to content

Commit

Permalink
Merge pull request #218 from CocoaPods/seg-module-map
Browse files Browse the repository at this point in the history
[Specification] Allow specifying a custom module map file
  • Loading branch information
mrackwitz committed Apr 9, 2015
2 parents b609fa0 + e3cb379 commit 971a8c4
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
[Samuel Giddins](https://github.com/segiddins)
[#221](https://github.com/CocoaPods/Core/issues/221)

* Allow specifying a custom module map file.
[Samuel Giddins](https://github.com/segiddins)
[Marius Rackwitz](https://github.com/mrackwitz)
[#218](https://github.com/CocoaPods/Coore/issues/218)

##### Bug Fixes

* The linter will now ensure that subspecs' names do not contain whitespace.
Expand Down
22 changes: 22 additions & 0 deletions lib/cocoapods-core/specification/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,28 @@ def dependency(*args)
:file_patterns => true,
:singularize => true

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

# @!method module_map=(module_map)
#
# The module map file that should be used when this pod is integrated as
# a framework.
#
# ---
#
# By default, CocoaPods creates a module map file based upon the public
# headers in a specification.
#
# @example
#
# spec.module_map = "source/module.modulemap"
#
# @param [String] module_map
# the path to the module map file that should be used.
#
attribute :module_map,
:root_only => true

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

# @!group Subspecs
Expand Down
4 changes: 0 additions & 4 deletions lib/cocoapods-core/specification/linter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,6 @@ def _validate_authors(a)
'from default')
end
end

if a.empty?
results.add_error('authors', 'The authors are unspecified.')
end
end

def _validate_version(v)
Expand Down
7 changes: 7 additions & 0 deletions lib/cocoapods-core/specification/root_attribute_accessors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ def deprecated?
deprecated || !deprecated_in_favor_of.nil?
end

# @return [String, Nil] The custom module map file of the Pod,
# if specified.
#
def module_map
attributes_hash['module_map']
end

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

private
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 @@ -253,6 +253,11 @@ module Pod
@spec.module_name = 'Three20'
@spec.attributes_hash['module_name'].should == 'Three20'
end

it 'allows to specify a custom module map file' do
@spec.module_map = 'module.modulemap'
@spec.attributes_hash['module_map'].should == 'module.modulemap'
end
end

#-----------------------------------------------------------------------------#
Expand Down
62 changes: 54 additions & 8 deletions spec/specification/linter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,42 @@ module Pod
@podspec_path = fixture(@fixture_path)
@linter = Specification::Linter.new(@podspec_path)
@spec = @linter.spec
@results = nil
end

def result_should_include(*values)
def results
@linter.lint
results = @linter.results
@results ||= @linter.results.map { |x| x }
end

def result_ignore(*values)
results.reject! do |result|
values.all? do |value|
result.to_s.downcase.include?(value.downcase)
end
end
end

def result_should_include(*values)
matched = results.select do |result|
values.all? do |value|
result.to_s.downcase.include?(value.downcase)
end
end

matched.size.should == 1
matched.should.satisfy("Expected #{values.inspect} " \
"but none of those results matched:\n" \
"#{results.map(&:to_s)}") do |m|
m.count > 0
end

matched.should.satisfy("Expected #{values.inspect} " \
"found matches:\n" \
"#{matched.map(&:to_s)}\n" \
"but unexpected results appeared:\n" \
"#{(results - matched).map(&:to_s)}") do |m|
m.count == results.count
end
end
end

Expand All @@ -132,6 +155,7 @@ def result_should_include(*values)

it 'checks for unknown keys in the license' do
@spec.license = { :name => 'MIT' }
result_ignore('license', 'missing', 'type')
result_should_include('license', 'unrecognized `name` key')
end

Expand All @@ -154,11 +178,13 @@ def result_should_include(*values)

it 'fails a specification whose name contains whitespace' do
@spec.name = 'bad name'
result_ignore('name', 'match')
result_should_include('name', 'whitespace')
end

it 'fails a specification whose name contains a slash' do
@spec.name = 'BananaKit/BananaFruit'
result_ignore('name', 'match')
result_should_include('name', 'slash')
end

Expand All @@ -171,12 +197,12 @@ def result_should_include(*values)

it 'fails a specification whose authors are an empty hash' do
@spec.stubs(:authors).returns({})
result_should_include('author', 'unspecified')
result_should_include('author', 'required')
end

it 'fails a specification whose authors are an empty array' do
@spec.stubs(:authors).returns([])
result_should_include('author', 'unspecified')
result_should_include('author', 'required')
end

#------------------#
Expand All @@ -194,6 +220,14 @@ def result_should_include(*values)

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

it 'passes a specification with a module map' do
@spec.module_map = 'module.modulemap'
@linter.lint
@linter.results.count.should == 0
end

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

it 'checks that the version has been specified' do
@spec.stubs(:version).returns(Pod::Version.new(nil))
result_should_include('version', 'required')
Expand Down Expand Up @@ -285,6 +319,7 @@ def result_should_include(*values)
it 'checks that the commit is not specified as `HEAD`' do
@spec.stubs(:version).returns(Version.new '0.0.1')
@spec.stubs(:source).returns(:git => 'http://repo.git', :commit => 'HEAD')
result_ignore('Git sources should specify a tag.')
result_should_include('source', 'HEAD')
end

Expand Down Expand Up @@ -470,20 +505,31 @@ def result_should_include(*values)

behaves_like 'Linter'

before do
@subspec = @spec.subspecs.first
end

it 'fails a subspec whose name contains whitespace' do
@spec.subspecs.each { |ss| ss.name = 'bad name' }
@subspec.name = 'bad name'
result_should_include('name', 'whitespace')
end

it 'fails a subspec whose name begins with a `.`' do
@spec.subspecs.each { |ss| ss.name = '.badname' }
@subspec.name = '.badname'
result_should_include('name', 'period')
end

it 'fails a specification whose name contains a slash' do
@spec.name = 'BananaKit/BananaFruit'
@subspec.name = 'BananaKit/BananaFruit'
result_should_include('name', 'slash')
end

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

it 'fails a specification with a subspec with a module map' do
@subspec.module_map = 'subspec.modulemap'
result_should_include('module_map', 'can\'t set', 'for subspecs')
end
end
end
end
5 changes: 5 additions & 0 deletions spec/specification/root_attribute_accessors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,10 @@ module Pod

@spec.deprecated?.should == false
end

it 'returns the custom module map file, if specified' do
@spec.module_map = 'module.modulemap'
@spec.module_map.should == 'module.modulemap'
end
end
end

0 comments on commit 971a8c4

Please sign in to comment.