blob: 340b317fd69f4886a0774547026966a9b81217cc [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",
81 llndk_stubs: "libllndk.llndk",
82 }
83
84 llndk_library {
85 name: "libllndk.llndk",
86 symbol_file: "",
87 }
88`
Paul Duffinc3e6ce02021-03-22 23:21:32 +000089 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -080090 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +090091 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -080092 ctx := testCcWithConfig(t, config)
93
94 // Check Vendor snapshot output.
95
96 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +000097 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -080098 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
99
100 var jsonFiles []string
101
102 for _, arch := range [][]string{
103 []string{"arm64", "armv8-a"},
104 []string{"arm", "armv7-a-neon"},
105 } {
106 archType := arch[0]
107 archVariant := arch[1]
108 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
109
110 // For shared libraries, only non-VNDK vendor_available modules are captured
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900111 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800112 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
113 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
114 checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
115 jsonFiles = append(jsonFiles,
116 filepath.Join(sharedDir, "libvendor.so.json"),
117 filepath.Join(sharedDir, "libvendor_available.so.json"))
118
119 // LLNDK modules are not captured
120 checkSnapshotExclude(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", sharedDir, sharedVariant)
121
122 // For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
123 // Also cfi variants are captured, except for prebuilts like toolchain_library
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900124 staticVariant := fmt.Sprintf("android_vendor.29_%s_%s_static", archType, archVariant)
125 staticCfiVariant := fmt.Sprintf("android_vendor.29_%s_%s_static_cfi", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800126 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
127 checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
128 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.a", staticDir, staticVariant)
129 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.cfi.a", staticDir, staticCfiVariant)
130 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.a", staticDir, staticVariant)
131 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.cfi.a", staticDir, staticCfiVariant)
132 checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.a", staticDir, staticVariant)
133 checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.cfi.a", staticDir, staticCfiVariant)
134 jsonFiles = append(jsonFiles,
135 filepath.Join(staticDir, "libb.a.json"),
136 filepath.Join(staticDir, "libvndk.a.json"),
137 filepath.Join(staticDir, "libvndk.cfi.a.json"),
138 filepath.Join(staticDir, "libvendor.a.json"),
139 filepath.Join(staticDir, "libvendor.cfi.a.json"),
140 filepath.Join(staticDir, "libvendor_available.a.json"),
141 filepath.Join(staticDir, "libvendor_available.cfi.a.json"))
142
143 // For binary executables, all vendor:true and vendor_available modules are captured.
144 if archType == "arm64" {
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900145 binaryVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800146 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
147 checkSnapshot(t, ctx, snapshotSingleton, "vendor_bin", "vendor_bin", binaryDir, binaryVariant)
148 checkSnapshot(t, ctx, snapshotSingleton, "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant)
149 jsonFiles = append(jsonFiles,
150 filepath.Join(binaryDir, "vendor_bin.json"),
151 filepath.Join(binaryDir, "vendor_available_bin.json"))
152 }
153
154 // For header libraries, all vendor:true and vendor_available modules are captured.
155 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
156 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "libvendor_headers.json"))
157
158 // For object modules, all vendor:true and vendor_available modules are captured.
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900159 objectVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800160 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
161 checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
162 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
163 }
164
165 for _, jsonFile := range jsonFiles {
166 // verify all json files exist
167 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
168 t.Errorf("%q expected but not found", jsonFile)
169 }
170 }
171
172 // fake snapshot should have all outputs in the normal snapshot.
173 fakeSnapshotSingleton := ctx.SingletonForTests("vendor-fake-snapshot")
174 for _, output := range snapshotSingleton.AllOutputs() {
175 fakeOutput := strings.Replace(output, "/vendor-snapshot/", "/fake/vendor-snapshot/", 1)
176 if fakeSnapshotSingleton.MaybeOutput(fakeOutput).Rule == nil {
177 t.Errorf("%q expected but not found", fakeOutput)
178 }
179 }
180}
181
182func TestVendorSnapshotDirected(t *testing.T) {
183 bp := `
184 cc_library_shared {
185 name: "libvendor",
186 vendor: true,
187 nocrt: true,
188 }
189
190 cc_library_shared {
191 name: "libvendor_available",
192 vendor_available: true,
193 nocrt: true,
194 }
195
196 genrule {
197 name: "libfoo_gen",
198 cmd: "",
199 out: ["libfoo.so"],
200 }
201
202 cc_prebuilt_library_shared {
203 name: "libfoo",
204 vendor: true,
205 prefer: true,
206 srcs: [":libfoo_gen"],
207 }
208
209 cc_library_shared {
210 name: "libfoo",
211 vendor: true,
212 nocrt: true,
213 }
214`
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000215 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800216 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900217 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800218 config.TestProductVariables.DirectedVendorSnapshot = true
219 config.TestProductVariables.VendorSnapshotModules = make(map[string]bool)
220 config.TestProductVariables.VendorSnapshotModules["libvendor"] = true
221 config.TestProductVariables.VendorSnapshotModules["libfoo"] = true
222 ctx := testCcWithConfig(t, config)
223
224 // Check Vendor snapshot output.
225
226 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000227 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800228 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
229
230 var includeJsonFiles []string
Colin Cross0fce0ba2021-01-08 16:40:12 -0800231
232 for _, arch := range [][]string{
233 []string{"arm64", "armv8-a"},
234 []string{"arm", "armv7-a-neon"},
235 } {
236 archType := arch[0]
237 archVariant := arch[1]
238 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
239
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900240 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800241 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
242
243 // Included modules
244 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
245 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
246 // Check that snapshot captures "prefer: true" prebuilt
247 checkSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
248 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
249
Jose Galmes0a942a02021-02-03 14:23:15 -0800250 // Excluded modules. Modules not included in the directed vendor snapshot
251 // are still include as fake modules.
252 checkSnapshotRule(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
253 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libvendor_available.so.json"))
Colin Cross0fce0ba2021-01-08 16:40:12 -0800254 }
255
256 // Verify that each json file for an included module has a rule.
257 for _, jsonFile := range includeJsonFiles {
258 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
259 t.Errorf("include json file %q not found", jsonFile)
260 }
261 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800262}
263
264func TestVendorSnapshotUse(t *testing.T) {
265 frameworkBp := `
266 cc_library {
267 name: "libvndk",
268 vendor_available: true,
269 product_available: true,
270 vndk: {
271 enabled: true,
272 },
273 nocrt: true,
Colin Cross0fce0ba2021-01-08 16:40:12 -0800274 }
275
276 cc_library {
277 name: "libvendor",
278 vendor: true,
279 nocrt: true,
280 no_libcrt: true,
281 stl: "none",
282 system_shared_libs: [],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800283 }
284
Colin Cross2e577f32021-01-22 13:06:25 -0800285 cc_library {
286 name: "libvendor_available",
287 vendor_available: true,
288 nocrt: true,
289 no_libcrt: true,
290 stl: "none",
291 system_shared_libs: [],
Jose Galmesf9523ed2021-04-06 19:48:10 -0700292 }
293
294 cc_library {
295 name: "lib32",
296 vendor: true,
297 nocrt: true,
298 no_libcrt: true,
299 stl: "none",
300 system_shared_libs: [],
301 compile_multilib: "32",
302 }
303
304 cc_library {
305 name: "lib64",
306 vendor: true,
307 nocrt: true,
308 no_libcrt: true,
309 stl: "none",
310 system_shared_libs: [],
Colin Cross2e577f32021-01-22 13:06:25 -0800311 compile_multilib: "64",
312 }
313
Colin Cross0fce0ba2021-01-08 16:40:12 -0800314 cc_binary {
315 name: "bin",
316 vendor: true,
317 nocrt: true,
318 no_libcrt: true,
319 stl: "none",
320 system_shared_libs: [],
Jose Galmesf9523ed2021-04-06 19:48:10 -0700321 }
322
323 cc_binary {
324 name: "bin32",
325 vendor: true,
326 nocrt: true,
327 no_libcrt: true,
328 stl: "none",
329 system_shared_libs: [],
330 compile_multilib: "32",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800331 }
332`
333
334 vndkBp := `
335 vndk_prebuilt_shared {
336 name: "libvndk",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900337 version: "28",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800338 target_arch: "arm64",
339 vendor_available: true,
340 product_available: true,
341 vndk: {
342 enabled: true,
343 },
344 arch: {
345 arm64: {
346 srcs: ["libvndk.so"],
347 export_include_dirs: ["include/libvndk"],
348 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700349 arm: {
350 srcs: ["libvndk.so"],
351 export_include_dirs: ["include/libvndk"],
352 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800353 },
354 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800355
356 // old snapshot module which has to be ignored
357 vndk_prebuilt_shared {
358 name: "libvndk",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900359 version: "26",
Colin Crosse0edaf92021-01-11 17:31:17 -0800360 target_arch: "arm64",
361 vendor_available: true,
362 product_available: true,
363 vndk: {
364 enabled: true,
365 },
366 arch: {
367 arm64: {
368 srcs: ["libvndk.so"],
369 export_include_dirs: ["include/libvndk"],
370 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700371 arm: {
372 srcs: ["libvndk.so"],
373 export_include_dirs: ["include/libvndk"],
374 },
375 },
376 }
377
378 // different arch snapshot which has to be ignored
379 vndk_prebuilt_shared {
380 name: "libvndk",
381 version: "28",
382 target_arch: "arm",
383 vendor_available: true,
384 product_available: true,
385 vndk: {
386 enabled: true,
387 },
388 arch: {
389 arm: {
390 srcs: ["libvndk.so"],
391 export_include_dirs: ["include/libvndk"],
392 },
Colin Crosse0edaf92021-01-11 17:31:17 -0800393 },
394 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800395`
396
397 vendorProprietaryBp := `
398 cc_library {
399 name: "libvendor_without_snapshot",
400 vendor: true,
401 nocrt: true,
402 no_libcrt: true,
403 stl: "none",
404 system_shared_libs: [],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800405 }
406
407 cc_library_shared {
408 name: "libclient",
409 vendor: true,
410 nocrt: true,
411 no_libcrt: true,
412 stl: "none",
413 system_shared_libs: [],
Colin Cross2e577f32021-01-22 13:06:25 -0800414 shared_libs: ["libvndk", "libvendor_available"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800415 static_libs: ["libvendor", "libvendor_without_snapshot"],
Jose Galmesf9523ed2021-04-06 19:48:10 -0700416 arch: {
417 arm64: {
418 shared_libs: ["lib64"],
419 },
420 arm: {
421 shared_libs: ["lib32"],
422 },
423 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800424 srcs: ["client.cpp"],
425 }
426
427 cc_binary {
428 name: "bin_without_snapshot",
429 vendor: true,
430 nocrt: true,
431 no_libcrt: true,
432 stl: "none",
433 system_shared_libs: [],
434 static_libs: ["libvndk"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800435 srcs: ["bin.cpp"],
436 }
437
Colin Crosse0edaf92021-01-11 17:31:17 -0800438 vendor_snapshot {
439 name: "vendor_snapshot",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900440 version: "28",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700441 arch: {
442 arm64: {
443 vndk_libs: [
444 "libvndk",
445 ],
446 static_libs: [
447 "libvendor",
448 "libvendor_available",
449 "libvndk",
450 "lib64",
451 ],
452 shared_libs: [
453 "libvendor",
454 "libvendor_available",
455 "lib64",
456 ],
457 binaries: [
458 "bin",
459 ],
460 },
461 arm: {
462 vndk_libs: [
463 "libvndk",
464 ],
465 static_libs: [
466 "libvendor",
467 "libvendor_available",
468 "libvndk",
469 "lib32",
470 ],
471 shared_libs: [
472 "libvendor",
473 "libvendor_available",
474 "lib32",
475 ],
476 binaries: [
477 "bin32",
478 ],
479 },
480 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800481 }
482
Colin Cross0fce0ba2021-01-08 16:40:12 -0800483 vendor_snapshot_static {
484 name: "libvndk",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900485 version: "28",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800486 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700487 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800488 vendor: true,
489 arch: {
490 arm64: {
491 src: "libvndk.a",
492 export_include_dirs: ["include/libvndk"],
493 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700494 arm: {
495 src: "libvndk.a",
496 export_include_dirs: ["include/libvndk"],
497 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800498 },
499 }
500
501 vendor_snapshot_shared {
502 name: "libvendor",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900503 version: "28",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800504 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700505 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800506 vendor: true,
Justin Yun48138672021-02-25 18:21:27 +0900507 shared_libs: [
508 "libvendor_without_snapshot",
509 "libvendor_available",
Justin Yun07b9f862021-02-26 14:00:03 +0900510 "libvndk",
Justin Yun48138672021-02-25 18:21:27 +0900511 ],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800512 arch: {
513 arm64: {
514 src: "libvendor.so",
515 export_include_dirs: ["include/libvendor"],
516 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700517 arm: {
518 src: "libvendor.so",
519 export_include_dirs: ["include/libvendor"],
520 },
521 },
522 }
523
524 vendor_snapshot_static {
525 name: "lib32",
526 version: "28",
527 target_arch: "arm64",
528 compile_multilib: "32",
529 vendor: true,
530 arch: {
531 arm: {
532 src: "lib32.a",
533 },
534 },
535 }
536
537 vendor_snapshot_shared {
538 name: "lib32",
539 version: "28",
540 target_arch: "arm64",
541 compile_multilib: "32",
542 vendor: true,
543 arch: {
544 arm: {
545 src: "lib32.so",
546 },
547 },
548 }
549
550 vendor_snapshot_static {
551 name: "lib64",
552 version: "28",
553 target_arch: "arm64",
554 compile_multilib: "64",
555 vendor: true,
556 arch: {
557 arm64: {
558 src: "lib64.a",
559 },
560 },
561 }
562
563 vendor_snapshot_shared {
564 name: "lib64",
565 version: "28",
566 target_arch: "arm64",
567 compile_multilib: "64",
568 vendor: true,
569 arch: {
570 arm64: {
571 src: "lib64.so",
572 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800573 },
574 }
575
576 vendor_snapshot_static {
577 name: "libvendor",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900578 version: "28",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800579 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700580 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800581 vendor: true,
582 arch: {
583 arm64: {
584 src: "libvendor.a",
585 export_include_dirs: ["include/libvendor"],
586 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700587 arm: {
588 src: "libvendor.a",
589 export_include_dirs: ["include/libvendor"],
590 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800591 },
592 }
593
Colin Cross2e577f32021-01-22 13:06:25 -0800594 vendor_snapshot_shared {
595 name: "libvendor_available",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900596 version: "28",
Colin Cross2e577f32021-01-22 13:06:25 -0800597 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700598 compile_multilib: "both",
Colin Cross2e577f32021-01-22 13:06:25 -0800599 vendor: true,
600 arch: {
601 arm64: {
602 src: "libvendor_available.so",
603 export_include_dirs: ["include/libvendor"],
604 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700605 arm: {
606 src: "libvendor_available.so",
607 export_include_dirs: ["include/libvendor"],
608 },
Colin Cross2e577f32021-01-22 13:06:25 -0800609 },
610 }
611
612 vendor_snapshot_static {
613 name: "libvendor_available",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900614 version: "28",
Colin Cross2e577f32021-01-22 13:06:25 -0800615 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700616 compile_multilib: "both",
Colin Cross2e577f32021-01-22 13:06:25 -0800617 vendor: true,
618 arch: {
619 arm64: {
620 src: "libvendor_available.a",
621 export_include_dirs: ["include/libvendor"],
622 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700623 arm: {
624 src: "libvendor_available.so",
625 export_include_dirs: ["include/libvendor"],
626 },
Colin Cross2e577f32021-01-22 13:06:25 -0800627 },
628 }
629
Colin Cross0fce0ba2021-01-08 16:40:12 -0800630 vendor_snapshot_binary {
631 name: "bin",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900632 version: "28",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800633 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700634 compile_multilib: "64",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800635 vendor: true,
636 arch: {
637 arm64: {
638 src: "bin",
639 },
640 },
641 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800642
Jose Galmesf9523ed2021-04-06 19:48:10 -0700643 vendor_snapshot_binary {
644 name: "bin32",
645 version: "28",
646 target_arch: "arm64",
647 compile_multilib: "32",
648 vendor: true,
649 arch: {
650 arm: {
651 src: "bin32",
652 },
653 },
654 }
655
Colin Crosse0edaf92021-01-11 17:31:17 -0800656 // old snapshot module which has to be ignored
657 vendor_snapshot_binary {
658 name: "bin",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900659 version: "26",
Colin Crosse0edaf92021-01-11 17:31:17 -0800660 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700661 compile_multilib: "first",
662 vendor: true,
663 arch: {
664 arm64: {
665 src: "bin",
666 },
667 },
668 }
669
670 // different arch snapshot which has to be ignored
671 vendor_snapshot_binary {
672 name: "bin",
673 version: "28",
674 target_arch: "arm",
675 compile_multilib: "first",
Colin Crosse0edaf92021-01-11 17:31:17 -0800676 vendor: true,
677 arch: {
678 arm64: {
679 src: "bin",
680 },
681 },
682 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800683`
684 depsBp := GatherRequiredDepsForTest(android.Android)
685
686 mockFS := map[string][]byte{
687 "deps/Android.bp": []byte(depsBp),
688 "framework/Android.bp": []byte(frameworkBp),
689 "vendor/Android.bp": []byte(vendorProprietaryBp),
690 "vendor/bin": nil,
Jose Galmesf9523ed2021-04-06 19:48:10 -0700691 "vendor/bin32": nil,
Colin Cross0fce0ba2021-01-08 16:40:12 -0800692 "vendor/bin.cpp": nil,
693 "vendor/client.cpp": nil,
694 "vendor/include/libvndk/a.h": nil,
695 "vendor/include/libvendor/b.h": nil,
696 "vendor/libvndk.a": nil,
697 "vendor/libvendor.a": nil,
698 "vendor/libvendor.so": nil,
Jose Galmesf9523ed2021-04-06 19:48:10 -0700699 "vendor/lib32.a": nil,
700 "vendor/lib32.so": nil,
701 "vendor/lib64.a": nil,
702 "vendor/lib64.so": nil,
Colin Cross0fce0ba2021-01-08 16:40:12 -0800703 "vndk/Android.bp": []byte(vndkBp),
704 "vndk/include/libvndk/a.h": nil,
705 "vndk/libvndk.so": nil,
706 }
707
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000708 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900709 config.TestProductVariables.DeviceVndkVersion = StringPtr("28")
710 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800711 ctx := CreateTestContext(config)
712 ctx.Register()
713
714 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "vendor/Android.bp", "vndk/Android.bp"})
715 android.FailIfErrored(t, errs)
716 _, errs = ctx.PrepareBuildActions(config)
717 android.FailIfErrored(t, errs)
718
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900719 sharedVariant := "android_vendor.28_arm64_armv8-a_shared"
720 staticVariant := "android_vendor.28_arm64_armv8-a_static"
721 binaryVariant := "android_vendor.28_arm64_armv8-a"
Colin Cross0fce0ba2021-01-08 16:40:12 -0800722
Jose Galmesf9523ed2021-04-06 19:48:10 -0700723 shared32Variant := "android_vendor.28_arm_armv7-a-neon_shared"
724 binary32Variant := "android_vendor.28_arm_armv7-a-neon"
725
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900726 // libclient uses libvndk.vndk.28.arm64, libvendor.vendor_static.28.arm64, libvendor_without_snapshot
Colin Cross0fce0ba2021-01-08 16:40:12 -0800727 libclientCcFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("cc").Args["cFlags"]
728 for _, includeFlags := range []string{
729 "-Ivndk/include/libvndk", // libvndk
730 "-Ivendor/include/libvendor", // libvendor
731 } {
732 if !strings.Contains(libclientCcFlags, includeFlags) {
733 t.Errorf("flags for libclient must contain %#v, but was %#v.",
734 includeFlags, libclientCcFlags)
735 }
736 }
737
738 libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("ld").Args["libFlags"]
739 for _, input := range [][]string{
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900740 []string{sharedVariant, "libvndk.vndk.28.arm64"},
741 []string{staticVariant, "libvendor.vendor_static.28.arm64"},
Colin Cross0fce0ba2021-01-08 16:40:12 -0800742 []string{staticVariant, "libvendor_without_snapshot"},
743 } {
744 outputPaths := getOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */)
745 if !strings.Contains(libclientLdFlags, outputPaths[0].String()) {
746 t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags)
747 }
748 }
749
Colin Cross2e577f32021-01-22 13:06:25 -0800750 libclientAndroidMkSharedLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkSharedLibs
Jose Galmesf9523ed2021-04-06 19:48:10 -0700751 if g, w := libclientAndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "lib64"}; !reflect.DeepEqual(g, w) {
Colin Cross2e577f32021-01-22 13:06:25 -0800752 t.Errorf("wanted libclient AndroidMkSharedLibs %q, got %q", w, g)
753 }
754
755 libclientAndroidMkStaticLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkStaticLibs
756 if g, w := libclientAndroidMkStaticLibs, []string{"libvendor", "libvendor_without_snapshot"}; !reflect.DeepEqual(g, w) {
757 t.Errorf("wanted libclient AndroidMkStaticLibs %q, got %q", w, g)
758 }
759
Jose Galmesf9523ed2021-04-06 19:48:10 -0700760 libclient32AndroidMkSharedLibs := ctx.ModuleForTests("libclient", shared32Variant).Module().(*Module).Properties.AndroidMkSharedLibs
761 if g, w := libclient32AndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "lib32"}; !reflect.DeepEqual(g, w) {
762 t.Errorf("wanted libclient32 AndroidMkSharedLibs %q, got %q", w, g)
763 }
764
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900765 // bin_without_snapshot uses libvndk.vendor_static.28.arm64
Colin Cross0fce0ba2021-01-08 16:40:12 -0800766 binWithoutSnapshotCcFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("cc").Args["cFlags"]
767 if !strings.Contains(binWithoutSnapshotCcFlags, "-Ivendor/include/libvndk") {
768 t.Errorf("flags for bin_without_snapshot must contain %#v, but was %#v.",
769 "-Ivendor/include/libvndk", binWithoutSnapshotCcFlags)
770 }
771
772 binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("ld").Args["libFlags"]
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900773 libVndkStaticOutputPaths := getOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.28.arm64"})
Colin Cross0fce0ba2021-01-08 16:40:12 -0800774 if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) {
775 t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v",
776 libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags)
777 }
778
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900779 // libvendor.so is installed by libvendor.vendor_shared.28.arm64
780 ctx.ModuleForTests("libvendor.vendor_shared.28.arm64", sharedVariant).Output("libvendor.so")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800781
Jose Galmesf9523ed2021-04-06 19:48:10 -0700782 // lib64.so is installed by lib64.vendor_shared.28.arm64
783 ctx.ModuleForTests("lib64.vendor_shared.28.arm64", sharedVariant).Output("lib64.so")
784
785 // lib32.so is installed by lib32.vendor_shared.28.arm64
786 ctx.ModuleForTests("lib32.vendor_shared.28.arm64", shared32Variant).Output("lib32.so")
787
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900788 // libvendor_available.so is installed by libvendor_available.vendor_shared.28.arm64
789 ctx.ModuleForTests("libvendor_available.vendor_shared.28.arm64", sharedVariant).Output("libvendor_available.so")
Colin Cross2e577f32021-01-22 13:06:25 -0800790
Colin Cross0fce0ba2021-01-08 16:40:12 -0800791 // libvendor_without_snapshot.so is installed by libvendor_without_snapshot
792 ctx.ModuleForTests("libvendor_without_snapshot", sharedVariant).Output("libvendor_without_snapshot.so")
793
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900794 // bin is installed by bin.vendor_binary.28.arm64
795 ctx.ModuleForTests("bin.vendor_binary.28.arm64", binaryVariant).Output("bin")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800796
Jose Galmesf9523ed2021-04-06 19:48:10 -0700797 // bin32 is installed by bin32.vendor_binary.28.arm64
798 ctx.ModuleForTests("bin32.vendor_binary.28.arm64", binary32Variant).Output("bin32")
799
Colin Cross0fce0ba2021-01-08 16:40:12 -0800800 // bin_without_snapshot is installed by bin_without_snapshot
801 ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot")
802
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900803 // libvendor, libvendor_available and bin don't have vendor.28 variant
Colin Cross0fce0ba2021-01-08 16:40:12 -0800804 libvendorVariants := ctx.ModuleVariantsForTests("libvendor")
805 if inList(sharedVariant, libvendorVariants) {
806 t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant)
807 }
808
Colin Cross2e577f32021-01-22 13:06:25 -0800809 libvendorAvailableVariants := ctx.ModuleVariantsForTests("libvendor_available")
810 if inList(sharedVariant, libvendorAvailableVariants) {
811 t.Errorf("libvendor_available must not have variant %#v, but it does", sharedVariant)
812 }
813
Colin Cross0fce0ba2021-01-08 16:40:12 -0800814 binVariants := ctx.ModuleVariantsForTests("bin")
815 if inList(binaryVariant, binVariants) {
816 t.Errorf("bin must not have variant %#v, but it does", sharedVariant)
817 }
818}
819
820func TestVendorSnapshotSanitizer(t *testing.T) {
821 bp := `
Inseob Kim253f5212021-04-08 17:10:31 +0900822 vendor_snapshot {
823 name: "vendor_snapshot",
824 version: "28",
825 arch: {
826 arm64: {
827 static_libs: [
828 "libsnapshot",
829 "note_memtag_heap_sync",
830 ],
831 },
832 },
833 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800834 vendor_snapshot_static {
835 name: "libsnapshot",
836 vendor: true,
837 target_arch: "arm64",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900838 version: "28",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800839 arch: {
840 arm64: {
841 src: "libsnapshot.a",
842 cfi: {
843 src: "libsnapshot.cfi.a",
844 }
845 },
846 },
847 }
Inseob Kim253f5212021-04-08 17:10:31 +0900848
849 vendor_snapshot_static {
850 name: "note_memtag_heap_sync",
851 vendor: true,
852 target_arch: "arm64",
853 version: "28",
854 arch: {
855 arm64: {
856 src: "note_memtag_heap_sync.a",
857 },
858 },
859 }
860
861 cc_test {
862 name: "vstest",
863 gtest: false,
864 vendor: true,
865 compile_multilib: "64",
866 nocrt: true,
867 no_libcrt: true,
868 stl: "none",
869 static_libs: ["libsnapshot"],
870 system_shared_libs: [],
871 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800872`
Inseob Kim253f5212021-04-08 17:10:31 +0900873
874 mockFS := map[string][]byte{
875 "vendor/Android.bp": []byte(bp),
876 "vendor/libc++demangle.a": nil,
877 "vendor/libsnapshot.a": nil,
878 "vendor/libsnapshot.cfi.a": nil,
879 "vendor/note_memtag_heap_sync.a": nil,
880 }
881
882 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900883 config.TestProductVariables.DeviceVndkVersion = StringPtr("28")
884 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800885 ctx := testCcWithConfig(t, config)
886
887 // Check non-cfi and cfi variant.
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900888 staticVariant := "android_vendor.28_arm64_armv8-a_static"
889 staticCfiVariant := "android_vendor.28_arm64_armv8-a_static_cfi"
Colin Cross0fce0ba2021-01-08 16:40:12 -0800890
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900891 staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800892 assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a")
893
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900894 staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticCfiVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800895 assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
896}
897
898func assertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool) {
899 t.Helper()
900 m := ctx.ModuleForTests(name, vendorVariant).Module().(*Module)
901 if m.ExcludeFromVendorSnapshot() != expected {
902 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
903 }
904}
905
906func assertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool) {
907 t.Helper()
908 m := ctx.ModuleForTests(name, recoveryVariant).Module().(*Module)
909 if m.ExcludeFromRecoverySnapshot() != expected {
910 t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", m.String(), expected)
911 }
912}
913
914func TestVendorSnapshotExclude(t *testing.T) {
915
916 // This test verifies that the exclude_from_vendor_snapshot property
917 // makes its way from the Android.bp source file into the module data
918 // structure. It also verifies that modules are correctly included or
919 // excluded in the vendor snapshot based on their path (framework or
920 // vendor) and the exclude_from_vendor_snapshot property.
921
922 frameworkBp := `
923 cc_library_shared {
924 name: "libinclude",
925 srcs: ["src/include.cpp"],
926 vendor_available: true,
927 }
928 cc_library_shared {
929 name: "libexclude",
930 srcs: ["src/exclude.cpp"],
931 vendor: true,
932 exclude_from_vendor_snapshot: true,
933 }
934 cc_library_shared {
935 name: "libavailable_exclude",
936 srcs: ["src/exclude.cpp"],
937 vendor_available: true,
938 exclude_from_vendor_snapshot: true,
939 }
940 `
941
942 vendorProprietaryBp := `
943 cc_library_shared {
944 name: "libvendor",
945 srcs: ["vendor.cpp"],
946 vendor: true,
947 }
948 `
949
950 depsBp := GatherRequiredDepsForTest(android.Android)
951
952 mockFS := map[string][]byte{
953 "deps/Android.bp": []byte(depsBp),
954 "framework/Android.bp": []byte(frameworkBp),
955 "framework/include.cpp": nil,
956 "framework/exclude.cpp": nil,
957 "device/Android.bp": []byte(vendorProprietaryBp),
958 "device/vendor.cpp": nil,
959 }
960
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000961 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800962 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900963 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800964 ctx := CreateTestContext(config)
965 ctx.Register()
966
967 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
968 android.FailIfErrored(t, errs)
969 _, errs = ctx.PrepareBuildActions(config)
970 android.FailIfErrored(t, errs)
971
972 // Test an include and exclude framework module.
973 assertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false)
974 assertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true)
975 assertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true)
976
977 // A vendor module is excluded, but by its path, not the
978 // exclude_from_vendor_snapshot property.
979 assertExcludeFromVendorSnapshotIs(t, ctx, "libvendor", false)
980
981 // Verify the content of the vendor snapshot.
982
983 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000984 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800985 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
986
987 var includeJsonFiles []string
988 var excludeJsonFiles []string
989
990 for _, arch := range [][]string{
991 []string{"arm64", "armv8-a"},
992 []string{"arm", "armv7-a-neon"},
993 } {
994 archType := arch[0]
995 archVariant := arch[1]
996 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
997
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900998 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800999 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1000
1001 // Included modules
1002 checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
1003 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1004
1005 // Excluded modules
1006 checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
1007 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
1008 checkSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
1009 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
1010 checkSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
1011 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1012 }
1013
1014 // Verify that each json file for an included module has a rule.
1015 for _, jsonFile := range includeJsonFiles {
1016 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1017 t.Errorf("include json file %q not found", jsonFile)
1018 }
1019 }
1020
1021 // Verify that each json file for an excluded module has no rule.
1022 for _, jsonFile := range excludeJsonFiles {
1023 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1024 t.Errorf("exclude json file %q found", jsonFile)
1025 }
1026 }
1027}
1028
1029func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) {
1030
1031 // This test verifies that using the exclude_from_vendor_snapshot
1032 // property on a module in a vendor proprietary path generates an
1033 // error. These modules are already excluded, so we prohibit using the
1034 // property in this way, which could add to confusion.
1035
1036 vendorProprietaryBp := `
1037 cc_library_shared {
1038 name: "libvendor",
1039 srcs: ["vendor.cpp"],
1040 vendor: true,
1041 exclude_from_vendor_snapshot: true,
1042 }
1043 `
1044
1045 depsBp := GatherRequiredDepsForTest(android.Android)
1046
1047 mockFS := map[string][]byte{
1048 "deps/Android.bp": []byte(depsBp),
1049 "device/Android.bp": []byte(vendorProprietaryBp),
1050 "device/vendor.cpp": nil,
1051 }
1052
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001053 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001054 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001055 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001056 ctx := CreateTestContext(config)
1057 ctx.Register()
1058
1059 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"})
1060 android.FailIfErrored(t, errs)
1061
1062 _, errs = ctx.PrepareBuildActions(config)
1063 android.CheckErrorsAgainstExpectations(t, errs, []string{
1064 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1065 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1066 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1067 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1068 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1069 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1070 })
1071}
1072
1073func TestRecoverySnapshotCapture(t *testing.T) {
1074 bp := `
1075 cc_library {
1076 name: "libvndk",
1077 vendor_available: true,
1078 recovery_available: true,
1079 product_available: true,
1080 vndk: {
1081 enabled: true,
1082 },
1083 nocrt: true,
1084 }
1085
1086 cc_library {
1087 name: "librecovery",
1088 recovery: true,
1089 nocrt: true,
1090 }
1091
1092 cc_library {
1093 name: "librecovery_available",
1094 recovery_available: true,
1095 nocrt: true,
1096 }
1097
1098 cc_library_headers {
1099 name: "librecovery_headers",
1100 recovery_available: true,
1101 nocrt: true,
1102 }
1103
1104 cc_binary {
1105 name: "recovery_bin",
1106 recovery: true,
1107 nocrt: true,
1108 }
1109
1110 cc_binary {
1111 name: "recovery_available_bin",
1112 recovery_available: true,
1113 nocrt: true,
1114 }
1115
1116 toolchain_library {
1117 name: "libb",
1118 recovery_available: true,
1119 src: "libb.a",
1120 }
1121
1122 cc_object {
1123 name: "obj",
1124 recovery_available: true,
1125 }
1126`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001127 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001128 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001129 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001130 ctx := testCcWithConfig(t, config)
1131
1132 // Check Recovery snapshot output.
1133
1134 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001135 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001136 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1137
1138 var jsonFiles []string
1139
1140 for _, arch := range [][]string{
1141 []string{"arm64", "armv8-a"},
1142 } {
1143 archType := arch[0]
1144 archVariant := arch[1]
1145 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1146
1147 // For shared libraries, only recovery_available modules are captured.
1148 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1149 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1150 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant)
1151 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1152 checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
1153 jsonFiles = append(jsonFiles,
1154 filepath.Join(sharedDir, "libvndk.so.json"),
1155 filepath.Join(sharedDir, "librecovery.so.json"),
1156 filepath.Join(sharedDir, "librecovery_available.so.json"))
1157
1158 // For static libraries, all recovery:true and recovery_available modules are captured.
1159 staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
1160 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
1161 checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
1162 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
1163 checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
1164 jsonFiles = append(jsonFiles,
1165 filepath.Join(staticDir, "libb.a.json"),
1166 filepath.Join(staticDir, "librecovery.a.json"),
1167 filepath.Join(staticDir, "librecovery_available.a.json"))
1168
1169 // For binary executables, all recovery:true and recovery_available modules are captured.
1170 if archType == "arm64" {
1171 binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1172 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
1173 checkSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
1174 checkSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
1175 jsonFiles = append(jsonFiles,
1176 filepath.Join(binaryDir, "recovery_bin.json"),
1177 filepath.Join(binaryDir, "recovery_available_bin.json"))
1178 }
1179
1180 // For header libraries, all vendor:true and vendor_available modules are captured.
1181 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
1182 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json"))
1183
1184 // For object modules, all vendor:true and vendor_available modules are captured.
1185 objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1186 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
1187 checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
1188 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
1189 }
1190
1191 for _, jsonFile := range jsonFiles {
1192 // verify all json files exist
1193 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1194 t.Errorf("%q expected but not found", jsonFile)
1195 }
1196 }
1197}
1198
1199func TestRecoverySnapshotExclude(t *testing.T) {
1200 // This test verifies that the exclude_from_recovery_snapshot property
1201 // makes its way from the Android.bp source file into the module data
1202 // structure. It also verifies that modules are correctly included or
1203 // excluded in the recovery snapshot based on their path (framework or
1204 // vendor) and the exclude_from_recovery_snapshot property.
1205
1206 frameworkBp := `
1207 cc_library_shared {
1208 name: "libinclude",
1209 srcs: ["src/include.cpp"],
1210 recovery_available: true,
1211 }
1212 cc_library_shared {
1213 name: "libexclude",
1214 srcs: ["src/exclude.cpp"],
1215 recovery: true,
1216 exclude_from_recovery_snapshot: true,
1217 }
1218 cc_library_shared {
1219 name: "libavailable_exclude",
1220 srcs: ["src/exclude.cpp"],
1221 recovery_available: true,
1222 exclude_from_recovery_snapshot: true,
1223 }
1224 `
1225
1226 vendorProprietaryBp := `
1227 cc_library_shared {
1228 name: "librecovery",
1229 srcs: ["recovery.cpp"],
1230 recovery: true,
1231 }
1232 `
1233
1234 depsBp := GatherRequiredDepsForTest(android.Android)
1235
1236 mockFS := map[string][]byte{
1237 "deps/Android.bp": []byte(depsBp),
1238 "framework/Android.bp": []byte(frameworkBp),
1239 "framework/include.cpp": nil,
1240 "framework/exclude.cpp": nil,
1241 "device/Android.bp": []byte(vendorProprietaryBp),
1242 "device/recovery.cpp": nil,
1243 }
1244
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001245 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001246 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001247 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001248 ctx := CreateTestContext(config)
1249 ctx.Register()
1250
1251 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1252 android.FailIfErrored(t, errs)
1253 _, errs = ctx.PrepareBuildActions(config)
1254 android.FailIfErrored(t, errs)
1255
1256 // Test an include and exclude framework module.
1257 assertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false)
1258 assertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true)
1259 assertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true)
1260
1261 // A recovery module is excluded, but by its path, not the
1262 // exclude_from_recovery_snapshot property.
1263 assertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false)
1264
1265 // Verify the content of the recovery snapshot.
1266
1267 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001268 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001269 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1270
1271 var includeJsonFiles []string
1272 var excludeJsonFiles []string
1273
1274 for _, arch := range [][]string{
1275 []string{"arm64", "armv8-a"},
1276 } {
1277 archType := arch[0]
1278 archVariant := arch[1]
1279 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1280
1281 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1282 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1283
1284 // Included modules
1285 checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
1286 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1287
1288 // Excluded modules
1289 checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
1290 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
1291 checkSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1292 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1293 checkSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
1294 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1295 }
1296
1297 // Verify that each json file for an included module has a rule.
1298 for _, jsonFile := range includeJsonFiles {
1299 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1300 t.Errorf("include json file %q not found", jsonFile)
1301 }
1302 }
1303
1304 // Verify that each json file for an excluded module has no rule.
1305 for _, jsonFile := range excludeJsonFiles {
1306 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1307 t.Errorf("exclude json file %q found", jsonFile)
1308 }
1309 }
1310}
Jose Galmes4c6895e2021-02-09 07:44:30 -08001311
1312func TestRecoverySnapshotDirected(t *testing.T) {
1313 bp := `
1314 cc_library_shared {
1315 name: "librecovery",
1316 recovery: true,
1317 nocrt: true,
1318 }
1319
1320 cc_library_shared {
1321 name: "librecovery_available",
1322 recovery_available: true,
1323 nocrt: true,
1324 }
1325
1326 genrule {
1327 name: "libfoo_gen",
1328 cmd: "",
1329 out: ["libfoo.so"],
1330 }
1331
1332 cc_prebuilt_library_shared {
1333 name: "libfoo",
1334 recovery: true,
1335 prefer: true,
1336 srcs: [":libfoo_gen"],
1337 }
1338
1339 cc_library_shared {
1340 name: "libfoo",
1341 recovery: true,
1342 nocrt: true,
1343 }
1344`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001345 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001346 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1347 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001348 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001349 config.TestProductVariables.DirectedRecoverySnapshot = true
1350 config.TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
1351 config.TestProductVariables.RecoverySnapshotModules["librecovery"] = true
1352 config.TestProductVariables.RecoverySnapshotModules["libfoo"] = true
1353 ctx := testCcWithConfig(t, config)
1354
1355 // Check recovery snapshot output.
1356
1357 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001358 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001359 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1360
1361 var includeJsonFiles []string
1362
1363 for _, arch := range [][]string{
1364 []string{"arm64", "armv8-a"},
1365 } {
1366 archType := arch[0]
1367 archVariant := arch[1]
1368 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1369
1370 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1371 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1372
1373 // Included modules
1374 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1375 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1376 // Check that snapshot captures "prefer: true" prebuilt
1377 checkSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
1378 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
1379
1380 // Excluded modules. Modules not included in the directed recovery snapshot
1381 // are still include as fake modules.
1382 checkSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
1383 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json"))
1384 }
1385
1386 // Verify that each json file for an included module has a rule.
1387 for _, jsonFile := range includeJsonFiles {
1388 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1389 t.Errorf("include json file %q not found", jsonFile)
1390 }
1391 }
1392}