@@ -1080,10 +1080,8 @@ func (b *Builder) vet(a *Action) error {
1080
1080
return err
1081
1081
}
1082
1082
1083
- env := b .cCompilerEnv ()
1084
- if cfg .BuildToolchainName == "gccgo" {
1085
- env = append (env , "GCCGO=" + BuildToolchain .compiler ())
1086
- }
1083
+ // TODO(rsc): Why do we pass $GCCGO to go vet?
1084
+ env := b .cgoEnv ()
1087
1085
1088
1086
p := a .Package
1089
1087
tool := VetTool
@@ -2014,6 +2012,24 @@ func (b *Builder) cCompilerEnv() []string {
2014
2012
return []string {"TERM=dumb" }
2015
2013
}
2016
2014
2015
+ // cgoEnv returns environment variables to set when running cgo.
2016
+ // Some of these pass through to cgo running the C compiler,
2017
+ // so it includes cCompilerEnv.
2018
+ func (b * Builder ) cgoEnv () []string {
2019
+ b .cgoEnvOnce .Do (func () {
2020
+ cc , err := exec .LookPath (b .ccExe ()[0 ])
2021
+ if err != nil || filepath .Base (cc ) == cc { // reject relative path
2022
+ cc = "/missing-cc"
2023
+ }
2024
+ gccgo := GccgoBin
2025
+ if filepath .Base (gccgo ) == gccgo { // reject relative path
2026
+ gccgo = "/missing-gccgo"
2027
+ }
2028
+ b .cgoEnvCache = append (b .cCompilerEnv (), "CC=" + cc , "GCCGO=" + gccgo )
2029
+ })
2030
+ return b .cgoEnvCache
2031
+ }
2032
+
2017
2033
// mkdir makes the named directory.
2018
2034
func (b * Builder ) Mkdir (dir string ) error {
2019
2035
// Make Mkdir(a.Objdir) a no-op instead of an error when a.Objdir == "".
@@ -2603,13 +2619,13 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
2603
2619
// along to the host linker. At this point in the code, cgoLDFLAGS
2604
2620
// consists of the original $CGO_LDFLAGS (unchecked) and all the
2605
2621
// flags put together from source code (checked).
2606
- cgoenv := b .cCompilerEnv ()
2622
+ cgoenv := b .cgoEnv ()
2607
2623
if len (cgoLDFLAGS ) > 0 {
2608
2624
flags := make ([]string , len (cgoLDFLAGS ))
2609
2625
for i , f := range cgoLDFLAGS {
2610
2626
flags [i ] = strconv .Quote (f )
2611
2627
}
2612
- cgoenv = [] string { "CGO_LDFLAGS=" + strings .Join (flags , " " )}
2628
+ cgoenv = append ( cgoenv , "CGO_LDFLAGS=" + strings .Join (flags , " " ))
2613
2629
}
2614
2630
2615
2631
if cfg .BuildToolchainName == "gccgo" {
@@ -2824,7 +2840,7 @@ func (b *Builder) dynimport(a *Action, p *load.Package, objdir, importGo, cgoExe
2824
2840
if p .Standard && p .ImportPath == "runtime/cgo" {
2825
2841
cgoflags = []string {"-dynlinker" } // record path to dynamic linker
2826
2842
}
2827
- return b .run (a , p .Dir , p .ImportPath , b .cCompilerEnv (), cfg .BuildToolexec , cgoExe , "-dynpackage" , p .Name , "-dynimport" , dynobj , "-dynout" , importGo , cgoflags )
2843
+ return b .run (a , p .Dir , p .ImportPath , b .cgoEnv (), cfg .BuildToolexec , cgoExe , "-dynpackage" , p .Name , "-dynimport" , dynobj , "-dynout" , importGo , cgoflags )
2828
2844
}
2829
2845
2830
2846
// Run SWIG on all SWIG input files.
0 commit comments