Mage calls go build via os/exec, explicitly passing through os.Environ to the subprocess.
Somehow the cross compiled binary from my osx laptop is referencing the goroot from my laptop when it tries to run go build on a Linux machine.
1. How is this possible?
2. How can I fix it?
I'll see if I can repro with a minimal example tonight.
c := exec.Command("go", "build", "main.go")
c.Env = append(os.Environ(), "GOROOT="+goroot)
err := c.Run()
--
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...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
So I figured out I was looking for the error in the wrong place. The place it was failing was in go/types when it tries to parse the files, using the go/build.Default context. Which is created here: https://github.com/golang/go/blob/master/src/go/build/build.go#L285It uses either the GOROOT of the environment (which is invariably not set), or the GOROOT of the machine that built this binary.Thanks to Dave, no one ever sets GOROOT, and so it defaults to the one from my OSX machine where I built the binary. aaarrggg
On Tuesday, 17 October 2017 14:59:30 UTC+11, Nate Finch wrote:Thanks to Dave, no one ever sets GOROOT, and so it defaults to the one from my OSX machine where I built the binary. aaarrgggI don't know if this was intended as a compliment, but I'll take it :)