SwiftGenPlugin icon indicating copy to clipboard operation
SwiftGenPlugin copied to clipboard

`swift test` fails with "You don’t have permission to save the file"

Open cassianomonteiro opened this issue 2 years ago • 1 comments

When trying to run the package's tests in the command line using swift test, the plugin fails with You don’t have permission to save the file “L10n.swift” in the folder “Generated”..

To reproduce:

  1. Create a swift package manifest with a main and a test target. The main target should contain resources.
  2. Add the swiftgen plugin to the main target.
  3. Run swift test in the package root folder

My package example:

// swift-tools-version:5.7
import PackageDescription

let package = Package(
  name: "MyPackage",
  defaultLocalization: "en",
  platforms: [
    .iOS(.v14),
  ],
  products: [
    .library(name: "MyPackage", targets: ["MyPackage"])
  ],
  dependencies: [
    .package(url: "[email protected]:SwiftGen/SwiftGenPlugin.git", from: "6.6.0"),
  ],
  targets: [
    .target(
      name: "MyPackage",
      resources: [
        .process("Resources"),
      ],
      plugins: [
        .plugin(name: "SwiftGenPlugin", package: "SwiftGenPlugin"),
      ]
    ),
    .testTarget(
      name: "MyPackageTests",
      path: "MyPackageTests"
    ),
  ]
)

My swiftgen.yml file in the package root folder

strings:
    inputs: ./Sources/Resources/en.lproj
    outputs:
      - templateName: structured-swift5
        output: ./Sources/Generated/L10n.swift
        params:
            publicAccess: true

It works fine when running with Xcode (ie, open the package and run tests). However running swift test gives this error:

error: failed: PrebuildCommand(configuration: SPMBuildCore.BuildToolPluginInvocationResult.CommandConfiguration(displayName: Optional("SwiftGen BuildTool Plugin"), executable: <AbsolutePath:"/Users/cassiano/Developer/MyPackage/.build/artifacts/swiftgenplugin/swiftgen.artifactbundle/swiftgen/bin/swiftgen">, arguments: ["config", "run", "--verbose", "--config", "/Users/cassiano/Developer/MyPackage/swiftgen.yml"], environment: ["PROJECT_DIR": "/Users/cassiano/Developer/MyPackage", "PRODUCT_MODULE_NAME": "MyPackage", "TARGET_NAME": "MyPackage", "DERIVED_SOURCES_DIR": "/Users/cassiano/Developer/MyPackage/.build/plugins/outputs/mypackage/MyPackage/SwiftGenPlugin"], workingDirectory: nil), outputFilesDirectory: <AbsolutePath:"/Users/cassiano/Developer/MyPackage/.build/plugins/outputs/mypackage/MyPackage/SwiftGenPlugin">)

Executing configuration file /Users/cassiano/Developer/MyPackage/swiftgen.yml
 $ swiftgen strings --templateName structured-swift5 --param publicAccess --output ./Sources/Generated/L10n.swift ./Sources/Resources/en.lproj
Error: You don’t have permission to save the file “L10n.swift” in the folder “Generated”.

cassianomonteiro avatar Mar 24 '23 17:03 cassianomonteiro

We're experiencing a similar issue with swift package --allow-writing-to-package-directory generate-code-for-resources: Error: You don’t have permission to save the file “Localisation.swift” in the folder “Generated”.

mickyzinho avatar Jun 22 '23 09:06 mickyzinho