aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/buildlist.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2020-07-27 12:57:36 -0400
committerBryan C. Mills <bcmills@google.com>2020-09-09 22:39:02 +0000
commit564b350c08a1906e8f6a876fef4cca71f6516d4c (patch)
tree4c6221b42e4ff068a4c5f3db09273271ab6f164a /src/cmd/go/internal/modload/buildlist.go
parent521393e7e05cd9272ae6023387fa92839d72eb4f (diff)
downloadgo-564b350c08a1906e8f6a876fef4cca71f6516d4c.tar.gz
go-564b350c08a1906e8f6a876fef4cca71f6516d4c.zip
cmd/go/internal/modload: rename LoadBuildList and BuildList
With lazy loading, the “build list” can be refined as packages are loaded. Rename functions that return the build list to more precisely describe the set of modules returned by the call. Also eliminate a redundant call to LoadBuildList (right before ListModules, which itself begins with the same call). For #36460 Change-Id: I0fc4f9dd7602e0df5e166e329ee5d516d810ca53 Reviewed-on: https://go-review.googlesource.com/c/go/+/249878 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>
Diffstat (limited to 'src/cmd/go/internal/modload/buildlist.go')
-rw-r--r--src/cmd/go/internal/modload/buildlist.go47
1 files changed, 26 insertions, 21 deletions
diff --git a/src/cmd/go/internal/modload/buildlist.go b/src/cmd/go/internal/modload/buildlist.go
index 2302b044e8..581a1b944a 100644
--- a/src/cmd/go/internal/modload/buildlist.go
+++ b/src/cmd/go/internal/modload/buildlist.go
@@ -27,34 +27,28 @@ import (
//
var buildList []module.Version
-// LoadBuildList loads and returns the build list from go.mod.
-// The loading of the build list happens automatically in ImportPaths:
-// LoadBuildList need only be called if ImportPaths is not
-// (typically in commands that care about the module but
-// no particular package).
-func LoadBuildList(ctx context.Context) []module.Version {
+// LoadAllModules loads and returns the list of modules matching the "all"
+// module pattern, starting with the Target module and in a deterministic
+// (stable) order, without loading any packages.
+//
+// Modules are loaded automatically (and lazily) in ImportPaths:
+// LoadAllModules need only be called if ImportPaths is not,
+// typically in commands that care about modules but no particular package.
+//
+// The caller must not modify the returned list.
+func LoadAllModules(ctx context.Context) []module.Version {
InitMod(ctx)
ReloadBuildList()
WriteGoMod()
return buildList
}
-// ReloadBuildList resets the state of loaded packages, then loads and returns
-// the build list set in SetBuildList.
-func ReloadBuildList() []module.Version {
- loaded = loadFromRoots(loaderParams{
- tags: imports.Tags(),
- listRoots: func() []string { return nil },
- allClosesOverTests: index.allPatternClosesOverTests(), // but doesn't matter because the root list is empty.
- })
- return buildList
-}
-
-// BuildList returns the module build list,
-// typically constructed by a previous call to
-// LoadBuildList or ImportPaths.
+// LoadedModules returns the list of module requirements loaded or set by a
+// previous call (typically LoadAllModules or ImportPaths), starting with the
+// Target module and in a deterministic (stable) order.
+//
// The caller must not modify the returned list.
-func BuildList() []module.Version {
+func LoadedModules() []module.Version {
return buildList
}
@@ -65,6 +59,17 @@ func SetBuildList(list []module.Version) {
buildList = append([]module.Version{}, list...)
}
+// ReloadBuildList resets the state of loaded packages, then loads and returns
+// the build list set in SetBuildList.
+func ReloadBuildList() []module.Version {
+ loaded = loadFromRoots(loaderParams{
+ tags: imports.Tags(),
+ listRoots: func() []string { return nil },
+ allClosesOverTests: index.allPatternClosesOverTests(), // but doesn't matter because the root list is empty.
+ })
+ return buildList
+}
+
// TidyBuildList trims the build list to the minimal requirements needed to
// retain the same versions of all packages from the preceding Load* or
// ImportPaths* call.