I'm trying to make kubernetes' codebase easier to navigate by people who 
have muscle-memory for go.  In the past we said "you have to call our 
Makefile" to build things.  I'd like to make \`go install\` work but I'm 
struggling to find a pattern that really works - am I missing something?

First, GOPATH is dead.  I hate that Go silently writes to my home 
directory, which is ALMOST NEVER what I really wanted. 

Aside: is there any way to get `go install` and `go build` to tell me what 
they wrote?  Would that be a reasonable feature request?  E.g. 

```
$ go install --print-result <pkg/path/to/cmd>
/home/thockin/go/bin/cmd
```

I usually set GOPATH=/dev/null.

```
$ GOPATH=/dev/null \
  go install <pkg>
go install <pkg>: mkdir /dev/null: not a directory
```

Good.  I want to install to a repo-local dir so all of our CI and stuff can 
find it.

```
$ GOPATH=/dev/null \
  GOBIN=./bin \
  go install <pkg>
```

That works.

```
$ GOPATH=/dev/null \
  GOBIN=./bin \
  GOARCH=arm \
  go install <pkg>
go: cannot install cross-compiled binaries when GOBIN is set
```

Well, shoot.  I can't find any other way for `go install` to work.

```
$ GOPATH=/dev/null \
  GOBIN=./bin \
  GOARCH=arm \
  go build <pkg>
```

That works, but splats the file into the current dir.  To be fair, that is 
documented behavior.

```
$ GOPATH=/dev/null \
  GOARCH=arm \
  go build -o ./bin <pkg>
```

That works, except when ./bin doesn't exist, in which case it becomes the 
output file (if I am building 1 thing) or I get an error (if I am building 
multiple things):

```
$ GOPATH=/dev/null \
  GOARCH=arm \
  go build -o ./bin <pkg1> <pkg2>
go: cannot write multiple packages to non-directory ./foo
```

I can specify a directory by adding a trailing `/` it seems:

```
$ GOPATH=/dev/null \
  GOARCH=arm \
  go build -o ./bin/ <pkg1> <pkg2>
```

That seems to work, but I have to get the invocation JUST RIGHT 100% of the 
time or risk causing weird errors and CI fails.  The obvious answer is 
"wrap it in a script or Makefile", which puts me right back where I started.

Is there a better answer?

Tim

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/d04fca5a-8b85-4386-9bae-50853f317fccn%40googlegroups.com.

Reply via email to