1#!/bin/bash 2# Copyright 2023 The ChromiumOS Authors 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5# Wrapper script that build opentitan tool with bazel then passes the 6# command line parameters to it 7# Use FORCE_REBUILD=<anything> to rebuild opentitantool even if binary exists 8 9set -euo pipefail 10 11FORCE_REBUILD="${FORCE_REBUILD:+1}" 12 13main() { 14 local script_path 15 local opentitan_root 16 local bin 17 18 script_path="$(cd "$(dirname \ 19 "$(test -L "$0" && readlink "$0" || echo "$0")")" >/dev/null 2>&1 ; \ 20 pwd -P)" 21 opentitan_root="${script_path}/../../../third_party/lowrisc/opentitan" 22 bin="${opentitan_root}/bazel-bin/sw/host/opentitantool/opentitantool" 23 24 # If we force rebuild or the binary isn't present, build it now 25 if [[ -n "${FORCE_REBUILD}" || ! -f "${bin}" ]]; then 26 # Execute in sub shell so we don't change working directories 27 ( "${opentitan_root}/bazelisk.sh" build //sw/host/opentitantool \ 28 >/dev/null 2>&1 ) 29 fi 30 31 # Call opentitantool from original working directory 32 "${bin}" "$@" 33} 34 35main "$@" 36