Vinh Tran | 457ddef | 2023-08-02 13:50:26 -0400 | [diff] [blame] | 1 | package aconfig |
| 2 | |
| 3 | import ( |
| 4 | "android/soong/android" |
| 5 | "android/soong/rust" |
| 6 | "fmt" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | func TestRustAconfigLibrary(t *testing.T) { |
| 11 | result := android.GroupFixturePreparers( |
| 12 | PrepareForTestWithAconfigBuildComponents, |
| 13 | rust.PrepareForTestWithRustIncludeVndk, |
| 14 | android.PrepareForTestWithArchMutator, |
| 15 | android.PrepareForTestWithDefaults, |
| 16 | android.PrepareForTestWithPrebuilts, |
| 17 | ). |
| 18 | ExtendWithErrorHandler(android.FixtureExpectsNoErrors). |
| 19 | RunTestWithBp(t, fmt.Sprintf(` |
| 20 | rust_library { |
| 21 | name: "libflags_rust", // test mock |
| 22 | crate_name: "flags_rust", |
| 23 | srcs: ["lib.rs"], |
| 24 | } |
Dennis Shen | ba6ed2d | 2023-11-08 21:02:53 +0000 | [diff] [blame^] | 25 | rust_library { |
| 26 | name: "liblazy_static", // test mock |
| 27 | crate_name: "lazy_static", |
| 28 | srcs: ["src/lib.rs"], |
| 29 | } |
Vinh Tran | 457ddef | 2023-08-02 13:50:26 -0400 | [diff] [blame] | 30 | aconfig_declarations { |
| 31 | name: "my_aconfig_declarations", |
| 32 | package: "com.example.package", |
| 33 | srcs: ["foo.aconfig"], |
| 34 | } |
| 35 | |
| 36 | rust_aconfig_library { |
| 37 | name: "libmy_rust_aconfig_library", |
| 38 | crate_name: "my_rust_aconfig_library", |
| 39 | aconfig_declarations: "my_aconfig_declarations", |
| 40 | } |
| 41 | `)) |
| 42 | |
| 43 | sourceVariant := result.ModuleForTests("libmy_rust_aconfig_library", "android_arm64_armv8-a_source") |
| 44 | rule := sourceVariant.Rule("rust_aconfig_library") |
| 45 | android.AssertStringEquals(t, "rule must contain production mode", rule.Args["mode"], "production") |
| 46 | |
| 47 | dylibVariant := result.ModuleForTests("libmy_rust_aconfig_library", "android_arm64_armv8-a_dylib") |
| 48 | rlibRlibStdVariant := result.ModuleForTests("libmy_rust_aconfig_library", "android_arm64_armv8-a_rlib_rlib-std") |
| 49 | rlibDylibStdVariant := result.ModuleForTests("libmy_rust_aconfig_library", "android_arm64_armv8-a_rlib_dylib-std") |
| 50 | |
| 51 | variants := []android.TestingModule{ |
| 52 | dylibVariant, |
| 53 | rlibDylibStdVariant, |
| 54 | rlibRlibStdVariant, |
| 55 | } |
| 56 | |
| 57 | for _, variant := range variants { |
Colin Cross | df0ed70 | 2023-09-22 21:59:59 +0000 | [diff] [blame] | 58 | android.AssertStringEquals( |
Vinh Tran | 457ddef | 2023-08-02 13:50:26 -0400 | [diff] [blame] | 59 | t, |
| 60 | "dylib variant builds from generated rust code", |
| 61 | "out/soong/.intermediates/libmy_rust_aconfig_library/android_arm64_armv8-a_source/gen/src/lib.rs", |
Colin Cross | df0ed70 | 2023-09-22 21:59:59 +0000 | [diff] [blame] | 62 | variant.Rule("rustc").Inputs[0].RelativeToTop().String(), |
Vinh Tran | 457ddef | 2023-08-02 13:50:26 -0400 | [diff] [blame] | 63 | ) |
| 64 | } |
| 65 | } |