I created the experimental plugin @rzulkoski mentioned in the original post.
I created this plugin in preparation for integration with our app's SPM micro-feature architecture where we are currently running SwiftGen from commit hooks.
I can also replicate the issue described using Ryan's simplified example, and I'll admit I hadn't gotten this far with integration on the plugin that I built - for reasons I'll explain.
I forked the above reproducing example to play with this a bit myself, and in doing so I stripped down the example as much as possible. To make sure the issue is not in the SwiftGen executable or anywhere else I just created a simple executable binary with the sole purpose of creating a file with the current reference time interval as it's filename in Derived Data.
It is incredibly difficult to debug anything for these plugins.
Sometimes swift build
will give an error when Xcode does not
Xcode will say
Applying plugin "TouchPlugin" to target "iOSAppFeature"
But if you run swift build
you will receive
error: failed: PrebuildCommand(configuration: SPMBuildCore.BuildToolPluginInvocationResult.CommandConfiguration(displayName: Optional("Create a file"), executable: AbsolutePath:"/Users/nicolas.richard/Projects/PluginNotRunning/SwiftPackages/.build/arm64-apple-macosx/debug/Touch", arguments: ["674575448.053521"], environment: [:], workingDirectory: nil), outputFilesDirectory: AbsolutePath:"/Users/nicolas.richard/Projects/PluginNotRunning/SwiftPackages/.build/plugins/outputs/swiftpackages/iOSAppFeature/TouchPlugin")
No output from the executable is included anywhere in Xcode
It would obviously be extremely useful to have the executable's output for debugging
You are allowed to violate the rules of the package plugins and there are no errors at all
SE-0305 proposes that plugins cannot depend on an executable target inside the package for technical reasons. But there are no errors or warnings if you do so.
Just try pointing your plugin to an executableTarget instead of a binaryTarget. There are no errors or warnings. But the command does not run.
You can do this in my example fork by just switching out the comments from binaryTarget to executableTarget.
There is some kind of synchronization issue with FileManager for plugins
Related to why I haven't continued integration of the plugin into our apps.
I've tried to do some things like clear out the plugin folder before writing new files to it and the behaviour seems to be that the deletion can occur at any time before/after the write.
This causes issues if a filename changes, or if a generated file is meant to be deleted. Extra garbage is left in DerivedData and developers have an inconsistent experience.
I know that one potential solution is to work on a build command which explicitly states its inputs and outputs but I haven't had the time to try this yet.
I hope my perspective helps in looking at this issue / improving the functionality.
A big help to me and my pursuit would be information for how to obtain the output from the command my plugin is running and/or any additional debug information for the build tool plugin.