Description
Archiving build for macCatalyst is always failed with error:
PhaseScriptExecution R.swift\ generate\ resources\ for\ application\----/Users/-------/Library/Developer/Xcode/DerivedData/-----cgdjxjbhuvkkviehgyewavizhdoh/Build/Intermediates.noindex/ArchiveIntermediates/----/IntermediateBuildFilesPath/----.build/Release-maccatalyst/----.build/Script-C28EBBAA297DAB5B00847376.sh (in target '----' from project '----')
cd /Users/--------/WorkProjects/----
/bin/sh -c /Users/-------/Library/Developer/Xcode/DerivedData/-----cgdjxjbhuvkkviehgyewavizhdoh/Build/Intermediates.noindex/ArchiveIntermediates/----/IntermediateBuildFilesPath/----.build/Release-maccatalyst/----.build/Script-C28EBBAA297DAB5B00847376.sh
sandbox-exec: execvp() of '//Users/--------/Library/Developer/Xcode/DerivedData/-----cgdjxjbhuvkkviehgyewavizhdoh/Build/Intermediates.noindex/ArchiveIntermediates/----/BuildProductsPath/Release/rswift' failed: No such file or directory
Command PhaseScriptExecution failed with a nonzero exit code
R.swift installed using SPM. M1 pro mac used.
The issue is reproducible only for archive builds and only for macCatalyst.
Update:
After some research, I found that the reason for the issue is a wrong path to rswift executable. :)
#if canImport(XcodeProjectPlugin)
import XcodeProjectPlugin
extension RswiftGeneratePublicResources: XcodeBuildToolPlugin {
func createBuildCommands(context: XcodePluginContext, target: XcodeTarget) throws -> [Command] {
let resourcesDirectoryPath = context.pluginWorkDirectory
.appending(subpath: target.displayName)
.appending(subpath: "Resources")
try FileManager.default.createDirectory(atPath: resourcesDirectoryPath.string, withIntermediateDirectories: true)
let rswiftPath = resourcesDirectoryPath.appending(subpath: "R.generated.swift")
let description: String
if let product = target.product {
description = "\(product.kind) \(target.displayName)"
} else {
description = target.displayName
}
return [
.buildCommand(
displayName: "R.swift generate resources for \(description)",
executable: try context.tool(named: "rswift").path,
arguments: [
"generate", rswiftPath.string,
"--target", target.displayName,
"--input-type", "xcodeproj",
"--bundle-source", "finder",
"--access-level", "public",
],
outputFiles: [rswiftPath]
),
]
}
}
#endif
As you can see, the path to the executable is produced with context.tool(named: "rswift").path
. And it generates something like this:
...DerivedData/APP_NAME/Build/Intermediates.noindex/.../BuildProductsPath/Release/rswift
And an executable can be found with this path, but only while building for ios.
When archiving for MacCatalyst the right path should be:
...DerivedData/APP_NAME/Build/Intermediates.noindex/.../BuildProductsPath/Release-maccatalyst/rswift
So it seems like it is an SPM bug