aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/get/get.go
AgeCommit message (Collapse)Author
2021-07-30[dev.cmdgo] cmd/internal/str: move package from cmd/go/internal/strJay Conrod
This will let cmd/cgo and cmd/link use this package for argument parsing. For golang/go#41400 Change-Id: I12ee21151bf3f00f3e8d427faaaab2453c823117 Reviewed-on: https://go-review.googlesource.com/c/go/+/334730 Trust: Jay Conrod <jayconrod@google.com> Reviewed-by: Michael Matloob <matloob@golang.org>
2021-07-22[dev.cmdgo] cmd/go: replace Target with MainModules, allowing for multiple ↵Michael Matloob
targets This change replaces the Target variable that represents the main module and the pathPrefix and inGorootSrc which provide other information about the main module with a single MainModules value that represents multiple main modules and holds their path prefixes, module roots, and whether they are in GOROOT/src. In cases where the code checks Target or its previously associated variables, the code now checks or iterates over MainModules. In some cases, the code still assumes a single main module by calling MainModules.MustGetSingleMainModule. Some of those cases are correct: for instance, there is always only one main module for mod=vendor. Other cases are accompanied with TODOs and will have to be fixed in future CLs to properly support multiple main modules. This CL (and other cls on top of it) are planned to be checked into a branch to allow for those evaluating the workspaces proposal to try it hands on. For #45713 Change-Id: I3b699e1d5cad8c76d62dc567b8460de8c73a87ea Reviewed-on: https://go-review.googlesource.com/c/go/+/334932 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>
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-16cmd/go/internal/load: convert two global flags to an options structJay Conrod
PackageOpts is a new struct type accepted by package loading functions. It initially has two fields: IgnoreImports, and ModResolveTests. Previously, these were global variables set by clients. We'll add more to this in the future. For #40775 Change-Id: I6956e56502de836d3815ce788bdf16fc5f3e5338 Reviewed-on: https://go-review.googlesource.com/c/go/+/310669 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-02cmd/go: remove -insecure flag on go getwitchard
Resolves #37519 Change-Id: Iba675a180b0e61b12835cdb6ecd4c6dc61e0605c GitHub-Last-Rev: aa018af6f8fc7f0b829820e831ad96734adcb8d0 GitHub-Pull-Request: golang/go#44724 Reviewed-on: https://go-review.googlesource.com/c/go/+/297709 Trust: Jay Conrod <jayconrod@google.com> Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-03-01cmd: upgrade golang.org/x/mod to relax import path checkJay Conrod
This incorporates CL 297089, which allows leading dots in import path elements but not module path elements. Also added a test. Fixes #43985 Updates #34992 Change-Id: I2d5faabd8f7b23a7943d3f3ccb6707ab5dc2ce3c Reviewed-on: https://go-review.googlesource.com/c/go/+/297530 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>
2020-12-14cmd/go: refactor error reporting in internal/loadJay Conrod
Replaced load.PackagesForBuild with a new function, load.CheckPackageErrors. Callers should now call PackagesAndErrors, then CheckPackageErrors for the same functionality. Removed load.Packages. Callers should call base.Errorf and filter the package list as needed. This gives callers more flexibility in handling package load errors. For #42638 Change-Id: Id75463ba695adc1ca3f8693ceb2c8978b74a3500 Reviewed-on: https://go-review.googlesource.com/c/go/+/277354 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-10-06cmd/go/internal/get: improve -insecure deprecation docswitchard
Updates #37519 Change-Id: I212607f1839b729d7da24b1258e56997b13ad830 GitHub-Last-Rev: db6d3c835bdf867a0b18f115276210e3a05902ed GitHub-Pull-Request: golang/go#41613 Reviewed-on: https://go-review.googlesource.com/c/go/+/257157 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Jay Conrod <jayconrod@google.com> Trust: Bryan C. Mills <bcmills@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Jay Conrod <jayconrod@google.com>
2020-09-21cmd/go/internal/get: warn about -insecure deprecationwitchard
Adds deprecation warning for -insecure flag on go get in both modules and GOPATH mode. Updates #37519. Change-Id: Ie2efeeb4a91e6dda92955295969e9715314ae50e GitHub-Last-Rev: a9ebe21fe067baa12391ad4f9357d8e5b0cf7051 GitHub-Pull-Request: golang/go#41497 Reviewed-on: https://go-review.googlesource.com/c/go/+/255882 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com> Trust: Michael Matloob <matloob@golang.org> Trust: Jay Conrod <jayconrod@google.com>
2020-09-11cmd/go: move repository resolution from internal/get to internal/vcsJay Conrod
This is a refactoring intended to break the dependency from internal/modfetch to internal/get. No change in functionality is intended. Change-Id: If51aba7139cc0b62ecc9ba454c055c99e8f36f0f Reviewed-on: https://go-review.googlesource.com/c/go/+/254364 Run-TryBot: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Michael Matloob <matloob@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-09-11cmd/go: move get.Insecure to cfg.Insecure to break dependency cycleJay Conrod
Change-Id: If9c73ff5adc7e080a48ecc6b35ce40822193d66f Reviewed-on: https://go-review.googlesource.com/c/go/+/254363 Run-TryBot: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Michael Matloob <matloob@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-09-01cmd/go/internal/get: add GOINSECURE supportwitchard
Adds support for the GOINSECURE environment variable to GOPATH mode. Updates #37519. Change-Id: Ibe3f52b7f30b1395edb000998905ee93abe6cada GitHub-Last-Rev: e298c0009eb5eba537bb00185a8778d2aab696ba GitHub-Pull-Request: golang/go#38628 Reviewed-on: https://go-review.googlesource.com/c/go/+/229758 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-09-01cmd/go/internal/get: disallow non-ASCII unicode letters from import pathsMichael Matloob
The copy of CheckImportPath in path.go and the regular expression for github repos in vcsPaths together allow import paths with unicode letters with import paths. These all come from github repos with non-ASCII unicode letters with paths in directories. This mainly shows up in GOPATH mode, but could also show up in Module mode when getting a module in GOPROXY=direct mode. We expect there to not be any significant affected users of this change-- an investingation of github repos that would produce import paths that would comply with the copy CheckImportPaths that's being removed, but not modload.CheckImportPaths only surfaced a handful of cases, all of which seemed to be small test or demonstation repos. But this CL is being submitted early in the cycle so that it can be backed out if need be. Updates #29101 Change-Id: I719df4af5b318e1330e90d8a0bffe5bb8d816f4f Reviewed-on: https://go-review.googlesource.com/c/go/+/251878 Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Jay Conrod <jayconrod@google.com>
2020-08-20cmd/go: do context propagation for tracing downloadsMichael Matloob
This change does context propagation (and only context propagation) necessary to add context to modfetch.Download and pkg.LoadImport. This was done by adding context to their callers, and then adding context to all call-sites, and then repeating adding context to callers of those enclosing functions and their callers until none were left. In some cases the call graph expansion was pruned by using context.TODOs. The next CL will add a span to Download. I kept it out of this change to avoid making it any larger (and harder to review) than it needs to be. Updates #38714 Change-Id: I7a03416e04a14ca71636d96f2c1bda2c4c30d348 Reviewed-on: https://go-review.googlesource.com/c/go/+/249021 Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
2020-08-18cmd/go: revert 3 CLs affecting par.Work, context propagation, tracingDmitri Shuralyov
This reverts the following changes: • cmd/go: add tracing for querying and downloading from the proxy CL 242786, commit 1a3558341860357c2400e37773e5076bb3a51628 • cmd/go: do context propagation for tracing downloads CL 248327, commit c0cf190d226cc3defb71d17c01d0b45bf49a8a85 • cmd/go/internal: remove some users of par.Work CL 248326, commit f30044a03bc7cf107dbec03c02fb6d0072878252 Reason for revert: broke linux 386 and amd64 longtest builders. The problem started with CL 248326, but CL 248327 and CL 242786 are reverted as well due to conflicts. Updates #38714. Fixes #40861. Change-Id: I68496b4e5a27e47a42183553c3a645b288edac83 Reviewed-on: https://go-review.googlesource.com/c/go/+/249017 Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-08-17cmd/go: do context propagation for tracing downloadsMichael Matloob
This change does context propagation (and only context propagation) necessary to add context to modfetch.Download and pkg.LoadImport. This was done by adding context to their callers, and then adding context to all call-sites, and then repeating adding context to callers of those enclosing functions and their callers until none were left. In some cases the call graph expansion was pruned by using context.TODOs. The next CL will add a span to Download. I kept it out of this change to avoid making it any larger (and harder to review) than it needs to be. Updates #38714 Change-Id: I5bf2d599aafef67334c384dfccd5e255198c85b4 Reviewed-on: https://go-review.googlesource.com/c/go/+/248327 Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-08-12cmd/go: propagate context into PackagesForBuild and Do for tracingMichael Matloob
This change propagates context into PackagesForErrors and Do for the purpose of tracing, and calls trace.StartSpan on PackagesForErrors and Do, so that the trace now shows the broad outline of where the "Loading" and "Execution" phases are in the build. Updates #38714 Change-Id: Ib9a7cf7030210f68f76663d1c8a7461e0a226611 Reviewed-on: https://go-review.googlesource.com/c/go/+/238541 Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-08-12cmd/go: add Context parameter to base.command.RunMichael Matloob
One small step to start propagating the context in cmd/go for tracing purposes. Updates #38714 Change-Id: Ibb6debeb9233f84d55f0e81244487355cbe7b82c Reviewed-on: https://go-review.googlesource.com/c/go/+/237684 Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-04-30cmd: disable *.go domains lookup in go get commandAnton Kuklin
Using 'go get x.go' instead of 'go build x.go' or some other go command is a common mistake. By that mistake, a user gets a misleading error message about unsuccessful `x.go` domain lookup. This improvement handles such cases, by validating, whether the argument hasn't specified version, has .go suffix, and either has no slashes or such file locally exists. Handled both GOPATH and GOMOD modes. Fixes #38478 Change-Id: I583a4ef7f7ca8901deb07ebc811e2b3c0e828fa6 Reviewed-on: https://go-review.googlesource.com/c/go/+/229938 Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Jay Conrod <jayconrod@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-02-28cmd/go: avoid matching wildcards rooted outside of available modulesBryan C. Mills
To avoid confusion, also distinguish between packages and dirs in search.Match results. No test because this is technically only a performance optimization: it would be very difficult to write such a test so that it would not be flaky. (However, tested the change manually.) Fixes #37521 Change-Id: I17b443699ce6a8f3a63805a7ef0be806f695a4b3 Reviewed-on: https://go-review.googlesource.com/c/go/+/221544 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
2020-02-28cmd/go/internal/search: consolidate package-pattern predicates into Match ↵Bryan C. Mills
methods This change consolidates predicates currently scattered throughout various parts of the package and module loader into methods on the search.Match type. That not only makes them more concise, but also encourages consistency, both in the code and in reasoning about the kinds of patterns that need to be handled. (For example, the IsLocal predicate was previously two different calls, either of which could be easily forgotten at a given call site.) Factored out from CL 185344 and CL 185345. Updates #32917 Change-Id: Ifa450ffaf6101f673e0ed69ced001a487d6f9335 Reviewed-on: https://go-review.googlesource.com/c/go/+/221458 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
2020-02-28cmd/go/internal/search: record errors in the Match structBryan C. Mills
Previously, we would either invoke base.Fatalf (which is too aggressive), or log.Print (which is too passive). Updates #32917 Change-Id: I5475e873e76948de7df65dca08bc0ce67a7fc827 Reviewed-on: https://go-review.googlesource.com/c/go/+/185344 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
2019-10-22cmd/go: support -modcacherw in 'go mod' subcommandsJay Conrod
The -modcacherw flag is now registered in work.AddModCommonFlags, which is called from work.AddBuildFlags, where it was registered before. 'go mod' subcommands register the flag by calling work.AddModCommonFlags directly. Also, build commands now exit with an error if -modcacherw is set explicitly (not in GOFLAGS) in GOPATH mode. Updates #31481 Change-Id: I461e59a51ed31b006fff4d5c57c2a866be0bbf38 Reviewed-on: https://go-review.googlesource.com/c/go/+/202563 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2019-10-09cmd/go: eliminate redundancy in import error messagesJay Conrod
This change introduces a new interface, load.ImportPathError. An error may satisfy this by providing an ImportPath method and including the import path in its error text. modload.ImportMissingError satisfies this interface. load.ImportErrorf also provides a convenient way to create an error satisfying this interface with an arbitrary message. When load.PackageError formats its error text, it may omit the last path on the import stack if the wrapped error satisfies ImportPathError and has a matching path. To make this work, PackageError.Err is now an error instead of a string. PackageError.MarshalJSON will write Err as a string for 'go list -json' output. When go/build.Import invokes 'go list' in module mode, it now runs with '-e' and includes '.Error' in the output format instead of expecting the error to be in the raw stderr text. If a package error is printed and a directory was not found, the error will be returned without extra decoration. Fixes #34752 Change-Id: I2d81dab7dec19e0ae9f51f6412bc9f30433a8596 Reviewed-on: https://go-review.googlesource.com/c/go/+/199840 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2019-10-04cmd/go: remove the -mod flag from 'go get'Bryan C. Mills
'GOFLAGS=-mod=vendor' currently causes 'go get' to always fail unless the '-mod' flag is explicitly overwritten. Moreover, as of CL 198319 we plan to set -mod=vendor by default if a vendor directory is present, so all users with vendor directories will be affected — not just those who set 'GOFLAGS' explicitly. Similarly, an explicit '-mod=readonly' argument to 'go get' is currently ignored as a special case, but the fact that it is ignored (rather than rejected) can be very surprising. Rather than adding more special cases, we should remove the '-mod' flag from 'go get' entirely. Fixes #30345 Fixes #32502 Updates #33848 Change-Id: Iecd3233ca3ef580ca3a66bd5e6ee8d86d4cbd8a7 Reviewed-on: https://go-review.googlesource.com/c/go/+/198438 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
2019-05-14cmd/go: default to GO111MODULE=auto and make it trigger in GOPATH/srcBryan C. Mills
Fixes #31857 Change-Id: Ib0b791376acb7ee1cdc163f808b8ecf77dbdaf06 Reviewed-on: https://go-review.googlesource.com/c/go/+/176580 Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Jay Conrod <jayconrod@google.com>
2019-04-23cmd/go/internal/web: merge internal/web2 into webBryan C. Mills
The cmd/go/internal/web package was forked in order to support direct HTTPS fetches from widely-used hosting providers,¹ but direct fetches were subsequently dropped in CL 107657. The forked web2 package, with its GitHub-specific diagnostics and .netrc support, remained in use for module proxy support, but was not used for the initial '?go-get=1' path resolution, so the .netrc file was only used to fetch from already-resolved module protocol servers. This CL moves the .netrc support into its own (new) package, cmd/go/internal/auth, and consolidates the web and web2 packages back into just web. As a result, fetches via the web package now support .netrc, and fetches that previously used web2 now enforce the same security policies as web (such as prohibiting HTTPS-to-HTTP redirects). ¹https://github.com/golang/vgo/commit/63138cb6ceed7d6d4e51a8cbd568c64bd3e2b132 Fixes #29591 Fixes #29888 Fixes #30610 Updates #26232 Change-Id: Ia3a13526e443679cf14a72a1f3db96f336ce5e73 Reviewed-on: https://go-review.googlesource.com/c/go/+/170879 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
2019-04-01cmd/go: refactor load.LoadPackage into other functionsJay Conrod
LoadPackage was used to load a *load.Package for a command line argument, after pattern expansion. It provided two special cases on top of LoadImport. First, it ensured that "cmd/" packages in GOROOT were installed in "$GOROOT/bin" or "$GOROOT/pkg/tool". Second, it translated absolute paths to packages in GOROOT and GOPATH into regular import paths. With this change, LoadImport now ensures "cmd/" packages have the right Target (without the need for a special case) and search.ImportPaths translates absolute paths. LoadPackage no longer handles these special cases and has been renamed to LoadImportWithFlags, since it's still useful for loading implicit dependencies. Updates #29758 Change-Id: I9d54036f90c3ccd9b3a0fe0eaddaa7749593cc91 Reviewed-on: https://go-review.googlesource.com/c/go/+/167748 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2018-12-14cmd/go/internal/get: move wildcard-trimming to before CheckImportPathBryan C. Mills
Previously, RepoRootForImportPath trimmed certain "..." wildcards from package patterns (even though its name suggests that the argument must be an actual import path). It trimmed at the first path element that was literally "..." (although wildcards in general may appear within a larger path element), and relied on a subsequent check in RepoRootForImportPath to catch confusing resolutions. However, that causes 'go get' with wildcard patterns in fresh paths to fail as of CL 154101: a wildcard pattern is not a valid import path, and fails the path check. (The existing Test{Vendor,Go}Get* packages in go_test.go and vendor_test.go catch the failure, but they are all skipped when the "-short" flag is set — including in all.bash — and we had forgotten to run them separately.) We now trim the path before any element that contains a wildcard, and perform the path check (and repo resolution) on only that prefix. It is possible that the expanded path after fetching the repo will be invalid, but a repository can contain directories that are not valid import paths in general anyway. Fixes #29241 Change-Id: I70fb2f7fc6603b7d339fd6c02e8cdeacfc93fc4b Reviewed-on: https://go-review.googlesource.com/c/154108 Reviewed-by: Russ Cox <rsc@golang.org>
2018-12-14cmd/go: reject 'get' of paths containing leading dots or unsupported charactersBryan C. Mills
On some platforms, directories beginning with dot are treated as hidden files, and filenames containing unusual characters can be confusing for users to manipulate (and delete). Fixes #29230 Fixes #29231 Change-Id: Ic6f97f577d8fafa83ef62438095a5c7ae022881a Reviewed-on: https://team-review.git.corp.google.com/c/368507 Reviewed-by: Russ Cox <rsc@google.com> Reviewed-on: https://go-review.googlesource.com/c/154101 Reviewed-by: Bryan C. Mills <bcmills@google.com>
2018-08-17cmd/go: fix -gcflags, -ldflags not applying to current directoryRuss Cox
A flag setting like -gcflags=-e applies only to the packages named on the command line, not to their dependencies. The way we used to implement this was to remember the command line arguments, reinterpret them as pattern matches instead of package argument generators (globs), and apply them during package load. The reason for this complexity was to address a command-line like: go build -gcflags=-e fmt runtime The load of fmt will load dependencies, including runtime, and the load of runtime will reuse the result of the earlier load. Because we were computing the effective -gcflags for each package during the load, we had to have a way to tell, when encountering runtime during the load of fmt, that runtime had been named on the command line, even though we hadn't gotten that far. That would be easy if the only possible arguments were import paths, but we also need to handle go build -gcflags=-e fmt runt... go build -gcflags=-e fmt $GOROOT/src/runtime go build -gcflags=-e fmt $GOROOT/src/runt... and so on. The match predicates usually did their job well, but not always. In particular, thanks to symlinks and case-insensitive file systems and unusual ways to spell file paths, it's always been possible in various corner cases to give an argument that evalutes to the runtime package during loading but failed to match it when reused to determine "was this package named on the command line?" CL 109235 fixed one instance of this problem by making a directory pattern match case-insensitive on Windows, but that is incorrect in some other cases and doesn't address the root problem, namely that there will probably always be odd corner cases where pattern matching and pattern globbing are not exactly aligned. This CL eliminates the assumption that pattern matching and pattern globbing are always completely in agreement, by simply marking the packages named on the command line after the package load returns them. This means delaying the computation of tool flags until after the load too, for a few different ways packages are loaded. The different load entry points add some complexity, which is why the original approach seemed more attractive, but the original approach had complexity that we simply didn't recognize at the time. This CL then rolls back the CL 109235 pattern-matching change, but it keeps the test introduced in that CL. That test still passes. In addition to fixing ambiguity due to case-sensitive file systems, this new approach also very likely fixes various ambiguities that might arise from abuse of symbolic links. Fixes #24232. Fixes #24456. Fixes #24750. Fixes #25046. Fixes #25878. Change-Id: I0b09825785dfb5112fb11494cff8527ebf57966f Reviewed-on: https://go-review.googlesource.com/129059 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com>
2018-08-17cmd/go: distinguish patterns from the results of matching themRuss Cox
To date the go command has always just treated the command line package patterns as a []string, expanded by pattern matching into another []string. As a result, the code is not always clear about whether a particular []string contains patterns or results. A few different important bugs are caused by not keeping this distinction clear enough. This CL sets us up well for fixing those, by introducing an explicit search.Match struct holding the results of matching a single pattern. The added clarity here also makes it clear how to avoid duplicate warnings about unmatched packages. Fixes #26925. (Test in followup CL.) Change-Id: Ic2f0606f7ab8b3734a40e22d3cb1e6f58d031061 Reviewed-on: https://go-review.googlesource.com/129058 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com>
2018-08-01cmd/go: split go mod into multiple subcommandsRuss Cox
The current "go mod" command does too many things. The design is unclear. It looks like "everything you might want to do with modules" which causes people to think all module operations go through "go mod", which is the opposite of the seamless integration we're going for. In particular too many people think "go mod -require" and "go get" are the same. It does make sense to put the module-specific functionality under "go mod", but not as flags. Instead, split "go mod" into multiple subcommands: go mod edit # old go mod -require ... go mod fix # old go mod -fix go mod graph # old go mod -graph go mod init # old go mod -init go mod tidy # old go mod -sync go mod vendor # old go mod -vendor go mod verify # old go mod -verify Splitting out the individual commands makes both the docs and the implementations dramatically easier to read. It simplifies the command lines (go mod -init -module m is now 'go mod init m') and allows command-specific flags. We've avoided subcommands in the go command to date, and we should continue to avoid adding them unless it really makes the experience significantly better. In this case, it does. Creating subcommands required some changes in the core command-parsing and help logic to generalize from one level to multiple levels. As part of having "go mod init" be a separate command, this CL changes the failure behavior during module initialization to be delayed until modules are actually needed. Initialization can still happen early, but the base.Fatalf is delayed until something needs to use modules. This fixes a bunch of commands like 'go env' that were unhelpfully failing with GO111MODULE=on when not in a module directory. Fixes #26432. Fixes #26581. Fixes #26596. Fixes #26639. Change-Id: I868db0babe8c288e8af684b29d4a5ae4825d6407 Reviewed-on: https://go-review.googlesource.com/126655 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2018-07-19cmd/go: warn about non-use of go.mod in legacy go getRuss Cox
It's important for a smooth transition for non-module users not to change operation in GOPATH/src by default in Go 1.11, even if go.mod exists in a downloaded dependency. Even so, users create go.mod and then are confused about why 'go get' commands seem to behave oddly, when in fact they are getting the old 'go get'. Try to split the difference by printing a warning in 'go get' when run in a tree that would normally be considered a module if only it were outside GOPATH/src. Change-Id: I55a1cbef127f3f36de54a8d7b93e1fc64bf0a708 Reviewed-on: https://go-review.googlesource.com/124859 Reviewed-by: Bryan C. Mills <bcmills@google.com>
2018-07-12cmd/go: merge module support from x/vgo repoRuss Cox
This CL corresponds to CL 123361, the final manual CL in that repo, making this the final manual sync. All future commits will happen in this repo (the main Go repo), and we'll update x/vgo automatically with a fixed patch+script. Change-Id: I572243309c1809727604fd704705a23c30e85d1a Reviewed-on: https://go-review.googlesource.com/123576 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2018-06-15cmd/go: add dark copy of golang.org/x/vgoRuss Cox
This CL corresponds to golang.org/cl/118096 (7fbc8df48a7) in the vgo repo. It copies the bulk of the code from vgo back into the main repo, but completely disabled - vgo.Init is a no-op and vgo.Enabled returns false unconditionally. The point of this CL is to make the two trees easier to diff and to make future syncs smaller. Change-Id: Ic34fd5ddd8272a70c5a3b3437b5169e967d0ed03 Reviewed-on: https://go-review.googlesource.com/118095 Reviewed-by: Bryan C. Mills <bcmills@google.com>
2018-06-07cmd/go: don't refuse to update a present package only because of its source ↵David Symonds
configuration If a package is checked out in the right place, but uses, for instance, an unusual Git remote configuration, don't refuse to update just because cmd/go can't parse it. In most cases, `git pull -ff-only` (or the equivalent in other VCSes) works just fine. Updates #25432. Change-Id: I1952a0e6e03f185f34029b186e1756c9549689e1 Reviewed-on: https://go-review.googlesource.com/113456 TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Andrew Gerrand <adg@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2018-06-04cmd/go: fix 'go get' compatibility for direct download of vgo-aware moduleRuss Cox
CL 109340 added “minimal module-awareness for legacy operation.” One part of that is reinterpreting imports inside code trees with go.mod files as using semantic import versioning, and converting them back to legacy import paths by stripping the major version element (for example, interpreting import "x.com/foo/v2/bar" as import "x.com/foo/bar"). This rewrite was not being applied during "go get", with the effect that once you had the target code downloaded already, everything was fine, but it didn't download and build successfully the first time. Fixes #25687. Change-Id: I3e122efdc8fd9a0a4e66f5aa3e6a99f90c7df779 Reviewed-on: https://go-review.googlesource.com/115797 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2018-05-30cmd/go: add minimal module-awareness for legacy operationRuss Cox
We want authors to be able to publish code that works with both the current standard go command and the planned new go command support for modules. If authors have tagged their code v2 or later, semantic import versioning means the import paths must include a v2 path element after the path prefix naming the module. One option for making this convention compatible with original go get is to move code into a v2 subdirectory of the root. That makes sense for some authors, but many authors would prefer not to move all the code into a v2 subdirectory for a transition and then move it back up once we everyone has a module-aware go command. Instead, this CL teaches the old (non-module-aware) go command a tiny amount about modules and their import paths, to expand the options for authors who want to publish compatible packages. If an author has a v2 of a package, say my/thing/v2/sub/pkg, in the my/thing repo's sub/pkg subdirectory (no v2 in the file system path), then old go get continues to import that package as my/thing/sub/pkg. But when go get is processing code in any module (code in a tree with a go.mod file) and encounters a path like my/thing/v2/sub/pkg, it will check to see if my/thing/go.mod says "module my/thing/v2". If so, the go command will read the import my/thing/v2/sub/pkg as if it said my/thing/sub/pkg, which is the correct "old" import path for the package in question. This CL will be back-ported to Go 1.10 and Go 1.9 as well. Once users have updated to the latest Go point releases containing this new logic, authors will be able to update to using modules within their own repos, including using semantic import paths with vN path elements, and old go get will still be able to consume those repositories. This CL also makes "go get" ignore meta go-import lines using the new "mod" VCS type. This allows a package to specify both a "mod" type and a "git" type, to present more efficient module access to module-aware go but still present a Git repo to the old "go get". Fixes #24751. Fixes #25069. Change-Id: I378955613a0d63834d4f50f121f4db7e4d87dc0a Reviewed-on: https://go-review.googlesource.com/109340 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2018-01-04cmd/go: add -v option in the usage section for getAgniva De Sarker
Updates #23332 Change-Id: I964d36ed751ef1844ab6c40f61047297ff1443a3 Reviewed-on: https://go-review.googlesource.com/85797 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-11-07cmd/go: accept relative -pkgdir argumentRuss Cox
Fixes #21309. Change-Id: I8ff1b0f37e34a3a4e9f8448d66a64fe3863d081f Reviewed-on: https://go-review.googlesource.com/76250 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-10-05all: revert "all: prefer strings.IndexByte over strings.Index"Marvin Stenger
This reverts https://golang.org/cl/65930. Fixes #22148 Change-Id: Ie0712621ed89c43bef94417fc32de9af77607760 Reviewed-on: https://go-review.googlesource.com/68430 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-10-04cmd/go: reject update of VCS inside VCSRuss Cox
This can only lead to confusion. Change-Id: Iae84c6404ab5eeb6950faa2364f97a017c67c506 Reviewed-on: https://go-review.googlesource.com/68110 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Crawshaw <crawshaw@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Simon Rawet <Simon@rawet.se>
2017-10-03cmd/go: replace PackageInternal.GoFiles, AllGoFiles with methodsRuss Cox
These are rarely used and can be computed on demand, to make clear that they are never out of sync with the lists in the non-internal Package fields. Change-Id: I8c621dceaff1aeb39a3ed83f18e848adf14d7106 Reviewed-on: https://go-review.googlesource.com/56284 Reviewed-by: David Crawshaw <crawshaw@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-09-25all: prefer strings.IndexByte over strings.IndexMarvin Stenger
strings.IndexByte was introduced in go1.2 and it can be used effectively wherever the second argument to strings.Index is exactly one byte long. This avoids generating unnecessary string symbols and saves a few calls to strings.Index. Change-Id: I1ab5edb7c4ee9058084cfa57cbcc267c2597e793 Reviewed-on: https://go-review.googlesource.com/65930 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-08-16cmd/go: add support for Fossil SCM to go getKyle Shannon
Fixes #10010. Change-Id: Ib13ac28eafed72c456d8b5b6549015cdf5fdda94 Reviewed-on: https://go-review.googlesource.com/56190 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-06-15cmd/go: improve documentation on defaults for getMarko Mudrinic
The existing docs states that, get looks for a branch or tag that matches the locally installed version of Go. First, this is only working for "go1", so it could be confusing. Second, "If no such version exists it retrieves the most recent version of the package". It's more the default branch, by git defaults, rather than most recent version. This should address the potential unclear parts. Fixes #20320 Change-Id: Id7d727d88dc350c9902974b64fa28c3766f7e245 Reviewed-on: https://go-review.googlesource.com/45890 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-06-13cmd/go: initialize in get before loading packagesIan Lance Taylor
Otherwise the packages will not pick up the way that -installsuffix is changed by -buildmode and -race. Fixes #20512. Change-Id: Ieca32c958a531beb6331dff30d7e9a4998867dbb Reviewed-on: https://go-review.googlesource.com/44630 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>