Skip to content

Commit

Permalink
Improved windows host support (git bash & cygwin)
Browse files Browse the repository at this point in the history
When using windows as a host OS, GOROOT must be a Windows path.
This condition applies whenever invoking go, either as part of
the installation or when written into the .env file.  Also,
the .exe files in the Windows Go distribution do not have
an executable flag set.  This change addresses both of these
issues, allowing at least binary installs to run correctly when
running under git bash or cygwin.
  • Loading branch information
pjeby committed Mar 12, 2020
1 parent 4d1d725 commit 00ed763
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions gimme
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,22 @@ EOF

# _env "dir"
_env() {
if [[ -d "${1}/bin" && -f "${1}/bin/go.exe" && "$GIMME_HOSTOS" == windows ]] && command -v cygpath &>/dev/null
then
# .exe's don't come in from the .zip with the executable flag set
chmod +x "${1}/bin/"*.exe
# $1 is a cygwin/msys path, but GOROOT needs a Windows path
local -x GOROOT
GOROOT="$(cygpath -wa "$1")"
else
local -x GOROOT="$1"
fi

[[ -d "${1}/bin" && -x "${1}/bin/go" ]] || return 1

# if we try to run a Darwin binary on Linux, we need to fail so 'auto' can fallback to cross-compiling from source
# automatically
GOROOT="${1}" "${1}/bin/go" version &>/dev/null || return 1
"${1}/bin/go" version &>/dev/null || return 1

# https://twitter.com/davecheney/status/431581286918934528
# we have to GOROOT sometimes because we use official release binaries in unofficial locations :(
Expand All @@ -370,18 +381,19 @@ _env() {
# Tools like `gimme` are the reason that GOROOT-in-env exists.

echo
if [[ "$(GOROOT="${1}" "${1}/bin/go" env GOHOSTOS)" == "${GIMME_OS}" ]]; then
if [[ "$("${1}/bin/go" env GOHOSTOS)" == "${GIMME_OS}" ]]; then
echo 'unset GOOS;'
else
echo 'export GOOS="'"${GIMME_OS}"'";'
fi
if [[ "$(GOROOT="${1}" "${1}/bin/go" env GOHOSTARCH)" == "${GIMME_ARCH}" ]]; then
if [[ "$("${1}/bin/go" env GOHOSTARCH)" == "${GIMME_ARCH}" ]]; then
echo 'unset GOARCH;'
else
echo 'export GOARCH="'"${GIMME_ARCH}"'";'
fi

echo "export GOROOT='${1}';"
# GOROOT on Windows can contain \, so ensure it is shell-quoted
printf 'export GOROOT=%q;\n' "$GOROOT"

# shellcheck disable=SC2016
echo 'export PATH="'"${1}/bin"':${PATH}";'
Expand All @@ -393,12 +405,20 @@ _env() {

# _env_alias "dir" "env-file"
_env_alias() {
if [[ "$GIMME_HOSTOS" == windows ]] && command -v cygpath &>/dev/null; then
# $1 is a cygwin/msys path, but GOROOT needs a Windows path
local -x GOROOT
GOROOT="$(cygpath -wa "$1")"
else
local -x GOROOT="$1"
fi

if [[ "${GIMME_NO_ENV_ALIAS}" ]]; then
echo "${2}"
return
fi

if [[ "$(GOROOT="${1}" "${1}/bin/go" env GOHOSTOS)" == "${GIMME_OS}" && "$(GOROOT="${1}" "${1}/bin/go" env GOHOSTARCH)" == "${GIMME_ARCH}" ]]; then
if [[ "$("${1}/bin/go" env GOHOSTOS)" == "${GIMME_OS}" && "$("${1}/bin/go" env GOHOSTARCH)" == "${GIMME_ARCH}" ]]; then
# GIMME_GO_VERSION might be a branch, which can contain '/'
local dest="${GIMME_ENV_PREFIX}/go${GIMME_GO_VERSION//\//__}.env"
cp "${2}" "${dest}"
Expand Down Expand Up @@ -799,7 +819,7 @@ case "${GIMME_VERSION_PREFIX}" in
;;
esac

case "${GIMME_OS}" in mingw* | msys_nt*)
case "${GIMME_OS}" in mingw* | msys_nt* | cygwin_nt-*)
# Minimalist GNU for Windows
GIMME_OS='windows'

Expand All @@ -811,6 +831,18 @@ case "${GIMME_OS}" in mingw* | msys_nt*)
;;
esac

case "${GIMME_HOSTOS}" in mingw* | msys_nt* | cygwin_nt-*)
# Minimalist GNU for Windows
GIMME_HOSTOS='windows'

if [ "${GIMME_HOSTARCH}" = 'i686' ]; then
GIMME_HOSTARCH="386"
else
GIMME_HOSTARCH="amd64"
fi
;;
esac

force_install=0
force_known_update=0

Expand Down

0 comments on commit 00ed763

Please sign in to comment.