-
Notifications
You must be signed in to change notification settings - Fork 93
/
Rakefile
110 lines (89 loc) · 3.06 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
require "bundler/gem_tasks"
require "minitest/test_task"
CLEAN.add("{ext,lib}/**/*.{o,so,bundle}", "pkg")
CLOBBER.add("Gemfile.lock")
Minitest::TestTask.create(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_globs = FileList['test/**/*_test.rb']
end
task :default => [:compile, :test]
gem = Gem::Specification.load( File.dirname(__FILE__) + '/mini_racer.gemspec' )
if RUBY_ENGINE == "truffleruby"
task :compile do
# noop
end
task :clean do
# noop
end
else
require 'rake/extensiontask'
Rake::ExtensionTask.new( 'mini_racer_loader', gem )
Rake::ExtensionTask.new( 'mini_racer_extension', gem )
end
# via http://blog.flavorjon.es/2009/06/easily-valgrind-gdb-your-ruby-c.html
namespace :test do
desc "run test suite with Address Sanitizer"
task :asan do
ENV["CONFIGURE_ARGS"] = [ENV["CONFIGURE_ARGS"], '--enable-asan'].compact.join(' ')
Rake::Task['compile'].invoke
asan_path = `ldconfig -N -p |grep libasan | grep -v 32 | sed 's/.* => \\(.*\\)$/\\1/'`.chomp.split("\n")[-1]
cmdline = "env LD_PRELOAD=\"#{asan_path}\" ruby test/test_leak.rb"
puts cmdline
system cmdline
cmdline = "env LD_PRELOAD=\"#{asan_path}\" rake test"
puts cmdline
system cmdline
end
# partial-loads-ok and undef-value-errors necessary to ignore
# spurious (and eminently ignorable) warnings from the ruby
# interpreter
VALGRIND_BASIC_OPTS = "--num-callers=50 --error-limit=no \
--partial-loads-ok=yes --undef-value-errors=no"
desc "run test suite under valgrind with basic ruby options"
task :valgrind => :compile do
cmdline = "valgrind #{VALGRIND_BASIC_OPTS} ruby test/test_leak.rb"
puts cmdline
system cmdline
end
desc "run test suite under valgrind with leak-check=full"
task :valgrind_leak_check => :compile do
cmdline = "valgrind #{VALGRIND_BASIC_OPTS} --leak-check=full ruby test/test_leak.rb"
puts cmdline
require 'open3'
_, stderr = Open3.capture3(cmdline)
section = ""
stderr.split("\n").each do |line|
if line =~ /==.*==\s*$/
if (section =~ /mini_racer|SUMMARY/)
puts
puts section
puts
end
section = ""
else
section << line << "\n"
end
end
end
end
desc 'run clang-tidy linter on mini_racer_extension.cc'
task :lint do
require 'mkmf'
require 'libv8'
Libv8.configure_makefile
conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote,
'arch_hdrdir' => $arch_hdrdir.quote,
'top_srcdir' => $top_srcdir.quote)
if $universal and (arch_flag = conf['ARCH_FLAG']) and !arch_flag.empty?
conf['ARCH_FLAG'] = arch_flag.gsub(/(?:\G|\s)-arch\s+\S+/, '')
end
checks = %W(bugprone-*
cert-*
cppcoreguidelines-*
clang-analyzer-*
performance-*
portability-*
readability-*).join(',')
sh RbConfig::expand("clang-tidy -checks='#{checks}' ext/mini_racer_extension/mini_racer_extension.cc -- #$INCFLAGS #$CXXFLAGS", conf)
end