From aa82aae4353ce7dabd1448936201b8929b0c2cd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sat, 23 Apr 2022 10:48:46 +0300 Subject: [PATCH] exec-env: don't touch GO{ROOT,PATH} if ASDF_GOLANG_DISABLE_GO{ROOT,PATH} is 1 Setting these variables is not really required for things to work, and some setups explicitly prefer them not to be touched. Modeled after the similar options in goenv. https://github.com/syndbg/goenv/blob/d4e2dd79b83496dbf9474e31dbdb8d7eb8bb0261/ENVIRONMENT_VARIABLES.md --- README.md | 12 ++++++++++-- bin/exec-env | 9 ++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4527044..f9550f4 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,8 @@ selected, not necessarily `1.14.patch`. ## Architecture Override -The `ASDF_GOLANG_OVERWRITE_ARCH` variable can be used to override the architecture -that is used for determining which Go build to download. The primary use case is when attempting +The `ASDF_GOLANG_OVERWRITE_ARCH` variable can be used to override the architecture +that is used for determining which Go build to download. The primary use case is when attempting to install an older version of Go for use on an Apple M1 computer as Go was not being built for ARM at the time. #### Without ASDF_GOLANG_OVERWRITE_ARCH @@ -86,6 +86,14 @@ checksum verified By default we try to verify the checksum of each install but ocassionally [that's not possible](https://github.com/kennyp/asdf-golang/issues/91). If you need to skip the checksum for some reason just set `ASDF_GOLANG_SKIP_CHECKSUM`. +## `GOROOT` and `GOPATH` Overrides + +By default, `$GOROOT` and `$GOPATH` are set to the selected version's +`.../go` and `.../packages` dirs, and unset if the selected version is +`system`. Set the `$ASDF_GOLANG_DISABLE_GOROOT` and/or +`$ASDF_GOLANG_DISABLE_GOPATH` environment variables to `1` to disable +this behavior for the respective variables. + ## Contributing Feel free to create an issue or pull request if you find a bug. diff --git a/bin/exec-env b/bin/exec-env index 9ffa647..000321d 100755 --- a/bin/exec-env +++ b/bin/exec-env @@ -1,8 +1,11 @@ #!/usr/bin/env bash if [ "${ASDF_INSTALL_VERSION}" = 'system' ] ; then - unset -v GOROOT GOPATH + [ "${ASDF_GOLANG_DISABLE_GOROOT-}" = '1' ] || unset -v GOROOT + [ "${ASDF_GOLANG_DISABLE_GOPATH-}" = '1' ] || unset -v GOPATH else - export GOROOT=$ASDF_INSTALL_PATH/go - export GOPATH=$ASDF_INSTALL_PATH/packages + [ "${ASDF_GOLANG_DISABLE_GOROOT-}" = '1' ] || + export GOROOT=$ASDF_INSTALL_PATH/go + [ "${ASDF_GOLANG_DISABLE_GOPATH-}" = '1' ] || + export GOPATH=$ASDF_INSTALL_PATH/packages fi