Fix long mac test times; only initialize host settings once
It looks like sometime in late February our Mac builds started taking
~10 minutes longer than before. On my local workstation the Soong tests
were taking >25 minutes before completing (likely because I don't have
the older SDKs installed, and we iterate from older to newer to find the
oldest installed SDK).
Most of this time was spend running the `xcrun` tools to interrogate the
system about which Mac SDKs are installed and where the tools are. This
will never change during any build or test, so wrap it all in a
sync.Once so that we only ever call them once.
And remove the macSdkPath variable, which has been unused for years and
no longer works (as we don't allow the use of xcode-select during the
build).
Bug: 153010389
Test: prebuilts/build-tools/build-prebuilts.sh on a Mac
Change-Id: I39b2d49739e628e4c11bec4805b25039115d2fd0
Merged-In: I39b2d49739e628e4c11bec4805b25039115d2fd0
(cherry picked from commit 6ba5367a70
)
This commit is contained in:
@@ -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 {
|
||||||
|
Reference in New Issue
Block a user