Skip to content

Add --output <DIR> to list and write list --format files to the target directory - #5227

Open
hiepnnguyentcu wants to merge 4 commits into
model-checking:mainfrom
hiepnnguyentcu:feat/list-output-path
Open

hiepnnguyentcu wants to merge 4 commits into
model-checking:mainfrom
hiepnnguyentcu:feat/list-output-path

Conversation

@hiepnnguyentcu

@hiepnnguyentcu hiepnnguyentcu commented Nov 24, 2026 •

Copy link
Copy Markdown

breaking: default output moves to target/kani/

cargo kani list --format json (or markdown) writes kani-list.json into the shell's current directory (#5124).

This change adds --output <DIR> to cargo kani list, kani list and autoharness --list, for --format json and --format markdown:

  • Kani writes kani-list.json or kani-list.md into DIR and creates it if needed.
  • It rejects a DIR that exists but is not a directory before the build starts.
  • It is also rejected with --format pretty since the command does not produce output file.

Without --output, cargo kani list and cargo kani autoharness --list now write to <target-dir>/kani/:

  • Scripts that read ./kani-list.json after cargo kani list need target/kani/kani-list.json or --output ..
  • kani list and kani list --std have no cargo target directory and keep the current directory, so verify-rust-std's run-kani.sh is not affected.

Testing

  • New script test cargo_list_output runs cargo kani list from src/, with --target-dir, and with --output for both formats. It fails on any kani-list.* in the package root or src/.
  • cargo_list_json and cargo_list_md now read from target/kani/. The kani_list_* tests pass unchanged.
  • Unit tests cover the --output checks and the standalone default.
  • I ran cargo kani autoharness --list and kani autoharness --list by hand, with and without --output, plus the error cases and plain cargo kani and kani verification.

AI coding tools helped write this change and this description.

Resolves #5124

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

With --no-codegen, Cargo list commands lose Cargo metadata and write kani-list.* to the current directory instead of honoring --target-dir.

1 open issue
What changed in this PR

This PR addresses #5124 by moving Cargo list files out of the source tree and adding explicit output-directory control for list and autoharness --list.

Changes:

  • Add --output <DIR> with validation and directory creation for JSON and Markdown output.
  • Default Cargo list files to <target-dir>/kani/, while preserving the current-directory default for standalone commands.
  • Update documentation and regression tests for the output locations.
File Description
tests/​script-based-pre/​cargo_list_output/​src/​lib.rs Add a minimal proof harness fixture.
tests/​script-based-pre/​cargo_list_output/​list.sh Test default, custom-target, and explicit output directories.
tests/​script-based-pre/​cargo_list_output/​list.expected Define expected output paths and harness entries.
tests/​script-based-pre/​cargo_list_output/​config.yml Register the new script test.
tests/​script-based-pre/​cargo_list_output/​Cargo.toml Define the test package.
tests/​script-based-pre/​cargo_list_md/​list.sh Read Markdown results from target/kani/.
tests/​script-based-pre/​cargo_list_md/​.gitignore Remove the obsolete source-root output exclusion.
tests/​script-based-pre/​cargo_list_json/​list.sh Read JSON results from target/kani/.
kani-driver/​src/​list/​output.rs Resolve default directories and create output files there.
kani-driver/​src/​list/​collect_metadata.rs Pass selected directories to list output generation.
kani-driver/​src/​autoharness/​mod.rs Apply output-directory selection to autoharness listings.
kani-driver/​src/​args/​list_args.rs Add and validate --output, with unit tests.
kani-driver/​src/​args/​autoharness_args.rs Add --output requiring --list, with validation tests.
docs/​src/​reference/​list.md Document the option and default output locations.
docs/​src/​reference/​experimental/​autoharness.md Document autoharness list output locations and overrides.

Review effort: Balanced

Comment thread kani-driver/src/list/output.rs Resolved

@feliperodri feliperodri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this fixes #5124 cleanly. I checked it locally: the kani-driver unit tests and the list and autoharness script tests pass, and clippy and fmt are clean. In a cargo workspace, cargo kani list from a member crate writes to the workspace's target/kani/, CARGO_TARGET_DIR is respected, and a relative --output is resolved against the current directory. kani list --std, which verify-rust-std's run-kani.sh uses, still writes to the current directory, so it isn't affected. The --no-codegen fix for Copilot's comment is right, and the only other user of project.cargo_metadata is coverage, which isn't affected. Approving.

