Hey!
I am trying to create an R.swift BuildToolPlugin with the help of SE0325, SE0332 and SE0303.
Unfortunately I end up getting the following error:
Failed to run build tool plugins: plugin process ended by an uncaught signal: 4 <command: /usr/bin/sandbox-exec -p '(version 1)
Showing Recent Messages
(deny default)
(import "system.sb")
(allow file-read*)
(allow process*)
(allow file-write*
(subpath "/private/tmp")
(subpath "/private/var/folders/rn/y9q4wz7n5fg84ymy0rxsxjv80000gn/T")
)
(deny file-write*
(subpath "/Users/user/Developer/myProject-ios/app/myProject/Components")
)
(allow file-write*
(subpath "/Users/user/Library/Developer/Xcode/DerivedData/myProject-apioztmvvdcrptgqqpavjxfgqryl/SourcePackages")
(subpath "/Users/user/Library/Developer/Xcode/DerivedData/myProject-apioztmvvdcrptgqqpavjxfgqryl/SourcePackages/plugins")
)
' /Users/user/Library/Developer/Xcode/DerivedData/myProject-apioztmvvdcrptgqqpavjxfgqryl/SourcePackages/plugins/RSwiftPlugin>, <output:
'Swift/ErrorType.swift:200: Fatal error: Error raised at top level: Swift.DecodingError.typeMismatch(PackagePlugin.WireInput.Target.TargetInfo.BinaryArtifactKind, Swift.DecodingError.Context(codingPath: [PerformActionCodingKeys(stringValue: "input", intValue: nil), CodingKeys(stringValue: "targets", intValue: nil), _JSONKey(stringValue: "Index 14", intValue: 14), CodingKeys(stringValue: "info", intValue: nil), BinaryArtifactInfoCodingKeys(stringValue: "kind", intValue: nil)], debugDescription: "Invalid number of keys found, expected one.", underlyingError: nil))
I think I made a mistake in the config, but I can't pinpoint it. Trying to interpret the error message, I would say I messed up the binary target configuration (I just downloaded the rswift binary and zipped it).
My project structure looks like this:
Components
├ Package.swift
├ Plugins
└ RSwiftPlugin
├ gen
└ RSwiftPlugin.swift
└ Sources
├ Rswift
└ Rswift.zip
└ Assets
RSwiftPlugin:
import PackagePlugin
@main struct RSwiftPlugin: BuildToolPlugin {
func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
let outputPath = context.pluginWorkDirectory.appending("gen")
let outputFilePath = outputPath.appending("R.generated.swift")
print("outputFilePath is: \(outputPath)")
return [
.prebuildCommand(
displayName: "running rswift",
executable: try context.tool(named: "rswift").path,
arguments: [
"generate",
"--accessLevel", "public",
"\(outputFilePath)"],
environment: [
"PROJECT_DIR": "\(context.package.directory)",
"TARGET_NAME": "\(target.name)"
],
outputFilesDirectory: outputPath
)
]
}
}
Package.swift:
import PackageDescription
let package = Package(
name: "Components",
platforms: [.iOS(.v14), .macOS(.v10_15)],
products: [
.library(name: "Assets", targets: ["Assets"]),
.plugin(name: "RSwiftPlugin", targets: ["RSwiftPlugin"])
],
dependencies: [
.package(url: "https://github.com/mac-cain13/R.swift.Library", from: "5.2.0")
],
targets: [
.binaryTarget(name: "rswift", path: "Sources/Rswift/rswift.zip"),
.plugin(
name: "RSwiftPlugin",
capability: .buildTool()
),
.target(
name: "Assets",
dependencies: [.product(name: "Rswift", package: "R.swift.Library")],
resources: [.process("Files")],
plugins: [.plugin(name: "RSwiftPlugin")])
]
)
Does anyone have an idea? Any help would be great. Thank you very much and have a nice day,
Arsatius