File tree Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 22##
33# Raised when there is an error while building extensions.
44
5+ require 'rubygems/exceptions'
6+
57class Gem ::Ext ::BuildError < Gem ::InstallError
68end
Original file line number Diff line number Diff line change 1+ require 'rubygems/ext'
12require 'rubygems/user_interaction'
23
34class Gem ::SpecificationPolicy
@@ -76,6 +77,8 @@ def validate(strict = false)
7677
7778 validate_dependencies
7879
80+ validate_extensions
81+
7982 validate_removed_attributes
8083
8184 if @warnings > 0
@@ -417,6 +420,17 @@ def validate_removed_attributes # :nodoc:
417420 end
418421 end
419422
423+ def validate_extensions # :nodoc:
424+ builder = Gem ::Ext ::Builder . new ( @specification )
425+
426+ rake_extension = @specification . extensions . any? { |s | builder . builder_for ( s ) == Gem ::Ext ::RakeBuilder }
427+ rake_dependency = @specification . dependencies . any? { |d | d . name == 'rake' }
428+
429+ warning <<-WARNING if rake_extension && !rake_dependency
430+ 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.
431+ WARNING
432+ end
433+
420434 def warning ( statement ) # :nodoc:
421435 @warnings += 1
422436
Original file line number Diff line number Diff line change @@ -2838,6 +2838,37 @@ def test_validate_prerelease_dependencies_with_prerelease_version
28382838 end
28392839 end
28402840
2841+ def test_validate_rake_extension_have_rake_dependency_warning
2842+ util_setup_validate
2843+
2844+ Dir . chdir @tempdir do
2845+ @a1 . extensions = [ 'Rakefile' ]
2846+ File . write File . join ( @tempdir , 'Rakefile' ) , ''
2847+
2848+ use_ui @ui do
2849+ @a1 . validate
2850+ end
2851+
2852+ assert_match ( /add rake as a dependency/ , @ui . error )
2853+ end
2854+ end
2855+
2856+ def test_validate_rake_extension_have_rake_dependency_no_warning
2857+ util_setup_validate
2858+
2859+ Dir . chdir @tempdir do
2860+ @a1 . extensions = [ 'Rakefile' ]
2861+ @a1 . add_runtime_dependency 'rake'
2862+ File . write File . join ( @tempdir , 'Rakefile' ) , ''
2863+
2864+ use_ui @ui do
2865+ @a1 . validate
2866+ end
2867+
2868+ refute_match ( /add rake as a dependency/ , @ui . error )
2869+ end
2870+ end
2871+
28412872 def test_validate_description
28422873 util_setup_validate
28432874
You can’t perform that action at this time.
0 commit comments