Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/rubygems/ext/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
class Gem::Ext::Builder
include Gem::UserInteraction

class NoMakefileError < Gem::InstallError
end

attr_accessor :build_args # :nodoc:

def self.class_name
Expand All @@ -21,7 +24,8 @@ def self.class_name
def self.make(dest_path, results, make_dir = Dir.pwd, sitedir = nil, targets = ["clean", "", "install"],
target_rbconfig: Gem.target_rbconfig)
unless File.exist? File.join(make_dir, "Makefile")
raise Gem::InstallError, "Makefile not found"
# No makefile exists, nothing to do.
raise NoMakefileError, "No Makefile found in #{make_dir}"
end

# try to find make program from Ruby configure arguments first
Expand Down
4 changes: 4 additions & 0 deletions lib/rubygems/ext/ext_conf_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def self.build(extension, dest_path, results, args=[], lib_dir=nil, extension_di
end

results
rescue Gem::Ext::Builder::NoMakefileError => error
results << error.message
results << "Skipping make for #{extension} as no Makefile was found."
# We are good, do not re-raise the error.
ensure
FileUtils.rm_rf tmp_dest if tmp_dest
end
Expand Down
33 changes: 14 additions & 19 deletions test/rubygems/test_gem_ext_ext_conf_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ def setup
end

def test_class_build
if Gem.java_platform?
pend("failing on jruby")
end

if vc_windows? && !nmake_found?
pend("test_class_build skipped - nmake not found")
end

File.open File.join(@ext, "extconf.rb"), "w" do |extconf|
extconf.puts "return if Gem.java_platform?"
extconf.puts "require 'mkmf'\ncreate_makefile 'foo'"
end

Expand All @@ -35,20 +32,22 @@ def test_class_build

assert_match(/^current directory:/, output[0])
assert_match(/^#{Regexp.quote(Gem.ruby)}.* extconf.rb/, output[1])
assert_equal "creating Makefile\n", output[2]
assert_match(/^current directory:/, output[3])
assert_contains_make_command "clean", output[4]
assert_contains_make_command "", output[7]
assert_contains_make_command "install", output[10]

if Gem.java_platform?
assert_includes(output, "Skipping make for extconf.rb as no Makefile was found.")
else
assert_equal "creating Makefile\n", output[2]
assert_match(/^current directory:/, output[3])
assert_contains_make_command "clean", output[4]
assert_contains_make_command "", output[7]
assert_contains_make_command "install", output[10]
end

assert_empty Dir.glob(File.join(@ext, "siteconf*.rb"))
assert_empty Dir.glob(File.join(@ext, ".gem.*"))
end

def test_class_build_rbconfig_make_prog
if Gem.java_platform?
pend("failing on jruby")
end

configure_args do
File.open File.join(@ext, "extconf.rb"), "w" do |extconf|
extconf.puts "require 'mkmf'\ncreate_makefile 'foo'"
Expand All @@ -72,10 +71,6 @@ def test_class_build_env_make
env_large_make = ENV.delete "MAKE"
ENV["MAKE"] = "anothermake"

if Gem.java_platform?
pend("failing on jruby")
end

configure_args "" do
File.open File.join(@ext, "extconf.rb"), "w" do |extconf|
extconf.puts "require 'mkmf'\ncreate_makefile 'foo'"
Expand Down Expand Up @@ -206,11 +201,11 @@ def test_class_make
end

def test_class_make_no_Makefile
error = assert_raise Gem::InstallError do
error = assert_raise Gem::Ext::Builder::NoMakefileError do
Gem::Ext::ExtConfBuilder.make @ext, ["output"], @ext
end

assert_equal "Makefile not found", error.message
assert_match(/No Makefile found/, error.message)
end

def configure_args(args = nil)
Expand Down