Skip to content

Commit 6f20549

Browse files
koobsghuntley
authored andcommitted
Allow overriding getopt from the environment
coder currently wants GNU getopt for reasons: # BSD getopt (which is installed by default on Macs) is not supported. Although getopt is notoriously non-portable and behaviour differs across implementations and operating systems, in leui of a discussion to remove this specific implementation requirement... Add a GETOPT environment variable in lib.sh and build_go.sh to allow specifying getopt location, leaving the current value 'getopt' as the default.
1 parent a4ea989 commit 6f20549

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

scripts/build_go.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ set -euo pipefail
2727
# shellcheck source=scripts/lib.sh
2828
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
2929

30+
# Allow specifying/overriding GETOPT via environment
31+
GETOPT?=getopt
32+
3033
version=""
3134
os="${GOOS:-linux}"
3235
arch="${GOARCH:-amd64}"
@@ -35,7 +38,7 @@ sign_darwin="${CODER_SIGN_DARWIN:-0}"
3538
output_path=""
3639
agpl="${CODER_BUILD_AGPL:-0}"
3740

38-
args="$(getopt -o "" -l version:,os:,arch:,output:,slim,agpl,sign-darwin -- "$@")"
41+
args="$($(GETOPT) -o "" -l version:,os:,arch:,output:,slim,agpl,sign-darwin -- "$@")"
3942
eval set -- "$args"
4043
while true; do
4144
case "$1" in

scripts/lib.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ realpath() {
3333
SCRIPT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"
3434
PROJECT_ROOT="$(cd "$SCRIPT_DIR" && realpath "$(git rev-parse --show-toplevel)")"
3535

36+
# Allow specifying/overriding GETOPT via environment
37+
GETOPT?=getopt
38+
3639
# pushd is a silent alternative to the real pushd shell command.
3740
pushd() {
3841
command pushd "$@" >/dev/null || error "Could not pushd to '$*'"
@@ -149,7 +152,7 @@ if [[ "${CODER_LIBSH_NO_CHECK_DEPENDENCIES:-}" != *t* ]]; then
149152
fi
150153

151154
# BSD getopt (which is installed by default on Macs) is not supported.
152-
if [[ "$(getopt --version)" == *--* ]]; then
155+
if [[ "$($(GETOPT) --version)" == *--* ]]; then
153156
libsh_bad_dependencies=1
154157
log "ERROR: You need GNU getopt to run the scripts in the Coder repo."
155158
if isdarwin; then

0 commit comments

Comments
 (0)