blob: fddd72aa1874ca1500d76d4272b55d438e9cf447 [file] [log] [blame]
Colin Cross0fce0ba2021-01-08 16:40:12 -08001// 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
15package cc
16
17import (
18 "android/soong/android"
19 "fmt"
20 "path/filepath"
Colin Cross2e577f32021-01-22 13:06:25 -080021 "reflect"
Colin Cross0fce0ba2021-01-08 16:40:12 -080022 "strings"
23 "testing"
24)
25
26func 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 Cross203b4212021-04-26 17:19:41 -070081 llndk: {
82 symbol_file: "libllndk.map.txt",
83 },
Colin Cross0fce0ba2021-01-08 16:40:12 -080084 }
85`
Colin Cross203b4212021-04-26 17:19:41 -070086
Paul Duffinc3e6ce02021-03-22 23:21:32 +000087 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -080088 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +090089 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -080090 ctx := testCcWithConfig(t, config)
91
92 // Check Vendor snapshot output.
93
94 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +000095 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -080096 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 Parkf58c46e2021-04-01 21:35:20 +0900109 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800110 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 Parkf58c46e2021-04-01 21:35:20 +0900122 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 Cross0fce0ba2021-01-08 16:40:12 -0800124 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 Parkf58c46e2021-04-01 21:35:20 +0900143 binaryVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800144 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 Parkf58c46e2021-04-01 21:35:20 +0900157 objectVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800158 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
180func 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 Duffinc3e6ce02021-03-22 23:21:32 +0000213 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800214 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900215 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800216 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 Duffinc3e6ce02021-03-22 23:21:32 +0000225 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800226 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
227
228 var includeJsonFiles []string
Colin Cross0fce0ba2021-01-08 16:40:12 -0800229
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 Parkf58c46e2021-04-01 21:35:20 +0900238 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800239 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 Galmes0a942a02021-02-03 14:23:15 -0800248 // 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 Cross0fce0ba2021-01-08 16:40:12 -0800252 }
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 Cross0fce0ba2021-01-08 16:40:12 -0800260}
261
262func 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 Cross0fce0ba2021-01-08 16:40:12 -0800272 }
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 Cross0fce0ba2021-01-08 16:40:12 -0800281 }
282
Colin Cross2e577f32021-01-22 13:06:25 -0800283 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 Galmesf9523ed2021-04-06 19:48:10 -0700290 }
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 Cross2e577f32021-01-22 13:06:25 -0800309 compile_multilib: "64",
310 }
311
Colin Cross0fce0ba2021-01-08 16:40:12 -0800312 cc_binary {
313 name: "bin",
314 vendor: true,
315 nocrt: true,
316 no_libcrt: true,
317 stl: "none",
318 system_shared_libs: [],
Jose Galmesf9523ed2021-04-06 19:48:10 -0700319 }
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 Cross0fce0ba2021-01-08 16:40:12 -0800329 }
330`
331
332 vndkBp := `
333 vndk_prebuilt_shared {
334 name: "libvndk",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900335 version: "30",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800336 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 Galmesf9523ed2021-04-06 19:48:10 -0700347 arm: {
348 srcs: ["libvndk.so"],
349 export_include_dirs: ["include/libvndk"],
350 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800351 },
352 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800353
354 // old snapshot module which has to be ignored
355 vndk_prebuilt_shared {
356 name: "libvndk",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900357 version: "26",
Colin Crosse0edaf92021-01-11 17:31:17 -0800358 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 Galmesf9523ed2021-04-06 19:48:10 -0700369 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 Kimd4c9f552021-04-08 19:28:28 +0900379 version: "30",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700380 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 Crosse0edaf92021-01-11 17:31:17 -0800391 },
392 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800393`
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 Cross0fce0ba2021-01-08 16:40:12 -0800403 }
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 Cross2e577f32021-01-22 13:06:25 -0800412 shared_libs: ["libvndk", "libvendor_available"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800413 static_libs: ["libvendor", "libvendor_without_snapshot"],
Jose Galmesf9523ed2021-04-06 19:48:10 -0700414 arch: {
415 arm64: {
416 shared_libs: ["lib64"],
417 },
418 arm: {
419 shared_libs: ["lib32"],
420 },
421 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800422 srcs: ["client.cpp"],
423 }
424
Inseob Kimf7aadf72021-04-13 10:15:31 +0900425 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 Cross0fce0ba2021-01-08 16:40:12 -0800439 cc_binary {
440 name: "bin_without_snapshot",
441 vendor: true,
442 nocrt: true,
443 no_libcrt: true,
Inseob Kimd4c9f552021-04-08 19:28:28 +0900444 stl: "libc++_static",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800445 system_shared_libs: [],
446 static_libs: ["libvndk"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800447 srcs: ["bin.cpp"],
448 }
449
Colin Crosse0edaf92021-01-11 17:31:17 -0800450 vendor_snapshot {
451 name: "vendor_snapshot",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900452 version: "30",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700453 arch: {
454 arm64: {
455 vndk_libs: [
456 "libvndk",
457 ],
458 static_libs: [
Inseob Kimd4c9f552021-04-08 19:28:28 +0900459 "libc++_static",
460 "libc++demangle",
461 "libgcc_stripped",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700462 "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 Crosse0edaf92021-01-11 17:31:17 -0800496 }
497
Colin Cross0fce0ba2021-01-08 16:40:12 -0800498 vendor_snapshot_static {
499 name: "libvndk",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900500 version: "30",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800501 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700502 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800503 vendor: true,
504 arch: {
505 arm64: {
506 src: "libvndk.a",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800507 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700508 arm: {
509 src: "libvndk.a",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700510 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800511 },
Inseob Kimdd0295d2021-04-12 21:09:59 +0900512 shared_libs: ["libvndk"],
513 export_shared_lib_headers: ["libvndk"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800514 }
515
516 vendor_snapshot_shared {
517 name: "libvendor",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900518 version: "30",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800519 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700520 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800521 vendor: true,
Justin Yun48138672021-02-25 18:21:27 +0900522 shared_libs: [
523 "libvendor_without_snapshot",
524 "libvendor_available",
Justin Yun07b9f862021-02-26 14:00:03 +0900525 "libvndk",
Justin Yun48138672021-02-25 18:21:27 +0900526 ],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800527 arch: {
528 arm64: {
529 src: "libvendor.so",
530 export_include_dirs: ["include/libvendor"],
531 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700532 arm: {
533 src: "libvendor.so",
534 export_include_dirs: ["include/libvendor"],
535 },
536 },
537 }
538
539 vendor_snapshot_static {
540 name: "lib32",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900541 version: "30",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700542 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 Kimd4c9f552021-04-08 19:28:28 +0900554 version: "30",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700555 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 Kimd4c9f552021-04-08 19:28:28 +0900567 version: "30",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700568 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 Kimd4c9f552021-04-08 19:28:28 +0900580 version: "30",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700581 target_arch: "arm64",
582 compile_multilib: "64",
583 vendor: true,
584 arch: {
585 arm64: {
586 src: "lib64.so",
587 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800588 },
589 }
590
591 vendor_snapshot_static {
592 name: "libvendor",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900593 version: "30",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800594 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700595 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800596 vendor: true,
597 arch: {
598 arm64: {
Inseob Kimf7aadf72021-04-13 10:15:31 +0900599 cfi: {
600 src: "libvendor.cfi.a",
601 export_include_dirs: ["include/libvendor_cfi"],
602 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800603 src: "libvendor.a",
604 export_include_dirs: ["include/libvendor"],
605 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700606 arm: {
Inseob Kimf7aadf72021-04-13 10:15:31 +0900607 cfi: {
608 src: "libvendor.cfi.a",
609 export_include_dirs: ["include/libvendor_cfi"],
610 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700611 src: "libvendor.a",
612 export_include_dirs: ["include/libvendor"],
613 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800614 },
615 }
616
Colin Cross2e577f32021-01-22 13:06:25 -0800617 vendor_snapshot_shared {
618 name: "libvendor_available",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900619 version: "30",
Colin Cross2e577f32021-01-22 13:06:25 -0800620 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700621 compile_multilib: "both",
Colin Cross2e577f32021-01-22 13:06:25 -0800622 vendor: true,
623 arch: {
624 arm64: {
625 src: "libvendor_available.so",
626 export_include_dirs: ["include/libvendor"],
627 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700628 arm: {
629 src: "libvendor_available.so",
630 export_include_dirs: ["include/libvendor"],
631 },
Colin Cross2e577f32021-01-22 13:06:25 -0800632 },
633 }
634
635 vendor_snapshot_static {
636 name: "libvendor_available",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900637 version: "30",
Colin Cross2e577f32021-01-22 13:06:25 -0800638 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700639 compile_multilib: "both",
Colin Cross2e577f32021-01-22 13:06:25 -0800640 vendor: true,
641 arch: {
642 arm64: {
643 src: "libvendor_available.a",
644 export_include_dirs: ["include/libvendor"],
645 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700646 arm: {
647 src: "libvendor_available.so",
648 export_include_dirs: ["include/libvendor"],
649 },
Colin Cross2e577f32021-01-22 13:06:25 -0800650 },
651 }
652
Inseob Kimd4c9f552021-04-08 19:28:28 +0900653 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 Cross0fce0ba2021-01-08 16:40:12 -0800692 vendor_snapshot_binary {
693 name: "bin",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900694 version: "30",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800695 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700696 compile_multilib: "64",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800697 vendor: true,
698 arch: {
699 arm64: {
700 src: "bin",
701 },
702 },
703 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800704
Jose Galmesf9523ed2021-04-06 19:48:10 -0700705 vendor_snapshot_binary {
706 name: "bin32",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900707 version: "30",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700708 target_arch: "arm64",
709 compile_multilib: "32",
710 vendor: true,
711 arch: {
712 arm: {
713 src: "bin32",
714 },
715 },
716 }
717
Colin Crosse0edaf92021-01-11 17:31:17 -0800718 // old snapshot module which has to be ignored
719 vendor_snapshot_binary {
720 name: "bin",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900721 version: "26",
Colin Crosse0edaf92021-01-11 17:31:17 -0800722 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700723 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 Kimd4c9f552021-04-08 19:28:28 +0900735 version: "30",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700736 target_arch: "arm",
737 compile_multilib: "first",
Colin Crosse0edaf92021-01-11 17:31:17 -0800738 vendor: true,
739 arch: {
740 arm64: {
741 src: "bin",
742 },
743 },
744 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800745`
746 depsBp := GatherRequiredDepsForTest(android.Android)
747
748 mockFS := map[string][]byte{
Inseob Kimf7aadf72021-04-13 10:15:31 +0900749 "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 Cross0fce0ba2021-01-08 16:40:12 -0800774 }
775
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000776 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Inseob Kimd4c9f552021-04-08 19:28:28 +0900777 config.TestProductVariables.DeviceVndkVersion = StringPtr("30")
778 config.TestProductVariables.Platform_vndk_version = StringPtr("31")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800779 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 Kimd4c9f552021-04-08 19:28:28 +0900787 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 Cross0fce0ba2021-01-08 16:40:12 -0800790
Inseob Kimf7aadf72021-04-13 10:15:31 +0900791 sharedCfiVariant := "android_vendor.30_arm64_armv8-a_shared_cfi"
792 staticCfiVariant := "android_vendor.30_arm64_armv8-a_static_cfi"
793
Inseob Kimd4c9f552021-04-08 19:28:28 +0900794 shared32Variant := "android_vendor.30_arm_armv7-a-neon_shared"
795 binary32Variant := "android_vendor.30_arm_armv7-a-neon"
Jose Galmesf9523ed2021-04-06 19:48:10 -0700796
Inseob Kimd4c9f552021-04-08 19:28:28 +0900797 // libclient uses libvndk.vndk.30.arm64, libvendor.vendor_static.30.arm64, libvendor_without_snapshot
Colin Cross0fce0ba2021-01-08 16:40:12 -0800798 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 Kimd4c9f552021-04-08 19:28:28 +0900811 []string{sharedVariant, "libvndk.vndk.30.arm64"},
812 []string{staticVariant, "libvendor.vendor_static.30.arm64"},
Colin Cross0fce0ba2021-01-08 16:40:12 -0800813 []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 Cross2e577f32021-01-22 13:06:25 -0800821 libclientAndroidMkSharedLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkSharedLibs
Jose Galmesf9523ed2021-04-06 19:48:10 -0700822 if g, w := libclientAndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "lib64"}; !reflect.DeepEqual(g, w) {
Colin Cross2e577f32021-01-22 13:06:25 -0800823 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 Galmesf9523ed2021-04-06 19:48:10 -0700831 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 Kimf7aadf72021-04-13 10:15:31 +0900836 // 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 Kimdd0295d2021-04-12 21:09:59 +0900849 // bin_without_snapshot uses libvndk.vendor_static.30.arm64 (which reexports vndk's exported headers)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800850 binWithoutSnapshotCcFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("cc").Args["cFlags"]
Inseob Kimdd0295d2021-04-12 21:09:59 +0900851 if !strings.Contains(binWithoutSnapshotCcFlags, "-Ivndk/include/libvndk") {
Colin Cross0fce0ba2021-01-08 16:40:12 -0800852 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 Kimd4c9f552021-04-08 19:28:28 +0900857 libVndkStaticOutputPaths := getOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.30.arm64"})
Colin Cross0fce0ba2021-01-08 16:40:12 -0800858 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 Kimd4c9f552021-04-08 19:28:28 +0900863 // libvendor.so is installed by libvendor.vendor_shared.30.arm64
864 ctx.ModuleForTests("libvendor.vendor_shared.30.arm64", sharedVariant).Output("libvendor.so")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800865
Inseob Kimd4c9f552021-04-08 19:28:28 +0900866 // lib64.so is installed by lib64.vendor_shared.30.arm64
867 ctx.ModuleForTests("lib64.vendor_shared.30.arm64", sharedVariant).Output("lib64.so")
Jose Galmesf9523ed2021-04-06 19:48:10 -0700868
Inseob Kimd4c9f552021-04-08 19:28:28 +0900869 // lib32.so is installed by lib32.vendor_shared.30.arm64
870 ctx.ModuleForTests("lib32.vendor_shared.30.arm64", shared32Variant).Output("lib32.so")
Jose Galmesf9523ed2021-04-06 19:48:10 -0700871
Inseob Kimd4c9f552021-04-08 19:28:28 +0900872 // 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 Cross2e577f32021-01-22 13:06:25 -0800874
Colin Cross0fce0ba2021-01-08 16:40:12 -0800875 // libvendor_without_snapshot.so is installed by libvendor_without_snapshot
876 ctx.ModuleForTests("libvendor_without_snapshot", sharedVariant).Output("libvendor_without_snapshot.so")
877
Inseob Kimd4c9f552021-04-08 19:28:28 +0900878 // bin is installed by bin.vendor_binary.30.arm64
879 ctx.ModuleForTests("bin.vendor_binary.30.arm64", binaryVariant).Output("bin")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800880
Inseob Kimd4c9f552021-04-08 19:28:28 +0900881 // bin32 is installed by bin32.vendor_binary.30.arm64
882 ctx.ModuleForTests("bin32.vendor_binary.30.arm64", binary32Variant).Output("bin32")
Jose Galmesf9523ed2021-04-06 19:48:10 -0700883
Colin Cross0fce0ba2021-01-08 16:40:12 -0800884 // bin_without_snapshot is installed by bin_without_snapshot
885 ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot")
886
Inseob Kimd4c9f552021-04-08 19:28:28 +0900887 // libvendor, libvendor_available and bin don't have vendor.30 variant
Colin Cross0fce0ba2021-01-08 16:40:12 -0800888 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 Cross2e577f32021-01-22 13:06:25 -0800893 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 Cross0fce0ba2021-01-08 16:40:12 -0800898 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
904func TestVendorSnapshotSanitizer(t *testing.T) {
905 bp := `
Inseob Kim253f5212021-04-08 17:10:31 +0900906 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 Cross0fce0ba2021-01-08 16:40:12 -0800918 vendor_snapshot_static {
919 name: "libsnapshot",
920 vendor: true,
921 target_arch: "arm64",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900922 version: "28",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800923 arch: {
924 arm64: {
925 src: "libsnapshot.a",
926 cfi: {
927 src: "libsnapshot.cfi.a",
928 }
929 },
930 },
931 }
Inseob Kim253f5212021-04-08 17:10:31 +0900932
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 Cross0fce0ba2021-01-08 16:40:12 -0800956`
Inseob Kim253f5212021-04-08 17:10:31 +0900957
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 Parkf58c46e2021-04-01 21:35:20 +0900967 config.TestProductVariables.DeviceVndkVersion = StringPtr("28")
968 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800969 ctx := testCcWithConfig(t, config)
970
971 // Check non-cfi and cfi variant.
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900972 staticVariant := "android_vendor.28_arm64_armv8-a_static"
973 staticCfiVariant := "android_vendor.28_arm64_armv8-a_static_cfi"
Colin Cross0fce0ba2021-01-08 16:40:12 -0800974
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900975 staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800976 assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a")
977
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900978 staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticCfiVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800979 assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
980}
981
982func 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
990func 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
998func 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 Duffinc3e6ce02021-03-22 23:21:32 +00001045 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001046 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001047 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001048 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 Duffinc3e6ce02021-03-22 23:21:32 +00001068 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001069 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 Parkf58c46e2021-04-01 21:35:20 +09001082 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001083 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
1113func 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 Duffinc3e6ce02021-03-22 23:21:32 +00001137 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001138 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001139 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001140 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
1157func 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 Duffinc3e6ce02021-03-22 23:21:32 +00001211 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001212 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001213 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001214 ctx := testCcWithConfig(t, config)
1215
1216 // Check Recovery snapshot output.
1217
1218 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001219 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001220 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
1283func 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 Duffinc3e6ce02021-03-22 23:21:32 +00001329 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001330 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001331 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001332 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 Duffinc3e6ce02021-03-22 23:21:32 +00001352 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001353 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 Galmes4c6895e2021-02-09 07:44:30 -08001395
1396func 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 Duffinc3e6ce02021-03-22 23:21:32 +00001429 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001430 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1431 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001432 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001433 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 Duffinc3e6ce02021-03-22 23:21:32 +00001442 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001443 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}