Skip to content

Commit 30b0ce0

Browse files
committed
migrate to shared tool
1 parent 632eb0b commit 30b0ce0

File tree

6 files changed

+18
-19
lines changed

6 files changed

+18
-19
lines changed

Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ package class FFMSwift2JavaGenerator: Swift2JavaGenerator {
5353

5454
func generate() throws {
5555
try writeSwiftThunkSources()
56+
print("[swift-java] Generated Swift sources (module: '\(self.swiftModuleName)') in: \(swiftOutputDirectory)/")
57+
5658
try writeExportedJavaSources()
59+
print("[swift-java] Generated Java sources (package: '\(javaPackage)') in: \(javaOutputDirectory)/")
5760
}
5861
}
5962

Sources/JExtractSwiftLib/Swift2Java.swift

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public struct SwiftToJava {
3131
}
3232

3333
let translator = Swift2JavaTranslator(
34-
javaPackage: config.javaPackage ?? "", // no package is ok, we'd generate all into top level
3534
swiftModuleName: swiftModule
3635
)
3736
translator.log.logLevel = config.logLevel ?? .info
@@ -89,27 +88,18 @@ public struct SwiftToJava {
8988

9089
try translator.analyze()
9190

92-
switch mode {
93-
case .ffm:
91+
switch config.mode {
92+
case .some(.ffm), .none:
9493
let generator = FFMSwift2JavaGenerator(
9594
translator: translator,
96-
javaPackage: self.packageName,
97-
swiftOutputDirectory: outputDirectorySwift,
98-
javaOutputDirectory: outputDirectoryJava
95+
javaPackage: config.javaPackage ?? "",
96+
swiftOutputDirectory: outputSwiftDirectory,
97+
javaOutputDirectory: outputJavaDirectory
9998
)
10099

101100
try generator.generate()
102101
}
103102

104-
105-
print("[swift-java] Generated Java sources (\(packageName)) in: \(outputDirectoryJava)/")
106-
107-
try translator.writeSwiftThunkSources(outputDirectory: outputSwiftDirectory)
108-
print("[swift-java] Generated Swift sources (module: '\(config.swiftModule ?? "")') in: \(outputSwiftDirectory)/")
109-
110-
try translator.writeExportedJavaSources(outputDirectory: outputJavaDirectory)
111-
print("[swift-java] Generated Java sources (package: '\(config.javaPackage ?? "")') in: \(outputJavaDirectory)/")
112-
113103
print("[swift-java] Imported Swift module '\(swiftModule)': " + "done.".green)
114104
}
115105

Sources/JavaKitConfigurationShared/Configuration.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public struct Configuration: Codable {
3838

3939
public var outputJavaDirectory: String?
4040

41+
public var mode: GenerationMode?
42+
4143
// ==== java 2 swift ---------------------------------------------------------
4244

4345
/// The Java class path that should be passed along to the Java2Swift tool.
@@ -255,4 +257,4 @@ extension LogLevel {
255257
}
256258
try container.encode(text)
257259
}
258-
}
260+
}

Sources/JExtractSwiftLib/GenerationMode.swift renamed to Sources/JavaKitConfigurationShared/GenerationMode.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
import ArgumentParser
16-
17-
public enum GenerationMode: String, ExpressibleByArgument {
15+
public enum GenerationMode: String, Codable {
1816
/// Foreign Value and Memory API
1917
case ffm
2018
}

Sources/SwiftJavaTool/SwiftJava.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ struct SwiftJava: AsyncParsableCommand {
7272
@Option(help: "The Java package the generated Java code should be emitted into.")
7373
var javaPackage: String? = nil
7474

75+
@Option(help: "The mode of generation to use for the output files. Used with jextract mode.")
76+
var mode: GenerationMode = .ffm
77+
7578
// TODO: clarify this vs outputSwift (history: outputSwift is jextract, and this was java2swift)
7679
@Option(name: .shortAndLong, help: "The directory in which to output the generated Swift files or the SwiftJava configuration file.")
7780
var outputDirectory: String? = nil
@@ -227,6 +230,7 @@ struct SwiftJava: AsyncParsableCommand {
227230
config.inputSwiftDirectory = self.inputSwift
228231
config.outputSwiftDirectory = self.outputSwift
229232
config.outputJavaDirectory = self.outputJava
233+
config.mode = self.mode
230234

231235
toolMode = .jextract
232236
} else if jar {
@@ -512,3 +516,5 @@ extension SwiftJava.ToolMode {
512516
}
513517
}
514518
}
519+
520+
extension GenerationMode: ExpressibleByArgument {}

0 commit comments

Comments
 (0)