Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1 | // Copyright 2021 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 ( |
| 18 | "fmt" |
| 19 | "path/filepath" |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 20 | "reflect" |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 21 | "strings" |
| 22 | "testing" |
| 23 | |
| 24 | "android/soong/android" |
| 25 | "android/soong/cc" |
| 26 | ) |
| 27 | |
| 28 | func TestVendorSnapshotCapture(t *testing.T) { |
| 29 | bp := ` |
| 30 | rust_ffi { |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 31 | name: "libffivendor_available", |
| 32 | crate_name: "ffivendor_available", |
| 33 | srcs: ["lib.rs"], |
| 34 | vendor_available: true, |
| 35 | include_dirs: ["rust_headers/"], |
| 36 | } |
| 37 | |
| 38 | rust_ffi { |
| 39 | name: "libffivendor", |
| 40 | crate_name: "ffivendor", |
| 41 | srcs: ["lib.rs"], |
| 42 | vendor: true, |
| 43 | include_dirs: ["rust_headers/"], |
| 44 | } |
| 45 | |
| 46 | rust_library { |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 47 | name: "librustvendor_available", |
| 48 | crate_name: "rustvendor_available", |
| 49 | srcs: ["lib.rs"], |
| 50 | vendor_available: true, |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 51 | } |
| 52 | |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 53 | rust_library { |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 54 | name: "librustvendor", |
| 55 | crate_name: "rustvendor", |
| 56 | srcs: ["lib.rs"], |
| 57 | vendor: true, |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 58 | } |
| 59 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 60 | rust_binary { |
| 61 | name: "vendor_available_bin", |
| 62 | vendor_available: true, |
| 63 | srcs: ["srcs/lib.rs"], |
| 64 | } |
| 65 | |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 66 | rust_binary { |
| 67 | name: "vendor_bin", |
| 68 | vendor: true, |
| 69 | srcs: ["srcs/lib.rs"], |
| 70 | } |
| 71 | ` |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 72 | skipTestIfOsNotSupported(t) |
| 73 | result := android.GroupFixturePreparers( |
| 74 | prepareForRustTest, |
| 75 | rustMockedFiles.AddToFixture(), |
| 76 | android.FixtureModifyProductVariables( |
| 77 | func(variables android.FixtureProductVariables) { |
| 78 | variables.DeviceVndkVersion = StringPtr("current") |
| 79 | variables.Platform_vndk_version = StringPtr("29") |
| 80 | }, |
| 81 | ), |
| 82 | ).RunTestWithBp(t, bp) |
| 83 | ctx := result.TestContext |
| 84 | |
| 85 | // Check Vendor snapshot output. |
| 86 | |
| 87 | snapshotDir := "vendor-snapshot" |
| 88 | snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64") |
| 89 | snapshotSingleton := ctx.SingletonForTests("vendor-snapshot") |
| 90 | var jsonFiles []string |
| 91 | for _, arch := range [][]string{ |
| 92 | []string{"arm64", "armv8-a"}, |
| 93 | []string{"arm", "armv7-a-neon"}, |
| 94 | } { |
| 95 | archType := arch[0] |
| 96 | archVariant := arch[1] |
| 97 | archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) |
| 98 | |
| 99 | // For shared libraries, only non-VNDK vendor_available modules are captured |
| 100 | sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant) |
| 101 | sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 102 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "libffivendor_available", "libffivendor_available.so", sharedDir, sharedVariant) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 103 | jsonFiles = append(jsonFiles, |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 104 | filepath.Join(sharedDir, "libffivendor_available.so.json")) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 105 | |
| 106 | // For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured. |
| 107 | staticVariant := fmt.Sprintf("android_vendor.29_%s_%s_static", archType, archVariant) |
| 108 | staticDir := filepath.Join(snapshotVariantPath, archDir, "static") |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 109 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "libffivendor_available", "libffivendor_available.a", staticDir, staticVariant) |
| 110 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "libffivendor", "libffivendor.a", staticDir, staticVariant) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 111 | jsonFiles = append(jsonFiles, |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 112 | filepath.Join(staticDir, "libffivendor_available.a.json")) |
| 113 | jsonFiles = append(jsonFiles, |
| 114 | filepath.Join(staticDir, "libffivendor.a.json")) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 115 | |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 116 | // For rlib libraries, all vendor:true and vendor_available modules (including VNDK) are captured. |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 117 | rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_dylib-std", archType, archVariant) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 118 | rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib") |
| 119 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib", rlibDir, rlibVariant) |
| 120 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor", "librustvendor.rlib", rlibDir, rlibVariant) |
| 121 | jsonFiles = append(jsonFiles, |
| 122 | filepath.Join(rlibDir, "librustvendor_available.rlib.json")) |
| 123 | jsonFiles = append(jsonFiles, |
| 124 | filepath.Join(rlibDir, "librustvendor.rlib.json")) |
| 125 | |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 126 | // For rlib libraries, all rlib-std variants vendor:true and vendor_available modules (including VNDK) are captured. |
| 127 | rlibStdVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant) |
| 128 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib-std.rlib", rlibDir, rlibStdVariant) |
| 129 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor", "librustvendor.rlib-std.rlib", rlibDir, rlibStdVariant) |
| 130 | jsonFiles = append(jsonFiles, |
| 131 | filepath.Join(rlibDir, "librustvendor_available.rlib.json")) |
| 132 | jsonFiles = append(jsonFiles, |
| 133 | filepath.Join(rlibDir, "librustvendor.rlib.json")) |
| 134 | |
| 135 | // For dylib libraries, all vendor:true and vendor_available modules (including VNDK) are captured. |
| 136 | dylibVariant := fmt.Sprintf("android_vendor.29_%s_%s_dylib", archType, archVariant) |
| 137 | dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib") |
| 138 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.dylib.so", dylibDir, dylibVariant) |
| 139 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor", "librustvendor.dylib.so", dylibDir, dylibVariant) |
| 140 | jsonFiles = append(jsonFiles, |
| 141 | filepath.Join(dylibDir, "librustvendor_available.dylib.so.json")) |
| 142 | jsonFiles = append(jsonFiles, |
| 143 | filepath.Join(dylibDir, "librustvendor.dylib.so.json")) |
| 144 | |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 145 | // For binary executables, all vendor:true and vendor_available modules are captured. |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 146 | if archType == "arm64" { |
| 147 | binaryVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant) |
| 148 | binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary") |
| 149 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 150 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "vendor_bin", "vendor_bin", binaryDir, binaryVariant) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 151 | jsonFiles = append(jsonFiles, |
| 152 | filepath.Join(binaryDir, "vendor_available_bin.json")) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 153 | jsonFiles = append(jsonFiles, |
| 154 | filepath.Join(binaryDir, "vendor_bin.json")) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | |
| 158 | for _, jsonFile := range jsonFiles { |
| 159 | // verify all json files exist |
| 160 | if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { |
| 161 | t.Errorf("%q expected but not found; #%v", jsonFile, jsonFiles) |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | // fake snapshot should have all outputs in the normal snapshot. |
| 166 | fakeSnapshotSingleton := ctx.SingletonForTests("vendor-fake-snapshot") |
| 167 | |
| 168 | for _, output := range snapshotSingleton.AllOutputs() { |
| 169 | fakeOutput := strings.Replace(output, "/vendor-snapshot/", "/fake/vendor-snapshot/", 1) |
| 170 | if fakeSnapshotSingleton.MaybeOutput(fakeOutput).Rule == nil { |
| 171 | t.Errorf("%q expected but not found", fakeOutput) |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | func TestVendorSnapshotDirected(t *testing.T) { |
| 177 | bp := ` |
| 178 | rust_ffi_shared { |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 179 | name: "libffivendor_available", |
| 180 | crate_name: "ffivendor_available", |
| 181 | srcs: ["lib.rs"], |
| 182 | vendor_available: true, |
| 183 | } |
| 184 | |
| 185 | rust_library { |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 186 | name: "librustvendor_available", |
| 187 | crate_name: "rustvendor_available", |
| 188 | srcs: ["lib.rs"], |
| 189 | vendor_available: true, |
| 190 | } |
| 191 | |
| 192 | rust_ffi_shared { |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 193 | name: "libffivendor_exclude", |
| 194 | crate_name: "ffivendor_exclude", |
| 195 | srcs: ["lib.rs"], |
| 196 | vendor_available: true, |
| 197 | } |
| 198 | |
| 199 | rust_library { |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 200 | name: "librustvendor_exclude", |
| 201 | crate_name: "rustvendor_exclude", |
| 202 | srcs: ["lib.rs"], |
| 203 | vendor_available: true, |
| 204 | } |
| 205 | ` |
| 206 | ctx := testRustVndk(t, bp) |
| 207 | ctx.Config().TestProductVariables.VendorSnapshotModules = make(map[string]bool) |
| 208 | ctx.Config().TestProductVariables.VendorSnapshotModules["librustvendor_available"] = true |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 209 | ctx.Config().TestProductVariables.VendorSnapshotModules["libffivendor_available"] = true |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 210 | ctx.Config().TestProductVariables.DirectedVendorSnapshot = true |
| 211 | |
| 212 | // Check Vendor snapshot output. |
| 213 | |
| 214 | snapshotDir := "vendor-snapshot" |
| 215 | snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64") |
| 216 | snapshotSingleton := ctx.SingletonForTests("vendor-snapshot") |
| 217 | |
| 218 | var includeJsonFiles []string |
| 219 | |
| 220 | for _, arch := range [][]string{ |
| 221 | []string{"arm64", "armv8-a"}, |
| 222 | []string{"arm", "armv7-a-neon"}, |
| 223 | } { |
| 224 | archType := arch[0] |
| 225 | archVariant := arch[1] |
| 226 | archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) |
| 227 | |
| 228 | sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 229 | rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_dylib-std", archType, archVariant) |
| 230 | rlibRlibStdVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 231 | sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 232 | rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib") |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 233 | dylibVariant := fmt.Sprintf("android_vendor.29_%s_%s_dylib", archType, archVariant) |
| 234 | dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib") |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 235 | |
| 236 | // Included modules |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 237 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib", rlibDir, rlibVariant) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 238 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib-std.rlib", rlibDir, rlibRlibStdVariant) |
| 239 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.dylib.so", dylibDir, dylibVariant) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 240 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "libffivendor_available", "libffivendor_available.so", sharedDir, sharedVariant) |
| 241 | includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_available.rlib.json")) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 242 | includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_available.rlib-std.rlib.json")) |
| 243 | includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librustvendor_available.dylib.so.json")) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 244 | includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libffivendor_available.so.json")) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 245 | |
| 246 | // Excluded modules. Modules not included in the directed vendor snapshot |
| 247 | // are still include as fake modules. |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 248 | cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librustvendor_exclude", "librustvendor_exclude.rlib", rlibDir, rlibVariant) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 249 | cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librustvendor_exclude", "librustvendor_exclude.rlib-std.rlib", rlibDir, rlibRlibStdVariant) |
| 250 | cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librustvendor_exclude", "librustvendor_exclude.dylib.so", dylibDir, dylibVariant) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 251 | cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "libffivendor_exclude", "libffivendor_exclude.so", sharedDir, sharedVariant) |
| 252 | includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_exclude.rlib.json")) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 253 | includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_exclude.rlib-std.rlib.json")) |
| 254 | includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librustvendor_exclude.dylib.so.json")) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 255 | includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libffivendor_exclude.so.json")) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | // Verify that each json file for an included module has a rule. |
| 259 | for _, jsonFile := range includeJsonFiles { |
| 260 | if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { |
| 261 | t.Errorf("include json file %q not found", jsonFile) |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | func TestVendorSnapshotExclude(t *testing.T) { |
| 267 | |
| 268 | // This test verifies that the exclude_from_vendor_snapshot property |
| 269 | // makes its way from the Android.bp source file into the module data |
| 270 | // structure. It also verifies that modules are correctly included or |
| 271 | // excluded in the vendor snapshot based on their path (framework or |
| 272 | // vendor) and the exclude_from_vendor_snapshot property. |
| 273 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 274 | frameworkBp := ` |
| 275 | rust_ffi_shared { |
| 276 | name: "libinclude", |
| 277 | crate_name: "include", |
| 278 | srcs: ["include.rs"], |
| 279 | vendor_available: true, |
| 280 | } |
| 281 | |
| 282 | rust_ffi_shared { |
| 283 | name: "libexclude", |
| 284 | crate_name: "exclude", |
| 285 | srcs: ["exclude.rs"], |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 286 | vendor: true, |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 287 | exclude_from_vendor_snapshot: true, |
| 288 | } |
| 289 | |
| 290 | rust_ffi_shared { |
| 291 | name: "libavailable_exclude", |
| 292 | crate_name: "available_exclude", |
| 293 | srcs: ["lib.rs"], |
| 294 | vendor_available: true, |
| 295 | exclude_from_vendor_snapshot: true, |
| 296 | } |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 297 | |
| 298 | rust_library { |
| 299 | name: "librust_include", |
| 300 | crate_name: "rust_include", |
| 301 | srcs: ["include.rs"], |
| 302 | vendor_available: true, |
| 303 | } |
| 304 | |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 305 | rust_library { |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 306 | name: "librust_exclude", |
| 307 | crate_name: "rust_exclude", |
| 308 | srcs: ["exclude.rs"], |
| 309 | vendor: true, |
| 310 | exclude_from_vendor_snapshot: true, |
| 311 | } |
| 312 | |
| 313 | rust_library { |
| 314 | name: "librust_available_exclude", |
| 315 | crate_name: "rust_available_exclude", |
| 316 | srcs: ["lib.rs"], |
| 317 | vendor_available: true, |
| 318 | exclude_from_vendor_snapshot: true, |
| 319 | } |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 320 | ` |
| 321 | |
| 322 | mockFS := map[string][]byte{ |
| 323 | "framework/Android.bp": []byte(frameworkBp), |
| 324 | "framework/include.rs": nil, |
| 325 | "framework/exclude.rs": nil, |
| 326 | } |
| 327 | |
| 328 | ctx := testRustVndkFs(t, "", mockFS) |
| 329 | |
| 330 | // Test an include and exclude framework module. |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 331 | cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false, sharedVendorVariant) |
| 332 | cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true, sharedVendorVariant) |
| 333 | cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true, sharedVendorVariant) |
| 334 | |
| 335 | cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_include", false, rlibVendorVariant) |
| 336 | cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_exclude", true, rlibVendorVariant) |
| 337 | cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_available_exclude", true, rlibVendorVariant) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 338 | |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 339 | cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_include", false, rlibDylibStdVendorVariant) |
| 340 | cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_exclude", true, rlibDylibStdVendorVariant) |
| 341 | cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_available_exclude", true, rlibDylibStdVendorVariant) |
| 342 | |
| 343 | cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_include", false, dylibVendorVariant) |
| 344 | cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_exclude", true, dylibVendorVariant) |
| 345 | cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_available_exclude", true, dylibVendorVariant) |
| 346 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 347 | // Verify the content of the vendor snapshot. |
| 348 | |
| 349 | snapshotDir := "vendor-snapshot" |
| 350 | snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64") |
| 351 | snapshotSingleton := ctx.SingletonForTests("vendor-snapshot") |
| 352 | |
| 353 | var includeJsonFiles []string |
| 354 | var excludeJsonFiles []string |
| 355 | |
| 356 | for _, arch := range [][]string{ |
| 357 | []string{"arm64", "armv8-a"}, |
| 358 | []string{"arm", "armv7-a-neon"}, |
| 359 | } { |
| 360 | archType := arch[0] |
| 361 | archVariant := arch[1] |
| 362 | archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) |
| 363 | |
| 364 | sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant) |
| 365 | sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 366 | |
| 367 | rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_dylib-std", archType, archVariant) |
| 368 | rlibRlibStdVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 369 | rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib") |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 370 | dylibVariant := fmt.Sprintf("android_vendor.29_%s_%s_dylib", archType, archVariant) |
| 371 | dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib") |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 372 | |
| 373 | // Included modules |
| 374 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant) |
| 375 | includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json")) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 376 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librust_include", "librust_include.rlib", rlibDir, rlibVariant) |
| 377 | includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librust_include.rlib.json")) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 378 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librust_include", "librust_include.rlib-std.rlib", rlibDir, rlibRlibStdVariant) |
| 379 | includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librust_include.rlib-std.rlib.json")) |
| 380 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librust_include", "librust_include.dylib.so", dylibDir, dylibVariant) |
| 381 | includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librust_include.dylib.so.json")) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 382 | |
| 383 | // Excluded modules |
| 384 | cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant) |
| 385 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json")) |
| 386 | cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant) |
| 387 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json")) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 388 | cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_exclude", "librust_exclude.rlib", rlibDir, rlibVariant) |
| 389 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librust_exclude.rlib.json")) |
| 390 | cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_available_exclude", "librust_available_exclude.rlib", rlibDir, rlibVariant) |
| 391 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librust_available_exclude.rlib.json")) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 392 | cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_available_exclude", "librust_available_exclude.rlib-std.rlib", rlibDir, rlibRlibStdVariant) |
| 393 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librust_available_exclude.rlib.rlib-std.json")) |
| 394 | cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_exclude", "librust_exclude.dylib.so", dylibDir, dylibVariant) |
| 395 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(dylibDir, "librust_exclude.dylib.so.json")) |
| 396 | cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_available_exclude", "librust_available_exclude.dylib.so", dylibDir, dylibVariant) |
| 397 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(dylibDir, "librust_available_exclude.dylib.so.json")) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | // Verify that each json file for an included module has a rule. |
| 401 | for _, jsonFile := range includeJsonFiles { |
| 402 | if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { |
| 403 | t.Errorf("include json file %q not found", jsonFile) |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | // Verify that each json file for an excluded module has no rule. |
| 408 | for _, jsonFile := range excludeJsonFiles { |
| 409 | if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil { |
| 410 | t.Errorf("exclude json file %q found", jsonFile) |
| 411 | } |
| 412 | } |
| 413 | } |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 414 | |
| 415 | func TestVendorSnapshotUse(t *testing.T) { |
| 416 | frameworkBp := ` |
| 417 | cc_library { |
| 418 | name: "libvndk", |
| 419 | vendor_available: true, |
| 420 | product_available: true, |
| 421 | vndk: { |
| 422 | enabled: true, |
| 423 | }, |
| 424 | nocrt: true, |
| 425 | } |
| 426 | |
| 427 | cc_library { |
| 428 | name: "libvendor", |
| 429 | vendor: true, |
| 430 | nocrt: true, |
| 431 | no_libcrt: true, |
| 432 | stl: "none", |
| 433 | system_shared_libs: [], |
| 434 | } |
| 435 | |
| 436 | cc_library { |
| 437 | name: "libvendor_available", |
| 438 | vendor_available: true, |
| 439 | nocrt: true, |
| 440 | no_libcrt: true, |
| 441 | stl: "none", |
| 442 | system_shared_libs: [], |
| 443 | } |
| 444 | |
| 445 | cc_library { |
| 446 | name: "lib32", |
| 447 | vendor: true, |
| 448 | nocrt: true, |
| 449 | no_libcrt: true, |
| 450 | stl: "none", |
| 451 | system_shared_libs: [], |
| 452 | compile_multilib: "32", |
| 453 | } |
| 454 | |
| 455 | cc_library { |
| 456 | name: "lib64", |
| 457 | vendor: true, |
| 458 | nocrt: true, |
| 459 | no_libcrt: true, |
| 460 | stl: "none", |
| 461 | system_shared_libs: [], |
| 462 | compile_multilib: "64", |
| 463 | } |
| 464 | |
| 465 | rust_binary { |
| 466 | name: "bin", |
| 467 | vendor: true, |
| 468 | srcs: ["bin.rs"], |
| 469 | } |
| 470 | |
| 471 | rust_binary { |
| 472 | name: "bin32", |
| 473 | vendor: true, |
| 474 | compile_multilib: "32", |
| 475 | srcs: ["bin.rs"], |
| 476 | } |
Justin Yun | 24b246a | 2023-03-16 10:36:16 +0900 | [diff] [blame] | 477 | |
| 478 | rust_library { |
| 479 | name: "librust_vendor_available", |
| 480 | crate_name: "rust_vendor", |
| 481 | vendor_available: true, |
| 482 | srcs: ["client.rs"], |
| 483 | } |
| 484 | |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 485 | ` |
| 486 | |
| 487 | vndkBp := ` |
| 488 | vndk_prebuilt_shared { |
| 489 | name: "libvndk", |
| 490 | version: "30", |
| 491 | target_arch: "arm64", |
| 492 | vendor_available: true, |
| 493 | product_available: true, |
| 494 | vndk: { |
| 495 | enabled: true, |
| 496 | }, |
| 497 | arch: { |
| 498 | arm64: { |
| 499 | srcs: ["libvndk.so"], |
| 500 | export_include_dirs: ["include/libvndk"], |
| 501 | }, |
| 502 | arm: { |
| 503 | srcs: ["libvndk.so"], |
| 504 | export_include_dirs: ["include/libvndk"], |
| 505 | }, |
| 506 | }, |
| 507 | } |
| 508 | |
| 509 | // old snapshot module which has to be ignored |
| 510 | vndk_prebuilt_shared { |
| 511 | name: "libvndk", |
| 512 | version: "26", |
| 513 | target_arch: "arm64", |
| 514 | vendor_available: true, |
| 515 | product_available: true, |
| 516 | vndk: { |
| 517 | enabled: true, |
| 518 | }, |
| 519 | arch: { |
| 520 | arm64: { |
| 521 | srcs: ["libvndk.so"], |
| 522 | export_include_dirs: ["include/libvndk"], |
| 523 | }, |
| 524 | arm: { |
| 525 | srcs: ["libvndk.so"], |
| 526 | export_include_dirs: ["include/libvndk"], |
| 527 | }, |
| 528 | }, |
| 529 | } |
| 530 | |
| 531 | // different arch snapshot which has to be ignored |
| 532 | vndk_prebuilt_shared { |
| 533 | name: "libvndk", |
| 534 | version: "30", |
| 535 | target_arch: "arm", |
| 536 | vendor_available: true, |
| 537 | product_available: true, |
| 538 | vndk: { |
| 539 | enabled: true, |
| 540 | }, |
| 541 | arch: { |
| 542 | arm: { |
| 543 | srcs: ["libvndk.so"], |
| 544 | export_include_dirs: ["include/libvndk"], |
| 545 | }, |
| 546 | }, |
| 547 | } |
| 548 | ` |
| 549 | |
| 550 | vendorProprietaryBp := ` |
| 551 | cc_library { |
| 552 | name: "libvendor_without_snapshot", |
| 553 | vendor: true, |
| 554 | nocrt: true, |
| 555 | no_libcrt: true, |
Kalesh Singh | f4ffe0a | 2024-01-29 13:01:51 -0800 | [diff] [blame] | 556 | no_crt_pad_segment: true, |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 557 | stl: "none", |
| 558 | system_shared_libs: [], |
| 559 | } |
| 560 | |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 561 | rust_ffi_shared { |
| 562 | name: "libclient", |
| 563 | crate_name: "client", |
| 564 | vendor: true, |
| 565 | shared_libs: ["libvndk", "libvendor_available"], |
| 566 | static_libs: ["libvendor", "libvendor_without_snapshot"], |
| 567 | rustlibs: ["librust_vendor_available"], |
| 568 | arch: { |
| 569 | arm64: { |
| 570 | shared_libs: ["lib64"], |
| 571 | }, |
| 572 | arm: { |
| 573 | shared_libs: ["lib32"], |
| 574 | }, |
| 575 | }, |
| 576 | srcs: ["client.rs"], |
| 577 | } |
| 578 | |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 579 | rust_library { |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 580 | name: "libclient_rust", |
| 581 | crate_name: "client_rust", |
| 582 | vendor: true, |
| 583 | shared_libs: ["libvndk", "libvendor_available"], |
| 584 | static_libs: ["libvendor", "libvendor_without_snapshot"], |
| 585 | rustlibs: ["librust_vendor_available"], |
| 586 | arch: { |
| 587 | arm64: { |
| 588 | shared_libs: ["lib64"], |
| 589 | }, |
| 590 | arm: { |
| 591 | shared_libs: ["lib32"], |
| 592 | }, |
| 593 | }, |
| 594 | srcs: ["client.rs"], |
| 595 | } |
| 596 | |
| 597 | rust_binary { |
| 598 | name: "bin_without_snapshot", |
| 599 | vendor: true, |
| 600 | static_libs: ["libvndk"], |
| 601 | srcs: ["bin.rs"], |
| 602 | rustlibs: ["librust_vendor_available"], |
| 603 | } |
| 604 | |
| 605 | vendor_snapshot { |
| 606 | name: "vendor_snapshot", |
| 607 | version: "30", |
| 608 | arch: { |
| 609 | arm64: { |
| 610 | vndk_libs: [ |
| 611 | "libvndk", |
| 612 | ], |
| 613 | static_libs: [ |
| 614 | "libvendor", |
| 615 | "libvndk", |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 616 | "libclang_rt.builtins", |
Ivan Lozano | 62cd038 | 2021-11-01 10:27:54 -0400 | [diff] [blame] | 617 | "note_memtag_heap_sync", |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 618 | ], |
| 619 | shared_libs: [ |
| 620 | "libvendor_available", |
| 621 | "lib64", |
| 622 | ], |
| 623 | rlibs: [ |
| 624 | "libstd", |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 625 | "librust_vendor_available", |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 626 | "librust_vendor_available.rlib-std" |
| 627 | ], |
| 628 | dylibs: [ |
| 629 | "libstd", |
| 630 | "librust_vendor_available", |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 631 | ], |
| 632 | binaries: [ |
| 633 | "bin", |
| 634 | ], |
| 635 | objects: [ |
| 636 | "crtend_so", |
| 637 | "crtbegin_so", |
| 638 | "crtbegin_dynamic", |
| 639 | "crtend_android" |
| 640 | ], |
| 641 | }, |
| 642 | arm: { |
| 643 | vndk_libs: [ |
| 644 | "libvndk", |
| 645 | ], |
| 646 | static_libs: [ |
| 647 | "libvendor", |
| 648 | "libvndk", |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 649 | "libclang_rt.builtins", |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 650 | ], |
| 651 | shared_libs: [ |
| 652 | "libvendor_available", |
| 653 | "lib32", |
| 654 | ], |
| 655 | rlibs: [ |
| 656 | "libstd", |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 657 | "librust_vendor_available", |
| 658 | ], |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 659 | dylibs: [ |
| 660 | "libstd", |
| 661 | "librust_vendor_available", |
| 662 | ], |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 663 | binaries: [ |
| 664 | "bin32", |
| 665 | ], |
| 666 | objects: [ |
| 667 | "crtend_so", |
| 668 | "crtbegin_so", |
| 669 | "crtbegin_dynamic", |
| 670 | "crtend_android" |
| 671 | ], |
| 672 | |
| 673 | }, |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | vendor_snapshot_object { |
| 678 | name: "crtend_so", |
| 679 | version: "30", |
| 680 | target_arch: "arm64", |
| 681 | vendor: true, |
| 682 | stl: "none", |
| 683 | crt: true, |
| 684 | arch: { |
| 685 | arm64: { |
| 686 | src: "crtend_so.o", |
| 687 | }, |
| 688 | arm: { |
| 689 | src: "crtend_so.o", |
| 690 | }, |
| 691 | }, |
| 692 | } |
| 693 | |
| 694 | vendor_snapshot_object { |
| 695 | name: "crtbegin_so", |
| 696 | version: "30", |
| 697 | target_arch: "arm64", |
| 698 | vendor: true, |
| 699 | stl: "none", |
| 700 | crt: true, |
| 701 | arch: { |
| 702 | arm64: { |
| 703 | src: "crtbegin_so.o", |
| 704 | }, |
| 705 | arm: { |
| 706 | src: "crtbegin_so.o", |
| 707 | }, |
| 708 | }, |
| 709 | } |
| 710 | |
| 711 | vendor_snapshot_rlib { |
| 712 | name: "libstd", |
| 713 | version: "30", |
| 714 | target_arch: "arm64", |
| 715 | vendor: true, |
| 716 | sysroot: true, |
| 717 | arch: { |
| 718 | arm64: { |
| 719 | src: "libstd.rlib", |
| 720 | }, |
| 721 | arm: { |
| 722 | src: "libstd.rlib", |
| 723 | }, |
| 724 | }, |
| 725 | } |
| 726 | |
| 727 | vendor_snapshot_rlib { |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 728 | name: "librust_vendor_available", |
| 729 | version: "30", |
| 730 | target_arch: "arm64", |
| 731 | vendor: true, |
| 732 | arch: { |
| 733 | arm64: { |
| 734 | src: "librust_vendor_available.rlib", |
| 735 | }, |
| 736 | arm: { |
| 737 | src: "librust_vendor_available.rlib", |
| 738 | }, |
| 739 | }, |
| 740 | } |
| 741 | |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 742 | vendor_snapshot_rlib { |
| 743 | name: "librust_vendor_available.rlib-std", |
| 744 | version: "30", |
| 745 | target_arch: "arm64", |
| 746 | vendor: true, |
| 747 | arch: { |
| 748 | arm64: { |
| 749 | src: "librust_vendor_available.rlib-std.rlib", |
| 750 | }, |
| 751 | arm: { |
| 752 | src: "librust_vendor_available.rlib-std.rlib", |
| 753 | }, |
| 754 | }, |
| 755 | } |
| 756 | |
| 757 | vendor_snapshot_dylib { |
| 758 | name: "libstd", |
| 759 | version: "30", |
| 760 | target_arch: "arm64", |
| 761 | vendor: true, |
| 762 | sysroot: true, |
| 763 | arch: { |
| 764 | arm64: { |
| 765 | src: "libstd.dylib.so", |
| 766 | }, |
| 767 | arm: { |
| 768 | src: "libstd.dylib.so", |
| 769 | }, |
| 770 | }, |
| 771 | } |
| 772 | |
| 773 | vendor_snapshot_dylib { |
| 774 | name: "librust_vendor_available", |
| 775 | version: "30", |
| 776 | target_arch: "arm64", |
| 777 | vendor: true, |
| 778 | arch: { |
| 779 | arm64: { |
| 780 | src: "librust_vendor_available.dylib.so", |
| 781 | }, |
| 782 | arm: { |
| 783 | src: "librust_vendor_available.dylib.so", |
| 784 | }, |
| 785 | }, |
| 786 | } |
| 787 | |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 788 | vendor_snapshot_object { |
| 789 | name: "crtend_android", |
| 790 | version: "30", |
| 791 | target_arch: "arm64", |
| 792 | vendor: true, |
| 793 | stl: "none", |
| 794 | crt: true, |
| 795 | arch: { |
| 796 | arm64: { |
| 797 | src: "crtend_so.o", |
| 798 | }, |
| 799 | arm: { |
| 800 | src: "crtend_so.o", |
| 801 | }, |
| 802 | }, |
| 803 | } |
| 804 | |
| 805 | vendor_snapshot_object { |
| 806 | name: "crtbegin_dynamic", |
| 807 | version: "30", |
| 808 | target_arch: "arm64", |
| 809 | vendor: true, |
| 810 | stl: "none", |
| 811 | crt: true, |
| 812 | arch: { |
| 813 | arm64: { |
| 814 | src: "crtbegin_so.o", |
| 815 | }, |
| 816 | arm: { |
| 817 | src: "crtbegin_so.o", |
| 818 | }, |
| 819 | }, |
| 820 | } |
| 821 | |
| 822 | vendor_snapshot_static { |
| 823 | name: "libvndk", |
| 824 | version: "30", |
| 825 | target_arch: "arm64", |
| 826 | compile_multilib: "both", |
| 827 | vendor: true, |
| 828 | arch: { |
| 829 | arm64: { |
| 830 | src: "libvndk.a", |
| 831 | }, |
| 832 | arm: { |
| 833 | src: "libvndk.a", |
| 834 | }, |
| 835 | }, |
| 836 | shared_libs: ["libvndk"], |
| 837 | export_shared_lib_headers: ["libvndk"], |
| 838 | } |
| 839 | |
| 840 | vendor_snapshot_static { |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 841 | name: "libclang_rt.builtins", |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 842 | version: "30", |
| 843 | target_arch: "arm64", |
| 844 | vendor: true, |
| 845 | arch: { |
| 846 | arm: { |
| 847 | src: "libclang_rt.builtins-arm-android.a", |
| 848 | }, |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 849 | arm64: { |
| 850 | src: "libclang_rt.builtins-aarch64-android.a", |
| 851 | }, |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 852 | }, |
| 853 | } |
| 854 | |
| 855 | vendor_snapshot_shared { |
| 856 | name: "lib32", |
| 857 | version: "30", |
| 858 | target_arch: "arm64", |
| 859 | compile_multilib: "32", |
| 860 | vendor: true, |
Kalesh Singh | f4ffe0a | 2024-01-29 13:01:51 -0800 | [diff] [blame] | 861 | no_crt_pad_segment: true, |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 862 | arch: { |
| 863 | arm: { |
| 864 | src: "lib32.so", |
| 865 | }, |
| 866 | }, |
| 867 | } |
| 868 | |
| 869 | vendor_snapshot_shared { |
| 870 | name: "lib64", |
| 871 | version: "30", |
| 872 | target_arch: "arm64", |
| 873 | compile_multilib: "64", |
| 874 | vendor: true, |
Kalesh Singh | f4ffe0a | 2024-01-29 13:01:51 -0800 | [diff] [blame] | 875 | no_crt_pad_segment: true, |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 876 | arch: { |
| 877 | arm64: { |
| 878 | src: "lib64.so", |
| 879 | }, |
| 880 | }, |
| 881 | } |
| 882 | vendor_snapshot_shared { |
| 883 | name: "liblog", |
| 884 | version: "30", |
| 885 | target_arch: "arm64", |
| 886 | compile_multilib: "64", |
| 887 | vendor: true, |
Kalesh Singh | f4ffe0a | 2024-01-29 13:01:51 -0800 | [diff] [blame] | 888 | no_crt_pad_segment: true, |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 889 | arch: { |
| 890 | arm64: { |
| 891 | src: "liblog.so", |
| 892 | }, |
| 893 | }, |
| 894 | } |
| 895 | |
| 896 | vendor_snapshot_static { |
| 897 | name: "libvendor", |
| 898 | version: "30", |
| 899 | target_arch: "arm64", |
| 900 | compile_multilib: "both", |
| 901 | vendor: true, |
| 902 | arch: { |
| 903 | arm64: { |
| 904 | src: "libvendor.a", |
| 905 | export_include_dirs: ["include/libvendor"], |
| 906 | }, |
| 907 | arm: { |
| 908 | src: "libvendor.a", |
| 909 | export_include_dirs: ["include/libvendor"], |
| 910 | }, |
| 911 | }, |
| 912 | } |
| 913 | |
| 914 | vendor_snapshot_shared { |
| 915 | name: "libvendor_available", |
| 916 | version: "30", |
| 917 | target_arch: "arm64", |
| 918 | compile_multilib: "both", |
| 919 | vendor: true, |
Kalesh Singh | f4ffe0a | 2024-01-29 13:01:51 -0800 | [diff] [blame] | 920 | no_crt_pad_segment: true, |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 921 | arch: { |
| 922 | arm64: { |
| 923 | src: "libvendor_available.so", |
| 924 | export_include_dirs: ["include/libvendor"], |
| 925 | }, |
| 926 | arm: { |
| 927 | src: "libvendor_available.so", |
| 928 | export_include_dirs: ["include/libvendor"], |
| 929 | }, |
| 930 | }, |
| 931 | } |
| 932 | |
| 933 | vendor_snapshot_binary { |
| 934 | name: "bin", |
| 935 | version: "30", |
| 936 | target_arch: "arm64", |
| 937 | compile_multilib: "64", |
| 938 | vendor: true, |
| 939 | arch: { |
| 940 | arm64: { |
| 941 | src: "bin", |
| 942 | }, |
| 943 | }, |
| 944 | } |
| 945 | |
| 946 | vendor_snapshot_binary { |
| 947 | name: "bin32", |
| 948 | version: "30", |
| 949 | target_arch: "arm64", |
| 950 | compile_multilib: "32", |
| 951 | vendor: true, |
| 952 | arch: { |
| 953 | arm: { |
| 954 | src: "bin32", |
| 955 | }, |
| 956 | }, |
| 957 | } |
| 958 | |
Ivan Lozano | 62cd038 | 2021-11-01 10:27:54 -0400 | [diff] [blame] | 959 | // Test sanitizers use the snapshot libraries |
| 960 | rust_binary { |
| 961 | name: "memtag_binary", |
| 962 | srcs: ["vendor/bin.rs"], |
| 963 | vendor: true, |
| 964 | compile_multilib: "64", |
| 965 | sanitize: { |
| 966 | memtag_heap: true, |
| 967 | diag: { |
| 968 | memtag_heap: true, |
| 969 | } |
| 970 | }, |
| 971 | } |
| 972 | |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 973 | // old snapshot module which has to be ignored |
| 974 | vendor_snapshot_binary { |
| 975 | name: "bin", |
| 976 | version: "26", |
| 977 | target_arch: "arm64", |
| 978 | compile_multilib: "first", |
| 979 | vendor: true, |
| 980 | arch: { |
| 981 | arm64: { |
| 982 | src: "bin", |
| 983 | }, |
| 984 | }, |
| 985 | } |
| 986 | |
| 987 | // different arch snapshot which has to be ignored |
| 988 | vendor_snapshot_binary { |
| 989 | name: "bin", |
| 990 | version: "30", |
| 991 | target_arch: "arm", |
| 992 | compile_multilib: "first", |
| 993 | vendor: true, |
| 994 | arch: { |
| 995 | arm64: { |
| 996 | src: "bin", |
| 997 | }, |
| 998 | }, |
| 999 | } |
Ivan Lozano | 62cd038 | 2021-11-01 10:27:54 -0400 | [diff] [blame] | 1000 | |
| 1001 | vendor_snapshot_static { |
| 1002 | name: "note_memtag_heap_sync", |
| 1003 | vendor: true, |
| 1004 | target_arch: "arm64", |
| 1005 | version: "30", |
| 1006 | arch: { |
| 1007 | arm64: { |
| 1008 | src: "note_memtag_heap_sync.a", |
| 1009 | }, |
| 1010 | }, |
| 1011 | } |
| 1012 | |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1013 | ` |
| 1014 | |
| 1015 | mockFS := android.MockFS{ |
| 1016 | "framework/Android.bp": []byte(frameworkBp), |
| 1017 | "framework/bin.rs": nil, |
Ivan Lozano | 62cd038 | 2021-11-01 10:27:54 -0400 | [diff] [blame] | 1018 | "note_memtag_heap_sync.a": nil, |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1019 | "vendor/Android.bp": []byte(vendorProprietaryBp), |
| 1020 | "vendor/bin": nil, |
| 1021 | "vendor/bin32": nil, |
| 1022 | "vendor/bin.rs": nil, |
| 1023 | "vendor/client.rs": nil, |
| 1024 | "vendor/include/libvndk/a.h": nil, |
| 1025 | "vendor/include/libvendor/b.h": nil, |
| 1026 | "vendor/libvndk.a": nil, |
| 1027 | "vendor/libvendor.a": nil, |
| 1028 | "vendor/libvendor.so": nil, |
| 1029 | "vendor/lib32.so": nil, |
| 1030 | "vendor/lib64.so": nil, |
| 1031 | "vendor/liblog.so": nil, |
| 1032 | "vendor/libstd.rlib": nil, |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1033 | "vendor/librust_vendor_available.rlib": nil, |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1034 | "vendor/librust_vendor_available.rlib-std.rlib": nil, |
| 1035 | "vendor/libstd.dylib.so": nil, |
| 1036 | "vendor/librust_vendor_available.dylib.so": nil, |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1037 | "vendor/crtbegin_so.o": nil, |
| 1038 | "vendor/crtend_so.o": nil, |
| 1039 | "vendor/libclang_rt.builtins-aarch64-android.a": nil, |
| 1040 | "vendor/libclang_rt.builtins-arm-android.a": nil, |
| 1041 | "vndk/Android.bp": []byte(vndkBp), |
| 1042 | "vndk/include/libvndk/a.h": nil, |
| 1043 | "vndk/libvndk.so": nil, |
| 1044 | } |
| 1045 | |
| 1046 | sharedVariant := "android_vendor.30_arm64_armv8-a_shared" |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1047 | rlibVariant := "android_vendor.30_arm64_armv8-a_rlib_dylib-std" |
| 1048 | rlibRlibStdVariant := "android_vendor.30_arm64_armv8-a_rlib_rlib-std" |
| 1049 | dylibVariant := "android_vendor.30_arm64_armv8-a_dylib" |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1050 | staticVariant := "android_vendor.30_arm64_armv8-a_static" |
| 1051 | binaryVariant := "android_vendor.30_arm64_armv8-a" |
| 1052 | |
| 1053 | shared32Variant := "android_vendor.30_arm_armv7-a-neon_shared" |
| 1054 | binary32Variant := "android_vendor.30_arm_armv7-a-neon" |
| 1055 | |
| 1056 | ctx := testRustVndkFsVersions(t, "", mockFS, "30", "current", "31") |
| 1057 | |
| 1058 | // libclient uses libvndk.vndk.30.arm64, libvendor.vendor_static.30.arm64, libvendor_without_snapshot |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 1059 | libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("rustc").Args["linkFlags"] |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1060 | for _, input := range [][]string{ |
| 1061 | []string{sharedVariant, "libvndk.vndk.30.arm64"}, |
| 1062 | []string{staticVariant, "libvendor.vendor_static.30.arm64"}, |
| 1063 | []string{staticVariant, "libvendor_without_snapshot"}, |
| 1064 | } { |
| 1065 | outputPaths := cc.GetOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */) |
| 1066 | if !strings.Contains(libclientLdFlags, outputPaths[0].String()) { |
| 1067 | t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags) |
| 1068 | } |
| 1069 | } |
| 1070 | |
Cole Faust | b6e6f99 | 2023-08-17 17:42:26 -0700 | [diff] [blame] | 1071 | libclientAndroidMkSharedLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).transitiveAndroidMkSharedLibs.ToList() |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1072 | if g, w := libclientAndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "lib64", "liblog.vendor", "libc.vendor", "libm.vendor", "libdl.vendor"}; !reflect.DeepEqual(g, w) { |
| 1073 | t.Errorf("wanted libclient AndroidMkSharedLibs %q, got %q", w, g) |
| 1074 | } |
| 1075 | |
| 1076 | libclientAndroidMkStaticLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkStaticLibs |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 1077 | if g, w := libclientAndroidMkStaticLibs, []string{"libvendor", "libvendor_without_snapshot", "libclang_rt.builtins.vendor"}; !reflect.DeepEqual(g, w) { |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1078 | t.Errorf("wanted libclient AndroidMkStaticLibs %q, got %q", w, g) |
| 1079 | } |
| 1080 | |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1081 | libclientAndroidMkDylibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkDylibs |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1082 | if g, w := libclientAndroidMkDylibs, []string{"librust_vendor_available.vendor", "libstd.vendor"}; !reflect.DeepEqual(g, w) { |
| 1083 | t.Errorf("wanted libclient libclientAndroidMkDylibs %q, got %q", w, libclientAndroidMkDylibs) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1084 | } |
| 1085 | |
Cole Faust | b6e6f99 | 2023-08-17 17:42:26 -0700 | [diff] [blame] | 1086 | libclient32AndroidMkSharedLibs := ctx.ModuleForTests("libclient", shared32Variant).Module().(*Module).transitiveAndroidMkSharedLibs.ToList() |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1087 | if g, w := libclient32AndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "lib32", "liblog.vendor", "libc.vendor", "libm.vendor", "libdl.vendor"}; !reflect.DeepEqual(g, w) { |
| 1088 | t.Errorf("wanted libclient32 AndroidMkSharedLibs %q, got %q", w, g) |
| 1089 | } |
| 1090 | |
| 1091 | libclientRustAndroidMkRlibs := ctx.ModuleForTests("libclient_rust", rlibVariant).Module().(*Module).Properties.AndroidMkRlibs |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1092 | if g, w := libclientRustAndroidMkRlibs, []string{"librust_vendor_available.vendor"}; !reflect.DeepEqual(g, w) { |
| 1093 | t.Errorf("wanted rlib libclient libclientAndroidMkRlibs %q, got %q", w, g) |
| 1094 | } |
| 1095 | |
| 1096 | libclientRlibStdRustAndroidMkRlibs := ctx.ModuleForTests("libclient_rust", rlibRlibStdVariant).Module().(*Module).Properties.AndroidMkRlibs |
| 1097 | if g, w := libclientRlibStdRustAndroidMkRlibs, []string{"librust_vendor_available.vendor.rlib-std", "libstd.vendor"}; !reflect.DeepEqual(g, w) { |
| 1098 | t.Errorf("wanted rlib libclient libclientAndroidMkRlibs %q, got %q", w, g) |
| 1099 | } |
| 1100 | |
| 1101 | libclientRustDylibAndroidMkDylibs := ctx.ModuleForTests("libclient_rust", dylibVariant).Module().(*Module).Properties.AndroidMkDylibs |
| 1102 | if g, w := libclientRustDylibAndroidMkDylibs, []string{"librust_vendor_available.vendor", "libstd.vendor"}; !reflect.DeepEqual(g, w) { |
| 1103 | t.Errorf("wanted dylib libclient libclientRustDylibAndroidMkDylibs %q, got %q", w, g) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1104 | } |
| 1105 | |
Justin Yun | 24b246a | 2023-03-16 10:36:16 +0900 | [diff] [blame] | 1106 | // rust vendor snapshot must have ".vendor" suffix in AndroidMk |
| 1107 | librustVendorAvailableSnapshotModule := ctx.ModuleForTests("librust_vendor_available.vendor_rlib.30.arm64", rlibVariant).Module() |
| 1108 | librustVendorSnapshotMkName := android.AndroidMkEntriesForTest(t, ctx, librustVendorAvailableSnapshotModule)[0].EntryMap["LOCAL_MODULE"][0] |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1109 | expectedRustVendorSnapshotName := "librust_vendor_available.vendor" |
Justin Yun | 24b246a | 2023-03-16 10:36:16 +0900 | [diff] [blame] | 1110 | if librustVendorSnapshotMkName != expectedRustVendorSnapshotName { |
| 1111 | t.Errorf("Unexpected rust vendor snapshot name in AndroidMk: %q, expected: %q\n", librustVendorSnapshotMkName, expectedRustVendorSnapshotName) |
| 1112 | } |
| 1113 | |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1114 | librustVendorAvailableDylibSnapshotModule := ctx.ModuleForTests("librust_vendor_available.vendor_dylib.30.arm64", dylibVariant).Module() |
| 1115 | librustVendorSnapshotDylibMkName := android.AndroidMkEntriesForTest(t, ctx, librustVendorAvailableDylibSnapshotModule)[0].EntryMap["LOCAL_MODULE"][0] |
| 1116 | expectedRustVendorDylibSnapshotName := "librust_vendor_available.vendor" |
| 1117 | if librustVendorSnapshotDylibMkName != expectedRustVendorDylibSnapshotName { |
| 1118 | t.Errorf("Unexpected rust vendor snapshot name in AndroidMk: %q, expected: %q\n", librustVendorSnapshotDylibMkName, expectedRustVendorDylibSnapshotName) |
| 1119 | } |
| 1120 | |
Justin Yun | 24b246a | 2023-03-16 10:36:16 +0900 | [diff] [blame] | 1121 | rustVendorBinModule := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Module() |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1122 | rustVendorBinMkDylibName := android.AndroidMkEntriesForTest(t, ctx, rustVendorBinModule)[0].EntryMap["LOCAL_DYLIB_LIBRARIES"][0] |
| 1123 | if rustVendorBinMkDylibName != expectedRustVendorSnapshotName { |
| 1124 | t.Errorf("Unexpected rust rlib name in AndroidMk: %q, expected: %q\n", rustVendorBinMkDylibName, expectedRustVendorSnapshotName) |
Justin Yun | 24b246a | 2023-03-16 10:36:16 +0900 | [diff] [blame] | 1125 | } |
| 1126 | |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 1127 | binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("rustc").Args["linkFlags"] |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1128 | libVndkStaticOutputPaths := cc.GetOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.30.arm64"}) |
| 1129 | if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) { |
| 1130 | t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v", |
| 1131 | libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags) |
| 1132 | } |
| 1133 | |
| 1134 | // bin is installed by bin.vendor_binary.30.arm64 |
| 1135 | ctx.ModuleForTests("bin.vendor_binary.30.arm64", binaryVariant).Output("bin") |
| 1136 | |
| 1137 | // bin32 is installed by bin32.vendor_binary.30.arm64 |
| 1138 | ctx.ModuleForTests("bin32.vendor_binary.30.arm64", binary32Variant).Output("bin32") |
| 1139 | |
| 1140 | // bin_without_snapshot is installed by bin_without_snapshot |
| 1141 | ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot") |
| 1142 | |
| 1143 | // libvendor, libvendor_available and bin don't have vendor.30 variant |
| 1144 | libvendorVariants := ctx.ModuleVariantsForTests("libvendor") |
| 1145 | if android.InList(sharedVariant, libvendorVariants) { |
| 1146 | t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant) |
| 1147 | } |
| 1148 | |
| 1149 | libvendorAvailableVariants := ctx.ModuleVariantsForTests("libvendor_available") |
| 1150 | if android.InList(sharedVariant, libvendorAvailableVariants) { |
| 1151 | t.Errorf("libvendor_available must not have variant %#v, but it does", sharedVariant) |
| 1152 | } |
| 1153 | |
| 1154 | binVariants := ctx.ModuleVariantsForTests("bin") |
| 1155 | if android.InList(binaryVariant, binVariants) { |
| 1156 | t.Errorf("bin must not have variant %#v, but it does", sharedVariant) |
| 1157 | } |
Ivan Lozano | 62cd038 | 2021-11-01 10:27:54 -0400 | [diff] [blame] | 1158 | |
| 1159 | memtagStaticLibs := ctx.ModuleForTests("memtag_binary", "android_vendor.30_arm64_armv8-a").Module().(*Module).Properties.AndroidMkStaticLibs |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 1160 | if g, w := memtagStaticLibs, []string{"libclang_rt.builtins.vendor", "note_memtag_heap_sync.vendor"}; !reflect.DeepEqual(g, w) { |
Ivan Lozano | 62cd038 | 2021-11-01 10:27:54 -0400 | [diff] [blame] | 1161 | t.Errorf("wanted memtag_binary AndroidMkStaticLibs %q, got %q", w, g) |
| 1162 | } |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1163 | } |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1164 | |
| 1165 | func TestRecoverySnapshotCapture(t *testing.T) { |
| 1166 | bp := ` |
| 1167 | rust_ffi { |
| 1168 | name: "librecovery", |
| 1169 | recovery: true, |
| 1170 | srcs: ["foo.rs"], |
| 1171 | crate_name: "recovery", |
| 1172 | } |
| 1173 | |
| 1174 | rust_ffi { |
| 1175 | name: "librecovery_available", |
| 1176 | recovery_available: true, |
| 1177 | srcs: ["foo.rs"], |
| 1178 | crate_name: "recovery_available", |
| 1179 | } |
| 1180 | |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1181 | rust_library { |
| 1182 | name: "librecovery_rustlib", |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1183 | recovery: true, |
| 1184 | srcs: ["foo.rs"], |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1185 | crate_name: "recovery_rustlib", |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1186 | } |
| 1187 | |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1188 | rust_library { |
| 1189 | name: "librecovery_available_rustlib", |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1190 | recovery_available: true, |
| 1191 | srcs: ["foo.rs"], |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1192 | crate_name: "recovery_available_rustlib", |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | rust_binary { |
| 1196 | name: "recovery_bin", |
| 1197 | recovery: true, |
| 1198 | srcs: ["foo.rs"], |
| 1199 | } |
| 1200 | |
| 1201 | rust_binary { |
| 1202 | name: "recovery_available_bin", |
| 1203 | recovery_available: true, |
| 1204 | srcs: ["foo.rs"], |
| 1205 | } |
| 1206 | |
| 1207 | ` |
| 1208 | // Check Recovery snapshot output. |
| 1209 | |
| 1210 | ctx := testRustRecoveryFsVersions(t, bp, rustMockedFiles, "", "29", "current") |
| 1211 | snapshotDir := "recovery-snapshot" |
| 1212 | snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64") |
| 1213 | snapshotSingleton := ctx.SingletonForTests("recovery-snapshot") |
| 1214 | |
| 1215 | var jsonFiles []string |
| 1216 | |
| 1217 | for _, arch := range [][]string{ |
| 1218 | []string{"arm64", "armv8-a"}, |
| 1219 | } { |
| 1220 | archType := arch[0] |
| 1221 | archVariant := arch[1] |
| 1222 | archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) |
| 1223 | |
| 1224 | // For shared libraries, all recovery:true and recovery_available modules are captured. |
| 1225 | sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant) |
| 1226 | sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") |
| 1227 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant) |
| 1228 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant) |
| 1229 | jsonFiles = append(jsonFiles, |
| 1230 | filepath.Join(sharedDir, "librecovery.so.json"), |
| 1231 | filepath.Join(sharedDir, "librecovery_available.so.json")) |
| 1232 | |
| 1233 | // For static libraries, all recovery:true and recovery_available modules are captured. |
| 1234 | staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant) |
| 1235 | staticDir := filepath.Join(snapshotVariantPath, archDir, "static") |
| 1236 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant) |
| 1237 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant) |
| 1238 | jsonFiles = append(jsonFiles, |
| 1239 | filepath.Join(staticDir, "librecovery.a.json"), |
| 1240 | filepath.Join(staticDir, "librecovery_available.a.json")) |
| 1241 | |
| 1242 | // For rlib libraries, all recovery:true and recovery_available modules are captured. |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1243 | rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_dylib-std", archType, archVariant) |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1244 | rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib") |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1245 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib", rlibDir, rlibVariant) |
| 1246 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.rlib", rlibDir, rlibVariant) |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1247 | jsonFiles = append(jsonFiles, |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1248 | filepath.Join(rlibDir, "librecovery_rustlib.rlib.json"), |
| 1249 | filepath.Join(rlibDir, "librecovery_available_rustlib.rlib.json")) |
| 1250 | |
| 1251 | rlibRlibStdVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant) |
| 1252 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant) |
| 1253 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant) |
| 1254 | jsonFiles = append(jsonFiles, |
| 1255 | filepath.Join(rlibDir, "librecovery_rustlib.rlib-std.rlib.json"), |
| 1256 | filepath.Join(rlibDir, "librecovery_available_rustlib.rlib-std.rlib.json")) |
| 1257 | |
| 1258 | // For dylib libraries, all recovery:true and recovery_available modules are captured. |
| 1259 | dylibVariant := fmt.Sprintf("android_recovery_%s_%s_dylib", archType, archVariant) |
| 1260 | dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib") |
| 1261 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.dylib.so", dylibDir, dylibVariant) |
| 1262 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.dylib.so", dylibDir, dylibVariant) |
| 1263 | jsonFiles = append(jsonFiles, |
| 1264 | filepath.Join(dylibDir, "librecovery_rustlib.dylib.so.json"), |
| 1265 | filepath.Join(dylibDir, "librecovery_available_rustlib.dylib.so.json")) |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1266 | |
| 1267 | // For binary executables, all recovery:true and recovery_available modules are captured. |
| 1268 | if archType == "arm64" { |
| 1269 | binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant) |
| 1270 | binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary") |
| 1271 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant) |
| 1272 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant) |
| 1273 | jsonFiles = append(jsonFiles, |
| 1274 | filepath.Join(binaryDir, "recovery_bin.json"), |
| 1275 | filepath.Join(binaryDir, "recovery_available_bin.json")) |
| 1276 | } |
| 1277 | } |
| 1278 | |
| 1279 | for _, jsonFile := range jsonFiles { |
| 1280 | // verify all json files exist |
| 1281 | if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { |
| 1282 | t.Errorf("%q expected but not found", jsonFile) |
| 1283 | } |
| 1284 | } |
| 1285 | } |
| 1286 | |
| 1287 | func TestRecoverySnapshotExclude(t *testing.T) { |
| 1288 | // This test verifies that the exclude_from_recovery_snapshot property |
| 1289 | // makes its way from the Android.bp source file into the module data |
| 1290 | // structure. It also verifies that modules are correctly included or |
| 1291 | // excluded in the recovery snapshot based on their path (framework or |
| 1292 | // vendor) and the exclude_from_recovery_snapshot property. |
| 1293 | |
| 1294 | frameworkBp := ` |
| 1295 | rust_ffi_shared { |
| 1296 | name: "libinclude", |
| 1297 | srcs: ["src/include.rs"], |
| 1298 | recovery_available: true, |
| 1299 | crate_name: "include", |
| 1300 | } |
| 1301 | rust_ffi_shared { |
| 1302 | name: "libexclude", |
| 1303 | srcs: ["src/exclude.rs"], |
| 1304 | recovery: true, |
| 1305 | exclude_from_recovery_snapshot: true, |
| 1306 | crate_name: "exclude", |
| 1307 | } |
| 1308 | rust_ffi_shared { |
| 1309 | name: "libavailable_exclude", |
| 1310 | srcs: ["src/exclude.rs"], |
| 1311 | recovery_available: true, |
| 1312 | exclude_from_recovery_snapshot: true, |
| 1313 | crate_name: "available_exclude", |
| 1314 | } |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1315 | rust_library { |
| 1316 | name: "libinclude_rustlib", |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1317 | srcs: ["src/include.rs"], |
| 1318 | recovery_available: true, |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1319 | crate_name: "include_rustlib", |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1320 | } |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1321 | rust_library { |
| 1322 | name: "libexclude_rustlib", |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1323 | srcs: ["src/exclude.rs"], |
| 1324 | recovery: true, |
| 1325 | exclude_from_recovery_snapshot: true, |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1326 | crate_name: "exclude_rustlib", |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1327 | } |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1328 | rust_library { |
| 1329 | name: "libavailable_exclude_rustlib", |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1330 | srcs: ["src/exclude.rs"], |
| 1331 | recovery_available: true, |
| 1332 | exclude_from_recovery_snapshot: true, |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1333 | crate_name: "available_exclude_rustlib", |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1334 | } |
| 1335 | ` |
| 1336 | |
| 1337 | vendorProprietaryBp := ` |
| 1338 | rust_ffi_shared { |
| 1339 | name: "librecovery", |
| 1340 | srcs: ["recovery.rs"], |
| 1341 | recovery: true, |
| 1342 | crate_name: "recovery", |
| 1343 | } |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1344 | rust_library { |
| 1345 | name: "librecovery_rustlib", |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1346 | srcs: ["recovery.rs"], |
| 1347 | recovery: true, |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1348 | crate_name: "recovery_rustlib", |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1349 | } |
| 1350 | ` |
| 1351 | |
| 1352 | mockFS := map[string][]byte{ |
| 1353 | "framework/Android.bp": []byte(frameworkBp), |
| 1354 | "framework/include.rs": nil, |
| 1355 | "framework/exclude.rs": nil, |
| 1356 | "device/Android.bp": []byte(vendorProprietaryBp), |
| 1357 | "device/recovery.rs": nil, |
| 1358 | } |
| 1359 | |
| 1360 | ctx := testRustRecoveryFsVersions(t, "", mockFS, "", "29", "current") |
| 1361 | |
| 1362 | // Test an include and exclude framework module. |
| 1363 | cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false, sharedRecoveryVariant) |
| 1364 | cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true, sharedRecoveryVariant) |
| 1365 | cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true, sharedRecoveryVariant) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1366 | |
| 1367 | cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude_rustlib", false, rlibRecoveryVariant) |
| 1368 | cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude_rustlib", true, rlibRecoveryVariant) |
| 1369 | cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude_rustlib", true, rlibRlibStdRecoveryVariant) |
| 1370 | |
| 1371 | cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude_rustlib", false, rlibRlibStdRecoveryVariant) |
| 1372 | cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude_rustlib", true, rlibRlibStdRecoveryVariant) |
| 1373 | cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude_rustlib", true, rlibRlibStdRecoveryVariant) |
| 1374 | |
| 1375 | cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude_rustlib", false, dylibRecoveryVariant) |
| 1376 | cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude_rustlib", true, dylibRecoveryVariant) |
| 1377 | cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude_rustlib", true, dylibRecoveryVariant) |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1378 | |
| 1379 | // A recovery module is excluded, but by its path not the exclude_from_recovery_snapshot property |
| 1380 | // ('device/' and 'vendor/' are default excluded). See snapshot/recovery_snapshot.go for more detail. |
| 1381 | cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false, sharedRecoveryVariant) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1382 | cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery_rustlib", false, rlibRecoveryVariant) |
| 1383 | cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery_rustlib", false, rlibRlibStdRecoveryVariant) |
| 1384 | cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery_rustlib", false, dylibRecoveryVariant) |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1385 | |
| 1386 | // Verify the content of the recovery snapshot. |
| 1387 | |
| 1388 | snapshotDir := "recovery-snapshot" |
| 1389 | snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64") |
| 1390 | snapshotSingleton := ctx.SingletonForTests("recovery-snapshot") |
| 1391 | |
| 1392 | var includeJsonFiles []string |
| 1393 | var excludeJsonFiles []string |
| 1394 | |
| 1395 | for _, arch := range [][]string{ |
| 1396 | []string{"arm64", "armv8-a"}, |
| 1397 | } { |
| 1398 | archType := arch[0] |
| 1399 | archVariant := arch[1] |
| 1400 | archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) |
| 1401 | |
| 1402 | sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1403 | rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_dylib-std", archType, archVariant) |
| 1404 | rlibRlibStdVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant) |
| 1405 | dylibVariant := fmt.Sprintf("android_recovery_%s_%s_dylib", archType, archVariant) |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1406 | sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") |
| 1407 | rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib") |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1408 | dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib") |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1409 | |
| 1410 | // Included modules |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1411 | |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1412 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant) |
| 1413 | includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json")) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1414 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude_rustlib", "libinclude_rustlib.rlib", rlibDir, rlibVariant) |
| 1415 | includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "libinclude_rustlib.rlib.json")) |
| 1416 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude_rustlib", "libinclude_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant) |
| 1417 | includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "libinclude_rustlib.rlib-std.rlib.json")) |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1418 | |
| 1419 | // Excluded modules |
| 1420 | cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant) |
| 1421 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json")) |
| 1422 | cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant) |
| 1423 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json")) |
| 1424 | cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant) |
| 1425 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json")) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1426 | |
| 1427 | cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude_rustlib", "libexclude_rustlib.rlib", rlibDir, rlibVariant) |
| 1428 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libexclude_rustlib.rlib.json")) |
| 1429 | cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib", rlibDir, rlibVariant) |
| 1430 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.rlib.json")) |
| 1431 | cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude_rustlib", "libavailable_exclude_rustlib.rlib", rlibDir, rlibVariant) |
| 1432 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libavailable_exclude_rustlib.rlib.json")) |
| 1433 | |
| 1434 | cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude_rustlib", "libexclude_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant) |
| 1435 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libexclude_rustlib.rlib-std.rlib.json")) |
| 1436 | cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant) |
| 1437 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.rlib-std.rlib.json")) |
| 1438 | cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude_rustlib", "libavailable_exclude_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant) |
| 1439 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libavailable_exclude_rustlib.rlib-std.rlib.json")) |
| 1440 | |
| 1441 | cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude_rustlib", "libexclude_rustlib.dylib.so", dylibDir, dylibVariant) |
| 1442 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libexclude_rustlib.dylib.so.json")) |
| 1443 | cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.dylib.so", dylibDir, dylibVariant) |
| 1444 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.dylib.so.json")) |
| 1445 | cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude_rustlib", "libavailable_exclude_rustlib.dylib.so", dylibDir, dylibVariant) |
| 1446 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libavailable_exclude_rustlib.dylib.so.json")) |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1447 | } |
| 1448 | |
| 1449 | // Verify that each json file for an included module has a rule. |
| 1450 | for _, jsonFile := range includeJsonFiles { |
| 1451 | if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { |
| 1452 | t.Errorf("include json file %q not found", jsonFile) |
| 1453 | } |
| 1454 | } |
| 1455 | |
| 1456 | // Verify that each json file for an excluded module has no rule. |
| 1457 | for _, jsonFile := range excludeJsonFiles { |
| 1458 | if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil { |
| 1459 | t.Errorf("exclude json file %q found", jsonFile) |
| 1460 | } |
| 1461 | } |
| 1462 | } |
| 1463 | |
| 1464 | func TestRecoverySnapshotDirected(t *testing.T) { |
| 1465 | bp := ` |
| 1466 | rust_ffi_shared { |
| 1467 | name: "librecovery", |
| 1468 | recovery: true, |
| 1469 | crate_name: "recovery", |
| 1470 | srcs: ["foo.rs"], |
| 1471 | } |
| 1472 | |
| 1473 | rust_ffi_shared { |
| 1474 | name: "librecovery_available", |
| 1475 | recovery_available: true, |
| 1476 | crate_name: "recovery_available", |
| 1477 | srcs: ["foo.rs"], |
| 1478 | } |
| 1479 | |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1480 | rust_library { |
| 1481 | name: "librecovery_rustlib", |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1482 | recovery: true, |
| 1483 | crate_name: "recovery", |
| 1484 | srcs: ["foo.rs"], |
| 1485 | } |
| 1486 | |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1487 | rust_library { |
| 1488 | name: "librecovery_available_rustlib", |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1489 | recovery_available: true, |
| 1490 | crate_name: "recovery_available", |
| 1491 | srcs: ["foo.rs"], |
| 1492 | } |
| 1493 | |
| 1494 | /* TODO: Uncomment when Rust supports the "prefer" property for prebuilts |
| 1495 | rust_library_rlib { |
| 1496 | name: "libfoo_rlib", |
| 1497 | recovery: true, |
| 1498 | crate_name: "foo", |
| 1499 | } |
| 1500 | |
| 1501 | rust_prebuilt_rlib { |
| 1502 | name: "libfoo_rlib", |
| 1503 | recovery: true, |
| 1504 | prefer: true, |
| 1505 | srcs: ["libfoo.rlib"], |
| 1506 | crate_name: "foo", |
| 1507 | } |
| 1508 | */ |
| 1509 | ` |
| 1510 | ctx := testRustRecoveryFsVersions(t, bp, rustMockedFiles, "current", "29", "current") |
| 1511 | ctx.Config().TestProductVariables.RecoverySnapshotModules = make(map[string]bool) |
| 1512 | ctx.Config().TestProductVariables.RecoverySnapshotModules["librecovery"] = true |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1513 | ctx.Config().TestProductVariables.RecoverySnapshotModules["librecovery_rustlib"] = true |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1514 | ctx.Config().TestProductVariables.DirectedRecoverySnapshot = true |
| 1515 | |
| 1516 | // Check recovery snapshot output. |
| 1517 | snapshotDir := "recovery-snapshot" |
| 1518 | snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64") |
| 1519 | snapshotSingleton := ctx.SingletonForTests("recovery-snapshot") |
| 1520 | |
| 1521 | var includeJsonFiles []string |
| 1522 | |
| 1523 | for _, arch := range [][]string{ |
| 1524 | []string{"arm64", "armv8-a"}, |
| 1525 | } { |
| 1526 | archType := arch[0] |
| 1527 | archVariant := arch[1] |
| 1528 | archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) |
| 1529 | |
| 1530 | sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1531 | rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_dylib-std", archType, archVariant) |
| 1532 | rlibRlibStdVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant) |
| 1533 | dylibVariant := fmt.Sprintf("android_recovery_%s_%s_dylib", archType, archVariant) |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1534 | sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") |
| 1535 | rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib") |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1536 | dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib") |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1537 | |
| 1538 | // Included modules |
| 1539 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant) |
| 1540 | includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json")) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1541 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib", rlibDir, rlibVariant) |
| 1542 | includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.rlib.json")) |
| 1543 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant) |
| 1544 | includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.rlib-std.rlib.json")) |
| 1545 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.dylib.so", dylibDir, dylibVariant) |
| 1546 | includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librecovery_rustlib.dylib.so.json")) |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1547 | |
| 1548 | // TODO: When Rust supports the "prefer" property for prebuilts, perform this check. |
| 1549 | /* |
| 1550 | // Check that snapshot captures "prefer: true" prebuilt |
| 1551 | cc.CheckSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo_rlib", "libfoo_rlib.rlib", rlibDir, rlibVariant) |
| 1552 | includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo_rlib.rlib.json")) |
| 1553 | */ |
| 1554 | |
| 1555 | // Excluded modules. Modules not included in the directed recovery snapshot |
| 1556 | // are still included as fake modules. |
| 1557 | cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant) |
| 1558 | includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json")) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1559 | cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.rlib", rlibDir, rlibVariant) |
| 1560 | includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_available_rustlib.rlib.json")) |
| 1561 | cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant) |
| 1562 | includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_available_rustlib.rlib-std.rlib.json")) |
| 1563 | cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.dylib.so", dylibDir, dylibVariant) |
| 1564 | includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librecovery_available_rustlib.dylib.so.json")) |
Ivan Lozano | c2ca1ee | 2021-11-09 16:23:40 -0500 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | // Verify that each json file for an included module has a rule. |
| 1568 | for _, jsonFile := range includeJsonFiles { |
| 1569 | if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { |
| 1570 | t.Errorf("include json file %q not found, %#v", jsonFile, includeJsonFiles) |
| 1571 | } |
| 1572 | } |
| 1573 | } |