blob: 03bd867a34054dd6d5306896ddb7163a3edd730c [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",
564 "libclang_rt.builtins-aarch64-android",
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",
592 "libclang_rt.builtins-arm-android",
593 ],
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 {
734 name: "libclang_rt.builtins-aarch64-android",
735 version: "30",
736 target_arch: "arm64",
737 vendor: true,
738 arch: {
739 arm64: {
740 src: "libclang_rt.builtins-aarch64-android.a",
741 },
742 },
743 }
744
745 vendor_snapshot_static {
746 name: "libclang_rt.builtins-arm-android",
747 version: "30",
748 target_arch: "arm64",
749 vendor: true,
750 arch: {
751 arm: {
752 src: "libclang_rt.builtins-arm-android.a",
753 },
754 },
755 }
756
757 vendor_snapshot_shared {
758 name: "lib32",
759 version: "30",
760 target_arch: "arm64",
761 compile_multilib: "32",
762 vendor: true,
763 arch: {
764 arm: {
765 src: "lib32.so",
766 },
767 },
768 }
769
770 vendor_snapshot_shared {
771 name: "lib64",
772 version: "30",
773 target_arch: "arm64",
774 compile_multilib: "64",
775 vendor: true,
776 arch: {
777 arm64: {
778 src: "lib64.so",
779 },
780 },
781 }
782 vendor_snapshot_shared {
783 name: "liblog",
784 version: "30",
785 target_arch: "arm64",
786 compile_multilib: "64",
787 vendor: true,
788 arch: {
789 arm64: {
790 src: "liblog.so",
791 },
792 },
793 }
794
795 vendor_snapshot_static {
796 name: "libvendor",
797 version: "30",
798 target_arch: "arm64",
799 compile_multilib: "both",
800 vendor: true,
801 arch: {
802 arm64: {
803 src: "libvendor.a",
804 export_include_dirs: ["include/libvendor"],
805 },
806 arm: {
807 src: "libvendor.a",
808 export_include_dirs: ["include/libvendor"],
809 },
810 },
811 }
812
813 vendor_snapshot_shared {
814 name: "libvendor_available",
815 version: "30",
816 target_arch: "arm64",
817 compile_multilib: "both",
818 vendor: true,
819 arch: {
820 arm64: {
821 src: "libvendor_available.so",
822 export_include_dirs: ["include/libvendor"],
823 },
824 arm: {
825 src: "libvendor_available.so",
826 export_include_dirs: ["include/libvendor"],
827 },
828 },
829 }
830
831 vendor_snapshot_binary {
832 name: "bin",
833 version: "30",
834 target_arch: "arm64",
835 compile_multilib: "64",
836 vendor: true,
837 arch: {
838 arm64: {
839 src: "bin",
840 },
841 },
842 }
843
844 vendor_snapshot_binary {
845 name: "bin32",
846 version: "30",
847 target_arch: "arm64",
848 compile_multilib: "32",
849 vendor: true,
850 arch: {
851 arm: {
852 src: "bin32",
853 },
854 },
855 }
856
Ivan Lozano62cd0382021-11-01 10:27:54 -0400857 // Test sanitizers use the snapshot libraries
858 rust_binary {
859 name: "memtag_binary",
860 srcs: ["vendor/bin.rs"],
861 vendor: true,
862 compile_multilib: "64",
863 sanitize: {
864 memtag_heap: true,
865 diag: {
866 memtag_heap: true,
867 }
868 },
869 }
870
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400871 // old snapshot module which has to be ignored
872 vendor_snapshot_binary {
873 name: "bin",
874 version: "26",
875 target_arch: "arm64",
876 compile_multilib: "first",
877 vendor: true,
878 arch: {
879 arm64: {
880 src: "bin",
881 },
882 },
883 }
884
885 // different arch snapshot which has to be ignored
886 vendor_snapshot_binary {
887 name: "bin",
888 version: "30",
889 target_arch: "arm",
890 compile_multilib: "first",
891 vendor: true,
892 arch: {
893 arm64: {
894 src: "bin",
895 },
896 },
897 }
Ivan Lozano62cd0382021-11-01 10:27:54 -0400898
899 vendor_snapshot_static {
900 name: "note_memtag_heap_sync",
901 vendor: true,
902 target_arch: "arm64",
903 version: "30",
904 arch: {
905 arm64: {
906 src: "note_memtag_heap_sync.a",
907 },
908 },
909 }
910
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400911`
912
913 mockFS := android.MockFS{
914 "framework/Android.bp": []byte(frameworkBp),
915 "framework/bin.rs": nil,
Ivan Lozano62cd0382021-11-01 10:27:54 -0400916 "note_memtag_heap_sync.a": nil,
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400917 "vendor/Android.bp": []byte(vendorProprietaryBp),
918 "vendor/bin": nil,
919 "vendor/bin32": nil,
920 "vendor/bin.rs": nil,
921 "vendor/client.rs": nil,
922 "vendor/include/libvndk/a.h": nil,
923 "vendor/include/libvendor/b.h": nil,
924 "vendor/libvndk.a": nil,
925 "vendor/libvendor.a": nil,
926 "vendor/libvendor.so": nil,
927 "vendor/lib32.so": nil,
928 "vendor/lib64.so": nil,
929 "vendor/liblog.so": nil,
930 "vendor/libstd.rlib": nil,
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400931 "vendor/librust_vendor_available.rlib": nil,
932 "vendor/crtbegin_so.o": nil,
933 "vendor/crtend_so.o": nil,
934 "vendor/libclang_rt.builtins-aarch64-android.a": nil,
935 "vendor/libclang_rt.builtins-arm-android.a": nil,
936 "vndk/Android.bp": []byte(vndkBp),
937 "vndk/include/libvndk/a.h": nil,
938 "vndk/libvndk.so": nil,
939 }
940
941 sharedVariant := "android_vendor.30_arm64_armv8-a_shared"
942 rlibVariant := "android_vendor.30_arm64_armv8-a_rlib_rlib-std"
943 staticVariant := "android_vendor.30_arm64_armv8-a_static"
944 binaryVariant := "android_vendor.30_arm64_armv8-a"
945
946 shared32Variant := "android_vendor.30_arm_armv7-a-neon_shared"
947 binary32Variant := "android_vendor.30_arm_armv7-a-neon"
948
949 ctx := testRustVndkFsVersions(t, "", mockFS, "30", "current", "31")
950
951 // libclient uses libvndk.vndk.30.arm64, libvendor.vendor_static.30.arm64, libvendor_without_snapshot
952 libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("rustc").Args["linkFlags"]
953 for _, input := range [][]string{
954 []string{sharedVariant, "libvndk.vndk.30.arm64"},
955 []string{staticVariant, "libvendor.vendor_static.30.arm64"},
956 []string{staticVariant, "libvendor_without_snapshot"},
957 } {
958 outputPaths := cc.GetOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */)
959 if !strings.Contains(libclientLdFlags, outputPaths[0].String()) {
960 t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags)
961 }
962 }
963
964 libclientAndroidMkSharedLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkSharedLibs
965 if g, w := libclientAndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "lib64", "liblog.vendor", "libc.vendor", "libm.vendor", "libdl.vendor"}; !reflect.DeepEqual(g, w) {
966 t.Errorf("wanted libclient AndroidMkSharedLibs %q, got %q", w, g)
967 }
968
969 libclientAndroidMkStaticLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkStaticLibs
970 if g, w := libclientAndroidMkStaticLibs, []string{"libvendor", "libvendor_without_snapshot", "libclang_rt.builtins-aarch64-android.vendor"}; !reflect.DeepEqual(g, w) {
971 t.Errorf("wanted libclient AndroidMkStaticLibs %q, got %q", w, g)
972 }
973
974 libclientAndroidMkRlibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkRlibs
Ivan Lozano3ee74c82021-07-15 15:44:10 -0400975 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 -0400976 t.Errorf("wanted libclient libclientAndroidMkRlibs %q, got %q", w, g)
977 }
978
979 libclientAndroidMkDylibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkDylibs
980 if len(libclientAndroidMkDylibs) > 0 {
981 t.Errorf("wanted libclient libclientAndroidMkDylibs [], got %q", libclientAndroidMkDylibs)
982 }
983
984 libclient32AndroidMkSharedLibs := ctx.ModuleForTests("libclient", shared32Variant).Module().(*Module).Properties.AndroidMkSharedLibs
985 if g, w := libclient32AndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "lib32", "liblog.vendor", "libc.vendor", "libm.vendor", "libdl.vendor"}; !reflect.DeepEqual(g, w) {
986 t.Errorf("wanted libclient32 AndroidMkSharedLibs %q, got %q", w, g)
987 }
988
989 libclientRustAndroidMkRlibs := ctx.ModuleForTests("libclient_rust", rlibVariant).Module().(*Module).Properties.AndroidMkRlibs
Ivan Lozano3ee74c82021-07-15 15:44:10 -0400990 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 -0400991 t.Errorf("wanted libclient libclientAndroidMkRlibs %q, got %q", w, g)
992 }
993
994 binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("rustc").Args["linkFlags"]
995 libVndkStaticOutputPaths := cc.GetOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.30.arm64"})
996 if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) {
997 t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v",
998 libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags)
999 }
1000
1001 // bin is installed by bin.vendor_binary.30.arm64
1002 ctx.ModuleForTests("bin.vendor_binary.30.arm64", binaryVariant).Output("bin")
1003
1004 // bin32 is installed by bin32.vendor_binary.30.arm64
1005 ctx.ModuleForTests("bin32.vendor_binary.30.arm64", binary32Variant).Output("bin32")
1006
1007 // bin_without_snapshot is installed by bin_without_snapshot
1008 ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot")
1009
1010 // libvendor, libvendor_available and bin don't have vendor.30 variant
1011 libvendorVariants := ctx.ModuleVariantsForTests("libvendor")
1012 if android.InList(sharedVariant, libvendorVariants) {
1013 t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant)
1014 }
1015
1016 libvendorAvailableVariants := ctx.ModuleVariantsForTests("libvendor_available")
1017 if android.InList(sharedVariant, libvendorAvailableVariants) {
1018 t.Errorf("libvendor_available must not have variant %#v, but it does", sharedVariant)
1019 }
1020
1021 binVariants := ctx.ModuleVariantsForTests("bin")
1022 if android.InList(binaryVariant, binVariants) {
1023 t.Errorf("bin must not have variant %#v, but it does", sharedVariant)
1024 }
Ivan Lozano62cd0382021-11-01 10:27:54 -04001025
1026 memtagStaticLibs := ctx.ModuleForTests("memtag_binary", "android_vendor.30_arm64_armv8-a").Module().(*Module).Properties.AndroidMkStaticLibs
1027 if g, w := memtagStaticLibs, []string{"libclang_rt.builtins-aarch64-android.vendor", "note_memtag_heap_sync.vendor"}; !reflect.DeepEqual(g, w) {
1028 t.Errorf("wanted memtag_binary AndroidMkStaticLibs %q, got %q", w, g)
1029 }
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001030}
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001031
1032func TestRecoverySnapshotCapture(t *testing.T) {
1033 bp := `
1034 rust_ffi {
1035 name: "librecovery",
1036 recovery: true,
1037 srcs: ["foo.rs"],
1038 crate_name: "recovery",
1039 }
1040
1041 rust_ffi {
1042 name: "librecovery_available",
1043 recovery_available: true,
1044 srcs: ["foo.rs"],
1045 crate_name: "recovery_available",
1046 }
1047
1048 rust_library_rlib {
1049 name: "librecovery_rlib",
1050 recovery: true,
1051 srcs: ["foo.rs"],
1052 crate_name: "recovery_rlib",
1053 }
1054
1055 rust_library_rlib {
1056 name: "librecovery_available_rlib",
1057 recovery_available: true,
1058 srcs: ["foo.rs"],
1059 crate_name: "recovery_available_rlib",
1060 }
1061
1062 rust_binary {
1063 name: "recovery_bin",
1064 recovery: true,
1065 srcs: ["foo.rs"],
1066 }
1067
1068 rust_binary {
1069 name: "recovery_available_bin",
1070 recovery_available: true,
1071 srcs: ["foo.rs"],
1072 }
1073
1074`
1075 // Check Recovery snapshot output.
1076
1077 ctx := testRustRecoveryFsVersions(t, bp, rustMockedFiles, "", "29", "current")
1078 snapshotDir := "recovery-snapshot"
1079 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
1080 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1081
1082 var jsonFiles []string
1083
1084 for _, arch := range [][]string{
1085 []string{"arm64", "armv8-a"},
1086 } {
1087 archType := arch[0]
1088 archVariant := arch[1]
1089 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1090
1091 // For shared libraries, all recovery:true and recovery_available modules are captured.
1092 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1093 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1094 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1095 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
1096 jsonFiles = append(jsonFiles,
1097 filepath.Join(sharedDir, "librecovery.so.json"),
1098 filepath.Join(sharedDir, "librecovery_available.so.json"))
1099
1100 // For static libraries, all recovery:true and recovery_available modules are captured.
1101 staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
1102 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
1103 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
1104 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
1105 jsonFiles = append(jsonFiles,
1106 filepath.Join(staticDir, "librecovery.a.json"),
1107 filepath.Join(staticDir, "librecovery_available.a.json"))
1108
1109 // For rlib libraries, all recovery:true and recovery_available modules are captured.
1110 rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant)
1111 rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
1112 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rlib", "librecovery_rlib.rlib", rlibDir, rlibVariant)
1113 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available_rlib", "librecovery_available_rlib.rlib", rlibDir, rlibVariant)
1114 jsonFiles = append(jsonFiles,
1115 filepath.Join(rlibDir, "librecovery_rlib.rlib.json"),
1116 filepath.Join(rlibDir, "librecovery_available_rlib.rlib.json"))
1117
1118 // For binary executables, all recovery:true and recovery_available modules are captured.
1119 if archType == "arm64" {
1120 binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1121 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
1122 cc.CheckSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
1123 cc.CheckSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
1124 jsonFiles = append(jsonFiles,
1125 filepath.Join(binaryDir, "recovery_bin.json"),
1126 filepath.Join(binaryDir, "recovery_available_bin.json"))
1127 }
1128 }
1129
1130 for _, jsonFile := range jsonFiles {
1131 // verify all json files exist
1132 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1133 t.Errorf("%q expected but not found", jsonFile)
1134 }
1135 }
1136}
1137
1138func TestRecoverySnapshotExclude(t *testing.T) {
1139 // This test verifies that the exclude_from_recovery_snapshot property
1140 // makes its way from the Android.bp source file into the module data
1141 // structure. It also verifies that modules are correctly included or
1142 // excluded in the recovery snapshot based on their path (framework or
1143 // vendor) and the exclude_from_recovery_snapshot property.
1144
1145 frameworkBp := `
1146 rust_ffi_shared {
1147 name: "libinclude",
1148 srcs: ["src/include.rs"],
1149 recovery_available: true,
1150 crate_name: "include",
1151 }
1152 rust_ffi_shared {
1153 name: "libexclude",
1154 srcs: ["src/exclude.rs"],
1155 recovery: true,
1156 exclude_from_recovery_snapshot: true,
1157 crate_name: "exclude",
1158 }
1159 rust_ffi_shared {
1160 name: "libavailable_exclude",
1161 srcs: ["src/exclude.rs"],
1162 recovery_available: true,
1163 exclude_from_recovery_snapshot: true,
1164 crate_name: "available_exclude",
1165 }
1166 rust_library_rlib {
1167 name: "libinclude_rlib",
1168 srcs: ["src/include.rs"],
1169 recovery_available: true,
1170 crate_name: "include_rlib",
1171 }
1172 rust_library_rlib {
1173 name: "libexclude_rlib",
1174 srcs: ["src/exclude.rs"],
1175 recovery: true,
1176 exclude_from_recovery_snapshot: true,
1177 crate_name: "exclude_rlib",
1178 }
1179 rust_library_rlib {
1180 name: "libavailable_exclude_rlib",
1181 srcs: ["src/exclude.rs"],
1182 recovery_available: true,
1183 exclude_from_recovery_snapshot: true,
1184 crate_name: "available_exclude_rlib",
1185 }
1186 `
1187
1188 vendorProprietaryBp := `
1189 rust_ffi_shared {
1190 name: "librecovery",
1191 srcs: ["recovery.rs"],
1192 recovery: true,
1193 crate_name: "recovery",
1194 }
1195 rust_library_rlib {
1196 name: "librecovery_rlib",
1197 srcs: ["recovery.rs"],
1198 recovery: true,
1199 crate_name: "recovery_rlib",
1200 }
1201 `
1202
1203 mockFS := map[string][]byte{
1204 "framework/Android.bp": []byte(frameworkBp),
1205 "framework/include.rs": nil,
1206 "framework/exclude.rs": nil,
1207 "device/Android.bp": []byte(vendorProprietaryBp),
1208 "device/recovery.rs": nil,
1209 }
1210
1211 ctx := testRustRecoveryFsVersions(t, "", mockFS, "", "29", "current")
1212
1213 // Test an include and exclude framework module.
1214 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false, sharedRecoveryVariant)
1215 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true, sharedRecoveryVariant)
1216 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true, sharedRecoveryVariant)
1217 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude_rlib", false, rlibRecoveryVariant)
1218 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude_rlib", true, rlibRecoveryVariant)
1219 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude_rlib", true, rlibRecoveryVariant)
1220
1221 // A recovery module is excluded, but by its path not the exclude_from_recovery_snapshot property
1222 // ('device/' and 'vendor/' are default excluded). See snapshot/recovery_snapshot.go for more detail.
1223 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false, sharedRecoveryVariant)
1224 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery_rlib", false, rlibRecoveryVariant)
1225
1226 // Verify the content of the recovery snapshot.
1227
1228 snapshotDir := "recovery-snapshot"
1229 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
1230 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1231
1232 var includeJsonFiles []string
1233 var excludeJsonFiles []string
1234
1235 for _, arch := range [][]string{
1236 []string{"arm64", "armv8-a"},
1237 } {
1238 archType := arch[0]
1239 archVariant := arch[1]
1240 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1241
1242 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1243 rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant)
1244 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1245 rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
1246
1247 // Included modules
1248 cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
1249 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1250 cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude_rlib", "libinclude_rlib.rlib", rlibDir, rlibVariant)
1251 includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "libinclude_rlib.rlib.json"))
1252
1253 // Excluded modules
1254 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
1255 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
1256 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1257 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1258 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
1259 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1260 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude_rlib", "libexclude_rlib.rlib", rlibDir, rlibVariant)
1261 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libexclude_rlib.rlib.json"))
1262 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery_rlib", "librecovery_rlib.rlib", rlibDir, rlibVariant)
1263 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librecovery_rlib.rlib.json"))
1264 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude_rlib", "libavailable_exclude_rlib.rlib", rlibDir, rlibVariant)
1265 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libavailable_exclude_rlib.rlib.json"))
1266 }
1267
1268 // Verify that each json file for an included module has a rule.
1269 for _, jsonFile := range includeJsonFiles {
1270 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1271 t.Errorf("include json file %q not found", jsonFile)
1272 }
1273 }
1274
1275 // Verify that each json file for an excluded module has no rule.
1276 for _, jsonFile := range excludeJsonFiles {
1277 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1278 t.Errorf("exclude json file %q found", jsonFile)
1279 }
1280 }
1281}
1282
1283func TestRecoverySnapshotDirected(t *testing.T) {
1284 bp := `
1285 rust_ffi_shared {
1286 name: "librecovery",
1287 recovery: true,
1288 crate_name: "recovery",
1289 srcs: ["foo.rs"],
1290 }
1291
1292 rust_ffi_shared {
1293 name: "librecovery_available",
1294 recovery_available: true,
1295 crate_name: "recovery_available",
1296 srcs: ["foo.rs"],
1297 }
1298
1299 rust_library_rlib {
1300 name: "librecovery_rlib",
1301 recovery: true,
1302 crate_name: "recovery",
1303 srcs: ["foo.rs"],
1304 }
1305
1306 rust_library_rlib {
1307 name: "librecovery_available_rlib",
1308 recovery_available: true,
1309 crate_name: "recovery_available",
1310 srcs: ["foo.rs"],
1311 }
1312
1313 /* TODO: Uncomment when Rust supports the "prefer" property for prebuilts
1314 rust_library_rlib {
1315 name: "libfoo_rlib",
1316 recovery: true,
1317 crate_name: "foo",
1318 }
1319
1320 rust_prebuilt_rlib {
1321 name: "libfoo_rlib",
1322 recovery: true,
1323 prefer: true,
1324 srcs: ["libfoo.rlib"],
1325 crate_name: "foo",
1326 }
1327 */
1328`
1329 ctx := testRustRecoveryFsVersions(t, bp, rustMockedFiles, "current", "29", "current")
1330 ctx.Config().TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
1331 ctx.Config().TestProductVariables.RecoverySnapshotModules["librecovery"] = true
1332 ctx.Config().TestProductVariables.RecoverySnapshotModules["librecovery_rlib"] = true
1333 ctx.Config().TestProductVariables.DirectedRecoverySnapshot = true
1334
1335 // Check recovery snapshot output.
1336 snapshotDir := "recovery-snapshot"
1337 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
1338 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1339
1340 var includeJsonFiles []string
1341
1342 for _, arch := range [][]string{
1343 []string{"arm64", "armv8-a"},
1344 } {
1345 archType := arch[0]
1346 archVariant := arch[1]
1347 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1348
1349 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1350 rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant)
1351 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1352 rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
1353
1354 // Included modules
1355 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1356 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1357 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rlib", "librecovery_rlib.rlib", rlibDir, rlibVariant)
1358 includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_rlib.rlib.json"))
1359
1360 // TODO: When Rust supports the "prefer" property for prebuilts, perform this check.
1361 /*
1362 // Check that snapshot captures "prefer: true" prebuilt
1363 cc.CheckSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo_rlib", "libfoo_rlib.rlib", rlibDir, rlibVariant)
1364 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo_rlib.rlib.json"))
1365 */
1366
1367 // Excluded modules. Modules not included in the directed recovery snapshot
1368 // are still included as fake modules.
1369 cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
1370 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json"))
1371 cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available_rlib", "librecovery_available_rlib.rlib", rlibDir, rlibVariant)
1372 includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_available_rlib.rlib.json"))
1373 }
1374
1375 // Verify that each json file for an included module has a rule.
1376 for _, jsonFile := range includeJsonFiles {
1377 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1378 t.Errorf("include json file %q not found, %#v", jsonFile, includeJsonFiles)
1379 }
1380 }
1381}