blob: 5b69a10bebbe019632eebff7ae0f04fec274fc1e [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 ],
Justin Yun08270c62022-12-19 17:01:26 +09001053 objects: [
1054 "snapshot_object",
1055 ],
1056 vndk_libs: [
1057 "libclang_rt.hwasan",
1058 ],
Inseob Kim253f5212021-04-08 17:10:31 +09001059 },
1060 },
1061 }
Justin Yun39c30312022-11-23 16:20:12 +09001062
Colin Cross0fce0ba2021-01-08 16:40:12 -08001063 vendor_snapshot_static {
1064 name: "libsnapshot",
1065 vendor: true,
1066 target_arch: "arm64",
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001067 version: "28",
Colin Cross0fce0ba2021-01-08 16:40:12 -08001068 arch: {
1069 arm64: {
1070 src: "libsnapshot.a",
1071 cfi: {
1072 src: "libsnapshot.cfi.a",
Justin Yun39c30312022-11-23 16:20:12 +09001073 },
1074 hwasan: {
1075 src: "libsnapshot.hwasan.a",
1076 },
Colin Cross0fce0ba2021-01-08 16:40:12 -08001077 },
1078 },
1079 }
Inseob Kim253f5212021-04-08 17:10:31 +09001080
1081 vendor_snapshot_static {
1082 name: "note_memtag_heap_sync",
1083 vendor: true,
1084 target_arch: "arm64",
1085 version: "28",
1086 arch: {
1087 arm64: {
1088 src: "note_memtag_heap_sync.a",
1089 },
1090 },
1091 }
1092
Justin Yun08270c62022-12-19 17:01:26 +09001093 vndk_prebuilt_shared {
1094 name: "libclang_rt.hwasan",
1095 version: "28",
1096 target_arch: "arm64",
1097 vendor_available: true,
1098 product_available: true,
1099 vndk: {
1100 enabled: true,
1101 },
1102 arch: {
1103 arm64: {
1104 srcs: ["libclang_rt.hwasan.so"],
1105 },
1106 },
1107 }
1108
1109 vendor_snapshot_object {
1110 name: "snapshot_object",
1111 vendor: true,
1112 target_arch: "arm64",
1113 version: "28",
1114 arch: {
1115 arm64: {
1116 src: "snapshot_object.o",
1117 },
1118 },
1119 stl: "none",
1120 }
1121
Inseob Kim253f5212021-04-08 17:10:31 +09001122 cc_test {
1123 name: "vstest",
1124 gtest: false,
1125 vendor: true,
1126 compile_multilib: "64",
1127 nocrt: true,
1128 no_libcrt: true,
1129 stl: "none",
1130 static_libs: ["libsnapshot"],
1131 system_shared_libs: [],
1132 }
Colin Cross0fce0ba2021-01-08 16:40:12 -08001133`
Inseob Kim253f5212021-04-08 17:10:31 +09001134
1135 mockFS := map[string][]byte{
1136 "vendor/Android.bp": []byte(bp),
1137 "vendor/libc++demangle.a": nil,
Justin Yun08270c62022-12-19 17:01:26 +09001138 "vendor/libclang_rt.hwasan.so": nil,
Inseob Kim253f5212021-04-08 17:10:31 +09001139 "vendor/libsnapshot.a": nil,
1140 "vendor/libsnapshot.cfi.a": nil,
Justin Yun39c30312022-11-23 16:20:12 +09001141 "vendor/libsnapshot.hwasan.a": nil,
Inseob Kim253f5212021-04-08 17:10:31 +09001142 "vendor/note_memtag_heap_sync.a": nil,
Justin Yun08270c62022-12-19 17:01:26 +09001143 "vendor/snapshot_object.o": nil,
Inseob Kim253f5212021-04-08 17:10:31 +09001144 }
1145
1146 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001147 config.TestProductVariables.DeviceVndkVersion = StringPtr("28")
1148 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Justin Yun08270c62022-12-19 17:01:26 +09001149 config.TestProductVariables.SanitizeDevice = []string{"hwaddress"}
Colin Cross0fce0ba2021-01-08 16:40:12 -08001150 ctx := testCcWithConfig(t, config)
1151
Justin Yun39c30312022-11-23 16:20:12 +09001152 // Check non-cfi, cfi and hwasan variant.
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001153 staticVariant := "android_vendor.28_arm64_armv8-a_static"
1154 staticCfiVariant := "android_vendor.28_arm64_armv8-a_static_cfi"
Justin Yun39c30312022-11-23 16:20:12 +09001155 staticHwasanVariant := "android_vendor.28_arm64_armv8-a_static_hwasan"
1156 staticHwasanCfiVariant := "android_vendor.28_arm64_armv8-a_static_hwasan_cfi"
Colin Cross0fce0ba2021-01-08 16:40:12 -08001157
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001158 staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001159 assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a")
1160
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001161 staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticCfiVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001162 assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
Justin Yun39c30312022-11-23 16:20:12 +09001163
1164 staticHwasanModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticHwasanVariant).Module().(*Module)
1165 assertString(t, staticHwasanModule.outputFile.Path().Base(), "libsnapshot.hwasan.a")
1166
1167 staticHwasanCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticHwasanCfiVariant).Module().(*Module)
1168 if !staticHwasanCfiModule.HiddenFromMake() || !staticHwasanCfiModule.PreventInstall() {
1169 t.Errorf("Hwasan and Cfi cannot enabled at the same time.")
1170 }
Justin Yun08270c62022-12-19 17:01:26 +09001171
1172 snapshotObjModule := ctx.ModuleForTests("snapshot_object.vendor_object.28.arm64", "android_vendor.28_arm64_armv8-a").Module()
1173 snapshotObjMkEntries := android.AndroidMkEntriesForTest(t, ctx, snapshotObjModule)
1174 // snapshot object must not add ".hwasan" suffix
1175 assertString(t, snapshotObjMkEntries[0].EntryMap["LOCAL_MODULE"][0], "snapshot_object")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001176}
1177
Colin Cross0fce0ba2021-01-08 16:40:12 -08001178func TestVendorSnapshotExclude(t *testing.T) {
1179
1180 // This test verifies that the exclude_from_vendor_snapshot property
1181 // makes its way from the Android.bp source file into the module data
1182 // structure. It also verifies that modules are correctly included or
1183 // excluded in the vendor snapshot based on their path (framework or
1184 // vendor) and the exclude_from_vendor_snapshot property.
1185
1186 frameworkBp := `
1187 cc_library_shared {
1188 name: "libinclude",
1189 srcs: ["src/include.cpp"],
1190 vendor_available: true,
1191 }
1192 cc_library_shared {
1193 name: "libexclude",
1194 srcs: ["src/exclude.cpp"],
1195 vendor: true,
1196 exclude_from_vendor_snapshot: true,
1197 }
1198 cc_library_shared {
1199 name: "libavailable_exclude",
1200 srcs: ["src/exclude.cpp"],
1201 vendor_available: true,
1202 exclude_from_vendor_snapshot: true,
1203 }
1204 `
1205
1206 vendorProprietaryBp := `
1207 cc_library_shared {
1208 name: "libvendor",
1209 srcs: ["vendor.cpp"],
1210 vendor: true,
1211 }
1212 `
1213
1214 depsBp := GatherRequiredDepsForTest(android.Android)
1215
1216 mockFS := map[string][]byte{
1217 "deps/Android.bp": []byte(depsBp),
1218 "framework/Android.bp": []byte(frameworkBp),
1219 "framework/include.cpp": nil,
1220 "framework/exclude.cpp": nil,
1221 "device/Android.bp": []byte(vendorProprietaryBp),
1222 "device/vendor.cpp": nil,
1223 }
1224
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001225 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001226 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001227 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001228 ctx := CreateTestContext(config)
1229 ctx.Register()
1230
1231 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1232 android.FailIfErrored(t, errs)
1233 _, errs = ctx.PrepareBuildActions(config)
1234 android.FailIfErrored(t, errs)
1235
1236 // Test an include and exclude framework module.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001237 AssertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false, vendorVariant)
1238 AssertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true, vendorVariant)
1239 AssertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true, vendorVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001240
1241 // A vendor module is excluded, but by its path, not the
1242 // exclude_from_vendor_snapshot property.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001243 AssertExcludeFromVendorSnapshotIs(t, ctx, "libvendor", false, vendorVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001244
1245 // Verify the content of the vendor snapshot.
1246
1247 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001248 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001249 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1250
1251 var includeJsonFiles []string
1252 var excludeJsonFiles []string
1253
1254 for _, arch := range [][]string{
1255 []string{"arm64", "armv8-a"},
1256 []string{"arm", "armv7-a-neon"},
1257 } {
1258 archType := arch[0]
1259 archVariant := arch[1]
1260 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1261
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001262 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001263 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1264
1265 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001266 CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001267 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1268
1269 // Excluded modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001270 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001271 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001272 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001273 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001274 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001275 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1276 }
1277
1278 // Verify that each json file for an included module has a rule.
1279 for _, jsonFile := range includeJsonFiles {
1280 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1281 t.Errorf("include json file %q not found", jsonFile)
1282 }
1283 }
1284
1285 // Verify that each json file for an excluded module has no rule.
1286 for _, jsonFile := range excludeJsonFiles {
1287 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1288 t.Errorf("exclude json file %q found", jsonFile)
1289 }
1290 }
1291}
1292
1293func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) {
1294
1295 // This test verifies that using the exclude_from_vendor_snapshot
1296 // property on a module in a vendor proprietary path generates an
1297 // error. These modules are already excluded, so we prohibit using the
1298 // property in this way, which could add to confusion.
1299
1300 vendorProprietaryBp := `
1301 cc_library_shared {
1302 name: "libvendor",
1303 srcs: ["vendor.cpp"],
1304 vendor: true,
1305 exclude_from_vendor_snapshot: true,
1306 }
1307 `
1308
1309 depsBp := GatherRequiredDepsForTest(android.Android)
1310
1311 mockFS := map[string][]byte{
1312 "deps/Android.bp": []byte(depsBp),
1313 "device/Android.bp": []byte(vendorProprietaryBp),
1314 "device/vendor.cpp": nil,
1315 }
1316
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001317 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001318 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001319 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001320 ctx := CreateTestContext(config)
1321 ctx.Register()
1322
1323 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"})
1324 android.FailIfErrored(t, errs)
1325
1326 _, errs = ctx.PrepareBuildActions(config)
1327 android.CheckErrorsAgainstExpectations(t, errs, []string{
1328 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1329 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1330 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1331 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1332 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1333 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1334 })
1335}
1336
1337func TestRecoverySnapshotCapture(t *testing.T) {
1338 bp := `
1339 cc_library {
1340 name: "libvndk",
1341 vendor_available: true,
1342 recovery_available: true,
1343 product_available: true,
1344 vndk: {
1345 enabled: true,
1346 },
1347 nocrt: true,
1348 }
1349
1350 cc_library {
1351 name: "librecovery",
1352 recovery: true,
1353 nocrt: true,
1354 }
1355
1356 cc_library {
1357 name: "librecovery_available",
1358 recovery_available: true,
1359 nocrt: true,
1360 }
1361
1362 cc_library_headers {
1363 name: "librecovery_headers",
1364 recovery_available: true,
1365 nocrt: true,
1366 }
1367
1368 cc_binary {
1369 name: "recovery_bin",
1370 recovery: true,
1371 nocrt: true,
1372 }
1373
1374 cc_binary {
1375 name: "recovery_available_bin",
1376 recovery_available: true,
1377 nocrt: true,
1378 }
1379
Liz Kammer718eb272022-01-07 10:53:37 -05001380 cc_prebuilt_library_static {
Colin Cross0fce0ba2021-01-08 16:40:12 -08001381 name: "libb",
1382 recovery_available: true,
Liz Kammer718eb272022-01-07 10:53:37 -05001383 srcs: ["libb.a"],
1384 nocrt: true,
1385 no_libcrt: true,
1386 stl: "none",
Colin Cross0fce0ba2021-01-08 16:40:12 -08001387 }
1388
1389 cc_object {
1390 name: "obj",
1391 recovery_available: true,
1392 }
1393`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001394 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001395 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001396 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001397 ctx := testCcWithConfig(t, config)
1398
1399 // Check Recovery snapshot output.
1400
1401 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001402 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001403 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1404
1405 var jsonFiles []string
1406
1407 for _, arch := range [][]string{
1408 []string{"arm64", "armv8-a"},
1409 } {
1410 archType := arch[0]
1411 archVariant := arch[1]
1412 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1413
1414 // For shared libraries, only recovery_available modules are captured.
1415 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1416 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001417 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant)
1418 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1419 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001420 jsonFiles = append(jsonFiles,
1421 filepath.Join(sharedDir, "libvndk.so.json"),
1422 filepath.Join(sharedDir, "librecovery.so.json"),
1423 filepath.Join(sharedDir, "librecovery_available.so.json"))
1424
1425 // For static libraries, all recovery:true and recovery_available modules are captured.
1426 staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
1427 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001428 CheckSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
1429 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
1430 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001431 jsonFiles = append(jsonFiles,
1432 filepath.Join(staticDir, "libb.a.json"),
1433 filepath.Join(staticDir, "librecovery.a.json"),
1434 filepath.Join(staticDir, "librecovery_available.a.json"))
1435
1436 // For binary executables, all recovery:true and recovery_available modules are captured.
1437 if archType == "arm64" {
1438 binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1439 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001440 CheckSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
1441 CheckSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001442 jsonFiles = append(jsonFiles,
1443 filepath.Join(binaryDir, "recovery_bin.json"),
1444 filepath.Join(binaryDir, "recovery_available_bin.json"))
1445 }
1446
1447 // For header libraries, all vendor:true and vendor_available modules are captured.
1448 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
1449 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json"))
1450
1451 // For object modules, all vendor:true and vendor_available modules are captured.
1452 objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1453 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001454 CheckSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001455 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
1456 }
1457
1458 for _, jsonFile := range jsonFiles {
1459 // verify all json files exist
1460 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1461 t.Errorf("%q expected but not found", jsonFile)
1462 }
1463 }
1464}
1465
1466func TestRecoverySnapshotExclude(t *testing.T) {
1467 // This test verifies that the exclude_from_recovery_snapshot property
1468 // makes its way from the Android.bp source file into the module data
1469 // structure. It also verifies that modules are correctly included or
1470 // excluded in the recovery snapshot based on their path (framework or
1471 // vendor) and the exclude_from_recovery_snapshot property.
1472
1473 frameworkBp := `
1474 cc_library_shared {
1475 name: "libinclude",
1476 srcs: ["src/include.cpp"],
1477 recovery_available: true,
1478 }
1479 cc_library_shared {
1480 name: "libexclude",
1481 srcs: ["src/exclude.cpp"],
1482 recovery: true,
1483 exclude_from_recovery_snapshot: true,
1484 }
1485 cc_library_shared {
1486 name: "libavailable_exclude",
1487 srcs: ["src/exclude.cpp"],
1488 recovery_available: true,
1489 exclude_from_recovery_snapshot: true,
1490 }
1491 `
1492
1493 vendorProprietaryBp := `
1494 cc_library_shared {
1495 name: "librecovery",
1496 srcs: ["recovery.cpp"],
1497 recovery: true,
1498 }
1499 `
1500
1501 depsBp := GatherRequiredDepsForTest(android.Android)
1502
1503 mockFS := map[string][]byte{
1504 "deps/Android.bp": []byte(depsBp),
1505 "framework/Android.bp": []byte(frameworkBp),
1506 "framework/include.cpp": nil,
1507 "framework/exclude.cpp": nil,
1508 "device/Android.bp": []byte(vendorProprietaryBp),
1509 "device/recovery.cpp": nil,
1510 }
1511
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001512 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001513 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001514 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001515 ctx := CreateTestContext(config)
1516 ctx.Register()
1517
1518 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1519 android.FailIfErrored(t, errs)
1520 _, errs = ctx.PrepareBuildActions(config)
1521 android.FailIfErrored(t, errs)
1522
1523 // Test an include and exclude framework module.
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001524 AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false, recoveryVariant)
1525 AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true, recoveryVariant)
1526 AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true, recoveryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001527
1528 // A recovery module is excluded, but by its path, not the
1529 // exclude_from_recovery_snapshot property.
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001530 AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false, recoveryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001531
1532 // Verify the content of the recovery snapshot.
1533
1534 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001535 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001536 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1537
1538 var includeJsonFiles []string
1539 var excludeJsonFiles []string
1540
1541 for _, arch := range [][]string{
1542 []string{"arm64", "armv8-a"},
1543 } {
1544 archType := arch[0]
1545 archVariant := arch[1]
1546 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1547
1548 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1549 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1550
1551 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001552 CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001553 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1554
1555 // Excluded modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001556 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001557 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001558 CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001559 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001560 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001561 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1562 }
1563
1564 // Verify that each json file for an included module has a rule.
1565 for _, jsonFile := range includeJsonFiles {
1566 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1567 t.Errorf("include json file %q not found", jsonFile)
1568 }
1569 }
1570
1571 // Verify that each json file for an excluded module has no rule.
1572 for _, jsonFile := range excludeJsonFiles {
1573 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1574 t.Errorf("exclude json file %q found", jsonFile)
1575 }
1576 }
1577}
Jose Galmes4c6895e2021-02-09 07:44:30 -08001578
1579func TestRecoverySnapshotDirected(t *testing.T) {
1580 bp := `
1581 cc_library_shared {
1582 name: "librecovery",
1583 recovery: true,
1584 nocrt: true,
1585 }
1586
1587 cc_library_shared {
1588 name: "librecovery_available",
1589 recovery_available: true,
1590 nocrt: true,
1591 }
1592
1593 genrule {
1594 name: "libfoo_gen",
1595 cmd: "",
1596 out: ["libfoo.so"],
1597 }
1598
1599 cc_prebuilt_library_shared {
1600 name: "libfoo",
1601 recovery: true,
1602 prefer: true,
1603 srcs: [":libfoo_gen"],
1604 }
1605
1606 cc_library_shared {
1607 name: "libfoo",
1608 recovery: true,
1609 nocrt: true,
1610 }
1611`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001612 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001613 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1614 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001615 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001616 config.TestProductVariables.DirectedRecoverySnapshot = true
1617 config.TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
1618 config.TestProductVariables.RecoverySnapshotModules["librecovery"] = true
1619 config.TestProductVariables.RecoverySnapshotModules["libfoo"] = true
1620 ctx := testCcWithConfig(t, config)
1621
1622 // Check recovery snapshot output.
1623
1624 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001625 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001626 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1627
1628 var includeJsonFiles []string
1629
1630 for _, arch := range [][]string{
1631 []string{"arm64", "armv8-a"},
1632 } {
1633 archType := arch[0]
1634 archVariant := arch[1]
1635 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1636
1637 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1638 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1639
1640 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001641 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001642 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1643 // Check that snapshot captures "prefer: true" prebuilt
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001644 CheckSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001645 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
1646
1647 // Excluded modules. Modules not included in the directed recovery snapshot
1648 // are still include as fake modules.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001649 CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001650 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json"))
1651 }
1652
1653 // Verify that each json file for an included module has a rule.
1654 for _, jsonFile := range includeJsonFiles {
1655 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1656 t.Errorf("include json file %q not found", jsonFile)
1657 }
1658 }
1659}
Justin Yun17d0ee22023-05-02 14:56:38 +09001660
1661func TestSnapshotInRelativeInstallPath(t *testing.T) {
1662 bp := `
1663 cc_library {
1664 name: "libvendor_available",
1665 vendor_available: true,
1666 nocrt: true,
1667 }
1668
1669 cc_library {
1670 name: "libvendor_available_var",
1671 vendor_available: true,
1672 stem: "libvendor_available",
1673 relative_install_path: "var",
1674 nocrt: true,
1675 }
1676`
1677
1678 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
1679 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1680 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
1681 ctx := testCcWithConfig(t, config)
1682
1683 // Check Vendor snapshot output.
1684
1685 snapshotDir := "vendor-snapshot"
1686 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
1687 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1688
1689 var jsonFiles []string
1690
1691 for _, arch := range [][]string{
1692 []string{"arm64", "armv8-a"},
1693 []string{"arm", "armv7-a-neon"},
1694 } {
1695 archType := arch[0]
1696 archVariant := arch[1]
1697 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1698
1699 // For shared libraries, only non-VNDK vendor_available modules are captured
1700 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
1701 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1702 sharedDirVar := filepath.Join(sharedDir, "var")
1703 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
1704 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available_var", "libvendor_available.so", sharedDirVar, sharedVariant)
1705 jsonFiles = append(jsonFiles,
1706 filepath.Join(sharedDir, "libvendor_available.so.json"),
1707 filepath.Join(sharedDirVar, "libvendor_available.so.json"))
1708 }
1709
1710 for _, jsonFile := range jsonFiles {
1711 // verify all json files exist
1712 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1713 t.Errorf("%q expected but not found", jsonFile)
1714 }
1715 }
1716
1717 // fake snapshot should have all outputs in the normal snapshot.
1718 fakeSnapshotSingleton := ctx.SingletonForTests("vendor-fake-snapshot")
1719 for _, output := range snapshotSingleton.AllOutputs() {
1720 fakeOutput := strings.Replace(output, "/vendor-snapshot/", "/fake/vendor-snapshot/", 1)
1721 if fakeSnapshotSingleton.MaybeOutput(fakeOutput).Rule == nil {
1722 t.Errorf("%q expected but not found", fakeOutput)
1723 }
1724 }
1725}