SwiftGenPlugin: Plugin doesn't work with Xcode 15

I tried to build my project with Xcode 15 and got a new error:

Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “Strings+Generated.swift” in the folder “Generated”." UserInfo={NSFilePath=ticketchain/Supporting Files/Generated/Strings+Generated.swift, NSUnderlyingError=0x6000023308a0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

Does anyone know how to fix it ?

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 37
  • Comments: 18

Commits related to this issue

Most upvoted comments

[Update] Got it sorted out and works with current SwiftGenPlugin! 😃

Plugin already provides environment variables one of which is DERIVED_SOURCES_DIR. SwiftGen tool itself allows for environment variable usage - that means we can easily use such env variable in config. Below is example swiftgen.yml config working with Xcode 15:

xcassets:
  inputs: Resources/Assets.xcassets
  outputs:
    templateName: swift5
    output: ${DERIVED_SOURCES_DIR}/AssetsGenerated.swift
    params:
        bundle: Bundle.module
        publicAccess: true
        
strings:
  inputs: Resources/Localized/en.lproj
  outputs:
    templateName: structured-swift5
    output: ${DERIVED_SOURCES_DIR}/StringsGenerated.swift
    params:
        publicAccess: true
        lookupFunction: stringLookup

See that output uses ${DERIVED_SOURCES_DIR} env variable which is expanded by swiftgne during run, see docs: https://github.com/SwiftGen/SwiftGen/blob/6.6.2/Documentation/ConfigFile.md#environment-variables

One downside (at least for me) is that now it works, but won’t create file that can be checked in to the repository. That is little bit sad, because it allowed me to see what is changing while eg manipulating localisable strings. At the same time pros is that no-one will ever again try to manipulate that by hand… 🗡️

[Update2]: All of that is mentioned in the plugin documentation… https://github.com/SwiftGen/SwiftGenPlugin#add-a-swiftgen-config Solving the issue for few hours saved me 15 minutes of reading documentation 🤦‍♂️

  • Open Terminal
  • Go to Your yml file location under Localpackages- > XYourUIkit -> sources…
  • Run this command.
  • swift package --allow-writing-to-package-directory generate-code-for-resources

The upstream feedback: “If this works on Xcode 14, it was just a bug and Xcode 15 fixed it.”

https://github.com/apple/swift-package-manager/issues/6814

And we may consider using SwiftGen-Generate to replace such usage. (buildTool can’t have writeToPackageDirectory permission currently.)

However there is other issue with SwiftGen-Generate and the fix PR(#9) is still open.

As a temporary solution until the update comes in, you can use this functionality https://github.com/SwiftGen/SwiftGenPlugin#using-it-as-a-command to bypass the access rights error.

Using DERIVED_SOURCES_DIR still doesn’t work if I have a custom DerivedData directory on an external drive (Xcode -> Settings -> Locations). There were no issues with this prior to Xcode 15. Not sure if this is a SwiftGen issue, though. Probably an SPM issue.

Does it work for you with standard DerivedData directory? I noticed that swiftgen will also fail if you would try to have nests folder structure for generated files. Eg those should lie flat in the DERIVED_SOURCES_DIR or otherwise folder cannot be created. If it still fails then I suppose that is SPM issue and good one to create issue on their side.

I have mistakenly created similar issue but in SwiftGen cli repo: https://github.com/SwiftGen/SwiftGen/issues/1075 Generally this is also issue for me in my current project. Command workaround is not best solution since in my case we are using SwiftGen plugin inside other Swift Package.