@@ -594,7 +594,7 @@ func (b *Builder) build(ctx context.Context, a *Action) (err error) {
594
594
var objects , cgoObjects , pcCFLAGS , pcLDFLAGS []string
595
595
596
596
if p .UsesCgo () || p .UsesSwig () {
597
- if pcCFLAGS , pcLDFLAGS , err = b .getPkgConfigFlags (p ); err != nil {
597
+ if pcCFLAGS , pcLDFLAGS , err = b .getPkgConfigFlags (a ); err != nil {
598
598
return
599
599
}
600
600
}
@@ -868,15 +868,7 @@ OverlayLoop:
868
868
// Compile Go.
869
869
objpkg := objdir + "_pkg_.a"
870
870
ofile , out , err := BuildToolchain .gc (b , a , objpkg , icfg .Bytes (), embedcfg , symabis , len (sfiles ) > 0 , gofiles )
871
- if len (out ) > 0 {
872
- output := b .processOutput (out )
873
- if err != nil {
874
- return formatOutput (b .WorkDir , p .Dir , p .ImportPath , p .Desc (), output )
875
- } else {
876
- b .showOutput (a , p .Dir , p .Desc (), output )
877
- }
878
- }
879
- if err != nil {
871
+ if err := b .reportCmd (a , nil , "" , "" , out , err ); err != nil {
880
872
return err
881
873
}
882
874
if ofile != objpkg {
@@ -1000,8 +992,11 @@ func (b *Builder) checkDirectives(a *Action) error {
1000
992
}
1001
993
}
1002
994
if msg != nil {
1003
- return formatOutput (b .WorkDir , p .Dir , p .ImportPath , p .Desc (), b .processOutput (msg .Bytes ()))
1004
-
995
+ // We pass a non-nil error to reportCmd to trigger the failure reporting
996
+ // path, but the content of the error doesn't matter because msg is
997
+ // non-empty.
998
+ err := errors .New ("invalid directive" )
999
+ return b .reportCmd (a , nil , "" , "" , msg .Bytes (), err )
1005
1000
}
1006
1001
return nil
1007
1002
}
@@ -1616,8 +1611,9 @@ func splitPkgConfigOutput(out []byte) ([]string, error) {
1616
1611
return flags , nil
1617
1612
}
1618
1613
1619
- // Calls pkg-config if needed and returns the cflags/ldflags needed to build the package.
1620
- func (b * Builder ) getPkgConfigFlags (p * load.Package ) (cflags , ldflags []string , err error ) {
1614
+ // Calls pkg-config if needed and returns the cflags/ldflags needed to build a's package.
1615
+ func (b * Builder ) getPkgConfigFlags (a * Action ) (cflags , ldflags []string , err error ) {
1616
+ p := a .Package
1621
1617
if pcargs := p .CgoPkgConfig ; len (pcargs ) > 0 {
1622
1618
// pkg-config permits arguments to appear anywhere in
1623
1619
// the command line. Move them all to the front, before --.
@@ -1640,8 +1636,8 @@ func (b *Builder) getPkgConfigFlags(p *load.Package) (cflags, ldflags []string,
1640
1636
var out []byte
1641
1637
out , err = b .runOut (nil , p .Dir , nil , b .PkgconfigCmd (), "--cflags" , pcflags , "--" , pkgs )
1642
1638
if err != nil {
1643
- err = formatOutput ( b . WorkDir , p . Dir , p . ImportPath , b . PkgconfigCmd ()+ " --cflags " + strings .Join (pcflags , " " )+ " -- " + strings .Join (pkgs , " " ), string ( out ) + err . Error () )
1644
- return nil , nil , err
1639
+ desc := b . PkgconfigCmd () + " --cflags " + strings .Join (pcflags , " " ) + " -- " + strings .Join (pkgs , " " )
1640
+ return nil , nil , b . reportCmd ( a , nil , desc , "" , out , err )
1645
1641
}
1646
1642
if len (out ) > 0 {
1647
1643
cflags , err = splitPkgConfigOutput (bytes .TrimSpace (out ))
@@ -1654,8 +1650,8 @@ func (b *Builder) getPkgConfigFlags(p *load.Package) (cflags, ldflags []string,
1654
1650
}
1655
1651
out , err = b .runOut (nil , p .Dir , nil , b .PkgconfigCmd (), "--libs" , pcflags , "--" , pkgs )
1656
1652
if err != nil {
1657
- err = formatOutput ( b . WorkDir , p . Dir , p . ImportPath , b . PkgconfigCmd ()+ " --libs " + strings .Join (pcflags , " " )+ " -- " + strings .Join (pkgs , " " ), string ( out ) + err . Error () )
1658
- return nil , nil , err
1653
+ desc := b . PkgconfigCmd () + " --libs " + strings .Join (pcflags , " " ) + " -- " + strings .Join (pkgs , " " )
1654
+ return nil , nil , b . reportCmd ( a , nil , desc , "" , out , err )
1659
1655
}
1660
1656
if len (out ) > 0 {
1661
1657
// We need to handle path with spaces so that C:/Program\ Files can pass
@@ -2511,17 +2507,10 @@ var cgoTypeSigRe = lazyregexp.New(`\b_C2?(type|func|var|macro)_\B`)
2511
2507
// and returns a non-nil error.
2512
2508
func (b * Builder ) run (a * Action , dir string , desc string , env []string , cmdargs ... any ) error {
2513
2509
out , err := b .runOut (a , dir , env , cmdargs ... )
2514
- if len (out ) > 0 {
2515
- if desc == "" {
2516
- desc = b .fmtcmd (dir , "%s" , strings .Join (str .StringList (cmdargs ... ), " " ))
2517
- }
2518
- if err != nil {
2519
- err = formatOutput (b .WorkDir , dir , a .Package .ImportPath , desc , b .processOutput (out ))
2520
- } else {
2521
- b .showOutput (a , dir , desc , b .processOutput (out ))
2522
- }
2510
+ if desc == "" {
2511
+ desc = b .fmtcmd (dir , "%s" , strings .Join (str .StringList (cmdargs ... ), " " ))
2523
2512
}
2524
- return err
2513
+ return b . reportCmd ( a , nil , desc , dir , out , err )
2525
2514
}
2526
2515
2527
2516
// processOutput prepares the output of runOut to be output to the console.
@@ -2870,38 +2859,33 @@ func (b *Builder) ccompile(a *Action, p *load.Package, outfile string, flags []s
2870
2859
overlayPath = p
2871
2860
}
2872
2861
output , err := b .runOut (a , filepath .Dir (overlayPath ), b .cCompilerEnv (), compiler , flags , "-o" , outfile , "-c" , filepath .Base (overlayPath ))
2873
- if len (output ) > 0 {
2874
- // On FreeBSD 11, when we pass -g to clang 3.8 it
2875
- // invokes its internal assembler with -dwarf-version=2.
2876
- // When it sees .section .note.GNU-stack, it warns
2877
- // "DWARF2 only supports one section per compilation unit".
2878
- // This warning makes no sense, since the section is empty,
2879
- // but it confuses people.
2880
- // We work around the problem by detecting the warning
2881
- // and dropping -g and trying again.
2882
- if bytes .Contains (output , []byte ("DWARF2 only supports one section per compilation unit" )) {
2883
- newFlags := make ([]string , 0 , len (flags ))
2884
- for _ , f := range flags {
2885
- if ! strings .HasPrefix (f , "-g" ) {
2886
- newFlags = append (newFlags , f )
2887
- }
2888
- }
2889
- if len (newFlags ) < len (flags ) {
2890
- return b .ccompile (a , p , outfile , newFlags , file , compiler )
2891
- }
2892
- }
2893
2862
2894
- if err == nil && os .Getenv ("GO_BUILDER_NAME" ) != "" {
2895
- output = append (output , "C compiler warning promoted to error on Go builders\n " ... )
2896
- err = errors .New ("warning promoted to error" )
2863
+ // On FreeBSD 11, when we pass -g to clang 3.8 it
2864
+ // invokes its internal assembler with -dwarf-version=2.
2865
+ // When it sees .section .note.GNU-stack, it warns
2866
+ // "DWARF2 only supports one section per compilation unit".
2867
+ // This warning makes no sense, since the section is empty,
2868
+ // but it confuses people.
2869
+ // We work around the problem by detecting the warning
2870
+ // and dropping -g and trying again.
2871
+ if bytes .Contains (output , []byte ("DWARF2 only supports one section per compilation unit" )) {
2872
+ newFlags := make ([]string , 0 , len (flags ))
2873
+ for _ , f := range flags {
2874
+ if ! strings .HasPrefix (f , "-g" ) {
2875
+ newFlags = append (newFlags , f )
2876
+ }
2897
2877
}
2898
- if err != nil {
2899
- err = formatOutput (b .WorkDir , p .Dir , p .ImportPath , p .Desc (), b .processOutput (output ))
2900
- } else {
2901
- b .showOutput (a , p .Dir , p .Desc (), b .processOutput (output ))
2878
+ if len (newFlags ) < len (flags ) {
2879
+ return b .ccompile (a , p , outfile , newFlags , file , compiler )
2902
2880
}
2903
2881
}
2904
- return err
2882
+
2883
+ if len (output ) > 0 && err == nil && os .Getenv ("GO_BUILDER_NAME" ) != "" {
2884
+ output = append (output , "C compiler warning promoted to error on Go builders\n " ... )
2885
+ err = errors .New ("warning promoted to error" )
2886
+ }
2887
+
2888
+ return b .reportCmd (a , p , "" , "" , output , err )
2905
2889
}
2906
2890
2907
2891
// gccld runs the gcc linker to create an executable from a set of object files.
@@ -2915,7 +2899,6 @@ func (b *Builder) gccld(a *Action, p *load.Package, objdir, outfile string, flag
2915
2899
}
2916
2900
2917
2901
cmdargs := []any {cmd , "-o" , outfile , objs , flags }
2918
- dir := p .Dir
2919
2902
out , err := b .runOut (a , base .Cwd (), b .cCompilerEnv (), cmdargs ... )
2920
2903
2921
2904
if len (out ) > 0 {
@@ -2951,9 +2934,11 @@ func (b *Builder) gccld(a *Action, p *load.Package, objdir, outfile string, flag
2951
2934
save = append (save , line )
2952
2935
}
2953
2936
out = bytes .Join (save , nil )
2954
- if len (out ) > 0 && (cfg .BuildN || cfg .BuildX ) {
2955
- b .showOutput (nil , dir , p .ImportPath , b .processOutput (out ))
2956
- }
2937
+ }
2938
+ // Note that failure is an expected outcome here, so we report output only
2939
+ // in debug mode and don't report the error.
2940
+ if cfg .BuildN || cfg .BuildX {
2941
+ b .reportCmd (a , p , "" , "" , out , nil )
2957
2942
}
2958
2943
return err
2959
2944
}
@@ -3493,7 +3478,7 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
3493
3478
if pkgpath := gccgoPkgpath (p ); pkgpath != "" {
3494
3479
cgoflags = append (cgoflags , "-gccgopkgpath=" + pkgpath )
3495
3480
}
3496
- if ! BuildToolchain .(gccgoToolchain ).supportsCgoIncomplete (b ) {
3481
+ if ! BuildToolchain .(gccgoToolchain ).supportsCgoIncomplete (b , a ) {
3497
3482
cgoflags = append (cgoflags , "-gccgo_define_cgoincomplete" )
3498
3483
}
3499
3484
}
@@ -3990,18 +3975,11 @@ func (b *Builder) swigOne(a *Action, p *load.Package, file, objdir string, pcCFL
3990
3975
}
3991
3976
3992
3977
out , err := b .runOut (a , p .Dir , nil , "swig" , args , file )
3993
- if err != nil {
3994
- if len (out ) > 0 {
3995
- if bytes .Contains (out , []byte ("-intgosize" )) || bytes .Contains (out , []byte ("-cgo" )) {
3996
- return "" , "" , errors .New ("must have SWIG version >= 3.0.6" )
3997
- }
3998
- // swig error
3999
- err = formatOutput (b .WorkDir , p .Dir , p .ImportPath , p .Desc (), b .processOutput (out ))
4000
- }
4001
- return "" , "" , err
3978
+ if err != nil && (bytes .Contains (out , []byte ("-intgosize" )) || bytes .Contains (out , []byte ("-cgo" ))) {
3979
+ return "" , "" , errors .New ("must have SWIG version >= 3.0.6" )
4002
3980
}
4003
- if len ( out ) > 0 {
4004
- b . showOutput ( a , p . Dir , p . Desc (), b . processOutput ( out )) // swig warning
3981
+ if err := b . reportCmd ( a , p , "" , "" , out , err ); err != nil {
3982
+ return "" , "" , err
4005
3983
}
4006
3984
4007
3985
// If the input was x.swig, the output is x.go in the objdir.
0 commit comments