Write permission for SPM SwiftLint Plugin

Viewed 29

I have managed to run SwiftLint as plugin for my project

struct Linting: BuildToolPlugin {
    func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
      let swiftLintConfigFile = context.package.directory.appending(".swiftlint.yml")
      let genSourcesDir = context.pluginWorkDirectory.appending("output")

      return [
            .buildCommand(
                displayName: "Running SwiftLint for \(target.name)",
                executable: try context.tool(named: "swiftlint").path,
                arguments: [
                    "lint",
                    "--config",
                    swiftLintConfigFile
                ],
                environment: [:],
                outputFiles: [genSourcesDir]
            
            )
        ]
    }

}

everything is working as expected and I can see the errors/warnings of SwiftLint but the problem is That I always get Command PhaseScriptExecution failed with a nonzero exit code

Xcode log

Here is my Package.swift

let package = Package(
  name: "APP",
  products: [
    .library(name: "AppFeature", targets: ["AppFeature"]),
    .library(name: "Models", targets: ["Models"]),
    
    .plugin(name: "Linting", targets: ["Linting"])
  ],
  dependencies: [],
  targets: [
  
    .target(name: "AppFeature", dependencies: ["Models"], plugins: ["Linting"]),
    .target(name: "Models"),
    
    .binaryTarget(name: "SwiftLintBinary", path: "Sources/SwiftLintBinary.artifactbundle"),
    .plugin(
      name: "Linting",
      capability: .buildTool(),
      dependencies: [
        "SwiftLintBinary"
      ]
    ),
    
    .testTarget(name: "AppFeatureTests", dependencies: ["AppFeature"]),
  ]
)

The Package belong to a Xcode project like the following.

project setup

I also have checked what does the Error I am getting means

Error: You don’t have permission to save the file “d42b39293bc4ddcfb20c48bf35251e7209d7ddee87edd739b0bc0bab05584478.plist” in the folder “8FE8CC02-8D70-373F-99BE-864A503CD73A”.

it turned out that the 8FE8CC02-8D70-373F-99BE-864A503CD73A is a folder being used by SwiftLint to cache some findings

.//Library/Caches/SwiftLint/0.49.0/8FE8CC02-8D70-373F-99BE-864A503CD73A

the weird thing is if I run the swiftlint from the Mac terminal it just works using ./Sources/SwiftLintBinary.artifactbundle/swiftlint-0.49.0-macos/bin/swiftlint but from Xcode it doesn't, any help would be appreciated.

0 Answers
Related