SwiftGenPlugin
SwiftGenPlugin copied to clipboard
`swift test` fails with "You don’t have permission to save the file"
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:
- Create a swift package manifest with a main and a test target. The main target should contain resources.
- Add the swiftgen plugin to the main target.
- Run
swift testin 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”.
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”.