I am attempting to give glide a trial run, but not able to get it to work successfully
I am using gvm and running go1.5 in my environment
echo $GOPATH
/Users/xxxx/.gvm/pkgsets/go1.5/global
Installed glide (glide version 0.8.0)
Initiated "glide create" (yaml successfully created)
more glide.yaml
package: .
import:
Issued glide install and it fetched the necessary dependencies
Issued gobuild and it fails
main.go:6:2: cannot find package "github.com/jeffail/gabs" in any of:
/Users/xxx/.gvm/gos/go1.5/src/github.com/jeffail/gabs (from $GOROOT)
/Users/xxx/.gvm/pkgsets/go1.5/global/src/github.com/jeffail/gabs (from $GOPATH)
Am I missing any steps here?
Can you share your environment from go env? Do you have the GO15VENDOREXPERIMENT enabled? In go env you'll should see GO15VENDOREXPERIMENT=1
Hi Matt
Here goes
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/XXX/.gvm/pkgsets/go1.5/global"
GORACE=""
GOROOT="/Users/XXX/.gvm/gos/go1.5"
GOTOOLDIR="/Users/XXX/.gvm/gos/go1.5/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
@conikeec My confusion is in the error message. When the GO15VENDOREXPERIMENT is enabled you get an error message in the form:
$ go build
glide.go:51:2: cannot find package "foo/bar" in any of:
/Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/foo/bar (vendor tree)
/usr/local/Cellar/go/1.5.2/libexec/src/foo/bar (from $GOROOT)
/Users/mfarina/Code/go/src/foo/bar (from $GOPATH)
Before it looks in the $GOPATH or $GOROOT it looks in the vendor tree. I don't see that in your error message which usually says the GO15VENDOREXPERIMENT is off (equal 0). This is the confusing part.
What are the exact commands you used? Was it:
$ go build
GO15VENDOREXPERIMENT is enabled
However, it's skipping the vendor tree completely
go build
main.go:8:2: cannot find package "github.com/jeffail/gabs" in any of:
/Users/xxx/.gvm/gos/go1.5/src/github.com/jeffail/gabs (from $GOROOT)
/Users/xxx/.gvm/pkgsets/go1.5/global/src/github.com/jeffail/gabs (from $GOPATH)
more glide.yaml
package: .
import:
Glide puts packages in the vendor/ folder and manages fetching dependencies. Go handles the rest. Glide is there to complement Go. The issue of not picking up the vendor/ folder when GO15VENDOREXPERIMENT is enabled is in your Go setup. You might want to check the gvm issue queue.
Removed GVM based go install
Reinstalled go1.5
Set GO15VENDOREXPERIMENT=1
go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/xxx/gopath"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
Same issue exists
go build
main.go:8:2: cannot find package "github.com/jeffail/gabs" in any of:
/usr/local/go/src/github.com/jeffail/gabs (from $GOROOT)
/Users/xxx/gopath/src/github.com/jeffail/gabs (from $GOPATH)
more glide.yaml
package: .
import:
There does seem to be a problem here. I see stdlib packages in your glide.yaml. If that was created with glide create then you may want to update to the latest release where a bug causing that was fixed.
In any case, not looking in the vendor/ directory is a Go thing and has nothing to do Glide here. I'm not sure whey that's not in your search path.
Just to make sure... the place where the go build command is being run is inside of $GOPATH, right?
I think I'm running into the same issue, using Go 1.6 on both Ubuntu and OS X. Glide gets my deps into $GOPATH/vendor, but go build never even looks there. go env always shows GO15VENDOREXPERIMENT="1".
@Tinche have you tried running go version and go env to make sure things are right? Looking in the vendor directory is part of the go tool. If it's not working (and if it can't find the package it will tell you it looked in the vendor directory) then the place to look is in Go itself.
I agree this is probably either a problem in Go itself or just me doing something fundamentally wrong (which is an option since I'm not that knowledgeable about Go's packaging). Glide seems to be doing its job as it's supposed to (getting stuff into /vendor), it's just go build that's failing. I commented here since I saw another person having a similar issue. :) As far as I'm concerned this issue, here, can be closed.
I do feel kinda dumb for not getting this to work, though. By now I've tried using Go 1.6 in three ways: installed from the lxd-stable PPA on an Ubuntu server machine, installed using Ubuntu Make on my desktop and installed through brew on my work Mac. No installation has mentioned looking inside vendor/ upon go build failure (the vendor directory exists and there are packages inside, just like there'd be in src/ if I just go get-ted them). go env always reports GO15VENDOREXPERIMENT="1", and setting it manually to 1 doesn't actually change anything.
Here's a hello world project I put together for testing: https://gist.github.com/Tinche/5919cf9a3741db5a4778. GOPATH is set to . (not actually "." since they can't be relative, the absolute path).
$ go build src/tin/hello.go
src/tin/hello.go:4:8: cannot find package "github.com/codegangsta/cli" in any of:
/home/tin/.local/share/umake/go/go-lang/src/github.com/codegangsta/cli (from $GOROOT)
/home/tin/pg/golang-helloworld/src/github.com/codegangsta/cli (from $GOPATH)
Any ideas? ¯_(ツ)_/¯
@Tinche What is your GOPATH? Your project needs to be within the GOPATH and cannot be outside of it. Also, the root of your project can't be the GOPATH. Go requires there to be a src directory inside the GOPATH with the source inside that. Some things break when you don't follow that.
Basically, you can't have project based GOPATHs and use the go toolchain. We tried that prior to Go 1.5 and Glide 0.5.
Is that what you're trying to do?
@mattfarina Thank you for helping :)
My GOPATH is /home/tin/pg/golang-helloworld - that's the root directory of the gist I linked (https://gist.github.com/Tinche/5919cf9a3741db5a4778). So I do have a src/ directory directly under my GOPATH. My code is in GOPATH/src/tin/. vendor/ is also directly under the GOPATH. Is this wrong?
If I use go get, the third party library gets installed in GOPATH/src, and the build works. If I use Glide, the third party library gets installed in GOPATH/vendor, and the build doesn't work.
The vendor/ directory needs to be inside the src directory.
Go requires you to use a setup like:
└── src
└── YOURAPP
├── your source code
└── vendor/
The GOPATH is a workspace and applications are supposed to be within in it. The base of your application doesn't work well as the root of an application like this.
Yeah, that works, thanks. We'll reorganize a little.
Just out of curiosity, how does Glide determine where to put the vendor/ directory? Current working directory, right next to glide.yaml/lock, or another way?
@Tinche Glide puts the vendor/ directory next to the glide.yaml. This is because of the way Go itself does the vendor/ directory lookups. Go starts looking in the current directory for a vendor/ directory with an imported package. Then it walks up the directory tree looking for a vendor/ directory with the import. Putting the vendor/ directory next to the glide.yaml and glide.lock let's us know that this one is managed by these files.
There are a few other reasons but this is a big one.
I setup up my project under GOPATH but happens the same that @Tinche described above. When I install dependencies from go get it works, but go compiler don't see vendor directory
go version
go version go1.8.1 darwin/amd64
go env
OARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/fagner/Development/somoseducacao/golang"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.8.1/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.8.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/pp/jwfb_mpn1hl_q3qxy2zp9r9c0000gp/T/go-build544545838=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
@seufagner I'm having the exact same issue on my environment...OSX + homebrew.
Most helpful comment
Just to make sure... the place where the
go buildcommand is being run is inside of$GOPATH, right?