Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cassianomonteiro opened this issue Mar 24, 2023 · 1 comment

Comments

@cassianomonteiro
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants