forked from trema/trema
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
214 lines (167 loc) · 4.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
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
#
# Copyright (C) 2008-2012 NEC Corporation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
require "rubygems"
require "rake"
task :default do
sh "./build.rb"
end
task :travis => [ :default, "spec:travis" ]
begin
require "bundler/gem_tasks"
rescue LoadError
$stderr.puts $!.to_s
end
begin
require "rspec/core"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new( :spec ) do | spec |
spec.pattern = FileList[ "spec/**/*_spec.rb" ]
end
RSpec::Core::RakeTask.new( "spec:travis" ) do | spec |
spec.pattern = FileList[ "spec/**/*_spec.rb" ]
# FIXME: use --tag ~sudo
spec.rspec_opts = "--tag nosudo -fs -c"
end
RSpec::Core::RakeTask.new( :rcov ) do | spec |
spec.pattern = "spec/**/*_spec.rb"
spec.rcov = true
end
rescue LoadError
$stderr.puts $!.to_s
end
begin
require "cucumber/rake/task"
Cucumber::Rake::Task.new( :features ) do | t |
t.cucumber_opts = "features --tags ~@wip"
end
rescue LoadError
$stderr.puts $!.to_s
end
desc "Enforce Ruby code quality with static analysis of code"
task :quality => [ :reek, :roodi, :flog, :flay ]
begin
require "reek/rake/task"
Reek::Rake::Task.new do | t |
t.fail_on_error = true
t.verbose = false
t.ruby_opts = [ "-rubygems" ]
t.reek_opts = "--quiet"
t.source_files = "ruby/**/*.rb"
end
rescue LoadError
$stderr.puts $!.to_s
end
begin
require "roodi"
require "roodi_task"
RoodiTask.new do | t |
t.verbose = false
t.patterns = %w(ruby/**/*.rb spec/**/*.rb features/**/*.rb)
end
rescue LoadError
$stderr.puts $!.to_s
end
begin
require "flog"
desc "Analyze for code complexity"
task :flog do
flog = Flog.new( :continue => true )
flog.flog [ "ruby" ]
threshold = 10
bad_methods = flog.totals.select do | name, score |
name != "main#none" && score > threshold
end
bad_methods.sort do | a, b |
a[ 1 ] <=> b[ 1 ]
end.each do | name, score |
puts "%8.1f: %s" % [ score, name ]
end
unless bad_methods.empty?
raise "#{ bad_methods.size } methods have a flog complexity > #{ threshold }"
end
end
rescue LoadError
$stderr.puts $!.to_s
end
begin
require "flay"
require "flay_task"
FlayTask.new do | t |
t.dirs = %w( ruby )
t.threshold = 0
t.verbose = true
end
rescue LoadError
$stderr.puts $!.to_s
end
desc "Generate a monolithic rant file"
task "build.rb" do
sh "rant-import --force --auto .mono.rant"
end
begin
require "yard"
YARD::Rake::YardocTask.new do | t |
t.files = [ "ruby/trema/**/*.c", "ruby/trema/**/*.rb" ]
t.options = [ "--no-private" ]
t.options << "--debug" << "--verbose" if $trace
end
yardoc_i18n = "./vendor/yard.i18n/bin/yardoc"
namespace :yard do
desc "Generate YARD Documentation in Japanese"
task :ja => "yard:po" do
sh "#{ yardoc_i18n } --language ja ruby/trema"
end
end
locale_base_dir = "locale"
locale_dir = "#{ locale_base_dir }/ja"
pot = "#{ locale_base_dir }/yard.pot"
po = "#{ locale_dir }/yard.po"
namespace :yard do
desc "generate .pot file"
task :pot => pot
desc "Generate .po file"
task :po => po
file pot => FileList[ "ruby/trema/**/*.rb", "ruby/trema/**/*.c" ] do
Rake::Task[ "yard:pot:generate" ].invoke
end
namespace :pot do
task :generate do
sh( yardoc_i18n, "--no-yardopts", "--output", locale_base_dir, "--format", "pot", "ruby/trema" )
end
end
directory locale_dir
file po => [ locale_dir, pot ] do
Rake::Task[ "yard:po:generate" ].invoke
end
namespace :po do
task :generate do
if File.exist?( po )
sh( "msgmerge", "--update", "--sort-by-file", po, pot )
else
sh( "msginit", "--input", pot, "--output", po, "--locale", "ja.UTF-8" )
end
end
end
end
rescue LoadError
$stderr.puts $!.to_s
end
### Local variables:
### mode: Ruby
### coding: utf-8-unix
### indent-tabs-mode: nil
### End: