@@ -22,8 +22,19 @@ 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+
35+ if expectedFileName. contains ( " MultiplePublicTypes " ) {
36+ log. error ( " MultiplePublicTypes MUST NOT BE EMPTY! " ) // FIXME: xxx
37+ }
2738
2839 var printer = CodePrinter ( )
2940 printer. print ( " // Empty file generated on purpose " )
@@ -46,32 +57,49 @@ extension FFMSwift2JavaGenerator {
4657 outputDirectory: self . swiftOutputDirectory,
4758 javaPackagePath: nil ,
4859 filename: moduleFilename) {
49- print ( " [swift-java] Generated: \( moduleFilenameBase. bold) .swift (at \( outputFile) ) " )
60+ log . info ( " Generated: \( moduleFilenameBase. bold) .swift (at \( outputFile. absoluteString ) ) " )
5061 self . expectedOutputSwiftFiles. remove ( moduleFilename)
5162 }
5263 } catch {
5364 log. warning ( " Failed to write to Swift thunks: \( moduleFilename) " )
5465 }
5566
5667 // === 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) " )
68+ // We have to write all types to their corresponding output file that matches the file they were declared in,
69+ // because otherwise SwiftPM plugins will not pick up files apropriately -- we expect 1 output +SwiftJava.swift file for every input.
70+ for group : ( key: String , value: [ Dictionary < String , ImportedNominalType > . Element ] ) in Dictionary ( grouping: self . analysis. importedTypes, by: { $0. value. sourceFilePath } ) {
71+ log. warning ( " Writing types in file group: \( group. key) : \( group. value. map ( \. key) ) " )
72+
73+ let importedTypesForThisFile = group. value
74+ . map ( \. value)
75+ . sorted ( by: { $0. qualifiedName < $1. qualifiedName } )
76+
77+ let inputFileName = " \( group. key) " . split ( separator: " / " ) . last ?? " __Unknown.swift "
78+ let filename = " \( inputFileName) " . replacing ( " .swift " , with: " +SwiftJava.swift " )
79+
80+ for ty in importedTypesForThisFile {
81+ log. info ( " Printing Swift thunks for type: \( ty. qualifiedName. bold) " )
82+ printer. printSeparator ( " Thunks for \( ty. qualifiedName) " )
83+
84+ do {
85+ try printSwiftThunkSources ( & printer, ty: ty)
86+ } catch {
87+ log. warning ( " Failed to print to Swift thunks for type' \( ty. qualifiedName) ' to ' \( filename) ', error: \( error) " )
88+ }
89+
90+ }
6291
92+ log. warning ( " Write Swift thunks file: \( filename. bold) " )
6393 do {
64- try printSwiftThunkSources ( & printer, ty: ty)
65-
6694 if let outputFile = try printer. writeContents (
6795 outputDirectory: self . swiftOutputDirectory,
6896 javaPackagePath: nil ,
6997 filename: filename) {
70- print ( " [swift-java] Generated: \( fileNameBase . bold ) .swift (at \( outputFile) ) " )
98+ log . info ( " Done writing Swift thunks to: \( outputFile. absoluteString ) " )
7199 self . expectedOutputSwiftFiles. remove ( filename)
72100 }
73101 } catch {
74- log. warning ( " Failed to write to Swift thunks: \( filename) " )
102+ log. warning ( " Failed to write to Swift thunks: \( filename) , error: \( error ) " )
75103 }
76104 }
77105 }
0 commit comments