cmd/go: ignore wildcard-matched test-only packages in go build

It makes sense to be able to cd into the top of a directory tree
and run commands like:

	go list ./...
	go test ./...
	go build ./...
	go install ./...

Some packages have no tests. Some packages have only tests (no code).
While go list applies to both kinds of packages, and go test correctly
handles packages without tests, go build and go install reject packages
with only tests.

If you run

	go install testonlypkg

then it does seem reasonable to fail with an error, since testonlypkg
cannot actually be installed. But if testonlypkg was only picked up
by wildcard expansion, then to keep the examples above working,
we should just silently skip over it during go build and go install.

CL 23314 fixed this same problem for "go get golang.org/x/tour/..."
but special-cased "go get", leaving "go build" and "go install" failing.

This CL fixes the general case and removes the "go get" special case.

Picked this up in module work because I'm using "go build ./..." as part
of evaluating whether repos are compatible with Go modules.

Fixes golang/go#20760.
Fixes golang/go#22409.

Change-Id: I5caaa6a346a5d07a7ad9e2669e89da76b397dc42
Reviewed-on: https://go-review.googlesource.com/121196
Reviewed-by: Bryan C. Mills <bcmills@google.com>
7 files changed
tree: cf6e1795b52256a1da9aede8cb7e2ef03f02389e
  1. vendor/
  2. AUTHORS
  3. codereview.cfg
  4. CONTRIBUTING.md
  5. CONTRIBUTORS
  6. LICENSE
  7. main.go
  8. PATENTS
  9. README.md
README.md

Versioned Go Prototype (vgo)

This repository holds a prototype of what the go command might look like with integrated support for package versioning.

See research.swtch.com/vgo for documents about the design.

Download/Install

Use go get -u golang.org/x/vgo.

You can also manually git clone the repository to $GOPATH/src/golang.org/x/vgo.

Report Issues / Send Patches

See CONTRIBUTING.md.

This is still a very early prototype. You are likely to run into bugs. Please file bugs in the main Go issue tracker, golang.org/issue, and put the prefix x/vgo: in the issue title.

Thank you.