aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/init.go
AgeCommit message (Collapse)Author
2021-08-09cmd/go: with -mod=vendor, don't panic if there are duplicate requirementsJay Conrod
In loadModFile with -mod=vendor, load the vendor list and use it to initialize the module graph before calling updateRoots. In updateLazyRoots with any mode other than "mod", return the original *Requirements if no roots needed to be upgraded, even if there are inconsistencies. This means 'go list -m -mod=readonly' and -mod=vendor may succeed if there are duplicate requirements or requirements on versions of the main module. Fixes #47565 Change-Id: I4640dffc4a7359367cc910da0d29e3538bfd1ca4 Reviewed-on: https://go-review.googlesource.com/c/go/+/340252 Trust: Jay Conrod <jayconrod@google.com> Trust: Bryan C. Mills <bcmills@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-07-07cmd/go: don't lock .mod and .sum files for read in overlayJay Conrod
On Plan 9, locking a file requires a chmod call. In general, the go command should not modify files in the overlay, even metadata. With this change, we won't lock these files for reading. The go command already reported errors when attempting to write these files if they were in the overlay, but this change moves those checks to the point of access for clearer error messages. cmd/go/internal/lockedfile no longer imports cmd/go/internal/fsys. Fixes #44700 Change-Id: Ib544459dd6cf56ca0f7a27b3285f045f08040d7e Reviewed-on: https://go-review.googlesource.com/c/go/+/333012 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-07-07cmd/go/internal/modload: fix an apparent typo in the AutoRoot commentBryan C. Mills
Updates #40276 Change-Id: Ic192d51f9f0306e5c206c550ef02f6d4495d0851 Reviewed-on: https://go-review.googlesource.com/c/go/+/332569 Trust: Bryan C. Mills <bcmills@google.com> Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-06-16cmd/go: in lazy modules, add transitive imports for 'go get' argumentsBryan C. Mills
I needed to also update TestScript/mod_sumdb_golang. It had been relying on 'go list -mod=mod' to add both the go.mod and go.sum entries for the named package, but when 'go get' actually adds all of the needed dependencies, lazy loading kicks in and 'go list' doesn't end up needing the checksums for go.mod files. We didn't detect the skew before because the 'go list' command was (unexpectedly) also adding the missing dependencies, which triggered a deep scan of the complete module graph. For #45979 Change-Id: Ica917dee22c83ffa71c6ad0f2e189f911b73edf4 Reviewed-on: https://go-review.googlesource.com/c/go/+/328231 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
2021-06-08cmd/go: in Go 1.17+ modules, add indirect go.mod dependencies separately ↵Bryan C. Mills
from direct ones Fixes #45965 Change-Id: If5c0d7b29e9f81be0763f3fa68051d4ef5419990 Reviewed-on: https://go-review.googlesource.com/c/go/+/325922 Trust: Bryan C. Mills <bcmills@google.com> Reviewed-by: Michael Matloob <matloob@golang.org>
2021-05-27cmd/go: don't let 'go mod download' save sums for inconsistent requirementsJay Conrod
'go mod download' calls modload.LoadModFile early to find the main module path in order to validate arguments. LoadModFile may write go.mod and go.sum to fix formatting and add a go directive. This calls keepSums, which, in eager mode, loaded the complete module graph in order to find out what sums are needed to load the complete module graph. If go.mod requires a lower version of a module than will be selected later, keepSums causes the sum for that version's go.mod to be retained, even though it isn't needed later after a consistent go.mod is written. This CL fixes keepSums not to load the graph if it hasn't already been loaded (whether eager or lazy), addressing comments from CL 318629. For #45332 Change-Id: I20d4404004e4ad335450fd0fd753e7bc0060f702 Reviewed-on: https://go-review.googlesource.com/c/go/+/322369 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2021-05-25cmd/go: add a -compat flag to 'go mod tidy'Bryan C. Mills
Fixes #46141 Change-Id: I9d4032e75252ade9eaa937389ea97ef3fb287499 Reviewed-on: https://go-review.googlesource.com/c/go/+/321071 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-05-24cmd/go: align checks of module path during initialization.Constantin Konstantinidis
Fixes #45025. Change-Id: I70c2b745f764484e4b3a2824adc470f168fb2c50 Reviewed-on: https://go-review.googlesource.com/c/go/+/320310 Trust: Jay Conrod <jayconrod@google.com> Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2021-05-24cmd/go/internal/modcmd: factor out a type for flags whose arguments are Go ↵Bryan C. Mills
versions For #46141 Updates #45094 Change-Id: I6553600c69273762a81795ef021c66f4e0872b6b Reviewed-on: https://go-review.googlesource.com/c/go/+/321069 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-05-05cmd/go: don't crash when running "go version" in deleted directoryPhilipp Sauter
If the go command is executed on Linux in a deleted directory, it fails. This behavior is reasonable for commands which depend on the CWD, but it's unexpected for commands like `go version`. This change delays initialization of a global CWD variable. Fixed #34499 Change-Id: I7302fb84a3b7f5f149a123d277abd5b9b5bc95b2 Reviewed-on: https://go-review.googlesource.com/c/go/+/268261 Reviewed-by: Bryan C. Mills <bcmills@google.com> Trust: Bryan C. Mills <bcmills@google.com> Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2021-05-04cmd/go: suppress SSH password prompts when fetching modules or reposBryan C. Mills
We were already setting GIT_SSH_COMMAND (if unset) to explicitly include 'ControlMaster=no' in order to disable connection pooling. Now we also set 'BatchMode=yes' to suppress password prompts for password-protected keys. While we're here, we also set GCM_INTERACTIVE=never to suppress similar prompts from the Git Credential Manager for Windows. Fixes #44904 Change-Id: Iebb050079ff7dd54d5b944c459ae212e9e6f2579 Reviewed-on: https://go-review.googlesource.com/c/go/+/300157 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-04-30cmd/go: smooth out upgrade paths for lazy loadingBryan C. Mills
This change adds two possible upgrade paths for lazy loading: 1. Run 'go mod tidy -go=1.17'. 2. Starting in a module with no existing 'go' directive, run any 'go' command that updates the go.mod file. In the latter case, commands other than 'go mod tidy' may leave the go.mod file *very* untidy if it had non-trivial dependencies. (The 'go' invocation will promote all implicit eager dependencies to explicit lazy ones, which preserves the original module graph — most of which is not actually relevant.) 'go mod tidy -go=1.17' can be used to enable lazy loading without accidentally downgrading existing transitive dependencies. 'go mod tidy -go=1.16' can be used to disable lazy loading and clear away redundant roots in a single step (if reducing the go version), or to prune away dependencies of tests-of-external-tests (if increasing the go version). 'go mod tidy -go=1.15' can be used to add dependencies of tests-of-external-tests, although there isn't much point to that. DO NOT MERGE This change still needs an explicit test and a release note. Fixes #45094 For #36460 Change-Id: I68f057e39489dfd6a667cd11dc1e320c1ee1aec1 Reviewed-on: https://go-review.googlesource.com/c/go/+/315210 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
2021-04-30cmd/go/internal/modload: avoid loading the full module graph to determine ↵Bryan C. Mills
which checksums to add to go.sum For #36460 Change-Id: I606314054bd9064f7c4053f56049fabbaec54143 Reviewed-on: https://go-review.googlesource.com/c/go/+/309189 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com> Reviewed-by: Michael Matloob <matloob@golang.org>
2021-04-30cmd/go/internal/modload: avoid loading the full module graph for imports ↵Bryan C. Mills
satisfied by lazy roots For #36460 Change-Id: Ibdbaa893ded772617e22f12db7a0463604db5195 Reviewed-on: https://go-review.googlesource.com/c/go/+/308516 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
2021-04-30cmd/go/internal/modload: implement lazy loadingBryan C. Mills
For #36460 Updates #41297 Change-Id: I1b82176a45df499e52f1a3a0ffe23eab2a1ca86e Reviewed-on: https://go-review.googlesource.com/c/go/+/265777 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
2021-04-27cmd/go/internal/modload: treat \ as a path separator instead of a shell ↵SataQiu
special character According to the code comment, \ should be treated as a path separator. See fileNameOK in golang.org/x/mod/module/module.go. Change-Id: I05e05246005191ecccfecf46848aba5cb1359956 Reviewed-on: https://go-review.googlesource.com/c/go/+/310429 Reviewed-by: Bryan C. Mills <bcmills@google.com> Trust: Robert Findley <rfindley@google.com>
2021-04-21cmd/go/internal/modload: use updateRequirements instead of editRequirements ↵Bryan C. Mills
to add modules for missing packages editRequirements does a lot of work in order to respect the upper bounds of mustSelect, and as a result it doesn't provide many promises about conserving other things (like root dependencies). When we add modules for missing packages, we aren't dealing with upper bounds at all, so we would rather avoid the upper-bound overhead and preserve the root-dependency invariants instead. (*loader).updateRequirements does exactly that; it just needs to be told about the additional dependencies to add. For #36460 Change-Id: Ie0f2bc0dde18026bbd23e51357bb1d725d201680 Reviewed-on: https://go-review.googlesource.com/c/go/+/310791 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-04-21cmd/go/internal/modload: split updateRoots into separate functions for ↵Bryan C. Mills
updating and tidying In CL 293689, I fused the mvs.Reqs calls that were formerly in MinReqs and TidyBuildList into a single function, updateRoots, in the hope that it expressed a fundamental operation. As I have been working on the lazy equivalents, I have come to realize that these functions are deeply related but fundamentally different. In order to help me reason about the two different roles, I am making the two functions separate once more, but leaving them colocated in the code. For #36460 Change-Id: I851d6d81fbfd84f39411e0d076ee72a9909c60ee Reviewed-on: https://go-review.googlesource.com/c/go/+/310629 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-04-21cmd/go: make Tidy an option in PackageOpts rather than a separate callBryan C. Mills
This eliminates some awkwardly-stateful outside calls to modload.{Disallow,Allow,}WriteGoMod. Perhaps more importantly, it gives the loader the opportunity to reload packages and revise dependencies after the tidied requirements are computed. With lazy loading, dropping an irrelevant requirement from the main module's go.mod file may (rarely) cause other test dependencies for packages outside the main module to become unresolved, which may require the loader to re-resolve those dependencies, which may in turn add new roots and increase the selected versions of modules providing other packages. This refactoring allows the loader to iterate between tidying the build list and reloading packages as needed, making the exact sequencing of loading and tidying an implementation detail of the modload package. For #36460 For #40775 Change-Id: Ib6da3672f32153d5bd7d653d85e3672ab96cbe36 Reviewed-on: https://go-review.googlesource.com/c/go/+/310181 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-04-16cmd/go/internal/modload: when outside a module, set cfg.BuildMod based on ↵Bryan C. Mills
allowMissingModuleImports For #36460 Change-Id: I50c7018a6841bba1a8c6f8f8eca150df1f685526 Reviewed-on: https://go-review.googlesource.com/c/go/+/310789 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-04-15cmd/go/internal/modconv: involve GOPROXY in ConvertLegacyConfigAofei Sheng
Fixes #33767 Change-Id: Ia2d6dd32bcb0e142f59346232b3b1aa3babb034a Reviewed-on: https://go-review.googlesource.com/c/go/+/306809 Trust: Jay Conrod <jayconrod@google.com> Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Aofei Sheng <aofei@aofeisheng.com> Reviewed-by: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2021-04-14cmd/go/internal/modload: fix truncated error message from goModDirtyErrorBryan C. Mills
The 'go mod tidy' hint was truncated due to a typo in CL 293689, and that particular case was not covered by any existing test. Updates #36460 Updates #40775 Change-Id: Ib6fa872a9dfdafc4e9a112e8add2ff5aecd2dbd0 Reviewed-on: https://go-review.googlesource.com/c/go/+/310089 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2021-04-08cmd/go/internal/modload: add a dormant depth typeBryan C. Mills
This change adds the depth constants 'lazy' and 'eager', but leaves the go117EnableLazyLoading constant set to false so that the depth in effect is still always 'eager'. The go117EnableLazyLoading constant can be toggled to true once the module loader has been updated to maintain the lazy-loading invariants in the go.mod file. In the meantime, this will allow me to progressively replace uses of go117LazyTODO with real conditions and locally toggle lazy-mode on to see which tests are still failing (or which behaviors are missing test coverage). For #36460 Change-Id: Ifd358265a3903a5000003c2072f28171f336e15c Reviewed-on: https://go-review.googlesource.com/c/go/+/308515 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com> Reviewed-by: Michael Matloob <matloob@golang.org>
2021-04-08cmd/go: assume Go 1.16 semantics uniformly for unversioned modulesBryan C. Mills
However, still only trigger -mod=vendor automatically (and only apply the more stringent Go 1.14 vendor consistency checks) if the 'go' version is explicit. This provides maximal compatibility with Go 1.16 and earlier: Go 1.11 modules will continue not to fail vendor consistency checks, but scripts that assume semantics up to Go 1.16 for unversioned modules will continue to work unmodified. Fixes #44976 For #36460 Change-Id: Idb05ca320023f57249c71fc8079218e8991d1ff9 Reviewed-on: https://go-review.googlesource.com/c/go/+/308509 Trust: Bryan C. Mills <bcmills@google.com> Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-03-25cmd/go/internal/modload: replace the global buildList with structured ↵Bryan C. Mills
requirements This is intended to be a pure-refactoring change, with very little observable change in the behavior of the 'go' command. A few error messages have prefixes changed (by virtue of being attached to packages or modules instead of the build list overall), and 'go list -m' (without arguments) no longer loads the complete module graph in order to provide the name of the (local) main module. The previous modload.buildList variable contained a flattened build list, from which the go.mod file was reconstructed using various heuristics and metadata cobbled together from the original go.mod file, the package loader (which was occasionally constructed without actually loading packages, for the sole purpose of populating otherwise-unrelated metadata!), and the updated build list. This change replaces that variable with a new package-level variable, named "requirements". The new variable is structured to match the structure of the go.mod file: it explicitly specifies the roots of the module graph, from which the complete module graph and complete build list can be reconstructed (and cached) on demand. Similarly, the "direct" markings on the go.mod requirements are now stored alongside the requirements themselves, rather than side-channeled through the loader. The requirements are now plumbed explicitly though the modload package, with accesses to the package-level variable occurring only within top-level exported functions. The structured requirements are logically immutable, so a new copy of the requirements is constructed whenever the requirements are changed, substantially reducing implicit communication-by-sharing in the package. For #36460 Updates #40775 Change-Id: I97bb0381708f9d3e42af385b5c88a7038e1f0556 Reviewed-on: https://go-review.googlesource.com/c/go/+/293689 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
2021-03-19cmd/go: assume Go 1.16 instead of Go 1.11 for dependencies that lack ↵Bryan C. Mills
explicit 'go' directives Fixes #45109 Updates #44976 Updates #36876 Change-Id: Icb00f8b6e0d4e076d82da1697e7058b9e7603916 Reviewed-on: https://go-review.googlesource.com/c/go/+/303229 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-03-17cmd/go: only add a 'go' directive to the main module when the go.mod file ↵Bryan C. Mills
will be written Then, write the 'go.mod' file with that version before further processing. That way, if the command errors out due to a change in behavior, the reason for the change in behavior will be visible in the file diffs. If the 'go.mod' file cannot be written (due to -mod=readonly or -mod=vendor), assume Go 1.11 instead of the current Go release. (cmd/go has added 'go' directives automatically, including in 'go mod init', since Go 1.12.) For #44976 Change-Id: If9d4af557366f134f40ce4c5638688ba3bab8380 Reviewed-on: https://go-review.googlesource.com/c/go/+/302051 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com> Reviewed-by: Michael Matloob <matloob@golang.org>
2021-03-04cmd/go: clarify errors for commands run outside a moduleJay Conrod
The new error message tells the user what was wrong (no go.mod found) and directs them to 'go help modules', which links to tutorials. Fixes #44745 Change-Id: I98f31fec4a8757eb1792b45491519da4c552cb0f Reviewed-on: https://go-review.googlesource.com/c/go/+/298650 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-03-01cmd/go/internal/modload: don't query when fixing canonical versionsJay Conrod
If a canonical version is passed to fixVersion when loading the main go.mod and that version don't match the module path's major version suffix, don't call Query. Query doesn't return a useful error in this case when the path is malformed, for example, when it doens't have a dot in the first path element. It's better to report the major version mismatch error. Fixes #44494 Change-Id: I97b1f64aee894fa0db6fb637aa03a51357ee782c Reviewed-on: https://go-review.googlesource.com/c/go/+/296590 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-01-08cmd/go: make hints in error messages more consistentJay Conrod
* All commands the user can run to fix the problem now appear alone on a separate line after a tab. * Removed -d from 'go get' commands. * Replaced 'go mod tidy' with 'go mod download $modpath' when a package might be provided by a module missing a sum. * Errors about 'path@version' syntax are more explicit. Fixes #29415 Fixes #42087 Fixes #43430 Fixes #43523 Change-Id: I4427c2c4506a727a2c727d652fd2d506bb134d3b Reviewed-on: https://go-review.googlesource.com/c/go/+/282121 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-01-08cmd/go: preserve sums for indirect deps fetched by 'go mod download'Jay Conrod
Previously, commands that wrote go.sum (except 'go mod tidy') would retain sums for zip files of directly required modules. Sums of indirect dependencies wouldn't be retained unless they were used to load packages. With this change, sums for indirect dependencies will be retained if they're available. This allows users to add missing sums with 'go mod download example.com/mod', which previously only worked for directly required modules. Note that 'go mod download' without arguments now adds sums for every module in the build list. That matches 1.15 behavior. For #41103 Change-Id: I4cce2bf1c73578dae836bdb5adb32da071554f1a Reviewed-on: https://go-review.googlesource.com/c/go/+/282692 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-01-06cmd/go: make module suggestion more friendlyBaokun Lee
We are trying to avoid by not automatically updating go.mod. The suggestion should be that users actually add the dependencies they need, and the command in an easily copy-pastable form now. Fixes: #43430 Change-Id: I2227dab498fcd8d66184c94ebe9e776629ccadfd Reviewed-on: https://go-review.googlesource.com/c/go/+/280713 Run-TryBot: Baokun Lee <bk@golangcn.org> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com> Trust: Jay Conrod <jayconrod@google.com> Trust: Bryan C. Mills <bcmills@google.com>
2021-01-05cmd/go: set cfg.BuildMod to "readonly" by default with no module rootJay Conrod
modload.Init now sets the default value for -mod if it wasn't set explicitly. This happens before go.mod is loaded, so modload.LoadModFile sets the default value again in order to enable automatic vendoring. Previously, cfg.BuildMod wasn't set at all if LoadModFile wasn't called, as is the case for commands that run outside of a module root. This problem only affected 'go install pkg@version' since other commands are either forbidden in module mode or run with -mod=mod (like 'go get' and 'go mod' subcommands). This change also suppresses "missing sum" errors when -mod=readonly is enabled and there is no module root. Fixes #43278 Related #40278 Change-Id: I6071cc42bc5e24d0d7e84556e5bfd8e368e0019d Reviewed-on: https://go-review.googlesource.com/c/go/+/279490 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-12-23cmd/go: in 'go get', promote named implicit dependencies to explicitJay Conrod
'go get pkg@vers' will now add an explicit requirement for the module providing pkg if that version was already indirectly required. 'go get mod@vers' will do the same if mod is a module path but not a package. Requirements promoted this way will be marked "// indirect" because 'go get' doesn't know whether they're needed to build packages in the main module. So users should prefer to run 'go get ./pkg' (where ./pkg is a package in the main module) to promote requirements. Fixes #43131 Change-Id: Ifbb65b71274b3cc752a7a593d6ddd875f7de23b8 Reviewed-on: https://go-review.googlesource.com/c/go/+/278812 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-12-09all: update to use os.ReadDir where appropriateRuss Cox
os.ReadDir is a replacement for ioutil.ReadDir that returns a slice of fs.DirEntry instead of fs.FileInfo, meaning it is the more efficient form. This CL updates call sites throughout the Go source tree wherever possible. As usual, code built using the Go 1.4 bootstrap toolchain is not included. There is also a use in go/build that appears in the public API and can't be changed, at least not without additional changes. Fixes #42026. Change-Id: Icfc9dd52c6045020f6830e22c72128499462d561 Reviewed-on: https://go-review.googlesource.com/c/go/+/266366 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-12-09all: update to use os.ReadFile, os.WriteFile, os.CreateTemp, os.MkdirTempRuss Cox
As part of #42026, these helpers from io/ioutil were moved to os. (ioutil.TempFile and TempDir became os.CreateTemp and MkdirTemp.) Update the Go tree to use the preferred names. As usual, code compiled with the Go 1.4 bootstrap toolchain and code vendored from other sources is excluded. ReadDir changes are in a separate CL, because they are not a simple search and replace. For #42026. Change-Id: If318df0216d57e95ea0c4093b89f65e5b0ababb3 Reviewed-on: https://go-review.googlesource.com/c/go/+/266365 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-11-30cmd/go: fix infinite loop in modload.keepSumsJay Conrod
Fixes #42891 Change-Id: I0cce4204a1c4959b896188a2ab3719c0507f95e6 Reviewed-on: https://go-review.googlesource.com/c/go/+/274172 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Trust: Jay Conrod <jayconrod@google.com>
2020-11-21cmd/go/internal/modload: remove the Reqs functionBryan C. Mills
The Reqs function returns an mvs.Reqs implemention for the global build list. The API that it presents assumes that the build list is globally consistent (problematic for #40775) and readily available (problematic for #36460). Fortunately, it is no longer used outside of the modload package. We can instead use individual instances of the unexported mvsReqs struct, making the dependency on the global build list more explicit. For #36460 For #40775 Change-Id: I8674442f2a86416b0bf9c3395cb591c1e724c9d2 Reviewed-on: https://go-review.googlesource.com/c/go/+/272129 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
2020-11-20cmd/go: support overlaying go.mod filesMichael Matloob
This change updates the lockedfile package to open files using the new fsys.OpenFile function. The logic of fsys.Open has been moved into fsys.OpenFile, and fsys.Open is now just a light wrapper around it. For #39958 Change-Id: I552f1a45ac00ac06b5812008d17a61e610b4b113 Reviewed-on: https://go-review.googlesource.com/c/go/+/266797 Trust: Michael Matloob <matloob@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-10-23cmd/go: save sums for zips needed to diagnose ambiguous importsJay Conrod
Previously, we would retain entries in go.sum for .mod files in the module graph (reachable from the main module) and for .zip files of modules providing packages. This isn't quite enough: when we load a package, we need the content of each module in the build list that *could* provide the package (that is, each module whose path is a prefix of the package's path) so we can diagnose ambiguous imports. For #33008 Change-Id: I0b4d9d68c1f4ca382f0983a3a7e537764f35c3aa Reviewed-on: https://go-review.googlesource.com/c/go/+/262781 Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Trust: Jay Conrod <jayconrod@google.com>
2020-10-23cmd/go: in 'go mod init', suggest running 'go mod tidy'Jay Conrod
When 'go mod init' is run in an existing project, it may import requirements from a vendor configuration file, but the requirements may not be complete, and go.sum won't contain sums for module zips. With -mod=readonly, the next build command is likely to fail. 'go mod init' will now suggest running 'go mod tidy' if there are .go files or subdirectories in the current directory. We could potentially run 'go mod tidy' automatically within 'go mod init', but it seems better to guide users to using 'go mod tidy' as a separate command to fix missing dependencies. For #41712 Updates #40278 Change-Id: Iaece607f291244588a732ef4c5d576108965ca91 Reviewed-on: https://go-review.googlesource.com/c/go/+/264622 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-10-23cmd/go: refactor modload.InitModJay Conrod
InitMod is split into two functions. LoadModFile parses an existing go.mod file and loads the build list (or checks vendor/modules.txt for consistency in vendor mode). CreateModFile creates a new go.mod file, possibly inferring the module path and importing a vendor configuration file. Some logic is moved from runInit to CreateModFile. init-specific logic is removed from other functions. This CL shouldn't cause substantial differences in behavior, though some error messages are slightly different. For #41712 Change-Id: Ia684945cfcf5beca30bbb81e7144fc246c4f27ed Reviewed-on: https://go-review.googlesource.com/c/go/+/264621 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-10-23cmd/go: don't import requirements into existing go.mod filesJay Conrod
Previously, if a go.mod file was present, and it only contained a module directive, any module-aware command would attempt to import requirements from a vendor configuration file like Gopkg.lock. This CL removes that functionality. It was undocumented and untested, and it can cause problems with -mod=readonly. It should never come up for go.mod files created with 'go mod init', since they have a "go" directive. For #40278 Change-Id: I64c0d67d204560aa5c775d29553883d094fd3b72 Reviewed-on: https://go-review.googlesource.com/c/go/+/264620 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2020-10-20cmd/go/internal/modload: remove printStackInDie functionalityJay Conrod
Previously, when running cmd/go tests, if the module root directory is requested when modules are explicitly disabled, we printed a stack trace in addition to the error message that's normally printed. The stack trace isn't that useful, and it makes the actual error hard to find. Change-Id: I8230d668f3f16659f08d0d685124c41b4055c5b9 Reviewed-on: https://go-review.googlesource.com/c/go/+/263659 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-10-06cmd/go: add basic support for overlaysMichael Matloob
This CL adds basic support for listing packages with overlays. The new cmd/go/internal/fs package adds an abstraction for communicating with the file system that will open files according to their overlaid paths, and provides functions to override those in the build context to open overlaid files. There is also some support for executing builds on packages with overlays. In cmd/go/internal/work.(*Builder).build, paths are mapped to their overlaid paths before they are given as arguments to tools. For #39958 Change-Id: I5ec0eb9ebbca303e2f1e7dbe22ec32613bc1fd17 Reviewed-on: https://go-review.googlesource.com/c/go/+/253747 Trust: Michael Matloob <matloob@golang.org> Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-09-30cmd/go: error if -modfile used with 'go install pkg@version'Jay Conrod
'go install pkg@version' runs without a main module or a module root directory. The -modfile flag cannot be used to set the module root directory or to substitute a different go.mod file. This error won't be reported if -modfile is set in GOFLAGS. Unsupported flags there are generally ignored. For #40276 Change-Id: I0b39b1fa9184c15c6e863b647d43c328710920f4 Reviewed-on: https://go-review.googlesource.com/c/go/+/258297 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2020-09-22cmd/go/internal/modget: consolidate Load entrypointsBryan C. Mills
This change replaces ImportPaths, ImportPathsQuiet, LoadALL, and LoadVendor with a single LoadPackages function, with a LoadOpts struct that more clearly documents the variations in behavior. It also eliminates the cmd/go/internal/load.ImportPaths function, which was undocumented and had only one call site (within its own package). The modload.LoadTests global variable is subsumed by a field in the new LoadOpts struct, and is no longer needed for callers that invoke LoadPackages directly. It has been (temporarily) replaced with a similar global variable, load.ModResolveTests, which can itself be converted to an explicit, local argument. For #37438 For #36460 Updates #40775 Fixes #26977 Change-Id: I4fb6086c01b04de829d98875db19cf0118d40f8c Reviewed-on: https://go-review.googlesource.com/c/go/+/255938 Trust: Bryan C. Mills <bcmills@google.com> Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
2020-09-21cmd/go: default to GO111MODULE=onJay Conrod
Fixes #41330 Change-Id: Ib66087ac5e1eb827694915f21c32c4d88e1b9a7e Reviewed-on: https://go-review.googlesource.com/c/go/+/255052 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Trust: Jay Conrod <jayconrod@google.com> Trust: Bryan C. Mills <bcmills@google.com>
2020-09-18cmd/go: fix review comments in load, modloadJay Conrod
Follow-up to CL 255719, fixing review comments. Change-Id: I26d3cc622496c3902c6924cf2b746c50705c4d50 Reviewed-on: https://go-review.googlesource.com/c/go/+/255937 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-09-17cmd/go: flip relationship between load and modloadJay Conrod
Previously, modload imported load, but it mainly just did so in order to install callbacks to the modload API. This was important during vgo development, but there's no longer a strong reason to do this. Nothing modload imports strongly depends on load, so there's little danger of a dependency cycle. This change deletes the callbacks in load and instead, makes load call exported functions in modload directly. In the future, these functions may have different signatures than their GOPATH counterparts. Change-Id: Ifde5c3ffebd190b5bd184924ec447d272b936f27 Reviewed-on: https://go-review.googlesource.com/c/go/+/255719 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>