apex_conversion_test.go 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595
  1. // Copyright 2021 Google Inc. All rights reserved.
  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 bp2build
  15. import (
  16. "android/soong/android"
  17. "android/soong/apex"
  18. "android/soong/cc"
  19. "android/soong/etc"
  20. "android/soong/java"
  21. "android/soong/sh"
  22. "fmt"
  23. "testing"
  24. )
  25. func runApexTestCase(t *testing.T, tc Bp2buildTestCase) {
  26. t.Helper()
  27. RunBp2BuildTestCase(t, registerApexModuleTypes, tc)
  28. }
  29. func registerApexModuleTypes(ctx android.RegistrationContext) {
  30. // CC module types needed as they can be APEX dependencies
  31. cc.RegisterCCBuildComponents(ctx)
  32. ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory)
  33. ctx.RegisterModuleType("cc_binary", cc.BinaryFactory)
  34. ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
  35. ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory)
  36. ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory)
  37. ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
  38. ctx.RegisterModuleType("prebuilt_etc", etc.PrebuiltEtcFactory)
  39. ctx.RegisterModuleType("cc_test", cc.TestFactory)
  40. }
  41. func runOverrideApexTestCase(t *testing.T, tc Bp2buildTestCase) {
  42. t.Helper()
  43. RunBp2BuildTestCase(t, registerOverrideApexModuleTypes, tc)
  44. }
  45. func registerOverrideApexModuleTypes(ctx android.RegistrationContext) {
  46. // CC module types needed as they can be APEX dependencies
  47. cc.RegisterCCBuildComponents(ctx)
  48. ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory)
  49. ctx.RegisterModuleType("cc_binary", cc.BinaryFactory)
  50. ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
  51. ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory)
  52. ctx.RegisterModuleType("apex_test", apex.TestApexBundleFactory)
  53. ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory)
  54. ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
  55. ctx.RegisterModuleType("apex", apex.BundleFactory)
  56. ctx.RegisterModuleType("apex_defaults", apex.DefaultsFactory)
  57. ctx.RegisterModuleType("prebuilt_etc", etc.PrebuiltEtcFactory)
  58. ctx.RegisterModuleType("soong_config_module_type", android.SoongConfigModuleTypeFactory)
  59. ctx.RegisterModuleType("soong_config_string_variable", android.SoongConfigStringVariableDummyFactory)
  60. }
  61. func TestApexBundleSimple(t *testing.T) {
  62. runApexTestCase(t, Bp2buildTestCase{
  63. Description: "apex - example with all props, file_context is a module in same Android.bp",
  64. ModuleTypeUnderTest: "apex",
  65. ModuleTypeUnderTestFactory: apex.BundleFactory,
  66. Filesystem: map[string]string{},
  67. Blueprint: `
  68. apex_key {
  69. name: "com.android.apogee.key",
  70. public_key: "com.android.apogee.avbpubkey",
  71. private_key: "com.android.apogee.pem",
  72. bazel_module: { bp2build_available: false },
  73. }
  74. android_app_certificate {
  75. name: "com.android.apogee.certificate",
  76. certificate: "com.android.apogee",
  77. bazel_module: { bp2build_available: false },
  78. }
  79. cc_library {
  80. name: "native_shared_lib_1",
  81. bazel_module: { bp2build_available: false },
  82. }
  83. cc_library {
  84. name: "native_shared_lib_2",
  85. bazel_module: { bp2build_available: false },
  86. }
  87. prebuilt_etc {
  88. name: "prebuilt_1",
  89. bazel_module: { bp2build_available: false },
  90. }
  91. prebuilt_etc {
  92. name: "prebuilt_2",
  93. bazel_module: { bp2build_available: false },
  94. }
  95. filegroup {
  96. name: "com.android.apogee-file_contexts",
  97. srcs: [
  98. "com.android.apogee-file_contexts",
  99. ],
  100. bazel_module: { bp2build_available: false },
  101. }
  102. cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } }
  103. sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } }
  104. apex {
  105. name: "com.android.apogee",
  106. manifest: "apogee_manifest.json",
  107. androidManifest: "ApogeeAndroidManifest.xml",
  108. apex_available_name: "apogee_apex_name",
  109. file_contexts: ":com.android.apogee-file_contexts",
  110. min_sdk_version: "29",
  111. key: "com.android.apogee.key",
  112. certificate: ":com.android.apogee.certificate",
  113. updatable: false,
  114. installable: false,
  115. compressible: false,
  116. native_shared_libs: [
  117. "native_shared_lib_1",
  118. "native_shared_lib_2",
  119. ],
  120. binaries: [
  121. "cc_binary_1",
  122. "sh_binary_2",
  123. ],
  124. prebuilts: [
  125. "prebuilt_1",
  126. "prebuilt_2",
  127. ],
  128. package_name: "com.android.apogee.test.package",
  129. logging_parent: "logging.parent",
  130. variant_version: "3",
  131. }
  132. `,
  133. ExpectedBazelTargets: []string{
  134. MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
  135. "android_manifest": `"ApogeeAndroidManifest.xml"`,
  136. "apex_available_name": `"apogee_apex_name"`,
  137. "binaries": `[
  138. ":cc_binary_1",
  139. ":sh_binary_2",
  140. ]`,
  141. "certificate": `":com.android.apogee.certificate"`,
  142. "file_contexts": `":com.android.apogee-file_contexts"`,
  143. "installable": "False",
  144. "key": `":com.android.apogee.key"`,
  145. "manifest": `"apogee_manifest.json"`,
  146. "min_sdk_version": `"29"`,
  147. "native_shared_libs_32": `select({
  148. "//build/bazel/platforms/arch:arm": [
  149. ":native_shared_lib_1",
  150. ":native_shared_lib_2",
  151. ],
  152. "//build/bazel/platforms/arch:x86": [
  153. ":native_shared_lib_1",
  154. ":native_shared_lib_2",
  155. ],
  156. "//conditions:default": [],
  157. })`,
  158. "native_shared_libs_64": `select({
  159. "//build/bazel/platforms/arch:arm64": [
  160. ":native_shared_lib_1",
  161. ":native_shared_lib_2",
  162. ],
  163. "//build/bazel/platforms/arch:x86_64": [
  164. ":native_shared_lib_1",
  165. ":native_shared_lib_2",
  166. ],
  167. "//conditions:default": [],
  168. })`,
  169. "prebuilts": `[
  170. ":prebuilt_1",
  171. ":prebuilt_2",
  172. ]`,
  173. "updatable": "False",
  174. "compressible": "False",
  175. "package_name": `"com.android.apogee.test.package"`,
  176. "logging_parent": `"logging.parent"`,
  177. "variant_version": `"3"`,
  178. }),
  179. }})
  180. }
  181. func TestApexBundleSimple_fileContextsInAnotherAndroidBp(t *testing.T) {
  182. runApexTestCase(t, Bp2buildTestCase{
  183. Description: "apex - file contexts is a module in another Android.bp",
  184. ModuleTypeUnderTest: "apex",
  185. ModuleTypeUnderTestFactory: apex.BundleFactory,
  186. Filesystem: map[string]string{
  187. "a/b/Android.bp": `
  188. filegroup {
  189. name: "com.android.apogee-file_contexts",
  190. srcs: [
  191. "com.android.apogee-file_contexts",
  192. ],
  193. bazel_module: { bp2build_available: false },
  194. }
  195. `,
  196. },
  197. Blueprint: `
  198. apex {
  199. name: "com.android.apogee",
  200. file_contexts: ":com.android.apogee-file_contexts",
  201. }
  202. `,
  203. ExpectedBazelTargets: []string{
  204. MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
  205. "file_contexts": `"//a/b:com.android.apogee-file_contexts"`,
  206. "manifest": `"apex_manifest.json"`,
  207. }),
  208. }})
  209. }
  210. func TestApexBundleSimple_fileContextsIsFile(t *testing.T) {
  211. runApexTestCase(t, Bp2buildTestCase{
  212. Description: "apex - file contexts is a file",
  213. ModuleTypeUnderTest: "apex",
  214. ModuleTypeUnderTestFactory: apex.BundleFactory,
  215. Filesystem: map[string]string{},
  216. Blueprint: `
  217. apex {
  218. name: "com.android.apogee",
  219. file_contexts: "file_contexts_file",
  220. }
  221. `,
  222. ExpectedBazelTargets: []string{
  223. MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
  224. "file_contexts": `"file_contexts_file"`,
  225. "manifest": `"apex_manifest.json"`,
  226. }),
  227. }})
  228. }
  229. func TestApexBundleSimple_fileContextsIsNotSpecified(t *testing.T) {
  230. runApexTestCase(t, Bp2buildTestCase{
  231. Description: "apex - file contexts is not specified",
  232. ModuleTypeUnderTest: "apex",
  233. ModuleTypeUnderTestFactory: apex.BundleFactory,
  234. Filesystem: map[string]string{
  235. "system/sepolicy/apex/Android.bp": `
  236. filegroup {
  237. name: "com.android.apogee-file_contexts",
  238. srcs: [
  239. "com.android.apogee-file_contexts",
  240. ],
  241. bazel_module: { bp2build_available: false },
  242. }
  243. `,
  244. },
  245. Blueprint: `
  246. apex {
  247. name: "com.android.apogee",
  248. }
  249. `,
  250. ExpectedBazelTargets: []string{
  251. MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
  252. "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
  253. "manifest": `"apex_manifest.json"`,
  254. }),
  255. }})
  256. }
  257. func TestApexBundleCompileMultilibBoth(t *testing.T) {
  258. runApexTestCase(t, Bp2buildTestCase{
  259. Description: "apex - example with compile_multilib=both",
  260. ModuleTypeUnderTest: "apex",
  261. ModuleTypeUnderTestFactory: apex.BundleFactory,
  262. Filesystem: map[string]string{
  263. "system/sepolicy/apex/Android.bp": `
  264. filegroup {
  265. name: "com.android.apogee-file_contexts",
  266. srcs: [ "apogee-file_contexts", ],
  267. bazel_module: { bp2build_available: false },
  268. }
  269. `,
  270. },
  271. Blueprint: createMultilibBlueprint(`compile_multilib: "both",`),
  272. ExpectedBazelTargets: []string{
  273. MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
  274. "native_shared_libs_32": `[
  275. ":unnested_native_shared_lib",
  276. ":native_shared_lib_for_both",
  277. ":native_shared_lib_for_lib32",
  278. ] + select({
  279. "//build/bazel/platforms/arch:arm": [":native_shared_lib_for_first"],
  280. "//build/bazel/platforms/arch:x86": [":native_shared_lib_for_first"],
  281. "//conditions:default": [],
  282. })`,
  283. "native_shared_libs_64": `select({
  284. "//build/bazel/platforms/arch:arm64": [
  285. ":unnested_native_shared_lib",
  286. ":native_shared_lib_for_both",
  287. ":native_shared_lib_for_lib64",
  288. ":native_shared_lib_for_first",
  289. ],
  290. "//build/bazel/platforms/arch:x86_64": [
  291. ":unnested_native_shared_lib",
  292. ":native_shared_lib_for_both",
  293. ":native_shared_lib_for_lib64",
  294. ":native_shared_lib_for_first",
  295. ],
  296. "//conditions:default": [],
  297. })`,
  298. "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
  299. "manifest": `"apex_manifest.json"`,
  300. }),
  301. }})
  302. }
  303. func TestApexBundleCompileMultilibFirstAndDefaultValue(t *testing.T) {
  304. expectedBazelTargets := []string{
  305. MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
  306. "native_shared_libs_32": `select({
  307. "//build/bazel/platforms/arch:arm": [
  308. ":unnested_native_shared_lib",
  309. ":native_shared_lib_for_both",
  310. ":native_shared_lib_for_lib32",
  311. ":native_shared_lib_for_first",
  312. ],
  313. "//build/bazel/platforms/arch:x86": [
  314. ":unnested_native_shared_lib",
  315. ":native_shared_lib_for_both",
  316. ":native_shared_lib_for_lib32",
  317. ":native_shared_lib_for_first",
  318. ],
  319. "//conditions:default": [],
  320. })`,
  321. "native_shared_libs_64": `select({
  322. "//build/bazel/platforms/arch:arm64": [
  323. ":unnested_native_shared_lib",
  324. ":native_shared_lib_for_both",
  325. ":native_shared_lib_for_lib64",
  326. ":native_shared_lib_for_first",
  327. ],
  328. "//build/bazel/platforms/arch:x86_64": [
  329. ":unnested_native_shared_lib",
  330. ":native_shared_lib_for_both",
  331. ":native_shared_lib_for_lib64",
  332. ":native_shared_lib_for_first",
  333. ],
  334. "//conditions:default": [],
  335. })`,
  336. "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
  337. "manifest": `"apex_manifest.json"`,
  338. }),
  339. }
  340. // "first" is the default value of compile_multilib prop so `compile_multilib_: "first"` and unset compile_multilib
  341. // should result to the same bp2build output
  342. compileMultiLibPropValues := []string{`compile_multilib: "first",`, ""}
  343. for _, compileMultiLibProp := range compileMultiLibPropValues {
  344. descriptionSuffix := compileMultiLibProp
  345. if descriptionSuffix == "" {
  346. descriptionSuffix = "compile_multilib unset"
  347. }
  348. runApexTestCase(t, Bp2buildTestCase{
  349. Description: "apex - example with " + compileMultiLibProp,
  350. ModuleTypeUnderTest: "apex",
  351. ModuleTypeUnderTestFactory: apex.BundleFactory,
  352. Filesystem: map[string]string{
  353. "system/sepolicy/apex/Android.bp": `
  354. filegroup {
  355. name: "com.android.apogee-file_contexts",
  356. srcs: [ "apogee-file_contexts", ],
  357. bazel_module: { bp2build_available: false },
  358. }
  359. `,
  360. },
  361. Blueprint: createMultilibBlueprint(compileMultiLibProp),
  362. ExpectedBazelTargets: expectedBazelTargets,
  363. })
  364. }
  365. }
  366. func TestApexBundleCompileMultilib32(t *testing.T) {
  367. runApexTestCase(t, Bp2buildTestCase{
  368. Description: "apex - example with compile_multilib=32",
  369. ModuleTypeUnderTest: "apex",
  370. ModuleTypeUnderTestFactory: apex.BundleFactory,
  371. Filesystem: map[string]string{
  372. "system/sepolicy/apex/Android.bp": `
  373. filegroup {
  374. name: "com.android.apogee-file_contexts",
  375. srcs: [ "apogee-file_contexts", ],
  376. bazel_module: { bp2build_available: false },
  377. }
  378. `,
  379. },
  380. Blueprint: createMultilibBlueprint(`compile_multilib: "32",`),
  381. ExpectedBazelTargets: []string{
  382. MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
  383. "native_shared_libs_32": `[
  384. ":unnested_native_shared_lib",
  385. ":native_shared_lib_for_both",
  386. ":native_shared_lib_for_lib32",
  387. ] + select({
  388. "//build/bazel/platforms/arch:arm": [":native_shared_lib_for_first"],
  389. "//build/bazel/platforms/arch:x86": [":native_shared_lib_for_first"],
  390. "//conditions:default": [],
  391. })`,
  392. "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
  393. "manifest": `"apex_manifest.json"`,
  394. }),
  395. }})
  396. }
  397. func TestApexBundleCompileMultilib64(t *testing.T) {
  398. runApexTestCase(t, Bp2buildTestCase{
  399. Description: "apex - example with compile_multilib=64",
  400. ModuleTypeUnderTest: "apex",
  401. ModuleTypeUnderTestFactory: apex.BundleFactory,
  402. Filesystem: map[string]string{
  403. "system/sepolicy/apex/Android.bp": `
  404. filegroup {
  405. name: "com.android.apogee-file_contexts",
  406. srcs: [ "apogee-file_contexts", ],
  407. bazel_module: { bp2build_available: false },
  408. }
  409. `,
  410. },
  411. Blueprint: createMultilibBlueprint(`compile_multilib: "64",`),
  412. ExpectedBazelTargets: []string{
  413. MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
  414. "native_shared_libs_64": `select({
  415. "//build/bazel/platforms/arch:arm64": [
  416. ":unnested_native_shared_lib",
  417. ":native_shared_lib_for_both",
  418. ":native_shared_lib_for_lib64",
  419. ":native_shared_lib_for_first",
  420. ],
  421. "//build/bazel/platforms/arch:x86_64": [
  422. ":unnested_native_shared_lib",
  423. ":native_shared_lib_for_both",
  424. ":native_shared_lib_for_lib64",
  425. ":native_shared_lib_for_first",
  426. ],
  427. "//conditions:default": [],
  428. })`,
  429. "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
  430. "manifest": `"apex_manifest.json"`,
  431. }),
  432. }})
  433. }
  434. func createMultilibBlueprint(compile_multilib string) string {
  435. return fmt.Sprintf(`
  436. cc_library {
  437. name: "native_shared_lib_for_both",
  438. bazel_module: { bp2build_available: false },
  439. }
  440. cc_library {
  441. name: "native_shared_lib_for_first",
  442. bazel_module: { bp2build_available: false },
  443. }
  444. cc_library {
  445. name: "native_shared_lib_for_lib32",
  446. bazel_module: { bp2build_available: false },
  447. }
  448. cc_library {
  449. name: "native_shared_lib_for_lib64",
  450. bazel_module: { bp2build_available: false },
  451. }
  452. cc_library {
  453. name: "unnested_native_shared_lib",
  454. bazel_module: { bp2build_available: false },
  455. }
  456. apex {
  457. name: "com.android.apogee",
  458. %s
  459. native_shared_libs: ["unnested_native_shared_lib"],
  460. multilib: {
  461. both: {
  462. native_shared_libs: [
  463. "native_shared_lib_for_both",
  464. ],
  465. },
  466. first: {
  467. native_shared_libs: [
  468. "native_shared_lib_for_first",
  469. ],
  470. },
  471. lib32: {
  472. native_shared_libs: [
  473. "native_shared_lib_for_lib32",
  474. ],
  475. },
  476. lib64: {
  477. native_shared_libs: [
  478. "native_shared_lib_for_lib64",
  479. ],
  480. },
  481. },
  482. }`, compile_multilib)
  483. }
  484. func TestApexBundleDefaultPropertyValues(t *testing.T) {
  485. runApexTestCase(t, Bp2buildTestCase{
  486. Description: "apex - default property values",
  487. ModuleTypeUnderTest: "apex",
  488. ModuleTypeUnderTestFactory: apex.BundleFactory,
  489. Filesystem: map[string]string{
  490. "system/sepolicy/apex/Android.bp": `
  491. filegroup {
  492. name: "com.android.apogee-file_contexts",
  493. srcs: [ "apogee-file_contexts", ],
  494. bazel_module: { bp2build_available: false },
  495. }
  496. `,
  497. },
  498. Blueprint: `
  499. apex {
  500. name: "com.android.apogee",
  501. manifest: "apogee_manifest.json",
  502. }
  503. `,
  504. ExpectedBazelTargets: []string{MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
  505. "manifest": `"apogee_manifest.json"`,
  506. "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
  507. }),
  508. }})
  509. }
  510. func TestApexBundleHasBazelModuleProps(t *testing.T) {
  511. runApexTestCase(t, Bp2buildTestCase{
  512. Description: "apex - has bazel module props",
  513. ModuleTypeUnderTest: "apex",
  514. ModuleTypeUnderTestFactory: apex.BundleFactory,
  515. Filesystem: map[string]string{
  516. "system/sepolicy/apex/Android.bp": `
  517. filegroup {
  518. name: "apogee-file_contexts",
  519. srcs: [ "apogee-file_contexts", ],
  520. bazel_module: { bp2build_available: false },
  521. }
  522. `,
  523. },
  524. Blueprint: `
  525. apex {
  526. name: "apogee",
  527. manifest: "manifest.json",
  528. bazel_module: { bp2build_available: true },
  529. }
  530. `,
  531. ExpectedBazelTargets: []string{MakeBazelTarget("apex", "apogee", AttrNameToString{
  532. "manifest": `"manifest.json"`,
  533. "file_contexts": `"//system/sepolicy/apex:apogee-file_contexts"`,
  534. }),
  535. }})
  536. }
  537. func TestBp2BuildOverrideApex(t *testing.T) {
  538. runOverrideApexTestCase(t, Bp2buildTestCase{
  539. Description: "override_apex",
  540. ModuleTypeUnderTest: "override_apex",
  541. ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
  542. Filesystem: map[string]string{},
  543. Blueprint: `
  544. apex_key {
  545. name: "com.android.apogee.key",
  546. public_key: "com.android.apogee.avbpubkey",
  547. private_key: "com.android.apogee.pem",
  548. bazel_module: { bp2build_available: false },
  549. }
  550. android_app_certificate {
  551. name: "com.android.apogee.certificate",
  552. certificate: "com.android.apogee",
  553. bazel_module: { bp2build_available: false },
  554. }
  555. cc_library {
  556. name: "native_shared_lib_1",
  557. bazel_module: { bp2build_available: false },
  558. }
  559. cc_library {
  560. name: "native_shared_lib_2",
  561. bazel_module: { bp2build_available: false },
  562. }
  563. prebuilt_etc {
  564. name: "prebuilt_1",
  565. bazel_module: { bp2build_available: false },
  566. }
  567. prebuilt_etc {
  568. name: "prebuilt_2",
  569. bazel_module: { bp2build_available: false },
  570. }
  571. filegroup {
  572. name: "com.android.apogee-file_contexts",
  573. srcs: [
  574. "com.android.apogee-file_contexts",
  575. ],
  576. bazel_module: { bp2build_available: false },
  577. }
  578. cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } }
  579. sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } }
  580. apex {
  581. name: "com.android.apogee",
  582. manifest: "apogee_manifest.json",
  583. androidManifest: "ApogeeAndroidManifest.xml",
  584. file_contexts: ":com.android.apogee-file_contexts",
  585. min_sdk_version: "29",
  586. key: "com.android.apogee.key",
  587. certificate: ":com.android.apogee.certificate",
  588. updatable: false,
  589. installable: false,
  590. compressible: false,
  591. native_shared_libs: [
  592. "native_shared_lib_1",
  593. "native_shared_lib_2",
  594. ],
  595. binaries: [
  596. "cc_binary_1",
  597. "sh_binary_2",
  598. ],
  599. prebuilts: [
  600. "prebuilt_1",
  601. "prebuilt_2",
  602. ],
  603. bazel_module: { bp2build_available: false },
  604. }
  605. apex_key {
  606. name: "com.google.android.apogee.key",
  607. public_key: "com.google.android.apogee.avbpubkey",
  608. private_key: "com.google.android.apogee.pem",
  609. bazel_module: { bp2build_available: false },
  610. }
  611. android_app_certificate {
  612. name: "com.google.android.apogee.certificate",
  613. certificate: "com.google.android.apogee",
  614. bazel_module: { bp2build_available: false },
  615. }
  616. override_apex {
  617. name: "com.google.android.apogee",
  618. base: ":com.android.apogee",
  619. key: "com.google.android.apogee.key",
  620. certificate: ":com.google.android.apogee.certificate",
  621. prebuilts: [],
  622. compressible: true,
  623. }
  624. `,
  625. ExpectedBazelTargets: []string{
  626. MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
  627. "android_manifest": `"ApogeeAndroidManifest.xml"`,
  628. "base_apex_name": `"com.android.apogee"`,
  629. "binaries": `[
  630. ":cc_binary_1",
  631. ":sh_binary_2",
  632. ]`,
  633. "certificate": `":com.google.android.apogee.certificate"`,
  634. "file_contexts": `":com.android.apogee-file_contexts"`,
  635. "installable": "False",
  636. "key": `":com.google.android.apogee.key"`,
  637. "manifest": `"apogee_manifest.json"`,
  638. "min_sdk_version": `"29"`,
  639. "native_shared_libs_32": `select({
  640. "//build/bazel/platforms/arch:arm": [
  641. ":native_shared_lib_1",
  642. ":native_shared_lib_2",
  643. ],
  644. "//build/bazel/platforms/arch:x86": [
  645. ":native_shared_lib_1",
  646. ":native_shared_lib_2",
  647. ],
  648. "//conditions:default": [],
  649. })`,
  650. "native_shared_libs_64": `select({
  651. "//build/bazel/platforms/arch:arm64": [
  652. ":native_shared_lib_1",
  653. ":native_shared_lib_2",
  654. ],
  655. "//build/bazel/platforms/arch:x86_64": [
  656. ":native_shared_lib_1",
  657. ":native_shared_lib_2",
  658. ],
  659. "//conditions:default": [],
  660. })`,
  661. "prebuilts": `[]`,
  662. "updatable": "False",
  663. "compressible": "True",
  664. }),
  665. }})
  666. }
  667. func TestOverrideApexTest(t *testing.T) {
  668. runOverrideApexTestCase(t, Bp2buildTestCase{
  669. Description: "override_apex",
  670. ModuleTypeUnderTest: "override_apex",
  671. ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
  672. Filesystem: map[string]string{},
  673. Blueprint: `
  674. apex_key {
  675. name: "com.android.apogee.key",
  676. public_key: "com.android.apogee.avbpubkey",
  677. private_key: "com.android.apogee.pem",
  678. bazel_module: { bp2build_available: false },
  679. }
  680. android_app_certificate {
  681. name: "com.android.apogee.certificate",
  682. certificate: "com.android.apogee",
  683. bazel_module: { bp2build_available: false },
  684. }
  685. cc_library {
  686. name: "native_shared_lib_1",
  687. bazel_module: { bp2build_available: false },
  688. }
  689. prebuilt_etc {
  690. name: "prebuilt_1",
  691. bazel_module: { bp2build_available: false },
  692. }
  693. filegroup {
  694. name: "com.android.apogee-file_contexts",
  695. srcs: [
  696. "com.android.apogee-file_contexts",
  697. ],
  698. bazel_module: { bp2build_available: false },
  699. }
  700. cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } }
  701. sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } }
  702. apex_test {
  703. name: "com.android.apogee",
  704. manifest: "apogee_manifest.json",
  705. androidManifest: "ApogeeAndroidManifest.xml",
  706. file_contexts: ":com.android.apogee-file_contexts",
  707. min_sdk_version: "29",
  708. key: "com.android.apogee.key",
  709. certificate: ":com.android.apogee.certificate",
  710. updatable: false,
  711. installable: false,
  712. compressible: false,
  713. native_shared_libs: [
  714. "native_shared_lib_1",
  715. ],
  716. binaries: [
  717. "cc_binary_1",
  718. "sh_binary_2",
  719. ],
  720. prebuilts: [
  721. "prebuilt_1",
  722. ],
  723. bazel_module: { bp2build_available: false },
  724. }
  725. apex_key {
  726. name: "com.google.android.apogee.key",
  727. public_key: "com.google.android.apogee.avbpubkey",
  728. private_key: "com.google.android.apogee.pem",
  729. bazel_module: { bp2build_available: false },
  730. }
  731. android_app_certificate {
  732. name: "com.google.android.apogee.certificate",
  733. certificate: "com.google.android.apogee",
  734. bazel_module: { bp2build_available: false },
  735. }
  736. override_apex {
  737. name: "com.google.android.apogee",
  738. base: ":com.android.apogee",
  739. key: "com.google.android.apogee.key",
  740. certificate: ":com.google.android.apogee.certificate",
  741. prebuilts: [],
  742. compressible: true,
  743. }
  744. `,
  745. ExpectedBazelTargets: []string{
  746. MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
  747. "android_manifest": `"ApogeeAndroidManifest.xml"`,
  748. "base_apex_name": `"com.android.apogee"`,
  749. "binaries": `[
  750. ":cc_binary_1",
  751. ":sh_binary_2",
  752. ]`,
  753. "certificate": `":com.google.android.apogee.certificate"`,
  754. "file_contexts": `":com.android.apogee-file_contexts"`,
  755. "installable": "False",
  756. "key": `":com.google.android.apogee.key"`,
  757. "manifest": `"apogee_manifest.json"`,
  758. "min_sdk_version": `"29"`,
  759. "native_shared_libs_32": `select({
  760. "//build/bazel/platforms/arch:arm": [":native_shared_lib_1"],
  761. "//build/bazel/platforms/arch:x86": [":native_shared_lib_1"],
  762. "//conditions:default": [],
  763. })`,
  764. "native_shared_libs_64": `select({
  765. "//build/bazel/platforms/arch:arm64": [":native_shared_lib_1"],
  766. "//build/bazel/platforms/arch:x86_64": [":native_shared_lib_1"],
  767. "//conditions:default": [],
  768. })`,
  769. "testonly": "True",
  770. "prebuilts": `[]`,
  771. "updatable": "False",
  772. "compressible": "True",
  773. }),
  774. }})
  775. }
  776. func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) {
  777. runOverrideApexTestCase(t, Bp2buildTestCase{
  778. Description: "override_apex - manifest of base apex is empty, base apex and override_apex is in different Android.bp",
  779. ModuleTypeUnderTest: "override_apex",
  780. ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
  781. Filesystem: map[string]string{
  782. "system/sepolicy/apex/Android.bp": `
  783. filegroup {
  784. name: "com.android.apogee-file_contexts",
  785. srcs: [ "apogee-file_contexts", ],
  786. bazel_module: { bp2build_available: false },
  787. }`,
  788. "a/b/Android.bp": `
  789. apex {
  790. name: "com.android.apogee",
  791. bazel_module: { bp2build_available: false },
  792. }
  793. `,
  794. },
  795. Blueprint: `
  796. override_apex {
  797. name: "com.google.android.apogee",
  798. base: ":com.android.apogee",
  799. }
  800. `,
  801. ExpectedBazelTargets: []string{
  802. MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
  803. "base_apex_name": `"com.android.apogee"`,
  804. "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
  805. "manifest": `"//a/b:apex_manifest.json"`,
  806. }),
  807. }})
  808. }
  809. func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) {
  810. runOverrideApexTestCase(t, Bp2buildTestCase{
  811. Description: "override_apex - manifest of base apex is set, base apex and override_apex is in different Android.bp",
  812. ModuleTypeUnderTest: "override_apex",
  813. ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
  814. Filesystem: map[string]string{
  815. "system/sepolicy/apex/Android.bp": `
  816. filegroup {
  817. name: "com.android.apogee-file_contexts",
  818. srcs: [ "apogee-file_contexts", ],
  819. bazel_module: { bp2build_available: false },
  820. }`,
  821. "a/b/Android.bp": `
  822. apex {
  823. name: "com.android.apogee",
  824. manifest: "apogee_manifest.json",
  825. bazel_module: { bp2build_available: false },
  826. }
  827. `,
  828. },
  829. Blueprint: `
  830. override_apex {
  831. name: "com.google.android.apogee",
  832. base: ":com.android.apogee",
  833. }
  834. `,
  835. ExpectedBazelTargets: []string{
  836. MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
  837. "base_apex_name": `"com.android.apogee"`,
  838. "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
  839. "manifest": `"//a/b:apogee_manifest.json"`,
  840. }),
  841. }})
  842. }
  843. func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
  844. runOverrideApexTestCase(t, Bp2buildTestCase{
  845. Description: "override_apex - manifest of base apex is empty, base apex and override_apex is in same Android.bp",
  846. ModuleTypeUnderTest: "override_apex",
  847. ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
  848. Filesystem: map[string]string{
  849. "system/sepolicy/apex/Android.bp": `
  850. filegroup {
  851. name: "com.android.apogee-file_contexts",
  852. srcs: [ "apogee-file_contexts", ],
  853. bazel_module: { bp2build_available: false },
  854. }`,
  855. },
  856. Blueprint: `
  857. apex {
  858. name: "com.android.apogee",
  859. bazel_module: { bp2build_available: false },
  860. }
  861. override_apex {
  862. name: "com.google.android.apogee",
  863. base: ":com.android.apogee",
  864. }
  865. `,
  866. ExpectedBazelTargets: []string{
  867. MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
  868. "base_apex_name": `"com.android.apogee"`,
  869. "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
  870. "manifest": `"apex_manifest.json"`,
  871. }),
  872. }})
  873. }
  874. func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
  875. runOverrideApexTestCase(t, Bp2buildTestCase{
  876. Description: "override_apex - manifest of base apex is set, base apex and override_apex is in same Android.bp",
  877. ModuleTypeUnderTest: "override_apex",
  878. ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
  879. Filesystem: map[string]string{
  880. "system/sepolicy/apex/Android.bp": `
  881. filegroup {
  882. name: "com.android.apogee-file_contexts",
  883. srcs: [ "apogee-file_contexts", ],
  884. bazel_module: { bp2build_available: false },
  885. }`,
  886. },
  887. Blueprint: `
  888. apex {
  889. name: "com.android.apogee",
  890. manifest: "apogee_manifest.json",
  891. bazel_module: { bp2build_available: false },
  892. }
  893. override_apex {
  894. name: "com.google.android.apogee",
  895. base: ":com.android.apogee",
  896. }
  897. `,
  898. ExpectedBazelTargets: []string{
  899. MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
  900. "base_apex_name": `"com.android.apogee"`,
  901. "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
  902. "manifest": `"apogee_manifest.json"`,
  903. }),
  904. }})
  905. }
  906. func TestApexBundleSimple_packageNameOverride(t *testing.T) {
  907. runOverrideApexTestCase(t, Bp2buildTestCase{
  908. Description: "override_apex - override package name",
  909. ModuleTypeUnderTest: "override_apex",
  910. ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
  911. Filesystem: map[string]string{
  912. "system/sepolicy/apex/Android.bp": `
  913. filegroup {
  914. name: "com.android.apogee-file_contexts",
  915. srcs: [ "apogee-file_contexts", ],
  916. bazel_module: { bp2build_available: false },
  917. }`,
  918. },
  919. Blueprint: `
  920. apex {
  921. name: "com.android.apogee",
  922. bazel_module: { bp2build_available: false },
  923. }
  924. override_apex {
  925. name: "com.google.android.apogee",
  926. base: ":com.android.apogee",
  927. package_name: "com.google.android.apogee",
  928. }
  929. `,
  930. ExpectedBazelTargets: []string{
  931. MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
  932. "base_apex_name": `"com.android.apogee"`,
  933. "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
  934. "manifest": `"apex_manifest.json"`,
  935. "package_name": `"com.google.android.apogee"`,
  936. }),
  937. }})
  938. }
  939. func TestApexBundleSimple_NoPrebuiltsOverride(t *testing.T) {
  940. runOverrideApexTestCase(t, Bp2buildTestCase{
  941. Description: "override_apex - no override",
  942. ModuleTypeUnderTest: "override_apex",
  943. ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
  944. Filesystem: map[string]string{
  945. "system/sepolicy/apex/Android.bp": `
  946. filegroup {
  947. name: "com.android.apogee-file_contexts",
  948. srcs: [ "apogee-file_contexts", ],
  949. bazel_module: { bp2build_available: false },
  950. }`,
  951. },
  952. Blueprint: `
  953. prebuilt_etc {
  954. name: "prebuilt_file",
  955. bazel_module: { bp2build_available: false },
  956. }
  957. apex {
  958. name: "com.android.apogee",
  959. bazel_module: { bp2build_available: false },
  960. prebuilts: ["prebuilt_file"]
  961. }
  962. override_apex {
  963. name: "com.google.android.apogee",
  964. base: ":com.android.apogee",
  965. }
  966. `,
  967. ExpectedBazelTargets: []string{
  968. MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
  969. "base_apex_name": `"com.android.apogee"`,
  970. "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
  971. "manifest": `"apex_manifest.json"`,
  972. "prebuilts": `[":prebuilt_file"]`,
  973. }),
  974. }})
  975. }
  976. func TestApexBundleSimple_PrebuiltsOverride(t *testing.T) {
  977. runOverrideApexTestCase(t, Bp2buildTestCase{
  978. Description: "override_apex - ooverride",
  979. ModuleTypeUnderTest: "override_apex",
  980. ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
  981. Filesystem: map[string]string{
  982. "system/sepolicy/apex/Android.bp": `
  983. filegroup {
  984. name: "com.android.apogee-file_contexts",
  985. srcs: [ "apogee-file_contexts", ],
  986. bazel_module: { bp2build_available: false },
  987. }`,
  988. },
  989. Blueprint: `
  990. prebuilt_etc {
  991. name: "prebuilt_file",
  992. bazel_module: { bp2build_available: false },
  993. }
  994. prebuilt_etc {
  995. name: "prebuilt_file2",
  996. bazel_module: { bp2build_available: false },
  997. }
  998. apex {
  999. name: "com.android.apogee",
  1000. bazel_module: { bp2build_available: false },
  1001. prebuilts: ["prebuilt_file"]
  1002. }
  1003. override_apex {
  1004. name: "com.google.android.apogee",
  1005. base: ":com.android.apogee",
  1006. prebuilts: ["prebuilt_file2"]
  1007. }
  1008. `,
  1009. ExpectedBazelTargets: []string{
  1010. MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
  1011. "base_apex_name": `"com.android.apogee"`,
  1012. "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
  1013. "manifest": `"apex_manifest.json"`,
  1014. "prebuilts": `[":prebuilt_file2"]`,
  1015. }),
  1016. }})
  1017. }
  1018. func TestApexBundleSimple_PrebuiltsOverrideEmptyList(t *testing.T) {
  1019. runOverrideApexTestCase(t, Bp2buildTestCase{
  1020. Description: "override_apex - override with empty list",
  1021. ModuleTypeUnderTest: "override_apex",
  1022. ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
  1023. Filesystem: map[string]string{
  1024. "system/sepolicy/apex/Android.bp": `
  1025. filegroup {
  1026. name: "com.android.apogee-file_contexts",
  1027. srcs: [ "apogee-file_contexts", ],
  1028. bazel_module: { bp2build_available: false },
  1029. }`,
  1030. },
  1031. Blueprint: `
  1032. prebuilt_etc {
  1033. name: "prebuilt_file",
  1034. bazel_module: { bp2build_available: false },
  1035. }
  1036. apex {
  1037. name: "com.android.apogee",
  1038. bazel_module: { bp2build_available: false },
  1039. prebuilts: ["prebuilt_file"]
  1040. }
  1041. override_apex {
  1042. name: "com.google.android.apogee",
  1043. base: ":com.android.apogee",
  1044. prebuilts: [],
  1045. }
  1046. `,
  1047. ExpectedBazelTargets: []string{
  1048. MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
  1049. "base_apex_name": `"com.android.apogee"`,
  1050. "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
  1051. "manifest": `"apex_manifest.json"`,
  1052. "prebuilts": `[]`,
  1053. }),
  1054. }})
  1055. }
  1056. func TestApexBundleSimple_NoLoggingParentOverride(t *testing.T) {
  1057. runOverrideApexTestCase(t, Bp2buildTestCase{
  1058. Description: "override_apex - logging_parent - no override",
  1059. ModuleTypeUnderTest: "override_apex",
  1060. ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
  1061. Filesystem: map[string]string{
  1062. "system/sepolicy/apex/Android.bp": `
  1063. filegroup {
  1064. name: "com.android.apogee-file_contexts",
  1065. srcs: [ "apogee-file_contexts", ],
  1066. bazel_module: { bp2build_available: false },
  1067. }`,
  1068. },
  1069. Blueprint: `
  1070. apex {
  1071. name: "com.android.apogee",
  1072. bazel_module: { bp2build_available: false },
  1073. logging_parent: "foo.bar.baz",
  1074. }
  1075. override_apex {
  1076. name: "com.google.android.apogee",
  1077. base: ":com.android.apogee",
  1078. }
  1079. `,
  1080. ExpectedBazelTargets: []string{
  1081. MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
  1082. "base_apex_name": `"com.android.apogee"`,
  1083. "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
  1084. "manifest": `"apex_manifest.json"`,
  1085. "logging_parent": `"foo.bar.baz"`,
  1086. }),
  1087. }})
  1088. }
  1089. func TestApexBundleSimple_LoggingParentOverride(t *testing.T) {
  1090. runOverrideApexTestCase(t, Bp2buildTestCase{
  1091. Description: "override_apex - logging_parent - override",
  1092. ModuleTypeUnderTest: "override_apex",
  1093. ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
  1094. Filesystem: map[string]string{
  1095. "system/sepolicy/apex/Android.bp": `
  1096. filegroup {
  1097. name: "com.android.apogee-file_contexts",
  1098. srcs: [ "apogee-file_contexts", ],
  1099. bazel_module: { bp2build_available: false },
  1100. }`,
  1101. },
  1102. Blueprint: `
  1103. apex {
  1104. name: "com.android.apogee",
  1105. bazel_module: { bp2build_available: false },
  1106. logging_parent: "foo.bar.baz",
  1107. }
  1108. override_apex {
  1109. name: "com.google.android.apogee",
  1110. base: ":com.android.apogee",
  1111. logging_parent: "foo.bar.baz.override",
  1112. }
  1113. `,
  1114. ExpectedBazelTargets: []string{
  1115. MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
  1116. "base_apex_name": `"com.android.apogee"`,
  1117. "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
  1118. "manifest": `"apex_manifest.json"`,
  1119. "logging_parent": `"foo.bar.baz.override"`,
  1120. }),
  1121. }})
  1122. }
  1123. func TestBp2BuildOverrideApex_CertificateNil(t *testing.T) {
  1124. runOverrideApexTestCase(t, Bp2buildTestCase{
  1125. Description: "override_apex - don't set default certificate",
  1126. ModuleTypeUnderTest: "override_apex",
  1127. ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
  1128. Filesystem: map[string]string{},
  1129. Blueprint: `
  1130. android_app_certificate {
  1131. name: "com.android.apogee.certificate",
  1132. certificate: "com.android.apogee",
  1133. bazel_module: { bp2build_available: false },
  1134. }
  1135. filegroup {
  1136. name: "com.android.apogee-file_contexts",
  1137. srcs: [
  1138. "com.android.apogee-file_contexts",
  1139. ],
  1140. bazel_module: { bp2build_available: false },
  1141. }
  1142. apex {
  1143. name: "com.android.apogee",
  1144. manifest: "apogee_manifest.json",
  1145. file_contexts: ":com.android.apogee-file_contexts",
  1146. certificate: ":com.android.apogee.certificate",
  1147. bazel_module: { bp2build_available: false },
  1148. }
  1149. override_apex {
  1150. name: "com.google.android.apogee",
  1151. base: ":com.android.apogee",
  1152. // certificate is deliberately omitted, and not converted to bazel,
  1153. // because the overridden apex shouldn't be using the base apex's cert.
  1154. }
  1155. `,
  1156. ExpectedBazelTargets: []string{
  1157. MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
  1158. "base_apex_name": `"com.android.apogee"`,
  1159. "file_contexts": `":com.android.apogee-file_contexts"`,
  1160. "manifest": `"apogee_manifest.json"`,
  1161. }),
  1162. }})
  1163. }
  1164. func TestApexCertificateIsModule(t *testing.T) {
  1165. runApexTestCase(t, Bp2buildTestCase{
  1166. Description: "apex - certificate is module",
  1167. ModuleTypeUnderTest: "apex",
  1168. ModuleTypeUnderTestFactory: apex.BundleFactory,
  1169. Filesystem: map[string]string{},
  1170. Blueprint: `
  1171. android_app_certificate {
  1172. name: "com.android.apogee.certificate",
  1173. certificate: "com.android.apogee",
  1174. bazel_module: { bp2build_available: false },
  1175. }
  1176. apex {
  1177. name: "com.android.apogee",
  1178. manifest: "apogee_manifest.json",
  1179. file_contexts: ":com.android.apogee-file_contexts",
  1180. certificate: ":com.android.apogee.certificate",
  1181. }
  1182. ` + simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee-file_contexts"),
  1183. ExpectedBazelTargets: []string{
  1184. MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
  1185. "certificate": `":com.android.apogee.certificate"`,
  1186. "file_contexts": `":com.android.apogee-file_contexts"`,
  1187. "manifest": `"apogee_manifest.json"`,
  1188. }),
  1189. }})
  1190. }
  1191. func TestApexWithStubLib(t *testing.T) {
  1192. runApexTestCase(t, Bp2buildTestCase{
  1193. Description: "apex - static variant of stub lib should not have apex_available tag",
  1194. ModuleTypeUnderTest: "apex",
  1195. ModuleTypeUnderTestFactory: apex.BundleFactory,
  1196. Filesystem: map[string]string{},
  1197. Blueprint: `
  1198. cc_library{
  1199. name: "foo",
  1200. stubs: { symbol_file: "foo.map.txt", versions: ["28", "29", "current"] },
  1201. apex_available: ["myapex"],
  1202. }
  1203. cc_binary{
  1204. name: "bar",
  1205. static_libs: ["foo"],
  1206. apex_available: ["myapex"],
  1207. }
  1208. apex {
  1209. name: "myapex",
  1210. manifest: "myapex_manifest.json",
  1211. file_contexts: ":myapex-file_contexts",
  1212. binaries: ["bar"],
  1213. native_shared_libs: ["foo"],
  1214. }
  1215. ` + simpleModuleDoNotConvertBp2build("filegroup", "myapex-file_contexts"),
  1216. ExpectedBazelTargets: []string{
  1217. MakeBazelTarget("cc_binary", "bar", AttrNameToString{
  1218. "local_includes": `["."]`,
  1219. "deps": `[":foo_bp2build_cc_library_static"]`,
  1220. "tags": `["apex_available=myapex"]`,
  1221. }),
  1222. MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
  1223. "local_includes": `["."]`,
  1224. }),
  1225. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  1226. "local_includes": `["."]`,
  1227. "stubs_symbol_file": `"foo.map.txt"`,
  1228. "tags": `["apex_available=myapex"]`,
  1229. }),
  1230. MakeBazelTarget("cc_stub_suite", "foo_stub_libs", AttrNameToString{
  1231. "soname": `"foo.so"`,
  1232. "source_library_label": `"//:foo"`,
  1233. "symbol_file": `"foo.map.txt"`,
  1234. "versions": `[
  1235. "28",
  1236. "29",
  1237. "current",
  1238. ]`,
  1239. }),
  1240. MakeBazelTarget("apex", "myapex", AttrNameToString{
  1241. "file_contexts": `":myapex-file_contexts"`,
  1242. "manifest": `"myapex_manifest.json"`,
  1243. "binaries": `[":bar"]`,
  1244. "native_shared_libs_32": `select({
  1245. "//build/bazel/platforms/arch:arm": [":foo"],
  1246. "//build/bazel/platforms/arch:x86": [":foo"],
  1247. "//conditions:default": [],
  1248. })`,
  1249. "native_shared_libs_64": `select({
  1250. "//build/bazel/platforms/arch:arm64": [":foo"],
  1251. "//build/bazel/platforms/arch:x86_64": [":foo"],
  1252. "//conditions:default": [],
  1253. })`,
  1254. }),
  1255. },
  1256. })
  1257. }
  1258. func TestApexCertificateIsSrc(t *testing.T) {
  1259. runApexTestCase(t, Bp2buildTestCase{
  1260. Description: "apex - certificate is src",
  1261. ModuleTypeUnderTest: "apex",
  1262. ModuleTypeUnderTestFactory: apex.BundleFactory,
  1263. Filesystem: map[string]string{},
  1264. Blueprint: `
  1265. apex {
  1266. name: "com.android.apogee",
  1267. manifest: "apogee_manifest.json",
  1268. file_contexts: ":com.android.apogee-file_contexts",
  1269. certificate: "com.android.apogee.certificate",
  1270. }
  1271. ` + simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee-file_contexts"),
  1272. ExpectedBazelTargets: []string{
  1273. MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
  1274. "certificate_name": `"com.android.apogee.certificate"`,
  1275. "file_contexts": `":com.android.apogee-file_contexts"`,
  1276. "manifest": `"apogee_manifest.json"`,
  1277. }),
  1278. }})
  1279. }
  1280. func TestBp2BuildOverrideApex_CertificateIsModule(t *testing.T) {
  1281. runOverrideApexTestCase(t, Bp2buildTestCase{
  1282. Description: "override_apex - certificate is module",
  1283. ModuleTypeUnderTest: "override_apex",
  1284. ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
  1285. Filesystem: map[string]string{},
  1286. Blueprint: `
  1287. android_app_certificate {
  1288. name: "com.android.apogee.certificate",
  1289. certificate: "com.android.apogee",
  1290. bazel_module: { bp2build_available: false },
  1291. }
  1292. filegroup {
  1293. name: "com.android.apogee-file_contexts",
  1294. srcs: [
  1295. "com.android.apogee-file_contexts",
  1296. ],
  1297. bazel_module: { bp2build_available: false },
  1298. }
  1299. apex {
  1300. name: "com.android.apogee",
  1301. manifest: "apogee_manifest.json",
  1302. file_contexts: ":com.android.apogee-file_contexts",
  1303. certificate: ":com.android.apogee.certificate",
  1304. bazel_module: { bp2build_available: false },
  1305. }
  1306. android_app_certificate {
  1307. name: "com.google.android.apogee.certificate",
  1308. certificate: "com.google.android.apogee",
  1309. bazel_module: { bp2build_available: false },
  1310. }
  1311. override_apex {
  1312. name: "com.google.android.apogee",
  1313. base: ":com.android.apogee",
  1314. certificate: ":com.google.android.apogee.certificate",
  1315. }
  1316. `,
  1317. ExpectedBazelTargets: []string{
  1318. MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
  1319. "base_apex_name": `"com.android.apogee"`,
  1320. "file_contexts": `":com.android.apogee-file_contexts"`,
  1321. "certificate": `":com.google.android.apogee.certificate"`,
  1322. "manifest": `"apogee_manifest.json"`,
  1323. }),
  1324. }})
  1325. }
  1326. func TestBp2BuildOverrideApex_CertificateIsSrc(t *testing.T) {
  1327. runOverrideApexTestCase(t, Bp2buildTestCase{
  1328. Description: "override_apex - certificate is src",
  1329. ModuleTypeUnderTest: "override_apex",
  1330. ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
  1331. Filesystem: map[string]string{},
  1332. Blueprint: `
  1333. android_app_certificate {
  1334. name: "com.android.apogee.certificate",
  1335. certificate: "com.android.apogee",
  1336. bazel_module: { bp2build_available: false },
  1337. }
  1338. filegroup {
  1339. name: "com.android.apogee-file_contexts",
  1340. srcs: [
  1341. "com.android.apogee-file_contexts",
  1342. ],
  1343. bazel_module: { bp2build_available: false },
  1344. }
  1345. apex {
  1346. name: "com.android.apogee",
  1347. manifest: "apogee_manifest.json",
  1348. file_contexts: ":com.android.apogee-file_contexts",
  1349. certificate: ":com.android.apogee.certificate",
  1350. bazel_module: { bp2build_available: false },
  1351. }
  1352. override_apex {
  1353. name: "com.google.android.apogee",
  1354. base: ":com.android.apogee",
  1355. certificate: "com.google.android.apogee.certificate",
  1356. }
  1357. `,
  1358. ExpectedBazelTargets: []string{
  1359. MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
  1360. "base_apex_name": `"com.android.apogee"`,
  1361. "file_contexts": `":com.android.apogee-file_contexts"`,
  1362. "certificate_name": `"com.google.android.apogee.certificate"`,
  1363. "manifest": `"apogee_manifest.json"`,
  1364. }),
  1365. }})
  1366. }
  1367. func TestApexTestBundleSimple(t *testing.T) {
  1368. runApexTestCase(t, Bp2buildTestCase{
  1369. Description: "apex_test - simple",
  1370. ModuleTypeUnderTest: "apex_test",
  1371. ModuleTypeUnderTestFactory: apex.TestApexBundleFactory,
  1372. Filesystem: map[string]string{},
  1373. Blueprint: `
  1374. cc_test { name: "cc_test_1", bazel_module: { bp2build_available: false } }
  1375. apex_test {
  1376. name: "test_com.android.apogee",
  1377. file_contexts: "file_contexts_file",
  1378. tests: ["cc_test_1"],
  1379. }
  1380. `,
  1381. ExpectedBazelTargets: []string{
  1382. MakeBazelTarget("apex", "test_com.android.apogee", AttrNameToString{
  1383. "file_contexts": `"file_contexts_file"`,
  1384. "base_apex_name": `"com.android.apogee"`,
  1385. "manifest": `"apex_manifest.json"`,
  1386. "testonly": `True`,
  1387. "tests": `[":cc_test_1"]`,
  1388. }),
  1389. }})
  1390. }
  1391. func TestApexBundle_overridePlusProductVars(t *testing.T) {
  1392. // Reproduction of b/271424349
  1393. // Tests that overriding an apex that uses product variables correctly copies the product var
  1394. // selects over to the override.
  1395. runOverrideApexTestCase(t, Bp2buildTestCase{
  1396. Description: "apex - overriding a module that uses product vars",
  1397. ModuleTypeUnderTest: "override_apex",
  1398. ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
  1399. Blueprint: `
  1400. soong_config_string_variable {
  1401. name: "library_linking_strategy",
  1402. values: [
  1403. "prefer_static",
  1404. ],
  1405. }
  1406. soong_config_module_type {
  1407. name: "library_linking_strategy_apex_defaults",
  1408. module_type: "apex_defaults",
  1409. config_namespace: "ANDROID",
  1410. variables: ["library_linking_strategy"],
  1411. properties: [
  1412. "manifest",
  1413. "min_sdk_version",
  1414. ],
  1415. }
  1416. library_linking_strategy_apex_defaults {
  1417. name: "higher_min_sdk_when_prefer_static",
  1418. soong_config_variables: {
  1419. library_linking_strategy: {
  1420. // Use the R min_sdk_version
  1421. prefer_static: {},
  1422. // Override the R min_sdk_version to min_sdk_version that supports dcla
  1423. conditions_default: {
  1424. min_sdk_version: "31",
  1425. },
  1426. },
  1427. },
  1428. }
  1429. filegroup {
  1430. name: "foo-file_contexts",
  1431. srcs: [
  1432. "com.android.apogee-file_contexts",
  1433. ],
  1434. bazel_module: { bp2build_available: false },
  1435. }
  1436. apex {
  1437. name: "foo",
  1438. defaults: ["higher_min_sdk_when_prefer_static"],
  1439. min_sdk_version: "30",
  1440. package_name: "pkg_name",
  1441. file_contexts: ":foo-file_contexts",
  1442. }
  1443. override_apex {
  1444. name: "override_foo",
  1445. base: ":foo",
  1446. package_name: "override_pkg_name",
  1447. }
  1448. `,
  1449. ExpectedBazelTargets: []string{
  1450. MakeBazelTarget("apex", "foo", AttrNameToString{
  1451. "file_contexts": `":foo-file_contexts"`,
  1452. "manifest": `"apex_manifest.json"`,
  1453. "min_sdk_version": `select({
  1454. "//build/bazel/product_variables:android__library_linking_strategy__prefer_static": "30",
  1455. "//conditions:default": "31",
  1456. })`,
  1457. "package_name": `"pkg_name"`,
  1458. }), MakeBazelTarget("apex", "override_foo", AttrNameToString{
  1459. "base_apex_name": `"foo"`,
  1460. "file_contexts": `":foo-file_contexts"`,
  1461. "manifest": `"apex_manifest.json"`,
  1462. "min_sdk_version": `select({
  1463. "//build/bazel/product_variables:android__library_linking_strategy__prefer_static": "30",
  1464. "//conditions:default": "31",
  1465. })`,
  1466. "package_name": `"override_pkg_name"`,
  1467. }),
  1468. }})
  1469. }
  1470. func TestApexBundleSimple_customCannedFsConfig(t *testing.T) {
  1471. runApexTestCase(t, Bp2buildTestCase{
  1472. Description: "apex - custom canned_fs_config",
  1473. ModuleTypeUnderTest: "apex",
  1474. ModuleTypeUnderTestFactory: apex.BundleFactory,
  1475. Filesystem: map[string]string{},
  1476. Blueprint: `
  1477. apex {
  1478. name: "com.android.apogee",
  1479. canned_fs_config: "custom.canned_fs_config",
  1480. file_contexts: "file_contexts_file",
  1481. }
  1482. `,
  1483. ExpectedBazelTargets: []string{
  1484. MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
  1485. "canned_fs_config": `"custom.canned_fs_config"`,
  1486. "file_contexts": `"file_contexts_file"`,
  1487. "manifest": `"apex_manifest.json"`,
  1488. }),
  1489. }})
  1490. }