diff options
author | Jay Conrod <jayconrod@google.com> | 2021-04-16 13:34:37 -0400 |
---|---|---|
committer | Jay Conrod <jayconrod@google.com> | 2021-04-16 18:29:56 +0000 |
commit | 492eb059f9ce08285fae8284e69b1103b63e879e (patch) | |
tree | 307ff5af29c29e49d9fb66f82647526c0d0911a4 /src/cmd/go/internal/run/run.go | |
parent | 60abe013217e224b200b6c3e6da344a6e5af431c (diff) | |
download | go-492eb059f9ce08285fae8284e69b1103b63e879e.tar.gz go-492eb059f9ce08285fae8284e69b1103b63e879e.zip |
cmd/go: fix mod_install_pkg_version
mainPackagesOnly now includes non-main packages matched by literal
arguments in the returned slice, since their errors must be reported.
GoFilesPackages attaches the same error to its package if
opts.MainOnly is true. This changes the error output of 'go run'
slightly, but it seems like an imporovement.
For #42088
Change-Id: I8f2942470383af5d4c9763022bc94338f5314b07
Reviewed-on: https://go-review.googlesource.com/c/go/+/310829
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>
Diffstat (limited to 'src/cmd/go/internal/run/run.go')
-rw-r--r-- | src/cmd/go/internal/run/run.go | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/src/cmd/go/internal/run/run.go b/src/cmd/go/internal/run/run.go index 914e5edc6f..784f7162df 100644 --- a/src/cmd/go/internal/run/run.go +++ b/src/cmd/go/internal/run/run.go @@ -92,6 +92,7 @@ func runRun(ctx context.Context, cmd *base.Command, args []string) { for i < len(args) && strings.HasSuffix(args[i], ".go") { i++ } + pkgOpts := load.PackageOpts{MainOnly: true} var p *load.Package if i > 0 { files := args[:i] @@ -102,10 +103,9 @@ func runRun(ctx context.Context, cmd *base.Command, args []string) { base.Fatalf("go run: cannot run *_test.go files (%s)", file) } } - p = load.GoFilesPackage(ctx, load.PackageOpts{}, files) + p = load.GoFilesPackage(ctx, pkgOpts, files) } else if len(args) > 0 && !strings.HasPrefix(args[0], "-") { arg := args[0] - pkgOpts := load.PackageOpts{MainOnly: true} var pkgs []*load.Package if strings.Contains(arg, "@") && !build.IsLocalImport(arg) && !filepath.IsAbs(arg) { var err error @@ -133,9 +133,6 @@ func runRun(ctx context.Context, cmd *base.Command, args []string) { base.Fatalf("go run: no go files listed") } cmdArgs := args[i:] - if p.Name != "main" { - base.Fatalf("go run: cannot run non-main package") - } load.CheckPackageErrors([]*load.Package{p}) p.Internal.OmitDebug = true |