3 ms·
Indeed. I have a couple of Go projects that are released in the classical manner as tarballs, which users can extract anywhere and compile with `make && make in
by majewsky 10y ago
Indeed. I have a couple of Go projects that are released in the classical manner as tarballs, which users can extract anywhere and compile with `make && make install`.
This used to work okay-ish until Go 1.5. Then Go 1.6 introduced vendoring support (i.e. you put the code for the libraries you need into your own repo) which is very nice if it works, so I wanted to have it. But `go build` stubbornly refuses to look at vendored code when you are not in the exact correct location inside the GOPATH.
To preserve the familiar build semantics, I set up the GOPATH inside the repo. Roughly like this:
$ git clone https://github.com/foo/bar && cd bar
$ mkdir -p .gopath/src/github.com/foo
$ ln -sTf ../../../.. .gopath/src/github.com/foo/bar
$ GOPATH=$PWD/.gopath go build github.com/foo/bar
Of course, all that bullshit can be nicely tugged away in the Makefile. For example: https://github.com/sapcc/swift-drive-autopilot/blob/a3d5d02ba86d59c6aa7aadbc9bfcef8b527bffa4/Makefile https://github.com/sapcc/swift-drive-autopilot/blob/a3d5d02b...
You can find this either hilarious or sad. I like the irony in using make(1) to patch up the deficiencies of a tool that was created decades after it.
- ernsheong 10y agoThere is a tool called gb that helps you with this https://getgb.io/ https://getgb.io/ (I have no affiliation with gb)
- majewsky 10y agoWhile we're shamelessly plugging: I actually wrote my own vendoring tool after being confused by the ecosystem. It's a shell script of maybe 30 LOC: https://github.com/holocm/golangvend/blob/master/golangvend https://github.com/holocm/golangvend/blob/master/golangvend I hope to abandon it for an official solution, though, given that it appears and is good.
- i4k 10y ago> To preserve the familiar build semantics You are trying to build Go in a way it wasn't designed for. Go encourages absolute import paths (relative to $GOPATH) and solves a myriad of other language faults in this way. A good benefit is go-gettable projects, where all dependencies can be reached without a setup/configuration file (like setup.py, requirements.txt, and so on). If you do not try to use Go like other language, your build should be something like: $ GOPATH=$PWD/some/path go get github.com/foo/bar
- codemac 10y ago> You are trying to build Go in a way it wasn't designed for. Yeah, I think his issue is with Go's choice to not search the current directory. The go tools should let you use the current directory, and the "best practice" would have been vendoring to start, relative to the current directory. Then suddenly you see no GOPATH would be necessary at all! For example: % mkdir $proj % go get github.com/$dep1 % go get github.com/$dep2 % vim main.go % find . ./main.go ./github.com ./github.com/$dep1 ./github.com/$dep1/somepkg ./github.com/$dep2 ... See, then main can import github.com/$dep1/somepkg, and it would be properly versioned and vendored! It falls out in a bunch of other ways of being nicer too IMO. The currently GOPATH design encourages untracked and complected dependencies, where we're at 1.8 of the toolchain and we're still changing packaging behavior of dependencies.
- majewsky 10y agoNote that my project is still go-gettable. I've structured it in such a way that it is familiar both to Go devs using `go get` and to users who know `tar xf && make && make install `.