Non-blocking:

  • The default location of kani-list.* moves for cargo kani list and cargo kani autoharness --list, which breaks scripts that read ./kani-list.json. Since the release notes are generated from PR titles, consider mentioning it in the title, e.g. "... (breaking: default output moves to target/kani/)".
  • The pretty/not-a-directory validation is repeated in CargoListArgs, StandaloneListArgs and CommonAutoharnessArgs. A shared validate_list_output(format, output) would keep the three in sync.
  • #5180 adds --target-dir after list and touches the same files. The two compose, since #5180 feeds session.args.target_dir, but whichever lands second needs a small rebase.

@feliperodri feliperodri added the [C] Bug This is a bug. Something isn't working. label Nov 25, 2026
@hiepnnguyentcu

hiepnnguyentcu commented Nov 25, 2026 •

Copy link
Copy Markdown
Author

Thanks @feliperodri for approving!

Since I don't have write access, any chance you could merge this when you get a chance?

Happy Thanksgiving!

@feliperodri

Copy link
Copy Markdown
Member

@hiepnnguyentcu before we merge it...

The default location of kani-list.* moves for cargo kani list and cargo kani autoharness --list, which breaks scripts that read ./kani-list.json. Since the release notes are generated from PR titles, consider mentioning it in the title, e.g. "... (breaking: default output moves to target/kani/)".

Is this gonna break any scripts we use for verify-rust-std?

The pretty/not-a-directory validation is repeated in CargoListArgs, StandaloneListArgs and CommonAutoharnessArgs. A shared validate_list_output(format, output) would keep the three in sync.

Can you send a commit to tidy up this part?

@hiepnnguyentcu

hiepnnguyentcu commented Nov 26, 2026 •

Copy link
Copy Markdown
Author

Hi @feliperodri,

This PR won't break verify-rust-std. Its scripts only run kani list --std and kani autoharness --list --std, and I kept the --std default in the current directory on purpose. I am planning to create two follow-ups for --std (more below).

It does, however, break scripts outside verify-rust-std that run cargo kani list and then read ./kani-list.json. If you know other repos under our direct maintenance that rely on the old location, please let me know.

I validated verify-rust-std against this branch (c27f6c5):

  • I pointed scripts/run-kani.sh at this branch through KANI_TOML_FILE and KANI_REPO_URL, so it builds Kani the same way CI does.
  • scripts/run-kani.sh --run list wrote kani-list.md to the repo root, where the run-kani-list job in kani.yml reads it. Nothing landed under target/.
  • I also ran every Kani flag set from run-kani.sh and kani.yml on a small test file. Both list formats went to the current directory, and the autoharness, --only-codegen and verification runs passed. The --std and verify-std forms parse cleanly, so the new --output flag doesn't clash with --output-format=terse.

About the follow-ups, I am planning to raise two more PRs for the below:

  1. Kani: move the --std default to its target directory.
  2. verify-rust-std: bump kani-version.toml and read target/kani-list.* in run-kani.sh and kani.yml, in one PR.

If we prefer to move --std in this PR as well, please let me know. I will add a commit and raise a PR for verify-rust-std, though I prefer to have them separately 🙂.

written by me, polished via Claude Opus 5.5

@hiepnnguyentcu

Copy link
Copy Markdown
Author

Hi @feliperodri, I hope you had a nice Thanksgiving, and no rush at all on this.

I wanted to check whether the plan in my last comment works for you. This PR keeps the --std default as it is, and I would follow up with one Kani PR that moves the --std default to its target directory and one verify-rust-std PR that bumps kani-version.toml and reads the new path. If you'd rather handle --std differently, I'm happy to follow your lead.

I also pushed a720dcd for the shared validate_list_output and marked the title as breaking, following your suggestions.

Thank you again for your time!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[C] Bug This is a bug. Something isn't working.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cargo kani list --format json writes kani-list.json into the package root

3 participants