diff --git a/cargo-klee/src/cargo_out.rs b/cargo-klee/src/cargo_out.rs new file mode 100644 index 0000000000000000000000000000000000000000..6c0011c961231c794989c7b40b0e8af03a8f6159 --- /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" + ); +}