From b491fa690d198cd485445d3e6cdc08307219f444 Mon Sep 17 00:00:00 2001 From: Mikhail Tishin Date: Tue, 12 Mar 2024 17:21:44 +0300 Subject: [PATCH 1/2] Fix build command execution on Windows using Swift 5.10 --- Plugins/CodeGeneratorPlugin/plugin.swift | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Plugins/CodeGeneratorPlugin/plugin.swift b/Plugins/CodeGeneratorPlugin/plugin.swift index b3b599a59..87bf4c420 100644 --- a/Plugins/CodeGeneratorPlugin/plugin.swift +++ b/Plugins/CodeGeneratorPlugin/plugin.swift @@ -11,6 +11,7 @@ import PackagePlugin /// Generates the API for the SwiftGodot from the Godot exported Json API @main struct SwiftCodeGeneratorPlugin: BuildToolPlugin { func createBuildCommands(context: PluginContext, target: Target) throws -> [Command] { + var commands: [Command] = [] // Configure the commands to write to a "GeneratedSources" directory. let genSourcesDir = context.pluginWorkDirectory.appending("GeneratedSources") @@ -26,23 +27,24 @@ import PackagePlugin outputFiles.append(genSourcesDir.appending(subpath: "Generated.swift")) arguments.append(context.package.directory.appending(subpath: "doc")) arguments.append("--singlefile") - let cmd: Command = Command.prebuildCommand( + commands.append(Command.prebuildCommand( displayName: "Generating Swift API from \(api) to \(genSourcesDir)", executable: generator, arguments: arguments, - outputFilesDirectory: genSourcesDir) + outputFilesDirectory: genSourcesDir)) #else outputFiles.append (contentsOf: knownBuiltin.map { genSourcesDir.appending(["generated-builtin", $0])}) outputFiles.append (contentsOf: known.map { genSourcesDir.appending(["generated", $0])}) - let cmd: Command = Command.buildCommand( + #endif + + commands.append(Command.buildCommand( displayName: "Generating Swift API from \(api) to \(genSourcesDir)", executable: generator, arguments: arguments, inputFiles: [api], - outputFiles: outputFiles) - #endif + outputFiles: outputFiles)) - return [cmd] + return commands } } From 4388c9a4003d6210dda4d85916db11cc3c4986f6 Mon Sep 17 00:00:00 2001 From: Mikhail Tishin Date: Tue, 12 Mar 2024 19:33:02 +0300 Subject: [PATCH 2/2] Disable buildCommand execution on Windows with Swift 5.9 --- Plugins/CodeGeneratorPlugin/plugin.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Plugins/CodeGeneratorPlugin/plugin.swift b/Plugins/CodeGeneratorPlugin/plugin.swift index 87bf4c420..7a8037f64 100644 --- a/Plugins/CodeGeneratorPlugin/plugin.swift +++ b/Plugins/CodeGeneratorPlugin/plugin.swift @@ -37,12 +37,15 @@ import PackagePlugin outputFiles.append (contentsOf: known.map { genSourcesDir.appending(["generated", $0])}) #endif + // For Windows with Swift 5.10 both prebuildCommand and buildCommand are needed + #if !os(Windows) || swift(>=5.10) commands.append(Command.buildCommand( displayName: "Generating Swift API from \(api) to \(genSourcesDir)", executable: generator, arguments: arguments, inputFiles: [api], outputFiles: outputFiles)) + #endif return commands }