From 8919024e836c20663ec7c0c31c4da2ffc0aa8bc8 Mon Sep 17 00:00:00 2001 From: "Dongjia \"toka\" Zhang" Date: Mon, 15 Jul 2024 19:17:21 +0200 Subject: [PATCH] New clippy script (#2400) * claude.ai * aaa * ps1 * set -e * nightly * nightly default * components? --- .../windows-tester-prepare/action.yml | 4 +- Cargo.toml | 2 + scripts/clippy.ps1 | 97 ++++++++++++++++--- scripts/clippy.sh | 80 +++++++++++---- 4 files changed, 150 insertions(+), 33 deletions(-) diff --git a/.github/workflows/windows-tester-prepare/action.yml b/.github/workflows/windows-tester-prepare/action.yml index 79e2f3c02c..87031d85fc 100644 --- a/.github/workflows/windows-tester-prepare/action.yml +++ b/.github/workflows/windows-tester-prepare/action.yml @@ -6,7 +6,9 @@ runs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: stable + toolchain: nightly + components: llvm-tools, clippy, rustfmt + default: true - uses: actions/checkout@v3 - uses: Swatinem/rust-cache@v2 - name: Build docs diff --git a/Cargo.toml b/Cargo.toml index 09b043a88b..5919d55ce1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ default-members = [ "libafl_derive", "libafl_targets", ] + exclude = [ "bindings", "fuzzers", @@ -32,6 +33,7 @@ exclude = [ "utils/desyscall", "utils/multi_machine_generator", "scripts", + # additional crates "libafl_concolic/symcc_runtime", "libafl_concolic/symcc_libafl", "libafl_frida", diff --git a/scripts/clippy.ps1 b/scripts/clippy.ps1 index 6d4ba7e6cc..ca10b5cb9c 100644 --- a/scripts/clippy.ps1 +++ b/scripts/clippy.ps1 @@ -1,14 +1,83 @@ -cargo clippy --all --all-features --exclude libafl_qemu --no-deps --tests --benches --examples -- ` - -D clippy::all ` - -D clippy::pedantic ` - -W clippy::similar_names ` - -A clippy::type_repetition_in_bounds ` - -A clippy::missing-errors-doc ` - -A clippy::cast-possible-truncation ` - -A clippy::used-underscore-binding ` - -A clippy::ptr-as-ptr ` - -A clippy::missing-panics-doc ` - -A clippy::missing-docs-in-private-items ` - -A clippy::unseparated-literal-suffix ` - -A clippy::module-name-repetitions ` - -A clippy::unreadable-literal +# Clippy Runner Script for PowerShell (Windows) + +$ErrorActionPreference = "Stop" # This is similar to set -e in Bash +$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path +Set-Location (Split-Path -Parent $ScriptDir) + +# Function to run Clippy on a single directory +function Run-Clippy { + param ( + [string]$dir + ) + Write-Host "Running Clippy on $dir" + Push-Location $dir + + try { + $env:RUST_BACKTRACE = "full" + cargo +nightly clippy --all --all-features --no-deps --tests --examples --benches -- -Z macro-backtrace ` + -D clippy::all ` + -D clippy::pedantic ` + -W clippy::similar_names ` + -A clippy::type_repetition_in_bounds ` + -A clippy::missing-errors-doc ` + -A clippy::cast-possible-truncation ` + -A clippy::used-underscore-binding ` + -A clippy::ptr-as-ptr ` + -A clippy::missing-panics-doc ` + -A clippy::missing-docs-in-private-items ` + -A clippy::unseparated-literal-suffix ` + -A clippy::module-name-repetitions ` + -A clippy::unreadable-literal + } + finally { + Pop-Location + } +} + +# Define projects for Windows +$AllProjects = @( + "libafl_frida", + "libafl_libfuzzer", + "libafl_nyx", + "libafl_tinyinst" +) + +# Check if arguments were provided +if ($args.Count -eq 0) { + # No arguments provided, run on all projects + $Projects = $AllProjects +} +else { + # Arguments provided, split the input string into an array + $Projects = $args[0] -split ',' +} + +# First run it on all +$env:RUST_BACKTRACE = "full" +cargo +nightly clippy --all --all-features --no-deps --tests --examples --benches -- -Z macro-backtrace ` + -D clippy::all ` + -D clippy::pedantic ` + -W clippy::similar_names ` + -A clippy::type_repetition_in_bounds ` + -A clippy::missing-errors-doc ` + -A clippy::cast-possible-truncation ` + -A clippy::used-underscore-binding ` + -A clippy::ptr-as-ptr ` + -A clippy::missing-panics-doc ` + -A clippy::missing-docs-in-private-items ` + -A clippy::unseparated-literal-suffix ` + -A clippy::module-name-repetitions ` + -A clippy::unreadable-literal + +# Loop through each project and run Clippy +foreach ($project in $Projects) { + $project = $project.Trim() + if (Test-Path $project -PathType Container) { + Run-Clippy $project + } + else { + Write-Host "Warning: Directory $project does not exist. Skipping." + } +} + +Write-Host "Clippy run completed for all specified projects." \ No newline at end of file diff --git a/scripts/clippy.sh b/scripts/clippy.sh index 55e64ffc5c..9c0d2b5fce 100755 --- a/scripts/clippy.sh +++ b/scripts/clippy.sh @@ -1,9 +1,57 @@ #!/bin/bash -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" cd "$SCRIPT_DIR/.." || exit 1 set -e +# Function to run Clippy on a single directory +run_clippy() { + local dir="$1" + echo "Running Clippy on $dir" + pushd "$dir" || return 1 + RUST_BACKTRACE=full cargo +nightly clippy --all --all-features --no-deps --tests --examples --benches -- -Z macro-backtrace \ + -D clippy::all \ + -D clippy::pedantic \ + -W clippy::similar_names \ + -A clippy::type_repetition_in_bounds \ + -A clippy::missing-errors-doc \ + -A clippy::cast-possible-truncation \ + -A clippy::used-underscore-binding \ + -A clippy::ptr-as-ptr \ + -A clippy::missing-panics-doc \ + -A clippy::missing-docs-in-private-items \ + -A clippy::unseparated-literal-suffix \ + -A clippy::module-name-repetitions \ + -A clippy::unreadable-literal + + popd || return 1 +} + +# Define projects based on the operating system +if [[ "$OSTYPE" == "linux-gnu"* ]]; then + ALL_PROJECTS=( + "libafl_concolic/symcc_runtime" + "libafl_concolic/symcc_libafl" + "libafl_frida" + "libafl_libfuzzer" + "libafl_nyx" + "libafl_qemu" + "libafl_tinyinst" + "libafl_qemu/libafl_qemu_build" + "libafl_qemu/libafl_qemu_sys" + ) +fi + +if [ "$#" -eq 0 ]; then + # No arguments provided, run on all projects + PROJECTS=("${ALL_PROJECTS[@]}") +else + # Arguments provided, split the input string into an array + IFS=',' read -ra PROJECTS <<<"$1" +fi + +# First run it on all RUST_BACKTRACE=full cargo +nightly clippy --all --all-features --no-deps --tests --examples --benches -- -Z macro-backtrace \ -D clippy::all \ -D clippy::pedantic \ @@ -19,20 +67,16 @@ RUST_BACKTRACE=full cargo +nightly clippy --all --all-features --no-deps --tests -A clippy::module-name-repetitions \ -A clippy::unreadable-literal -if [[ "$OSTYPE" == "linux-gnu"* ]]; then - cd libafl_libfuzzer_runtime - RUST_BACKTRACE=full cargo +nightly clippy --all --all-features --no-deps --tests --examples --benches -- -Z macro-backtrace \ - -D clippy::all \ - -D clippy::pedantic \ - -W clippy::similar_names \ - -A clippy::type_repetition_in_bounds \ - -A clippy::missing-errors-doc \ - -A clippy::cast-possible-truncation \ - -A clippy::used-underscore-binding \ - -A clippy::ptr-as-ptr \ - -A clippy::missing-panics-doc \ - -A clippy::missing-docs-in-private-items \ - -A clippy::unseparated-literal-suffix \ - -A clippy::module-name-repetitions \ - -A clippy::unreadable-literal -fi + +# Loop through each project and run Clippy +for project in "${PROJECTS[@]}"; do + # Trim leading and trailing whitespace + project=$(echo "$project" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') + if [ -d "$project" ]; then + run_clippy "$project" + else + echo "Warning: Directory $project does not exist. Skipping." + fi +done + +echo "Clippy run completed for all specified projects."