[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
This commit is contained in:
Josef Šimánek 2020-05-01 00:55:07 +02:00 коммит произвёл Hiroshi SHIBATA
Родитель f61ee674d8
Коммит b7adb10e39
3 изменённых файлов: 47 добавлений и 0 удалений

Просмотреть файл

@ -2,5 +2,7 @@
##
# Raised when there is an error while building extensions.
require 'rubygems/exceptions'
class Gem::Ext::BuildError < Gem::InstallError
end

Просмотреть файл

@ -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

Просмотреть файл

@ -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