Description
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version
)?
go version go1.10.3 linux/amd64
vgo commit 22e23900224f03be49670113d5781e4d89090f45
Does this issue reproduce with the latest release?
Yes; and latest vgo
commit (per above)
What operating system and processor architecture are you using (go env
)?
GOARCH="amd64"
GOBIN="/tmp/tmp.VQw1O3x8Wy/hello/bin"
GOCACHE="/home/myitcv/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/tmp/tmp.VQw1O3x8Wy"
GORACE=""
GOROOT="/home/myitcv/gos"
GOTMPDIR=""
GOTOOLDIR="/home/myitcv/gos/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build414355570=/tmp/go-build -gno-record-gcc-switches"
What did you do?
Off the back of #25624 (comment), I'd like to confirm that the following represents the "best practice" advice when adding and installing tool dependencies:
cd `mktemp -d`
export GOPATH=$PWD
mkdir hello
cd hello
vgo mod -init -module example.com/hello
# this could be anywhere but for convenience...
export GOBIN=$PWD/bin
# add a dependency on golang.org/x/tools/cmd/stringer
cat <<EOD > tools.go
// +build tools
package tools
import (
_ "golang.org/x/tools/cmd/stringer"
)
EOD
vgo install golang.org/x/tools/cmd/stringer
The go.mod
and .Target
for stringer
look fine:
$ cat go.mod
module example.com/hello
require golang.org/x/tools v0.0.0-20180615195736-465e6f399236
$ vgo list -f "{{.Target}}" golang.org/x/tools/cmd/stringer
/tmp/tmp.VQw1O3x8Wy/hello/bin/stringer
The issue however is that running vgo mod -sync
then removes our module requirement on golang.org/x/tools
- I suspect this is a bug:
$ vgo mod -json
{
"Module": {
"Path": "example.com/hello",
"Version": ""
},
"Require": [
{
"Path": "golang.org/x/tools",
"Version": "v0.0.0-20180615195736-465e6f399236"
}
],
"Exclude": null,
"Replace": null
}
$ vgo mod -sync
warning: "ALL" matched no packages
$ vgo mod -json
{
"Module": {
"Path": "example.com/hello",
"Version": ""
},
"Require": null,
"Exclude": null,
"Replace": null
}
If we assume this is a bug and ignore it for now, I also wonder whether we can improve this workflow for adding tool dependencies somehow. The following steps feel a bit "boilerplate" and unnecessary:
- define a fake
tools.go
file - add a dependency on the tool (which will never compile because it's a
main
package, so I'm not sure we can ever safely verifytools.go
is "good"?) - set
GOBIN
to an appropriate location vgo install tool
- ensure
PATH
includesGOBIN
I wonder whether we could in fact obviate all of this by having something like:
vgo install -tool golang.org/x/tools/cmd/stringer
vgo run golang.org/x/tools/cmd/stringer
Thoughts?
vgo run tool
is possible as a result of #22726, but because of #25416 it effectively requires a link step each time.
What did you expect to see?
With respect to what I think is a bug with vgo mod -sync
go.mod
unchanged by the vgo mod -sync
What did you see instead?
The golang.org/x/tools
requirement removed.
Activity