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-05 23:43:45 +02:00
|
|
|
TESTS = FileList['tests/*.elna'].flat_map do |test|
|
|
|
|
build = Pathname.new 'build'
|
|
|
|
asm_test = build + 'asm' + Pathname.new(test).basename('')
|
|
|
|
|
|
|
|
[build + test, asm_test].map { |path| path.sub_ext('').to_path }
|
|
|
|
end
|
2022-06-05 15:16:04 +02:00
|
|
|
SOURCES = FileList['source/**/*.d']
|
|
|
|
|
|
|
|
directory 'build'
|
|
|
|
|
|
|
|
CLEAN.include 'build'
|
|
|
|
CLEAN.include '.dub'
|
|
|
|
|
2022-06-08 08:34:44 +02:00
|
|
|
rule(/build\/tests\/[^\/\.]+$/ => ->(file) { test_for_out(file, '.o') }) do |t|
|
|
|
|
sh 'ld.gold', '-L/usr/lib64',
|
|
|
|
'--dynamic-linker', '/lib64/ld-linux-x86-64.so.2',
|
|
|
|
'-o', t.name,
|
|
|
|
'/usr/lib64/crt1.o', '/usr/lib64/crti.o', '-lc', t.source, '/usr/lib64/crtn.o'
|
2022-06-05 23:43:45 +02:00
|
|
|
end
|
|
|
|
|
2022-06-08 08:34:44 +02:00
|
|
|
rule(/build\/asm\/[^\/\.]+$/ => ->(file) { test_for_out(file, '.s') }) do |t|
|
|
|
|
sh 'gcc', '-x', 'assembler', '-o', t.name, t.source
|
2022-06-05 23:43:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
rule(/build\/tests\/.+\.o$/ => ->(file) { test_for_object(file) }) do |t|
|
2022-06-05 15:16:04 +02:00
|
|
|
Pathname.new(t.name).dirname.mkpath
|
2022-06-08 08:34:44 +02:00
|
|
|
sh BINARY, '-o', t.name, t.source
|
|
|
|
end
|
|
|
|
|
|
|
|
rule(/build\/asm\/.+\.s$/ => ->(file) { test_for_object(file) }) do |t|
|
|
|
|
Pathname.new(t.name).dirname.mkpath
|
|
|
|
sh BINARY, '-s', '-o', t.name, t.source
|
2022-06-05 15:16:04 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
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}"
|
|
|
|
system test
|
|
|
|
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-05 23:43:45 +02:00
|
|
|
def test_for_object(out_file)
|
2022-06-05 15:16:04 +02:00
|
|
|
test_source = Pathname
|
|
|
|
.new(out_file)
|
|
|
|
.sub_ext('.elna')
|
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
|
|
|
|
2022-06-08 08:34:44 +02:00
|
|
|
def test_for_out(out_file, extension)
|
2022-06-05 23:43:45 +02:00
|
|
|
Pathname
|
|
|
|
.new(out_file)
|
2022-06-08 08:34:44 +02:00
|
|
|
.sub_ext(extension)
|
2022-06-05 23:43:45 +02:00
|
|
|
.to_path
|
|
|
|
end
|