diff options
author | Vincent Ambo <tazjin@google.com> | 2019-07-02T15·40+0100 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2019-07-02T15·40+0100 |
commit | 892493a4788a9843b1b71848e58554e445658d31 (patch) | |
tree | f69e71ffabcc63647e9dab2831ae9162faeda38c /tools/bin/__dispatch.sh | |
parent | c31a0b552b98cf297e3b7c90c63968faab0a1f49 (diff) |
feat(tools): Add dispatcher script to transparently access tools r/12
Initial version of tool provider via Nix. This requires two separate steps for adding a new tool: 1. New symlink in tools/bin to point at the dispatch script. 2. Mapping of tool to Nix package set attribute in dispatch script.
Diffstat (limited to 'tools/bin/__dispatch.sh')
-rwxr-xr-x | tools/bin/__dispatch.sh | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tools/bin/__dispatch.sh b/tools/bin/__dispatch.sh new file mode 100755 index 000000000000..7db75bf870f3 --- /dev/null +++ b/tools/bin/__dispatch.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# This script dispatches invocations transparently to programs instantiated from +# Nix. +# +# To add a new tool, in +set -ueo pipefail + +readonly REPO_ROOT=$(git rev-parse --show-toplevel) +readonly ARGS="$@" +readonly TARGET_TOOL=$(basename $0) + +function nix_dispatch() { + local attr="${1}" + local result=$(nix-build --no-out-link --attr "${attr}" "${REPO_ROOT}") + + PATH="${result}/bin:$PATH" + if [ -z "${ARGS}" ]; then + exec "${TARGET_TOOL}" + else + exec "${TARGET_TOOL}" "${ARGS}" + fi +} + +case "${TARGET_TOOL}" in + git-appraise) + nix_dispatch "thirdParty.gitAppraise" + ;; + *) + echo "The tool '${TARGET_TOOL}' is currently not installed in this repository." + ;; +esac |