blob: 4f45799e655767ee7e5d23964bf3a6510c5d8ce5 [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,
Ivan Lozano1921e802021-05-20 13:39:16 -040051 }
52
Ivan Lozanoadd122a2023-07-13 11:01:41 -040053 rust_library {
Ivan Lozano3149e6e2021-06-01 15:09:53 -040054 name: "librustvendor",
55 crate_name: "rustvendor",
56 srcs: ["lib.rs"],
57 vendor: true,
Ivan Lozano3149e6e2021-06-01 15:09:53 -040058 }
59
Ivan Lozano1921e802021-05-20 13:39:16 -040060 rust_binary {
61 name: "vendor_available_bin",
62 vendor_available: true,
63 srcs: ["srcs/lib.rs"],
64 }
65
Ivan Lozano3149e6e2021-06-01 15:09:53 -040066 rust_binary {
67 name: "vendor_bin",
68 vendor: true,
69 srcs: ["srcs/lib.rs"],
70 }
71 `
Ivan Lozano1921e802021-05-20 13:39:16 -040072 skipTestIfOsNotSupported(t)
73 result := android.GroupFixturePreparers(
74 prepareForRustTest,
75 rustMockedFiles.AddToFixture(),
76 android.FixtureModifyProductVariables(
77 func(variables android.FixtureProductVariables) {
78 variables.DeviceVndkVersion = StringPtr("current")
79 variables.Platform_vndk_version = StringPtr("29")
80 },
81 ),
82 ).RunTestWithBp(t, bp)
83 ctx := result.TestContext
84
85 // Check Vendor snapshot output.
86
87 snapshotDir := "vendor-snapshot"
88 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
89 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
90 var jsonFiles []string
91 for _, arch := range [][]string{
92 []string{"arm64", "armv8-a"},
93 []string{"arm", "armv7-a-neon"},
94 } {
95 archType := arch[0]
96 archVariant := arch[1]
97 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
98
99 // For shared libraries, only non-VNDK vendor_available modules are captured
100 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
101 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400102 cc.CheckSnapshot(t, ctx, snapshotSingleton, "libffivendor_available", "libffivendor_available.so", sharedDir, sharedVariant)
Ivan Lozano1921e802021-05-20 13:39:16 -0400103 jsonFiles = append(jsonFiles,
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400104 filepath.Join(sharedDir, "libffivendor_available.so.json"))
Ivan Lozano1921e802021-05-20 13:39:16 -0400105
106 // For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
107 staticVariant := fmt.Sprintf("android_vendor.29_%s_%s_static", archType, archVariant)
108 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400109 cc.CheckSnapshot(t, ctx, snapshotSingleton, "libffivendor_available", "libffivendor_available.a", staticDir, staticVariant)
110 cc.CheckSnapshot(t, ctx, snapshotSingleton, "libffivendor", "libffivendor.a", staticDir, staticVariant)
Ivan Lozano1921e802021-05-20 13:39:16 -0400111 jsonFiles = append(jsonFiles,
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400112 filepath.Join(staticDir, "libffivendor_available.a.json"))
113 jsonFiles = append(jsonFiles,
114 filepath.Join(staticDir, "libffivendor.a.json"))
Ivan Lozano1921e802021-05-20 13:39:16 -0400115
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400116 // For rlib libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400117 rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_dylib-std", archType, archVariant)
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400118 rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
119 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib", rlibDir, rlibVariant)
120 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor", "librustvendor.rlib", rlibDir, rlibVariant)
121 jsonFiles = append(jsonFiles,
122 filepath.Join(rlibDir, "librustvendor_available.rlib.json"))
123 jsonFiles = append(jsonFiles,
124 filepath.Join(rlibDir, "librustvendor.rlib.json"))
125
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400126 // For rlib libraries, all rlib-std variants vendor:true and vendor_available modules (including VNDK) are captured.
127 rlibStdVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant)
128 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib-std.rlib", rlibDir, rlibStdVariant)
129 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor", "librustvendor.rlib-std.rlib", rlibDir, rlibStdVariant)
130 jsonFiles = append(jsonFiles,
131 filepath.Join(rlibDir, "librustvendor_available.rlib.json"))
132 jsonFiles = append(jsonFiles,
133 filepath.Join(rlibDir, "librustvendor.rlib.json"))
134
135 // For dylib libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
136 dylibVariant := fmt.Sprintf("android_vendor.29_%s_%s_dylib", archType, archVariant)
137 dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
138 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.dylib.so", dylibDir, dylibVariant)
139 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor", "librustvendor.dylib.so", dylibDir, dylibVariant)
140 jsonFiles = append(jsonFiles,
141 filepath.Join(dylibDir, "librustvendor_available.dylib.so.json"))
142 jsonFiles = append(jsonFiles,
143 filepath.Join(dylibDir, "librustvendor.dylib.so.json"))
144
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400145 // For binary executables, all vendor:true and vendor_available modules are captured.
Ivan Lozano1921e802021-05-20 13:39:16 -0400146 if archType == "arm64" {
147 binaryVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
148 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
149 cc.CheckSnapshot(t, ctx, snapshotSingleton, "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant)
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400150 cc.CheckSnapshot(t, ctx, snapshotSingleton, "vendor_bin", "vendor_bin", binaryDir, binaryVariant)
Ivan Lozano1921e802021-05-20 13:39:16 -0400151 jsonFiles = append(jsonFiles,
152 filepath.Join(binaryDir, "vendor_available_bin.json"))
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400153 jsonFiles = append(jsonFiles,
154 filepath.Join(binaryDir, "vendor_bin.json"))
Ivan Lozano1921e802021-05-20 13:39:16 -0400155 }
156 }
157
158 for _, jsonFile := range jsonFiles {
159 // verify all json files exist
160 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
161 t.Errorf("%q expected but not found; #%v", jsonFile, jsonFiles)
162 }
163 }
164
165 // fake snapshot should have all outputs in the normal snapshot.
166 fakeSnapshotSingleton := ctx.SingletonForTests("vendor-fake-snapshot")
167
168 for _, output := range snapshotSingleton.AllOutputs() {
169 fakeOutput := strings.Replace(output, "/vendor-snapshot/", "/fake/vendor-snapshot/", 1)
170 if fakeSnapshotSingleton.MaybeOutput(fakeOutput).Rule == nil {
171 t.Errorf("%q expected but not found", fakeOutput)
172 }
173 }
174}
175
176func TestVendorSnapshotDirected(t *testing.T) {
177 bp := `
178 rust_ffi_shared {
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400179 name: "libffivendor_available",
180 crate_name: "ffivendor_available",
181 srcs: ["lib.rs"],
182 vendor_available: true,
183 }
184
185 rust_library {
Ivan Lozano1921e802021-05-20 13:39:16 -0400186 name: "librustvendor_available",
187 crate_name: "rustvendor_available",
188 srcs: ["lib.rs"],
189 vendor_available: true,
190 }
191
192 rust_ffi_shared {
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400193 name: "libffivendor_exclude",
194 crate_name: "ffivendor_exclude",
195 srcs: ["lib.rs"],
196 vendor_available: true,
197 }
198
199 rust_library {
Ivan Lozano1921e802021-05-20 13:39:16 -0400200 name: "librustvendor_exclude",
201 crate_name: "rustvendor_exclude",
202 srcs: ["lib.rs"],
203 vendor_available: true,
204 }
205`
206 ctx := testRustVndk(t, bp)
207 ctx.Config().TestProductVariables.VendorSnapshotModules = make(map[string]bool)
208 ctx.Config().TestProductVariables.VendorSnapshotModules["librustvendor_available"] = true
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400209 ctx.Config().TestProductVariables.VendorSnapshotModules["libffivendor_available"] = true
Ivan Lozano1921e802021-05-20 13:39:16 -0400210 ctx.Config().TestProductVariables.DirectedVendorSnapshot = true
211
212 // Check Vendor snapshot output.
213
214 snapshotDir := "vendor-snapshot"
215 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
216 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
217
218 var includeJsonFiles []string
219
220 for _, arch := range [][]string{
221 []string{"arm64", "armv8-a"},
222 []string{"arm", "armv7-a-neon"},
223 } {
224 archType := arch[0]
225 archVariant := arch[1]
226 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
227
228 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400229 rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_dylib-std", archType, archVariant)
230 rlibRlibStdVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant)
Ivan Lozano1921e802021-05-20 13:39:16 -0400231 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400232 rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400233 dylibVariant := fmt.Sprintf("android_vendor.29_%s_%s_dylib", archType, archVariant)
234 dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
Ivan Lozano1921e802021-05-20 13:39:16 -0400235
236 // Included modules
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400237 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib", rlibDir, rlibVariant)
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400238 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
239 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.dylib.so", dylibDir, dylibVariant)
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400240 cc.CheckSnapshot(t, ctx, snapshotSingleton, "libffivendor_available", "libffivendor_available.so", sharedDir, sharedVariant)
241 includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_available.rlib.json"))
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400242 includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_available.rlib-std.rlib.json"))
243 includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librustvendor_available.dylib.so.json"))
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400244 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libffivendor_available.so.json"))
Ivan Lozano1921e802021-05-20 13:39:16 -0400245
246 // Excluded modules. Modules not included in the directed vendor snapshot
247 // are still include as fake modules.
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400248 cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librustvendor_exclude", "librustvendor_exclude.rlib", rlibDir, rlibVariant)
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400249 cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librustvendor_exclude", "librustvendor_exclude.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
250 cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librustvendor_exclude", "librustvendor_exclude.dylib.so", dylibDir, dylibVariant)
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400251 cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "libffivendor_exclude", "libffivendor_exclude.so", sharedDir, sharedVariant)
252 includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_exclude.rlib.json"))
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400253 includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_exclude.rlib-std.rlib.json"))
254 includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librustvendor_exclude.dylib.so.json"))
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400255 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libffivendor_exclude.so.json"))
Ivan Lozano1921e802021-05-20 13:39:16 -0400256 }
257
258 // Verify that each json file for an included module has a rule.
259 for _, jsonFile := range includeJsonFiles {
260 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
261 t.Errorf("include json file %q not found", jsonFile)
262 }
263 }
264}
265
266func TestVendorSnapshotExclude(t *testing.T) {
267
268 // This test verifies that the exclude_from_vendor_snapshot property
269 // makes its way from the Android.bp source file into the module data
270 // structure. It also verifies that modules are correctly included or
271 // excluded in the vendor snapshot based on their path (framework or
272 // vendor) and the exclude_from_vendor_snapshot property.
273
Ivan Lozano1921e802021-05-20 13:39:16 -0400274 frameworkBp := `
275 rust_ffi_shared {
276 name: "libinclude",
277 crate_name: "include",
278 srcs: ["include.rs"],
279 vendor_available: true,
280 }
281
282 rust_ffi_shared {
283 name: "libexclude",
284 crate_name: "exclude",
285 srcs: ["exclude.rs"],
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400286 vendor: true,
Ivan Lozano1921e802021-05-20 13:39:16 -0400287 exclude_from_vendor_snapshot: true,
288 }
289
290 rust_ffi_shared {
291 name: "libavailable_exclude",
292 crate_name: "available_exclude",
293 srcs: ["lib.rs"],
294 vendor_available: true,
295 exclude_from_vendor_snapshot: true,
296 }
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400297
298 rust_library {
299 name: "librust_include",
300 crate_name: "rust_include",
301 srcs: ["include.rs"],
302 vendor_available: true,
303 }
304
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400305 rust_library {
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400306 name: "librust_exclude",
307 crate_name: "rust_exclude",
308 srcs: ["exclude.rs"],
309 vendor: true,
310 exclude_from_vendor_snapshot: true,
311 }
312
313 rust_library {
314 name: "librust_available_exclude",
315 crate_name: "rust_available_exclude",
316 srcs: ["lib.rs"],
317 vendor_available: true,
318 exclude_from_vendor_snapshot: true,
319 }
Ivan Lozano1921e802021-05-20 13:39:16 -0400320 `
321
322 mockFS := map[string][]byte{
323 "framework/Android.bp": []byte(frameworkBp),
324 "framework/include.rs": nil,
325 "framework/exclude.rs": nil,
326 }
327
328 ctx := testRustVndkFs(t, "", mockFS)
329
330 // Test an include and exclude framework module.
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400331 cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false, sharedVendorVariant)
332 cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true, sharedVendorVariant)
333 cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true, sharedVendorVariant)
334
335 cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_include", false, rlibVendorVariant)
336 cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_exclude", true, rlibVendorVariant)
337 cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_available_exclude", true, rlibVendorVariant)
Ivan Lozano1921e802021-05-20 13:39:16 -0400338
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400339 cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_include", false, rlibDylibStdVendorVariant)
340 cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_exclude", true, rlibDylibStdVendorVariant)
341 cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_available_exclude", true, rlibDylibStdVendorVariant)
342
343 cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_include", false, dylibVendorVariant)
344 cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_exclude", true, dylibVendorVariant)
345 cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_available_exclude", true, dylibVendorVariant)
346
Ivan Lozano1921e802021-05-20 13:39:16 -0400347 // Verify the content of the vendor snapshot.
348
349 snapshotDir := "vendor-snapshot"
350 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
351 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
352
353 var includeJsonFiles []string
354 var excludeJsonFiles []string
355
356 for _, arch := range [][]string{
357 []string{"arm64", "armv8-a"},
358 []string{"arm", "armv7-a-neon"},
359 } {
360 archType := arch[0]
361 archVariant := arch[1]
362 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
363
364 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
365 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400366
367 rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_dylib-std", archType, archVariant)
368 rlibRlibStdVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant)
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400369 rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400370 dylibVariant := fmt.Sprintf("android_vendor.29_%s_%s_dylib", archType, archVariant)
371 dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
Ivan Lozano1921e802021-05-20 13:39:16 -0400372
373 // Included modules
374 cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
375 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400376 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librust_include", "librust_include.rlib", rlibDir, rlibVariant)
377 includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librust_include.rlib.json"))
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400378 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librust_include", "librust_include.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
379 includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librust_include.rlib-std.rlib.json"))
380 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librust_include", "librust_include.dylib.so", dylibDir, dylibVariant)
381 includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librust_include.dylib.so.json"))
Ivan Lozano1921e802021-05-20 13:39:16 -0400382
383 // Excluded modules
384 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
385 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
386 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
387 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400388 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_exclude", "librust_exclude.rlib", rlibDir, rlibVariant)
389 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librust_exclude.rlib.json"))
390 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_available_exclude", "librust_available_exclude.rlib", rlibDir, rlibVariant)
391 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librust_available_exclude.rlib.json"))
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400392 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_available_exclude", "librust_available_exclude.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
393 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librust_available_exclude.rlib.rlib-std.json"))
394 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_exclude", "librust_exclude.dylib.so", dylibDir, dylibVariant)
395 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(dylibDir, "librust_exclude.dylib.so.json"))
396 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_available_exclude", "librust_available_exclude.dylib.so", dylibDir, dylibVariant)
397 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(dylibDir, "librust_available_exclude.dylib.so.json"))
Ivan Lozano1921e802021-05-20 13:39:16 -0400398 }
399
400 // Verify that each json file for an included module has a rule.
401 for _, jsonFile := range includeJsonFiles {
402 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
403 t.Errorf("include json file %q not found", jsonFile)
404 }
405 }
406
407 // Verify that each json file for an excluded module has no rule.
408 for _, jsonFile := range excludeJsonFiles {
409 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
410 t.Errorf("exclude json file %q found", jsonFile)
411 }
412 }
413}
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400414
415func TestVendorSnapshotUse(t *testing.T) {
416 frameworkBp := `
417 cc_library {
418 name: "libvndk",
419 vendor_available: true,
420 product_available: true,
421 vndk: {
422 enabled: true,
423 },
424 nocrt: true,
425 }
426
427 cc_library {
428 name: "libvendor",
429 vendor: true,
430 nocrt: true,
431 no_libcrt: true,
432 stl: "none",
433 system_shared_libs: [],
434 }
435
436 cc_library {
437 name: "libvendor_available",
438 vendor_available: true,
439 nocrt: true,
440 no_libcrt: true,
441 stl: "none",
442 system_shared_libs: [],
443 }
444
445 cc_library {
446 name: "lib32",
447 vendor: true,
448 nocrt: true,
449 no_libcrt: true,
450 stl: "none",
451 system_shared_libs: [],
452 compile_multilib: "32",
453 }
454
455 cc_library {
456 name: "lib64",
457 vendor: true,
458 nocrt: true,
459 no_libcrt: true,
460 stl: "none",
461 system_shared_libs: [],
462 compile_multilib: "64",
463 }
464
465 rust_binary {
466 name: "bin",
467 vendor: true,
468 srcs: ["bin.rs"],
469 }
470
471 rust_binary {
472 name: "bin32",
473 vendor: true,
474 compile_multilib: "32",
475 srcs: ["bin.rs"],
476 }
Justin Yun24b246a2023-03-16 10:36:16 +0900477
478 rust_library {
479 name: "librust_vendor_available",
480 crate_name: "rust_vendor",
481 vendor_available: true,
482 srcs: ["client.rs"],
483 }
484
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400485`
486
487 vndkBp := `
488 vndk_prebuilt_shared {
489 name: "libvndk",
490 version: "30",
491 target_arch: "arm64",
492 vendor_available: true,
493 product_available: true,
494 vndk: {
495 enabled: true,
496 },
497 arch: {
498 arm64: {
499 srcs: ["libvndk.so"],
500 export_include_dirs: ["include/libvndk"],
501 },
502 arm: {
503 srcs: ["libvndk.so"],
504 export_include_dirs: ["include/libvndk"],
505 },
506 },
507 }
508
509 // old snapshot module which has to be ignored
510 vndk_prebuilt_shared {
511 name: "libvndk",
512 version: "26",
513 target_arch: "arm64",
514 vendor_available: true,
515 product_available: true,
516 vndk: {
517 enabled: true,
518 },
519 arch: {
520 arm64: {
521 srcs: ["libvndk.so"],
522 export_include_dirs: ["include/libvndk"],
523 },
524 arm: {
525 srcs: ["libvndk.so"],
526 export_include_dirs: ["include/libvndk"],
527 },
528 },
529 }
530
531 // different arch snapshot which has to be ignored
532 vndk_prebuilt_shared {
533 name: "libvndk",
534 version: "30",
535 target_arch: "arm",
536 vendor_available: true,
537 product_available: true,
538 vndk: {
539 enabled: true,
540 },
541 arch: {
542 arm: {
543 srcs: ["libvndk.so"],
544 export_include_dirs: ["include/libvndk"],
545 },
546 },
547 }
548`
549
550 vendorProprietaryBp := `
551 cc_library {
552 name: "libvendor_without_snapshot",
553 vendor: true,
554 nocrt: true,
555 no_libcrt: true,
556 stl: "none",
557 system_shared_libs: [],
558 }
559
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400560 rust_ffi_shared {
561 name: "libclient",
562 crate_name: "client",
563 vendor: true,
564 shared_libs: ["libvndk", "libvendor_available"],
565 static_libs: ["libvendor", "libvendor_without_snapshot"],
566 rustlibs: ["librust_vendor_available"],
567 arch: {
568 arm64: {
569 shared_libs: ["lib64"],
570 },
571 arm: {
572 shared_libs: ["lib32"],
573 },
574 },
575 srcs: ["client.rs"],
576 }
577
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400578 rust_library {
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400579 name: "libclient_rust",
580 crate_name: "client_rust",
581 vendor: true,
582 shared_libs: ["libvndk", "libvendor_available"],
583 static_libs: ["libvendor", "libvendor_without_snapshot"],
584 rustlibs: ["librust_vendor_available"],
585 arch: {
586 arm64: {
587 shared_libs: ["lib64"],
588 },
589 arm: {
590 shared_libs: ["lib32"],
591 },
592 },
593 srcs: ["client.rs"],
594 }
595
596 rust_binary {
597 name: "bin_without_snapshot",
598 vendor: true,
599 static_libs: ["libvndk"],
600 srcs: ["bin.rs"],
601 rustlibs: ["librust_vendor_available"],
602 }
603
604 vendor_snapshot {
605 name: "vendor_snapshot",
606 version: "30",
607 arch: {
608 arm64: {
609 vndk_libs: [
610 "libvndk",
611 ],
612 static_libs: [
613 "libvendor",
614 "libvndk",
Colin Cross4c4c1be2022-02-10 11:41:18 -0800615 "libclang_rt.builtins",
Ivan Lozano62cd0382021-11-01 10:27:54 -0400616 "note_memtag_heap_sync",
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400617 ],
618 shared_libs: [
619 "libvendor_available",
620 "lib64",
621 ],
622 rlibs: [
623 "libstd",
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400624 "librust_vendor_available",
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400625 "librust_vendor_available.rlib-std"
626 ],
627 dylibs: [
628 "libstd",
629 "librust_vendor_available",
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400630 ],
631 binaries: [
632 "bin",
633 ],
634 objects: [
635 "crtend_so",
636 "crtbegin_so",
637 "crtbegin_dynamic",
638 "crtend_android"
639 ],
640 },
641 arm: {
642 vndk_libs: [
643 "libvndk",
644 ],
645 static_libs: [
646 "libvendor",
647 "libvndk",
Colin Cross4c4c1be2022-02-10 11:41:18 -0800648 "libclang_rt.builtins",
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400649 ],
650 shared_libs: [
651 "libvendor_available",
652 "lib32",
653 ],
654 rlibs: [
655 "libstd",
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400656 "librust_vendor_available",
657 ],
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400658 dylibs: [
659 "libstd",
660 "librust_vendor_available",
661 ],
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400662 binaries: [
663 "bin32",
664 ],
665 objects: [
666 "crtend_so",
667 "crtbegin_so",
668 "crtbegin_dynamic",
669 "crtend_android"
670 ],
671
672 },
673 }
674 }
675
676 vendor_snapshot_object {
677 name: "crtend_so",
678 version: "30",
679 target_arch: "arm64",
680 vendor: true,
681 stl: "none",
682 crt: true,
683 arch: {
684 arm64: {
685 src: "crtend_so.o",
686 },
687 arm: {
688 src: "crtend_so.o",
689 },
690 },
691 }
692
693 vendor_snapshot_object {
694 name: "crtbegin_so",
695 version: "30",
696 target_arch: "arm64",
697 vendor: true,
698 stl: "none",
699 crt: true,
700 arch: {
701 arm64: {
702 src: "crtbegin_so.o",
703 },
704 arm: {
705 src: "crtbegin_so.o",
706 },
707 },
708 }
709
710 vendor_snapshot_rlib {
711 name: "libstd",
712 version: "30",
713 target_arch: "arm64",
714 vendor: true,
715 sysroot: true,
716 arch: {
717 arm64: {
718 src: "libstd.rlib",
719 },
720 arm: {
721 src: "libstd.rlib",
722 },
723 },
724 }
725
726 vendor_snapshot_rlib {
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400727 name: "librust_vendor_available",
728 version: "30",
729 target_arch: "arm64",
730 vendor: true,
731 arch: {
732 arm64: {
733 src: "librust_vendor_available.rlib",
734 },
735 arm: {
736 src: "librust_vendor_available.rlib",
737 },
738 },
739 }
740
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400741 vendor_snapshot_rlib {
742 name: "librust_vendor_available.rlib-std",
743 version: "30",
744 target_arch: "arm64",
745 vendor: true,
746 arch: {
747 arm64: {
748 src: "librust_vendor_available.rlib-std.rlib",
749 },
750 arm: {
751 src: "librust_vendor_available.rlib-std.rlib",
752 },
753 },
754 }
755
756 vendor_snapshot_dylib {
757 name: "libstd",
758 version: "30",
759 target_arch: "arm64",
760 vendor: true,
761 sysroot: true,
762 arch: {
763 arm64: {
764 src: "libstd.dylib.so",
765 },
766 arm: {
767 src: "libstd.dylib.so",
768 },
769 },
770 }
771
772 vendor_snapshot_dylib {
773 name: "librust_vendor_available",
774 version: "30",
775 target_arch: "arm64",
776 vendor: true,
777 arch: {
778 arm64: {
779 src: "librust_vendor_available.dylib.so",
780 },
781 arm: {
782 src: "librust_vendor_available.dylib.so",
783 },
784 },
785 }
786
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400787 vendor_snapshot_object {
788 name: "crtend_android",
789 version: "30",
790 target_arch: "arm64",
791 vendor: true,
792 stl: "none",
793 crt: true,
794 arch: {
795 arm64: {
796 src: "crtend_so.o",
797 },
798 arm: {
799 src: "crtend_so.o",
800 },
801 },
802 }
803
804 vendor_snapshot_object {
805 name: "crtbegin_dynamic",
806 version: "30",
807 target_arch: "arm64",
808 vendor: true,
809 stl: "none",
810 crt: true,
811 arch: {
812 arm64: {
813 src: "crtbegin_so.o",
814 },
815 arm: {
816 src: "crtbegin_so.o",
817 },
818 },
819 }
820
821 vendor_snapshot_static {
822 name: "libvndk",
823 version: "30",
824 target_arch: "arm64",
825 compile_multilib: "both",
826 vendor: true,
827 arch: {
828 arm64: {
829 src: "libvndk.a",
830 },
831 arm: {
832 src: "libvndk.a",
833 },
834 },
835 shared_libs: ["libvndk"],
836 export_shared_lib_headers: ["libvndk"],
837 }
838
839 vendor_snapshot_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800840 name: "libclang_rt.builtins",
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400841 version: "30",
842 target_arch: "arm64",
843 vendor: true,
844 arch: {
845 arm: {
846 src: "libclang_rt.builtins-arm-android.a",
847 },
Colin Cross4c4c1be2022-02-10 11:41:18 -0800848 arm64: {
849 src: "libclang_rt.builtins-aarch64-android.a",
850 },
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400851 },
852 }
853
854 vendor_snapshot_shared {
855 name: "lib32",
856 version: "30",
857 target_arch: "arm64",
858 compile_multilib: "32",
859 vendor: true,
860 arch: {
861 arm: {
862 src: "lib32.so",
863 },
864 },
865 }
866
867 vendor_snapshot_shared {
868 name: "lib64",
869 version: "30",
870 target_arch: "arm64",
871 compile_multilib: "64",
872 vendor: true,
873 arch: {
874 arm64: {
875 src: "lib64.so",
876 },
877 },
878 }
879 vendor_snapshot_shared {
880 name: "liblog",
881 version: "30",
882 target_arch: "arm64",
883 compile_multilib: "64",
884 vendor: true,
885 arch: {
886 arm64: {
887 src: "liblog.so",
888 },
889 },
890 }
891
892 vendor_snapshot_static {
893 name: "libvendor",
894 version: "30",
895 target_arch: "arm64",
896 compile_multilib: "both",
897 vendor: true,
898 arch: {
899 arm64: {
900 src: "libvendor.a",
901 export_include_dirs: ["include/libvendor"],
902 },
903 arm: {
904 src: "libvendor.a",
905 export_include_dirs: ["include/libvendor"],
906 },
907 },
908 }
909
910 vendor_snapshot_shared {
911 name: "libvendor_available",
912 version: "30",
913 target_arch: "arm64",
914 compile_multilib: "both",
915 vendor: true,
916 arch: {
917 arm64: {
918 src: "libvendor_available.so",
919 export_include_dirs: ["include/libvendor"],
920 },
921 arm: {
922 src: "libvendor_available.so",
923 export_include_dirs: ["include/libvendor"],
924 },
925 },
926 }
927
928 vendor_snapshot_binary {
929 name: "bin",
930 version: "30",
931 target_arch: "arm64",
932 compile_multilib: "64",
933 vendor: true,
934 arch: {
935 arm64: {
936 src: "bin",
937 },
938 },
939 }
940
941 vendor_snapshot_binary {
942 name: "bin32",
943 version: "30",
944 target_arch: "arm64",
945 compile_multilib: "32",
946 vendor: true,
947 arch: {
948 arm: {
949 src: "bin32",
950 },
951 },
952 }
953
Ivan Lozano62cd0382021-11-01 10:27:54 -0400954 // Test sanitizers use the snapshot libraries
955 rust_binary {
956 name: "memtag_binary",
957 srcs: ["vendor/bin.rs"],
958 vendor: true,
959 compile_multilib: "64",
960 sanitize: {
961 memtag_heap: true,
962 diag: {
963 memtag_heap: true,
964 }
965 },
966 }
967
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400968 // old snapshot module which has to be ignored
969 vendor_snapshot_binary {
970 name: "bin",
971 version: "26",
972 target_arch: "arm64",
973 compile_multilib: "first",
974 vendor: true,
975 arch: {
976 arm64: {
977 src: "bin",
978 },
979 },
980 }
981
982 // different arch snapshot which has to be ignored
983 vendor_snapshot_binary {
984 name: "bin",
985 version: "30",
986 target_arch: "arm",
987 compile_multilib: "first",
988 vendor: true,
989 arch: {
990 arm64: {
991 src: "bin",
992 },
993 },
994 }
Ivan Lozano62cd0382021-11-01 10:27:54 -0400995
996 vendor_snapshot_static {
997 name: "note_memtag_heap_sync",
998 vendor: true,
999 target_arch: "arm64",
1000 version: "30",
1001 arch: {
1002 arm64: {
1003 src: "note_memtag_heap_sync.a",
1004 },
1005 },
1006 }
1007
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001008`
1009
1010 mockFS := android.MockFS{
1011 "framework/Android.bp": []byte(frameworkBp),
1012 "framework/bin.rs": nil,
Ivan Lozano62cd0382021-11-01 10:27:54 -04001013 "note_memtag_heap_sync.a": nil,
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001014 "vendor/Android.bp": []byte(vendorProprietaryBp),
1015 "vendor/bin": nil,
1016 "vendor/bin32": nil,
1017 "vendor/bin.rs": nil,
1018 "vendor/client.rs": nil,
1019 "vendor/include/libvndk/a.h": nil,
1020 "vendor/include/libvendor/b.h": nil,
1021 "vendor/libvndk.a": nil,
1022 "vendor/libvendor.a": nil,
1023 "vendor/libvendor.so": nil,
1024 "vendor/lib32.so": nil,
1025 "vendor/lib64.so": nil,
1026 "vendor/liblog.so": nil,
1027 "vendor/libstd.rlib": nil,
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001028 "vendor/librust_vendor_available.rlib": nil,
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001029 "vendor/librust_vendor_available.rlib-std.rlib": nil,
1030 "vendor/libstd.dylib.so": nil,
1031 "vendor/librust_vendor_available.dylib.so": nil,
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001032 "vendor/crtbegin_so.o": nil,
1033 "vendor/crtend_so.o": nil,
1034 "vendor/libclang_rt.builtins-aarch64-android.a": nil,
1035 "vendor/libclang_rt.builtins-arm-android.a": nil,
1036 "vndk/Android.bp": []byte(vndkBp),
1037 "vndk/include/libvndk/a.h": nil,
1038 "vndk/libvndk.so": nil,
1039 }
1040
1041 sharedVariant := "android_vendor.30_arm64_armv8-a_shared"
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001042 rlibVariant := "android_vendor.30_arm64_armv8-a_rlib_dylib-std"
1043 rlibRlibStdVariant := "android_vendor.30_arm64_armv8-a_rlib_rlib-std"
1044 dylibVariant := "android_vendor.30_arm64_armv8-a_dylib"
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001045 staticVariant := "android_vendor.30_arm64_armv8-a_static"
1046 binaryVariant := "android_vendor.30_arm64_armv8-a"
1047
1048 shared32Variant := "android_vendor.30_arm_armv7-a-neon_shared"
1049 binary32Variant := "android_vendor.30_arm_armv7-a-neon"
1050
1051 ctx := testRustVndkFsVersions(t, "", mockFS, "30", "current", "31")
1052
1053 // libclient uses libvndk.vndk.30.arm64, libvendor.vendor_static.30.arm64, libvendor_without_snapshot
Colin Cross004bd3f2023-10-02 11:39:17 -07001054 libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("rustc").Args["linkFlags"]
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001055 for _, input := range [][]string{
1056 []string{sharedVariant, "libvndk.vndk.30.arm64"},
1057 []string{staticVariant, "libvendor.vendor_static.30.arm64"},
1058 []string{staticVariant, "libvendor_without_snapshot"},
1059 } {
1060 outputPaths := cc.GetOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */)
1061 if !strings.Contains(libclientLdFlags, outputPaths[0].String()) {
1062 t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags)
1063 }
1064 }
1065
Cole Faustb6e6f992023-08-17 17:42:26 -07001066 libclientAndroidMkSharedLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).transitiveAndroidMkSharedLibs.ToList()
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001067 if g, w := libclientAndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "lib64", "liblog.vendor", "libc.vendor", "libm.vendor", "libdl.vendor"}; !reflect.DeepEqual(g, w) {
1068 t.Errorf("wanted libclient AndroidMkSharedLibs %q, got %q", w, g)
1069 }
1070
1071 libclientAndroidMkStaticLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkStaticLibs
Colin Cross4c4c1be2022-02-10 11:41:18 -08001072 if g, w := libclientAndroidMkStaticLibs, []string{"libvendor", "libvendor_without_snapshot", "libclang_rt.builtins.vendor"}; !reflect.DeepEqual(g, w) {
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001073 t.Errorf("wanted libclient AndroidMkStaticLibs %q, got %q", w, g)
1074 }
1075
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001076 libclientAndroidMkDylibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkDylibs
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001077 if g, w := libclientAndroidMkDylibs, []string{"librust_vendor_available.vendor", "libstd.vendor"}; !reflect.DeepEqual(g, w) {
1078 t.Errorf("wanted libclient libclientAndroidMkDylibs %q, got %q", w, libclientAndroidMkDylibs)
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001079 }
1080
Cole Faustb6e6f992023-08-17 17:42:26 -07001081 libclient32AndroidMkSharedLibs := ctx.ModuleForTests("libclient", shared32Variant).Module().(*Module).transitiveAndroidMkSharedLibs.ToList()
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001082 if g, w := libclient32AndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "lib32", "liblog.vendor", "libc.vendor", "libm.vendor", "libdl.vendor"}; !reflect.DeepEqual(g, w) {
1083 t.Errorf("wanted libclient32 AndroidMkSharedLibs %q, got %q", w, g)
1084 }
1085
1086 libclientRustAndroidMkRlibs := ctx.ModuleForTests("libclient_rust", rlibVariant).Module().(*Module).Properties.AndroidMkRlibs
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001087 if g, w := libclientRustAndroidMkRlibs, []string{"librust_vendor_available.vendor"}; !reflect.DeepEqual(g, w) {
1088 t.Errorf("wanted rlib libclient libclientAndroidMkRlibs %q, got %q", w, g)
1089 }
1090
1091 libclientRlibStdRustAndroidMkRlibs := ctx.ModuleForTests("libclient_rust", rlibRlibStdVariant).Module().(*Module).Properties.AndroidMkRlibs
1092 if g, w := libclientRlibStdRustAndroidMkRlibs, []string{"librust_vendor_available.vendor.rlib-std", "libstd.vendor"}; !reflect.DeepEqual(g, w) {
1093 t.Errorf("wanted rlib libclient libclientAndroidMkRlibs %q, got %q", w, g)
1094 }
1095
1096 libclientRustDylibAndroidMkDylibs := ctx.ModuleForTests("libclient_rust", dylibVariant).Module().(*Module).Properties.AndroidMkDylibs
1097 if g, w := libclientRustDylibAndroidMkDylibs, []string{"librust_vendor_available.vendor", "libstd.vendor"}; !reflect.DeepEqual(g, w) {
1098 t.Errorf("wanted dylib libclient libclientRustDylibAndroidMkDylibs %q, got %q", w, g)
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001099 }
1100
Justin Yun24b246a2023-03-16 10:36:16 +09001101 // rust vendor snapshot must have ".vendor" suffix in AndroidMk
1102 librustVendorAvailableSnapshotModule := ctx.ModuleForTests("librust_vendor_available.vendor_rlib.30.arm64", rlibVariant).Module()
1103 librustVendorSnapshotMkName := android.AndroidMkEntriesForTest(t, ctx, librustVendorAvailableSnapshotModule)[0].EntryMap["LOCAL_MODULE"][0]
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001104 expectedRustVendorSnapshotName := "librust_vendor_available.vendor"
Justin Yun24b246a2023-03-16 10:36:16 +09001105 if librustVendorSnapshotMkName != expectedRustVendorSnapshotName {
1106 t.Errorf("Unexpected rust vendor snapshot name in AndroidMk: %q, expected: %q\n", librustVendorSnapshotMkName, expectedRustVendorSnapshotName)
1107 }
1108
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001109 librustVendorAvailableDylibSnapshotModule := ctx.ModuleForTests("librust_vendor_available.vendor_dylib.30.arm64", dylibVariant).Module()
1110 librustVendorSnapshotDylibMkName := android.AndroidMkEntriesForTest(t, ctx, librustVendorAvailableDylibSnapshotModule)[0].EntryMap["LOCAL_MODULE"][0]
1111 expectedRustVendorDylibSnapshotName := "librust_vendor_available.vendor"
1112 if librustVendorSnapshotDylibMkName != expectedRustVendorDylibSnapshotName {
1113 t.Errorf("Unexpected rust vendor snapshot name in AndroidMk: %q, expected: %q\n", librustVendorSnapshotDylibMkName, expectedRustVendorDylibSnapshotName)
1114 }
1115
Justin Yun24b246a2023-03-16 10:36:16 +09001116 rustVendorBinModule := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Module()
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001117 rustVendorBinMkDylibName := android.AndroidMkEntriesForTest(t, ctx, rustVendorBinModule)[0].EntryMap["LOCAL_DYLIB_LIBRARIES"][0]
1118 if rustVendorBinMkDylibName != expectedRustVendorSnapshotName {
1119 t.Errorf("Unexpected rust rlib name in AndroidMk: %q, expected: %q\n", rustVendorBinMkDylibName, expectedRustVendorSnapshotName)
Justin Yun24b246a2023-03-16 10:36:16 +09001120 }
1121
Colin Cross004bd3f2023-10-02 11:39:17 -07001122 binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("rustc").Args["linkFlags"]
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001123 libVndkStaticOutputPaths := cc.GetOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.30.arm64"})
1124 if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) {
1125 t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v",
1126 libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags)
1127 }
1128
1129 // bin is installed by bin.vendor_binary.30.arm64
1130 ctx.ModuleForTests("bin.vendor_binary.30.arm64", binaryVariant).Output("bin")
1131
1132 // bin32 is installed by bin32.vendor_binary.30.arm64
1133 ctx.ModuleForTests("bin32.vendor_binary.30.arm64", binary32Variant).Output("bin32")
1134
1135 // bin_without_snapshot is installed by bin_without_snapshot
1136 ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot")
1137
1138 // libvendor, libvendor_available and bin don't have vendor.30 variant
1139 libvendorVariants := ctx.ModuleVariantsForTests("libvendor")
1140 if android.InList(sharedVariant, libvendorVariants) {
1141 t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant)
1142 }
1143
1144 libvendorAvailableVariants := ctx.ModuleVariantsForTests("libvendor_available")
1145 if android.InList(sharedVariant, libvendorAvailableVariants) {
1146 t.Errorf("libvendor_available must not have variant %#v, but it does", sharedVariant)
1147 }
1148
1149 binVariants := ctx.ModuleVariantsForTests("bin")
1150 if android.InList(binaryVariant, binVariants) {
1151 t.Errorf("bin must not have variant %#v, but it does", sharedVariant)
1152 }
Ivan Lozano62cd0382021-11-01 10:27:54 -04001153
1154 memtagStaticLibs := ctx.ModuleForTests("memtag_binary", "android_vendor.30_arm64_armv8-a").Module().(*Module).Properties.AndroidMkStaticLibs
Colin Cross4c4c1be2022-02-10 11:41:18 -08001155 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 -04001156 t.Errorf("wanted memtag_binary AndroidMkStaticLibs %q, got %q", w, g)
1157 }
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001158}
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001159
1160func TestRecoverySnapshotCapture(t *testing.T) {
1161 bp := `
1162 rust_ffi {
1163 name: "librecovery",
1164 recovery: true,
1165 srcs: ["foo.rs"],
1166 crate_name: "recovery",
1167 }
1168
1169 rust_ffi {
1170 name: "librecovery_available",
1171 recovery_available: true,
1172 srcs: ["foo.rs"],
1173 crate_name: "recovery_available",
1174 }
1175
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001176 rust_library {
1177 name: "librecovery_rustlib",
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001178 recovery: true,
1179 srcs: ["foo.rs"],
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001180 crate_name: "recovery_rustlib",
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001181 }
1182
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001183 rust_library {
1184 name: "librecovery_available_rustlib",
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001185 recovery_available: true,
1186 srcs: ["foo.rs"],
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001187 crate_name: "recovery_available_rustlib",
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001188 }
1189
1190 rust_binary {
1191 name: "recovery_bin",
1192 recovery: true,
1193 srcs: ["foo.rs"],
1194 }
1195
1196 rust_binary {
1197 name: "recovery_available_bin",
1198 recovery_available: true,
1199 srcs: ["foo.rs"],
1200 }
1201
1202`
1203 // Check Recovery snapshot output.
1204
1205 ctx := testRustRecoveryFsVersions(t, bp, rustMockedFiles, "", "29", "current")
1206 snapshotDir := "recovery-snapshot"
1207 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
1208 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1209
1210 var jsonFiles []string
1211
1212 for _, arch := range [][]string{
1213 []string{"arm64", "armv8-a"},
1214 } {
1215 archType := arch[0]
1216 archVariant := arch[1]
1217 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1218
1219 // For shared libraries, all recovery:true and recovery_available modules are captured.
1220 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1221 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1222 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1223 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
1224 jsonFiles = append(jsonFiles,
1225 filepath.Join(sharedDir, "librecovery.so.json"),
1226 filepath.Join(sharedDir, "librecovery_available.so.json"))
1227
1228 // For static libraries, all recovery:true and recovery_available modules are captured.
1229 staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
1230 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
1231 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
1232 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
1233 jsonFiles = append(jsonFiles,
1234 filepath.Join(staticDir, "librecovery.a.json"),
1235 filepath.Join(staticDir, "librecovery_available.a.json"))
1236
1237 // For rlib libraries, all recovery:true and recovery_available modules are captured.
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001238 rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_dylib-std", archType, archVariant)
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001239 rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001240 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib", rlibDir, rlibVariant)
1241 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.rlib", rlibDir, rlibVariant)
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001242 jsonFiles = append(jsonFiles,
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001243 filepath.Join(rlibDir, "librecovery_rustlib.rlib.json"),
1244 filepath.Join(rlibDir, "librecovery_available_rustlib.rlib.json"))
1245
1246 rlibRlibStdVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant)
1247 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
1248 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
1249 jsonFiles = append(jsonFiles,
1250 filepath.Join(rlibDir, "librecovery_rustlib.rlib-std.rlib.json"),
1251 filepath.Join(rlibDir, "librecovery_available_rustlib.rlib-std.rlib.json"))
1252
1253 // For dylib libraries, all recovery:true and recovery_available modules are captured.
1254 dylibVariant := fmt.Sprintf("android_recovery_%s_%s_dylib", archType, archVariant)
1255 dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
1256 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.dylib.so", dylibDir, dylibVariant)
1257 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.dylib.so", dylibDir, dylibVariant)
1258 jsonFiles = append(jsonFiles,
1259 filepath.Join(dylibDir, "librecovery_rustlib.dylib.so.json"),
1260 filepath.Join(dylibDir, "librecovery_available_rustlib.dylib.so.json"))
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001261
1262 // For binary executables, all recovery:true and recovery_available modules are captured.
1263 if archType == "arm64" {
1264 binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1265 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
1266 cc.CheckSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
1267 cc.CheckSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
1268 jsonFiles = append(jsonFiles,
1269 filepath.Join(binaryDir, "recovery_bin.json"),
1270 filepath.Join(binaryDir, "recovery_available_bin.json"))
1271 }
1272 }
1273
1274 for _, jsonFile := range jsonFiles {
1275 // verify all json files exist
1276 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1277 t.Errorf("%q expected but not found", jsonFile)
1278 }
1279 }
1280}
1281
1282func TestRecoverySnapshotExclude(t *testing.T) {
1283 // This test verifies that the exclude_from_recovery_snapshot property
1284 // makes its way from the Android.bp source file into the module data
1285 // structure. It also verifies that modules are correctly included or
1286 // excluded in the recovery snapshot based on their path (framework or
1287 // vendor) and the exclude_from_recovery_snapshot property.
1288
1289 frameworkBp := `
1290 rust_ffi_shared {
1291 name: "libinclude",
1292 srcs: ["src/include.rs"],
1293 recovery_available: true,
1294 crate_name: "include",
1295 }
1296 rust_ffi_shared {
1297 name: "libexclude",
1298 srcs: ["src/exclude.rs"],
1299 recovery: true,
1300 exclude_from_recovery_snapshot: true,
1301 crate_name: "exclude",
1302 }
1303 rust_ffi_shared {
1304 name: "libavailable_exclude",
1305 srcs: ["src/exclude.rs"],
1306 recovery_available: true,
1307 exclude_from_recovery_snapshot: true,
1308 crate_name: "available_exclude",
1309 }
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001310 rust_library {
1311 name: "libinclude_rustlib",
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001312 srcs: ["src/include.rs"],
1313 recovery_available: true,
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001314 crate_name: "include_rustlib",
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001315 }
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001316 rust_library {
1317 name: "libexclude_rustlib",
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001318 srcs: ["src/exclude.rs"],
1319 recovery: true,
1320 exclude_from_recovery_snapshot: true,
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001321 crate_name: "exclude_rustlib",
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001322 }
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001323 rust_library {
1324 name: "libavailable_exclude_rustlib",
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001325 srcs: ["src/exclude.rs"],
1326 recovery_available: true,
1327 exclude_from_recovery_snapshot: true,
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001328 crate_name: "available_exclude_rustlib",
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001329 }
1330 `
1331
1332 vendorProprietaryBp := `
1333 rust_ffi_shared {
1334 name: "librecovery",
1335 srcs: ["recovery.rs"],
1336 recovery: true,
1337 crate_name: "recovery",
1338 }
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001339 rust_library {
1340 name: "librecovery_rustlib",
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001341 srcs: ["recovery.rs"],
1342 recovery: true,
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001343 crate_name: "recovery_rustlib",
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001344 }
1345 `
1346
1347 mockFS := map[string][]byte{
1348 "framework/Android.bp": []byte(frameworkBp),
1349 "framework/include.rs": nil,
1350 "framework/exclude.rs": nil,
1351 "device/Android.bp": []byte(vendorProprietaryBp),
1352 "device/recovery.rs": nil,
1353 }
1354
1355 ctx := testRustRecoveryFsVersions(t, "", mockFS, "", "29", "current")
1356
1357 // Test an include and exclude framework module.
1358 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false, sharedRecoveryVariant)
1359 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true, sharedRecoveryVariant)
1360 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true, sharedRecoveryVariant)
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001361
1362 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude_rustlib", false, rlibRecoveryVariant)
1363 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude_rustlib", true, rlibRecoveryVariant)
1364 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude_rustlib", true, rlibRlibStdRecoveryVariant)
1365
1366 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude_rustlib", false, rlibRlibStdRecoveryVariant)
1367 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude_rustlib", true, rlibRlibStdRecoveryVariant)
1368 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude_rustlib", true, rlibRlibStdRecoveryVariant)
1369
1370 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude_rustlib", false, dylibRecoveryVariant)
1371 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude_rustlib", true, dylibRecoveryVariant)
1372 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude_rustlib", true, dylibRecoveryVariant)
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001373
1374 // A recovery module is excluded, but by its path not the exclude_from_recovery_snapshot property
1375 // ('device/' and 'vendor/' are default excluded). See snapshot/recovery_snapshot.go for more detail.
1376 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false, sharedRecoveryVariant)
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001377 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery_rustlib", false, rlibRecoveryVariant)
1378 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery_rustlib", false, rlibRlibStdRecoveryVariant)
1379 cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery_rustlib", false, dylibRecoveryVariant)
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001380
1381 // Verify the content of the recovery snapshot.
1382
1383 snapshotDir := "recovery-snapshot"
1384 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
1385 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1386
1387 var includeJsonFiles []string
1388 var excludeJsonFiles []string
1389
1390 for _, arch := range [][]string{
1391 []string{"arm64", "armv8-a"},
1392 } {
1393 archType := arch[0]
1394 archVariant := arch[1]
1395 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1396
1397 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001398 rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_dylib-std", archType, archVariant)
1399 rlibRlibStdVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant)
1400 dylibVariant := fmt.Sprintf("android_recovery_%s_%s_dylib", archType, archVariant)
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001401 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1402 rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001403 dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001404
1405 // Included modules
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001406
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001407 cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
1408 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001409 cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude_rustlib", "libinclude_rustlib.rlib", rlibDir, rlibVariant)
1410 includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "libinclude_rustlib.rlib.json"))
1411 cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude_rustlib", "libinclude_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
1412 includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "libinclude_rustlib.rlib-std.rlib.json"))
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001413
1414 // Excluded modules
1415 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
1416 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
1417 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1418 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1419 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
1420 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001421
1422 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude_rustlib", "libexclude_rustlib.rlib", rlibDir, rlibVariant)
1423 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libexclude_rustlib.rlib.json"))
1424 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib", rlibDir, rlibVariant)
1425 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.rlib.json"))
1426 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude_rustlib", "libavailable_exclude_rustlib.rlib", rlibDir, rlibVariant)
1427 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libavailable_exclude_rustlib.rlib.json"))
1428
1429 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude_rustlib", "libexclude_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
1430 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libexclude_rustlib.rlib-std.rlib.json"))
1431 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
1432 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.rlib-std.rlib.json"))
1433 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude_rustlib", "libavailable_exclude_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
1434 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libavailable_exclude_rustlib.rlib-std.rlib.json"))
1435
1436 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude_rustlib", "libexclude_rustlib.dylib.so", dylibDir, dylibVariant)
1437 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libexclude_rustlib.dylib.so.json"))
1438 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.dylib.so", dylibDir, dylibVariant)
1439 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.dylib.so.json"))
1440 cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude_rustlib", "libavailable_exclude_rustlib.dylib.so", dylibDir, dylibVariant)
1441 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libavailable_exclude_rustlib.dylib.so.json"))
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001442 }
1443
1444 // Verify that each json file for an included module has a rule.
1445 for _, jsonFile := range includeJsonFiles {
1446 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1447 t.Errorf("include json file %q not found", jsonFile)
1448 }
1449 }
1450
1451 // Verify that each json file for an excluded module has no rule.
1452 for _, jsonFile := range excludeJsonFiles {
1453 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1454 t.Errorf("exclude json file %q found", jsonFile)
1455 }
1456 }
1457}
1458
1459func TestRecoverySnapshotDirected(t *testing.T) {
1460 bp := `
1461 rust_ffi_shared {
1462 name: "librecovery",
1463 recovery: true,
1464 crate_name: "recovery",
1465 srcs: ["foo.rs"],
1466 }
1467
1468 rust_ffi_shared {
1469 name: "librecovery_available",
1470 recovery_available: true,
1471 crate_name: "recovery_available",
1472 srcs: ["foo.rs"],
1473 }
1474
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001475 rust_library {
1476 name: "librecovery_rustlib",
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001477 recovery: true,
1478 crate_name: "recovery",
1479 srcs: ["foo.rs"],
1480 }
1481
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001482 rust_library {
1483 name: "librecovery_available_rustlib",
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001484 recovery_available: true,
1485 crate_name: "recovery_available",
1486 srcs: ["foo.rs"],
1487 }
1488
1489 /* TODO: Uncomment when Rust supports the "prefer" property for prebuilts
1490 rust_library_rlib {
1491 name: "libfoo_rlib",
1492 recovery: true,
1493 crate_name: "foo",
1494 }
1495
1496 rust_prebuilt_rlib {
1497 name: "libfoo_rlib",
1498 recovery: true,
1499 prefer: true,
1500 srcs: ["libfoo.rlib"],
1501 crate_name: "foo",
1502 }
1503 */
1504`
1505 ctx := testRustRecoveryFsVersions(t, bp, rustMockedFiles, "current", "29", "current")
1506 ctx.Config().TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
1507 ctx.Config().TestProductVariables.RecoverySnapshotModules["librecovery"] = true
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001508 ctx.Config().TestProductVariables.RecoverySnapshotModules["librecovery_rustlib"] = true
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001509 ctx.Config().TestProductVariables.DirectedRecoverySnapshot = true
1510
1511 // Check recovery snapshot output.
1512 snapshotDir := "recovery-snapshot"
1513 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
1514 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1515
1516 var includeJsonFiles []string
1517
1518 for _, arch := range [][]string{
1519 []string{"arm64", "armv8-a"},
1520 } {
1521 archType := arch[0]
1522 archVariant := arch[1]
1523 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1524
1525 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001526 rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_dylib-std", archType, archVariant)
1527 rlibRlibStdVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant)
1528 dylibVariant := fmt.Sprintf("android_recovery_%s_%s_dylib", archType, archVariant)
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001529 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1530 rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001531 dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001532
1533 // Included modules
1534 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1535 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001536 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib", rlibDir, rlibVariant)
1537 includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.rlib.json"))
1538 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
1539 includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.rlib-std.rlib.json"))
1540 cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.dylib.so", dylibDir, dylibVariant)
1541 includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librecovery_rustlib.dylib.so.json"))
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001542
1543 // TODO: When Rust supports the "prefer" property for prebuilts, perform this check.
1544 /*
1545 // Check that snapshot captures "prefer: true" prebuilt
1546 cc.CheckSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo_rlib", "libfoo_rlib.rlib", rlibDir, rlibVariant)
1547 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo_rlib.rlib.json"))
1548 */
1549
1550 // Excluded modules. Modules not included in the directed recovery snapshot
1551 // are still included as fake modules.
1552 cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
1553 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json"))
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001554 cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.rlib", rlibDir, rlibVariant)
1555 includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_available_rustlib.rlib.json"))
1556 cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
1557 includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_available_rustlib.rlib-std.rlib.json"))
1558 cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.dylib.so", dylibDir, dylibVariant)
1559 includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librecovery_available_rustlib.dylib.so.json"))
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001560 }
1561
1562 // Verify that each json file for an included module has a rule.
1563 for _, jsonFile := range includeJsonFiles {
1564 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1565 t.Errorf("include json file %q not found, %#v", jsonFile, includeJsonFiles)
1566 }
1567 }
1568}