| 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 | b4bb20f | 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 rustRustProcMacroTestCase(t *testing.T, tc Bp2buildTestCase) { | 
|  | 24 | t.Helper() | 
|  | 25 | RunBp2BuildTestCase(t, registerRustProcMacroModuleTypes, tc) | 
|  | 26 | } | 
|  | 27 |  | 
|  | 28 | func registerRustProcMacroModuleTypes(ctx android.RegistrationContext) { | 
|  | 29 | ctx.RegisterModuleType("rust_library_host", rust.RustLibraryHostFactory) | 
|  | 30 | ctx.RegisterModuleType("rust_proc_macro", rust.ProcMacroFactory) | 
|  | 31 | } | 
|  | 32 |  | 
|  | 33 | func TestRustProcMacroLibrary(t *testing.T) { | 
| Liz Kammer | 267f1f7 | 2023-09-01 01:17:21 -0400 | [diff] [blame] | 34 | rustRustProcMacroTestCase(t, Bp2buildTestCase{ | 
| Vinh Tran | b4bb20f | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 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_proc_macro { | 
|  | 42 | name: "libfoo", | 
|  | 43 | crate_name: "foo", | 
|  | 44 | srcs: ["src/lib.rs"], | 
|  | 45 | edition: "2021", | 
|  | 46 | features: ["bah-enabled"], | 
|  | 47 | cfgs: ["baz"], | 
|  | 48 | rustlibs: ["libbar"], | 
|  | 49 | bazel_module: { bp2build_available: true }, | 
|  | 50 | } | 
|  | 51 | `, | 
|  | 52 | "external/rust/crates/bar/src/lib.rs": "", | 
|  | 53 | "external/rust/crates/bar/Android.bp": ` | 
|  | 54 | rust_library_host { | 
|  | 55 | name: "libbar", | 
|  | 56 | crate_name: "bar", | 
|  | 57 | srcs: ["src/lib.rs"], | 
|  | 58 | bazel_module: { bp2build_available: true }, | 
|  | 59 | }`, | 
|  | 60 | }, | 
|  | 61 | ExpectedBazelTargets: []string{ | 
|  | 62 | makeBazelTargetHostOrDevice("rust_proc_macro", "libfoo", AttrNameToString{ | 
|  | 63 | "crate_name": `"foo"`, | 
|  | 64 | "srcs": `[ | 
|  | 65 | "src/helper.rs", | 
|  | 66 | "src/lib.rs", | 
|  | 67 | ]`, | 
|  | 68 | "crate_features": `["bah-enabled"]`, | 
|  | 69 | "edition":        `"2021"`, | 
|  | 70 | "rustc_flags":    `["--cfg=baz"]`, | 
|  | 71 | "deps":           `["//external/rust/crates/bar:libbar"]`, | 
|  | 72 | }, android.HostSupported), | 
|  | 73 | }, | 
|  | 74 | }, | 
|  | 75 | ) | 
|  | 76 | } |