Skip to content

Commit 8a7e607

Browse files
committed
more build plugin changes to prevent running phases when disabled
1 parent 2df821a commit 8a7e607

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

Plugins/JExtractSwiftPlugin/JExtractSwiftPlugin.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,26 +126,32 @@ struct JExtractSwiftBuildToolPlugin: SwiftJavaPluginProtocol, BuildToolPlugin {
126126

127127
print("[swift-java-plugin] Output swift files:\n - \(outputSwiftFiles.map({$0.absoluteString}).joined(separator: "\n - "))")
128128

129+
var jextractOutputFiles = outputSwiftFiles
130+
131+
let runJavaCallbacksPhases = configuration?.enableJavaCallbacks ?? false && configuration?.effectiveMode == .jni
132+
129133
// Extract list of all sources
130134
let javaSourcesListFileName = "jextract-generated-sources.txt"
131135
let javaSourcesFile = outputJavaDirectory.appending(path: javaSourcesListFileName)
132-
133-
arguments += [
134-
"--generated-java-sources-list-file-output", javaSourcesListFileName
135-
]
136+
if runJavaCallbacksPhases {
137+
arguments += [
138+
"--generated-java-sources-list-file-output", javaSourcesListFileName
139+
]
140+
jextractOutputFiles += [javaSourcesFile]
141+
}
136142

137143
commands += [
138144
.buildCommand(
139145
displayName: "Generate Java wrappers for Swift types",
140146
executable: toolURL,
141147
arguments: arguments,
142148
inputFiles: [ configFile ] + swiftFiles,
143-
outputFiles: outputSwiftFiles + [javaSourcesFile]
149+
outputFiles: jextractOutputFiles
144150
)
145151
]
146152

147153
// If we do not need Java callbacks, we can skip the remaining steps.
148-
guard configuration?.enableJavaCallbacks ?? false else {
154+
guard runJavaCallbacksPhases else {
149155
return commands
150156
}
151157

Sources/SwiftJavaTool/Commands/JExtractCommand.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ extension SwiftJava {
8282
@Option(help: "The mode to use for extracting asynchronous Swift functions. By default async methods are extracted as Java functions returning CompletableFuture.")
8383
var asyncFuncMode: JExtractAsyncFuncMode?
8484

85-
@Flag(help: "By enabling this mode, JExtract will generate Java code that allows you to implement Swift protocols using Java classes. This feature requires disabling the sandbox mode in SwiftPM.")
85+
@Flag(help: "By enabling this mode, JExtract will generate Java code that allows you to implement Swift protocols using Java classes. This feature requires disabling the sandbox mode in SwiftPM. This only works in the 'jni' mode.")
8686
var enableJavaCallbacks: Bool = false
8787

8888
@Option(help: "If specified, JExtract will output to this file a list of paths to all generated Java source files")
@@ -136,11 +136,15 @@ extension SwiftJava.JExtractCommand {
136136
case .annotate:
137137
() // OK
138138
case .wrapGuava:
139-
throw IllegalModeCombinationError("JNI mode does not support '\(JExtractUnsignedIntegerMode.wrapGuava)' Unsigned integer mode! \(Self.helpMessage)")
139+
throw IllegalModeCombinationError("JNI mode does not support '\(JExtractUnsignedIntegerMode.wrapGuava)' Unsigned integer mode! \(Self.helpMessage())")
140140
}
141141
} else if config.effectiveMode == .ffm {
142142
guard config.effectiveMemoryManagementMode == .explicit else {
143-
throw IllegalModeCombinationError("FFM mode does not support '\(self.memoryManagementMode)' memory management mode! \(Self.helpMessage)")
143+
throw IllegalModeCombinationError("FFM mode does not support '\(self.memoryManagementMode ?? .default)' memory management mode! \(Self.helpMessage())")
144+
}
145+
146+
if let enableJavaCallbacks = config.enableJavaCallbacks, enableJavaCallbacks {
147+
throw IllegalModeCombinationError("FFM mode does not support enabling Java callbacks! \(Self.helpMessage())")
144148
}
145149
}
146150
}

0 commit comments

Comments
 (0)