Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 1 | // 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 | |
| 15 | package rust |
| 16 | |
| 17 | import ( |
Ivan Lozano | 6a3d1e9 | 2020-11-02 15:06:26 -0500 | [diff] [blame] | 18 | "strings" |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 19 | "testing" |
Ivan Lozano | 6a3d1e9 | 2020-11-02 15:06:26 -0500 | [diff] [blame] | 20 | |
| 21 | "android/soong/android" |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 22 | ) |
| 23 | |
| 24 | func 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", |
| 31 | } |
| 32 | `) |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 33 | // Check that libprotobuf is added as a dependency. |
| 34 | librust_proto := ctx.ModuleForTests("librust_proto", "android_arm64_armv8-a_dylib").Module().(*Module) |
| 35 | if !android.InList("libprotobuf", librust_proto.Properties.AndroidMkDylibs) { |
| 36 | t.Errorf("libprotobuf dependency missing for rust_protobuf (dependency missing from AndroidMkDylibs)") |
| 37 | } |
Ivan Lozano | 6a3d1e9 | 2020-11-02 15:06:26 -0500 | [diff] [blame] | 38 | |
| 39 | // Make sure the correct plugin is being used. |
| 40 | librust_proto_out := ctx.ModuleForTests("librust_proto", "android_arm64_armv8-a_source").Output("buf.rs") |
| 41 | cmd := librust_proto_out.RuleParams.Command |
| 42 | if w := "protoc-gen-rust"; !strings.Contains(cmd, w) { |
| 43 | t.Errorf("expected %q in %q", w, cmd) |
| 44 | } |
| 45 | |
| 46 | } |
| 47 | |
| 48 | func TestRustGrpcio(t *testing.T) { |
| 49 | ctx := testRust(t, ` |
| 50 | rust_grpcio { |
| 51 | name: "librust_grpcio", |
| 52 | proto: "buf.proto", |
| 53 | crate_name: "rust_grpcio", |
| 54 | source_stem: "buf", |
| 55 | } |
| 56 | `) |
| 57 | |
| 58 | // Check that libprotobuf is added as a dependency. |
| 59 | librust_grpcio_module := ctx.ModuleForTests("librust_grpcio", "android_arm64_armv8-a_dylib").Module().(*Module) |
| 60 | if !android.InList("libprotobuf", librust_grpcio_module.Properties.AndroidMkDylibs) { |
| 61 | t.Errorf("libprotobuf dependency missing for rust_grpcio (dependency missing from AndroidMkDylibs)") |
| 62 | } |
| 63 | |
| 64 | // Make sure the correct plugin is being used. |
| 65 | librust_grpcio_out := ctx.ModuleForTests("librust_grpcio", "android_arm64_armv8-a_source").Output("buf.rs") |
| 66 | cmd := librust_grpcio_out.RuleParams.Command |
| 67 | if w := "protoc-gen-grpc"; !strings.Contains(cmd, w) { |
| 68 | t.Errorf("expected %q in %q", w, cmd) |
| 69 | } |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 70 | } |