Merge "Fix long mac test times; only initialize host settings once" am: 131db09396

Change-Id: Id5af2a56b4c6a69a481d495ae232f5e5416f79b3
This commit is contained in:
Treehugger Robot
2020-04-02 03:52:55 +00:00
committed by Automerger Merge Worker

View File

@@ -15,9 +15,11 @@
package config package config
import ( import (
"fmt"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strings" "strings"
"sync"
"android/soong/android" "android/soong/android"
) )
@@ -89,28 +91,20 @@ const (
) )
func init() { func init() {
pctx.VariableFunc("macSdkPath", func(ctx android.PackageVarContext) string {
xcodeselect := ctx.Config().HostSystemTool("xcode-select")
bytes, err := exec.Command(xcodeselect, "--print-path").Output()
if err != nil {
ctx.Errorf("xcode-select failed with: %q", err.Error())
}
return strings.TrimSpace(string(bytes))
})
pctx.VariableFunc("macSdkRoot", func(ctx android.PackageVarContext) string { pctx.VariableFunc("macSdkRoot", func(ctx android.PackageVarContext) string {
return xcrunSdk(ctx, "--show-sdk-path") return getMacTools(ctx).sdkRoot
}) })
pctx.StaticVariable("macMinVersion", "10.10") pctx.StaticVariable("macMinVersion", "10.10")
pctx.VariableFunc("MacArPath", func(ctx android.PackageVarContext) string { pctx.VariableFunc("MacArPath", func(ctx android.PackageVarContext) string {
return xcrun(ctx, "--find", "ar") return getMacTools(ctx).arPath
}) })
pctx.VariableFunc("MacStripPath", func(ctx android.PackageVarContext) string { pctx.VariableFunc("MacStripPath", func(ctx android.PackageVarContext) string {
return xcrun(ctx, "--find", "strip") return getMacTools(ctx).stripPath
}) })
pctx.VariableFunc("MacToolPath", func(ctx android.PackageVarContext) string { pctx.VariableFunc("MacToolPath", func(ctx android.PackageVarContext) string {
return filepath.Dir(xcrun(ctx, "--find", "ld")) return getMacTools(ctx).toolPath
}) })
pctx.StaticVariable("DarwinGccVersion", darwinGccVersion) pctx.StaticVariable("DarwinGccVersion", darwinGccVersion)
@@ -126,38 +120,66 @@ func init() {
pctx.StaticVariable("DarwinYasmFlags", "-f macho -m amd64") pctx.StaticVariable("DarwinYasmFlags", "-f macho -m amd64")
} }
func xcrun(ctx android.PackageVarContext, args ...string) string { type macPlatformTools struct {
xcrun := ctx.Config().HostSystemTool("xcrun") once sync.Once
bytes, err := exec.Command(xcrun, args...).Output() err error
if err != nil {
ctx.Errorf("xcrun failed with: %q", err.Error()) sdkRoot string
} arPath string
return strings.TrimSpace(string(bytes)) stripPath string
toolPath string
} }
func xcrunSdk(ctx android.PackageVarContext, arg string) string { var macTools = &macPlatformTools{}
xcrun := ctx.Config().HostSystemTool("xcrun")
if selected := ctx.Config().Getenv("MAC_SDK_VERSION"); selected != "" { func getMacTools(ctx android.PackageVarContext) *macPlatformTools {
if !inList(selected, darwinSupportedSdkVersions) { macTools.once.Do(func() {
ctx.Errorf("MAC_SDK_VERSION %s isn't supported: %q", selected, darwinSupportedSdkVersions) xcrunTool := ctx.Config().HostSystemTool("xcrun")
xcrun := func(args ...string) string {
if macTools.err != nil {
return ""
}
bytes, err := exec.Command(xcrunTool, args...).Output()
if err != nil {
macTools.err = fmt.Errorf("xcrun %q failed with: %q", args, err)
return ""
}
return strings.TrimSpace(string(bytes))
}
xcrunSdk := func(arg string) string {
if selected := ctx.Config().Getenv("MAC_SDK_VERSION"); selected != "" {
if !inList(selected, darwinSupportedSdkVersions) {
macTools.err = fmt.Errorf("MAC_SDK_VERSION %s isn't supported: %q", selected, darwinSupportedSdkVersions)
return ""
}
return xcrun("--sdk", "macosx"+selected, arg)
}
for _, sdk := range darwinSupportedSdkVersions {
bytes, err := exec.Command(xcrunTool, "--sdk", "macosx"+sdk, arg).Output()
if err == nil {
return strings.TrimSpace(string(bytes))
}
}
macTools.err = fmt.Errorf("Could not find a supported mac sdk: %q", darwinSupportedSdkVersions)
return "" return ""
} }
bytes, err := exec.Command(xcrun, "--sdk", "macosx"+selected, arg).Output() macTools.sdkRoot = xcrunSdk("--show-sdk-path")
if err != nil {
ctx.Errorf("MAC_SDK_VERSION %s is not installed", selected)
}
return strings.TrimSpace(string(bytes))
}
for _, sdk := range darwinSupportedSdkVersions { macTools.arPath = xcrun("--find", "ar")
bytes, err := exec.Command(xcrun, "--sdk", "macosx"+sdk, arg).Output() macTools.stripPath = xcrun("--find", "strip")
if err == nil { macTools.toolPath = filepath.Dir(xcrun("--find", "ld"))
return strings.TrimSpace(string(bytes)) })
} if macTools.err != nil {
ctx.Errorf("%q", macTools.err)
} }
ctx.Errorf("Could not find a supported mac sdk: %q", darwinSupportedSdkVersions) return macTools
return ""
} }
type toolchainDarwin struct { type toolchainDarwin struct {