From c229d13fbe3935abfe3d325af86f95305a833fe7 Mon Sep 17 00:00:00 2001 From: Hanley Lee Date: Sat, 1 Jun 2024 11:48:54 +0800 Subject: [PATCH 1/2] fix: user encounter error when use option: `--xc-setting OTHER_SWIFT_FLAGS="-debug-prefix-map $PWD=."` --- Sources/CreateXCFramework/BuildSetting.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/CreateXCFramework/BuildSetting.swift b/Sources/CreateXCFramework/BuildSetting.swift index a7482c7..afddc0d 100644 --- a/Sources/CreateXCFramework/BuildSetting.swift +++ b/Sources/CreateXCFramework/BuildSetting.swift @@ -16,7 +16,7 @@ struct BuildSetting: ExpressibleByArgument { let value: String init?(argument: String) { - let components = argument.components(separatedBy: "=") + let components = argument.split(separator: "=", maxSplits: 1) guard components.count == 2 else { return nil } self.name = components[0].trimmingCharacters(in: .whitespacesAndNewlines) self.value = components[1].trimmingCharacters(in: .whitespacesAndNewlines) From 0f3122108afb99874127241531534227067ddcf2 Mon Sep 17 00:00:00 2001 From: Hanley Lee Date: Sat, 1 Jun 2024 12:39:07 +0800 Subject: [PATCH 2/2] add 'action' option, can assign 'build' or 'archive' --- .../CreateXCFramework/Command+Options.swift | 3 ++ .../CreateXCFramework/XcodeBuildAction.swift | 13 ++++++++ Sources/CreateXCFramework/XcodeBuilder.swift | 32 ++++++++++++++----- 3 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 Sources/CreateXCFramework/XcodeBuildAction.swift diff --git a/Sources/CreateXCFramework/Command+Options.swift b/Sources/CreateXCFramework/Command+Options.swift index 238e46c..551cda9 100644 --- a/Sources/CreateXCFramework/Command+Options.swift +++ b/Sources/CreateXCFramework/Command+Options.swift @@ -25,6 +25,9 @@ extension Command { @Option(help: ArgumentHelp("Build with a specific configuration", valueName: "debug|release")) var configuration = PackageModel.BuildConfiguration.release + @Option(help: ArgumentHelp("Action used to create artifact", valueName: "archive|build")) + var action: XcodeBuildAction = .archive + @Flag(inversion: .prefixedNo, help: "Whether to clean before we build") var clean = true diff --git a/Sources/CreateXCFramework/XcodeBuildAction.swift b/Sources/CreateXCFramework/XcodeBuildAction.swift new file mode 100644 index 0000000..7c3da5a --- /dev/null +++ b/Sources/CreateXCFramework/XcodeBuildAction.swift @@ -0,0 +1,13 @@ +// +// XcodeBuildAction.swift +// swift-create-xcframework +// +// Created by Hanley Lee on 2024/6/1. +// + +import ArgumentParser + +enum XcodeBuildAction: String, ExpressibleByArgument { + case build + case archive +} diff --git a/Sources/CreateXCFramework/XcodeBuilder.swift b/Sources/CreateXCFramework/XcodeBuilder.swift index a48b1e9..9c1de7f 100644 --- a/Sources/CreateXCFramework/XcodeBuilder.swift +++ b/Sources/CreateXCFramework/XcodeBuilder.swift @@ -109,12 +109,17 @@ struct XcodeBuilder { "xcodebuild", "-project", self.path.pathString, "-configuration", self.options.configuration.xcodeConfigurationName, - "-archivePath", self.buildDirectory.appendingPathComponent(self.productName(target: target)).appendingPathComponent(sdk.archiveName).path, "-destination", sdk.destination, "BUILD_DIR=\(self.buildDirectory.path)", "SKIP_INSTALL=NO" ] + if self.options.action == .archive { + command += [ + "-archivePath", self.buildDirectory.appendingPathComponent(self.productName(target: target)).appendingPathComponent(sdk.archiveName).path, + ] + } + // add SDK-specific build settings if let settings = sdk.buildSettings { for setting in settings { @@ -136,19 +141,30 @@ struct XcodeBuilder { command += [ "-scheme", target ] // and the command - command += [ "archive" ] + if self.options.action == .build { + command += [ "build" ] + } else { + command += [ "archive" ] + } return command } // we should probably pull this from the build output but we just make assumptions here private func frameworkPath (target: String, sdk: TargetPlatform.SDK) -> Foundation.URL { - return self.buildDirectory - .appendingPathComponent(self.productName(target: target)) - .appendingPathComponent(sdk.archiveName) - .appendingPathComponent("Products/Library/Frameworks") - .appendingPathComponent("\(self.productName(target: target)).framework") - .absoluteURL + if self.options.action == .build { + return self.buildDirectory + .appendingPathComponent(sdk.releaseFolder) + .appendingPathComponent("\(self.productName(target: target)).framework") + .absoluteURL + } else { + return self.buildDirectory + .appendingPathComponent(self.productName(target: target)) + .appendingPathComponent(sdk.archiveName) + .appendingPathComponent("Products/Library/Frameworks") + .appendingPathComponent("\(self.productName(target: target)).framework") + .absoluteURL + } } // MARK: - Debug Symbols