1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/rubygems/ext/cmake_builder.rb: Added a builder for cmake.

* lib/rubygems/ext.rb:  ditto.
* lib/rubygems/installer.rb:  ditto.
* test/rubygems/test_gem_ext_cmake_builder.rb:  Test for above.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38283 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
drbrain 2012-12-10 00:40:39 +00:00
parent a16cf580b0
commit f58ff1ba12
5 changed files with 108 additions and 0 deletions

View file

@ -1,3 +1,10 @@
Mon Dec 10 09:40:19 2012 Eric Hodel <drbrain@segment7.net>
* lib/rubygems/ext/cmake_builder.rb: Added a builder for cmake.
* lib/rubygems/ext.rb: ditto.
* lib/rubygems/installer.rb: ditto.
* test/rubygems/test_gem_ext_cmake_builder.rb: Test for above.
Mon Dec 10 09:13:08 2012 Eric Hodel <drbrain@segment7.net>
* lib/rubygems/package.rb: Omit directories when packaging gems like

View file

@ -15,4 +15,5 @@ require 'rubygems/ext/builder'
require 'rubygems/ext/configure_builder'
require 'rubygems/ext/ext_conf_builder'
require 'rubygems/ext/rake_builder'
require 'rubygems/ext/cmake_builder'

View file

@ -0,0 +1,14 @@
class Gem::Ext::CmakeBuilder < Gem::Ext::Builder
def self.build(extension, directory, dest_path, results)
unless File.exist?('Makefile') then
cmd = "cmake . -DCMAKE_INSTALL_PREFIX=#{dest_path}"
cmd << " #{Gem::Command.build_args.join ' '}" unless Gem::Command.build_args.empty?
run cmd, results
end
make dest_path, results
results
end
end

View file

@ -667,6 +667,8 @@ TEXT
when /rakefile/i, /mkrf_conf/i then
ran_rake = true
Gem::Ext::RakeBuilder
when /CMakeLists.txt/ then
Gem::Ext::CmakeBuilder
else
message = "No builder for extension '#{extension}'"
extension_build_error extension_dir, message

View file

@ -0,0 +1,84 @@
require 'rubygems/test_case'
require 'rubygems/ext'
class TestGemExtCmakeBuilder < Gem::TestCase
def setup
super
`cmake #{Gem::Ext::Builder.redirector}`
skip 'cmake not present' unless $?.success?
@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|
cmakelists.write <<-eo_cmake
cmake_minimum_required(VERSION 2.8)
install (FILES test.txt DESTINATION bin)
eo_cmake
end
File.open File.join(@ext, 'test.txt'), 'w' do |testfile|
end
output = []
Dir.chdir @ext do
Gem::Ext::CmakeBuilder.build nil, nil, @dest_path, output
end
assert_equal "cmake . -DCMAKE_INSTALL_PREFIX=#{@dest_path}", output.shift
assert_match(/#{@ext}/, output.shift)
assert_equal make_command, output.shift
assert_equal "", output.shift
assert_equal make_command + " install", output.shift
assert_match(/test\.txt/, output.shift)
end
def test_self_build_fail
output = []
error = assert_raises Gem::InstallError do
Dir.chdir @ext do
Gem::Ext::CmakeBuilder.build nil, nil, @dest_path, output
end
end
shell_error_msg = %r{(CMake Error: .*)}
sh_prefix_cmake = "cmake . -DCMAKE_INSTALL_PREFIX="
expected = %r(cmake failed:
#{Regexp.escape sh_prefix_cmake}#{Regexp.escape @dest_path}
#{shell_error_msg}
)
assert_match expected, error.message
assert_equal "#{sh_prefix_cmake}#{@dest_path}", output.shift
assert_match %r(#{shell_error_msg}), output.shift
assert_equal true, output.empty?
end
def test_self_build_has_makefile
File.open File.join(@ext, 'Makefile'), 'w' do |makefile|
makefile.puts "all:\n\t@echo ok\ninstall:\n\t@echo ok"
end
output = []
Dir.chdir @ext do
Gem::Ext::CmakeBuilder.build nil, nil, @dest_path, output
end
assert_equal make_command, output[0]
assert_equal "#{make_command} install", output[2]
end
end