1
0
Fork 0
forked from AbleOS/ableos

fixing error messages

This commit is contained in:
Jakub Doka 2024-11-08 15:04:10 +01:00
parent 444fcdb0c4
commit 2676bd7b62
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
3 changed files with 37 additions and 17 deletions

View file

@ -62,12 +62,11 @@ impl Package {
build_cmd, build_cmd,
} }
} }
pub fn build(&self) -> std::io::Result<()> { pub fn build(&self, out: &mut Vec<u8>) -> std::io::Result<()> {
if self.binaries.contains(&"hblang".to_string()) { if self.binaries.contains(&"hblang".to_string()) {
let file = self.build_cmd.split_ascii_whitespace().last().unwrap(); let file = self.build_cmd.split_ascii_whitespace().last().unwrap();
let path = format!("sysdata/programs/{}/{}", self.name, file); let path = format!("sysdata/programs/{}/{}", self.name, file);
let mut bytes = Vec::new();
// compile here // compile here
hblang::run_compiler( hblang::run_compiler(
@ -76,15 +75,7 @@ impl Package {
fmt: true, fmt: true,
..Default::default() ..Default::default()
}, },
&mut bytes, out,
)?;
hblang::run_compiler(
&path,
Options {
..Default::default()
},
&mut bytes,
)?; )?;
match std::fs::create_dir("target/programs") { match std::fs::create_dir("target/programs") {
@ -92,17 +83,27 @@ impl Package {
Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => (), Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => (),
Err(e) => panic!("{}", e), 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( hblang::run_compiler(
&path, &path,
Options { Options {
dump_asm: true, dump_asm: true,
..Default::default() ..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(()) Ok(())
} }

View file

@ -1,6 +1,7 @@
mod dev; mod dev;
use { use {
core::fmt::Write as _,
derive_more::Display, derive_more::Display,
dev::Package, dev::Package,
error_stack::{bail, report, Context, Report, Result, ResultExt}, 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 modules = value.get_mut("modules").unwrap().as_table_mut().unwrap();
// let mut real_modules = modules.clone(); // let mut real_modules = modules.clone();
let mut errors = String::new();
let mut out = Vec::new();
modules modules
.into_iter() .into_iter()
.map(|(_, value)| -> Result<(), io::Error> { .map(|(_, value)| -> Result<(), io::Error> {
@ -218,11 +222,26 @@ TERM_BACKDROP={}
let p = Package::load_from_file( let p = Package::load_from_file(
format!("sysdata/programs/{}/meta.toml", path).to_owned(), 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(()) Ok(())
}) })
.for_each(drop); .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)| { modules.into_iter().for_each(|(_key, value)| {
if value.is_table() { if value.is_table() {
let path = value.get("path").expect("You must have `path` as a value"); let path = value.get("path").expect("You must have `path` as a value");

View file

@ -148,4 +148,4 @@ draw_screen := fn(screen: render.Surface, window: render.Surface): void {
render.clear(screen, render.light_blue) render.clear(screen, render.light_blue)
render.put_surface(screen, window, .(100, 100), false) render.put_surface(screen, window, .(100, 100), false)
render.sync(screen) render.sync(screen)
} }