From 7588024990392340b86ec38877d0e9e39206a6a1 Mon Sep 17 00:00:00 2001 From: belkhadir Date: Mon, 4 Aug 2025 17:01:14 +0100 Subject: [PATCH 1/5] Remove unused code --- .../PackagePlugin+Helpers.swift | 20 ------------------- Sources/Swiftly/OutputSchema.swift | 1 - 2 files changed, 21 deletions(-) diff --git a/Plugins/GenerateDocsReference/PackagePlugin+Helpers.swift b/Plugins/GenerateDocsReference/PackagePlugin+Helpers.swift index 53f08344..2fc6b068 100644 --- a/Plugins/GenerateDocsReference/PackagePlugin+Helpers.swift +++ b/Plugins/GenerateDocsReference/PackagePlugin+Helpers.swift @@ -26,17 +26,6 @@ extension ArgumentExtractor { } extension Path { - func createOutputDirectory() throws { - do { - try FileManager.default.createDirectory( - atPath: self.string, - withIntermediateDirectories: true - ) - } catch { - throw GenerateDocsReferencePluginError.createOutputDirectoryFailed(error) - } - } - func exec(arguments: [String]) throws { do { let process = Process() @@ -58,15 +47,6 @@ extension Path { } } -extension PackageManager.BuildResult.BuiltArtifact { - func matchingProduct(context: PluginContext) -> Product? { - context - .package - .products - .first { $0.name == self.path.lastComponent } - } -} - extension Product { func hasDependency(named name: String) -> Bool { self.recursiveTargetDependencies diff --git a/Sources/Swiftly/OutputSchema.swift b/Sources/Swiftly/OutputSchema.swift index fc4ee8e9..5a9b6f77 100644 --- a/Sources/Swiftly/OutputSchema.swift +++ b/Sources/Swiftly/OutputSchema.swift @@ -249,7 +249,6 @@ struct InstallToolchainInfo: OutputData { let versionContainer = try container.nestedContainer( keyedBy: ToolchainVersionCodingKeys.self, forKey: .version ) - let name = try versionContainer.decode(String.self, forKey: .name) switch try versionContainer.decode(String.self, forKey: .type) { case "stable": From fc78d0c2630a59c34db694a978e93db2df9c7dfd Mon Sep 17 00:00:00 2001 From: belkhadir Date: Mon, 4 Aug 2025 17:08:56 +0100 Subject: [PATCH 2/5] Remove unused var binding and simplify case pattern --- Sources/Swiftly/List.swift | 2 +- Sources/Swiftly/Update.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Swiftly/List.swift b/Sources/Swiftly/List.swift index 986cd06a..7efcb9c8 100644 --- a/Sources/Swiftly/List.swift +++ b/Sources/Swiftly/List.swift @@ -55,7 +55,7 @@ struct List: SwiftlyCommand { let toolchains = config.listInstalledToolchains(selector: selector).sorted { $0 > $1 } let (inUse, _) = try await selectToolchain(ctx, config: &config) - var installedToolchainInfos = toolchains.compactMap { toolchain -> InstallToolchainInfo? in + let installedToolchainInfos = toolchains.compactMap { toolchain -> InstallToolchainInfo? in InstallToolchainInfo( version: toolchain, inUse: inUse == toolchain, diff --git a/Sources/Swiftly/Update.swift b/Sources/Swiftly/Update.swift index 8ae31bdb..fead9c14 100644 --- a/Sources/Swiftly/Update.swift +++ b/Sources/Swiftly/Update.swift @@ -192,7 +192,7 @@ struct Update: SwiftlyCommand { default: fatalError("unreachable") } - case let .xcode: + case .xcode: throw SwiftlyError(message: "xcode cannot be updated from swiftly") } } From 9fd760fdf442c5aa2dc597b8011bc5a0828564e2 Mon Sep 17 00:00:00 2001 From: belkhadir Date: Mon, 4 Aug 2025 17:57:12 +0100 Subject: [PATCH 3/5] Replace Path with URL --- Plugins/GenerateCommandModels/plugin.swift | 14 ++++++++------ .../GenerateDocsReference.swift | 15 ++++++++------- .../GenerateDocsReferenceError.swift | 8 ++++---- .../PackagePlugin+Helpers.swift | 4 ++-- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Plugins/GenerateCommandModels/plugin.swift b/Plugins/GenerateCommandModels/plugin.swift index b030d3de..75292dae 100644 --- a/Plugins/GenerateCommandModels/plugin.swift +++ b/Plugins/GenerateCommandModels/plugin.swift @@ -5,19 +5,21 @@ struct GenerateCommandModelsPlugin: BuildToolPlugin { func createBuildCommands(context: PluginContext, target: Target) throws -> [Command] { guard let target = target as? SourceModuleTarget else { return [] } - let jsonSources = target.sourceFiles.map(\.path).filter { $0.extension == "json" } + let jsonSources = target.sourceFiles.map(\.url).filter { $0.pathExtension == "json" } - guard jsonSources.count > 0 else { return [] } + guard !jsonSources.isEmpty else { return [] } - let outputPath = context.pluginWorkDirectory.appending("Commands.swift") + let outputURL = context.pluginWorkDirectoryURL.appendingPathComponent("Commands.swift") return [ .buildCommand( displayName: "Generating Command Models from dumped JSON help", - executable: try context.tool(named: "generate-command-models").path, - arguments: ["--output-file", outputPath] + jsonSources, + executable: try context.tool(named: "generate-command-models").url, + arguments: [ + "--output-file", outputURL.path + ] + jsonSources.map { $0.path }, inputFiles: jsonSources, - outputFiles: [outputPath] + outputFiles: [outputURL] ), ] } diff --git a/Plugins/GenerateDocsReference/GenerateDocsReference.swift b/Plugins/GenerateDocsReference/GenerateDocsReference.swift index d3253388..6425be05 100644 --- a/Plugins/GenerateDocsReference/GenerateDocsReference.swift +++ b/Plugins/GenerateDocsReference/GenerateDocsReference.swift @@ -7,8 +7,7 @@ struct GenerateDocsReferencePlugin: CommandPlugin { arguments: [String] ) async throws { // Locate generation tool. - let generationToolFile = try context.tool(named: "generate-docs-reference").path - + let generationToolFile = try context.tool(named: "generate-docs-reference").url // Create an extractor to extract plugin-only arguments from the `arguments` // array. var extractor = ArgumentExtractor(arguments) @@ -52,18 +51,20 @@ struct GenerateDocsReferencePlugin: CommandPlugin { guard builtArtifact.kind == .executable else { continue } // Get the artifacts name. - let executableName = builtArtifact.path.lastComponent + let executableName = builtArtifact.url.lastPathComponent print("Generating docs reference for \(executableName)...") - let outputFile = context.package.directory - .appending("Documentation/SwiftlyDocs.docc/swiftly-cli-reference.md") + let outputFile = context.package.directoryURL + .appendingPathComponent("Documentation") + .appendingPathComponent("SwiftlyDocs.docc") + .appendingPathComponent("swiftly-cli-reference.md") // Create generation tool arguments. var generationToolArguments = [ - builtArtifact.path.string, + builtArtifact.url.path(), "--output-file", - outputFile.string, + outputFile.path(), ] generationToolArguments.append( contentsOf: extractor.remainingArguments) diff --git a/Plugins/GenerateDocsReference/GenerateDocsReferenceError.swift b/Plugins/GenerateDocsReference/GenerateDocsReferenceError.swift index 5e4b44fa..6fae99f6 100644 --- a/Plugins/GenerateDocsReference/GenerateDocsReferenceError.swift +++ b/Plugins/GenerateDocsReference/GenerateDocsReferenceError.swift @@ -6,8 +6,8 @@ enum GenerateDocsReferencePluginError: Error { case unknownBuildConfiguration(String) case buildFailed(String) case createOutputDirectoryFailed(Error) - case subprocessFailedNonZeroExit(Path, Int32) - case subprocessFailedError(Path, Error) + case subprocessFailedNonZeroExit(URL, Int32) + case subprocessFailedError(URL, Error) } extension GenerateDocsReferencePluginError: CustomStringConvertible { @@ -23,12 +23,12 @@ extension GenerateDocsReferencePluginError: CustomStringConvertible { """ case let .subprocessFailedNonZeroExit(tool, exitCode): return """ - '\(tool.lastComponent)' invocation failed with a nonzero exit code: \ + '\(tool.lastPathComponent)' invocation failed with a nonzero exit code: \ '\(exitCode)'. """ case let .subprocessFailedError(tool, error): return """ - '\(tool.lastComponent)' invocation failed: \ + '\(tool.lastPathComponent)' invocation failed: \ '\(error.localizedDescription)' """ } diff --git a/Plugins/GenerateDocsReference/PackagePlugin+Helpers.swift b/Plugins/GenerateDocsReference/PackagePlugin+Helpers.swift index 2fc6b068..a5257baf 100644 --- a/Plugins/GenerateDocsReference/PackagePlugin+Helpers.swift +++ b/Plugins/GenerateDocsReference/PackagePlugin+Helpers.swift @@ -25,11 +25,11 @@ extension ArgumentExtractor { } } -extension Path { +extension URL { func exec(arguments: [String]) throws { do { let process = Process() - process.executableURL = URL(fileURLWithPath: self.string) + process.executableURL = self process.arguments = arguments try process.run() process.waitUntilExit() From 3672645721b9695c643caadbc6d0c2563ced444a Mon Sep 17 00:00:00 2001 From: belkhadir Date: Sat, 27 Sep 2025 11:12:21 +0100 Subject: [PATCH 4/5] Decode `name` field explicitly for symmetry and fix file path decoding for subprocess --- Plugins/GenerateDocsReference/GenerateDocsReference.swift | 4 ++-- Sources/Swiftly/OutputSchema.swift | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Plugins/GenerateDocsReference/GenerateDocsReference.swift b/Plugins/GenerateDocsReference/GenerateDocsReference.swift index 6425be05..9b708c6d 100644 --- a/Plugins/GenerateDocsReference/GenerateDocsReference.swift +++ b/Plugins/GenerateDocsReference/GenerateDocsReference.swift @@ -62,9 +62,9 @@ struct GenerateDocsReferencePlugin: CommandPlugin { // Create generation tool arguments. var generationToolArguments = [ - builtArtifact.url.path(), + builtArtifact.url.path(percentEncoded: false), "--output-file", - outputFile.path(), + outputFile.path(percentEncoded: false), ] generationToolArguments.append( contentsOf: extractor.remainingArguments) diff --git a/Sources/Swiftly/OutputSchema.swift b/Sources/Swiftly/OutputSchema.swift index 5a9b6f77..136ba44b 100644 --- a/Sources/Swiftly/OutputSchema.swift +++ b/Sources/Swiftly/OutputSchema.swift @@ -249,6 +249,7 @@ struct InstallToolchainInfo: OutputData { let versionContainer = try container.nestedContainer( keyedBy: ToolchainVersionCodingKeys.self, forKey: .version ) + _ = try versionContainer.decode(String.self, forKey: .name) switch try versionContainer.decode(String.self, forKey: .type) { case "stable": From 64c1505872dd9b64f2bb2263e71a41f7a05131d9 Mon Sep 17 00:00:00 2001 From: belkhadir Date: Fri, 3 Oct 2025 14:12:27 +0100 Subject: [PATCH 5/5] Run command line `swift run swiftformat .` --- Plugins/GenerateCommandModels/plugin.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/GenerateCommandModels/plugin.swift b/Plugins/GenerateCommandModels/plugin.swift index 75292dae..6e990096 100644 --- a/Plugins/GenerateCommandModels/plugin.swift +++ b/Plugins/GenerateCommandModels/plugin.swift @@ -16,8 +16,8 @@ struct GenerateCommandModelsPlugin: BuildToolPlugin { displayName: "Generating Command Models from dumped JSON help", executable: try context.tool(named: "generate-command-models").url, arguments: [ - "--output-file", outputURL.path - ] + jsonSources.map { $0.path }, + "--output-file", outputURL.path, + ] + jsonSources.map(\.path), inputFiles: jsonSources, outputFiles: [outputURL] ),