Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't archive app (macCatalyst): Command PhaseScriptExecution failed with a nonzero exit code #801

Open
antfisher opened this issue Jan 22, 2023 · 8 comments

Comments

@antfisher
Copy link

antfisher commented Jan 22, 2023

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

@tomlokhorst
Copy link
Collaborator

From the error message, this looks similar to: #798

@deloitteshalem
Copy link

@antfisher were you able to get past this?

@marekpridal
Copy link

marekpridal commented Feb 11, 2023

I think it's different to #798 and I am unable to get around this. Here is the sample project with R.swift failing on Archive for Mac Catalyst.

rswift-catalyst.zip

@antfisher
Copy link
Author

antfisher commented Feb 16, 2023

From the error message, this looks similar to: #798

Seems like it is different.

@antfisher were you able to get past this?

@deloitteshalem No. But I've updated my first post. Now it should be easier to create a temporary fix.

@tomlokhorst
Copy link
Collaborator

Thank you both for doing some more research and providing an example project.

This indeed sounds like an SPM bug.

I'm not quite sure what to do about it.
I could try to create some hack to manipulate the path if I can somehow detect that the project is build for MacCatalyst.
But a better approach would be to report the bug at SPM, and wait for a bug fix there.

@Zeta611
Copy link

Zeta611 commented Mar 12, 2023

I'm having the same issue too.

@kyoji2
Copy link

kyoji2 commented Sep 14, 2023

I'm encountering the same issue. Does anyone know of any workarounds?

@antfisher
Copy link
Author

I'm encountering the same issue. Does anyone know of any workarounds?

Since the problem is specifically related to SPM, the first thing that comes to mind is to try an alternative way to install R.swift, for example, using Cocoapods or manually adding the R.swift library to your project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants