Skip to content

Commit

Permalink
improved logging for formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
riesentoaster committed Nov 10, 2024
1 parent 19f9144 commit ba8a7d5
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions utils/libafl_fmt/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,19 +244,22 @@ async fn main() -> io::Result<()> {
.map(DirEntry::into_path)
.collect();

let mut tokio_joinset = JoinSet::new();

for project in rust_projects_to_fmt {
tokio_joinset.spawn(run_cargo_fmt(project, cli.check, cli.verbose));
}
println!(
"Using {}",
get_version_string("cargo", &["+nightly"]).await?
); // cargo version
println!(
"Using {}",
get_version_string("cargo", &["+nightly", "fmt"]).await?
); // rustfmt version

let reference_clang_format = format!("clang-format-{REF_LLVM_VERSION}");
let unspecified_clang_format = "clang-format";

let (clang, warning) = if which(&reference_clang_format).is_ok() {
println!(
"Using the reference clang-format with version: {}",
get_version_string(&reference_clang_format).await?
get_version_string(&reference_clang_format, &[]).await?
);

(Some(reference_clang_format.as_str()), None)
Expand All @@ -265,7 +268,7 @@ async fn main() -> io::Result<()> {
Some(unspecified_clang_format),
Some(format!(
"using {}, could provide a different result from {}",
get_version_string(unspecified_clang_format).await?,
get_version_string(unspecified_clang_format, &[]).await?,
reference_clang_format
)),
)
Expand All @@ -276,6 +279,12 @@ async fn main() -> io::Result<()> {
)
};

let mut tokio_joinset = JoinSet::new();

for project in rust_projects_to_fmt {
tokio_joinset.spawn(run_cargo_fmt(project, cli.check, cli.verbose));
}

if let Some(clang) = clang {
let c_files_to_fmt: Vec<PathBuf> = WalkDir::new(&libafl_root_dir)
.into_iter()
Expand Down Expand Up @@ -319,7 +328,12 @@ async fn main() -> io::Result<()> {
Ok(())
}

async fn get_version_string(path: &str) -> Result<String, io::Error> {
let version = Command::new(path).arg("--version").output().await?.stdout;
async fn get_version_string(path: &str, args: &[&str]) -> Result<String, io::Error> {
let version = Command::new(path)
.args(args)
.arg("--version")
.output()
.await?
.stdout;
Ok(from_utf8(&version).unwrap().replace('\n', ""))
}

0 comments on commit ba8a7d5

Please sign in to comment.