Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 1 | // Copyright 2021 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "fmt" |
| 20 | "path/filepath" |
Colin Cross | 2e577f3 | 2021-01-22 13:06:25 -0800 | [diff] [blame] | 21 | "reflect" |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 22 | "strings" |
| 23 | "testing" |
| 24 | ) |
| 25 | |
| 26 | func TestVendorSnapshotCapture(t *testing.T) { |
| 27 | bp := ` |
| 28 | cc_library { |
| 29 | name: "libvndk", |
| 30 | vendor_available: true, |
| 31 | product_available: true, |
| 32 | vndk: { |
| 33 | enabled: true, |
| 34 | }, |
| 35 | nocrt: true, |
| 36 | } |
| 37 | |
| 38 | cc_library { |
| 39 | name: "libvendor", |
| 40 | vendor: true, |
| 41 | nocrt: true, |
| 42 | } |
| 43 | |
| 44 | cc_library { |
| 45 | name: "libvendor_available", |
| 46 | vendor_available: true, |
| 47 | nocrt: true, |
| 48 | } |
| 49 | |
| 50 | cc_library_headers { |
| 51 | name: "libvendor_headers", |
| 52 | vendor_available: true, |
| 53 | nocrt: true, |
| 54 | } |
| 55 | |
| 56 | cc_binary { |
| 57 | name: "vendor_bin", |
| 58 | vendor: true, |
| 59 | nocrt: true, |
| 60 | } |
| 61 | |
| 62 | cc_binary { |
| 63 | name: "vendor_available_bin", |
| 64 | vendor_available: true, |
| 65 | nocrt: true, |
| 66 | } |
| 67 | |
| 68 | toolchain_library { |
| 69 | name: "libb", |
| 70 | vendor_available: true, |
| 71 | src: "libb.a", |
| 72 | } |
| 73 | |
| 74 | cc_object { |
| 75 | name: "obj", |
| 76 | vendor_available: true, |
| 77 | } |
| 78 | |
| 79 | cc_library { |
| 80 | name: "libllndk", |
| 81 | llndk_stubs: "libllndk.llndk", |
| 82 | } |
| 83 | |
| 84 | llndk_library { |
| 85 | name: "libllndk.llndk", |
| 86 | symbol_file: "", |
| 87 | } |
| 88 | ` |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 89 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 90 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 91 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 92 | ctx := testCcWithConfig(t, config) |
| 93 | |
| 94 | // Check Vendor snapshot output. |
| 95 | |
| 96 | snapshotDir := "vendor-snapshot" |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 97 | snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64") |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 98 | snapshotSingleton := ctx.SingletonForTests("vendor-snapshot") |
| 99 | |
| 100 | var jsonFiles []string |
| 101 | |
| 102 | for _, arch := range [][]string{ |
| 103 | []string{"arm64", "armv8-a"}, |
| 104 | []string{"arm", "armv7-a-neon"}, |
| 105 | } { |
| 106 | archType := arch[0] |
| 107 | archVariant := arch[1] |
| 108 | archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) |
| 109 | |
| 110 | // For shared libraries, only non-VNDK vendor_available modules are captured |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 111 | sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant) |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 112 | sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") |
| 113 | checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant) |
| 114 | checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant) |
| 115 | jsonFiles = append(jsonFiles, |
| 116 | filepath.Join(sharedDir, "libvendor.so.json"), |
| 117 | filepath.Join(sharedDir, "libvendor_available.so.json")) |
| 118 | |
| 119 | // LLNDK modules are not captured |
| 120 | checkSnapshotExclude(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", sharedDir, sharedVariant) |
| 121 | |
| 122 | // For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured. |
| 123 | // Also cfi variants are captured, except for prebuilts like toolchain_library |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 124 | staticVariant := fmt.Sprintf("android_vendor.29_%s_%s_static", archType, archVariant) |
| 125 | staticCfiVariant := fmt.Sprintf("android_vendor.29_%s_%s_static_cfi", archType, archVariant) |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 126 | staticDir := filepath.Join(snapshotVariantPath, archDir, "static") |
| 127 | checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant) |
| 128 | checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.a", staticDir, staticVariant) |
| 129 | checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.cfi.a", staticDir, staticCfiVariant) |
| 130 | checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.a", staticDir, staticVariant) |
| 131 | checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.cfi.a", staticDir, staticCfiVariant) |
| 132 | checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.a", staticDir, staticVariant) |
| 133 | checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.cfi.a", staticDir, staticCfiVariant) |
| 134 | jsonFiles = append(jsonFiles, |
| 135 | filepath.Join(staticDir, "libb.a.json"), |
| 136 | filepath.Join(staticDir, "libvndk.a.json"), |
| 137 | filepath.Join(staticDir, "libvndk.cfi.a.json"), |
| 138 | filepath.Join(staticDir, "libvendor.a.json"), |
| 139 | filepath.Join(staticDir, "libvendor.cfi.a.json"), |
| 140 | filepath.Join(staticDir, "libvendor_available.a.json"), |
| 141 | filepath.Join(staticDir, "libvendor_available.cfi.a.json")) |
| 142 | |
| 143 | // For binary executables, all vendor:true and vendor_available modules are captured. |
| 144 | if archType == "arm64" { |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 145 | binaryVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant) |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 146 | binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary") |
| 147 | checkSnapshot(t, ctx, snapshotSingleton, "vendor_bin", "vendor_bin", binaryDir, binaryVariant) |
| 148 | checkSnapshot(t, ctx, snapshotSingleton, "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant) |
| 149 | jsonFiles = append(jsonFiles, |
| 150 | filepath.Join(binaryDir, "vendor_bin.json"), |
| 151 | filepath.Join(binaryDir, "vendor_available_bin.json")) |
| 152 | } |
| 153 | |
| 154 | // For header libraries, all vendor:true and vendor_available modules are captured. |
| 155 | headerDir := filepath.Join(snapshotVariantPath, archDir, "header") |
| 156 | jsonFiles = append(jsonFiles, filepath.Join(headerDir, "libvendor_headers.json")) |
| 157 | |
| 158 | // For object modules, all vendor:true and vendor_available modules are captured. |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 159 | objectVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant) |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 160 | objectDir := filepath.Join(snapshotVariantPath, archDir, "object") |
| 161 | checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant) |
| 162 | jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json")) |
| 163 | } |
| 164 | |
| 165 | for _, jsonFile := range jsonFiles { |
| 166 | // verify all json files exist |
| 167 | if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { |
| 168 | t.Errorf("%q expected but not found", jsonFile) |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | // fake snapshot should have all outputs in the normal snapshot. |
| 173 | fakeSnapshotSingleton := ctx.SingletonForTests("vendor-fake-snapshot") |
| 174 | for _, output := range snapshotSingleton.AllOutputs() { |
| 175 | fakeOutput := strings.Replace(output, "/vendor-snapshot/", "/fake/vendor-snapshot/", 1) |
| 176 | if fakeSnapshotSingleton.MaybeOutput(fakeOutput).Rule == nil { |
| 177 | t.Errorf("%q expected but not found", fakeOutput) |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | func TestVendorSnapshotDirected(t *testing.T) { |
| 183 | bp := ` |
| 184 | cc_library_shared { |
| 185 | name: "libvendor", |
| 186 | vendor: true, |
| 187 | nocrt: true, |
| 188 | } |
| 189 | |
| 190 | cc_library_shared { |
| 191 | name: "libvendor_available", |
| 192 | vendor_available: true, |
| 193 | nocrt: true, |
| 194 | } |
| 195 | |
| 196 | genrule { |
| 197 | name: "libfoo_gen", |
| 198 | cmd: "", |
| 199 | out: ["libfoo.so"], |
| 200 | } |
| 201 | |
| 202 | cc_prebuilt_library_shared { |
| 203 | name: "libfoo", |
| 204 | vendor: true, |
| 205 | prefer: true, |
| 206 | srcs: [":libfoo_gen"], |
| 207 | } |
| 208 | |
| 209 | cc_library_shared { |
| 210 | name: "libfoo", |
| 211 | vendor: true, |
| 212 | nocrt: true, |
| 213 | } |
| 214 | ` |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 215 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 216 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 217 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 218 | config.TestProductVariables.DirectedVendorSnapshot = true |
| 219 | config.TestProductVariables.VendorSnapshotModules = make(map[string]bool) |
| 220 | config.TestProductVariables.VendorSnapshotModules["libvendor"] = true |
| 221 | config.TestProductVariables.VendorSnapshotModules["libfoo"] = true |
| 222 | ctx := testCcWithConfig(t, config) |
| 223 | |
| 224 | // Check Vendor snapshot output. |
| 225 | |
| 226 | snapshotDir := "vendor-snapshot" |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 227 | snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64") |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 228 | snapshotSingleton := ctx.SingletonForTests("vendor-snapshot") |
| 229 | |
| 230 | var includeJsonFiles []string |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 231 | |
| 232 | for _, arch := range [][]string{ |
| 233 | []string{"arm64", "armv8-a"}, |
| 234 | []string{"arm", "armv7-a-neon"}, |
| 235 | } { |
| 236 | archType := arch[0] |
| 237 | archVariant := arch[1] |
| 238 | archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) |
| 239 | |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 240 | sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant) |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 241 | sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") |
| 242 | |
| 243 | // Included modules |
| 244 | checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant) |
| 245 | includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json")) |
| 246 | // Check that snapshot captures "prefer: true" prebuilt |
| 247 | checkSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant) |
| 248 | includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json")) |
| 249 | |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 250 | // Excluded modules. Modules not included in the directed vendor snapshot |
| 251 | // are still include as fake modules. |
| 252 | checkSnapshotRule(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant) |
| 253 | includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libvendor_available.so.json")) |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | // Verify that each json file for an included module has a rule. |
| 257 | for _, jsonFile := range includeJsonFiles { |
| 258 | if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { |
| 259 | t.Errorf("include json file %q not found", jsonFile) |
| 260 | } |
| 261 | } |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | func TestVendorSnapshotUse(t *testing.T) { |
| 265 | frameworkBp := ` |
| 266 | cc_library { |
| 267 | name: "libvndk", |
| 268 | vendor_available: true, |
| 269 | product_available: true, |
| 270 | vndk: { |
| 271 | enabled: true, |
| 272 | }, |
| 273 | nocrt: true, |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | cc_library { |
| 277 | name: "libvendor", |
| 278 | vendor: true, |
| 279 | nocrt: true, |
| 280 | no_libcrt: true, |
| 281 | stl: "none", |
| 282 | system_shared_libs: [], |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 283 | } |
| 284 | |
Colin Cross | 2e577f3 | 2021-01-22 13:06:25 -0800 | [diff] [blame] | 285 | cc_library { |
| 286 | name: "libvendor_available", |
| 287 | vendor_available: true, |
| 288 | nocrt: true, |
| 289 | no_libcrt: true, |
| 290 | stl: "none", |
| 291 | system_shared_libs: [], |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | cc_library { |
| 295 | name: "lib32", |
| 296 | vendor: true, |
| 297 | nocrt: true, |
| 298 | no_libcrt: true, |
| 299 | stl: "none", |
| 300 | system_shared_libs: [], |
| 301 | compile_multilib: "32", |
| 302 | } |
| 303 | |
| 304 | cc_library { |
| 305 | name: "lib64", |
| 306 | vendor: true, |
| 307 | nocrt: true, |
| 308 | no_libcrt: true, |
| 309 | stl: "none", |
| 310 | system_shared_libs: [], |
Colin Cross | 2e577f3 | 2021-01-22 13:06:25 -0800 | [diff] [blame] | 311 | compile_multilib: "64", |
| 312 | } |
| 313 | |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 314 | cc_binary { |
| 315 | name: "bin", |
| 316 | vendor: true, |
| 317 | nocrt: true, |
| 318 | no_libcrt: true, |
| 319 | stl: "none", |
| 320 | system_shared_libs: [], |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | cc_binary { |
| 324 | name: "bin32", |
| 325 | vendor: true, |
| 326 | nocrt: true, |
| 327 | no_libcrt: true, |
| 328 | stl: "none", |
| 329 | system_shared_libs: [], |
| 330 | compile_multilib: "32", |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 331 | } |
| 332 | ` |
| 333 | |
| 334 | vndkBp := ` |
| 335 | vndk_prebuilt_shared { |
| 336 | name: "libvndk", |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 337 | version: "30", |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 338 | target_arch: "arm64", |
| 339 | vendor_available: true, |
| 340 | product_available: true, |
| 341 | vndk: { |
| 342 | enabled: true, |
| 343 | }, |
| 344 | arch: { |
| 345 | arm64: { |
| 346 | srcs: ["libvndk.so"], |
| 347 | export_include_dirs: ["include/libvndk"], |
| 348 | }, |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 349 | arm: { |
| 350 | srcs: ["libvndk.so"], |
| 351 | export_include_dirs: ["include/libvndk"], |
| 352 | }, |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 353 | }, |
| 354 | } |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 355 | |
| 356 | // old snapshot module which has to be ignored |
| 357 | vndk_prebuilt_shared { |
| 358 | name: "libvndk", |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 359 | version: "26", |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 360 | target_arch: "arm64", |
| 361 | vendor_available: true, |
| 362 | product_available: true, |
| 363 | vndk: { |
| 364 | enabled: true, |
| 365 | }, |
| 366 | arch: { |
| 367 | arm64: { |
| 368 | srcs: ["libvndk.so"], |
| 369 | export_include_dirs: ["include/libvndk"], |
| 370 | }, |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 371 | arm: { |
| 372 | srcs: ["libvndk.so"], |
| 373 | export_include_dirs: ["include/libvndk"], |
| 374 | }, |
| 375 | }, |
| 376 | } |
| 377 | |
| 378 | // different arch snapshot which has to be ignored |
| 379 | vndk_prebuilt_shared { |
| 380 | name: "libvndk", |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 381 | version: "30", |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 382 | target_arch: "arm", |
| 383 | vendor_available: true, |
| 384 | product_available: true, |
| 385 | vndk: { |
| 386 | enabled: true, |
| 387 | }, |
| 388 | arch: { |
| 389 | arm: { |
| 390 | srcs: ["libvndk.so"], |
| 391 | export_include_dirs: ["include/libvndk"], |
| 392 | }, |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 393 | }, |
| 394 | } |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 395 | ` |
| 396 | |
| 397 | vendorProprietaryBp := ` |
| 398 | cc_library { |
| 399 | name: "libvendor_without_snapshot", |
| 400 | vendor: true, |
| 401 | nocrt: true, |
| 402 | no_libcrt: true, |
| 403 | stl: "none", |
| 404 | system_shared_libs: [], |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | cc_library_shared { |
| 408 | name: "libclient", |
| 409 | vendor: true, |
| 410 | nocrt: true, |
| 411 | no_libcrt: true, |
| 412 | stl: "none", |
| 413 | system_shared_libs: [], |
Colin Cross | 2e577f3 | 2021-01-22 13:06:25 -0800 | [diff] [blame] | 414 | shared_libs: ["libvndk", "libvendor_available"], |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 415 | static_libs: ["libvendor", "libvendor_without_snapshot"], |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 416 | arch: { |
| 417 | arm64: { |
| 418 | shared_libs: ["lib64"], |
| 419 | }, |
| 420 | arm: { |
| 421 | shared_libs: ["lib32"], |
| 422 | }, |
| 423 | }, |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 424 | srcs: ["client.cpp"], |
| 425 | } |
| 426 | |
| 427 | cc_binary { |
| 428 | name: "bin_without_snapshot", |
| 429 | vendor: true, |
| 430 | nocrt: true, |
| 431 | no_libcrt: true, |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 432 | stl: "libc++_static", |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 433 | system_shared_libs: [], |
| 434 | static_libs: ["libvndk"], |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 435 | srcs: ["bin.cpp"], |
| 436 | } |
| 437 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 438 | vendor_snapshot { |
| 439 | name: "vendor_snapshot", |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 440 | version: "30", |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 441 | arch: { |
| 442 | arm64: { |
| 443 | vndk_libs: [ |
| 444 | "libvndk", |
| 445 | ], |
| 446 | static_libs: [ |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 447 | "libc++_static", |
| 448 | "libc++demangle", |
| 449 | "libgcc_stripped", |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 450 | "libvendor", |
| 451 | "libvendor_available", |
| 452 | "libvndk", |
| 453 | "lib64", |
| 454 | ], |
| 455 | shared_libs: [ |
| 456 | "libvendor", |
| 457 | "libvendor_available", |
| 458 | "lib64", |
| 459 | ], |
| 460 | binaries: [ |
| 461 | "bin", |
| 462 | ], |
| 463 | }, |
| 464 | arm: { |
| 465 | vndk_libs: [ |
| 466 | "libvndk", |
| 467 | ], |
| 468 | static_libs: [ |
| 469 | "libvendor", |
| 470 | "libvendor_available", |
| 471 | "libvndk", |
| 472 | "lib32", |
| 473 | ], |
| 474 | shared_libs: [ |
| 475 | "libvendor", |
| 476 | "libvendor_available", |
| 477 | "lib32", |
| 478 | ], |
| 479 | binaries: [ |
| 480 | "bin32", |
| 481 | ], |
| 482 | }, |
| 483 | } |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 484 | } |
| 485 | |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 486 | vendor_snapshot_static { |
| 487 | name: "libvndk", |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 488 | version: "30", |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 489 | target_arch: "arm64", |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 490 | compile_multilib: "both", |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 491 | vendor: true, |
| 492 | arch: { |
| 493 | arm64: { |
| 494 | src: "libvndk.a", |
| 495 | export_include_dirs: ["include/libvndk"], |
| 496 | }, |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 497 | arm: { |
| 498 | src: "libvndk.a", |
| 499 | export_include_dirs: ["include/libvndk"], |
| 500 | }, |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 501 | }, |
| 502 | } |
| 503 | |
| 504 | vendor_snapshot_shared { |
| 505 | name: "libvendor", |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 506 | version: "30", |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 507 | target_arch: "arm64", |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 508 | compile_multilib: "both", |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 509 | vendor: true, |
Justin Yun | 4813867 | 2021-02-25 18:21:27 +0900 | [diff] [blame] | 510 | shared_libs: [ |
| 511 | "libvendor_without_snapshot", |
| 512 | "libvendor_available", |
Justin Yun | 07b9f86 | 2021-02-26 14:00:03 +0900 | [diff] [blame] | 513 | "libvndk", |
Justin Yun | 4813867 | 2021-02-25 18:21:27 +0900 | [diff] [blame] | 514 | ], |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 515 | arch: { |
| 516 | arm64: { |
| 517 | src: "libvendor.so", |
| 518 | export_include_dirs: ["include/libvendor"], |
| 519 | }, |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 520 | arm: { |
| 521 | src: "libvendor.so", |
| 522 | export_include_dirs: ["include/libvendor"], |
| 523 | }, |
| 524 | }, |
| 525 | } |
| 526 | |
| 527 | vendor_snapshot_static { |
| 528 | name: "lib32", |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 529 | version: "30", |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 530 | target_arch: "arm64", |
| 531 | compile_multilib: "32", |
| 532 | vendor: true, |
| 533 | arch: { |
| 534 | arm: { |
| 535 | src: "lib32.a", |
| 536 | }, |
| 537 | }, |
| 538 | } |
| 539 | |
| 540 | vendor_snapshot_shared { |
| 541 | name: "lib32", |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 542 | version: "30", |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 543 | target_arch: "arm64", |
| 544 | compile_multilib: "32", |
| 545 | vendor: true, |
| 546 | arch: { |
| 547 | arm: { |
| 548 | src: "lib32.so", |
| 549 | }, |
| 550 | }, |
| 551 | } |
| 552 | |
| 553 | vendor_snapshot_static { |
| 554 | name: "lib64", |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 555 | version: "30", |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 556 | target_arch: "arm64", |
| 557 | compile_multilib: "64", |
| 558 | vendor: true, |
| 559 | arch: { |
| 560 | arm64: { |
| 561 | src: "lib64.a", |
| 562 | }, |
| 563 | }, |
| 564 | } |
| 565 | |
| 566 | vendor_snapshot_shared { |
| 567 | name: "lib64", |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 568 | version: "30", |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 569 | target_arch: "arm64", |
| 570 | compile_multilib: "64", |
| 571 | vendor: true, |
| 572 | arch: { |
| 573 | arm64: { |
| 574 | src: "lib64.so", |
| 575 | }, |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 576 | }, |
| 577 | } |
| 578 | |
| 579 | vendor_snapshot_static { |
| 580 | name: "libvendor", |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 581 | version: "30", |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 582 | target_arch: "arm64", |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 583 | compile_multilib: "both", |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 584 | vendor: true, |
| 585 | arch: { |
| 586 | arm64: { |
| 587 | src: "libvendor.a", |
| 588 | export_include_dirs: ["include/libvendor"], |
| 589 | }, |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 590 | arm: { |
| 591 | src: "libvendor.a", |
| 592 | export_include_dirs: ["include/libvendor"], |
| 593 | }, |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 594 | }, |
| 595 | } |
| 596 | |
Colin Cross | 2e577f3 | 2021-01-22 13:06:25 -0800 | [diff] [blame] | 597 | vendor_snapshot_shared { |
| 598 | name: "libvendor_available", |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 599 | version: "30", |
Colin Cross | 2e577f3 | 2021-01-22 13:06:25 -0800 | [diff] [blame] | 600 | target_arch: "arm64", |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 601 | compile_multilib: "both", |
Colin Cross | 2e577f3 | 2021-01-22 13:06:25 -0800 | [diff] [blame] | 602 | vendor: true, |
| 603 | arch: { |
| 604 | arm64: { |
| 605 | src: "libvendor_available.so", |
| 606 | export_include_dirs: ["include/libvendor"], |
| 607 | }, |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 608 | arm: { |
| 609 | src: "libvendor_available.so", |
| 610 | export_include_dirs: ["include/libvendor"], |
| 611 | }, |
Colin Cross | 2e577f3 | 2021-01-22 13:06:25 -0800 | [diff] [blame] | 612 | }, |
| 613 | } |
| 614 | |
| 615 | vendor_snapshot_static { |
| 616 | name: "libvendor_available", |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 617 | version: "30", |
Colin Cross | 2e577f3 | 2021-01-22 13:06:25 -0800 | [diff] [blame] | 618 | target_arch: "arm64", |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 619 | compile_multilib: "both", |
Colin Cross | 2e577f3 | 2021-01-22 13:06:25 -0800 | [diff] [blame] | 620 | vendor: true, |
| 621 | arch: { |
| 622 | arm64: { |
| 623 | src: "libvendor_available.a", |
| 624 | export_include_dirs: ["include/libvendor"], |
| 625 | }, |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 626 | arm: { |
| 627 | src: "libvendor_available.so", |
| 628 | export_include_dirs: ["include/libvendor"], |
| 629 | }, |
Colin Cross | 2e577f3 | 2021-01-22 13:06:25 -0800 | [diff] [blame] | 630 | }, |
| 631 | } |
| 632 | |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 633 | vendor_snapshot_static { |
| 634 | name: "libc++_static", |
| 635 | version: "30", |
| 636 | target_arch: "arm64", |
| 637 | compile_multilib: "64", |
| 638 | vendor: true, |
| 639 | arch: { |
| 640 | arm64: { |
| 641 | src: "libc++_static.a", |
| 642 | }, |
| 643 | }, |
| 644 | } |
| 645 | |
| 646 | vendor_snapshot_static { |
| 647 | name: "libc++demangle", |
| 648 | version: "30", |
| 649 | target_arch: "arm64", |
| 650 | compile_multilib: "64", |
| 651 | vendor: true, |
| 652 | arch: { |
| 653 | arm64: { |
| 654 | src: "libc++demangle.a", |
| 655 | }, |
| 656 | }, |
| 657 | } |
| 658 | |
| 659 | vendor_snapshot_static { |
| 660 | name: "libgcc_stripped", |
| 661 | version: "30", |
| 662 | target_arch: "arm64", |
| 663 | compile_multilib: "64", |
| 664 | vendor: true, |
| 665 | arch: { |
| 666 | arm64: { |
| 667 | src: "libgcc_stripped.a", |
| 668 | }, |
| 669 | }, |
| 670 | } |
| 671 | |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 672 | vendor_snapshot_binary { |
| 673 | name: "bin", |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 674 | version: "30", |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 675 | target_arch: "arm64", |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 676 | compile_multilib: "64", |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 677 | vendor: true, |
| 678 | arch: { |
| 679 | arm64: { |
| 680 | src: "bin", |
| 681 | }, |
| 682 | }, |
| 683 | } |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 684 | |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 685 | vendor_snapshot_binary { |
| 686 | name: "bin32", |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 687 | version: "30", |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 688 | target_arch: "arm64", |
| 689 | compile_multilib: "32", |
| 690 | vendor: true, |
| 691 | arch: { |
| 692 | arm: { |
| 693 | src: "bin32", |
| 694 | }, |
| 695 | }, |
| 696 | } |
| 697 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 698 | // old snapshot module which has to be ignored |
| 699 | vendor_snapshot_binary { |
| 700 | name: "bin", |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 701 | version: "26", |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 702 | target_arch: "arm64", |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 703 | compile_multilib: "first", |
| 704 | vendor: true, |
| 705 | arch: { |
| 706 | arm64: { |
| 707 | src: "bin", |
| 708 | }, |
| 709 | }, |
| 710 | } |
| 711 | |
| 712 | // different arch snapshot which has to be ignored |
| 713 | vendor_snapshot_binary { |
| 714 | name: "bin", |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 715 | version: "30", |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 716 | target_arch: "arm", |
| 717 | compile_multilib: "first", |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 718 | vendor: true, |
| 719 | arch: { |
| 720 | arm64: { |
| 721 | src: "bin", |
| 722 | }, |
| 723 | }, |
| 724 | } |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 725 | ` |
| 726 | depsBp := GatherRequiredDepsForTest(android.Android) |
| 727 | |
| 728 | mockFS := map[string][]byte{ |
| 729 | "deps/Android.bp": []byte(depsBp), |
| 730 | "framework/Android.bp": []byte(frameworkBp), |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 731 | "framework/symbol.txt": nil, |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 732 | "vendor/Android.bp": []byte(vendorProprietaryBp), |
| 733 | "vendor/bin": nil, |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 734 | "vendor/bin32": nil, |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 735 | "vendor/bin.cpp": nil, |
| 736 | "vendor/client.cpp": nil, |
| 737 | "vendor/include/libvndk/a.h": nil, |
| 738 | "vendor/include/libvendor/b.h": nil, |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 739 | "vendor/libc++_static.a": nil, |
| 740 | "vendor/libc++demangle.a": nil, |
| 741 | "vendor/libgcc_striped.a": nil, |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 742 | "vendor/libvndk.a": nil, |
| 743 | "vendor/libvendor.a": nil, |
| 744 | "vendor/libvendor.so": nil, |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 745 | "vendor/lib32.a": nil, |
| 746 | "vendor/lib32.so": nil, |
| 747 | "vendor/lib64.a": nil, |
| 748 | "vendor/lib64.so": nil, |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 749 | "vndk/Android.bp": []byte(vndkBp), |
| 750 | "vndk/include/libvndk/a.h": nil, |
| 751 | "vndk/libvndk.so": nil, |
| 752 | } |
| 753 | |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 754 | config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS) |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 755 | config.TestProductVariables.DeviceVndkVersion = StringPtr("30") |
| 756 | config.TestProductVariables.Platform_vndk_version = StringPtr("31") |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 757 | ctx := CreateTestContext(config) |
| 758 | ctx.Register() |
| 759 | |
| 760 | _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "vendor/Android.bp", "vndk/Android.bp"}) |
| 761 | android.FailIfErrored(t, errs) |
| 762 | _, errs = ctx.PrepareBuildActions(config) |
| 763 | android.FailIfErrored(t, errs) |
| 764 | |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 765 | sharedVariant := "android_vendor.30_arm64_armv8-a_shared" |
| 766 | staticVariant := "android_vendor.30_arm64_armv8-a_static" |
| 767 | binaryVariant := "android_vendor.30_arm64_armv8-a" |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 768 | |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 769 | shared32Variant := "android_vendor.30_arm_armv7-a-neon_shared" |
| 770 | binary32Variant := "android_vendor.30_arm_armv7-a-neon" |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 771 | |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 772 | // libclient uses libvndk.vndk.30.arm64, libvendor.vendor_static.30.arm64, libvendor_without_snapshot |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 773 | libclientCcFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("cc").Args["cFlags"] |
| 774 | for _, includeFlags := range []string{ |
| 775 | "-Ivndk/include/libvndk", // libvndk |
| 776 | "-Ivendor/include/libvendor", // libvendor |
| 777 | } { |
| 778 | if !strings.Contains(libclientCcFlags, includeFlags) { |
| 779 | t.Errorf("flags for libclient must contain %#v, but was %#v.", |
| 780 | includeFlags, libclientCcFlags) |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("ld").Args["libFlags"] |
| 785 | for _, input := range [][]string{ |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 786 | []string{sharedVariant, "libvndk.vndk.30.arm64"}, |
| 787 | []string{staticVariant, "libvendor.vendor_static.30.arm64"}, |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 788 | []string{staticVariant, "libvendor_without_snapshot"}, |
| 789 | } { |
| 790 | outputPaths := getOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */) |
| 791 | if !strings.Contains(libclientLdFlags, outputPaths[0].String()) { |
| 792 | t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags) |
| 793 | } |
| 794 | } |
| 795 | |
Colin Cross | 2e577f3 | 2021-01-22 13:06:25 -0800 | [diff] [blame] | 796 | libclientAndroidMkSharedLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkSharedLibs |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 797 | if g, w := libclientAndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "lib64"}; !reflect.DeepEqual(g, w) { |
Colin Cross | 2e577f3 | 2021-01-22 13:06:25 -0800 | [diff] [blame] | 798 | t.Errorf("wanted libclient AndroidMkSharedLibs %q, got %q", w, g) |
| 799 | } |
| 800 | |
| 801 | libclientAndroidMkStaticLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkStaticLibs |
| 802 | if g, w := libclientAndroidMkStaticLibs, []string{"libvendor", "libvendor_without_snapshot"}; !reflect.DeepEqual(g, w) { |
| 803 | t.Errorf("wanted libclient AndroidMkStaticLibs %q, got %q", w, g) |
| 804 | } |
| 805 | |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 806 | libclient32AndroidMkSharedLibs := ctx.ModuleForTests("libclient", shared32Variant).Module().(*Module).Properties.AndroidMkSharedLibs |
| 807 | if g, w := libclient32AndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "lib32"}; !reflect.DeepEqual(g, w) { |
| 808 | t.Errorf("wanted libclient32 AndroidMkSharedLibs %q, got %q", w, g) |
| 809 | } |
| 810 | |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 811 | // bin_without_snapshot uses libvndk.vendor_static.30.arm64 |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 812 | binWithoutSnapshotCcFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("cc").Args["cFlags"] |
| 813 | if !strings.Contains(binWithoutSnapshotCcFlags, "-Ivendor/include/libvndk") { |
| 814 | t.Errorf("flags for bin_without_snapshot must contain %#v, but was %#v.", |
| 815 | "-Ivendor/include/libvndk", binWithoutSnapshotCcFlags) |
| 816 | } |
| 817 | |
| 818 | binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("ld").Args["libFlags"] |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 819 | libVndkStaticOutputPaths := getOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.30.arm64"}) |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 820 | if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) { |
| 821 | t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v", |
| 822 | libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags) |
| 823 | } |
| 824 | |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 825 | // libvendor.so is installed by libvendor.vendor_shared.30.arm64 |
| 826 | ctx.ModuleForTests("libvendor.vendor_shared.30.arm64", sharedVariant).Output("libvendor.so") |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 827 | |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 828 | // lib64.so is installed by lib64.vendor_shared.30.arm64 |
| 829 | ctx.ModuleForTests("lib64.vendor_shared.30.arm64", sharedVariant).Output("lib64.so") |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 830 | |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 831 | // lib32.so is installed by lib32.vendor_shared.30.arm64 |
| 832 | ctx.ModuleForTests("lib32.vendor_shared.30.arm64", shared32Variant).Output("lib32.so") |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 833 | |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 834 | // libvendor_available.so is installed by libvendor_available.vendor_shared.30.arm64 |
| 835 | ctx.ModuleForTests("libvendor_available.vendor_shared.30.arm64", sharedVariant).Output("libvendor_available.so") |
Colin Cross | 2e577f3 | 2021-01-22 13:06:25 -0800 | [diff] [blame] | 836 | |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 837 | // libvendor_without_snapshot.so is installed by libvendor_without_snapshot |
| 838 | ctx.ModuleForTests("libvendor_without_snapshot", sharedVariant).Output("libvendor_without_snapshot.so") |
| 839 | |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 840 | // bin is installed by bin.vendor_binary.30.arm64 |
| 841 | ctx.ModuleForTests("bin.vendor_binary.30.arm64", binaryVariant).Output("bin") |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 842 | |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 843 | // bin32 is installed by bin32.vendor_binary.30.arm64 |
| 844 | ctx.ModuleForTests("bin32.vendor_binary.30.arm64", binary32Variant).Output("bin32") |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 845 | |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 846 | // bin_without_snapshot is installed by bin_without_snapshot |
| 847 | ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot") |
| 848 | |
Inseob Kim | d4c9f55 | 2021-04-08 19:28:28 +0900 | [diff] [blame^] | 849 | // libvendor, libvendor_available and bin don't have vendor.30 variant |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 850 | libvendorVariants := ctx.ModuleVariantsForTests("libvendor") |
| 851 | if inList(sharedVariant, libvendorVariants) { |
| 852 | t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant) |
| 853 | } |
| 854 | |
Colin Cross | 2e577f3 | 2021-01-22 13:06:25 -0800 | [diff] [blame] | 855 | libvendorAvailableVariants := ctx.ModuleVariantsForTests("libvendor_available") |
| 856 | if inList(sharedVariant, libvendorAvailableVariants) { |
| 857 | t.Errorf("libvendor_available must not have variant %#v, but it does", sharedVariant) |
| 858 | } |
| 859 | |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 860 | binVariants := ctx.ModuleVariantsForTests("bin") |
| 861 | if inList(binaryVariant, binVariants) { |
| 862 | t.Errorf("bin must not have variant %#v, but it does", sharedVariant) |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | func TestVendorSnapshotSanitizer(t *testing.T) { |
| 867 | bp := ` |
Inseob Kim | 253f521 | 2021-04-08 17:10:31 +0900 | [diff] [blame] | 868 | vendor_snapshot { |
| 869 | name: "vendor_snapshot", |
| 870 | version: "28", |
| 871 | arch: { |
| 872 | arm64: { |
| 873 | static_libs: [ |
| 874 | "libsnapshot", |
| 875 | "note_memtag_heap_sync", |
| 876 | ], |
| 877 | }, |
| 878 | }, |
| 879 | } |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 880 | vendor_snapshot_static { |
| 881 | name: "libsnapshot", |
| 882 | vendor: true, |
| 883 | target_arch: "arm64", |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 884 | version: "28", |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 885 | arch: { |
| 886 | arm64: { |
| 887 | src: "libsnapshot.a", |
| 888 | cfi: { |
| 889 | src: "libsnapshot.cfi.a", |
| 890 | } |
| 891 | }, |
| 892 | }, |
| 893 | } |
Inseob Kim | 253f521 | 2021-04-08 17:10:31 +0900 | [diff] [blame] | 894 | |
| 895 | vendor_snapshot_static { |
| 896 | name: "note_memtag_heap_sync", |
| 897 | vendor: true, |
| 898 | target_arch: "arm64", |
| 899 | version: "28", |
| 900 | arch: { |
| 901 | arm64: { |
| 902 | src: "note_memtag_heap_sync.a", |
| 903 | }, |
| 904 | }, |
| 905 | } |
| 906 | |
| 907 | cc_test { |
| 908 | name: "vstest", |
| 909 | gtest: false, |
| 910 | vendor: true, |
| 911 | compile_multilib: "64", |
| 912 | nocrt: true, |
| 913 | no_libcrt: true, |
| 914 | stl: "none", |
| 915 | static_libs: ["libsnapshot"], |
| 916 | system_shared_libs: [], |
| 917 | } |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 918 | ` |
Inseob Kim | 253f521 | 2021-04-08 17:10:31 +0900 | [diff] [blame] | 919 | |
| 920 | mockFS := map[string][]byte{ |
| 921 | "vendor/Android.bp": []byte(bp), |
| 922 | "vendor/libc++demangle.a": nil, |
| 923 | "vendor/libsnapshot.a": nil, |
| 924 | "vendor/libsnapshot.cfi.a": nil, |
| 925 | "vendor/note_memtag_heap_sync.a": nil, |
| 926 | } |
| 927 | |
| 928 | config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS) |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 929 | config.TestProductVariables.DeviceVndkVersion = StringPtr("28") |
| 930 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 931 | ctx := testCcWithConfig(t, config) |
| 932 | |
| 933 | // Check non-cfi and cfi variant. |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 934 | staticVariant := "android_vendor.28_arm64_armv8-a_static" |
| 935 | staticCfiVariant := "android_vendor.28_arm64_armv8-a_static_cfi" |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 936 | |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 937 | staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticVariant).Module().(*Module) |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 938 | assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a") |
| 939 | |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 940 | staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticCfiVariant).Module().(*Module) |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 941 | assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a") |
| 942 | } |
| 943 | |
| 944 | func assertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool) { |
| 945 | t.Helper() |
| 946 | m := ctx.ModuleForTests(name, vendorVariant).Module().(*Module) |
| 947 | if m.ExcludeFromVendorSnapshot() != expected { |
| 948 | t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected) |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | func assertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool) { |
| 953 | t.Helper() |
| 954 | m := ctx.ModuleForTests(name, recoveryVariant).Module().(*Module) |
| 955 | if m.ExcludeFromRecoverySnapshot() != expected { |
| 956 | t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", m.String(), expected) |
| 957 | } |
| 958 | } |
| 959 | |
| 960 | func TestVendorSnapshotExclude(t *testing.T) { |
| 961 | |
| 962 | // This test verifies that the exclude_from_vendor_snapshot property |
| 963 | // makes its way from the Android.bp source file into the module data |
| 964 | // structure. It also verifies that modules are correctly included or |
| 965 | // excluded in the vendor snapshot based on their path (framework or |
| 966 | // vendor) and the exclude_from_vendor_snapshot property. |
| 967 | |
| 968 | frameworkBp := ` |
| 969 | cc_library_shared { |
| 970 | name: "libinclude", |
| 971 | srcs: ["src/include.cpp"], |
| 972 | vendor_available: true, |
| 973 | } |
| 974 | cc_library_shared { |
| 975 | name: "libexclude", |
| 976 | srcs: ["src/exclude.cpp"], |
| 977 | vendor: true, |
| 978 | exclude_from_vendor_snapshot: true, |
| 979 | } |
| 980 | cc_library_shared { |
| 981 | name: "libavailable_exclude", |
| 982 | srcs: ["src/exclude.cpp"], |
| 983 | vendor_available: true, |
| 984 | exclude_from_vendor_snapshot: true, |
| 985 | } |
| 986 | ` |
| 987 | |
| 988 | vendorProprietaryBp := ` |
| 989 | cc_library_shared { |
| 990 | name: "libvendor", |
| 991 | srcs: ["vendor.cpp"], |
| 992 | vendor: true, |
| 993 | } |
| 994 | ` |
| 995 | |
| 996 | depsBp := GatherRequiredDepsForTest(android.Android) |
| 997 | |
| 998 | mockFS := map[string][]byte{ |
| 999 | "deps/Android.bp": []byte(depsBp), |
| 1000 | "framework/Android.bp": []byte(frameworkBp), |
| 1001 | "framework/include.cpp": nil, |
| 1002 | "framework/exclude.cpp": nil, |
| 1003 | "device/Android.bp": []byte(vendorProprietaryBp), |
| 1004 | "device/vendor.cpp": nil, |
| 1005 | } |
| 1006 | |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 1007 | config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS) |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 1008 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 1009 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 1010 | ctx := CreateTestContext(config) |
| 1011 | ctx.Register() |
| 1012 | |
| 1013 | _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"}) |
| 1014 | android.FailIfErrored(t, errs) |
| 1015 | _, errs = ctx.PrepareBuildActions(config) |
| 1016 | android.FailIfErrored(t, errs) |
| 1017 | |
| 1018 | // Test an include and exclude framework module. |
| 1019 | assertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false) |
| 1020 | assertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true) |
| 1021 | assertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true) |
| 1022 | |
| 1023 | // A vendor module is excluded, but by its path, not the |
| 1024 | // exclude_from_vendor_snapshot property. |
| 1025 | assertExcludeFromVendorSnapshotIs(t, ctx, "libvendor", false) |
| 1026 | |
| 1027 | // Verify the content of the vendor snapshot. |
| 1028 | |
| 1029 | snapshotDir := "vendor-snapshot" |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 1030 | snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64") |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 1031 | snapshotSingleton := ctx.SingletonForTests("vendor-snapshot") |
| 1032 | |
| 1033 | var includeJsonFiles []string |
| 1034 | var excludeJsonFiles []string |
| 1035 | |
| 1036 | for _, arch := range [][]string{ |
| 1037 | []string{"arm64", "armv8-a"}, |
| 1038 | []string{"arm", "armv7-a-neon"}, |
| 1039 | } { |
| 1040 | archType := arch[0] |
| 1041 | archVariant := arch[1] |
| 1042 | archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) |
| 1043 | |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 1044 | sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant) |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 1045 | sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") |
| 1046 | |
| 1047 | // Included modules |
| 1048 | checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant) |
| 1049 | includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json")) |
| 1050 | |
| 1051 | // Excluded modules |
| 1052 | checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant) |
| 1053 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json")) |
| 1054 | checkSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant) |
| 1055 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json")) |
| 1056 | checkSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant) |
| 1057 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json")) |
| 1058 | } |
| 1059 | |
| 1060 | // Verify that each json file for an included module has a rule. |
| 1061 | for _, jsonFile := range includeJsonFiles { |
| 1062 | if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { |
| 1063 | t.Errorf("include json file %q not found", jsonFile) |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | // Verify that each json file for an excluded module has no rule. |
| 1068 | for _, jsonFile := range excludeJsonFiles { |
| 1069 | if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil { |
| 1070 | t.Errorf("exclude json file %q found", jsonFile) |
| 1071 | } |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) { |
| 1076 | |
| 1077 | // This test verifies that using the exclude_from_vendor_snapshot |
| 1078 | // property on a module in a vendor proprietary path generates an |
| 1079 | // error. These modules are already excluded, so we prohibit using the |
| 1080 | // property in this way, which could add to confusion. |
| 1081 | |
| 1082 | vendorProprietaryBp := ` |
| 1083 | cc_library_shared { |
| 1084 | name: "libvendor", |
| 1085 | srcs: ["vendor.cpp"], |
| 1086 | vendor: true, |
| 1087 | exclude_from_vendor_snapshot: true, |
| 1088 | } |
| 1089 | ` |
| 1090 | |
| 1091 | depsBp := GatherRequiredDepsForTest(android.Android) |
| 1092 | |
| 1093 | mockFS := map[string][]byte{ |
| 1094 | "deps/Android.bp": []byte(depsBp), |
| 1095 | "device/Android.bp": []byte(vendorProprietaryBp), |
| 1096 | "device/vendor.cpp": nil, |
| 1097 | } |
| 1098 | |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 1099 | config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS) |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 1100 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 1101 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 1102 | ctx := CreateTestContext(config) |
| 1103 | ctx.Register() |
| 1104 | |
| 1105 | _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"}) |
| 1106 | android.FailIfErrored(t, errs) |
| 1107 | |
| 1108 | _, errs = ctx.PrepareBuildActions(config) |
| 1109 | android.CheckErrorsAgainstExpectations(t, errs, []string{ |
| 1110 | `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`, |
| 1111 | `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`, |
| 1112 | `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`, |
| 1113 | `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`, |
| 1114 | `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`, |
| 1115 | `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`, |
| 1116 | }) |
| 1117 | } |
| 1118 | |
| 1119 | func TestRecoverySnapshotCapture(t *testing.T) { |
| 1120 | bp := ` |
| 1121 | cc_library { |
| 1122 | name: "libvndk", |
| 1123 | vendor_available: true, |
| 1124 | recovery_available: true, |
| 1125 | product_available: true, |
| 1126 | vndk: { |
| 1127 | enabled: true, |
| 1128 | }, |
| 1129 | nocrt: true, |
| 1130 | } |
| 1131 | |
| 1132 | cc_library { |
| 1133 | name: "librecovery", |
| 1134 | recovery: true, |
| 1135 | nocrt: true, |
| 1136 | } |
| 1137 | |
| 1138 | cc_library { |
| 1139 | name: "librecovery_available", |
| 1140 | recovery_available: true, |
| 1141 | nocrt: true, |
| 1142 | } |
| 1143 | |
| 1144 | cc_library_headers { |
| 1145 | name: "librecovery_headers", |
| 1146 | recovery_available: true, |
| 1147 | nocrt: true, |
| 1148 | } |
| 1149 | |
| 1150 | cc_binary { |
| 1151 | name: "recovery_bin", |
| 1152 | recovery: true, |
| 1153 | nocrt: true, |
| 1154 | } |
| 1155 | |
| 1156 | cc_binary { |
| 1157 | name: "recovery_available_bin", |
| 1158 | recovery_available: true, |
| 1159 | nocrt: true, |
| 1160 | } |
| 1161 | |
| 1162 | toolchain_library { |
| 1163 | name: "libb", |
| 1164 | recovery_available: true, |
| 1165 | src: "libb.a", |
| 1166 | } |
| 1167 | |
| 1168 | cc_object { |
| 1169 | name: "obj", |
| 1170 | recovery_available: true, |
| 1171 | } |
| 1172 | ` |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 1173 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 1174 | config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 1175 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 1176 | ctx := testCcWithConfig(t, config) |
| 1177 | |
| 1178 | // Check Recovery snapshot output. |
| 1179 | |
| 1180 | snapshotDir := "recovery-snapshot" |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 1181 | snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64") |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 1182 | snapshotSingleton := ctx.SingletonForTests("recovery-snapshot") |
| 1183 | |
| 1184 | var jsonFiles []string |
| 1185 | |
| 1186 | for _, arch := range [][]string{ |
| 1187 | []string{"arm64", "armv8-a"}, |
| 1188 | } { |
| 1189 | archType := arch[0] |
| 1190 | archVariant := arch[1] |
| 1191 | archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) |
| 1192 | |
| 1193 | // For shared libraries, only recovery_available modules are captured. |
| 1194 | sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant) |
| 1195 | sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") |
| 1196 | checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant) |
| 1197 | checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant) |
| 1198 | checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant) |
| 1199 | jsonFiles = append(jsonFiles, |
| 1200 | filepath.Join(sharedDir, "libvndk.so.json"), |
| 1201 | filepath.Join(sharedDir, "librecovery.so.json"), |
| 1202 | filepath.Join(sharedDir, "librecovery_available.so.json")) |
| 1203 | |
| 1204 | // For static libraries, all recovery:true and recovery_available modules are captured. |
| 1205 | staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant) |
| 1206 | staticDir := filepath.Join(snapshotVariantPath, archDir, "static") |
| 1207 | checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant) |
| 1208 | checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant) |
| 1209 | checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant) |
| 1210 | jsonFiles = append(jsonFiles, |
| 1211 | filepath.Join(staticDir, "libb.a.json"), |
| 1212 | filepath.Join(staticDir, "librecovery.a.json"), |
| 1213 | filepath.Join(staticDir, "librecovery_available.a.json")) |
| 1214 | |
| 1215 | // For binary executables, all recovery:true and recovery_available modules are captured. |
| 1216 | if archType == "arm64" { |
| 1217 | binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant) |
| 1218 | binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary") |
| 1219 | checkSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant) |
| 1220 | checkSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant) |
| 1221 | jsonFiles = append(jsonFiles, |
| 1222 | filepath.Join(binaryDir, "recovery_bin.json"), |
| 1223 | filepath.Join(binaryDir, "recovery_available_bin.json")) |
| 1224 | } |
| 1225 | |
| 1226 | // For header libraries, all vendor:true and vendor_available modules are captured. |
| 1227 | headerDir := filepath.Join(snapshotVariantPath, archDir, "header") |
| 1228 | jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json")) |
| 1229 | |
| 1230 | // For object modules, all vendor:true and vendor_available modules are captured. |
| 1231 | objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant) |
| 1232 | objectDir := filepath.Join(snapshotVariantPath, archDir, "object") |
| 1233 | checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant) |
| 1234 | jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json")) |
| 1235 | } |
| 1236 | |
| 1237 | for _, jsonFile := range jsonFiles { |
| 1238 | // verify all json files exist |
| 1239 | if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { |
| 1240 | t.Errorf("%q expected but not found", jsonFile) |
| 1241 | } |
| 1242 | } |
| 1243 | } |
| 1244 | |
| 1245 | func TestRecoverySnapshotExclude(t *testing.T) { |
| 1246 | // This test verifies that the exclude_from_recovery_snapshot property |
| 1247 | // makes its way from the Android.bp source file into the module data |
| 1248 | // structure. It also verifies that modules are correctly included or |
| 1249 | // excluded in the recovery snapshot based on their path (framework or |
| 1250 | // vendor) and the exclude_from_recovery_snapshot property. |
| 1251 | |
| 1252 | frameworkBp := ` |
| 1253 | cc_library_shared { |
| 1254 | name: "libinclude", |
| 1255 | srcs: ["src/include.cpp"], |
| 1256 | recovery_available: true, |
| 1257 | } |
| 1258 | cc_library_shared { |
| 1259 | name: "libexclude", |
| 1260 | srcs: ["src/exclude.cpp"], |
| 1261 | recovery: true, |
| 1262 | exclude_from_recovery_snapshot: true, |
| 1263 | } |
| 1264 | cc_library_shared { |
| 1265 | name: "libavailable_exclude", |
| 1266 | srcs: ["src/exclude.cpp"], |
| 1267 | recovery_available: true, |
| 1268 | exclude_from_recovery_snapshot: true, |
| 1269 | } |
| 1270 | ` |
| 1271 | |
| 1272 | vendorProprietaryBp := ` |
| 1273 | cc_library_shared { |
| 1274 | name: "librecovery", |
| 1275 | srcs: ["recovery.cpp"], |
| 1276 | recovery: true, |
| 1277 | } |
| 1278 | ` |
| 1279 | |
| 1280 | depsBp := GatherRequiredDepsForTest(android.Android) |
| 1281 | |
| 1282 | mockFS := map[string][]byte{ |
| 1283 | "deps/Android.bp": []byte(depsBp), |
| 1284 | "framework/Android.bp": []byte(frameworkBp), |
| 1285 | "framework/include.cpp": nil, |
| 1286 | "framework/exclude.cpp": nil, |
| 1287 | "device/Android.bp": []byte(vendorProprietaryBp), |
| 1288 | "device/recovery.cpp": nil, |
| 1289 | } |
| 1290 | |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 1291 | config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS) |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 1292 | config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 1293 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 1294 | ctx := CreateTestContext(config) |
| 1295 | ctx.Register() |
| 1296 | |
| 1297 | _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"}) |
| 1298 | android.FailIfErrored(t, errs) |
| 1299 | _, errs = ctx.PrepareBuildActions(config) |
| 1300 | android.FailIfErrored(t, errs) |
| 1301 | |
| 1302 | // Test an include and exclude framework module. |
| 1303 | assertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false) |
| 1304 | assertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true) |
| 1305 | assertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true) |
| 1306 | |
| 1307 | // A recovery module is excluded, but by its path, not the |
| 1308 | // exclude_from_recovery_snapshot property. |
| 1309 | assertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false) |
| 1310 | |
| 1311 | // Verify the content of the recovery snapshot. |
| 1312 | |
| 1313 | snapshotDir := "recovery-snapshot" |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 1314 | snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64") |
Colin Cross | 0fce0ba | 2021-01-08 16:40:12 -0800 | [diff] [blame] | 1315 | snapshotSingleton := ctx.SingletonForTests("recovery-snapshot") |
| 1316 | |
| 1317 | var includeJsonFiles []string |
| 1318 | var excludeJsonFiles []string |
| 1319 | |
| 1320 | for _, arch := range [][]string{ |
| 1321 | []string{"arm64", "armv8-a"}, |
| 1322 | } { |
| 1323 | archType := arch[0] |
| 1324 | archVariant := arch[1] |
| 1325 | archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) |
| 1326 | |
| 1327 | sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant) |
| 1328 | sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") |
| 1329 | |
| 1330 | // Included modules |
| 1331 | checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant) |
| 1332 | includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json")) |
| 1333 | |
| 1334 | // Excluded modules |
| 1335 | checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant) |
| 1336 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json")) |
| 1337 | checkSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant) |
| 1338 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json")) |
| 1339 | checkSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant) |
| 1340 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json")) |
| 1341 | } |
| 1342 | |
| 1343 | // Verify that each json file for an included module has a rule. |
| 1344 | for _, jsonFile := range includeJsonFiles { |
| 1345 | if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { |
| 1346 | t.Errorf("include json file %q not found", jsonFile) |
| 1347 | } |
| 1348 | } |
| 1349 | |
| 1350 | // Verify that each json file for an excluded module has no rule. |
| 1351 | for _, jsonFile := range excludeJsonFiles { |
| 1352 | if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil { |
| 1353 | t.Errorf("exclude json file %q found", jsonFile) |
| 1354 | } |
| 1355 | } |
| 1356 | } |
Jose Galmes | 4c6895e | 2021-02-09 07:44:30 -0800 | [diff] [blame] | 1357 | |
| 1358 | func TestRecoverySnapshotDirected(t *testing.T) { |
| 1359 | bp := ` |
| 1360 | cc_library_shared { |
| 1361 | name: "librecovery", |
| 1362 | recovery: true, |
| 1363 | nocrt: true, |
| 1364 | } |
| 1365 | |
| 1366 | cc_library_shared { |
| 1367 | name: "librecovery_available", |
| 1368 | recovery_available: true, |
| 1369 | nocrt: true, |
| 1370 | } |
| 1371 | |
| 1372 | genrule { |
| 1373 | name: "libfoo_gen", |
| 1374 | cmd: "", |
| 1375 | out: ["libfoo.so"], |
| 1376 | } |
| 1377 | |
| 1378 | cc_prebuilt_library_shared { |
| 1379 | name: "libfoo", |
| 1380 | recovery: true, |
| 1381 | prefer: true, |
| 1382 | srcs: [":libfoo_gen"], |
| 1383 | } |
| 1384 | |
| 1385 | cc_library_shared { |
| 1386 | name: "libfoo", |
| 1387 | recovery: true, |
| 1388 | nocrt: true, |
| 1389 | } |
| 1390 | ` |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 1391 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Jose Galmes | 4c6895e | 2021-02-09 07:44:30 -0800 | [diff] [blame] | 1392 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 1393 | config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 1394 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Jose Galmes | 4c6895e | 2021-02-09 07:44:30 -0800 | [diff] [blame] | 1395 | config.TestProductVariables.DirectedRecoverySnapshot = true |
| 1396 | config.TestProductVariables.RecoverySnapshotModules = make(map[string]bool) |
| 1397 | config.TestProductVariables.RecoverySnapshotModules["librecovery"] = true |
| 1398 | config.TestProductVariables.RecoverySnapshotModules["libfoo"] = true |
| 1399 | ctx := testCcWithConfig(t, config) |
| 1400 | |
| 1401 | // Check recovery snapshot output. |
| 1402 | |
| 1403 | snapshotDir := "recovery-snapshot" |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 1404 | snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64") |
Jose Galmes | 4c6895e | 2021-02-09 07:44:30 -0800 | [diff] [blame] | 1405 | snapshotSingleton := ctx.SingletonForTests("recovery-snapshot") |
| 1406 | |
| 1407 | var includeJsonFiles []string |
| 1408 | |
| 1409 | for _, arch := range [][]string{ |
| 1410 | []string{"arm64", "armv8-a"}, |
| 1411 | } { |
| 1412 | archType := arch[0] |
| 1413 | archVariant := arch[1] |
| 1414 | archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) |
| 1415 | |
| 1416 | sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant) |
| 1417 | sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") |
| 1418 | |
| 1419 | // Included modules |
| 1420 | checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant) |
| 1421 | includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json")) |
| 1422 | // Check that snapshot captures "prefer: true" prebuilt |
| 1423 | checkSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant) |
| 1424 | includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json")) |
| 1425 | |
| 1426 | // Excluded modules. Modules not included in the directed recovery snapshot |
| 1427 | // are still include as fake modules. |
| 1428 | checkSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant) |
| 1429 | includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json")) |
| 1430 | } |
| 1431 | |
| 1432 | // Verify that each json file for an included module has a rule. |
| 1433 | for _, jsonFile := range includeJsonFiles { |
| 1434 | if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { |
| 1435 | t.Errorf("include json file %q not found", jsonFile) |
| 1436 | } |
| 1437 | } |
| 1438 | } |