Skip to content

Commit

Permalink
Fixing version pinning in CI (#2679)
Browse files Browse the repository at this point in the history
  • Loading branch information
riesentoaster authored Nov 11, 2024
1 parent 4269be1 commit ae9ab80
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ jobs:

cargo-fmt:
runs-on: ubuntu-24.04
env:
MAIN_LLVM_VERSION: 19
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/ubuntu-prepare
Expand Down
4 changes: 2 additions & 2 deletions fuzzers/inprocess/libfuzzer_libmozjpeg/hook_allocs.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#ifdef _WIN32
#define posix_memalign(p, a, s) \
(((*(p)) = _aligned_malloc((s), (a))), *(p) ? 0 : errno)
#define RETADDR (uintptr_t) _ReturnAddress()
#define RETADDR (uintptr_t)_ReturnAddress()
#else
#define RETADDR (uintptr_t) __builtin_return_address(0)
#define RETADDR (uintptr_t)__builtin_return_address(0)
#endif

#ifdef __GNUC__
Expand Down
76 changes: 57 additions & 19 deletions utils/libafl_fmt/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,38 +244,63 @@ async fn main() -> io::Result<()> {
.map(DirEntry::into_path)
.collect();

let mut tokio_joinset = JoinSet::new();
// cargo version
println!(
"Using {}",
get_version_string("cargo", &["+nightly"]).await?
);

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

let reference_clang_format = format!("clang-format-{REF_LLVM_VERSION}");
let reference_clang_format = format!(
"clang-format-{}",
std::env::var("MAIN_LLVM_VERSION")
.inspect(|e| {
println!(
"Overriding clang-format version from the default {REF_LLVM_VERSION} to {e} using env variable MAIN_LLVM_VERSION"
);
})
.unwrap_or(REF_LLVM_VERSION.to_string())
);
let unspecified_clang_format = "clang-format";

let (clang, warning) = if which(&reference_clang_format).is_ok() {
(Some(reference_clang_format.as_str()), None)
let (clang, version, warning) = if which(&reference_clang_format).is_ok() {
(
Some(reference_clang_format.as_str()),
Some(get_version_string(&reference_clang_format, &[]).await?),
None,
)
} else if which(unspecified_clang_format).is_ok() {
let version = Command::new(unspecified_clang_format)
.arg("--version")
.output()
.await?
.stdout;

let version = get_version_string(unspecified_clang_format, &[]).await?;
(
Some(unspecified_clang_format),
Some(version.clone()),
Some(format!(
"using {}, could provide a different result from clang-format-17",
from_utf8(&version).unwrap().replace('\n', "")
"using {version}, could provide a different result from {reference_clang_format}"
)),
)
} else {
(
None,
None,
Some("clang-format not found. Skipping C formatting...".to_string()),
)
};
// println!("Using {:#?} to format...", clang);

if let Some(version) = &version {
println!("Using {version}");
}

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 @@ -306,9 +331,7 @@ async fn main() -> io::Result<()> {
}
}

if let Some(warning) = warning {
println!("\n{}: {}\n", "Warning".yellow().bold(), warning);
}
let _ = warning.map(print_warning);

if cli.check {
println!("[*] Check finished successfully.");
Expand All @@ -318,3 +341,18 @@ async fn main() -> io::Result<()> {

Ok(())
}

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', ""))
}

#[allow(clippy::needless_pass_by_value)]
fn print_warning(warning: String) {
println!("\n{} {}\n", "Warning:".yellow().bold(), warning);
}

0 comments on commit ae9ab80

Please sign in to comment.