2012-11-29 01:52:18 -05:00
|
|
|
# coding: UTF-8
|
2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
require 'rubygems/test_case'
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/ext'
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
class TestGemExtExtConfBuilder < Gem::TestCase
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@ext = File.join @tempdir, 'ext'
|
|
|
|
@dest_path = File.join @tempdir, 'prefix'
|
|
|
|
|
|
|
|
FileUtils.mkdir_p @ext
|
|
|
|
FileUtils.mkdir_p @dest_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_build
|
2019-11-11 01:03:57 -05:00
|
|
|
if java_platform?
|
2019-06-01 05:45:11 -04:00
|
|
|
skip("failing on jruby")
|
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
if vc_windows? && !nmake_found?
|
|
|
|
skip("test_class_build skipped - nmake not found")
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf|
|
|
|
|
extconf.puts "require 'mkmf'\ncreate_makefile 'foo'"
|
|
|
|
end
|
|
|
|
|
|
|
|
output = []
|
|
|
|
|
|
|
|
Dir.chdir @ext do
|
2013-07-22 18:46:50 -04:00
|
|
|
result =
|
2018-05-30 09:01:35 -04:00
|
|
|
Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output
|
2013-07-22 18:46:50 -04:00
|
|
|
|
|
|
|
assert_same result, output
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
assert_match(/^current directory:/, output[0])
|
2018-11-21 05:20:47 -05:00
|
|
|
assert_match(/^#{Gem.ruby}.* extconf.rb/, output[1])
|
2015-07-01 17:50:14 -04:00
|
|
|
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]
|
2013-07-09 18:34:58 -04:00
|
|
|
assert_empty Dir.glob(File.join(@ext, 'siteconf*.rb'))
|
2011-01-18 19:08:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_build_rbconfig_make_prog
|
2019-11-11 01:03:57 -05:00
|
|
|
if java_platform?
|
2019-06-01 05:45:11 -04:00
|
|
|
skip("failing on jruby")
|
|
|
|
end
|
|
|
|
|
2014-02-03 19:48:31 -05:00
|
|
|
configure_args do
|
2011-01-18 19:08:49 -05:00
|
|
|
|
2014-02-03 19:48:31 -05:00
|
|
|
File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf|
|
|
|
|
extconf.puts "require 'mkmf'\ncreate_makefile 'foo'"
|
|
|
|
end
|
2011-01-18 19:08:49 -05:00
|
|
|
|
2014-02-03 19:48:31 -05:00
|
|
|
output = []
|
2011-01-18 19:08:49 -05:00
|
|
|
|
2014-02-03 19:48:31 -05:00
|
|
|
Dir.chdir @ext do
|
2018-05-30 09:01:35 -04:00
|
|
|
Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output
|
2014-02-03 19:48:31 -05:00
|
|
|
end
|
2011-01-18 19:08:49 -05:00
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
assert_equal "creating Makefile\n", output[2]
|
|
|
|
assert_contains_make_command 'clean', output[4]
|
|
|
|
assert_contains_make_command '', output[7]
|
|
|
|
assert_contains_make_command 'install', output[10]
|
2014-02-03 19:48:31 -05:00
|
|
|
end
|
2011-01-18 19:08:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_build_env_make
|
2015-10-27 16:18:15 -04:00
|
|
|
env_make = ENV.delete 'MAKE'
|
|
|
|
ENV['MAKE'] = 'anothermake'
|
2011-01-18 19:08:49 -05:00
|
|
|
|
2019-11-11 01:03:57 -05:00
|
|
|
if java_platform?
|
2019-06-01 05:45:11 -04:00
|
|
|
skip("failing on jruby")
|
|
|
|
end
|
|
|
|
|
2014-02-03 19:48:31 -05:00
|
|
|
configure_args '' do
|
|
|
|
File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf|
|
|
|
|
extconf.puts "require 'mkmf'\ncreate_makefile 'foo'"
|
|
|
|
end
|
2011-01-18 19:08:49 -05:00
|
|
|
|
2014-02-03 19:48:31 -05:00
|
|
|
output = []
|
2011-01-18 19:08:49 -05:00
|
|
|
|
2014-02-03 19:48:31 -05:00
|
|
|
assert_raises Gem::InstallError do
|
|
|
|
Dir.chdir @ext do
|
2018-05-30 09:01:35 -04:00
|
|
|
Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output
|
2014-02-03 19:48:31 -05:00
|
|
|
end
|
2011-01-18 19:08:49 -05:00
|
|
|
end
|
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
assert_equal "creating Makefile\n", output[2]
|
|
|
|
assert_contains_make_command 'clean', output[4]
|
2014-02-03 19:48:31 -05:00
|
|
|
end
|
2011-01-18 19:08:49 -05:00
|
|
|
ensure
|
2015-10-27 16:18:15 -04:00
|
|
|
ENV['MAKE'] = env_make
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_build_extconf_fail
|
2009-06-09 17:38:59 -04:00
|
|
|
if vc_windows? && !nmake_found?
|
|
|
|
skip("test_class_build_extconf_fail skipped - nmake not found")
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf|
|
|
|
|
extconf.puts "require 'mkmf'"
|
|
|
|
extconf.puts "have_library 'nonexistent' or abort 'need libnonexistent'"
|
|
|
|
extconf.puts "create_makefile 'foo'"
|
|
|
|
end
|
|
|
|
|
|
|
|
output = []
|
|
|
|
|
2008-10-25 18:58:43 -04:00
|
|
|
error = assert_raises Gem::InstallError do
|
2007-11-10 02:48:56 -05:00
|
|
|
Dir.chdir @ext do
|
2018-05-30 09:01:35 -04:00
|
|
|
Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-10-15 20:14:16 -04:00
|
|
|
assert_equal 'extconf failed, exit code 1', error.message
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
assert_match(/^#{Gem.ruby}.* extconf.rb/, output[1])
|
2015-07-01 17:50:14 -04:00
|
|
|
assert_match(File.join(@dest_path, 'mkmf.log'), output[4])
|
2017-01-23 21:38:57 -05:00
|
|
|
assert_includes(output, "To see why this extension failed to compile, please check the mkmf.log which can be found here:\n")
|
|
|
|
|
|
|
|
assert_path_exists File.join @dest_path, 'mkmf.log'
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_build_extconf_success_without_warning
|
|
|
|
if vc_windows? && !nmake_found?
|
|
|
|
skip("test_class_build_extconf_fail skipped - nmake not found")
|
|
|
|
end
|
|
|
|
|
|
|
|
File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf|
|
|
|
|
extconf.puts "require 'mkmf'"
|
|
|
|
extconf.puts "File.open('mkmf.log', 'w'){|f| f.write('a')}"
|
|
|
|
extconf.puts "create_makefile 'foo'"
|
|
|
|
end
|
|
|
|
|
|
|
|
output = []
|
|
|
|
|
|
|
|
Dir.chdir @ext do
|
2018-05-30 09:01:35 -04:00
|
|
|
Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output
|
2017-01-23 21:38:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
refute_includes(output, "To see why this extension failed to compile, please check the mkmf.log which can be found here:\n")
|
2015-07-01 17:50:14 -04:00
|
|
|
|
2014-02-03 19:48:31 -05:00
|
|
|
assert_path_exists File.join @dest_path, 'mkmf.log'
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2013-07-22 18:46:50 -04:00
|
|
|
def test_class_build_unconventional
|
|
|
|
if vc_windows? && !nmake_found?
|
|
|
|
skip("test_class_build skipped - nmake not found")
|
|
|
|
end
|
|
|
|
|
|
|
|
File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf|
|
|
|
|
extconf.puts <<-'EXTCONF'
|
|
|
|
include RbConfig
|
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
ruby =
|
|
|
|
if ENV['RUBY'] then
|
|
|
|
ENV['RUBY']
|
|
|
|
else
|
|
|
|
ruby_exe = "#{CONFIG['RUBY_INSTALL_NAME']}#{CONFIG['EXEEXT']}"
|
|
|
|
File.join CONFIG['bindir'], ruby_exe
|
|
|
|
end
|
2013-07-22 18:46:50 -04:00
|
|
|
|
|
|
|
open 'Makefile', 'w' do |io|
|
|
|
|
io.write <<-Makefile
|
2013-10-15 20:14:16 -04:00
|
|
|
clean: ruby
|
2013-07-22 18:46:50 -04:00
|
|
|
all: ruby
|
|
|
|
install: ruby
|
|
|
|
|
|
|
|
ruby:
|
|
|
|
\t#{ruby} -e0
|
|
|
|
|
|
|
|
Makefile
|
|
|
|
end
|
|
|
|
EXTCONF
|
|
|
|
end
|
|
|
|
|
|
|
|
output = []
|
|
|
|
|
|
|
|
Dir.chdir @ext do
|
2018-05-30 09:01:35 -04:00
|
|
|
Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output
|
2013-07-22 18:46:50 -04:00
|
|
|
end
|
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
assert_contains_make_command 'clean', output[4]
|
|
|
|
assert_contains_make_command '', output[7]
|
|
|
|
assert_contains_make_command 'install', output[10]
|
2013-07-22 18:46:50 -04:00
|
|
|
assert_empty Dir.glob(File.join(@ext, 'siteconf*.rb'))
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_class_make
|
2009-06-09 17:38:59 -04:00
|
|
|
if vc_windows? && !nmake_found?
|
|
|
|
skip("test_class_make skipped - nmake not found")
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
output = []
|
|
|
|
makefile_path = File.join(@ext, 'Makefile')
|
|
|
|
File.open makefile_path, 'w' do |makefile|
|
2012-11-29 01:52:18 -05:00
|
|
|
makefile.puts "# π"
|
2007-11-10 02:48:56 -05:00
|
|
|
makefile.puts "RUBYARCHDIR = $(foo)$(target_prefix)"
|
|
|
|
makefile.puts "RUBYLIBDIR = $(bar)$(target_prefix)"
|
2013-10-15 20:14:16 -04:00
|
|
|
makefile.puts "clean:"
|
2007-11-10 02:48:56 -05:00
|
|
|
makefile.puts "all:"
|
|
|
|
makefile.puts "install:"
|
|
|
|
end
|
|
|
|
|
|
|
|
Dir.chdir @ext do
|
|
|
|
Gem::Ext::ExtConfBuilder.make @ext, output
|
|
|
|
end
|
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
assert_contains_make_command 'clean', output[1]
|
|
|
|
assert_contains_make_command '', output[4]
|
|
|
|
assert_contains_make_command 'install', output[7]
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_make_no_Makefile
|
2008-10-25 18:58:43 -04:00
|
|
|
error = assert_raises Gem::InstallError do
|
2007-11-10 02:48:56 -05:00
|
|
|
Dir.chdir @ext do
|
|
|
|
Gem::Ext::ExtConfBuilder.make @ext, ['output']
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-10-15 20:14:16 -04:00
|
|
|
assert_equal 'Makefile not found', error.message
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def configure_args(args = nil)
|
2014-02-03 19:48:31 -05:00
|
|
|
configure_args = RbConfig::CONFIG['configure_args']
|
|
|
|
RbConfig::CONFIG['configure_args'] = args if args
|
|
|
|
|
|
|
|
yield
|
|
|
|
|
|
|
|
ensure
|
2018-11-21 05:20:47 -05:00
|
|
|
if configure_args
|
2014-02-03 19:48:31 -05:00
|
|
|
RbConfig::CONFIG['configure_args'] = configure_args
|
|
|
|
else
|
|
|
|
RbConfig::CONFIG.delete 'configure_args'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|