Skip to content

Clean up unused code and replace Path with URL to resolve warnings #407

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 8 additions & 6 deletions Plugins/GenerateCommandModels/plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
),
]
}
Expand Down
15 changes: 8 additions & 7 deletions Plugins/GenerateDocsReference/GenerateDocsReference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)'
"""
}
Expand Down
24 changes: 2 additions & 22 deletions Plugins/GenerateDocsReference/PackagePlugin+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Sources/Swiftly/List.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion Sources/Swiftly/OutputSchema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
2 changes: 1 addition & 1 deletion Sources/Swiftly/Update.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ struct Update: SwiftlyCommand {
default:
fatalError("unreachable")
}
case let .xcode:
case .xcode:
throw SwiftlyError(message: "xcode cannot be updated from swiftly")
}
}
Expand Down