aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/load.go
AgeCommit message (Collapse)Author
8 dayscmd/go: add compatibility tests for go mod tidy -diffSam Thanawalla
For #27005 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest Change-Id: I90ab8c21222ac2189abb40e8c8e7549e2d940dd2 Reviewed-on: https://go-review.googlesource.com/c/go/+/587941 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Matloob <matloob@golang.org>
2024-05-22cmd/go: add go mod tidy -diffSam Thanawalla
The -diff flag causes tidy not to modify the files but instead print the necessary changes as a unified diff. It exits with a non-zero code if updates are needed. Fixes: #27005 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest Change-Id: Ie239367f2fc73ecb55ec2ce76442293635c1b47d Reviewed-on: https://go-review.googlesource.com/c/go/+/585401 Reviewed-by: Michael Matloob <matloob@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-15cmd/go/internal/modload: compute direct in workspace modeMichael Matloob
The Requirements structure, which represents the root level requirements of the module graph also has a 'direct' field which contains the set of direct dependencies of a module. Before this change, in workspace mode, the direct field was not set on the Requirements structure. This change sets direct in the two places it's needed: when initializing Requirements from the workspace's mod files and when updating Requirements based on imports. When initializing Requirements from the workspace's mod files, this change will use the 'indirect' comments in those mod files to record the set of direct modules passed to the Requirements. There is a loop in updateRequirements where we consider the imports of the packages we loaded from the main module to make sure that all those imported packages' modules are required. The loop also updates direct for each of those modules (which have at least one package directly imported by the main modules). Before this change, in the workspace case we continued early from the loop and didn't proceed to the code where direct is computed. This change fixes that. Fixes #66789 Change-Id: I2b497fbf28c2197e8ba8e8ca5314c1a720f16364 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/580256 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com>
2024-03-27cmd/go: replace reflect.DeepEqual with slices.Equal and maps.EqualDaniel Martí
All of these maps and slices are made up of comparable types, so we can avoid the overhead of reflection entirely. Change-Id: If77dbe648a336ba729c171e84c9ff3f7e160297d Reviewed-on: https://go-review.googlesource.com/c/go/+/574597 Reviewed-by: Than McIntosh <thanm@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-11-08cmd/go/internal/modload: avoid calling strings.HasPrefix twice in ↵Jes Cok
*MainModuleSet.DirImportPath Since TrimPrefix uses HasPrefix internally. Change-Id: Ifadb99dd9192578056636adacaccc9d88a1c1f32 GitHub-Last-Rev: 74bcfff3fb5eaee281796ccb5bc84c6941d44615 GitHub-Pull-Request: golang/go#63893 Reviewed-on: https://go-review.googlesource.com/c/go/+/539096 Run-TryBot: Jes Cok <xigua67damn@gmail.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
2023-07-24cmd/go: add support for vendoring in workspace modeMichael Matloob
In most cases this change removes assumptions that there is a single main module in vendor mode and iterates over the workspace modules when doing checks. The go mod vendor command will now, if in workspace mode, create a vendor directory in the same directory as the go.work file, containing the packages (and modules in modules.txt) loaded from the workspace. When reassembling the module graph from the vendor directory, an edges are added from each of the main modules to their requirements, plus additionally to a fake 'vendor/modules.txt' module with edges to all the modules listed in vendor/modules.txt. For #60056 Change-Id: I4a485bb39836e7ab35cdc7726229191c6599903e Reviewed-on: https://go-review.googlesource.com/c/go/+/495801 Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org>
2023-06-03cmd/go: maintain go and toolchain lines in go.workRuss Cox
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>
2023-06-03cmd/go: adjust pruning and switch toolchain when needed in 'go mod tidy'Bryan C. Mills
'go mod tidy' may resolve an imported package by added a dependency that requires a higher 'go' version, which may activate graph pruning (if the version goes from below go 1.16 to above it), and may even require switching to a newer toolchain (if the version is not supported by the current one). For #57001. Change-Id: Ic8e9b87d5979b3a6d1ee70f1f2bf2eea46b1bb0d Reviewed-on: https://go-review.googlesource.com/c/go/+/499676 Reviewed-by: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
2023-06-02cmd/go: adjust pruning and switch toolchains if needed when go get changes ↵Bryan C. Mills
go version When we do 'go get', the Go version can change now. That means we need to do the pruning conversions that until now have only been necessary in go mod tidy -go=version. We may also need to upgrade the toolchain in order to load enough o the module graph to finish the edit, so we should let a TooNewError bubble up to the caller instead of trying to downgrade the affected module to avoid the error. Revised from CL 498120. For #57001. Change-Id: Ic8994737eca4ed61ccc093a69e46f5a6caa8be87 Reviewed-on: https://go-review.googlesource.com/c/go/+/498267 Reviewed-by: Russ Cox <rsc@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-06-02cmd/go: adjust conditions in which toolchain lines are writtenBryan C. Mills
'go mod tidy -go=1.20' should tidy as Go 1.20 did, without writing a toolchain line implicitly. (We don't need it to stabilize toolchain version switching anyway: because Go 1.20 predates toolchain switching, any toolchain that supports switching toolchains also supports Go 1.20 modules directly.) For #57001. Change-Id: I415abac75d8d6de9f8ed470aab0d1ed4c225b08d Reviewed-on: https://go-review.googlesource.com/c/go/+/499987 Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-06-02cmd/go: return more errors from ReadModFile, loadModFileRuss Cox
Return more errors instead of base.Fatalf, so we can handle them in the callers. For #57001. Change-Id: If3e63d3f64188148f5d750991f9cb1175790d89d Reviewed-on: https://go-review.googlesource.com/c/go/+/499983 Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Russ Cox <rsc@golang.org>
2023-06-01cmd/go: add base.Error and base.FatalRuss Cox
Many many places in the go command use base.Errorf("go: %v", err) or base.Fatalf("go: %v", err) Introduce Error(error) and Fatal(error) to do this and update all call sites (global search and replace). The new Error gives us the opportunity to unwrap a multierror and add the go prefix to each line, which is the motivation for this change. (We want to start returning a multierror from LoadModFile and LoadModGraph.) For #57001. Change-Id: I9613653b94808224146077c30d22f814d4e19eed Reviewed-on: https://go-review.googlesource.com/c/go/+/499980 Auto-Submit: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
2023-06-01cmd/go: move version constants from modload to goverRuss Cox
For #57001. Change-Id: Ia76478b8eaa934b7e1dc1e9cd7fe8a2428fc291a Reviewed-on: https://go-review.googlesource.com/c/go/+/499978 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Russ Cox <rsc@golang.org>
2023-05-31cmd/go: introduce WriteOpts argument for WriteGoModRuss Cox
This CL is a no-op, just adding the new options and plumbing it through. 'go get' will use this option to let commitRequirements know whether toolchain was mentioned explicitly on the command line. For #57001. Change-Id: Iee7145f3335e899704df3e98fb840f1aa4063b0c Reviewed-on: https://go-review.googlesource.com/c/go/+/499555 Run-TryBot: Russ Cox <rsc@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-05-25cmd/go: avoid duplicate errors in module loadRuss Cox
Just a missing base.ExitIfErrors. Fixes #46160. Change-Id: I41949b0b7b036da94ba269220951677585d3f8e9 Reviewed-on: https://go-review.googlesource.com/c/go/+/498122 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Russ Cox <rsc@golang.org>
2023-05-25cmd/go: add go get go@version and toolchain@versionRuss Cox
go get go@version and toolchain@version updates the go and toolchain lines in go.mod. If toolchain ends up <= go, it is dropped. When the go version crosses certain version boundaries, it may be necessary to run 'go mod tidy -go=version'. That's left for a followup CL. When the go or toolchain version ends up higher than the current toolchain version, we cannot be sure we know how to write the file out, so we fail with an error message. In GOTOOLCHAIN auto mode, the newer toolchain should be downloaded and reinvoked; that's left for a followup CL too. For #57001. Change-Id: Ibfdcc549b40555a53bdb2d019816d18f1bd16be6 Reviewed-on: https://go-review.googlesource.com/c/go/+/497081 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
2023-05-23cmd/go: convert semver.Compare to gover.ModCompareRuss Cox
This sets up for introducing the 'go' and 'toolchain' modules but should be a no-op by itself. For #57001. Change-Id: I2e02b5d417f1edd4f4653b101e4975fe23093f66 Reviewed-on: https://go-review.googlesource.com/c/go/+/497456 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Russ Cox <rsc@golang.org>
2023-05-23cmd/go/internal/gover: add new Go version packageRuss Cox
Clean up Go version comparison. CL 494436 added an ad hoc version comparison for the toolchain switch. There are also other version comparisons scattered throughout the code, assuming that using semver.Compare with a "v" prefix gives the right answer. As we start to allow versions like "go 1.21rc1" in the go.mod file, those comparisons will not work properly. A future CL will need to inject Go versions into semver for use with MVS, so do what Bryan suggested in the review of CL 494436 and rewrite the comparison in terms of that conversion. For #57001. Change-Id: Ia1d441f1bc259874c6c1b3b9349bdf9823a707d4 Reviewed-on: https://go-review.googlesource.com/c/go/+/496735 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
2023-05-18cmd/go: propagate Context arguments through modfetch methodsBryan C. Mills
For #56886. For #38714. Change-Id: I15c4a8673407d3423d7e203d645c6d0fb780d192 Reviewed-on: https://go-review.googlesource.com/c/go/+/452456 Reviewed-by: Michael Matloob <matloob@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com>
2023-05-12cmd/go/internal/modload: reject the -modfile flag in workspace modeZeke Lu
Currently, in workspace mode, the -modfile flag affects all the modules listed in the go.work file. This is not desirable most of the time. And when it results in an error, the error message does not help. For example, when there are more than one modules listed in the go.work file, running "go list -m -modfile=path/to/go.mod" gives this error: go: module example.com/foo appears multiple times in workspace This change reject -modfile flag explicitly with this error message: go: -modfile cannot be used in workspace mode While at here, correct some typos in the modload package. Fixes #59996. Change-Id: Iff4cd9f3974ea359889dd713a747b6932cf42dfd GitHub-Last-Rev: 7dbc9c3f2f9bfe8acab088eb3266a08d8ec1ba16 GitHub-Pull-Request: golang/go#60033 Reviewed-on: https://go-review.googlesource.com/c/go/+/493315 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com>
2023-05-10cmd/go/internal/modload: skip reading go.mod files for imports in 'go mod ↵Bryan C. Mills
tidy' of modules before 'go 1.21' This eliminate a network access in 'go mod tidy' of an already-tidy module, which would otherwise be needed to fetch go.mod checksums for the test dependencies whose go.mod checksums were omitted in Go releases between Go 1.17 and 1.20 due to bug #56222. For modules between 'go 1.17' and 'go 1.20' we intentionally preserve the old 'go mod tidy' output (omitting go.sum entries for the go.mod files of test dependencies of external packages). We should also avoid performing extra sumdb lookups for checksums that would be discarded anyway. Updates #56222. Change-Id: I7f0f1c8e902db0e3414c819621c4b99052f503f0 Reviewed-on: https://go-review.googlesource.com/c/go/+/492741 Auto-Submit: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-02-03cmd/go/internal/par: use generic CacheRoger Peppe
Using generics here makes the code easier to understand, as the contract is clearly specified. It also makes the code a little more concise, as it's easy to write a wrapper for the cache that adds an error value, meaning that a bunch of auxilliary types no longer need to be defined for this common case. The load.cachingRepo code has been changed to use a separate cache for each key-value type combination, which seems a bit less sleazy, but might have some knock-on effect on memory usage, and could easily be changed back if desired. Because there's no longer an unambiguous way to find out whether there's an entry in the cache, the Cache.Get method now returns a bool as well as the value itself. Change-Id: I28443125bab0b3720cc95d750e72d28e9b96257d Reviewed-on: https://go-review.googlesource.com/c/go/+/463843 Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: roger peppe <rogpeppe@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-01-31cmd/go: use Join functions instead of adding path separators to stringsBryan C. Mills
Adding a file path separator is incorrect for a file path that may be the root directory on a Unix platform (such as in a container or chroot). Adding a path separator is incorrect for a package path prefix that may be the empty string (as in the "std" module in GOROOT/src). And in both cases, a Join function is arguably clearer and simpler anyway. Fixes #51506 (maybe). Change-Id: Id816930811ad5e4d1fbd206cddf219ecd4ad39a2 Reviewed-on: https://go-review.googlesource.com/c/go/+/463178 Reviewed-by: Russ Cox <rsc@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com>
2022-11-18cmd/go: replace 'directory .' with 'current directory' in some errorsMichael Matloob
To make the error clearer Fixes #56697 Change-Id: Idfb5e8704d1bfc64bd0a09d5b553086d9ba5ac33 Reviewed-on: https://go-review.googlesource.com/c/go/+/451295 Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Joedian Reid <joedian@golang.org>
2022-10-26cmd: remove redundant _cui fliter
Change-Id: Ia7e1e3679e03d125feb9708cb05bbd32c4954edb GitHub-Last-Rev: a62b72ea3edcf2b4f9f378cd03b1ac073ab80c74 GitHub-Pull-Request: golang/go#55957 Reviewed-on: https://go-review.googlesource.com/c/go/+/436879 Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: hopehook <hopehook@golangcn.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-14cmd/go/internal/modload: return error when tidyRoots failianwoolf
Fixes #51589 Change-Id: Ie9c56110754f4a435b22e2d7a86ae34b0bd28909 Reviewed-on: https://go-review.googlesource.com/c/go/+/427054 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
2022-10-07modload: provide a clearer error for standard library packages from newer ↵Jeremy Brewer
releases An older version of go compiling a main module that references a standard library package from a newer release (e.g. net/netip added in go 1.18) currently produces a confusing error message. This changes adds a new error message including go version diagnostics. Fixes #48966 Change-Id: I1e8319dafcf1f67d1b1ca869fe84190c3b3f3c3e Reviewed-on: https://go-review.googlesource.com/c/go/+/432075 Auto-Submit: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-06cmd/go: fix incorrect determination of import path is DirImportPathMichael Matloob
In practice this only shows up when a vendored package, imported on the command line, imports an internal package. Change-Id: I34c161d1f1ef15a87c58a422f17d11f77fbac53f Reviewed-on: https://go-review.googlesource.com/c/go/+/439735 Run-TryBot: Michael Matloob <matloob@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
2022-09-29cmd/go: using strings.CutPrefix replace strings.HasPrefix and strings.TrimPrefixcuiweixie
Change-Id: I143d05c24a3e897d0f3ee78dd16954c32ceae091 Reviewed-on: https://go-review.googlesource.com/c/go/+/435137 Run-TryBot: xie cui <523516579@qq.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com>
2022-09-15cmd/go: use strings.Buildercuiweixie
Change-Id: I0db93b7bdcd622ce9e23df183de4737744e6d6ea Reviewed-on: https://go-review.googlesource.com/c/go/+/428294 Reviewed-by: Jenny Rakoczy <jenny@golang.org> Auto-Submit: Jenny Rakoczy <jenny@golang.org> Run-TryBot: xie cui <523516579@qq.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Jenny Rakoczy <jenny@golang.org>
2022-09-09cmd/go/internal/modload: use atomic.Pointer for Requirements.graphAbirdcfly
Change-Id: Ie543e1b1df667cfaf3aafa4be727881461ee8b7d GitHub-Last-Rev: ed993dbe2445c4797303138b62f6c7e26050dcd4 GitHub-Pull-Request: golang/go#54888 Reviewed-on: https://go-review.googlesource.com/c/go/+/428716 Auto-Submit: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2022-08-26cmd/go/internal/modload: convert atomicLoadPkgFlags.bits to atomic typehopehook
Change-Id: I9e59530953439dec6f4524c5a7adc75c98c12b8f Reviewed-on: https://go-review.googlesource.com/c/go/+/425456 Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com>
2022-08-23cmd/go/internal/modload: remove ImportMap and PackageDirBryan C. Mills
These two functions together duplicated much of the functionality of modload.Lookup. Use that instead in modcmd.vendorPkg, and reduce the modload surface area. Updates #42504 Updates #40775 For #26904 Change-Id: Ib8aaac495d090178dd56971aef9e5aa44ffa818b Reviewed-on: https://go-review.googlesource.com/c/go/+/332571 Reviewed-by: Michael Matloob <matloob@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
2022-08-17cmd/go: propagate match errors in 'go run'Bryan C. Mills
Fixes #51604. Change-Id: I3bc86652c62d2b329d9c2db5ea443d56cf17f8d1 Reviewed-on: https://go-review.googlesource.com/c/go/+/418094 Reviewed-by: Nooras Saba‎ <saba@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
2022-06-24cmd/go: add per-package indexing for modules outside mod cacheMichael Matloob
Packages outside the module cache including the standard library will be indexed individually rather than as a whole module. For #52876 Change-Id: I142dad6a790e9e8eb4dc6430a588fbfa86552e49 Reviewed-on: https://go-review.googlesource.com/c/go/+/413815 Reviewed-by: Michael Matloob <matloob@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-06-03cmd/go: changes to use modindexMichael Matloob
This CL makes the changes to actually use the module index when loading packages and instead of scanning their directories to see if they contain go files or to extract imports. Change-Id: I70106181cf64d6fd5a416644ba518b6b90030e0a Reviewed-on: https://go-review.googlesource.com/c/go/+/403778 Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org>
2022-05-06cmd/go: mod tidy returns proper error with /tmp/go.modtenkoh
`go mod tidy` results in panic due to nil pointer dereference with the current implementation. Though the panic occurs only in a limited situation described as below, we had better fix it. Situation: - go.mod is in the exactly system's temporary directory (i.e. temp root) - `go mod tidy` in temp root or in the child directory not having go.mod No go.mod are found in the situation (i.e. *modFile is nil), however, *modFile is referred without nil check. Although just adding nil check works well, the better solution is using ModFile() function. It works as same as the current implementation and, in addition, it has either nil check and user friendly error indication. With using it, users can get a proper error message like "go.mod file not found in current directory or any parent directory" instead of a panic. Fixes #51992 Change-Id: I2ba26762778acca6cd637c8eb8c615fb747063f4 Reviewed-on: https://go-review.googlesource.com/c/go/+/400554 Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: David Chase <drchase@google.com>
2022-05-04cmd/go: write changes to go.mod and go.sum after loading the ↵Bryan C. Mills
command-line-arguments package This entrypoint was missed in CL 349600, and the behavior happened not to be covered by existing tests. Fixes #52331. Change-Id: Iccf12e8e633215abe4bfa1c3ca2fe3a8391b5ba5 Reviewed-on: https://go-review.googlesource.com/c/go/+/401536 Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
2022-04-21cmd/go: add a better error message when in a module outside workspaceMichael Matloob
When the user is trying to list or build a package in a module that's outside of the workspace provide a more clear message hinting to the user that they can add the module to the workspace using go work use. Fixes #51604 Change-Id: I1202ecb2f22fd6351bfdec88ed613b8167687fb7 Reviewed-on: https://go-review.googlesource.com/c/go/+/400014 Run-TryBot: Michael Matloob <matloob@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> Auto-Submit: Michael Matloob <matloob@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-11all: gofmt main repoRuss Cox
[This CL is part of a sequence implementing the proposal #51082. The design doc is at https://go.dev/s/godocfmt-design.] Run the updated gofmt, which reformats doc comments, on the main repository. Vendored files are excluded. For #51082. Change-Id: I7332f099b60f716295fb34719c98c04eb1a85407 Reviewed-on: https://go-review.googlesource.com/c/go/+/384268 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-04-01all: remove trailing blank doc comment linesRuss Cox
A future change to gofmt will rewrite // Doc comment. // func f() to // Doc comment. func f() Apply that change preemptively to all doc comments. For #51082. Change-Id: I4023e16cfb0729b64a8590f071cd92f17343081d Reviewed-on: https://go-review.googlesource.com/c/go/+/384259 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-16cmd/go/internal/modload: set errors for packages with invalid import pathsBryan C. Mills
Prior to CL 339170, relative errors in module mode resulted in a base.Fatalf from the module loader, which caused unrecoverable errors from 'go list -e' but successfully rejected relative imports (which were never intended to work in module mode in the first place). After that CL, the base.Fatalf is no longer present, but some errors that had triggered that base.Fatalf were no longer diagnosed at all: the module loader left them for the package loader to report, and the package loader assumed that the module loader would report them. Since the module loader already knows that the paths are invalid, it now reports those errors itself. Fixes #51125 Change-Id: I70e5818cfcfeea0ac70e17274427b08a74fd7c13 Reviewed-on: https://go-review.googlesource.com/c/go/+/386176 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2022-02-10cmd/go: mention go.work when local path outside modules in go.workMichael Matloob
In workspace mode, if a user lists a package or patternthat's inside a module that's not listed in go.work, mention that the package or pattern is outside the modules listed in go.work so the user has a better idea of how to fix the issue. (Question: it's valid in those flows to add a pattern that points into the module cache. Should we expand the error to say "package outside modules listed in go.work file or contained in module cache"? That seems clunky (and is the uncommon case) which is why I didn't do so in this case, but it's possible) Fixes #49632 Change-Id: I3f0ea1b2f566d52a8079b58593fcc5cc095e7a41 Reviewed-on: https://go-review.googlesource.com/c/go/+/384236 Trust: Michael Matloob <matloob@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-12-13all: gofmt -w -r 'interface{} -> any' srcRuss Cox
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-12-01cmd/go/internal/modload: fix up main-module checks from CL 334932Bryan C. Mills
Some critical Version == "" checks were missing in mvs.go, causing mvs.Req to fail to retain requirements provided by older versions of main modules. A few checks also ought to be rotated to put the less expensive string-equality checks before the more expensive map lookups. Fixes #48511 Change-Id: Ib8de9d49a6413660792c003866bfcf9ab7f82ee2 Reviewed-on: https://go-review.googlesource.com/c/go/+/368136 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2021-11-09cmd/go: add go work sync commandMichael Matloob
Change-Id: I09b22f05035700e1ed90bd066ee8f77c3913286a Reviewed-on: https://go-review.googlesource.com/c/go/+/358540 Trust: Michael Matloob <matloob@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-11-09cmd/go: add workspace pruning modeMichael Matloob
[ this is a roll-forward of golang.org/cl/357169 with minor changes to fix the cmd/go/internal/modload tests: because they don't run the go command, some initialization isn't run on the test and modroots is empty in cases it can't be when the full command setup is done. So directly check for workFilePath != "" instead of calling inWorkspaceMode which checks that Init is called first, and check that modRoots is non empty when calling mustGetSingleMainModule.] This change corrects a bug in the handling of module loading of workspaces. Namely, there is an assumption by the module pruning code that if a root module is selected then the packages of that module can be resolved without loading the whole module graph. This is not true in workspace mode because two workspace modules can require different versions of a dependency. Worse, one workspace module can directly require a depencency that is transitively required by another workspace module, changing the version of that module loaded in the fully expanded graph. To correct this, a new 'workspace' pruning mode is added where the roots are the workspace modules themselves, satisfying the assumption made by the module pruning logic. The rest of this change accounts for the new pruning mode where it's used and correctly sets the requirements in this pruning mode. Change-Id: I8bdf4b30f669c1ded0ed8a5dd202ac8d1939bbbd Reviewed-on: https://go-review.googlesource.com/c/go/+/362754 Trust: Michael Matloob <matloob@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2021-11-08Revert "cmd/go: add workspace pruning mode"Bryan C. Mills
This reverts CL 357169. Reason for revert: appears to be failing on longtest SlowBot.¹ ¹https://storage.googleapis.com/go-build-log/a97c855b/linux-amd64-longtest_7c9857d4.log Change-Id: I3b94395671db78ed5fb2fb1019e7199e4ffbd272 Reviewed-on: https://go-review.googlesource.com/c/go/+/362249 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Michael Matloob <matloob@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
2021-11-08cmd/go: add workspace pruning modeMichael Matloob
This change corrects a bug in the handling of module loading of workspaces. Namely, there is an assumption by the module pruning code that if a root module is selected then the packages of that module can be resolved without loading the whole module graph. This is not true in workspace mode because two workspace modules can require different versions of a dependency. Worse, one workspace module can directly require a depencency that is transitively required by another workspace module, changing the version of that module loaded in the fully expanded graph. To correct this, a new 'workspace' pruning mode is added where the roots are the workspace modules themselves, satisfying the assumption made by the module pruning logic. The rest of this change accounts for the new pruning mode where it's used and correctly sets the requirements in this pruning mode. Change-Id: I5d4d9877e492e196681f6ee9f8f18a08b4e95c61 Reviewed-on: https://go-review.googlesource.com/c/go/+/357169 Trust: Michael Matloob <matloob@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-10-27cmd: move internal/str back to cmd/goRuss Cox
cmd/go is not subject to all the same restrictions as most of cmd. In particular it need not be buildable with the bootstrap toolchain. So it is better to keep as little code shared between cmd/go and cmd/compile, cmd/link, cmd/cgo as possible. cmd/internal/str started as cmd/go/internal/str but was moved to cmd/internal in order to make use of the quoted string code. Move that code to cmd/internal/quoted and then move the rest of cmd/internal/str back to cmd/go/internal/str. Change-Id: I3a98f754d545cc3af7e9a32c2b77a5a035ea7b9a Reviewed-on: https://go-review.googlesource.com/c/go/+/355010 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>