From 338c89fcb3520c905d57d39dedd78010e3747768 Mon Sep 17 00:00:00 2001 From: Wolfgang Lutz Date: Fri, 30 Nov 2018 09:21:23 +0100 Subject: [PATCH 1/7] Improve error messages for podspec dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improves the error message ’Unsupported version requirements' if it is caused by specifying :git or :path in the podspec file. --- lib/cocoapods-core/specification/dsl.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/cocoapods-core/specification/dsl.rb b/lib/cocoapods-core/specification/dsl.rb index 97748c762..275208115 100644 --- a/lib/cocoapods-core/specification/dsl.rb +++ b/lib/cocoapods-core/specification/dsl.rb @@ -677,7 +677,13 @@ def dependency(*args) end end unless version_requirements.all? { |req| req.is_a?(String) } - raise Informative, 'Unsupported version requirements' + unless version_requirements.is_a?(Hash) + version_requirements.each do |requirement| + raise Informative, "Podspecs can only use remote pods as dependencies. :path is not supported" if requirement[:path] != nil + raise Informative, "Podspecs can only use remote pods as dependencies. :git is not supported" if requirement[:git] != nil + end + end + raise Informative, "Unsupported version requirements. #{version_requirements} is not valid." end attributes_hash['dependencies'] ||= {} attributes_hash['dependencies'][name] = version_requirements From e130d0c1aa22c6f3459fc1c65b60c6048426b9d4 Mon Sep 17 00:00:00 2001 From: Wolfgang Lutz Date: Mon, 3 Dec 2018 22:40:47 +0100 Subject: [PATCH 2/7] improve implementation, add tests. --- lib/cocoapods-core/specification/dsl.rb | 15 ++++++++++----- spec/specification/dsl_spec.rb | 14 +++++++++++++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/cocoapods-core/specification/dsl.rb b/lib/cocoapods-core/specification/dsl.rb index 275208115..17f701475 100644 --- a/lib/cocoapods-core/specification/dsl.rb +++ b/lib/cocoapods-core/specification/dsl.rb @@ -677,14 +677,19 @@ def dependency(*args) end end unless version_requirements.all? { |req| req.is_a?(String) } - unless version_requirements.is_a?(Hash) - version_requirements.each do |requirement| - raise Informative, "Podspecs can only use remote pods as dependencies. :path is not supported" if requirement[:path] != nil - raise Informative, "Podspecs can only use remote pods as dependencies. :git is not supported" if requirement[:git] != nil + version_requirements.each do |requirement| + if requirement.is_a?(Hash) + if requirement[:path] != nil + raise Informative, "Podspecs can only use remote pods as dependencies. :path is not supported" + elsif requirement[:git] != nil + raise Informative, "Podspecs can only use remote pods as dependencies. :git is not supported" + end end end - raise Informative, "Unsupported version requirements. #{version_requirements} is not valid." + + raise Informative, "Unsupported version requirements. #{version_requirements.inspect()} is not valid." end + attributes_hash['dependencies'] ||= {} attributes_hash['dependencies'][name] = version_requirements end diff --git a/spec/specification/dsl_spec.rb b/spec/specification/dsl_spec.rb index 9d047b80d..a3128bf1d 100644 --- a/spec/specification/dsl_spec.rb +++ b/spec/specification/dsl_spec.rb @@ -240,7 +240,19 @@ module Pod it 'raises if the requirements are not supported' do should.raise Informative do @spec.dependency('SVProgressHUD', :head) - end.message.should.match /Unsupported version requirements/ + end.message.should.match /Unsupported version requirements. \[\:head\] is not valid/ + end + + it 'raises if the requirements specify :git' do + should.raise Informative do + @spec.dependency('SVProgressHUD', :git => "AnyPath") + end.message.should.match /Podspecs can only use remote pods as dependencies. :git is not supported/ + end + + it 'raises if the requirements specify :path' do + should.raise Informative do + @spec.dependency('SVProgressHUD', :path => "AnyPath") + end.message.should.match /Podspecs can only use remote pods as dependencies. :path is not supported/ end it 'raises when attempting to assign a value to dependency' do From 3a9adbdf5cbeba8b137f8b933ab60b174aaad26e Mon Sep 17 00:00:00 2001 From: Wolfgang Lutz Date: Mon, 3 Dec 2018 22:41:09 +0100 Subject: [PATCH 3/7] add Changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9d8d91c3..d1a387f41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ ##### Enhancements +* Better error messages, if unallowed version requirement is specified in Podspec. + [Wolfgang Lutz][https://github.com/lutzifer] + [#466](https://github.com/CocoaPods/Core/pull/474) + * DSL for `scheme` support. [Dimitris Koutsogiorgas](https://github.com/dnkoutso) [#7577](https://github.com/CocoaPods/CocoaPods/issues/7577) From 3081e04df0793cd76e442333d9abc45922960446 Mon Sep 17 00:00:00 2001 From: Wolfgang Lutz Date: Mon, 3 Dec 2018 22:46:47 +0100 Subject: [PATCH 4/7] fix rubocop issues --- lib/cocoapods-core/specification/dsl.rb | 10 +++++----- spec/specification/dsl_spec.rb | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/cocoapods-core/specification/dsl.rb b/lib/cocoapods-core/specification/dsl.rb index 17f701475..e3b5309b3 100644 --- a/lib/cocoapods-core/specification/dsl.rb +++ b/lib/cocoapods-core/specification/dsl.rb @@ -679,15 +679,15 @@ def dependency(*args) unless version_requirements.all? { |req| req.is_a?(String) } version_requirements.each do |requirement| if requirement.is_a?(Hash) - if requirement[:path] != nil - raise Informative, "Podspecs can only use remote pods as dependencies. :path is not supported" - elsif requirement[:git] != nil - raise Informative, "Podspecs can only use remote pods as dependencies. :git is not supported" + if !requirement[:path].nil? + raise Informative, 'Podspecs can only use remote pods as dependencies. :path is not supported' + elsif !requirement[:git].nil? + raise Informative, 'Podspecs can only use remote pods as dependencies. :git is not supported' end end end - raise Informative, "Unsupported version requirements. #{version_requirements.inspect()} is not valid." + raise Informative, "Unsupported version requirements. #{version_requirements.inspect} is not valid." end attributes_hash['dependencies'] ||= {} diff --git a/spec/specification/dsl_spec.rb b/spec/specification/dsl_spec.rb index a3128bf1d..4ac989943 100644 --- a/spec/specification/dsl_spec.rb +++ b/spec/specification/dsl_spec.rb @@ -245,13 +245,13 @@ module Pod it 'raises if the requirements specify :git' do should.raise Informative do - @spec.dependency('SVProgressHUD', :git => "AnyPath") + @spec.dependency('SVProgressHUD', :git => 'AnyPath') end.message.should.match /Podspecs can only use remote pods as dependencies. :git is not supported/ end it 'raises if the requirements specify :path' do should.raise Informative do - @spec.dependency('SVProgressHUD', :path => "AnyPath") + @spec.dependency('SVProgressHUD', :path => 'AnyPath') end.message.should.match /Podspecs can only use remote pods as dependencies. :path is not supported/ end From e9404438d148483e94442f210a600030e8a52f3f Mon Sep 17 00:00:00 2001 From: Wolfgang Lutz Date: Wed, 5 Dec 2018 21:32:00 +0100 Subject: [PATCH 5/7] format changelog, improve error message --- CHANGELOG.md | 2 +- lib/cocoapods-core/specification/dsl.rb | 4 ++-- spec/specification/dsl_spec.rb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1a387f41..e2fcedcf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ##### Enhancements -* Better error messages, if unallowed version requirement is specified in Podspec. +* Better error messages, if unallowed version requirement is specified in Podspec. [Wolfgang Lutz][https://github.com/lutzifer] [#466](https://github.com/CocoaPods/Core/pull/474) diff --git a/lib/cocoapods-core/specification/dsl.rb b/lib/cocoapods-core/specification/dsl.rb index e3b5309b3..1d71125cf 100644 --- a/lib/cocoapods-core/specification/dsl.rb +++ b/lib/cocoapods-core/specification/dsl.rb @@ -680,9 +680,9 @@ def dependency(*args) version_requirements.each do |requirement| if requirement.is_a?(Hash) if !requirement[:path].nil? - raise Informative, 'Podspecs can only use remote pods as dependencies. :path is not supported' + raise Informative, 'Podspecs cannot specify the source of dependencies. The :path option is not supported. :path can be used in the Podfile instead to override global dependencies.' elsif !requirement[:git].nil? - raise Informative, 'Podspecs can only use remote pods as dependencies. :git is not supported' + raise Informative, 'Podspecs cannot specify the source of dependencies. The :git option is not supported. :git can be used in the Podfile instead to override global dependencies.' end end end diff --git a/spec/specification/dsl_spec.rb b/spec/specification/dsl_spec.rb index 4ac989943..638a810b4 100644 --- a/spec/specification/dsl_spec.rb +++ b/spec/specification/dsl_spec.rb @@ -246,13 +246,13 @@ module Pod it 'raises if the requirements specify :git' do should.raise Informative do @spec.dependency('SVProgressHUD', :git => 'AnyPath') - end.message.should.match /Podspecs can only use remote pods as dependencies. :git is not supported/ + end.message.should.match /Podspecs cannot specify the source of dependencies. The :git option is not supported. :git can be used in the Podfile instead to override global dependencies./ end it 'raises if the requirements specify :path' do should.raise Informative do @spec.dependency('SVProgressHUD', :path => 'AnyPath') - end.message.should.match /Podspecs can only use remote pods as dependencies. :path is not supported/ + end.message.should.match /Podspecs cannot specify the source of dependencies. The :path option is not supported. :path can be used in the Podfile instead to override global dependencies./ end it 'raises when attempting to assign a value to dependency' do From 51d661f77e784de144c159ef4b209bdda015cb9a Mon Sep 17 00:00:00 2001 From: Wolfgang Lutz Date: Thu, 6 Dec 2018 10:50:41 +0100 Subject: [PATCH 6/7] fix linter warnings --- lib/cocoapods-core/specification/dsl.rb | 6 ++++-- spec/specification/dsl_spec.rb | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/cocoapods-core/specification/dsl.rb b/lib/cocoapods-core/specification/dsl.rb index 1d71125cf..2bbf728c9 100644 --- a/lib/cocoapods-core/specification/dsl.rb +++ b/lib/cocoapods-core/specification/dsl.rb @@ -680,9 +680,11 @@ def dependency(*args) version_requirements.each do |requirement| if requirement.is_a?(Hash) if !requirement[:path].nil? - raise Informative, 'Podspecs cannot specify the source of dependencies. The :path option is not supported. :path can be used in the Podfile instead to override global dependencies.' + raise Informative, 'Podspecs cannot specify the source of dependencies. The :path option is not supported.'\ + ' :path can be used in the Podfile instead to override global dependencies.' elsif !requirement[:git].nil? - raise Informative, 'Podspecs cannot specify the source of dependencies. The :git option is not supported. :git can be used in the Podfile instead to override global dependencies.' + raise Informative, 'Podspecs cannot specify the source of dependencies. The :git option is not supported.'\ + ' :git can be used in the Podfile instead to override global dependencies.' end end end diff --git a/spec/specification/dsl_spec.rb b/spec/specification/dsl_spec.rb index 638a810b4..f764a65ef 100644 --- a/spec/specification/dsl_spec.rb +++ b/spec/specification/dsl_spec.rb @@ -246,13 +246,13 @@ module Pod it 'raises if the requirements specify :git' do should.raise Informative do @spec.dependency('SVProgressHUD', :git => 'AnyPath') - end.message.should.match /Podspecs cannot specify the source of dependencies. The :git option is not supported. :git can be used in the Podfile instead to override global dependencies./ + end.message.should.match /Podspecs cannot specify the source of dependencies. The :git option is not supported.\.*/ end it 'raises if the requirements specify :path' do should.raise Informative do @spec.dependency('SVProgressHUD', :path => 'AnyPath') - end.message.should.match /Podspecs cannot specify the source of dependencies. The :path option is not supported. :path can be used in the Podfile instead to override global dependencies./ + end.message.should.match /Podspecs cannot specify the source of dependencies. The :path option is not supported.\.*/ end it 'raises when attempting to assign a value to dependency' do From 0d96cd5c8466d4dc5bb3019bd7eac3e6bd3e0c76 Mon Sep 17 00:00:00 2001 From: Wolfgang Lutz Date: Wed, 19 Dec 2018 09:23:11 +0100 Subject: [PATCH 7/7] wrap params in backticks --- lib/cocoapods-core/specification/dsl.rb | 8 ++++---- spec/specification/dsl_spec.rb | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/cocoapods-core/specification/dsl.rb b/lib/cocoapods-core/specification/dsl.rb index 2bbf728c9..4773367c7 100644 --- a/lib/cocoapods-core/specification/dsl.rb +++ b/lib/cocoapods-core/specification/dsl.rb @@ -680,11 +680,11 @@ def dependency(*args) version_requirements.each do |requirement| if requirement.is_a?(Hash) if !requirement[:path].nil? - raise Informative, 'Podspecs cannot specify the source of dependencies. The :path option is not supported.'\ - ' :path can be used in the Podfile instead to override global dependencies.' + raise Informative, 'Podspecs cannot specify the source of dependencies. The `:path` option is not supported.'\ + ' `:path` can be used in the Podfile instead to override global dependencies.' elsif !requirement[:git].nil? - raise Informative, 'Podspecs cannot specify the source of dependencies. The :git option is not supported.'\ - ' :git can be used in the Podfile instead to override global dependencies.' + raise Informative, 'Podspecs cannot specify the source of dependencies. The `:git` option is not supported.'\ + ' `:git` can be used in the Podfile instead to override global dependencies.' end end end diff --git a/spec/specification/dsl_spec.rb b/spec/specification/dsl_spec.rb index f764a65ef..6f72f9571 100644 --- a/spec/specification/dsl_spec.rb +++ b/spec/specification/dsl_spec.rb @@ -246,13 +246,13 @@ module Pod it 'raises if the requirements specify :git' do should.raise Informative do @spec.dependency('SVProgressHUD', :git => 'AnyPath') - end.message.should.match /Podspecs cannot specify the source of dependencies. The :git option is not supported.\.*/ + end.message.should.match /Podspecs cannot specify the source of dependencies. The `:git` option is not supported.\.*/ end it 'raises if the requirements specify :path' do should.raise Informative do @spec.dependency('SVProgressHUD', :path => 'AnyPath') - end.message.should.match /Podspecs cannot specify the source of dependencies. The :path option is not supported.\.*/ + end.message.should.match /Podspecs cannot specify the source of dependencies. The `:path` option is not supported.\.*/ end it 'raises when attempting to assign a value to dependency' do