blob: ed9e9d6e231110f3420dcde1a9e2f2981bc3f49e [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",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900337 version: "30",
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",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900381 version: "30",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700382 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
Inseob Kimf7aadf72021-04-13 10:15:31 +0900427 cc_library_shared {
428 name: "libclient_cfi",
429 vendor: true,
430 nocrt: true,
431 no_libcrt: true,
432 stl: "none",
433 system_shared_libs: [],
434 static_libs: ["libvendor"],
435 sanitize: {
436 cfi: true,
437 },
438 srcs: ["client.cpp"],
439 }
440
Colin Cross0fce0ba2021-01-08 16:40:12 -0800441 cc_binary {
442 name: "bin_without_snapshot",
443 vendor: true,
444 nocrt: true,
445 no_libcrt: true,
Inseob Kimd4c9f552021-04-08 19:28:28 +0900446 stl: "libc++_static",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800447 system_shared_libs: [],
448 static_libs: ["libvndk"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800449 srcs: ["bin.cpp"],
450 }
451
Colin Crosse0edaf92021-01-11 17:31:17 -0800452 vendor_snapshot {
453 name: "vendor_snapshot",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900454 version: "30",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700455 arch: {
456 arm64: {
457 vndk_libs: [
458 "libvndk",
459 ],
460 static_libs: [
Inseob Kimd4c9f552021-04-08 19:28:28 +0900461 "libc++_static",
462 "libc++demangle",
463 "libgcc_stripped",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700464 "libvendor",
465 "libvendor_available",
466 "libvndk",
467 "lib64",
468 ],
469 shared_libs: [
470 "libvendor",
471 "libvendor_available",
472 "lib64",
473 ],
474 binaries: [
475 "bin",
476 ],
477 },
478 arm: {
479 vndk_libs: [
480 "libvndk",
481 ],
482 static_libs: [
483 "libvendor",
484 "libvendor_available",
485 "libvndk",
486 "lib32",
487 ],
488 shared_libs: [
489 "libvendor",
490 "libvendor_available",
491 "lib32",
492 ],
493 binaries: [
494 "bin32",
495 ],
496 },
497 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800498 }
499
Colin Cross0fce0ba2021-01-08 16:40:12 -0800500 vendor_snapshot_static {
501 name: "libvndk",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900502 version: "30",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800503 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700504 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800505 vendor: true,
506 arch: {
507 arm64: {
508 src: "libvndk.a",
509 export_include_dirs: ["include/libvndk"],
510 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700511 arm: {
512 src: "libvndk.a",
513 export_include_dirs: ["include/libvndk"],
514 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800515 },
516 }
517
518 vendor_snapshot_shared {
519 name: "libvendor",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900520 version: "30",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800521 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700522 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800523 vendor: true,
Justin Yun48138672021-02-25 18:21:27 +0900524 shared_libs: [
525 "libvendor_without_snapshot",
526 "libvendor_available",
Justin Yun07b9f862021-02-26 14:00:03 +0900527 "libvndk",
Justin Yun48138672021-02-25 18:21:27 +0900528 ],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800529 arch: {
530 arm64: {
531 src: "libvendor.so",
532 export_include_dirs: ["include/libvendor"],
533 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700534 arm: {
535 src: "libvendor.so",
536 export_include_dirs: ["include/libvendor"],
537 },
538 },
539 }
540
541 vendor_snapshot_static {
542 name: "lib32",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900543 version: "30",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700544 target_arch: "arm64",
545 compile_multilib: "32",
546 vendor: true,
547 arch: {
548 arm: {
549 src: "lib32.a",
550 },
551 },
552 }
553
554 vendor_snapshot_shared {
555 name: "lib32",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900556 version: "30",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700557 target_arch: "arm64",
558 compile_multilib: "32",
559 vendor: true,
560 arch: {
561 arm: {
562 src: "lib32.so",
563 },
564 },
565 }
566
567 vendor_snapshot_static {
568 name: "lib64",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900569 version: "30",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700570 target_arch: "arm64",
571 compile_multilib: "64",
572 vendor: true,
573 arch: {
574 arm64: {
575 src: "lib64.a",
576 },
577 },
578 }
579
580 vendor_snapshot_shared {
581 name: "lib64",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900582 version: "30",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700583 target_arch: "arm64",
584 compile_multilib: "64",
585 vendor: true,
586 arch: {
587 arm64: {
588 src: "lib64.so",
589 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800590 },
591 }
592
593 vendor_snapshot_static {
594 name: "libvendor",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900595 version: "30",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800596 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700597 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800598 vendor: true,
599 arch: {
600 arm64: {
Inseob Kimf7aadf72021-04-13 10:15:31 +0900601 cfi: {
602 src: "libvendor.cfi.a",
603 export_include_dirs: ["include/libvendor_cfi"],
604 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800605 src: "libvendor.a",
606 export_include_dirs: ["include/libvendor"],
607 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700608 arm: {
Inseob Kimf7aadf72021-04-13 10:15:31 +0900609 cfi: {
610 src: "libvendor.cfi.a",
611 export_include_dirs: ["include/libvendor_cfi"],
612 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700613 src: "libvendor.a",
614 export_include_dirs: ["include/libvendor"],
615 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800616 },
617 }
618
Colin Cross2e577f32021-01-22 13:06:25 -0800619 vendor_snapshot_shared {
620 name: "libvendor_available",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900621 version: "30",
Colin Cross2e577f32021-01-22 13:06:25 -0800622 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700623 compile_multilib: "both",
Colin Cross2e577f32021-01-22 13:06:25 -0800624 vendor: true,
625 arch: {
626 arm64: {
627 src: "libvendor_available.so",
628 export_include_dirs: ["include/libvendor"],
629 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700630 arm: {
631 src: "libvendor_available.so",
632 export_include_dirs: ["include/libvendor"],
633 },
Colin Cross2e577f32021-01-22 13:06:25 -0800634 },
635 }
636
637 vendor_snapshot_static {
638 name: "libvendor_available",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900639 version: "30",
Colin Cross2e577f32021-01-22 13:06:25 -0800640 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700641 compile_multilib: "both",
Colin Cross2e577f32021-01-22 13:06:25 -0800642 vendor: true,
643 arch: {
644 arm64: {
645 src: "libvendor_available.a",
646 export_include_dirs: ["include/libvendor"],
647 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700648 arm: {
649 src: "libvendor_available.so",
650 export_include_dirs: ["include/libvendor"],
651 },
Colin Cross2e577f32021-01-22 13:06:25 -0800652 },
653 }
654
Inseob Kimd4c9f552021-04-08 19:28:28 +0900655 vendor_snapshot_static {
656 name: "libc++_static",
657 version: "30",
658 target_arch: "arm64",
659 compile_multilib: "64",
660 vendor: true,
661 arch: {
662 arm64: {
663 src: "libc++_static.a",
664 },
665 },
666 }
667
668 vendor_snapshot_static {
669 name: "libc++demangle",
670 version: "30",
671 target_arch: "arm64",
672 compile_multilib: "64",
673 vendor: true,
674 arch: {
675 arm64: {
676 src: "libc++demangle.a",
677 },
678 },
679 }
680
681 vendor_snapshot_static {
682 name: "libgcc_stripped",
683 version: "30",
684 target_arch: "arm64",
685 compile_multilib: "64",
686 vendor: true,
687 arch: {
688 arm64: {
689 src: "libgcc_stripped.a",
690 },
691 },
692 }
693
Colin Cross0fce0ba2021-01-08 16:40:12 -0800694 vendor_snapshot_binary {
695 name: "bin",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900696 version: "30",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800697 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700698 compile_multilib: "64",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800699 vendor: true,
700 arch: {
701 arm64: {
702 src: "bin",
703 },
704 },
705 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800706
Jose Galmesf9523ed2021-04-06 19:48:10 -0700707 vendor_snapshot_binary {
708 name: "bin32",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900709 version: "30",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700710 target_arch: "arm64",
711 compile_multilib: "32",
712 vendor: true,
713 arch: {
714 arm: {
715 src: "bin32",
716 },
717 },
718 }
719
Colin Crosse0edaf92021-01-11 17:31:17 -0800720 // old snapshot module which has to be ignored
721 vendor_snapshot_binary {
722 name: "bin",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900723 version: "26",
Colin Crosse0edaf92021-01-11 17:31:17 -0800724 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700725 compile_multilib: "first",
726 vendor: true,
727 arch: {
728 arm64: {
729 src: "bin",
730 },
731 },
732 }
733
734 // different arch snapshot which has to be ignored
735 vendor_snapshot_binary {
736 name: "bin",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900737 version: "30",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700738 target_arch: "arm",
739 compile_multilib: "first",
Colin Crosse0edaf92021-01-11 17:31:17 -0800740 vendor: true,
741 arch: {
742 arm64: {
743 src: "bin",
744 },
745 },
746 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800747`
748 depsBp := GatherRequiredDepsForTest(android.Android)
749
750 mockFS := map[string][]byte{
Inseob Kimf7aadf72021-04-13 10:15:31 +0900751 "deps/Android.bp": []byte(depsBp),
752 "framework/Android.bp": []byte(frameworkBp),
753 "framework/symbol.txt": nil,
754 "vendor/Android.bp": []byte(vendorProprietaryBp),
755 "vendor/bin": nil,
756 "vendor/bin32": nil,
757 "vendor/bin.cpp": nil,
758 "vendor/client.cpp": nil,
759 "vendor/include/libvndk/a.h": nil,
760 "vendor/include/libvendor/b.h": nil,
761 "vendor/include/libvendor_cfi/c.h": nil,
762 "vendor/libc++_static.a": nil,
763 "vendor/libc++demangle.a": nil,
764 "vendor/libgcc_striped.a": nil,
765 "vendor/libvndk.a": nil,
766 "vendor/libvendor.a": nil,
767 "vendor/libvendor.cfi.a": nil,
768 "vendor/libvendor.so": nil,
769 "vendor/lib32.a": nil,
770 "vendor/lib32.so": nil,
771 "vendor/lib64.a": nil,
772 "vendor/lib64.so": nil,
773 "vndk/Android.bp": []byte(vndkBp),
774 "vndk/include/libvndk/a.h": nil,
775 "vndk/libvndk.so": nil,
Colin Cross0fce0ba2021-01-08 16:40:12 -0800776 }
777
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000778 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Inseob Kimd4c9f552021-04-08 19:28:28 +0900779 config.TestProductVariables.DeviceVndkVersion = StringPtr("30")
780 config.TestProductVariables.Platform_vndk_version = StringPtr("31")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800781 ctx := CreateTestContext(config)
782 ctx.Register()
783
784 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "vendor/Android.bp", "vndk/Android.bp"})
785 android.FailIfErrored(t, errs)
786 _, errs = ctx.PrepareBuildActions(config)
787 android.FailIfErrored(t, errs)
788
Inseob Kimd4c9f552021-04-08 19:28:28 +0900789 sharedVariant := "android_vendor.30_arm64_armv8-a_shared"
790 staticVariant := "android_vendor.30_arm64_armv8-a_static"
791 binaryVariant := "android_vendor.30_arm64_armv8-a"
Colin Cross0fce0ba2021-01-08 16:40:12 -0800792
Inseob Kimf7aadf72021-04-13 10:15:31 +0900793 sharedCfiVariant := "android_vendor.30_arm64_armv8-a_shared_cfi"
794 staticCfiVariant := "android_vendor.30_arm64_armv8-a_static_cfi"
795
Inseob Kimd4c9f552021-04-08 19:28:28 +0900796 shared32Variant := "android_vendor.30_arm_armv7-a-neon_shared"
797 binary32Variant := "android_vendor.30_arm_armv7-a-neon"
Jose Galmesf9523ed2021-04-06 19:48:10 -0700798
Inseob Kimd4c9f552021-04-08 19:28:28 +0900799 // libclient uses libvndk.vndk.30.arm64, libvendor.vendor_static.30.arm64, libvendor_without_snapshot
Colin Cross0fce0ba2021-01-08 16:40:12 -0800800 libclientCcFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("cc").Args["cFlags"]
801 for _, includeFlags := range []string{
802 "-Ivndk/include/libvndk", // libvndk
803 "-Ivendor/include/libvendor", // libvendor
804 } {
805 if !strings.Contains(libclientCcFlags, includeFlags) {
806 t.Errorf("flags for libclient must contain %#v, but was %#v.",
807 includeFlags, libclientCcFlags)
808 }
809 }
810
811 libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("ld").Args["libFlags"]
812 for _, input := range [][]string{
Inseob Kimd4c9f552021-04-08 19:28:28 +0900813 []string{sharedVariant, "libvndk.vndk.30.arm64"},
814 []string{staticVariant, "libvendor.vendor_static.30.arm64"},
Colin Cross0fce0ba2021-01-08 16:40:12 -0800815 []string{staticVariant, "libvendor_without_snapshot"},
816 } {
817 outputPaths := getOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */)
818 if !strings.Contains(libclientLdFlags, outputPaths[0].String()) {
819 t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags)
820 }
821 }
822
Colin Cross2e577f32021-01-22 13:06:25 -0800823 libclientAndroidMkSharedLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkSharedLibs
Jose Galmesf9523ed2021-04-06 19:48:10 -0700824 if g, w := libclientAndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "lib64"}; !reflect.DeepEqual(g, w) {
Colin Cross2e577f32021-01-22 13:06:25 -0800825 t.Errorf("wanted libclient AndroidMkSharedLibs %q, got %q", w, g)
826 }
827
828 libclientAndroidMkStaticLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkStaticLibs
829 if g, w := libclientAndroidMkStaticLibs, []string{"libvendor", "libvendor_without_snapshot"}; !reflect.DeepEqual(g, w) {
830 t.Errorf("wanted libclient AndroidMkStaticLibs %q, got %q", w, g)
831 }
832
Jose Galmesf9523ed2021-04-06 19:48:10 -0700833 libclient32AndroidMkSharedLibs := ctx.ModuleForTests("libclient", shared32Variant).Module().(*Module).Properties.AndroidMkSharedLibs
834 if g, w := libclient32AndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "lib32"}; !reflect.DeepEqual(g, w) {
835 t.Errorf("wanted libclient32 AndroidMkSharedLibs %q, got %q", w, g)
836 }
837
Inseob Kimf7aadf72021-04-13 10:15:31 +0900838 // libclient_cfi uses libvendor.vendor_static.30.arm64's cfi variant
839 libclientCfiCcFlags := ctx.ModuleForTests("libclient_cfi", sharedCfiVariant).Rule("cc").Args["cFlags"]
840 if !strings.Contains(libclientCfiCcFlags, "-Ivendor/include/libvendor_cfi") {
841 t.Errorf("flags for libclient_cfi must contain %#v, but was %#v.",
842 "-Ivendor/include/libvendor_cfi", libclientCfiCcFlags)
843 }
844
845 libclientCfiLdFlags := ctx.ModuleForTests("libclient_cfi", sharedCfiVariant).Rule("ld").Args["libFlags"]
846 libvendorCfiOutputPaths := getOutputPaths(ctx, staticCfiVariant, []string{"libvendor.vendor_static.30.arm64"})
847 if !strings.Contains(libclientCfiLdFlags, libvendorCfiOutputPaths[0].String()) {
848 t.Errorf("libflags for libclientCfi must contain %#v, but was %#v", libvendorCfiOutputPaths[0], libclientCfiLdFlags)
849 }
850
Inseob Kimd4c9f552021-04-08 19:28:28 +0900851 // bin_without_snapshot uses libvndk.vendor_static.30.arm64
Colin Cross0fce0ba2021-01-08 16:40:12 -0800852 binWithoutSnapshotCcFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("cc").Args["cFlags"]
853 if !strings.Contains(binWithoutSnapshotCcFlags, "-Ivendor/include/libvndk") {
854 t.Errorf("flags for bin_without_snapshot must contain %#v, but was %#v.",
855 "-Ivendor/include/libvndk", binWithoutSnapshotCcFlags)
856 }
857
858 binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("ld").Args["libFlags"]
Inseob Kimd4c9f552021-04-08 19:28:28 +0900859 libVndkStaticOutputPaths := getOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.30.arm64"})
Colin Cross0fce0ba2021-01-08 16:40:12 -0800860 if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) {
861 t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v",
862 libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags)
863 }
864
Inseob Kimd4c9f552021-04-08 19:28:28 +0900865 // libvendor.so is installed by libvendor.vendor_shared.30.arm64
866 ctx.ModuleForTests("libvendor.vendor_shared.30.arm64", sharedVariant).Output("libvendor.so")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800867
Inseob Kimd4c9f552021-04-08 19:28:28 +0900868 // lib64.so is installed by lib64.vendor_shared.30.arm64
869 ctx.ModuleForTests("lib64.vendor_shared.30.arm64", sharedVariant).Output("lib64.so")
Jose Galmesf9523ed2021-04-06 19:48:10 -0700870
Inseob Kimd4c9f552021-04-08 19:28:28 +0900871 // lib32.so is installed by lib32.vendor_shared.30.arm64
872 ctx.ModuleForTests("lib32.vendor_shared.30.arm64", shared32Variant).Output("lib32.so")
Jose Galmesf9523ed2021-04-06 19:48:10 -0700873
Inseob Kimd4c9f552021-04-08 19:28:28 +0900874 // libvendor_available.so is installed by libvendor_available.vendor_shared.30.arm64
875 ctx.ModuleForTests("libvendor_available.vendor_shared.30.arm64", sharedVariant).Output("libvendor_available.so")
Colin Cross2e577f32021-01-22 13:06:25 -0800876
Colin Cross0fce0ba2021-01-08 16:40:12 -0800877 // libvendor_without_snapshot.so is installed by libvendor_without_snapshot
878 ctx.ModuleForTests("libvendor_without_snapshot", sharedVariant).Output("libvendor_without_snapshot.so")
879
Inseob Kimd4c9f552021-04-08 19:28:28 +0900880 // bin is installed by bin.vendor_binary.30.arm64
881 ctx.ModuleForTests("bin.vendor_binary.30.arm64", binaryVariant).Output("bin")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800882
Inseob Kimd4c9f552021-04-08 19:28:28 +0900883 // bin32 is installed by bin32.vendor_binary.30.arm64
884 ctx.ModuleForTests("bin32.vendor_binary.30.arm64", binary32Variant).Output("bin32")
Jose Galmesf9523ed2021-04-06 19:48:10 -0700885
Colin Cross0fce0ba2021-01-08 16:40:12 -0800886 // bin_without_snapshot is installed by bin_without_snapshot
887 ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot")
888
Inseob Kimd4c9f552021-04-08 19:28:28 +0900889 // libvendor, libvendor_available and bin don't have vendor.30 variant
Colin Cross0fce0ba2021-01-08 16:40:12 -0800890 libvendorVariants := ctx.ModuleVariantsForTests("libvendor")
891 if inList(sharedVariant, libvendorVariants) {
892 t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant)
893 }
894
Colin Cross2e577f32021-01-22 13:06:25 -0800895 libvendorAvailableVariants := ctx.ModuleVariantsForTests("libvendor_available")
896 if inList(sharedVariant, libvendorAvailableVariants) {
897 t.Errorf("libvendor_available must not have variant %#v, but it does", sharedVariant)
898 }
899
Colin Cross0fce0ba2021-01-08 16:40:12 -0800900 binVariants := ctx.ModuleVariantsForTests("bin")
901 if inList(binaryVariant, binVariants) {
902 t.Errorf("bin must not have variant %#v, but it does", sharedVariant)
903 }
904}
905
906func TestVendorSnapshotSanitizer(t *testing.T) {
907 bp := `
Inseob Kim253f5212021-04-08 17:10:31 +0900908 vendor_snapshot {
909 name: "vendor_snapshot",
910 version: "28",
911 arch: {
912 arm64: {
913 static_libs: [
914 "libsnapshot",
915 "note_memtag_heap_sync",
916 ],
917 },
918 },
919 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800920 vendor_snapshot_static {
921 name: "libsnapshot",
922 vendor: true,
923 target_arch: "arm64",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900924 version: "28",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800925 arch: {
926 arm64: {
927 src: "libsnapshot.a",
928 cfi: {
929 src: "libsnapshot.cfi.a",
930 }
931 },
932 },
933 }
Inseob Kim253f5212021-04-08 17:10:31 +0900934
935 vendor_snapshot_static {
936 name: "note_memtag_heap_sync",
937 vendor: true,
938 target_arch: "arm64",
939 version: "28",
940 arch: {
941 arm64: {
942 src: "note_memtag_heap_sync.a",
943 },
944 },
945 }
946
947 cc_test {
948 name: "vstest",
949 gtest: false,
950 vendor: true,
951 compile_multilib: "64",
952 nocrt: true,
953 no_libcrt: true,
954 stl: "none",
955 static_libs: ["libsnapshot"],
956 system_shared_libs: [],
957 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800958`
Inseob Kim253f5212021-04-08 17:10:31 +0900959
960 mockFS := map[string][]byte{
961 "vendor/Android.bp": []byte(bp),
962 "vendor/libc++demangle.a": nil,
963 "vendor/libsnapshot.a": nil,
964 "vendor/libsnapshot.cfi.a": nil,
965 "vendor/note_memtag_heap_sync.a": nil,
966 }
967
968 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900969 config.TestProductVariables.DeviceVndkVersion = StringPtr("28")
970 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800971 ctx := testCcWithConfig(t, config)
972
973 // Check non-cfi and cfi variant.
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900974 staticVariant := "android_vendor.28_arm64_armv8-a_static"
975 staticCfiVariant := "android_vendor.28_arm64_armv8-a_static_cfi"
Colin Cross0fce0ba2021-01-08 16:40:12 -0800976
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900977 staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800978 assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a")
979
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900980 staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticCfiVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800981 assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
982}
983
984func assertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool) {
985 t.Helper()
986 m := ctx.ModuleForTests(name, vendorVariant).Module().(*Module)
987 if m.ExcludeFromVendorSnapshot() != expected {
988 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
989 }
990}
991
992func assertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool) {
993 t.Helper()
994 m := ctx.ModuleForTests(name, recoveryVariant).Module().(*Module)
995 if m.ExcludeFromRecoverySnapshot() != expected {
996 t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", m.String(), expected)
997 }
998}
999
1000func TestVendorSnapshotExclude(t *testing.T) {
1001
1002 // This test verifies that the exclude_from_vendor_snapshot property
1003 // makes its way from the Android.bp source file into the module data
1004 // structure. It also verifies that modules are correctly included or
1005 // excluded in the vendor snapshot based on their path (framework or
1006 // vendor) and the exclude_from_vendor_snapshot property.
1007
1008 frameworkBp := `
1009 cc_library_shared {
1010 name: "libinclude",
1011 srcs: ["src/include.cpp"],
1012 vendor_available: true,
1013 }
1014 cc_library_shared {
1015 name: "libexclude",
1016 srcs: ["src/exclude.cpp"],
1017 vendor: true,
1018 exclude_from_vendor_snapshot: true,
1019 }
1020 cc_library_shared {
1021 name: "libavailable_exclude",
1022 srcs: ["src/exclude.cpp"],
1023 vendor_available: true,
1024 exclude_from_vendor_snapshot: true,
1025 }
1026 `
1027
1028 vendorProprietaryBp := `
1029 cc_library_shared {
1030 name: "libvendor",
1031 srcs: ["vendor.cpp"],
1032 vendor: true,
1033 }
1034 `
1035
1036 depsBp := GatherRequiredDepsForTest(android.Android)
1037
1038 mockFS := map[string][]byte{
1039 "deps/Android.bp": []byte(depsBp),
1040 "framework/Android.bp": []byte(frameworkBp),
1041 "framework/include.cpp": nil,
1042 "framework/exclude.cpp": nil,
1043 "device/Android.bp": []byte(vendorProprietaryBp),
1044 "device/vendor.cpp": nil,
1045 }
1046
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001047 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001048 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001049 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001050 ctx := CreateTestContext(config)
1051 ctx.Register()
1052
1053 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1054 android.FailIfErrored(t, errs)
1055 _, errs = ctx.PrepareBuildActions(config)
1056 android.FailIfErrored(t, errs)
1057
1058 // Test an include and exclude framework module.
1059 assertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false)
1060 assertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true)
1061 assertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true)
1062
1063 // A vendor module is excluded, but by its path, not the
1064 // exclude_from_vendor_snapshot property.
1065 assertExcludeFromVendorSnapshotIs(t, ctx, "libvendor", false)
1066
1067 // Verify the content of the vendor snapshot.
1068
1069 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001070 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001071 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1072
1073 var includeJsonFiles []string
1074 var excludeJsonFiles []string
1075
1076 for _, arch := range [][]string{
1077 []string{"arm64", "armv8-a"},
1078 []string{"arm", "armv7-a-neon"},
1079 } {
1080 archType := arch[0]
1081 archVariant := arch[1]
1082 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1083
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001084 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001085 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1086
1087 // Included modules
1088 checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
1089 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1090
1091 // Excluded modules
1092 checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
1093 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
1094 checkSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
1095 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
1096 checkSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
1097 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1098 }
1099
1100 // Verify that each json file for an included module has a rule.
1101 for _, jsonFile := range includeJsonFiles {
1102 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1103 t.Errorf("include json file %q not found", jsonFile)
1104 }
1105 }
1106
1107 // Verify that each json file for an excluded module has no rule.
1108 for _, jsonFile := range excludeJsonFiles {
1109 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1110 t.Errorf("exclude json file %q found", jsonFile)
1111 }
1112 }
1113}
1114
1115func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) {
1116
1117 // This test verifies that using the exclude_from_vendor_snapshot
1118 // property on a module in a vendor proprietary path generates an
1119 // error. These modules are already excluded, so we prohibit using the
1120 // property in this way, which could add to confusion.
1121
1122 vendorProprietaryBp := `
1123 cc_library_shared {
1124 name: "libvendor",
1125 srcs: ["vendor.cpp"],
1126 vendor: true,
1127 exclude_from_vendor_snapshot: true,
1128 }
1129 `
1130
1131 depsBp := GatherRequiredDepsForTest(android.Android)
1132
1133 mockFS := map[string][]byte{
1134 "deps/Android.bp": []byte(depsBp),
1135 "device/Android.bp": []byte(vendorProprietaryBp),
1136 "device/vendor.cpp": nil,
1137 }
1138
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001139 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001140 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001141 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001142 ctx := CreateTestContext(config)
1143 ctx.Register()
1144
1145 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"})
1146 android.FailIfErrored(t, errs)
1147
1148 _, errs = ctx.PrepareBuildActions(config)
1149 android.CheckErrorsAgainstExpectations(t, errs, []string{
1150 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1151 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1152 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1153 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1154 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1155 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1156 })
1157}
1158
1159func TestRecoverySnapshotCapture(t *testing.T) {
1160 bp := `
1161 cc_library {
1162 name: "libvndk",
1163 vendor_available: true,
1164 recovery_available: true,
1165 product_available: true,
1166 vndk: {
1167 enabled: true,
1168 },
1169 nocrt: true,
1170 }
1171
1172 cc_library {
1173 name: "librecovery",
1174 recovery: true,
1175 nocrt: true,
1176 }
1177
1178 cc_library {
1179 name: "librecovery_available",
1180 recovery_available: true,
1181 nocrt: true,
1182 }
1183
1184 cc_library_headers {
1185 name: "librecovery_headers",
1186 recovery_available: true,
1187 nocrt: true,
1188 }
1189
1190 cc_binary {
1191 name: "recovery_bin",
1192 recovery: true,
1193 nocrt: true,
1194 }
1195
1196 cc_binary {
1197 name: "recovery_available_bin",
1198 recovery_available: true,
1199 nocrt: true,
1200 }
1201
1202 toolchain_library {
1203 name: "libb",
1204 recovery_available: true,
1205 src: "libb.a",
1206 }
1207
1208 cc_object {
1209 name: "obj",
1210 recovery_available: true,
1211 }
1212`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001213 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001214 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001215 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001216 ctx := testCcWithConfig(t, config)
1217
1218 // Check Recovery snapshot output.
1219
1220 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001221 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001222 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1223
1224 var jsonFiles []string
1225
1226 for _, arch := range [][]string{
1227 []string{"arm64", "armv8-a"},
1228 } {
1229 archType := arch[0]
1230 archVariant := arch[1]
1231 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1232
1233 // For shared libraries, only recovery_available modules are captured.
1234 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1235 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1236 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant)
1237 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1238 checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
1239 jsonFiles = append(jsonFiles,
1240 filepath.Join(sharedDir, "libvndk.so.json"),
1241 filepath.Join(sharedDir, "librecovery.so.json"),
1242 filepath.Join(sharedDir, "librecovery_available.so.json"))
1243
1244 // For static libraries, all recovery:true and recovery_available modules are captured.
1245 staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
1246 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
1247 checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
1248 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
1249 checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
1250 jsonFiles = append(jsonFiles,
1251 filepath.Join(staticDir, "libb.a.json"),
1252 filepath.Join(staticDir, "librecovery.a.json"),
1253 filepath.Join(staticDir, "librecovery_available.a.json"))
1254
1255 // For binary executables, all recovery:true and recovery_available modules are captured.
1256 if archType == "arm64" {
1257 binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1258 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
1259 checkSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
1260 checkSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
1261 jsonFiles = append(jsonFiles,
1262 filepath.Join(binaryDir, "recovery_bin.json"),
1263 filepath.Join(binaryDir, "recovery_available_bin.json"))
1264 }
1265
1266 // For header libraries, all vendor:true and vendor_available modules are captured.
1267 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
1268 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json"))
1269
1270 // For object modules, all vendor:true and vendor_available modules are captured.
1271 objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1272 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
1273 checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
1274 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
1275 }
1276
1277 for _, jsonFile := range jsonFiles {
1278 // verify all json files exist
1279 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1280 t.Errorf("%q expected but not found", jsonFile)
1281 }
1282 }
1283}
1284
1285func TestRecoverySnapshotExclude(t *testing.T) {
1286 // This test verifies that the exclude_from_recovery_snapshot property
1287 // makes its way from the Android.bp source file into the module data
1288 // structure. It also verifies that modules are correctly included or
1289 // excluded in the recovery snapshot based on their path (framework or
1290 // vendor) and the exclude_from_recovery_snapshot property.
1291
1292 frameworkBp := `
1293 cc_library_shared {
1294 name: "libinclude",
1295 srcs: ["src/include.cpp"],
1296 recovery_available: true,
1297 }
1298 cc_library_shared {
1299 name: "libexclude",
1300 srcs: ["src/exclude.cpp"],
1301 recovery: true,
1302 exclude_from_recovery_snapshot: true,
1303 }
1304 cc_library_shared {
1305 name: "libavailable_exclude",
1306 srcs: ["src/exclude.cpp"],
1307 recovery_available: true,
1308 exclude_from_recovery_snapshot: true,
1309 }
1310 `
1311
1312 vendorProprietaryBp := `
1313 cc_library_shared {
1314 name: "librecovery",
1315 srcs: ["recovery.cpp"],
1316 recovery: true,
1317 }
1318 `
1319
1320 depsBp := GatherRequiredDepsForTest(android.Android)
1321
1322 mockFS := map[string][]byte{
1323 "deps/Android.bp": []byte(depsBp),
1324 "framework/Android.bp": []byte(frameworkBp),
1325 "framework/include.cpp": nil,
1326 "framework/exclude.cpp": nil,
1327 "device/Android.bp": []byte(vendorProprietaryBp),
1328 "device/recovery.cpp": nil,
1329 }
1330
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001331 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001332 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001333 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001334 ctx := CreateTestContext(config)
1335 ctx.Register()
1336
1337 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1338 android.FailIfErrored(t, errs)
1339 _, errs = ctx.PrepareBuildActions(config)
1340 android.FailIfErrored(t, errs)
1341
1342 // Test an include and exclude framework module.
1343 assertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false)
1344 assertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true)
1345 assertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true)
1346
1347 // A recovery module is excluded, but by its path, not the
1348 // exclude_from_recovery_snapshot property.
1349 assertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false)
1350
1351 // Verify the content of the recovery snapshot.
1352
1353 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001354 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001355 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1356
1357 var includeJsonFiles []string
1358 var excludeJsonFiles []string
1359
1360 for _, arch := range [][]string{
1361 []string{"arm64", "armv8-a"},
1362 } {
1363 archType := arch[0]
1364 archVariant := arch[1]
1365 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1366
1367 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1368 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1369
1370 // Included modules
1371 checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
1372 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1373
1374 // Excluded modules
1375 checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
1376 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
1377 checkSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1378 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1379 checkSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
1380 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1381 }
1382
1383 // Verify that each json file for an included module has a rule.
1384 for _, jsonFile := range includeJsonFiles {
1385 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1386 t.Errorf("include json file %q not found", jsonFile)
1387 }
1388 }
1389
1390 // Verify that each json file for an excluded module has no rule.
1391 for _, jsonFile := range excludeJsonFiles {
1392 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1393 t.Errorf("exclude json file %q found", jsonFile)
1394 }
1395 }
1396}
Jose Galmes4c6895e2021-02-09 07:44:30 -08001397
1398func TestRecoverySnapshotDirected(t *testing.T) {
1399 bp := `
1400 cc_library_shared {
1401 name: "librecovery",
1402 recovery: true,
1403 nocrt: true,
1404 }
1405
1406 cc_library_shared {
1407 name: "librecovery_available",
1408 recovery_available: true,
1409 nocrt: true,
1410 }
1411
1412 genrule {
1413 name: "libfoo_gen",
1414 cmd: "",
1415 out: ["libfoo.so"],
1416 }
1417
1418 cc_prebuilt_library_shared {
1419 name: "libfoo",
1420 recovery: true,
1421 prefer: true,
1422 srcs: [":libfoo_gen"],
1423 }
1424
1425 cc_library_shared {
1426 name: "libfoo",
1427 recovery: true,
1428 nocrt: true,
1429 }
1430`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001431 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001432 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1433 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001434 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001435 config.TestProductVariables.DirectedRecoverySnapshot = true
1436 config.TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
1437 config.TestProductVariables.RecoverySnapshotModules["librecovery"] = true
1438 config.TestProductVariables.RecoverySnapshotModules["libfoo"] = true
1439 ctx := testCcWithConfig(t, config)
1440
1441 // Check recovery snapshot output.
1442
1443 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001444 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001445 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1446
1447 var includeJsonFiles []string
1448
1449 for _, arch := range [][]string{
1450 []string{"arm64", "armv8-a"},
1451 } {
1452 archType := arch[0]
1453 archVariant := arch[1]
1454 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1455
1456 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1457 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1458
1459 // Included modules
1460 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1461 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1462 // Check that snapshot captures "prefer: true" prebuilt
1463 checkSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
1464 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
1465
1466 // Excluded modules. Modules not included in the directed recovery snapshot
1467 // are still include as fake modules.
1468 checkSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
1469 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json"))
1470 }
1471
1472 // Verify that each json file for an included module has a rule.
1473 for _, jsonFile := range includeJsonFiles {
1474 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1475 t.Errorf("include json file %q not found", jsonFile)
1476 }
1477 }
1478}