From 2676bd7b62f1f43c67aeb450769ff1d9e2e5aaff Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Fri, 8 Nov 2024 15:04:10 +0100 Subject: [PATCH] fixing error messages --- repbuild/src/dev.rs | 31 ++++++++++--------- repbuild/src/main.rs | 21 ++++++++++++- .../render_example/src/examples/text.hb | 2 +- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/repbuild/src/dev.rs b/repbuild/src/dev.rs index f93edd1..91c4644 100644 --- a/repbuild/src/dev.rs +++ b/repbuild/src/dev.rs @@ -62,12 +62,11 @@ impl Package { build_cmd, } } - pub fn build(&self) -> std::io::Result<()> { + pub fn build(&self, out: &mut Vec) -> std::io::Result<()> { if self.binaries.contains(&"hblang".to_string()) { let file = self.build_cmd.split_ascii_whitespace().last().unwrap(); let path = format!("sysdata/programs/{}/{}", self.name, file); - let mut bytes = Vec::new(); // compile here hblang::run_compiler( @@ -76,15 +75,7 @@ impl Package { fmt: true, ..Default::default() }, - &mut bytes, - )?; - - hblang::run_compiler( - &path, - Options { - ..Default::default() - }, - &mut bytes, + out, )?; match std::fs::create_dir("target/programs") { @@ -92,17 +83,27 @@ impl Package { Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => (), Err(e) => panic!("{}", e), } - std::fs::write(format!("target/programs/{}.hbf", self.name), &bytes).unwrap(); - bytes.clear(); + + hblang::run_compiler( + &path, + Options { + ..Default::default() + }, + out, + )?; + std::fs::write(format!("target/programs/{}.hbf", self.name), &out)?; + out.clear(); + hblang::run_compiler( &path, Options { dump_asm: true, ..Default::default() }, - &mut bytes, + out, )?; - std::fs::write(format!("target/programs/{}.hba", self.name), &bytes).unwrap(); + std::fs::write(format!("target/programs/{}.hba", self.name), &out)?; + out.clear(); } Ok(()) } diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index 19f2d38..898d1f7 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -1,6 +1,7 @@ mod dev; use { + core::fmt::Write as _, derive_more::Display, dev::Package, error_stack::{bail, report, Context, Report, Result, ResultExt}, @@ -204,6 +205,9 @@ TERM_BACKDROP={} let modules = value.get_mut("modules").unwrap().as_table_mut().unwrap(); // let mut real_modules = modules.clone(); + let mut errors = String::new(); + let mut out = Vec::new(); + modules .into_iter() .map(|(_, value)| -> Result<(), io::Error> { @@ -218,11 +222,26 @@ TERM_BACKDROP={} let p = Package::load_from_file( format!("sysdata/programs/{}/meta.toml", path).to_owned(), ); - p.build()?; + match p.build(&mut out) { + Ok(()) => {} + Err(_) => { + writeln!(errors, "========= while compiling {} =========", path) + .unwrap(); + errors.push_str(core::str::from_utf8(&out).expect("no")); + out.clear(); + } + } } Ok(()) }) .for_each(drop); + + if !errors.is_empty() { + writeln!(errors, "!!! STOPPING DUE TO PREVIOUS ERRORS !!!"); + std::eprint!("{errors}"); + continue; + } + modules.into_iter().for_each(|(_key, value)| { if value.is_table() { let path = value.get("path").expect("You must have `path` as a value"); diff --git a/sysdata/programs/render_example/src/examples/text.hb b/sysdata/programs/render_example/src/examples/text.hb index 71b4d50..2f2c299 100644 --- a/sysdata/programs/render_example/src/examples/text.hb +++ b/sysdata/programs/render_example/src/examples/text.hb @@ -148,4 +148,4 @@ draw_screen := fn(screen: render.Surface, window: render.Surface): void { render.clear(screen, render.light_blue) render.put_surface(screen, window, .(100, 100), false) render.sync(screen) -} \ No newline at end of file +}