From b6a4c14bedeab03c05650b2421e54e209e281dd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sat, 23 Apr 2022 10:35:00 +0300 Subject: [PATCH 1/3] exec-env: unset GOROOT and GOPATH if version is system Otherwise they -- especially GOROOT -- may end up pointing to a completely wrong one. --- bin/exec-env | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/exec-env b/bin/exec-env index a363908..1efaf05 100755 --- a/bin/exec-env +++ b/bin/exec-env @@ -1,6 +1,8 @@ #!/usr/bin/env bash -if [ "${ASDF_INSTALL_VERSION}" != 'system' ] ; then +if [ "${ASDF_INSTALL_VERSION}" = 'system' ] ; then + unset -v GOROOT GOPATH +else if [[ "unset" == "${GOROOT:-unset}" ]] ; then export GOROOT=$ASDF_INSTALL_PATH/go fi From 1fe10b7641c784398c2eceddc12da232d9482b73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sat, 23 Apr 2022 10:37:11 +0300 Subject: [PATCH 2/3] exec-env: set GOROOT and GOPATH unconditionally Otherwise, existing values from the environment may continue to point to a wrong version. Refs https://github.com/asdf-community/asdf-direnv/issues/149 --- bin/exec-env | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/bin/exec-env b/bin/exec-env index 1efaf05..9ffa647 100755 --- a/bin/exec-env +++ b/bin/exec-env @@ -3,11 +3,6 @@ if [ "${ASDF_INSTALL_VERSION}" = 'system' ] ; then unset -v GOROOT GOPATH else - if [[ "unset" == "${GOROOT:-unset}" ]] ; then - export GOROOT=$ASDF_INSTALL_PATH/go - fi - - if [[ "unset" == "${GOPATH:-unset}" ]] ; then - export GOPATH=$ASDF_INSTALL_PATH/packages - fi + export GOROOT=$ASDF_INSTALL_PATH/go + export GOPATH=$ASDF_INSTALL_PATH/packages fi From 91cd860ccbebafbd9abd2a36386ad9b144005afb 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 3/3] 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 | 8 ++++++++ bin/exec-env | 9 ++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4527044..d28fe9f 100644 --- a/README.md +++ b/README.md @@ -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