elna/Rakefile

89 lines
2.2 KiB
Ruby
Raw Normal View History

2022-06-05 15:16:04 +02:00
require 'pathname'
require 'rake/clean'
require 'open3'
DFLAGS = ['--warn-no-deprecated', '-L/usr/lib64/gcc-12']
BINARY = 'build/bin/elna'
2022-06-11 00:38:03 +02:00
TESTS = FileList['tests/*.eln'].flat_map do |test|
2022-06-05 23:43:45 +02:00
build = Pathname.new 'build'
2022-06-11 00:38:03 +02:00
test_basename = Pathname.new(test).basename('')
2022-06-05 23:43:45 +02:00
2022-06-11 00:38:03 +02:00
[build + 'riscv' + test_basename].map { |path| path.sub_ext('').to_path }
2022-06-05 23:43:45 +02:00
end
2022-06-11 00:38:03 +02:00
2022-06-05 15:16:04 +02:00
SOURCES = FileList['source/**/*.d']
directory 'build'
CLEAN.include 'build'
CLEAN.include '.dub'
2022-06-11 00:38:03 +02:00
rule(/build\/riscv\/[^\/\.]+$/ => ->(file) { test_for_out(file, '.o') }) do |t|
sh '/opt/riscv/bin/riscv32-unknown-elf-ld',
'-o', t.name,
2022-06-11 00:38:03 +02:00
'-L/opt/riscv/lib/gcc/riscv32-unknown-elf/11.1.0',
'-L/opt/riscv/riscv32-unknown-elf/lib',
'/opt/riscv/riscv32-unknown-elf/lib/crt0.o',
'/opt/riscv/lib/gcc/riscv32-unknown-elf/11.1.0/crtbegin.o',
t.source,
2022-06-11 22:52:13 +02:00
'--start-group', '-lgcc', '-lc', '-lgloss', '--end-group',
2022-06-11 00:38:03 +02:00
'/opt/riscv/lib/gcc/riscv32-unknown-elf/11.1.0/crtend.o'
2022-06-05 23:43:45 +02:00
end
2022-06-11 00:38:03 +02:00
rule(/build\/riscv\/.+\.o$/ => ->(file) { test_for_object(file, '.eln') }) do |t|
2022-06-05 15:16:04 +02:00
Pathname.new(t.name).dirname.mkpath
sh BINARY, '-o', t.name, t.source
end
2022-06-05 15:16:04 +02:00
file BINARY => SOURCES do |t|
sh({ 'DFLAGS' => (DFLAGS * ' ') }, 'dub', 'build', '--compiler=gdc-12')
end
task default: BINARY
desc 'Run all tests and check the results'
task test: TESTS
task test: BINARY do
TESTS.each do |test|
expected = Pathname
.new(test)
.sub_ext('.txt')
2022-06-05 23:43:45 +02:00
.sub(/^build\/[[:alpha:]]+\//, 'tests/expectations/')
2022-06-05 15:16:04 +02:00
.read
.to_i
puts "Running #{test}"
2022-06-11 00:38:03 +02:00
if test.include? '/riscv/'
system('/opt/riscv/bin/spike',
'/opt/riscv/riscv32-unknown-elf/bin/pk', test,
{ out: '/dev/null' })
else
raise 'Unsupported test platform'
end
2022-06-05 15:16:04 +02:00
actual = $?.exitstatus
fail "#{test}: Expected #{expected}, got #{actual}" unless expected == actual
end
end
desc 'Run unittest blocks'
task unittest: SOURCES do |t|
sh('dub', 'test', '--compiler=gdc-12')
end
2022-06-11 00:38:03 +02:00
def test_for_object(out_file, extension)
2022-06-05 15:16:04 +02:00
test_source = Pathname
.new(out_file)
2022-06-11 00:38:03 +02:00
.sub_ext(extension)
2022-06-05 23:43:45 +02:00
.sub(/^build\/[[:alpha:]]+\//, 'tests/')
2022-06-05 15:16:04 +02:00
.to_path
[test_source, BINARY]
end
2022-06-05 23:43:45 +02:00
def test_for_out(out_file, extension)
2022-06-05 23:43:45 +02:00
Pathname
.new(out_file)
.sub_ext(extension)
2022-06-05 23:43:45 +02:00
.to_path
end