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:25 -0800
committerRoland Shoemaker <roland@golang.org>2021-01-20 09:56:25 -0800
commit9cf003256bc39608db03d7b82f7120715a0fca43 (patch)
treeac8000b9c013a4720ec32d17852a008a44be8f94 /src/cmd/go/internal/work/exec.go
parent2bb8e5a94e8ad214ab78dc4b953c98e9f3881d09 (diff)
parentccb4f250bd7e382e50824c36ec5a3e1a57dcf11a (diff)
downloadgo-9cf003256bc39608db03d7b82f7120715a0fca43.tar.gz
go-9cf003256bc39608db03d7b82f7120715a0fca43.zip
[dev.boringcrypto.go1.14] all: merge go1.14.14 into dev.boringcrypto.go1.14
Change-Id: I3f120b8b0f009108457de97302700b45757a557c
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 a87bc802c1..8230d85938 100644
--- a/src/cmd/go/internal/work/exec.go
+++ b/src/cmd/go/internal/work/exec.go
@@ -16,13 +16,13 @@ import (
"encoding/json"
"errors"
"fmt"
+ exec "internal/execabs"
"internal/lazyregexp"
"io"
"io/ioutil"
"log"
"math/rand"
"os"
- "os/exec"
"path/filepath"
"regexp"
"runtime"
@@ -1075,10 +1075,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
@@ -1920,6 +1918,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)
@@ -1979,6 +1980,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 == "".
@@ -2524,13 +2543,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" {
@@ -2745,7 +2764,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.