@@ -22,8 +22,16 @@ extension FFMSwift2JavaGenerator {
2222 }
2323
2424 package func writeSwiftExpectedEmptySources( ) throws {
25+ let pendingFileCount = self . expectedOutputSwiftFiles. count
26+ guard pendingFileCount > 0 else {
27+ return // no need to write any empty files, yay
28+ }
29+
30+ print ( " [swift-java] Write empty [ \( self . expectedOutputSwiftFiles. count) ] 'expected' files in: \( swiftOutputDirectory) / " )
31+
2532 for expectedFileName in self . expectedOutputSwiftFiles {
26- log. trace ( " Write empty file: \( expectedFileName) ... " )
33+ log. debug ( " Write SwiftPM-'expected' empty file: \( expectedFileName. bold) " )
34+
2735
2836 var printer = CodePrinter ( )
2937 printer. print ( " // Empty file generated on purpose " )
@@ -46,32 +54,49 @@ extension FFMSwift2JavaGenerator {
4654 outputDirectory: self . swiftOutputDirectory,
4755 javaPackagePath: nil ,
4856 filename: moduleFilename) {
49- print ( " [swift-java] Generated: \( moduleFilenameBase. bold) .swift (at \( outputFile) ) " )
57+ log . info ( " Generated: \( moduleFilenameBase. bold) .swift (at \( outputFile. absoluteString ) ) " )
5058 self . expectedOutputSwiftFiles. remove ( moduleFilename)
5159 }
5260 } catch {
5361 log. warning ( " Failed to write to Swift thunks: \( moduleFilename) " )
5462 }
5563
5664 // === All types
57- // FIXME: write them all into the same file they were declared from +SwiftJava
58- for (_, ty) in self . analysis. importedTypes. sorted ( by: { ( lhs, rhs) in lhs. key < rhs. key } ) {
59- let fileNameBase = " \( ty. swiftNominal. qualifiedName) +SwiftJava "
60- let filename = " \( fileNameBase) .swift "
61- log. debug ( " Printing contents: \( filename) " )
65+ // We have to write all types to their corresponding output file that matches the file they were declared in,
66+ // because otherwise SwiftPM plugins will not pick up files apropriately -- we expect 1 output +SwiftJava.swift file for every input.
67+ for group : ( key: String , value: [ Dictionary < String , ImportedNominalType > . Element ] ) in Dictionary ( grouping: self . analysis. importedTypes, by: { $0. value. sourceFilePath } ) {
68+ log. warning ( " Writing types in file group: \( group. key) : \( group. value. map ( \. key) ) " )
69+
70+ let importedTypesForThisFile = group. value
71+ . map ( \. value)
72+ . sorted ( by: { $0. qualifiedName < $1. qualifiedName } )
73+
74+ let inputFileName = " \( group. key) " . split ( separator: " / " ) . last ?? " __Unknown.swift "
75+ let filename = " \( inputFileName) " . replacing ( " .swift " , with: " +SwiftJava.swift " )
76+
77+ for ty in importedTypesForThisFile {
78+ log. info ( " Printing Swift thunks for type: \( ty. qualifiedName. bold) " )
79+ printer. printSeparator ( " Thunks for \( ty. qualifiedName) " )
80+
81+ do {
82+ try printSwiftThunkSources ( & printer, ty: ty)
83+ } catch {
84+ log. warning ( " Failed to print to Swift thunks for type' \( ty. qualifiedName) ' to ' \( filename) ', error: \( error) " )
85+ }
86+
87+ }
6288
89+ log. warning ( " Write Swift thunks file: \( filename. bold) " )
6390 do {
64- try printSwiftThunkSources ( & printer, ty: ty)
65-
6691 if let outputFile = try printer. writeContents (
6792 outputDirectory: self . swiftOutputDirectory,
6893 javaPackagePath: nil ,
6994 filename: filename) {
70- print ( " [swift-java] Generated: \( fileNameBase . bold ) .swift (at \( outputFile) ) " )
95+ log . info ( " Done writing Swift thunks to: \( outputFile. absoluteString ) " )
7196 self . expectedOutputSwiftFiles. remove ( filename)
7297 }
7398 } catch {
74- log. warning ( " Failed to write to Swift thunks: \( filename) " )
99+ log. warning ( " Failed to write to Swift thunks: \( filename) , error: \( error ) " )
75100 }
76101 }
77102 }
0 commit comments