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

Error using SwiftGen as SPM plugin in Xcode 15 #1075

Closed
TomaszLizer opened this issue Sep 19, 2023 · 2 comments
Closed

Error using SwiftGen as SPM plugin in Xcode 15 #1075

TomaszLizer opened this issue Sep 19, 2023 · 2 comments

Comments

@TomaszLizer
Copy link

TomaszLizer commented Sep 19, 2023

Hi all 👋

I am using SwiftGen plugin in few places as SPM plugin, one of which is creation of static accessors for Localizable.Strings.
SwiftGen is defined as Package dependency in other SwiftPackage (which uses it for codegen). Below is simplified definition of this Package (skipping other products/targets):

let package = Package(
    name: "StylePackage",
    defaultLocalization: "en",
    platforms: [.iOS(.v13), .macOS(.v10_15)],
    products: [
        .library(name: "AssetKit", targets: ["AssetKit"])
    ],
    dependencies: [
        .package(url: "https://github.com/lukepistrol/SwiftLintPlugin", .upToNextMinor(from: "0.2.2")),
        .package(url: "https://github.com/SwiftGen/SwiftGenPlugin", from: "6.6.0"),
    ],
    targets: [
        .target(
            name: "AssetKit",
            path: "Sources/AssetKit",
            plugins: [
                .plugin(name: "SwiftLint", package: "SwiftLintPlugin"),
                .plugin(name: "SwiftGenPlugin", package: "SwiftGenPlugin")
            ]
        ),
    ],
    swiftLanguageVersions: [.v5]
)

Using SwiftGen as SPM plugin with Xcode 15 ends with error:

Showing All Errors Only

Prepare packages

/usr/bin/sandbox-exec -p "(version 1)
(deny default)
(import \"system.sb\")
(allow file-read*)
(allow process*)
(allow file-write*
    (subpath \"/private/tmp\")
    (subpath \"/private/var/folders/5w/m87hs1f951z3974j7m46h05h0000gn/T\")
)
(deny file-write*
    (subpath \"/Users/tomaszlizer/Workspace/Repositories/IOS-Style-Kit\")
)
(allow file-write*
    (subpath \"/Users/tomaszlizer/Library/Developer/Xcode/DerivedData/IOS-Style-Kit-ejtosxfgrvjkqcfebfywljbtlqmo/SourcePackages/plugins/ios-style-kit.output/AssetKit/SwiftGenPlugin\")
)
" /Users/tomaszlizer/Library/Developer/Xcode/DerivedData/IOS-Style-Kit-ejtosxfgrvjkqcfebfywljbtlqmo/SourcePackages/artifacts/swiftgenplugin/swiftgen/swiftgen.artifactbundle/swiftgen/bin/swiftgen config run --verbose --config /Users/tomaszlizer/Workspace/Repositories/IOS-Style-Kit/Sources/AssetKit/swiftgen.yml

Error: You don’t have permission to save the file “StringsGenerated.swift” in the folder “Generated”.
Executing configuration file /Users/tomaszlizer/Workspace/Repositories/IOS-Style-Kit/Sources/AssetKit/swiftgen.yml
 $ swiftgen strings --templateName structured-swift5 --param publicAccess --param lookupFunction=stringLookup --output Resources/Generated/StringsGenerated.swift Resources/Localized/en.lproj
 $ swiftgen xcassets --templateName swift5 --param publicAccess --param bundle=Bundle.module --output Resources/Generated/AssetsGenerated.swift Resources/Assets.xcassets
Not writing the file as content is unchanged

Plug-in ended with non-zero exit code: 1)

Build stopped    19/09/2023, 12:40    0.3 seconds

Plugin works as expected with Xcode 14.3.1 with same codebase. This seems to be change in security policy in Xcode 15 but cannot find any setting / documentation allowing to override denial of write access to package directory.

[EDIT]:
Strangely plugin works for Xcode 14.3.1 yet it also shows similar deny write message compile time...

/usr/bin/sandbox-exec -p "(version 1)
(deny default)
(import \"system.sb\")
(allow file-read*)
(allow process*)
(allow file-write*
    (subpath \"/private/tmp\")
    (subpath \"/private/var/folders/5w/m87hs1f951z3974j7m46h05h0000gn/T\")
)
(deny file-write*
    (subpath \"/Users/tomaszlizer/Workspace/Repositories/IOS-Style-Kit\")
)
(allow file-write*
    (subpath \"/Users/tomaszlizer/Library/Developer/Xcode/DerivedData/IOS-Style-Kit-ejtosxfgrvjkqcfebfywljbtlqmo/SourcePackages/plugins/ios-style-kit.output/AssetKit/SwiftGenPlugin\")
)
" /Users/tomaszlizer/Library/Developer/Xcode/DerivedData/IOS-Style-Kit-ejtosxfgrvjkqcfebfywljbtlqmo/SourcePackages/artifacts/swiftgenplugin/swiftgen/swiftgen.artifactbundle/swiftgen/bin/swiftgen config run --verbose --config /Users/tomaszlizer/Workspace/Repositories/IOS-Style-Kit/Sources/AssetKit/swiftgen.yml

Executing configuration file /Users/tomaszlizer/Workspace/Repositories/IOS-Style-Kit/Sources/AssetKit/swiftgen.yml
 $ swiftgen strings --templateName structured-swift5 --param lookupFunction=stringLookup --param publicAccess --output Resources/Generated/StringsGenerated.swift Resources/Localized/en.lproj
 $ swiftgen xcassets --templateName swift5 --param bundle=Bundle.module --param publicAccess --output Resources/Generated/AssetsGenerated.swift Resources/Assets.xcassets
Not writing the file as content is unchanged
File written: Resources/Generated/StringsGenerated.swift

Build succeeded    19/09/2023, 12:59    1.3 seconds

SwiftGen config:

strings:
  inputs: Resources/Localized/en.lproj
  outputs:
    templateName: structured-swift5
    output: Resources/Generated/StringsGenerated.swift
    params:
        publicAccess: true
        lookupFunction: stringLookup
@TomaszLizer
Copy link
Author

I have solved that in the end.
Plugin can work seamlessly with Xcode 15 but cannot write to package directory, it can however write to build dir which will create sources used by compiler (somewhere in the build folder).
So one con is that there won't be actual file checked in the repository, pros is that no-one ever will be able to edit it manually 😅

Details here: SwiftGen/SwiftGenPlugin#14 (comment)

@TomaszLizer
Copy link
Author

Marking as resolved

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

1 participant