OSX: Use the oldest SDK, but always set our target to 10.8

Build binaries usable on older machines even if older SDKs are not
installed. Older SDKs can no longer be installed on newer Xcode
versions.

Port of https://android-review.googlesource.com/207242

Change-Id: If66f2eef7593bce9fb858fc7b71369f55dd362e4
diff --git a/cc/x86_darwin_host.go b/cc/x86_darwin_host.go
index 9a7b68a..bff9a03 100644
--- a/cc/x86_darwin_host.go
+++ b/cc/x86_darwin_host.go
@@ -79,10 +79,10 @@
 	darwinX8664ClangLdflags = clangFilterUnknownCflags(darwinX8664Ldflags)
 
 	darwinSupportedSdkVersions = []string{
-		"macosx10.8",
-		"macosx10.9",
-		"macosx10.10",
-		"macosx10.11",
+		"10.8",
+		"10.9",
+		"10.10",
+		"10.11",
 	}
 )
 
@@ -99,9 +99,7 @@
 	pctx.VariableFunc("macSdkRoot", func(config interface{}) (string, error) {
 		return xcrunSdk(config.(common.Config), "--show-sdk-path")
 	})
-	pctx.VariableFunc("macSdkVersion", func(config interface{}) (string, error) {
-		return xcrunSdk(config.(common.Config), "--show-sdk-version")
-	})
+	pctx.StaticVariable("macSdkVersion", darwinSupportedSdkVersions[0])
 	pctx.VariableFunc("macArPath", func(config interface{}) (string, error) {
 		bytes, err := exec.Command("xcrun", "--find", "ar").Output()
 		return strings.TrimSpace(string(bytes)), err
@@ -138,7 +136,7 @@
 
 func xcrunSdk(config common.Config, arg string) (string, error) {
 	if selected := config.Getenv("MAC_SDK_VERSION"); selected != "" {
-		if !inList("macosx"+selected, darwinSupportedSdkVersions) {
+		if !inList(selected, darwinSupportedSdkVersions) {
 			return "", fmt.Errorf("MAC_SDK_VERSION %s isn't supported: %q", selected, darwinSupportedSdkVersions)
 		}
 
@@ -150,7 +148,7 @@
 	}
 
 	for _, sdk := range darwinSupportedSdkVersions {
-		bytes, err := exec.Command("xcrun", "--sdk", sdk, arg).Output()
+		bytes, err := exec.Command("xcrun", "--sdk", "macosx"+sdk, arg).Output()
 		if err == nil {
 			return strings.TrimSpace(string(bytes)), err
 		}