]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/go: maintain go and toolchain lines in go.work
authorRuss Cox <rsc@golang.org>
Thu, 1 Jun 2023 18:16:58 +0000 (14:16 -0400)
committerRuss Cox <rsc@golang.org>
Sat, 3 Jun 2023 21:13:11 +0000 (21:13 +0000)
commitce8146ed3361f584ba79427ac6c6d6fe9c297bea
treeea68532f8304b5ed7bceb9a56b8fbdf0431b672d
parent363713223385476b87dc5f26d267df8c67d13006
cmd/go: maintain go and toolchain lines in go.work

go work init / sync / use need to maintain the invariant that the
go version and toolchain in go.work are up-to-date with respect
to the modules in the workspace.

go get also preserves the invariant when running in a module.

go work use (including with no arguments) reestablishes the invariant.

Replaces the ToolchainTrySwitch func in PackageOpts with a new
gover.Switcher interface implemented by toolchain.Switcher.
Until now, the basic sketch of a particular phase of the go command
has been to call base.Error repeatedly, to report as many problems
as possible, and then call base.ExitIfErrors at strategic places where
continuing in the presence of errors is no longer possible.
A Switcher is similar: you call sw.Error repeatedly and then, when
all the errors from a given phase have been identified, call sw.Switch
to potentially switch toolchains, typically before calling base.ExitIfErrors.

One effect of the regularization of errors reported by the modload.loader
is to add a "go: " prefix to errors showing import stacks. That seems fine.

For #57001.

Change-Id: Id49ff7a28a969d3475c70e6a09d40d7aa529afa8
Reviewed-on: https://go-review.googlesource.com/c/go/+/499984
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
51 files changed:
src/cmd/go/alldocs.go
src/cmd/go/internal/gover/toolchain.go
src/cmd/go/internal/gover/version.go
src/cmd/go/internal/modcmd/graph.go
src/cmd/go/internal/modcmd/tidy.go
src/cmd/go/internal/modget/get.go
src/cmd/go/internal/modload/init.go
src/cmd/go/internal/modload/load.go
src/cmd/go/internal/modload/modfile.go
src/cmd/go/internal/toolchain/reqs.go [new file with mode: 0644]
src/cmd/go/internal/toolchain/toolchain.go
src/cmd/go/internal/workcmd/edit.go
src/cmd/go/internal/workcmd/init.go
src/cmd/go/internal/workcmd/sync.go
src/cmd/go/internal/workcmd/use.go
src/cmd/go/testdata/script/godebug_default.txt
src/cmd/go/testdata/script/goline_order.txt [new file with mode: 0644]
src/cmd/go/testdata/script/gotoolchain_modcmds.txt
src/cmd/go/testdata/script/mod_bad_domain.txt
src/cmd/go/testdata/script/mod_build_info_err.txt
src/cmd/go/testdata/script/mod_e.txt
src/cmd/go/testdata/script/mod_get_ambiguous_import.txt
src/cmd/go/testdata/script/mod_get_downgrade_missing.txt
src/cmd/go/testdata/script/mod_get_errors.txt
src/cmd/go/testdata/script/mod_get_exec_toolchain.txt
src/cmd/go/testdata/script/mod_get_pkgtags.txt
src/cmd/go/testdata/script/mod_get_split.txt
src/cmd/go/testdata/script/mod_go_version.txt
src/cmd/go/testdata/script/mod_goline.txt
src/cmd/go/testdata/script/mod_goline_too_new.txt
src/cmd/go/testdata/script/mod_import_toolchain.txt
src/cmd/go/testdata/script/mod_replace_import.txt
src/cmd/go/testdata/script/mod_tidy_compat_added.txt
src/cmd/go/testdata/script/mod_tidy_compat_ambiguous.txt
src/cmd/go/testdata/script/mod_tidy_compat_deleted.txt
src/cmd/go/testdata/script/mod_tidy_compat_implicit.txt
src/cmd/go/testdata/script/mod_tidy_compat_incompatible.txt
src/cmd/go/testdata/script/mod_tidy_convergence.txt
src/cmd/go/testdata/script/mod_tidy_convergence_loop.txt
src/cmd/go/testdata/script/mod_tidy_error.txt
src/cmd/go/testdata/script/mod_tidy_replace_old.txt
src/cmd/go/testdata/script/work.txt
src/cmd/go/testdata/script/work_get_toolchain.txt [new file with mode: 0644]
src/cmd/go/testdata/script/work_goline_order.txt [new file with mode: 0644]
src/cmd/go/testdata/script/work_init_toolchain.txt [new file with mode: 0644]
src/cmd/go/testdata/script/work_sync_toolchain.txt [new file with mode: 0644]
src/cmd/go/testdata/script/work_use.txt
src/cmd/go/testdata/script/work_use_issue55952.txt
src/cmd/go/testdata/script/work_use_noargs.txt [deleted file]
src/cmd/go/testdata/script/work_use_only_dirs.txt
src/cmd/go/testdata/script/work_use_toolchain.txt [new file with mode: 0644]