rogpeppe / go-internal

Selected Go-internal packages factored out from the standard library
BSD 3-Clause "New" or "Revised" License
823 stars 66 forks source link

Using golang.org/dl/go1.12 with testscript #63

Open pwaller opened 5 years ago

pwaller commented 5 years ago

Hi, I have go in my $PATH by symlinking to a golang.org/dl/go* binary. The problem is, that binary seems to locate itself by using the home directory.

The net result is that when I run this, exec go build doesn't work, because:

> exec go build
[stderr]
go1.12: not downloaded. Run 'go1.12 download' to install to /no-home/sdk/go1.12

... i.e, it thinks it isn't yet installed. Any tricks for working around this?

myitcv commented 5 years ago

@mvdan - do you use golang.org/dl/go*?

I'm afraid I don't use it. Instead I have full installs and use process mount namespaces to flip between versions (largely to avoid any issues with binaries being called go1.12 etc)

mvdan commented 5 years ago

Hmm, I do use golang.org/dl/go* for old Go versions. Right now, I have go1.11.5 set up via that.

Perhaps a way to work around this would be to run testscript with an explicit GOROOT, and then teach programs like go1.11.5 to look there.

mvdan commented 2 months ago

With https://go.dev/doc/toolchain existing today, I think this problem is "solved" as long as GOTOOLCHAIN is forwarded into testscripts. We already have a bit of code that does this for other env vars, so we could add it there as well:

https://github.com/rogpeppe/go-internal/blob/2af95f28b640cfd81947d78491669def10dc61f6/testscript/testscript.go#L457-L470