-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go: suppress errors for 'go get' of package paths that contain only tests #29268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
One comment on the current implementation: it seems a repo root that only has a
GO111MODULE=on go get k8s.io/api@master go: finding k8s.io/api master go: downloading k8s.io/api v0.0.0-20181130031204-d04500c8c3dd go build k8s.io/api: no non-test Go files in .../go/pkg/mod/k8s.io/[email protected]
CC @bhcleek |
I don't have a strong opinion about this, but I lean toward reporting the error, especially if it's consistent with non-module behavior. I assume go.mod would be updated as if |
Module paths being the import path of the root directory of the module is just a fundamental design choice we've made (and are not going to unmake). That creates a little bit of ambiguity, which can easily lead to confusion. But some confusion will exist no matter what we choose here. The choice is what the confusion looks like. In the world where go get module@version simply doesn't build code that isn't there (but still updates go.mod and therefore has a useful effect), users mostly ignore the distinction between module path and import path and they go on with their work. I think this is the best world; it's the one we're in now. In the world where go get module@version succeeds when there is code in the root of the module but fails when there is not, we will get a steady stream of bugs complaining that some modules are compatible with 'go get without -m' while other modules are not, and people will be confused about why. Some people will learn to type 'go get -m' literally every time they run 'go get' (because downloads now happen automatically, the only time you really run 'go get' anymore is for manipulating modules). Other people will write blog posts explaining that best practice is to write dummy empty packages in the roots of your modules so that they work even when users forget to type -m. This seems to me a worse world. It has strictly more confusion for end users than the current world. The k8s.io/api failure (only test go files in package) should be suppressed for all go get targets, not just the root of the module. |
The particularly confusing behavior here for repos with major-version breaks that predate semantic import paths. To draw an example from #27123: the module The options are unfortunate either way:
This may be a corner case either way, since packages should not disappear in general, but there certainly are plenty for existing repos that behave this way. |
I'm missing something: I don't understand what the github.com/lxc/lxd example has to do with requiring -m. |
The ambiguity occurs without |
Here is another neat example, from a conversation with @lopezator. The root of The message is not
|
My comment from Dec 18 #29268 (comment) still stands. I think we should not report the error and should close this bug. |
Is this comment from Russ from #29268 (comment) still pending:
... which I think references #29268 (comment)? (Maybe it is addressed by another issue, or maybe there is no plan to address it, but just wanted to double check). |
@bcmills Re-opening for tracking purposes regarding question in immediately prior comment. Feel free to close again. |
Same with me. But it occurs when I create a project outside With golang 1.12 or earlier I used
I hope it will help |
I'm running into a similar issue. I have 2 module-based projects, each hosted on our private GitLab instance. When I run
At the suggestion of several people in the Gophers Slack, I tried the variations below (all with $ go version
go version go1.12.9 linux/amd64
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/snip/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/snip/dev/golang"
GOPROXY="https://goproxy.io"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/snip/project2/go.mod"
CGO_CFLAGS=""
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS=""
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build290359151=/tmp/go-build -gno-record-gcc-switches" I agree with the earlier commenters that this should not be an error case, especially when the module contains multiple sub-packages that are being imported and used. |
Here is what I think is a variation of this issue in Go 1.14:
I think that is effectively the same as what @dylan-bourque reported above in #29268 (comment) CC @broady |
So it appears that we have also been experiencing this issue, however, we've found that the problem stems from not having a proper For example, if we add package main
// This file exists to define any Go code in the repo root
// so that it can be depended on as a library
func main() {} Then our |
Change https://golang.org/cl/289769 mentions this issue: |
A Go module path is not necessarily a valid Go package path: for example,
golang.org/x/tools
is a valid module path, but since there are no.go
files in the repo root it is not an importable package.go get
inGOPATH
mode returns a non-zero exit code if that happens, but today in module mode we explicitly suppress that error:go/src/cmd/go/internal/modget/get.go
Lines 532 to 536 in dbd323b
On the other hand, if the user intends to pass a module path (rather than a package path), they can indicate that explicitly using the
-m
flag.Should we change the error-suppressing path to instead produce a non-zero exit code? We could still make the error explicit about the fact that the requested path is a module but not a package.
(CC @rsc @hyangah @myitcv @thepudds @jayconrod )
The text was updated successfully, but these errors were encountered: