Unverified Commit 11f6642a authored by Dimitris Koutsogiorgas's avatar Dimitris Koutsogiorgas Committed by GitHub

Merge pull request #7381 from amorde/missing-license

Warn instead of throwing an exception when dev pod's license file is missing
parents 1828d95c 8126b727
...@@ -25,6 +25,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ...@@ -25,6 +25,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
##### Bug Fixes ##### Bug Fixes
* Warn instead of throwing an exception when a development pod specifies an invalid license file path
[Eric Amorde](https://github.com/amorde)
[#7377](https://github.com/CocoaPods/CocoaPods/issues/7377)
* Better static frameworks transitive dependency error checking * Better static frameworks transitive dependency error checking
[Paul Beusterien](https://github.com/paulb777) [Paul Beusterien](https://github.com/paulb777)
[#7352](https://github.com/CocoaPods/CocoaPods/issues/7352) [#7352](https://github.com/CocoaPods/CocoaPods/issues/7352)
......
...@@ -73,13 +73,16 @@ module Pod ...@@ -73,13 +73,16 @@ module Pod
return nil unless spec.license return nil unless spec.license
text = spec.license[:text] text = spec.license[:text]
unless text unless text
if license_file = file_accessor(spec).license if license_file = spec.license[:file]
if license_file.exist? license_path = file_accessor(spec).root + license_file
text = IO.read(license_file) if File.exist?(license_path)
text = IO.read(license_path)
else else
UI.warn "Unable to read the license file `#{license_file}` " \ UI.warn "Unable to read the license file `#{license_file}` " \
"for the spec `#{spec}`" "for the spec `#{spec}`"
end end
elsif license_file = file_accessor(spec).license
text = IO.read(license_file)
end end
end end
text text
......
...@@ -278,11 +278,7 @@ module Pod ...@@ -278,11 +278,7 @@ module Pod
# specification or auto-detected. # specification or auto-detected.
# #
def license def license
if file = spec_consumer.license[:file] spec_license || path_list.glob([GLOB_PATTERNS[:license]]).first
path_list.root + file
else
path_list.glob([GLOB_PATTERNS[:license]]).first
end
end end
# @return [Pathname, Nil] The path of the custom module map file of the # @return [Pathname, Nil] The path of the custom module map file of the
...@@ -305,17 +301,37 @@ module Pod ...@@ -305,17 +301,37 @@ module Pod
path_list.glob([GLOB_PATTERNS[:docs]]) path_list.glob([GLOB_PATTERNS[:docs]])
end end
# @return [Pathname] The path of the license file specified in the
# specification, if it exists
#
def spec_license
if file = spec_consumer.license[:file]
absolute_path = root + file
absolute_path if File.exist?(absolute_path)
end
end
# @return [Array<Pathname>] Paths to include for local pods to assist in development # @return [Array<Pathname>] Paths to include for local pods to assist in development
# #
def developer_files def developer_files
podspecs = specs podspecs = specs
result = [module_map, prefix_header] result = [module_map, prefix_header]
if license_path = spec_consumer.license[:file]
license_path = root + license_path
unless File.exist?(license_path)
UI.warn "A license was specified in podspec `#{spec.name}` but the file does not exist - #{license_path}"
end
end
if podspecs.size <= 1 if podspecs.size <= 1
result += [license, readme, podspecs, docs] result += [license, readme, podspecs, docs]
else else
# Manually add non-globbing files since there are multiple podspecs in the same folder
result << podspec_file result << podspec_file
if file = spec_consumer.license[:file] if license_file = spec_license
result << root + file absolute_path = root + license_file
result << absolute_path if File.exist?(absolute_path)
end end
end end
result.compact.flatten.sort result.compact.flatten.sort
......
...@@ -211,6 +211,24 @@ module Pod ...@@ -211,6 +211,24 @@ module Pod
@accessor.license.should == @root + 'LICENSE' @accessor.license.should == @root + 'LICENSE'
end end
describe '#spec_license' do
it 'returns the license file of the specification' do
@accessor.spec_license.should == @root + 'LICENSE'
end
it 'does not auto-detect the license' do
FileUtils.cp(@root + 'LICENSE', @root + 'LICENSE_TEMP')
@spec_consumer.stubs(:license).returns({})
@accessor.spec_license.should.be.nil
FileUtils.rm_f(@root + 'LICENSE_TEMP')
end
it 'returns nil if the license file path does not exist' do
@spec_consumer.stubs(:license).returns(:file => 'MISSING_PATH')
@accessor.spec_license.should.be.nil
end
end
it 'returns the docs of the specification' do it 'returns the docs of the specification' do
@accessor.docs.should == [ @accessor.docs.should == [
@root + 'docs/guide1.md', @root + 'docs/guide1.md',
...@@ -241,6 +259,20 @@ module Pod ...@@ -241,6 +259,20 @@ module Pod
] ]
end end
it 'warns when a LICENSE file is specified but the path does not exist' do
@spec_consumer.stubs(:license).returns(:file => 'PathThatDoesNotExist/LICENSE')
@accessor.developer_files.should == [
@root + 'Banana.modulemap',
@root + 'BananaLib.podspec',
@root + 'Classes/BananaLib.pch',
@root + 'LICENSE', # Found by globbing
@root + 'README',
@root + 'docs/guide1.md',
@root + 'docs/subdir/guide2.md',
]
UI.warnings.should.include "A license was specified in podspec `#{@spec_consumer.name}` but the file does not exist - #{@accessor.root + 'PathThatDoesNotExist/LICENSE'}\n"
end
it 'does not return auto-detected developer files when there are multiple podspecs' do it 'does not return auto-detected developer files when there are multiple podspecs' do
@accessor.stubs(:specs).returns([@root + 'BananaLib.podspec', @root + 'OtherLib.podspec']) @accessor.stubs(:specs).returns([@root + 'BananaLib.podspec', @root + 'OtherLib.podspec'])
@accessor.developer_files.should == [ @accessor.developer_files.should == [
......
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