# This Source Code Form is subject to the terms of the Mozilla Public License, # v. 2.0. If a copy of the MPL was not distributed with this file, You can # obtain one at https://mozilla.org/MPL/2.0/. # frozen_string_literal: true require 'open3' require 'rake/clean' STAGES = Dir.glob('boot/stage*') .collect { |stage| File.basename stage } .sort { |a, b| a.delete_prefix('stage').to_i <=> b.delete_prefix('stage').to_i } .drop(1) # First assembly stage does not count. CLOBBER.include 'build' def run(exe) ENV.fetch('QEMU', '').split << exe end directory 'build' task :default do Rake::Task["build/valid/#{STAGES.last}/cl"].invoke Rake::Task["boot"].invoke end desc 'Final stage' task boot: "build/valid/#{STAGES.last}/cl" task boot: "boot/#{STAGES.last}/cl.elna" do |t| groupped = t.prerequisites.group_by { |stage| File.extname stage }.transform_values(&:first) exe = groupped[''] expected = groupped[''] + '.s' source = groupped['.elna'] cat_arguments = ['cat', source] diff_arguments = ['diff', '-Nur', '--text', expected, '-'] Open3.pipeline(cat_arguments, run(exe), diff_arguments) end namespace :stage do stage_number = STAGES.last.delete_prefix('stage').to_i desc 'Create a new stabe by duplicating the last one' task :new do new_stage = "stage#{stage_number.succ}" cp_r "boot/stage#{stage_number}", "boot/#{new_stage}" STAGES << new_stage Rake::Task['ninja'].invoke end desc 'Delete the last stage' task :drop do rm_r "boot/stage#{stage_number}" STAGES.pop Rake::Task['ninja'].invoke end desc 'Convert previous stage language into the current stage language' task :convert do from = "boot/stage#{stage_number.pred}/cl.elna" to = "boot/stage#{stage_number}/cl.elna" puts "Converting #{from} to #{to}." File.open(to, 'w') do |current_stage| File.readlines(from).each do |line| current_stage << line end end end end