Skip to content

Commit 420090e

Browse files
authored
Allow custom path for installation/setup (rust-lang#2089)
1 parent 886c035 commit 420090e

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

.github/workflows/kani.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,15 @@ jobs:
143143
if: ${{ matrix.os == 'ubuntu-18.04' }}
144144
run: |
145145
docker build -t kani-20-04 -f scripts/ci/Dockerfile.bundle-test-ubuntu-20-04 .
146+
docker build -t kani-20-04-alt -f scripts/ci/Dockerfile.bundle-test-ubuntu-20-04-alt .
146147
docker build -t kani-18-04 -f scripts/ci/Dockerfile.bundle-test-ubuntu-18-04 .
147148
# this one does its tests automatically, for reasons documented in the file:
148149
docker build -t kani-nixos -f scripts/ci/Dockerfile.bundle-test-nixos .
149150
150151
- name: Run installed tests
151152
if: ${{ matrix.os == 'ubuntu-18.04' }}
152153
run: |
153-
for tag in kani-20-04 kani-18-04; do
154+
for tag in kani-20-04 kani-20-04-alt kani-18-04; do
154155
docker run $tag cargo kani --version
155156
docker run -w /tmp/kani/tests/cargo-kani/simple-lib $tag cargo kani
156157
docker run -w /tmp/kani/tests/cargo-kani/simple-visualize $tag cargo kani
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright Kani Contributors
2+
# SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
# Note: this file is intended only for testing the kani release bundle
5+
# using an alternative install path *
6+
7+
FROM ubuntu:20.04
8+
ENV DEBIAN_FRONTEND=noninteractive \
9+
DEBCONF_NONINTERACTIVE_SEEN=true \
10+
KANI_HOME="/tmp"
11+
RUN apt-get update && \
12+
apt-get install -y python3 python3-pip curl ctags && \
13+
curl -sSf https://sh.rustup.rs | sh -s -- -y
14+
ENV PATH="/root/.cargo/bin:${PATH}"
15+
16+
WORKDIR /tmp/kani
17+
COPY ./tests ./tests
18+
COPY ./kani-latest-x86_64-unknown-linux-gnu.tar.gz ./
19+
# Very awkward glob (not regex!) to get `kani-verifier-*` and not `kani-verifier-*.crate`
20+
COPY ./target/package/kani-verifier-*[^e] ./kani-verifier
21+
RUN cargo install --path ./kani-verifier
22+
RUN cargo-kani setup --use-local-bundle ./kani-latest-x86_64-unknown-linux-gnu.tar.gz

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fn fail_if_in_dev_environment() -> Result<()> {
8989
/// Executes `kani-driver` in `bin` mode (kani or cargo-kani)
9090
/// augmenting environment variables to accomodate our release environment
9191
fn exec(bin: &str) -> Result<()> {
92-
let kani_dir = setup::kani_dir();
92+
let kani_dir = setup::kani_dir()?;
9393
let program = kani_dir.join("bin").join("kani-driver");
9494
let pyroot = kani_dir.join("pyroot");
9595
let bin_kani = kani_dir.join("bin");

src/setup.rs

+30-5
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,44 @@ const VERSION: &str = env!("CARGO_PKG_VERSION");
1818
/// Set by our `build.rs`, reflects the Rust target triple we're building for
1919
const TARGET: &str = env!("TARGET");
2020

21-
/// Where Kani has been installed. Typically `~/.kani/kani-1.x/`
22-
pub fn kani_dir() -> PathBuf {
23-
home::home_dir().expect("Couldn't find home dir?").join(".kani").join(format!("kani-{VERSION}"))
21+
/// The directory where Kani is installed, either:
22+
/// * (custom) `${KANI_HOME}/kani-<VERSION>` if the environment variable
23+
/// `KANI_HOME` is set.
24+
/// * (default) `${HOME}/.kani/kani-<VERSION>` where `HOME` is the canonical
25+
/// definition of home directory used by Cargo and rustup.
26+
pub fn kani_dir() -> Result<PathBuf> {
27+
let kani_dir = match env::var("KANI_HOME") {
28+
Ok(val) => custom_kani_dir(val),
29+
Err(_) => default_kani_dir()?,
30+
};
31+
let kani_dir = kani_dir.join(format!("kani-{VERSION}"));
32+
Ok(kani_dir)
33+
}
34+
35+
/// Returns the custom Kani home directory: `${KANI_HOME}`
36+
fn custom_kani_dir(path: String) -> PathBuf {
37+
// We don't check if it doesn't exist since we create it later
38+
PathBuf::from(path)
39+
}
40+
41+
/// Returns the default Kani home directory: `${HOME}/.kani`
42+
fn default_kani_dir() -> Result<PathBuf> {
43+
let home_dir = home::home_dir().expect("couldn't find home directory");
44+
if !home_dir.is_dir() {
45+
bail!("got home directory `{}` which isn't a directory", home_dir.display());
46+
}
47+
let kani_dir = home_dir.join(".kani");
48+
Ok(kani_dir)
2449
}
2550

2651
/// Fast check to see if we look setup already
2752
pub fn appears_setup() -> bool {
28-
kani_dir().exists()
53+
kani_dir().expect("couldn't find kani directory").exists()
2954
}
3055

3156
/// Sets up Kani by unpacking/installing to `~/.kani/kani-VERSION`
3257
pub fn setup(use_local_bundle: Option<OsString>) -> Result<()> {
33-
let kani_dir = kani_dir();
58+
let kani_dir = kani_dir()?;
3459
let os = os_info::get();
3560

3661
println!("[0/5] Running Kani first-time setup...");

0 commit comments

Comments
 (0)