2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2021-06-01 23:32:47 -04:00
|
|
|
require_relative 'helper'
|
2012-12-09 19:40:39 -05:00
|
|
|
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
|
2021-05-10 23:27:07 -04:00
|
|
|
pend "CmakeBuilder doesn't work on Windows." if Gem.win_platform?
|
2016-03-03 19:29:40 -05:00
|
|
|
|
2020-05-08 01:27:41 -04:00
|
|
|
begin
|
|
|
|
_, status = Open3.capture2e('cmake')
|
2021-05-10 23:27:07 -04:00
|
|
|
pend 'cmake not present' unless status.success?
|
2020-05-08 01:27:41 -04:00
|
|
|
rescue Errno::ENOENT
|
2021-05-10 23:27:07 -04:00
|
|
|
pend 'cmake not present'
|
2020-05-08 01:27:41 -04:00
|
|
|
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"
|
|
|
|
|
2021-01-03 20:09:05 -05:00
|
|
|
assert_match %r{^cmake \. -DCMAKE_INSTALL_PREFIX\\=#{Regexp.escape @dest_path}}, output
|
2020-03-24 14:51:43 -04:00
|
|
|
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 = []
|
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
error = assert_raise 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: .*)}
|
|
|
|
|
2013-10-15 20:14:16 -04:00
|
|
|
assert_match 'cmake failed', error.message
|
2012-12-09 19:40:39 -05:00
|
|
|
|
2021-01-03 20:09:05 -05:00
|
|
|
assert_match %r{^cmake . -DCMAKE_INSTALL_PREFIX\\=#{Regexp.escape @dest_path}}, output
|
2020-03-24 14:51:43 -04:00
|
|
|
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
|