Skip to content

Commit c77a9b4

Browse files
committed
Add type checking to Rakefile
1 parent dc130df commit c77a9b4

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

Rakefile

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# frozen_string_literal: true
2+
# typed: true
3+
4+
require "sorbet-runtime"
5+
T.bind(self, T.all(Rake::DSL, Object))
6+
extend T::Sig
27

38
$jobs = ENV["JOBS"].nil? ? 1 : ENV["JOBS"].to_i
49
Rake.application.options.thread_pool_size = $jobs
@@ -23,8 +28,8 @@ end
2328

2429
directory "#{$root}/.stamps"
2530

31+
sig { params(config: T.any(String, Pathname)).returns(ConfiguredArchitecture) }
2632
def cfg_arch_for(config)
27-
raise ArgumentError, "excpecting String or Pathname" unless config.is_a?(String) || config.is_a?(Pathname)
2833
config = config.to_s
2934

3035
$cfg_archs ||= {}
@@ -146,26 +151,28 @@ namespace :serve do
146151
end
147152
end
148153

154+
sig { params(test_files: T::Array[String]).returns(String) }
155+
def make_test_cmd(test_files)
156+
"-Ilib:test -w -e 'require \"minitest/autorun\"; #{test_files.map{ |f| "require \"#{f}\""}.join("; ")}' --"
157+
end
158+
149159
namespace :test do
150160
# "Run the IDL compiler test suite"
151161
task :idl_compiler do
152-
t = Minitest::TestTask.new(:lib_test)
153-
t.test_globs = ["#{$root}/lib/idl/tests/test_*.rb"]
154-
t.process_env
155-
ruby t.make_test_cmd
162+
test_files = Dir["#{$root}/lib/idl/tests/test_*.rb"]
163+
ruby make_test_cmd(test_files)
156164
end
157165

158166
# "Run the Ruby library test suite"
159167
task :lib do
160-
t = Minitest::TestTask.new(:lib_test)
161-
t.test_globs = ["#{$root}/lib/test/test_*.rb"]
162-
t.process_env
163-
ruby t.make_test_cmd
168+
test_files = Dir["#{$root}/lib/test/test_*.rb"]
169+
170+
ruby make_test_cmd(test_files)
164171
end
165172

166173
desc "Type-check the Ruby library"
167174
task :sorbet do
168-
sh "srb tc --no-config @.sorbet-config"
175+
sh "srb tc"
169176
end
170177
end
171178

@@ -187,13 +194,13 @@ namespace :test do
187194

188195
cfg_arch = cfg_arch_for("_")
189196
insts = cfg_arch.instructions
190-
failed = false
197+
failed = T.let(false, T::Boolean)
191198
insts.each_with_index do |inst, idx|
192199
[32, 64].each do |xlen|
193200
next unless inst.defined_in_base?(xlen)
194201

195202
(idx...insts.size).each do |other_idx|
196-
other_inst = insts[other_idx]
203+
other_inst = T.must(insts[other_idx])
197204
next unless other_inst.defined_in_base?(xlen)
198205
next if other_inst == inst
199206

@@ -215,13 +222,13 @@ namespace :test do
215222

216223
cfg_arch = cfg_arch_for("_")
217224
csrs = cfg_arch.csrs
218-
failed = false
225+
failed = T.let(false, T::Boolean)
219226
csrs.each_with_index do |csr, idx|
220227
[32, 64].each do |xlen|
221228
next unless csr.defined_in_base?(xlen)
222229

223230
(idx...csrs.size).each do |other_idx|
224-
other_csr = csrs[other_idx]
231+
other_csr = T.must(csrs[other_idx])
225232
next unless other_csr.defined_in_base?(xlen)
226233
next if other_csr == csr
227234

@@ -266,7 +273,6 @@ def insert_warning(str, from)
266273
first_line = lines.shift
267274
lines.unshift(first_line, "\n# WARNING: This file is auto-generated from #{Pathname.new(from).relative_path_from($root)}").join("")
268275
end
269-
private :insert_warning
270276

271277
(3..31).each do |hpm_num|
272278
file "#{$root}/arch/csr/Zihpm/mhpmcounter#{hpm_num}.yaml" => [

sorbet/config

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
--dir
22
lib
3+
--dir
4+
sorbet/rbi
5+
--file
6+
Rakefile
37
--file
48
backends/ext_pdf_doc/idl_lexer.rb
59
--file
610
backends/cpp_hart_gen/lib/template_helpers.rb
7-
--ignore=tmp/
8-
--ignore=vendor/
9-
--ignore=.home/
10-
--ignore=node_modules/

sorbet/rbi/dsl/architecture.rbi

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)