-
Notifications
You must be signed in to change notification settings - Fork 143
/
Rakefile
357 lines (296 loc) · 9.27 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# -*- ruby -*-
require 'rubygems'
require 'rubygems/package_task'
require 'bundler'
#Specify plugins to build on the command line like:
#rake whatever nmatrix_plugins=atlas,lapacke
#or
#rake whatever nmatrix_plugins=all
#If you want to build *only* plugins and not the core nmatrix gem:
#rake whatever nmatrix_plugins=all nmatrix_core=false
if ENV["nmatrix_plugins"] == "all"
gemspecs = Dir["*.gemspec"]
else
plugins = []
plugins = ENV["nmatrix_plugins"].split(",") if ENV["nmatrix_plugins"]
gemspecs = ["nmatrix.gemspec"] #always include the main nmatrix gem
plugins.each do |plugin|
gemspecs << "nmatrix-#{plugin}.gemspec"
end
end
if ENV["nmatrix_core"] == "false"
gemspecs -= ["nmatrix.gemspec"]
end
gemspecs.map! { |gemspec| eval(IO.read(gemspec)) }
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
desc "Build and install into system gems."
task :install => :repackage do
gemspecs.each do |gemspec|
gem_file = "pkg/#{gemspec.name}-#{gemspec.version}.gem"
system "gem install '#{gem_file}'"
end
end
require 'rake'
require "rake/extensiontask"
gemspecs.each do |gemspec|
next unless gemspec.extensions
gemspec.extensions.each do |extconf|
ext_name = extconf.match(/ext\/(.*)\/extconf\.rb/)[1]
Rake::ExtensionTask.new do |ext|
ext.name = ext_name
ext.ext_dir = "ext/#{ext_name}"
ext.lib_dir = 'lib/'
ext.source_pattern = "**/*.{c,cpp,h}"
end
end
end
gemspecs.each do |gemspec|
Gem::PackageTask.new(gemspec).define
end
require 'rspec/core/rake_task'
require 'rspec/core'
namespace :spec do
#We need a separate rake task for each plugin, rather than one big task that
#runs all of the specs. This is because there's no way to tell rspec
#to run the specs in a certain order with (say) "nmatrix/atlas" require'd
#for some of the specs, but not for others, without splitting them up like
#this.
spec_tasks = []
gemspecs.each do |gemspec|
test_files = gemspec.test_files
test_files.keep_if { |file| file =~ /_spec\.rb$/ }
test_files -= ['spec/nmatrix_yale_spec.rb', 'spec/blas_spec.rb', 'spec/lapack_core_spec.rb'] if /java/ === RUBY_PLATFORM
next if test_files.empty?
spec_tasks << gemspec.name
RSpec::Core::RakeTask.new(gemspec.name) do |spec|
spec.pattern = FileList.new(test_files)
end
end
task :all => spec_tasks
end
task :spec => "spec:all"
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
#the generated Makefile doesn't have a soclean target, should this be removed?
task :so do |task|
gemspecs.each do |gemspec|
next unless gemspec.extensions
gemspec.extensions.each do |extconf|
ext_name = extconf.match(/ext\/(.*)\/extconf\.rb/)[1]
tmp_path = "tmp/#{RUBY_PLATFORM}/#{ext_name}/#{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
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"
#separate out docs for plugins?
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_atlas/extconf.rb"
rdoc.options << "--exclude=ext/nmatrix/ttable_helper.rb"
rdoc.options << "--exclude=lib/nmatrix/rspec.rb"
end
# jruby tasks
namespace :jruby do
PROJECT_DIR = File.expand_path(".",Dir.pwd)
BUILD_DIR = "build"
CLASSES_DIR = "../build/classes"
TEST_CLASSES_DIR = "build/testClasses"
JRUBY_DIR = "#{PROJECT_DIR}/ext/nmatrix_java"
VENDOR_DIR = "#{JRUBY_DIR}/vendor"
TARGET_DIR = "#{JRUBY_DIR}/target"
jars = Dir["#{VENDOR_DIR}/*.jar"]
desc 'Compile java classes'
task :javac do
unless RUBY_PLATFORM == 'java'
abort 'Please run with JRuby'
end
sh "mkdir -p #{JRUBY_DIR}/build/classes"
Dir.chdir("#{JRUBY_DIR}/nmatrix")
classes = Dir['**/*.java']
sh "javac -classpath #{jars.join(':')} -d #{CLASSES_DIR} #{classes.join(' ')}"
end
desc 'Package java classes in a jar file'
task :jar do
unless RUBY_PLATFORM == 'java'
abort 'Please run with JRuby'
end
sh "mkdir -p #{TARGET_DIR}"
Dir.chdir("#{JRUBY_DIR}/build/classes")
classes = Dir['**/*.class']
sh "jar -cf #{TARGET_DIR}/nmatrix.jar #{classes.join(' ')}"
end
task :all => [:javac, :jar]
end
desc "Compile java classes and Package them in a jar file"
task :jruby => 'jruby:all'
namespace :travis do
task :env do
if /java/ === RUBY_PLATFORM
puts "Building for jruby"
sh "mkdir ext/nmatrix_java/vendor"
puts "Downloading tar file."
sh "wget http://www-eu.apache.org/dist//commons/math/binaries/commons-math3-3.6.1-bin.tar.gz"
puts "Unzipping tar file."
sh "tar -zxf commons-math3-3.6.1-bin.tar.gz"
puts "Deleting tar file."
sh "rm commons-math3-3.6.1-bin.tar.gz"
sh "cp -r commons-math3-3.6.1/commons-math3-3.6.1.jar ext/nmatrix_java/vendor"
else
puts "\n# Build environment:"
%w[
CC CXX
USE_ATLAS USE_OPENBLAS USE_REF NO_EXTERNAL_LIB
TRAVIS_OS_NAME TRAVIS_BRANCH TRAVIS_COMMIT TRAVIS_PULL_REQUEST
].each do |name|
puts "- #{name}: #{ENV[name]}"
end
require 'rbconfig'
puts "\n# RbConfig::MAKEFILE_CONFIG values:"
%w[
CC CXX CPPFLAGS CFLAGS CXXFLAGS
].each do |name|
puts "- #{name}: #{RbConfig::MAKEFILE_CONFIG[name]}"
end
cc = RbConfig::MAKEFILE_CONFIG['CC']
puts "\n$ #{cc} -v\n#{`#{cc} -v 2>&1`}"
end
end
end
# vim: syntax=ruby