2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2012-12-09 19:40:39 -05:00
|
|
|
require 'rubygems/test_case'
|
|
|
|
require 'rubygems/ext'
|
|
|
|
|
|
|
|
class TestGemExtCmakeBuilder < Gem::TestCase
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
2016-03-03 19:29:40 -05:00
|
|
|
# Details: https://github.com/rubygems/rubygems/issues/1270#issuecomment-177368340
|
|
|
|
skip "CmakeBuilder doesn't work on Windows." if Gem.win_platform?
|
|
|
|
|
2020-05-08 01:27:41 -04:00
|
|
|
begin
|
|
|
|
_, status = Open3.capture2e('cmake')
|
2020-05-10 01:18:25 -04:00
|
|
|
skip 'cmake not present' unless status.success?
|
2020-05-08 01:27:41 -04:00
|
|
|
rescue Errno::ENOENT
|
|
|
|
skip 'cmake not present'
|
|
|
|
end
|
2012-12-09 19:40:39 -05:00
|
|
|
|
|
|
|
@ext = File.join @tempdir, 'ext'
|
|
|
|
@dest_path = File.join @tempdir, 'prefix'
|
|
|
|
|
|
|
|
FileUtils.mkdir_p @ext
|
|
|
|
FileUtils.mkdir_p @dest_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_self_build
|
|
|
|
File.open File.join(@ext, 'CMakeLists.txt'), 'w' do |cmakelists|
|
2020-04-20 12:32:51 -04:00
|
|
|
cmakelists.write <<-EO_CMAKE
|
2015-01-09 09:20:10 -05:00
|
|
|
cmake_minimum_required(VERSION 2.6)
|
2019-01-22 01:28:04 -05:00
|
|
|
project(self_build NONE)
|
2012-12-09 19:40:39 -05:00
|
|
|
install (FILES test.txt DESTINATION bin)
|
2020-04-20 12:32:51 -04:00
|
|
|
EO_CMAKE
|
2012-12-09 19:40:39 -05:00
|
|
|
end
|
2012-12-17 22:16:27 -05:00
|
|
|
|
|
|
|
FileUtils.touch File.join(@ext, 'test.txt')
|
2012-12-09 19:40:39 -05:00
|
|
|
|
|
|
|
output = []
|
|
|
|
|
2020-12-08 02:33:39 -05:00
|
|
|
Gem::Ext::CmakeBuilder.build nil, @dest_path, output, [], nil, @ext
|
2012-12-09 19:40:39 -05:00
|
|
|
|
2012-12-17 22:16:27 -05:00
|
|
|
output = output.join "\n"
|
|
|
|
|
|
|
|
assert_match \
|
2020-03-24 14:51:43 -04:00
|
|
|
%r{^cmake \. -DCMAKE_INSTALL_PREFIX=#{Regexp.escape @dest_path}}, output
|
|
|
|
assert_match %r{#{Regexp.escape @ext}}, output
|
2013-06-25 09:28:57 -04:00
|
|
|
assert_contains_make_command '', output
|
|
|
|
assert_contains_make_command 'install', output
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{test\.txt}, output
|
2012-12-09 19:40:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_self_build_fail
|
|
|
|
output = []
|
|
|
|
|
|
|
|
error = assert_raises Gem::InstallError do
|
2020-12-08 02:33:39 -05:00
|
|
|
Gem::Ext::CmakeBuilder.build nil, @dest_path, output, [], nil, @ext
|
2012-12-09 19:40:39 -05:00
|
|
|
end
|
|
|
|
|
2012-12-17 22:16:27 -05:00
|
|
|
output = output.join "\n"
|
|
|
|
|
2012-12-09 19:40:39 -05:00
|
|
|
shell_error_msg = %r{(CMake Error: .*)}
|
|
|
|
sh_prefix_cmake = "cmake . -DCMAKE_INSTALL_PREFIX="
|
|
|
|
|
2013-10-15 20:14:16 -04:00
|
|
|
assert_match 'cmake failed', error.message
|
2012-12-09 19:40:39 -05:00
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{^#{sh_prefix_cmake}#{Regexp.escape @dest_path}}, output
|
|
|
|
assert_match %r{#{shell_error_msg}}, output
|
2012-12-09 19:40:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_self_build_has_makefile
|
|
|
|
File.open File.join(@ext, 'Makefile'), 'w' do |makefile|
|
2013-10-15 20:43:14 -04:00
|
|
|
makefile.puts "all:\n\t@echo ok\ninstall:\n\t@echo ok"
|
2012-12-09 19:40:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
output = []
|
2012-12-17 22:16:27 -05:00
|
|
|
|
2020-12-08 02:33:39 -05:00
|
|
|
Gem::Ext::CmakeBuilder.build nil, @dest_path, output, [], nil, @ext
|
2012-12-09 19:40:39 -05:00
|
|
|
|
2012-12-17 22:16:27 -05:00
|
|
|
output = output.join "\n"
|
|
|
|
|
2013-06-25 09:28:57 -04:00
|
|
|
assert_contains_make_command '', output
|
|
|
|
assert_contains_make_command 'install', output
|
2012-12-09 19:40:39 -05:00
|
|
|
end
|
|
|
|
end
|