aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/work/exec.go
diff options
context:
space:
mode:
authorRoland Shoemaker <roland@golang.org>2021-01-20 09:56:46 -0800
committerRoland Shoemaker <roland@golang.org>2021-01-20 09:56:46 -0800
commit79ea7a16d7e3bc36e98a4b7afd997bb315e80a1c (patch)
tree348f738736723bad4f3dbdf866e1b81d6c679dea /src/cmd/go/internal/work/exec.go
parentf78276931172f6781bd448a010b547a9517abe41 (diff)
parent2117ea9737bc9cb2e30cb087b76a283f68768819 (diff)
downloadgo-79ea7a16d7e3bc36e98a4b7afd997bb315e80a1c.tar.gz
go-79ea7a16d7e3bc36e98a4b7afd997bb315e80a1c.zip
[dev.boringcrypto.go1.15] all: merge go1.15.7 into dev.boringcrypto.go1.15
Change-Id: I2d5a481ef3862f558467c6d71f46e483cc50e1fe
Diffstat (limited to 'src/cmd/go/internal/work/exec.go')
-rw-r--r--src/cmd/go/internal/work/exec.go35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go
index dc0c4fc344..f5f9951afa 100644
--- a/src/cmd/go/internal/work/exec.go
+++ b/src/cmd/go/internal/work/exec.go
@@ -11,13 +11,13 @@ import (
"encoding/json"
"errors"
"fmt"
+ exec "internal/execabs"
"internal/lazyregexp"
"io"
"io/ioutil"
"log"
"math/rand"
"os"
- "os/exec"
"path/filepath"
"regexp"
"runtime"
@@ -1080,10 +1080,8 @@ func (b *Builder) vet(a *Action) error {
return err
}
- env := b.cCompilerEnv()
- if cfg.BuildToolchainName == "gccgo" {
- env = append(env, "GCCGO="+BuildToolchain.compiler())
- }
+ // TODO(rsc): Why do we pass $GCCGO to go vet?
+ env := b.cgoEnv()
p := a.Package
tool := VetTool
@@ -1955,6 +1953,9 @@ func (b *Builder) runOut(a *Action, dir string, env []string, cmdargs ...interfa
var buf bytes.Buffer
cmd := exec.Command(cmdline[0], cmdline[1:]...)
+ if cmd.Path != "" {
+ cmd.Args[0] = cmd.Path
+ }
cmd.Stdout = &buf
cmd.Stderr = &buf
cleanup := passLongArgsInResponseFiles(cmd)
@@ -2014,6 +2015,24 @@ func (b *Builder) cCompilerEnv() []string {
return []string{"TERM=dumb"}
}
+// cgoEnv returns environment variables to set when running cgo.
+// Some of these pass through to cgo running the C compiler,
+// so it includes cCompilerEnv.
+func (b *Builder) cgoEnv() []string {
+ b.cgoEnvOnce.Do(func() {
+ cc, err := exec.LookPath(b.ccExe()[0])
+ if err != nil || filepath.Base(cc) == cc { // reject relative path
+ cc = "/missing-cc"
+ }
+ gccgo := GccgoBin
+ if filepath.Base(gccgo) == gccgo { // reject relative path
+ gccgo = "/missing-gccgo"
+ }
+ b.cgoEnvCache = append(b.cCompilerEnv(), "CC="+cc, "GCCGO="+gccgo)
+ })
+ return b.cgoEnvCache
+}
+
// mkdir makes the named directory.
func (b *Builder) Mkdir(dir string) error {
// Make Mkdir(a.Objdir) a no-op instead of an error when a.Objdir == "".
@@ -2603,13 +2622,13 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
// along to the host linker. At this point in the code, cgoLDFLAGS
// consists of the original $CGO_LDFLAGS (unchecked) and all the
// flags put together from source code (checked).
- cgoenv := b.cCompilerEnv()
+ cgoenv := b.cgoEnv()
if len(cgoLDFLAGS) > 0 {
flags := make([]string, len(cgoLDFLAGS))
for i, f := range cgoLDFLAGS {
flags[i] = strconv.Quote(f)
}
- cgoenv = []string{"CGO_LDFLAGS=" + strings.Join(flags, " ")}
+ cgoenv = append(cgoenv, "CGO_LDFLAGS="+strings.Join(flags, " "))
}
if cfg.BuildToolchainName == "gccgo" {
@@ -2824,7 +2843,7 @@ func (b *Builder) dynimport(a *Action, p *load.Package, objdir, importGo, cgoExe
if p.Standard && p.ImportPath == "runtime/cgo" {
cgoflags = []string{"-dynlinker"} // record path to dynamic linker
}
- return b.run(a, p.Dir, p.ImportPath, b.cCompilerEnv(), cfg.BuildToolexec, cgoExe, "-dynpackage", p.Name, "-dynimport", dynobj, "-dynout", importGo, cgoflags)
+ return b.run(a, p.Dir, p.ImportPath, b.cgoEnv(), cfg.BuildToolexec, cgoExe, "-dynpackage", p.Name, "-dynimport", dynobj, "-dynout", importGo, cgoflags)
}
// Run SWIG on all SWIG input files.