blob: 890a533083fd80d5168306503e1d498570eb32c5 [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
Colin Crossf61d03d2023-11-02 16:56:39 -070026func checkJsonContents(t *testing.T, ctx *android.TestContext, snapshotSingleton android.TestingSingleton, jsonPath string, key string, value string) {
27 jsonOut := snapshotSingleton.MaybeOutput(jsonPath)
Justin Yun3cc78462023-05-08 21:06:59 +090028 if jsonOut.Rule == nil {
29 t.Errorf("%q expected but not found", jsonPath)
30 return
31 }
Colin Crossf61d03d2023-11-02 16:56:39 -070032 content := android.ContentFromFileRuleForTests(t, ctx, jsonOut)
33 if !strings.Contains(content, fmt.Sprintf("%q:%q", key, value)) {
Justin Yun3cc78462023-05-08 21:06:59 +090034 t.Errorf("%q must include %q:%q but it only has %v", jsonPath, key, value, jsonOut.Args["content"])
35 }
36}
37
Colin Cross0fce0ba2021-01-08 16:40:12 -080038func TestVendorSnapshotCapture(t *testing.T) {
39 bp := `
40 cc_library {
41 name: "libvndk",
42 vendor_available: true,
43 product_available: true,
44 vndk: {
45 enabled: true,
46 },
47 nocrt: true,
48 }
49
50 cc_library {
51 name: "libvendor",
52 vendor: true,
53 nocrt: true,
54 }
55
56 cc_library {
Inseob Kima1888ce2022-10-04 14:42:02 +090057 name: "libvendor_override",
58 vendor: true,
59 nocrt: true,
60 overrides: ["libvendor"],
61 }
62
63 cc_library {
Colin Cross0fce0ba2021-01-08 16:40:12 -080064 name: "libvendor_available",
65 vendor_available: true,
66 nocrt: true,
Justin Yun3cc78462023-05-08 21:06:59 +090067 min_sdk_version: "29",
Colin Cross0fce0ba2021-01-08 16:40:12 -080068 }
69
70 cc_library_headers {
71 name: "libvendor_headers",
72 vendor_available: true,
73 nocrt: true,
74 }
75
76 cc_binary {
77 name: "vendor_bin",
78 vendor: true,
79 nocrt: true,
80 }
81
82 cc_binary {
83 name: "vendor_available_bin",
84 vendor_available: true,
85 nocrt: true,
86 }
87
Inseob Kima1888ce2022-10-04 14:42:02 +090088 cc_binary {
89 name: "vendor_bin_override",
90 vendor: true,
91 nocrt: true,
92 overrides: ["vendor_bin"],
93 }
94
Liz Kammer718eb272022-01-07 10:53:37 -050095 cc_prebuilt_library_static {
Colin Cross0fce0ba2021-01-08 16:40:12 -080096 name: "libb",
97 vendor_available: true,
Liz Kammer718eb272022-01-07 10:53:37 -050098 srcs: ["libb.a"],
99 nocrt: true,
100 no_libcrt: true,
101 stl: "none",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800102 }
103
104 cc_object {
105 name: "obj",
106 vendor_available: true,
107 }
108
109 cc_library {
110 name: "libllndk",
Colin Cross203b4212021-04-26 17:19:41 -0700111 llndk: {
112 symbol_file: "libllndk.map.txt",
113 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800114 }
115`
Colin Cross203b4212021-04-26 17:19:41 -0700116
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000117 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800118 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900119 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800120 ctx := testCcWithConfig(t, config)
121
122 // Check Vendor snapshot output.
123
124 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000125 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800126 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
127
128 var jsonFiles []string
129
130 for _, arch := range [][]string{
131 []string{"arm64", "armv8-a"},
132 []string{"arm", "armv7-a-neon"},
133 } {
134 archType := arch[0]
135 archVariant := arch[1]
136 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
137
138 // For shared libraries, only non-VNDK vendor_available modules are captured
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900139 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800140 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400141 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
142 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800143 jsonFiles = append(jsonFiles,
144 filepath.Join(sharedDir, "libvendor.so.json"),
145 filepath.Join(sharedDir, "libvendor_available.so.json"))
146
147 // LLNDK modules are not captured
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400148 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800149
150 // For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
151 // Also cfi variants are captured, except for prebuilts like toolchain_library
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900152 staticVariant := fmt.Sprintf("android_vendor.29_%s_%s_static", archType, archVariant)
153 staticCfiVariant := fmt.Sprintf("android_vendor.29_%s_%s_static_cfi", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800154 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400155 CheckSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
156 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.a", staticDir, staticVariant)
157 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.cfi.a", staticDir, staticCfiVariant)
158 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.a", staticDir, staticVariant)
159 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.cfi.a", staticDir, staticCfiVariant)
160 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.a", staticDir, staticVariant)
161 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.cfi.a", staticDir, staticCfiVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800162 jsonFiles = append(jsonFiles,
163 filepath.Join(staticDir, "libb.a.json"),
164 filepath.Join(staticDir, "libvndk.a.json"),
165 filepath.Join(staticDir, "libvndk.cfi.a.json"),
166 filepath.Join(staticDir, "libvendor.a.json"),
167 filepath.Join(staticDir, "libvendor.cfi.a.json"),
168 filepath.Join(staticDir, "libvendor_available.a.json"),
169 filepath.Join(staticDir, "libvendor_available.cfi.a.json"))
170
Colin Crossf61d03d2023-11-02 16:56:39 -0700171 checkJsonContents(t, ctx, snapshotSingleton, filepath.Join(staticDir, "libb.a.json"), "MinSdkVersion", "apex_inherit")
172 checkJsonContents(t, ctx, snapshotSingleton, filepath.Join(staticDir, "libvendor_available.a.json"), "MinSdkVersion", "29")
Justin Yun3cc78462023-05-08 21:06:59 +0900173
Colin Cross0fce0ba2021-01-08 16:40:12 -0800174 // For binary executables, all vendor:true and vendor_available modules are captured.
175 if archType == "arm64" {
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900176 binaryVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800177 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400178 CheckSnapshot(t, ctx, snapshotSingleton, "vendor_bin", "vendor_bin", binaryDir, binaryVariant)
179 CheckSnapshot(t, ctx, snapshotSingleton, "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800180 jsonFiles = append(jsonFiles,
181 filepath.Join(binaryDir, "vendor_bin.json"),
182 filepath.Join(binaryDir, "vendor_available_bin.json"))
Inseob Kima1888ce2022-10-04 14:42:02 +0900183
184 checkOverrides(t, ctx, snapshotSingleton, filepath.Join(binaryDir, "vendor_bin_override.json"), []string{"vendor_bin"})
Colin Cross0fce0ba2021-01-08 16:40:12 -0800185 }
186
187 // For header libraries, all vendor:true and vendor_available modules are captured.
188 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
189 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "libvendor_headers.json"))
190
191 // For object modules, all vendor:true and vendor_available modules are captured.
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900192 objectVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800193 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400194 CheckSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800195 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
Inseob Kima1888ce2022-10-04 14:42:02 +0900196
197 checkOverrides(t, ctx, snapshotSingleton, filepath.Join(sharedDir, "libvendor_override.so.json"), []string{"libvendor"})
Colin Cross0fce0ba2021-01-08 16:40:12 -0800198 }
199
200 for _, jsonFile := range jsonFiles {
201 // verify all json files exist
202 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
203 t.Errorf("%q expected but not found", jsonFile)
204 }
205 }
206
207 // fake snapshot should have all outputs in the normal snapshot.
208 fakeSnapshotSingleton := ctx.SingletonForTests("vendor-fake-snapshot")
209 for _, output := range snapshotSingleton.AllOutputs() {
210 fakeOutput := strings.Replace(output, "/vendor-snapshot/", "/fake/vendor-snapshot/", 1)
211 if fakeSnapshotSingleton.MaybeOutput(fakeOutput).Rule == nil {
212 t.Errorf("%q expected but not found", fakeOutput)
213 }
214 }
215}
216
217func TestVendorSnapshotDirected(t *testing.T) {
218 bp := `
219 cc_library_shared {
220 name: "libvendor",
221 vendor: true,
222 nocrt: true,
223 }
224
225 cc_library_shared {
226 name: "libvendor_available",
227 vendor_available: true,
228 nocrt: true,
229 }
230
231 genrule {
232 name: "libfoo_gen",
233 cmd: "",
234 out: ["libfoo.so"],
235 }
236
237 cc_prebuilt_library_shared {
238 name: "libfoo",
239 vendor: true,
240 prefer: true,
241 srcs: [":libfoo_gen"],
242 }
243
244 cc_library_shared {
245 name: "libfoo",
246 vendor: true,
247 nocrt: true,
248 }
249`
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000250 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800251 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900252 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800253 config.TestProductVariables.DirectedVendorSnapshot = true
254 config.TestProductVariables.VendorSnapshotModules = make(map[string]bool)
255 config.TestProductVariables.VendorSnapshotModules["libvendor"] = true
256 config.TestProductVariables.VendorSnapshotModules["libfoo"] = true
257 ctx := testCcWithConfig(t, config)
258
259 // Check Vendor snapshot output.
260
261 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000262 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800263 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
264
265 var includeJsonFiles []string
Colin Cross0fce0ba2021-01-08 16:40:12 -0800266
267 for _, arch := range [][]string{
268 []string{"arm64", "armv8-a"},
269 []string{"arm", "armv7-a-neon"},
270 } {
271 archType := arch[0]
272 archVariant := arch[1]
273 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
274
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900275 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800276 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
277
278 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400279 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800280 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
281 // Check that snapshot captures "prefer: true" prebuilt
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400282 CheckSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800283 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
284
Jose Galmes0a942a02021-02-03 14:23:15 -0800285 // Excluded modules. Modules not included in the directed vendor snapshot
286 // are still include as fake modules.
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400287 CheckSnapshotRule(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
Jose Galmes0a942a02021-02-03 14:23:15 -0800288 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libvendor_available.so.json"))
Colin Cross0fce0ba2021-01-08 16:40:12 -0800289 }
290
291 // Verify that each json file for an included module has a rule.
292 for _, jsonFile := range includeJsonFiles {
293 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
294 t.Errorf("include json file %q not found", jsonFile)
295 }
296 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800297}
298
299func TestVendorSnapshotUse(t *testing.T) {
300 frameworkBp := `
301 cc_library {
302 name: "libvndk",
303 vendor_available: true,
304 product_available: true,
305 vndk: {
306 enabled: true,
307 },
308 nocrt: true,
Colin Cross0fce0ba2021-01-08 16:40:12 -0800309 }
310
311 cc_library {
312 name: "libvendor",
313 vendor: true,
314 nocrt: true,
315 no_libcrt: true,
316 stl: "none",
317 system_shared_libs: [],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800318 }
319
Colin Cross2e577f32021-01-22 13:06:25 -0800320 cc_library {
321 name: "libvendor_available",
322 vendor_available: true,
323 nocrt: true,
324 no_libcrt: true,
325 stl: "none",
326 system_shared_libs: [],
Jose Galmesf9523ed2021-04-06 19:48:10 -0700327 }
328
329 cc_library {
330 name: "lib32",
331 vendor: true,
332 nocrt: true,
333 no_libcrt: true,
334 stl: "none",
335 system_shared_libs: [],
336 compile_multilib: "32",
337 }
338
339 cc_library {
340 name: "lib64",
341 vendor: true,
342 nocrt: true,
343 no_libcrt: true,
344 stl: "none",
345 system_shared_libs: [],
Colin Cross2e577f32021-01-22 13:06:25 -0800346 compile_multilib: "64",
347 }
348
Justin Yundee806f2021-05-18 23:10:00 +0900349 cc_library {
350 name: "libllndk",
351 llndk: {
352 symbol_file: "libllndk.map.txt",
353 },
354 }
355
Colin Cross0fce0ba2021-01-08 16:40:12 -0800356 cc_binary {
357 name: "bin",
358 vendor: true,
359 nocrt: true,
360 no_libcrt: true,
361 stl: "none",
362 system_shared_libs: [],
Jose Galmesf9523ed2021-04-06 19:48:10 -0700363 }
364
365 cc_binary {
366 name: "bin32",
367 vendor: true,
368 nocrt: true,
369 no_libcrt: true,
370 stl: "none",
371 system_shared_libs: [],
372 compile_multilib: "32",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800373 }
374`
375
376 vndkBp := `
377 vndk_prebuilt_shared {
378 name: "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900379 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800380 target_arch: "arm64",
381 vendor_available: true,
382 product_available: true,
383 vndk: {
384 enabled: true,
385 },
386 arch: {
387 arm64: {
388 srcs: ["libvndk.so"],
389 export_include_dirs: ["include/libvndk"],
390 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700391 arm: {
392 srcs: ["libvndk.so"],
393 export_include_dirs: ["include/libvndk"],
394 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800395 },
396 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800397
398 // old snapshot module which has to be ignored
399 vndk_prebuilt_shared {
400 name: "libvndk",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900401 version: "26",
Colin Crosse0edaf92021-01-11 17:31:17 -0800402 target_arch: "arm64",
403 vendor_available: true,
404 product_available: true,
405 vndk: {
406 enabled: true,
407 },
408 arch: {
409 arm64: {
410 srcs: ["libvndk.so"],
411 export_include_dirs: ["include/libvndk"],
412 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700413 arm: {
414 srcs: ["libvndk.so"],
415 export_include_dirs: ["include/libvndk"],
416 },
417 },
418 }
419
420 // different arch snapshot which has to be ignored
421 vndk_prebuilt_shared {
422 name: "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900423 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700424 target_arch: "arm",
425 vendor_available: true,
426 product_available: true,
427 vndk: {
428 enabled: true,
429 },
430 arch: {
431 arm: {
432 srcs: ["libvndk.so"],
433 export_include_dirs: ["include/libvndk"],
434 },
Colin Crosse0edaf92021-01-11 17:31:17 -0800435 },
436 }
Justin Yundee806f2021-05-18 23:10:00 +0900437
438 vndk_prebuilt_shared {
439 name: "libllndk",
440 version: "31",
441 target_arch: "arm64",
442 vendor_available: true,
443 product_available: true,
444 arch: {
445 arm64: {
446 srcs: ["libllndk.so"],
447 },
448 arm: {
449 srcs: ["libllndk.so"],
450 },
451 },
452 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800453`
454
455 vendorProprietaryBp := `
456 cc_library {
457 name: "libvendor_without_snapshot",
458 vendor: true,
459 nocrt: true,
460 no_libcrt: true,
461 stl: "none",
462 system_shared_libs: [],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800463 }
464
465 cc_library_shared {
466 name: "libclient",
467 vendor: true,
468 nocrt: true,
469 no_libcrt: true,
470 stl: "none",
471 system_shared_libs: [],
Justin Yundee806f2021-05-18 23:10:00 +0900472 shared_libs: ["libvndk", "libvendor_available", "libllndk"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800473 static_libs: ["libvendor", "libvendor_without_snapshot"],
Jose Galmesf9523ed2021-04-06 19:48:10 -0700474 arch: {
475 arm64: {
476 shared_libs: ["lib64"],
477 },
478 arm: {
479 shared_libs: ["lib32"],
480 },
481 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800482 srcs: ["client.cpp"],
483 }
484
Inseob Kimf7aadf72021-04-13 10:15:31 +0900485 cc_library_shared {
486 name: "libclient_cfi",
487 vendor: true,
488 nocrt: true,
489 no_libcrt: true,
490 stl: "none",
491 system_shared_libs: [],
492 static_libs: ["libvendor"],
493 sanitize: {
494 cfi: true,
495 },
496 srcs: ["client.cpp"],
497 }
498
Justin Yun27b95722021-07-28 17:04:44 +0900499 cc_library_shared {
500 name: "libvndkext",
501 vendor: true,
502 nocrt: true,
503 no_libcrt: true,
504 stl: "none",
505 system_shared_libs: [],
506 vndk: {
507 extends: "libvndk",
508 enabled: true,
509 }
510 }
511
Colin Cross0fce0ba2021-01-08 16:40:12 -0800512 cc_binary {
513 name: "bin_without_snapshot",
514 vendor: true,
515 nocrt: true,
516 no_libcrt: true,
Inseob Kimd4c9f552021-04-08 19:28:28 +0900517 stl: "libc++_static",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800518 system_shared_libs: [],
519 static_libs: ["libvndk"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800520 srcs: ["bin.cpp"],
521 }
522
Colin Crosse0edaf92021-01-11 17:31:17 -0800523 vendor_snapshot {
524 name: "vendor_snapshot",
Justin Yundee806f2021-05-18 23:10:00 +0900525 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700526 arch: {
527 arm64: {
528 vndk_libs: [
529 "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900530 "libllndk",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700531 ],
532 static_libs: [
Inseob Kimd4c9f552021-04-08 19:28:28 +0900533 "libc++_static",
534 "libc++demangle",
Justin Yundee806f2021-05-18 23:10:00 +0900535 "libunwind",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700536 "libvendor",
537 "libvendor_available",
538 "libvndk",
539 "lib64",
540 ],
541 shared_libs: [
542 "libvendor",
Inseob Kima1888ce2022-10-04 14:42:02 +0900543 "libvendor_override",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700544 "libvendor_available",
545 "lib64",
546 ],
547 binaries: [
548 "bin",
Inseob Kima1888ce2022-10-04 14:42:02 +0900549 "bin_override",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700550 ],
551 },
552 arm: {
553 vndk_libs: [
554 "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900555 "libllndk",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700556 ],
557 static_libs: [
558 "libvendor",
559 "libvendor_available",
560 "libvndk",
561 "lib32",
562 ],
563 shared_libs: [
564 "libvendor",
Inseob Kima1888ce2022-10-04 14:42:02 +0900565 "libvendor_override",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700566 "libvendor_available",
567 "lib32",
568 ],
569 binaries: [
570 "bin32",
571 ],
572 },
573 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800574 }
575
Colin Cross0fce0ba2021-01-08 16:40:12 -0800576 vendor_snapshot_static {
577 name: "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900578 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800579 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700580 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800581 vendor: true,
582 arch: {
583 arm64: {
584 src: "libvndk.a",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800585 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700586 arm: {
587 src: "libvndk.a",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700588 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800589 },
Inseob Kimdd0295d2021-04-12 21:09:59 +0900590 shared_libs: ["libvndk"],
591 export_shared_lib_headers: ["libvndk"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800592 }
593
594 vendor_snapshot_shared {
595 name: "libvendor",
Justin Yundee806f2021-05-18 23:10:00 +0900596 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800597 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700598 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800599 vendor: true,
Justin Yun48138672021-02-25 18:21:27 +0900600 shared_libs: [
601 "libvendor_without_snapshot",
602 "libvendor_available",
Justin Yun07b9f862021-02-26 14:00:03 +0900603 "libvndk",
Justin Yun48138672021-02-25 18:21:27 +0900604 ],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800605 arch: {
606 arm64: {
607 src: "libvendor.so",
608 export_include_dirs: ["include/libvendor"],
609 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700610 arm: {
611 src: "libvendor.so",
612 export_include_dirs: ["include/libvendor"],
613 },
614 },
615 }
616
Inseob Kima1888ce2022-10-04 14:42:02 +0900617 vendor_snapshot_shared {
618 name: "libvendor_override",
619 version: "31",
620 target_arch: "arm64",
621 compile_multilib: "both",
622 vendor: true,
623 overrides: ["libvendor"],
624 shared_libs: [
625 "libvendor_without_snapshot",
626 "libvendor_available",
627 "libvndk",
628 ],
629 arch: {
630 arm64: {
631 src: "override/libvendor.so",
632 export_include_dirs: ["include/libvendor"],
633 },
634 arm: {
635 src: "override/libvendor.so",
636 export_include_dirs: ["include/libvendor"],
637 },
638 },
639 }
640
Jose Galmesf9523ed2021-04-06 19:48:10 -0700641 vendor_snapshot_static {
642 name: "lib32",
Justin Yundee806f2021-05-18 23:10:00 +0900643 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700644 target_arch: "arm64",
645 compile_multilib: "32",
646 vendor: true,
647 arch: {
648 arm: {
649 src: "lib32.a",
650 },
651 },
652 }
653
654 vendor_snapshot_shared {
655 name: "lib32",
Justin Yundee806f2021-05-18 23:10:00 +0900656 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700657 target_arch: "arm64",
658 compile_multilib: "32",
659 vendor: true,
660 arch: {
661 arm: {
662 src: "lib32.so",
663 },
664 },
665 }
666
667 vendor_snapshot_static {
668 name: "lib64",
Justin Yundee806f2021-05-18 23:10:00 +0900669 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700670 target_arch: "arm64",
671 compile_multilib: "64",
672 vendor: true,
673 arch: {
674 arm64: {
675 src: "lib64.a",
676 },
677 },
678 }
679
680 vendor_snapshot_shared {
681 name: "lib64",
Justin Yundee806f2021-05-18 23:10:00 +0900682 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700683 target_arch: "arm64",
684 compile_multilib: "64",
685 vendor: true,
686 arch: {
687 arm64: {
688 src: "lib64.so",
689 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800690 },
691 }
692
693 vendor_snapshot_static {
694 name: "libvendor",
Justin Yundee806f2021-05-18 23:10:00 +0900695 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800696 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700697 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800698 vendor: true,
699 arch: {
700 arm64: {
Inseob Kimf7aadf72021-04-13 10:15:31 +0900701 cfi: {
702 src: "libvendor.cfi.a",
703 export_include_dirs: ["include/libvendor_cfi"],
704 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800705 src: "libvendor.a",
706 export_include_dirs: ["include/libvendor"],
707 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700708 arm: {
Inseob Kimf7aadf72021-04-13 10:15:31 +0900709 cfi: {
710 src: "libvendor.cfi.a",
711 export_include_dirs: ["include/libvendor_cfi"],
712 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700713 src: "libvendor.a",
714 export_include_dirs: ["include/libvendor"],
715 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800716 },
717 }
718
Colin Cross2e577f32021-01-22 13:06:25 -0800719 vendor_snapshot_shared {
720 name: "libvendor_available",
Justin Yundee806f2021-05-18 23:10:00 +0900721 version: "31",
Colin Cross2e577f32021-01-22 13:06:25 -0800722 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700723 compile_multilib: "both",
Colin Cross2e577f32021-01-22 13:06:25 -0800724 vendor: true,
725 arch: {
726 arm64: {
727 src: "libvendor_available.so",
728 export_include_dirs: ["include/libvendor"],
729 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700730 arm: {
731 src: "libvendor_available.so",
732 export_include_dirs: ["include/libvendor"],
733 },
Colin Cross2e577f32021-01-22 13:06:25 -0800734 },
735 }
736
737 vendor_snapshot_static {
738 name: "libvendor_available",
Justin Yundee806f2021-05-18 23:10:00 +0900739 version: "31",
Colin Cross2e577f32021-01-22 13:06:25 -0800740 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700741 compile_multilib: "both",
Colin Cross2e577f32021-01-22 13:06:25 -0800742 vendor: true,
743 arch: {
744 arm64: {
745 src: "libvendor_available.a",
746 export_include_dirs: ["include/libvendor"],
747 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700748 arm: {
749 src: "libvendor_available.so",
750 export_include_dirs: ["include/libvendor"],
751 },
Colin Cross2e577f32021-01-22 13:06:25 -0800752 },
753 }
754
Inseob Kimd4c9f552021-04-08 19:28:28 +0900755 vendor_snapshot_static {
756 name: "libc++_static",
Justin Yundee806f2021-05-18 23:10:00 +0900757 version: "31",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900758 target_arch: "arm64",
759 compile_multilib: "64",
760 vendor: true,
761 arch: {
762 arm64: {
763 src: "libc++_static.a",
764 },
765 },
766 }
767
768 vendor_snapshot_static {
769 name: "libc++demangle",
Justin Yundee806f2021-05-18 23:10:00 +0900770 version: "31",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900771 target_arch: "arm64",
772 compile_multilib: "64",
773 vendor: true,
774 arch: {
775 arm64: {
776 src: "libc++demangle.a",
777 },
778 },
779 }
780
781 vendor_snapshot_static {
Justin Yundee806f2021-05-18 23:10:00 +0900782 name: "libunwind",
783 version: "31",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900784 target_arch: "arm64",
785 compile_multilib: "64",
786 vendor: true,
787 arch: {
788 arm64: {
Justin Yundee806f2021-05-18 23:10:00 +0900789 src: "libunwind.a",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900790 },
791 },
792 }
793
Colin Cross0fce0ba2021-01-08 16:40:12 -0800794 vendor_snapshot_binary {
795 name: "bin",
Justin Yundee806f2021-05-18 23:10:00 +0900796 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800797 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700798 compile_multilib: "64",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800799 vendor: true,
800 arch: {
801 arm64: {
802 src: "bin",
803 },
804 },
Inseob Kim4d945ee2022-02-24 10:29:18 +0900805 symlinks: ["binfoo", "binbar"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800806 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800807
Jose Galmesf9523ed2021-04-06 19:48:10 -0700808 vendor_snapshot_binary {
Inseob Kima1888ce2022-10-04 14:42:02 +0900809 name: "bin_override",
810 version: "31",
811 target_arch: "arm64",
812 compile_multilib: "64",
813 vendor: true,
814 overrides: ["bin"],
815 arch: {
816 arm64: {
817 src: "override/bin",
818 },
819 },
820 symlinks: ["binfoo", "binbar"],
821 }
822
823 vendor_snapshot_binary {
Jose Galmesf9523ed2021-04-06 19:48:10 -0700824 name: "bin32",
Justin Yundee806f2021-05-18 23:10:00 +0900825 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700826 target_arch: "arm64",
827 compile_multilib: "32",
828 vendor: true,
829 arch: {
830 arm: {
831 src: "bin32",
832 },
833 },
834 }
835
Colin Crosse0edaf92021-01-11 17:31:17 -0800836 // old snapshot module which has to be ignored
837 vendor_snapshot_binary {
838 name: "bin",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900839 version: "26",
Colin Crosse0edaf92021-01-11 17:31:17 -0800840 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700841 compile_multilib: "first",
842 vendor: true,
843 arch: {
844 arm64: {
845 src: "bin",
846 },
847 },
848 }
849
850 // different arch snapshot which has to be ignored
851 vendor_snapshot_binary {
852 name: "bin",
Justin Yundee806f2021-05-18 23:10:00 +0900853 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700854 target_arch: "arm",
855 compile_multilib: "first",
Colin Crosse0edaf92021-01-11 17:31:17 -0800856 vendor: true,
857 arch: {
858 arm64: {
859 src: "bin",
860 },
861 },
862 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800863`
864 depsBp := GatherRequiredDepsForTest(android.Android)
865
866 mockFS := map[string][]byte{
Inseob Kimf7aadf72021-04-13 10:15:31 +0900867 "deps/Android.bp": []byte(depsBp),
868 "framework/Android.bp": []byte(frameworkBp),
869 "framework/symbol.txt": nil,
870 "vendor/Android.bp": []byte(vendorProprietaryBp),
871 "vendor/bin": nil,
Inseob Kima1888ce2022-10-04 14:42:02 +0900872 "vendor/override/bin": nil,
Inseob Kimf7aadf72021-04-13 10:15:31 +0900873 "vendor/bin32": nil,
874 "vendor/bin.cpp": nil,
875 "vendor/client.cpp": nil,
876 "vendor/include/libvndk/a.h": nil,
877 "vendor/include/libvendor/b.h": nil,
878 "vendor/include/libvendor_cfi/c.h": nil,
879 "vendor/libc++_static.a": nil,
880 "vendor/libc++demangle.a": nil,
Justin Yundee806f2021-05-18 23:10:00 +0900881 "vendor/libunwind.a": nil,
Inseob Kimf7aadf72021-04-13 10:15:31 +0900882 "vendor/libvndk.a": nil,
883 "vendor/libvendor.a": nil,
884 "vendor/libvendor.cfi.a": nil,
885 "vendor/libvendor.so": nil,
Inseob Kima1888ce2022-10-04 14:42:02 +0900886 "vendor/override/libvendor.so": nil,
Inseob Kimf7aadf72021-04-13 10:15:31 +0900887 "vendor/lib32.a": nil,
888 "vendor/lib32.so": nil,
889 "vendor/lib64.a": nil,
890 "vendor/lib64.so": nil,
891 "vndk/Android.bp": []byte(vndkBp),
892 "vndk/include/libvndk/a.h": nil,
893 "vndk/libvndk.so": nil,
Justin Yundee806f2021-05-18 23:10:00 +0900894 "vndk/libllndk.so": nil,
Colin Cross0fce0ba2021-01-08 16:40:12 -0800895 }
896
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000897 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Justin Yundee806f2021-05-18 23:10:00 +0900898 config.TestProductVariables.DeviceVndkVersion = StringPtr("31")
899 config.TestProductVariables.Platform_vndk_version = StringPtr("32")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800900 ctx := CreateTestContext(config)
901 ctx.Register()
902
903 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "vendor/Android.bp", "vndk/Android.bp"})
904 android.FailIfErrored(t, errs)
905 _, errs = ctx.PrepareBuildActions(config)
906 android.FailIfErrored(t, errs)
907
Justin Yundee806f2021-05-18 23:10:00 +0900908 sharedVariant := "android_vendor.31_arm64_armv8-a_shared"
909 staticVariant := "android_vendor.31_arm64_armv8-a_static"
910 binaryVariant := "android_vendor.31_arm64_armv8-a"
Colin Cross0fce0ba2021-01-08 16:40:12 -0800911
Justin Yundee806f2021-05-18 23:10:00 +0900912 sharedCfiVariant := "android_vendor.31_arm64_armv8-a_shared_cfi"
913 staticCfiVariant := "android_vendor.31_arm64_armv8-a_static_cfi"
Inseob Kimf7aadf72021-04-13 10:15:31 +0900914
Justin Yundee806f2021-05-18 23:10:00 +0900915 shared32Variant := "android_vendor.31_arm_armv7-a-neon_shared"
916 binary32Variant := "android_vendor.31_arm_armv7-a-neon"
Jose Galmesf9523ed2021-04-06 19:48:10 -0700917
Justin Yundee806f2021-05-18 23:10:00 +0900918 // libclient uses libvndk.vndk.31.arm64, libvendor.vendor_static.31.arm64, libvendor_without_snapshot
Colin Cross0fce0ba2021-01-08 16:40:12 -0800919 libclientCcFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("cc").Args["cFlags"]
920 for _, includeFlags := range []string{
921 "-Ivndk/include/libvndk", // libvndk
922 "-Ivendor/include/libvendor", // libvendor
923 } {
924 if !strings.Contains(libclientCcFlags, includeFlags) {
925 t.Errorf("flags for libclient must contain %#v, but was %#v.",
926 includeFlags, libclientCcFlags)
927 }
928 }
929
930 libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("ld").Args["libFlags"]
931 for _, input := range [][]string{
Justin Yundee806f2021-05-18 23:10:00 +0900932 []string{sharedVariant, "libvndk.vndk.31.arm64"},
933 []string{sharedVariant, "libllndk.vndk.31.arm64"},
934 []string{staticVariant, "libvendor.vendor_static.31.arm64"},
Colin Cross0fce0ba2021-01-08 16:40:12 -0800935 []string{staticVariant, "libvendor_without_snapshot"},
936 } {
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400937 outputPaths := GetOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800938 if !strings.Contains(libclientLdFlags, outputPaths[0].String()) {
939 t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags)
940 }
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400941
Colin Cross0fce0ba2021-01-08 16:40:12 -0800942 }
943
Colin Cross2e577f32021-01-22 13:06:25 -0800944 libclientAndroidMkSharedLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkSharedLibs
Justin Yundee806f2021-05-18 23:10:00 +0900945 if g, w := libclientAndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "libllndk.vendor", "lib64"}; !reflect.DeepEqual(g, w) {
Colin Cross2e577f32021-01-22 13:06:25 -0800946 t.Errorf("wanted libclient AndroidMkSharedLibs %q, got %q", w, g)
947 }
948
949 libclientAndroidMkStaticLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkStaticLibs
950 if g, w := libclientAndroidMkStaticLibs, []string{"libvendor", "libvendor_without_snapshot"}; !reflect.DeepEqual(g, w) {
951 t.Errorf("wanted libclient AndroidMkStaticLibs %q, got %q", w, g)
952 }
953
Jose Galmesf9523ed2021-04-06 19:48:10 -0700954 libclient32AndroidMkSharedLibs := ctx.ModuleForTests("libclient", shared32Variant).Module().(*Module).Properties.AndroidMkSharedLibs
Justin Yundee806f2021-05-18 23:10:00 +0900955 if g, w := libclient32AndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "libllndk.vendor", "lib32"}; !reflect.DeepEqual(g, w) {
Jose Galmesf9523ed2021-04-06 19:48:10 -0700956 t.Errorf("wanted libclient32 AndroidMkSharedLibs %q, got %q", w, g)
957 }
958
Justin Yundee806f2021-05-18 23:10:00 +0900959 // libclient_cfi uses libvendor.vendor_static.31.arm64's cfi variant
Inseob Kimf7aadf72021-04-13 10:15:31 +0900960 libclientCfiCcFlags := ctx.ModuleForTests("libclient_cfi", sharedCfiVariant).Rule("cc").Args["cFlags"]
961 if !strings.Contains(libclientCfiCcFlags, "-Ivendor/include/libvendor_cfi") {
962 t.Errorf("flags for libclient_cfi must contain %#v, but was %#v.",
963 "-Ivendor/include/libvendor_cfi", libclientCfiCcFlags)
964 }
965
966 libclientCfiLdFlags := ctx.ModuleForTests("libclient_cfi", sharedCfiVariant).Rule("ld").Args["libFlags"]
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400967 libvendorCfiOutputPaths := GetOutputPaths(ctx, staticCfiVariant, []string{"libvendor.vendor_static.31.arm64"})
Inseob Kimf7aadf72021-04-13 10:15:31 +0900968 if !strings.Contains(libclientCfiLdFlags, libvendorCfiOutputPaths[0].String()) {
969 t.Errorf("libflags for libclientCfi must contain %#v, but was %#v", libvendorCfiOutputPaths[0], libclientCfiLdFlags)
970 }
971
Justin Yundee806f2021-05-18 23:10:00 +0900972 // bin_without_snapshot uses libvndk.vendor_static.31.arm64 (which reexports vndk's exported headers)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800973 binWithoutSnapshotCcFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("cc").Args["cFlags"]
Inseob Kimdd0295d2021-04-12 21:09:59 +0900974 if !strings.Contains(binWithoutSnapshotCcFlags, "-Ivndk/include/libvndk") {
Colin Cross0fce0ba2021-01-08 16:40:12 -0800975 t.Errorf("flags for bin_without_snapshot must contain %#v, but was %#v.",
976 "-Ivendor/include/libvndk", binWithoutSnapshotCcFlags)
977 }
978
979 binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("ld").Args["libFlags"]
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400980 libVndkStaticOutputPaths := GetOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.31.arm64"})
Colin Cross0fce0ba2021-01-08 16:40:12 -0800981 if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) {
982 t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v",
983 libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags)
984 }
985
Justin Yundee806f2021-05-18 23:10:00 +0900986 // libvendor.so is installed by libvendor.vendor_shared.31.arm64
987 ctx.ModuleForTests("libvendor.vendor_shared.31.arm64", sharedVariant).Output("libvendor.so")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800988
Justin Yundee806f2021-05-18 23:10:00 +0900989 // lib64.so is installed by lib64.vendor_shared.31.arm64
990 ctx.ModuleForTests("lib64.vendor_shared.31.arm64", sharedVariant).Output("lib64.so")
Jose Galmesf9523ed2021-04-06 19:48:10 -0700991
Justin Yundee806f2021-05-18 23:10:00 +0900992 // lib32.so is installed by lib32.vendor_shared.31.arm64
993 ctx.ModuleForTests("lib32.vendor_shared.31.arm64", shared32Variant).Output("lib32.so")
Jose Galmesf9523ed2021-04-06 19:48:10 -0700994
Justin Yundee806f2021-05-18 23:10:00 +0900995 // libvendor_available.so is installed by libvendor_available.vendor_shared.31.arm64
996 ctx.ModuleForTests("libvendor_available.vendor_shared.31.arm64", sharedVariant).Output("libvendor_available.so")
Colin Cross2e577f32021-01-22 13:06:25 -0800997
Colin Cross0fce0ba2021-01-08 16:40:12 -0800998 // libvendor_without_snapshot.so is installed by libvendor_without_snapshot
999 ctx.ModuleForTests("libvendor_without_snapshot", sharedVariant).Output("libvendor_without_snapshot.so")
1000
Justin Yundee806f2021-05-18 23:10:00 +09001001 // bin is installed by bin.vendor_binary.31.arm64
Inseob Kim4d945ee2022-02-24 10:29:18 +09001002 bin64Module := ctx.ModuleForTests("bin.vendor_binary.31.arm64", binaryVariant)
1003 bin64Module.Output("bin")
1004
1005 // also test symlinks
1006 bin64MkEntries := android.AndroidMkEntriesForTest(t, ctx, bin64Module.Module())
1007 bin64KatiSymlinks := bin64MkEntries[0].EntryMap["LOCAL_SOONG_INSTALL_SYMLINKS"]
1008
1009 // Either AndroidMk entries contain symlinks, or symlinks should be installed by Soong
1010 for _, symlink := range []string{"binfoo", "binbar"} {
1011 if inList(symlink, bin64KatiSymlinks) {
1012 continue
1013 }
1014
1015 bin64Module.Output(symlink)
1016 }
Colin Cross0fce0ba2021-01-08 16:40:12 -08001017
Justin Yundee806f2021-05-18 23:10:00 +09001018 // bin32 is installed by bin32.vendor_binary.31.arm64
1019 ctx.ModuleForTests("bin32.vendor_binary.31.arm64", binary32Variant).Output("bin32")
Jose Galmesf9523ed2021-04-06 19:48:10 -07001020
Colin Cross0fce0ba2021-01-08 16:40:12 -08001021 // bin_without_snapshot is installed by bin_without_snapshot
1022 ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot")
1023
Justin Yundee806f2021-05-18 23:10:00 +09001024 // libvendor, libvendor_available and bin don't have vendor.31 variant
Colin Cross0fce0ba2021-01-08 16:40:12 -08001025 libvendorVariants := ctx.ModuleVariantsForTests("libvendor")
1026 if inList(sharedVariant, libvendorVariants) {
1027 t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant)
1028 }
1029
Colin Cross2e577f32021-01-22 13:06:25 -08001030 libvendorAvailableVariants := ctx.ModuleVariantsForTests("libvendor_available")
1031 if inList(sharedVariant, libvendorAvailableVariants) {
1032 t.Errorf("libvendor_available must not have variant %#v, but it does", sharedVariant)
1033 }
1034
Colin Cross0fce0ba2021-01-08 16:40:12 -08001035 binVariants := ctx.ModuleVariantsForTests("bin")
1036 if inList(binaryVariant, binVariants) {
1037 t.Errorf("bin must not have variant %#v, but it does", sharedVariant)
1038 }
Inseob Kima1888ce2022-10-04 14:42:02 +09001039
1040 // test overrides property
1041 binOverrideModule := ctx.ModuleForTests("bin_override.vendor_binary.31.arm64", binaryVariant)
1042 binOverrideModule.Output("bin")
1043 binOverrideMkEntries := android.AndroidMkEntriesForTest(t, ctx, binOverrideModule.Module())
1044 binOverrideEntry := binOverrideMkEntries[0].EntryMap["LOCAL_OVERRIDES_MODULES"]
1045 if !inList("bin", binOverrideEntry) {
1046 t.Errorf("bin_override must override bin but was %q\n", binOverrideEntry)
1047 }
1048
1049 libvendorOverrideModule := ctx.ModuleForTests("libvendor_override.vendor_shared.31.arm64", sharedVariant)
1050 libvendorOverrideModule.Output("libvendor.so")
1051 libvendorOverrideMkEntries := android.AndroidMkEntriesForTest(t, ctx, libvendorOverrideModule.Module())
1052 libvendorOverrideEntry := libvendorOverrideMkEntries[0].EntryMap["LOCAL_OVERRIDES_MODULES"]
1053 if !inList("libvendor", libvendorOverrideEntry) {
1054 t.Errorf("libvendor_override must override libvendor but was %q\n", libvendorOverrideEntry)
1055 }
Colin Cross0fce0ba2021-01-08 16:40:12 -08001056}
1057
1058func TestVendorSnapshotSanitizer(t *testing.T) {
1059 bp := `
Inseob Kim253f5212021-04-08 17:10:31 +09001060 vendor_snapshot {
1061 name: "vendor_snapshot",
1062 version: "28",
1063 arch: {
1064 arm64: {
1065 static_libs: [
1066 "libsnapshot",
1067 "note_memtag_heap_sync",
1068 ],
Justin Yun08270c62022-12-19 17:01:26 +09001069 objects: [
1070 "snapshot_object",
1071 ],
1072 vndk_libs: [
1073 "libclang_rt.hwasan",
1074 ],
Inseob Kim253f5212021-04-08 17:10:31 +09001075 },
1076 },
1077 }
Justin Yun39c30312022-11-23 16:20:12 +09001078
Colin Cross0fce0ba2021-01-08 16:40:12 -08001079 vendor_snapshot_static {
1080 name: "libsnapshot",
1081 vendor: true,
1082 target_arch: "arm64",
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001083 version: "28",
Colin Cross0fce0ba2021-01-08 16:40:12 -08001084 arch: {
1085 arm64: {
1086 src: "libsnapshot.a",
1087 cfi: {
1088 src: "libsnapshot.cfi.a",
Justin Yun39c30312022-11-23 16:20:12 +09001089 },
1090 hwasan: {
1091 src: "libsnapshot.hwasan.a",
1092 },
Colin Cross0fce0ba2021-01-08 16:40:12 -08001093 },
1094 },
1095 }
Inseob Kim253f5212021-04-08 17:10:31 +09001096
1097 vendor_snapshot_static {
1098 name: "note_memtag_heap_sync",
1099 vendor: true,
1100 target_arch: "arm64",
1101 version: "28",
1102 arch: {
1103 arm64: {
1104 src: "note_memtag_heap_sync.a",
1105 },
1106 },
1107 }
1108
Justin Yun08270c62022-12-19 17:01:26 +09001109 vndk_prebuilt_shared {
1110 name: "libclang_rt.hwasan",
1111 version: "28",
1112 target_arch: "arm64",
1113 vendor_available: true,
1114 product_available: true,
1115 vndk: {
1116 enabled: true,
1117 },
1118 arch: {
1119 arm64: {
1120 srcs: ["libclang_rt.hwasan.so"],
1121 },
1122 },
1123 }
1124
1125 vendor_snapshot_object {
1126 name: "snapshot_object",
1127 vendor: true,
1128 target_arch: "arm64",
1129 version: "28",
1130 arch: {
1131 arm64: {
1132 src: "snapshot_object.o",
1133 },
1134 },
1135 stl: "none",
1136 }
1137
Inseob Kim253f5212021-04-08 17:10:31 +09001138 cc_test {
1139 name: "vstest",
1140 gtest: false,
1141 vendor: true,
1142 compile_multilib: "64",
1143 nocrt: true,
1144 no_libcrt: true,
1145 stl: "none",
1146 static_libs: ["libsnapshot"],
1147 system_shared_libs: [],
1148 }
Colin Cross0fce0ba2021-01-08 16:40:12 -08001149`
Inseob Kim253f5212021-04-08 17:10:31 +09001150
1151 mockFS := map[string][]byte{
1152 "vendor/Android.bp": []byte(bp),
1153 "vendor/libc++demangle.a": nil,
Justin Yun08270c62022-12-19 17:01:26 +09001154 "vendor/libclang_rt.hwasan.so": nil,
Inseob Kim253f5212021-04-08 17:10:31 +09001155 "vendor/libsnapshot.a": nil,
1156 "vendor/libsnapshot.cfi.a": nil,
Justin Yun39c30312022-11-23 16:20:12 +09001157 "vendor/libsnapshot.hwasan.a": nil,
Inseob Kim253f5212021-04-08 17:10:31 +09001158 "vendor/note_memtag_heap_sync.a": nil,
Justin Yun08270c62022-12-19 17:01:26 +09001159 "vendor/snapshot_object.o": nil,
Inseob Kim253f5212021-04-08 17:10:31 +09001160 }
1161
1162 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001163 config.TestProductVariables.DeviceVndkVersion = StringPtr("28")
1164 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Justin Yun08270c62022-12-19 17:01:26 +09001165 config.TestProductVariables.SanitizeDevice = []string{"hwaddress"}
Colin Cross0fce0ba2021-01-08 16:40:12 -08001166 ctx := testCcWithConfig(t, config)
1167
Justin Yun39c30312022-11-23 16:20:12 +09001168 // Check non-cfi, cfi and hwasan variant.
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001169 staticVariant := "android_vendor.28_arm64_armv8-a_static"
1170 staticCfiVariant := "android_vendor.28_arm64_armv8-a_static_cfi"
Justin Yun39c30312022-11-23 16:20:12 +09001171 staticHwasanVariant := "android_vendor.28_arm64_armv8-a_static_hwasan"
1172 staticHwasanCfiVariant := "android_vendor.28_arm64_armv8-a_static_hwasan_cfi"
Colin Cross0fce0ba2021-01-08 16:40:12 -08001173
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001174 staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001175 assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a")
1176
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001177 staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticCfiVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001178 assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
Justin Yun39c30312022-11-23 16:20:12 +09001179
1180 staticHwasanModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticHwasanVariant).Module().(*Module)
1181 assertString(t, staticHwasanModule.outputFile.Path().Base(), "libsnapshot.hwasan.a")
1182
1183 staticHwasanCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticHwasanCfiVariant).Module().(*Module)
1184 if !staticHwasanCfiModule.HiddenFromMake() || !staticHwasanCfiModule.PreventInstall() {
1185 t.Errorf("Hwasan and Cfi cannot enabled at the same time.")
1186 }
Justin Yun08270c62022-12-19 17:01:26 +09001187
1188 snapshotObjModule := ctx.ModuleForTests("snapshot_object.vendor_object.28.arm64", "android_vendor.28_arm64_armv8-a").Module()
1189 snapshotObjMkEntries := android.AndroidMkEntriesForTest(t, ctx, snapshotObjModule)
1190 // snapshot object must not add ".hwasan" suffix
1191 assertString(t, snapshotObjMkEntries[0].EntryMap["LOCAL_MODULE"][0], "snapshot_object")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001192}
1193
Colin Cross0fce0ba2021-01-08 16:40:12 -08001194func TestVendorSnapshotExclude(t *testing.T) {
1195
1196 // This test verifies that the exclude_from_vendor_snapshot property
1197 // makes its way from the Android.bp source file into the module data
1198 // structure. It also verifies that modules are correctly included or
1199 // excluded in the vendor snapshot based on their path (framework or
1200 // vendor) and the exclude_from_vendor_snapshot property.
1201
1202 frameworkBp := `
1203 cc_library_shared {
1204 name: "libinclude",
1205 srcs: ["src/include.cpp"],
1206 vendor_available: true,
1207 }
1208 cc_library_shared {
1209 name: "libexclude",
1210 srcs: ["src/exclude.cpp"],
1211 vendor: true,
1212 exclude_from_vendor_snapshot: true,
1213 }
1214 cc_library_shared {
1215 name: "libavailable_exclude",
1216 srcs: ["src/exclude.cpp"],
1217 vendor_available: true,
1218 exclude_from_vendor_snapshot: true,
1219 }
1220 `
1221
1222 vendorProprietaryBp := `
1223 cc_library_shared {
1224 name: "libvendor",
1225 srcs: ["vendor.cpp"],
1226 vendor: true,
1227 }
1228 `
1229
1230 depsBp := GatherRequiredDepsForTest(android.Android)
1231
1232 mockFS := map[string][]byte{
1233 "deps/Android.bp": []byte(depsBp),
1234 "framework/Android.bp": []byte(frameworkBp),
1235 "framework/include.cpp": nil,
1236 "framework/exclude.cpp": nil,
1237 "device/Android.bp": []byte(vendorProprietaryBp),
1238 "device/vendor.cpp": nil,
1239 }
1240
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001241 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001242 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001243 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001244 ctx := CreateTestContext(config)
1245 ctx.Register()
1246
1247 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1248 android.FailIfErrored(t, errs)
1249 _, errs = ctx.PrepareBuildActions(config)
1250 android.FailIfErrored(t, errs)
1251
1252 // Test an include and exclude framework module.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001253 AssertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false, vendorVariant)
1254 AssertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true, vendorVariant)
1255 AssertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true, vendorVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001256
1257 // A vendor module is excluded, but by its path, not the
1258 // exclude_from_vendor_snapshot property.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001259 AssertExcludeFromVendorSnapshotIs(t, ctx, "libvendor", false, vendorVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001260
1261 // Verify the content of the vendor snapshot.
1262
1263 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001264 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001265 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1266
1267 var includeJsonFiles []string
1268 var excludeJsonFiles []string
1269
1270 for _, arch := range [][]string{
1271 []string{"arm64", "armv8-a"},
1272 []string{"arm", "armv7-a-neon"},
1273 } {
1274 archType := arch[0]
1275 archVariant := arch[1]
1276 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1277
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001278 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001279 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1280
1281 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001282 CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001283 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1284
1285 // Excluded modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001286 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001287 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001288 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001289 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001290 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001291 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1292 }
1293
1294 // Verify that each json file for an included module has a rule.
1295 for _, jsonFile := range includeJsonFiles {
1296 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1297 t.Errorf("include json file %q not found", jsonFile)
1298 }
1299 }
1300
1301 // Verify that each json file for an excluded module has no rule.
1302 for _, jsonFile := range excludeJsonFiles {
1303 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1304 t.Errorf("exclude json file %q found", jsonFile)
1305 }
1306 }
1307}
1308
1309func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) {
1310
1311 // This test verifies that using the exclude_from_vendor_snapshot
1312 // property on a module in a vendor proprietary path generates an
1313 // error. These modules are already excluded, so we prohibit using the
1314 // property in this way, which could add to confusion.
1315
1316 vendorProprietaryBp := `
1317 cc_library_shared {
1318 name: "libvendor",
1319 srcs: ["vendor.cpp"],
1320 vendor: true,
1321 exclude_from_vendor_snapshot: true,
1322 }
1323 `
1324
1325 depsBp := GatherRequiredDepsForTest(android.Android)
1326
1327 mockFS := map[string][]byte{
1328 "deps/Android.bp": []byte(depsBp),
1329 "device/Android.bp": []byte(vendorProprietaryBp),
1330 "device/vendor.cpp": nil,
1331 }
1332
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001333 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001334 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001335 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001336 ctx := CreateTestContext(config)
1337 ctx.Register()
1338
1339 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"})
1340 android.FailIfErrored(t, errs)
1341
1342 _, errs = ctx.PrepareBuildActions(config)
1343 android.CheckErrorsAgainstExpectations(t, errs, []string{
1344 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1345 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1346 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1347 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1348 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1349 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1350 })
1351}
1352
1353func TestRecoverySnapshotCapture(t *testing.T) {
1354 bp := `
1355 cc_library {
1356 name: "libvndk",
1357 vendor_available: true,
1358 recovery_available: true,
1359 product_available: true,
1360 vndk: {
1361 enabled: true,
1362 },
1363 nocrt: true,
1364 }
1365
1366 cc_library {
1367 name: "librecovery",
1368 recovery: true,
1369 nocrt: true,
1370 }
1371
1372 cc_library {
1373 name: "librecovery_available",
1374 recovery_available: true,
1375 nocrt: true,
1376 }
1377
1378 cc_library_headers {
1379 name: "librecovery_headers",
1380 recovery_available: true,
1381 nocrt: true,
1382 }
1383
1384 cc_binary {
1385 name: "recovery_bin",
1386 recovery: true,
1387 nocrt: true,
1388 }
1389
1390 cc_binary {
1391 name: "recovery_available_bin",
1392 recovery_available: true,
1393 nocrt: true,
1394 }
1395
Liz Kammer718eb272022-01-07 10:53:37 -05001396 cc_prebuilt_library_static {
Colin Cross0fce0ba2021-01-08 16:40:12 -08001397 name: "libb",
1398 recovery_available: true,
Liz Kammer718eb272022-01-07 10:53:37 -05001399 srcs: ["libb.a"],
1400 nocrt: true,
1401 no_libcrt: true,
1402 stl: "none",
Colin Cross0fce0ba2021-01-08 16:40:12 -08001403 }
1404
1405 cc_object {
1406 name: "obj",
1407 recovery_available: true,
1408 }
1409`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001410 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001411 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001412 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001413 ctx := testCcWithConfig(t, config)
1414
1415 // Check Recovery snapshot output.
1416
1417 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001418 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001419 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1420
1421 var jsonFiles []string
1422
1423 for _, arch := range [][]string{
1424 []string{"arm64", "armv8-a"},
1425 } {
1426 archType := arch[0]
1427 archVariant := arch[1]
1428 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1429
1430 // For shared libraries, only recovery_available modules are captured.
1431 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1432 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001433 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant)
1434 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1435 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001436 jsonFiles = append(jsonFiles,
1437 filepath.Join(sharedDir, "libvndk.so.json"),
1438 filepath.Join(sharedDir, "librecovery.so.json"),
1439 filepath.Join(sharedDir, "librecovery_available.so.json"))
1440
1441 // For static libraries, all recovery:true and recovery_available modules are captured.
1442 staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
1443 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001444 CheckSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
1445 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
1446 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001447 jsonFiles = append(jsonFiles,
1448 filepath.Join(staticDir, "libb.a.json"),
1449 filepath.Join(staticDir, "librecovery.a.json"),
1450 filepath.Join(staticDir, "librecovery_available.a.json"))
1451
1452 // For binary executables, all recovery:true and recovery_available modules are captured.
1453 if archType == "arm64" {
1454 binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1455 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001456 CheckSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
1457 CheckSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001458 jsonFiles = append(jsonFiles,
1459 filepath.Join(binaryDir, "recovery_bin.json"),
1460 filepath.Join(binaryDir, "recovery_available_bin.json"))
1461 }
1462
1463 // For header libraries, all vendor:true and vendor_available modules are captured.
1464 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
1465 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json"))
1466
1467 // For object modules, all vendor:true and vendor_available modules are captured.
1468 objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1469 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001470 CheckSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001471 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
1472 }
1473
1474 for _, jsonFile := range jsonFiles {
1475 // verify all json files exist
1476 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1477 t.Errorf("%q expected but not found", jsonFile)
1478 }
1479 }
1480}
1481
1482func TestRecoverySnapshotExclude(t *testing.T) {
1483 // This test verifies that the exclude_from_recovery_snapshot property
1484 // makes its way from the Android.bp source file into the module data
1485 // structure. It also verifies that modules are correctly included or
1486 // excluded in the recovery snapshot based on their path (framework or
1487 // vendor) and the exclude_from_recovery_snapshot property.
1488
1489 frameworkBp := `
1490 cc_library_shared {
1491 name: "libinclude",
1492 srcs: ["src/include.cpp"],
1493 recovery_available: true,
1494 }
1495 cc_library_shared {
1496 name: "libexclude",
1497 srcs: ["src/exclude.cpp"],
1498 recovery: true,
1499 exclude_from_recovery_snapshot: true,
1500 }
1501 cc_library_shared {
1502 name: "libavailable_exclude",
1503 srcs: ["src/exclude.cpp"],
1504 recovery_available: true,
1505 exclude_from_recovery_snapshot: true,
1506 }
1507 `
1508
1509 vendorProprietaryBp := `
1510 cc_library_shared {
1511 name: "librecovery",
1512 srcs: ["recovery.cpp"],
1513 recovery: true,
1514 }
1515 `
1516
1517 depsBp := GatherRequiredDepsForTest(android.Android)
1518
1519 mockFS := map[string][]byte{
1520 "deps/Android.bp": []byte(depsBp),
1521 "framework/Android.bp": []byte(frameworkBp),
1522 "framework/include.cpp": nil,
1523 "framework/exclude.cpp": nil,
1524 "device/Android.bp": []byte(vendorProprietaryBp),
1525 "device/recovery.cpp": nil,
1526 }
1527
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001528 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001529 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001530 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001531 ctx := CreateTestContext(config)
1532 ctx.Register()
1533
1534 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1535 android.FailIfErrored(t, errs)
1536 _, errs = ctx.PrepareBuildActions(config)
1537 android.FailIfErrored(t, errs)
1538
1539 // Test an include and exclude framework module.
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001540 AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false, recoveryVariant)
1541 AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true, recoveryVariant)
1542 AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true, recoveryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001543
1544 // A recovery module is excluded, but by its path, not the
1545 // exclude_from_recovery_snapshot property.
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001546 AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false, recoveryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001547
1548 // Verify the content of the recovery snapshot.
1549
1550 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001551 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001552 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1553
1554 var includeJsonFiles []string
1555 var excludeJsonFiles []string
1556
1557 for _, arch := range [][]string{
1558 []string{"arm64", "armv8-a"},
1559 } {
1560 archType := arch[0]
1561 archVariant := arch[1]
1562 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1563
1564 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1565 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1566
1567 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001568 CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001569 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1570
1571 // Excluded modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001572 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001573 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001574 CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001575 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001576 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001577 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1578 }
1579
1580 // Verify that each json file for an included module has a rule.
1581 for _, jsonFile := range includeJsonFiles {
1582 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1583 t.Errorf("include json file %q not found", jsonFile)
1584 }
1585 }
1586
1587 // Verify that each json file for an excluded module has no rule.
1588 for _, jsonFile := range excludeJsonFiles {
1589 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1590 t.Errorf("exclude json file %q found", jsonFile)
1591 }
1592 }
1593}
Jose Galmes4c6895e2021-02-09 07:44:30 -08001594
1595func TestRecoverySnapshotDirected(t *testing.T) {
1596 bp := `
1597 cc_library_shared {
1598 name: "librecovery",
1599 recovery: true,
1600 nocrt: true,
1601 }
1602
1603 cc_library_shared {
1604 name: "librecovery_available",
1605 recovery_available: true,
1606 nocrt: true,
1607 }
1608
1609 genrule {
1610 name: "libfoo_gen",
1611 cmd: "",
1612 out: ["libfoo.so"],
1613 }
1614
1615 cc_prebuilt_library_shared {
1616 name: "libfoo",
1617 recovery: true,
1618 prefer: true,
1619 srcs: [":libfoo_gen"],
1620 }
1621
1622 cc_library_shared {
1623 name: "libfoo",
1624 recovery: true,
1625 nocrt: true,
1626 }
1627`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001628 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001629 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1630 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001631 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001632 config.TestProductVariables.DirectedRecoverySnapshot = true
1633 config.TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
1634 config.TestProductVariables.RecoverySnapshotModules["librecovery"] = true
1635 config.TestProductVariables.RecoverySnapshotModules["libfoo"] = true
1636 ctx := testCcWithConfig(t, config)
1637
1638 // Check recovery snapshot output.
1639
1640 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001641 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001642 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1643
1644 var includeJsonFiles []string
1645
1646 for _, arch := range [][]string{
1647 []string{"arm64", "armv8-a"},
1648 } {
1649 archType := arch[0]
1650 archVariant := arch[1]
1651 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1652
1653 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1654 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1655
1656 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001657 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001658 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1659 // Check that snapshot captures "prefer: true" prebuilt
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001660 CheckSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001661 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
1662
1663 // Excluded modules. Modules not included in the directed recovery snapshot
1664 // are still include as fake modules.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001665 CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001666 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json"))
1667 }
1668
1669 // Verify that each json file for an included module has a rule.
1670 for _, jsonFile := range includeJsonFiles {
1671 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1672 t.Errorf("include json file %q not found", jsonFile)
1673 }
1674 }
1675}
Justin Yun17d0ee22023-05-02 14:56:38 +09001676
1677func TestSnapshotInRelativeInstallPath(t *testing.T) {
1678 bp := `
1679 cc_library {
1680 name: "libvendor_available",
1681 vendor_available: true,
1682 nocrt: true,
1683 }
1684
1685 cc_library {
1686 name: "libvendor_available_var",
1687 vendor_available: true,
1688 stem: "libvendor_available",
1689 relative_install_path: "var",
1690 nocrt: true,
1691 }
1692`
1693
1694 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
1695 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1696 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
1697 ctx := testCcWithConfig(t, config)
1698
1699 // Check Vendor snapshot output.
1700
1701 snapshotDir := "vendor-snapshot"
1702 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
1703 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1704
1705 var jsonFiles []string
1706
1707 for _, arch := range [][]string{
1708 []string{"arm64", "armv8-a"},
1709 []string{"arm", "armv7-a-neon"},
1710 } {
1711 archType := arch[0]
1712 archVariant := arch[1]
1713 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1714
1715 // For shared libraries, only non-VNDK vendor_available modules are captured
1716 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
1717 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1718 sharedDirVar := filepath.Join(sharedDir, "var")
1719 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
1720 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available_var", "libvendor_available.so", sharedDirVar, sharedVariant)
1721 jsonFiles = append(jsonFiles,
1722 filepath.Join(sharedDir, "libvendor_available.so.json"),
1723 filepath.Join(sharedDirVar, "libvendor_available.so.json"))
1724 }
1725
1726 for _, jsonFile := range jsonFiles {
1727 // verify all json files exist
1728 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1729 t.Errorf("%q expected but not found", jsonFile)
1730 }
1731 }
1732
1733 // fake snapshot should have all outputs in the normal snapshot.
1734 fakeSnapshotSingleton := ctx.SingletonForTests("vendor-fake-snapshot")
1735 for _, output := range snapshotSingleton.AllOutputs() {
1736 fakeOutput := strings.Replace(output, "/vendor-snapshot/", "/fake/vendor-snapshot/", 1)
1737 if fakeSnapshotSingleton.MaybeOutput(fakeOutput).Rule == nil {
1738 t.Errorf("%q expected but not found", fakeOutput)
1739 }
1740 }
1741}