blob: 6a98778859dffcd6490797dbc5b67528deaf507e [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 }
Colin Cross0fce0ba2021-01-08 16:40:12 -08001056 vendor_snapshot_static {
1057 name: "libsnapshot",
1058 vendor: true,
1059 target_arch: "arm64",
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001060 version: "28",
Colin Cross0fce0ba2021-01-08 16:40:12 -08001061 arch: {
1062 arm64: {
1063 src: "libsnapshot.a",
1064 cfi: {
1065 src: "libsnapshot.cfi.a",
1066 }
1067 },
1068 },
1069 }
Inseob Kim253f5212021-04-08 17:10:31 +09001070
1071 vendor_snapshot_static {
1072 name: "note_memtag_heap_sync",
1073 vendor: true,
1074 target_arch: "arm64",
1075 version: "28",
1076 arch: {
1077 arm64: {
1078 src: "note_memtag_heap_sync.a",
1079 },
1080 },
1081 }
1082
1083 cc_test {
1084 name: "vstest",
1085 gtest: false,
1086 vendor: true,
1087 compile_multilib: "64",
1088 nocrt: true,
1089 no_libcrt: true,
1090 stl: "none",
1091 static_libs: ["libsnapshot"],
1092 system_shared_libs: [],
1093 }
Colin Cross0fce0ba2021-01-08 16:40:12 -08001094`
Inseob Kim253f5212021-04-08 17:10:31 +09001095
1096 mockFS := map[string][]byte{
1097 "vendor/Android.bp": []byte(bp),
1098 "vendor/libc++demangle.a": nil,
1099 "vendor/libsnapshot.a": nil,
1100 "vendor/libsnapshot.cfi.a": nil,
1101 "vendor/note_memtag_heap_sync.a": nil,
1102 }
1103
1104 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001105 config.TestProductVariables.DeviceVndkVersion = StringPtr("28")
1106 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001107 ctx := testCcWithConfig(t, config)
1108
1109 // Check non-cfi and cfi variant.
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001110 staticVariant := "android_vendor.28_arm64_armv8-a_static"
1111 staticCfiVariant := "android_vendor.28_arm64_armv8-a_static_cfi"
Colin Cross0fce0ba2021-01-08 16:40:12 -08001112
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001113 staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001114 assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a")
1115
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001116 staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticCfiVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001117 assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
1118}
1119
Colin Cross0fce0ba2021-01-08 16:40:12 -08001120func TestVendorSnapshotExclude(t *testing.T) {
1121
1122 // This test verifies that the exclude_from_vendor_snapshot property
1123 // makes its way from the Android.bp source file into the module data
1124 // structure. It also verifies that modules are correctly included or
1125 // excluded in the vendor snapshot based on their path (framework or
1126 // vendor) and the exclude_from_vendor_snapshot property.
1127
1128 frameworkBp := `
1129 cc_library_shared {
1130 name: "libinclude",
1131 srcs: ["src/include.cpp"],
1132 vendor_available: true,
1133 }
1134 cc_library_shared {
1135 name: "libexclude",
1136 srcs: ["src/exclude.cpp"],
1137 vendor: true,
1138 exclude_from_vendor_snapshot: true,
1139 }
1140 cc_library_shared {
1141 name: "libavailable_exclude",
1142 srcs: ["src/exclude.cpp"],
1143 vendor_available: true,
1144 exclude_from_vendor_snapshot: true,
1145 }
1146 `
1147
1148 vendorProprietaryBp := `
1149 cc_library_shared {
1150 name: "libvendor",
1151 srcs: ["vendor.cpp"],
1152 vendor: true,
1153 }
1154 `
1155
1156 depsBp := GatherRequiredDepsForTest(android.Android)
1157
1158 mockFS := map[string][]byte{
1159 "deps/Android.bp": []byte(depsBp),
1160 "framework/Android.bp": []byte(frameworkBp),
1161 "framework/include.cpp": nil,
1162 "framework/exclude.cpp": nil,
1163 "device/Android.bp": []byte(vendorProprietaryBp),
1164 "device/vendor.cpp": nil,
1165 }
1166
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001167 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001168 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001169 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001170 ctx := CreateTestContext(config)
1171 ctx.Register()
1172
1173 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1174 android.FailIfErrored(t, errs)
1175 _, errs = ctx.PrepareBuildActions(config)
1176 android.FailIfErrored(t, errs)
1177
1178 // Test an include and exclude framework module.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001179 AssertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false, vendorVariant)
1180 AssertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true, vendorVariant)
1181 AssertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true, vendorVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001182
1183 // A vendor module is excluded, but by its path, not the
1184 // exclude_from_vendor_snapshot property.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001185 AssertExcludeFromVendorSnapshotIs(t, ctx, "libvendor", false, vendorVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001186
1187 // Verify the content of the vendor snapshot.
1188
1189 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001190 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001191 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1192
1193 var includeJsonFiles []string
1194 var excludeJsonFiles []string
1195
1196 for _, arch := range [][]string{
1197 []string{"arm64", "armv8-a"},
1198 []string{"arm", "armv7-a-neon"},
1199 } {
1200 archType := arch[0]
1201 archVariant := arch[1]
1202 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1203
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001204 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001205 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1206
1207 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001208 CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001209 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1210
1211 // Excluded modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001212 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001213 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001214 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001215 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001216 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001217 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1218 }
1219
1220 // Verify that each json file for an included module has a rule.
1221 for _, jsonFile := range includeJsonFiles {
1222 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1223 t.Errorf("include json file %q not found", jsonFile)
1224 }
1225 }
1226
1227 // Verify that each json file for an excluded module has no rule.
1228 for _, jsonFile := range excludeJsonFiles {
1229 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1230 t.Errorf("exclude json file %q found", jsonFile)
1231 }
1232 }
1233}
1234
1235func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) {
1236
1237 // This test verifies that using the exclude_from_vendor_snapshot
1238 // property on a module in a vendor proprietary path generates an
1239 // error. These modules are already excluded, so we prohibit using the
1240 // property in this way, which could add to confusion.
1241
1242 vendorProprietaryBp := `
1243 cc_library_shared {
1244 name: "libvendor",
1245 srcs: ["vendor.cpp"],
1246 vendor: true,
1247 exclude_from_vendor_snapshot: true,
1248 }
1249 `
1250
1251 depsBp := GatherRequiredDepsForTest(android.Android)
1252
1253 mockFS := map[string][]byte{
1254 "deps/Android.bp": []byte(depsBp),
1255 "device/Android.bp": []byte(vendorProprietaryBp),
1256 "device/vendor.cpp": nil,
1257 }
1258
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001259 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001260 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001261 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001262 ctx := CreateTestContext(config)
1263 ctx.Register()
1264
1265 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"})
1266 android.FailIfErrored(t, errs)
1267
1268 _, errs = ctx.PrepareBuildActions(config)
1269 android.CheckErrorsAgainstExpectations(t, errs, []string{
1270 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1271 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1272 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1273 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1274 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1275 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1276 })
1277}
1278
1279func TestRecoverySnapshotCapture(t *testing.T) {
1280 bp := `
1281 cc_library {
1282 name: "libvndk",
1283 vendor_available: true,
1284 recovery_available: true,
1285 product_available: true,
1286 vndk: {
1287 enabled: true,
1288 },
1289 nocrt: true,
1290 }
1291
1292 cc_library {
1293 name: "librecovery",
1294 recovery: true,
1295 nocrt: true,
1296 }
1297
1298 cc_library {
1299 name: "librecovery_available",
1300 recovery_available: true,
1301 nocrt: true,
1302 }
1303
1304 cc_library_headers {
1305 name: "librecovery_headers",
1306 recovery_available: true,
1307 nocrt: true,
1308 }
1309
1310 cc_binary {
1311 name: "recovery_bin",
1312 recovery: true,
1313 nocrt: true,
1314 }
1315
1316 cc_binary {
1317 name: "recovery_available_bin",
1318 recovery_available: true,
1319 nocrt: true,
1320 }
1321
Liz Kammer718eb272022-01-07 10:53:37 -05001322 cc_prebuilt_library_static {
Colin Cross0fce0ba2021-01-08 16:40:12 -08001323 name: "libb",
1324 recovery_available: true,
Liz Kammer718eb272022-01-07 10:53:37 -05001325 srcs: ["libb.a"],
1326 nocrt: true,
1327 no_libcrt: true,
1328 stl: "none",
Colin Cross0fce0ba2021-01-08 16:40:12 -08001329 }
1330
1331 cc_object {
1332 name: "obj",
1333 recovery_available: true,
1334 }
1335`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001336 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001337 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001338 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001339 ctx := testCcWithConfig(t, config)
1340
1341 // Check Recovery snapshot output.
1342
1343 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001344 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001345 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1346
1347 var jsonFiles []string
1348
1349 for _, arch := range [][]string{
1350 []string{"arm64", "armv8-a"},
1351 } {
1352 archType := arch[0]
1353 archVariant := arch[1]
1354 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1355
1356 // For shared libraries, only recovery_available modules are captured.
1357 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1358 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001359 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant)
1360 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1361 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001362 jsonFiles = append(jsonFiles,
1363 filepath.Join(sharedDir, "libvndk.so.json"),
1364 filepath.Join(sharedDir, "librecovery.so.json"),
1365 filepath.Join(sharedDir, "librecovery_available.so.json"))
1366
1367 // For static libraries, all recovery:true and recovery_available modules are captured.
1368 staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
1369 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001370 CheckSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
1371 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
1372 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001373 jsonFiles = append(jsonFiles,
1374 filepath.Join(staticDir, "libb.a.json"),
1375 filepath.Join(staticDir, "librecovery.a.json"),
1376 filepath.Join(staticDir, "librecovery_available.a.json"))
1377
1378 // For binary executables, all recovery:true and recovery_available modules are captured.
1379 if archType == "arm64" {
1380 binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1381 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001382 CheckSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
1383 CheckSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001384 jsonFiles = append(jsonFiles,
1385 filepath.Join(binaryDir, "recovery_bin.json"),
1386 filepath.Join(binaryDir, "recovery_available_bin.json"))
1387 }
1388
1389 // For header libraries, all vendor:true and vendor_available modules are captured.
1390 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
1391 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json"))
1392
1393 // For object modules, all vendor:true and vendor_available modules are captured.
1394 objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1395 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001396 CheckSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001397 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
1398 }
1399
1400 for _, jsonFile := range jsonFiles {
1401 // verify all json files exist
1402 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1403 t.Errorf("%q expected but not found", jsonFile)
1404 }
1405 }
1406}
1407
1408func TestRecoverySnapshotExclude(t *testing.T) {
1409 // This test verifies that the exclude_from_recovery_snapshot property
1410 // makes its way from the Android.bp source file into the module data
1411 // structure. It also verifies that modules are correctly included or
1412 // excluded in the recovery snapshot based on their path (framework or
1413 // vendor) and the exclude_from_recovery_snapshot property.
1414
1415 frameworkBp := `
1416 cc_library_shared {
1417 name: "libinclude",
1418 srcs: ["src/include.cpp"],
1419 recovery_available: true,
1420 }
1421 cc_library_shared {
1422 name: "libexclude",
1423 srcs: ["src/exclude.cpp"],
1424 recovery: true,
1425 exclude_from_recovery_snapshot: true,
1426 }
1427 cc_library_shared {
1428 name: "libavailable_exclude",
1429 srcs: ["src/exclude.cpp"],
1430 recovery_available: true,
1431 exclude_from_recovery_snapshot: true,
1432 }
1433 `
1434
1435 vendorProprietaryBp := `
1436 cc_library_shared {
1437 name: "librecovery",
1438 srcs: ["recovery.cpp"],
1439 recovery: true,
1440 }
1441 `
1442
1443 depsBp := GatherRequiredDepsForTest(android.Android)
1444
1445 mockFS := map[string][]byte{
1446 "deps/Android.bp": []byte(depsBp),
1447 "framework/Android.bp": []byte(frameworkBp),
1448 "framework/include.cpp": nil,
1449 "framework/exclude.cpp": nil,
1450 "device/Android.bp": []byte(vendorProprietaryBp),
1451 "device/recovery.cpp": nil,
1452 }
1453
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001454 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001455 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001456 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001457 ctx := CreateTestContext(config)
1458 ctx.Register()
1459
1460 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1461 android.FailIfErrored(t, errs)
1462 _, errs = ctx.PrepareBuildActions(config)
1463 android.FailIfErrored(t, errs)
1464
1465 // Test an include and exclude framework module.
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001466 AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false, recoveryVariant)
1467 AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true, recoveryVariant)
1468 AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true, recoveryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001469
1470 // A recovery module is excluded, but by its path, not the
1471 // exclude_from_recovery_snapshot property.
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001472 AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false, recoveryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001473
1474 // Verify the content of the recovery snapshot.
1475
1476 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001477 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001478 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1479
1480 var includeJsonFiles []string
1481 var excludeJsonFiles []string
1482
1483 for _, arch := range [][]string{
1484 []string{"arm64", "armv8-a"},
1485 } {
1486 archType := arch[0]
1487 archVariant := arch[1]
1488 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1489
1490 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1491 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1492
1493 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001494 CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001495 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1496
1497 // Excluded modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001498 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001499 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001500 CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001501 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001502 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001503 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1504 }
1505
1506 // Verify that each json file for an included module has a rule.
1507 for _, jsonFile := range includeJsonFiles {
1508 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1509 t.Errorf("include json file %q not found", jsonFile)
1510 }
1511 }
1512
1513 // Verify that each json file for an excluded module has no rule.
1514 for _, jsonFile := range excludeJsonFiles {
1515 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1516 t.Errorf("exclude json file %q found", jsonFile)
1517 }
1518 }
1519}
Jose Galmes4c6895e2021-02-09 07:44:30 -08001520
1521func TestRecoverySnapshotDirected(t *testing.T) {
1522 bp := `
1523 cc_library_shared {
1524 name: "librecovery",
1525 recovery: true,
1526 nocrt: true,
1527 }
1528
1529 cc_library_shared {
1530 name: "librecovery_available",
1531 recovery_available: true,
1532 nocrt: true,
1533 }
1534
1535 genrule {
1536 name: "libfoo_gen",
1537 cmd: "",
1538 out: ["libfoo.so"],
1539 }
1540
1541 cc_prebuilt_library_shared {
1542 name: "libfoo",
1543 recovery: true,
1544 prefer: true,
1545 srcs: [":libfoo_gen"],
1546 }
1547
1548 cc_library_shared {
1549 name: "libfoo",
1550 recovery: true,
1551 nocrt: true,
1552 }
1553`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001554 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001555 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1556 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001557 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001558 config.TestProductVariables.DirectedRecoverySnapshot = true
1559 config.TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
1560 config.TestProductVariables.RecoverySnapshotModules["librecovery"] = true
1561 config.TestProductVariables.RecoverySnapshotModules["libfoo"] = true
1562 ctx := testCcWithConfig(t, config)
1563
1564 // Check recovery snapshot output.
1565
1566 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001567 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001568 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1569
1570 var includeJsonFiles []string
1571
1572 for _, arch := range [][]string{
1573 []string{"arm64", "armv8-a"},
1574 } {
1575 archType := arch[0]
1576 archVariant := arch[1]
1577 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1578
1579 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1580 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1581
1582 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001583 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001584 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1585 // Check that snapshot captures "prefer: true" prebuilt
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001586 CheckSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001587 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
1588
1589 // Excluded modules. Modules not included in the directed recovery snapshot
1590 // are still include as fake modules.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001591 CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001592 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json"))
1593 }
1594
1595 // Verify that each json file for an included module has a rule.
1596 for _, jsonFile := range includeJsonFiles {
1597 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1598 t.Errorf("include json file %q not found", jsonFile)
1599 }
1600 }
1601}