Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved windows host support (git bash & cygwin) #184

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 37 additions & 6 deletions gimme
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,21 @@ 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/pkg/tool/*/*.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}" GOFLAGS="" "${1}/bin/go" version &>/dev/null || return 1
GOFLAGS="" "${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 +380,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 +404,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 +818,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 +830,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