Skip to content

Commit 5ba1c3f

Browse files
author
Bryan C. Mills
committed
cmd/go/internal/modload: remove SetBuildList
For the last remaining call site (in cmd/go/internal/work, added for the new 'go install pkg@version' codepath in CL 254365), use EditBuildList instead. SetBuildList assumes that the caller has enough information to produce a complete, coherent build list. With lazy loading, producing a complete, coherent build list is no longer quite so trivial. In CL 263267, I rewrote the main caller of SetBuildList (the 'go get' command), and in the process added a more targeted modload hook (EditBuildList). That hook also suffices for 'go install pkg@version'. The resulting error messages are perhaps not as smooth as they ought to be, but if they are too awkward we should probably fix them for 'go get' too, and the commands can continue to share the edit hook. For #36460 Updates #40276 Change-Id: I698a9dcd2efe6378a4d91f21362880aa8e50001b Reviewed-on: https://go-review.googlesource.com/c/go/+/270980 Trust: Bryan C. Mills <[email protected]> Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent ff2824d commit 5ba1c3f

File tree

4 files changed

+9
-14
lines changed

4 files changed

+9
-14
lines changed

src/cmd/go/internal/modload/buildlist.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,6 @@ func Selected(path string) (version string) {
7373
return ""
7474
}
7575

76-
// SetBuildList sets the module build list.
77-
// The caller is responsible for ensuring that the list is valid.
78-
// SetBuildList does not retain a reference to the original list.
79-
func SetBuildList(list []module.Version) {
80-
buildList = append([]module.Version{}, list...)
81-
}
82-
8376
// EditBuildList edits the global build list by first adding every module in add
8477
// to the existing build list, then adjusting versions (and adding or removing
8578
// requirements as needed) until every module in mustSelect is selected at the
@@ -222,7 +215,7 @@ type Conflict struct {
222215
}
223216

224217
// ReloadBuildList resets the state of loaded packages, then loads and returns
225-
// the build list set in SetBuildList.
218+
// the build list set by EditBuildList.
226219
func ReloadBuildList() []module.Version {
227220
loaded = loadFromRoots(loaderParams{
228221
PackageOpts: PackageOpts{

src/cmd/go/internal/modload/mvs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type mvsReqs struct {
2424
}
2525

2626
// Reqs returns the current module requirement graph.
27-
// Future calls to SetBuildList do not affect the operation
27+
// Future calls to EditBuildList do not affect the operation
2828
// of the returned Reqs.
2929
func Reqs() mvs.Reqs {
3030
r := &mvsReqs{

src/cmd/go/internal/work/build.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -789,10 +789,12 @@ func installOutsideModule(ctx context.Context, args []string) {
789789
base.Fatalf(directiveFmt, args[0], installMod, "exclude")
790790
}
791791

792-
// Initialize the build list using a dummy main module that requires the
793-
// module providing the packages on the command line.
794-
target := module.Version{Path: "go-install-target"}
795-
modload.SetBuildList([]module.Version{target, installMod})
792+
// Since we are in NoRoot mode, the build list initially contains only
793+
// the dummy command-line-arguments module. Add a requirement on the
794+
// module that provides the packages named on the command line.
795+
if err := modload.EditBuildList(ctx, nil, []module.Version{installMod}); err != nil {
796+
base.Fatalf("go install %s: %v", args[0], err)
797+
}
796798

797799
// Load packages for all arguments. Ignore non-main packages.
798800
// Print a warning if an argument contains "..." and matches no main packages.

src/cmd/go/testdata/script/mod_install_pkg_version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ cmp stderr exclude-err
159159
# 'go install pkg@version' should report an error if the module requires a
160160
# higher version of itself.
161161
! go install example.com/cmd/[email protected]
162-
stderr '^go install: example.com/[email protected]: module requires a higher version of itself \(v1.0.0\)$'
162+
stderr '^go install example.com/cmd/a@v1.0.0-newerself: version constraints conflict:\n\texample.com/[email protected] requires example.com/[email protected], but example.com/cmd@v1.0.0-newerself is requested$'
163163

164164

165165
# 'go install pkg@version' will only match a retracted version if it's

0 commit comments

Comments
 (0)