From 9f99f5385f2cec422105c8970b0a300ae9820f2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliv=C3=A9r=20Falvai?= Date: Mon, 26 Jul 2021 13:53:22 +0200 Subject: [PATCH] Add workaround for Big Sur simulator boot failure (#177) * Add workaround for Big Sur simulator boot failure * Tweak logging [STEP-1268] --- main.go | 5 +++++ simulator.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/main.go b/main.go index cc59ed22..c84aa7fd 100644 --- a/main.go +++ b/main.go @@ -344,6 +344,11 @@ func (s Step) InstallDeps(xcpretty bool) error { func (s Step) Run(cfg Config) (Result, error) { log.SetEnableDebugLog(cfg.Verbose) + err := resetLaunchServices() + if err != nil { + log.Warnf("Failed to apply simulator boot workaround, error: %s", err) + } + // Boot simulator if cfg.SimulatorDebug != never { log.Infof("Enabling Simulator verbose log for better diagnostics") diff --git a/simulator.go b/simulator.go index a96d043a..c044a9e8 100644 --- a/simulator.go +++ b/simulator.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "io/ioutil" + "path/filepath" "strings" "time" @@ -100,3 +101,37 @@ func simulatorCollectDiagnostics() (string, error) { return diagnosticsOutDir, nil } + +// Reset launch services database to avoid Big Sur's sporadic failure to find the Simulator App +// The following error is printed when this happens: "kLSNoExecutableErr: The executable is missing" +// Details: +// - https://stackoverflow.com/questions/2182040/the-application-cannot-be-opened-because-its-executable-is-missing/16546673#16546673 +// - https://ss64.com/osx/lsregister.html +func resetLaunchServices() error { + cmd := command.New("sw_vers", "-productVersion") + macOSVersion, err := cmd.RunAndReturnTrimmedCombinedOutput() + if err != nil { + return err + } + + if strings.HasPrefix(macOSVersion, "11.") { // It's Big Sur + cmd := command.New("xcode-select", "--print-path") + xcodeDevDirPath, err := cmd.RunAndReturnTrimmedCombinedOutput() + if err != nil { + return err + } + + simulatorAppPath := filepath.Join(xcodeDevDirPath, "Applications", "Simulator.app") + + cmdString := "/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister" + cmd = command.New(cmdString, "-f", simulatorAppPath) + + log.Infof("Applying launch services reset workaround before booting simulator") + _, err = cmd.RunAndReturnTrimmedCombinedOutput() + if err != nil { + return err + } + } + + return nil +}