Skip to content

Fix warnings in generated build-tool-plugin template code #8801

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

Merged
Merged
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
19 changes: 10 additions & 9 deletions Sources/Workspace/InitPackage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ public final class InitPackage {

var content = """
import PackagePlugin
import struct Foundation.URL

@main

Expand All @@ -484,8 +485,8 @@ public final class InitPackage {
let generatorTool = try context.tool(named: "my-code-generator")

// Construct a build command for each source file with a particular suffix.
return sourceFiles.map(\\.path).compactMap {
createBuildCommand(for: $0, in: context.pluginWorkDirectory, with: generatorTool.path)
return sourceFiles.map(\\.url).compactMap {
createBuildCommand(for: $0, in: context.pluginWorkDirectoryURL, with: generatorTool.url)
}
}
}
Expand All @@ -500,8 +501,8 @@ public final class InitPackage {
let generatorTool = try context.tool(named: "my-code-generator")

// Construct a build command for each source file with a particular suffix.
return target.inputFiles.map(\\.path).compactMap {
createBuildCommand(for: $0, in: context.pluginWorkDirectory, with: generatorTool.path)
return target.inputFiles.map(\\.url).compactMap {
createBuildCommand(for: $0, in: context.pluginWorkDirectoryURL, with: generatorTool.url)
}
}
}
Expand All @@ -510,14 +511,14 @@ public final class InitPackage {

extension \(typeName) {
/// Shared function that returns a configured build command if the input files is one that should be processed.
func createBuildCommand(for inputPath: Path, in outputDirectoryPath: Path, with generatorToolPath: Path) -> Command? {
func createBuildCommand(for inputPath: URL, in outputDirectoryPath: URL, with generatorToolPath: URL) -> Command? {
// Skip any file that doesn't have the extension we're looking for (replace this with the actual one).
guard inputPath.extension == "my-input-suffix" else { return .none }
guard inputPath.pathExtension == "my-input-suffix" else { return .none }

// Return a command that will run during the build to generate the output file.
let inputName = inputPath.lastComponent
let outputName = inputPath.stem + ".swift"
let outputPath = outputDirectoryPath.appending(outputName)
let inputName = inputPath.lastPathComponent
let outputName = inputPath.deletingPathExtension().lastPathComponent + ".swift"
let outputPath = outputDirectoryPath.appendingPathComponent(outputName)
return .buildCommand(
displayName: "Generating \\(outputName) from \\(inputName)",
executable: generatorToolPath,
Expand Down