Skip to content

Commit 4bf4c7d

Browse files
aclementsgopherbot
authored andcommitted
cmd/go: drop unnecessary Package argument to reportCmd
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 <[email protected]> Reviewed-by: Bryan Mills <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 66287d5 commit 4bf4c7d

File tree

4 files changed

+18
-23
lines changed

4 files changed

+18
-23
lines changed

src/cmd/go/internal/work/cover.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func WriteCoveragePercent(b *Builder, runAct *Action, mf string, w io.Writer) er
7272
dir := filepath.Dir(mf)
7373
output, cerr := b.CovData(runAct, "percent", "-i", dir)
7474
if cerr != nil {
75-
return b.reportCmd(runAct, nil, "", "", output, cerr)
75+
return b.reportCmd(runAct, "", "", output, cerr)
7676
}
7777
_, werr := w.Write(output)
7878
return werr
@@ -87,7 +87,7 @@ func WriteCoverageProfile(b *Builder, runAct *Action, mf, outf string, w io.Writ
8787
dir := filepath.Dir(mf)
8888
output, err := b.CovData(runAct, "textfmt", "-i", dir, "-o", outf)
8989
if err != nil {
90-
return b.reportCmd(runAct, nil, "", "", output, err)
90+
return b.reportCmd(runAct, "", "", output, err)
9191
}
9292
_, werr := w.Write(output)
9393
return werr

src/cmd/go/internal/work/exec.go

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ OverlayLoop:
868868
// Compile Go.
869869
objpkg := objdir + "_pkg_.a"
870870
ofile, out, err := BuildToolchain.gc(b, a, objpkg, icfg.Bytes(), embedcfg, symabis, len(sfiles) > 0, gofiles)
871-
if err := b.reportCmd(a, nil, "", "", out, err); err != nil {
871+
if err := b.reportCmd(a, "", "", out, err); err != nil {
872872
return err
873873
}
874874
if ofile != objpkg {
@@ -996,7 +996,7 @@ func (b *Builder) checkDirectives(a *Action) error {
996996
// path, but the content of the error doesn't matter because msg is
997997
// non-empty.
998998
err := errors.New("invalid directive")
999-
return b.reportCmd(a, nil, "", "", msg.Bytes(), err)
999+
return b.reportCmd(a, "", "", msg.Bytes(), err)
10001000
}
10011001
return nil
10021002
}
@@ -1637,7 +1637,7 @@ func (b *Builder) getPkgConfigFlags(a *Action) (cflags, ldflags []string, err er
16371637
out, err = b.runOut(nil, p.Dir, nil, b.PkgconfigCmd(), "--cflags", pcflags, "--", pkgs)
16381638
if err != nil {
16391639
desc := b.PkgconfigCmd() + " --cflags " + strings.Join(pcflags, " ") + " -- " + strings.Join(pkgs, " ")
1640-
return nil, nil, b.reportCmd(a, nil, desc, "", out, err)
1640+
return nil, nil, b.reportCmd(a, desc, "", out, err)
16411641
}
16421642
if len(out) > 0 {
16431643
cflags, err = splitPkgConfigOutput(bytes.TrimSpace(out))
@@ -1651,7 +1651,7 @@ func (b *Builder) getPkgConfigFlags(a *Action) (cflags, ldflags []string, err er
16511651
out, err = b.runOut(nil, p.Dir, nil, b.PkgconfigCmd(), "--libs", pcflags, "--", pkgs)
16521652
if err != nil {
16531653
desc := b.PkgconfigCmd() + " --libs " + strings.Join(pcflags, " ") + " -- " + strings.Join(pkgs, " ")
1654-
return nil, nil, b.reportCmd(a, nil, desc, "", out, err)
1654+
return nil, nil, b.reportCmd(a, desc, "", out, err)
16551655
}
16561656
if len(out) > 0 {
16571657
// 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) {
22412241
// cgo file paths with the original file path, and replaces cgo-mangled names
22422242
// with "C.name".
22432243
//
2244-
// p is optional. If nil, a.Package is used.
2244+
// desc is optional. If "", a.Package.Desc() is used.
22452245
//
2246-
// desc is optional. If "", p.Desc() is used.
2247-
//
2248-
// dir is optional. If "", p.Dir is used.
2249-
func (b *Builder) reportCmd(a *Action, p *load.Package, desc, dir string, cmdOut []byte, cmdErr error) error {
2250-
// TODO: It seems we can always get p from a.Package, so it should be
2251-
// possible to drop the "p" argument. However, a lot of callers take both
2252-
// Action and Package, so we'd want to drop the Package argument from those,
2253-
// too.
2246+
// dir is optional. If "", a.Package.Dir is used.
2247+
func (b *Builder) reportCmd(a *Action, desc, dir string, cmdOut []byte, cmdErr error) error {
22542248
if len(cmdOut) == 0 && cmdErr == nil {
22552249
// Common case
22562250
return nil
@@ -2267,7 +2261,8 @@ func (b *Builder) reportCmd(a *Action, p *load.Package, desc, dir string, cmdOut
22672261
}
22682262

22692263
// Fetch defaults from the package.
2270-
if a != nil && p == nil {
2264+
var p *load.Package
2265+
if a != nil {
22712266
p = a.Package
22722267
}
22732268
var importPath string
@@ -2397,7 +2392,7 @@ func (b *Builder) run(a *Action, dir string, desc string, env []string, cmdargs
23972392
if desc == "" {
23982393
desc = b.fmtcmd(dir, "%s", strings.Join(str.StringList(cmdargs...), " "))
23992394
}
2400-
return b.reportCmd(a, nil, desc, dir, out, err)
2395+
return b.reportCmd(a, desc, dir, out, err)
24012396
}
24022397

24032398
// 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
27592754
err = errors.New("warning promoted to error")
27602755
}
27612756

2762-
return b.reportCmd(a, nil, "", "", output, err)
2757+
return b.reportCmd(a, "", "", output, err)
27632758
}
27642759

27652760
// 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
28132808
// Note that failure is an expected outcome here, so we report output only
28142809
// in debug mode and don't report the error.
28152810
if cfg.BuildN || cfg.BuildX {
2816-
b.reportCmd(a, nil, "", "", out, nil)
2811+
b.reportCmd(a, "", "", out, nil)
28172812
}
28182813
return err
28192814
}
@@ -3848,7 +3843,7 @@ func (b *Builder) swigOne(a *Action, file, objdir string, pcCFLAGS []string, cxx
38483843
if err != nil && (bytes.Contains(out, []byte("-intgosize")) || bytes.Contains(out, []byte("-cgo"))) {
38493844
return "", "", errors.New("must have SWIG version >= 3.0.6")
38503845
}
3851-
if err := b.reportCmd(a, nil, "", "", out, err); err != nil {
3846+
if err := b.reportCmd(a, "", "", out, err); err != nil {
38523847
return "", "", err
38533848
}
38543849

src/cmd/go/internal/work/gc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ func (gcToolchain) pack(b *Builder, a *Action, afile string, ofiles []string) er
464464
return nil
465465
}
466466
if err := packInternal(absAfile, absOfiles); err != nil {
467-
return b.reportCmd(a, nil, "", "", nil, err)
467+
return b.reportCmd(a, "", "", nil, err)
468468
}
469469
return nil
470470
}

src/cmd/go/internal/work/gccgo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func (tools gccgoToolchain) pack(b *Builder, a *Action, afile string, ofiles []s
245245
}
246246

247247
// Show the output if there is any even without errors.
248-
return b.reportCmd(a, nil, "", "", output, nil)
248+
return b.reportCmd(a, "", "", output, nil)
249249
}
250250

251251
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 {
659659
// Show output. We always pass a nil err because errors are an
660660
// expected outcome in this case.
661661
desc := b.fmtcmd(tmpdir, "%s -c -o %s %s", tools.compiler(), on, fn)
662-
b.reportCmd(a, nil, desc, tmpdir, buf.Bytes(), nil)
662+
b.reportCmd(a, desc, tmpdir, buf.Bytes(), nil)
663663
}
664664
})
665665
return gccgoSupportsCgoIncomplete

0 commit comments

Comments
 (0)