-
Notifications
You must be signed in to change notification settings - Fork 43
/
xcode.go
68 lines (55 loc) · 2.24 KB
/
xcode.go
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
package codesigndoc
import (
"fmt"
"github.com/bitrise-io/codesigndoc/codesign"
"github.com/bitrise-io/codesigndoc/models"
"github.com/bitrise-io/codesigndoc/xcode"
"github.com/bitrise-io/go-utils/colorstring"
"github.com/bitrise-io/go-utils/log"
"github.com/bitrise-io/go-utils/stringutil"
"github.com/bitrise-io/go-xcode/utility"
)
// BuildXcodeArchive builds an Xcode archive.
func BuildXcodeArchive(xcodeCmd xcode.CommandModel, handleBuildLog func(string) error) (archivePath string, err error) {
// Output tools versions
xcodebuildVersion, err := utility.GetXcodeVersion()
if err != nil {
return "", fmt.Errorf("failed to get Xcode (xcodebuild) version, error: %s", err)
}
fmt.Println()
log.Infof("%s: %s (%s)", colorstring.Green("Xcode (xcodebuild) version"), xcodebuildVersion.Version, xcodebuildVersion.BuildVersion)
fmt.Println()
fmt.Println()
log.Printf("🔦 Running an Xcode Archive, to get all the required code signing settings...")
archivePath, xcodebuildOutput, err := xcodeCmd.GenerateArchive()
defer func() {
if handleBuildLog != nil {
if derr := handleBuildLog(xcodebuildOutput); derr != nil {
if err != nil {
err = derr
}
}
}
}()
if err != nil {
log.Warnf("Last lines of the build log:")
fmt.Println(stringutil.LastNLines(xcodebuildOutput, 15))
log.Infof(colorstring.Yellow("Please check the build log to see what caused the error."))
fmt.Println()
log.Errorf("Xcode Archive failed.")
log.Infof(colorstring.Yellow("Open the project: ")+"%s", xcodeCmd.ProjectFilePath)
log.Infof(colorstring.Yellow("and make sure that you can build an Archive, with the scheme: ")+"%s", xcodeCmd.Scheme)
fmt.Println()
return "", err
}
return archivePath, nil
}
// CodesigningFilesForXCodeProject ...
func CodesigningFilesForXCodeProject(archivePath string, certificatesOnly bool, isAskForPassword bool) (models.Certificates, []models.ProvisioningProfile, error) {
// If certificatesOnly is set, CollectCodesignFiles returns an empty slice for profiles
certificatesToExport, profilesToExport, err := CollectCodesignFiles(archivePath, certificatesOnly)
if err != nil {
return models.Certificates{}, nil, err
}
return codesign.ExportCodesigningFiles(certificatesToExport, profilesToExport, isAskForPassword)
}