blob: 65b998a6910673279075dd2b1e6f6c8e6a23a0d8 [file] [log] [blame]
Ben Claytonbe2362b2022-01-18 18:58:16 +00001#!/usr/bin/env bash
2# Copyright 2022 The Tint Authors
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16set -e # Fail on any error.
17
Ben Clayton9f49ac52022-04-07 18:26:45 +000018SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )"
19TOOL="$1"
20BINARY="${SCRIPT_DIR}/bin/${TOOL}"
21
Ben Claytonbe2362b2022-01-18 18:58:16 +000022if [ ! -x "$(which go)" ] ; then
Ben Clayton9f49ac52022-04-07 18:26:45 +000023 echo "error: go needs to be on \$PATH to use $0"
24 exit 1
Ben Claytonbe2362b2022-01-18 18:58:16 +000025fi
26
Ben Clayton9f49ac52022-04-07 18:26:45 +000027function list_tools() {
28 echo "Available tools:"
29 ls "${SCRIPT_DIR}/src/cmd"
30}
31
32function show_usage() {
33 echo "run <tool> <args>"
34 echo
35 echo "builds and runs the go tool in <dawn>/tools/src/cmd"
36 echo
37 list_tools
38 exit 1
39}
40
41if [ -z "${TOOL}" ]; then
42 show_usage
43fi
44
45if [ ! -d "${SCRIPT_DIR}/src/cmd/${TOOL}" ]; then
46 show_usage
47fi
Ben Claytonbe2362b2022-01-18 18:58:16 +000048
49# Rebuild the binary.
50# Note, go caches build artifacts, so this is quick for repeat calls
Ben Clayton9f49ac52022-04-07 18:26:45 +000051pushd "${SCRIPT_DIR}/src" > /dev/null
52 go build -o "${BINARY}" "./cmd/${TOOL}"
Ben Claytonbe2362b2022-01-18 18:58:16 +000053popd > /dev/null
54
Ben Clayton9f49ac52022-04-07 18:26:45 +000055"${BINARY}" "${@:2}"