Skip to content

Commit 66287d5

Browse files
aclementsgopherbot
authored andcommitted
cmd/go: drop unnecessary Package arguments
There are several functions that take both an Action argument and a Package argument. It takes a decent amount of work to determine that in all cases the value of the Package argument is just Action.Package. This makes these Package arguments both redundant and potentially confusing because it makes these APIs look like they have more flexibility than they actually do. Drop these unnecessary Package arguments. For #62067. Change-Id: Ibd3295cf6a79d95ceb421d60671f87e023517f8d Reviewed-on: https://go-review.googlesource.com/c/go/+/536095 Reviewed-by: Bryan Mills <[email protected]> Auto-Submit: Austin Clements <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent ce25ad6 commit 66287d5

File tree

1 file changed

+36
-26
lines changed

1 file changed

+36
-26
lines changed

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

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ OverlayLoop:
631631
// Each run will generate two files, a .go file and a .c or .cxx file.
632632
// The .go file will use import "C" and is to be processed by cgo.
633633
if p.UsesSwig() {
634-
outGo, outC, outCXX, err := b.swig(a, p, objdir, pcCFLAGS)
634+
outGo, outC, outCXX, err := b.swig(a, objdir, pcCFLAGS)
635635
if err != nil {
636636
return err
637637
}
@@ -2648,22 +2648,26 @@ func (noToolchain) cc(b *Builder, a *Action, ofile, cfile string) error {
26482648
}
26492649

26502650
// gcc runs the gcc C compiler to create an object from a single C file.
2651-
func (b *Builder) gcc(a *Action, p *load.Package, workdir, out string, flags []string, cfile string) error {
2652-
return b.ccompile(a, p, out, flags, cfile, b.GccCmd(p.Dir, workdir))
2651+
func (b *Builder) gcc(a *Action, workdir, out string, flags []string, cfile string) error {
2652+
p := a.Package
2653+
return b.ccompile(a, out, flags, cfile, b.GccCmd(p.Dir, workdir))
26532654
}
26542655

26552656
// gxx runs the g++ C++ compiler to create an object from a single C++ file.
2656-
func (b *Builder) gxx(a *Action, p *load.Package, workdir, out string, flags []string, cxxfile string) error {
2657-
return b.ccompile(a, p, out, flags, cxxfile, b.GxxCmd(p.Dir, workdir))
2657+
func (b *Builder) gxx(a *Action, workdir, out string, flags []string, cxxfile string) error {
2658+
p := a.Package
2659+
return b.ccompile(a, out, flags, cxxfile, b.GxxCmd(p.Dir, workdir))
26582660
}
26592661

26602662
// gfortran runs the gfortran Fortran compiler to create an object from a single Fortran file.
2661-
func (b *Builder) gfortran(a *Action, p *load.Package, workdir, out string, flags []string, ffile string) error {
2662-
return b.ccompile(a, p, out, flags, ffile, b.gfortranCmd(p.Dir, workdir))
2663+
func (b *Builder) gfortran(a *Action, workdir, out string, flags []string, ffile string) error {
2664+
p := a.Package
2665+
return b.ccompile(a, out, flags, ffile, b.gfortranCmd(p.Dir, workdir))
26632666
}
26642667

26652668
// ccompile runs the given C or C++ compiler and creates an object from a single source file.
2666-
func (b *Builder) ccompile(a *Action, p *load.Package, outfile string, flags []string, file string, compiler []string) error {
2669+
func (b *Builder) ccompile(a *Action, outfile string, flags []string, file string, compiler []string) error {
2670+
p := a.Package
26672671
file = mkAbs(p.Dir, file)
26682672
outfile = mkAbs(p.Dir, outfile)
26692673

@@ -2746,7 +2750,7 @@ func (b *Builder) ccompile(a *Action, p *load.Package, outfile string, flags []s
27462750
}
27472751
}
27482752
if len(newFlags) < len(flags) {
2749-
return b.ccompile(a, p, outfile, newFlags, file, compiler)
2753+
return b.ccompile(a, outfile, newFlags, file, compiler)
27502754
}
27512755
}
27522756

@@ -2755,12 +2759,13 @@ func (b *Builder) ccompile(a *Action, p *load.Package, outfile string, flags []s
27552759
err = errors.New("warning promoted to error")
27562760
}
27572761

2758-
return b.reportCmd(a, p, "", "", output, err)
2762+
return b.reportCmd(a, nil, "", "", output, err)
27592763
}
27602764

27612765
// gccld runs the gcc linker to create an executable from a set of object files.
27622766
// Any error output is only displayed for BuildN or BuildX.
2763-
func (b *Builder) gccld(a *Action, p *load.Package, objdir, outfile string, flags []string, objs []string) error {
2767+
func (b *Builder) gccld(a *Action, objdir, outfile string, flags []string, objs []string) error {
2768+
p := a.Package
27642769
var cmd []string
27652770
if len(p.CXXFiles) > 0 || len(p.SwigCXXFiles) > 0 {
27662771
cmd = b.GxxCmd(p.Dir, objdir)
@@ -2808,7 +2813,7 @@ func (b *Builder) gccld(a *Action, p *load.Package, objdir, outfile string, flag
28082813
// Note that failure is an expected outcome here, so we report output only
28092814
// in debug mode and don't report the error.
28102815
if cfg.BuildN || cfg.BuildX {
2811-
b.reportCmd(a, p, "", "", out, nil)
2816+
b.reportCmd(a, nil, "", "", out, nil)
28122817
}
28132818
return err
28142819
}
@@ -3391,15 +3396,15 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
33913396
cflags := str.StringList(cgoCPPFLAGS, cgoCFLAGS)
33923397
for _, cfile := range cfiles {
33933398
ofile := nextOfile()
3394-
if err := b.gcc(a, p, a.Objdir, ofile, cflags, objdir+cfile); err != nil {
3399+
if err := b.gcc(a, a.Objdir, ofile, cflags, objdir+cfile); err != nil {
33953400
return nil, nil, err
33963401
}
33973402
outObj = append(outObj, ofile)
33983403
}
33993404

34003405
for _, file := range gccfiles {
34013406
ofile := nextOfile()
3402-
if err := b.gcc(a, p, a.Objdir, ofile, cflags, file); err != nil {
3407+
if err := b.gcc(a, a.Objdir, ofile, cflags, file); err != nil {
34033408
return nil, nil, err
34043409
}
34053410
outObj = append(outObj, ofile)
@@ -3408,15 +3413,15 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
34083413
cxxflags := str.StringList(cgoCPPFLAGS, cgoCXXFLAGS)
34093414
for _, file := range gxxfiles {
34103415
ofile := nextOfile()
3411-
if err := b.gxx(a, p, a.Objdir, ofile, cxxflags, file); err != nil {
3416+
if err := b.gxx(a, a.Objdir, ofile, cxxflags, file); err != nil {
34123417
return nil, nil, err
34133418
}
34143419
outObj = append(outObj, ofile)
34153420
}
34163421

34173422
for _, file := range mfiles {
34183423
ofile := nextOfile()
3419-
if err := b.gcc(a, p, a.Objdir, ofile, cflags, file); err != nil {
3424+
if err := b.gcc(a, a.Objdir, ofile, cflags, file); err != nil {
34203425
return nil, nil, err
34213426
}
34223427
outObj = append(outObj, ofile)
@@ -3425,7 +3430,7 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
34253430
fflags := str.StringList(cgoCPPFLAGS, cgoFFLAGS)
34263431
for _, file := range ffiles {
34273432
ofile := nextOfile()
3428-
if err := b.gfortran(a, p, a.Objdir, ofile, fflags, file); err != nil {
3433+
if err := b.gfortran(a, a.Objdir, ofile, fflags, file); err != nil {
34293434
return nil, nil, err
34303435
}
34313436
outObj = append(outObj, ofile)
@@ -3434,7 +3439,7 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
34343439
switch cfg.BuildToolchainName {
34353440
case "gc":
34363441
importGo := objdir + "_cgo_import.go"
3437-
dynOutGo, dynOutObj, err := b.dynimport(a, p, objdir, importGo, cgoExe, cflags, cgoLDFLAGS, outObj)
3442+
dynOutGo, dynOutObj, err := b.dynimport(a, objdir, importGo, cgoExe, cflags, cgoLDFLAGS, outObj)
34383443
if err != nil {
34393444
return nil, nil, err
34403445
}
@@ -3558,10 +3563,11 @@ func flagsNotCompatibleWithInternalLinking(sourceList []string, flagListList [][
35583563
// dynamically imported by the object files outObj.
35593564
// dynOutGo, if not empty, is a new Go file to build as part of the package.
35603565
// dynOutObj, if not empty, is a new file to add to the generated archive.
3561-
func (b *Builder) dynimport(a *Action, p *load.Package, objdir, importGo, cgoExe string, cflags, cgoLDFLAGS, outObj []string) (dynOutGo, dynOutObj string, err error) {
3566+
func (b *Builder) dynimport(a *Action, objdir, importGo, cgoExe string, cflags, cgoLDFLAGS, outObj []string) (dynOutGo, dynOutObj string, err error) {
3567+
p := a.Package
35623568
cfile := objdir + "_cgo_main.c"
35633569
ofile := objdir + "_cgo_main.o"
3564-
if err := b.gcc(a, p, objdir, ofile, cflags, cfile); err != nil {
3570+
if err := b.gcc(a, objdir, ofile, cflags, cfile); err != nil {
35653571
return "", "", err
35663572
}
35673573

@@ -3606,7 +3612,7 @@ func (b *Builder) dynimport(a *Action, p *load.Package, objdir, importGo, cgoExe
36063612
ldflags = n
36073613
}
36083614
}
3609-
if err := b.gccld(a, p, objdir, dynobj, ldflags, linkobj); err != nil {
3615+
if err := b.gccld(a, objdir, dynobj, ldflags, linkobj); err != nil {
36103616
// We only need this information for internal linking.
36113617
// If this link fails, mark the object as requiring
36123618
// external linking. This link can fail for things like
@@ -3635,7 +3641,9 @@ func (b *Builder) dynimport(a *Action, p *load.Package, objdir, importGo, cgoExe
36353641
// Run SWIG on all SWIG input files.
36363642
// TODO: Don't build a shared library, once SWIG emits the necessary
36373643
// pragmas for external linking.
3638-
func (b *Builder) swig(a *Action, p *load.Package, objdir string, pcCFLAGS []string) (outGo, outC, outCXX []string, err error) {
3644+
func (b *Builder) swig(a *Action, objdir string, pcCFLAGS []string) (outGo, outC, outCXX []string, err error) {
3645+
p := a.Package
3646+
36393647
if err := b.swigVersionCheck(); err != nil {
36403648
return nil, nil, nil, err
36413649
}
@@ -3646,7 +3654,7 @@ func (b *Builder) swig(a *Action, p *load.Package, objdir string, pcCFLAGS []str
36463654
}
36473655

36483656
for _, f := range p.SwigFiles {
3649-
goFile, cFile, err := b.swigOne(a, p, f, objdir, pcCFLAGS, false, intgosize)
3657+
goFile, cFile, err := b.swigOne(a, f, objdir, pcCFLAGS, false, intgosize)
36503658
if err != nil {
36513659
return nil, nil, nil, err
36523660
}
@@ -3658,7 +3666,7 @@ func (b *Builder) swig(a *Action, p *load.Package, objdir string, pcCFLAGS []str
36583666
}
36593667
}
36603668
for _, f := range p.SwigCXXFiles {
3661-
goFile, cxxFile, err := b.swigOne(a, p, f, objdir, pcCFLAGS, true, intgosize)
3669+
goFile, cxxFile, err := b.swigOne(a, f, objdir, pcCFLAGS, true, intgosize)
36623670
if err != nil {
36633671
return nil, nil, nil, err
36643672
}
@@ -3781,7 +3789,9 @@ func (b *Builder) swigIntSize(objdir string) (intsize string, err error) {
37813789
}
37823790

37833791
// Run SWIG on one SWIG input file.
3784-
func (b *Builder) swigOne(a *Action, p *load.Package, file, objdir string, pcCFLAGS []string, cxx bool, intgosize string) (outGo, outC string, err error) {
3792+
func (b *Builder) swigOne(a *Action, file, objdir string, pcCFLAGS []string, cxx bool, intgosize string) (outGo, outC string, err error) {
3793+
p := a.Package
3794+
37853795
cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, _, _, err := b.CFlags(p)
37863796
if err != nil {
37873797
return "", "", err
@@ -3838,7 +3848,7 @@ func (b *Builder) swigOne(a *Action, p *load.Package, file, objdir string, pcCFL
38383848
if err != nil && (bytes.Contains(out, []byte("-intgosize")) || bytes.Contains(out, []byte("-cgo"))) {
38393849
return "", "", errors.New("must have SWIG version >= 3.0.6")
38403850
}
3841-
if err := b.reportCmd(a, p, "", "", out, err); err != nil {
3851+
if err := b.reportCmd(a, nil, "", "", out, err); err != nil {
38423852
return "", "", err
38433853
}
38443854

0 commit comments

Comments
 (0)