blob: 79405e9c43e9976d9159e16cb0c00f40a433d78c [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 {
Inseob Kima1888ce2022-10-04 14:42:02 +090045 name: "libvendor_override",
46 vendor: true,
47 nocrt: true,
48 overrides: ["libvendor"],
49 }
50
51 cc_library {
Colin Cross0fce0ba2021-01-08 16:40:12 -080052 name: "libvendor_available",
53 vendor_available: true,
54 nocrt: true,
55 }
56
57 cc_library_headers {
58 name: "libvendor_headers",
59 vendor_available: true,
60 nocrt: true,
61 }
62
63 cc_binary {
64 name: "vendor_bin",
65 vendor: true,
66 nocrt: true,
67 }
68
69 cc_binary {
70 name: "vendor_available_bin",
71 vendor_available: true,
72 nocrt: true,
73 }
74
Inseob Kima1888ce2022-10-04 14:42:02 +090075 cc_binary {
76 name: "vendor_bin_override",
77 vendor: true,
78 nocrt: true,
79 overrides: ["vendor_bin"],
80 }
81
Liz Kammer718eb272022-01-07 10:53:37 -050082 cc_prebuilt_library_static {
Colin Cross0fce0ba2021-01-08 16:40:12 -080083 name: "libb",
84 vendor_available: true,
Liz Kammer718eb272022-01-07 10:53:37 -050085 srcs: ["libb.a"],
86 nocrt: true,
87 no_libcrt: true,
88 stl: "none",
Colin Cross0fce0ba2021-01-08 16:40:12 -080089 }
90
91 cc_object {
92 name: "obj",
93 vendor_available: true,
94 }
95
96 cc_library {
97 name: "libllndk",
Colin Cross203b4212021-04-26 17:19:41 -070098 llndk: {
99 symbol_file: "libllndk.map.txt",
100 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800101 }
102`
Colin Cross203b4212021-04-26 17:19:41 -0700103
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000104 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800105 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900106 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800107 ctx := testCcWithConfig(t, config)
108
109 // Check Vendor snapshot output.
110
111 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000112 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800113 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
114
115 var jsonFiles []string
116
117 for _, arch := range [][]string{
118 []string{"arm64", "armv8-a"},
119 []string{"arm", "armv7-a-neon"},
120 } {
121 archType := arch[0]
122 archVariant := arch[1]
123 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
124
125 // For shared libraries, only non-VNDK vendor_available modules are captured
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900126 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800127 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400128 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
129 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800130 jsonFiles = append(jsonFiles,
131 filepath.Join(sharedDir, "libvendor.so.json"),
132 filepath.Join(sharedDir, "libvendor_available.so.json"))
133
134 // LLNDK modules are not captured
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400135 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800136
137 // For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
138 // Also cfi variants are captured, except for prebuilts like toolchain_library
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900139 staticVariant := fmt.Sprintf("android_vendor.29_%s_%s_static", archType, archVariant)
140 staticCfiVariant := fmt.Sprintf("android_vendor.29_%s_%s_static_cfi", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800141 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400142 CheckSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
143 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.a", staticDir, staticVariant)
144 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.cfi.a", staticDir, staticCfiVariant)
145 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.a", staticDir, staticVariant)
146 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.cfi.a", staticDir, staticCfiVariant)
147 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.a", staticDir, staticVariant)
148 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.cfi.a", staticDir, staticCfiVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800149 jsonFiles = append(jsonFiles,
150 filepath.Join(staticDir, "libb.a.json"),
151 filepath.Join(staticDir, "libvndk.a.json"),
152 filepath.Join(staticDir, "libvndk.cfi.a.json"),
153 filepath.Join(staticDir, "libvendor.a.json"),
154 filepath.Join(staticDir, "libvendor.cfi.a.json"),
155 filepath.Join(staticDir, "libvendor_available.a.json"),
156 filepath.Join(staticDir, "libvendor_available.cfi.a.json"))
157
158 // For binary executables, all vendor:true and vendor_available modules are captured.
159 if archType == "arm64" {
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900160 binaryVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800161 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400162 CheckSnapshot(t, ctx, snapshotSingleton, "vendor_bin", "vendor_bin", binaryDir, binaryVariant)
163 CheckSnapshot(t, ctx, snapshotSingleton, "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800164 jsonFiles = append(jsonFiles,
165 filepath.Join(binaryDir, "vendor_bin.json"),
166 filepath.Join(binaryDir, "vendor_available_bin.json"))
Inseob Kima1888ce2022-10-04 14:42:02 +0900167
168 checkOverrides(t, ctx, snapshotSingleton, filepath.Join(binaryDir, "vendor_bin_override.json"), []string{"vendor_bin"})
Colin Cross0fce0ba2021-01-08 16:40:12 -0800169 }
170
171 // For header libraries, all vendor:true and vendor_available modules are captured.
172 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
173 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "libvendor_headers.json"))
174
175 // For object modules, all vendor:true and vendor_available modules are captured.
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900176 objectVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800177 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400178 CheckSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800179 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
Inseob Kima1888ce2022-10-04 14:42:02 +0900180
181 checkOverrides(t, ctx, snapshotSingleton, filepath.Join(sharedDir, "libvendor_override.so.json"), []string{"libvendor"})
Colin Cross0fce0ba2021-01-08 16:40:12 -0800182 }
183
184 for _, jsonFile := range jsonFiles {
185 // verify all json files exist
186 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
187 t.Errorf("%q expected but not found", jsonFile)
188 }
189 }
190
191 // fake snapshot should have all outputs in the normal snapshot.
192 fakeSnapshotSingleton := ctx.SingletonForTests("vendor-fake-snapshot")
193 for _, output := range snapshotSingleton.AllOutputs() {
194 fakeOutput := strings.Replace(output, "/vendor-snapshot/", "/fake/vendor-snapshot/", 1)
195 if fakeSnapshotSingleton.MaybeOutput(fakeOutput).Rule == nil {
196 t.Errorf("%q expected but not found", fakeOutput)
197 }
198 }
199}
200
201func TestVendorSnapshotDirected(t *testing.T) {
202 bp := `
203 cc_library_shared {
204 name: "libvendor",
205 vendor: true,
206 nocrt: true,
207 }
208
209 cc_library_shared {
210 name: "libvendor_available",
211 vendor_available: true,
212 nocrt: true,
213 }
214
215 genrule {
216 name: "libfoo_gen",
217 cmd: "",
218 out: ["libfoo.so"],
219 }
220
221 cc_prebuilt_library_shared {
222 name: "libfoo",
223 vendor: true,
224 prefer: true,
225 srcs: [":libfoo_gen"],
226 }
227
228 cc_library_shared {
229 name: "libfoo",
230 vendor: true,
231 nocrt: true,
232 }
233`
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000234 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800235 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900236 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800237 config.TestProductVariables.DirectedVendorSnapshot = true
238 config.TestProductVariables.VendorSnapshotModules = make(map[string]bool)
239 config.TestProductVariables.VendorSnapshotModules["libvendor"] = true
240 config.TestProductVariables.VendorSnapshotModules["libfoo"] = true
241 ctx := testCcWithConfig(t, config)
242
243 // Check Vendor snapshot output.
244
245 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000246 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800247 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
248
249 var includeJsonFiles []string
Colin Cross0fce0ba2021-01-08 16:40:12 -0800250
251 for _, arch := range [][]string{
252 []string{"arm64", "armv8-a"},
253 []string{"arm", "armv7-a-neon"},
254 } {
255 archType := arch[0]
256 archVariant := arch[1]
257 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
258
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900259 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800260 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
261
262 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400263 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800264 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
265 // Check that snapshot captures "prefer: true" prebuilt
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400266 CheckSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800267 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
268
Jose Galmes0a942a02021-02-03 14:23:15 -0800269 // Excluded modules. Modules not included in the directed vendor snapshot
270 // are still include as fake modules.
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400271 CheckSnapshotRule(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
Jose Galmes0a942a02021-02-03 14:23:15 -0800272 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libvendor_available.so.json"))
Colin Cross0fce0ba2021-01-08 16:40:12 -0800273 }
274
275 // Verify that each json file for an included module has a rule.
276 for _, jsonFile := range includeJsonFiles {
277 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
278 t.Errorf("include json file %q not found", jsonFile)
279 }
280 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800281}
282
283func TestVendorSnapshotUse(t *testing.T) {
284 frameworkBp := `
285 cc_library {
286 name: "libvndk",
287 vendor_available: true,
288 product_available: true,
289 vndk: {
290 enabled: true,
291 },
292 nocrt: true,
Colin Cross0fce0ba2021-01-08 16:40:12 -0800293 }
294
295 cc_library {
296 name: "libvendor",
297 vendor: true,
298 nocrt: true,
299 no_libcrt: true,
300 stl: "none",
301 system_shared_libs: [],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800302 }
303
Colin Cross2e577f32021-01-22 13:06:25 -0800304 cc_library {
305 name: "libvendor_available",
306 vendor_available: true,
307 nocrt: true,
308 no_libcrt: true,
309 stl: "none",
310 system_shared_libs: [],
Jose Galmesf9523ed2021-04-06 19:48:10 -0700311 }
312
313 cc_library {
314 name: "lib32",
315 vendor: true,
316 nocrt: true,
317 no_libcrt: true,
318 stl: "none",
319 system_shared_libs: [],
320 compile_multilib: "32",
321 }
322
323 cc_library {
324 name: "lib64",
325 vendor: true,
326 nocrt: true,
327 no_libcrt: true,
328 stl: "none",
329 system_shared_libs: [],
Colin Cross2e577f32021-01-22 13:06:25 -0800330 compile_multilib: "64",
331 }
332
Justin Yundee806f2021-05-18 23:10:00 +0900333 cc_library {
334 name: "libllndk",
335 llndk: {
336 symbol_file: "libllndk.map.txt",
337 },
338 }
339
Colin Cross0fce0ba2021-01-08 16:40:12 -0800340 cc_binary {
341 name: "bin",
342 vendor: true,
343 nocrt: true,
344 no_libcrt: true,
345 stl: "none",
346 system_shared_libs: [],
Jose Galmesf9523ed2021-04-06 19:48:10 -0700347 }
348
349 cc_binary {
350 name: "bin32",
351 vendor: true,
352 nocrt: true,
353 no_libcrt: true,
354 stl: "none",
355 system_shared_libs: [],
356 compile_multilib: "32",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800357 }
358`
359
360 vndkBp := `
361 vndk_prebuilt_shared {
362 name: "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900363 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800364 target_arch: "arm64",
365 vendor_available: true,
366 product_available: true,
367 vndk: {
368 enabled: true,
369 },
370 arch: {
371 arm64: {
372 srcs: ["libvndk.so"],
373 export_include_dirs: ["include/libvndk"],
374 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700375 arm: {
376 srcs: ["libvndk.so"],
377 export_include_dirs: ["include/libvndk"],
378 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800379 },
380 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800381
382 // old snapshot module which has to be ignored
383 vndk_prebuilt_shared {
384 name: "libvndk",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900385 version: "26",
Colin Crosse0edaf92021-01-11 17:31:17 -0800386 target_arch: "arm64",
387 vendor_available: true,
388 product_available: true,
389 vndk: {
390 enabled: true,
391 },
392 arch: {
393 arm64: {
394 srcs: ["libvndk.so"],
395 export_include_dirs: ["include/libvndk"],
396 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700397 arm: {
398 srcs: ["libvndk.so"],
399 export_include_dirs: ["include/libvndk"],
400 },
401 },
402 }
403
404 // different arch snapshot which has to be ignored
405 vndk_prebuilt_shared {
406 name: "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900407 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700408 target_arch: "arm",
409 vendor_available: true,
410 product_available: true,
411 vndk: {
412 enabled: true,
413 },
414 arch: {
415 arm: {
416 srcs: ["libvndk.so"],
417 export_include_dirs: ["include/libvndk"],
418 },
Colin Crosse0edaf92021-01-11 17:31:17 -0800419 },
420 }
Justin Yundee806f2021-05-18 23:10:00 +0900421
422 vndk_prebuilt_shared {
423 name: "libllndk",
424 version: "31",
425 target_arch: "arm64",
426 vendor_available: true,
427 product_available: true,
428 arch: {
429 arm64: {
430 srcs: ["libllndk.so"],
431 },
432 arm: {
433 srcs: ["libllndk.so"],
434 },
435 },
436 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800437`
438
439 vendorProprietaryBp := `
440 cc_library {
441 name: "libvendor_without_snapshot",
442 vendor: true,
443 nocrt: true,
444 no_libcrt: true,
445 stl: "none",
446 system_shared_libs: [],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800447 }
448
449 cc_library_shared {
450 name: "libclient",
451 vendor: true,
452 nocrt: true,
453 no_libcrt: true,
454 stl: "none",
455 system_shared_libs: [],
Justin Yundee806f2021-05-18 23:10:00 +0900456 shared_libs: ["libvndk", "libvendor_available", "libllndk"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800457 static_libs: ["libvendor", "libvendor_without_snapshot"],
Jose Galmesf9523ed2021-04-06 19:48:10 -0700458 arch: {
459 arm64: {
460 shared_libs: ["lib64"],
461 },
462 arm: {
463 shared_libs: ["lib32"],
464 },
465 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800466 srcs: ["client.cpp"],
467 }
468
Inseob Kimf7aadf72021-04-13 10:15:31 +0900469 cc_library_shared {
470 name: "libclient_cfi",
471 vendor: true,
472 nocrt: true,
473 no_libcrt: true,
474 stl: "none",
475 system_shared_libs: [],
476 static_libs: ["libvendor"],
477 sanitize: {
478 cfi: true,
479 },
480 srcs: ["client.cpp"],
481 }
482
Justin Yun27b95722021-07-28 17:04:44 +0900483 cc_library_shared {
484 name: "libvndkext",
485 vendor: true,
486 nocrt: true,
487 no_libcrt: true,
488 stl: "none",
489 system_shared_libs: [],
490 vndk: {
491 extends: "libvndk",
492 enabled: true,
493 }
494 }
495
Colin Cross0fce0ba2021-01-08 16:40:12 -0800496 cc_binary {
497 name: "bin_without_snapshot",
498 vendor: true,
499 nocrt: true,
500 no_libcrt: true,
Inseob Kimd4c9f552021-04-08 19:28:28 +0900501 stl: "libc++_static",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800502 system_shared_libs: [],
503 static_libs: ["libvndk"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800504 srcs: ["bin.cpp"],
505 }
506
Colin Crosse0edaf92021-01-11 17:31:17 -0800507 vendor_snapshot {
508 name: "vendor_snapshot",
Justin Yundee806f2021-05-18 23:10:00 +0900509 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700510 arch: {
511 arm64: {
512 vndk_libs: [
513 "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900514 "libllndk",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700515 ],
516 static_libs: [
Inseob Kimd4c9f552021-04-08 19:28:28 +0900517 "libc++_static",
518 "libc++demangle",
Justin Yundee806f2021-05-18 23:10:00 +0900519 "libunwind",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700520 "libvendor",
521 "libvendor_available",
522 "libvndk",
523 "lib64",
524 ],
525 shared_libs: [
526 "libvendor",
Inseob Kima1888ce2022-10-04 14:42:02 +0900527 "libvendor_override",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700528 "libvendor_available",
529 "lib64",
530 ],
531 binaries: [
532 "bin",
Inseob Kima1888ce2022-10-04 14:42:02 +0900533 "bin_override",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700534 ],
535 },
536 arm: {
537 vndk_libs: [
538 "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900539 "libllndk",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700540 ],
541 static_libs: [
542 "libvendor",
543 "libvendor_available",
544 "libvndk",
545 "lib32",
546 ],
547 shared_libs: [
548 "libvendor",
Inseob Kima1888ce2022-10-04 14:42:02 +0900549 "libvendor_override",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700550 "libvendor_available",
551 "lib32",
552 ],
553 binaries: [
554 "bin32",
555 ],
556 },
557 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800558 }
559
Colin Cross0fce0ba2021-01-08 16:40:12 -0800560 vendor_snapshot_static {
561 name: "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900562 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800563 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700564 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800565 vendor: true,
566 arch: {
567 arm64: {
568 src: "libvndk.a",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800569 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700570 arm: {
571 src: "libvndk.a",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700572 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800573 },
Inseob Kimdd0295d2021-04-12 21:09:59 +0900574 shared_libs: ["libvndk"],
575 export_shared_lib_headers: ["libvndk"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800576 }
577
578 vendor_snapshot_shared {
579 name: "libvendor",
Justin Yundee806f2021-05-18 23:10:00 +0900580 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800581 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700582 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800583 vendor: true,
Justin Yun48138672021-02-25 18:21:27 +0900584 shared_libs: [
585 "libvendor_without_snapshot",
586 "libvendor_available",
Justin Yun07b9f862021-02-26 14:00:03 +0900587 "libvndk",
Justin Yun48138672021-02-25 18:21:27 +0900588 ],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800589 arch: {
590 arm64: {
591 src: "libvendor.so",
592 export_include_dirs: ["include/libvendor"],
593 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700594 arm: {
595 src: "libvendor.so",
596 export_include_dirs: ["include/libvendor"],
597 },
598 },
599 }
600
Inseob Kima1888ce2022-10-04 14:42:02 +0900601 vendor_snapshot_shared {
602 name: "libvendor_override",
603 version: "31",
604 target_arch: "arm64",
605 compile_multilib: "both",
606 vendor: true,
607 overrides: ["libvendor"],
608 shared_libs: [
609 "libvendor_without_snapshot",
610 "libvendor_available",
611 "libvndk",
612 ],
613 arch: {
614 arm64: {
615 src: "override/libvendor.so",
616 export_include_dirs: ["include/libvendor"],
617 },
618 arm: {
619 src: "override/libvendor.so",
620 export_include_dirs: ["include/libvendor"],
621 },
622 },
623 }
624
Jose Galmesf9523ed2021-04-06 19:48:10 -0700625 vendor_snapshot_static {
626 name: "lib32",
Justin Yundee806f2021-05-18 23:10:00 +0900627 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700628 target_arch: "arm64",
629 compile_multilib: "32",
630 vendor: true,
631 arch: {
632 arm: {
633 src: "lib32.a",
634 },
635 },
636 }
637
638 vendor_snapshot_shared {
639 name: "lib32",
Justin Yundee806f2021-05-18 23:10:00 +0900640 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700641 target_arch: "arm64",
642 compile_multilib: "32",
643 vendor: true,
644 arch: {
645 arm: {
646 src: "lib32.so",
647 },
648 },
649 }
650
651 vendor_snapshot_static {
652 name: "lib64",
Justin Yundee806f2021-05-18 23:10:00 +0900653 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700654 target_arch: "arm64",
655 compile_multilib: "64",
656 vendor: true,
657 arch: {
658 arm64: {
659 src: "lib64.a",
660 },
661 },
662 }
663
664 vendor_snapshot_shared {
665 name: "lib64",
Justin Yundee806f2021-05-18 23:10:00 +0900666 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700667 target_arch: "arm64",
668 compile_multilib: "64",
669 vendor: true,
670 arch: {
671 arm64: {
672 src: "lib64.so",
673 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800674 },
675 }
676
677 vendor_snapshot_static {
678 name: "libvendor",
Justin Yundee806f2021-05-18 23:10:00 +0900679 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800680 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700681 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800682 vendor: true,
683 arch: {
684 arm64: {
Inseob Kimf7aadf72021-04-13 10:15:31 +0900685 cfi: {
686 src: "libvendor.cfi.a",
687 export_include_dirs: ["include/libvendor_cfi"],
688 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800689 src: "libvendor.a",
690 export_include_dirs: ["include/libvendor"],
691 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700692 arm: {
Inseob Kimf7aadf72021-04-13 10:15:31 +0900693 cfi: {
694 src: "libvendor.cfi.a",
695 export_include_dirs: ["include/libvendor_cfi"],
696 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700697 src: "libvendor.a",
698 export_include_dirs: ["include/libvendor"],
699 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800700 },
701 }
702
Colin Cross2e577f32021-01-22 13:06:25 -0800703 vendor_snapshot_shared {
704 name: "libvendor_available",
Justin Yundee806f2021-05-18 23:10:00 +0900705 version: "31",
Colin Cross2e577f32021-01-22 13:06:25 -0800706 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700707 compile_multilib: "both",
Colin Cross2e577f32021-01-22 13:06:25 -0800708 vendor: true,
709 arch: {
710 arm64: {
711 src: "libvendor_available.so",
712 export_include_dirs: ["include/libvendor"],
713 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700714 arm: {
715 src: "libvendor_available.so",
716 export_include_dirs: ["include/libvendor"],
717 },
Colin Cross2e577f32021-01-22 13:06:25 -0800718 },
719 }
720
721 vendor_snapshot_static {
722 name: "libvendor_available",
Justin Yundee806f2021-05-18 23:10:00 +0900723 version: "31",
Colin Cross2e577f32021-01-22 13:06:25 -0800724 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700725 compile_multilib: "both",
Colin Cross2e577f32021-01-22 13:06:25 -0800726 vendor: true,
727 arch: {
728 arm64: {
729 src: "libvendor_available.a",
730 export_include_dirs: ["include/libvendor"],
731 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700732 arm: {
733 src: "libvendor_available.so",
734 export_include_dirs: ["include/libvendor"],
735 },
Colin Cross2e577f32021-01-22 13:06:25 -0800736 },
737 }
738
Inseob Kimd4c9f552021-04-08 19:28:28 +0900739 vendor_snapshot_static {
740 name: "libc++_static",
Justin Yundee806f2021-05-18 23:10:00 +0900741 version: "31",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900742 target_arch: "arm64",
743 compile_multilib: "64",
744 vendor: true,
745 arch: {
746 arm64: {
747 src: "libc++_static.a",
748 },
749 },
750 }
751
752 vendor_snapshot_static {
753 name: "libc++demangle",
Justin Yundee806f2021-05-18 23:10:00 +0900754 version: "31",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900755 target_arch: "arm64",
756 compile_multilib: "64",
757 vendor: true,
758 arch: {
759 arm64: {
760 src: "libc++demangle.a",
761 },
762 },
763 }
764
765 vendor_snapshot_static {
Justin Yundee806f2021-05-18 23:10:00 +0900766 name: "libunwind",
767 version: "31",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900768 target_arch: "arm64",
769 compile_multilib: "64",
770 vendor: true,
771 arch: {
772 arm64: {
Justin Yundee806f2021-05-18 23:10:00 +0900773 src: "libunwind.a",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900774 },
775 },
776 }
777
Colin Cross0fce0ba2021-01-08 16:40:12 -0800778 vendor_snapshot_binary {
779 name: "bin",
Justin Yundee806f2021-05-18 23:10:00 +0900780 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800781 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700782 compile_multilib: "64",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800783 vendor: true,
784 arch: {
785 arm64: {
786 src: "bin",
787 },
788 },
Inseob Kim4d945ee2022-02-24 10:29:18 +0900789 symlinks: ["binfoo", "binbar"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800790 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800791
Jose Galmesf9523ed2021-04-06 19:48:10 -0700792 vendor_snapshot_binary {
Inseob Kima1888ce2022-10-04 14:42:02 +0900793 name: "bin_override",
794 version: "31",
795 target_arch: "arm64",
796 compile_multilib: "64",
797 vendor: true,
798 overrides: ["bin"],
799 arch: {
800 arm64: {
801 src: "override/bin",
802 },
803 },
804 symlinks: ["binfoo", "binbar"],
805 }
806
807 vendor_snapshot_binary {
Jose Galmesf9523ed2021-04-06 19:48:10 -0700808 name: "bin32",
Justin Yundee806f2021-05-18 23:10:00 +0900809 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700810 target_arch: "arm64",
811 compile_multilib: "32",
812 vendor: true,
813 arch: {
814 arm: {
815 src: "bin32",
816 },
817 },
818 }
819
Colin Crosse0edaf92021-01-11 17:31:17 -0800820 // old snapshot module which has to be ignored
821 vendor_snapshot_binary {
822 name: "bin",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900823 version: "26",
Colin Crosse0edaf92021-01-11 17:31:17 -0800824 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700825 compile_multilib: "first",
826 vendor: true,
827 arch: {
828 arm64: {
829 src: "bin",
830 },
831 },
832 }
833
834 // different arch snapshot which has to be ignored
835 vendor_snapshot_binary {
836 name: "bin",
Justin Yundee806f2021-05-18 23:10:00 +0900837 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700838 target_arch: "arm",
839 compile_multilib: "first",
Colin Crosse0edaf92021-01-11 17:31:17 -0800840 vendor: true,
841 arch: {
842 arm64: {
843 src: "bin",
844 },
845 },
846 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800847`
848 depsBp := GatherRequiredDepsForTest(android.Android)
849
850 mockFS := map[string][]byte{
Inseob Kimf7aadf72021-04-13 10:15:31 +0900851 "deps/Android.bp": []byte(depsBp),
852 "framework/Android.bp": []byte(frameworkBp),
853 "framework/symbol.txt": nil,
854 "vendor/Android.bp": []byte(vendorProprietaryBp),
855 "vendor/bin": nil,
Inseob Kima1888ce2022-10-04 14:42:02 +0900856 "vendor/override/bin": nil,
Inseob Kimf7aadf72021-04-13 10:15:31 +0900857 "vendor/bin32": nil,
858 "vendor/bin.cpp": nil,
859 "vendor/client.cpp": nil,
860 "vendor/include/libvndk/a.h": nil,
861 "vendor/include/libvendor/b.h": nil,
862 "vendor/include/libvendor_cfi/c.h": nil,
863 "vendor/libc++_static.a": nil,
864 "vendor/libc++demangle.a": nil,
Justin Yundee806f2021-05-18 23:10:00 +0900865 "vendor/libunwind.a": nil,
Inseob Kimf7aadf72021-04-13 10:15:31 +0900866 "vendor/libvndk.a": nil,
867 "vendor/libvendor.a": nil,
868 "vendor/libvendor.cfi.a": nil,
869 "vendor/libvendor.so": nil,
Inseob Kima1888ce2022-10-04 14:42:02 +0900870 "vendor/override/libvendor.so": nil,
Inseob Kimf7aadf72021-04-13 10:15:31 +0900871 "vendor/lib32.a": nil,
872 "vendor/lib32.so": nil,
873 "vendor/lib64.a": nil,
874 "vendor/lib64.so": nil,
875 "vndk/Android.bp": []byte(vndkBp),
876 "vndk/include/libvndk/a.h": nil,
877 "vndk/libvndk.so": nil,
Justin Yundee806f2021-05-18 23:10:00 +0900878 "vndk/libllndk.so": nil,
Colin Cross0fce0ba2021-01-08 16:40:12 -0800879 }
880
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000881 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Justin Yundee806f2021-05-18 23:10:00 +0900882 config.TestProductVariables.DeviceVndkVersion = StringPtr("31")
883 config.TestProductVariables.Platform_vndk_version = StringPtr("32")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800884 ctx := CreateTestContext(config)
885 ctx.Register()
886
887 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "vendor/Android.bp", "vndk/Android.bp"})
888 android.FailIfErrored(t, errs)
889 _, errs = ctx.PrepareBuildActions(config)
890 android.FailIfErrored(t, errs)
891
Justin Yundee806f2021-05-18 23:10:00 +0900892 sharedVariant := "android_vendor.31_arm64_armv8-a_shared"
893 staticVariant := "android_vendor.31_arm64_armv8-a_static"
894 binaryVariant := "android_vendor.31_arm64_armv8-a"
Colin Cross0fce0ba2021-01-08 16:40:12 -0800895
Justin Yundee806f2021-05-18 23:10:00 +0900896 sharedCfiVariant := "android_vendor.31_arm64_armv8-a_shared_cfi"
897 staticCfiVariant := "android_vendor.31_arm64_armv8-a_static_cfi"
Inseob Kimf7aadf72021-04-13 10:15:31 +0900898
Justin Yundee806f2021-05-18 23:10:00 +0900899 shared32Variant := "android_vendor.31_arm_armv7-a-neon_shared"
900 binary32Variant := "android_vendor.31_arm_armv7-a-neon"
Jose Galmesf9523ed2021-04-06 19:48:10 -0700901
Justin Yundee806f2021-05-18 23:10:00 +0900902 // libclient uses libvndk.vndk.31.arm64, libvendor.vendor_static.31.arm64, libvendor_without_snapshot
Colin Cross0fce0ba2021-01-08 16:40:12 -0800903 libclientCcFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("cc").Args["cFlags"]
904 for _, includeFlags := range []string{
905 "-Ivndk/include/libvndk", // libvndk
906 "-Ivendor/include/libvendor", // libvendor
907 } {
908 if !strings.Contains(libclientCcFlags, includeFlags) {
909 t.Errorf("flags for libclient must contain %#v, but was %#v.",
910 includeFlags, libclientCcFlags)
911 }
912 }
913
914 libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("ld").Args["libFlags"]
915 for _, input := range [][]string{
Justin Yundee806f2021-05-18 23:10:00 +0900916 []string{sharedVariant, "libvndk.vndk.31.arm64"},
917 []string{sharedVariant, "libllndk.vndk.31.arm64"},
918 []string{staticVariant, "libvendor.vendor_static.31.arm64"},
Colin Cross0fce0ba2021-01-08 16:40:12 -0800919 []string{staticVariant, "libvendor_without_snapshot"},
920 } {
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400921 outputPaths := GetOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800922 if !strings.Contains(libclientLdFlags, outputPaths[0].String()) {
923 t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags)
924 }
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400925
Colin Cross0fce0ba2021-01-08 16:40:12 -0800926 }
927
Colin Cross2e577f32021-01-22 13:06:25 -0800928 libclientAndroidMkSharedLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkSharedLibs
Justin Yundee806f2021-05-18 23:10:00 +0900929 if g, w := libclientAndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "libllndk.vendor", "lib64"}; !reflect.DeepEqual(g, w) {
Colin Cross2e577f32021-01-22 13:06:25 -0800930 t.Errorf("wanted libclient AndroidMkSharedLibs %q, got %q", w, g)
931 }
932
933 libclientAndroidMkStaticLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkStaticLibs
934 if g, w := libclientAndroidMkStaticLibs, []string{"libvendor", "libvendor_without_snapshot"}; !reflect.DeepEqual(g, w) {
935 t.Errorf("wanted libclient AndroidMkStaticLibs %q, got %q", w, g)
936 }
937
Jose Galmesf9523ed2021-04-06 19:48:10 -0700938 libclient32AndroidMkSharedLibs := ctx.ModuleForTests("libclient", shared32Variant).Module().(*Module).Properties.AndroidMkSharedLibs
Justin Yundee806f2021-05-18 23:10:00 +0900939 if g, w := libclient32AndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "libllndk.vendor", "lib32"}; !reflect.DeepEqual(g, w) {
Jose Galmesf9523ed2021-04-06 19:48:10 -0700940 t.Errorf("wanted libclient32 AndroidMkSharedLibs %q, got %q", w, g)
941 }
942
Justin Yundee806f2021-05-18 23:10:00 +0900943 // libclient_cfi uses libvendor.vendor_static.31.arm64's cfi variant
Inseob Kimf7aadf72021-04-13 10:15:31 +0900944 libclientCfiCcFlags := ctx.ModuleForTests("libclient_cfi", sharedCfiVariant).Rule("cc").Args["cFlags"]
945 if !strings.Contains(libclientCfiCcFlags, "-Ivendor/include/libvendor_cfi") {
946 t.Errorf("flags for libclient_cfi must contain %#v, but was %#v.",
947 "-Ivendor/include/libvendor_cfi", libclientCfiCcFlags)
948 }
949
950 libclientCfiLdFlags := ctx.ModuleForTests("libclient_cfi", sharedCfiVariant).Rule("ld").Args["libFlags"]
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400951 libvendorCfiOutputPaths := GetOutputPaths(ctx, staticCfiVariant, []string{"libvendor.vendor_static.31.arm64"})
Inseob Kimf7aadf72021-04-13 10:15:31 +0900952 if !strings.Contains(libclientCfiLdFlags, libvendorCfiOutputPaths[0].String()) {
953 t.Errorf("libflags for libclientCfi must contain %#v, but was %#v", libvendorCfiOutputPaths[0], libclientCfiLdFlags)
954 }
955
Justin Yundee806f2021-05-18 23:10:00 +0900956 // bin_without_snapshot uses libvndk.vendor_static.31.arm64 (which reexports vndk's exported headers)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800957 binWithoutSnapshotCcFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("cc").Args["cFlags"]
Inseob Kimdd0295d2021-04-12 21:09:59 +0900958 if !strings.Contains(binWithoutSnapshotCcFlags, "-Ivndk/include/libvndk") {
Colin Cross0fce0ba2021-01-08 16:40:12 -0800959 t.Errorf("flags for bin_without_snapshot must contain %#v, but was %#v.",
960 "-Ivendor/include/libvndk", binWithoutSnapshotCcFlags)
961 }
962
963 binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("ld").Args["libFlags"]
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400964 libVndkStaticOutputPaths := GetOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.31.arm64"})
Colin Cross0fce0ba2021-01-08 16:40:12 -0800965 if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) {
966 t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v",
967 libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags)
968 }
969
Justin Yundee806f2021-05-18 23:10:00 +0900970 // libvendor.so is installed by libvendor.vendor_shared.31.arm64
971 ctx.ModuleForTests("libvendor.vendor_shared.31.arm64", sharedVariant).Output("libvendor.so")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800972
Justin Yundee806f2021-05-18 23:10:00 +0900973 // lib64.so is installed by lib64.vendor_shared.31.arm64
974 ctx.ModuleForTests("lib64.vendor_shared.31.arm64", sharedVariant).Output("lib64.so")
Jose Galmesf9523ed2021-04-06 19:48:10 -0700975
Justin Yundee806f2021-05-18 23:10:00 +0900976 // lib32.so is installed by lib32.vendor_shared.31.arm64
977 ctx.ModuleForTests("lib32.vendor_shared.31.arm64", shared32Variant).Output("lib32.so")
Jose Galmesf9523ed2021-04-06 19:48:10 -0700978
Justin Yundee806f2021-05-18 23:10:00 +0900979 // libvendor_available.so is installed by libvendor_available.vendor_shared.31.arm64
980 ctx.ModuleForTests("libvendor_available.vendor_shared.31.arm64", sharedVariant).Output("libvendor_available.so")
Colin Cross2e577f32021-01-22 13:06:25 -0800981
Colin Cross0fce0ba2021-01-08 16:40:12 -0800982 // libvendor_without_snapshot.so is installed by libvendor_without_snapshot
983 ctx.ModuleForTests("libvendor_without_snapshot", sharedVariant).Output("libvendor_without_snapshot.so")
984
Justin Yundee806f2021-05-18 23:10:00 +0900985 // bin is installed by bin.vendor_binary.31.arm64
Inseob Kim4d945ee2022-02-24 10:29:18 +0900986 bin64Module := ctx.ModuleForTests("bin.vendor_binary.31.arm64", binaryVariant)
987 bin64Module.Output("bin")
988
989 // also test symlinks
990 bin64MkEntries := android.AndroidMkEntriesForTest(t, ctx, bin64Module.Module())
991 bin64KatiSymlinks := bin64MkEntries[0].EntryMap["LOCAL_SOONG_INSTALL_SYMLINKS"]
992
993 // Either AndroidMk entries contain symlinks, or symlinks should be installed by Soong
994 for _, symlink := range []string{"binfoo", "binbar"} {
995 if inList(symlink, bin64KatiSymlinks) {
996 continue
997 }
998
999 bin64Module.Output(symlink)
1000 }
Colin Cross0fce0ba2021-01-08 16:40:12 -08001001
Justin Yundee806f2021-05-18 23:10:00 +09001002 // bin32 is installed by bin32.vendor_binary.31.arm64
1003 ctx.ModuleForTests("bin32.vendor_binary.31.arm64", binary32Variant).Output("bin32")
Jose Galmesf9523ed2021-04-06 19:48:10 -07001004
Colin Cross0fce0ba2021-01-08 16:40:12 -08001005 // bin_without_snapshot is installed by bin_without_snapshot
1006 ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot")
1007
Justin Yundee806f2021-05-18 23:10:00 +09001008 // libvendor, libvendor_available and bin don't have vendor.31 variant
Colin Cross0fce0ba2021-01-08 16:40:12 -08001009 libvendorVariants := ctx.ModuleVariantsForTests("libvendor")
1010 if inList(sharedVariant, libvendorVariants) {
1011 t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant)
1012 }
1013
Colin Cross2e577f32021-01-22 13:06:25 -08001014 libvendorAvailableVariants := ctx.ModuleVariantsForTests("libvendor_available")
1015 if inList(sharedVariant, libvendorAvailableVariants) {
1016 t.Errorf("libvendor_available must not have variant %#v, but it does", sharedVariant)
1017 }
1018
Colin Cross0fce0ba2021-01-08 16:40:12 -08001019 binVariants := ctx.ModuleVariantsForTests("bin")
1020 if inList(binaryVariant, binVariants) {
1021 t.Errorf("bin must not have variant %#v, but it does", sharedVariant)
1022 }
Inseob Kima1888ce2022-10-04 14:42:02 +09001023
1024 // test overrides property
1025 binOverrideModule := ctx.ModuleForTests("bin_override.vendor_binary.31.arm64", binaryVariant)
1026 binOverrideModule.Output("bin")
1027 binOverrideMkEntries := android.AndroidMkEntriesForTest(t, ctx, binOverrideModule.Module())
1028 binOverrideEntry := binOverrideMkEntries[0].EntryMap["LOCAL_OVERRIDES_MODULES"]
1029 if !inList("bin", binOverrideEntry) {
1030 t.Errorf("bin_override must override bin but was %q\n", binOverrideEntry)
1031 }
1032
1033 libvendorOverrideModule := ctx.ModuleForTests("libvendor_override.vendor_shared.31.arm64", sharedVariant)
1034 libvendorOverrideModule.Output("libvendor.so")
1035 libvendorOverrideMkEntries := android.AndroidMkEntriesForTest(t, ctx, libvendorOverrideModule.Module())
1036 libvendorOverrideEntry := libvendorOverrideMkEntries[0].EntryMap["LOCAL_OVERRIDES_MODULES"]
1037 if !inList("libvendor", libvendorOverrideEntry) {
1038 t.Errorf("libvendor_override must override libvendor but was %q\n", libvendorOverrideEntry)
1039 }
Colin Cross0fce0ba2021-01-08 16:40:12 -08001040}
1041
1042func TestVendorSnapshotSanitizer(t *testing.T) {
1043 bp := `
Inseob Kim253f5212021-04-08 17:10:31 +09001044 vendor_snapshot {
1045 name: "vendor_snapshot",
1046 version: "28",
1047 arch: {
1048 arm64: {
1049 static_libs: [
1050 "libsnapshot",
1051 "note_memtag_heap_sync",
1052 ],
1053 },
1054 },
1055 }
Justin Yun39c30312022-11-23 16:20:12 +09001056
Colin Cross0fce0ba2021-01-08 16:40:12 -08001057 vendor_snapshot_static {
1058 name: "libsnapshot",
1059 vendor: true,
1060 target_arch: "arm64",
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001061 version: "28",
Colin Cross0fce0ba2021-01-08 16:40:12 -08001062 arch: {
1063 arm64: {
1064 src: "libsnapshot.a",
1065 cfi: {
1066 src: "libsnapshot.cfi.a",
Justin Yun39c30312022-11-23 16:20:12 +09001067 },
1068 hwasan: {
1069 src: "libsnapshot.hwasan.a",
1070 },
Colin Cross0fce0ba2021-01-08 16:40:12 -08001071 },
1072 },
1073 }
Inseob Kim253f5212021-04-08 17:10:31 +09001074
1075 vendor_snapshot_static {
1076 name: "note_memtag_heap_sync",
1077 vendor: true,
1078 target_arch: "arm64",
1079 version: "28",
1080 arch: {
1081 arm64: {
1082 src: "note_memtag_heap_sync.a",
1083 },
1084 },
1085 }
1086
1087 cc_test {
1088 name: "vstest",
1089 gtest: false,
1090 vendor: true,
1091 compile_multilib: "64",
1092 nocrt: true,
1093 no_libcrt: true,
1094 stl: "none",
1095 static_libs: ["libsnapshot"],
1096 system_shared_libs: [],
1097 }
Colin Cross0fce0ba2021-01-08 16:40:12 -08001098`
Inseob Kim253f5212021-04-08 17:10:31 +09001099
1100 mockFS := map[string][]byte{
1101 "vendor/Android.bp": []byte(bp),
1102 "vendor/libc++demangle.a": nil,
1103 "vendor/libsnapshot.a": nil,
1104 "vendor/libsnapshot.cfi.a": nil,
Justin Yun39c30312022-11-23 16:20:12 +09001105 "vendor/libsnapshot.hwasan.a": nil,
Inseob Kim253f5212021-04-08 17:10:31 +09001106 "vendor/note_memtag_heap_sync.a": nil,
1107 }
1108
1109 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001110 config.TestProductVariables.DeviceVndkVersion = StringPtr("28")
1111 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001112 ctx := testCcWithConfig(t, config)
1113
Justin Yun39c30312022-11-23 16:20:12 +09001114 // Check non-cfi, cfi and hwasan variant.
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001115 staticVariant := "android_vendor.28_arm64_armv8-a_static"
1116 staticCfiVariant := "android_vendor.28_arm64_armv8-a_static_cfi"
Justin Yun39c30312022-11-23 16:20:12 +09001117 staticHwasanVariant := "android_vendor.28_arm64_armv8-a_static_hwasan"
1118 staticHwasanCfiVariant := "android_vendor.28_arm64_armv8-a_static_hwasan_cfi"
Colin Cross0fce0ba2021-01-08 16:40:12 -08001119
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001120 staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001121 assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a")
1122
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001123 staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticCfiVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001124 assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
Justin Yun39c30312022-11-23 16:20:12 +09001125
1126 staticHwasanModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticHwasanVariant).Module().(*Module)
1127 assertString(t, staticHwasanModule.outputFile.Path().Base(), "libsnapshot.hwasan.a")
1128
1129 staticHwasanCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticHwasanCfiVariant).Module().(*Module)
1130 if !staticHwasanCfiModule.HiddenFromMake() || !staticHwasanCfiModule.PreventInstall() {
1131 t.Errorf("Hwasan and Cfi cannot enabled at the same time.")
1132 }
Colin Cross0fce0ba2021-01-08 16:40:12 -08001133}
1134
Colin Cross0fce0ba2021-01-08 16:40:12 -08001135func TestVendorSnapshotExclude(t *testing.T) {
1136
1137 // This test verifies that the exclude_from_vendor_snapshot property
1138 // makes its way from the Android.bp source file into the module data
1139 // structure. It also verifies that modules are correctly included or
1140 // excluded in the vendor snapshot based on their path (framework or
1141 // vendor) and the exclude_from_vendor_snapshot property.
1142
1143 frameworkBp := `
1144 cc_library_shared {
1145 name: "libinclude",
1146 srcs: ["src/include.cpp"],
1147 vendor_available: true,
1148 }
1149 cc_library_shared {
1150 name: "libexclude",
1151 srcs: ["src/exclude.cpp"],
1152 vendor: true,
1153 exclude_from_vendor_snapshot: true,
1154 }
1155 cc_library_shared {
1156 name: "libavailable_exclude",
1157 srcs: ["src/exclude.cpp"],
1158 vendor_available: true,
1159 exclude_from_vendor_snapshot: true,
1160 }
1161 `
1162
1163 vendorProprietaryBp := `
1164 cc_library_shared {
1165 name: "libvendor",
1166 srcs: ["vendor.cpp"],
1167 vendor: true,
1168 }
1169 `
1170
1171 depsBp := GatherRequiredDepsForTest(android.Android)
1172
1173 mockFS := map[string][]byte{
1174 "deps/Android.bp": []byte(depsBp),
1175 "framework/Android.bp": []byte(frameworkBp),
1176 "framework/include.cpp": nil,
1177 "framework/exclude.cpp": nil,
1178 "device/Android.bp": []byte(vendorProprietaryBp),
1179 "device/vendor.cpp": nil,
1180 }
1181
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001182 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001183 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001184 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001185 ctx := CreateTestContext(config)
1186 ctx.Register()
1187
1188 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1189 android.FailIfErrored(t, errs)
1190 _, errs = ctx.PrepareBuildActions(config)
1191 android.FailIfErrored(t, errs)
1192
1193 // Test an include and exclude framework module.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001194 AssertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false, vendorVariant)
1195 AssertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true, vendorVariant)
1196 AssertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true, vendorVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001197
1198 // A vendor module is excluded, but by its path, not the
1199 // exclude_from_vendor_snapshot property.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001200 AssertExcludeFromVendorSnapshotIs(t, ctx, "libvendor", false, vendorVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001201
1202 // Verify the content of the vendor snapshot.
1203
1204 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001205 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001206 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1207
1208 var includeJsonFiles []string
1209 var excludeJsonFiles []string
1210
1211 for _, arch := range [][]string{
1212 []string{"arm64", "armv8-a"},
1213 []string{"arm", "armv7-a-neon"},
1214 } {
1215 archType := arch[0]
1216 archVariant := arch[1]
1217 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1218
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001219 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001220 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1221
1222 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001223 CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001224 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1225
1226 // Excluded modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001227 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001228 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001229 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001230 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001231 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001232 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1233 }
1234
1235 // Verify that each json file for an included module has a rule.
1236 for _, jsonFile := range includeJsonFiles {
1237 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1238 t.Errorf("include json file %q not found", jsonFile)
1239 }
1240 }
1241
1242 // Verify that each json file for an excluded module has no rule.
1243 for _, jsonFile := range excludeJsonFiles {
1244 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1245 t.Errorf("exclude json file %q found", jsonFile)
1246 }
1247 }
1248}
1249
1250func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) {
1251
1252 // This test verifies that using the exclude_from_vendor_snapshot
1253 // property on a module in a vendor proprietary path generates an
1254 // error. These modules are already excluded, so we prohibit using the
1255 // property in this way, which could add to confusion.
1256
1257 vendorProprietaryBp := `
1258 cc_library_shared {
1259 name: "libvendor",
1260 srcs: ["vendor.cpp"],
1261 vendor: true,
1262 exclude_from_vendor_snapshot: true,
1263 }
1264 `
1265
1266 depsBp := GatherRequiredDepsForTest(android.Android)
1267
1268 mockFS := map[string][]byte{
1269 "deps/Android.bp": []byte(depsBp),
1270 "device/Android.bp": []byte(vendorProprietaryBp),
1271 "device/vendor.cpp": nil,
1272 }
1273
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001274 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001275 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001276 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001277 ctx := CreateTestContext(config)
1278 ctx.Register()
1279
1280 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"})
1281 android.FailIfErrored(t, errs)
1282
1283 _, errs = ctx.PrepareBuildActions(config)
1284 android.CheckErrorsAgainstExpectations(t, errs, []string{
1285 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1286 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1287 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1288 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1289 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1290 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1291 })
1292}
1293
1294func TestRecoverySnapshotCapture(t *testing.T) {
1295 bp := `
1296 cc_library {
1297 name: "libvndk",
1298 vendor_available: true,
1299 recovery_available: true,
1300 product_available: true,
1301 vndk: {
1302 enabled: true,
1303 },
1304 nocrt: true,
1305 }
1306
1307 cc_library {
1308 name: "librecovery",
1309 recovery: true,
1310 nocrt: true,
1311 }
1312
1313 cc_library {
1314 name: "librecovery_available",
1315 recovery_available: true,
1316 nocrt: true,
1317 }
1318
1319 cc_library_headers {
1320 name: "librecovery_headers",
1321 recovery_available: true,
1322 nocrt: true,
1323 }
1324
1325 cc_binary {
1326 name: "recovery_bin",
1327 recovery: true,
1328 nocrt: true,
1329 }
1330
1331 cc_binary {
1332 name: "recovery_available_bin",
1333 recovery_available: true,
1334 nocrt: true,
1335 }
1336
Liz Kammer718eb272022-01-07 10:53:37 -05001337 cc_prebuilt_library_static {
Colin Cross0fce0ba2021-01-08 16:40:12 -08001338 name: "libb",
1339 recovery_available: true,
Liz Kammer718eb272022-01-07 10:53:37 -05001340 srcs: ["libb.a"],
1341 nocrt: true,
1342 no_libcrt: true,
1343 stl: "none",
Colin Cross0fce0ba2021-01-08 16:40:12 -08001344 }
1345
1346 cc_object {
1347 name: "obj",
1348 recovery_available: true,
1349 }
1350`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001351 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001352 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001353 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001354 ctx := testCcWithConfig(t, config)
1355
1356 // Check Recovery snapshot output.
1357
1358 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001359 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001360 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1361
1362 var jsonFiles []string
1363
1364 for _, arch := range [][]string{
1365 []string{"arm64", "armv8-a"},
1366 } {
1367 archType := arch[0]
1368 archVariant := arch[1]
1369 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1370
1371 // For shared libraries, only recovery_available modules are captured.
1372 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1373 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001374 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant)
1375 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1376 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001377 jsonFiles = append(jsonFiles,
1378 filepath.Join(sharedDir, "libvndk.so.json"),
1379 filepath.Join(sharedDir, "librecovery.so.json"),
1380 filepath.Join(sharedDir, "librecovery_available.so.json"))
1381
1382 // For static libraries, all recovery:true and recovery_available modules are captured.
1383 staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
1384 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001385 CheckSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
1386 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
1387 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001388 jsonFiles = append(jsonFiles,
1389 filepath.Join(staticDir, "libb.a.json"),
1390 filepath.Join(staticDir, "librecovery.a.json"),
1391 filepath.Join(staticDir, "librecovery_available.a.json"))
1392
1393 // For binary executables, all recovery:true and recovery_available modules are captured.
1394 if archType == "arm64" {
1395 binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1396 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001397 CheckSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
1398 CheckSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001399 jsonFiles = append(jsonFiles,
1400 filepath.Join(binaryDir, "recovery_bin.json"),
1401 filepath.Join(binaryDir, "recovery_available_bin.json"))
1402 }
1403
1404 // For header libraries, all vendor:true and vendor_available modules are captured.
1405 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
1406 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json"))
1407
1408 // For object modules, all vendor:true and vendor_available modules are captured.
1409 objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1410 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001411 CheckSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001412 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
1413 }
1414
1415 for _, jsonFile := range jsonFiles {
1416 // verify all json files exist
1417 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1418 t.Errorf("%q expected but not found", jsonFile)
1419 }
1420 }
1421}
1422
1423func TestRecoverySnapshotExclude(t *testing.T) {
1424 // This test verifies that the exclude_from_recovery_snapshot property
1425 // makes its way from the Android.bp source file into the module data
1426 // structure. It also verifies that modules are correctly included or
1427 // excluded in the recovery snapshot based on their path (framework or
1428 // vendor) and the exclude_from_recovery_snapshot property.
1429
1430 frameworkBp := `
1431 cc_library_shared {
1432 name: "libinclude",
1433 srcs: ["src/include.cpp"],
1434 recovery_available: true,
1435 }
1436 cc_library_shared {
1437 name: "libexclude",
1438 srcs: ["src/exclude.cpp"],
1439 recovery: true,
1440 exclude_from_recovery_snapshot: true,
1441 }
1442 cc_library_shared {
1443 name: "libavailable_exclude",
1444 srcs: ["src/exclude.cpp"],
1445 recovery_available: true,
1446 exclude_from_recovery_snapshot: true,
1447 }
1448 `
1449
1450 vendorProprietaryBp := `
1451 cc_library_shared {
1452 name: "librecovery",
1453 srcs: ["recovery.cpp"],
1454 recovery: true,
1455 }
1456 `
1457
1458 depsBp := GatherRequiredDepsForTest(android.Android)
1459
1460 mockFS := map[string][]byte{
1461 "deps/Android.bp": []byte(depsBp),
1462 "framework/Android.bp": []byte(frameworkBp),
1463 "framework/include.cpp": nil,
1464 "framework/exclude.cpp": nil,
1465 "device/Android.bp": []byte(vendorProprietaryBp),
1466 "device/recovery.cpp": nil,
1467 }
1468
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001469 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001470 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001471 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001472 ctx := CreateTestContext(config)
1473 ctx.Register()
1474
1475 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1476 android.FailIfErrored(t, errs)
1477 _, errs = ctx.PrepareBuildActions(config)
1478 android.FailIfErrored(t, errs)
1479
1480 // Test an include and exclude framework module.
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001481 AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false, recoveryVariant)
1482 AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true, recoveryVariant)
1483 AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true, recoveryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001484
1485 // A recovery module is excluded, but by its path, not the
1486 // exclude_from_recovery_snapshot property.
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001487 AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false, recoveryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001488
1489 // Verify the content of the recovery snapshot.
1490
1491 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001492 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001493 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1494
1495 var includeJsonFiles []string
1496 var excludeJsonFiles []string
1497
1498 for _, arch := range [][]string{
1499 []string{"arm64", "armv8-a"},
1500 } {
1501 archType := arch[0]
1502 archVariant := arch[1]
1503 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1504
1505 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1506 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1507
1508 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001509 CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001510 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1511
1512 // Excluded modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001513 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001514 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001515 CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001516 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001517 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001518 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1519 }
1520
1521 // Verify that each json file for an included module has a rule.
1522 for _, jsonFile := range includeJsonFiles {
1523 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1524 t.Errorf("include json file %q not found", jsonFile)
1525 }
1526 }
1527
1528 // Verify that each json file for an excluded module has no rule.
1529 for _, jsonFile := range excludeJsonFiles {
1530 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1531 t.Errorf("exclude json file %q found", jsonFile)
1532 }
1533 }
1534}
Jose Galmes4c6895e2021-02-09 07:44:30 -08001535
1536func TestRecoverySnapshotDirected(t *testing.T) {
1537 bp := `
1538 cc_library_shared {
1539 name: "librecovery",
1540 recovery: true,
1541 nocrt: true,
1542 }
1543
1544 cc_library_shared {
1545 name: "librecovery_available",
1546 recovery_available: true,
1547 nocrt: true,
1548 }
1549
1550 genrule {
1551 name: "libfoo_gen",
1552 cmd: "",
1553 out: ["libfoo.so"],
1554 }
1555
1556 cc_prebuilt_library_shared {
1557 name: "libfoo",
1558 recovery: true,
1559 prefer: true,
1560 srcs: [":libfoo_gen"],
1561 }
1562
1563 cc_library_shared {
1564 name: "libfoo",
1565 recovery: true,
1566 nocrt: true,
1567 }
1568`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001569 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001570 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1571 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001572 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001573 config.TestProductVariables.DirectedRecoverySnapshot = true
1574 config.TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
1575 config.TestProductVariables.RecoverySnapshotModules["librecovery"] = true
1576 config.TestProductVariables.RecoverySnapshotModules["libfoo"] = true
1577 ctx := testCcWithConfig(t, config)
1578
1579 // Check recovery snapshot output.
1580
1581 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001582 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001583 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1584
1585 var includeJsonFiles []string
1586
1587 for _, arch := range [][]string{
1588 []string{"arm64", "armv8-a"},
1589 } {
1590 archType := arch[0]
1591 archVariant := arch[1]
1592 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1593
1594 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1595 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1596
1597 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001598 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001599 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1600 // Check that snapshot captures "prefer: true" prebuilt
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001601 CheckSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001602 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
1603
1604 // Excluded modules. Modules not included in the directed recovery snapshot
1605 // are still include as fake modules.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001606 CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001607 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json"))
1608 }
1609
1610 // Verify that each json file for an included module has a rule.
1611 for _, jsonFile := range includeJsonFiles {
1612 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1613 t.Errorf("include json file %q not found", jsonFile)
1614 }
1615 }
1616}