summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosef Šimánek <josef.simanek@gmail.com>2020-05-01 00:55:07 +0200
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2020-06-05 07:32:42 +0900
commitb7adb10e3986ac8334b5f304321dda6f8d135e69 (patch)
treee22dde35930b6beddaa1c20787209b375ba05702
parentf61ee674d8c5871e8e81b1a7f5884635a0ee9803 (diff)
[rubygems/rubygems] Add build warning when rake based extension is present, but rake is not specified as dependency.
https://github.com/rubygems/rubygems/commit/75fe5475b6
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3184
-rw-r--r--lib/rubygems/ext/build_error.rb2
-rw-r--r--lib/rubygems/specification_policy.rb14
-rw-r--r--test/rubygems/test_gem_specification.rb31
3 files changed, 47 insertions, 0 deletions
diff --git a/lib/rubygems/ext/build_error.rb b/lib/rubygems/ext/build_error.rb
index 6dffddb5cc..720f37cf26 100644
--- a/lib/rubygems/ext/build_error.rb
+++ b/lib/rubygems/ext/build_error.rb
@@ -2,5 +2,7 @@
##
# Raised when there is an error while building extensions.
+require 'rubygems/exceptions'
+
class Gem::Ext::BuildError < Gem::InstallError
end
diff --git a/lib/rubygems/specification_policy.rb b/lib/rubygems/specification_policy.rb
index e830d9af48..3a30750056 100644
--- a/lib/rubygems/specification_policy.rb
+++ b/lib/rubygems/specification_policy.rb
@@ -1,3 +1,4 @@
+require 'rubygems/ext'
require 'rubygems/user_interaction'
class Gem::SpecificationPolicy
@@ -76,6 +77,8 @@ class Gem::SpecificationPolicy
validate_dependencies
+ validate_extensions
+
validate_removed_attributes
if @warnings > 0
@@ -417,6 +420,17 @@ http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard li
end
end
+ def validate_extensions # :nodoc:
+ builder = Gem::Ext::Builder.new(@specification)
+
+ rake_extension = @specification.extensions.any? {|s| builder.builder_for(s) == Gem::Ext::RakeBuilder }
+ rake_dependency = @specification.dependencies.any? {|d| d.name == 'rake'}
+
+ warning <<-WARNING if rake_extension && !rake_dependency
+You have specified rake based extension, but rake is not added as dependency. It is recommended to add rake as a dependency since there's no guarantee rake will be already installed.
+ WARNING
+ end
+
def warning(statement) # :nodoc:
@warnings += 1
diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb
index 7b45f0a865..e223171aef 100644
--- a/test/rubygems/test_gem_specification.rb
+++ b/test/rubygems/test_gem_specification.rb
@@ -2838,6 +2838,37 @@ duplicate dependency on c (>= 1.2.3, development), (~> 1.2) use:
end
end
+ def test_validate_rake_extension_have_rake_dependency_warning
+ util_setup_validate
+
+ Dir.chdir @tempdir do
+ @a1.extensions = ['Rakefile']
+ File.write File.join(@tempdir, 'Rakefile'), ''
+
+ use_ui @ui do
+ @a1.validate
+ end
+
+ assert_match(/add rake as a dependency/, @ui.error)
+ end
+ end
+
+ def test_validate_rake_extension_have_rake_dependency_no_warning
+ util_setup_validate
+
+ Dir.chdir @tempdir do
+ @a1.extensions = ['Rakefile']
+ @a1.add_runtime_dependency 'rake'
+ File.write File.join(@tempdir, 'Rakefile'), ''
+
+ use_ui @ui do
+ @a1.validate
+ end
+
+ refute_match(/add rake as a dependency/, @ui.error)
+ end
+ end
+
def test_validate_description
util_setup_validate