Only generates Swift interface for mixed source
We have internal tooling that publishes Swift interfaces for comment and review. For Swift-only frameworks our tooling works fine simply getting the abstract syntax tree of the Swift source code. However, this approach doesn't work when the source contains, or is primarily, Objective-C.
We have an alternate process that will process *.swiftinterface files, but we have yet to find a process that works for generating these files from Objective-C or mixed source except for using the internal Xcode Generated interface. We are searching for a programmatic solution.
Based on comments here (https://github.com/jpsim/SourceKitten/issues/405) I was hoping that this tool might solve our issue. However, when I run it on a simple dummy framework, which contains a SwiftClass object and an ObjCClass object, the generated interface only includes the SwiftClass interface even though the bridged ObjCClass is exposed.
Is ModuleInterface intended to work with mixed source, or is it strictly for Swift-only frameworks (or the Swift-only portion of mixed frameworks)?
It was designed for Swift interfaces, as I didn't thought of the objc use case. I'd need to capture which request does SourceKit launch in order to create the Objc interface object, as I don't use the *.swiftinterface file to generate the module.
The generated module follows the *.swiftinterface format, but I found a way to get these from SourceKitten.
import SourceKittenFramework
if sourceUrl.absoluteString.hasSuffix("h") {
let args = [String]()
let generated = try Request.interface(file: sourceUrl.absoluteString, uuid: NSUUID().uuidString, arguments: args).send()
if let match = generated.first(where: { key, _ in
return key == "key.sourcetext"
}) {
let sourceCode = match.value as! String
// do whatever with the swiftinterface code
}
Since this is not a use case for ModuleInterface, I'll close this issue.
With this snippet I could add support for both kind of sources as an enhancement.
I think it would be a worthy enhancement. In our case, we process Swift source file-by-file and generate a final artifact. Using SourceKitten we can process *.h files individually, convert them to Swift interface (which we then have to process since Swift interface != swift source code) and it all works out. It might be tricky depending on how you combine things.
Our finalized, combined representation looks like (for our demo package)

I think this would be a nice improvement to this library 👍
I agree :)
PRs are welcome if you want to help with this!🤩