From 49ce87ef75458685736d590c6db2739bbe191726 Mon Sep 17 00:00:00 2001 From: Andrea Marchini Date: Mon, 22 Jul 2024 10:34:00 +0000 Subject: [PATCH] Soong cc proto fix for grpc plugin - Update output file names when using grpc plugin (grpc.pb instead of pb) Change-Id: I702553713d1a667f90a5502291bd15b7cedd7eb7 Signed-off-by: Andrea Marchini --- cc/proto.go | 18 ++++++++++++++---- cc/proto_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/cc/proto.go b/cc/proto.go index 4d72f2665..93142b9fe 100644 --- a/cc/proto.go +++ b/cc/proto.go @@ -19,6 +19,8 @@ import ( "github.com/google/blueprint/proptools" "android/soong/android" + + "strings" ) const ( @@ -35,13 +37,21 @@ func genProto(ctx android.ModuleContext, protoFile android.Path, flags builderFl srcSuffix = ".c" } + srcInfix := "pb" + for _, value := range flags.proto.Flags { + if strings.HasPrefix(value, "--plugin=") && strings.HasSuffix(value, "protoc-gen-grpc-cpp-plugin") { + srcInfix = "grpc.pb" + break + } + } + if flags.proto.CanonicalPathFromRoot { - ccFile = android.GenPathWithExt(ctx, "proto", protoFile, "pb"+srcSuffix) - headerFile = android.GenPathWithExt(ctx, "proto", protoFile, "pb.h") + ccFile = android.GenPathWithExt(ctx, "proto", protoFile, srcInfix+srcSuffix) + headerFile = android.GenPathWithExt(ctx, "proto", protoFile, srcInfix+".h") } else { rel := protoFile.Rel() - ccFile = android.PathForModuleGen(ctx, "proto", pathtools.ReplaceExtension(rel, "pb"+srcSuffix)) - headerFile = android.PathForModuleGen(ctx, "proto", pathtools.ReplaceExtension(rel, "pb.h")) + ccFile = android.PathForModuleGen(ctx, "proto", pathtools.ReplaceExtension(rel, srcInfix+srcSuffix)) + headerFile = android.PathForModuleGen(ctx, "proto", pathtools.ReplaceExtension(rel, srcInfix+".h")) } protoDeps := flags.proto.Deps diff --git a/cc/proto_test.go b/cc/proto_test.go index abcb27304..a905ea889 100644 --- a/cc/proto_test.go +++ b/cc/proto_test.go @@ -68,4 +68,36 @@ func TestProto(t *testing.T) { } }) + t.Run("grpc-cpp-plugin", func(t *testing.T) { + ctx := testCc(t, ` + cc_binary_host { + name: "protoc-gen-grpc-cpp-plugin", + stl: "none", + } + + cc_library_shared { + name: "libgrpc", + srcs: ["a.proto"], + proto: { + plugin: "grpc-cpp-plugin", + }, + }`) + + buildOS := ctx.Config().BuildOS.String() + + proto := ctx.ModuleForTests("libgrpc", "android_arm_armv7-a-neon_shared").Output("proto/a.grpc.pb.cc") + grpcCppPlugin := ctx.ModuleForTests("protoc-gen-grpc-cpp-plugin", buildOS+"_x86_64") + + cmd := proto.RuleParams.Command + if w := "--grpc-cpp-plugin_out="; !strings.Contains(cmd, w) { + t.Errorf("expected %q in %q", w, cmd) + } + + grpcCppPluginPath := grpcCppPlugin.Module().(android.HostToolProvider).HostToolPath().RelativeToTop().String() + + if w := "--plugin=protoc-gen-grpc-cpp-plugin=" + grpcCppPluginPath; !strings.Contains(cmd, w) { + t.Errorf("expected %q in %q", w, cmd) + } + }) + }