@@ -44,7 +44,10 @@ package class JNISwift2JavaGenerator: Swift2JavaGenerator {
4444
4545 /// Because we need to write empty files for SwiftPM, keep track which files we didn't write yet,
4646 /// and write an empty file for those.
47- var expectedOutputSwiftFiles : Set < String >
47+ ///
48+ /// Since Swift files in SwiftPM builds needs to be unique, we use this fact to flatten paths into plain names here.
49+ /// For uniqueness checking "did we write this file already", just checking the name should be sufficient.
50+ var expectedOutputSwiftFileNames : Set < String >
4851
4952 package init (
5053 config: Configuration ,
@@ -64,27 +67,34 @@ package class JNISwift2JavaGenerator: Swift2JavaGenerator {
6467 self . javaClassLookupTable = javaClassLookupTable
6568 self . lookupContext = translator. lookupContext
6669
67- // If we are forced to write empty files, construct the expected outputs
70+ // If we are forced to write empty files, construct the expected outputs.
71+ // It is sufficient to use file names only, since SwiftPM requires names to be unique within a module anyway.
6872 if translator. config. writeEmptyFiles ?? false {
69- self . expectedOutputSwiftFiles = Set ( translator. inputs. compactMap { ( input) -> String ? in
70- guard let filePathPart = input. path. split ( separator: " / \( translator. swiftModuleName) / " ) . last else {
73+ self . expectedOutputSwiftFileNames = Set ( translator. inputs. compactMap { ( input) -> String ? in
74+ // guard let filePathPart = input.path.split(separator: "/\(translator.swiftModuleName)/").last else {
75+ // return nil
76+ // }
77+ // return String(filePathPart.replacing(".swift", with: "+SwiftJava.swift"))
78+ guard let fileName = input. path. split ( separator: PATH_SEPARATOR) . last else {
7179 return nil
7280 }
73-
74- return String ( filePathPart. replacing ( " .swift " , with: " +SwiftJava.swift " ) )
81+ guard fileName. hasSuffix ( " .swift " ) else {
82+ return nil
83+ }
84+ return String ( fileName. replacing ( " .swift " , with: " +SwiftJava.swift " ) )
7585 } )
76- self . expectedOutputSwiftFiles . insert ( " \( translator. swiftModuleName) Module+SwiftJava.swift " )
77- self . expectedOutputSwiftFiles . insert ( " Foundation+SwiftJava.swift " )
86+ self . expectedOutputSwiftFileNames . insert ( " \( translator. swiftModuleName) Module+SwiftJava.swift " )
87+ self . expectedOutputSwiftFileNames . insert ( " Foundation+SwiftJava.swift " )
7888 } else {
79- self . expectedOutputSwiftFiles = [ ]
89+ self . expectedOutputSwiftFileNames = [ ]
8090 }
8191 }
8292
8393 func generate( ) throws {
8494 try writeSwiftThunkSources ( )
8595 try writeExportedJavaSources ( )
8696
87- let pendingFileCount = self . expectedOutputSwiftFiles . count
97+ let pendingFileCount = self . expectedOutputSwiftFileNames . count
8898 if pendingFileCount > 0 {
8999 print ( " [swift-java] Write empty [ \( pendingFileCount) ] 'expected' files in: \( swiftOutputDirectory) / " )
90100 try writeSwiftExpectedEmptySources ( )
0 commit comments