22//
33// This source file is part of the Swift.org open source project
44//
5- // Copyright (c) 2024 Apple Inc. and the Swift.org project authors
5+ // Copyright (c) 2024-2025 Apple Inc. and the Swift.org project authors
66// Licensed under Apache License v2.0
77//
88// See LICENSE.txt for license information
@@ -52,6 +52,9 @@ extension SwiftJava {
5252 @Option ( help: " The names of Java classes whose declared native methods will be implemented in Swift. " )
5353 var swiftNativeImplementation : [ String ] = [ ]
5454
55+ @Option ( help: " Cache directory for intermediate results and other outputs between runs " )
56+ var cacheDirectory : String ?
57+
5558 @Argument ( help: " Path to .jar file whose Java classes should be wrapped using Swift bindings " )
5659 var input : String
5760 }
@@ -60,34 +63,46 @@ extension SwiftJava {
6063extension SwiftJava . WrapJavaCommand {
6164
6265 mutating func runSwiftJavaCommand( config: inout Configuration ) async throws {
66+ // Perform any config overrides by command options:
6367 if let javaPackage {
6468 config. javaPackage = javaPackage
6569 }
6670
67- // Load all of the dependent configurations and associate them with Swift
68- // modules.
69- let dependentConfigs = try loadDependentConfigs ( )
7071
71- // Configure our own classpath based on config
72- var classpathEntries =
73- self . configureCommandJVMClasspath ( effectiveSwiftModuleURL: self . effectiveSwiftModuleURL, config: config)
72+
73+ // Get base classpath configuration for this target and configuration
74+ var classpathSearchDirs = [ self . effectiveSwiftModuleURL]
75+ if let cacheDir = self . cacheDirectory {
76+ print ( " [trace][swift-java] Cache directory: \( cacheDir) " )
77+ classpathSearchDirs += [ URL ( fileURLWithPath: cacheDir) ]
78+ } else {
79+ print ( " [trace][swift-java] Cache directory: none " )
80+ }
81+ print ( " [trace][swift-java] INPUT: \( input) " )
82+
83+ var classpathEntries = self . configureCommandJVMClasspath (
84+ searchDirs: classpathSearchDirs, config: config)
85+
86+ // Load all of the dependent configurations and associate them with Swift modules.
87+ let dependentConfigs = try self . loadDependentConfigs ( )
88+ print ( " [debug][swift-java] Dependent configs: \( dependentConfigs. count) " )
7489
7590 // Include classpath entries which libs we depend on require...
7691 for (fromModule, config) in dependentConfigs {
92+ print ( " [trace][swift-java] Add dependent config ( \( fromModule) ) classpath elements: \( config. classpathEntries. count) " )
7793 // TODO: may need to resolve the dependent configs rather than just get their configs
7894 // TODO: We should cache the resolved classpaths as well so we don't do it many times
79- config . classpath . map { entry in
95+ for entry in config . classpathEntries {
8096 print ( " [trace][swift-java] Add dependent config ( \( fromModule) ) classpath element: \( entry) " )
8197 classpathEntries. append ( entry)
8298 }
8399 }
84100
85- let completeClasspath = classpathEntries. joined ( separator: " : " )
86101 let jvm = try self . makeJVM ( classpathEntries: classpathEntries)
87102
88103 try self . generateWrappers (
89104 config: config,
90- classpath : completeClasspath ,
105+ // classpathEntries: classpathEntries ,
91106 dependentConfigs: dependentConfigs,
92107 environment: jvm. environment ( )
93108 )
@@ -118,7 +133,7 @@ extension SwiftJava.WrapJavaCommand {
118133extension SwiftJava . WrapJavaCommand {
119134 mutating func generateWrappers(
120135 config: Configuration ,
121- classpath : String ,
136+ // classpathEntries: [ String] ,
122137 dependentConfigs: [ ( String , Configuration ) ] ,
123138 environment: JNIEnvironment
124139 ) throws {
0 commit comments