Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print Kani version #2619

Merged
merged 10 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions kani-driver/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::args::StandaloneSubcommand;
use crate::concrete_playback::playback::{playback_cargo, playback_standalone};
use crate::project::Project;
use crate::session::KaniSession;
use crate::version::print_kani_version;
use clap::Parser;
use tracing::debug;

Expand All @@ -35,12 +36,15 @@ mod metadata;
mod project;
mod session;
mod util;
mod version;

/// The main function for the `kani-driver`.
/// The driver can be invoked via `cargo kani` and `kani` commands, which determines what kind of
/// project should be verified.
fn main() -> ExitCode {
let result = match determine_invocation_type(Vec::from_iter(std::env::args_os())) {
let invocation_type = determine_invocation_type(Vec::from_iter(std::env::args_os()));

let result = match invocation_type {
InvocationType::CargoKani(args) => cargokani_main(args),
InvocationType::Standalone => standalone_main(),
};
Expand All @@ -59,10 +63,15 @@ fn main() -> ExitCode {
/// The main function for the `cargo kani` command.
fn cargokani_main(input_args: Vec<OsString>) -> Result<()> {
let input_args = join_args(input_args)?;
let args = args::CargoKaniArgs::parse_from(input_args);
let args = args::CargoKaniArgs::parse_from(&input_args);
check_is_valid(&args);

let session = session::KaniSession::new(args.verify_opts)?;

if !session.args.common_args.quiet {
print_kani_version(InvocationType::CargoKani(input_args));
}

match args.command {
Some(CargoKaniSubcommand::Assess(args)) => {
return assess::run_assess(session, *args);
Expand Down Expand Up @@ -91,6 +100,11 @@ fn standalone_main() -> Result<()> {
}

let session = session::KaniSession::new(args.verify_opts)?;

if !session.args.common_args.quiet {
print_kani_version(InvocationType::Standalone);
}

let project = project::standalone_project(&args.input.unwrap(), &session)?;
if session.args.only_codegen { Ok(()) } else { verify_project(project, session) }
}
Expand Down
31 changes: 31 additions & 0 deletions kani-driver/src/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

use crate::InvocationType;

const KANI_RUST_VERIFIER: &str = "Kani Rust Verifier";
/// We assume this is the same as the `kani-verifier` version, but we should
/// make sure it's enforced through CI:
/// <https://github.com/model-checking/kani/issues/2626>
const KANI_VERSION: &str = env!("CARGO_PKG_VERSION");

/// Print Kani version. At present, this is only release version information.
adpaco-aws marked this conversation as resolved.
Show resolved Hide resolved
pub(crate) fn print_kani_version(invocation_type: InvocationType) {
let kani_version = kani_version_release(invocation_type);
// TODO: Print development version information.
// <https://github.com/model-checking/kani/issues/2617>
println!("{kani_version}");
}

/// Print Kani release version as `Kani Rust Verifier <version> (<invocation>)`
/// where:
/// - `<version>` is the `kani-verifier` version
/// - `<invocation>` is `cargo plugin` if Kani was invoked with `cargo kani` or
/// `standalone` if it was invoked with `kani`.
fn kani_version_release(invocation_type: InvocationType) -> String {
let invocation_str = match invocation_type {
InvocationType::CargoKani(_) => "cargo plugin",
InvocationType::Standalone => "standalone",
};
format!("{KANI_RUST_VERIFIER} {KANI_VERSION} ({invocation_str})")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
success: version printed agrees
success: `(cargo plugin)` appears in version line
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT

set -eu

KANI_VERSION_CMD=`cargo kani --version`
KANI_VERSION_CMD_VERSION=`echo ${KANI_VERSION_CMD} | awk '{print $2}'`

# Check that the version printed is the same. Note: We use `sed -n '1p'` instead
# of `head -n 1` to avoid https://github.com/model-checking/kani/issues/2618
KANI_CARGO_OUTPUT_HEAD=`cd dummy-project; cargo kani | sed -n '1p'`
KANI_CARGO_OUTPUT_HEAD_VERSION=`echo ${KANI_CARGO_OUTPUT_HEAD} | awk '{print $4}'`

if [[ $KANI_VERSION_CMD_VERSION == $KANI_CARGO_OUTPUT_HEAD_VERSION ]]; then
echo "success: version printed agrees"
else
echo "failed: version printed differs ($KANI_VERSION_CMD_VERSION - $KANI_CARGO_OUTPUT_HEAD_VERSION)"
exit 1
fi

KANI_CARGO_OUTPUT_HEAD_MODE=`echo ${KANI_CARGO_OUTPUT_HEAD} | awk '{print $5,$6}'`

# Check that `(cargo plugin)` appears in the version line
if [[ $KANI_CARGO_OUTPUT_HEAD_MODE == "(cargo plugin)" ]]; then
echo "success: \`(cargo plugin)\` appears in version line"
else
echo "failed: expected \`(cargo plugin)\` in version line"
exit 1
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT
script: cargo-kani-version-flag-version.sh
expected: cargo-kani-version-flag-version.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT

[package]
name = "dummy-project"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! This test is used to check that an invocation of `cargo kani` prints the version
//! and invocation type as expected.

fn main() {
println!("Hello, world!");
}

#[kani::proof]
fn dummy() {
assert!(1 + 1 == 2);
}
4 changes: 4 additions & 0 deletions tests/script-based-pre/kani-version-flag-version/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT
script: kani-version-flag-version.sh
expected: kani-version-flag-version.expected
10 changes: 10 additions & 0 deletions tests/script-based-pre/kani-version-flag-version/dummy-file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! This test is used to check that an invocation of `kani` or `cargo kani`
//! prints the version and invocation type as expected.

#[kani::proof]
fn dummy() {
assert!(1 + 1 == 2);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
success: version printed agrees
success: `(standalone)` appears in version line
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT

set -eu

KANI_VERSION_CMD=`kani --version`
KANI_VERSION_CMD_VERSION=`echo ${KANI_VERSION_CMD} | awk '{print $2}'`

# Check that the version printed is the same. Note: We use `sed -n '1p'` instead
# of `head -n 1` to avoid https://github.com/model-checking/kani/issues/2618
KANI_STANDALONE_OUTPUT_HEAD=`kani dummy-file.rs | sed -n '1p'`
KANI_STANDALONE_OUTPUT_HEAD_VERSION=`echo ${KANI_STANDALONE_OUTPUT_HEAD} | awk '{print $4}'`

if [[ $KANI_VERSION_CMD_VERSION == $KANI_STANDALONE_OUTPUT_HEAD_VERSION ]]; then
echo "success: version printed agrees"
else
echo "failed: version printed differs ($KANI_VERSION_CMD_VERSION - $KANI_STANDALONE_OUTPUT_HEAD_VERSION)"
exit 1
fi

KANI_STANDALONE_OUTPUT_HEAD_MODE=`echo ${KANI_STANDALONE_OUTPUT_HEAD} | awk '{print $5}'`

# Check that `(standalone)` appears in the version line
if [[ $KANI_STANDALONE_OUTPUT_HEAD_MODE == "(standalone)" ]]; then
echo "success: \`(standalone)\` appears in version line"
else
echo "failed: expected \`(standalone)\` in version line"
exit 1
fi
Loading