Description
$ pwd
/home/mvdan/tip/src/cmd/gofmt
$ go version
go version devel go1.17-8e91458b19 Fri Apr 30 20:00:36 2021 +0000 linux/amd64
$ go install
$ which gofmt
/home/mvdan/tip/bin/gofmt
$ /usr/bin/go version
go version go1.16.3 linux/amd64
$ /usr/bin/go install
$ go version $(which gofmt)
/home/mvdan/tip/bin/gofmt: devel go1.17-8e91458b19 Fri Apr 30 20:00:36 2021 +0000
Note that Go 1.16.3 happily does nothing when it's told to go install
cmd/gofmt from tip, even though that should most definitely error. From the last command, you can see that the gofmt I'm using has not changed. The gofmt from /usr/bin can't have been changed either, as I'm not root.
I think I get why this is happening. /usr/bin/go install
turns into /usr/bin/go install cmd/gofmt
, so that ends up installing 1.16.3's cmd/gofmt, which is already up to date - hence nothing to do.
But that feels wrong. If I'm installing the package at the current directory, and this is a package under a different GOROOT than the toolchain's, that should simply fail very early on.
This caused me confusion on https://go-review.googlesource.com/c/go/+/284139. After a rebase on a cmd/gofmt change, I ran go install
and it finished incredibly quickly, even though I knew I had likely made a mistake. Plus, I would expect the first build to take about a second, as I'd need a new binary for sure. It was five minutes later that I realised I had forgot to re-run make.bash
earlier in the day, so my go
binary was falling back to the system's 1.16.3, rather than tip.