1pkg/gopium

environment variable issues

verdverm opened this issue · 9 comments

tony at penguin in ~/cue/gerrit on (no branch)▲
$ env | grep GOCACHE
GOCACHE=/home/tony/.cache/go-build
tony at penguin in ~/cue/gerrit on (no branch)▲
$ gopium ast_go cuelang.org/go/internal/core/adt memory_pack
Error: visiting error happened err: exit status 1: stderr: build cache is required, but could not be located: GOCACHE is not defined and neither $XDG_CACHE_HOME nor $HOME are defined

the other ENV VARs are in my environment as well

1pkg commented

Hi @verdverm you can pass env variables to gopium via -e, --package_build_envs strings Gopium go package build envs, additional list of building envs is expected. cli flag (gopium -e "GOCACHE=/home/tony/.cache/go-build" ast_go cuelang.org/go/internal/core/adt memory_pack should work for you). Env variables implemented via flag to be easy integrated with vscode extension using "gopium.packageBuildEnvs" key in settings.json and because underlying type parser typepkg.ParserXToolPackagesAst uses exactly the same array format anyway.

1pkg commented

Btw I just checked latest gopium binary because I was curious why you even need to setup custom GOCACHE env. And I believe I found an issue. So If you install gopium via extension or inside gomodule it will work as expected. But If you try install gopium outside of any gomodule (let's say just in GOPATH) it will throw an error Error: visiting error happened err: exit status 1: stderr: build cache is required, but could not be located: GOCACHE is not defined and $HOME is not defined and won't work without -e "GOCACHE=/Users/default/Library/Caches/go-build" -e "GOPATH=/Users/default/dev". Which sounds really weird to me 😞 I need to read what is the difference between installed binary from gomodule and outside of it.

1pkg commented

UPD the most weird piece is if I just install gopium from source code with cd $GOPATH/src/github.com/1pkg/gopium && go install it works without extra GOCACHE and GOPATH envs. I would think that go get should do exactly same: download + install ... but it seems something is off for non gomod scenario.

@verdverm please try to use v1.2.5

1pkg commented

Okay I read go get docs, I couldn't find what can cause the issue ... for now I created a bandage that will set default GOCACHE and GOPATH values if no env variables were provided. Should be good enough as default if you still need override defaults it could be done via -e flag. I tested it on my local machine: now both go mod installation and GOPATH installation works as expected.

GOPATH is deprecated as Go continues to embrace modules. There is a new directory, typically in $HOME/go, where Go stores stuff

I don't use VS Code either, doing this at the terminal.

1pkg commented

GOPATH is deprecated as Go continues to embrace modules. - this is the fact.
However there are two things to say here:

  • when you install package globally, for example using go get github.com/1pkg/gopium inside $HOME, it still will be installed into $GOPATH
  • gopium uses packages.Load from golang.org/x/tools/go/packages that requires both GOCACHE and GOPATH vars set

So simplest solution for now - just artificially set them.

I don't have any GO* environment variables set. Go uses its own defaults

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/tony/.cache/go-build"
GOENV="/home/tony/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/tony/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/tony/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build732687623=/tmp/go-build -gno-record-gcc-switches"


$ env | grep GO
1pkg commented

Yes but that doesn't change the fact that for some reason for gopium that was goget globally those variables (even go default ones) are not propagated properly to packages.Load golang.org/x/tools/go/packages. I have 0 clue why it's happening only for goget global installation but it's really hard to debug. So I would say current fix with proactive set of env vars for a packages.Load parser is a small enough evil to justify.

Please try update your gopium binary with go get -u github.com/1pkg/gopium it should all work now.

1pkg commented

I will consider this fixed then.