bootclasspath_fragment_test.go 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408
  1. // Copyright (C) 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 apex
  15. import (
  16. "fmt"
  17. "path"
  18. "sort"
  19. "strings"
  20. "testing"
  21. "android/soong/android"
  22. "android/soong/dexpreopt"
  23. "android/soong/java"
  24. "github.com/google/blueprint/proptools"
  25. )
  26. // Contains tests for bootclasspath_fragment logic from java/bootclasspath_fragment.go as the ART
  27. // bootclasspath_fragment requires modules from the ART apex.
  28. var prepareForTestWithBootclasspathFragment = android.GroupFixturePreparers(
  29. java.PrepareForTestWithDexpreopt,
  30. PrepareForTestWithApexBuildComponents,
  31. )
  32. // Some additional files needed for the art apex.
  33. var prepareForTestWithArtApex = android.GroupFixturePreparers(
  34. android.FixtureMergeMockFs(android.MockFS{
  35. "com.android.art.avbpubkey": nil,
  36. "com.android.art.pem": nil,
  37. "system/sepolicy/apex/com.android.art-file_contexts": nil,
  38. }),
  39. dexpreopt.FixtureSetBootImageProfiles("art/build/boot/boot-image-profile.txt"),
  40. )
  41. func TestBootclasspathFragments(t *testing.T) {
  42. result := android.GroupFixturePreparers(
  43. prepareForTestWithBootclasspathFragment,
  44. // Configure some libraries in the art bootclasspath_fragment and platform_bootclasspath.
  45. java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo", "platform:bar"),
  46. prepareForTestWithArtApex,
  47. java.PrepareForTestWithJavaSdkLibraryFiles,
  48. java.FixtureWithLastReleaseApis("foo"),
  49. ).RunTestWithBp(t, `
  50. java_sdk_library {
  51. name: "foo",
  52. srcs: ["b.java"],
  53. }
  54. java_library {
  55. name: "bar",
  56. srcs: ["b.java"],
  57. installable: true,
  58. }
  59. apex {
  60. name: "com.android.art",
  61. key: "com.android.art.key",
  62. bootclasspath_fragments: ["art-bootclasspath-fragment"],
  63. updatable: false,
  64. }
  65. apex_key {
  66. name: "com.android.art.key",
  67. public_key: "com.android.art.avbpubkey",
  68. private_key: "com.android.art.pem",
  69. }
  70. java_library {
  71. name: "baz",
  72. apex_available: [
  73. "com.android.art",
  74. ],
  75. srcs: ["b.java"],
  76. compile_dex: true,
  77. }
  78. java_library {
  79. name: "quuz",
  80. apex_available: [
  81. "com.android.art",
  82. ],
  83. srcs: ["b.java"],
  84. compile_dex: true,
  85. }
  86. bootclasspath_fragment {
  87. name: "art-bootclasspath-fragment",
  88. image_name: "art",
  89. // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
  90. contents: ["baz", "quuz"],
  91. apex_available: [
  92. "com.android.art",
  93. ],
  94. hidden_api: {
  95. split_packages: ["*"],
  96. },
  97. }
  98. `,
  99. )
  100. // Make sure that the art-bootclasspath-fragment is using the correct configuration.
  101. checkBootclasspathFragment(t, result, "art-bootclasspath-fragment", "android_common_apex10000",
  102. "com.android.art:baz,com.android.art:quuz", `
  103. dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art
  104. dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat
  105. dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex
  106. dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.art
  107. dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.oat
  108. dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.vdex
  109. dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art
  110. dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat
  111. dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex
  112. dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.art
  113. dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.oat
  114. dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.vdex
  115. `)
  116. }
  117. func TestBootclasspathFragments_FragmentDependency(t *testing.T) {
  118. result := android.GroupFixturePreparers(
  119. prepareForTestWithBootclasspathFragment,
  120. // Configure some libraries in the art bootclasspath_fragment and platform_bootclasspath.
  121. java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"),
  122. java.FixtureConfigureApexBootJars("someapex:foo", "someapex:bar"),
  123. prepareForTestWithArtApex,
  124. java.PrepareForTestWithJavaSdkLibraryFiles,
  125. java.FixtureWithLastReleaseApis("foo", "baz"),
  126. ).RunTestWithBp(t, `
  127. java_sdk_library {
  128. name: "foo",
  129. srcs: ["b.java"],
  130. shared_library: false,
  131. public: {
  132. enabled: true,
  133. },
  134. system: {
  135. enabled: true,
  136. },
  137. }
  138. java_library {
  139. name: "bar",
  140. srcs: ["b.java"],
  141. installable: true,
  142. }
  143. apex {
  144. name: "com.android.art",
  145. key: "com.android.art.key",
  146. bootclasspath_fragments: ["art-bootclasspath-fragment"],
  147. updatable: false,
  148. }
  149. apex_key {
  150. name: "com.android.art.key",
  151. public_key: "com.android.art.avbpubkey",
  152. private_key: "com.android.art.pem",
  153. }
  154. java_sdk_library {
  155. name: "baz",
  156. apex_available: [
  157. "com.android.art",
  158. ],
  159. srcs: ["b.java"],
  160. shared_library: false,
  161. public: {
  162. enabled: true,
  163. },
  164. system: {
  165. enabled: true,
  166. },
  167. test: {
  168. enabled: true,
  169. },
  170. }
  171. java_library {
  172. name: "quuz",
  173. apex_available: [
  174. "com.android.art",
  175. ],
  176. srcs: ["b.java"],
  177. compile_dex: true,
  178. }
  179. bootclasspath_fragment {
  180. name: "art-bootclasspath-fragment",
  181. image_name: "art",
  182. // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
  183. contents: ["baz", "quuz"],
  184. apex_available: [
  185. "com.android.art",
  186. ],
  187. hidden_api: {
  188. split_packages: ["*"],
  189. },
  190. }
  191. bootclasspath_fragment {
  192. name: "other-bootclasspath-fragment",
  193. contents: ["foo", "bar"],
  194. fragments: [
  195. {
  196. apex: "com.android.art",
  197. module: "art-bootclasspath-fragment",
  198. },
  199. ],
  200. hidden_api: {
  201. split_packages: ["*"],
  202. },
  203. }
  204. `,
  205. )
  206. checkAPIScopeStubs := func(message string, info java.HiddenAPIInfo, apiScope *java.HiddenAPIScope, expectedPaths ...string) {
  207. t.Helper()
  208. paths := info.TransitiveStubDexJarsByScope.StubDexJarsForScope(apiScope)
  209. android.AssertPathsRelativeToTopEquals(t, fmt.Sprintf("%s %s", message, apiScope), expectedPaths, paths)
  210. }
  211. // Check stub dex paths exported by art.
  212. artFragment := result.Module("art-bootclasspath-fragment", "android_common")
  213. artInfo := result.ModuleProvider(artFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo)
  214. bazPublicStubs := "out/soong/.intermediates/baz.stubs/android_common/dex/baz.stubs.jar"
  215. bazSystemStubs := "out/soong/.intermediates/baz.stubs.system/android_common/dex/baz.stubs.system.jar"
  216. bazTestStubs := "out/soong/.intermediates/baz.stubs.test/android_common/dex/baz.stubs.test.jar"
  217. checkAPIScopeStubs("art", artInfo, java.PublicHiddenAPIScope, bazPublicStubs)
  218. checkAPIScopeStubs("art", artInfo, java.SystemHiddenAPIScope, bazSystemStubs)
  219. checkAPIScopeStubs("art", artInfo, java.TestHiddenAPIScope, bazTestStubs)
  220. checkAPIScopeStubs("art", artInfo, java.CorePlatformHiddenAPIScope)
  221. // Check stub dex paths exported by other.
  222. otherFragment := result.Module("other-bootclasspath-fragment", "android_common")
  223. otherInfo := result.ModuleProvider(otherFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo)
  224. fooPublicStubs := "out/soong/.intermediates/foo.stubs/android_common/dex/foo.stubs.jar"
  225. fooSystemStubs := "out/soong/.intermediates/foo.stubs.system/android_common/dex/foo.stubs.system.jar"
  226. checkAPIScopeStubs("other", otherInfo, java.PublicHiddenAPIScope, bazPublicStubs, fooPublicStubs)
  227. checkAPIScopeStubs("other", otherInfo, java.SystemHiddenAPIScope, bazSystemStubs, fooSystemStubs)
  228. checkAPIScopeStubs("other", otherInfo, java.TestHiddenAPIScope, bazTestStubs, fooSystemStubs)
  229. checkAPIScopeStubs("other", otherInfo, java.CorePlatformHiddenAPIScope)
  230. }
  231. func checkBootclasspathFragment(t *testing.T, result *android.TestResult, moduleName, variantName string, expectedConfiguredModules string, expectedBootclasspathFragmentFiles string) {
  232. t.Helper()
  233. bootclasspathFragment := result.ModuleForTests(moduleName, variantName).Module().(*java.BootclasspathFragmentModule)
  234. bootclasspathFragmentInfo := result.ModuleProvider(bootclasspathFragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
  235. modules := bootclasspathFragmentInfo.Modules()
  236. android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String())
  237. // Get a list of all the paths in the boot image sorted by arch type.
  238. allPaths := []string{}
  239. bootImageFilesByArchType := bootclasspathFragmentInfo.AndroidBootImageFilesByArchType()
  240. for _, archType := range android.ArchTypeList() {
  241. if paths, ok := bootImageFilesByArchType[archType]; ok {
  242. for _, path := range paths {
  243. allPaths = append(allPaths, android.NormalizePathForTesting(path))
  244. }
  245. }
  246. }
  247. android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootclasspathFragmentFiles, strings.Join(allPaths, "\n"))
  248. }
  249. func TestBootclasspathFragmentInArtApex(t *testing.T) {
  250. commonPreparer := android.GroupFixturePreparers(
  251. prepareForTestWithBootclasspathFragment,
  252. prepareForTestWithArtApex,
  253. android.FixtureWithRootAndroidBp(`
  254. apex {
  255. name: "com.android.art",
  256. key: "com.android.art.key",
  257. bootclasspath_fragments: [
  258. "mybootclasspathfragment",
  259. ],
  260. // bar (like foo) should be transitively included in this apex because it is part of the
  261. // mybootclasspathfragment bootclasspath_fragment.
  262. updatable: false,
  263. }
  264. apex_key {
  265. name: "com.android.art.key",
  266. public_key: "testkey.avbpubkey",
  267. private_key: "testkey.pem",
  268. }
  269. java_library {
  270. name: "foo",
  271. srcs: ["b.java"],
  272. installable: true,
  273. apex_available: [
  274. "com.android.art",
  275. ],
  276. }
  277. java_library {
  278. name: "bar",
  279. srcs: ["b.java"],
  280. installable: true,
  281. apex_available: [
  282. "com.android.art",
  283. ],
  284. }
  285. java_import {
  286. name: "foo",
  287. jars: ["foo.jar"],
  288. apex_available: [
  289. "com.android.art",
  290. ],
  291. compile_dex: true,
  292. }
  293. java_import {
  294. name: "bar",
  295. jars: ["bar.jar"],
  296. apex_available: [
  297. "com.android.art",
  298. ],
  299. compile_dex: true,
  300. }
  301. `),
  302. )
  303. contentsInsert := func(contents []string) string {
  304. insert := ""
  305. if contents != nil {
  306. insert = fmt.Sprintf(`contents: ["%s"],`, strings.Join(contents, `", "`))
  307. }
  308. return insert
  309. }
  310. addSource := func(contents ...string) android.FixturePreparer {
  311. text := fmt.Sprintf(`
  312. bootclasspath_fragment {
  313. name: "mybootclasspathfragment",
  314. image_name: "art",
  315. %s
  316. apex_available: [
  317. "com.android.art",
  318. ],
  319. hidden_api: {
  320. split_packages: ["*"],
  321. },
  322. }
  323. `, contentsInsert(contents))
  324. return android.FixtureAddTextFile("art/build/boot/Android.bp", text)
  325. }
  326. addPrebuilt := func(prefer bool, contents ...string) android.FixturePreparer {
  327. text := fmt.Sprintf(`
  328. prebuilt_apex {
  329. name: "com.android.art",
  330. arch: {
  331. arm64: {
  332. src: "com.android.art-arm64.apex",
  333. },
  334. arm: {
  335. src: "com.android.art-arm.apex",
  336. },
  337. },
  338. exported_bootclasspath_fragments: ["mybootclasspathfragment"],
  339. }
  340. prebuilt_bootclasspath_fragment {
  341. name: "mybootclasspathfragment",
  342. image_name: "art",
  343. %s
  344. prefer: %t,
  345. apex_available: [
  346. "com.android.art",
  347. ],
  348. hidden_api: {
  349. annotation_flags: "mybootclasspathfragment/annotation-flags.csv",
  350. metadata: "mybootclasspathfragment/metadata.csv",
  351. index: "mybootclasspathfragment/index.csv",
  352. stub_flags: "mybootclasspathfragment/stub-flags.csv",
  353. all_flags: "mybootclasspathfragment/all-flags.csv",
  354. },
  355. }
  356. `, contentsInsert(contents), prefer)
  357. return android.FixtureAddTextFile("prebuilts/module_sdk/art/Android.bp", text)
  358. }
  359. t.Run("boot image files from source", func(t *testing.T) {
  360. result := android.GroupFixturePreparers(
  361. commonPreparer,
  362. // Configure some libraries in the art bootclasspath_fragment that match the source
  363. // bootclasspath_fragment's contents property.
  364. java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
  365. addSource("foo", "bar"),
  366. java.FixtureSetBootImageInstallDirOnDevice("art", "apex/com.android.art/javalib"),
  367. ).RunTest(t)
  368. ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
  369. "etc/boot-image.prof",
  370. "etc/classpaths/bootclasspath.pb",
  371. "javalib/arm/boot.art",
  372. "javalib/arm/boot.oat",
  373. "javalib/arm/boot.vdex",
  374. "javalib/arm/boot-bar.art",
  375. "javalib/arm/boot-bar.oat",
  376. "javalib/arm/boot-bar.vdex",
  377. "javalib/arm64/boot.art",
  378. "javalib/arm64/boot.oat",
  379. "javalib/arm64/boot.vdex",
  380. "javalib/arm64/boot-bar.art",
  381. "javalib/arm64/boot-bar.oat",
  382. "javalib/arm64/boot-bar.vdex",
  383. "javalib/bar.jar",
  384. "javalib/foo.jar",
  385. })
  386. java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
  387. `com.android.art.key`,
  388. `mybootclasspathfragment`,
  389. })
  390. // The boot images are installed in the APEX by Soong, so there shouldn't be any dexpreopt-related Make modules.
  391. ensureDoesNotContainRequiredDeps(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
  392. "mybootclasspathfragment-dexpreopt-arm64-boot.art",
  393. "mybootclasspathfragment-dexpreopt-arm64-boot.oat",
  394. "mybootclasspathfragment-dexpreopt-arm64-boot.vdex",
  395. "mybootclasspathfragment-dexpreopt-arm64-boot-bar.art",
  396. "mybootclasspathfragment-dexpreopt-arm64-boot-bar.oat",
  397. "mybootclasspathfragment-dexpreopt-arm64-boot-bar.vdex",
  398. "mybootclasspathfragment-dexpreopt-arm-boot.art",
  399. "mybootclasspathfragment-dexpreopt-arm-boot.oat",
  400. "mybootclasspathfragment-dexpreopt-arm-boot.vdex",
  401. "mybootclasspathfragment-dexpreopt-arm-boot-bar.art",
  402. "mybootclasspathfragment-dexpreopt-arm-boot-bar.oat",
  403. "mybootclasspathfragment-dexpreopt-arm-boot-bar.vdex",
  404. })
  405. // Make sure that the source bootclasspath_fragment copies its dex files to the predefined
  406. // locations for the art image.
  407. module := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
  408. checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo")
  409. })
  410. t.Run("boot image files from source no boot image in apex", func(t *testing.T) {
  411. result := android.GroupFixturePreparers(
  412. commonPreparer,
  413. // Configure some libraries in the art bootclasspath_fragment that match the source
  414. // bootclasspath_fragment's contents property.
  415. java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
  416. addSource("foo", "bar"),
  417. java.FixtureSetBootImageInstallDirOnDevice("art", "system/framework"),
  418. ).RunTest(t)
  419. ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
  420. "etc/boot-image.prof",
  421. "etc/classpaths/bootclasspath.pb",
  422. "javalib/bar.jar",
  423. "javalib/foo.jar",
  424. })
  425. ensureContainsRequiredDeps(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
  426. "mybootclasspathfragment-dexpreopt-arm64-boot.art",
  427. "mybootclasspathfragment-dexpreopt-arm64-boot.oat",
  428. "mybootclasspathfragment-dexpreopt-arm64-boot.vdex",
  429. "mybootclasspathfragment-dexpreopt-arm64-boot-bar.art",
  430. "mybootclasspathfragment-dexpreopt-arm64-boot-bar.oat",
  431. "mybootclasspathfragment-dexpreopt-arm64-boot-bar.vdex",
  432. "mybootclasspathfragment-dexpreopt-arm-boot.art",
  433. "mybootclasspathfragment-dexpreopt-arm-boot.oat",
  434. "mybootclasspathfragment-dexpreopt-arm-boot.vdex",
  435. "mybootclasspathfragment-dexpreopt-arm-boot-bar.art",
  436. "mybootclasspathfragment-dexpreopt-arm-boot-bar.oat",
  437. "mybootclasspathfragment-dexpreopt-arm-boot-bar.vdex",
  438. })
  439. })
  440. t.Run("generate boot image profile even if dexpreopt is disabled", func(t *testing.T) {
  441. result := android.GroupFixturePreparers(
  442. commonPreparer,
  443. // Configure some libraries in the art bootclasspath_fragment that match the source
  444. // bootclasspath_fragment's contents property.
  445. java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
  446. addSource("foo", "bar"),
  447. java.FixtureSetBootImageInstallDirOnDevice("art", "system/framework"),
  448. dexpreopt.FixtureDisableDexpreoptBootImages(true),
  449. ).RunTest(t)
  450. ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
  451. "etc/boot-image.prof",
  452. "etc/classpaths/bootclasspath.pb",
  453. "javalib/bar.jar",
  454. "javalib/foo.jar",
  455. })
  456. })
  457. t.Run("boot image disable generate profile", func(t *testing.T) {
  458. result := android.GroupFixturePreparers(
  459. commonPreparer,
  460. // Configure some libraries in the art bootclasspath_fragment that match the source
  461. // bootclasspath_fragment's contents property.
  462. java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
  463. addSource("foo", "bar"),
  464. dexpreopt.FixtureDisableGenerateProfile(true),
  465. ).RunTest(t)
  466. files := getFiles(t, result.TestContext, "com.android.art", "android_common_com.android.art_image")
  467. for _, file := range files {
  468. matched, _ := path.Match("etc/boot-image.prof", file.path)
  469. android.AssertBoolEquals(t, "\"etc/boot-image.prof\" should not be in the APEX", matched, false)
  470. }
  471. })
  472. t.Run("boot image files with preferred prebuilt", func(t *testing.T) {
  473. result := android.GroupFixturePreparers(
  474. commonPreparer,
  475. // Configure some libraries in the art bootclasspath_fragment that match the source
  476. // bootclasspath_fragment's contents property.
  477. java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
  478. addSource("foo", "bar"),
  479. // Make sure that a preferred prebuilt with consistent contents doesn't affect the apex.
  480. addPrebuilt(true, "foo", "bar"),
  481. java.FixtureSetBootImageInstallDirOnDevice("art", "apex/com.android.art/javalib"),
  482. ).RunTest(t)
  483. ensureExactDeapexedContents(t, result.TestContext, "com.android.art", "android_common", []string{
  484. "etc/boot-image.prof",
  485. "javalib/arm/boot.art",
  486. "javalib/arm/boot.oat",
  487. "javalib/arm/boot.vdex",
  488. "javalib/arm/boot-bar.art",
  489. "javalib/arm/boot-bar.oat",
  490. "javalib/arm/boot-bar.vdex",
  491. "javalib/arm64/boot.art",
  492. "javalib/arm64/boot.oat",
  493. "javalib/arm64/boot.vdex",
  494. "javalib/arm64/boot-bar.art",
  495. "javalib/arm64/boot-bar.oat",
  496. "javalib/arm64/boot-bar.vdex",
  497. "javalib/bar.jar",
  498. "javalib/foo.jar",
  499. })
  500. java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
  501. `com.android.art.key`,
  502. `mybootclasspathfragment`,
  503. `prebuilt_com.android.art`,
  504. })
  505. // The boot images are installed in the APEX by Soong, so there shouldn't be any dexpreopt-related Make modules.
  506. ensureDoesNotContainRequiredDeps(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
  507. "mybootclasspathfragment-dexpreopt-arm64-boot.art",
  508. "mybootclasspathfragment-dexpreopt-arm64-boot.oat",
  509. "mybootclasspathfragment-dexpreopt-arm64-boot.vdex",
  510. "mybootclasspathfragment-dexpreopt-arm64-boot-bar.art",
  511. "mybootclasspathfragment-dexpreopt-arm64-boot-bar.oat",
  512. "mybootclasspathfragment-dexpreopt-arm64-boot-bar.vdex",
  513. "mybootclasspathfragment-dexpreopt-arm-boot.art",
  514. "mybootclasspathfragment-dexpreopt-arm-boot.oat",
  515. "mybootclasspathfragment-dexpreopt-arm-boot.vdex",
  516. "mybootclasspathfragment-dexpreopt-arm-boot-bar.art",
  517. "mybootclasspathfragment-dexpreopt-arm-boot-bar.oat",
  518. "mybootclasspathfragment-dexpreopt-arm-boot-bar.vdex",
  519. })
  520. // Make sure that the prebuilt bootclasspath_fragment copies its dex files to the predefined
  521. // locations for the art image.
  522. module := result.ModuleForTests("prebuilt_mybootclasspathfragment", "android_common_com.android.art")
  523. checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo")
  524. })
  525. t.Run("boot image files from preferred prebuilt no boot image in apex", func(t *testing.T) {
  526. result := android.GroupFixturePreparers(
  527. commonPreparer,
  528. // Configure some libraries in the art bootclasspath_fragment that match the source
  529. // bootclasspath_fragment's contents property.
  530. java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
  531. addSource("foo", "bar"),
  532. // Make sure that a preferred prebuilt with consistent contents doesn't affect the apex.
  533. addPrebuilt(true, "foo", "bar"),
  534. java.FixtureSetBootImageInstallDirOnDevice("art", "system/framework"),
  535. ).RunTest(t)
  536. ensureExactDeapexedContents(t, result.TestContext, "com.android.art", "android_common", []string{
  537. "etc/boot-image.prof",
  538. "javalib/bar.jar",
  539. "javalib/foo.jar",
  540. })
  541. ensureContainsRequiredDeps(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
  542. "mybootclasspathfragment-dexpreopt-arm64-boot.art",
  543. "mybootclasspathfragment-dexpreopt-arm64-boot.oat",
  544. "mybootclasspathfragment-dexpreopt-arm64-boot.vdex",
  545. "mybootclasspathfragment-dexpreopt-arm64-boot-bar.art",
  546. "mybootclasspathfragment-dexpreopt-arm64-boot-bar.oat",
  547. "mybootclasspathfragment-dexpreopt-arm64-boot-bar.vdex",
  548. "mybootclasspathfragment-dexpreopt-arm-boot.art",
  549. "mybootclasspathfragment-dexpreopt-arm-boot.oat",
  550. "mybootclasspathfragment-dexpreopt-arm-boot.vdex",
  551. "mybootclasspathfragment-dexpreopt-arm-boot-bar.art",
  552. "mybootclasspathfragment-dexpreopt-arm-boot-bar.oat",
  553. "mybootclasspathfragment-dexpreopt-arm-boot-bar.vdex",
  554. })
  555. })
  556. t.Run("source with inconsistency between config and contents", func(t *testing.T) {
  557. android.GroupFixturePreparers(
  558. commonPreparer,
  559. // Create an inconsistency between the ArtApexJars configuration and the art source
  560. // bootclasspath_fragment module's contents property.
  561. java.FixtureConfigureBootJars("com.android.art:foo"),
  562. addSource("foo", "bar"),
  563. ).
  564. ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
  565. RunTest(t)
  566. })
  567. t.Run("prebuilt with inconsistency between config and contents", func(t *testing.T) {
  568. android.GroupFixturePreparers(
  569. commonPreparer,
  570. // Create an inconsistency between the ArtApexJars configuration and the art
  571. // prebuilt_bootclasspath_fragment module's contents property.
  572. java.FixtureConfigureBootJars("com.android.art:foo"),
  573. addPrebuilt(false, "foo", "bar"),
  574. ).
  575. ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
  576. RunTest(t)
  577. })
  578. t.Run("preferred prebuilt with inconsistency between config and contents", func(t *testing.T) {
  579. android.GroupFixturePreparers(
  580. commonPreparer,
  581. // Create an inconsistency between the ArtApexJars configuration and the art
  582. // prebuilt_bootclasspath_fragment module's contents property.
  583. java.FixtureConfigureBootJars("com.android.art:foo"),
  584. addPrebuilt(true, "foo", "bar"),
  585. // Source contents property is consistent with the config.
  586. addSource("foo"),
  587. ).
  588. ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
  589. RunTest(t)
  590. })
  591. t.Run("source preferred and prebuilt with inconsistency between config and contents", func(t *testing.T) {
  592. android.GroupFixturePreparers(
  593. commonPreparer,
  594. // Create an inconsistency between the ArtApexJars configuration and the art
  595. // prebuilt_bootclasspath_fragment module's contents property.
  596. java.FixtureConfigureBootJars("com.android.art:foo"),
  597. addPrebuilt(false, "foo", "bar"),
  598. // Source contents property is consistent with the config.
  599. addSource("foo"),
  600. // This should pass because while the prebuilt is inconsistent with the configuration it is
  601. // not actually used.
  602. ).RunTest(t)
  603. })
  604. }
  605. func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) {
  606. preparers := android.GroupFixturePreparers(
  607. prepareForTestWithBootclasspathFragment,
  608. prepareForTestWithArtApex,
  609. android.FixtureMergeMockFs(android.MockFS{
  610. "com.android.art-arm64.apex": nil,
  611. "com.android.art-arm.apex": nil,
  612. }),
  613. // Configure some libraries in the art bootclasspath_fragment.
  614. java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
  615. java.FixtureSetBootImageInstallDirOnDevice("art", "apex/com.android.art/javalib"),
  616. )
  617. bp := `
  618. prebuilt_apex {
  619. name: "com.android.art",
  620. arch: {
  621. arm64: {
  622. src: "com.android.art-arm64.apex",
  623. },
  624. arm: {
  625. src: "com.android.art-arm.apex",
  626. },
  627. },
  628. exported_bootclasspath_fragments: ["mybootclasspathfragment"],
  629. }
  630. java_import {
  631. name: "foo",
  632. jars: ["foo.jar"],
  633. apex_available: [
  634. "com.android.art",
  635. ],
  636. }
  637. java_import {
  638. name: "bar",
  639. jars: ["bar.jar"],
  640. apex_available: [
  641. "com.android.art",
  642. ],
  643. }
  644. prebuilt_bootclasspath_fragment {
  645. name: "mybootclasspathfragment",
  646. image_name: "art",
  647. // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
  648. contents: ["foo", "bar"],
  649. apex_available: [
  650. "com.android.art",
  651. ],
  652. hidden_api: {
  653. annotation_flags: "mybootclasspathfragment/annotation-flags.csv",
  654. metadata: "mybootclasspathfragment/metadata.csv",
  655. index: "mybootclasspathfragment/index.csv",
  656. stub_flags: "mybootclasspathfragment/stub-flags.csv",
  657. all_flags: "mybootclasspathfragment/all-flags.csv",
  658. },
  659. }
  660. // A prebuilt apex with the same apex_name that shouldn't interfere when it isn't enabled.
  661. prebuilt_apex {
  662. name: "com.mycompany.android.art",
  663. apex_name: "com.android.art",
  664. %s
  665. src: "com.mycompany.android.art.apex",
  666. exported_bootclasspath_fragments: ["mybootclasspathfragment"],
  667. }
  668. `
  669. t.Run("disabled alternative APEX", func(t *testing.T) {
  670. result := preparers.RunTestWithBp(t, fmt.Sprintf(bp, "enabled: false,"))
  671. java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art", []string{
  672. `com.android.art.apex.selector`,
  673. `prebuilt_mybootclasspathfragment`,
  674. })
  675. java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_com.android.art", []string{
  676. `com.android.art.deapexer`,
  677. `dex2oatd`,
  678. `prebuilt_bar`,
  679. `prebuilt_foo`,
  680. })
  681. module := result.ModuleForTests("mybootclasspathfragment", "android_common_com.android.art")
  682. checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo")
  683. // Check that the right deapexer module was chosen for a boot image.
  684. param := module.Output("out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art")
  685. android.AssertStringDoesContain(t, "didn't find the expected deapexer in the input path", param.Input.String(), "/com.android.art.deapexer")
  686. })
  687. t.Run("enabled alternative APEX", func(t *testing.T) {
  688. preparers.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
  689. "Multiple installable prebuilt APEXes provide ambiguous deapexers: com.android.art and com.mycompany.android.art")).
  690. RunTestWithBp(t, fmt.Sprintf(bp, ""))
  691. })
  692. }
  693. // checkCopiesToPredefinedLocationForArt checks that the supplied modules are copied to the
  694. // predefined locations of boot dex jars used as inputs for the ART boot image.
  695. func checkCopiesToPredefinedLocationForArt(t *testing.T, config android.Config, module android.TestingModule, modules ...string) {
  696. t.Helper()
  697. bootJarLocations := []string{}
  698. for _, output := range module.AllOutputs() {
  699. output = android.StringRelativeToTop(config, output)
  700. if strings.HasPrefix(output, "out/soong/dexpreopt_arm64/dex_artjars_input/") {
  701. bootJarLocations = append(bootJarLocations, output)
  702. }
  703. }
  704. sort.Strings(bootJarLocations)
  705. expected := []string{}
  706. for _, m := range modules {
  707. expected = append(expected, fmt.Sprintf("out/soong/dexpreopt_arm64/dex_artjars_input/%s.jar", m))
  708. }
  709. sort.Strings(expected)
  710. android.AssertArrayString(t, "copies to predefined locations for art", expected, bootJarLocations)
  711. }
  712. func TestBootclasspathFragmentContentsNoName(t *testing.T) {
  713. result := android.GroupFixturePreparers(
  714. prepareForTestWithBootclasspathFragment,
  715. prepareForTestWithMyapex,
  716. // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
  717. java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
  718. // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
  719. // is disabled.
  720. android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
  721. java.PrepareForTestWithJavaSdkLibraryFiles,
  722. java.FixtureWithLastReleaseApis("foo"),
  723. ).RunTestWithBp(t, `
  724. apex {
  725. name: "myapex",
  726. key: "myapex.key",
  727. bootclasspath_fragments: [
  728. "mybootclasspathfragment",
  729. ],
  730. updatable: false,
  731. }
  732. apex_key {
  733. name: "myapex.key",
  734. public_key: "testkey.avbpubkey",
  735. private_key: "testkey.pem",
  736. }
  737. java_sdk_library {
  738. name: "foo",
  739. srcs: ["b.java"],
  740. shared_library: false,
  741. public: {enabled: true},
  742. apex_available: [
  743. "myapex",
  744. ],
  745. }
  746. java_library {
  747. name: "bar",
  748. srcs: ["b.java"],
  749. installable: true,
  750. apex_available: [
  751. "myapex",
  752. ],
  753. }
  754. bootclasspath_fragment {
  755. name: "mybootclasspathfragment",
  756. contents: [
  757. "foo",
  758. "bar",
  759. ],
  760. apex_available: [
  761. "myapex",
  762. ],
  763. hidden_api: {
  764. split_packages: ["*"],
  765. },
  766. }
  767. `)
  768. ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
  769. // This does not include art, oat or vdex files as they are only included for the art boot
  770. // image.
  771. "etc/classpaths/bootclasspath.pb",
  772. "javalib/bar.jar",
  773. "javalib/foo.jar",
  774. })
  775. java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
  776. `myapex.key`,
  777. `mybootclasspathfragment`,
  778. })
  779. apex := result.ModuleForTests("myapex", "android_common_myapex_image")
  780. apexRule := apex.Rule("apexRule")
  781. copyCommands := apexRule.Args["copy_commands"]
  782. // Make sure that the fragment provides the hidden API encoded dex jars to the APEX.
  783. fragment := result.Module("mybootclasspathfragment", "android_common_apex10000")
  784. info := result.ModuleProvider(fragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
  785. checkFragmentExportedDexJar := func(name string, expectedDexJar string) {
  786. module := result.Module(name, "android_common_apex10000")
  787. dexJar, err := info.DexBootJarPathForContentModule(module)
  788. if err != nil {
  789. t.Error(err)
  790. }
  791. android.AssertPathRelativeToTopEquals(t, name+" dex", expectedDexJar, dexJar)
  792. expectedCopyCommand := fmt.Sprintf("&& cp -f %s out/soong/.intermediates/myapex/android_common_myapex_image/image.apex/javalib/%s.jar", expectedDexJar, name)
  793. android.AssertStringDoesContain(t, name+" apex copy command", copyCommands, expectedCopyCommand)
  794. }
  795. checkFragmentExportedDexJar("foo", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/foo.jar")
  796. checkFragmentExportedDexJar("bar", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/bar.jar")
  797. }
  798. func getDexJarPath(result *android.TestResult, name string) string {
  799. module := result.Module(name, "android_common")
  800. return module.(java.UsesLibraryDependency).DexJarBuildPath().Path().RelativeToTop().String()
  801. }
  802. // TestBootclasspathFragment_HiddenAPIList checks to make sure that the correct parameters are
  803. // passed to the hiddenapi list tool.
  804. func TestBootclasspathFragment_HiddenAPIList(t *testing.T) {
  805. result := android.GroupFixturePreparers(
  806. prepareForTestWithBootclasspathFragment,
  807. prepareForTestWithArtApex,
  808. prepareForTestWithMyapex,
  809. // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
  810. java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"),
  811. java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
  812. // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
  813. // is disabled.
  814. android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
  815. java.PrepareForTestWithJavaSdkLibraryFiles,
  816. java.FixtureWithLastReleaseApis("foo", "quuz"),
  817. ).RunTestWithBp(t, `
  818. apex {
  819. name: "com.android.art",
  820. key: "com.android.art.key",
  821. bootclasspath_fragments: ["art-bootclasspath-fragment"],
  822. updatable: false,
  823. }
  824. apex_key {
  825. name: "com.android.art.key",
  826. public_key: "com.android.art.avbpubkey",
  827. private_key: "com.android.art.pem",
  828. }
  829. java_library {
  830. name: "baz",
  831. apex_available: [
  832. "com.android.art",
  833. ],
  834. srcs: ["b.java"],
  835. compile_dex: true,
  836. }
  837. java_sdk_library {
  838. name: "quuz",
  839. apex_available: [
  840. "com.android.art",
  841. ],
  842. srcs: ["b.java"],
  843. compile_dex: true,
  844. public: {enabled: true},
  845. system: {enabled: true},
  846. test: {enabled: true},
  847. module_lib: {enabled: true},
  848. }
  849. bootclasspath_fragment {
  850. name: "art-bootclasspath-fragment",
  851. image_name: "art",
  852. // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
  853. contents: ["baz", "quuz"],
  854. apex_available: [
  855. "com.android.art",
  856. ],
  857. hidden_api: {
  858. split_packages: ["*"],
  859. },
  860. }
  861. apex {
  862. name: "myapex",
  863. key: "myapex.key",
  864. bootclasspath_fragments: [
  865. "mybootclasspathfragment",
  866. ],
  867. updatable: false,
  868. }
  869. apex_key {
  870. name: "myapex.key",
  871. public_key: "testkey.avbpubkey",
  872. private_key: "testkey.pem",
  873. }
  874. java_sdk_library {
  875. name: "foo",
  876. srcs: ["b.java"],
  877. shared_library: false,
  878. public: {enabled: true},
  879. apex_available: [
  880. "myapex",
  881. ],
  882. }
  883. java_library {
  884. name: "bar",
  885. srcs: ["b.java"],
  886. installable: true,
  887. apex_available: [
  888. "myapex",
  889. ],
  890. }
  891. bootclasspath_fragment {
  892. name: "mybootclasspathfragment",
  893. contents: [
  894. "foo",
  895. "bar",
  896. ],
  897. apex_available: [
  898. "myapex",
  899. ],
  900. fragments: [
  901. {
  902. apex: "com.android.art",
  903. module: "art-bootclasspath-fragment",
  904. },
  905. ],
  906. hidden_api: {
  907. split_packages: ["*"],
  908. },
  909. }
  910. `)
  911. java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{
  912. "art-bootclasspath-fragment",
  913. "bar",
  914. "dex2oatd",
  915. "foo",
  916. })
  917. fooStubs := getDexJarPath(result, "foo.stubs")
  918. quuzPublicStubs := getDexJarPath(result, "quuz.stubs")
  919. quuzSystemStubs := getDexJarPath(result, "quuz.stubs.system")
  920. quuzTestStubs := getDexJarPath(result, "quuz.stubs.test")
  921. quuzModuleLibStubs := getDexJarPath(result, "quuz.stubs.module_lib")
  922. // Make sure that the fragment uses the quuz stub dex jars when generating the hidden API flags.
  923. fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
  924. rule := fragment.Rule("modularHiddenAPIStubFlagsFile")
  925. command := rule.RuleParams.Command
  926. android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list")
  927. // Make sure that the quuz stubs are available for resolving references from the implementation
  928. // boot dex jars provided by this module.
  929. android.AssertStringDoesContain(t, "quuz widest", command, "--dependency-stub-dex="+quuzModuleLibStubs)
  930. // Make sure that the quuz stubs are available for resolving references from the different API
  931. // stubs provided by this module.
  932. android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+quuzPublicStubs+":"+fooStubs)
  933. android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+quuzSystemStubs+":"+fooStubs)
  934. android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+quuzTestStubs+":"+fooStubs)
  935. }
  936. // TestBootclasspathFragment_AndroidNonUpdatable checks to make sure that setting
  937. // additional_stubs: ["android-non-updatable"] causes the source android-non-updatable modules to be
  938. // added to the hiddenapi list tool.
  939. func TestBootclasspathFragment_AndroidNonUpdatable(t *testing.T) {
  940. result := android.GroupFixturePreparers(
  941. prepareForTestWithBootclasspathFragment,
  942. prepareForTestWithArtApex,
  943. prepareForTestWithMyapex,
  944. // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
  945. java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"),
  946. java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
  947. // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
  948. // is disabled.
  949. android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
  950. java.PrepareForTestWithJavaSdkLibraryFiles,
  951. java.FixtureWithLastReleaseApis("foo", "android-non-updatable"),
  952. ).RunTestWithBp(t, `
  953. java_sdk_library {
  954. name: "android-non-updatable",
  955. srcs: ["b.java"],
  956. compile_dex: true,
  957. public: {
  958. enabled: true,
  959. },
  960. system: {
  961. enabled: true,
  962. },
  963. test: {
  964. enabled: true,
  965. },
  966. module_lib: {
  967. enabled: true,
  968. },
  969. }
  970. apex {
  971. name: "com.android.art",
  972. key: "com.android.art.key",
  973. bootclasspath_fragments: ["art-bootclasspath-fragment"],
  974. updatable: false,
  975. }
  976. apex_key {
  977. name: "com.android.art.key",
  978. public_key: "com.android.art.avbpubkey",
  979. private_key: "com.android.art.pem",
  980. }
  981. java_library {
  982. name: "baz",
  983. apex_available: [
  984. "com.android.art",
  985. ],
  986. srcs: ["b.java"],
  987. compile_dex: true,
  988. }
  989. java_library {
  990. name: "quuz",
  991. apex_available: [
  992. "com.android.art",
  993. ],
  994. srcs: ["b.java"],
  995. compile_dex: true,
  996. }
  997. bootclasspath_fragment {
  998. name: "art-bootclasspath-fragment",
  999. image_name: "art",
  1000. // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
  1001. contents: ["baz", "quuz"],
  1002. apex_available: [
  1003. "com.android.art",
  1004. ],
  1005. hidden_api: {
  1006. split_packages: ["*"],
  1007. },
  1008. }
  1009. apex {
  1010. name: "myapex",
  1011. key: "myapex.key",
  1012. bootclasspath_fragments: [
  1013. "mybootclasspathfragment",
  1014. ],
  1015. updatable: false,
  1016. }
  1017. apex_key {
  1018. name: "myapex.key",
  1019. public_key: "testkey.avbpubkey",
  1020. private_key: "testkey.pem",
  1021. }
  1022. java_sdk_library {
  1023. name: "foo",
  1024. srcs: ["b.java"],
  1025. shared_library: false,
  1026. public: {enabled: true},
  1027. apex_available: [
  1028. "myapex",
  1029. ],
  1030. }
  1031. java_library {
  1032. name: "bar",
  1033. srcs: ["b.java"],
  1034. installable: true,
  1035. apex_available: [
  1036. "myapex",
  1037. ],
  1038. }
  1039. bootclasspath_fragment {
  1040. name: "mybootclasspathfragment",
  1041. contents: [
  1042. "foo",
  1043. "bar",
  1044. ],
  1045. apex_available: [
  1046. "myapex",
  1047. ],
  1048. additional_stubs: ["android-non-updatable"],
  1049. fragments: [
  1050. {
  1051. apex: "com.android.art",
  1052. module: "art-bootclasspath-fragment",
  1053. },
  1054. ],
  1055. hidden_api: {
  1056. split_packages: ["*"],
  1057. },
  1058. }
  1059. `)
  1060. java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{
  1061. "android-non-updatable.stubs",
  1062. "android-non-updatable.stubs.module_lib",
  1063. "android-non-updatable.stubs.system",
  1064. "android-non-updatable.stubs.test",
  1065. "art-bootclasspath-fragment",
  1066. "bar",
  1067. "dex2oatd",
  1068. "foo",
  1069. })
  1070. nonUpdatablePublicStubs := getDexJarPath(result, "android-non-updatable.stubs")
  1071. nonUpdatableSystemStubs := getDexJarPath(result, "android-non-updatable.stubs.system")
  1072. nonUpdatableTestStubs := getDexJarPath(result, "android-non-updatable.stubs.test")
  1073. nonUpdatableModuleLibStubs := getDexJarPath(result, "android-non-updatable.stubs.module_lib")
  1074. // Make sure that the fragment uses the android-non-updatable modules when generating the hidden
  1075. // API flags.
  1076. fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
  1077. rule := fragment.Rule("modularHiddenAPIStubFlagsFile")
  1078. command := rule.RuleParams.Command
  1079. android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list")
  1080. // Make sure that the module_lib non-updatable stubs are available for resolving references from
  1081. // the implementation boot dex jars provided by this module.
  1082. android.AssertStringDoesContain(t, "android-non-updatable widest", command, "--dependency-stub-dex="+nonUpdatableModuleLibStubs)
  1083. // Make sure that the appropriate non-updatable stubs are available for resolving references from
  1084. // the different API stubs provided by this module.
  1085. android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+nonUpdatablePublicStubs)
  1086. android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+nonUpdatableSystemStubs)
  1087. android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+nonUpdatableTestStubs)
  1088. }
  1089. // TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks checks to make sure that
  1090. // setting additional_stubs: ["android-non-updatable"] causes the prebuilt android-non-updatable
  1091. // modules to be added to the hiddenapi list tool.
  1092. func TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks(t *testing.T) {
  1093. result := android.GroupFixturePreparers(
  1094. prepareForTestWithBootclasspathFragment,
  1095. java.PrepareForTestWithDexpreopt,
  1096. prepareForTestWithArtApex,
  1097. prepareForTestWithMyapex,
  1098. // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
  1099. java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"),
  1100. java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
  1101. // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
  1102. // is disabled.
  1103. android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
  1104. android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
  1105. variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
  1106. }),
  1107. java.PrepareForTestWithJavaSdkLibraryFiles,
  1108. java.FixtureWithPrebuiltApis(map[string][]string{
  1109. "current": {"android-non-updatable"},
  1110. "30": {"foo"},
  1111. }),
  1112. ).RunTestWithBp(t, `
  1113. apex {
  1114. name: "com.android.art",
  1115. key: "com.android.art.key",
  1116. bootclasspath_fragments: ["art-bootclasspath-fragment"],
  1117. updatable: false,
  1118. }
  1119. apex_key {
  1120. name: "com.android.art.key",
  1121. public_key: "com.android.art.avbpubkey",
  1122. private_key: "com.android.art.pem",
  1123. }
  1124. java_library {
  1125. name: "baz",
  1126. apex_available: [
  1127. "com.android.art",
  1128. ],
  1129. srcs: ["b.java"],
  1130. compile_dex: true,
  1131. }
  1132. java_library {
  1133. name: "quuz",
  1134. apex_available: [
  1135. "com.android.art",
  1136. ],
  1137. srcs: ["b.java"],
  1138. compile_dex: true,
  1139. }
  1140. bootclasspath_fragment {
  1141. name: "art-bootclasspath-fragment",
  1142. image_name: "art",
  1143. // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
  1144. contents: ["baz", "quuz"],
  1145. apex_available: [
  1146. "com.android.art",
  1147. ],
  1148. hidden_api: {
  1149. split_packages: ["*"],
  1150. },
  1151. }
  1152. apex {
  1153. name: "myapex",
  1154. key: "myapex.key",
  1155. bootclasspath_fragments: [
  1156. "mybootclasspathfragment",
  1157. ],
  1158. updatable: false,
  1159. }
  1160. apex_key {
  1161. name: "myapex.key",
  1162. public_key: "testkey.avbpubkey",
  1163. private_key: "testkey.pem",
  1164. }
  1165. java_sdk_library {
  1166. name: "foo",
  1167. srcs: ["b.java"],
  1168. shared_library: false,
  1169. public: {enabled: true},
  1170. apex_available: [
  1171. "myapex",
  1172. ],
  1173. }
  1174. java_library {
  1175. name: "bar",
  1176. srcs: ["b.java"],
  1177. installable: true,
  1178. apex_available: [
  1179. "myapex",
  1180. ],
  1181. }
  1182. bootclasspath_fragment {
  1183. name: "mybootclasspathfragment",
  1184. contents: [
  1185. "foo",
  1186. "bar",
  1187. ],
  1188. apex_available: [
  1189. "myapex",
  1190. ],
  1191. additional_stubs: ["android-non-updatable"],
  1192. fragments: [
  1193. {
  1194. apex: "com.android.art",
  1195. module: "art-bootclasspath-fragment",
  1196. },
  1197. ],
  1198. hidden_api: {
  1199. split_packages: ["*"],
  1200. },
  1201. }
  1202. `)
  1203. java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{
  1204. "art-bootclasspath-fragment",
  1205. "bar",
  1206. "dex2oatd",
  1207. "foo",
  1208. "prebuilt_sdk_module-lib_current_android-non-updatable",
  1209. "prebuilt_sdk_public_current_android-non-updatable",
  1210. "prebuilt_sdk_system_current_android-non-updatable",
  1211. "prebuilt_sdk_test_current_android-non-updatable",
  1212. })
  1213. nonUpdatablePublicStubs := getDexJarPath(result, "sdk_public_current_android-non-updatable")
  1214. nonUpdatableSystemStubs := getDexJarPath(result, "sdk_system_current_android-non-updatable")
  1215. nonUpdatableTestStubs := getDexJarPath(result, "sdk_test_current_android-non-updatable")
  1216. nonUpdatableModuleLibStubs := getDexJarPath(result, "sdk_module-lib_current_android-non-updatable")
  1217. // Make sure that the fragment uses the android-non-updatable modules when generating the hidden
  1218. // API flags.
  1219. fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
  1220. rule := fragment.Rule("modularHiddenAPIStubFlagsFile")
  1221. command := rule.RuleParams.Command
  1222. android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list")
  1223. // Make sure that the module_lib non-updatable stubs are available for resolving references from
  1224. // the implementation boot dex jars provided by this module.
  1225. android.AssertStringDoesContain(t, "android-non-updatable widest", command, "--dependency-stub-dex="+nonUpdatableModuleLibStubs)
  1226. // Make sure that the appropriate non-updatable stubs are available for resolving references from
  1227. // the different API stubs provided by this module.
  1228. android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+nonUpdatablePublicStubs)
  1229. android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+nonUpdatableSystemStubs)
  1230. android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+nonUpdatableTestStubs)
  1231. }
  1232. // TODO(b/177892522) - add test for host apex.