@@ -36,91 +36,38 @@ struct SwiftJava: SwiftJavaBaseAsyncParsableCommand, HasCommonJVMOptions { // FI
36
36
ConfigureCommand . self,
37
37
ResolveCommand . self,
38
38
WrapJavaCommand . self,
39
+ JExtractCommand . self
39
40
] )
40
41
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
-
47
42
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 {
51
44
String ( module)
52
45
} else {
53
46
" UnknownSwiftModule "
54
47
}
55
48
}
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] = []
67
49
68
50
@Option ( help: " The directory where generated Swift files should be written. Generally used with jextract mode. " )
69
51
var outputSwift : String ? = nil
70
52
71
53
@Option ( help: " The directory where generated Java files should be written. Generally used with jextract mode. " )
72
54
var outputJava : String ? = nil
73
55
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
-
83
56
@OptionGroup var commonOptions : SwiftJava . CommonOptions
84
57
@OptionGroup var commonJVMOptions : SwiftJava . CommonJVMOptions
85
58
86
- // var effectiveCacheDirectory: String? {
87
- // if let cacheDirectory {
88
- // return cacheDirectory
89
- // } else {
90
- // return nil
91
- // }
92
- // }
93
-
94
59
// @Argument(
95
60
// help: "The input file, which is either a Java2Swift configuration file or (if '-jar' was specified) a Jar file."
96
61
// )
97
62
var input : String ? // FIXME: top level command cannot have input argument like this
98
63
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
-
110
64
mutating func runSwiftJavaCommand( config: inout Configuration ) async throws {
111
65
guard CommandLine . arguments. count >= 2 else {
112
66
// there's no "default" command, print USAGE when no arguments/parameters are passed.
113
67
print ( " error: Must specify mode subcommand (e.g. configure, resolve, jextract, ...). \n \n \( Self . helpMessage ( ) ) " )
114
68
return
115
69
}
116
70
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
-
124
71
// TODO: some options are exclusive to each other so we should detect that
125
72
if let inputSwift = commonOptions. inputSwift {
126
73
guard let inputSwift = commonOptions. inputSwift else {
@@ -139,124 +86,11 @@ struct SwiftJava: SwiftJavaBaseAsyncParsableCommand, HasCommonJVMOptions { // FI
139
86
config. inputSwiftDirectory = inputSwift
140
87
config. outputSwiftDirectory = outputSwift
141
88
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
208
89
}
209
90
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) " )
223
92
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)
260
94
}
261
95
262
96
private func names( from javaClassNameOpt: String ) -> ( javaClassName: String , swiftName: String ) {
@@ -295,13 +129,3 @@ extension JavaToSwiftError: CustomStringConvertible {
295
129
}
296
130
}
297
131
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