]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/go: drop unnecessary Package argument to reportCmd
authorAustin Clements <austin@google.com>
Tue, 17 Oct 2023 16:39:32 +0000 (12:39 -0400)
committerGopher Robot <gobot@golang.org>
Wed, 18 Oct 2023 14:46:56 +0000 (14:46 +0000)
Now that we've dropped the redundant Package arguments to many
functions, we can see that the Package argument to reportCmd is always
nil. That means we can drop it and always use a.Package.

For #62067.

Change-Id: I2e11e770f495d6f770047993358c76b08204e923
Reviewed-on: https://go-review.googlesource.com/c/go/+/536096
Auto-Submit: Austin Clements <austin@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/go/internal/work/cover.go
src/cmd/go/internal/work/exec.go
src/cmd/go/internal/work/gc.go
src/cmd/go/internal/work/gccgo.go

index ebffe524125dcb288830103fecad6b45ca6cdcda..524beb40243113945cd9466caea55456edb6f9ad 100644 (file)
@@ -72,7 +72,7 @@ func WriteCoveragePercent(b *Builder, runAct *Action, mf string, w io.Writer) er
        dir := filepath.Dir(mf)
        output, cerr := b.CovData(runAct, "percent", "-i", dir)
        if cerr != nil {
-               return b.reportCmd(runAct, nil, "", "", output, cerr)
+               return b.reportCmd(runAct, "", "", output, cerr)
        }
        _, werr := w.Write(output)
        return werr
