blob: 7be00425ee3c89d2400d0348906fcd7a41df9114 [file] [log] [blame]
Ivan Lozano1921e802021-05-20 13:39:16 -04001// Copyright 2021 The Android Open Source Project
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 rust
16
17import (
18 "fmt"
19 "path/filepath"
Ivan Lozano3149e6e2021-06-01 15:09:53 -040020 "reflect"
Ivan Lozano1921e802021-05-20 13:39:16 -040021 "strings"
22 "testing"
23
24 "android/soong/android"
25 "android/soong/cc"
26)
27
28func TestVendorSnapshotCapture(t *testing.T) {
29 bp := `
30 rust_ffi {
Ivan Lozano3149e6e2021-06-01 15:09:53 -040031 name: "libffivendor_available",
32 crate_name: "ffivendor_available",
33 srcs: ["lib.rs"],
34 vendor_available: true,
35 include_dirs: ["rust_headers/"],
36 }
37
38 rust_ffi {
39 name: "libffivendor",
40 crate_name: "ffivendor",
41 srcs: ["lib.rs"],
42 vendor: true,
43 include_dirs: ["rust_headers/"],
44 }
45
46 rust_library {
Ivan Lozano1921e802021-05-20 13:39:16 -040047 name: "librustvendor_available",
48 crate_name: "rustvendor_available",
49 srcs: ["lib.rs"],
50 vendor_available: true,
51 include_dirs: ["rust_headers/"],
52 }
53
Ivan Lozano3149e6e2021-06-01 15:09:53 -040054 rust_library_rlib {
55 name: "librustvendor",
56 crate_name: "rustvendor",
57 srcs: ["lib.rs"],
58 vendor: true,
59 include_dirs: ["rust_headers/"],
60 }
61
Ivan Lozano1921e802021-05-20 13:39:16 -040062 rust_binary {
63 name: "vendor_available_bin",
64 vendor_available: true,
65 srcs: ["srcs/lib.rs"],
66 }
67
Ivan Lozano3149e6e2021-06-01 15:09:53 -040068 rust_binary {
69 name: "vendor_bin",
70 vendor: true,
71 srcs: ["srcs/lib.rs"],
72 }
73 `
Ivan Lozano1921e802021-05-20 13:39:16 -040074 skipTestIfOsNotSupported(t)
75 result := android.GroupFixturePreparers(
76 prepareForRustTest,
77 rustMockedFiles.AddToFixture(),
78 android.FixtureModifyProductVariables(
79 func(variables android.FixtureProductVariables) {
80 variables.DeviceVndkVersion = StringPtr("current")
81 variables.Platform_vndk_version = StringPtr("29")
82 },
83 ),
84 ).RunTestWithBp(t, bp)
85 ctx := result.TestContext
86
87 // Check Vendor snapshot output.
88
89 snapshotDir := "vendor-snapshot"
90 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
91 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
92 var jsonFiles []string
93 for _, arch := range [][]string{
94 []string{"arm64", "armv8-a"},
95 []string{"arm", "armv7-a-neon"},
96 } {
97 archType := arch[0]
98 archVariant := arch[1]
99 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
100
101 // For shared libraries, only non-VNDK vendor_available modules are captured
102 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
103 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400104 cc.CheckSnapshot(t, ctx, snapshotSingleton, "libffivendor_available", "libffivendor_available.so", sharedDir, sharedVariant)
Ivan Lozano1921e802021-05-20 13:39:16 -0400105 jsonFiles = append(jsonFiles,
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400106 filepath.Join(sharedDir, "libffivendor_available.so.json"))
Ivan Lozano1921e802021-05-20 13:39:16 -0400107
108 // For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
109 staticVariant := fmt.Sprintf("android_vendor.29_%s_%s_static", archType, archVariant)
110 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400111 cc.CheckSnapshot(t, ctx, snapshotSingleton, "libffivendor_available", "libffivendor_available.a", staticDir, staticVariant)
112 cc.CheckSnapshot(t, ctx, snapshotSingleton, "libffivendor", "libffivendor.a", staticDir, staticVariant)
Ivan Lozano1921e802021-05-20 13:39:16 -0400113 jsonFiles = append(jsonFiles,
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400114 filepath.Join(staticDir, "libffivendor_available.a.json"))
115 jsonFiles = append(jsonFiles,
116 filepath.Join(staticDir, "libffivendor.a.json"))
Ivan Lozano1921e802021-05-20 13:39:16 -0400117
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400118 // For rlib libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
119 rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant)
120 rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
121 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib", rlibDir, rlibVariant)
122 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor", "librustvendor.rlib", rlibDir, rlibVariant)
123 jsonFiles = append(jsonFiles,
124 filepath.Join(rlibDir, "librustvendor_available.rlib.json"))
125 jsonFiles = append(jsonFiles,
126 filepath.Join(rlibDir, "librustvendor.rlib.json"))
127
128 // For binary executables, all vendor:true and vendor_available modules are captured.
Ivan Lozano1921e802021-05-20 13:39:16 -0400129 if archType == "arm64" {
130 binaryVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
131 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
132 cc.CheckSnapshot(t, ctx, snapshotSingleton, "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant)
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400133 cc.CheckSnapshot(t, ctx, snapshotSingleton, "vendor_bin", "vendor_bin", binaryDir, binaryVariant)
Ivan Lozano1921e802021-05-20 13:39:16 -0400134 jsonFiles = append(jsonFiles,
135 filepath.Join(binaryDir, "vendor_available_bin.json"))
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400136 jsonFiles = append(jsonFiles,
137 filepath.Join(binaryDir, "vendor_bin.json"))
Ivan Lozano1921e802021-05-20 13:39:16 -0400138 }
139 }
140
141 for _, jsonFile := range jsonFiles {
142 // verify all json files exist
143 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
144 t.Errorf("%q expected but not found; #%v", jsonFile, jsonFiles)
145 }
146 }
147
148 // fake snapshot should have all outputs in the normal snapshot.
149 fakeSnapshotSingleton := ctx.SingletonForTests("vendor-fake-snapshot")
150
151 for _, output := range snapshotSingleton.AllOutputs() {
152 fakeOutput := strings.Replace(output, "/vendor-snapshot/", "/fake/vendor-snapshot/", 1)
153 if fakeSnapshotSingleton.MaybeOutput(fakeOutput).Rule == nil {
154 t.Errorf("%q expected but not found", fakeOutput)
155 }
156 }
157}
158
159func TestVendorSnapshotDirected(t *testing.T) {
160 bp := `
161 rust_ffi_shared {
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400162 name: "libffivendor_available",
163 crate_name: "ffivendor_available",
164 srcs: ["lib.rs"],
165 vendor_available: true,
166 }
167
168 rust_library {
Ivan Lozano1921e802021-05-20 13:39:16 -0400169 name: "librustvendor_available",
170 crate_name: "rustvendor_available",
171 srcs: ["lib.rs"],
172 vendor_available: true,
173 }
174
175 rust_ffi_shared {
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400176 name: "libffivendor_exclude",
177 crate_name: "ffivendor_exclude",
178 srcs: ["lib.rs"],
179 vendor_available: true,
180 }
181
182 rust_library {
Ivan Lozano1921e802021-05-20 13:39:16 -0400183 name: "librustvendor_exclude",
184 crate_name: "rustvendor_exclude",
185 srcs: ["lib.rs"],
186 vendor_available: true,
187 }
188`
189 ctx := testRustVndk(t, bp)
190 ctx.Config().TestProductVariables.VendorSnapshotModules = make(map[string]bool)
191 ctx.Config().TestProductVariables.VendorSnapshotModules["librustvendor_available"] = true
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400192 ctx.Config().TestProductVariables.VendorSnapshotModules["libffivendor_available"] = true
Ivan Lozano1921e802021-05-20 13:39:16 -0400193 ctx.Config().TestProductVariables.DirectedVendorSnapshot = true
194
195 // Check Vendor snapshot output.
196
197 snapshotDir := "vendor-snapshot"
198 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
199 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
200
201 var includeJsonFiles []string
202
203 for _, arch := range [][]string{
204 []string{"arm64", "armv8-a"},
205 []string{"arm", "armv7-a-neon"},
206 } {
207 archType := arch[0]
208 archVariant := arch[1]
209 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
210
211 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400212 rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant)
Ivan Lozano1921e802021-05-20 13:39:16 -0400213 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400214 rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
Ivan Lozano1921e802021-05-20 13:39:16 -0400215
216 // Included modules
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400217 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib", rlibDir, rlibVariant)
218 cc.CheckSnapshot(t, ctx, snapshotSingleton, "libffivendor_available", "libffivendor_available.so", sharedDir, sharedVariant)
219 includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_available.rlib.json"))
220 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libffivendor_available.so.json"))
Ivan Lozano1921e802021-05-20 13:39:16 -0400221
222 // Excluded modules. Modules not included in the directed vendor snapshot
223 // are still include as fake modules.
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400224 cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librustvendor_exclude", "librustvendor_exclude.rlib", rlibDir, rlibVariant)
225 cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "libffivendor_exclude", "libffivendor_exclude.so", sharedDir, sharedVariant)
226 includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_exclude.rlib.json"))
227 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libffivendor_exclude.so.json"))
Ivan Lozano1921e802021-05-20 13:39:16 -0400228 }
229
230 // Verify that each json file for an included module has a rule.
231 for _, jsonFile := range includeJsonFiles {
232 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
233 t.Errorf("include json file %q not found", jsonFile)
234 }
235 }
236}
237
238func TestVendorSnapshotExclude(t *testing.T) {
239
240 // This test verifies that the exclude_from_vendor_snapshot property
241 // makes its way from the Android.bp source file into the module data
242 // structure. It also verifies that modules are correctly included or
243 // excluded in the vendor snapshot based on their path (framework or
244 // vendor) and the exclude_from_vendor_snapshot property.
245
Ivan Lozano1921e802021-05-20 13:39:16 -0400246 frameworkBp := `
247 rust_ffi_shared {
248 name: "libinclude",
249 crate_name: "include",
250 srcs: ["include.rs"],
251 vendor_available: true,
252 }
253
254 rust_ffi_shared {
255 name: "libexclude",
256 crate_name: "exclude",
257 srcs: ["exclude.rs"],
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400258 vendor: true,
Ivan Lozano1921e802021-05-20 13:39:16 -0400259 exclude_from_vendor_snapshot: true,
260 }
261
262 rust_ffi_shared {
263 name: "libavailable_exclude",
264 crate_name: "available_exclude",
265 srcs: ["lib.rs"],
266 vendor_available: true,
267 exclude_from_vendor_snapshot: true,
268 }
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400269
270 rust_library {
271 name: "librust_include",
272 crate_name: "rust_include",
273 srcs: ["include.rs"],
274 vendor_available: true,
275 }
276
277 rust_library_rlib {
278 name: "librust_exclude",
279 crate_name: "rust_exclude",
280 srcs: ["exclude.rs"],
281 vendor: true,
282 exclude_from_vendor_snapshot: true,
283 }
284
285 rust_library {
286 name: "librust_available_exclude",
287 crate_name: "rust_available_exclude",
288 srcs: ["lib.rs"],
289 vendor_available: true,
290 exclude_from_vendor_snapshot: true,
291 }
Ivan Lozano1921e802021-05-20 13:39:16 -0400292 `
293
294 mockFS := map[string][]byte{
295 "framework/Android.bp": []byte(frameworkBp),
296 "framework/include.rs": nil,
297 "framework/exclude.rs": nil,
298 }
299
300 ctx := testRustVndkFs(t, "", mockFS)
301
302 // Test an include and exclude framework module.
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400303 cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false, sharedVendorVariant)
304 cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true, sharedVendorVariant)
305 cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true, sharedVendorVariant)
306
307 cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_include", false, rlibVendorVariant)
308 cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_exclude", true, rlibVendorVariant)
309 cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_available_exclude", true, rlibVendorVariant)
Ivan Lozano1921e802021-05-20 13:39:16 -0400310
311 // Verify the content of the vendor snapshot.
312
313 snapshotDir := "vendor-snapshot"
314 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
315 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
316
317 var includeJsonFiles []string
318 var excludeJsonFiles []string
319
320 for _, arch := range [][]string{
321 []string{"arm64", "armv8-a"},
322 []string{"arm", "armv7-a-neon"},
323 } {
324 archType := arch[0]
325 archVariant := arch[1]
326 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
327
328 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
329 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400330 rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant)
331 rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
Ivan Lozano1921e802021-05-20 13:39:16 -0400332
333 // Included modules
334 cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
335 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400336 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librust_include", "librust_include.rlib", rlibDir, rlibVariant)
337 includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librust_include.rlib.json"))
Ivan Lozano1921e802021-05-20 13:39:16 -0400338
339 // Excluded modules
340 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
341 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
342 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
343 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400344 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_exclude", "librust_exclude.rlib", rlibDir, rlibVariant)
345 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librust_exclude.rlib.json"))
346 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_available_exclude", "librust_available_exclude.rlib", rlibDir, rlibVariant)
347 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librust_available_exclude.rlib.json"))
Ivan Lozano1921e802021-05-20 13:39:16 -0400348 }
349
350 // Verify that each json file for an included module has a rule.
351 for _, jsonFile := range includeJsonFiles {
352 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
353 t.Errorf("include json file %q not found", jsonFile)
354 }
355 }
356
357 // Verify that each json file for an excluded module has no rule.
358 for _, jsonFile := range excludeJsonFiles {
359 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
360 t.Errorf("exclude json file %q found", jsonFile)
361 }
362 }
363}
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400364
365func TestVendorSnapshotUse(t *testing.T) {
366 frameworkBp := `
367 cc_library {
368 name: "libvndk",
369 vendor_available: true,
370 product_available: true,
371 vndk: {
372 enabled: true,
373 },
374 nocrt: true,
375 }
376
377 cc_library {
378 name: "libvendor",
379 vendor: true,
380 nocrt: true,
381 no_libcrt: true,
382 stl: "none",
383 system_shared_libs: [],
384 }
385
386 cc_library {
387 name: "libvendor_available",
388 vendor_available: true,
389 nocrt: true,
390 no_libcrt: true,
391 stl: "none",
392 system_shared_libs: [],
393 }
394
395 cc_library {
396 name: "lib32",
397 vendor: true,
398 nocrt: true,
399 no_libcrt: true,
400 stl: "none",
401 system_shared_libs: [],
402 compile_multilib: "32",
403 }
404
405 cc_library {
406 name: "lib64",
407 vendor: true,
408 nocrt: true,
409 no_libcrt: true,
410 stl: "none",
411 system_shared_libs: [],
412 compile_multilib: "64",
413 }
414
415 rust_binary {
416 name: "bin",
417 vendor: true,
418 srcs: ["bin.rs"],
419 }
420
421 rust_binary {
422 name: "bin32",
423 vendor: true,
424 compile_multilib: "32",
425 srcs: ["bin.rs"],
426 }
427`
428
429 vndkBp := `
430 vndk_prebuilt_shared {
431 name: "libvndk",
432 version: "30",
433 target_arch: "arm64",
434 vendor_available: true,
435 product_available: true,
436 vndk: {
437 enabled: true,
438 },
439 arch: {
440 arm64: {
441 srcs: ["libvndk.so"],
442 export_include_dirs: ["include/libvndk"],
443 },
444 arm: {
445 srcs: ["libvndk.so"],
446 export_include_dirs: ["include/libvndk"],
447 },
448 },
449 }
450
451 // old snapshot module which has to be ignored
452 vndk_prebuilt_shared {
453 name: "libvndk",
454 version: "26",
455 target_arch: "arm64",
456 vendor_available: true,
457 product_available: true,
458 vndk: {
459 enabled: true,
460 },
461 arch: {
462 arm64: {
463 srcs: ["libvndk.so"],
464 export_include_dirs: ["include/libvndk"],
465 },
466 arm: {
467 srcs: ["libvndk.so"],
468 export_include_dirs: ["include/libvndk"],
469 },
470 },
471 }
472
473 // different arch snapshot which has to be ignored
474 vndk_prebuilt_shared {
475 name: "libvndk",
476 version: "30",
477 target_arch: "arm",
478 vendor_available: true,
479 product_available: true,
480 vndk: {
481 enabled: true,
482 },
483 arch: {
484 arm: {
485 srcs: ["libvndk.so"],
486 export_include_dirs: ["include/libvndk"],
487 },
488 },
489 }
490`
491
492 vendorProprietaryBp := `
493 cc_library {
494 name: "libvendor_without_snapshot",
495 vendor: true,
496 nocrt: true,
497 no_libcrt: true,
498 stl: "none",
499 system_shared_libs: [],
500 }
501
502 rust_library {
503 name: "librust_vendor_available",
504 crate_name: "rust_vendor",
505 vendor_available: true,
506 srcs: ["client.rs"],
507 }
508
509 rust_ffi_shared {
510 name: "libclient",
511 crate_name: "client",
512 vendor: true,
513 shared_libs: ["libvndk", "libvendor_available"],
514 static_libs: ["libvendor", "libvendor_without_snapshot"],
515 rustlibs: ["librust_vendor_available"],
516 arch: {
517 arm64: {
518 shared_libs: ["lib64"],
519 },
520 arm: {
521 shared_libs: ["lib32"],
522 },
523 },
524 srcs: ["client.rs"],
525 }
526
527 rust_library_rlib {
528 name: "libclient_rust",
529 crate_name: "client_rust",
530 vendor: true,
531 shared_libs: ["libvndk", "libvendor_available"],
532 static_libs: ["libvendor", "libvendor_without_snapshot"],
533 rustlibs: ["librust_vendor_available"],
534 arch: {
535 arm64: {
536 shared_libs: ["lib64"],
537 },
538 arm: {
539 shared_libs: ["lib32"],
540 },
541 },
542 srcs: ["client.rs"],
543 }
544
545 rust_binary {
546 name: "bin_without_snapshot",
547 vendor: true,
548 static_libs: ["libvndk"],
549 srcs: ["bin.rs"],
550 rustlibs: ["librust_vendor_available"],
551 }
552
553 vendor_snapshot {
554 name: "vendor_snapshot",
555 version: "30",
556 arch: {
557 arm64: {
558 vndk_libs: [
559 "libvndk",
560 ],
561 static_libs: [
562 "libvendor",
563 "libvndk",
Colin Cross4c4c1be2022-02-10 11:41:18 -0800564 "libclang_rt.builtins",
Ivan Lozano62cd0382021-11-01 10:27:54 -0400565 "note_memtag_heap_sync",
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400566 ],
567 shared_libs: [
568 "libvendor_available",
569 "lib64",
570 ],
571 rlibs: [
572 "libstd",
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400573 "librust_vendor_available",
574 ],
575 binaries: [
576 "bin",
577 ],
578 objects: [
579 "crtend_so",
580 "crtbegin_so",
581 "crtbegin_dynamic",
582 "crtend_android"
583 ],
584 },
585 arm: {
586 vndk_libs: [
587 "libvndk",
588 ],
589 static_libs: [
590 "libvendor",
591 "libvndk",
Colin Cross4c4c1be2022-02-10 11:41:18 -0800592 "libclang_rt.builtins",
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400593 ],
594 shared_libs: [
595 "libvendor_available",
596 "lib32",
597 ],
598 rlibs: [
599 "libstd",
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400600 "librust_vendor_available",
601 ],
602 binaries: [
603 "bin32",
604 ],
605 objects: [
606 "crtend_so",
607 "crtbegin_so",
608 "crtbegin_dynamic",
609 "crtend_android"
610 ],
611
612 },
613 }
614 }
615
616 vendor_snapshot_object {
617 name: "crtend_so",
618 version: "30",
619 target_arch: "arm64",
620 vendor: true,
621 stl: "none",
622 crt: true,
623 arch: {
624 arm64: {
625 src: "crtend_so.o",
626 },
627 arm: {
628 src: "crtend_so.o",
629 },
630 },
631 }
632
633 vendor_snapshot_object {
634 name: "crtbegin_so",
635 version: "30",
636 target_arch: "arm64",
637 vendor: true,
638 stl: "none",
639 crt: true,
640 arch: {
641 arm64: {
642 src: "crtbegin_so.o",
643 },
644 arm: {
645 src: "crtbegin_so.o",
646 },
647 },
648 }
649
650 vendor_snapshot_rlib {
651 name: "libstd",
652 version: "30",
653 target_arch: "arm64",
654 vendor: true,
655 sysroot: true,
656 arch: {
657 arm64: {
658 src: "libstd.rlib",
659 },
660 arm: {
661 src: "libstd.rlib",
662 },
663 },
664 }
665
666 vendor_snapshot_rlib {
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400667 name: "librust_vendor_available",
668 version: "30",
669 target_arch: "arm64",
670 vendor: true,
671 arch: {
672 arm64: {
673 src: "librust_vendor_available.rlib",
674 },
675 arm: {
676 src: "librust_vendor_available.rlib",
677 },
678 },
679 }
680
681 vendor_snapshot_object {
682 name: "crtend_android",
683 version: "30",
684 target_arch: "arm64",
685 vendor: true,
686 stl: "none",
687 crt: true,
688 arch: {
689 arm64: {
690 src: "crtend_so.o",
691 },
692 arm: {
693 src: "crtend_so.o",
694 },
695 },
696 }
697
698 vendor_snapshot_object {
699 name: "crtbegin_dynamic",
700 version: "30",
701 target_arch: "arm64",
702 vendor: true,
703 stl: "none",
704 crt: true,
705 arch: {
706 arm64: {
707 src: "crtbegin_so.o",
708 },
709 arm: {
710 src: "crtbegin_so.o",
711 },
712 },
713 }
714
715 vendor_snapshot_static {
716 name: "libvndk",
717 version: "30",
718 target_arch: "arm64",
719 compile_multilib: "both",
720 vendor: true,
721 arch: {
722 arm64: {
723 src: "libvndk.a",
724 },
725 arm: {
726 src: "libvndk.a",
727 },
728 },
729 shared_libs: ["libvndk"],
730 export_shared_lib_headers: ["libvndk"],
731 }
732
733 vendor_snapshot_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800734 name: "libclang_rt.builtins",
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400735 version: "30",
736 target_arch: "arm64",
737 vendor: true,
738 arch: {
739 arm: {
740 src: "libclang_rt.builtins-arm-android.a",
741 },
Colin Cross4c4c1be2022-02-10 11:41:18 -0800742 arm64: {
743 src: "libclang_rt.builtins-aarch64-android.a",
744 },
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400745 },
746 }
747
748 vendor_snapshot_shared {
749 name: "lib32",
750 version: "30",
751 target_arch: "arm64",
752 compile_multilib: "32",
753 vendor: true,
754 arch: {
755 arm: {
756 src: "lib32.so",
757 },
758 },
759 }
760
761 vendor_snapshot_shared {
762 name: "lib64",
763 version: "30",
764 target_arch: "arm64",
765 compile_multilib: "64",
766 vendor: true,
767 arch: {
768 arm64: {
769 src: "lib64.so",
770 },
771 },
772 }
773 vendor_snapshot_shared {
774 name: "liblog",
775 version: "30",
776 target_arch: "arm64",
777 compile_multilib: "64",
778 vendor: true,
779 arch: {
780 arm64: {
781 src: "liblog.so",
782 },
783 },
784 }
785
786 vendor_snapshot_static {
787 name: "libvendor",
788 version: "30",
789 target_arch: "arm64",
790 compile_multilib: "both",
791 vendor: true,
792 arch: {
793 arm64: {
794 src: "libvendor.a",
795 export_include_dirs: ["include/libvendor"],
796 },
797 arm: {
798 src: "libvendor.a",
799 export_include_dirs: ["include/libvendor"],
800 },
801 },
802 }
803
804 vendor_snapshot_shared {
805 name: "libvendor_available",
806 version: "30",
807 target_arch: "arm64",
808 compile_multilib: "both",
809 vendor: true,
810 arch: {
811 arm64: {
812 src: "libvendor_available.so",
813 export_include_dirs: ["include/libvendor"],
814 },
815 arm: {
816 src: "libvendor_available.so",
817 export_include_dirs: ["include/libvendor"],
818 },
819 },
820 }
821
822 vendor_snapshot_binary {
823 name: "bin",
824 version: "30",
825 target_arch: "arm64",
826 compile_multilib: "64",
827 vendor: true,
828 arch: {
829 arm64: {
830 src: "bin",
831 },
832 },
833 }
834
835 vendor_snapshot_binary {
836 name: "bin32",
837 version: "30",
838 target_arch: "arm64",
839 compile_multilib: "32",
840 vendor: true,
841 arch: {
842 arm: {
843 src: "bin32",
844 },
845 },
846 }
847
Ivan Lozano62cd0382021-11-01 10:27:54 -0400848 // Test sanitizers use the snapshot libraries
849 rust_binary {
850 name: "memtag_binary",
851 srcs: ["vendor/bin.rs"],
852 vendor: true,
853 compile_multilib: "64",
854 sanitize: {
855 memtag_heap: true,
856 diag: {
857 memtag_heap: true,
858 }
859 },
860 }
861
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400862 // old snapshot module which has to be ignored
863 vendor_snapshot_binary {
864 name: "bin",
865 version: "26",
866 target_arch: "arm64",
867 compile_multilib: "first",
868 vendor: true,
869 arch: {
870 arm64: {
871 src: "bin",
872 },
873 },
874 }
875
876 // different arch snapshot which has to be ignored
877 vendor_snapshot_binary {
878 name: "bin",
879 version: "30",
880 target_arch: "arm",
881 compile_multilib: "first",
882 vendor: true,
883 arch: {
884 arm64: {
885 src: "bin",
886 },
887 },
888 }
Ivan Lozano62cd0382021-11-01 10:27:54 -0400889
890 vendor_snapshot_static {
891 name: "note_memtag_heap_sync",
892 vendor: true,
893 target_arch: "arm64",
894 version: "30",
895 arch: {
896 arm64: {
897 src: "note_memtag_heap_sync.a",
898 },
899 },
900 }
901
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400902`
903
904 mockFS := android.MockFS{
905 "framework/Android.bp": []byte(frameworkBp),
906 "framework/bin.rs": nil,
Ivan Lozano62cd0382021-11-01 10:27:54 -0400907 "note_memtag_heap_sync.a": nil,
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400908 "vendor/Android.bp": []byte(vendorProprietaryBp),
909 "vendor/bin": nil,
910 "vendor/bin32": nil,
911 "vendor/bin.rs": nil,
912 "vendor/client.rs": nil,
913 "vendor/include/libvndk/a.h": nil,
914 "vendor/include/libvendor/b.h": nil,
915 "vendor/libvndk.a": nil,
916 "vendor/libvendor.a": nil,
917 "vendor/libvendor.so": nil,
918 "vendor/lib32.so": nil,
919 "vendor/lib64.so": nil,
920 "vendor/liblog.so": nil,
921 "vendor/libstd.rlib": nil,
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400922 "vendor/librust_vendor_available.rlib": nil,
923 "vendor/crtbegin_so.o": nil,
924 "vendor/crtend_so.o": nil,
925 "vendor/libclang_rt.builtins-aarch64-android.a": nil,
926 "vendor/libclang_rt.builtins-arm-android.a": nil,
927 "vndk/Android.bp": []byte(vndkBp),
928 "vndk/include/libvndk/a.h": nil,
929 "vndk/libvndk.so": nil,
930 }
931
932 sharedVariant := "android_vendor.30_arm64_armv8-a_shared"
933 rlibVariant := "android_vendor.30_arm64_armv8-a_rlib_rlib-std"
934 staticVariant := "android_vendor.30_arm64_armv8-a_static"
935 binaryVariant := "android_vendor.30_arm64_armv8-a"
936
937 shared32Variant := "android_vendor.30_arm_armv7-a-neon_shared"
938 binary32Variant := "android_vendor.30_arm_armv7-a-neon"
939
940 ctx := testRustVndkFsVersions(t, "", mockFS, "30", "current", "31")
941
942 // libclient uses libvndk.vndk.30.arm64, libvendor.vendor_static.30.arm64, libvendor_without_snapshot
943 libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("rustc").Args["linkFlags"]
944 for _, input := range [][]string{
945 []string{sharedVariant, "libvndk.vndk.30.arm64"},
946 []string{staticVariant, "libvendor.vendor_static.30.arm64"},
947 []string{staticVariant, "libvendor_without_snapshot"},
948 } {
949 outputPaths := cc.GetOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */)
950 if !strings.Contains(libclientLdFlags, outputPaths[0].String()) {
951 t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags)
952 }
953 }
954
955 libclientAndroidMkSharedLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkSharedLibs
956 if g, w := libclientAndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "lib64", "liblog.vendor", "libc.vendor", "libm.vendor", "libdl.vendor"}; !reflect.DeepEqual(g, w) {
957 t.Errorf("wanted libclient AndroidMkSharedLibs %q, got %q", w, g)
958 }
959
960 libclientAndroidMkStaticLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkStaticLibs
Colin Cross4c4c1be2022-02-10 11:41:18 -0800961 if g, w := libclientAndroidMkStaticLibs, []string{"libvendor", "libvendor_without_snapshot", "libclang_rt.builtins.vendor"}; !reflect.DeepEqual(g, w) {
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400962 t.Errorf("wanted libclient AndroidMkStaticLibs %q, got %q", w, g)
963 }
964
965 libclientAndroidMkRlibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkRlibs
Ivan Lozano3ee74c82021-07-15 15:44:10 -0400966 if g, w := libclientAndroidMkRlibs, []string{"librust_vendor_available.vendor_rlib.30.arm64.rlib-std", "libstd.vendor_rlib.30.arm64"}; !reflect.DeepEqual(g, w) {
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400967 t.Errorf("wanted libclient libclientAndroidMkRlibs %q, got %q", w, g)
968 }
969
970 libclientAndroidMkDylibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkDylibs
971 if len(libclientAndroidMkDylibs) > 0 {
972 t.Errorf("wanted libclient libclientAndroidMkDylibs [], got %q", libclientAndroidMkDylibs)
973 }
974
975 libclient32AndroidMkSharedLibs := ctx.ModuleForTests("libclient", shared32Variant).Module().(*Module).Properties.AndroidMkSharedLibs
976 if g, w := libclient32AndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "lib32", "liblog.vendor", "libc.vendor", "libm.vendor", "libdl.vendor"}; !reflect.DeepEqual(g, w) {
977 t.Errorf("wanted libclient32 AndroidMkSharedLibs %q, got %q", w, g)
978 }
979
980 libclientRustAndroidMkRlibs := ctx.ModuleForTests("libclient_rust", rlibVariant).Module().(*Module).Properties.AndroidMkRlibs
Ivan Lozano3ee74c82021-07-15 15:44:10 -0400981 if g, w := libclientRustAndroidMkRlibs, []string{"librust_vendor_available.vendor_rlib.30.arm64.rlib-std", "libstd.vendor_rlib.30.arm64"}; !reflect.DeepEqual(g, w) {
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400982 t.Errorf("wanted libclient libclientAndroidMkRlibs %q, got %q", w, g)
983 }
984
985 binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("rustc").Args["linkFlags"]
986 libVndkStaticOutputPaths := cc.GetOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.30.arm64"})
987 if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) {
988 t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v",
989 libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags)
990 }
991
992 // bin is installed by bin.vendor_binary.30.arm64
993 ctx.ModuleForTests("bin.vendor_binary.30.arm64", binaryVariant).Output("bin")
994
995 // bin32 is installed by bin32.vendor_binary.30.arm64
996 ctx.ModuleForTests("bin32.vendor_binary.30.arm64", binary32Variant).Output("bin32")
997
998 // bin_without_snapshot is installed by bin_without_snapshot
999 ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot")
1000
1001 // libvendor, libvendor_available and bin don't have vendor.30 variant
1002 libvendorVariants := ctx.ModuleVariantsForTests("libvendor")
1003 if android.InList(sharedVariant, libvendorVariants) {
1004 t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant)
1005 }
1006
1007 libvendorAvailableVariants := ctx.ModuleVariantsForTests("libvendor_available")
1008 if android.InList(sharedVariant, libvendorAvailableVariants) {
1009 t.Errorf("libvendor_available must not have variant %#v, but it does", sharedVariant)
1010 }
1011
1012 binVariants := ctx.ModuleVariantsForTests("bin")
1013 if android.InList(binaryVariant, binVariants) {
1014 t.Errorf("bin must not have variant %#v, but it does", sharedVariant)
1015 }
Ivan Lozano62cd0382021-11-01 10:27:54 -04001016
1017 memtagStaticLibs := ctx.ModuleForTests("memtag_binary", "android_vendor.30_arm64_armv8-a").Module().(*Module).Properties.AndroidMkStaticLibs
Colin Cross4c4c1be2022-02-10 11:41:18 -08001018 if g, w := memtagStaticLibs, []string{"libclang_rt.builtins.vendor", "note_memtag_heap_sync.vendor"}; !reflect.DeepEqual(g, w) {
Ivan Lozano62cd0382021-11-01 10:27:54 -04001019 t.Errorf("wanted memtag_binary AndroidMkStaticLibs %q, got %q", w, g)
1020 }
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001021}
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001022
1023func TestRecoverySnapshotCapture(t *testing.T) {
1024 bp := `
1025 rust_ffi {
1026 name: "librecovery",
1027 recovery: true,
1028 srcs: ["foo.rs"],
1029 crate_name: "recovery",
1030 }
1031
1032 rust_ffi {
1033 name: "librecovery_available",
1034 recovery_available: true,
1035 srcs: ["foo.rs"],
1036 crate_name: "recovery_available",
1037 }
1038
1039 rust_library_rlib {
1040 name: "librecovery_rlib",
1041 recovery: true,
1042 srcs: ["foo.rs"],
1043 crate_name: "recovery_rlib",
1044 }
1045
1046 rust_library_rlib {
1047 name: "librecovery_available_rlib",
1048 recovery_available: true,
1049 srcs: ["foo.rs"],
1050 crate_name: "recovery_available_rlib",
1051 }
1052
1053 rust_binary {
1054 name: "recovery_bin",
1055 recovery: true,
1056 srcs: ["foo.rs"],
1057 }
1058
1059 rust_binary {
1060 name: "recovery_available_bin",
1061 recovery_available: true,
1062 srcs: ["foo.rs"],
1063 }
1064
1065`
1066 // Check Recovery snapshot output.
1067
1068 ctx := testRustRecoveryFsVersions(t, bp, rustMockedFiles, "", "29", "current")
1069 snapshotDir := "recovery-snapshot"
1070 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
1071 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1072
1073 var jsonFiles []string
1074
1075 for _, arch := range [][]string{
1076 []string{"arm64", "armv8-a"},
1077 } {
1078 archType := arch[0]
1079 archVariant := arch[1]
1080 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1081
1082 // For shared libraries, all recovery:true and recovery_available modules are captured.
1083 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1084 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1085 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1086 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
1087 jsonFiles = append(jsonFiles,
1088 filepath.Join(sharedDir, "librecovery.so.json"),
1089 filepath.Join(sharedDir, "librecovery_available.so.json"))
1090
1091 // For static libraries, all recovery:true and recovery_available modules are captured.
1092 staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
1093 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
1094 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
1095 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
1096 jsonFiles = append(jsonFiles,
1097 filepath.Join(staticDir, "librecovery.a.json"),
1098 filepath.Join(staticDir, "librecovery_available.a.json"))
1099
1100 // For rlib libraries, all recovery:true and recovery_available modules are captured.
1101 rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant)
1102 rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
1103 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rlib", "librecovery_rlib.rlib", rlibDir, rlibVariant)
1104 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available_rlib", "librecovery_available_rlib.rlib", rlibDir, rlibVariant)
1105 jsonFiles = append(jsonFiles,
1106 filepath.Join(rlibDir, "librecovery_rlib.rlib.json"),
1107 filepath.Join(rlibDir, "librecovery_available_rlib.rlib.json"))
1108
1109 // For binary executables, all recovery:true and recovery_available modules are captured.
1110 if archType == "arm64" {
1111 binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1112 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
1113 cc.CheckSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
1114 cc.CheckSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
1115 jsonFiles = append(jsonFiles,
1116 filepath.Join(binaryDir, "recovery_bin.json"),
1117 filepath.Join(binaryDir, "recovery_available_bin.json"))
1118 }
1119 }
1120
1121 for _, jsonFile := range jsonFiles {
1122 // verify all json files exist
1123 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1124 t.Errorf("%q expected but not found", jsonFile)
1125 }
1126 }
1127}
1128
1129func TestRecoverySnapshotExclude(t *testing.T) {
1130 // This test verifies that the exclude_from_recovery_snapshot property
1131 // makes its way from the Android.bp source file into the module data
1132 // structure. It also verifies that modules are correctly included or
1133 // excluded in the recovery snapshot based on their path (framework or
1134 // vendor) and the exclude_from_recovery_snapshot property.
1135
1136 frameworkBp := `
1137 rust_ffi_shared {
1138 name: "libinclude",
1139 srcs: ["src/include.rs"],
1140 recovery_available: true,
1141 crate_name: "include",
1142 }
1143 rust_ffi_shared {
1144 name: "libexclude",
1145 srcs: ["src/exclude.rs"],
1146 recovery: true,
1147 exclude_from_recovery_snapshot: true,
1148 crate_name: "exclude",
1149 }
1150 rust_ffi_shared {
1151 name: "libavailable_exclude",
1152 srcs: ["src/exclude.rs"],
1153 recovery_available: true,
1154 exclude_from_recovery_snapshot: true,
1155 crate_name: "available_exclude",
1156 }
1157 rust_library_rlib {
1158 name: "libinclude_rlib",
1159 srcs: ["src/include.rs"],
1160 recovery_available: true,
1161 crate_name: "include_rlib",
1162 }
1163 rust_library_rlib {
1164 name: "libexclude_rlib",
1165 srcs: ["src/exclude.rs"],
1166 recovery: true,
1167 exclude_from_recovery_snapshot: true,
1168 crate_name: "exclude_rlib",
1169 }
1170 rust_library_rlib {
1171 name: "libavailable_exclude_rlib",
1172 srcs: ["src/exclude.rs"],
1173 recovery_available: true,
1174 exclude_from_recovery_snapshot: true,
1175 crate_name: "available_exclude_rlib",
1176 }
1177 `
1178
1179 vendorProprietaryBp := `
1180 rust_ffi_shared {
1181 name: "librecovery",
1182 srcs: ["recovery.rs"],
1183 recovery: true,
1184 crate_name: "recovery",
1185 }
1186 rust_library_rlib {
1187 name: "librecovery_rlib",
1188 srcs: ["recovery.rs"],
1189 recovery: true,
1190 crate_name: "recovery_rlib",
1191 }
1192 `
1193
1194 mockFS := map[string][]byte{
1195 "framework/Android.bp": []byte(frameworkBp),
1196 "framework/include.rs": nil,
1197 "framework/exclude.rs": nil,
1198 "device/Android.bp": []byte(vendorProprietaryBp),
1199 "device/recovery.rs": nil,
1200 }
1201
1202 ctx := testRustRecoveryFsVersions(t, "", mockFS, "", "29", "current")
1203
1204 // Test an include and exclude framework module.
1205 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false, sharedRecoveryVariant)
1206 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true, sharedRecoveryVariant)
1207 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true, sharedRecoveryVariant)
1208 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude_rlib", false, rlibRecoveryVariant)
1209 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude_rlib", true, rlibRecoveryVariant)
1210 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude_rlib", true, rlibRecoveryVariant)
1211
1212 // A recovery module is excluded, but by its path not the exclude_from_recovery_snapshot property
1213 // ('device/' and 'vendor/' are default excluded). See snapshot/recovery_snapshot.go for more detail.
1214 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false, sharedRecoveryVariant)
1215 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery_rlib", false, rlibRecoveryVariant)
1216
1217 // Verify the content of the recovery snapshot.
1218
1219 snapshotDir := "recovery-snapshot"
1220 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
1221 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1222
1223 var includeJsonFiles []string
1224 var excludeJsonFiles []string
1225
1226 for _, arch := range [][]string{
1227 []string{"arm64", "armv8-a"},
1228 } {
1229 archType := arch[0]
1230 archVariant := arch[1]
1231 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1232
1233 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1234 rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant)
1235 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1236 rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
1237
1238 // Included modules
1239 cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
1240 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1241 cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude_rlib", "libinclude_rlib.rlib", rlibDir, rlibVariant)
1242 includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "libinclude_rlib.rlib.json"))
1243
1244 // Excluded modules
1245 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
1246 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
1247 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1248 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1249 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
1250 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1251 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude_rlib", "libexclude_rlib.rlib", rlibDir, rlibVariant)
1252 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libexclude_rlib.rlib.json"))
1253 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery_rlib", "librecovery_rlib.rlib", rlibDir, rlibVariant)
1254 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librecovery_rlib.rlib.json"))
1255 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude_rlib", "libavailable_exclude_rlib.rlib", rlibDir, rlibVariant)
1256 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libavailable_exclude_rlib.rlib.json"))
1257 }
1258
1259 // Verify that each json file for an included module has a rule.
1260 for _, jsonFile := range includeJsonFiles {
1261 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1262 t.Errorf("include json file %q not found", jsonFile)
1263 }
1264 }
1265
1266 // Verify that each json file for an excluded module has no rule.
1267 for _, jsonFile := range excludeJsonFiles {
1268 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1269 t.Errorf("exclude json file %q found", jsonFile)
1270 }
1271 }
1272}
1273
1274func TestRecoverySnapshotDirected(t *testing.T) {
1275 bp := `
1276 rust_ffi_shared {
1277 name: "librecovery",
1278 recovery: true,
1279 crate_name: "recovery",
1280 srcs: ["foo.rs"],
1281 }
1282
1283 rust_ffi_shared {
1284 name: "librecovery_available",
1285 recovery_available: true,
1286 crate_name: "recovery_available",
1287 srcs: ["foo.rs"],
1288 }
1289
1290 rust_library_rlib {
1291 name: "librecovery_rlib",
1292 recovery: true,
1293 crate_name: "recovery",
1294 srcs: ["foo.rs"],
1295 }
1296
1297 rust_library_rlib {
1298 name: "librecovery_available_rlib",
1299 recovery_available: true,
1300 crate_name: "recovery_available",
1301 srcs: ["foo.rs"],
1302 }
1303
1304 /* TODO: Uncomment when Rust supports the "prefer" property for prebuilts
1305 rust_library_rlib {
1306 name: "libfoo_rlib",
1307 recovery: true,
1308 crate_name: "foo",
1309 }
1310
1311 rust_prebuilt_rlib {
1312 name: "libfoo_rlib",
1313 recovery: true,
1314 prefer: true,
1315 srcs: ["libfoo.rlib"],
1316 crate_name: "foo",
1317 }
1318 */
1319`
1320 ctx := testRustRecoveryFsVersions(t, bp, rustMockedFiles, "current", "29", "current")
1321 ctx.Config().TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
1322 ctx.Config().TestProductVariables.RecoverySnapshotModules["librecovery"] = true
1323 ctx.Config().TestProductVariables.RecoverySnapshotModules["librecovery_rlib"] = true
1324 ctx.Config().TestProductVariables.DirectedRecoverySnapshot = true
1325
1326 // Check recovery snapshot output.
1327 snapshotDir := "recovery-snapshot"
1328 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
1329 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1330
1331 var includeJsonFiles []string
1332
1333 for _, arch := range [][]string{
1334 []string{"arm64", "armv8-a"},
1335 } {
1336 archType := arch[0]
1337 archVariant := arch[1]
1338 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1339
1340 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1341 rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant)
1342 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1343 rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
1344
1345 // Included modules
1346 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1347 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1348 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rlib", "librecovery_rlib.rlib", rlibDir, rlibVariant)
1349 includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_rlib.rlib.json"))
1350
1351 // TODO: When Rust supports the "prefer" property for prebuilts, perform this check.
1352 /*
1353 // Check that snapshot captures "prefer: true" prebuilt
1354 cc.CheckSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo_rlib", "libfoo_rlib.rlib", rlibDir, rlibVariant)
1355 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo_rlib.rlib.json"))
1356 */
1357
1358 // Excluded modules. Modules not included in the directed recovery snapshot
1359 // are still included as fake modules.
1360 cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
1361 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json"))
1362 cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available_rlib", "librecovery_available_rlib.rlib", rlibDir, rlibVariant)
1363 includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_available_rlib.rlib.json"))
1364 }
1365
1366 // Verify that each json file for an included module has a rule.
1367 for _, jsonFile := range includeJsonFiles {
1368 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1369 t.Errorf("include json file %q not found, %#v", jsonFile, includeJsonFiles)
1370 }
1371 }
1372}