Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
133 lines (115 loc) · 5.48 KB
/
Copy pathmain.go
File metadata and controls
133 lines (115 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package main
import (
"context"
"fmt"
"os"
"github.com/bitrise-io/bitrise-build-cache-cli/v2/pkg/reactnative/wrap"
"github.com/bitrise-io/go-steputils/v2/export"
"github.com/bitrise-io/go-steputils/v2/ruby"
"github.com/bitrise-io/go-steputils/v2/stepconf"
"github.com/bitrise-io/go-steputils/v2/stepenv"
"github.com/bitrise-io/go-utils/v2/command"
"github.com/bitrise-io/go-utils/v2/env"
"github.com/bitrise-io/go-utils/v2/errorutil"
"github.com/bitrise-io/go-utils/v2/fileutil"
"github.com/bitrise-io/go-utils/v2/log"
"github.com/bitrise-io/go-utils/v2/pathutil"
"github.com/bitrise-io/go-utils/v2/ziputil"
"github.com/bitrise-io/go-xcode/v2/destination"
"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/xcodecommand"
"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"
)
func main() {
os.Exit(run())
}
func run() int {
logger := log.NewLogger()
configParser := createConfigParser(logger)
config, err := configParser.ProcessConfig()
if err != nil {
logger.Errorf("%s", errorutil.FormattedError(fmt.Errorf("Failed to process Step inputs: %w", err))) //nolint:staticcheck // top-level messages are user facing
return 1
}
xcodeTestRunner, err := createStep(logger, config.LogFormatter)
if err != nil {
logger.Errorf("%s", errorutil.FormattedError(fmt.Errorf("Failed to process Step inputs: %w", err))) //nolint:staticcheck // top-level messages are user facing
return 1
}
xcodeTestRunner.InstallDeps()
res, runErr := xcodeTestRunner.Run(config)
exportErr := xcodeTestRunner.Export(res, runErr != nil)
if runErr != nil {
logger.Errorf("%s", errorutil.FormattedError(fmt.Errorf("Failed to execute Step: %w", runErr))) //nolint:staticcheck // top-level messages are user facing
return 1
}
if exportErr != nil {
logger.Errorf("%s", errorutil.FormattedError(fmt.Errorf("Failed to export Step outputs: %w", exportErr))) //nolint:staticcheck // top-level messages are user facing
return 1
}
return 0
}
func createConfigParser(logger log.Logger) step.XcodeTestConfigParser {
envRepository := env.NewRepository()
commandFactory := command.NewFactory(envRepository)
inputParser := stepconf.NewInputParser(envRepository)
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: %s", err)
}
pathModifier := pathutil.NewPathModifier()
deviceFinder := destination.NewDeviceFinder(logger, commandFactory, xcodeVersion)
utils := step.NewUtils(logger)
return step.NewXcodeTestConfigParser(inputParser, logger, deviceFinder, pathModifier, utils, xcodeVersion)
}
func createStep(logger log.Logger, logFormatter string) (step.XcodeTestRunner, error) {
envRepository := env.NewRepository()
commandFactory := command.NewFactory(envRepository)
pathChecker := pathutil.NewPathChecker()
pathProvider := pathutil.NewPathProvider()
pathModifier := pathutil.NewPathModifier()
fileManager := fileutil.NewFileManager()
xcconfigWriter := xcconfig.NewWriter(pathProvider, fileManager, pathChecker, pathModifier)
simulatorManager := simulator.NewManager(logger, commandFactory)
swiftCache := cache.NewSwiftPackageCache()
zipManager := ziputil.NewZipManager(pathChecker)
outputExporter := export.NewExporter(commandFactory, fileManager, zipManager)
testAddonExporter := testaddon.NewExporter(testaddon.NewTestAddon(logger))
stepenvRepository := stepenv.NewRepository(envRepository)
exporter := output.NewExporter(stepenvRepository, logger, outputExporter, testAddonExporter, zipManager, fileManager)
utils := step.NewUtils(logger)
// Only the factory handed to the xcodecommand runner gets wrapped — codesign,
// project readers, and other commandFactory consumers keep invoking binaries
// directly.
det := wrap.Detect(context.Background(), wrap.DetectParams{Logger: logger})
if det.ReactNativeEnabled {
logger.Infof("Bitrise Build Cache: React Native cache active — wrapping xcodebuild with %s", det.CLIPath)
}
runnerCmdFactory := wrap.NewWrappingCommandFactory(commandFactory, det, "xcodebuild")
xcodeCommandRunner := xcodecommand.Runner(nil)
switch logFormatter {
case step.XcodebuildTool:
xcodeCommandRunner = xcodecommand.NewRawCommandRunner(logger, runnerCmdFactory)
case step.XcbeautifyTool:
xcodeCommandRunner = xcodecommand.NewXcbeautifyRunner(logger, runnerCmdFactory)
case step.XcprettyTool:
commandLocator := env.NewCommandLocator()
rubyComamndFactory, err := ruby.NewCommandFactory(commandFactory, commandLocator, logger)
if err != nil {
return step.XcodeTestRunner{}, fmt.Errorf("failed to install xcpretty: %s", err)
}
rubyEnv := ruby.NewEnvironment(rubyComamndFactory, commandLocator, logger)
xcodeCommandRunner = xcodecommand.NewXcprettyCommandRunner(logger, runnerCmdFactory, pathChecker, fileManager, rubyComamndFactory, rubyEnv)
default:
panic(fmt.Sprintf("Unknown log formatter: %s", logFormatter))
}
xcodebuilder := xcodebuild.NewXcodebuild(logger, fileManager, xcconfigWriter, xcodeCommandRunner)
return step.NewXcodeTestRunner(logger, commandFactory, xcodebuilder, simulatorManager, swiftCache, exporter, pathModifier, pathProvider, utils), nil
}