@@ -6,10 +6,12 @@ import (
6
6
"strings"
7
7
8
8
"github.com/bitrise-io/go-utils/v2/log"
9
+ "github.com/bitrise-io/go-xcode/xcodebuild"
9
10
"github.com/bitrise-io/go-xcode/xcodeproject/schemeint"
10
11
"github.com/bitrise-io/go-xcode/xcodeproject/serialized"
11
12
"github.com/bitrise-io/go-xcode/xcodeproject/xcodeproj"
12
13
"github.com/bitrise-io/go-xcode/xcodeproject/xcscheme"
14
+ "github.com/bitrise-io/go-xcode/xcodeproject/xcworkspace"
13
15
)
14
16
15
17
type Platform string
@@ -23,6 +25,44 @@ const (
23
25
visionOS Platform = "visionOS"
24
26
)
25
27
28
+ // ArchivableProject represents either a workspace or a project that can be archived
29
+ type ArchivableProject interface {
30
+ BuildSettings (scheme , configuration string , customOptions ... string ) (serialized.Object , error )
31
+ GetProject () (* xcodeproj.XcodeProj , error )
32
+ }
33
+
34
+ // WorkspaceProject wraps a workspace and its main project
35
+ type WorkspaceProject struct {
36
+ Workspace xcworkspace.Workspace
37
+ XcodeProj * xcodeproj.XcodeProj
38
+ }
39
+
40
+ func (w WorkspaceProject ) BuildSettings (scheme , configuration string , customOptions ... string ) (serialized.Object , error ) {
41
+ return w .Workspace .SchemeBuildSettings (scheme , configuration , customOptions ... )
42
+ }
43
+
44
+ func (w WorkspaceProject ) GetProject () (* xcodeproj.XcodeProj , error ) {
45
+ return w .XcodeProj , nil
46
+ }
47
+
48
+ // XcodeProjWrapper wraps a standalone project
49
+ type XcodeProjWrapper struct {
50
+ XcodeProj * xcodeproj.XcodeProj
51
+ }
52
+
53
+ func (p XcodeProjWrapper ) BuildSettings (scheme , configuration string , customOptions ... string ) (serialized.Object , error ) {
54
+ // For xcodeproj projects, use xcodebuild command directly with the project path
55
+ commandModel := xcodebuild .NewShowBuildSettingsCommand (p .XcodeProj .Path )
56
+ commandModel .SetScheme (scheme )
57
+ commandModel .SetConfiguration (configuration )
58
+ commandModel .SetCustomOptions (customOptions )
59
+ return commandModel .RunAndReturnSettings ()
60
+ }
61
+
62
+ func (p XcodeProjWrapper ) GetProject () (* xcodeproj.XcodeProj , error ) {
63
+ return p .XcodeProj , nil
64
+ }
65
+
26
66
func parsePlatform (platform string ) (Platform , error ) {
27
67
switch strings .ToLower (platform ) {
28
68
case "detect" :
@@ -40,7 +80,7 @@ func parsePlatform(platform string) (Platform, error) {
40
80
}
41
81
}
42
82
43
- func OpenArchivableProject (pth , schemeName , configurationName string ) (* xcodeproj. XcodeProj , * xcscheme.Scheme , string , error ) {
83
+ func OpenArchivableProject (pth , schemeName , configurationName string ) (ArchivableProject , * xcscheme.Scheme , string , error ) {
44
84
scheme , schemeContainerDir , err := schemeint .Scheme (pth , schemeName )
45
85
if err != nil {
46
86
return nil , nil , "" , fmt .Errorf ("could not get scheme (%s) from path (%s): %s" , schemeName , pth , err )
@@ -67,41 +107,56 @@ func OpenArchivableProject(pth, schemeName, configurationName string) (*xcodepro
67
107
if err != nil {
68
108
return nil , nil , "" , err
69
109
}
70
- return & xcodeProj , scheme , configurationName , nil
110
+
111
+ // Check if the original path is a workspace
112
+ if strings .HasSuffix (pth , xcworkspace .XCWorkspaceExtension ) {
113
+ workspace , err := xcworkspace .Open (pth )
114
+ if err != nil {
115
+ return nil , nil , "" , fmt .Errorf ("failed to open workspace: %s" , err )
116
+ }
117
+ return WorkspaceProject {Workspace : workspace , XcodeProj : & xcodeProj }, scheme , configurationName , nil
118
+ }
119
+
120
+ // Otherwise it's a standalone project
121
+ return XcodeProjWrapper {XcodeProj : & xcodeProj }, scheme , configurationName , nil
71
122
}
72
123
73
- type TargetBuildSettingsProvider interface {
74
- TargetBuildSettings ( xcodeProj * xcodeproj. XcodeProj , target , configuration string , customOptions ... string ) (serialized.Object , error )
124
+ type BuildSettingsProvider interface {
125
+ BuildSettings ( archivableProject ArchivableProject , schemeName , target , configuration string , customOptions ... string ) (serialized.Object , error )
75
126
}
76
127
77
128
type XcodeBuild struct {
78
129
}
79
130
80
- func (x XcodeBuild ) TargetBuildSettings (xcodeProj * xcodeproj.XcodeProj , target , configuration string , customOptions ... string ) (serialized.Object , error ) {
81
- return xcodeProj .TargetBuildSettings (target , configuration , customOptions ... )
131
+ func (x XcodeBuild ) BuildSettings (archivableProject ArchivableProject , schemeName , target , configuration string , customOptions ... string ) (serialized.Object , error ) {
132
+ // Use the archivable project's scheme build settings method
133
+ return archivableProject .BuildSettings (schemeName , configuration , customOptions ... )
82
134
}
83
135
84
136
func BuildableTargetPlatform (
85
- xcodeProj * xcodeproj. XcodeProj ,
137
+ archivableProject ArchivableProject ,
86
138
scheme * xcscheme.Scheme ,
87
139
configurationName string ,
88
140
additionalOptions []string ,
89
- provider TargetBuildSettingsProvider ,
141
+ provider BuildSettingsProvider ,
90
142
logger log.Logger ,
91
143
) (Platform , error ) {
92
- logger .Printf ("Finding platform type" )
93
-
94
144
archiveEntry , ok := scheme .AppBuildActionEntry ()
95
145
if ! ok {
96
- return "" , fmt .Errorf ("archivable entry not found in project: %s, scheme: %s" , xcodeProj .Path , scheme .Name )
146
+ return "" , fmt .Errorf ("archivable entry not found in scheme: %s" , scheme .Name )
147
+ }
148
+
149
+ xcodeProj , err := archivableProject .GetProject ()
150
+ if err != nil {
151
+ return "" , fmt .Errorf ("failed to get project: %s" , err )
97
152
}
98
153
99
154
mainTarget , ok := xcodeProj .Proj .Target (archiveEntry .BuildableReference .BlueprintIdentifier )
100
155
if ! ok {
101
156
return "" , fmt .Errorf ("target not found: %s" , archiveEntry .BuildableReference .BlueprintIdentifier )
102
157
}
103
158
104
- settings , err := provider .TargetBuildSettings ( xcodeProj , mainTarget .Name , configurationName , additionalOptions ... )
159
+ settings , err := provider .BuildSettings ( archivableProject , scheme . Name , mainTarget .Name , configurationName , additionalOptions ... )
105
160
if err != nil {
106
161
return "" , fmt .Errorf ("failed to get target (%s) build settings: %s" , mainTarget .Name , err )
107
162
}
0 commit comments