From 55e3fdf56a5d41eb5d0c2654b577e5f459e972fa Mon Sep 17 00:00:00 2001 From: Per Lindgren <per.lindgren@ltu.se> Date: Mon, 3 Oct 2022 21:02:25 +0200 Subject: [PATCH] move to clap 4, wip4, replay almost working --- cargo-klee/src/cargo_out.rs | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 cargo-klee/src/cargo_out.rs diff --git a/cargo-klee/src/cargo_out.rs b/cargo-klee/src/cargo_out.rs new file mode 100644 index 0000000..6c0011c --- /dev/null +++ b/cargo-klee/src/cargo_out.rs @@ -0,0 +1,38 @@ +// Commodity functions to parse the output of `cargo`. +// Notice, this is fragile and depends on the output format of `cargo` which has no stability guarantees. +use regex::Regex; + +pub fn get_hash(s: &str) -> Option<String> { + let re = Regex::new(r"(-C metadata=)([\da-f]*)").unwrap(); + let cap = re.captures(s)?; + Some(cap[2].to_string()) +} + +pub fn get_out_dir(s: &str) -> Option<String> { + let re = Regex::new(r"(--out-dir)( )([[:alpha:]\d/-]*)").unwrap(); + let cap = re.captures(s)?; + Some(cap[3].to_string()) +} + +#[test] +fn test_hash() { + let s = "-C linker=true -C lto --emit=llvm-ir -C metadata=71aaac8ea4e4b0e4 extra-filename=-71aaac8ea4e4b0e4 -C metadata=71e4"; + + let hash = get_hash(s); + + println!("hash {:?}", hash); + assert_eq!(hash.unwrap(), "71aaac8ea4e4b0e4"); +} + +#[test] +fn test_out_dir_bin() { + let s = "-C extra-filename=-6539d757805e64cf --out-dir /home/pln/courses/d7020e/cargo-klee/klee-examples/target/debug/examples -L dependency=/home/pln/courses/d7020e/cargo-klee/klee-examples/target/debug/deps"; + + let dir = get_out_dir(s); + println!("dir {:?}", dir); + + assert_eq!( + dir.unwrap(), + "/home/pln/courses/d7020e/cargo-klee/klee-examples/target/debug/examples" + ); +} -- GitLab