Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions Sources/SwiftBundler/Bundler/Xcodebuild/Xcodebuild.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,41 @@ enum Xcodebuild {
.map(\.rawValue)
.joined(separator: "_")

// Needs to be modified if simulatorSpecifier is specified
var additionalArguments = context.additionalArguments

var destinationString: String
if [.macOS, .macCatalyst].contains(platform) {
if context.architectures.count == 1 {
destinationString = "platform=macOS,arch=\(archString)"
} else {
destinationString = "generic/platform=macOS"
}
} else if platform.isSimulator {
// BundleCommand/doBundling forwards the simulator specifier if specified
if let index = additionalArguments.firstIndex(of: "simulatorSpecifier"),
additionalArguments.count > index + 1
{
let specifier = additionalArguments[index + 1]
// The simulator specifier is not an argument that should be
// forwarded to xcodebuild, so it needs to be removed
additionalArguments.removeSubrange(index...index + 1)

// --simulator supports UUID and name, which need to be handled
// separately for xcodebuild
if UUID(uuidString: specifier) != nil {
destinationString = "platform=\(applePlatform.xcodeDestinationName),id=\(specifier)"
} else {
destinationString = "platform=\(applePlatform.xcodeDestinationName),name=\(specifier)"
}
} else {
// Fallback
destinationString = "generic/platform=\(applePlatform.xcodeDestinationName)"
}
} else {
destinationString = "generic/platform=\(applePlatform.xcodeDestinationName)"
}

if let variant = platform.asApplePlatform?.xcodeDestinationVariant {
destinationString += ",variant=\(variant)"
}
Expand Down Expand Up @@ -128,9 +153,9 @@ enum Xcodebuild {
".build/\(archString)-apple-\(suffix)"
).path,
]
+ destinationArguments
+ context.additionalArguments
+ metadataArguments,
+ destinationArguments
+ additionalArguments
+ metadataArguments,
directory: context.projectDirectory,
runSilentlyWhenNotVerbose: false
)
Expand All @@ -157,7 +182,7 @@ enum Xcodebuild {
try await process.runAndWait()
} catch {
throw Error(
.failedToRunXcodebuild( command: "Failed to run xcodebuild."),
.failedToRunXcodebuild(command: "Failed to run xcodebuild."),
cause: error
)
}
Expand Down
18 changes: 15 additions & 3 deletions Sources/SwiftBundler/Commands/BundleCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,20 @@ struct BundleCommand: ErrorHandledCommand {
)
}

// Forwards the simulatorSpecifier if set, so it can be used in the
// xcodebuild command generation
var additionalArguments =
isUsingXcodebuild
? arguments.additionalXcodeBuildArguments
: arguments.additionalSwiftPMArguments

if isUsingXcodebuild,
let specifier = arguments.simulatorSpecifier
{
additionalArguments.append("simulatorSpecifier")
additionalArguments.append(specifier)
}

let buildContext = SwiftPackageManager.BuildContext(
genericContext: GenericBuildContext(
projectDirectory: packageDirectory,
Expand All @@ -591,9 +605,7 @@ struct BundleCommand: ErrorHandledCommand {
architectures: architectures,
platform: resolvedPlatform,
platformVersion: platformVersion,
additionalArguments: isUsingXcodebuild
? arguments.additionalXcodeBuildArguments
: arguments.additionalSwiftPMArguments
additionalArguments: additionalArguments
),
hotReloadingEnabled: hotReloadingEnabled,
isGUIExecutable: true,
Expand Down
Loading