Vinh Tran | b4bb20f | 2023-08-24 11:10:01 -0400 | [diff] [blame^] | 1 | package bp2build |
| 2 | |
| 3 | import ( |
| 4 | "android/soong/android" |
| 5 | "android/soong/rust" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func rustRustProcMacroTestCase(t *testing.T, tc Bp2buildTestCase) { |
| 10 | t.Helper() |
| 11 | RunBp2BuildTestCase(t, registerRustProcMacroModuleTypes, tc) |
| 12 | } |
| 13 | |
| 14 | func registerRustProcMacroModuleTypes(ctx android.RegistrationContext) { |
| 15 | ctx.RegisterModuleType("rust_library_host", rust.RustLibraryHostFactory) |
| 16 | ctx.RegisterModuleType("rust_proc_macro", rust.ProcMacroFactory) |
| 17 | } |
| 18 | |
| 19 | func TestRustProcMacroLibrary(t *testing.T) { |
| 20 | runRustLibraryTestCase(t, Bp2buildTestCase{ |
| 21 | Dir: "external/rust/crates/foo", |
| 22 | Blueprint: "", |
| 23 | Filesystem: map[string]string{ |
| 24 | "external/rust/crates/foo/src/lib.rs": "", |
| 25 | "external/rust/crates/foo/src/helper.rs": "", |
| 26 | "external/rust/crates/foo/Android.bp": ` |
| 27 | rust_proc_macro { |
| 28 | name: "libfoo", |
| 29 | crate_name: "foo", |
| 30 | srcs: ["src/lib.rs"], |
| 31 | edition: "2021", |
| 32 | features: ["bah-enabled"], |
| 33 | cfgs: ["baz"], |
| 34 | rustlibs: ["libbar"], |
| 35 | bazel_module: { bp2build_available: true }, |
| 36 | } |
| 37 | `, |
| 38 | "external/rust/crates/bar/src/lib.rs": "", |
| 39 | "external/rust/crates/bar/Android.bp": ` |
| 40 | rust_library_host { |
| 41 | name: "libbar", |
| 42 | crate_name: "bar", |
| 43 | srcs: ["src/lib.rs"], |
| 44 | bazel_module: { bp2build_available: true }, |
| 45 | }`, |
| 46 | }, |
| 47 | ExpectedBazelTargets: []string{ |
| 48 | makeBazelTargetHostOrDevice("rust_proc_macro", "libfoo", AttrNameToString{ |
| 49 | "crate_name": `"foo"`, |
| 50 | "srcs": `[ |
| 51 | "src/helper.rs", |
| 52 | "src/lib.rs", |
| 53 | ]`, |
| 54 | "crate_features": `["bah-enabled"]`, |
| 55 | "edition": `"2021"`, |
| 56 | "rustc_flags": `["--cfg=baz"]`, |
| 57 | "deps": `["//external/rust/crates/bar:libbar"]`, |
| 58 | }, android.HostSupported), |
| 59 | }, |
| 60 | }, |
| 61 | ) |
| 62 | } |