blob: 8f77c284318b46a5a3782794de00d5e4d1d5ea73 [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 := `
822 vendor_snapshot_static {
823 name: "libsnapshot",
824 vendor: true,
825 target_arch: "arm64",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900826 version: "28",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800827 arch: {
828 arm64: {
829 src: "libsnapshot.a",
830 cfi: {
831 src: "libsnapshot.cfi.a",
832 }
833 },
834 },
835 }
836`
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000837 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900838 config.TestProductVariables.DeviceVndkVersion = StringPtr("28")
839 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800840 ctx := testCcWithConfig(t, config)
841
842 // Check non-cfi and cfi variant.
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900843 staticVariant := "android_vendor.28_arm64_armv8-a_static"
844 staticCfiVariant := "android_vendor.28_arm64_armv8-a_static_cfi"
Colin Cross0fce0ba2021-01-08 16:40:12 -0800845
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900846 staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800847 assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a")
848
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900849 staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticCfiVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800850 assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
851}
852
853func assertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool) {
854 t.Helper()
855 m := ctx.ModuleForTests(name, vendorVariant).Module().(*Module)
856 if m.ExcludeFromVendorSnapshot() != expected {
857 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
858 }
859}
860
861func assertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool) {
862 t.Helper()
863 m := ctx.ModuleForTests(name, recoveryVariant).Module().(*Module)
864 if m.ExcludeFromRecoverySnapshot() != expected {
865 t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", m.String(), expected)
866 }
867}
868
869func TestVendorSnapshotExclude(t *testing.T) {
870
871 // This test verifies that the exclude_from_vendor_snapshot property
872 // makes its way from the Android.bp source file into the module data
873 // structure. It also verifies that modules are correctly included or
874 // excluded in the vendor snapshot based on their path (framework or
875 // vendor) and the exclude_from_vendor_snapshot property.
876
877 frameworkBp := `
878 cc_library_shared {
879 name: "libinclude",
880 srcs: ["src/include.cpp"],
881 vendor_available: true,
882 }
883 cc_library_shared {
884 name: "libexclude",
885 srcs: ["src/exclude.cpp"],
886 vendor: true,
887 exclude_from_vendor_snapshot: true,
888 }
889 cc_library_shared {
890 name: "libavailable_exclude",
891 srcs: ["src/exclude.cpp"],
892 vendor_available: true,
893 exclude_from_vendor_snapshot: true,
894 }
895 `
896
897 vendorProprietaryBp := `
898 cc_library_shared {
899 name: "libvendor",
900 srcs: ["vendor.cpp"],
901 vendor: true,
902 }
903 `
904
905 depsBp := GatherRequiredDepsForTest(android.Android)
906
907 mockFS := map[string][]byte{
908 "deps/Android.bp": []byte(depsBp),
909 "framework/Android.bp": []byte(frameworkBp),
910 "framework/include.cpp": nil,
911 "framework/exclude.cpp": nil,
912 "device/Android.bp": []byte(vendorProprietaryBp),
913 "device/vendor.cpp": nil,
914 }
915
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000916 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800917 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900918 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800919 ctx := CreateTestContext(config)
920 ctx.Register()
921
922 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
923 android.FailIfErrored(t, errs)
924 _, errs = ctx.PrepareBuildActions(config)
925 android.FailIfErrored(t, errs)
926
927 // Test an include and exclude framework module.
928 assertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false)
929 assertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true)
930 assertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true)
931
932 // A vendor module is excluded, but by its path, not the
933 // exclude_from_vendor_snapshot property.
934 assertExcludeFromVendorSnapshotIs(t, ctx, "libvendor", false)
935
936 // Verify the content of the vendor snapshot.
937
938 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000939 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800940 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
941
942 var includeJsonFiles []string
943 var excludeJsonFiles []string
944
945 for _, arch := range [][]string{
946 []string{"arm64", "armv8-a"},
947 []string{"arm", "armv7-a-neon"},
948 } {
949 archType := arch[0]
950 archVariant := arch[1]
951 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
952
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900953 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800954 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
955
956 // Included modules
957 checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
958 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
959
960 // Excluded modules
961 checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
962 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
963 checkSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
964 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
965 checkSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
966 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
967 }
968
969 // Verify that each json file for an included module has a rule.
970 for _, jsonFile := range includeJsonFiles {
971 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
972 t.Errorf("include json file %q not found", jsonFile)
973 }
974 }
975
976 // Verify that each json file for an excluded module has no rule.
977 for _, jsonFile := range excludeJsonFiles {
978 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
979 t.Errorf("exclude json file %q found", jsonFile)
980 }
981 }
982}
983
984func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) {
985
986 // This test verifies that using the exclude_from_vendor_snapshot
987 // property on a module in a vendor proprietary path generates an
988 // error. These modules are already excluded, so we prohibit using the
989 // property in this way, which could add to confusion.
990
991 vendorProprietaryBp := `
992 cc_library_shared {
993 name: "libvendor",
994 srcs: ["vendor.cpp"],
995 vendor: true,
996 exclude_from_vendor_snapshot: true,
997 }
998 `
999
1000 depsBp := GatherRequiredDepsForTest(android.Android)
1001
1002 mockFS := map[string][]byte{
1003 "deps/Android.bp": []byte(depsBp),
1004 "device/Android.bp": []byte(vendorProprietaryBp),
1005 "device/vendor.cpp": nil,
1006 }
1007
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001008 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001009 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001010 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001011 ctx := CreateTestContext(config)
1012 ctx.Register()
1013
1014 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"})
1015 android.FailIfErrored(t, errs)
1016
1017 _, errs = ctx.PrepareBuildActions(config)
1018 android.CheckErrorsAgainstExpectations(t, errs, []string{
1019 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1020 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1021 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1022 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1023 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1024 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1025 })
1026}
1027
1028func TestRecoverySnapshotCapture(t *testing.T) {
1029 bp := `
1030 cc_library {
1031 name: "libvndk",
1032 vendor_available: true,
1033 recovery_available: true,
1034 product_available: true,
1035 vndk: {
1036 enabled: true,
1037 },
1038 nocrt: true,
1039 }
1040
1041 cc_library {
1042 name: "librecovery",
1043 recovery: true,
1044 nocrt: true,
1045 }
1046
1047 cc_library {
1048 name: "librecovery_available",
1049 recovery_available: true,
1050 nocrt: true,
1051 }
1052
1053 cc_library_headers {
1054 name: "librecovery_headers",
1055 recovery_available: true,
1056 nocrt: true,
1057 }
1058
1059 cc_binary {
1060 name: "recovery_bin",
1061 recovery: true,
1062 nocrt: true,
1063 }
1064
1065 cc_binary {
1066 name: "recovery_available_bin",
1067 recovery_available: true,
1068 nocrt: true,
1069 }
1070
1071 toolchain_library {
1072 name: "libb",
1073 recovery_available: true,
1074 src: "libb.a",
1075 }
1076
1077 cc_object {
1078 name: "obj",
1079 recovery_available: true,
1080 }
1081`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001082 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001083 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001084 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001085 ctx := testCcWithConfig(t, config)
1086
1087 // Check Recovery snapshot output.
1088
1089 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001090 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001091 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1092
1093 var jsonFiles []string
1094
1095 for _, arch := range [][]string{
1096 []string{"arm64", "armv8-a"},
1097 } {
1098 archType := arch[0]
1099 archVariant := arch[1]
1100 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1101
1102 // For shared libraries, only recovery_available modules are captured.
1103 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1104 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1105 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant)
1106 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1107 checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
1108 jsonFiles = append(jsonFiles,
1109 filepath.Join(sharedDir, "libvndk.so.json"),
1110 filepath.Join(sharedDir, "librecovery.so.json"),
1111 filepath.Join(sharedDir, "librecovery_available.so.json"))
1112
1113 // For static libraries, all recovery:true and recovery_available modules are captured.
1114 staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
1115 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
1116 checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
1117 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
1118 checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
1119 jsonFiles = append(jsonFiles,
1120 filepath.Join(staticDir, "libb.a.json"),
1121 filepath.Join(staticDir, "librecovery.a.json"),
1122 filepath.Join(staticDir, "librecovery_available.a.json"))
1123
1124 // For binary executables, all recovery:true and recovery_available modules are captured.
1125 if archType == "arm64" {
1126 binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1127 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
1128 checkSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
1129 checkSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
1130 jsonFiles = append(jsonFiles,
1131 filepath.Join(binaryDir, "recovery_bin.json"),
1132 filepath.Join(binaryDir, "recovery_available_bin.json"))
1133 }
1134
1135 // For header libraries, all vendor:true and vendor_available modules are captured.
1136 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
1137 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json"))
1138
1139 // For object modules, all vendor:true and vendor_available modules are captured.
1140 objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1141 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
1142 checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
1143 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
1144 }
1145
1146 for _, jsonFile := range jsonFiles {
1147 // verify all json files exist
1148 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1149 t.Errorf("%q expected but not found", jsonFile)
1150 }
1151 }
1152}
1153
1154func TestRecoverySnapshotExclude(t *testing.T) {
1155 // This test verifies that the exclude_from_recovery_snapshot property
1156 // makes its way from the Android.bp source file into the module data
1157 // structure. It also verifies that modules are correctly included or
1158 // excluded in the recovery snapshot based on their path (framework or
1159 // vendor) and the exclude_from_recovery_snapshot property.
1160
1161 frameworkBp := `
1162 cc_library_shared {
1163 name: "libinclude",
1164 srcs: ["src/include.cpp"],
1165 recovery_available: true,
1166 }
1167 cc_library_shared {
1168 name: "libexclude",
1169 srcs: ["src/exclude.cpp"],
1170 recovery: true,
1171 exclude_from_recovery_snapshot: true,
1172 }
1173 cc_library_shared {
1174 name: "libavailable_exclude",
1175 srcs: ["src/exclude.cpp"],
1176 recovery_available: true,
1177 exclude_from_recovery_snapshot: true,
1178 }
1179 `
1180
1181 vendorProprietaryBp := `
1182 cc_library_shared {
1183 name: "librecovery",
1184 srcs: ["recovery.cpp"],
1185 recovery: true,
1186 }
1187 `
1188
1189 depsBp := GatherRequiredDepsForTest(android.Android)
1190
1191 mockFS := map[string][]byte{
1192 "deps/Android.bp": []byte(depsBp),
1193 "framework/Android.bp": []byte(frameworkBp),
1194 "framework/include.cpp": nil,
1195 "framework/exclude.cpp": nil,
1196 "device/Android.bp": []byte(vendorProprietaryBp),
1197 "device/recovery.cpp": nil,
1198 }
1199
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001200 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001201 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001202 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001203 ctx := CreateTestContext(config)
1204 ctx.Register()
1205
1206 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1207 android.FailIfErrored(t, errs)
1208 _, errs = ctx.PrepareBuildActions(config)
1209 android.FailIfErrored(t, errs)
1210
1211 // Test an include and exclude framework module.
1212 assertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false)
1213 assertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true)
1214 assertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true)
1215
1216 // A recovery module is excluded, but by its path, not the
1217 // exclude_from_recovery_snapshot property.
1218 assertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false)
1219
1220 // Verify the content of the recovery snapshot.
1221
1222 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001223 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001224 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1225
1226 var includeJsonFiles []string
1227 var excludeJsonFiles []string
1228
1229 for _, arch := range [][]string{
1230 []string{"arm64", "armv8-a"},
1231 } {
1232 archType := arch[0]
1233 archVariant := arch[1]
1234 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1235
1236 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1237 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1238
1239 // Included modules
1240 checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
1241 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1242
1243 // Excluded modules
1244 checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
1245 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
1246 checkSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1247 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1248 checkSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
1249 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1250 }
1251
1252 // Verify that each json file for an included module has a rule.
1253 for _, jsonFile := range includeJsonFiles {
1254 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1255 t.Errorf("include json file %q not found", jsonFile)
1256 }
1257 }
1258
1259 // Verify that each json file for an excluded module has no rule.
1260 for _, jsonFile := range excludeJsonFiles {
1261 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1262 t.Errorf("exclude json file %q found", jsonFile)
1263 }
1264 }
1265}
Jose Galmes4c6895e2021-02-09 07:44:30 -08001266
1267func TestRecoverySnapshotDirected(t *testing.T) {
1268 bp := `
1269 cc_library_shared {
1270 name: "librecovery",
1271 recovery: true,
1272 nocrt: true,
1273 }
1274
1275 cc_library_shared {
1276 name: "librecovery_available",
1277 recovery_available: true,
1278 nocrt: true,
1279 }
1280
1281 genrule {
1282 name: "libfoo_gen",
1283 cmd: "",
1284 out: ["libfoo.so"],
1285 }
1286
1287 cc_prebuilt_library_shared {
1288 name: "libfoo",
1289 recovery: true,
1290 prefer: true,
1291 srcs: [":libfoo_gen"],
1292 }
1293
1294 cc_library_shared {
1295 name: "libfoo",
1296 recovery: true,
1297 nocrt: true,
1298 }
1299`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001300 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001301 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1302 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001303 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001304 config.TestProductVariables.DirectedRecoverySnapshot = true
1305 config.TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
1306 config.TestProductVariables.RecoverySnapshotModules["librecovery"] = true
1307 config.TestProductVariables.RecoverySnapshotModules["libfoo"] = true
1308 ctx := testCcWithConfig(t, config)
1309
1310 // Check recovery snapshot output.
1311
1312 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001313 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001314 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1315
1316 var includeJsonFiles []string
1317
1318 for _, arch := range [][]string{
1319 []string{"arm64", "armv8-a"},
1320 } {
1321 archType := arch[0]
1322 archVariant := arch[1]
1323 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1324
1325 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1326 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1327
1328 // Included modules
1329 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1330 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1331 // Check that snapshot captures "prefer: true" prebuilt
1332 checkSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
1333 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
1334
1335 // Excluded modules. Modules not included in the directed recovery snapshot
1336 // are still include as fake modules.
1337 checkSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
1338 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json"))
1339 }
1340
1341 // Verify that each json file for an included module has a rule.
1342 for _, jsonFile := range includeJsonFiles {
1343 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1344 t.Errorf("include json file %q not found", jsonFile)
1345 }
1346 }
1347}