Skip to content

Commit

Permalink
cmd/go: drop unnecessary Package argument to reportCmd
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
aclements authored and gopherbot committed Oct 18, 2023
1 parent 66287d5 commit 4bf4c7d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/cmd/go/internal/work/cover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
31 changes: 13 additions & 18 deletions src/cmd/go/internal/work/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/work/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/go/internal/work/gccgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4bf4c7d

Please sign in to comment.