diff --git a/cargo-klee/Cargo.toml b/cargo-klee/Cargo.toml index 8614ece38ad84a7ee7ead29c0dae619e8a49459d..05bfe76f263cca4a6dfda96e9ec196399245640d 100644 --- a/cargo-klee/Cargo.toml +++ b/cargo-klee/Cargo.toml @@ -15,3 +15,6 @@ either = "1.6.1" clap = { version = "4.0.6", features = ["derive", "color"] } rustc_version = "0.4.0" anyhow = "1.0.65" +# cargo_metadata = "0.15.0" +regex = "1.6.0" +# colored = "2.0.0" diff --git a/cargo-klee/src/lib.rs b/cargo-klee/src/lib.rs index 4f773726a20b821d11320ef75d522be0bc862871..47b4f01bb36ef67d59e2bfaaf99b8da72c099a85 100644 --- a/cargo-klee/src/lib.rs +++ b/cargo-klee/src/lib.rs @@ -1 +1,2 @@ +pub mod cargo_out; pub mod cli; diff --git a/cargo-klee/src/main.rs b/cargo-klee/src/main.rs index 416a1b310a3ddc538d5f9749e614600e92133c2e..5addb95f68b642a33aac00530e3a2a4f6524650d 100644 --- a/cargo-klee/src/main.rs +++ b/cargo-klee/src/main.rs @@ -1,15 +1,16 @@ -use anyhow::Error; +use anyhow::{anyhow, Error}; // use std::error::Error; use cargo_klee::cli::Cli; use clap::Parser; +use std::str::Split; // extern crate libc; use std::{ env, fs, path::PathBuf, - process::{self, Command}, + process::{self, Command, ExitStatus, Stdio}, time::SystemTime, }; @@ -67,12 +68,9 @@ fn main() -> Result<(), Error> { let mut cargo = Command::new("cargo"); cargo // compile using rustc - .arg("rustc"); - - // verbose output for debugging purposes - if args.verbose { - cargo.arg("-v"); - } + .arg("rustc") + // verbose output for debugging purposes + .arg("-v"); // set features, always including `klee-analysis` if args.all_features { @@ -128,13 +126,36 @@ fn main() -> Result<(), Error> { eprintln!("\n{:?}\n", cargo); } - // execute the command and unwrap the result into status - let status = cargo.status()?; + // // execute the command and unwrap the result into status + // let status = cargo.status()?; + + // if !status.success() { + // // TODO! correctly handle exit status + // panic!("{:?}", status); + // // return Err(status.code().unwrap_or(1).into()); + // } + + println!("project name {:?}", project.name()); + println!("project target {:?}", project.target()); + println!("project toml {:?}", project.toml()); + println!("project target_dir {:?}", project.target_dir()); + + let output = cargo.stdout(Stdio::piped()).output()?; + let stderr = String::from_utf8(output.stderr)?; + + // We enforce color, assumes standard utf-8 coding for Green + let comp = "\u{1b}[32m Compiling"; + let s: Split<&str> = stderr.split(comp); + let last = s.last().unwrap(); + + if args.verbose { + println!("{}", stderr); + } else { + println!("{}{}", comp, last); + } - if !status.success() { - // TODO! correctly handle exit status - panic!("{:?}", status); - // return Err(status.code().unwrap_or(1).into()); + if !output.status.success() { + return Err(anyhow!("Compilation failed, exiting cargo-klee")); } Ok(())