-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
133 lines (107 loc) · 2.49 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
require 'rake/testtask'
Rake::TestTask.new :test do |t|
t.pattern = "test/*.rb"
t.warning = true
end
Rake::TestTask.new bench: [:test, :loadavg] do |t|
t.pattern = "test/bench/*.rb"
t.warning = true
t.description = "Run benchmarks"
end
desc "Run type checks (RBS + Steep)"
task :steep do
ENV['RUBYOPT'] = ENV['RUBYOPT'].sub('--enable-frozen-string-literal', '')
bindir = Dir[File.join(ENV['HOME'], '.local/share/gem/ruby/*/bin')].last
bindir ? sh("#{File.join(bindir, 'steep')} check") : puts("can't find steep")
end
desc "Run example scripts"
task examples: [:test, :loadavg] do
Dir['examples/**/*.rb'].each { |filepath|
puts
sh "ruby -Ilib #{filepath}"
puts
}
end
task default: :examples
#
# METRICS
#
begin
require 'flog_task'
FlogTask.new do |t|
t.threshold = 9000
t.dirs = ['lib']
t.verbose = true
end
rescue LoadError
# warn 'flog_task unavailable'
end
begin
require 'flay_task'
FlayTask.new do |t|
t.dirs = ['lib']
t.verbose = true
end
rescue LoadError
# warn 'flay_task unavailable'
end
begin
require 'roodi_task'
RoodiTask.new config: '.roodi.yml', patterns: ['lib/**/*.rb']
rescue LoadError
# warn "roodi_task unavailable"
end
#
# PROFILING
#
desc "Show current system load"
task "loadavg" do
puts "/proc/loadavg %s" % (File.read("/proc/loadavg") rescue "Unavailable")
end
def lib_sh(cmd)
sh "RUBYLIB=lib #{cmd}"
end
def rprof_sh(script, args = '', rprof_args = '')
lib_sh ['ruby-prof', rprof_args, script, '--', args].join(' ')
end
scripts = [
"examples/complete_tree.rb",
"examples/heap.rb",
"examples/heap_push.rb",
"examples/tree.rb",
"examples/flex_node.rb",
"examples/binary_search_tree.rb",
"examples/ternary_search_tree.rb",
]
desc "Run ruby-prof on examples/"
task "ruby-prof" => "loadavg" do
scripts.each { |script| rprof_sh script }
end
desc "Run ruby-prof on examples/ with --exclude-common-cycles"
task "ruby-prof-exclude" => "loadavg" do
scripts.each { |script| rprof_sh script, "", "--exclude-common-cycles" }
end
#
# REPORTS
#
desc "Generate code metrics and reports"
task report: :test do
%w{examples bench flog flay roodi ruby-prof ruby-prof-exclude}.each { |t|
sh "rake #{t} > reports/#{t} 2>&1" do |ok, _status|
puts "rake #{t} failed" unless ok
end
}
end
#
# GEM BUILD / PUBLISH
#
begin
require 'buildar'
Buildar.new do |b|
b.gemspec_file = 'compsci.gemspec'
b.version_file = 'VERSION'
b.use_git = true
end
rescue LoadError
warn "buildar tasks unavailable"
end