diff options
author | Bryan C. Mills <bcmills@google.com> | 2021-02-26 13:28:23 -0500 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2021-03-18 14:43:33 +0000 |
commit | e726e2a6087683eb21afe79ef8b5a1dbef80b0f1 (patch) | |
tree | 39c9a7116d1f33052048d0969b0cb18be5a4fa0a /src/cmd/go/internal/modget/get.go | |
parent | 6b6ea3271fd4f0ed99d5390461db9fa45ce4c164 (diff) | |
download | go-e726e2a6087683eb21afe79ef8b5a1dbef80b0f1.tar.gz go-e726e2a6087683eb21afe79ef8b5a1dbef80b0f1.zip |
cmd/go: suppress errors for 'go get' of module paths that are also constrained-out packages
Fixes #33526
Change-Id: Iedd2d6dbe440499bf074ac632513319a22f2d648
Reviewed-on: https://go-review.googlesource.com/c/go/+/297009
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>
Diffstat (limited to 'src/cmd/go/internal/modget/get.go')
-rw-r--r-- | src/cmd/go/internal/modget/get.go | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/cmd/go/internal/modget/get.go b/src/cmd/go/internal/modget/get.go index 6b416d3622..4892db8781 100644 --- a/src/cmd/go/internal/modget/get.go +++ b/src/cmd/go/internal/modget/get.go @@ -369,7 +369,23 @@ func runGet(ctx context.Context, cmd *base.Command, args []string) { // directory. if !*getD && len(pkgPatterns) > 0 { work.BuildInit() - pkgs := load.PackagesAndErrors(ctx, pkgPatterns) + + var pkgs []*load.Package + for _, pkg := range load.PackagesAndErrors(ctx, pkgPatterns) { + if pkg.Error != nil { + var noGo *load.NoGoError + if errors.As(pkg.Error.Err, &noGo) { + if m := modload.PackageModule(pkg.ImportPath); m.Path == pkg.ImportPath { + // pkg is at the root of a module, and doesn't exist with the current + // build tags. Probably the user just wanted to change the version of + // that module — not also build the package — so suppress the error. + // (See https://golang.org/issue/33526.) + continue + } + } + } + pkgs = append(pkgs, pkg) + } load.CheckPackageErrors(pkgs) work.InstallPackages(ctx, pkgPatterns, pkgs) // TODO(#40276): After Go 1.16, print a deprecation notice when building and @@ -1453,6 +1469,7 @@ func (r *resolver) checkPackagesAndRetractions(ctx context.Context, pkgPatterns LoadTests: *getT, ResolveMissingImports: false, AllowErrors: true, + SilenceNoGoErrors: true, } matches, pkgs := modload.LoadPackages(ctx, pkgOpts, pkgPatterns...) for _, m := range matches { @@ -1468,9 +1485,9 @@ func (r *resolver) checkPackagesAndRetractions(ctx context.Context, pkgPatterns // associated with either the package or its test — ErrNoGo must // indicate that none of those source files happen to apply in this // configuration. If we are actually building the package (no -d - // flag), the compiler will report the problem; otherwise, assume that - // the user is going to build or test it in some other configuration - // and suppress the error. + // flag), we will report the problem then; otherwise, assume that the + // user is going to build or test this package in some other + // configuration and suppress the error. continue } |