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 53f08344..a5257baf 100644 --- a/Plugins/GenerateDocsReference/PackagePlugin+Helpers.swift +++ b/Plugins/GenerateDocsReference/PackagePlugin+Helpers.swift @@ -25,22 +25,11 @@ extension ArgumentExtractor { } } -extension Path { - func createOutputDirectory() throws { - do { - try FileManager.default.createDirectory( - atPath: self.string, - withIntermediateDirectories: true - ) - } catch { - throw GenerateDocsReferencePluginError.createOutputDirectoryFailed(error) - } - } - +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() @@ -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/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/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": 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") } }