Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added Generator#abort! method

git-svn-id: http://mkrf.rubyforge.org/svn/trunk@50 6e48df83-f314-0410-b1e7-e69642b30866
  • Loading branch information...
commit 5dff8d230c5f2c3a0394ae8cf045cf1c0b9bb684 1 parent a3d32f0
kevinclark authored
View
1  CHANGELOG
@@ -1,4 +1,5 @@
= svn
+* [NEW] Added Generator#abort! for when that critical library just isn't there.
* [NEW] Added Zed Shaw's rakehelper lib (from rfuzz, with permission).
* [NEW] Extensions using mkrf can now build properly in RubyGems!
* [NEW] Extension configurations should now be named mkrf_conf.rb to not conflict with the mkmf settings in RubyGems.
View
BIN  examples/trivial/ext/trivial/trivial.bundle
Binary file not shown
View
2  examples/trivial/ext/trivial/trivial.c
@@ -1,5 +1,5 @@
#include "ruby.h"
void Init_trivial() {
- rb_define_class("MyClass", rb_cObject);
+ rb_define_class("Trivial", rb_cObject);
}
View
10 lib/mkrf/generator.rb
@@ -63,6 +63,7 @@ class Generator
# Params:
# * +extension_name+ -- the name of the extension
# * +source_patterns+ -- an array of patterns describing source files to be compiled. ["*.c"] is the default.
+
def initialize(extension_name, source_patterns = ["*.c"], availability_options = {})
@sources = source_patterns
@extension_name = extension_name + ".#{CONFIG['DLEXT']}"
@@ -130,11 +131,17 @@ def logger
@available.logger
end
+ # Logs a fatal error and exits with a non-zero code (defaults to 1)
+ def abort!(str, code = 1)
+ logger.fatal str
+ exit code
+ end
+
def write_rakefile(filename = "Rakefile") # :nodoc:
File.open(filename, "w+") do |f|
f.puts rakefile_contents
end
- @available.logger.info "Rakefile written"
+ logger.info "Rakefile written"
end
def defines_compile_string # :nodoc:
@@ -143,6 +150,7 @@ def defines_compile_string # :nodoc:
def rakefile_contents # :nodoc:
<<-END_RAKEFILE
+# Generated by mkrf
require 'rake/clean'
CLEAN.include('*.o')
View
25 test/unit/test_generator.rb
@@ -1,5 +1,8 @@
require File.dirname(__FILE__) + '/../abstract_unit'
require 'rbconfig'
+# require 'rubygems'
+# require 'mocha'
+# require 'stubba'
# stubb this out so we don't overwrite our test rakefile
module Mkrf
@@ -11,6 +14,11 @@ def write_rakefile(file = "Rakefile")
end
end
+module Kernel
+ def exit(*args)
+ end
+end
+
class TestGenerator < Test::Unit::TestCase
def setup
FileUtils.rm_f 'mkrf.log'
@@ -51,6 +59,23 @@ def test_logging_defaults_to_info_level
assert_match(/WARN/, logs)
end
+ def test_abort_logs_fatal_error
+ generator = Mkrf::Generator.new('testlib') do |g|
+ g.abort! "Fake header wasn't found." unless g.include_header 'fake_header.h'
+ end
+
+ logs = File.open('mkrf.log').read
+ assert_match(/FATAL/, logs)
+ assert_match("Fake header wasn't found.", logs)
+ end
+
+ # Need to figure out how to test this.. mocking doesn't seem to work
+ # def test_abort_exits
+ # generator = Mkrf::Generator.new('testlib') do |g|
+ # g.abort! "Aborting!"
+ # end
+ # end
+
def test_availability_options_accessible_in_initialize
generator = Mkrf::Generator.new('testlib', ['lib/*.c'], {:loaded_libs => 'static_ruby'})
assert_equal ['static_ruby'], generator.available.loaded_libs
Please sign in to comment.
Something went wrong with that request. Please try again.