/
rakehelp.rb
118 lines (95 loc) · 2.44 KB
/
rakehelp.rb
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
def make(makedir)
Dir.chdir(makedir) do
sh(PLATFORM =~ /win32/ ? 'nmake' : 'make')
end
end
def extconf(dir)
Dir.chdir(dir) do ruby "extconf.rb" end
end
def setup_tests
desc "Run the unit tests in test"
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.test_files = FileList['test/*_test.rb']
t.verbose = true
end
end
def setup_clean otherfiles
files = ['build/*', '**/*.o', '**/*.so', '**/*.a', 'lib/*-*', '**/*.log'] + otherfiles
CLEAN.include(files)
end
def setup_rdoc files
Rake::RDocTask.new do |rdoc|
rdoc.rdoc_dir = 'doc/rdoc'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.add(files)
end
end
def setup_extension(dir, extension)
ext = "ext/#{dir}"
ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}"
ext_files = FileList[
"#{ext}/*.c",
"#{ext}/*.h",
"#{ext}/extconf.rb",
"#{ext}/Makefile",
"lib"
]
task "lib" do
directory "lib"
end
desc "Builds just the #{extension} extension"
task extension.to_sym => ["#{ext}/Makefile", ext_so ]
file "#{ext}/Makefile" => ["#{ext}/extconf.rb"] do
extconf "#{ext}"
end
file ext_so => ext_files do
make "#{ext}"
cp ext_so, "lib"
end
end
def base_gem_spec(pkg_name, pkg_version)
rm_rf "test/coverage"
pkg_version = pkg_version
pkg_name = pkg_name
pkg_file_name = "#{pkg_name}-#{pkg_version}"
Gem::Specification.new do |s|
s.name = pkg_name
s.version = pkg_version
s.platform = Gem::Platform::RUBY
s.has_rdoc = true
s.extra_rdoc_files = [ "README" ]
s.files = %w(COPYING LICENSE README Rakefile) +
Dir.glob("{bin,doc/rdoc,test}/**/*") +
Dir.glob("ext/**/*.{h,c,rb,rl}") +
Dir.glob("{examples,tools,lib}/**/*.rb")
s.require_path = "lib"
s.extensions = FileList["ext/**/extconf.rb"].to_a
s.bindir = "bin"
end
end
def setup_gem(pkg_name, pkg_version)
spec = base_gem_spec(pkg_name, pkg_version)
yield spec if block_given?
Rake::GemPackageTask.new(spec) do |p|
p.gem_spec = spec
p.need_tar = true if RUBY_PLATFORM !~ /mswin/
end
end
def sub_project(project, *targets)
targets.each do |target|
Dir.chdir "projects/#{project}" do
sh %{rake --trace #{target.to_s} }
end
end
end
# Conditional require rcov/rcovtask if present
begin
require 'rcov/rcovtask'
Rcov::RcovTask.new do |t|
t.test_files = FileList['test/test*.rb']
t.rcov_opts << "-x /usr"
t.output_dir = "test/coverage"
end
rescue Object
end