Skip to content

Commit

Permalink
Update to latest go-xcode, use xcodeversion package (#230)
Browse files Browse the repository at this point in the history
Check for iOS Simulator <-> Xcode compatibility when using latest device for destination.
  • Loading branch information
lpusok authored Aug 1, 2023
1 parent 96bccac commit ab4b14a
Show file tree
Hide file tree
Showing 21 changed files with 298 additions and 235 deletions.
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
module github.com/bitrise-steplib/steps-xcode-test

go 1.17
go 1.18

require (
github.com/bitrise-io/bitrise v0.0.0-20230704133514-4c3c1429a139
github.com/bitrise-io/bitrise v0.0.0-20230707121919-a5b9e2d27ea9
github.com/bitrise-io/go-steputils/v2 v2.0.0-alpha.18
github.com/bitrise-io/go-utils v1.0.8
github.com/bitrise-io/go-utils v1.0.9
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.19
github.com/bitrise-io/go-xcode v1.0.11
github.com/bitrise-io/go-xcode/v2 v2.0.0-alpha.27
github.com/bitrise-io/go-xcode v1.0.13
github.com/bitrise-io/go-xcode/v2 v2.0.0-alpha.29
github.com/hashicorp/go-version v1.6.0
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/stretchr/testify v1.8.4
)

require (
github.com/bitrise-io/envman v0.0.0-20230330151556-11e5bde91b36 // indirect
github.com/bitrise-io/envman v0.0.0-20230721122944-6b164ed0c2f8 // indirect
github.com/bitrise-io/go-steputils v1.0.5 // indirect
github.com/bitrise-io/stepman v0.0.0-20221010110437-a88e9a915b58 // indirect
github.com/bitrise-io/stepman v0.0.0-20230728094915-939f0fe5c19a // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
golang.org/x/crypto v0.10.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
Expand Down
116 changes: 15 additions & 101 deletions go.sum

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import (
"github.com/bitrise-io/go-xcode/v2/simulator"
"github.com/bitrise-io/go-xcode/v2/xcconfig"
cache "github.com/bitrise-io/go-xcode/v2/xcodecache"
"github.com/bitrise-io/go-xcode/v2/xcodeversion"
"github.com/bitrise-steplib/steps-xcode-test/output"
"github.com/bitrise-steplib/steps-xcode-test/step"
"github.com/bitrise-steplib/steps-xcode-test/testaddon"
"github.com/bitrise-steplib/steps-xcode-test/xcodebuild"
"github.com/bitrise-steplib/steps-xcode-test/xcodecommand"
"github.com/bitrise-steplib/steps-xcode-test/xcodeversion"
)

func main() {
Expand Down Expand Up @@ -71,12 +71,16 @@ func createConfigParser(logger log.Logger) step.XcodeTestConfigParser {
envRepository := env.NewRepository()
commandFactory := command.NewFactory(envRepository)
inputParser := stepconf.NewInputParser(envRepository)
xcodeVersionReader := xcodeversion.NewXcodeVersionReader()
xcodeVersionProvider := xcodeversion.NewXcodeVersionProvider(commandFactory)
xcodeVersion, err := xcodeVersionProvider.GetVersion()
if err != nil { // Not a fatal error, continuing with empty version
logger.Errorf("failed to read Xcode version: %w", err)
}
pathModifier := pathutil.NewPathModifier()
deviceFinder := destination.NewDeviceFinder(logger, commandFactory)
deviceFinder := destination.NewDeviceFinder(logger, commandFactory, xcodeVersion)
utils := step.NewUtils(logger)

return step.NewXcodeTestConfigParser(inputParser, logger, xcodeVersionReader, deviceFinder, pathModifier, utils)
return step.NewXcodeTestConfigParser(inputParser, logger, xcodeVersion, deviceFinder, pathModifier, utils)
}

func createStep(logger log.Logger, logFormatter string) (step.XcodeTestRunner, error) {
Expand Down
27 changes: 15 additions & 12 deletions step/mocks/Manager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 15 additions & 13 deletions step/mocks/Reader.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 28 additions & 29 deletions step/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
"github.com/bitrise-io/go-xcode/v2/destination"
"github.com/bitrise-io/go-xcode/v2/simulator"
cache "github.com/bitrise-io/go-xcode/v2/xcodecache"
"github.com/bitrise-io/go-xcode/v2/xcodeversion"
"github.com/bitrise-steplib/steps-xcode-test/output"
"github.com/bitrise-steplib/steps-xcode-test/xcodebuild"
"github.com/bitrise-steplib/steps-xcode-test/xcodecommand"
"github.com/bitrise-steplib/steps-xcode-test/xcodeversion"
"github.com/kballard/go-shellquote"
)

Expand Down Expand Up @@ -110,22 +110,22 @@ type Config struct {
}

type XcodeTestConfigParser struct {
logger log.Logger
inputParser stepconf.InputParser
xcodeVersionReader xcodeversion.Reader
deviceFinder destination.DeviceFinder
pathModifier pathutil.PathModifier
utils Utils
logger log.Logger
inputParser stepconf.InputParser
xcodeVersion xcodeversion.Version
deviceFinder destination.DeviceFinder
pathModifier pathutil.PathModifier
utils Utils
}

func NewXcodeTestConfigParser(inputParser stepconf.InputParser, logger log.Logger, xcodeVersionReader xcodeversion.Reader, deviceFinder destination.DeviceFinder, pathModifier pathutil.PathModifier, utils Utils) XcodeTestConfigParser {
func NewXcodeTestConfigParser(inputParser stepconf.InputParser, logger log.Logger, xcodeVersion xcodeversion.Version, deviceFinder destination.DeviceFinder, pathModifier pathutil.PathModifier, utils Utils) XcodeTestConfigParser {
return XcodeTestConfigParser{
logger: logger,
inputParser: inputParser,
xcodeVersionReader: xcodeVersionReader,
deviceFinder: deviceFinder,
pathModifier: pathModifier,
utils: utils,
logger: logger,
inputParser: inputParser,
xcodeVersion: xcodeVersion,
deviceFinder: deviceFinder,
pathModifier: pathModifier,
utils: utils,
}
}

Expand Down Expand Up @@ -170,14 +170,8 @@ func (s XcodeTestConfigParser) ProcessConfig() (Config, error) {

s.logger.EnableDebugLog(input.VerboseLog)

// validate Xcode version
xcodebuildVersion, err := s.xcodeVersionReader.Version()
if err != nil {
return Config{}, fmt.Errorf("failed to determine Xcode version: %w", err)
}
s.logger.Printf("- xcodebuildVersion: %s (%s)", xcodebuildVersion.Version, xcodebuildVersion.BuildVersion)

if err := s.validateXcodeVersion(&input, int(xcodebuildVersion.MajorVersion)); err != nil {
s.logger.Printf("- xcodebuild_version: %s (%s)", s.xcodeVersion.Version, s.xcodeVersion.BuildVersion)
if err := s.validateXcodeVersion(&input, int(s.xcodeVersion.MajorVersion)); err != nil {
return Config{}, err
}

Expand Down Expand Up @@ -223,7 +217,7 @@ func (s XcodeTestConfigParser) ProcessConfig() (Config, error) {
return Config{}, fmt.Errorf("`-xcconfig` option found in 'Additional options for the xcodebuild command' (xcodebuild_options), please clear 'Build settings (xcconfig)' (`xcconfig_content`) input as only one can be set")
}

return s.utils.CreateConfig(input, projectPath, int(xcodebuildVersion.MajorVersion), sim, additionalOptions, additionalLogFormatterOptions), nil
return s.utils.CreateConfig(input, projectPath, int(s.xcodeVersion.MajorVersion), sim, additionalOptions, additionalLogFormatterOptions), nil
}

// InstallDeps ...
Expand Down Expand Up @@ -257,7 +251,7 @@ type Result struct {
func (s XcodeTestRunner) Run(cfg Config) (Result, error) {
enableSimulatorVerboseLog := cfg.CollectSimulatorDiagnostics != never
launchSimulator := !cfg.IsSimulatorBooted && !cfg.HeadlessMode
if err := s.prepareSimulator(enableSimulatorVerboseLog, cfg.Simulator.ID, launchSimulator); err != nil {
if err := s.prepareSimulator(enableSimulatorVerboseLog, cfg.Simulator, launchSimulator); err != nil {
return Result{}, err
}

Expand Down Expand Up @@ -354,6 +348,11 @@ func (s XcodeTestConfigParser) parseAdditionalLogFormatterOptions(logFormatter,
}

func (s XcodeTestConfigParser) validateXcodeVersion(input *Input, xcodeMajorVersion int) error {
if xcodeMajorVersion == 0 {
s.logger.Printf("Skipping Xcode major version check as it is not available.")
return nil
}

if xcodeMajorVersion < minSupportedXcodeMajorVersion {
return fmt.Errorf("invalid Xcode major version (%d), should not be less then min supported: %d", xcodeMajorVersion, minSupportedXcodeMajorVersion)
}
Expand Down Expand Up @@ -389,7 +388,7 @@ func (s XcodeTestConfigParser) getSimulatorForDestination(destinationSpecifier s
return device, nil
}

func (s XcodeTestRunner) prepareSimulator(enableSimulatorVerboseLog bool, simulatorID string, launchSimulator bool) error {
func (s XcodeTestRunner) prepareSimulator(enableSimulatorVerboseLog bool, simulator destination.Device, launchSimulator bool) error {
err := s.simulatorManager.ResetLaunchServices()
if err != nil {
s.logger.Warnf("Failed to apply simulator boot workaround: %s", err)
Expand All @@ -399,20 +398,20 @@ func (s XcodeTestRunner) prepareSimulator(enableSimulatorVerboseLog bool, simula
if enableSimulatorVerboseLog {
s.logger.Infof("Enabling Simulator verbose log for better diagnostics")
// Boot the simulator now, so verbose logging can be enabled, and it is kept booted after running tests.
if err := s.simulatorManager.Boot(simulatorID); err != nil {
if err := s.simulatorManager.Boot(simulator); err != nil {
return fmt.Errorf("%v", err)
}
if err := s.simulatorManager.EnableVerboseLog(simulatorID); err != nil {
if err := s.simulatorManager.EnableVerboseLog(simulator.ID); err != nil {
return fmt.Errorf("%v", err)
}

s.logger.Println()
}

if launchSimulator {
s.logger.Infof("Booting simulator (%s)...", simulatorID)
s.logger.Infof("Booting simulator (%s)...", simulator.ID)

if err := s.simulatorManager.LaunchWithGUI(simulatorID); err != nil {
if err := s.simulatorManager.LaunchWithGUI(simulator.ID); err != nil {
return fmt.Errorf("failed to boot simulator: %w", err)
}

Expand Down
Loading

0 comments on commit ab4b14a

Please sign in to comment.