blob: 814568bcffd38e4a93179d16ee188a2fd58bb324 [file] [log] [blame]
#!/bin/bash
# Copyright 2023 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -eu
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
WORKSPACE_ROOT=""
SHAC_DIR=""
VERBOSE=0
source "$SCRIPT_DIR/common.sh" || exit $?
help() {
echo
echo "Script used to bootstrap the shac config files"
echo
echo "Usage:"
echo " $(basename "$0") [<options>]"
echo
echo "Options:"
echo
echo " -h"
echo " Prints this help message"
echo " -v"
echo " Uses verbose output"
echo
}
function log {
if [[ "$VERBOSE" -eq 1 ]]; then
echo "$@"
fi
}
function main() {
while getopts ":hv" opt; do
case ${opt} in
'h' | '?')
help
exit 1
;;
'v')
VERBOSE=1
;;
esac
done
WORKSPACE_ROOT=$(get_workspace_root)
log "Found WORKSPACE file at ${WORKSPACE_ROOT}"
cd "${WORKSPACE_ROOT}/tools"
# TODO(b/301136767): Don't assume these shared shac checks are always located here.
SHAC_DIR="../third_party/fuchsia-infra-bazel-rules/shac"
# If this repo is checked-out by itself, the above directory won't exist.
# Exit cleanly to prevent issues in CQ.
if [[ ! -d "${SHAC_DIR}" ]]; then
return
fi
ln -f -s "${SHAC_DIR}/scripts/shac" shac
if [[ ! -L shac ]] || [[ ! -e shac ]] ; then
echo >&2 "ERROR: failed to setup shac tool. Ensure ${SHAC_DIR} exists, then rerun this script."
return 1
fi
if [[ ! -f ../shac.star ]]; then
log "Creating shac.star file"
cp "${SHAC_DIR}/bootstrap/shac.star" ..
fi
if [[ ! -f ../shac.textproto ]]; then
log "Creating shac.textproto file"
cp "${SHAC_DIR}/bootstrap/shac.textproto" ..
fi
log "Success: created shac tool: ${WORKSPACE_ROOT}/tools/shac"
}
main "$@"