Skip to content

[jextract/JExtractSwiftCommandPlugin] Pass extra arguments to the tool #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,18 @@ final class JExtractSwiftCommandPlugin: SwiftJavaPluginProtocol, BuildToolPlugin
// Plugin can't have dependencies, so we have some naive argument parsing instead:
self.verbose = arguments.contains("-v") || arguments.contains("--verbose")

let selectedTargets: [String] =
if let last = arguments.lastIndex(where: { $0.starts(with: "-")}),
last < arguments.endIndex {
Array(arguments[..<last])
} else {
[]
}
Comment on lines -43 to -49
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was unused.


for target in context.package.targets {
guard getSwiftJavaConfigPath(target: target) != nil else {
log("[swift-java-command] Skipping jextract step: Missing swift-java.config for target '\(target.name)'")
continue
}

do {
let extraArguments = arguments.filter { arg in
arg != "-v" && arg != "--verbose"
}
print("[swift-java-command] Extracting Java wrappers from target: '\(target.name)'...")
try performCommand(context: context, target: target, extraArguments: arguments)
try performCommand(context: context, target: target, extraArguments: extraArguments)
} catch {
print("[swift-java-command] error: Failed to extract from target '\(target.name)': \(error)")
}
Expand Down Expand Up @@ -94,7 +89,7 @@ final class JExtractSwiftCommandPlugin: SwiftJavaPluginProtocol, BuildToolPlugin
}

/// Perform the command on a specific target.
func performCommand(context: PluginContext, target: Target, extraArguments _: [String]) throws {
func performCommand(context: PluginContext, target: Target, extraArguments: [String]) throws {
guard let sourceModule = target.sourceModule else { return }

if self.buildInputs {
Expand All @@ -110,7 +105,7 @@ final class JExtractSwiftCommandPlugin: SwiftJavaPluginProtocol, BuildToolPlugin

let arguments = try prepareJExtractArguments(context: context, target: target)

try runExtract(context: context, target: target, arguments: arguments)
try runExtract(context: context, target: target, arguments: arguments + extraArguments)

if self.buildOutputs {
// Building the *products* since we need to build the dylib that contains our newly generated sources,
Expand Down