Skip to content

Commit 928b8a3

Browse files
authored
Added Platform input (#382)
* SDKROOT build setting can be set to auto inside Xcode project lately, as there is multi-platform target support. Adding Platform solves this as delegating to manual choice of platform is not neccesary. It also helps to avoid reading a project-level build settings, where passing additional options caused unexpected failures.
1 parent 427a05a commit 928b8a3

File tree

6 files changed

+98
-31
lines changed

6 files changed

+98
-31
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ Build a development IPA with custom xcconfig file path:
123123
| --- | --- | --- | --- |
124124
| `project_path` | Xcode Project (`.xcodeproj`) or Workspace (`.xcworkspace`) path. The input value sets xcodebuild's `-project` or `-workspace` option. | required | `$BITRISE_PROJECT_PATH` |
125125
| `scheme` | Xcode Scheme name. The input value sets xcodebuild's `-scheme` option. | required | `$BITRISE_SCHEME` |
126+
| `platform` | Platform to archive the product for. If set to `detect`, the step will try to detect the platform from the Xcode project settings. Its value sets xcodebuild's `-destination` option. Example: `-destination generic/platform=iOS Simulator`. | required | `detect` |
126127
| `distribution_method` | Describes how Xcode should export the archive. The input value sets the method in the export options plist content. Note: In Xcode 15.3, distribution methods have been renamed. The values of this input reflect the old names. When running with Xcode 15.3 and later, the new names are passed to `xcodebuild`: - `debugging`, when `development` is selected - `app-store-connect`, when `app-store` is selected - `release-testing`, when `ad-hoc` is selected - `enterprise` is unchanged | required | `development` |
127128
| `configuration` | Xcode Build Configuration. If not specified, the default Build Configuration will be used. The input value sets xcodebuild's `-configuration` option. | | |
128129
| `xcconfig_content` | Build settings to override the project's build settings, using xcodebuild's `-xcconfig` option. You can't define `-xcconfig` option in `Additional options for the xcodebuild command` if this input is set. If empty, no setting is changed. When set it can be either: 1. Existing `.xcconfig` file path. Example: `./ios-sample/ios-sample/Configurations/Dev.xcconfig` 2. The contents of a newly created temporary `.xcconfig` file. (This is the default.) Build settings must be separated by newline character (`\n`). Example: ``` COMPILER_INDEX_STORE_ENABLE = NO ONLY_ACTIVE_ARCH[config=Debug][sdk=*][arch=*] = YES ``` | | `COMPILER_INDEX_STORE_ENABLE = NO` |

e2e/bitrise.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ workflows:
5858
- TEST_APP_COMMIT: ""
5959
- BITRISE_PROJECT_PATH: Fruta.xcodeproj
6060
- BITRISE_SCHEME: Fruta iOS
61+
- DESTINATION: iOS
6162
- CODE_SIGNING_METHOD: api-key
6263
- API_KEY_PATH: $BITFALL_APPSTORECONNECT_API_KEY_URL
6364
- API_KEY_ID: $BITFALL_APPSTORECONNECT_API_KEY_ID
@@ -188,6 +189,7 @@ workflows:
188189
- TEST_APP_BRANCH: new-certificates
189190
- BITRISE_PROJECT_PATH: ios-simple-objc/ios-simple-objc.xcodeproj
190191
- BITRISE_SCHEME: ios-simple-objc
192+
- DESTINATION: detect
191193
- CODE_SIGNING_METHOD: api-key
192194
- XCCONFIG_CONTENT: |
193195
COMPILER_INDEX_STORE_ENABLE = NO
@@ -221,6 +223,7 @@ workflows:
221223
- TEST_APP_BRANCH: master
222224
- BITRISE_PROJECT_PATH: Fruta.xcodeproj
223225
- BITRISE_SCHEME: Fruta iOS
226+
- DESTINATION: detect
224227
- CODE_SIGNING_METHOD: api-key
225228
- MIN_DAYS_PROFILE_VALID: 0
226229
- IPA_EXPORT_METHOD: ad-hoc
@@ -247,6 +250,7 @@ workflows:
247250
- TEST_APP_BRANCH: manual-signing
248251
- BITRISE_PROJECT_PATH: Fruta.xcodeproj
249252
- BITRISE_SCHEME: Fruta iOS
253+
- DESTINATION: detect
250254
- CODE_SIGNING_METHOD: api-key
251255
- MIN_DAYS_PROFILE_VALID: 0
252256
- IPA_EXPORT_METHOD: development
@@ -272,6 +276,7 @@ workflows:
272276
- TEST_APP_BRANCH: new-certificates
273277
- BITRISE_PROJECT_PATH: ios-simple-objc/ios-simple-objc.xcodeproj
274278
- BITRISE_SCHEME: ios-simple-objc
279+
- DESTINATION: iOS
275280
- CODE_SIGNING_METHOD: apple-id
276281
- TEAM_ID: 72SA8V3WYL
277282
- MIN_DAYS_PROFILE_VALID: 0
@@ -289,6 +294,7 @@ workflows:
289294
- TEST_APP_BRANCH: entitlements
290295
- BITRISE_PROJECT_PATH: code-sign-test.xcodeproj
291296
- BITRISE_SCHEME: code-sign-test
297+
- DESTINATION: detect
292298
- CODE_SIGNING_METHOD: api-key
293299
- MIN_DAYS_PROFILE_VALID: 0
294300
- IPA_EXPORT_METHOD: app-store
@@ -305,6 +311,7 @@ workflows:
305311
- TEST_APP_BRANCH: automatic
306312
- BITRISE_PROJECT_PATH: code-sign-test.xcodeproj
307313
- BITRISE_SCHEME: code-sign-test
314+
- DESTINATION: detect
308315
- CODE_SIGNING_METHOD: api-key
309316
- MIN_DAYS_PROFILE_VALID: 0
310317
- IPA_EXPORT_METHOD: app-store
@@ -331,6 +338,7 @@ workflows:
331338
- TEST_APP_BRANCH: automatic
332339
- BITRISE_PROJECT_PATH: code-sign-test.xcodeproj
333340
- BITRISE_SCHEME: code-sign-test
341+
- DESTINATION: detect
334342
- CODE_SIGNING_METHOD: apple-id
335343
- TEAM_ID: 72SA8V3WYL
336344
- MIN_DAYS_PROFILE_VALID: 0
@@ -348,6 +356,7 @@ workflows:
348356
- TEST_APP_COMMIT: ""
349357
- BITRISE_PROJECT_PATH: code-sign-test.xcodeproj
350358
- BITRISE_SCHEME: code-sign-test-Prod
359+
- DESTINATION: detect
351360
- CODE_SIGNING_METHOD: api-key
352361
- MIN_DAYS_PROFILE_VALID: 0
353362
- TEAM_ID: 72SA8V3WYL
@@ -366,6 +375,7 @@ workflows:
366375
- TEST_APP_COMMIT: ""
367376
- BITRISE_PROJECT_PATH: ios-simple-objc/ios-simple-objc.xcworkspace
368377
- BITRISE_SCHEME: ios-simple-objc
378+
- DESTINATION: detect
369379
- CODE_SIGNING_METHOD: api-key
370380
- MIN_DAYS_PROFILE_VALID: 0
371381
- TEAM_ID: 72SA8V3WYL
@@ -385,6 +395,7 @@ workflows:
385395
- TEST_APP_COMMIT: ""
386396
- BITRISE_PROJECT_PATH: ios-simple-objc/ios-simple-objc.xcodeproj
387397
- BITRISE_SCHEME: ios-simple-objc
398+
- DESTINATION: detect
388399
- CODE_SIGNING_METHOD: api-key
389400
- MIN_DAYS_PROFILE_VALID: 0
390401
- TEAM_ID: 72SA8V3WYL
@@ -407,6 +418,7 @@ workflows:
407418
- TEST_APP_BRANCH: master
408419
- BITRISE_PROJECT_PATH: code-sign-test.xcodeproj
409420
- BITRISE_SCHEME: code-sign-test
421+
- DESTINATION: iOS
410422
- CODE_SIGNING_METHOD: api-key
411423
- MIN_DAYS_PROFILE_VALID: 112
412424
- TEAM_ID: 72SA8V3WYL
@@ -424,6 +436,7 @@ workflows:
424436
- TEST_APP_BRANCH: master
425437
- BITRISE_PROJECT_PATH: sample-apps-ios-workspace-swift.xcworkspace
426438
- BITRISE_SCHEME: sample-apps-ios-workspace-swift
439+
- DESTINATION: iOS
427440
- CODE_SIGNING_METHOD: api-key
428441
- MIN_DAYS_PROFILE_VALID: 0
429442
- TEAM_ID: 72SA8V3WYL
@@ -442,6 +455,7 @@ workflows:
442455
- TEST_APP_COMMIT: ""
443456
- BITRISE_PROJECT_PATH: Catalyst Sample.xcodeproj
444457
- BITRISE_SCHEME: Catalyst Sample
458+
- DESTINATION: detect
445459
- CODE_SIGNING_METHOD: api-key
446460
- MIN_DAYS_PROFILE_VALID: 0
447461
- FORCE_CODE_SIGN_IDENTITY: "Apple Development: Tooling Bot Bitrise"
@@ -484,6 +498,7 @@ workflows:
484498
inputs:
485499
- project_path: ./_tmp/$BITRISE_PROJECT_PATH
486500
- scheme: $BITRISE_SCHEME
501+
- platform: $DESTINATION
487502
- automatic_code_signing: $CODE_SIGNING_METHOD
488503
- min_profile_validity: $MIN_DAYS_PROFILE_VALID
489504
- certificate_url_list: $BITFALL_APPLE_APPLE_CERTIFICATE_URL_LIST|$BITFALL_APPLE_IOS_CERTIFICATE_URL_LIST

main.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,12 @@ func createXcodebuildArchiver(logger log.Logger, logFormatter string) (step.Xcod
9999

100100
func createRunOptions(config step.Config) step.RunOpts {
101101
return step.RunOpts{
102-
ProjectPath: config.ProjectPath,
103-
Scheme: config.Scheme,
104-
Configuration: config.Configuration,
105-
XcodeMajorVersion: config.XcodeMajorVersion,
106-
ArtifactName: config.ArtifactName,
102+
ProjectPath: config.ProjectPath,
103+
Scheme: config.Scheme,
104+
DestinationPlatform: config.DestinationPlatform,
105+
Configuration: config.Configuration,
106+
XcodeMajorVersion: config.XcodeMajorVersion,
107+
ArtifactName: config.ArtifactName,
107108

108109
CodesignManager: config.CodesignManager,
109110

step.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,24 @@ inputs:
9090
The input value sets xcodebuild's `-scheme` option.
9191
is_required: true
9292

93+
- platform: detect
94+
opts:
95+
title: Platform
96+
summary: Platform to archive the product for.
97+
description: |-
98+
Platform to archive the product for.
99+
If set to `detect`, the step will try to detect the platform from the Xcode project settings.
100+
101+
Its value sets xcodebuild's `-destination` option.
102+
Example: `-destination generic/platform=iOS Simulator`.
103+
value_options:
104+
- detect
105+
- iOS
106+
- watchOS
107+
- tvOS
108+
- visionOS
109+
is_required: true
110+
93111
- distribution_method: development
94112
opts:
95113
title: Distribution method

step/platform.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,31 @@ import (
1515
type Platform string
1616

1717
const (
18-
iOS Platform = "iOS"
19-
osX Platform = "OS X"
20-
tvOS Platform = "tvOS"
21-
watchOS Platform = "watchOS"
22-
visionOS Platform = "visionOS"
18+
detectPlatform Platform = "detect"
19+
iOS Platform = "iOS"
20+
osX Platform = "OS X"
21+
tvOS Platform = "tvOS"
22+
watchOS Platform = "watchOS"
23+
visionOS Platform = "visionOS"
2324
)
2425

26+
func parsePlatform(platform string) (Platform, error) {
27+
switch strings.ToLower(platform) {
28+
case "detect":
29+
return detectPlatform, nil
30+
case "ios":
31+
return iOS, nil
32+
case "tvos":
33+
return tvOS, nil
34+
case "watchos":
35+
return watchOS, nil
36+
case "visionos":
37+
return visionOS, nil
38+
default:
39+
return "", fmt.Errorf("unknown platform: %s", platform)
40+
}
41+
}
42+
2543
func OpenArchivableProject(pth, schemeName, configurationName string) (*xcodeproj.XcodeProj, *xcscheme.Scheme, string, error) {
2644
scheme, schemeContainerDir, err := schemeint.Scheme(pth, schemeName)
2745
if err != nil {

step/step.go

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ type Inputs struct {
7676
ProjectPath string `env:"project_path,file"`
7777
Scheme string `env:"scheme,required"`
7878
ExportMethod string `env:"distribution_method,opt[app-store,ad-hoc,enterprise,development]"`
79+
Platform string `env:"platform,opt[detect,iOS,watchOS,tvOS,visionOS]"`
7980

8081
// xcodebuild configuration
8182
Configuration string `env:"configuration"`
@@ -130,6 +131,7 @@ type Inputs struct {
130131
// Config ...
131132
type Config struct {
132133
Inputs
134+
DestinationPlatform Platform
133135
XcodeMajorVersion int
134136
XcodebuildAdditionalOptions []string
135137
CodesignManager *codesign.Manager // nil if automatic code signing is "off"
@@ -199,6 +201,10 @@ func (s XcodebuildArchiveConfigParser) ProcessInputs() (Config, error) {
199201
}
200202

201203
var err error
204+
if config.DestinationPlatform, err = parsePlatform(config.Platform); err != nil {
205+
return Config{}, fmt.Errorf("issue with input Platform: %w", err)
206+
}
207+
202208
config.XcodebuildAdditionalOptions, err = shellquote.Split(inputs.XcodebuildOptions)
203209
if err != nil {
204210
return Config{}, fmt.Errorf("provided XcodebuildOptions (%s) are not valid CLI parameters: %s", inputs.XcodebuildOptions, err)
@@ -316,11 +322,12 @@ func (s *XcodebuildArchiver) EnsureDependencies() {
316322
// RunOpts ...
317323
type RunOpts struct {
318324
// Shared
319-
ProjectPath string
320-
Scheme string
321-
Configuration string
322-
XcodeMajorVersion int
323-
ArtifactName string
325+
ProjectPath string
326+
Scheme string
327+
DestinationPlatform Platform
328+
Configuration string
329+
XcodeMajorVersion int
330+
ArtifactName string
324331

325332
// Code signing, nil if automatic code signing is "off"
326333
CodesignManager *codesign.Manager
@@ -426,12 +433,13 @@ func (s XcodebuildArchiver) Run(opts RunOpts) (RunResult, error) {
426433
s.logger.Println()
427434

428435
archiveOpts := xcodeArchiveOpts{
429-
ProjectPath: opts.ProjectPath,
430-
Scheme: opts.Scheme,
431-
Configuration: opts.Configuration,
432-
XcodeMajorVersion: opts.XcodeMajorVersion,
433-
ArtifactName: opts.ArtifactName,
434-
XcodeAuthOptions: authOptions,
436+
ProjectPath: opts.ProjectPath,
437+
Scheme: opts.Scheme,
438+
DestinationPlatform: opts.DestinationPlatform,
439+
Configuration: opts.Configuration,
440+
XcodeMajorVersion: opts.XcodeMajorVersion,
441+
ArtifactName: opts.ArtifactName,
442+
XcodeAuthOptions: authOptions,
435443

436444
PerformCleanAction: opts.PerformCleanAction,
437445
XcconfigContent: opts.XcconfigContent,
@@ -784,12 +792,13 @@ func (s XcodebuildArchiveConfigParser) createCodesignManager(config Config) (cod
784792
}
785793

786794
type xcodeArchiveOpts struct {
787-
ProjectPath string
788-
Scheme string
789-
Configuration string
790-
XcodeMajorVersion int
791-
ArtifactName string
792-
XcodeAuthOptions *xcodebuild.AuthenticationParams
795+
ProjectPath string
796+
Scheme string
797+
DestinationPlatform Platform
798+
Configuration string
799+
XcodeMajorVersion int
800+
ArtifactName string
801+
XcodeAuthOptions *xcodebuild.AuthenticationParams
793802

794803
PerformCleanAction bool
795804
XcconfigContent string
@@ -816,9 +825,14 @@ func (s XcodebuildArchiver) xcodeArchive(opts xcodeArchiveOpts) (xcodeArchiveRes
816825

817826
s.logger.TInfof("Reading xcode project")
818827

819-
platform, err := BuildableTargetPlatform(xcodeProj, scheme, configuration, opts.AdditionalOptions, XcodeBuild{}, s.logger)
820-
if err != nil {
821-
return out, fmt.Errorf("failed to read project platform: %s: %s", opts.ProjectPath, err)
828+
if opts.DestinationPlatform == detectPlatform {
829+
s.logger.TInfof("Platform is set to 'automatic', detecting platform from the project.")
830+
s.logger.TWarnf("Define the platform step input manually to avoid this phase in the future.")
831+
platform, err := BuildableTargetPlatform(xcodeProj, scheme, configuration, opts.AdditionalOptions, XcodeBuild{}, s.logger)
832+
if err != nil {
833+
return out, fmt.Errorf("failed to read project platform: %s: %s", opts.ProjectPath, err)
834+
}
835+
opts.DestinationPlatform = platform
822836
}
823837

824838
s.logger.TInfof("Reading main target")
@@ -869,7 +883,7 @@ and use 'Export iOS and tvOS Xcode archive' step to export an App Clip.`, opts.S
869883
archiveCmd.SetAuthentication(*opts.XcodeAuthOptions)
870884
}
871885

872-
additionalOptions := generateAdditionalOptions(string(platform), opts.AdditionalOptions)
886+
additionalOptions := generateAdditionalOptions(string(opts.DestinationPlatform), opts.AdditionalOptions)
873887
archiveCmd.SetCustomOptions(additionalOptions)
874888

875889
var swiftPackagesPath string

0 commit comments

Comments
 (0)