-
Notifications
You must be signed in to change notification settings - Fork 28
/
Rakefile
111 lines (95 loc) · 3.62 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 'rubygems'
require 'rake'
require 'bundler'
Bundler::GemHelper.install_tasks
SPEC_SCRIPT = File.expand_path('../spec/run_build.sh', __FILE__)
task :default => :spec
RUBIES = {
:parsetree => [
[nil, 'ruby-1.8.6-p420@sourcify-parsetree'],
[nil, 'ruby-1.8.7-p334@sourcify-parsetree'],
[nil, 'ree-1.8.7--2012.02@sourcify-parsetree']
],
:static => [
[nil, 'ruby-1.8.6-p420@sourcify'],
[nil, 'ruby-1.8.7-p334@sourcify'],
[nil, 'ree-1.8.7--2012.02@sourcify'],
[nil, 'jruby-1.6.3@sourcify'],
[nil, 'ruby-1.9.2-p320@sourcify'],
[nil, 'ruby-1.9.3-p194@sourcify'],
# NOTE: This doesn't support Method#to_source (& friends) yet yet due to
# jruby's Method#parameters bug, see http://jira.codehaus.org/browse/JRUBY-5954
['JRUBY_OPTS="--1.9"', 'jruby-1.6.3@sourcify'],
]
}
def run_build_for(envs_and_rubies)
envs_and_rubies.group_by{|arry| arry[0..-2] }.each do |envs, arry|
rubies = arry.map(&:last)
declared_envs = ['export MUTE_BACON=true']
declared_envs << envs.map{|env| env ? "export #{env}" : nil }.compact
system [
declared_envs.flatten.join('; '),
"rvm #{rubies.join(',')} exec #{SPEC_SCRIPT}"
].join('; ')
end
end
# ///////////////////////////////////////////////////////////
# Running Specs
# ///////////////////////////////////////////////////////////
desc "Run all specs"
task :spec do |t|
system SPEC_SCRIPT
end
desc "Run specs in all rubies (both ParseTree & static scanner modes)"
task :'spec:all' do
run_build_for RUBIES.values.flatten(1)
end
desc "Run specs in rubies supporting ParseTree mode"
task :'spec:parsetree' do
run_build_for RUBIES[:parsetree]
end
desc "Run specs in rubies supporting static scanner mode"
task :'spec:static' do
run_build_for RUBIES[:static]
end
# ///////////////////////////////////////////////////////////
# Build ruby files from ragel definitions
# ///////////////////////////////////////////////////////////
desc "Run ragel to generate ruby scanner files from ragel definitions"
task :ragel do
%w{method proc}.each do |m|
common_dir = File.expand_path('../lib/sourcify/common/ragel', __FILE__)
ragel_dir = File.expand_path("../lib/sourcify/#{m}/parser", __FILE__)
ragel_file = File.join(ragel_dir, 'raw_scanner.rl')
ruby_file = File.join(ragel_dir, 'raw_scanner.rb')
File.delete(ruby_file) rescue nil
puts 'Processing %s -> %s' %
[ragel_file, ruby_file].map{|f| f.sub(File.expand_path('../', __FILE__) + '/', '')}
system("ragel -I #{common_dir} -R #{ragel_file}")
end
end
# ///////////////////////////////////////////////////////////
# Benchmarking
# ///////////////////////////////////////////////////////////
desc "Benchmarking"
task :benchmark, :task, :times do |t, args|
times, task = (args.times || 5).to_i.method(:times), args.task
title = " ~ Benchmark Results for Task :#{task} ~ "
results = [%w{nth}, %w{user}, %w{system}, %w{total}, %w{real}]
# Running benchmarking & collecting results
require 'benchmark'
times.call do |i|
result = Benchmark.measure{ Rake::Task[task].execute }.to_s
user, system, total, real =
result.match(/^\s*(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+\(\s*(\d+\.\d+)\)$/)[1..-1]
["##{i.succ}", user, system, total, real].each_with_index{|val, j| results[j] << val }
end
# Formatting benchmarking results
formatted_results = results.map do |rs|
width = rs.map(&:to_s).map(&:size).max
rs.map{|r| ' ' + r.ljust(width, ' ') }
end.transpose.map{|row| row.join }
# Showdown .. printout
line = '=' * ([title.size, formatted_results.map(&:size).max].max + 2)
puts [line, title, formatted_results.join("\n"), line].join("\n\n")
end