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