summaryrefslogtreecommitdiff
path: root/rust/protobuf_test.go
diff options
context:
space:
mode:
author Ivan Lozano <ivanlozano@google.com> 2023-09-21 23:30:26 -0400
committer Ivan Lozano <ivanlozano@google.com> 2023-09-27 20:53:54 -0400
commitd106efe76d0301de27868d3c714b5ba4a42a3fb1 (patch)
tree141ef6e5e5e8113497ade1f9d8d9f9a8c624f361 /rust/protobuf_test.go
parentc5b9abba309e4bb65e6ae69c60b44d0f4b59e278 (diff)
rust: Import protos from dependent rust_protobuf
rust_protobuf were unable to import protos from other rust_protobuf modules. This CL adds support for that. rust_protobuf modules which are listed in rustlibs will have their modules imported into the generated protobuf stub. Additionally, rust_protobuf modules which define "exported_include_dirs" will export those include paths to dependent rust_protobuf modules. Bug: 301266700 Test: m rust Change-Id: I132edffa4d77e0ac80a7ac934f873374c8e94c1b
Diffstat (limited to 'rust/protobuf_test.go')
-rw-r--r--rust/protobuf_test.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/rust/protobuf_test.go b/rust/protobuf_test.go
index b723f3f1a..9dca0290f 100644
--- a/rust/protobuf_test.go
+++ b/rust/protobuf_test.go
@@ -118,6 +118,58 @@ func TestRustProtobuf3(t *testing.T) {
}
}
+func TestRustProtobufInclude(t *testing.T) {
+ ctx := testRust(t, `
+ rust_protobuf {
+ name: "librust_proto",
+ protos: ["proto.proto"],
+ crate_name: "rust_proto",
+ source_stem: "proto",
+ use_protobuf3: true,
+ rustlibs: ["librust_exported_proto", "libfoo"],
+ }
+ rust_protobuf {
+ name: "librust_exported_proto",
+ protos: ["proto.proto"],
+ crate_name: "rust_exported_proto",
+ source_stem: "exported_proto",
+ use_protobuf3: true,
+ exported_include_dirs: ["proto"]
+ }
+ rust_library {
+ name: "libfoo",
+ crate_name: "foo",
+ srcs: ["foo.rs"],
+ }
+ `)
+ // Check that librust_exported_proto is added as additional crate to generate source.
+ librust_proto := ctx.ModuleForTests("librust_proto", "android_arm64_armv8-a_source").Module().(*Module).sourceProvider.(*protobufDecorator)
+ if !android.InList("rust_exported_proto", librust_proto.additionalCrates) {
+ t.Errorf("librust_proto should have librust_exported_proto included as an additional crate for generated source, instead got: %#v", librust_proto.additionalCrates)
+ }
+
+ // Make sure the default crates aren't being included.
+ if android.InList("std", librust_proto.additionalCrates) {
+ t.Errorf("librust_proto should not have included libstd as an additional crate for generated source, instead got: %#v", librust_proto.additionalCrates)
+ }
+ if android.InList("protobuf", librust_proto.additionalCrates) {
+ t.Errorf("librust_proto should not have included libprotobuf as an additional crate for generated source, instead got: %#v", librust_proto.additionalCrates)
+ }
+
+ // And make sure that non-protobuf crates aren't getting included either.
+ if android.InList("foo", librust_proto.additionalCrates) {
+ t.Errorf("librust_proto should not have included libfoo as an additional crate for generated source, instead got: %#v", librust_proto.additionalCrates)
+ }
+
+ // Check librust_proto args includes -Iproto
+ librust_proto_rule := ctx.ModuleForTests("librust_proto", "android_arm64_armv8-a_source").Output("proto.rs")
+ cmd := librust_proto_rule.RuleParams.Command
+ if w := "-Iproto"; !strings.Contains(cmd, w) {
+ t.Errorf("expected %q in %q", w, cmd)
+ }
+
+}
+
func TestRustGrpc(t *testing.T) {
ctx := testRust(t, `
rust_protobuf {