-
Notifications
You must be signed in to change notification settings - Fork 18
/
Rakefile
374 lines (321 loc) · 12.6 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# frozen_string_literal: true
require "etc"
$root = Pathname.new(__FILE__).dirname.realpath
$lib = $root / "lib"
require "ruby-progressbar"
require "yard"
require "minitest/test_task"
require_relative $root / "lib" / "validate"
directory "#{$root}/.stamps"
Dir.glob("#{$root}/backends/*/tasks.rake") do |rakefile|
load rakefile
end
directory "#{$root}/.stamps"
file "#{$root}/.stamps/dev_gems" => "#{$root}/.stamps" do
Dir.chdir($root) do
sh "bundle config set --local with development"
sh "bundle install"
FileUtils.touch "#{$root}/.stamps/dev_gems"
end
end
namespace :gen do
desc "Generate documentation for the ruby tooling"
task tool_doc: "#{$root}/.stamps/dev_gems" do
Dir.chdir($root) do
sh "bundle exec yard doc --yardopts arch_def.yardopts"
sh "bundle exec yard doc --yardopts idl.yardopts"
end
end
end
namespace :serve do
desc <<~DESC
Start an HTML server to view the generated HTML documentation for the tool
The default port is 8000, though it can be overridden with an argument
DESC
task :tool_doc, [:port] => "gen:tool_doc" do |_t, args|
args.with_defaults(port: 8000)
puts <<~MSG
Server will come up on http://#{`hostname`.strip}:#{args[:port]}.
It will regenerate the documentation on every access
MSG
sh "yard server -p #{args[:port]} --reload"
end
end
namespace :test do
# "Run the IDL compiler test suite"
task :idl_compiler do
t = Minitest::TestTask.new(:lib_test)
t.test_globs = ["#{$root}/lib/idl/tests/test_*.rb"]
t.process_env
ruby t.make_test_cmd
end
# "Run the Ruby library test suite"
task :lib do
t = Minitest::TestTask.new(:lib_test)
t.test_globs = ["#{$root}/lib/test/test_*.rb"]
t.process_env
ruby t.make_test_cmd
end
end
desc "Clean up all generated files"
task :clean do
FileUtils.rm_rf $root / "gen"
FileUtils.rm_rf $root / ".stamps"
end
namespace :test do
task :insts do
puts "Checking instruction encodings..."
inst_paths = Dir.glob("#{$root}/arch/inst/**/*.yaml").map { |f| Pathname.new(f) }
inst_paths.each do |inst_path|
Validator.instance.validate_instruction(inst_path)
end
puts "All instruction encodings pass basic sanity tests"
end
task schema: "gen:arch" do
validator = Validator.instance
puts "Checking arch files against schema.."
arch_files = Dir.glob("#{$root}/arch/**/*.yaml")
progressbar = ProgressBar.create(total: arch_files.size)
arch_files.each do |f|
progressbar.increment
validator.validate(f)
end
Rake::Task["test:insts"].invoke
puts "All files validate against their schema"
end
task idl_model: ["gen:arch", "#{$root}/.stamps/arch-gen-_32.stamp", "#{$root}/.stamps/arch-gen-_64.stamp"] do
print "Parsing IDL code for RV32..."
arch_def_32 = arch_def_for("_32")
puts "done"
arch_def_32.type_check
print "Parsing IDL code for RV64..."
arch_def_64 = arch_def_for("_64")
puts "done"
arch_def_64.type_check
puts "All IDL passed type checking"
end
end
def insert_warning(str, from)
# insert a warning on the second line
lines = str.lines
first_line = lines.shift
lines.unshift(first_line, "\n# WARNING: This file is auto-generated from #{Pathname.new(from).relative_path_from($root)}\n\n").join("")
end
private :insert_warning
(3..31).each do |hpm_num|
file "#{$root}/arch/csr/Zihpm/mhpmcounter#{hpm_num}.yaml" => [
"#{$root}/arch/csr/Zihpm/mhpmcounterN.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/Zihpm/mhpmcounterN.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/Zihpm/mhpmcounterN.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
file "#{$root}/arch/csr/Zihpm/mhpmcounter#{hpm_num}h.yaml" => [
"#{$root}/arch/csr/Zihpm/mhpmcounterNh.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/Zihpm/mhpmcounterNh.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/Zihpm/mhpmcounterNh.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
file "#{$root}/arch/csr/Zihpm/mhpmevent#{hpm_num}.yaml" => [
"#{$root}/arch/csr/Zihpm/mhpmeventN.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/Zihpm/mhpmeventN.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/Zihpm/mhpmeventN.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
file "#{$root}/arch/csr/Zihpm/mhpmevent#{hpm_num}h.yaml" => [
"#{$root}/arch/csr/Zihpm/mhpmeventNh.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/Zihpm/mhpmeventNh.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/Zihpm/mhpmeventNh.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
file "#{$root}/arch/csr/Zihpm/hpmcounter#{hpm_num}.yaml" => [
"#{$root}/arch/csr/Zihpm/hpmcounterN.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/Zihpm/hpmcounterN.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/Zihpm/hpmcounterN.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
file "#{$root}/arch/csr/Zihpm/hpmcounter#{hpm_num}h.yaml" => [
"#{$root}/arch/csr/Zihpm/hpmcounterNh.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/Zihpm/hpmcounterNh.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/Zihpm/hpmcounterNh.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
end
(0..63).each do |pmpaddr_num|
file "#{$root}/arch/csr/I/pmpaddr#{pmpaddr_num}.yaml" => [
"#{$root}/arch/csr/I/pmpaddrN.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/I/pmpaddrN.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/I/pmpaddrN.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
end
(0..15).each do |pmpcfg_num|
file "#{$root}/arch/csr/I/pmpcfg#{pmpcfg_num}.yaml" => [
"#{$root}/arch/csr/I/pmpcfgN.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/I/pmpcfgN.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/I/pmpcfgN.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
end
file "#{$root}/arch/csr/I/mcounteren.yaml" => [
"#{$root}/arch/csr/I/mcounteren.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/I/mcounteren.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/I/mcounteren.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
file "#{$root}/arch/csr/S/scounteren.yaml" => [
"#{$root}/arch/csr/S/scounteren.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/S/scounteren.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/S/scounteren.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
file "#{$root}/arch/csr/H/hcounteren.yaml" => [
"#{$root}/arch/csr/H/hcounteren.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/H/hcounteren.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/H/hcounteren.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
file "#{$root}/arch/csr/Zicntr/mcountinhibit.yaml" => [
"#{$root}/arch/csr/Zicntr/mcountinhibit.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/Zicntr/mcountinhibit.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/Zicntr/mcountinhibit.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
namespace :gen do
desc "Generate architecture files from layouts"
task :arch do
(3..31).each do |hpm_num|
Rake::Task["#{$root}/arch/csr/Zihpm/mhpmcounter#{hpm_num}.yaml"].invoke
Rake::Task["#{$root}/arch/csr/Zihpm/mhpmcounter#{hpm_num}h.yaml"].invoke
Rake::Task["#{$root}/arch/csr/Zihpm/mhpmevent#{hpm_num}.yaml"].invoke
Rake::Task["#{$root}/arch/csr/Zihpm/mhpmevent#{hpm_num}h.yaml"].invoke
Rake::Task["#{$root}/arch/csr/Zihpm/hpmcounter#{hpm_num}.yaml"].invoke
Rake::Task["#{$root}/arch/csr/Zihpm/hpmcounter#{hpm_num}h.yaml"].invoke
end
Rake::Task["#{$root}/arch/csr/I/mcounteren.yaml"].invoke
Rake::Task["#{$root}/arch/csr/S/scounteren.yaml"].invoke
Rake::Task["#{$root}/arch/csr/H/hcounteren.yaml"].invoke
Rake::Task["#{$root}/arch/csr/Zicntr/mcountinhibit.yaml"].invoke
(0..63).each do |pmpaddr_num|
Rake::Task["#{$root}/arch/csr/I/pmpaddr#{pmpaddr_num}.yaml"].invoke
end
(0..15).each do |pmpcfg_num|
Rake::Task["#{$root}/arch/csr/I/pmpcfg#{pmpcfg_num}.yaml"].invoke
end
end
end
namespace :test do
desc <<~DESC
Run smoke tests
These are basic but fast-running tests to check the database and tools
DESC
task :smoke do
Rake::Task["test:idl_compiler"].invoke
Rake::Task["test:lib"].invoke
Rake::Task["test:schema"].invoke
Rake::Task["test:idl_model"].invoke
end
desc <<~DESC
Run the regression tests
These tests must pass before a commit will be allowed in the main branch on GitHub
DESC
task :regress do
Rake::Task["test:smoke"].invoke
ENV["MANUAL_NAME"] = "isa"
ENV["VERSIONS"] = "all"
Rake::Task["gen:html_manual"].invoke
ENV["EXT"] = "B"
ENV["VERSION"] = "latest"
Rake::Task["gen:ext_pdf"].invoke
Rake::Task["gen:html"].invoke("generic_rv64")
Rake::Task["#{$root}/gen/certificate_doc/pdf/MockCertificateModel.pdf"].invoke
Rake::Task["#{$root}/gen/profile_doc/pdf/MockProfileRelease.pdf"].invoke
puts
puts "Regression test PASSED"
end
desc <<~DESC
Run the nightly regression tests
Generally, this tries to build all artifacts
DESC
task :nightly do
Rake::Task["regress"].invoke
Rake::Task["#{$root}/gen/certificate_doc/pdf/MC100.pdf"].invoke
Rake::Task["#{$root}/gen/profile_doc/pdf/RVA20.pdf"].invoke
Rake::Task["#{$root}/gen/profile_doc/pdf/RVA22.pdf"].invoke
Rake::Task["#{$root}/gen/profile_doc/pdf/RVI20.pdf"].invoke
puts
puts "Nightly regression test PASSED"
end
end
namespace :gen do
desc <<~DESC
Generate all certificates and profile PDFs.
DESC
task :cert_profile_pdfs do
puts "==================================="
puts "cert_profile_pdfs: Generating MC100"
puts " 1st target"
puts "==================================="
Rake::Task["#{$root}/gen/certificate_doc/pdf/MC100.pdf"].invoke
puts "=================================================="
puts "cert_profile_pdfs: Generating MockCertificateModel"
puts " 2nd target"
puts "=================================================="
Rake::Task["#{$root}/gen/certificate_doc/pdf/MockCertificateModel.pdf"].invoke
puts "==================================="
puts "cert_profile_pdfs: Generating RVA20"
puts " 3rd target"
puts "==================================="
Rake::Task["#{$root}/gen/profile_doc/pdf/RVA20.pdf"].invoke
puts "==================================="
puts "cert_profile_pdfs: Generating RVA22"
puts " 4th target"
puts "==================================="
Rake::Task["#{$root}/gen/profile_doc/pdf/RVA22.pdf"].invoke
puts "==================================="
puts "cert_profile_pdfs: Generating RVI20"
puts " 5th target"
puts "==================================="
Rake::Task["#{$root}/gen/profile_doc/pdf/RVI20.pdf"].invoke
puts "==================================="
puts "cert_profile_pdfs: Generating MockProfileRelease"
puts " 6th target"
puts "==================================="
Rake::Task["#{$root}/gen/profile_doc/pdf/MockProfileRelease.pdf"].invoke
end
end