blob: b70540c2a95210096f0212ae5cc000aedbf1a891 [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"
Ben Clayton9f49ac52022-04-07 18:26:45 +000020
Ben Claytonbe2362b2022-01-18 18:58:16 +000021if [ ! -x "$(which go)" ] ; then
Ben Clayton9f49ac52022-04-07 18:26:45 +000022 echo "error: go needs to be on \$PATH to use $0"
23 exit 1
Ben Claytonbe2362b2022-01-18 18:58:16 +000024fi
25
Ben Clayton9f49ac52022-04-07 18:26:45 +000026function list_tools() {
27 echo "Available tools:"
28 ls "${SCRIPT_DIR}/src/cmd"
29}
30
31function show_usage() {
32 echo "run <tool> <args>"
33 echo
34 echo "builds and runs the go tool in <dawn>/tools/src/cmd"
35 echo
36 list_tools
37 exit 1
38}
39
40if [ -z "${TOOL}" ]; then
41 show_usage
42fi
43
44if [ ! -d "${SCRIPT_DIR}/src/cmd/${TOOL}" ]; then
45 show_usage
46fi
Ben Claytonbe2362b2022-01-18 18:58:16 +000047
Ben Clayton97b83482023-02-05 10:52:57 +000048pushd "${SCRIPT_DIR}/.." > /dev/null
49 go run "${SCRIPT_DIR}/src/cmd/${TOOL}" "${@:2}"
Ben Claytonbe2362b2022-01-18 18:58:16 +000050popd > /dev/null