vendor_snapshot_test.go 43 KB

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