Add support for protoc plugins

Add a proto.plugin property to allow specifying a custom protoc
plugin to generate the code.

Fixes: 70706119
Test: m am StreamingProtoTest
Change-Id: I1ecdd346284b42bbcc8297019d98d2cd564eb94c
This commit is contained in:
Colin Cross
2019-03-28 19:30:56 -07:00
parent 19878da6a0
commit fe17f6f0e8
16 changed files with 208 additions and 115 deletions

View File

@@ -17,6 +17,8 @@ package cc
import (
"strings"
"testing"
"android/soong/android"
)
func TestProto(t *testing.T) {
@@ -33,4 +35,37 @@ func TestProto(t *testing.T) {
t.Errorf("expected '--cpp_out' in %q", cmd)
}
})
t.Run("plugin", func(t *testing.T) {
ctx := testCc(t, `
cc_binary_host {
name: "protoc-gen-foobar",
stl: "none",
}
cc_library_shared {
name: "libfoo",
srcs: ["a.proto"],
proto: {
plugin: "foobar",
},
}`)
buildOS := android.BuildOs.String()
proto := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Output("proto/a.pb.cc")
foobar := ctx.ModuleForTests("protoc-gen-foobar", buildOS+"_x86_64")
cmd := proto.RuleParams.Command
if w := "--foobar_out="; !strings.Contains(cmd, w) {
t.Errorf("expected %q in %q", w, cmd)
}
foobarPath := foobar.Module().(android.HostToolProvider).HostToolPath().String()
if w := "--plugin=protoc-gen-foobar=" + foobarPath; !strings.Contains(cmd, w) {
t.Errorf("expected %q in %q", w, cmd)
}
})
}