@@ -631,7 +631,7 @@ OverlayLoop:
631
631
// Each run will generate two files, a .go file and a .c or .cxx file.
632
632
// The .go file will use import "C" and is to be processed by cgo.
633
633
if p .UsesSwig () {
634
- outGo , outC , outCXX , err := b .swig (a , p , objdir , pcCFLAGS )
634
+ outGo , outC , outCXX , err := b .swig (a , objdir , pcCFLAGS )
635
635
if err != nil {
636
636
return err
637
637
}
@@ -2648,22 +2648,26 @@ func (noToolchain) cc(b *Builder, a *Action, ofile, cfile string) error {
2648
2648
}
2649
2649
2650
2650
// 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 ))
2653
2654
}
2654
2655
2655
2656
// 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 ))
2658
2660
}
2659
2661
2660
2662
// 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 ))
2663
2666
}
2664
2667
2665
2668
// 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
2667
2671
file = mkAbs (p .Dir , file )
2668
2672
outfile = mkAbs (p .Dir , outfile )
2669
2673
@@ -2746,7 +2750,7 @@ func (b *Builder) ccompile(a *Action, p *load.Package, outfile string, flags []s
2746
2750
}
2747
2751
}
2748
2752
if len (newFlags ) < len (flags ) {
2749
- return b .ccompile (a , p , outfile , newFlags , file , compiler )
2753
+ return b .ccompile (a , outfile , newFlags , file , compiler )
2750
2754
}
2751
2755
}
2752
2756
@@ -2755,12 +2759,13 @@ func (b *Builder) ccompile(a *Action, p *load.Package, outfile string, flags []s
2755
2759
err = errors .New ("warning promoted to error" )
2756
2760
}
2757
2761
2758
- return b .reportCmd (a , p , "" , "" , output , err )
2762
+ return b .reportCmd (a , nil , "" , "" , output , err )
2759
2763
}
2760
2764
2761
2765
// gccld runs the gcc linker to create an executable from a set of object files.
2762
2766
// 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
2764
2769
var cmd []string
2765
2770
if len (p .CXXFiles ) > 0 || len (p .SwigCXXFiles ) > 0 {
2766
2771
cmd = b .GxxCmd (p .Dir , objdir )
@@ -2808,7 +2813,7 @@ func (b *Builder) gccld(a *Action, p *load.Package, objdir, outfile string, flag
2808
2813
// Note that failure is an expected outcome here, so we report output only
2809
2814
// in debug mode and don't report the error.
2810
2815
if cfg .BuildN || cfg .BuildX {
2811
- b .reportCmd (a , p , "" , "" , out , nil )
2816
+ b .reportCmd (a , nil , "" , "" , out , nil )
2812
2817
}
2813
2818
return err
2814
2819
}
@@ -3391,15 +3396,15 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
3391
3396
cflags := str .StringList (cgoCPPFLAGS , cgoCFLAGS )
3392
3397
for _ , cfile := range cfiles {
3393
3398
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 {
3395
3400
return nil , nil , err
3396
3401
}
3397
3402
outObj = append (outObj , ofile )
3398
3403
}
3399
3404
3400
3405
for _ , file := range gccfiles {
3401
3406
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 {
3403
3408
return nil , nil , err
3404
3409
}
3405
3410
outObj = append (outObj , ofile )
@@ -3408,15 +3413,15 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
3408
3413
cxxflags := str .StringList (cgoCPPFLAGS , cgoCXXFLAGS )
3409
3414
for _ , file := range gxxfiles {
3410
3415
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 {
3412
3417
return nil , nil , err
3413
3418
}
3414
3419
outObj = append (outObj , ofile )
3415
3420
}
3416
3421
3417
3422
for _ , file := range mfiles {
3418
3423
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 {
3420
3425
return nil , nil , err
3421
3426
}
3422
3427
outObj = append (outObj , ofile )
@@ -3425,7 +3430,7 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
3425
3430
fflags := str .StringList (cgoCPPFLAGS , cgoFFLAGS )
3426
3431
for _ , file := range ffiles {
3427
3432
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 {
3429
3434
return nil , nil , err
3430
3435
}
3431
3436
outObj = append (outObj , ofile )
@@ -3434,7 +3439,7 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
3434
3439
switch cfg .BuildToolchainName {
3435
3440
case "gc" :
3436
3441
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 )
3438
3443
if err != nil {
3439
3444
return nil , nil , err
3440
3445
}
@@ -3558,10 +3563,11 @@ func flagsNotCompatibleWithInternalLinking(sourceList []string, flagListList [][
3558
3563
// dynamically imported by the object files outObj.
3559
3564
// dynOutGo, if not empty, is a new Go file to build as part of the package.
3560
3565
// 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
3562
3568
cfile := objdir + "_cgo_main.c"
3563
3569
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 {
3565
3571
return "" , "" , err
3566
3572
}
3567
3573
@@ -3606,7 +3612,7 @@ func (b *Builder) dynimport(a *Action, p *load.Package, objdir, importGo, cgoExe
3606
3612
ldflags = n
3607
3613
}
3608
3614
}
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 {
3610
3616
// We only need this information for internal linking.
3611
3617
// If this link fails, mark the object as requiring
3612
3618
// 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
3635
3641
// Run SWIG on all SWIG input files.
3636
3642
// TODO: Don't build a shared library, once SWIG emits the necessary
3637
3643
// 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
+
3639
3647
if err := b .swigVersionCheck (); err != nil {
3640
3648
return nil , nil , nil , err
3641
3649
}
@@ -3646,7 +3654,7 @@ func (b *Builder) swig(a *Action, p *load.Package, objdir string, pcCFLAGS []str
3646
3654
}
3647
3655
3648
3656
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 )
3650
3658
if err != nil {
3651
3659
return nil , nil , nil , err
3652
3660
}
@@ -3658,7 +3666,7 @@ func (b *Builder) swig(a *Action, p *load.Package, objdir string, pcCFLAGS []str
3658
3666
}
3659
3667
}
3660
3668
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 )
3662
3670
if err != nil {
3663
3671
return nil , nil , nil , err
3664
3672
}
@@ -3781,7 +3789,9 @@ func (b *Builder) swigIntSize(objdir string) (intsize string, err error) {
3781
3789
}
3782
3790
3783
3791
// 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
+
3785
3795
cgoCPPFLAGS , cgoCFLAGS , cgoCXXFLAGS , _ , _ , err := b .CFlags (p )
3786
3796
if err != nil {
3787
3797
return "" , "" , err
@@ -3838,7 +3848,7 @@ func (b *Builder) swigOne(a *Action, p *load.Package, file, objdir string, pcCFL
3838
3848
if err != nil && (bytes .Contains (out , []byte ("-intgosize" )) || bytes .Contains (out , []byte ("-cgo" ))) {
3839
3849
return "" , "" , errors .New ("must have SWIG version >= 3.0.6" )
3840
3850
}
3841
- if err := b .reportCmd (a , p , "" , "" , out , err ); err != nil {
3851
+ if err := b .reportCmd (a , nil , "" , "" , out , err ); err != nil {
3842
3852
return "" , "" , err
3843
3853
}
3844
3854
0 commit comments