Skip to content

Commit 3883eed

Browse files
authored
Fix warnings in generated build-tool-plugin template code (#8801)
Migrate the template code generated by `swift package init --type build-tool-plugin` to use URL instead of Path, fixing compile warnings. Fixes #8797
1 parent 3c08cff commit 3883eed

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Sources/Workspace/InitPackage.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ public final class InitPackage {
468468

469469
var content = """
470470
import PackagePlugin
471+
import struct Foundation.URL
471472
472473
@main
473474
@@ -484,8 +485,8 @@ public final class InitPackage {
484485
let generatorTool = try context.tool(named: "my-code-generator")
485486
486487
// Construct a build command for each source file with a particular suffix.
487-
return sourceFiles.map(\\.path).compactMap {
488-
createBuildCommand(for: $0, in: context.pluginWorkDirectory, with: generatorTool.path)
488+
return sourceFiles.map(\\.url).compactMap {
489+
createBuildCommand(for: $0, in: context.pluginWorkDirectoryURL, with: generatorTool.url)
489490
}
490491
}
491492
}
@@ -500,8 +501,8 @@ public final class InitPackage {
500501
let generatorTool = try context.tool(named: "my-code-generator")
501502
502503
// Construct a build command for each source file with a particular suffix.
503-
return target.inputFiles.map(\\.path).compactMap {
504-
createBuildCommand(for: $0, in: context.pluginWorkDirectory, with: generatorTool.path)
504+
return target.inputFiles.map(\\.url).compactMap {
505+
createBuildCommand(for: $0, in: context.pluginWorkDirectoryURL, with: generatorTool.url)
505506
}
506507
}
507508
}
@@ -510,14 +511,14 @@ public final class InitPackage {
510511
511512
extension \(typeName) {
512513
/// Shared function that returns a configured build command if the input files is one that should be processed.
513-
func createBuildCommand(for inputPath: Path, in outputDirectoryPath: Path, with generatorToolPath: Path) -> Command? {
514+
func createBuildCommand(for inputPath: URL, in outputDirectoryPath: URL, with generatorToolPath: URL) -> Command? {
514515
// Skip any file that doesn't have the extension we're looking for (replace this with the actual one).
515-
guard inputPath.extension == "my-input-suffix" else { return .none }
516+
guard inputPath.pathExtension == "my-input-suffix" else { return .none }
516517
517518
// Return a command that will run during the build to generate the output file.
518-
let inputName = inputPath.lastComponent
519-
let outputName = inputPath.stem + ".swift"
520-
let outputPath = outputDirectoryPath.appending(outputName)
519+
let inputName = inputPath.lastPathComponent
520+
let outputName = inputPath.deletingPathExtension().lastPathComponent + ".swift"
521+
let outputPath = outputDirectoryPath.appendingPathComponent(outputName)
521522
return .buildCommand(
522523
displayName: "Generating \\(outputName) from \\(inputName)",
523524
executable: generatorToolPath,

0 commit comments

Comments
 (0)