File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -407,8 +407,26 @@ public final class InitPackage {
407
407
content += """
408
408
struct \( typeName) : BuildToolPlugin {
409
409
func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
410
- print( " Hello, World! " )
411
- return []
410
+ // The plugin can choose what parts of the package to process.
411
+ guard let sourceFiles = target.sourceModule?.sourceFiles else { return [] }
412
+
413
+ // Find the code generator tool to run (replace this with the actual one).
414
+ let generatorTool = try context.tool(named: " my-code-generator " )
415
+
416
+ // Construct a build command for each source file with a particular suffix.
417
+ return sourceFiles.map( \\ .path).compactMap { inputPath in
418
+ guard inputPath.extension == " my-input-suffix " else { return .none }
419
+ let inputName = inputPath.lastComponent
420
+ let outputName = inputPath.stem + " .swift "
421
+ let outputPath = context.pluginWorkDirectory.appending(outputName)
422
+ return .buildCommand(
423
+ displayName: " Generating \\ (outputName) from \\ (inputName) " ,
424
+ executable: generatorTool.path,
425
+ arguments: [ " \\ (inputPath) " , " -o " , " \\ (outputPath) " ],
426
+ inputFiles: [inputPath],
427
+ outputFiles: [outputPath]
428
+ )
429
+ }
412
430
}
413
431
}
414
432
You can’t perform that action at this time.
0 commit comments