From 21fe254aa9e172043029a8a005ef949cccd9ffb7 Mon Sep 17 00:00:00 2001 From: Per Lindgren <per.lindgren@ltu.se> Date: Sun, 2 Oct 2022 18:35:11 +0200 Subject: [PATCH] move to clap 4, wip3 --- cargo-klee/Cargo.toml | 3 +++ cargo-klee/src/lib.rs | 1 + cargo-klee/src/main.rs | 49 ++++++++++++++++++++++++++++++------------ 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/cargo-klee/Cargo.toml b/cargo-klee/Cargo.toml index 8614ece..05bfe76 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 4f77372..47b4f01 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 416a1b3..5addb95 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(()) -- GitLab