blob: 0a55431467ccba7b99dbc977a3b8cb4e3ba94601 [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,
Kalesh Singhf4ffe0a2024-01-29 13:01:51 -0800344 no_crt_pad_segment: true,
Jose Galmesf9523ed2021-04-06 19:48:10 -0700345 stl: "none",
346 system_shared_libs: [],
Colin Cross2e577f32021-01-22 13:06:25 -0800347 compile_multilib: "64",
348 }
349
Justin Yundee806f2021-05-18 23:10:00 +0900350 cc_library {
351 name: "libllndk",
352 llndk: {
353 symbol_file: "libllndk.map.txt",
354 },
355 }
356
Colin Cross0fce0ba2021-01-08 16:40:12 -0800357 cc_binary {
358 name: "bin",
359 vendor: true,
360 nocrt: true,
361 no_libcrt: true,
362 stl: "none",
363 system_shared_libs: [],
Jose Galmesf9523ed2021-04-06 19:48:10 -0700364 }
365
366 cc_binary {
367 name: "bin32",
368 vendor: true,
369 nocrt: true,
370 no_libcrt: true,
371 stl: "none",
372 system_shared_libs: [],
373 compile_multilib: "32",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800374 }
375`
376
377 vndkBp := `
378 vndk_prebuilt_shared {
379 name: "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900380 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800381 target_arch: "arm64",
382 vendor_available: true,
383 product_available: true,
384 vndk: {
385 enabled: true,
386 },
387 arch: {
388 arm64: {
389 srcs: ["libvndk.so"],
390 export_include_dirs: ["include/libvndk"],
391 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700392 arm: {
393 srcs: ["libvndk.so"],
394 export_include_dirs: ["include/libvndk"],
395 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800396 },
397 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800398
399 // old snapshot module which has to be ignored
400 vndk_prebuilt_shared {
401 name: "libvndk",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900402 version: "26",
Colin Crosse0edaf92021-01-11 17:31:17 -0800403 target_arch: "arm64",
404 vendor_available: true,
405 product_available: true,
406 vndk: {
407 enabled: true,
408 },
409 arch: {
410 arm64: {
411 srcs: ["libvndk.so"],
412 export_include_dirs: ["include/libvndk"],
413 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700414 arm: {
415 srcs: ["libvndk.so"],
416 export_include_dirs: ["include/libvndk"],
417 },
418 },
419 }
420
421 // different arch snapshot which has to be ignored
422 vndk_prebuilt_shared {
423 name: "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900424 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700425 target_arch: "arm",
426 vendor_available: true,
427 product_available: true,
428 vndk: {
429 enabled: true,
430 },
431 arch: {
432 arm: {
433 srcs: ["libvndk.so"],
434 export_include_dirs: ["include/libvndk"],
435 },
Colin Crosse0edaf92021-01-11 17:31:17 -0800436 },
437 }
Justin Yundee806f2021-05-18 23:10:00 +0900438
439 vndk_prebuilt_shared {
440 name: "libllndk",
441 version: "31",
442 target_arch: "arm64",
443 vendor_available: true,
444 product_available: true,
445 arch: {
446 arm64: {
447 srcs: ["libllndk.so"],
448 },
449 arm: {
450 srcs: ["libllndk.so"],
451 },
452 },
453 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800454`
455
456 vendorProprietaryBp := `
457 cc_library {
458 name: "libvendor_without_snapshot",
459 vendor: true,
460 nocrt: true,
461 no_libcrt: true,
Kalesh Singhf4ffe0a2024-01-29 13:01:51 -0800462 no_crt_pad_segment: true,
Colin Cross0fce0ba2021-01-08 16:40:12 -0800463 stl: "none",
464 system_shared_libs: [],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800465 }
466
467 cc_library_shared {
468 name: "libclient",
469 vendor: true,
470 nocrt: true,
471 no_libcrt: true,
Kalesh Singhf4ffe0a2024-01-29 13:01:51 -0800472 no_crt_pad_segment: true,
Colin Cross0fce0ba2021-01-08 16:40:12 -0800473 stl: "none",
474 system_shared_libs: [],
Justin Yundee806f2021-05-18 23:10:00 +0900475 shared_libs: ["libvndk", "libvendor_available", "libllndk"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800476 static_libs: ["libvendor", "libvendor_without_snapshot"],
Jose Galmesf9523ed2021-04-06 19:48:10 -0700477 arch: {
478 arm64: {
479 shared_libs: ["lib64"],
480 },
481 arm: {
482 shared_libs: ["lib32"],
483 },
484 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800485 srcs: ["client.cpp"],
486 }
487
Inseob Kimf7aadf72021-04-13 10:15:31 +0900488 cc_library_shared {
489 name: "libclient_cfi",
490 vendor: true,
491 nocrt: true,
492 no_libcrt: true,
Kalesh Singhf4ffe0a2024-01-29 13:01:51 -0800493 no_crt_pad_segment: true,
Inseob Kimf7aadf72021-04-13 10:15:31 +0900494 stl: "none",
495 system_shared_libs: [],
496 static_libs: ["libvendor"],
497 sanitize: {
498 cfi: true,
499 },
500 srcs: ["client.cpp"],
501 }
502
Justin Yun27b95722021-07-28 17:04:44 +0900503 cc_library_shared {
504 name: "libvndkext",
505 vendor: true,
506 nocrt: true,
507 no_libcrt: true,
Kalesh Singhf4ffe0a2024-01-29 13:01:51 -0800508 no_crt_pad_segment: true,
Justin Yun27b95722021-07-28 17:04:44 +0900509 stl: "none",
510 system_shared_libs: [],
511 vndk: {
512 extends: "libvndk",
513 enabled: true,
514 }
515 }
516
Colin Cross0fce0ba2021-01-08 16:40:12 -0800517 cc_binary {
518 name: "bin_without_snapshot",
519 vendor: true,
520 nocrt: true,
521 no_libcrt: true,
Inseob Kimd4c9f552021-04-08 19:28:28 +0900522 stl: "libc++_static",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800523 system_shared_libs: [],
524 static_libs: ["libvndk"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800525 srcs: ["bin.cpp"],
526 }
527
Colin Crosse0edaf92021-01-11 17:31:17 -0800528 vendor_snapshot {
529 name: "vendor_snapshot",
Justin Yundee806f2021-05-18 23:10:00 +0900530 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700531 arch: {
532 arm64: {
533 vndk_libs: [
534 "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900535 "libllndk",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700536 ],
537 static_libs: [
Inseob Kimd4c9f552021-04-08 19:28:28 +0900538 "libc++_static",
539 "libc++demangle",
Justin Yundee806f2021-05-18 23:10:00 +0900540 "libunwind",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700541 "libvendor",
542 "libvendor_available",
543 "libvndk",
544 "lib64",
545 ],
546 shared_libs: [
547 "libvendor",
Inseob Kima1888ce2022-10-04 14:42:02 +0900548 "libvendor_override",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700549 "libvendor_available",
550 "lib64",
551 ],
552 binaries: [
553 "bin",
Inseob Kima1888ce2022-10-04 14:42:02 +0900554 "bin_override",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700555 ],
556 },
557 arm: {
558 vndk_libs: [
559 "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900560 "libllndk",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700561 ],
562 static_libs: [
563 "libvendor",
564 "libvendor_available",
565 "libvndk",
566 "lib32",
567 ],
568 shared_libs: [
569 "libvendor",
Inseob Kima1888ce2022-10-04 14:42:02 +0900570 "libvendor_override",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700571 "libvendor_available",
572 "lib32",
573 ],
574 binaries: [
575 "bin32",
576 ],
577 },
578 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800579 }
580
Colin Cross0fce0ba2021-01-08 16:40:12 -0800581 vendor_snapshot_static {
582 name: "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900583 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800584 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700585 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800586 vendor: true,
587 arch: {
588 arm64: {
589 src: "libvndk.a",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800590 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700591 arm: {
592 src: "libvndk.a",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700593 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800594 },
Inseob Kimdd0295d2021-04-12 21:09:59 +0900595 shared_libs: ["libvndk"],
596 export_shared_lib_headers: ["libvndk"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800597 }
598
599 vendor_snapshot_shared {
600 name: "libvendor",
Justin Yundee806f2021-05-18 23:10:00 +0900601 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800602 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700603 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800604 vendor: true,
Kalesh Singhf4ffe0a2024-01-29 13:01:51 -0800605 no_crt_pad_segment: true,
Justin Yun48138672021-02-25 18:21:27 +0900606 shared_libs: [
607 "libvendor_without_snapshot",
608 "libvendor_available",
Justin Yun07b9f862021-02-26 14:00:03 +0900609 "libvndk",
Justin Yun48138672021-02-25 18:21:27 +0900610 ],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800611 arch: {
612 arm64: {
613 src: "libvendor.so",
614 export_include_dirs: ["include/libvendor"],
615 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700616 arm: {
617 src: "libvendor.so",
618 export_include_dirs: ["include/libvendor"],
619 },
620 },
621 }
622
Inseob Kima1888ce2022-10-04 14:42:02 +0900623 vendor_snapshot_shared {
624 name: "libvendor_override",
625 version: "31",
626 target_arch: "arm64",
627 compile_multilib: "both",
628 vendor: true,
Kalesh Singhf4ffe0a2024-01-29 13:01:51 -0800629 no_crt_pad_segment: true,
Inseob Kima1888ce2022-10-04 14:42:02 +0900630 overrides: ["libvendor"],
631 shared_libs: [
632 "libvendor_without_snapshot",
633 "libvendor_available",
634 "libvndk",
635 ],
636 arch: {
637 arm64: {
638 src: "override/libvendor.so",
639 export_include_dirs: ["include/libvendor"],
640 },
641 arm: {
642 src: "override/libvendor.so",
643 export_include_dirs: ["include/libvendor"],
644 },
645 },
646 }
647
Jose Galmesf9523ed2021-04-06 19:48:10 -0700648 vendor_snapshot_static {
649 name: "lib32",
Justin Yundee806f2021-05-18 23:10:00 +0900650 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700651 target_arch: "arm64",
652 compile_multilib: "32",
653 vendor: true,
654 arch: {
655 arm: {
656 src: "lib32.a",
657 },
658 },
659 }
660
661 vendor_snapshot_shared {
662 name: "lib32",
Justin Yundee806f2021-05-18 23:10:00 +0900663 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700664 target_arch: "arm64",
665 compile_multilib: "32",
666 vendor: true,
Kalesh Singhf4ffe0a2024-01-29 13:01:51 -0800667 no_crt_pad_segment: true,
Jose Galmesf9523ed2021-04-06 19:48:10 -0700668 arch: {
669 arm: {
670 src: "lib32.so",
671 },
672 },
673 }
674
675 vendor_snapshot_static {
676 name: "lib64",
Justin Yundee806f2021-05-18 23:10:00 +0900677 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700678 target_arch: "arm64",
679 compile_multilib: "64",
680 vendor: true,
681 arch: {
682 arm64: {
683 src: "lib64.a",
684 },
685 },
686 }
687
688 vendor_snapshot_shared {
689 name: "lib64",
Justin Yundee806f2021-05-18 23:10:00 +0900690 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700691 target_arch: "arm64",
692 compile_multilib: "64",
693 vendor: true,
Kalesh Singhf4ffe0a2024-01-29 13:01:51 -0800694 no_crt_pad_segment: true,
Jose Galmesf9523ed2021-04-06 19:48:10 -0700695 arch: {
696 arm64: {
697 src: "lib64.so",
698 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800699 },
700 }
701
702 vendor_snapshot_static {
703 name: "libvendor",
Justin Yundee806f2021-05-18 23:10:00 +0900704 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800705 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700706 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800707 vendor: true,
708 arch: {
709 arm64: {
Inseob Kimf7aadf72021-04-13 10:15:31 +0900710 cfi: {
711 src: "libvendor.cfi.a",
712 export_include_dirs: ["include/libvendor_cfi"],
713 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800714 src: "libvendor.a",
715 export_include_dirs: ["include/libvendor"],
716 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700717 arm: {
Inseob Kimf7aadf72021-04-13 10:15:31 +0900718 cfi: {
719 src: "libvendor.cfi.a",
720 export_include_dirs: ["include/libvendor_cfi"],
721 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700722 src: "libvendor.a",
723 export_include_dirs: ["include/libvendor"],
724 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800725 },
726 }
727
Colin Cross2e577f32021-01-22 13:06:25 -0800728 vendor_snapshot_shared {
729 name: "libvendor_available",
Justin Yundee806f2021-05-18 23:10:00 +0900730 version: "31",
Colin Cross2e577f32021-01-22 13:06:25 -0800731 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700732 compile_multilib: "both",
Colin Cross2e577f32021-01-22 13:06:25 -0800733 vendor: true,
Kalesh Singhf4ffe0a2024-01-29 13:01:51 -0800734 no_crt_pad_segment: true,
Colin Cross2e577f32021-01-22 13:06:25 -0800735 arch: {
736 arm64: {
737 src: "libvendor_available.so",
738 export_include_dirs: ["include/libvendor"],
739 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700740 arm: {
741 src: "libvendor_available.so",
742 export_include_dirs: ["include/libvendor"],
743 },
Colin Cross2e577f32021-01-22 13:06:25 -0800744 },
745 }
746
747 vendor_snapshot_static {
748 name: "libvendor_available",
Justin Yundee806f2021-05-18 23:10:00 +0900749 version: "31",
Colin Cross2e577f32021-01-22 13:06:25 -0800750 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700751 compile_multilib: "both",
Colin Cross2e577f32021-01-22 13:06:25 -0800752 vendor: true,
753 arch: {
754 arm64: {
755 src: "libvendor_available.a",
756 export_include_dirs: ["include/libvendor"],
757 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700758 arm: {
759 src: "libvendor_available.so",
760 export_include_dirs: ["include/libvendor"],
761 },
Colin Cross2e577f32021-01-22 13:06:25 -0800762 },
763 }
764
Inseob Kimd4c9f552021-04-08 19:28:28 +0900765 vendor_snapshot_static {
766 name: "libc++_static",
Justin Yundee806f2021-05-18 23:10:00 +0900767 version: "31",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900768 target_arch: "arm64",
769 compile_multilib: "64",
770 vendor: true,
771 arch: {
772 arm64: {
773 src: "libc++_static.a",
774 },
775 },
776 }
777
778 vendor_snapshot_static {
779 name: "libc++demangle",
Justin Yundee806f2021-05-18 23:10:00 +0900780 version: "31",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900781 target_arch: "arm64",
782 compile_multilib: "64",
783 vendor: true,
784 arch: {
785 arm64: {
786 src: "libc++demangle.a",
787 },
788 },
789 }
790
791 vendor_snapshot_static {
Justin Yundee806f2021-05-18 23:10:00 +0900792 name: "libunwind",
793 version: "31",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900794 target_arch: "arm64",
795 compile_multilib: "64",
796 vendor: true,
797 arch: {
798 arm64: {
Justin Yundee806f2021-05-18 23:10:00 +0900799 src: "libunwind.a",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900800 },
801 },
802 }
803
Colin Cross0fce0ba2021-01-08 16:40:12 -0800804 vendor_snapshot_binary {
805 name: "bin",
Justin Yundee806f2021-05-18 23:10:00 +0900806 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800807 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700808 compile_multilib: "64",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800809 vendor: true,
810 arch: {
811 arm64: {
812 src: "bin",
813 },
814 },
Inseob Kim4d945ee2022-02-24 10:29:18 +0900815 symlinks: ["binfoo", "binbar"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800816 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800817
Jose Galmesf9523ed2021-04-06 19:48:10 -0700818 vendor_snapshot_binary {
Inseob Kima1888ce2022-10-04 14:42:02 +0900819 name: "bin_override",
820 version: "31",
821 target_arch: "arm64",
822 compile_multilib: "64",
823 vendor: true,
824 overrides: ["bin"],
825 arch: {
826 arm64: {
827 src: "override/bin",
828 },
829 },
830 symlinks: ["binfoo", "binbar"],
831 }
832
833 vendor_snapshot_binary {
Jose Galmesf9523ed2021-04-06 19:48:10 -0700834 name: "bin32",
Justin Yundee806f2021-05-18 23:10:00 +0900835 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700836 target_arch: "arm64",
837 compile_multilib: "32",
838 vendor: true,
839 arch: {
840 arm: {
841 src: "bin32",
842 },
843 },
844 }
845
Colin Crosse0edaf92021-01-11 17:31:17 -0800846 // old snapshot module which has to be ignored
847 vendor_snapshot_binary {
848 name: "bin",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900849 version: "26",
Colin Crosse0edaf92021-01-11 17:31:17 -0800850 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700851 compile_multilib: "first",
852 vendor: true,
853 arch: {
854 arm64: {
855 src: "bin",
856 },
857 },
858 }
859
860 // different arch snapshot which has to be ignored
861 vendor_snapshot_binary {
862 name: "bin",
Justin Yundee806f2021-05-18 23:10:00 +0900863 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700864 target_arch: "arm",
865 compile_multilib: "first",
Colin Crosse0edaf92021-01-11 17:31:17 -0800866 vendor: true,
867 arch: {
868 arm64: {
869 src: "bin",
870 },
871 },
872 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800873`
874 depsBp := GatherRequiredDepsForTest(android.Android)
875
876 mockFS := map[string][]byte{
Inseob Kimf7aadf72021-04-13 10:15:31 +0900877 "deps/Android.bp": []byte(depsBp),
878 "framework/Android.bp": []byte(frameworkBp),
879 "framework/symbol.txt": nil,
880 "vendor/Android.bp": []byte(vendorProprietaryBp),
881 "vendor/bin": nil,
Inseob Kima1888ce2022-10-04 14:42:02 +0900882 "vendor/override/bin": nil,
Inseob Kimf7aadf72021-04-13 10:15:31 +0900883 "vendor/bin32": nil,
884 "vendor/bin.cpp": nil,
885 "vendor/client.cpp": nil,
886 "vendor/include/libvndk/a.h": nil,
887 "vendor/include/libvendor/b.h": nil,
888 "vendor/include/libvendor_cfi/c.h": nil,
889 "vendor/libc++_static.a": nil,
890 "vendor/libc++demangle.a": nil,
Justin Yundee806f2021-05-18 23:10:00 +0900891 "vendor/libunwind.a": nil,
Inseob Kimf7aadf72021-04-13 10:15:31 +0900892 "vendor/libvndk.a": nil,
893 "vendor/libvendor.a": nil,
894 "vendor/libvendor.cfi.a": nil,
895 "vendor/libvendor.so": nil,
Inseob Kima1888ce2022-10-04 14:42:02 +0900896 "vendor/override/libvendor.so": nil,
Inseob Kimf7aadf72021-04-13 10:15:31 +0900897 "vendor/lib32.a": nil,
898 "vendor/lib32.so": nil,
899 "vendor/lib64.a": nil,
900 "vendor/lib64.so": nil,
901 "vndk/Android.bp": []byte(vndkBp),
902 "vndk/include/libvndk/a.h": nil,
903 "vndk/libvndk.so": nil,
Justin Yundee806f2021-05-18 23:10:00 +0900904 "vndk/libllndk.so": nil,
Colin Cross0fce0ba2021-01-08 16:40:12 -0800905 }
906
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000907 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Justin Yundee806f2021-05-18 23:10:00 +0900908 config.TestProductVariables.DeviceVndkVersion = StringPtr("31")
909 config.TestProductVariables.Platform_vndk_version = StringPtr("32")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800910 ctx := CreateTestContext(config)
911 ctx.Register()
912
913 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "vendor/Android.bp", "vndk/Android.bp"})
914 android.FailIfErrored(t, errs)
915 _, errs = ctx.PrepareBuildActions(config)
916 android.FailIfErrored(t, errs)
917
Justin Yundee806f2021-05-18 23:10:00 +0900918 sharedVariant := "android_vendor.31_arm64_armv8-a_shared"
919 staticVariant := "android_vendor.31_arm64_armv8-a_static"
920 binaryVariant := "android_vendor.31_arm64_armv8-a"
Colin Cross0fce0ba2021-01-08 16:40:12 -0800921
Justin Yundee806f2021-05-18 23:10:00 +0900922 sharedCfiVariant := "android_vendor.31_arm64_armv8-a_shared_cfi"
923 staticCfiVariant := "android_vendor.31_arm64_armv8-a_static_cfi"
Inseob Kimf7aadf72021-04-13 10:15:31 +0900924
Justin Yundee806f2021-05-18 23:10:00 +0900925 shared32Variant := "android_vendor.31_arm_armv7-a-neon_shared"
926 binary32Variant := "android_vendor.31_arm_armv7-a-neon"
Jose Galmesf9523ed2021-04-06 19:48:10 -0700927
Justin Yundee806f2021-05-18 23:10:00 +0900928 // libclient uses libvndk.vndk.31.arm64, libvendor.vendor_static.31.arm64, libvendor_without_snapshot
Colin Cross0fce0ba2021-01-08 16:40:12 -0800929 libclientCcFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("cc").Args["cFlags"]
930 for _, includeFlags := range []string{
931 "-Ivndk/include/libvndk", // libvndk
932 "-Ivendor/include/libvendor", // libvendor
933 } {
934 if !strings.Contains(libclientCcFlags, includeFlags) {
935 t.Errorf("flags for libclient must contain %#v, but was %#v.",
936 includeFlags, libclientCcFlags)
937 }
938 }
939
940 libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("ld").Args["libFlags"]
941 for _, input := range [][]string{
Justin Yundee806f2021-05-18 23:10:00 +0900942 []string{sharedVariant, "libvndk.vndk.31.arm64"},
943 []string{sharedVariant, "libllndk.vndk.31.arm64"},
944 []string{staticVariant, "libvendor.vendor_static.31.arm64"},
Colin Cross0fce0ba2021-01-08 16:40:12 -0800945 []string{staticVariant, "libvendor_without_snapshot"},
946 } {
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400947 outputPaths := GetOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800948 if !strings.Contains(libclientLdFlags, outputPaths[0].String()) {
949 t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags)
950 }
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400951
Colin Cross0fce0ba2021-01-08 16:40:12 -0800952 }
953
Colin Cross2e577f32021-01-22 13:06:25 -0800954 libclientAndroidMkSharedLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkSharedLibs
Justin Yundee806f2021-05-18 23:10:00 +0900955 if g, w := libclientAndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "libllndk.vendor", "lib64"}; !reflect.DeepEqual(g, w) {
Colin Cross2e577f32021-01-22 13:06:25 -0800956 t.Errorf("wanted libclient AndroidMkSharedLibs %q, got %q", w, g)
957 }
958
959 libclientAndroidMkStaticLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkStaticLibs
960 if g, w := libclientAndroidMkStaticLibs, []string{"libvendor", "libvendor_without_snapshot"}; !reflect.DeepEqual(g, w) {
961 t.Errorf("wanted libclient AndroidMkStaticLibs %q, got %q", w, g)
962 }
963
Jose Galmesf9523ed2021-04-06 19:48:10 -0700964 libclient32AndroidMkSharedLibs := ctx.ModuleForTests("libclient", shared32Variant).Module().(*Module).Properties.AndroidMkSharedLibs
Justin Yundee806f2021-05-18 23:10:00 +0900965 if g, w := libclient32AndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "libllndk.vendor", "lib32"}; !reflect.DeepEqual(g, w) {
Jose Galmesf9523ed2021-04-06 19:48:10 -0700966 t.Errorf("wanted libclient32 AndroidMkSharedLibs %q, got %q", w, g)
967 }
968
Justin Yundee806f2021-05-18 23:10:00 +0900969 // libclient_cfi uses libvendor.vendor_static.31.arm64's cfi variant
Inseob Kimf7aadf72021-04-13 10:15:31 +0900970 libclientCfiCcFlags := ctx.ModuleForTests("libclient_cfi", sharedCfiVariant).Rule("cc").Args["cFlags"]
971 if !strings.Contains(libclientCfiCcFlags, "-Ivendor/include/libvendor_cfi") {
972 t.Errorf("flags for libclient_cfi must contain %#v, but was %#v.",
973 "-Ivendor/include/libvendor_cfi", libclientCfiCcFlags)
974 }
975
976 libclientCfiLdFlags := ctx.ModuleForTests("libclient_cfi", sharedCfiVariant).Rule("ld").Args["libFlags"]
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400977 libvendorCfiOutputPaths := GetOutputPaths(ctx, staticCfiVariant, []string{"libvendor.vendor_static.31.arm64"})
Inseob Kimf7aadf72021-04-13 10:15:31 +0900978 if !strings.Contains(libclientCfiLdFlags, libvendorCfiOutputPaths[0].String()) {
979 t.Errorf("libflags for libclientCfi must contain %#v, but was %#v", libvendorCfiOutputPaths[0], libclientCfiLdFlags)
980 }
981
Justin Yundee806f2021-05-18 23:10:00 +0900982 // bin_without_snapshot uses libvndk.vendor_static.31.arm64 (which reexports vndk's exported headers)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800983 binWithoutSnapshotCcFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("cc").Args["cFlags"]
Inseob Kimdd0295d2021-04-12 21:09:59 +0900984 if !strings.Contains(binWithoutSnapshotCcFlags, "-Ivndk/include/libvndk") {
Colin Cross0fce0ba2021-01-08 16:40:12 -0800985 t.Errorf("flags for bin_without_snapshot must contain %#v, but was %#v.",
986 "-Ivendor/include/libvndk", binWithoutSnapshotCcFlags)
987 }
988
989 binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("ld").Args["libFlags"]
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400990 libVndkStaticOutputPaths := GetOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.31.arm64"})
Colin Cross0fce0ba2021-01-08 16:40:12 -0800991 if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) {
992 t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v",
993 libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags)
994 }
995
Justin Yundee806f2021-05-18 23:10:00 +0900996 // libvendor.so is installed by libvendor.vendor_shared.31.arm64
997 ctx.ModuleForTests("libvendor.vendor_shared.31.arm64", sharedVariant).Output("libvendor.so")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800998
Justin Yundee806f2021-05-18 23:10:00 +0900999 // lib64.so is installed by lib64.vendor_shared.31.arm64
1000 ctx.ModuleForTests("lib64.vendor_shared.31.arm64", sharedVariant).Output("lib64.so")
Jose Galmesf9523ed2021-04-06 19:48:10 -07001001
Justin Yundee806f2021-05-18 23:10:00 +09001002 // lib32.so is installed by lib32.vendor_shared.31.arm64
1003 ctx.ModuleForTests("lib32.vendor_shared.31.arm64", shared32Variant).Output("lib32.so")
Jose Galmesf9523ed2021-04-06 19:48:10 -07001004
Justin Yundee806f2021-05-18 23:10:00 +09001005 // libvendor_available.so is installed by libvendor_available.vendor_shared.31.arm64
1006 ctx.ModuleForTests("libvendor_available.vendor_shared.31.arm64", sharedVariant).Output("libvendor_available.so")
Colin Cross2e577f32021-01-22 13:06:25 -08001007
Colin Cross0fce0ba2021-01-08 16:40:12 -08001008 // libvendor_without_snapshot.so is installed by libvendor_without_snapshot
1009 ctx.ModuleForTests("libvendor_without_snapshot", sharedVariant).Output("libvendor_without_snapshot.so")
1010
Justin Yundee806f2021-05-18 23:10:00 +09001011 // bin is installed by bin.vendor_binary.31.arm64
Inseob Kim4d945ee2022-02-24 10:29:18 +09001012 bin64Module := ctx.ModuleForTests("bin.vendor_binary.31.arm64", binaryVariant)
1013 bin64Module.Output("bin")
1014
1015 // also test symlinks
1016 bin64MkEntries := android.AndroidMkEntriesForTest(t, ctx, bin64Module.Module())
1017 bin64KatiSymlinks := bin64MkEntries[0].EntryMap["LOCAL_SOONG_INSTALL_SYMLINKS"]
1018
1019 // Either AndroidMk entries contain symlinks, or symlinks should be installed by Soong
1020 for _, symlink := range []string{"binfoo", "binbar"} {
1021 if inList(symlink, bin64KatiSymlinks) {
1022 continue
1023 }
1024
1025 bin64Module.Output(symlink)
1026 }
Colin Cross0fce0ba2021-01-08 16:40:12 -08001027
Justin Yundee806f2021-05-18 23:10:00 +09001028 // bin32 is installed by bin32.vendor_binary.31.arm64
1029 ctx.ModuleForTests("bin32.vendor_binary.31.arm64", binary32Variant).Output("bin32")
Jose Galmesf9523ed2021-04-06 19:48:10 -07001030
Colin Cross0fce0ba2021-01-08 16:40:12 -08001031 // bin_without_snapshot is installed by bin_without_snapshot
1032 ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot")
1033
Justin Yundee806f2021-05-18 23:10:00 +09001034 // libvendor, libvendor_available and bin don't have vendor.31 variant
Colin Cross0fce0ba2021-01-08 16:40:12 -08001035 libvendorVariants := ctx.ModuleVariantsForTests("libvendor")
1036 if inList(sharedVariant, libvendorVariants) {
1037 t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant)
1038 }
1039
Colin Cross2e577f32021-01-22 13:06:25 -08001040 libvendorAvailableVariants := ctx.ModuleVariantsForTests("libvendor_available")
1041 if inList(sharedVariant, libvendorAvailableVariants) {
1042 t.Errorf("libvendor_available must not have variant %#v, but it does", sharedVariant)
1043 }
1044
Colin Cross0fce0ba2021-01-08 16:40:12 -08001045 binVariants := ctx.ModuleVariantsForTests("bin")
1046 if inList(binaryVariant, binVariants) {
1047 t.Errorf("bin must not have variant %#v, but it does", sharedVariant)
1048 }
Inseob Kima1888ce2022-10-04 14:42:02 +09001049
1050 // test overrides property
1051 binOverrideModule := ctx.ModuleForTests("bin_override.vendor_binary.31.arm64", binaryVariant)
1052 binOverrideModule.Output("bin")
1053 binOverrideMkEntries := android.AndroidMkEntriesForTest(t, ctx, binOverrideModule.Module())
1054 binOverrideEntry := binOverrideMkEntries[0].EntryMap["LOCAL_OVERRIDES_MODULES"]
1055 if !inList("bin", binOverrideEntry) {
1056 t.Errorf("bin_override must override bin but was %q\n", binOverrideEntry)
1057 }
1058
1059 libvendorOverrideModule := ctx.ModuleForTests("libvendor_override.vendor_shared.31.arm64", sharedVariant)
1060 libvendorOverrideModule.Output("libvendor.so")
1061 libvendorOverrideMkEntries := android.AndroidMkEntriesForTest(t, ctx, libvendorOverrideModule.Module())
1062 libvendorOverrideEntry := libvendorOverrideMkEntries[0].EntryMap["LOCAL_OVERRIDES_MODULES"]
1063 if !inList("libvendor", libvendorOverrideEntry) {
1064 t.Errorf("libvendor_override must override libvendor but was %q\n", libvendorOverrideEntry)
1065 }
Colin Cross0fce0ba2021-01-08 16:40:12 -08001066}
1067
1068func TestVendorSnapshotSanitizer(t *testing.T) {
1069 bp := `
Inseob Kim253f5212021-04-08 17:10:31 +09001070 vendor_snapshot {
1071 name: "vendor_snapshot",
1072 version: "28",
1073 arch: {
1074 arm64: {
1075 static_libs: [
1076 "libsnapshot",
1077 "note_memtag_heap_sync",
1078 ],
Justin Yun08270c62022-12-19 17:01:26 +09001079 objects: [
1080 "snapshot_object",
1081 ],
1082 vndk_libs: [
1083 "libclang_rt.hwasan",
1084 ],
Inseob Kim253f5212021-04-08 17:10:31 +09001085 },
1086 },
1087 }
Justin Yun39c30312022-11-23 16:20:12 +09001088
Colin Cross0fce0ba2021-01-08 16:40:12 -08001089 vendor_snapshot_static {
1090 name: "libsnapshot",
1091 vendor: true,
1092 target_arch: "arm64",
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001093 version: "28",
Colin Cross0fce0ba2021-01-08 16:40:12 -08001094 arch: {
1095 arm64: {
1096 src: "libsnapshot.a",
1097 cfi: {
1098 src: "libsnapshot.cfi.a",
Justin Yun39c30312022-11-23 16:20:12 +09001099 },
1100 hwasan: {
1101 src: "libsnapshot.hwasan.a",
1102 },
Colin Cross0fce0ba2021-01-08 16:40:12 -08001103 },
1104 },
1105 }
Inseob Kim253f5212021-04-08 17:10:31 +09001106
1107 vendor_snapshot_static {
1108 name: "note_memtag_heap_sync",
1109 vendor: true,
1110 target_arch: "arm64",
1111 version: "28",
1112 arch: {
1113 arm64: {
1114 src: "note_memtag_heap_sync.a",
1115 },
1116 },
1117 }
1118
Justin Yun08270c62022-12-19 17:01:26 +09001119 vndk_prebuilt_shared {
1120 name: "libclang_rt.hwasan",
1121 version: "28",
1122 target_arch: "arm64",
1123 vendor_available: true,
1124 product_available: true,
1125 vndk: {
1126 enabled: true,
1127 },
1128 arch: {
1129 arm64: {
1130 srcs: ["libclang_rt.hwasan.so"],
1131 },
1132 },
1133 }
1134
1135 vendor_snapshot_object {
1136 name: "snapshot_object",
1137 vendor: true,
1138 target_arch: "arm64",
1139 version: "28",
1140 arch: {
1141 arm64: {
1142 src: "snapshot_object.o",
1143 },
1144 },
1145 stl: "none",
1146 }
1147
Inseob Kim253f5212021-04-08 17:10:31 +09001148 cc_test {
1149 name: "vstest",
1150 gtest: false,
1151 vendor: true,
1152 compile_multilib: "64",
1153 nocrt: true,
1154 no_libcrt: true,
1155 stl: "none",
1156 static_libs: ["libsnapshot"],
1157 system_shared_libs: [],
1158 }
Colin Cross0fce0ba2021-01-08 16:40:12 -08001159`
Inseob Kim253f5212021-04-08 17:10:31 +09001160
1161 mockFS := map[string][]byte{
1162 "vendor/Android.bp": []byte(bp),
1163 "vendor/libc++demangle.a": nil,
Justin Yun08270c62022-12-19 17:01:26 +09001164 "vendor/libclang_rt.hwasan.so": nil,
Inseob Kim253f5212021-04-08 17:10:31 +09001165 "vendor/libsnapshot.a": nil,
1166 "vendor/libsnapshot.cfi.a": nil,
Justin Yun39c30312022-11-23 16:20:12 +09001167 "vendor/libsnapshot.hwasan.a": nil,
Inseob Kim253f5212021-04-08 17:10:31 +09001168 "vendor/note_memtag_heap_sync.a": nil,
Justin Yun08270c62022-12-19 17:01:26 +09001169 "vendor/snapshot_object.o": nil,
Inseob Kim253f5212021-04-08 17:10:31 +09001170 }
1171
1172 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001173 config.TestProductVariables.DeviceVndkVersion = StringPtr("28")
1174 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Justin Yun08270c62022-12-19 17:01:26 +09001175 config.TestProductVariables.SanitizeDevice = []string{"hwaddress"}
Colin Cross0fce0ba2021-01-08 16:40:12 -08001176 ctx := testCcWithConfig(t, config)
1177
Justin Yun39c30312022-11-23 16:20:12 +09001178 // Check non-cfi, cfi and hwasan variant.
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001179 staticVariant := "android_vendor.28_arm64_armv8-a_static"
1180 staticCfiVariant := "android_vendor.28_arm64_armv8-a_static_cfi"
Justin Yun39c30312022-11-23 16:20:12 +09001181 staticHwasanVariant := "android_vendor.28_arm64_armv8-a_static_hwasan"
1182 staticHwasanCfiVariant := "android_vendor.28_arm64_armv8-a_static_hwasan_cfi"
Colin Cross0fce0ba2021-01-08 16:40:12 -08001183
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001184 staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001185 assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a")
1186
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001187 staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticCfiVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001188 assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
Justin Yun39c30312022-11-23 16:20:12 +09001189
1190 staticHwasanModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticHwasanVariant).Module().(*Module)
1191 assertString(t, staticHwasanModule.outputFile.Path().Base(), "libsnapshot.hwasan.a")
1192
1193 staticHwasanCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticHwasanCfiVariant).Module().(*Module)
1194 if !staticHwasanCfiModule.HiddenFromMake() || !staticHwasanCfiModule.PreventInstall() {
1195 t.Errorf("Hwasan and Cfi cannot enabled at the same time.")
1196 }
Justin Yun08270c62022-12-19 17:01:26 +09001197
1198 snapshotObjModule := ctx.ModuleForTests("snapshot_object.vendor_object.28.arm64", "android_vendor.28_arm64_armv8-a").Module()
1199 snapshotObjMkEntries := android.AndroidMkEntriesForTest(t, ctx, snapshotObjModule)
1200 // snapshot object must not add ".hwasan" suffix
1201 assertString(t, snapshotObjMkEntries[0].EntryMap["LOCAL_MODULE"][0], "snapshot_object")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001202}
1203
Colin Cross0fce0ba2021-01-08 16:40:12 -08001204func TestVendorSnapshotExclude(t *testing.T) {
1205
1206 // This test verifies that the exclude_from_vendor_snapshot property
1207 // makes its way from the Android.bp source file into the module data
1208 // structure. It also verifies that modules are correctly included or
1209 // excluded in the vendor snapshot based on their path (framework or
1210 // vendor) and the exclude_from_vendor_snapshot property.
1211
1212 frameworkBp := `
1213 cc_library_shared {
1214 name: "libinclude",
1215 srcs: ["src/include.cpp"],
1216 vendor_available: true,
1217 }
1218 cc_library_shared {
1219 name: "libexclude",
1220 srcs: ["src/exclude.cpp"],
1221 vendor: true,
1222 exclude_from_vendor_snapshot: true,
1223 }
1224 cc_library_shared {
1225 name: "libavailable_exclude",
1226 srcs: ["src/exclude.cpp"],
1227 vendor_available: true,
1228 exclude_from_vendor_snapshot: true,
1229 }
1230 `
1231
1232 vendorProprietaryBp := `
1233 cc_library_shared {
1234 name: "libvendor",
1235 srcs: ["vendor.cpp"],
1236 vendor: true,
1237 }
1238 `
1239
1240 depsBp := GatherRequiredDepsForTest(android.Android)
1241
1242 mockFS := map[string][]byte{
1243 "deps/Android.bp": []byte(depsBp),
1244 "framework/Android.bp": []byte(frameworkBp),
1245 "framework/include.cpp": nil,
1246 "framework/exclude.cpp": nil,
1247 "device/Android.bp": []byte(vendorProprietaryBp),
1248 "device/vendor.cpp": nil,
1249 }
1250
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001251 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001252 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001253 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001254 ctx := CreateTestContext(config)
1255 ctx.Register()
1256
1257 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1258 android.FailIfErrored(t, errs)
1259 _, errs = ctx.PrepareBuildActions(config)
1260 android.FailIfErrored(t, errs)
1261
1262 // Test an include and exclude framework module.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001263 AssertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false, vendorVariant)
1264 AssertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true, vendorVariant)
1265 AssertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true, vendorVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001266
1267 // A vendor module is excluded, but by its path, not the
1268 // exclude_from_vendor_snapshot property.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001269 AssertExcludeFromVendorSnapshotIs(t, ctx, "libvendor", false, vendorVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001270
1271 // Verify the content of the vendor snapshot.
1272
1273 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001274 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001275 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1276
1277 var includeJsonFiles []string
1278 var excludeJsonFiles []string
1279
1280 for _, arch := range [][]string{
1281 []string{"arm64", "armv8-a"},
1282 []string{"arm", "armv7-a-neon"},
1283 } {
1284 archType := arch[0]
1285 archVariant := arch[1]
1286 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1287
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001288 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001289 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1290
1291 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001292 CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001293 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1294
1295 // Excluded modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001296 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001297 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001298 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001299 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001300 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001301 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1302 }
1303
1304 // Verify that each json file for an included module has a rule.
1305 for _, jsonFile := range includeJsonFiles {
1306 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1307 t.Errorf("include json file %q not found", jsonFile)
1308 }
1309 }
1310
1311 // Verify that each json file for an excluded module has no rule.
1312 for _, jsonFile := range excludeJsonFiles {
1313 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1314 t.Errorf("exclude json file %q found", jsonFile)
1315 }
1316 }
1317}
1318
1319func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) {
1320
1321 // This test verifies that using the exclude_from_vendor_snapshot
1322 // property on a module in a vendor proprietary path generates an
1323 // error. These modules are already excluded, so we prohibit using the
1324 // property in this way, which could add to confusion.
1325
1326 vendorProprietaryBp := `
1327 cc_library_shared {
1328 name: "libvendor",
1329 srcs: ["vendor.cpp"],
1330 vendor: true,
1331 exclude_from_vendor_snapshot: true,
1332 }
1333 `
1334
1335 depsBp := GatherRequiredDepsForTest(android.Android)
1336
1337 mockFS := map[string][]byte{
1338 "deps/Android.bp": []byte(depsBp),
1339 "device/Android.bp": []byte(vendorProprietaryBp),
1340 "device/vendor.cpp": nil,
1341 }
1342
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001343 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001344 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001345 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001346 ctx := CreateTestContext(config)
1347 ctx.Register()
1348
1349 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"})
1350 android.FailIfErrored(t, errs)
1351
1352 _, errs = ctx.PrepareBuildActions(config)
1353 android.CheckErrorsAgainstExpectations(t, errs, []string{
1354 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1355 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1356 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1357 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1358 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1359 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1360 })
1361}
1362
1363func TestRecoverySnapshotCapture(t *testing.T) {
1364 bp := `
1365 cc_library {
1366 name: "libvndk",
1367 vendor_available: true,
1368 recovery_available: true,
1369 product_available: true,
1370 vndk: {
1371 enabled: true,
1372 },
1373 nocrt: true,
1374 }
1375
1376 cc_library {
1377 name: "librecovery",
1378 recovery: true,
1379 nocrt: true,
1380 }
1381
1382 cc_library {
1383 name: "librecovery_available",
1384 recovery_available: true,
1385 nocrt: true,
1386 }
1387
1388 cc_library_headers {
1389 name: "librecovery_headers",
1390 recovery_available: true,
1391 nocrt: true,
1392 }
1393
1394 cc_binary {
1395 name: "recovery_bin",
1396 recovery: true,
1397 nocrt: true,
1398 }
1399
1400 cc_binary {
1401 name: "recovery_available_bin",
1402 recovery_available: true,
1403 nocrt: true,
1404 }
1405
Liz Kammer718eb272022-01-07 10:53:37 -05001406 cc_prebuilt_library_static {
Colin Cross0fce0ba2021-01-08 16:40:12 -08001407 name: "libb",
1408 recovery_available: true,
Liz Kammer718eb272022-01-07 10:53:37 -05001409 srcs: ["libb.a"],
1410 nocrt: true,
1411 no_libcrt: true,
1412 stl: "none",
Colin Cross0fce0ba2021-01-08 16:40:12 -08001413 }
1414
1415 cc_object {
1416 name: "obj",
1417 recovery_available: true,
1418 }
1419`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001420 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001421 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001422 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001423 ctx := testCcWithConfig(t, config)
1424
1425 // Check Recovery snapshot output.
1426
1427 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001428 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001429 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1430
1431 var jsonFiles []string
1432
1433 for _, arch := range [][]string{
1434 []string{"arm64", "armv8-a"},
1435 } {
1436 archType := arch[0]
1437 archVariant := arch[1]
1438 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1439
1440 // For shared libraries, only recovery_available modules are captured.
1441 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1442 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001443 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant)
1444 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1445 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001446 jsonFiles = append(jsonFiles,
1447 filepath.Join(sharedDir, "libvndk.so.json"),
1448 filepath.Join(sharedDir, "librecovery.so.json"),
1449 filepath.Join(sharedDir, "librecovery_available.so.json"))
1450
1451 // For static libraries, all recovery:true and recovery_available modules are captured.
1452 staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
1453 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001454 CheckSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
1455 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
1456 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001457 jsonFiles = append(jsonFiles,
1458 filepath.Join(staticDir, "libb.a.json"),
1459 filepath.Join(staticDir, "librecovery.a.json"),
1460 filepath.Join(staticDir, "librecovery_available.a.json"))
1461
1462 // For binary executables, all recovery:true and recovery_available modules are captured.
1463 if archType == "arm64" {
1464 binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1465 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001466 CheckSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
1467 CheckSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001468 jsonFiles = append(jsonFiles,
1469 filepath.Join(binaryDir, "recovery_bin.json"),
1470 filepath.Join(binaryDir, "recovery_available_bin.json"))
1471 }
1472
1473 // For header libraries, all vendor:true and vendor_available modules are captured.
1474 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
1475 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json"))
1476
1477 // For object modules, all vendor:true and vendor_available modules are captured.
1478 objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1479 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001480 CheckSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001481 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
1482 }
1483
1484 for _, jsonFile := range jsonFiles {
1485 // verify all json files exist
1486 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1487 t.Errorf("%q expected but not found", jsonFile)
1488 }
1489 }
1490}
1491
1492func TestRecoverySnapshotExclude(t *testing.T) {
1493 // This test verifies that the exclude_from_recovery_snapshot property
1494 // makes its way from the Android.bp source file into the module data
1495 // structure. It also verifies that modules are correctly included or
1496 // excluded in the recovery snapshot based on their path (framework or
1497 // vendor) and the exclude_from_recovery_snapshot property.
1498
1499 frameworkBp := `
1500 cc_library_shared {
1501 name: "libinclude",
1502 srcs: ["src/include.cpp"],
1503 recovery_available: true,
1504 }
1505 cc_library_shared {
1506 name: "libexclude",
1507 srcs: ["src/exclude.cpp"],
1508 recovery: true,
1509 exclude_from_recovery_snapshot: true,
1510 }
1511 cc_library_shared {
1512 name: "libavailable_exclude",
1513 srcs: ["src/exclude.cpp"],
1514 recovery_available: true,
1515 exclude_from_recovery_snapshot: true,
1516 }
1517 `
1518
1519 vendorProprietaryBp := `
1520 cc_library_shared {
1521 name: "librecovery",
1522 srcs: ["recovery.cpp"],
1523 recovery: true,
1524 }
1525 `
1526
1527 depsBp := GatherRequiredDepsForTest(android.Android)
1528
1529 mockFS := map[string][]byte{
1530 "deps/Android.bp": []byte(depsBp),
1531 "framework/Android.bp": []byte(frameworkBp),
1532 "framework/include.cpp": nil,
1533 "framework/exclude.cpp": nil,
1534 "device/Android.bp": []byte(vendorProprietaryBp),
1535 "device/recovery.cpp": nil,
1536 }
1537
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001538 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001539 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001540 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001541 ctx := CreateTestContext(config)
1542 ctx.Register()
1543
1544 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1545 android.FailIfErrored(t, errs)
1546 _, errs = ctx.PrepareBuildActions(config)
1547 android.FailIfErrored(t, errs)
1548
1549 // Test an include and exclude framework module.
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001550 AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false, recoveryVariant)
1551 AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true, recoveryVariant)
1552 AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true, recoveryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001553
1554 // A recovery module is excluded, but by its path, not the
1555 // exclude_from_recovery_snapshot property.
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001556 AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false, recoveryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001557
1558 // Verify the content of the recovery snapshot.
1559
1560 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001561 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001562 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1563
1564 var includeJsonFiles []string
1565 var excludeJsonFiles []string
1566
1567 for _, arch := range [][]string{
1568 []string{"arm64", "armv8-a"},
1569 } {
1570 archType := arch[0]
1571 archVariant := arch[1]
1572 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1573
1574 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1575 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1576
1577 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001578 CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001579 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1580
1581 // Excluded modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001582 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001583 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001584 CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001585 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001586 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001587 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1588 }
1589
1590 // Verify that each json file for an included module has a rule.
1591 for _, jsonFile := range includeJsonFiles {
1592 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1593 t.Errorf("include json file %q not found", jsonFile)
1594 }
1595 }
1596
1597 // Verify that each json file for an excluded module has no rule.
1598 for _, jsonFile := range excludeJsonFiles {
1599 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1600 t.Errorf("exclude json file %q found", jsonFile)
1601 }
1602 }
1603}
Jose Galmes4c6895e2021-02-09 07:44:30 -08001604
1605func TestRecoverySnapshotDirected(t *testing.T) {
1606 bp := `
1607 cc_library_shared {
1608 name: "librecovery",
1609 recovery: true,
1610 nocrt: true,
1611 }
1612
1613 cc_library_shared {
1614 name: "librecovery_available",
1615 recovery_available: true,
1616 nocrt: true,
1617 }
1618
1619 genrule {
1620 name: "libfoo_gen",
1621 cmd: "",
1622 out: ["libfoo.so"],
1623 }
1624
1625 cc_prebuilt_library_shared {
1626 name: "libfoo",
1627 recovery: true,
1628 prefer: true,
1629 srcs: [":libfoo_gen"],
1630 }
1631
1632 cc_library_shared {
1633 name: "libfoo",
1634 recovery: true,
1635 nocrt: true,
1636 }
1637`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001638 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001639 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1640 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001641 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001642 config.TestProductVariables.DirectedRecoverySnapshot = true
1643 config.TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
1644 config.TestProductVariables.RecoverySnapshotModules["librecovery"] = true
1645 config.TestProductVariables.RecoverySnapshotModules["libfoo"] = true
1646 ctx := testCcWithConfig(t, config)
1647
1648 // Check recovery snapshot output.
1649
1650 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001651 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001652 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1653
1654 var includeJsonFiles []string
1655
1656 for _, arch := range [][]string{
1657 []string{"arm64", "armv8-a"},
1658 } {
1659 archType := arch[0]
1660 archVariant := arch[1]
1661 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1662
1663 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1664 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1665
1666 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001667 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001668 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1669 // Check that snapshot captures "prefer: true" prebuilt
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001670 CheckSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001671 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
1672
1673 // Excluded modules. Modules not included in the directed recovery snapshot
1674 // are still include as fake modules.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001675 CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001676 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json"))
1677 }
1678
1679 // Verify that each json file for an included module has a rule.
1680 for _, jsonFile := range includeJsonFiles {
1681 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1682 t.Errorf("include json file %q not found", jsonFile)
1683 }
1684 }
1685}
Justin Yun17d0ee22023-05-02 14:56:38 +09001686
1687func TestSnapshotInRelativeInstallPath(t *testing.T) {
1688 bp := `
1689 cc_library {
1690 name: "libvendor_available",
1691 vendor_available: true,
1692 nocrt: true,
1693 }
1694
1695 cc_library {
1696 name: "libvendor_available_var",
1697 vendor_available: true,
1698 stem: "libvendor_available",
1699 relative_install_path: "var",
1700 nocrt: true,
1701 }
1702`
1703
1704 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
1705 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1706 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
1707 ctx := testCcWithConfig(t, config)
1708
1709 // Check Vendor snapshot output.
1710
1711 snapshotDir := "vendor-snapshot"
1712 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
1713 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1714
1715 var jsonFiles []string
1716
1717 for _, arch := range [][]string{
1718 []string{"arm64", "armv8-a"},
1719 []string{"arm", "armv7-a-neon"},
1720 } {
1721 archType := arch[0]
1722 archVariant := arch[1]
1723 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1724
1725 // For shared libraries, only non-VNDK vendor_available modules are captured
1726 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
1727 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1728 sharedDirVar := filepath.Join(sharedDir, "var")
1729 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
1730 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available_var", "libvendor_available.so", sharedDirVar, sharedVariant)
1731 jsonFiles = append(jsonFiles,
1732 filepath.Join(sharedDir, "libvendor_available.so.json"),
1733 filepath.Join(sharedDirVar, "libvendor_available.so.json"))
1734 }
1735
1736 for _, jsonFile := range jsonFiles {
1737 // verify all json files exist
1738 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1739 t.Errorf("%q expected but not found", jsonFile)
1740 }
1741 }
1742
1743 // fake snapshot should have all outputs in the normal snapshot.
1744 fakeSnapshotSingleton := ctx.SingletonForTests("vendor-fake-snapshot")
1745 for _, output := range snapshotSingleton.AllOutputs() {
1746 fakeOutput := strings.Replace(output, "/vendor-snapshot/", "/fake/vendor-snapshot/", 1)
1747 if fakeSnapshotSingleton.MaybeOutput(fakeOutput).Rule == nil {
1748 t.Errorf("%q expected but not found", fakeOutput)
1749 }
1750 }
1751}