Skip to content

Commit 971befd

Browse files
authored
Improve run-kani script to use default target (#172)
Use default target folder instead of using a temporary folder. Users are still able to customize the folder using Kani argument. Avoid needless updates when Kani dependencies are already up-to-date. Fixes #170
1 parent 8f5512d commit 971befd

File tree

1 file changed

+36
-27
lines changed

1 file changed

+36
-27
lines changed

scripts/run-kani.sh

+36-27
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,26 @@ read_commit_from_toml() {
9292
echo "$commit"
9393
}
9494

95-
clone_kani_repo() {
95+
setup_kani_repo() {
9696
local repo_url="$1"
9797
local directory="$2"
9898
local branch="$3"
9999
local commit="$4"
100-
git clone "$repo_url" "$directory"
101-
pushd "$directory"
102-
git checkout "$commit"
103-
popd
100+
101+
if [[ ! -d "${directory}" ]]; then
102+
mkdir -p "${directory}"
103+
pushd "${directory}" > /dev/null
104+
105+
git init . >& /dev/null
106+
git remote add origin "${repo_url}" >& /dev/null
107+
else
108+
pushd "${directory}" > /dev/null
109+
fi
110+
111+
git fetch --depth 1 origin "$commit" --quiet
112+
git checkout "$commit" --quiet
113+
git submodule update --init --recursive --depth 1 --quiet
114+
popd > /dev/null
104115
}
105116

106117
get_current_commit() {
@@ -115,17 +126,22 @@ get_current_commit() {
115126
build_kani() {
116127
local directory="$1"
117128
pushd "$directory"
118-
os_name=$(uname -s)
119-
120-
if [[ "$os_name" == "Linux" ]]; then
121-
./scripts/setup/ubuntu/install_deps.sh
122-
elif [[ "$os_name" == "Darwin" ]]; then
123-
./scripts/setup/macos/install_deps.sh
129+
source "kani-dependencies"
130+
# Check if installed versions are correct.
131+
if ./scripts/check-cbmc-version.py --major ${CBMC_MAJOR} --minor ${CBMC_MINOR} && ./scripts/check_kissat_version.sh; then
132+
echo "Dependencies are up-to-date"
124133
else
125-
echo "Unknown operating system"
134+
os_name=$(uname -s)
135+
136+
if [[ "$os_name" == "Linux" ]]; then
137+
./scripts/setup/ubuntu/install_deps.sh
138+
elif [[ "$os_name" == "Darwin" ]]; then
139+
./scripts/setup/macos/install_deps.sh
140+
else
141+
echo "Unknown operating system"
142+
fi
126143
fi
127144

128-
git submodule update --init --recursive
129145
cargo build-dev --release
130146
popd
131147
}
@@ -147,19 +163,22 @@ check_binary_exists() {
147163
local expected_commit="$2"
148164
local kani_path=$(get_kani_path "$build_dir")
149165

150-
if [[ -f "$kani_path" ]]; then
166+
if [[ -d "${build_dir}" ]]; then
151167
local current_commit=$(get_current_commit "$build_dir")
152168
if [[ "$current_commit" = "$expected_commit" ]]; then
153169
return 0
170+
else
171+
echo "Kani repository is out of date. Rebuilding..."
154172
fi
173+
else
174+
echo "Kani repository not found. Creating..."
155175
fi
156176
return 1
157177
}
158178

159179

160180
main() {
161181
local build_dir="$WORK_DIR/kani_build"
162-
local temp_dir_target=$(mktemp -d)
163182

164183
echo "Using TOML file: $TOML_FILE"
165184
echo "Using repository URL: $REPO_URL"
@@ -173,12 +192,8 @@ main() {
173192
else
174193
echo "Building Kani from commit: $commit"
175194

176-
# Remove old build directory if it exists
177-
rm -rf "$build_dir"
178-
mkdir -p "$build_dir"
179-
180195
# Clone repository and checkout specific commit
181-
clone_kani_repo "$REPO_URL" "$build_dir" "$BRANCH_NAME" "$commit"
196+
setup_kani_repo "$REPO_URL" "$build_dir" "$BRANCH_NAME" "$commit"
182197

183198
# Build project
184199
build_kani "$build_dir"
@@ -195,7 +210,7 @@ main() {
195210

196211
if [[ "$run_command" == "verify-std" ]]; then
197212
echo "Running Kani verify-std command..."
198-
"$kani_path" verify-std -Z unstable-options ./library --target-dir "$temp_dir_target" \
213+
"$kani_path" verify-std -Z unstable-options ./library \
199214
-Z function-contracts \
200215
-Z mem-predicates \
201216
-Z loop-contracts \
@@ -211,9 +226,3 @@ main() {
211226

212227
main
213228

214-
cleanup()
215-
{
216-
rm -rf "$temp_dir_target"
217-
}
218-
219-
trap cleanup EXIT

0 commit comments

Comments
 (0)