ruby-changes:26226
From: drbrain <ko1@a...>
Date: Mon, 10 Dec 2012 09:40:53 +0900 (JST)
Subject: [ruby-changes:26226] drbrain:r38283 (trunk): * lib/rubygems/ext/cmake_builder.rb: Added a builder for cmake.
drbrain 2012-12-10 09:40:39 +0900 (Mon, 10 Dec 2012) New Revision: 38283 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38283 Log: * 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. Added files: trunk/lib/rubygems/ext/cmake_builder.rb trunk/test/rubygems/test_gem_ext_cmake_builder.rb Modified files: trunk/ChangeLog trunk/lib/rubygems/ext.rb trunk/lib/rubygems/installer.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 38282) +++ ChangeLog (revision 38283) @@ -1,3 +1,10 @@ +Mon Dec 10 09:40:19 2012 Eric Hodel <drbrain@s...> + + * 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@s...> * lib/rubygems/package.rb: Omit directories when packaging gems like Index: lib/rubygems/ext/cmake_builder.rb =================================================================== --- lib/rubygems/ext/cmake_builder.rb (revision 0) +++ lib/rubygems/ext/cmake_builder.rb (revision 38283) @@ -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 Index: lib/rubygems/installer.rb =================================================================== --- lib/rubygems/installer.rb (revision 38282) +++ lib/rubygems/installer.rb (revision 38283) @@ -667,6 +667,8 @@ 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 Index: lib/rubygems/ext.rb =================================================================== --- lib/rubygems/ext.rb (revision 38282) +++ lib/rubygems/ext.rb (revision 38283) @@ -15,4 +15,5 @@ require 'rubygems/ext/configure_builder' require 'rubygems/ext/ext_conf_builder' require 'rubygems/ext/rake_builder' +require 'rubygems/ext/cmake_builder' Index: test/rubygems/test_gem_ext_cmake_builder.rb =================================================================== --- test/rubygems/test_gem_ext_cmake_builder.rb (revision 0) +++ test/rubygems/test_gem_ext_cmake_builder.rb (revision 38283) @@ -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 + -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/