blob: 71b9df556ecdb5dcc3c0d5c327701ad33d0030b3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
require 'rake'
require 'rake/clean'
require 'rake/tasklib'
require 'rbconfig'
begin
require 'psych'
rescue LoadError
end
require 'yaml'
require 'pathname'
module Rake
class BaseExtensionTask < TaskLib
attr_accessor :name
attr_accessor :gem_spec
attr_accessor :tmp_dir
attr_accessor :ext_dir
attr_accessor :lib_dir
attr_accessor :platform
attr_accessor :config_options
attr_accessor :source_pattern
attr_accessor :extra_options
def platform
@platform ||= RUBY_PLATFORM
end
def initialize(name = nil, gem_spec = nil)
init(name, gem_spec)
yield self if block_given?
define
end
def init(name = nil, gem_spec = nil)
@name = name
@gem_spec = gem_spec
@tmp_dir = 'tmp'
@ext_dir = "ext/#{@name}"
@lib_dir = 'lib'
@config_options = []
@extra_options = ARGV.select { |i| i =~ /\A--?/ }
end
def define
fail "Extension name must be provided." if @name.nil?
define_compile_tasks
end
private
def define_compile_tasks
raise NotImplementedError
end
def binary(platform = nil)
ext = case platform
when /darwin/
'bundle'
when /mingw|mswin|linux/
'so'
when /java/
'jar'
else
RbConfig::CONFIG['DLEXT']
end
"#{File.basename(@name)}.#{ext}"
end
def source_files
FileList["#{@ext_dir}/#{@source_pattern}"]
end
def warn_once(message)
@@already_warned ||= false
return if @@already_warned
@@already_warned = true
warn message
end
def windows?
Rake.application.windows?
end
end
end
|