From 8eac67a5d0213765a4f71694168b7b61903baadd Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Fri, 26 Feb 2021 18:03:52 +0300 Subject: [PATCH] golang: Prepare for future GOPATH removal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GOPATH is going to be removed in Go1.17 (see e.g. https://github.com/golang/go/issues/37755#issuecomment-771879911). -> Prevent programs suddenly become installed into $HOME/go/bin instead of gowork/bin, and mod cache to become something like $HOME/go/... instead of being kept under gowork/ No change in behaviour for Go ≤ 1.16 --- component/golang/buildout.cfg | 2 +- component/golang/goenv.sh.in | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/component/golang/buildout.cfg b/component/golang/buildout.cfg index 70d2e49ffa5..d6d983adfbc 100644 --- a/component/golang/buildout.cfg +++ b/component/golang/buildout.cfg @@ -142,7 +142,7 @@ recipe = slapos.recipe.template url = ${:_profile_base_location_}/goenv.sh.in output = ${gowork:directory}/env.sh depends = ${gowork.mkdir:recipe} -md5sum = 09c229292b341da0de933f5900de7011 +md5sum = 6efdf5d63381c240c7d206d7939a63f7 [gowork.mkdir] # NOTE do not use slapos.cookbook:mkdirectory here - if anything in software (not instance) diff --git a/component/golang/goenv.sh.in b/component/golang/goenv.sh.in index fb763b7013d..ab53d99a9f7 100644 --- a/component/golang/goenv.sh.in +++ b/component/golang/goenv.sh.in @@ -10,11 +10,14 @@ export PKG_CONFIG_PATH=$(echo -n "${gowork:cpkgpath}" |tr '\n' ':'):$PKG_CONFIG_ # ---- 8< ---- export GOPATH=$X:$GOPATH -export PATH=$X/bin:$PATH -export PS1="(`basename $X`) $PS1" +export GOBIN=$X/bin export GOCACHE=$X/cache +export GOMODCACHE=$X/pkg/mod export GOENV=$X/goenv +export PATH=$GOBIN:$PATH +export PS1="(`basename $X`) $PS1" + # by default make go run in module-aware mode only if go.mod is present, and in GOPATH-mode otherwise. # (we still have some GOPATH uses; TODO -> default to "on" after GOPATH-mode usage is gone) export GO111MODULE=auto