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" |
| 20 | BINARY="${SCRIPT_DIR}/bin/${TOOL}" |
| 21 | |
Ben Clayton | be2362b | 2022-01-18 18:58:16 +0000 | [diff] [blame] | 22 | if [ ! -x "$(which go)" ] ; then |
Ben Clayton | 9f49ac5 | 2022-04-07 18:26:45 +0000 | [diff] [blame] | 23 | echo "error: go needs to be on \$PATH to use $0" |
| 24 | exit 1 |
Ben Clayton | be2362b | 2022-01-18 18:58:16 +0000 | [diff] [blame] | 25 | fi |
| 26 | |
Ben Clayton | 9f49ac5 | 2022-04-07 18:26:45 +0000 | [diff] [blame] | 27 | function list_tools() { |
| 28 | echo "Available tools:" |
| 29 | ls "${SCRIPT_DIR}/src/cmd" |
| 30 | } |
| 31 | |
| 32 | function 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 | |
| 41 | if [ -z "${TOOL}" ]; then |
| 42 | show_usage |
| 43 | fi |
| 44 | |
| 45 | if [ ! -d "${SCRIPT_DIR}/src/cmd/${TOOL}" ]; then |
| 46 | show_usage |
| 47 | fi |
Ben Clayton | be2362b | 2022-01-18 18:58:16 +0000 | [diff] [blame] | 48 | |
| 49 | # Rebuild the binary. |
| 50 | # Note, go caches build artifacts, so this is quick for repeat calls |
Ben Clayton | 9f49ac5 | 2022-04-07 18:26:45 +0000 | [diff] [blame] | 51 | pushd "${SCRIPT_DIR}/src" > /dev/null |
| 52 | go build -o "${BINARY}" "./cmd/${TOOL}" |
Ben Clayton | be2362b | 2022-01-18 18:58:16 +0000 | [diff] [blame] | 53 | popd > /dev/null |
| 54 | |
Ben Clayton | 9f49ac5 | 2022-04-07 18:26:45 +0000 | [diff] [blame] | 55 | "${BINARY}" "${@:2}" |