SwiftGen / SwiftGenPlugin

SwiftGen plugin for SPM
MIT License
92 stars 61 forks source link

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

Open cassianomonteiro opened 1 year ago

cassianomonteiro commented 1 year ago

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: "git@github.com: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”.
mickyzinho commented 1 year ago

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”.