From b07fb557a1f26f1c821d0b2ca4fbe88362f78fdf Mon Sep 17 00:00:00 2001 From: George Barnett Date: Wed, 5 Mar 2025 17:10:45 +0000 Subject: [PATCH] Add command plugin to package products Motivation: The command plugin needs to be a product in order for it to be used. Modifications: - Add it to the products - Give it the same name as the command, otherwise diagnostics (like SwiftPM asking for permission to write to the package dir) will use a different name which isn't obvious. - Fix a few build warnings. Result: - Command plugin can be used --- Package.swift | 9 +++++++-- Plugins/GRPCProtobufGeneratorCommand/Plugin.swift | 4 +--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Package.swift b/Package.swift index 2188d62..cad2418 100644 --- a/Package.swift +++ b/Package.swift @@ -30,6 +30,10 @@ let products: [Product] = [ name: "GRPCProtobufGenerator", targets: ["GRPCProtobufGenerator"] ), + .plugin( + name: "generate-grpc-code-from-protos", + targets: ["generate-grpc-code-from-protos"] + ), ] let dependencies: [Package.Dependency] = [ @@ -118,7 +122,7 @@ let targets: [Target] = [ // Code generator SwiftPM command .plugin( - name: "GRPCProtobufGeneratorCommand", + name: "generate-grpc-code-from-protos", capability: .command( intent: .custom( verb: "generate-grpc-code-from-protos", @@ -134,7 +138,8 @@ let targets: [Target] = [ dependencies: [ .target(name: "protoc-gen-grpc-swift"), .product(name: "protoc-gen-swift", package: "swift-protobuf"), - ] + ], + path: "Plugins/GRPCProtobufGeneratorCommand" ), ] diff --git a/Plugins/GRPCProtobufGeneratorCommand/Plugin.swift b/Plugins/GRPCProtobufGeneratorCommand/Plugin.swift index 5123376..830174a 100644 --- a/Plugins/GRPCProtobufGeneratorCommand/Plugin.swift +++ b/Plugins/GRPCProtobufGeneratorCommand/Plugin.swift @@ -145,7 +145,7 @@ struct GRPCProtobufGeneratorCommandPlugin { outputDirectory: outputDirectory ) - let completionStatus = try executeProtocInvocation( + try executeProtocInvocation( executableURL: protocPath, arguments: arguments, verbose: commandConfig.verbose, @@ -229,8 +229,6 @@ func executeProtocInvocation( arguments: arguments, stdErr: stdErr ) - - return } func printProtocOutput(_ stdOut: Pipe, verbose: Bool) throws {