Skip to content

Commit 17d8f28

Browse files
committed
Fix build tool plugin on Windows
1 parent 59a0869 commit 17d8f28

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed
Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import PackagePlugin
2+
import Foundation
23

34
@main
45
struct SimpleBuildToolPlugin: BuildToolPlugin {
@@ -9,28 +10,35 @@ struct SimpleBuildToolPlugin: BuildToolPlugin {
910

1011
// Construct a build command for each source file with a particular suffix.
1112
return sourceFiles.map(\.path).compactMap {
12-
createBuildCommand(for: $0, in: context.pluginWorkDirectory, with: generatorTool.path)
13+
createBuildCommand(
14+
for: $0,
15+
in: context.pluginWorkDirectory,
16+
with: generatorTool.path
17+
)
1318
}
1419
}
1520

1621
/// Calls a build tool that transforms JSON files into Swift files.
1722
func createBuildCommand(for inputPath: Path, in outputDirectoryPath: Path, with generatorToolPath: Path) -> Command? {
23+
let inputURL = URL(fileURLWithPath: inputPath.string)
24+
let outputDirectoryURL = URL(fileURLWithPath: outputDirectoryPath.string)
25+
1826
// Skip any file that doesn't have the extension we're looking for (replace this with the actual one).
19-
guard inputPath.extension == "json" else { return .none }
27+
guard inputURL.pathExtension == "json" else { return .none }
2028

2129
// Produces .swift files in the same directory structure as the input JSON files appear in the target.
22-
let components = inputPath.string.split(separator: "LibraryTarget", omittingEmptySubsequences: false).map(String.init)
23-
let inputName = inputPath.lastComponent
24-
let outputDir = outputDirectoryPath.appending(components[1]).removingLastComponent()
25-
let outputName = inputPath.stem + ".swift"
26-
let outputPath = outputDir.appending(outputName)
30+
let components = inputURL.absoluteString.split(separator: "LibraryTarget", omittingEmptySubsequences: false).map(String.init)
31+
let inputName = inputURL.lastPathComponent
32+
let outputDir = outputDirectoryURL.appending(path: components[1]).deletingLastPathComponent()
33+
let outputName = inputURL.deletingPathExtension().lastPathComponent + ".swift"
34+
let outputURL = outputDir.appending(path: outputName)
2735

2836
return .buildCommand(
2937
displayName: "Generating \(outputName) from \(inputName)",
3038
executable: generatorToolPath,
31-
arguments: ["\(inputPath)", "\(outputPath)"],
39+
arguments: ["\(inputPath)", "\(outputURL.path)"],
3240
inputFiles: [inputPath],
33-
outputFiles: [outputPath]
41+
outputFiles: [Path(outputURL.path)],
3442
)
3543
}
3644
}

0 commit comments

Comments
 (0)