From d34b56d05f6f364c4c6ded12931b78d03088a3bc Mon Sep 17 00:00:00 2001 From: fromtaoyuanhsinchuuuu Date: Thu, 3 Dec 2026 04:04:45 +0800 Subject: [PATCH] Collect autoharness metadata from both Cargo layouts --- scripts/run-kani.sh | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/scripts/run-kani.sh b/scripts/run-kani.sh index 55227b2921c11..268ac5e615a3e 100755 --- a/scripts/run-kani.sh +++ b/scripts/run-kani.sh @@ -357,7 +357,7 @@ main() { --kani-list-file $current_dir/kani-list.json \ --metrics-file metrics-data-std.json popd - elif [[ "$run_command" == "autoharness-analyzer" ]]; then + elif [[ "$run_command" == "autoharness-analyzer" ]]; then ( echo "Running Kani autoharness codegen command..." "$kani_path" autoharness -Z autoharness -Z unstable-options --std ./library \ --only-codegen -j --output-format=terse \ @@ -365,31 +365,37 @@ main() { --no-assert-contracts \ "${command_args[@]}" \ --cbmc-args --object-bits 12 - # remove metadata file for Kani-generated "dummy" crate that we won't - # get scanner data for - local target=$(find "target/kani_verify_std/target/" -mindepth 1 -maxdepth 1 \ - -type d -exec test -d '{}'/debug/ \; -print) - local metadata=$target/debug/deps - # Cargo 1.99+ gives each package its own debug/build/PKG/HASH/out/ and no longer creates - # debug/deps, so gather the metadata files in one directory for the analyzer. - if [ ! -d "$metadata" ]; then - metadata=$(mktemp -d) - find "$(pwd)/$target/debug/build" -path '*/out/*.kani-metadata.json' \ - -exec ln -s '{}' "$metadata/" \; + local target="$WORK_DIR/target/kani_verify_std/target" + local metadata + metadata=$(mktemp -d) + trap 'rm -rf -- "$metadata"' EXIT + + # Stage metadata from either Cargo layout. The dummy crate has no scanner data. + shopt -s nullglob + local -a metadata_files=() + local file + for file in "$target"/*/debug/deps/*.kani-metadata.json \ + "$target"/*/debug/build/*/*/out/*.kani-metadata.json; do + [[ ${file##*/} != dummy-* ]] || continue + metadata_files+=("$file") + done + if [[ ${#metadata_files[@]} -eq 0 ]]; then + echo "No Kani metadata found under $target" >&2 + exit 1 fi - rm $metadata/dummy-* + ln -s "${metadata_files[@]}" "$metadata/" echo "Running Kani's std-analysis command..." pushd scripts/kani-std-analysis - ./std-analysis.sh $build_dir + ./std-analysis.sh "$build_dir" popd echo "Running autoharness-analyzer command..." pushd scripts/autoharness_analyzer - [[ $metadata = /* ]] || metadata=../../$metadata cargo run -- --per-crate \ - $metadata/ /tmp/std_lib_analysis/results/ + "$metadata/" /tmp/std_lib_analysis/results/ cargo run -- --per-crate --unsafe-fns-only \ - $metadata/ /tmp/std_lib_analysis/results/ + "$metadata/" /tmp/std_lib_analysis/results/ popd + ) fi }