wip
This commit is contained in:
30
Plugins/GenerateVersionPlugin/GenerateVersionPlugin.swift
Normal file
30
Plugins/GenerateVersionPlugin/GenerateVersionPlugin.swift
Normal file
@@ -0,0 +1,30 @@
|
||||
import PackagePlugin
|
||||
import Foundation
|
||||
|
||||
@main
|
||||
struct GenerateVersionPlugin: CommandPlugin {
|
||||
|
||||
func performCommand(context: PluginContext, arguments: [String]) async throws {
|
||||
let gitVersion = try context.tool(named: "git-version")
|
||||
|
||||
var arguments = ["generate"] + arguments
|
||||
|
||||
for target in context.package.targets {
|
||||
guard let target = target as? SourceModuleTarget,
|
||||
arguments.first(where: { $0.contains(target.name) }) != nil
|
||||
else { continue }
|
||||
|
||||
let process = Process()
|
||||
process.executableURL = URL(fileURLWithPath: gitVersion.path.string)
|
||||
process.arguments = arguments
|
||||
try process.run()
|
||||
process.waitUntilExit()
|
||||
|
||||
guard process.terminationReason == .exit && process.terminationStatus == 0 else {
|
||||
Diagnostics.error("Reason: \(process.terminationReason), status: \(process.terminationStatus)")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user