1
0
mirror of https://github.com/golang/go synced 2024-11-05 19:36:10 -07:00
go/imports/testdata/mod
Heschi Kreinick 9c309ee22f imports: stop using go/packages for modules
go/packages needs to call `go list` multiple times, which causes
redundant work and slows down goimports. If we reimplement `go list` in
memory, we can reuse state, saving time. `go list` also does work we
don't really need, like adding stuff to go.mod, and skipping that saves
more time.

We start with `go list -m`, which does MVS and such. The remaining work
is mostly mapping import paths and directories through the in-scope
modules to make sure we're giving the right answers. Unfortunately this
is quite subtle, and I don't know where all the traps are. I did my
best.

cmd/go already has tests for `go list`, of course, and packagestest is
not well suited to tests of this complexity. So I ripped off the script
tests in cmd/go that seemed relevant and made sure that our logic
returns the right stuff in each case. I'm sure that there are more cases
to cover, but this hit all the stuff I knew about and quite a bit I
didn't.

Since we may want to use the go/packages code path in the future, e.g.
for Bazel, I left that in place. It won't be used unless the magic env
var is set.

Files in internal and imports/testdata/mod were copied verbatim from
cmd/go.

Change-Id: I1248d99c400c1a0c7ef180d4460b9b8a3db0246b
Reviewed-on: https://go-review.googlesource.com/c/158097
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-01-22 20:29:12 +00:00
..
example.com_v1.0.0.txt imports: stop using go/packages for modules 2019-01-22 20:29:12 +00:00
golang.org_x_text_v0.0.0-20170915032832-14c0d48ead0c.txt imports: stop using go/packages for modules 2019-01-22 20:29:12 +00:00
rsc.io_!q!u!o!t!e_v1.5.2.txt imports: stop using go/packages for modules 2019-01-22 20:29:12 +00:00
rsc.io_!q!u!o!t!e_v1.5.3-!p!r!e.txt imports: stop using go/packages for modules 2019-01-22 20:29:12 +00:00
rsc.io_quote_v1.5.1.txt imports: stop using go/packages for modules 2019-01-22 20:29:12 +00:00
rsc.io_quote_v1.5.2.txt imports: stop using go/packages for modules 2019-01-22 20:29:12 +00:00
rsc.io_quote_v2_v2.0.1.txt imports: stop using go/packages for modules 2019-01-22 20:29:12 +00:00
rsc.io_quote_v3_v3.0.0.txt imports: stop using go/packages for modules 2019-01-22 20:29:12 +00:00
rsc.io_sampler_v1.3.0.txt imports: stop using go/packages for modules 2019-01-22 20:29:12 +00:00
rsc.io_sampler_v1.3.1.txt imports: stop using go/packages for modules 2019-01-22 20:29:12 +00:00