blob: 845911f75c359eebc2982ec24879dedcb1868c1d [file] [log] [blame]
Treehugger Robot588aae72020-08-21 10:01:58 +00001// Copyright 2020 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package rust
16
17import (
Ivan Lozano6a3d1e92020-11-02 15:06:26 -050018 "strings"
Treehugger Robot588aae72020-08-21 10:01:58 +000019 "testing"
Ivan Lozano6a3d1e92020-11-02 15:06:26 -050020
21 "android/soong/android"
Treehugger Robot588aae72020-08-21 10:01:58 +000022)
23
24func TestRustProtobuf(t *testing.T) {
25 ctx := testRust(t, `
26 rust_protobuf {
27 name: "librust_proto",
28 proto: "buf.proto",
29 crate_name: "rust_proto",
30 source_stem: "buf",
Zach Johnson3df4e632020-11-06 11:56:27 -080031 shared_libs: ["libfoo_shared"],
32 static_libs: ["libfoo_static"],
33 }
34 cc_library_shared {
35 name: "libfoo_shared",
36 export_include_dirs: ["shared_include"],
37 }
38 cc_library_static {
39 name: "libfoo_static",
40 export_include_dirs: ["static_include"],
Treehugger Robot588aae72020-08-21 10:01:58 +000041 }
42 `)
Treehugger Robot588aae72020-08-21 10:01:58 +000043 // Check that libprotobuf is added as a dependency.
44 librust_proto := ctx.ModuleForTests("librust_proto", "android_arm64_armv8-a_dylib").Module().(*Module)
45 if !android.InList("libprotobuf", librust_proto.Properties.AndroidMkDylibs) {
46 t.Errorf("libprotobuf dependency missing for rust_protobuf (dependency missing from AndroidMkDylibs)")
47 }
Ivan Lozano6a3d1e92020-11-02 15:06:26 -050048
49 // Make sure the correct plugin is being used.
50 librust_proto_out := ctx.ModuleForTests("librust_proto", "android_arm64_armv8-a_source").Output("buf.rs")
51 cmd := librust_proto_out.RuleParams.Command
52 if w := "protoc-gen-rust"; !strings.Contains(cmd, w) {
53 t.Errorf("expected %q in %q", w, cmd)
54 }
55
Zach Johnson3df4e632020-11-06 11:56:27 -080056 // Check exported include directories
57 if w := "-Ishared_include"; !strings.Contains(cmd, w) {
58 t.Errorf("expected %q in %q", w, cmd)
59 }
60 if w := "-Istatic_include"; !strings.Contains(cmd, w) {
61 t.Errorf("expected %q in %q", w, cmd)
62 }
Ivan Lozano6a3d1e92020-11-02 15:06:26 -050063}
64
65func TestRustGrpcio(t *testing.T) {
66 ctx := testRust(t, `
67 rust_grpcio {
68 name: "librust_grpcio",
69 proto: "buf.proto",
70 crate_name: "rust_grpcio",
71 source_stem: "buf",
Zach Johnson3df4e632020-11-06 11:56:27 -080072 shared_libs: ["libfoo_shared"],
73 static_libs: ["libfoo_static"],
74 }
75 cc_library_shared {
76 name: "libfoo_shared",
77 export_include_dirs: ["shared_include"],
78 }
79 cc_library_static {
80 name: "libfoo_static",
81 export_include_dirs: ["static_include"],
Ivan Lozano6a3d1e92020-11-02 15:06:26 -050082 }
83 `)
84
85 // Check that libprotobuf is added as a dependency.
86 librust_grpcio_module := ctx.ModuleForTests("librust_grpcio", "android_arm64_armv8-a_dylib").Module().(*Module)
87 if !android.InList("libprotobuf", librust_grpcio_module.Properties.AndroidMkDylibs) {
88 t.Errorf("libprotobuf dependency missing for rust_grpcio (dependency missing from AndroidMkDylibs)")
89 }
90
Zach Johnson3df4e632020-11-06 11:56:27 -080091 // Check that libgrpcio is added as a dependency.
92 if !android.InList("libgrpcio", librust_grpcio_module.Properties.AndroidMkDylibs) {
93 t.Errorf("libgrpcio dependency missing for rust_grpcio (dependency missing from AndroidMkDylibs)")
94 }
95
96 // Check that libfutures is added as a dependency.
97 if !android.InList("libfutures", librust_grpcio_module.Properties.AndroidMkDylibs) {
98 t.Errorf("libfutures dependency missing for rust_grpcio (dependency missing from AndroidMkDylibs)")
99 }
100
Ivan Lozano6a3d1e92020-11-02 15:06:26 -0500101 // Make sure the correct plugin is being used.
Zach Johnson3df4e632020-11-06 11:56:27 -0800102 librust_grpcio_out := ctx.ModuleForTests("librust_grpcio", "android_arm64_armv8-a_source").Output("buf_grpc.rs")
Ivan Lozano6a3d1e92020-11-02 15:06:26 -0500103 cmd := librust_grpcio_out.RuleParams.Command
104 if w := "protoc-gen-grpc"; !strings.Contains(cmd, w) {
105 t.Errorf("expected %q in %q", w, cmd)
106 }
Zach Johnson3df4e632020-11-06 11:56:27 -0800107
108 // Check exported include directories
109 if w := "-Ishared_include"; !strings.Contains(cmd, w) {
110 t.Errorf("expected %q in %q", w, cmd)
111 }
112 if w := "-Istatic_include"; !strings.Contains(cmd, w) {
113 t.Errorf("expected %q in %q", w, cmd)
114 }
115
116 // Check that we're including the exported directory from libprotobuf-cpp-full
117 if w := "-Ilibprotobuf-cpp-full-includes"; !strings.Contains(cmd, w) {
118 t.Errorf("expected %q in %q", w, cmd)
119 }
Treehugger Robot588aae72020-08-21 10:01:58 +0000120}