]> Cypherpunks repositories - gostls13.git/commit
cmd/go/internal/modload: rework import resolution
authorBryan C. Mills <bcmills@google.com>
Fri, 28 Aug 2020 22:19:22 +0000 (18:19 -0400)
committerBryan C. Mills <bcmills@google.com>
Wed, 9 Sep 2020 20:53:04 +0000 (20:53 +0000)
commit015a5a5c5c4b4ce4dce55601032b8e2f5fbcca9a
tree02c56af111aa676db00917d8cf8ff5eb7e31618b
parent26d27f96fec733fe09751b49b47282c9109fb8ad
cmd/go/internal/modload: rework import resolution

modload.Import previously performed two otherwise-separable tasks:

1. Identify which module in the build list contains the requested
   package.

2. If no such module exists, search available modules to try to find
   the missing package.

This change splits those two tasks into two separate unexported
functions, and reports import-resolution errors by attaching them to
the package rather than emitting them directly to stderr. That allows
'list' to report the errors, but 'list -e' to ignore them.

With the two tasks now separate, it will be easier to avoid the
overhead of resolving missing packages during lazy loading if we
discover that some existing dependency needs to be promoted to the top
level (potentially altering the main module's selected versions, and
thus suppling packages that were previously missing).

For #36460
Updates #26909

Change-Id: I32bd853b266d7cd231d1f45f92b0650d95c4bcbd
Reviewed-on: https://go-review.googlesource.com/c/go/+/251445
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
src/cmd/go/internal/list/list.go
src/cmd/go/internal/modload/import.go
src/cmd/go/internal/modload/import_test.go
src/cmd/go/internal/modload/load.go
src/cmd/go/testdata/script/list_bad_import.txt
src/cmd/go/testdata/script/list_test_err.txt
src/cmd/go/testdata/script/mod_list_bad_import.txt
src/cmd/go/testdata/script/mod_missingpkg_prerelease.txt