blob: 60ddb653fb24c6a1081dabb12fdfb8055fd897cb [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",
565 ],
566 shared_libs: [
567 "libvendor_available",
568 "lib64",
569 ],
570 rlibs: [
571 "libstd",
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400572 "librust_vendor_available",
573 ],
574 binaries: [
575 "bin",
576 ],
577 objects: [
578 "crtend_so",
579 "crtbegin_so",
580 "crtbegin_dynamic",
581 "crtend_android"
582 ],
583 },
584 arm: {
585 vndk_libs: [
586 "libvndk",
587 ],
588 static_libs: [
589 "libvendor",
590 "libvndk",
591 "libclang_rt.builtins-arm-android",
592 ],
593 shared_libs: [
594 "libvendor_available",
595 "lib32",
596 ],
597 rlibs: [
598 "libstd",
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400599 "librust_vendor_available",
600 ],
601 binaries: [
602 "bin32",
603 ],
604 objects: [
605 "crtend_so",
606 "crtbegin_so",
607 "crtbegin_dynamic",
608 "crtend_android"
609 ],
610
611 },
612 }
613 }
614
615 vendor_snapshot_object {
616 name: "crtend_so",
617 version: "30",
618 target_arch: "arm64",
619 vendor: true,
620 stl: "none",
621 crt: true,
622 arch: {
623 arm64: {
624 src: "crtend_so.o",
625 },
626 arm: {
627 src: "crtend_so.o",
628 },
629 },
630 }
631
632 vendor_snapshot_object {
633 name: "crtbegin_so",
634 version: "30",
635 target_arch: "arm64",
636 vendor: true,
637 stl: "none",
638 crt: true,
639 arch: {
640 arm64: {
641 src: "crtbegin_so.o",
642 },
643 arm: {
644 src: "crtbegin_so.o",
645 },
646 },
647 }
648
649 vendor_snapshot_rlib {
650 name: "libstd",
651 version: "30",
652 target_arch: "arm64",
653 vendor: true,
654 sysroot: true,
655 arch: {
656 arm64: {
657 src: "libstd.rlib",
658 },
659 arm: {
660 src: "libstd.rlib",
661 },
662 },
663 }
664
665 vendor_snapshot_rlib {
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400666 name: "librust_vendor_available",
667 version: "30",
668 target_arch: "arm64",
669 vendor: true,
670 arch: {
671 arm64: {
672 src: "librust_vendor_available.rlib",
673 },
674 arm: {
675 src: "librust_vendor_available.rlib",
676 },
677 },
678 }
679
680 vendor_snapshot_object {
681 name: "crtend_android",
682 version: "30",
683 target_arch: "arm64",
684 vendor: true,
685 stl: "none",
686 crt: true,
687 arch: {
688 arm64: {
689 src: "crtend_so.o",
690 },
691 arm: {
692 src: "crtend_so.o",
693 },
694 },
695 }
696
697 vendor_snapshot_object {
698 name: "crtbegin_dynamic",
699 version: "30",
700 target_arch: "arm64",
701 vendor: true,
702 stl: "none",
703 crt: true,
704 arch: {
705 arm64: {
706 src: "crtbegin_so.o",
707 },
708 arm: {
709 src: "crtbegin_so.o",
710 },
711 },
712 }
713
714 vendor_snapshot_static {
715 name: "libvndk",
716 version: "30",
717 target_arch: "arm64",
718 compile_multilib: "both",
719 vendor: true,
720 arch: {
721 arm64: {
722 src: "libvndk.a",
723 },
724 arm: {
725 src: "libvndk.a",
726 },
727 },
728 shared_libs: ["libvndk"],
729 export_shared_lib_headers: ["libvndk"],
730 }
731
732 vendor_snapshot_static {
733 name: "libclang_rt.builtins-aarch64-android",
734 version: "30",
735 target_arch: "arm64",
736 vendor: true,
737 arch: {
738 arm64: {
739 src: "libclang_rt.builtins-aarch64-android.a",
740 },
741 },
742 }
743
744 vendor_snapshot_static {
745 name: "libclang_rt.builtins-arm-android",
746 version: "30",
747 target_arch: "arm64",
748 vendor: true,
749 arch: {
750 arm: {
751 src: "libclang_rt.builtins-arm-android.a",
752 },
753 },
754 }
755
756 vendor_snapshot_shared {
757 name: "lib32",
758 version: "30",
759 target_arch: "arm64",
760 compile_multilib: "32",
761 vendor: true,
762 arch: {
763 arm: {
764 src: "lib32.so",
765 },
766 },
767 }
768
769 vendor_snapshot_shared {
770 name: "lib64",
771 version: "30",
772 target_arch: "arm64",
773 compile_multilib: "64",
774 vendor: true,
775 arch: {
776 arm64: {
777 src: "lib64.so",
778 },
779 },
780 }
781 vendor_snapshot_shared {
782 name: "liblog",
783 version: "30",
784 target_arch: "arm64",
785 compile_multilib: "64",
786 vendor: true,
787 arch: {
788 arm64: {
789 src: "liblog.so",
790 },
791 },
792 }
793
794 vendor_snapshot_static {
795 name: "libvendor",
796 version: "30",
797 target_arch: "arm64",
798 compile_multilib: "both",
799 vendor: true,
800 arch: {
801 arm64: {
802 src: "libvendor.a",
803 export_include_dirs: ["include/libvendor"],
804 },
805 arm: {
806 src: "libvendor.a",
807 export_include_dirs: ["include/libvendor"],
808 },
809 },
810 }
811
812 vendor_snapshot_shared {
813 name: "libvendor_available",
814 version: "30",
815 target_arch: "arm64",
816 compile_multilib: "both",
817 vendor: true,
818 arch: {
819 arm64: {
820 src: "libvendor_available.so",
821 export_include_dirs: ["include/libvendor"],
822 },
823 arm: {
824 src: "libvendor_available.so",
825 export_include_dirs: ["include/libvendor"],
826 },
827 },
828 }
829
830 vendor_snapshot_binary {
831 name: "bin",
832 version: "30",
833 target_arch: "arm64",
834 compile_multilib: "64",
835 vendor: true,
836 arch: {
837 arm64: {
838 src: "bin",
839 },
840 },
841 }
842
843 vendor_snapshot_binary {
844 name: "bin32",
845 version: "30",
846 target_arch: "arm64",
847 compile_multilib: "32",
848 vendor: true,
849 arch: {
850 arm: {
851 src: "bin32",
852 },
853 },
854 }
855
856 // old snapshot module which has to be ignored
857 vendor_snapshot_binary {
858 name: "bin",
859 version: "26",
860 target_arch: "arm64",
861 compile_multilib: "first",
862 vendor: true,
863 arch: {
864 arm64: {
865 src: "bin",
866 },
867 },
868 }
869
870 // different arch snapshot which has to be ignored
871 vendor_snapshot_binary {
872 name: "bin",
873 version: "30",
874 target_arch: "arm",
875 compile_multilib: "first",
876 vendor: true,
877 arch: {
878 arm64: {
879 src: "bin",
880 },
881 },
882 }
883`
884
885 mockFS := android.MockFS{
886 "framework/Android.bp": []byte(frameworkBp),
887 "framework/bin.rs": nil,
888 "vendor/Android.bp": []byte(vendorProprietaryBp),
889 "vendor/bin": nil,
890 "vendor/bin32": nil,
891 "vendor/bin.rs": nil,
892 "vendor/client.rs": nil,
893 "vendor/include/libvndk/a.h": nil,
894 "vendor/include/libvendor/b.h": nil,
895 "vendor/libvndk.a": nil,
896 "vendor/libvendor.a": nil,
897 "vendor/libvendor.so": nil,
898 "vendor/lib32.so": nil,
899 "vendor/lib64.so": nil,
900 "vendor/liblog.so": nil,
901 "vendor/libstd.rlib": nil,
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400902 "vendor/librust_vendor_available.rlib": nil,
903 "vendor/crtbegin_so.o": nil,
904 "vendor/crtend_so.o": nil,
905 "vendor/libclang_rt.builtins-aarch64-android.a": nil,
906 "vendor/libclang_rt.builtins-arm-android.a": nil,
907 "vndk/Android.bp": []byte(vndkBp),
908 "vndk/include/libvndk/a.h": nil,
909 "vndk/libvndk.so": nil,
910 }
911
912 sharedVariant := "android_vendor.30_arm64_armv8-a_shared"
913 rlibVariant := "android_vendor.30_arm64_armv8-a_rlib_rlib-std"
914 staticVariant := "android_vendor.30_arm64_armv8-a_static"
915 binaryVariant := "android_vendor.30_arm64_armv8-a"
916
917 shared32Variant := "android_vendor.30_arm_armv7-a-neon_shared"
918 binary32Variant := "android_vendor.30_arm_armv7-a-neon"
919
920 ctx := testRustVndkFsVersions(t, "", mockFS, "30", "current", "31")
921
922 // libclient uses libvndk.vndk.30.arm64, libvendor.vendor_static.30.arm64, libvendor_without_snapshot
923 libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("rustc").Args["linkFlags"]
924 for _, input := range [][]string{
925 []string{sharedVariant, "libvndk.vndk.30.arm64"},
926 []string{staticVariant, "libvendor.vendor_static.30.arm64"},
927 []string{staticVariant, "libvendor_without_snapshot"},
928 } {
929 outputPaths := cc.GetOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */)
930 if !strings.Contains(libclientLdFlags, outputPaths[0].String()) {
931 t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags)
932 }
933 }
934
935 libclientAndroidMkSharedLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkSharedLibs
936 if g, w := libclientAndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "lib64", "liblog.vendor", "libc.vendor", "libm.vendor", "libdl.vendor"}; !reflect.DeepEqual(g, w) {
937 t.Errorf("wanted libclient AndroidMkSharedLibs %q, got %q", w, g)
938 }
939
940 libclientAndroidMkStaticLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkStaticLibs
941 if g, w := libclientAndroidMkStaticLibs, []string{"libvendor", "libvendor_without_snapshot", "libclang_rt.builtins-aarch64-android.vendor"}; !reflect.DeepEqual(g, w) {
942 t.Errorf("wanted libclient AndroidMkStaticLibs %q, got %q", w, g)
943 }
944
945 libclientAndroidMkRlibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkRlibs
Ivan Lozano3ee74c82021-07-15 15:44:10 -0400946 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 -0400947 t.Errorf("wanted libclient libclientAndroidMkRlibs %q, got %q", w, g)
948 }
949
950 libclientAndroidMkDylibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkDylibs
951 if len(libclientAndroidMkDylibs) > 0 {
952 t.Errorf("wanted libclient libclientAndroidMkDylibs [], got %q", libclientAndroidMkDylibs)
953 }
954
955 libclient32AndroidMkSharedLibs := ctx.ModuleForTests("libclient", shared32Variant).Module().(*Module).Properties.AndroidMkSharedLibs
956 if g, w := libclient32AndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "lib32", "liblog.vendor", "libc.vendor", "libm.vendor", "libdl.vendor"}; !reflect.DeepEqual(g, w) {
957 t.Errorf("wanted libclient32 AndroidMkSharedLibs %q, got %q", w, g)
958 }
959
960 libclientRustAndroidMkRlibs := ctx.ModuleForTests("libclient_rust", rlibVariant).Module().(*Module).Properties.AndroidMkRlibs
Ivan Lozano3ee74c82021-07-15 15:44:10 -0400961 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 -0400962 t.Errorf("wanted libclient libclientAndroidMkRlibs %q, got %q", w, g)
963 }
964
965 binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("rustc").Args["linkFlags"]
966 libVndkStaticOutputPaths := cc.GetOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.30.arm64"})
967 if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) {
968 t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v",
969 libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags)
970 }
971
972 // bin is installed by bin.vendor_binary.30.arm64
973 ctx.ModuleForTests("bin.vendor_binary.30.arm64", binaryVariant).Output("bin")
974
975 // bin32 is installed by bin32.vendor_binary.30.arm64
976 ctx.ModuleForTests("bin32.vendor_binary.30.arm64", binary32Variant).Output("bin32")
977
978 // bin_without_snapshot is installed by bin_without_snapshot
979 ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot")
980
981 // libvendor, libvendor_available and bin don't have vendor.30 variant
982 libvendorVariants := ctx.ModuleVariantsForTests("libvendor")
983 if android.InList(sharedVariant, libvendorVariants) {
984 t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant)
985 }
986
987 libvendorAvailableVariants := ctx.ModuleVariantsForTests("libvendor_available")
988 if android.InList(sharedVariant, libvendorAvailableVariants) {
989 t.Errorf("libvendor_available must not have variant %#v, but it does", sharedVariant)
990 }
991
992 binVariants := ctx.ModuleVariantsForTests("bin")
993 if android.InList(binaryVariant, binVariants) {
994 t.Errorf("bin must not have variant %#v, but it does", sharedVariant)
995 }
996}