if ctxt.CgoEnabled {
if os.Getenv("CC") == "" {
cc := DefaultCC(ctxt.GOOS, ctxt.GOARCH)
- if _, err := exec.LookPath(cc); err != nil {
+ if filepath.IsAbs(cc) {
+ if _, err := os.Stat(cc); os.IsNotExist(err) {
+ // The default CC is an absolute path that doesn't exist.
+ // (Perhaps make.bash was run on a system with a C compiler
+ // installed, and the current system doesn't have it there.)
+ ctxt.CgoEnabled = false
+ }
+ } else if _, err := exec.LookPath(cc); err != nil {
ctxt.CgoEnabled = false
}
}
package main_test
import (
+ "cmd/go/internal/cfg"
"cmd/go/internal/script"
"cmd/go/internal/script/scripttest"
"errors"
return script.OnceCondition(summary, func() (bool, error) { return f(), nil })
}
+ add("abscc", script.Condition("default $CC path is absolute and exists", defaultCCIsAbsolute))
add("asan", sysCondition("-asan", platform.ASanSupported, true))
add("buildmode", script.PrefixCondition("go supports -buildmode=<suffix>", hasBuildmode))
add("case-sensitive", script.OnceCondition("$WORK filesystem is case-sensitive", isCaseSensitive))
return conds
}
+func defaultCCIsAbsolute(s *script.State) (bool, error) {
+ GOOS, _ := s.LookupEnv("GOOS")
+ GOARCH, _ := s.LookupEnv("GOARCH")
+ defaultCC := cfg.DefaultCC(GOOS, GOARCH)
+ if filepath.IsAbs(defaultCC) {
+ if _, err := os.Stat(defaultCC); err == nil {
+ return true, nil
+ }
+ }
+ return false, nil
+}
+
func isMismatchedGoroot(s *script.State) (bool, error) {
gorootFinal, _ := s.LookupEnv("GOROOT_FINAL")
if gorootFinal == "" {
go env CGO_ENABLED
stdout 1
-# Clearing CC and removing everything but Go from the PATH should disable cgo: no C compiler anymore.
+# Clearing CC and removing everything but Go from the PATH should usually
+# disable cgo: no C compiler anymore (unless the baked-in defaultCC is an
+# absolute path and exists.
env CC=
env PATH=$GOROOT/bin
go env CGO_ENABLED
-stdout 0
+[!abscc] stdout 0
+[abscc] stdout 1
# Setting CC should re-enable cgo.
env CC=cc