Liz Kammer | 267f1f7 | 2023-09-01 01:17:21 -0400 | [diff] [blame] | 1 | // Copyright 2023 Google Inc. All rights reserved. |
| 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 | |
Vinh Tran | 0c4b9ec | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 15 | package bp2build |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/rust" |
| 20 | "testing" |
| 21 | ) |
| 22 | |
| 23 | func runRustProtobufTestCase(t *testing.T, tc Bp2buildTestCase) { |
| 24 | t.Helper() |
| 25 | RunBp2BuildTestCase(t, registerRustProtobufModuleTypes, tc) |
| 26 | } |
| 27 | |
| 28 | func registerRustProtobufModuleTypes(ctx android.RegistrationContext) { |
| 29 | ctx.RegisterModuleType("rust_protobuf_host", rust.RustProtobufHostFactory) |
Vinh Tran | 47faaad | 2023-09-25 14:47:19 -0400 | [diff] [blame] | 30 | ctx.RegisterModuleType("rust_protobuf", rust.RustProtobufHostFactory) |
Vinh Tran | 0c4b9ec | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | func TestRustProtobufHostTestCase(t *testing.T) { |
| 34 | runRustProtobufTestCase(t, Bp2buildTestCase{ |
| 35 | Dir: "external/rust/crates/foo", |
| 36 | Blueprint: "", |
| 37 | Filesystem: map[string]string{ |
| 38 | "external/rust/crates/foo/src/lib.rs": "", |
| 39 | "external/rust/crates/foo/src/helper.rs": "", |
| 40 | "external/rust/crates/foo/Android.bp": ` |
| 41 | rust_protobuf_host { |
| 42 | name: "libfoo", |
| 43 | crate_name: "foo", |
| 44 | protos: ["src/foo.proto"], |
| 45 | bazel_module: { bp2build_available: true }, |
| 46 | } |
| 47 | `, |
| 48 | }, |
| 49 | ExpectedBazelTargets: []string{ |
| 50 | makeBazelTargetHostOrDevice("proto_library", "libfoo_proto", AttrNameToString{ |
| 51 | "srcs": `["src/foo.proto"]`, |
| 52 | }, android.HostSupported), |
| 53 | makeBazelTargetHostOrDevice("rust_proto_library", "libfoo", AttrNameToString{ |
| 54 | "crate_name": `"foo"`, |
| 55 | "deps": `[":libfoo_proto"]`, |
| 56 | }, android.HostSupported), |
| 57 | }, |
| 58 | }, |
| 59 | ) |
| 60 | } |
Vinh Tran | 47faaad | 2023-09-25 14:47:19 -0400 | [diff] [blame] | 61 | |
| 62 | func TestRustProtobufTestCase(t *testing.T) { |
| 63 | runRustProtobufTestCase(t, Bp2buildTestCase{ |
| 64 | Dir: "external/rust/crates/foo", |
| 65 | Blueprint: "", |
| 66 | Filesystem: map[string]string{ |
| 67 | "external/rust/crates/foo/src/lib.rs": "", |
| 68 | "external/rust/crates/foo/src/helper.rs": "", |
| 69 | "external/rust/crates/foo/Android.bp": ` |
| 70 | rust_protobuf { |
| 71 | name: "libfoo", |
| 72 | crate_name: "foo", |
| 73 | protos: ["src/foo.proto"], |
| 74 | bazel_module: { bp2build_available: true }, |
| 75 | } |
| 76 | `, |
| 77 | }, |
| 78 | ExpectedBazelTargets: []string{ |
| 79 | makeBazelTargetHostOrDevice("proto_library", "libfoo_proto", AttrNameToString{ |
| 80 | "srcs": `["src/foo.proto"]`, |
| 81 | }, android.HostSupported), |
| 82 | makeBazelTargetHostOrDevice("rust_proto_library", "libfoo", AttrNameToString{ |
| 83 | "crate_name": `"foo"`, |
| 84 | "deps": `[":libfoo_proto"]`, |
| 85 | }, android.HostSupported), |
| 86 | }, |
| 87 | }, |
| 88 | ) |
| 89 | } |