Make some of our scripts work outside the chroot
When we detect that we're being run outside the chroot, use the run-tool
script to rerun ourselves inside the chroot.
BUG=b:239366015
TEST=./scripts/format
TEST=./scripts/run-tests
TEST=./scripts/build-fpga-rom
TEST=./scripts/build-fpga-bistream
Change-Id: Id7bfaf41f90ea8f02ce1ccfc28c15d768316938d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/hps-firmware/+/3769105
Reviewed-by: Dan Callaghan <dcallagh@chromium.org>
Tested-by: David Lattimore <dml@chromium.org>
Commit-Queue: David Lattimore <dml@chromium.org>
diff --git a/scripts/build-fpga-bitstream b/scripts/build-fpga-bitstream
index 6525355..7f5f61f 100755
--- a/scripts/build-fpga-bitstream
+++ b/scripts/build-fpga-bitstream
@@ -6,13 +6,13 @@
set -o errexit
-if [ ! -e /etc/cros_chroot_version ] ; then
- echo "HPS helper scripts must be run inside the ChromeOS chroot." >&2
- exit 1
-fi
-
PROJECT_ROOT=$(realpath "$(dirname "${BASH_SOURCE[0]}")"/..)
+# If we're outside the chroot, rerun inside.
+if [ ! -e /etc/cros_chroot_version ] ; then
+ exec "${PROJECT_ROOT}/scripts/run-tool" "$0" "$@"
+fi
+
cd "${PROJECT_ROOT}"
scripts/pyrun -m soc.hps_soc "$@"