Skip to content

Commit

Permalink
Add workaround for Big Sur simulator boot failure (#177)
Browse files Browse the repository at this point in the history
* Add workaround for Big Sur simulator boot failure

* Tweak logging

[STEP-1268]
  • Loading branch information
ofalvai authored Jul 26, 2021
1 parent 4fb0772 commit 9f99f53
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
35 changes: 35 additions & 0 deletions simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"io/ioutil"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -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
}

0 comments on commit 9f99f53

Please sign in to comment.