Skip to content

Commit

Permalink
Improved child process error printing in Rishka CC.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Feb 26, 2024
1 parent ed8392b commit 243b380
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
5 changes: 4 additions & 1 deletion tools/rishka-cc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ use std::process::exit;

fn compile_task(argv: Options, envvars: RishkaEnv) {
print!("{} ELF binary from sources... ", "Building".blue().bold());
if !process::run_riscv64_gpp(&argv, envvars) {

let (compiled, err) = process::run_riscv64_gpp(&argv, envvars);
if !compiled {
println!("something went {}.", "wrong".red().bold());
println!("{}", err);
exit(0);
}
else {
Expand Down
31 changes: 25 additions & 6 deletions tools/rishka-cc/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ extern crate colored;
use crate::args::Options;
use crate::env::RishkaEnv;
use colored::Colorize;
use std::io::Read;
use std::process::Command;
use std::process::exit;
use std::process::Stdio;

fn test_process(name: &str) -> bool {
match Command::new(name).arg("--version").output() {
Expand All @@ -40,8 +42,9 @@ fn check_dep(dep: &str) {
}
}

pub fn run_riscv64_gpp(options: &Options, cc_env: RishkaEnv) -> bool {
match Command::new("riscv64-unknown-elf-g++")
pub fn run_riscv64_gpp(options: &Options, cc_env: RishkaEnv) -> (bool, String) {
let mut binding = Command::new("riscv64-unknown-elf-g++");
let command = binding
.arg("-march=rv64im")
.arg("-mabi=lp64")
.arg("-nostdlib")
Expand All @@ -51,10 +54,26 @@ pub fn run_riscv64_gpp(options: &Options, cc_env: RishkaEnv) -> bool {
.arg(format!("-o{}.out", options.output))
.arg(format!("{}/librishka_impl.cpp", cc_env.library))
.arg(format!("{}/launcher.s", cc_env.scripts))
.arg(options.files.join(" "))
.output() {
Ok(proc)=> proc.status.success(),
Err(_)=> false
.arg(options.files.join(" "));

match command.output() {
Ok(proc)=> {
let stat = proc.status.success();
let mut stderr: String = String::new();

if !stat {
command.stderr(Stdio::piped())
.spawn()
.unwrap()
.stderr
.unwrap()
.read_to_string(&mut stderr)
.unwrap();
}

(stat, stderr)
},
Err(_)=> (false, "".to_string())
}
}

Expand Down

0 comments on commit 243b380

Please sign in to comment.