// compilerEnvLookup returns the compiler settings for goos/goarch in map m.
// kind is "CC" or "CXX".
func compilerEnvLookup(kind string, m map[string]string, goos, goarch string) string {
+ if !needCC() {
+ return ""
+ }
if cc := m[goos+"/"+goarch]; cc != "" {
return cc
}
}
// Remove go_bootstrap now that we're done.
- xremove(pathf("%s/go_bootstrap", tooldir))
+ xremove(pathf("%s/go_bootstrap"+exe, tooldir))
if goos == "android" {
// Make sure the exec wrapper will sync a fresh $GOROOT to the device.
}
func needCC() bool {
- switch os.Getenv("CGO_ENABLED") {
- case "1":
- return true
- case "0":
- return false
- }
- return cgoEnabled[gohostos+"/"+gohostarch]
+ return os.Getenv("CGO_ENABLED") == "1"
}
func checkCC() {
}
sort.Strings(keys)
for _, k := range keys {
- fmt.Fprintf(&buf, "\tcase %q:\n\t\treturn %q\n", k, defaultcc[k])
+ fmt.Fprintf(&buf, "\tcase %s:\n\t\treturn %s\n", quote(k), quote(defaultcc[k]))
}
fmt.Fprintf(&buf, "\t}\n")
if cc := defaultcc[""]; cc != "" {
- fmt.Fprintf(&buf, "\treturn %q\n", cc)
+ fmt.Fprintf(&buf, "\treturn %s\n", quote(cc))
} else {
clang, gcc := "clang", "gcc"
if strings.HasSuffix(name, "CXX") {
if i > 0 {
fmt.Fprintf(&buf, ", ")
}
- fmt.Fprintf(&buf, "%q", os)
+ fmt.Fprintf(&buf, "%s", quote(os))
}
fmt.Fprintf(&buf, ":\n")
- fmt.Fprintf(&buf, "\t\treturn %q\n", clang)
+ fmt.Fprintf(&buf, "\t\treturn %s\n", quote(clang))
fmt.Fprintf(&buf, "\t}\n")
- fmt.Fprintf(&buf, "\treturn %q\n", gcc)
+ fmt.Fprintf(&buf, "\treturn %s\n", quote(gcc))
}
fmt.Fprintf(&buf, "}\n")
fmt.Fprintf(&buf, "package cfg\n\n")
fmt.Fprintf(&buf, "var OSArchSupportsCgo = map[string]bool{\n")
for _, plat := range list {
- fmt.Fprintf(&buf, "\t%q: %v,\n", plat, cgoEnabled[plat])
+ fmt.Fprintf(&buf, "\t%s: %v,\n", quote(plat), cgoEnabled[plat])
}
fmt.Fprintf(&buf, "}\n")
fmt.Fprintln(&buf)
fmt.Fprintf(&buf, "package build\n")
fmt.Fprintln(&buf)
- fmt.Fprintf(&buf, "const defaultCGO_ENABLED = %q\n", os.Getenv("CGO_ENABLED"))
+ fmt.Fprintf(&buf, "const defaultCGO_ENABLED = %s\n", quote(os.Getenv("CGO_ENABLED")))
fmt.Fprintln(&buf)
fmt.Fprintf(&buf, "var cgoEnabled = map[string]bool{\n")
for _, plat := range list {
- fmt.Fprintf(&buf, "\t%q: true,\n", plat)
+ fmt.Fprintf(&buf, "\t%s: true,\n", quote(plat))
}
fmt.Fprintf(&buf, "}\n")
fmt.Fprintln(&buf)
fmt.Fprintf(&buf, "package tzdata\n")
fmt.Fprintln(&buf)
- fmt.Fprintf(&buf, "const zipdata = %q\n", zip)
+ fmt.Fprintf(&buf, "const zipdata = %s\n", quote(zip))
writefile(buf.String(), file, writeSkipSame)
}
+
+// quote is like strconv.Quote but simpler and has output
+// that does not depend on the exact Go bootstrap version.
+func quote(s string) string {
+ const hex = "0123456789abcdef"
+ var out strings.Builder
+ out.WriteByte('"')
+ for i := 0; i < len(s); i++ {
+ c := s[i]
+ if 0x20 <= c && c <= 0x7E && c != '"' && c != '\\' {
+ out.WriteByte(c)
+ } else {
+ out.WriteByte('\\')
+ out.WriteByte('x')
+ out.WriteByte(hex[c>>4])
+ out.WriteByte(hex[c&0xf])
+ }
+ }
+ out.WriteByte('"')
+ return out.String()
+}