Skip to content

Commit 0f31221

Browse files
committed
add 'action' option, can assign 'build' or 'archive'
1 parent c229d13 commit 0f31221

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

Sources/CreateXCFramework/Command+Options.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ extension Command {
2525
@Option(help: ArgumentHelp("Build with a specific configuration", valueName: "debug|release"))
2626
var configuration = PackageModel.BuildConfiguration.release
2727

28+
@Option(help: ArgumentHelp("Action used to create artifact", valueName: "archive|build"))
29+
var action: XcodeBuildAction = .archive
30+
2831
@Flag(inversion: .prefixedNo, help: "Whether to clean before we build")
2932
var clean = true
3033

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// XcodeBuildAction.swift
3+
// swift-create-xcframework
4+
//
5+
// Created by Hanley Lee on 2024/6/1.
6+
//
7+
8+
import ArgumentParser
9+
10+
enum XcodeBuildAction: String, ExpressibleByArgument {
11+
case build
12+
case archive
13+
}

Sources/CreateXCFramework/XcodeBuilder.swift

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,17 @@ struct XcodeBuilder {
109109
"xcodebuild",
110110
"-project", self.path.pathString,
111111
"-configuration", self.options.configuration.xcodeConfigurationName,
112-
"-archivePath", self.buildDirectory.appendingPathComponent(self.productName(target: target)).appendingPathComponent(sdk.archiveName).path,
113112
"-destination", sdk.destination,
114113
"BUILD_DIR=\(self.buildDirectory.path)",
115114
"SKIP_INSTALL=NO"
116115
]
117116

117+
if self.options.action == .archive {
118+
command += [
119+
"-archivePath", self.buildDirectory.appendingPathComponent(self.productName(target: target)).appendingPathComponent(sdk.archiveName).path,
120+
]
121+
}
122+
118123
// add SDK-specific build settings
119124
if let settings = sdk.buildSettings {
120125
for setting in settings {
@@ -136,19 +141,30 @@ struct XcodeBuilder {
136141
command += [ "-scheme", target ]
137142

138143
// and the command
139-
command += [ "archive" ]
144+
if self.options.action == .build {
145+
command += [ "build" ]
146+
} else {
147+
command += [ "archive" ]
148+
}
140149

141150
return command
142151
}
143152

144153
// we should probably pull this from the build output but we just make assumptions here
145154
private func frameworkPath (target: String, sdk: TargetPlatform.SDK) -> Foundation.URL {
146-
return self.buildDirectory
147-
.appendingPathComponent(self.productName(target: target))
148-
.appendingPathComponent(sdk.archiveName)
149-
.appendingPathComponent("Products/Library/Frameworks")
150-
.appendingPathComponent("\(self.productName(target: target)).framework")
151-
.absoluteURL
155+
if self.options.action == .build {
156+
return self.buildDirectory
157+
.appendingPathComponent(sdk.releaseFolder)
158+
.appendingPathComponent("\(self.productName(target: target)).framework")
159+
.absoluteURL
160+
} else {
161+
return self.buildDirectory
162+
.appendingPathComponent(self.productName(target: target))
163+
.appendingPathComponent(sdk.archiveName)
164+
.appendingPathComponent("Products/Library/Frameworks")
165+
.appendingPathComponent("\(self.productName(target: target)).framework")
166+
.absoluteURL
167+
}
152168
}
153169

154170
// MARK: - Debug Symbols

0 commit comments

Comments
 (0)