elna/Rakefile

96 lines
2.4 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,
2024-02-15 15:13:47 +01:00
'-L/opt/riscv/lib/gcc/riscv32-unknown-elf/13.2.0/',
2022-06-11 00:38:03 +02:00
'-L/opt/riscv/riscv32-unknown-elf/lib',
'/opt/riscv/riscv32-unknown-elf/lib/crt0.o',
2024-02-15 15:13:47 +01:00
'/opt/riscv/lib/gcc/riscv32-unknown-elf/13.2.0/crtbegin.o',
2022-06-11 00:38:03 +02:00
t.source,
2022-06-11 22:52:13 +02:00
'--start-group', '-lgcc', '-lc', '-lgloss', '--end-group',
2024-02-15 15:13:47 +01:00
'/opt/riscv/lib/gcc/riscv32-unknown-elf/13.2.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|
2024-02-15 15:13:47 +01:00
sh({ 'DFLAGS' => (DFLAGS * ' ') }, 'dub', 'build', '--compiler=gdc')
2022-06-05 15:16:04 +02:00
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-12 23:48:50 +02:00
.to_path
2022-06-05 15:16:04 +02:00
puts "Running #{test}"
2022-06-11 00:38:03 +02:00
if test.include? '/riscv/'
2022-06-12 23:48:50 +02:00
spike = [
'/opt/riscv/bin/spike',
2024-02-15 15:13:47 +01:00
'--isa=RV32IMAC',
2022-06-12 23:48:50 +02:00
'/opt/riscv/riscv32-unknown-elf/bin/pk',
test
]
diff = ['diff', '-Nur', '--color', expected, '-']
tail = ['tail', '-n', '1']
last_stdout, wait_threads = Open3.pipeline_r spike, tail, diff
2022-06-11 00:38:03 +02:00
else
raise 'Unsupported test platform'
end
2022-06-12 23:48:50 +02:00
print last_stdout.read
last_stdout.close
2022-06-05 15:16:04 +02:00
2022-06-12 23:48:50 +02:00
fail unless wait_threads.last.value.exitstatus.zero?
2022-06-05 15:16:04 +02:00
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