platform_bootclasspath_test.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  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. "strings"
  18. "testing"
  19. "android/soong/android"
  20. "android/soong/dexpreopt"
  21. "android/soong/java"
  22. "github.com/google/blueprint"
  23. "github.com/google/blueprint/proptools"
  24. )
  25. // Contains tests for platform_bootclasspath logic from java/platform_bootclasspath.go that requires
  26. // apexes.
  27. var prepareForTestWithPlatformBootclasspath = android.GroupFixturePreparers(
  28. java.PrepareForTestWithJavaDefaultModules,
  29. PrepareForTestWithApexBuildComponents,
  30. )
  31. func TestPlatformBootclasspath_Fragments(t *testing.T) {
  32. result := android.GroupFixturePreparers(
  33. prepareForTestWithPlatformBootclasspath,
  34. prepareForTestWithMyapex,
  35. java.PrepareForTestWithJavaSdkLibraryFiles,
  36. java.FixtureWithLastReleaseApis("foo"),
  37. java.FixtureConfigureApexBootJars("myapex:bar"),
  38. android.FixtureWithRootAndroidBp(`
  39. platform_bootclasspath {
  40. name: "platform-bootclasspath",
  41. fragments: [
  42. {
  43. apex: "myapex",
  44. module:"bar-fragment",
  45. },
  46. ],
  47. hidden_api: {
  48. unsupported: [
  49. "unsupported.txt",
  50. ],
  51. removed: [
  52. "removed.txt",
  53. ],
  54. max_target_r_low_priority: [
  55. "max-target-r-low-priority.txt",
  56. ],
  57. max_target_q: [
  58. "max-target-q.txt",
  59. ],
  60. max_target_p: [
  61. "max-target-p.txt",
  62. ],
  63. max_target_o_low_priority: [
  64. "max-target-o-low-priority.txt",
  65. ],
  66. blocked: [
  67. "blocked.txt",
  68. ],
  69. unsupported_packages: [
  70. "unsupported-packages.txt",
  71. ],
  72. },
  73. }
  74. apex {
  75. name: "myapex",
  76. key: "myapex.key",
  77. bootclasspath_fragments: [
  78. "bar-fragment",
  79. ],
  80. updatable: false,
  81. }
  82. apex_key {
  83. name: "myapex.key",
  84. public_key: "testkey.avbpubkey",
  85. private_key: "testkey.pem",
  86. }
  87. bootclasspath_fragment {
  88. name: "bar-fragment",
  89. contents: ["bar"],
  90. apex_available: ["myapex"],
  91. api: {
  92. stub_libs: ["foo"],
  93. },
  94. hidden_api: {
  95. unsupported: [
  96. "bar-unsupported.txt",
  97. ],
  98. removed: [
  99. "bar-removed.txt",
  100. ],
  101. max_target_r_low_priority: [
  102. "bar-max-target-r-low-priority.txt",
  103. ],
  104. max_target_q: [
  105. "bar-max-target-q.txt",
  106. ],
  107. max_target_p: [
  108. "bar-max-target-p.txt",
  109. ],
  110. max_target_o_low_priority: [
  111. "bar-max-target-o-low-priority.txt",
  112. ],
  113. blocked: [
  114. "bar-blocked.txt",
  115. ],
  116. unsupported_packages: [
  117. "bar-unsupported-packages.txt",
  118. ],
  119. split_packages: ["*"],
  120. },
  121. }
  122. java_library {
  123. name: "bar",
  124. apex_available: ["myapex"],
  125. srcs: ["a.java"],
  126. system_modules: "none",
  127. sdk_version: "none",
  128. compile_dex: true,
  129. permitted_packages: ["bar"],
  130. }
  131. java_sdk_library {
  132. name: "foo",
  133. srcs: ["a.java"],
  134. public: {
  135. enabled: true,
  136. },
  137. compile_dex: true,
  138. }
  139. `),
  140. ).RunTest(t)
  141. pbcp := result.Module("platform-bootclasspath", "android_common")
  142. info := result.ModuleProvider(pbcp, java.MonolithicHiddenAPIInfoProvider).(java.MonolithicHiddenAPIInfo)
  143. for _, category := range java.HiddenAPIFlagFileCategories {
  144. name := category.PropertyName
  145. message := fmt.Sprintf("category %s", name)
  146. filename := strings.ReplaceAll(name, "_", "-")
  147. expected := []string{fmt.Sprintf("%s.txt", filename), fmt.Sprintf("bar-%s.txt", filename)}
  148. android.AssertPathsRelativeToTopEquals(t, message, expected, info.FlagsFilesByCategory[category])
  149. }
  150. android.AssertPathsRelativeToTopEquals(t, "annotation flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/annotation-flags.csv"}, info.AnnotationFlagsPaths)
  151. android.AssertPathsRelativeToTopEquals(t, "metadata flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/metadata.csv"}, info.MetadataPaths)
  152. android.AssertPathsRelativeToTopEquals(t, "index flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/index.csv"}, info.IndexPaths)
  153. android.AssertArrayString(t, "stub flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/filtered-stub-flags.csv:out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/signature-patterns.csv"}, info.StubFlagSubsets.RelativeToTop())
  154. android.AssertArrayString(t, "all flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/filtered-flags.csv:out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/signature-patterns.csv"}, info.FlagSubsets.RelativeToTop())
  155. }
  156. // TestPlatformBootclasspath_LegacyPrebuiltFragment verifies that the
  157. // prebuilt_bootclasspath_fragment falls back to using the complete stub-flags/all-flags if the
  158. // filtered files are not provided.
  159. //
  160. // TODO: Remove once all prebuilts use the filtered_... properties.
  161. func TestPlatformBootclasspath_LegacyPrebuiltFragment(t *testing.T) {
  162. result := android.GroupFixturePreparers(
  163. prepareForTestWithPlatformBootclasspath,
  164. java.FixtureConfigureApexBootJars("myapex:foo"),
  165. java.PrepareForTestWithJavaSdkLibraryFiles,
  166. ).RunTestWithBp(t, `
  167. prebuilt_apex {
  168. name: "myapex",
  169. src: "myapex.apex",
  170. exported_bootclasspath_fragments: ["mybootclasspath-fragment"],
  171. }
  172. // A prebuilt java_sdk_library_import that is not preferred by default but will be preferred
  173. // because AlwaysUsePrebuiltSdks() is true.
  174. java_sdk_library_import {
  175. name: "foo",
  176. prefer: false,
  177. shared_library: false,
  178. permitted_packages: ["foo"],
  179. public: {
  180. jars: ["sdk_library/public/foo-stubs.jar"],
  181. stub_srcs: ["sdk_library/public/foo_stub_sources"],
  182. current_api: "sdk_library/public/foo.txt",
  183. removed_api: "sdk_library/public/foo-removed.txt",
  184. sdk_version: "current",
  185. },
  186. apex_available: ["myapex"],
  187. }
  188. prebuilt_bootclasspath_fragment {
  189. name: "mybootclasspath-fragment",
  190. apex_available: [
  191. "myapex",
  192. ],
  193. contents: [
  194. "foo",
  195. ],
  196. hidden_api: {
  197. stub_flags: "prebuilt-stub-flags.csv",
  198. annotation_flags: "prebuilt-annotation-flags.csv",
  199. metadata: "prebuilt-metadata.csv",
  200. index: "prebuilt-index.csv",
  201. all_flags: "prebuilt-all-flags.csv",
  202. },
  203. }
  204. platform_bootclasspath {
  205. name: "myplatform-bootclasspath",
  206. fragments: [
  207. {
  208. apex: "myapex",
  209. module:"mybootclasspath-fragment",
  210. },
  211. ],
  212. }
  213. `,
  214. )
  215. pbcp := result.Module("myplatform-bootclasspath", "android_common")
  216. info := result.ModuleProvider(pbcp, java.MonolithicHiddenAPIInfoProvider).(java.MonolithicHiddenAPIInfo)
  217. android.AssertArrayString(t, "stub flags", []string{"prebuilt-stub-flags.csv:out/soong/.intermediates/mybootclasspath-fragment/android_common_myapex/modular-hiddenapi/signature-patterns.csv"}, info.StubFlagSubsets.RelativeToTop())
  218. android.AssertArrayString(t, "all flags", []string{"prebuilt-all-flags.csv:out/soong/.intermediates/mybootclasspath-fragment/android_common_myapex/modular-hiddenapi/signature-patterns.csv"}, info.FlagSubsets.RelativeToTop())
  219. }
  220. func TestPlatformBootclasspathDependencies(t *testing.T) {
  221. result := android.GroupFixturePreparers(
  222. prepareForTestWithPlatformBootclasspath,
  223. prepareForTestWithArtApex,
  224. prepareForTestWithMyapex,
  225. // Configure some libraries in the art and framework boot images.
  226. java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo"),
  227. java.FixtureConfigureApexBootJars("myapex:bar"),
  228. java.PrepareForTestWithJavaSdkLibraryFiles,
  229. java.FixtureWithLastReleaseApis("foo"),
  230. java.PrepareForTestWithDexpreopt,
  231. dexpreopt.FixtureDisableDexpreoptBootImages(false),
  232. ).RunTestWithBp(t, `
  233. apex {
  234. name: "com.android.art",
  235. key: "com.android.art.key",
  236. bootclasspath_fragments: [
  237. "art-bootclasspath-fragment",
  238. ],
  239. updatable: false,
  240. }
  241. apex_key {
  242. name: "com.android.art.key",
  243. public_key: "com.android.art.avbpubkey",
  244. private_key: "com.android.art.pem",
  245. }
  246. bootclasspath_fragment {
  247. name: "art-bootclasspath-fragment",
  248. image_name: "art",
  249. apex_available: [
  250. "com.android.art",
  251. ],
  252. contents: [
  253. "baz",
  254. "quuz",
  255. ],
  256. hidden_api: {
  257. split_packages: ["*"],
  258. },
  259. }
  260. java_library {
  261. name: "baz",
  262. apex_available: [
  263. "com.android.art",
  264. ],
  265. srcs: ["b.java"],
  266. installable: true,
  267. }
  268. // Add a java_import that is not preferred and so won't have an appropriate apex variant created
  269. // for it to make sure that the platform_bootclasspath doesn't try and add a dependency onto it.
  270. java_import {
  271. name: "baz",
  272. apex_available: [
  273. "com.android.art",
  274. ],
  275. jars: ["b.jar"],
  276. }
  277. java_library {
  278. name: "quuz",
  279. apex_available: [
  280. "com.android.art",
  281. ],
  282. srcs: ["b.java"],
  283. installable: true,
  284. }
  285. apex {
  286. name: "myapex",
  287. key: "myapex.key",
  288. bootclasspath_fragments: [
  289. "my-bootclasspath-fragment",
  290. ],
  291. updatable: false,
  292. }
  293. bootclasspath_fragment {
  294. name: "my-bootclasspath-fragment",
  295. contents: ["bar"],
  296. apex_available: ["myapex"],
  297. hidden_api: {
  298. split_packages: ["*"],
  299. },
  300. }
  301. apex_key {
  302. name: "myapex.key",
  303. public_key: "testkey.avbpubkey",
  304. private_key: "testkey.pem",
  305. }
  306. java_sdk_library {
  307. name: "foo",
  308. srcs: ["b.java"],
  309. }
  310. java_library {
  311. name: "bar",
  312. srcs: ["b.java"],
  313. installable: true,
  314. apex_available: ["myapex"],
  315. permitted_packages: ["bar"],
  316. }
  317. platform_bootclasspath {
  318. name: "myplatform-bootclasspath",
  319. fragments: [
  320. {
  321. apex: "com.android.art",
  322. module: "art-bootclasspath-fragment",
  323. },
  324. {
  325. apex: "myapex",
  326. module: "my-bootclasspath-fragment",
  327. },
  328. ],
  329. }
  330. `,
  331. )
  332. java.CheckPlatformBootclasspathModules(t, result, "myplatform-bootclasspath", []string{
  333. // The configured contents of BootJars.
  334. "com.android.art:baz",
  335. "com.android.art:quuz",
  336. "platform:foo",
  337. // The configured contents of ApexBootJars.
  338. "myapex:bar",
  339. })
  340. java.CheckPlatformBootclasspathFragments(t, result, "myplatform-bootclasspath", []string{
  341. "com.android.art:art-bootclasspath-fragment",
  342. "myapex:my-bootclasspath-fragment",
  343. })
  344. // Make sure that the myplatform-bootclasspath has the correct dependencies.
  345. CheckModuleDependencies(t, result.TestContext, "myplatform-bootclasspath", "android_common", []string{
  346. // The following are stubs.
  347. `platform:android_stubs_current`,
  348. `platform:android_system_stubs_current`,
  349. `platform:android_test_stubs_current`,
  350. `platform:legacy.core.platform.api.stubs`,
  351. // Needed for generating the boot image.
  352. `platform:dex2oatd`,
  353. // The configured contents of BootJars.
  354. `com.android.art:baz`,
  355. `com.android.art:quuz`,
  356. `platform:foo`,
  357. // The configured contents of ApexBootJars.
  358. `myapex:bar`,
  359. // The fragments.
  360. `com.android.art:art-bootclasspath-fragment`,
  361. `myapex:my-bootclasspath-fragment`,
  362. })
  363. }
  364. // TestPlatformBootclasspath_AlwaysUsePrebuiltSdks verifies that the build does not fail when
  365. // AlwaysUsePrebuiltSdk() returns true.
  366. func TestPlatformBootclasspath_AlwaysUsePrebuiltSdks(t *testing.T) {
  367. result := android.GroupFixturePreparers(
  368. prepareForTestWithPlatformBootclasspath,
  369. prepareForTestWithMyapex,
  370. // Configure two libraries, the first is a java_sdk_library whose prebuilt will be used because
  371. // of AlwaysUsePrebuiltsSdk(). The second is a normal library that is unaffected. The order
  372. // matters, so that the dependencies resolved by the platform_bootclasspath matches the
  373. // configured list.
  374. java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
  375. java.PrepareForTestWithJavaSdkLibraryFiles,
  376. android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
  377. variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
  378. }),
  379. java.FixtureWithPrebuiltApis(map[string][]string{
  380. "current": {},
  381. "30": {"foo"},
  382. }),
  383. ).RunTestWithBp(t, `
  384. apex {
  385. name: "myapex",
  386. key: "myapex.key",
  387. bootclasspath_fragments: [
  388. "mybootclasspath-fragment",
  389. ],
  390. updatable: false,
  391. }
  392. apex_key {
  393. name: "myapex.key",
  394. public_key: "testkey.avbpubkey",
  395. private_key: "testkey.pem",
  396. }
  397. java_library {
  398. name: "bar",
  399. srcs: ["b.java"],
  400. installable: true,
  401. apex_available: ["myapex"],
  402. permitted_packages: ["bar"],
  403. }
  404. java_sdk_library {
  405. name: "foo",
  406. srcs: ["b.java"],
  407. shared_library: false,
  408. public: {
  409. enabled: true,
  410. },
  411. apex_available: ["myapex"],
  412. permitted_packages: ["foo"],
  413. }
  414. prebuilt_apex {
  415. name: "myapex",
  416. src: "myapex.apex",
  417. exported_bootclasspath_fragments: ["mybootclasspath-fragment"],
  418. }
  419. // A prebuilt java_sdk_library_import that is not preferred by default but will be preferred
  420. // because AlwaysUsePrebuiltSdks() is true.
  421. java_sdk_library_import {
  422. name: "foo",
  423. prefer: false,
  424. shared_library: false,
  425. permitted_packages: ["foo"],
  426. public: {
  427. jars: ["sdk_library/public/foo-stubs.jar"],
  428. stub_srcs: ["sdk_library/public/foo_stub_sources"],
  429. current_api: "sdk_library/public/foo.txt",
  430. removed_api: "sdk_library/public/foo-removed.txt",
  431. sdk_version: "current",
  432. },
  433. apex_available: ["myapex"],
  434. }
  435. // This always depends on the source foo module, its dependencies are not affected by the
  436. // AlwaysUsePrebuiltSdks().
  437. bootclasspath_fragment {
  438. name: "mybootclasspath-fragment",
  439. apex_available: [
  440. "myapex",
  441. ],
  442. contents: [
  443. "foo", "bar",
  444. ],
  445. hidden_api: {
  446. split_packages: ["*"],
  447. },
  448. }
  449. prebuilt_bootclasspath_fragment {
  450. name: "mybootclasspath-fragment",
  451. apex_available: [
  452. "myapex",
  453. ],
  454. contents: [
  455. "foo",
  456. ],
  457. hidden_api: {
  458. stub_flags: "",
  459. annotation_flags: "",
  460. metadata: "",
  461. index: "",
  462. all_flags: "",
  463. },
  464. }
  465. platform_bootclasspath {
  466. name: "myplatform-bootclasspath",
  467. fragments: [
  468. {
  469. apex: "myapex",
  470. module:"mybootclasspath-fragment",
  471. },
  472. ],
  473. }
  474. `,
  475. )
  476. java.CheckPlatformBootclasspathModules(t, result, "myplatform-bootclasspath", []string{
  477. // The configured contents of BootJars.
  478. "myapex:prebuilt_foo",
  479. "myapex:bar",
  480. })
  481. // Make sure that the myplatform-bootclasspath has the correct dependencies.
  482. CheckModuleDependencies(t, result.TestContext, "myplatform-bootclasspath", "android_common", []string{
  483. // The following are stubs.
  484. "platform:prebuilt_sdk_public_current_android",
  485. "platform:prebuilt_sdk_system_current_android",
  486. "platform:prebuilt_sdk_test_current_android",
  487. // Not a prebuilt as no prebuilt existed when it was added.
  488. "platform:legacy.core.platform.api.stubs",
  489. // The platform_bootclasspath intentionally adds dependencies on both source and prebuilt
  490. // modules when available as it does not know which one will be preferred.
  491. "myapex:foo",
  492. "myapex:prebuilt_foo",
  493. // Only a source module exists.
  494. "myapex:bar",
  495. // The fragments.
  496. "myapex:mybootclasspath-fragment",
  497. "myapex:prebuilt_mybootclasspath-fragment",
  498. })
  499. }
  500. // CheckModuleDependencies checks the dependencies of the selected module against the expected list.
  501. //
  502. // The expected list must be a list of strings of the form "<apex>:<module>", where <apex> is the
  503. // name of the apex, or platform is it is not part of an apex and <module> is the module name.
  504. func CheckModuleDependencies(t *testing.T, ctx *android.TestContext, name, variant string, expected []string) {
  505. t.Helper()
  506. module := ctx.ModuleForTests(name, variant).Module()
  507. modules := []android.Module{}
  508. ctx.VisitDirectDeps(module, func(m blueprint.Module) {
  509. modules = append(modules, m.(android.Module))
  510. })
  511. pairs := java.ApexNamePairsFromModules(ctx, modules)
  512. android.AssertDeepEquals(t, "module dependencies", expected, pairs)
  513. }
  514. // TestPlatformBootclasspath_IncludesRemainingApexJars verifies that any apex boot jar is present in
  515. // platform_bootclasspath's classpaths.proto config, if the apex does not generate its own config
  516. // by setting generate_classpaths_proto property to false.
  517. func TestPlatformBootclasspath_IncludesRemainingApexJars(t *testing.T) {
  518. result := android.GroupFixturePreparers(
  519. prepareForTestWithPlatformBootclasspath,
  520. prepareForTestWithMyapex,
  521. java.FixtureConfigureApexBootJars("myapex:foo"),
  522. android.FixtureWithRootAndroidBp(`
  523. platform_bootclasspath {
  524. name: "platform-bootclasspath",
  525. fragments: [
  526. {
  527. apex: "myapex",
  528. module:"foo-fragment",
  529. },
  530. ],
  531. }
  532. apex {
  533. name: "myapex",
  534. key: "myapex.key",
  535. bootclasspath_fragments: ["foo-fragment"],
  536. updatable: false,
  537. }
  538. apex_key {
  539. name: "myapex.key",
  540. public_key: "testkey.avbpubkey",
  541. private_key: "testkey.pem",
  542. }
  543. bootclasspath_fragment {
  544. name: "foo-fragment",
  545. generate_classpaths_proto: false,
  546. contents: ["foo"],
  547. apex_available: ["myapex"],
  548. hidden_api: {
  549. split_packages: ["*"],
  550. },
  551. }
  552. java_library {
  553. name: "foo",
  554. srcs: ["a.java"],
  555. system_modules: "none",
  556. sdk_version: "none",
  557. compile_dex: true,
  558. apex_available: ["myapex"],
  559. permitted_packages: ["foo"],
  560. }
  561. `),
  562. ).RunTest(t)
  563. java.CheckClasspathFragmentProtoContentInfoProvider(t, result,
  564. true, // proto should be generated
  565. "myapex:foo", // apex doesn't generate its own config, so must be in platform_bootclasspath
  566. "bootclasspath.pb",
  567. "out/soong/target/product/test_device/system/etc/classpaths",
  568. )
  569. }
  570. func TestBootJarNotInApex(t *testing.T) {
  571. android.GroupFixturePreparers(
  572. prepareForTestWithPlatformBootclasspath,
  573. PrepareForTestWithApexBuildComponents,
  574. prepareForTestWithMyapex,
  575. java.FixtureConfigureApexBootJars("myapex:foo"),
  576. ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
  577. `dependency "foo" of "myplatform-bootclasspath" missing variant`)).
  578. RunTestWithBp(t, `
  579. apex {
  580. name: "myapex",
  581. key: "myapex.key",
  582. updatable: false,
  583. }
  584. apex_key {
  585. name: "myapex.key",
  586. public_key: "testkey.avbpubkey",
  587. private_key: "testkey.pem",
  588. }
  589. java_library {
  590. name: "foo",
  591. srcs: ["b.java"],
  592. installable: true,
  593. apex_available: [
  594. "myapex",
  595. ],
  596. }
  597. bootclasspath_fragment {
  598. name: "not-in-apex-fragment",
  599. contents: [
  600. "foo",
  601. ],
  602. hidden_api: {
  603. split_packages: ["*"],
  604. },
  605. }
  606. platform_bootclasspath {
  607. name: "myplatform-bootclasspath",
  608. }
  609. `)
  610. }
  611. func TestBootFragmentNotInApex(t *testing.T) {
  612. android.GroupFixturePreparers(
  613. prepareForTestWithPlatformBootclasspath,
  614. PrepareForTestWithApexBuildComponents,
  615. prepareForTestWithMyapex,
  616. java.FixtureConfigureApexBootJars("myapex:foo"),
  617. ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
  618. `library foo.*have no corresponding fragment.*`)).RunTestWithBp(t, `
  619. apex {
  620. name: "myapex",
  621. key: "myapex.key",
  622. java_libs: ["foo"],
  623. updatable: false,
  624. }
  625. apex_key {
  626. name: "myapex.key",
  627. public_key: "testkey.avbpubkey",
  628. private_key: "testkey.pem",
  629. }
  630. java_library {
  631. name: "foo",
  632. srcs: ["b.java"],
  633. installable: true,
  634. apex_available: ["myapex"],
  635. permitted_packages: ["foo"],
  636. }
  637. bootclasspath_fragment {
  638. name: "not-in-apex-fragment",
  639. contents: ["foo"],
  640. hidden_api: {
  641. split_packages: ["*"],
  642. },
  643. }
  644. platform_bootclasspath {
  645. name: "myplatform-bootclasspath",
  646. }
  647. `)
  648. }
  649. func TestNonBootJarInFragment(t *testing.T) {
  650. android.GroupFixturePreparers(
  651. prepareForTestWithPlatformBootclasspath,
  652. PrepareForTestWithApexBuildComponents,
  653. prepareForTestWithMyapex,
  654. java.FixtureConfigureApexBootJars("myapex:foo"),
  655. ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
  656. `in contents must also be declared in PRODUCT_APEX_BOOT_JARS`)).
  657. RunTestWithBp(t, `
  658. apex {
  659. name: "myapex",
  660. key: "myapex.key",
  661. bootclasspath_fragments: ["apex-fragment"],
  662. updatable: false,
  663. }
  664. apex_key {
  665. name: "myapex.key",
  666. public_key: "testkey.avbpubkey",
  667. private_key: "testkey.pem",
  668. }
  669. java_library {
  670. name: "foo",
  671. srcs: ["b.java"],
  672. installable: true,
  673. apex_available: ["myapex"],
  674. permitted_packages: ["foo"],
  675. }
  676. java_library {
  677. name: "bar",
  678. srcs: ["b.java"],
  679. installable: true,
  680. apex_available: ["myapex"],
  681. permitted_packages: ["bar"],
  682. }
  683. bootclasspath_fragment {
  684. name: "apex-fragment",
  685. contents: ["foo", "bar"],
  686. apex_available:[ "myapex" ],
  687. hidden_api: {
  688. split_packages: ["*"],
  689. },
  690. }
  691. platform_bootclasspath {
  692. name: "myplatform-bootclasspath",
  693. fragments: [{
  694. apex: "myapex",
  695. module:"apex-fragment",
  696. }],
  697. }
  698. `)
  699. }