Apologies in advance for the long post (and reviving this thread)...
@rzulkoski @nicorichard I'm trying to do a very similar (if not the same) thing, but am running into the same issues as above. The difference in my use case is that I'm trying to use SwiftGenPlugin in a pre-commit hook for a server-side Vapor application. You can see my Package.swift
here:
// swift-tools-version:5.6
import PackageDescription
let package = Package(
name: "wishlist-server",
platforms: [
.macOS(.v12)
],
dependencies: [
// đź’§ A server-side Swift web framework.
.package(url: "https://github.com/SwiftGen/SwiftGenPlugin", from: "6.6.2"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
],
targets: [
.target(
name: "App",
dependencies: [
.product(name: "Vapor", package: "vapor")
],
resources: [.process("Resources")],
swiftSettings: [
.unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))
],
plugins: [
.plugin(name: "SwiftGenPlugin", package: "SwiftGenPlugin")
]
),
.executableTarget(name: "Run", dependencies: [.target(name: "App")]),
.testTarget(
name: "AppTests",
dependencies: [
.target(name: "App"),
.product(name: "XCTVapor", package: "vapor"),
]
)
]
)
And the relevant portion of my pre-commit
file is here (SwiftGen should be run during swift test
, as that also builds):
#!/bin/sh
XCPRETTY=$(which xcpretty)
if [[ -e "${XCPRETTY}" ]]; then
echo "[SWIFT TEST] Testing..."
swift test 2>&1 | $XCPRETTY
else
echo "[SWIFT TEST] xcpretty does not exist, download from https://github.com/xcpretty/xcpretty"
swift test 2>&1
fi
Building in Xcode works and properly generates my Strings.generated.swift
file. This was the expected behavior and I'm glad this is working.
However, running swift build
or swift test
in the CLI (ex: pre-commit
hook, or manually via Terminal) does not work as expected.
Here is the error I'm getting in my pre-commit
hook (formatted for readability):
[SWIFT TEST] Testing...
❌ error: failed: PrebuildCommand(
configuration: SPMBuildCore.BuildToolPluginInvocationResult.CommandConfiguration(
displayName: Optional("SwiftGen BuildTool Plugin"),
executable: <AbsolutePath:"path/to/project/.build/artifacts/swiftgenplugin/swiftgen.artifactbundle/swiftgen/bin/swiftgen">,
arguments: [
"config",
"run",
"--verbose",
"--config",
"/path/to/project/swiftgen.yml"
],
environment: [
"TARGET_NAME": "App",
"DERIVED_SOURCES_DIR": "/path/to/project/.build/plugins/outputs/wishlist-server/App/SwiftGenPlugin",
"PRODUCT_MODULE_NAME": "App",
"PROJECT_DIR": "/path/to/project"
],
workingDirectory: nil
),
outputFilesDirectory: <AbsolutePath:"/path/to/project/.build/plugins/outputs/wishlist-server/App/SwiftGenPlugin">
)
As you can see (and have experienced yourselves), It's not particularly informative. But, if I now run swift build
manually via CLI, I get the same error as above, but fortunately with a little more info:
Executing configuration file /path/to/project/swiftgen.yml
$ swiftgen strings --templatePath ./swiftgen-structured-swift5.stencil --param publicAccess --output ./Sources/App/Enums/Strings.generated.swift ./Resources/Localizable.strings ./Resources/Localizable.stringsdict
Error: You don’t have permission to save the file “Strings.generated.swift” in the folder “Enums”.
I was also able to find this thread that may be related (also with no resolution).
Would love any assistance getting this working!