forked from jeremyevans/home_run
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
142 lines (121 loc) · 4.37 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
require "rake"
require "rake/clean"
require 'rbconfig'
CLEAN.include %w'ext/Makefile ext/date_ext.*o **/*.rbc *.core rdoc coverage'
RUBY=ENV['RUBY'] || File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
desc "Build the RDoc documentation"
task :rdoc do
require 'fileutils'
FileUtils.rm_rf('rdoc')
sh 'rdoc --quiet --line-numbers --inline-source --output rdoc --title ' \
'"home_run: Fast Date/DateTime classes for ruby" --main README.rdoc ' \
'README.rdoc CHANGELOG LICENSE ext/**/*.rb ext/*.c'
end
desc "Run the specs with mspec"
task :default => :spec
task :spec do
ENV['RUBY'] ||= RUBY
sh %{mspec}
end
desc "Run a coverage report for the pure ruby file"
task :coverage do
sh %{cd spec && ../bin/home_run mspec -o ../coverage -t rcov -- ../ext/date/format.rb date*/*}
end
desc "Build the gem"
task :gem => [:clean, :parser] do
sh %{gem build home_run.gemspec}
end
desc "Try to clean up everything"
task :distclean do
CLEAN.concat(%w'pkg home_run-*.gem ext/1.* tmp rdoc ext/date_parser.c')
Rake::Task[:clean].invoke
end
if RUBY_PLATFORM !~ /mswin|mingw/ and File.directory?(File.join(File.expand_path(ENV['HOME']), '.rake-compiler'))
begin
require "rake/extensiontask"
ENV['RUBY_CC_VERSION'] = '1.8.6:1.9.1'
load('home_run.gemspec')
desc "Internal--cross compile the windows binary gem"
cross_platform = ENV['CROSS_PLATFORM'] || 'i386-mingw32'
Rake::ExtensionTask.new('date_ext', HOME_RUN_GEMSPEC) do |ext|
ext.name = 'date_ext'
ext.ext_dir = 'ext'
ext.lib_dir = 'ext'
ext.cross_compile = true
ext.cross_platform = cross_platform
ext.source_pattern = '*.c'
end
# FIXME: Incredibly hacky, should figure out how to get
# rake compiler to do this correctly
desc "Build the cross compiled windows binary gem"
task :windows_gem => [:clean, :parser] do
sh %{rm -rf tmp pkg home_run-*.gem ext/1.*}
system %{rake cross native gem}
unless File.directory?('pkg')
sh "cp ext/*.c tmp/#{cross_platform}/date_ext/1.8.6"
system %{rake cross native gem}
sh "cp ext/*.c tmp/#{cross_platform}/date_ext/1.9.1"
system %{rake cross native gem}
sh %{rake cross native gem}
end
sh %{rm -rf home_run-*.gem tmp ext/1.*}
sh %{mv pkg/home_run-*.gem .}
sh %{rmdir pkg}
end
rescue LoadError
end
end
desc "Build the ragel parser"
task :parser do
sh %{cd ext && ragel date_parser.rl}
end
desc "Build the extension"
task :build=>[:clean] do
sh %{cd ext && #{RUBY} extconf.rb && make}
end
desc "Build debug version of extension"
task :build_debug=>[:clean] do
ENV['DEBUG'] = '1'
sh %{cd ext && #{RUBY} extconf.rb && make}
end
desc "Start an IRB shell using the extension"
task :irb do
irb = ENV['IRB'] || File.join(RbConfig::CONFIG['bindir'], File.basename(RUBY).sub('ruby', 'irb'))
sh %{#{irb} -I ext -r date}
end
desc "Run comparative benchmarks"
task :bench do
sh %{#{RUBY} bench/cpu_bench.rb}
end
desc "Run all benchmarks"
task :bench_all => [:bench, :mem_bench, :garbage_bench]
desc "Run comparative benchmarks"
task :parser_bench do
sh %{#{RUBY} bench/parser_bench.rb}
end
desc "Run comparative memory benchmarks"
task :mem_bench do
if RUBY_PLATFORM =~ /mswin|mingw/
puts "Memory benchmarks not supported on Windows"
next
end
stdlib = `#{RUBY} -I #{RbConfig::CONFIG['rubylibdir']} bench/mem_bench.rb`.to_i
home_run = `#{RUBY} -I ext bench/mem_bench.rb`.to_i
puts "Date memory use,#{stdlib}KB,#{home_run}KB,#{sprintf('%0.1f', stdlib/home_run.to_f)}"
stdlib = `#{RUBY} -I #{RbConfig::CONFIG['rubylibdir']} bench/dt_mem_bench.rb`.to_i
home_run = `#{RUBY} -I ext bench/dt_mem_bench.rb`.to_i
puts "DateTime memory use,#{stdlib}KB,#{home_run}KB,#{sprintf('%0.1f', stdlib/home_run.to_f)}"
end
desc "Run comparative garbage creation benchmarks"
task :garbage_bench do
if RUBY_PLATFORM =~ /mswin|mingw/
puts "Garbage creation benchmarks not supported on Windows"
next
end
stdlib = `#{RUBY} -I #{RbConfig::CONFIG['rubylibdir']} bench/garbage_bench.rb`.to_i
home_run = `#{RUBY} -I ext bench/garbage_bench.rb`.to_i
puts "Date garbage created,#{stdlib}KB,#{home_run}KB,#{sprintf('%0.1f', stdlib/home_run.to_f)}"
stdlib = `#{RUBY} -I #{RbConfig::CONFIG['rubylibdir']} bench/dt_garbage_bench.rb`.to_i
home_run = `#{RUBY} -I ext bench/dt_garbage_bench.rb`.to_i
puts "DateTime garbage created,#{stdlib}KB,#{home_run}KB,#{sprintf('%0.1f', stdlib/home_run.to_f)}"
end