Repository navigation
Expand file tree
/
Copy pathrun-tool
More file actions
executable file
·77 lines (69 loc) · 2.76 KB
/
Copy pathrun-tool
File metadata and controls
executable file
·77 lines (69 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bash
# *******************************************************************************
# Copyright (c) 2026 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
# Consumer repositories install this runner as .devcontainer/run-tool.
# It runs a pinned CLI tool from PATH in a container, from local PATH on the host
# when available, or through Bazel otherwise.
# Use --strict to bypass local tools on the host and force execution through Bazel.
# See https://github.com/eclipse-score/devcontainer/tree/main/tools.
set -euo pipefail
strict=0
if [[ "${1:-}" == "--strict" ]]; then
strict=1
shift
fi
if [[ "$#" -lt 1 ]]; then
echo "Usage: $0 [--strict] <tool> [args...]" >&2
exit 2
fi
tool_name="$1"
shift
# Tests can force either side of the container boundary without changing the
# runtime's automatic detection behavior.
in_container() {
case "${RUN_TOOL_CONTAINER_MODE:-auto}" in
host) return 1 ;;
container) return 0 ;;
auto)
[[ -f /.dockerenv ]] || [[ -f /run/.containerenv ]] || [[ -d /devcontainer ]]
;;
*)
echo "Invalid RUN_TOOL_CONTAINER_MODE: ${RUN_TOOL_CONTAINER_MODE}" >&2
return 2
;;
esac
}
# A container built from this catalog only ever has the pinned version on
# PATH, so container execution is direct and untouched.
# shellcheck disable=SC2310
if in_container && command -v "${tool_name}" >/dev/null 2>&1; then
exec "${tool_name}" "$@"
# On the host, prefer the local tool on PATH for faster execution unless --strict
# is set. If local execution fails, suggest --strict to run the pinned Bazel target.
elif [[ "${strict}" -eq 0 ]] && command -v "${tool_name}" >/dev/null 2>&1; then
if "${tool_name}" "$@"; then
exit 0
else
exit_code=$?
echo "Execution of local '${tool_name}' failed with exit code ${exit_code}." >&2
echo "Use '--strict' to bypass the local tool and run the pinned version via Bazel." >&2
exit "${exit_code}"
fi
elif command -v bazel >/dev/null 2>&1; then
# Consumer repositories expose this module as @score_devcontainer; `--`
# prevents tool flags from being interpreted as Bazel flags.
exec bazel run "@score_devcontainer//tools:${tool_name}" -- "$@"
else
echo "Could not run '${tool_name}': no container command or Bazel executable is available." >&2
exit 127
fi