@@ -87,7 +87,7 @@ func WriteCoverageProfile(b *Builder, runAct *Action, mf, outf string, w io.Writ
        dir := filepath.Dir(mf)
        output, err := b.CovData(runAct, "textfmt", "-i", dir, "-o", outf)
        if err != nil {
-               return b.reportCmd(runAct, nil, "", "", output, err)
+               return b.reportCmd(runAct, "", "", output, err)
        }
        _, werr := w.Write(output)
        return werr
index 5f24e3d48e2871378a8a2414cdaba18ad3563a00..f115b5dc47715ac7ec6a757cc3229958e0615c8d 100644 (file)
@@ -868,7 +868,7 @@ OverlayLoop:
        // Compile Go.
        objpkg := objdir + "_pkg_.a"
        ofile, out, err := BuildToolchain.gc(b, a, objpkg, icfg.Bytes(), embedcfg, symabis, len(sfiles) > 0, gofiles)
-       if err := b.reportCmd(a, nil, "", "", out, err); err != nil {
+       if err := b.reportCmd(a, "", "", out, err); err != nil {
                return err
        }
        if ofile != objpkg {
@@ -996,7 +996,7 @@ func (b *Builder) checkDirectives(a *Action) error {
                // path, but the content of the error doesn't matter because msg is
                // non-empty.
                err := errors.New("invalid directive")
-               return b.reportCmd(a, nil, "", "", msg.Bytes(), err)
+               return b.reportCmd(a, "", "", msg.Bytes(), err)
        }
        return nil
 }
@@ -1637,7 +1637,7 @@ func (b *Builder) getPkgConfigFlags(a *Action) (cflags, ldflags []string, err er
                out, err = b.runOut(nil, p.Dir, nil, b.PkgconfigCmd(), "--cflags", pcflags, "--", pkgs)
                if err != nil {
                        desc := b.PkgconfigCmd() + " --cflags " + strings.Join(pcflags, " ") + " -- " + strings.Join(pkgs, " ")
-                       return nil, nil, b.reportCmd(a, nil, desc, "", out, err)
+                       return nil, nil, b.reportCmd(a, desc, "", out, err)
                }
                if len(out) > 0 {
                        cflags, err = splitPkgConfigOutput(bytes.TrimSpace(out))
@@ -1651,7 +1651,7 @@ func (b *Builder) getPkgConfigFlags(a *Action) (cflags, ldflags []string, err er
                out, err = b.runOut(nil, p.Dir, nil, b.PkgconfigCmd(), "--libs", pcflags, "--", pkgs)
                if err != nil {
                        desc := b.PkgconfigCmd() + " --libs " + strings.Join(pcflags, " ") + " -- " + strings.Join(pkgs, " ")
-                       return nil, nil, b.reportCmd(a, nil, desc, "", out, err)
+                       return nil, nil, b.reportCmd(a, desc, "", out, err)
                }
                if len(out) > 0 {
                        // We need to handle path with spaces so that C:/Program\ Files can pass
@@ -2241,16 +2241,10 @@ func (b *Builder) Showcmd(dir string, format string, args ...any) {
 // cgo file paths with the original file path, and replaces cgo-mangled names
 // with "C.name".
 //
-// p is optional. If nil, a.Package is used.
+// desc is optional. If "", a.Package.Desc() is used.
 //
-// desc is optional. If "", p.Desc() is used.
-//
-// dir is optional. If "", p.Dir is used.
-func (b *Builder) reportCmd(a *Action, p *load.Package, desc, dir string, cmdOut []byte, cmdErr error) error {
-       // TODO: It seems we can always get p from a.Package, so it should be
-       // possible to drop the "p" argument. However, a lot of callers take both
-       // Action and Package, so we'd want to drop the Package argument from those,
-       // too.
+// dir is optional. If "", a.Package.Dir is used.
+func (b *Builder) reportCmd(a *Action, desc, dir string, cmdOut []byte, cmdErr error) error {
        if len(cmdOut) == 0 && cmdErr == nil {
                // Common case
                return nil
@@ -2267,7 +2261,8 @@ func (b *Builder) reportCmd(a *Action, p *load.Package, desc, dir string, cmdOut
        }
 
        // Fetch defaults from the package.
-       if a != nil && p == nil {
+       var p *load.Package
+       if a != nil {
                p = a.Package
        }
        var importPath string
@@ -2397,7 +2392,7 @@ func (b *Builder) run(a *Action, dir string, desc string, env []string, cmdargs
        if desc == "" {
                desc = b.fmtcmd(dir, "%s", strings.Join(str.StringList(cmdargs...), " "))
        }
-       return b.reportCmd(a, nil, desc, dir, out, err)
+       return b.reportCmd(a, desc, dir, out, err)
 }
 
 // runOut runs the command given by cmdline in the directory dir.
@@ -2759,7 +2754,7 @@ func (b *Builder) ccompile(a *Action, outfile string, flags []string, file strin
                err = errors.New("warning promoted to error")
        }
 
-       return b.reportCmd(a, nil, "", "", output, err)
+       return b.reportCmd(a, "", "", output, err)
 }
 
 // gccld runs the gcc linker to create an executable from a set of object files.
@@ -2813,7 +2808,7 @@ func (b *Builder) gccld(a *Action, objdir, outfile string, flags []string, objs
        // Note that failure is an expected outcome here, so we report output only
        // in debug mode and don't report the error.
        if cfg.BuildN || cfg.BuildX {
-               b.reportCmd(a, nil, "", "", out, nil)
+               b.reportCmd(a, "", "", out, nil)
        }
        return err
 }
@@ -3848,7 +3843,7 @@ func (b *Builder) swigOne(a *Action, file, objdir string, pcCFLAGS []string, cxx
        if err != nil && (bytes.Contains(out, []byte("-intgosize")) || bytes.Contains(out, []byte("-cgo"))) {
                return "", "", errors.New("must have SWIG version >= 3.0.6")
        }
-       if err := b.reportCmd(a, nil, "", "", out, err); err != nil {
+       if err := b.reportCmd(a, "", "", out, err); err != nil {
                return "", "", err
        }
 
index 6054e8d81c93c3de0c787121e0ddb81197078621..962bc53b4b62c407b6273b5d83767a05c8b9bb1e 100644 (file)
@@ -464,7 +464,7 @@ func (gcToolchain) pack(b *Builder, a *Action, afile string, ofiles []string) er
                return nil
        }
        if err := packInternal(absAfile, absOfiles); err != nil {
-               return b.reportCmd(a, nil, "", "", nil, err)
+               return b.reportCmd(a, "", "", nil, err)
        }
        return nil
 }
index f38d57a43f4d732af4f4ba5e58b6ca8cfb9dfd63..a7b13ffa6f10ca8f3835a587e2615b99c9da11a1 100644 (file)
@@ -245,7 +245,7 @@ func (tools gccgoToolchain) pack(b *Builder, a *Action, afile string, ofiles []s
        }
 
        // Show the output if there is any even without errors.
-       return b.reportCmd(a, nil, "", "", output, nil)
+       return b.reportCmd(a, "", "", output, nil)
 }
 
 func (tools gccgoToolchain) link(b *Builder, root *Action, out, importcfg string, allactions []*Action, buildmode, desc string) error {
@@ -659,7 +659,7 @@ func (tools gccgoToolchain) supportsCgoIncomplete(b *Builder, a *Action) bool {
                        // Show output. We always pass a nil err because errors are an
                        // expected outcome in this case.
                        desc := b.fmtcmd(tmpdir, "%s -c -o %s %s", tools.compiler(), on, fn)
-                       b.reportCmd(a, nil, desc, tmpdir, buf.Bytes(), nil)
+                       b.reportCmd(a, desc, tmpdir, buf.Bytes(), nil)
                }
        })
        return gccgoSupportsCgoIncomplete