@@ -36,91 +36,38 @@ struct SwiftJava: SwiftJavaBaseAsyncParsableCommand, HasCommonJVMOptions { // FI
3636 ConfigureCommand . self,
3737 ResolveCommand . self,
3838 WrapJavaCommand . self,
39+ JExtractCommand . self
3940 ] )
4041
41- // FIXME: this must be removed when we move things out from the SwiftJava main file!
42- @Option (
43- name: . long,
44- help: " The name of the Swift module into which the resulting Swift types will be generated. " )
45- var swiftModuleDeprecated : String ?
46-
4742 var effectiveSwiftModule : String {
48- if let module = swiftModuleDeprecated {
49- module
50- } else if let module = self . outputSwift? . split ( separator: " / " ) . last {
43+ if let module = self . outputSwift? . split ( separator: " / " ) . last {
5144 String ( module)
5245 } else {
5346 " UnknownSwiftModule "
5447 }
5548 }
56- //
57- // @Option(
58- // help:
59- // "A Java2Swift configuration file for a given Swift module name on which this module depends, e.g., JavaKitJar=Sources/JavaKitJar/Java2Swift.config. There should be one of these options for each Swift module that this module depends on (transitively) that contains wrapped Java sources."
60- // )
61- // var dependsOn: [String] = []
62- //
63- // @Option(
64- // help: "The names of Java classes whose declared native methods will be implemented in Swift."
65- // )
66- // var swiftNativeImplementation: [String] = []
6749
6850 @Option ( help: " The directory where generated Swift files should be written. Generally used with jextract mode. " )
6951 var outputSwift : String ? = nil
7052
7153 @Option ( help: " The directory where generated Java files should be written. Generally used with jextract mode. " )
7254 var outputJava : String ? = nil
7355
74- // @Option(help: "The Java package the generated Java code should be emitted into.")
75- // var javaPackage: String? = nil
76-
77- @Option ( help: " The mode of generation to use for the output files. Used with jextract mode. " )
78- var mode : GenerationMode = . ffm
79-
80- // @Option(name: .shortAndLong, help: "Directory where to write cached values (e.g. swift-java.classpath files)")
81- // var cacheDirectory: String? = nil
82-
8356 @OptionGroup var commonOptions : SwiftJava . CommonOptions
8457 @OptionGroup var commonJVMOptions : SwiftJava . CommonJVMOptions
8558
86- // var effectiveCacheDirectory: String? {
87- // if let cacheDirectory {
88- // return cacheDirectory
89- // } else {
90- // return nil
91- // }
92- // }
93-
9459// @Argument(
9560// help: "The input file, which is either a Java2Swift configuration file or (if '-jar' was specified) a Jar file."
9661// )
9762 var input : String ? // FIXME: top level command cannot have input argument like this
9863
99- // FIXME: this is subcommands
100- /// Describes what kind of generation action is being performed by swift-java.
101- enum ToolMode {
102- // /// Generate Swift wrappers for Java classes based on the given
103- // /// configuration.
104- // case classWrappers
105-
106- /// Extract Java bindings from provided Swift sources.
107- case jextract // TODO: carry jextract specific config here?
108- }
109-
11064 mutating func runSwiftJavaCommand( config: inout Configuration ) async throws {
11165 guard CommandLine . arguments. count >= 2 else {
11266 // there's no "default" command, print USAGE when no arguments/parameters are passed.
11367 print ( " error: Must specify mode subcommand (e.g. configure, resolve, jextract, ...). \n \n \( Self . helpMessage ( ) ) " )
11468 return
11569 }
11670
117- // if let javaPackage {
118- // config.javaPackage = javaPackage
119- // }
120-
121- // Determine the mode in which we'll execute.
122- let toolMode : ToolMode = . jextract
123-
12471 // TODO: some options are exclusive to each other so we should detect that
12572 if let inputSwift = commonOptions. inputSwift {
12673 guard let inputSwift = commonOptions. inputSwift else {
@@ -139,124 +86,11 @@ struct SwiftJava: SwiftJavaBaseAsyncParsableCommand, HasCommonJVMOptions { // FI
13986 config. inputSwiftDirectory = inputSwift
14087 config. outputSwiftDirectory = outputSwift
14188 config. outputJavaDirectory = outputJava
142-
143- // toolMode = .jextract
144- // } else if fetch {
145- // guard let input else {
146- // fatalError("Mode 'fetch' requires <input> path\n\(Self.helpMessage())")
147- // }
148- // config = try JavaTranslator.readConfiguration(from: URL(fileURLWithPath: input))
149- // guard let dependencies = config.dependencies else {
150- // print("[swift-java] Running in 'fetch dependencies' mode but dependencies list was empty!")
151- // print("[swift-java] Nothing to do: done.")
152- // return
153- // }
154- // toolMode = .fetchDependencies
155- }
156- // else {
157- // guard let input else {
158- // fatalError("Mode -jar requires <input> path\n\(Self.helpMessage())")
159- // }
160- // config = try JavaTranslator.readConfiguration(from: URL(fileURLWithPath: input))
161- // toolMode = .classWrappers
162- // }
163-
164- print ( " [debug][swift-java] Running swift-java in mode: " + " \( toolMode. prettyName) " . bold)
165-
166- let swiftModule : String =
167- self . effectiveSwiftModule
168- // ??
169- // self.effectiveSwiftModule.split(separator: "/").dropLast().last.map(String.init) ?? "__UnknownModule"
170-
171- // // Load all of the dependent configurations and associate them with Swift
172- // // modules.
173- // let dependentConfigs = try dependsOn.map { dependentConfig in
174- // guard let equalLoc = dependentConfig.firstIndex(of: "=") else {
175- // throw JavaToSwiftError.badConfigOption(dependentConfig)
176- // }
177- //
178- // let afterEqual = dependentConfig.index(after: equalLoc)
179- // let swiftModuleName = String(dependentConfig[..<equalLoc])
180- // let configFileName = String(dependentConfig[afterEqual...])
181- //
182- // let config = try readConfiguration(from: URL(fileURLWithPath: configFileName))
183- //
184- // return (swiftModuleName, config)
185- // }
186-
187- // Form a class path from all of our input sources:
188- // * Command-line option --classpath
189- let classpathOptionEntries : [ String ] = self . classpathEntries
190- let classpathFromEnv = self . classpathEnvEntries
191- let classpathFromConfig : [ String ] = config. classpathEntries
192- print ( " [debug][swift-java] Base classpath from config: \( classpathFromConfig) " )
193-
194- var classpathEntries : [ String ] = classpathFromConfig
195-
196- // let swiftJavaCachedModuleClasspath = findSwiftJavaClasspaths(
197- // in: self.effectiveCacheDirectory ?? FileManager.default.currentDirectoryPath)
198- // print("[debug][swift-java] Classpath from *.swift-java.classpath files: \(swiftJavaCachedModuleClasspath)")
199- // classpathEntries += swiftJavaCachedModuleClasspath
200-
201- if !classpathOptionEntries. isEmpty {
202- print ( " [debug][swift-java] Classpath from options: \( classpathOptionEntries) " )
203- classpathEntries += classpathOptionEntries
204- } else {
205- // * Base classpath from CLASSPATH env variable
206- print ( " [debug][swift-java] Classpath from environment: \( classpathFromEnv) " )
207- classpathEntries += classpathFromEnv
20889 }
20990
210- // switch toolMode {
211- // case .fetchDependencies:
212- // // if we have already fetched dependencies for the dependency loader,
213- // // let's use them so we can in-process resolve rather than forking a new
214- // // gradle process.
215- // print("[debug][swift-java] Add classpath from .classpath files")
216- //// if let dependencyResolverClasspath = fetchDependenciesCachedClasspath() {
217- //// print("[debug][swift-java] Found cached dependency resolver classpath: \(dependencyResolverClasspath)")
218- //// classpathEntries += dependencyResolverClasspath
219- //// }
220- // case .classWrappers, .jextract:
221- // break;
222- // }
91+ print ( " [debug][swift-java] Running swift-java in mode: " + " jextract (legacy, to be moved into subcommand) " )
22392
224- // Bring up the Java VM when necessary
225- // // TODO: print only in verbose mode
226- // let classpath = classpathEntries.joined(separator: ":")
227-
228- // let jvm: JavaVirtualMachine! = nil
229- // switch toolMode {
230- // case .classWrappers:
231- // print("[debug][swift-java] Initialize JVM with classpath: \(classpath)")
232- // jvm = try JavaVirtualMachine.shared(classpath: classpathEntries)
233- // default:
234- // jvm = nil
235- // }
236-
237- // // * Classpaths from all dependent configuration files
238- // for (_, config) in dependentConfigs {
239- // // TODO: may need to resolve the dependent configs rather than just get their configs
240- // // TODO: We should cache the resolved classpaths as well so we don't do it many times
241- // config.classpath.map { entry in
242- // print("[swift-java] Add dependent config classpath element: \(entry)")
243- // classpathEntries.append(entry)
244- // }
245- // }
246-
247- // Run the task.
248- // switch toolMode {
249- //// case .classWrappers:
250- //// try generateWrappers(
251- //// config: config,
252- //// classpath: classpath,
253- //// dependentConfigs: dependentConfigs,
254- //// environment: jvm.environment()
255- //// )
256- //
257- // case .jextract:
258- try jextractSwift ( config: config)
259- // }
93+ try jextractSwift ( config: config)
26094 }
26195
26296 private func names( from javaClassNameOpt: String ) -> ( javaClassName: String , swiftName: String ) {
@@ -295,13 +129,3 @@ extension JavaToSwiftError: CustomStringConvertible {
295129 }
296130}
297131
298- extension SwiftJava . ToolMode {
299- var prettyName : String {
300- switch self {
301- // case .classWrappers: "Wrap Java classes"
302- case . jextract: " JExtract Swift for Java "
303- }
304- }
305- }
306-
307- extension GenerationMode : ExpressibleByArgument { }
0 commit comments