Ben Clayton | be2362b | 2022-01-18 18:58:16 +0000 | [diff] [blame] | 1 | #!/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 | |
| 16 | set -e # Fail on any error. |
| 17 | |
Ben Clayton | 9f49ac5 | 2022-04-07 18:26:45 +0000 | [diff] [blame] | 18 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )" |
| 19 | TOOL="$1" |
Ben Clayton | 9f49ac5 | 2022-04-07 18:26:45 +0000 | [diff] [blame] | 20 | |
Ben Clayton | be2362b | 2022-01-18 18:58:16 +0000 | [diff] [blame] | 21 | if [ ! -x "$(which go)" ] ; then |
Ben Clayton | 9f49ac5 | 2022-04-07 18:26:45 +0000 | [diff] [blame] | 22 | echo "error: go needs to be on \$PATH to use $0" |
| 23 | exit 1 |
Ben Clayton | be2362b | 2022-01-18 18:58:16 +0000 | [diff] [blame] | 24 | fi |
| 25 | |
Ben Clayton | 9f49ac5 | 2022-04-07 18:26:45 +0000 | [diff] [blame] | 26 | function list_tools() { |
| 27 | echo "Available tools:" |
| 28 | ls "${SCRIPT_DIR}/src/cmd" |
| 29 | } |
| 30 | |
| 31 | function 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 | |
| 40 | if [ -z "${TOOL}" ]; then |
| 41 | show_usage |
| 42 | fi |
| 43 | |
| 44 | if [ ! -d "${SCRIPT_DIR}/src/cmd/${TOOL}" ]; then |
| 45 | show_usage |
| 46 | fi |
Ben Clayton | be2362b | 2022-01-18 18:58:16 +0000 | [diff] [blame] | 47 | |
Ben Clayton | 97b8348 | 2023-02-05 10:52:57 +0000 | [diff] [blame] | 48 | pushd "${SCRIPT_DIR}/.." > /dev/null |
| 49 | go run "${SCRIPT_DIR}/src/cmd/${TOOL}" "${@:2}" |
Ben Clayton | be2362b | 2022-01-18 18:58:16 +0000 | [diff] [blame] | 50 | popd > /dev/null |