6

I have this Plugin

struct Main: BuildToolPlugin {
  func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
    let inputFolder = target.directory.appending("Image")
    let output = context.pluginWorkDirectory.appending("GeneratedImageAssets.swift")
    return [
      .buildCommand(
        displayName: "Running ImageAssets parser",
        executable: try context.tool(named: "ImageAssetsParser").path,
        arguments: [inputFolder.string, output.string],
        environment: [:],
        inputFiles: [inputFolder],
        outputFiles: [output]
      )
    ]
  }
}

ImageAssetsParser is an executableTarget in swift code that scan folders and write them in the output folder sent by the plugin.

Although locally it works everything, on Xcode Cloud I got permission error:

enter image description here

The weird things is that I have also a prebuildCommand plugin that uses swiftgen, as an artifactbundle and it works properly, it writes in same folder.

Am I missing something?

2 Answers 2

1

After months, by chance I found what was the issue!

In my plugin implementation I write the file through

"""
// auto generated swift file

// ... the content
""".write(to: output, atomically: true, encoding: .utf8)

Using atomically: true is the issue: this means that swift writes the entire content into a temporary file placed somewhere else and Xcode Cloud doesn't have permission in this moment!

Using atomically: false the file is written directly into our output file, which is the context.pluginWorkDirectory.appending("GeneratedImageAssets.swift") and permissions here hare granted!!

Sign up to request clarification or add additional context in comments.

Comments

-2

I had similar issue. Try replacing buildCommand with preBuildCommand that fixed the issue.

4 Comments

I cannot use a preBuildCommand in my context as I don't have a binary to execute but a target. Also I discovered that on Xcode 15 this issue is also for preBuildCommand
Indeed. I am also facing similar issue while using swiftgen prebuild command plugin on Xcode Cloud for Xcode 15. I am also wondering if there is some permission defaults i can set in post-clone script
I have the same issue after updating to Xcode 15. Please let me know, if you find a solution. I haven't been able to find one yet :/
@NicolaiHarbo I found a solution for my case!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.