Skip to content

Commit 5045375

Browse files
committed
[ot] scripts/opentitan: run-bazel-tests.sh: Don't clean local overrides
Currently, the `run-bazel-tests.sh` script assumes it is being run from CI and thus cleans up the local Bazel override files it makes. It is useful to run it as a developer before making a PR however, but the current logic would both (a) error upon creating these Bazel override files if you already had them, and (b) delete them afterwards, breaking existing OpenTitan integration flows. Add conditional checks to this logic based on whether these files previously existed to avoid this behaviour. Signed-off-by: Alex Jones <[email protected]>
1 parent dafb264 commit 5045375

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

scripts/opentitan/run-bazel-tests.sh

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,39 @@ if [ ! -x "${qemu_path}/build/qemu-system-riscv32" ]; then
4545
exit 1
4646
fi
4747

48+
# Check if needed Bazel repository override files exist
49+
prev_bazel_files=false
50+
if [ -f "${qemu_path}/REPO.bazel" ]; then
51+
prev_bazel_files=true
52+
else
53+
# Add temporary Bazel `REPO.bazel` file
54+
touch "${qemu_path}/REPO.bazel"
55+
fi
56+
57+
if [ -f "${qemu_path}/BUILD" ]; then
58+
prev_bazel_files=true
59+
else
60+
# Add temporary Bazel 'BUILD' file
61+
ln -s \
62+
"${opentitan_path}/third_party/qemu/BUILD.qemu_opentitan.bazel" \
63+
"${qemu_path}/BUILD"
64+
fi
65+
66+
4867
# Temporary files used by this script:
4968
results="$(mktemp)"
5069
flaky="$(mktemp)"
5170
expected="$(mktemp)"
5271
all_passed="$(mktemp)"
5372
passed="$(mktemp)"
5473
cleanup() {
55-
rm -f "${qemu_path}/REPO.bazel" "${qemu_path}/BUILD"
74+
if [ "$prev_bazel_files" != "true" ]; then
75+
rm -f "${qemu_path}/REPO.bazel" "${qemu_path}/BUILD"
76+
fi
5677
rm -f "$results" "$flaky" "$expected" "$all_passed" "$passed"
5778
}
5879
trap "cleanup" EXIT
5980

60-
## Add temporary `REPO.bazel` and `BUILD` files from Bazel:
61-
touch "${qemu_path}/REPO.bazel"
62-
ln -s \
63-
"${opentitan_path}/third_party/qemu/BUILD.qemu_opentitan.bazel" \
64-
"${qemu_path}/BUILD"
65-
6681
## RUN BAZEL TESTS
6782
cd "$opentitan_path" >/dev/null
6883

0 commit comments

Comments
 (0)