Skip to content
Merged
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(\.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(percentEncoded: false),
"--output-file",
outputFile.string,
outputFile.path(percentEncoded: false),
]
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
2 changes: 1 addition & 1 deletion Sources/Swiftly/OutputSchema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ struct InstallToolchainInfo: OutputData {
let versionContainer = try container.nestedContainer(
keyedBy: ToolchainVersionCodingKeys.self, forKey: .version
)
let name = try versionContainer.decode(String.self, forKey: .name)
Copy link
Member

Choose a reason for hiding this comment

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

issue (blocking): I think that the name could be in the decoding stream, even though it is redundant for decoding because it is a synthesized property of ToolchainVersion. I expect that the name will need to be decoded here, even if the return value is thrown away. Some kind of handling of the name key here will also help with symmetry between this init and the encode method above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your feedback.

To clarify, are you expecting the decode to be strict in this context?
I am considering adding:

_ = try versionContainer.decode(String.self, forKey: .name)

This approach ensures that decoding fails if the name is missing, maintaining symmetry with the encode(to:) function, even if the value is not directly used.
Please let me know if this aligns with your intended solution.

_ = 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