mkrf 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +7 -0
- data/README +11 -10
- data/Rakefile +13 -8
- data/lib/mkrf.rb +1 -1
- data/lib/mkrf/availability.rb +71 -28
- data/lib/mkrf/generator.rb +27 -10
- data/test/abstract_unit.rb +41 -1
- data/test/sample_files/libtrivial/extconf.rb +1 -1
- data/test/sample_files/libtrivial/lib/libtrivial.o +0 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/extconf.rb +1 -1
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/extconf.rb +1 -1
- data/test/test_availability.rb +34 -5
- data/test/test_generator.rb +65 -54
- data/test/test_sample_projects.rb +27 -0
- metadata +5 -8
- data/test/sample_files/libtrivial/Rakefile +0 -31
- data/test/sample_files/libtrivial/libtrivial_so.bundle +0 -0
- data/test/sample_files/libtrivial/mkrf.log +0 -1
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/mkrf.log +0 -1
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/mkrf.log +0 -1
data/CHANGELOG
CHANGED
@@ -1,2 +1,9 @@
|
|
1
|
+
= 0.1.1 8/17/06
|
2
|
+
* [NEW] Logging! [22]
|
3
|
+
* [NEW] Added a description to the extension building task [21]
|
4
|
+
* [NEW] Added additional_code accessor. If you have stuff you want to add to the Rakefile the Generator doesn't provide for, feel free to stick it (in string form!) in here. Yes, I know this smells. If you have a better suggestion, PDI and tell me about it. [20]
|
5
|
+
* [FIXED] Use proper file extensions for libraries. [18]
|
6
|
+
* [FIXED] default source pattern for Generator [17]
|
7
|
+
|
1
8
|
= 0.1.0 6/28/06
|
2
9
|
* First release.
|
data/README
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= mkrf -- making C extensions for Ruby a bit easier
|
2
2
|
|
3
|
-
<tt>mkrf</tt> is intended to replace <tt>mkmf</tt>, a library for
|
3
|
+
<tt>mkrf</tt> is intended to replace <tt>mkmf</tt>, a library for building
|
4
4
|
Makefiles to build C extensions to Ruby. Its major goals are easy code reuse of
|
5
5
|
its <tt>Availability</tt> class and simple, well documented, use of the
|
6
6
|
<tt>Generator</tt> class for Rakefile generation for extensions.
|
@@ -19,11 +19,19 @@ The most basic usage looks like this, with the name of the library to be linked
|
|
19
19
|
as the first argument to <tt>Mkrf::Generator.new</tt>:
|
20
20
|
|
21
21
|
require 'mkrf'
|
22
|
-
Mkrf::Generator.new('
|
22
|
+
Mkrf::Generator.new('libtrivial')
|
23
23
|
|
24
24
|
Extra arguments may be passed to the generator in a block:
|
25
|
+
|
26
|
+
Mkrf::Generator.new('libtrivial) do |g|
|
27
|
+
g.logger.level = Logger::WARN
|
28
|
+
g.include_library('z')
|
29
|
+
end
|
25
30
|
|
26
|
-
|
31
|
+
If the extension does not follow the source in <tt>lib/</tt> / <tt>.c</tt>
|
32
|
+
extension convention, it may be overridden in the constructor:
|
33
|
+
|
34
|
+
Mkrf::Generator.new('libxml', '*.c') do |g|
|
27
35
|
g.include_library('socket','socket')
|
28
36
|
g.include_header('libxml/xmlversion.h',
|
29
37
|
'/opt/include/libxml2',
|
@@ -31,13 +39,6 @@ Extra arguments may be passed to the generator in a block:
|
|
31
39
|
'/usr/include/libxml2')
|
32
40
|
end
|
33
41
|
|
34
|
-
If the extension does not follow the source in <tt>lib/</tt> / <tt>.c</tt>
|
35
|
-
extension convention, it may be overridden in the constructor:
|
36
|
-
|
37
|
-
Mkrf::Generator.new('syck.bundle', '*.c') do |g|
|
38
|
-
g.include_header("st.h")
|
39
|
-
end
|
40
|
-
|
41
42
|
|
42
43
|
== Credits
|
43
44
|
* Jim Weirich for writing Rake
|
data/Rakefile
CHANGED
@@ -34,7 +34,7 @@ namespace :test do
|
|
34
34
|
BASE_DIR = File.dirname(__FILE__) + '/test/sample_files'
|
35
35
|
|
36
36
|
SAMPLE_DIRS = {
|
37
|
-
:
|
37
|
+
:trivial => BASE_DIR + '/libtrivial/',
|
38
38
|
:syck => BASE_DIR + '/syck-0.55/ext/ruby/ext/syck/',
|
39
39
|
:libxml => BASE_DIR + '/libxml-ruby-0.3.8/ext/xml/'
|
40
40
|
}
|
@@ -42,11 +42,11 @@ namespace :test do
|
|
42
42
|
task :default => [:all]
|
43
43
|
|
44
44
|
desc "Try to compile all of the sample extensions"
|
45
|
-
task :all => [:
|
45
|
+
task :all => [:trivial, :libxml, :syck]
|
46
46
|
|
47
47
|
desc "Try to compile a trivial extension"
|
48
48
|
task :trivial do
|
49
|
-
sh "cd #{SAMPLE_DIRS[:
|
49
|
+
sh "cd #{SAMPLE_DIRS[:trivial]}; ruby extconf.rb; rake"
|
50
50
|
end
|
51
51
|
|
52
52
|
desc "Try to compile libxml"
|
@@ -60,11 +60,16 @@ namespace :test do
|
|
60
60
|
end
|
61
61
|
|
62
62
|
desc "Clean up after sample tests"
|
63
|
-
task :
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
63
|
+
task :clobber do
|
64
|
+
if ENV['PROJECT']
|
65
|
+
if File.exist?(SAMPLE_DIRS[ENV['PROJECT'].to_sym] + "/Rakefile")
|
66
|
+
sh "cd #{SAMPLE_DIRS[ENV['PROJECT'].to_sym]}; rake clobber; rm Rakefile"
|
67
|
+
end
|
68
|
+
else
|
69
|
+
SAMPLE_DIRS.each_value do |test_dir|
|
70
|
+
next unless File.exist?(test_dir + "/Rakefile")
|
71
|
+
sh "cd #{test_dir}; rake clobber; rm Rakefile"
|
72
|
+
end
|
68
73
|
end
|
69
74
|
end
|
70
75
|
|
data/lib/mkrf.rb
CHANGED
data/lib/mkrf/availability.rb
CHANGED
@@ -15,7 +15,7 @@ module Mkrf
|
|
15
15
|
TEMP_SOURCE_FILE = "temp_source.c"
|
16
16
|
TEMP_EXECUTABLE = "temp_executable"
|
17
17
|
|
18
|
-
attr_reader :headers, :loaded_libs, :includes
|
18
|
+
attr_reader :headers, :loaded_libs, :includes, :logger
|
19
19
|
|
20
20
|
# Create a new Availability instance.
|
21
21
|
#
|
@@ -59,10 +59,9 @@ module Mkrf
|
|
59
59
|
# * <tt>library</tt> -- the library to be included as a string
|
60
60
|
# * <tt>function</tt> -- a method to base the inclusion of the library on. +main+ by default.
|
61
61
|
def has_library?(library, function = "main")
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
}
|
62
|
+
logger.info "Checking for library: #{library}"
|
63
|
+
return true if library_already_loaded?(library)
|
64
|
+
found_library?(library, function)
|
66
65
|
end
|
67
66
|
|
68
67
|
# Returns +true+ if the header is found in the default search path or in
|
@@ -72,23 +71,9 @@ module Mkrf
|
|
72
71
|
# * <tt>header</tt> -- the header to be searched for
|
73
72
|
# * <tt>paths</tt> -- an optional list of search paths if the header is not found in the default paths
|
74
73
|
def has_header?(header, *paths)
|
75
|
-
return true if
|
76
|
-
|
77
|
-
|
78
|
-
can_link?(simple_include(header))
|
79
|
-
}
|
80
|
-
|
81
|
-
return true if has_header
|
82
|
-
|
83
|
-
paths.each do |include_path|
|
84
|
-
has_header = with_includes(include_path) {
|
85
|
-
with_headers(header) {
|
86
|
-
can_link?(simple_include(header))
|
87
|
-
}
|
88
|
-
}
|
89
|
-
@includes << include_path and return true if has_header
|
90
|
-
end
|
91
|
-
|
74
|
+
return true if header_already_loaded?(header) || header_can_link?(header) ||
|
75
|
+
header_found_in_paths?(header, paths)
|
76
|
+
logger.warn "Header not found: #{header}"
|
92
77
|
return false
|
93
78
|
end
|
94
79
|
|
@@ -98,7 +83,13 @@ module Mkrf
|
|
98
83
|
# Params:
|
99
84
|
# * <tt>function</tt> -- the function to check for
|
100
85
|
def has_function?(function)
|
101
|
-
can_link?(simple_call(function)) or can_link?(simple_reference(function))
|
86
|
+
if can_link?(simple_call(function)) or can_link?(simple_reference(function))
|
87
|
+
logger.info "Function found: #{function}()"
|
88
|
+
return true
|
89
|
+
else
|
90
|
+
logger.warn "Function not found: #{function}()"
|
91
|
+
return false
|
92
|
+
end
|
102
93
|
end
|
103
94
|
|
104
95
|
# Returns the result of an attempt to compile and link the function body
|
@@ -133,16 +124,67 @@ module Mkrf
|
|
133
124
|
end
|
134
125
|
|
135
126
|
private
|
136
|
-
|
127
|
+
|
128
|
+
def found_library?(library, function)
|
129
|
+
library_found = with_loaded_libs(library) {
|
130
|
+
has_function? function
|
131
|
+
}
|
132
|
+
|
133
|
+
library_found ? logger.info("Library found: #{library}") :
|
134
|
+
logger.warn("Library not found: #{library}")
|
135
|
+
|
136
|
+
library_found
|
137
|
+
end
|
138
|
+
|
139
|
+
def header_can_link?(header)
|
140
|
+
has_header = with_headers(header) {
|
141
|
+
can_link?(simple_include(header))
|
142
|
+
}
|
143
|
+
|
144
|
+
if has_header
|
145
|
+
logger.info("Header found: #{header}")
|
146
|
+
return true
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def library_already_loaded?(library)
|
151
|
+
if @loaded_libs.include? library
|
152
|
+
logger.info "Library already loaded: #{library}"
|
153
|
+
return true
|
154
|
+
end
|
155
|
+
|
156
|
+
return false
|
157
|
+
end
|
158
|
+
|
159
|
+
def header_already_loaded?(header)
|
160
|
+
if @headers.include? header
|
161
|
+
logger.info("Header already loaded: #{header}")
|
162
|
+
return true
|
163
|
+
end
|
164
|
+
|
165
|
+
return false
|
166
|
+
end
|
167
|
+
|
168
|
+
def header_found_in_paths?(header, paths)
|
169
|
+
paths.each do |include_path|
|
170
|
+
if with_includes(include_path) { header_can_link?(header) }
|
171
|
+
@includes << include_path
|
172
|
+
return true
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
return false
|
177
|
+
end
|
178
|
+
|
137
179
|
STACKABLE_ATTRIBUTES = ['loaded_libs', 'headers', 'includes']
|
138
180
|
|
139
181
|
def with_stackable_attribute(attribute, *args)
|
140
182
|
args = args.to_a
|
141
|
-
instance_variable_set(
|
142
|
-
instance_variable_get(
|
183
|
+
instance_variable_set("@#{attribute}",
|
184
|
+
instance_variable_get("@#{attribute}") + args)
|
143
185
|
value = yield
|
144
|
-
instance_variable_set(
|
145
|
-
instance_variable_get(
|
186
|
+
instance_variable_set("@#{attribute}",
|
187
|
+
instance_variable_get("@#{attribute}") - args)
|
146
188
|
return value
|
147
189
|
end
|
148
190
|
|
@@ -190,6 +232,7 @@ module Mkrf
|
|
190
232
|
end
|
191
233
|
|
192
234
|
def silence_command_line
|
235
|
+
yield and return if $debug
|
193
236
|
silence_stream(STDERR) do
|
194
237
|
silence_stream(STDOUT) do
|
195
238
|
yield
|
data/lib/mkrf/generator.rb
CHANGED
@@ -2,6 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rbconfig'
|
3
3
|
require 'rake/tasklib'
|
4
4
|
|
5
|
+
|
5
6
|
module Mkrf
|
6
7
|
|
7
8
|
# +Generator+ is concerned with taking configuration for an extension
|
@@ -12,12 +13,12 @@ module Mkrf
|
|
12
13
|
# to compile:
|
13
14
|
#
|
14
15
|
# require 'mkrf'
|
15
|
-
# Mkrf::Generator.new('
|
16
|
+
# Mkrf::Generator.new('libtrivial')
|
16
17
|
#
|
17
18
|
# Configuration of the build can be passed to the +Generator+ constructor
|
18
19
|
# as a block:
|
19
20
|
#
|
20
|
-
# Mkrf::Generator.new('
|
21
|
+
# Mkrf::Generator.new('libxml', '*.c') do |g|
|
21
22
|
# g.include_library('socket','socket')
|
22
23
|
# g.include_header('libxml/xmlversion.h',
|
23
24
|
# '/opt/include/libxml2',
|
@@ -30,15 +31,17 @@ module Mkrf
|
|
30
31
|
|
31
32
|
CONFIG = Config::CONFIG
|
32
33
|
|
34
|
+
attr_accessor :additional_code # Any extra code to be added to the Rakefile as a string
|
35
|
+
|
33
36
|
# Create a new generator which will write a new +Rakefile+ to the local
|
34
37
|
# filesystem.
|
35
38
|
#
|
36
39
|
# Params:
|
37
|
-
# * +
|
40
|
+
# * +extension_name+ -- the name of the extension
|
38
41
|
# * +source_patterns+ -- a pattern describing source files to be compiled, "lib/*.c" by default
|
39
|
-
def initialize(
|
40
|
-
@sources = source_patterns
|
41
|
-
@
|
42
|
+
def initialize(extension_name, *source_patterns)
|
43
|
+
@sources = (source_patterns.empty? ? ["lib/*.c"] : source_patterns)
|
44
|
+
@extension_name = extension_name + ".#{CONFIG['DLEXT']}"
|
42
45
|
@available = Mkrf::Availability.new(:includes => [CONFIG['includedir'], CONFIG["archdir"],
|
43
46
|
CONFIG['sitelibdir'], "."] )
|
44
47
|
@defines = []
|
@@ -94,10 +97,21 @@ module Mkrf
|
|
94
97
|
@available.has_function? function
|
95
98
|
end
|
96
99
|
|
100
|
+
# Returns mkrf's logger instance. You can use this to set logging levels.
|
101
|
+
#
|
102
|
+
# Mkrf::Generator.new('libsomethin') do |g|
|
103
|
+
# g.logger.level = Logger::WARN
|
104
|
+
# end
|
105
|
+
#
|
106
|
+
def logger
|
107
|
+
@available.logger
|
108
|
+
end
|
109
|
+
|
97
110
|
def write_rakefile(filename = "Rakefile") # :nodoc:
|
98
111
|
File.open(filename, "w+") do |f|
|
99
112
|
f.puts rakefile_contents
|
100
113
|
end
|
114
|
+
@available.logger.info "Rakefile written"
|
101
115
|
end
|
102
116
|
|
103
117
|
def defines_compile_string # :nodoc:
|
@@ -112,7 +126,7 @@ module Mkrf
|
|
112
126
|
require 'rake/clean'
|
113
127
|
|
114
128
|
CLEAN.include('*.o')
|
115
|
-
CLOBBER.include('#{@
|
129
|
+
CLOBBER.include('#{@extension_name}', 'mkrf.log')
|
116
130
|
|
117
131
|
SRC = FileList[#{sources.join(',')}]
|
118
132
|
OBJ = SRC.ext('o')
|
@@ -127,7 +141,7 @@ module Mkrf
|
|
127
141
|
|
128
142
|
CFLAGS = "#{CONFIG['CCDLFLAGS']} #{CONFIG['CFLAGS']} #{CONFIG['ARCH_FLAG']} #{defines_compile_string}"
|
129
143
|
|
130
|
-
task :default => ['#{@
|
144
|
+
task :default => ['#{@extension_name}']
|
131
145
|
|
132
146
|
rule '.o' => '.c' do |t|
|
133
147
|
sh "\#{CC} \#{CFLAGS} \#{INCLUDES} -c -o \#{t.name} \#{t.source}"
|
@@ -137,9 +151,12 @@ module Mkrf
|
|
137
151
|
sh "\#{LDSHARED} \#{LIBPATH} -o \#{OBJ} \#{LOCAL_LIBS} \#{LIBS}"
|
138
152
|
end
|
139
153
|
|
140
|
-
|
141
|
-
|
154
|
+
desc "Build this extension"
|
155
|
+
file '#{@extension_name}' => OBJ do
|
156
|
+
sh "\#{LDSHARED} \#{LIBPATH} -o #{@extension_name} \#{OBJ} \#{LIBS}"
|
142
157
|
end
|
158
|
+
|
159
|
+
#{additional_code}
|
143
160
|
END_RAKEFILE
|
144
161
|
end
|
145
162
|
end
|
data/test/abstract_unit.rb
CHANGED
@@ -1,4 +1,44 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
2
|
|
3
3
|
require 'test/unit'
|
4
|
-
require File.dirname(__FILE__) + '/../lib/mkrf'
|
4
|
+
require File.dirname(__FILE__) + '/../lib/mkrf'
|
5
|
+
|
6
|
+
$debug = false
|
7
|
+
|
8
|
+
class Test::Unit::TestCase
|
9
|
+
def silence_command_line
|
10
|
+
yield and return if $debug
|
11
|
+
silence_stream(STDERR) do
|
12
|
+
silence_stream(STDOUT) do
|
13
|
+
yield
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# silence_stream taken from Rails ActiveSupport reporting.rb
|
19
|
+
|
20
|
+
# Silences any stream for the duration of the block.
|
21
|
+
#
|
22
|
+
# silence_stream(STDOUT) do
|
23
|
+
# puts 'This will never be seen'
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# puts 'But this will'
|
27
|
+
def silence_stream(stream)
|
28
|
+
old_stream = stream.dup
|
29
|
+
stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
|
30
|
+
stream.sync = true
|
31
|
+
yield
|
32
|
+
ensure
|
33
|
+
stream.reopen(old_stream)
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
|
38
|
+
def assert_creates_file(file)
|
39
|
+
assert !File.exist?(file), "#{file} already exists!"
|
40
|
+
yield
|
41
|
+
assert File.exist?(file), "#{file} wasn't created!"
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
Binary file
|
@@ -4,7 +4,7 @@ require "../../../../../../../lib/mkrf"
|
|
4
4
|
`cp #{File::dirname $0}/../../../../lib/#{codefile} #{codefile}`
|
5
5
|
end
|
6
6
|
|
7
|
-
Mkrf::Generator.new('syck
|
7
|
+
Mkrf::Generator.new('syck') do |g|
|
8
8
|
g.include_header("st.h")
|
9
9
|
g.add_source('*.c') # We can actually do this in the contructor, but this tests add_source
|
10
10
|
end
|
data/test/test_availability.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/abstract_unit'
|
2
2
|
|
3
|
+
|
3
4
|
class TestAvailability < Test::Unit::TestCase
|
4
5
|
def setup
|
5
6
|
@avail = Mkrf::Availability.new(:includes => File.join(File.dirname(__FILE__), 'fixtures'))
|
6
7
|
end
|
7
8
|
|
9
|
+
def teardown
|
10
|
+
FileUtils.rm_f 'mkrf.log'
|
11
|
+
end
|
12
|
+
|
8
13
|
def test_has_library_should_return_true_when_lib_already_loaded
|
9
14
|
@avail = Mkrf::Availability.new(:loaded_libs => ['sample_library'])
|
10
15
|
assert @avail.has_library?('sample_library')
|
@@ -21,11 +26,9 @@ class TestAvailability < Test::Unit::TestCase
|
|
21
26
|
end
|
22
27
|
|
23
28
|
def test_create_source
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
assert File.exist?(Mkrf::Availability::TEMP_SOURCE_FILE)
|
29
|
+
assert_creates_file(Mkrf::Availability::TEMP_SOURCE_FILE) do
|
30
|
+
@avail.send(:create_source, "puts 'Hello World!'")
|
31
|
+
end
|
29
32
|
|
30
33
|
source = File.open(Mkrf::Availability::TEMP_SOURCE_FILE).read
|
31
34
|
assert_equal "puts 'Hello World!'", source
|
@@ -65,4 +68,30 @@ class TestAvailability < Test::Unit::TestCase
|
|
65
68
|
assert_raises(NoMethodError) { @avail.not_a_stackable_attribute }
|
66
69
|
assert_raises(NoMethodError) { @avail.with_not_a_stackable_attribute }
|
67
70
|
end
|
71
|
+
|
72
|
+
def test_logging
|
73
|
+
@avail.logger.level = Logger::INFO
|
74
|
+
assert @avail.include_library('z')
|
75
|
+
assert @avail.include_library('z')
|
76
|
+
assert !@avail.include_library('bogus_lib')
|
77
|
+
assert !@avail.include_header('some_fake_header.h')
|
78
|
+
assert @avail.include_header('stdio.h')
|
79
|
+
assert !@avail.has_function?('blah_blah_blah')
|
80
|
+
assert @avail.has_function?('printf')
|
81
|
+
|
82
|
+
source = File.open('mkrf.log').read
|
83
|
+
|
84
|
+
|
85
|
+
[ 'Checking for library: z',
|
86
|
+
'Library found: z',
|
87
|
+
'Library already loaded: z',
|
88
|
+
'Library not found: bogus_lib',
|
89
|
+
'Header not found: some_fake_header.h',
|
90
|
+
'Header found: stdio.h',
|
91
|
+
'Function not found: blah_blah_blah()',
|
92
|
+
'Function found: printf()'
|
93
|
+
].each do |log_items|
|
94
|
+
assert_match log_items, source
|
95
|
+
end
|
96
|
+
end
|
68
97
|
end
|
data/test/test_generator.rb
CHANGED
@@ -1,74 +1,85 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/abstract_unit'
|
2
2
|
|
3
|
+
# stubb this out so we don't overwrite our test rakefile
|
4
|
+
module Mkrf
|
5
|
+
class Generator
|
6
|
+
def write_rakefile(file = "Rakefile")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
3
11
|
class TestGenerator < Test::Unit::TestCase
|
4
|
-
SAMPLES_DIR = File.dirname(__FILE__) + '/sample_files'
|
5
|
-
|
6
|
-
SAMPLE_LIBS = {
|
7
|
-
:libtrivial => '/libtrivial/libtrivial_so.bundle',
|
8
|
-
:syck => '/syck-0.55/ext/ruby/ext/syck/syck.bundle',
|
9
|
-
:libxml => '/libxml-ruby-0.3.8/ext/xml/libxml_so.bundle'
|
10
|
-
}
|
11
|
-
|
12
|
-
# Set to true for full command line output
|
13
|
-
@@debug = false
|
14
|
-
|
15
12
|
def setup
|
16
|
-
|
17
|
-
system('rake test:samples:clean')
|
18
|
-
end
|
13
|
+
FileUtils.rm_f 'mkrf.log'
|
19
14
|
end
|
20
15
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
system('rake test:samples:trivial')
|
25
|
-
end
|
26
|
-
assert File.exist?(SAMPLES_DIR + SAMPLE_LIBS[:libtrivial])
|
16
|
+
def test_default_sources
|
17
|
+
g = Mkrf::Generator.new('testlib')
|
18
|
+
assert_equal ["'lib/*.c'"], g.sources, "Default sources incorrect"
|
27
19
|
end
|
28
20
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
-
system('rake test:samples:syck')
|
21
|
+
def test_additional_code
|
22
|
+
generator = Mkrf::Generator.new('testlib') do |g|
|
23
|
+
g.additional_code = spec_code
|
33
24
|
end
|
34
|
-
|
25
|
+
assert_match spec_code, generator.rakefile_contents
|
35
26
|
end
|
36
27
|
|
37
|
-
def
|
38
|
-
|
39
|
-
|
40
|
-
|
28
|
+
def test_logging_levels
|
29
|
+
generator = Mkrf::Generator.new('testlib') do |g|
|
30
|
+
g.logger.level = Logger::WARN
|
31
|
+
g.include_header 'stdio.h'
|
32
|
+
g.include_header 'fake_header.h'
|
41
33
|
end
|
42
|
-
|
34
|
+
|
35
|
+
logs = File.open('mkrf.log').read
|
36
|
+
assert_no_match(/INFO/, logs)
|
37
|
+
assert_match(/WARN/, logs)
|
43
38
|
end
|
44
39
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
silence_stream(STDERR) do
|
50
|
-
silence_stream(STDOUT) do
|
51
|
-
yield
|
52
|
-
end
|
40
|
+
def test_logging_defaults_to_info_level
|
41
|
+
generator = Mkrf::Generator.new('testlib') do |g|
|
42
|
+
g.include_header 'stdio.h'
|
43
|
+
g.include_header 'fake_header.h'
|
53
44
|
end
|
45
|
+
|
46
|
+
logs = File.open('mkrf.log').read
|
47
|
+
assert_match(/INFO/, logs)
|
48
|
+
assert_match(/WARN/, logs)
|
54
49
|
end
|
55
50
|
|
56
|
-
|
51
|
+
protected
|
57
52
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
53
|
+
def spec_code
|
54
|
+
<<-SPEC
|
55
|
+
# Create compressed packages
|
56
|
+
spec = Gem::Specification.new do |s|
|
57
|
+
s.platform = Gem::Platform::RUBY
|
58
|
+
s.name = PKG_NAME
|
59
|
+
s.summary = "Generate Rakefiles to Build C Extensions to Ruby"
|
60
|
+
s.description = %q{This proposed replacement to mkmf generates Rakefiles to build C Extensions.}
|
61
|
+
s.version = PKG_VERSION
|
62
|
+
|
63
|
+
s.author = "Kevin Clark"
|
64
|
+
s.email = "kevin.clark@gmail.com"
|
65
|
+
s.rubyforge_project = RUBY_FORGE_PROJECT
|
66
|
+
s.homepage = "http://glu.ttono.us"
|
67
|
+
|
68
|
+
s.has_rdoc = true
|
69
|
+
s.requirements << 'rake'
|
70
|
+
s.require_path = 'lib'
|
71
|
+
s.autorequire = 'mkrf'
|
72
|
+
|
73
|
+
s.files = [ "Rakefile", "README", "CHANGELOG", "MIT-LICENSE" ]
|
74
|
+
s.files = s.files + Dir.glob( "lib/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
75
|
+
s.files = s.files + Dir.glob( "test/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
76
|
+
end
|
77
|
+
|
78
|
+
Rake::GemPackageTask.new(spec) do |p|
|
79
|
+
p.gem_spec = spec
|
80
|
+
p.need_tar = true
|
81
|
+
p.need_zip = true
|
82
|
+
end
|
83
|
+
SPEC
|
72
84
|
end
|
73
|
-
|
74
85
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/abstract_unit'
|
2
|
+
|
3
|
+
class TestSampleProjects < Test::Unit::TestCase
|
4
|
+
SAMPLES_DIR = File.dirname(__FILE__) + '/sample_files'
|
5
|
+
|
6
|
+
SAMPLE_LIBS = {
|
7
|
+
:trivial => '/libtrivial/libtrivial.bundle',
|
8
|
+
:syck => '/syck-0.55/ext/ruby/ext/syck/syck.bundle',
|
9
|
+
:libxml => '/libxml-ruby-0.3.8/ext/xml/libxml_so.bundle'
|
10
|
+
}
|
11
|
+
|
12
|
+
# Set to true for full command line output
|
13
|
+
@@debug = false
|
14
|
+
|
15
|
+
SAMPLE_LIBS.each do |k,v|
|
16
|
+
define_method("test_that_#{k}_compiles") do
|
17
|
+
silence_command_line do
|
18
|
+
system("rake test:samples:clobber PROJECT=#{k}")
|
19
|
+
end
|
20
|
+
assert_creates_file(SAMPLES_DIR + v) do
|
21
|
+
silence_command_line do
|
22
|
+
system("rake test:samples:#{k}")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.
|
2
|
+
rubygems_version: 0.9.0
|
3
3
|
specification_version: 1
|
4
4
|
name: mkrf
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2006-
|
6
|
+
version: 0.1.1
|
7
|
+
date: 2006-08-17 00:00:00 -07:00
|
8
8
|
summary: Generate Rakefiles to Build C Extensions to Ruby
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -25,6 +25,7 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
25
25
|
platform: ruby
|
26
26
|
signing_key:
|
27
27
|
cert_chain:
|
28
|
+
post_install_message:
|
28
29
|
authors:
|
29
30
|
- Kevin Clark
|
30
31
|
files:
|
@@ -41,6 +42,7 @@ files:
|
|
41
42
|
- test/sample_files
|
42
43
|
- test/test_availability.rb
|
43
44
|
- test/test_generator.rb
|
45
|
+
- test/test_sample_projects.rb
|
44
46
|
- test/fixtures/down_a_directory
|
45
47
|
- test/fixtures/stdmkrf.h
|
46
48
|
- test/fixtures/down_a_directory/header_down_a_directory.h
|
@@ -49,9 +51,6 @@ files:
|
|
49
51
|
- test/sample_files/syck-0.55
|
50
52
|
- test/sample_files/libtrivial/extconf.rb
|
51
53
|
- test/sample_files/libtrivial/lib
|
52
|
-
- test/sample_files/libtrivial/libtrivial_so.bundle
|
53
|
-
- test/sample_files/libtrivial/mkrf.log
|
54
|
-
- test/sample_files/libtrivial/Rakefile
|
55
54
|
- test/sample_files/libtrivial/lib/libtrivial.c
|
56
55
|
- test/sample_files/libtrivial/lib/libtrivial.o
|
57
56
|
- test/sample_files/libxml-ruby-0.3.8/CHANGELOG
|
@@ -64,7 +63,6 @@ files:
|
|
64
63
|
- test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.c
|
65
64
|
- test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.h
|
66
65
|
- test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.rb
|
67
|
-
- test/sample_files/libxml-ruby-0.3.8/ext/xml/mkrf.log
|
68
66
|
- test/sample_files/libxml-ruby-0.3.8/ext/xml/old_extconf.rb
|
69
67
|
- test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attr.c
|
70
68
|
- test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attr.h
|
@@ -147,7 +145,6 @@ files:
|
|
147
145
|
- test/sample_files/syck-0.55/ext/ruby/ext/syck/handler.c
|
148
146
|
- test/sample_files/syck-0.55/ext/ruby/ext/syck/implicit.c
|
149
147
|
- test/sample_files/syck-0.55/ext/ruby/ext/syck/MANIFEST
|
150
|
-
- test/sample_files/syck-0.55/ext/ruby/ext/syck/mkrf.log
|
151
148
|
- test/sample_files/syck-0.55/ext/ruby/ext/syck/node.c
|
152
149
|
- test/sample_files/syck-0.55/ext/ruby/ext/syck/rubyext.c
|
153
150
|
- test/sample_files/syck-0.55/ext/ruby/ext/syck/syck.c
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'rake/clean'
|
2
|
-
|
3
|
-
CLEAN.include('*.o')
|
4
|
-
CLOBBER.include('libtrivial_so.bundle')
|
5
|
-
|
6
|
-
SRC = FileList[]
|
7
|
-
OBJ = SRC.ext('o')
|
8
|
-
CC = "gcc"
|
9
|
-
|
10
|
-
LDSHARED = "cc -dynamic -bundle -undefined suppress -flat_namespace"
|
11
|
-
LIBPATH = '-L"/usr/local/lib"'
|
12
|
-
|
13
|
-
INCLUDES = "-I/usr/local/include -I/usr/local/lib/ruby/1.8/i686-darwin8.6.1 -I/usr/local/lib/ruby/site_ruby/1.8 -I."
|
14
|
-
|
15
|
-
LIBS = "-lruby -ldl"
|
16
|
-
|
17
|
-
CFLAGS = " -fno-common -g -O2 -pipe -fno-common "
|
18
|
-
|
19
|
-
task :default => ['libtrivial_so.bundle']
|
20
|
-
|
21
|
-
rule '.o' => '.c' do |t|
|
22
|
-
sh "#{CC} #{CFLAGS} #{INCLUDES} -c -o #{t.name} #{t.source}"
|
23
|
-
end
|
24
|
-
|
25
|
-
rule '.so' => '.o' do |t|
|
26
|
-
sh "#{LDSHARED} #{LIBPATH} -o #{OBJ} #{LOCAL_LIBS} #{LIBS}"
|
27
|
-
end
|
28
|
-
|
29
|
-
file 'libtrivial_so.bundle' => OBJ do
|
30
|
-
sh "#{LDSHARED} #{LIBPATH} -o libtrivial_so.bundle #{OBJ} #{LIBS}"
|
31
|
-
end
|
Binary file
|
@@ -1 +0,0 @@
|
|
1
|
-
# Logfile created on Mon Jun 26 15:47:07 PDT 2006 by logger.rb/1.5.2.7
|
@@ -1 +0,0 @@
|
|
1
|
-
# Logfile created on Mon Jun 26 13:34:01 PDT 2006 by logger.rb/1.5.2.4
|
@@ -1 +0,0 @@
|
|
1
|
-
# Logfile created on Mon Jun 26 15:44:42 PDT 2006 by logger.rb/1.5.2.4
|