forked from SciRuby/nmatrix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
216 lines (171 loc) · 5 KB
/
Rakefile
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# -*- ruby -*-
require 'rubygems'
require 'rubygems/package_task'
require 'bundler'
Bundler::GemHelper.install_tasks
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'rake'
require "rake/extensiontask"
Rake::ExtensionTask.new do |ext|
ext.name = 'nmatrix'
ext.ext_dir = 'ext/nmatrix'
ext.lib_dir = 'lib/'
ext.source_pattern = "**/*.{c,cpp,h}"
end
gemspec = eval(IO.read("nmatrix.gemspec"))
Gem::PackageTask.new(gemspec).define
require 'rspec/core/rake_task'
require 'rspec/core'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb'].uniq
end
BASEDIR = Pathname( __FILE__ ).dirname.relative_path_from( Pathname.pwd )
SPECDIR = BASEDIR + 'spec'
VALGRIND_OPTIONS = [
"--tool=memcheck",
#"--leak-check=yes",
"--num-callers=15",
#"--error-limit=no",
"--partial-loads-ok=yes",
"--undef-value-errors=no" #,
#"--dsymutil=yes"
]
CALLGRIND_OPTIONS = [
"--tool=callgrind",
"--dump-instr=yes",
"--simulate-cache=yes",
"--collect-jumps=yes"
]
VALGRIND_MEMORYFILL_OPTIONS = [
"--freelist-vol=100000000",
"--malloc-fill=6D",
"--free-fill=66 ",
]
GDB_OPTIONS = []
task :console do |task|
cmd = [ 'irb', "-r './lib/nmatrix.rb'" ]
run *cmd
end
task :pry do |task|
cmd = [ 'pry', "-r './lib/nmatrix.rb'" ]
run *cmd
end
namespace :pry do
task :valgrind => [ :compile ] do |task|
cmd = [ 'valgrind' ] + VALGRIND_OPTIONS
cmd += ['ruby', '-Ilib:ext', "-r './lib/nmatrix.rb'", "-r 'pry'", "-e 'binding.pry'"]
run *cmd
end
end
namespace :console do
CONSOLE_CMD = ['irb', "-r './lib/nmatrix.rb'"]
desc "Run console under GDB."
task :gdb => [ :compile ] do |task|
cmd = [ 'gdb' ] + GDB_OPTIONS
cmd += [ '--args' ]
cmd += CONSOLE_CMD
run( *cmd )
end
desc "Run console under Valgrind."
task :valgrind => [ :compile ] do |task|
cmd = [ 'valgrind' ] + VALGRIND_OPTIONS
cmd += CONSOLE_CMD
run( *cmd )
end
end
task :default => :spec
def run *cmd
sh(cmd.join(" "))
end
namespace :spec do
# partial-loads-ok and undef-value-errors necessary to ignore
# spurious (and eminently ignorable) warnings from the ruby
# interpreter
RSPEC_CMD = [ 'ruby', '-S', 'rspec', '-Ilib:ext', SPECDIR.to_s ]
#desc "Run the spec for generator.rb"
#task :generator do |task|
# run 'rspec spec/generator_spec.rb'
#end
desc "Run specs under GDB."
task :gdb => [ :compile ] do |task|
cmd = [ 'gdb' ] + GDB_OPTIONS
cmd += [ '--args' ]
cmd += RSPEC_CMD
run( *cmd )
end
desc "Run specs under cgdb."
task :cgdb => [ :compile ] do |task|
cmd = [ 'cgdb' ] + GDB_OPTIONS
cmd += [ '--args' ]
cmd += RSPEC_CMD
run( *cmd )
end
desc "Run specs under Valgrind."
task :valgrind => [ :compile ] do |task|
cmd = [ 'valgrind' ] + VALGRIND_OPTIONS
cmd += RSPEC_CMD
run( *cmd )
end
desc "Run specs under Callgrind."
task :callgrind => [ :compile ] do |task|
cmd = [ 'valgrind' ] + CALLGRIND_OPTIONS
cmd += RSPEC_CMD
run( *cmd )
end
end
LEAKCHECK_CMD = [ 'ruby', '-Ilib:ext', "#{SPECDIR}/leakcheck.rb" ]
desc "Run leakcheck script."
task :leakcheck => [ :compile ] do |task|
cmd = [ 'valgrind' ] + VALGRIND_OPTIONS
cmd += LEAKCHECK_CMD
run( *cmd )
end
namespace :clean do
task :so do |task|
tmp_path = "tmp/#{RUBY_PLATFORM}/nmatrix/#{RUBY_VERSION}"
chdir tmp_path do
if RUBY_PLATFORM =~ /mswin/
`nmake soclean`
else
mkcmd = ENV['MAKE'] || %w[gmake make].find { |c| system("#{c} -v >> /dev/null 2>&1") }
`#{mkcmd} soclean`
end
end
end
end
desc "Check the manifest for correctness"
task :check_manifest do |task|
manifest_files = File.read("Manifest.txt").split
git_files = `git ls-files |grep -v 'spec/'`.split
ignore_files = %w{.gitignore .rspec ext/nmatrix/binary_format.txt ext/nmatrix/ttable_helper.rb scripts/mac-brew-gcc.sh}
possible_files = git_files - ignore_files
missing_files = possible_files - manifest_files
extra_files = manifest_files - possible_files
unless missing_files.empty?
STDERR.puts "The following files are in the git repo but not the Manifest:"
missing_files.each { |f| STDERR.puts " -- #{f}"}
end
unless extra_files.empty?
STDERR.puts "The following files are in the Manifest but may not be necessary:"
extra_files.each { |f| STDERR.puts " -- #{f}"}
end
if extra_files.empty? && missing_files.empty?
STDERR.puts "Manifest looks good!"
end
end
require "rdoc/task"
RDoc::Task.new do |rdoc|
rdoc.main = "README.rdoc"
rdoc.rdoc_files.include(%w{README.rdoc History.txt LICENSE.txt CONTRIBUTING.md lib ext})
rdoc.options << "--exclude=ext/nmatrix/extconf.rb"
rdoc.options << "--exclude=ext/nmatrix/ttable_helper.rb"
rdoc.options << "--exclude=lib/nmatrix/rspec.rb"
end
# vim: syntax=ruby