cmd/go/internal/cfg: read default CC and CXX from Go source code.
Fixes golang/go#23965
Change-Id: I8f73a26a58c631d92faf73473a1cec821d3b37a7
Reviewed-on: https://go-review.googlesource.com/109975
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/vendor/cmd/go/internal/cfg/cfg.go b/vendor/cmd/go/internal/cfg/cfg.go
index 5093c28..03a4746 100644
--- a/vendor/cmd/go/internal/cfg/cfg.go
+++ b/vendor/cmd/go/internal/cfg/cfg.go
@@ -86,6 +86,9 @@
// Used in envcmd.MkEnv and build ID computations.
GOARM, GO386, GOMIPS = objabi()
+
+ // C and C++ compilers
+ CC, CXX = compilers()
)
// Update build context to use our computed GOROOT.
@@ -121,6 +124,34 @@
return find("GOARM"), find("GO386"), find("GOMIPS")
}
+func compilers() (CC, CXX string) {
+ data, err := ioutil.ReadFile(filepath.Join(GOROOT, "src/cmd/go/internal/cfg/zdefaultcc.go"))
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "vgo compilers: %v\n", err)
+ }
+
+ find := func(key string) string {
+ if env := os.Getenv(key); env != "" {
+ return env
+ }
+ fi := bytes.Index(data, []byte("Default"+key+"(goos, goarch string)"))
+ if fi < 0 {
+ fmt.Fprintf(os.Stderr, "vgo compilers: cannot find %s\n", key)
+ os.Exit(2)
+ }
+ i := bytes.Index(data[fi:], []byte("\treturn "))
+ if i < 0 {
+ fmt.Fprintf(os.Stderr, "vgo compilers: cannot find %s\n", key)
+ os.Exit(2)
+ }
+ line := data[fi+i:]
+ line = line[bytes.IndexByte(line, '"')+1:]
+ return string(line[:bytes.IndexByte(line, '"')])
+ }
+
+ return find("CC"), find("CXX")
+}
+
func findGOROOT() string {
goroot := findGOROOT1()
_, err := os.Stat(filepath.Join(goroot, "api/go1.10.txt"))
diff --git a/vendor/cmd/go/internal/cfg/zdefaultcc.go b/vendor/cmd/go/internal/cfg/zdefaultcc.go
index 28761b7..215d777 100644
--- a/vendor/cmd/go/internal/cfg/zdefaultcc.go
+++ b/vendor/cmd/go/internal/cfg/zdefaultcc.go
@@ -3,13 +3,14 @@
package cfg
const DefaultPkgConfig = `pkg-config`
+
func DefaultCC(goos, goarch string) string {
- switch goos+`/`+goarch {
+ switch goos + `/` + goarch {
}
- return "clang"
+ return CC
}
func DefaultCXX(goos, goarch string) string {
- switch goos+`/`+goarch {
+ switch goos + `/` + goarch {
}
- return "clang++"
+ return CXX
}