apex.go 130 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634
  1. // Copyright (C) 2018 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 implements build rules for creating the APEX files which are container for
  15. // lower-level system components. See https://source.android.com/devices/tech/ota/apex
  16. package apex
  17. import (
  18. "fmt"
  19. "path/filepath"
  20. "sort"
  21. "strings"
  22. "github.com/google/blueprint"
  23. "github.com/google/blueprint/bootstrap"
  24. "github.com/google/blueprint/proptools"
  25. "android/soong/android"
  26. "android/soong/bazel"
  27. "android/soong/bpf"
  28. "android/soong/cc"
  29. prebuilt_etc "android/soong/etc"
  30. "android/soong/filesystem"
  31. "android/soong/java"
  32. "android/soong/multitree"
  33. "android/soong/python"
  34. "android/soong/rust"
  35. "android/soong/sh"
  36. )
  37. func init() {
  38. registerApexBuildComponents(android.InitRegistrationContext)
  39. }
  40. func registerApexBuildComponents(ctx android.RegistrationContext) {
  41. ctx.RegisterModuleType("apex", BundleFactory)
  42. ctx.RegisterModuleType("apex_test", testApexBundleFactory)
  43. ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
  44. ctx.RegisterModuleType("apex_defaults", defaultsFactory)
  45. ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
  46. ctx.RegisterModuleType("override_apex", overrideApexFactory)
  47. ctx.RegisterModuleType("apex_set", apexSetFactory)
  48. ctx.PreArchMutators(registerPreArchMutators)
  49. ctx.PreDepsMutators(RegisterPreDepsMutators)
  50. ctx.PostDepsMutators(RegisterPostDepsMutators)
  51. }
  52. func registerPreArchMutators(ctx android.RegisterMutatorsContext) {
  53. ctx.TopDown("prebuilt_apex_module_creator", prebuiltApexModuleCreatorMutator).Parallel()
  54. }
  55. func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
  56. ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
  57. ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
  58. }
  59. func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
  60. ctx.TopDown("apex_info", apexInfoMutator).Parallel()
  61. ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel()
  62. ctx.BottomUp("apex_test_for_deps", apexTestForDepsMutator).Parallel()
  63. ctx.BottomUp("apex_test_for", apexTestForMutator).Parallel()
  64. // Run mark_platform_availability before the apexMutator as the apexMutator needs to know whether
  65. // it should create a platform variant.
  66. ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
  67. ctx.BottomUp("apex", apexMutator).Parallel()
  68. ctx.BottomUp("apex_directly_in_any", apexDirectlyInAnyMutator).Parallel()
  69. ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
  70. // Register after apex_info mutator so that it can use ApexVariationName
  71. ctx.TopDown("apex_strict_updatability_lint", apexStrictUpdatibilityLintMutator).Parallel()
  72. }
  73. type apexBundleProperties struct {
  74. // Json manifest file describing meta info of this APEX bundle. Refer to
  75. // system/apex/proto/apex_manifest.proto for the schema. Default: "apex_manifest.json"
  76. Manifest *string `android:"path"`
  77. // AndroidManifest.xml file used for the zip container of this APEX bundle. If unspecified,
  78. // a default one is automatically generated.
  79. AndroidManifest *string `android:"path"`
  80. // Canonical name of this APEX bundle. Used to determine the path to the activated APEX on
  81. // device (/apex/<apex_name>). If unspecified, follows the name property.
  82. Apex_name *string
  83. // Determines the file contexts file for setting the security contexts to files in this APEX
  84. // bundle. For platform APEXes, this should points to a file under /system/sepolicy Default:
  85. // /system/sepolicy/apex/<module_name>_file_contexts.
  86. File_contexts *string `android:"path"`
  87. // Path to the canned fs config file for customizing file's uid/gid/mod/capabilities. The
  88. // format is /<path_or_glob> <uid> <gid> <mode> [capabilities=0x<cap>], where path_or_glob is a
  89. // path or glob pattern for a file or set of files, uid/gid are numerial values of user ID
  90. // and group ID, mode is octal value for the file mode, and cap is hexadecimal value for the
  91. // capability. If this property is not set, or a file is missing in the file, default config
  92. // is used.
  93. Canned_fs_config *string `android:"path"`
  94. ApexNativeDependencies
  95. Multilib apexMultilibProperties
  96. // List of sh binaries that are embedded inside this APEX bundle.
  97. Sh_binaries []string
  98. // List of platform_compat_config files that are embedded inside this APEX bundle.
  99. Compat_configs []string
  100. // List of filesystem images that are embedded inside this APEX bundle.
  101. Filesystems []string
  102. // The minimum SDK version that this APEX must support at minimum. This is usually set to
  103. // the SDK version that the APEX was first introduced.
  104. Min_sdk_version *string
  105. // Whether this APEX is considered updatable or not. When set to true, this will enforce
  106. // additional rules for making sure that the APEX is truly updatable. To be updatable,
  107. // min_sdk_version should be set as well. This will also disable the size optimizations like
  108. // symlinking to the system libs. Default is true.
  109. Updatable *bool
  110. // Marks that this APEX is designed to be updatable in the future, although it's not
  111. // updatable yet. This is used to mimic some of the build behaviors that are applied only to
  112. // updatable APEXes. Currently, this disables the size optimization, so that the size of
  113. // APEX will not increase when the APEX is actually marked as truly updatable. Default is
  114. // false.
  115. Future_updatable *bool
  116. // Whether this APEX can use platform APIs or not. Can be set to true only when `updatable:
  117. // false`. Default is false.
  118. Platform_apis *bool
  119. // Whether this APEX is installable to one of the partitions like system, vendor, etc.
  120. // Default: true.
  121. Installable *bool
  122. // If set true, VNDK libs are considered as stable libs and are not included in this APEX.
  123. // Should be only used in non-system apexes (e.g. vendor: true). Default is false.
  124. Use_vndk_as_stable *bool
  125. // Whether this is multi-installed APEX should skip installing symbol files.
  126. // Multi-installed APEXes share the same apex_name and are installed at the same time.
  127. // Default is false.
  128. //
  129. // Should be set to true for all multi-installed APEXes except the singular
  130. // default version within the multi-installed group.
  131. // Only the default version can install symbol files in $(PRODUCT_OUT}/apex,
  132. // or else conflicting build rules may be created.
  133. Multi_install_skip_symbol_files *bool
  134. // List of SDKs that are used to build this APEX. A reference to an SDK should be either
  135. // `name#version` or `name` which is an alias for `name#current`. If left empty,
  136. // `platform#current` is implied. This value affects all modules included in this APEX. In
  137. // other words, they are also built with the SDKs specified here.
  138. Uses_sdks []string
  139. // The type of APEX to build. Controls what the APEX payload is. Either 'image', 'zip' or
  140. // 'both'. When set to image, contents are stored in a filesystem image inside a zip
  141. // container. When set to zip, contents are stored in a zip container directly. This type is
  142. // mostly for host-side debugging. When set to both, the two types are both built. Default
  143. // is 'image'.
  144. Payload_type *string
  145. // The type of filesystem to use when the payload_type is 'image'. Either 'ext4', 'f2fs'
  146. // or 'erofs'. Default 'ext4'.
  147. Payload_fs_type *string
  148. // For telling the APEX to ignore special handling for system libraries such as bionic.
  149. // Default is false.
  150. Ignore_system_library_special_case *bool
  151. // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
  152. // Default value is true.
  153. Generate_hashtree *bool
  154. // Whenever apex_payload.img of the APEX should not be dm-verity signed. Should be only
  155. // used in tests.
  156. Test_only_unsigned_payload *bool
  157. // Whenever apex should be compressed, regardless of product flag used. Should be only
  158. // used in tests.
  159. Test_only_force_compression *bool
  160. // Put extra tags (signer=<value>) to apexkeys.txt, so that release tools can sign this apex
  161. // with the tool to sign payload contents.
  162. Custom_sign_tool *string
  163. // Canonical name of this APEX bundle. Used to determine the path to the
  164. // activated APEX on device (i.e. /apex/<apexVariationName>), and used for the
  165. // apex mutator variations. For override_apex modules, this is the name of the
  166. // overridden base module.
  167. ApexVariationName string `blueprint:"mutated"`
  168. IsCoverageVariant bool `blueprint:"mutated"`
  169. // List of sanitizer names that this APEX is enabled for
  170. SanitizerNames []string `blueprint:"mutated"`
  171. PreventInstall bool `blueprint:"mutated"`
  172. HideFromMake bool `blueprint:"mutated"`
  173. // Internal package method for this APEX. When payload_type is image, this can be either
  174. // imageApex or flattenedApex depending on Config.FlattenApex(). When payload_type is zip,
  175. // this becomes zipApex.
  176. ApexType apexPackaging `blueprint:"mutated"`
  177. }
  178. type ApexNativeDependencies struct {
  179. // List of native libraries that are embedded inside this APEX.
  180. Native_shared_libs []string
  181. // List of JNI libraries that are embedded inside this APEX.
  182. Jni_libs []string
  183. // List of rust dyn libraries
  184. Rust_dyn_libs []string
  185. // List of native executables that are embedded inside this APEX.
  186. Binaries []string
  187. // List of native tests that are embedded inside this APEX.
  188. Tests []string
  189. // List of filesystem images that are embedded inside this APEX bundle.
  190. Filesystems []string
  191. }
  192. type apexMultilibProperties struct {
  193. // Native dependencies whose compile_multilib is "first"
  194. First ApexNativeDependencies
  195. // Native dependencies whose compile_multilib is "both"
  196. Both ApexNativeDependencies
  197. // Native dependencies whose compile_multilib is "prefer32"
  198. Prefer32 ApexNativeDependencies
  199. // Native dependencies whose compile_multilib is "32"
  200. Lib32 ApexNativeDependencies
  201. // Native dependencies whose compile_multilib is "64"
  202. Lib64 ApexNativeDependencies
  203. }
  204. type apexTargetBundleProperties struct {
  205. Target struct {
  206. // Multilib properties only for android.
  207. Android struct {
  208. Multilib apexMultilibProperties
  209. }
  210. // Multilib properties only for host.
  211. Host struct {
  212. Multilib apexMultilibProperties
  213. }
  214. // Multilib properties only for host linux_bionic.
  215. Linux_bionic struct {
  216. Multilib apexMultilibProperties
  217. }
  218. // Multilib properties only for host linux_glibc.
  219. Linux_glibc struct {
  220. Multilib apexMultilibProperties
  221. }
  222. }
  223. }
  224. type apexArchBundleProperties struct {
  225. Arch struct {
  226. Arm struct {
  227. ApexNativeDependencies
  228. }
  229. Arm64 struct {
  230. ApexNativeDependencies
  231. }
  232. X86 struct {
  233. ApexNativeDependencies
  234. }
  235. X86_64 struct {
  236. ApexNativeDependencies
  237. }
  238. }
  239. }
  240. // These properties can be used in override_apex to override the corresponding properties in the
  241. // base apex.
  242. type overridableProperties struct {
  243. // List of APKs that are embedded inside this APEX.
  244. Apps []string
  245. // List of prebuilt files that are embedded inside this APEX bundle.
  246. Prebuilts []string
  247. // List of runtime resource overlays (RROs) that are embedded inside this APEX.
  248. Rros []string
  249. // List of BPF programs inside this APEX bundle.
  250. Bpfs []string
  251. // List of bootclasspath fragments that are embedded inside this APEX bundle.
  252. Bootclasspath_fragments []string
  253. // List of systemserverclasspath fragments that are embedded inside this APEX bundle.
  254. Systemserverclasspath_fragments []string
  255. // List of java libraries that are embedded inside this APEX bundle.
  256. Java_libs []string
  257. // Names of modules to be overridden. Listed modules can only be other binaries (in Make or
  258. // Soong). This does not completely prevent installation of the overridden binaries, but if
  259. // both binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will
  260. // be removed from PRODUCT_PACKAGES.
  261. Overrides []string
  262. // Logging parent value.
  263. Logging_parent string
  264. // Apex Container package name. Override value for attribute package:name in
  265. // AndroidManifest.xml
  266. Package_name string
  267. // A txt file containing list of files that are allowed to be included in this APEX.
  268. Allowed_files *string `android:"path"`
  269. // Name of the apex_key module that provides the private key to sign this APEX bundle.
  270. Key *string
  271. // Specifies the certificate and the private key to sign the zip container of this APEX. If
  272. // this is "foo", foo.x509.pem and foo.pk8 under PRODUCT_DEFAULT_DEV_CERTIFICATE are used
  273. // as the certificate and the private key, respectively. If this is ":module", then the
  274. // certificate and the private key are provided from the android_app_certificate module
  275. // named "module".
  276. Certificate *string
  277. // Whether this APEX can be compressed or not. Setting this property to false means this
  278. // APEX will never be compressed. When set to true, APEX will be compressed if other
  279. // conditions, e.g., target device needs to support APEX compression, are also fulfilled.
  280. // Default: false.
  281. Compressible *bool
  282. }
  283. type apexBundle struct {
  284. // Inherited structs
  285. android.ModuleBase
  286. android.DefaultableModuleBase
  287. android.OverridableModuleBase
  288. android.SdkBase
  289. android.BazelModuleBase
  290. multitree.ExportableModuleBase
  291. // Properties
  292. properties apexBundleProperties
  293. targetProperties apexTargetBundleProperties
  294. archProperties apexArchBundleProperties
  295. overridableProperties overridableProperties
  296. vndkProperties apexVndkProperties // only for apex_vndk modules
  297. ///////////////////////////////////////////////////////////////////////////////////////////
  298. // Inputs
  299. // Keys for apex_paylaod.img
  300. publicKeyFile android.Path
  301. privateKeyFile android.Path
  302. // Cert/priv-key for the zip container
  303. containerCertificateFile android.Path
  304. containerPrivateKeyFile android.Path
  305. // Flags for special variants of APEX
  306. testApex bool
  307. vndkApex bool
  308. // Tells whether this variant of the APEX bundle is the primary one or not. Only the primary
  309. // one gets installed to the device.
  310. primaryApexType bool
  311. // Suffix of module name in Android.mk ".flattened", ".apex", ".zipapex", or ""
  312. suffix string
  313. // File system type of apex_payload.img
  314. payloadFsType fsType
  315. // Whether to create symlink to the system file instead of having a file inside the apex or
  316. // not
  317. linkToSystemLib bool
  318. // List of files to be included in this APEX. This is filled in the first part of
  319. // GenerateAndroidBuildActions.
  320. filesInfo []apexFile
  321. // List of other module names that should be installed when this APEX gets installed.
  322. requiredDeps []string
  323. ///////////////////////////////////////////////////////////////////////////////////////////
  324. // Outputs (final and intermediates)
  325. // Processed apex manifest in JSONson format (for Q)
  326. manifestJsonOut android.WritablePath
  327. // Processed apex manifest in PB format (for R+)
  328. manifestPbOut android.WritablePath
  329. // Processed file_contexts files
  330. fileContexts android.WritablePath
  331. // Path to notice file in html.gz format.
  332. htmlGzNotice android.WritablePath
  333. // The built APEX file. This is the main product.
  334. // Could be .apex or .capex
  335. outputFile android.WritablePath
  336. // The built uncompressed .apex file.
  337. outputApexFile android.WritablePath
  338. // The built APEX file in app bundle format. This file is not directly installed to the
  339. // device. For an APEX, multiple app bundles are created each of which is for a specific ABI
  340. // like arm, arm64, x86, etc. Then they are processed again (outside of the Android build
  341. // system) to be merged into a single app bundle file that Play accepts. See
  342. // vendor/google/build/build_unbundled_mainline_module.sh for more detail.
  343. bundleModuleFile android.WritablePath
  344. // Target directory to install this APEX. Usually out/target/product/<device>/<partition>/apex.
  345. installDir android.InstallPath
  346. // Path where this APEX was installed.
  347. installedFile android.InstallPath
  348. // Installed locations of symlinks for backward compatibility.
  349. compatSymlinks android.InstallPaths
  350. // Text file having the list of individual files that are included in this APEX. Used for
  351. // debugging purpose.
  352. installedFilesFile android.WritablePath
  353. // List of module names that this APEX is including (to be shown via *-deps-info target).
  354. // Used for debugging purpose.
  355. android.ApexBundleDepsInfo
  356. // Optional list of lint report zip files for apexes that contain java or app modules
  357. lintReports android.Paths
  358. prebuiltFileToDelete string
  359. isCompressed bool
  360. // Path of API coverage generate file
  361. nativeApisUsedByModuleFile android.ModuleOutPath
  362. nativeApisBackedByModuleFile android.ModuleOutPath
  363. javaApisUsedByModuleFile android.ModuleOutPath
  364. // Collect the module directory for IDE info in java/jdeps.go.
  365. modulePaths []string
  366. }
  367. // apexFileClass represents a type of file that can be included in APEX.
  368. type apexFileClass int
  369. const (
  370. app apexFileClass = iota
  371. appSet
  372. etc
  373. goBinary
  374. javaSharedLib
  375. nativeExecutable
  376. nativeSharedLib
  377. nativeTest
  378. pyBinary
  379. shBinary
  380. )
  381. // apexFile represents a file in an APEX bundle. This is created during the first half of
  382. // GenerateAndroidBuildActions by traversing the dependencies of the APEX. Then in the second half
  383. // of the function, this is used to create commands that copies the files into a staging directory,
  384. // where they are packaged into the APEX file. This struct is also used for creating Make modules
  385. // for each of the files in case when the APEX is flattened.
  386. type apexFile struct {
  387. // buildFile is put in the installDir inside the APEX.
  388. builtFile android.Path
  389. installDir string
  390. customStem string
  391. symlinks []string // additional symlinks
  392. // Info for Android.mk Module name of `module` in AndroidMk. Note the generated AndroidMk
  393. // module for apexFile is named something like <AndroidMk module name>.<apex name>[<apex
  394. // suffix>]
  395. androidMkModuleName string // becomes LOCAL_MODULE
  396. class apexFileClass // becomes LOCAL_MODULE_CLASS
  397. moduleDir string // becomes LOCAL_PATH
  398. requiredModuleNames []string // becomes LOCAL_REQUIRED_MODULES
  399. targetRequiredModuleNames []string // becomes LOCAL_TARGET_REQUIRED_MODULES
  400. hostRequiredModuleNames []string // becomes LOCAL_HOST_REQUIRED_MODULES
  401. dataPaths []android.DataPath // becomes LOCAL_TEST_DATA
  402. jacocoReportClassesFile android.Path // only for javalibs and apps
  403. lintDepSets java.LintDepSets // only for javalibs and apps
  404. certificate java.Certificate // only for apps
  405. overriddenPackageName string // only for apps
  406. transitiveDep bool
  407. isJniLib bool
  408. multilib string
  409. // TODO(jiyong): remove this
  410. module android.Module
  411. }
  412. // TODO(jiyong): shorten the arglist using an option struct
  413. func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
  414. ret := apexFile{
  415. builtFile: builtFile,
  416. installDir: installDir,
  417. androidMkModuleName: androidMkModuleName,
  418. class: class,
  419. module: module,
  420. }
  421. if module != nil {
  422. ret.moduleDir = ctx.OtherModuleDir(module)
  423. ret.requiredModuleNames = module.RequiredModuleNames()
  424. ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
  425. ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
  426. ret.multilib = module.Target().Arch.ArchType.Multilib
  427. }
  428. return ret
  429. }
  430. func (af *apexFile) ok() bool {
  431. return af.builtFile != nil && af.builtFile.String() != ""
  432. }
  433. // apexRelativePath returns the relative path of the given path from the install directory of this
  434. // apexFile.
  435. // TODO(jiyong): rename this
  436. func (af *apexFile) apexRelativePath(path string) string {
  437. return filepath.Join(af.installDir, path)
  438. }
  439. // path returns path of this apex file relative to the APEX root
  440. func (af *apexFile) path() string {
  441. return af.apexRelativePath(af.stem())
  442. }
  443. // stem returns the base filename of this apex file
  444. func (af *apexFile) stem() string {
  445. if af.customStem != "" {
  446. return af.customStem
  447. }
  448. return af.builtFile.Base()
  449. }
  450. // symlinkPaths returns paths of the symlinks (if any) relative to the APEX root
  451. func (af *apexFile) symlinkPaths() []string {
  452. var ret []string
  453. for _, symlink := range af.symlinks {
  454. ret = append(ret, af.apexRelativePath(symlink))
  455. }
  456. return ret
  457. }
  458. // availableToPlatform tests whether this apexFile is from a module that can be installed to the
  459. // platform.
  460. func (af *apexFile) availableToPlatform() bool {
  461. if af.module == nil {
  462. return false
  463. }
  464. if am, ok := af.module.(android.ApexModule); ok {
  465. return am.AvailableFor(android.AvailableToPlatform)
  466. }
  467. return false
  468. }
  469. ////////////////////////////////////////////////////////////////////////////////////////////////////
  470. // Mutators
  471. //
  472. // Brief description about mutators for APEX. The following three mutators are the most important
  473. // ones.
  474. //
  475. // 1) DepsMutator: from the properties like native_shared_libs, java_libs, etc., modules are added
  476. // to the (direct) dependencies of this APEX bundle.
  477. //
  478. // 2) apexInfoMutator: this is a post-deps mutator, so runs after DepsMutator. Its goal is to
  479. // collect modules that are direct and transitive dependencies of each APEX bundle. The collected
  480. // modules are marked as being included in the APEX via BuildForApex().
  481. //
  482. // 3) apexMutator: this is a post-deps mutator that runs after apexInfoMutator. For each module that
  483. // are marked by the apexInfoMutator, apex variations are created using CreateApexVariations().
  484. type dependencyTag struct {
  485. blueprint.BaseDependencyTag
  486. name string
  487. // Determines if the dependent will be part of the APEX payload. Can be false for the
  488. // dependencies to the signing key module, etc.
  489. payload bool
  490. // True if the dependent can only be a source module, false if a prebuilt module is a suitable
  491. // replacement. This is needed because some prebuilt modules do not provide all the information
  492. // needed by the apex.
  493. sourceOnly bool
  494. }
  495. func (d dependencyTag) ReplaceSourceWithPrebuilt() bool {
  496. return !d.sourceOnly
  497. }
  498. var _ android.ReplaceSourceWithPrebuilt = &dependencyTag{}
  499. var (
  500. androidAppTag = dependencyTag{name: "androidApp", payload: true}
  501. bpfTag = dependencyTag{name: "bpf", payload: true}
  502. certificateTag = dependencyTag{name: "certificate"}
  503. executableTag = dependencyTag{name: "executable", payload: true}
  504. fsTag = dependencyTag{name: "filesystem", payload: true}
  505. bcpfTag = dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true}
  506. sscpfTag = dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true}
  507. compatConfigTag = dependencyTag{name: "compatConfig", payload: true, sourceOnly: true}
  508. javaLibTag = dependencyTag{name: "javaLib", payload: true}
  509. jniLibTag = dependencyTag{name: "jniLib", payload: true}
  510. keyTag = dependencyTag{name: "key"}
  511. prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
  512. rroTag = dependencyTag{name: "rro", payload: true}
  513. sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
  514. testForTag = dependencyTag{name: "test for"}
  515. testTag = dependencyTag{name: "test", payload: true}
  516. shBinaryTag = dependencyTag{name: "shBinary", payload: true}
  517. )
  518. // TODO(jiyong): shorten this function signature
  519. func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeModules ApexNativeDependencies, target android.Target, imageVariation string) {
  520. binVariations := target.Variations()
  521. libVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
  522. rustLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"})
  523. if ctx.Device() {
  524. binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
  525. libVariations = append(libVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
  526. rustLibVariations = append(rustLibVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
  527. }
  528. // Use *FarVariation* to be able to depend on modules having conflicting variations with
  529. // this module. This is required since arch variant of an APEX bundle is 'common' but it is
  530. // 'arm' or 'arm64' for native shared libs.
  531. ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
  532. ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
  533. ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
  534. ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
  535. ctx.AddFarVariationDependencies(rustLibVariations, sharedLibTag, nativeModules.Rust_dyn_libs...)
  536. ctx.AddFarVariationDependencies(target.Variations(), fsTag, nativeModules.Filesystems...)
  537. }
  538. func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
  539. if ctx.Device() {
  540. proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
  541. } else {
  542. proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
  543. if ctx.Os().Bionic() {
  544. proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
  545. } else {
  546. proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
  547. }
  548. }
  549. }
  550. // getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply
  551. // android.CoreVariation, but gets complicated for the vendor APEXes and the VNDK APEX.
  552. func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
  553. deviceConfig := ctx.DeviceConfig()
  554. if a.vndkApex {
  555. return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
  556. }
  557. var prefix string
  558. var vndkVersion string
  559. if deviceConfig.VndkVersion() != "" {
  560. if a.SocSpecific() || a.DeviceSpecific() {
  561. prefix = cc.VendorVariationPrefix
  562. vndkVersion = deviceConfig.VndkVersion()
  563. } else if a.ProductSpecific() {
  564. prefix = cc.ProductVariationPrefix
  565. vndkVersion = deviceConfig.ProductVndkVersion()
  566. }
  567. }
  568. if vndkVersion == "current" {
  569. vndkVersion = deviceConfig.PlatformVndkVersion()
  570. }
  571. if vndkVersion != "" {
  572. return prefix + vndkVersion
  573. }
  574. return android.CoreVariation // The usual case
  575. }
  576. func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
  577. // apexBundle is a multi-arch targets module. Arch variant of apexBundle is set to 'common'.
  578. // arch-specific targets are enabled by the compile_multilib setting of the apex bundle. For
  579. // each target os/architectures, appropriate dependencies are selected by their
  580. // target.<os>.multilib.<type> groups and are added as (direct) dependencies.
  581. targets := ctx.MultiTargets()
  582. imageVariation := a.getImageVariation(ctx)
  583. a.combineProperties(ctx)
  584. has32BitTarget := false
  585. for _, target := range targets {
  586. if target.Arch.ArchType.Multilib == "lib32" {
  587. has32BitTarget = true
  588. }
  589. }
  590. for i, target := range targets {
  591. // Don't include artifacts for the host cross targets because there is no way for us
  592. // to run those artifacts natively on host
  593. if target.HostCross {
  594. continue
  595. }
  596. var depsList []ApexNativeDependencies
  597. // Add native modules targeting both ABIs. When multilib.* is omitted for
  598. // native_shared_libs/jni_libs/tests, it implies multilib.both
  599. depsList = append(depsList, a.properties.Multilib.Both)
  600. depsList = append(depsList, ApexNativeDependencies{
  601. Native_shared_libs: a.properties.Native_shared_libs,
  602. Tests: a.properties.Tests,
  603. Jni_libs: a.properties.Jni_libs,
  604. Binaries: nil,
  605. })
  606. // Add native modules targeting the first ABI When multilib.* is omitted for
  607. // binaries, it implies multilib.first
  608. isPrimaryAbi := i == 0
  609. if isPrimaryAbi {
  610. depsList = append(depsList, a.properties.Multilib.First)
  611. depsList = append(depsList, ApexNativeDependencies{
  612. Native_shared_libs: nil,
  613. Tests: nil,
  614. Jni_libs: nil,
  615. Binaries: a.properties.Binaries,
  616. })
  617. }
  618. // Add native modules targeting either 32-bit or 64-bit ABI
  619. switch target.Arch.ArchType.Multilib {
  620. case "lib32":
  621. depsList = append(depsList, a.properties.Multilib.Lib32)
  622. depsList = append(depsList, a.properties.Multilib.Prefer32)
  623. case "lib64":
  624. depsList = append(depsList, a.properties.Multilib.Lib64)
  625. if !has32BitTarget {
  626. depsList = append(depsList, a.properties.Multilib.Prefer32)
  627. }
  628. }
  629. // Add native modules targeting a specific arch variant
  630. switch target.Arch.ArchType {
  631. case android.Arm:
  632. depsList = append(depsList, a.archProperties.Arch.Arm.ApexNativeDependencies)
  633. case android.Arm64:
  634. depsList = append(depsList, a.archProperties.Arch.Arm64.ApexNativeDependencies)
  635. case android.X86:
  636. depsList = append(depsList, a.archProperties.Arch.X86.ApexNativeDependencies)
  637. case android.X86_64:
  638. depsList = append(depsList, a.archProperties.Arch.X86_64.ApexNativeDependencies)
  639. default:
  640. panic(fmt.Errorf("unsupported arch %v\n", ctx.Arch().ArchType))
  641. }
  642. for _, d := range depsList {
  643. addDependenciesForNativeModules(ctx, d, target, imageVariation)
  644. }
  645. ctx.AddFarVariationDependencies([]blueprint.Variation{
  646. {Mutator: "os", Variation: target.OsVariation()},
  647. {Mutator: "arch", Variation: target.ArchVariation()},
  648. }, shBinaryTag, a.properties.Sh_binaries...)
  649. }
  650. // Common-arch dependencies come next
  651. commonVariation := ctx.Config().AndroidCommonTarget.Variations()
  652. ctx.AddFarVariationDependencies(commonVariation, fsTag, a.properties.Filesystems...)
  653. ctx.AddFarVariationDependencies(commonVariation, compatConfigTag, a.properties.Compat_configs...)
  654. // Marks that this APEX (in fact all the modules in it) has to be built with the given SDKs.
  655. // This field currently isn't used.
  656. // TODO(jiyong): consider dropping this feature
  657. // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
  658. if len(a.properties.Uses_sdks) > 0 {
  659. sdkRefs := []android.SdkRef{}
  660. for _, str := range a.properties.Uses_sdks {
  661. parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
  662. sdkRefs = append(sdkRefs, parsed)
  663. }
  664. a.BuildWithSdks(sdkRefs)
  665. }
  666. }
  667. // DepsMutator for the overridden properties.
  668. func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
  669. if a.overridableProperties.Allowed_files != nil {
  670. android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
  671. }
  672. commonVariation := ctx.Config().AndroidCommonTarget.Variations()
  673. ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps...)
  674. ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.overridableProperties.Bpfs...)
  675. ctx.AddFarVariationDependencies(commonVariation, rroTag, a.overridableProperties.Rros...)
  676. ctx.AddFarVariationDependencies(commonVariation, bcpfTag, a.overridableProperties.Bootclasspath_fragments...)
  677. ctx.AddFarVariationDependencies(commonVariation, sscpfTag, a.overridableProperties.Systemserverclasspath_fragments...)
  678. ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.overridableProperties.Java_libs...)
  679. if prebuilts := a.overridableProperties.Prebuilts; len(prebuilts) > 0 {
  680. // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device)
  681. // regardless of the TARGET_PREFER_* setting. See b/144532908
  682. arches := ctx.DeviceConfig().Arches()
  683. if len(arches) != 0 {
  684. archForPrebuiltEtc := arches[0]
  685. for _, arch := range arches {
  686. // Prefer 64-bit arch if there is any
  687. if arch.ArchType.Multilib == "lib64" {
  688. archForPrebuiltEtc = arch
  689. break
  690. }
  691. }
  692. ctx.AddFarVariationDependencies([]blueprint.Variation{
  693. {Mutator: "os", Variation: ctx.Os().String()},
  694. {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
  695. }, prebuiltTag, prebuilts...)
  696. }
  697. }
  698. // Dependencies for signing
  699. if String(a.overridableProperties.Key) == "" {
  700. ctx.PropertyErrorf("key", "missing")
  701. return
  702. }
  703. ctx.AddDependency(ctx.Module(), keyTag, String(a.overridableProperties.Key))
  704. cert := android.SrcIsModule(a.getCertString(ctx))
  705. if cert != "" {
  706. ctx.AddDependency(ctx.Module(), certificateTag, cert)
  707. // empty cert is not an error. Cert and private keys will be directly found under
  708. // PRODUCT_DEFAULT_DEV_CERTIFICATE
  709. }
  710. }
  711. type ApexBundleInfo struct {
  712. Contents *android.ApexContents
  713. }
  714. var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_info")
  715. var _ ApexInfoMutator = (*apexBundle)(nil)
  716. func (a *apexBundle) ApexVariationName() string {
  717. return a.properties.ApexVariationName
  718. }
  719. // ApexInfoMutator is responsible for collecting modules that need to have apex variants. They are
  720. // identified by doing a graph walk starting from an apexBundle. Basically, all the (direct and
  721. // indirect) dependencies are collected. But a few types of modules that shouldn't be included in
  722. // the apexBundle (e.g. stub libraries) are not collected. Note that a single module can be depended
  723. // on by multiple apexBundles. In that case, the module is collected for all of the apexBundles.
  724. //
  725. // For each dependency between an apex and an ApexModule an ApexInfo object describing the apex
  726. // is passed to that module's BuildForApex(ApexInfo) method which collates them all in a list.
  727. // The apexMutator uses that list to create module variants for the apexes to which it belongs.
  728. // The relationship between module variants and apexes is not one-to-one as variants will be
  729. // shared between compatible apexes.
  730. func (a *apexBundle) ApexInfoMutator(mctx android.TopDownMutatorContext) {
  731. // The VNDK APEX is special. For the APEX, the membership is described in a very different
  732. // way. There is no dependency from the VNDK APEX to the VNDK libraries. Instead, VNDK
  733. // libraries are self-identified by their vndk.enabled properties. There is no need to run
  734. // this mutator for the APEX as nothing will be collected. So, let's return fast.
  735. if a.vndkApex {
  736. return
  737. }
  738. // Special casing for APEXes on non-system (e.g., vendor, odm, etc.) partitions. They are
  739. // provided with a property named use_vndk_as_stable, which when set to true doesn't collect
  740. // VNDK libraries as transitive dependencies. This option is useful for reducing the size of
  741. // the non-system APEXes because the VNDK libraries won't be included (and duped) in the
  742. // APEX, but shared across APEXes via the VNDK APEX.
  743. useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
  744. excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
  745. if proptools.Bool(a.properties.Use_vndk_as_stable) {
  746. if !useVndk {
  747. mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
  748. }
  749. mctx.VisitDirectDepsWithTag(sharedLibTag, func(dep android.Module) {
  750. if c, ok := dep.(*cc.Module); ok && c.IsVndk() {
  751. mctx.PropertyErrorf("use_vndk_as_stable", "Trying to include a VNDK library(%s) while use_vndk_as_stable is true.", dep.Name())
  752. }
  753. })
  754. if mctx.Failed() {
  755. return
  756. }
  757. }
  758. continueApexDepsWalk := func(child, parent android.Module) bool {
  759. am, ok := child.(android.ApexModule)
  760. if !ok || !am.CanHaveApexVariants() {
  761. return false
  762. }
  763. depTag := mctx.OtherModuleDependencyTag(child)
  764. // Check to see if the tag always requires that the child module has an apex variant for every
  765. // apex variant of the parent module. If it does not then it is still possible for something
  766. // else, e.g. the DepIsInSameApex(...) method to decide that a variant is required.
  767. if required, ok := depTag.(android.AlwaysRequireApexVariantTag); ok && required.AlwaysRequireApexVariant() {
  768. return true
  769. }
  770. if !android.IsDepInSameApex(mctx, parent, child) {
  771. return false
  772. }
  773. if excludeVndkLibs {
  774. if c, ok := child.(*cc.Module); ok && c.IsVndk() {
  775. return false
  776. }
  777. }
  778. // By default, all the transitive dependencies are collected, unless filtered out
  779. // above.
  780. return true
  781. }
  782. // Records whether a certain module is included in this apexBundle via direct dependency or
  783. // inndirect dependency.
  784. contents := make(map[string]android.ApexMembership)
  785. mctx.WalkDeps(func(child, parent android.Module) bool {
  786. if !continueApexDepsWalk(child, parent) {
  787. return false
  788. }
  789. // If the parent is apexBundle, this child is directly depended.
  790. _, directDep := parent.(*apexBundle)
  791. depName := mctx.OtherModuleName(child)
  792. contents[depName] = contents[depName].Add(directDep)
  793. return true
  794. })
  795. // The membership information is saved for later access
  796. apexContents := android.NewApexContents(contents)
  797. mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
  798. Contents: apexContents,
  799. })
  800. minSdkVersion := a.minSdkVersion(mctx)
  801. // When min_sdk_version is not set, the apex is built against FutureApiLevel.
  802. if minSdkVersion.IsNone() {
  803. minSdkVersion = android.FutureApiLevel
  804. }
  805. // This is the main part of this mutator. Mark the collected dependencies that they need to
  806. // be built for this apexBundle.
  807. apexVariationName := proptools.StringDefault(a.properties.Apex_name, mctx.ModuleName()) // could be com.android.foo
  808. a.properties.ApexVariationName = apexVariationName
  809. apexInfo := android.ApexInfo{
  810. ApexVariationName: apexVariationName,
  811. MinSdkVersion: minSdkVersion,
  812. RequiredSdks: a.RequiredSdks(),
  813. Updatable: a.Updatable(),
  814. UsePlatformApis: a.UsePlatformApis(),
  815. InApexVariants: []string{apexVariationName},
  816. InApexModules: []string{a.Name()}, // could be com.mycompany.android.foo
  817. ApexContents: []*android.ApexContents{apexContents},
  818. }
  819. mctx.WalkDeps(func(child, parent android.Module) bool {
  820. if !continueApexDepsWalk(child, parent) {
  821. return false
  822. }
  823. child.(android.ApexModule).BuildForApex(apexInfo) // leave a mark!
  824. return true
  825. })
  826. }
  827. type ApexInfoMutator interface {
  828. // ApexVariationName returns the name of the APEX variation to use in the apex
  829. // mutator etc. It is the same name as ApexInfo.ApexVariationName.
  830. ApexVariationName() string
  831. // ApexInfoMutator implementations must call BuildForApex(ApexInfo) on any modules that are
  832. // depended upon by an apex and which require an apex specific variant.
  833. ApexInfoMutator(android.TopDownMutatorContext)
  834. }
  835. // apexInfoMutator delegates the work of identifying which modules need an ApexInfo and apex
  836. // specific variant to modules that support the ApexInfoMutator.
  837. func apexInfoMutator(mctx android.TopDownMutatorContext) {
  838. if !mctx.Module().Enabled() {
  839. return
  840. }
  841. if a, ok := mctx.Module().(ApexInfoMutator); ok {
  842. a.ApexInfoMutator(mctx)
  843. return
  844. }
  845. }
  846. // apexStrictUpdatibilityLintMutator propagates strict_updatability_linting to transitive deps of a mainline module
  847. // This check is enforced for updatable modules
  848. func apexStrictUpdatibilityLintMutator(mctx android.TopDownMutatorContext) {
  849. if !mctx.Module().Enabled() {
  850. return
  851. }
  852. if apex, ok := mctx.Module().(*apexBundle); ok && apex.checkStrictUpdatabilityLinting() {
  853. mctx.WalkDeps(func(child, parent android.Module) bool {
  854. // b/208656169 Do not propagate strict updatability linting to libcore/
  855. // These libs are available on the classpath during compilation
  856. // These libs are transitive deps of the sdk. See java/sdk.go:decodeSdkDep
  857. // Only skip libraries defined in libcore root, not subdirectories
  858. if mctx.OtherModuleDir(child) == "libcore" {
  859. // Do not traverse transitive deps of libcore/ libs
  860. return false
  861. }
  862. if android.InList(child.Name(), skipLintJavalibAllowlist) {
  863. return false
  864. }
  865. if lintable, ok := child.(java.LintDepSetsIntf); ok {
  866. lintable.SetStrictUpdatabilityLinting(true)
  867. }
  868. // visit transitive deps
  869. return true
  870. })
  871. }
  872. }
  873. // TODO: b/215736885 Whittle the denylist
  874. // Transitive deps of certain mainline modules baseline NewApi errors
  875. // Skip these mainline modules for now
  876. var (
  877. skipStrictUpdatabilityLintAllowlist = []string{
  878. "com.android.art",
  879. "com.android.art.debug",
  880. "com.android.conscrypt",
  881. "com.android.media",
  882. // test apexes
  883. "test_com.android.art",
  884. "test_com.android.conscrypt",
  885. "test_com.android.media",
  886. "test_jitzygote_com.android.art",
  887. }
  888. // TODO: b/215736885 Remove this list
  889. skipLintJavalibAllowlist = []string{
  890. "conscrypt.module.platform.api.stubs",
  891. "conscrypt.module.public.api.stubs",
  892. "conscrypt.module.public.api.stubs.system",
  893. "conscrypt.module.public.api.stubs.module_lib",
  894. "framework-media.stubs",
  895. "framework-media.stubs.system",
  896. "framework-media.stubs.module_lib",
  897. }
  898. )
  899. func (a *apexBundle) checkStrictUpdatabilityLinting() bool {
  900. return a.Updatable() && !android.InList(a.ApexVariationName(), skipStrictUpdatabilityLintAllowlist)
  901. }
  902. // apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use
  903. // unique apex variations for this module. See android/apex.go for more about unique apex variant.
  904. // TODO(jiyong): move this to android/apex.go?
  905. func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
  906. if !mctx.Module().Enabled() {
  907. return
  908. }
  909. if am, ok := mctx.Module().(android.ApexModule); ok {
  910. android.UpdateUniqueApexVariationsForDeps(mctx, am)
  911. }
  912. }
  913. // apexTestForDepsMutator checks if this module is a test for an apex. If so, add a dependency on
  914. // the apex in order to retrieve its contents later.
  915. // TODO(jiyong): move this to android/apex.go?
  916. func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
  917. if !mctx.Module().Enabled() {
  918. return
  919. }
  920. if am, ok := mctx.Module().(android.ApexModule); ok {
  921. if testFor := am.TestFor(); len(testFor) > 0 {
  922. mctx.AddFarVariationDependencies([]blueprint.Variation{
  923. {Mutator: "os", Variation: am.Target().OsVariation()},
  924. {"arch", "common"},
  925. }, testForTag, testFor...)
  926. }
  927. }
  928. }
  929. // TODO(jiyong): move this to android/apex.go?
  930. func apexTestForMutator(mctx android.BottomUpMutatorContext) {
  931. if !mctx.Module().Enabled() {
  932. return
  933. }
  934. if _, ok := mctx.Module().(android.ApexModule); ok {
  935. var contents []*android.ApexContents
  936. for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
  937. abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
  938. contents = append(contents, abInfo.Contents)
  939. }
  940. mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
  941. ApexContents: contents,
  942. })
  943. }
  944. }
  945. // markPlatformAvailability marks whether or not a module can be available to platform. A module
  946. // cannot be available to platform if 1) it is explicitly marked as not available (i.e.
  947. // "//apex_available:platform" is absent) or 2) it depends on another module that isn't (or can't
  948. // be) available to platform
  949. // TODO(jiyong): move this to android/apex.go?
  950. func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
  951. // Host and recovery are not considered as platform
  952. if mctx.Host() || mctx.Module().InstallInRecovery() {
  953. return
  954. }
  955. am, ok := mctx.Module().(android.ApexModule)
  956. if !ok {
  957. return
  958. }
  959. availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
  960. // If any of the dep is not available to platform, this module is also considered as being
  961. // not available to platform even if it has "//apex_available:platform"
  962. mctx.VisitDirectDeps(func(child android.Module) {
  963. if !android.IsDepInSameApex(mctx, am, child) {
  964. // if the dependency crosses apex boundary, don't consider it
  965. return
  966. }
  967. if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
  968. availableToPlatform = false
  969. // TODO(b/154889534) trigger an error when 'am' has
  970. // "//apex_available:platform"
  971. }
  972. })
  973. // Exception 1: check to see if the module always requires it.
  974. if am.AlwaysRequiresPlatformApexVariant() {
  975. availableToPlatform = true
  976. }
  977. // Exception 2: bootstrap bionic libraries are also always available to platform
  978. if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
  979. availableToPlatform = true
  980. }
  981. if !availableToPlatform {
  982. am.SetNotAvailableForPlatform()
  983. }
  984. }
  985. // apexMutator visits each module and creates apex variations if the module was marked in the
  986. // previous run of apexInfoMutator.
  987. func apexMutator(mctx android.BottomUpMutatorContext) {
  988. if !mctx.Module().Enabled() {
  989. return
  990. }
  991. // This is the usual path.
  992. if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
  993. android.CreateApexVariations(mctx, am)
  994. return
  995. }
  996. // apexBundle itself is mutated so that it and its dependencies have the same apex variant.
  997. if ai, ok := mctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) {
  998. apexBundleName := ai.ApexVariationName()
  999. mctx.CreateVariations(apexBundleName)
  1000. if strings.HasPrefix(apexBundleName, "com.android.art") {
  1001. // Create an alias from the platform variant. This is done to make
  1002. // test_for dependencies work for modules that are split by the APEX
  1003. // mutator, since test_for dependencies always go to the platform variant.
  1004. // This doesn't happen for normal APEXes that are disjunct, so only do
  1005. // this for the overlapping ART APEXes.
  1006. // TODO(b/183882457): Remove this if the test_for functionality is
  1007. // refactored to depend on the proper APEX variants instead of platform.
  1008. mctx.CreateAliasVariation("", apexBundleName)
  1009. }
  1010. } else if o, ok := mctx.Module().(*OverrideApex); ok {
  1011. apexBundleName := o.GetOverriddenModuleName()
  1012. if apexBundleName == "" {
  1013. mctx.ModuleErrorf("base property is not set")
  1014. return
  1015. }
  1016. mctx.CreateVariations(apexBundleName)
  1017. if strings.HasPrefix(apexBundleName, "com.android.art") {
  1018. // TODO(b/183882457): See note for CreateAliasVariation above.
  1019. mctx.CreateAliasVariation("", apexBundleName)
  1020. }
  1021. }
  1022. }
  1023. // apexModuleTypeRequiresVariant determines whether the module supplied requires an apex specific
  1024. // variant.
  1025. func apexModuleTypeRequiresVariant(module ApexInfoMutator) bool {
  1026. if a, ok := module.(*apexBundle); ok {
  1027. // TODO(jiyong): document the reason why the VNDK APEX is an exception here.
  1028. return !a.vndkApex
  1029. }
  1030. return true
  1031. }
  1032. // See android.UpdateDirectlyInAnyApex
  1033. // TODO(jiyong): move this to android/apex.go?
  1034. func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
  1035. if !mctx.Module().Enabled() {
  1036. return
  1037. }
  1038. if am, ok := mctx.Module().(android.ApexModule); ok {
  1039. android.UpdateDirectlyInAnyApex(mctx, am)
  1040. }
  1041. }
  1042. // apexPackaging represents a specific packaging method for an APEX.
  1043. type apexPackaging int
  1044. const (
  1045. // imageApex is a packaging method where contents are included in a filesystem image which
  1046. // is then included in a zip container. This is the most typical way of packaging.
  1047. imageApex apexPackaging = iota
  1048. // zipApex is a packaging method where contents are directly included in the zip container.
  1049. // This is used for host-side testing - because the contents are easily accessible by
  1050. // unzipping the container.
  1051. zipApex
  1052. // flattendApex is a packaging method where contents are not included in the APEX file, but
  1053. // installed to /apex/<apexname> directory on the device. This packaging method is used for
  1054. // old devices where the filesystem-based APEX file can't be supported.
  1055. flattenedApex
  1056. )
  1057. const (
  1058. // File extensions of an APEX for different packaging methods
  1059. imageApexSuffix = ".apex"
  1060. imageCapexSuffix = ".capex"
  1061. zipApexSuffix = ".zipapex"
  1062. flattenedSuffix = ".flattened"
  1063. // variant names each of which is for a packaging method
  1064. imageApexType = "image"
  1065. zipApexType = "zip"
  1066. flattenedApexType = "flattened"
  1067. ext4FsType = "ext4"
  1068. f2fsFsType = "f2fs"
  1069. erofsFsType = "erofs"
  1070. )
  1071. // The suffix for the output "file", not the module
  1072. func (a apexPackaging) suffix() string {
  1073. switch a {
  1074. case imageApex:
  1075. return imageApexSuffix
  1076. case zipApex:
  1077. return zipApexSuffix
  1078. default:
  1079. panic(fmt.Errorf("unknown APEX type %d", a))
  1080. }
  1081. }
  1082. func (a apexPackaging) name() string {
  1083. switch a {
  1084. case imageApex:
  1085. return imageApexType
  1086. case zipApex:
  1087. return zipApexType
  1088. default:
  1089. panic(fmt.Errorf("unknown APEX type %d", a))
  1090. }
  1091. }
  1092. // apexFlattenedMutator creates one or more variations each of which is for a packaging method.
  1093. // TODO(jiyong): give a better name to this mutator
  1094. func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
  1095. if !mctx.Module().Enabled() {
  1096. return
  1097. }
  1098. if ab, ok := mctx.Module().(*apexBundle); ok {
  1099. var variants []string
  1100. switch proptools.StringDefault(ab.properties.Payload_type, "image") {
  1101. case "image":
  1102. // This is the normal case. Note that both image and flattend APEXes are
  1103. // created. The image type is installed to the system partition, while the
  1104. // flattened APEX is (optionally) installed to the system_ext partition.
  1105. // This is mostly for GSI which has to support wide range of devices. If GSI
  1106. // is installed on a newer (APEX-capable) device, the image APEX in the
  1107. // system will be used. However, if the same GSI is installed on an old
  1108. // device which can't support image APEX, the flattened APEX in the
  1109. // system_ext partion (which still is part of GSI) is used instead.
  1110. variants = append(variants, imageApexType, flattenedApexType)
  1111. case "zip":
  1112. variants = append(variants, zipApexType)
  1113. case "both":
  1114. variants = append(variants, imageApexType, zipApexType, flattenedApexType)
  1115. default:
  1116. mctx.PropertyErrorf("payload_type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
  1117. return
  1118. }
  1119. modules := mctx.CreateLocalVariations(variants...)
  1120. for i, v := range variants {
  1121. switch v {
  1122. case imageApexType:
  1123. modules[i].(*apexBundle).properties.ApexType = imageApex
  1124. case zipApexType:
  1125. modules[i].(*apexBundle).properties.ApexType = zipApex
  1126. case flattenedApexType:
  1127. modules[i].(*apexBundle).properties.ApexType = flattenedApex
  1128. // See the comment above for why system_ext.
  1129. if !mctx.Config().FlattenApex() && ab.Platform() {
  1130. modules[i].(*apexBundle).MakeAsSystemExt()
  1131. }
  1132. }
  1133. }
  1134. } else if _, ok := mctx.Module().(*OverrideApex); ok {
  1135. // payload_type is forcibly overridden to "image"
  1136. // TODO(jiyong): is this the right decision?
  1137. mctx.CreateVariations(imageApexType, flattenedApexType)
  1138. }
  1139. }
  1140. var _ android.DepIsInSameApex = (*apexBundle)(nil)
  1141. // Implements android.DepInInSameApex
  1142. func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
  1143. // direct deps of an APEX bundle are all part of the APEX bundle
  1144. // TODO(jiyong): shouldn't we look into the payload field of the dependencyTag?
  1145. return true
  1146. }
  1147. var _ android.OutputFileProducer = (*apexBundle)(nil)
  1148. // Implements android.OutputFileProducer
  1149. func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
  1150. switch tag {
  1151. case "", android.DefaultDistTag:
  1152. // This is the default dist path.
  1153. return android.Paths{a.outputFile}, nil
  1154. case imageApexSuffix:
  1155. // uncompressed one
  1156. if a.outputApexFile != nil {
  1157. return android.Paths{a.outputApexFile}, nil
  1158. }
  1159. fallthrough
  1160. default:
  1161. return nil, fmt.Errorf("unsupported module reference tag %q", tag)
  1162. }
  1163. }
  1164. var _ multitree.Exportable = (*apexBundle)(nil)
  1165. func (a *apexBundle) Exportable() bool {
  1166. if a.properties.ApexType == flattenedApex {
  1167. return false
  1168. }
  1169. return true
  1170. }
  1171. func (a *apexBundle) TaggedOutputs() map[string]android.Paths {
  1172. ret := make(map[string]android.Paths)
  1173. ret["apex"] = android.Paths{a.outputFile}
  1174. return ret
  1175. }
  1176. var _ cc.Coverage = (*apexBundle)(nil)
  1177. // Implements cc.Coverage
  1178. func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
  1179. return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
  1180. }
  1181. // Implements cc.Coverage
  1182. func (a *apexBundle) SetPreventInstall() {
  1183. a.properties.PreventInstall = true
  1184. }
  1185. // Implements cc.Coverage
  1186. func (a *apexBundle) HideFromMake() {
  1187. a.properties.HideFromMake = true
  1188. // This HideFromMake is shadowing the ModuleBase one, call through to it for now.
  1189. // TODO(ccross): untangle these
  1190. a.ModuleBase.HideFromMake()
  1191. }
  1192. // Implements cc.Coverage
  1193. func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
  1194. a.properties.IsCoverageVariant = coverage
  1195. }
  1196. // Implements cc.Coverage
  1197. func (a *apexBundle) EnableCoverageIfNeeded() {}
  1198. var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
  1199. // Implements android.ApexBundleDepsInfoIntf
  1200. func (a *apexBundle) Updatable() bool {
  1201. return proptools.BoolDefault(a.properties.Updatable, true)
  1202. }
  1203. func (a *apexBundle) FutureUpdatable() bool {
  1204. return proptools.BoolDefault(a.properties.Future_updatable, false)
  1205. }
  1206. func (a *apexBundle) UsePlatformApis() bool {
  1207. return proptools.BoolDefault(a.properties.Platform_apis, false)
  1208. }
  1209. // getCertString returns the name of the cert that should be used to sign this APEX. This is
  1210. // basically from the "certificate" property, but could be overridden by the device config.
  1211. func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
  1212. moduleName := ctx.ModuleName()
  1213. // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the
  1214. // OVERRIDE_* list, we check with the pseudo module name to see if its certificate is
  1215. // overridden.
  1216. if a.vndkApex {
  1217. moduleName = vndkApexName
  1218. }
  1219. certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
  1220. if overridden {
  1221. return ":" + certificate
  1222. }
  1223. return String(a.overridableProperties.Certificate)
  1224. }
  1225. // See the installable property
  1226. func (a *apexBundle) installable() bool {
  1227. return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
  1228. }
  1229. // See the generate_hashtree property
  1230. func (a *apexBundle) shouldGenerateHashtree() bool {
  1231. return proptools.BoolDefault(a.properties.Generate_hashtree, true)
  1232. }
  1233. // See the test_only_unsigned_payload property
  1234. func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
  1235. return proptools.Bool(a.properties.Test_only_unsigned_payload)
  1236. }
  1237. // See the test_only_force_compression property
  1238. func (a *apexBundle) testOnlyShouldForceCompression() bool {
  1239. return proptools.Bool(a.properties.Test_only_force_compression)
  1240. }
  1241. // These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its
  1242. // members) can be sanitized, either forcibly, or by the global configuration. For some of the
  1243. // sanitizers, extra dependencies can be forcibly added as well.
  1244. func (a *apexBundle) EnableSanitizer(sanitizerName string) {
  1245. if !android.InList(sanitizerName, a.properties.SanitizerNames) {
  1246. a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
  1247. }
  1248. }
  1249. func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
  1250. if android.InList(sanitizerName, a.properties.SanitizerNames) {
  1251. return true
  1252. }
  1253. // Then follow the global setting
  1254. globalSanitizerNames := []string{}
  1255. if a.Host() {
  1256. globalSanitizerNames = ctx.Config().SanitizeHost()
  1257. } else {
  1258. arches := ctx.Config().SanitizeDeviceArch()
  1259. if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
  1260. globalSanitizerNames = ctx.Config().SanitizeDevice()
  1261. }
  1262. }
  1263. return android.InList(sanitizerName, globalSanitizerNames)
  1264. }
  1265. func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
  1266. // TODO(jiyong): move this info (the sanitizer name, the lib name, etc.) to cc/sanitize.go
  1267. // Keep only the mechanism here.
  1268. if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
  1269. imageVariation := a.getImageVariation(ctx)
  1270. for _, target := range ctx.MultiTargets() {
  1271. if target.Arch.ArchType.Multilib == "lib64" {
  1272. addDependenciesForNativeModules(ctx, ApexNativeDependencies{
  1273. Native_shared_libs: []string{"libclang_rt.hwasan"},
  1274. Tests: nil,
  1275. Jni_libs: nil,
  1276. Binaries: nil,
  1277. }, target, imageVariation)
  1278. break
  1279. }
  1280. }
  1281. }
  1282. }
  1283. // apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The
  1284. // returned apexFile saves information about the Soong module that will be used for creating the
  1285. // build rules.
  1286. func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
  1287. // Decide the APEX-local directory by the multilib of the library In the future, we may
  1288. // query this to the module.
  1289. // TODO(jiyong): use the new PackagingSpec
  1290. var dirInApex string
  1291. switch ccMod.Arch().ArchType.Multilib {
  1292. case "lib32":
  1293. dirInApex = "lib"
  1294. case "lib64":
  1295. dirInApex = "lib64"
  1296. }
  1297. if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
  1298. dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
  1299. }
  1300. dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
  1301. if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
  1302. // Special case for Bionic libs and other libs installed with them. This is to
  1303. // prevent those libs from being included in the search path
  1304. // /apex/com.android.runtime/${LIB}. This exclusion is required because those libs
  1305. // in the Runtime APEX are available via the legacy paths in /system/lib/. By the
  1306. // init process, the libs in the APEX are bind-mounted to the legacy paths and thus
  1307. // will be loaded into the default linker namespace (aka "platform" namespace). If
  1308. // the libs are directly in /apex/com.android.runtime/${LIB} then the same libs will
  1309. // be loaded again into the runtime linker namespace, which will result in double
  1310. // loading of them, which isn't supported.
  1311. dirInApex = filepath.Join(dirInApex, "bionic")
  1312. }
  1313. fileToCopy := ccMod.OutputFile().Path()
  1314. androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
  1315. return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
  1316. }
  1317. func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
  1318. dirInApex := "bin"
  1319. if cc.Target().NativeBridge == android.NativeBridgeEnabled {
  1320. dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
  1321. }
  1322. dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
  1323. fileToCopy := cc.OutputFile().Path()
  1324. androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
  1325. af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
  1326. af.symlinks = cc.Symlinks()
  1327. af.dataPaths = cc.DataPaths()
  1328. return af
  1329. }
  1330. func apexFileForRustExecutable(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
  1331. dirInApex := "bin"
  1332. if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
  1333. dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
  1334. }
  1335. fileToCopy := rustm.OutputFile().Path()
  1336. androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
  1337. af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, rustm)
  1338. return af
  1339. }
  1340. func apexFileForRustLibrary(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
  1341. // Decide the APEX-local directory by the multilib of the library
  1342. // In the future, we may query this to the module.
  1343. var dirInApex string
  1344. switch rustm.Arch().ArchType.Multilib {
  1345. case "lib32":
  1346. dirInApex = "lib"
  1347. case "lib64":
  1348. dirInApex = "lib64"
  1349. }
  1350. if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
  1351. dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
  1352. }
  1353. fileToCopy := rustm.OutputFile().Path()
  1354. androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
  1355. return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, rustm)
  1356. }
  1357. func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
  1358. dirInApex := "bin"
  1359. fileToCopy := py.HostToolPath().Path()
  1360. return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
  1361. }
  1362. func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
  1363. dirInApex := "bin"
  1364. fileToCopy := android.PathForGoBinary(ctx, gb)
  1365. // NB: Since go binaries are static we don't need the module for anything here, which is
  1366. // good since the go tool is a blueprint.Module not an android.Module like we would
  1367. // normally use.
  1368. return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
  1369. }
  1370. func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
  1371. dirInApex := filepath.Join("bin", sh.SubDir())
  1372. if sh.Target().NativeBridge == android.NativeBridgeEnabled {
  1373. dirInApex = filepath.Join(dirInApex, sh.Target().NativeBridgeRelativePath)
  1374. }
  1375. fileToCopy := sh.OutputFile()
  1376. af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
  1377. af.symlinks = sh.Symlinks()
  1378. return af
  1379. }
  1380. func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
  1381. dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
  1382. fileToCopy := prebuilt.OutputFile()
  1383. return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
  1384. }
  1385. func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
  1386. dirInApex := filepath.Join("etc", config.SubDir())
  1387. fileToCopy := config.CompatConfig()
  1388. return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
  1389. }
  1390. // javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same
  1391. // way.
  1392. type javaModule interface {
  1393. android.Module
  1394. BaseModuleName() string
  1395. DexJarBuildPath() java.OptionalDexJarPath
  1396. JacocoReportClassesFile() android.Path
  1397. LintDepSets() java.LintDepSets
  1398. Stem() string
  1399. }
  1400. var _ javaModule = (*java.Library)(nil)
  1401. var _ javaModule = (*java.Import)(nil)
  1402. var _ javaModule = (*java.SdkLibrary)(nil)
  1403. var _ javaModule = (*java.DexImport)(nil)
  1404. var _ javaModule = (*java.SdkLibraryImport)(nil)
  1405. // apexFileForJavaModule creates an apexFile for a java module's dex implementation jar.
  1406. func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile {
  1407. return apexFileForJavaModuleWithFile(ctx, module, module.DexJarBuildPath().PathOrNil())
  1408. }
  1409. // apexFileForJavaModuleWithFile creates an apexFile for a java module with the supplied file.
  1410. func apexFileForJavaModuleWithFile(ctx android.BaseModuleContext, module javaModule, dexImplementationJar android.Path) apexFile {
  1411. dirInApex := "javalib"
  1412. af := newApexFile(ctx, dexImplementationJar, module.BaseModuleName(), dirInApex, javaSharedLib, module)
  1413. af.jacocoReportClassesFile = module.JacocoReportClassesFile()
  1414. af.lintDepSets = module.LintDepSets()
  1415. af.customStem = module.Stem() + ".jar"
  1416. if dexpreopter, ok := module.(java.DexpreopterInterface); ok {
  1417. for _, install := range dexpreopter.DexpreoptBuiltInstalledForApex() {
  1418. af.requiredModuleNames = append(af.requiredModuleNames, install.FullModuleName())
  1419. }
  1420. }
  1421. return af
  1422. }
  1423. // androidApp is an interface to handle all app modules (android_app, android_app_import, etc.) in
  1424. // the same way.
  1425. type androidApp interface {
  1426. android.Module
  1427. Privileged() bool
  1428. InstallApkName() string
  1429. OutputFile() android.Path
  1430. JacocoReportClassesFile() android.Path
  1431. Certificate() java.Certificate
  1432. BaseModuleName() string
  1433. LintDepSets() java.LintDepSets
  1434. }
  1435. var _ androidApp = (*java.AndroidApp)(nil)
  1436. var _ androidApp = (*java.AndroidAppImport)(nil)
  1437. const APEX_VERSION_PLACEHOLDER = "__APEX_VERSION_PLACEHOLDER__"
  1438. func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile {
  1439. appDir := "app"
  1440. if aapp.Privileged() {
  1441. appDir = "priv-app"
  1442. }
  1443. // TODO(b/224589412, b/226559955): Ensure that the subdirname is suffixed
  1444. // so that PackageManager correctly invalidates the existing installed apk
  1445. // in favour of the new APK-in-APEX. See bugs for more information.
  1446. dirInApex := filepath.Join(appDir, aapp.InstallApkName()+"@"+APEX_VERSION_PLACEHOLDER)
  1447. fileToCopy := aapp.OutputFile()
  1448. af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
  1449. af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
  1450. af.lintDepSets = aapp.LintDepSets()
  1451. af.certificate = aapp.Certificate()
  1452. if app, ok := aapp.(interface {
  1453. OverriddenManifestPackageName() string
  1454. }); ok {
  1455. af.overriddenPackageName = app.OverriddenManifestPackageName()
  1456. }
  1457. return af
  1458. }
  1459. func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
  1460. rroDir := "overlay"
  1461. dirInApex := filepath.Join(rroDir, rro.Theme())
  1462. fileToCopy := rro.OutputFile()
  1463. af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
  1464. af.certificate = rro.Certificate()
  1465. if a, ok := rro.(interface {
  1466. OverriddenManifestPackageName() string
  1467. }); ok {
  1468. af.overriddenPackageName = a.OverriddenManifestPackageName()
  1469. }
  1470. return af
  1471. }
  1472. func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, apex_sub_dir string, bpfProgram bpf.BpfModule) apexFile {
  1473. dirInApex := filepath.Join("etc", "bpf", apex_sub_dir)
  1474. return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
  1475. }
  1476. func apexFileForFilesystem(ctx android.BaseModuleContext, buildFile android.Path, fs filesystem.Filesystem) apexFile {
  1477. dirInApex := filepath.Join("etc", "fs")
  1478. return newApexFile(ctx, buildFile, buildFile.Base(), dirInApex, etc, fs)
  1479. }
  1480. // WalkPayloadDeps visits dependencies that contributes to the payload of this APEX. For each of the
  1481. // visited module, the `do` callback is executed. Returning true in the callback continues the visit
  1482. // to the child modules. Returning false makes the visit to continue in the sibling or the parent
  1483. // modules. This is used in check* functions below.
  1484. func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
  1485. ctx.WalkDeps(func(child, parent android.Module) bool {
  1486. am, ok := child.(android.ApexModule)
  1487. if !ok || !am.CanHaveApexVariants() {
  1488. return false
  1489. }
  1490. // Filter-out unwanted depedendencies
  1491. depTag := ctx.OtherModuleDependencyTag(child)
  1492. if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
  1493. return false
  1494. }
  1495. if dt, ok := depTag.(dependencyTag); ok && !dt.payload {
  1496. return false
  1497. }
  1498. ai := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
  1499. externalDep := !android.InList(ctx.ModuleName(), ai.InApexVariants)
  1500. // Visit actually
  1501. return do(ctx, parent, am, externalDep)
  1502. })
  1503. }
  1504. // filesystem type of the apex_payload.img inside the APEX. Currently, ext4 and f2fs are supported.
  1505. type fsType int
  1506. const (
  1507. ext4 fsType = iota
  1508. f2fs
  1509. erofs
  1510. )
  1511. func (f fsType) string() string {
  1512. switch f {
  1513. case ext4:
  1514. return ext4FsType
  1515. case f2fs:
  1516. return f2fsFsType
  1517. case erofs:
  1518. return erofsFsType
  1519. default:
  1520. panic(fmt.Errorf("unknown APEX payload type %d", f))
  1521. }
  1522. }
  1523. // Creates build rules for an APEX. It consists of the following major steps:
  1524. //
  1525. // 1) do some validity checks such as apex_available, min_sdk_version, etc.
  1526. // 2) traverse the dependency tree to collect apexFile structs from them.
  1527. // 3) some fields in apexBundle struct are configured
  1528. // 4) generate the build rules to create the APEX. This is mostly done in builder.go.
  1529. func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
  1530. ////////////////////////////////////////////////////////////////////////////////////////////
  1531. // 1) do some validity checks such as apex_available, min_sdk_version, etc.
  1532. a.checkApexAvailability(ctx)
  1533. a.checkUpdatable(ctx)
  1534. a.CheckMinSdkVersion(ctx)
  1535. a.checkStaticLinkingToStubLibraries(ctx)
  1536. a.checkStaticExecutables(ctx)
  1537. if len(a.properties.Tests) > 0 && !a.testApex {
  1538. ctx.PropertyErrorf("tests", "property allowed only in apex_test module type")
  1539. return
  1540. }
  1541. ////////////////////////////////////////////////////////////////////////////////////////////
  1542. // 2) traverse the dependency tree to collect apexFile structs from them.
  1543. // all the files that will be included in this APEX
  1544. var filesInfo []apexFile
  1545. // native lib dependencies
  1546. var provideNativeLibs []string
  1547. var requireNativeLibs []string
  1548. handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
  1549. // Collect the module directory for IDE info in java/jdeps.go.
  1550. a.modulePaths = append(a.modulePaths, ctx.ModuleDir())
  1551. // TODO(jiyong): do this using WalkPayloadDeps
  1552. // TODO(jiyong): make this clean!!!
  1553. ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
  1554. depTag := ctx.OtherModuleDependencyTag(child)
  1555. if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
  1556. return false
  1557. }
  1558. if mod, ok := child.(android.Module); ok && !mod.Enabled() {
  1559. return false
  1560. }
  1561. depName := ctx.OtherModuleName(child)
  1562. if _, isDirectDep := parent.(*apexBundle); isDirectDep {
  1563. switch depTag {
  1564. case sharedLibTag, jniLibTag:
  1565. isJniLib := depTag == jniLibTag
  1566. if c, ok := child.(*cc.Module); ok {
  1567. fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
  1568. fi.isJniLib = isJniLib
  1569. filesInfo = append(filesInfo, fi)
  1570. // Collect the list of stub-providing libs except:
  1571. // - VNDK libs are only for vendors
  1572. // - bootstrap bionic libs are treated as provided by system
  1573. if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
  1574. provideNativeLibs = append(provideNativeLibs, fi.stem())
  1575. }
  1576. return true // track transitive dependencies
  1577. } else if r, ok := child.(*rust.Module); ok {
  1578. fi := apexFileForRustLibrary(ctx, r)
  1579. fi.isJniLib = isJniLib
  1580. filesInfo = append(filesInfo, fi)
  1581. return true // track transitive dependencies
  1582. } else {
  1583. propertyName := "native_shared_libs"
  1584. if isJniLib {
  1585. propertyName = "jni_libs"
  1586. }
  1587. ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
  1588. }
  1589. case executableTag:
  1590. if cc, ok := child.(*cc.Module); ok {
  1591. filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
  1592. return true // track transitive dependencies
  1593. } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
  1594. filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
  1595. } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
  1596. filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
  1597. } else if rust, ok := child.(*rust.Module); ok {
  1598. filesInfo = append(filesInfo, apexFileForRustExecutable(ctx, rust))
  1599. return true // track transitive dependencies
  1600. } else {
  1601. ctx.PropertyErrorf("binaries", "%q is neither cc_binary, rust_binary, (embedded) py_binary, (host) blueprint_go_binary, nor (host) bootstrap_go_binary", depName)
  1602. }
  1603. case shBinaryTag:
  1604. if sh, ok := child.(*sh.ShBinary); ok {
  1605. filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
  1606. } else {
  1607. ctx.PropertyErrorf("sh_binaries", "%q is not a sh_binary module", depName)
  1608. }
  1609. case bcpfTag:
  1610. {
  1611. bcpfModule, ok := child.(*java.BootclasspathFragmentModule)
  1612. if !ok {
  1613. ctx.PropertyErrorf("bootclasspath_fragments", "%q is not a bootclasspath_fragment module", depName)
  1614. return false
  1615. }
  1616. filesToAdd := apexBootclasspathFragmentFiles(ctx, child)
  1617. filesInfo = append(filesInfo, filesToAdd...)
  1618. for _, makeModuleName := range bcpfModule.BootImageDeviceInstallMakeModules() {
  1619. a.requiredDeps = append(a.requiredDeps, makeModuleName)
  1620. }
  1621. return true
  1622. }
  1623. case sscpfTag:
  1624. {
  1625. if _, ok := child.(*java.SystemServerClasspathModule); !ok {
  1626. ctx.PropertyErrorf("systemserverclasspath_fragments", "%q is not a systemserverclasspath_fragment module", depName)
  1627. return false
  1628. }
  1629. if af := apexClasspathFragmentProtoFile(ctx, child); af != nil {
  1630. filesInfo = append(filesInfo, *af)
  1631. }
  1632. return true
  1633. }
  1634. case javaLibTag:
  1635. switch child.(type) {
  1636. case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport, *java.Import:
  1637. af := apexFileForJavaModule(ctx, child.(javaModule))
  1638. if !af.ok() {
  1639. ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
  1640. return false
  1641. }
  1642. filesInfo = append(filesInfo, af)
  1643. return true // track transitive dependencies
  1644. default:
  1645. ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
  1646. }
  1647. case androidAppTag:
  1648. if ap, ok := child.(*java.AndroidApp); ok {
  1649. filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
  1650. return true // track transitive dependencies
  1651. } else if ap, ok := child.(*java.AndroidAppImport); ok {
  1652. filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
  1653. } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
  1654. filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
  1655. } else if ap, ok := child.(*java.AndroidAppSet); ok {
  1656. appDir := "app"
  1657. if ap.Privileged() {
  1658. appDir = "priv-app"
  1659. }
  1660. // TODO(b/224589412, b/226559955): Ensure that the dirname is
  1661. // suffixed so that PackageManager correctly invalidates the
  1662. // existing installed apk in favour of the new APK-in-APEX.
  1663. // See bugs for more information.
  1664. appDirName := filepath.Join(appDir, ap.BaseModuleName()+"@"+APEX_VERSION_PLACEHOLDER)
  1665. af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(), appDirName, appSet, ap)
  1666. af.certificate = java.PresignedCertificate
  1667. filesInfo = append(filesInfo, af)
  1668. } else {
  1669. ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
  1670. }
  1671. case rroTag:
  1672. if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
  1673. filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
  1674. } else {
  1675. ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
  1676. }
  1677. case bpfTag:
  1678. if bpfProgram, ok := child.(bpf.BpfModule); ok {
  1679. filesToCopy, _ := bpfProgram.OutputFiles("")
  1680. apex_sub_dir := bpfProgram.SubDir()
  1681. for _, bpfFile := range filesToCopy {
  1682. filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, apex_sub_dir, bpfProgram))
  1683. }
  1684. } else {
  1685. ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
  1686. }
  1687. case fsTag:
  1688. if fs, ok := child.(filesystem.Filesystem); ok {
  1689. filesInfo = append(filesInfo, apexFileForFilesystem(ctx, fs.OutputPath(), fs))
  1690. } else {
  1691. ctx.PropertyErrorf("filesystems", "%q is not a filesystem module", depName)
  1692. }
  1693. case prebuiltTag:
  1694. if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
  1695. filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
  1696. } else {
  1697. ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
  1698. }
  1699. case compatConfigTag:
  1700. if compatConfig, ok := child.(java.PlatformCompatConfigIntf); ok {
  1701. filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, compatConfig, depName))
  1702. } else {
  1703. ctx.PropertyErrorf("compat_configs", "%q is not a platform_compat_config module", depName)
  1704. }
  1705. case testTag:
  1706. if ccTest, ok := child.(*cc.Module); ok {
  1707. if ccTest.IsTestPerSrcAllTestsVariation() {
  1708. // Multiple-output test module (where `test_per_src: true`).
  1709. //
  1710. // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
  1711. // We do not add this variation to `filesInfo`, as it has no output;
  1712. // however, we do add the other variations of this module as indirect
  1713. // dependencies (see below).
  1714. } else {
  1715. // Single-output test module (where `test_per_src: false`).
  1716. af := apexFileForExecutable(ctx, ccTest)
  1717. af.class = nativeTest
  1718. filesInfo = append(filesInfo, af)
  1719. }
  1720. return true // track transitive dependencies
  1721. } else {
  1722. ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
  1723. }
  1724. case keyTag:
  1725. if key, ok := child.(*apexKey); ok {
  1726. a.privateKeyFile = key.privateKeyFile
  1727. a.publicKeyFile = key.publicKeyFile
  1728. } else {
  1729. ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
  1730. }
  1731. return false
  1732. case certificateTag:
  1733. if dep, ok := child.(*java.AndroidAppCertificate); ok {
  1734. a.containerCertificateFile = dep.Certificate.Pem
  1735. a.containerPrivateKeyFile = dep.Certificate.Key
  1736. } else {
  1737. ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
  1738. }
  1739. case android.PrebuiltDepTag:
  1740. // If the prebuilt is force disabled, remember to delete the prebuilt file
  1741. // that might have been installed in the previous builds
  1742. if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
  1743. a.prebuiltFileToDelete = prebuilt.InstallFilename()
  1744. }
  1745. }
  1746. } else if !a.vndkApex {
  1747. // indirect dependencies
  1748. if am, ok := child.(android.ApexModule); ok {
  1749. // We cannot use a switch statement on `depTag` here as the checked
  1750. // tags used below are private (e.g. `cc.sharedDepTag`).
  1751. if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
  1752. if cc, ok := child.(*cc.Module); ok {
  1753. if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
  1754. requireNativeLibs = append(requireNativeLibs, ":vndk")
  1755. return false
  1756. }
  1757. af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
  1758. af.transitiveDep = true
  1759. // Always track transitive dependencies for host.
  1760. if a.Host() {
  1761. filesInfo = append(filesInfo, af)
  1762. return true
  1763. }
  1764. abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
  1765. if !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
  1766. // If the dependency is a stubs lib, don't include it in this APEX,
  1767. // but make sure that the lib is installed on the device.
  1768. // In case no APEX is having the lib, the lib is installed to the system
  1769. // partition.
  1770. //
  1771. // Always include if we are a host-apex however since those won't have any
  1772. // system libraries.
  1773. if !am.DirectlyInAnyApex() {
  1774. // we need a module name for Make
  1775. name := cc.ImplementationModuleNameForMake(ctx) + cc.Properties.SubName
  1776. if !android.InList(name, a.requiredDeps) {
  1777. a.requiredDeps = append(a.requiredDeps, name)
  1778. }
  1779. }
  1780. requireNativeLibs = append(requireNativeLibs, af.stem())
  1781. // Don't track further
  1782. return false
  1783. }
  1784. // If the dep is not considered to be in the same
  1785. // apex, don't add it to filesInfo so that it is not
  1786. // included in this APEX.
  1787. // TODO(jiyong): move this to at the top of the
  1788. // else-if clause for the indirect dependencies.
  1789. // Currently, that's impossible because we would
  1790. // like to record requiredNativeLibs even when
  1791. // DepIsInSameAPex is false. We also shouldn't do
  1792. // this for host.
  1793. //
  1794. // TODO(jiyong): explain why the same module is passed in twice.
  1795. // Switching the first am to parent breaks lots of tests.
  1796. if !android.IsDepInSameApex(ctx, am, am) {
  1797. return false
  1798. }
  1799. filesInfo = append(filesInfo, af)
  1800. return true // track transitive dependencies
  1801. } else if rm, ok := child.(*rust.Module); ok {
  1802. af := apexFileForRustLibrary(ctx, rm)
  1803. af.transitiveDep = true
  1804. filesInfo = append(filesInfo, af)
  1805. return true // track transitive dependencies
  1806. }
  1807. } else if cc.IsTestPerSrcDepTag(depTag) {
  1808. if cc, ok := child.(*cc.Module); ok {
  1809. af := apexFileForExecutable(ctx, cc)
  1810. // Handle modules created as `test_per_src` variations of a single test module:
  1811. // use the name of the generated test binary (`fileToCopy`) instead of the name
  1812. // of the original test module (`depName`, shared by all `test_per_src`
  1813. // variations of that module).
  1814. af.androidMkModuleName = filepath.Base(af.builtFile.String())
  1815. // these are not considered transitive dep
  1816. af.transitiveDep = false
  1817. filesInfo = append(filesInfo, af)
  1818. return true // track transitive dependencies
  1819. }
  1820. } else if cc.IsHeaderDepTag(depTag) {
  1821. // nothing
  1822. } else if java.IsJniDepTag(depTag) {
  1823. // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
  1824. return false
  1825. } else if java.IsXmlPermissionsFileDepTag(depTag) {
  1826. if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
  1827. filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
  1828. }
  1829. } else if rust.IsDylibDepTag(depTag) {
  1830. if rustm, ok := child.(*rust.Module); ok && rustm.IsInstallableToApex() {
  1831. af := apexFileForRustLibrary(ctx, rustm)
  1832. af.transitiveDep = true
  1833. filesInfo = append(filesInfo, af)
  1834. return true // track transitive dependencies
  1835. }
  1836. } else if rust.IsRlibDepTag(depTag) {
  1837. // Rlib is statically linked, but it might have shared lib
  1838. // dependencies. Track them.
  1839. return true
  1840. } else if java.IsBootclasspathFragmentContentDepTag(depTag) {
  1841. // Add the contents of the bootclasspath fragment to the apex.
  1842. switch child.(type) {
  1843. case *java.Library, *java.SdkLibrary:
  1844. javaModule := child.(javaModule)
  1845. af := apexFileForBootclasspathFragmentContentModule(ctx, parent, javaModule)
  1846. if !af.ok() {
  1847. ctx.PropertyErrorf("bootclasspath_fragments", "bootclasspath_fragment content %q is not configured to be compiled into dex", depName)
  1848. return false
  1849. }
  1850. filesInfo = append(filesInfo, af)
  1851. return true // track transitive dependencies
  1852. default:
  1853. ctx.PropertyErrorf("bootclasspath_fragments", "bootclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child))
  1854. }
  1855. } else if java.IsSystemServerClasspathFragmentContentDepTag(depTag) {
  1856. // Add the contents of the systemserverclasspath fragment to the apex.
  1857. switch child.(type) {
  1858. case *java.Library, *java.SdkLibrary:
  1859. af := apexFileForJavaModule(ctx, child.(javaModule))
  1860. filesInfo = append(filesInfo, af)
  1861. return true // track transitive dependencies
  1862. default:
  1863. ctx.PropertyErrorf("systemserverclasspath_fragments", "systemserverclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child))
  1864. }
  1865. } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
  1866. // nothing
  1867. } else if depTag == android.DarwinUniversalVariantTag {
  1868. // nothing
  1869. } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
  1870. ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
  1871. }
  1872. }
  1873. }
  1874. return false
  1875. })
  1876. if a.privateKeyFile == nil {
  1877. ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.overridableProperties.Key))
  1878. return
  1879. }
  1880. // Remove duplicates in filesInfo
  1881. removeDup := func(filesInfo []apexFile) []apexFile {
  1882. encountered := make(map[string]apexFile)
  1883. for _, f := range filesInfo {
  1884. dest := filepath.Join(f.installDir, f.builtFile.Base())
  1885. if e, ok := encountered[dest]; !ok {
  1886. encountered[dest] = f
  1887. } else {
  1888. // If a module is directly included and also transitively depended on
  1889. // consider it as directly included.
  1890. e.transitiveDep = e.transitiveDep && f.transitiveDep
  1891. encountered[dest] = e
  1892. }
  1893. }
  1894. var result []apexFile
  1895. for _, v := range encountered {
  1896. result = append(result, v)
  1897. }
  1898. return result
  1899. }
  1900. filesInfo = removeDup(filesInfo)
  1901. // Sort to have consistent build rules
  1902. sort.Slice(filesInfo, func(i, j int) bool {
  1903. // Sort by destination path so as to ensure consistent ordering even if the source of the files
  1904. // changes.
  1905. return filesInfo[i].path() < filesInfo[j].path()
  1906. })
  1907. ////////////////////////////////////////////////////////////////////////////////////////////
  1908. // 3) some fields in apexBundle struct are configured
  1909. a.installDir = android.PathForModuleInstall(ctx, "apex")
  1910. a.filesInfo = filesInfo
  1911. // Set suffix and primaryApexType depending on the ApexType
  1912. buildFlattenedAsDefault := ctx.Config().FlattenApex()
  1913. switch a.properties.ApexType {
  1914. case imageApex:
  1915. if buildFlattenedAsDefault {
  1916. a.suffix = imageApexSuffix
  1917. } else {
  1918. a.suffix = ""
  1919. a.primaryApexType = true
  1920. if ctx.Config().InstallExtraFlattenedApexes() {
  1921. a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
  1922. }
  1923. }
  1924. case zipApex:
  1925. if proptools.String(a.properties.Payload_type) == "zip" {
  1926. a.suffix = ""
  1927. a.primaryApexType = true
  1928. } else {
  1929. a.suffix = zipApexSuffix
  1930. }
  1931. case flattenedApex:
  1932. if buildFlattenedAsDefault {
  1933. a.suffix = ""
  1934. a.primaryApexType = true
  1935. } else {
  1936. a.suffix = flattenedSuffix
  1937. }
  1938. }
  1939. switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
  1940. case ext4FsType:
  1941. a.payloadFsType = ext4
  1942. case f2fsFsType:
  1943. a.payloadFsType = f2fs
  1944. case erofsFsType:
  1945. a.payloadFsType = erofs
  1946. default:
  1947. ctx.PropertyErrorf("payload_fs_type", "%q is not a valid filesystem for apex [ext4, f2fs, erofs]", *a.properties.Payload_fs_type)
  1948. }
  1949. // Optimization. If we are building bundled APEX, for the files that are gathered due to the
  1950. // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
  1951. // the same library in the system partition, thus effectively sharing the same libraries
  1952. // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
  1953. // in the APEX.
  1954. a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable()
  1955. // APEXes targeting other than system/system_ext partitions use vendor/product variants.
  1956. // So we can't link them to /system/lib libs which are core variants.
  1957. if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
  1958. a.linkToSystemLib = false
  1959. }
  1960. forced := ctx.Config().ForceApexSymlinkOptimization()
  1961. updatable := a.Updatable() || a.FutureUpdatable()
  1962. // We don't need the optimization for updatable APEXes, as it might give false signal
  1963. // to the system health when the APEXes are still bundled (b/149805758).
  1964. if !forced && updatable && a.properties.ApexType == imageApex {
  1965. a.linkToSystemLib = false
  1966. }
  1967. // We also don't want the optimization for host APEXes, because it doesn't make sense.
  1968. if ctx.Host() {
  1969. a.linkToSystemLib = false
  1970. }
  1971. if a.properties.ApexType != zipApex {
  1972. a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx, a.primaryApexType)
  1973. }
  1974. ////////////////////////////////////////////////////////////////////////////////////////////
  1975. // 4) generate the build rules to create the APEX. This is done in builder.go.
  1976. a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
  1977. if a.properties.ApexType == flattenedApex {
  1978. a.buildFlattenedApex(ctx)
  1979. } else {
  1980. a.buildUnflattenedApex(ctx)
  1981. }
  1982. a.buildApexDependencyInfo(ctx)
  1983. a.buildLintReports(ctx)
  1984. // Append meta-files to the filesInfo list so that they are reflected in Android.mk as well.
  1985. if a.installable() {
  1986. // For flattened APEX, make sure that APEX manifest and apex_pubkey are also copied
  1987. // along with other ordinary files. (Note that this is done by apexer for
  1988. // non-flattened APEXes)
  1989. a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
  1990. // Place the public key as apex_pubkey. This is also done by apexer for
  1991. // non-flattened APEXes case.
  1992. // TODO(jiyong): Why do we need this CP rule?
  1993. copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
  1994. ctx.Build(pctx, android.BuildParams{
  1995. Rule: android.Cp,
  1996. Input: a.publicKeyFile,
  1997. Output: copiedPubkey,
  1998. })
  1999. a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
  2000. }
  2001. }
  2002. // apexBootclasspathFragmentFiles returns the list of apexFile structures defining the files that
  2003. // the bootclasspath_fragment contributes to the apex.
  2004. func apexBootclasspathFragmentFiles(ctx android.ModuleContext, module blueprint.Module) []apexFile {
  2005. bootclasspathFragmentInfo := ctx.OtherModuleProvider(module, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
  2006. var filesToAdd []apexFile
  2007. // Add the boot image files, e.g. .art, .oat and .vdex files.
  2008. if bootclasspathFragmentInfo.ShouldInstallBootImageInApex() {
  2009. for arch, files := range bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() {
  2010. dirInApex := filepath.Join("javalib", arch.String())
  2011. for _, f := range files {
  2012. androidMkModuleName := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
  2013. // TODO(b/177892522) - consider passing in the bootclasspath fragment module here instead of nil
  2014. af := newApexFile(ctx, f, androidMkModuleName, dirInApex, etc, nil)
  2015. filesToAdd = append(filesToAdd, af)
  2016. }
  2017. }
  2018. }
  2019. // Add classpaths.proto config.
  2020. if af := apexClasspathFragmentProtoFile(ctx, module); af != nil {
  2021. filesToAdd = append(filesToAdd, *af)
  2022. }
  2023. if pathInApex := bootclasspathFragmentInfo.ProfileInstallPathInApex(); pathInApex != "" {
  2024. pathOnHost := bootclasspathFragmentInfo.ProfilePathOnHost()
  2025. tempPath := android.PathForModuleOut(ctx, "boot_image_profile", pathInApex)
  2026. if pathOnHost != nil {
  2027. // We need to copy the profile to a temporary path with the right filename because the apexer
  2028. // will take the filename as is.
  2029. ctx.Build(pctx, android.BuildParams{
  2030. Rule: android.Cp,
  2031. Input: pathOnHost,
  2032. Output: tempPath,
  2033. })
  2034. } else {
  2035. // At this point, the boot image profile cannot be generated. It is probably because the boot
  2036. // image profile source file does not exist on the branch, or it is not available for the
  2037. // current build target.
  2038. // However, we cannot enforce the boot image profile to be generated because some build
  2039. // targets (such as module SDK) do not need it. It is only needed when the APEX is being
  2040. // built. Therefore, we create an error rule so that an error will occur at the ninja phase
  2041. // only if the APEX is being built.
  2042. ctx.Build(pctx, android.BuildParams{
  2043. Rule: android.ErrorRule,
  2044. Output: tempPath,
  2045. Args: map[string]string{
  2046. "error": "Boot image profile cannot be generated",
  2047. },
  2048. })
  2049. }
  2050. androidMkModuleName := filepath.Base(pathInApex)
  2051. af := newApexFile(ctx, tempPath, androidMkModuleName, filepath.Dir(pathInApex), etc, nil)
  2052. filesToAdd = append(filesToAdd, af)
  2053. }
  2054. return filesToAdd
  2055. }
  2056. // apexClasspathFragmentProtoFile returns *apexFile structure defining the classpath.proto config that
  2057. // the module contributes to the apex; or nil if the proto config was not generated.
  2058. func apexClasspathFragmentProtoFile(ctx android.ModuleContext, module blueprint.Module) *apexFile {
  2059. info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
  2060. if !info.ClasspathFragmentProtoGenerated {
  2061. return nil
  2062. }
  2063. classpathProtoOutput := info.ClasspathFragmentProtoOutput
  2064. af := newApexFile(ctx, classpathProtoOutput, classpathProtoOutput.Base(), info.ClasspathFragmentProtoInstallDir.Rel(), etc, nil)
  2065. return &af
  2066. }
  2067. // apexFileForBootclasspathFragmentContentModule creates an apexFile for a bootclasspath_fragment
  2068. // content module, i.e. a library that is part of the bootclasspath.
  2069. func apexFileForBootclasspathFragmentContentModule(ctx android.ModuleContext, fragmentModule blueprint.Module, javaModule javaModule) apexFile {
  2070. bootclasspathFragmentInfo := ctx.OtherModuleProvider(fragmentModule, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
  2071. // Get the dexBootJar from the bootclasspath_fragment as that is responsible for performing the
  2072. // hidden API encpding.
  2073. dexBootJar, err := bootclasspathFragmentInfo.DexBootJarPathForContentModule(javaModule)
  2074. if err != nil {
  2075. ctx.ModuleErrorf("%s", err)
  2076. }
  2077. // Create an apexFile as for a normal java module but with the dex boot jar provided by the
  2078. // bootclasspath_fragment.
  2079. af := apexFileForJavaModuleWithFile(ctx, javaModule, dexBootJar)
  2080. return af
  2081. }
  2082. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2083. // Factory functions
  2084. //
  2085. func newApexBundle() *apexBundle {
  2086. module := &apexBundle{}
  2087. module.AddProperties(&module.properties)
  2088. module.AddProperties(&module.targetProperties)
  2089. module.AddProperties(&module.archProperties)
  2090. module.AddProperties(&module.overridableProperties)
  2091. android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
  2092. android.InitDefaultableModule(module)
  2093. android.InitSdkAwareModule(module)
  2094. android.InitOverridableModule(module, &module.overridableProperties.Overrides)
  2095. android.InitBazelModule(module)
  2096. multitree.InitExportableModule(module)
  2097. return module
  2098. }
  2099. func ApexBundleFactory(testApex bool) android.Module {
  2100. bundle := newApexBundle()
  2101. bundle.testApex = testApex
  2102. return bundle
  2103. }
  2104. // apex_test is an APEX for testing. The difference from the ordinary apex module type is that
  2105. // certain compatibility checks such as apex_available are not done for apex_test.
  2106. func testApexBundleFactory() android.Module {
  2107. bundle := newApexBundle()
  2108. bundle.testApex = true
  2109. return bundle
  2110. }
  2111. // apex packages other modules into an APEX file which is a packaging format for system-level
  2112. // components like binaries, shared libraries, etc.
  2113. func BundleFactory() android.Module {
  2114. return newApexBundle()
  2115. }
  2116. type Defaults struct {
  2117. android.ModuleBase
  2118. android.DefaultsModuleBase
  2119. }
  2120. // apex_defaults provides defaultable properties to other apex modules.
  2121. func defaultsFactory() android.Module {
  2122. return DefaultsFactory()
  2123. }
  2124. func DefaultsFactory(props ...interface{}) android.Module {
  2125. module := &Defaults{}
  2126. module.AddProperties(props...)
  2127. module.AddProperties(
  2128. &apexBundleProperties{},
  2129. &apexTargetBundleProperties{},
  2130. &overridableProperties{},
  2131. )
  2132. android.InitDefaultsModule(module)
  2133. return module
  2134. }
  2135. type OverrideApex struct {
  2136. android.ModuleBase
  2137. android.OverrideModuleBase
  2138. }
  2139. func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
  2140. // All the overrides happen in the base module.
  2141. }
  2142. // override_apex is used to create an apex module based on another apex module by overriding some of
  2143. // its properties.
  2144. func overrideApexFactory() android.Module {
  2145. m := &OverrideApex{}
  2146. m.AddProperties(&overridableProperties{})
  2147. android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
  2148. android.InitOverrideModule(m)
  2149. return m
  2150. }
  2151. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2152. // Vality check routines
  2153. //
  2154. // These are called in at the very beginning of GenerateAndroidBuildActions to flag an error when
  2155. // certain conditions are not met.
  2156. //
  2157. // TODO(jiyong): move these checks to a separate go file.
  2158. var _ android.ModuleWithMinSdkVersionCheck = (*apexBundle)(nil)
  2159. // Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version
  2160. // of this apexBundle.
  2161. func (a *apexBundle) CheckMinSdkVersion(ctx android.ModuleContext) {
  2162. if a.testApex || a.vndkApex {
  2163. return
  2164. }
  2165. // apexBundle::minSdkVersion reports its own errors.
  2166. minSdkVersion := a.minSdkVersion(ctx)
  2167. android.CheckMinSdkVersion(ctx, minSdkVersion, a.WalkPayloadDeps)
  2168. }
  2169. // Returns apex's min_sdk_version string value, honoring overrides
  2170. func (a *apexBundle) minSdkVersionValue(ctx android.EarlyModuleContext) string {
  2171. // Only override the minSdkVersion value on Apexes which already specify
  2172. // a min_sdk_version (it's optional for non-updatable apexes), and that its
  2173. // min_sdk_version value is lower than the one to override with.
  2174. overrideMinSdkValue := ctx.DeviceConfig().ApexGlobalMinSdkVersionOverride()
  2175. overrideApiLevel := minSdkVersionFromValue(ctx, overrideMinSdkValue)
  2176. originalMinApiLevel := minSdkVersionFromValue(ctx, proptools.String(a.properties.Min_sdk_version))
  2177. isMinSdkSet := a.properties.Min_sdk_version != nil
  2178. isOverrideValueHigher := overrideApiLevel.CompareTo(originalMinApiLevel) > 0
  2179. if overrideMinSdkValue != "" && isMinSdkSet && isOverrideValueHigher {
  2180. return overrideMinSdkValue
  2181. }
  2182. return proptools.String(a.properties.Min_sdk_version)
  2183. }
  2184. // Returns apex's min_sdk_version SdkSpec, honoring overrides
  2185. func (a *apexBundle) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
  2186. return android.SdkSpec{
  2187. Kind: android.SdkNone,
  2188. ApiLevel: a.minSdkVersion(ctx),
  2189. Raw: a.minSdkVersionValue(ctx),
  2190. }
  2191. }
  2192. // Returns apex's min_sdk_version ApiLevel, honoring overrides
  2193. func (a *apexBundle) minSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
  2194. return minSdkVersionFromValue(ctx, a.minSdkVersionValue(ctx))
  2195. }
  2196. // Construct ApiLevel object from min_sdk_version string value
  2197. func minSdkVersionFromValue(ctx android.EarlyModuleContext, value string) android.ApiLevel {
  2198. if value == "" {
  2199. return android.NoneApiLevel
  2200. }
  2201. apiLevel, err := android.ApiLevelFromUser(ctx, value)
  2202. if err != nil {
  2203. ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
  2204. return android.NoneApiLevel
  2205. }
  2206. return apiLevel
  2207. }
  2208. // Ensures that a lib providing stub isn't statically linked
  2209. func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
  2210. // Practically, we only care about regular APEXes on the device.
  2211. if ctx.Host() || a.testApex || a.vndkApex {
  2212. return
  2213. }
  2214. abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
  2215. a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
  2216. if ccm, ok := to.(*cc.Module); ok {
  2217. apexName := ctx.ModuleName()
  2218. fromName := ctx.OtherModuleName(from)
  2219. toName := ctx.OtherModuleName(to)
  2220. // If `to` is not actually in the same APEX as `from` then it does not need
  2221. // apex_available and neither do any of its dependencies.
  2222. //
  2223. // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
  2224. if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
  2225. // As soon as the dependency graph crosses the APEX boundary, don't go further.
  2226. return false
  2227. }
  2228. // The dynamic linker and crash_dump tool in the runtime APEX is the only
  2229. // exception to this rule. It can't make the static dependencies dynamic
  2230. // because it can't do the dynamic linking for itself.
  2231. // Same rule should be applied to linkerconfig, because it should be executed
  2232. // only with static linked libraries before linker is available with ld.config.txt
  2233. if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump" || fromName == "linkerconfig") {
  2234. return false
  2235. }
  2236. isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
  2237. if isStubLibraryFromOtherApex && !externalDep {
  2238. ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
  2239. "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
  2240. }
  2241. }
  2242. return true
  2243. })
  2244. }
  2245. // checkUpdatable enforces APEX and its transitive dep properties to have desired values for updatable APEXes.
  2246. func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
  2247. if a.Updatable() {
  2248. if a.minSdkVersionValue(ctx) == "" {
  2249. ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
  2250. }
  2251. if a.UsePlatformApis() {
  2252. ctx.PropertyErrorf("updatable", "updatable APEXes can't use platform APIs")
  2253. }
  2254. if a.SocSpecific() || a.DeviceSpecific() {
  2255. ctx.PropertyErrorf("updatable", "vendor APEXes are not updatable")
  2256. }
  2257. if a.FutureUpdatable() {
  2258. ctx.PropertyErrorf("future_updatable", "Already updatable. Remove `future_updatable: true:`")
  2259. }
  2260. a.checkJavaStableSdkVersion(ctx)
  2261. a.checkClasspathFragments(ctx)
  2262. }
  2263. }
  2264. // checkClasspathFragments enforces that all classpath fragments in deps generate classpaths.proto config.
  2265. func (a *apexBundle) checkClasspathFragments(ctx android.ModuleContext) {
  2266. ctx.VisitDirectDeps(func(module android.Module) {
  2267. if tag := ctx.OtherModuleDependencyTag(module); tag == bcpfTag || tag == sscpfTag {
  2268. info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
  2269. if !info.ClasspathFragmentProtoGenerated {
  2270. ctx.OtherModuleErrorf(module, "is included in updatable apex %v, it must not set generate_classpaths_proto to false", ctx.ModuleName())
  2271. }
  2272. }
  2273. })
  2274. }
  2275. // checkJavaStableSdkVersion enforces that all Java deps are using stable SDKs to compile.
  2276. func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
  2277. // Visit direct deps only. As long as we guarantee top-level deps are using stable SDKs,
  2278. // java's checkLinkType guarantees correct usage for transitive deps
  2279. ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
  2280. tag := ctx.OtherModuleDependencyTag(module)
  2281. switch tag {
  2282. case javaLibTag, androidAppTag:
  2283. if m, ok := module.(interface {
  2284. CheckStableSdkVersion(ctx android.BaseModuleContext) error
  2285. }); ok {
  2286. if err := m.CheckStableSdkVersion(ctx); err != nil {
  2287. ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
  2288. }
  2289. }
  2290. }
  2291. })
  2292. }
  2293. // checkApexAvailability ensures that the all the dependencies are marked as available for this APEX.
  2294. func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
  2295. // Let's be practical. Availability for test, host, and the VNDK apex isn't important
  2296. if ctx.Host() || a.testApex || a.vndkApex {
  2297. return
  2298. }
  2299. // Because APEXes targeting other than system/system_ext partitions can't set
  2300. // apex_available, we skip checks for these APEXes
  2301. if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
  2302. return
  2303. }
  2304. // Coverage build adds additional dependencies for the coverage-only runtime libraries.
  2305. // Requiring them and their transitive depencies with apex_available is not right
  2306. // because they just add noise.
  2307. if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
  2308. return
  2309. }
  2310. a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
  2311. // As soon as the dependency graph crosses the APEX boundary, don't go further.
  2312. if externalDep {
  2313. return false
  2314. }
  2315. apexName := ctx.ModuleName()
  2316. fromName := ctx.OtherModuleName(from)
  2317. toName := ctx.OtherModuleName(to)
  2318. // If `to` is not actually in the same APEX as `from` then it does not need
  2319. // apex_available and neither do any of its dependencies.
  2320. //
  2321. // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
  2322. if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
  2323. // As soon as the dependency graph crosses the APEX boundary, don't go
  2324. // further.
  2325. return false
  2326. }
  2327. if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
  2328. return true
  2329. }
  2330. ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'."+
  2331. "\n\nDependency path:%s\n\n"+
  2332. "Consider adding %q to 'apex_available' property of %q",
  2333. fromName, toName, ctx.GetPathString(true), apexName, toName)
  2334. // Visit this module's dependencies to check and report any issues with their availability.
  2335. return true
  2336. })
  2337. }
  2338. // checkStaticExecutable ensures that executables in an APEX are not static.
  2339. func (a *apexBundle) checkStaticExecutables(ctx android.ModuleContext) {
  2340. // No need to run this for host APEXes
  2341. if ctx.Host() {
  2342. return
  2343. }
  2344. ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
  2345. if ctx.OtherModuleDependencyTag(module) != executableTag {
  2346. return
  2347. }
  2348. if l, ok := module.(cc.LinkableInterface); ok && l.StaticExecutable() {
  2349. apex := a.ApexVariationName()
  2350. exec := ctx.OtherModuleName(module)
  2351. if isStaticExecutableAllowed(apex, exec) {
  2352. return
  2353. }
  2354. ctx.ModuleErrorf("executable %s is static", ctx.OtherModuleName(module))
  2355. }
  2356. })
  2357. }
  2358. // A small list of exceptions where static executables are allowed in APEXes.
  2359. func isStaticExecutableAllowed(apex string, exec string) bool {
  2360. m := map[string][]string{
  2361. "com.android.runtime": []string{
  2362. "linker",
  2363. "linkerconfig",
  2364. },
  2365. }
  2366. execNames, ok := m[apex]
  2367. return ok && android.InList(exec, execNames)
  2368. }
  2369. // Collect information for opening IDE project files in java/jdeps.go.
  2370. func (a *apexBundle) IDEInfo(dpInfo *android.IdeInfo) {
  2371. dpInfo.Deps = append(dpInfo.Deps, a.overridableProperties.Java_libs...)
  2372. dpInfo.Deps = append(dpInfo.Deps, a.overridableProperties.Bootclasspath_fragments...)
  2373. dpInfo.Deps = append(dpInfo.Deps, a.overridableProperties.Systemserverclasspath_fragments...)
  2374. dpInfo.Paths = append(dpInfo.Paths, a.modulePaths...)
  2375. }
  2376. var (
  2377. apexAvailBaseline = makeApexAvailableBaseline()
  2378. inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
  2379. )
  2380. func baselineApexAvailable(apex, moduleName string) bool {
  2381. key := apex
  2382. moduleName = normalizeModuleName(moduleName)
  2383. if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
  2384. return true
  2385. }
  2386. key = android.AvailableToAnyApex
  2387. if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
  2388. return true
  2389. }
  2390. return false
  2391. }
  2392. func normalizeModuleName(moduleName string) string {
  2393. // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
  2394. // system. Trim the prefix for the check since they are confusing
  2395. moduleName = android.RemoveOptionalPrebuiltPrefix(moduleName)
  2396. if strings.HasPrefix(moduleName, "libclang_rt.") {
  2397. // This module has many arch variants that depend on the product being built.
  2398. // We don't want to list them all
  2399. moduleName = "libclang_rt"
  2400. }
  2401. if strings.HasPrefix(moduleName, "androidx.") {
  2402. // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
  2403. moduleName = "androidx"
  2404. }
  2405. return moduleName
  2406. }
  2407. // Transform the map of apex -> modules to module -> apexes.
  2408. func invertApexBaseline(m map[string][]string) map[string][]string {
  2409. r := make(map[string][]string)
  2410. for apex, modules := range m {
  2411. for _, module := range modules {
  2412. r[module] = append(r[module], apex)
  2413. }
  2414. }
  2415. return r
  2416. }
  2417. // Retrieve the baseline of apexes to which the supplied module belongs.
  2418. func BaselineApexAvailable(moduleName string) []string {
  2419. return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
  2420. }
  2421. // This is a map from apex to modules, which overrides the apex_available setting for that
  2422. // particular module to make it available for the apex regardless of its setting.
  2423. // TODO(b/147364041): remove this
  2424. func makeApexAvailableBaseline() map[string][]string {
  2425. // The "Module separator"s below are employed to minimize merge conflicts.
  2426. m := make(map[string][]string)
  2427. //
  2428. // Module separator
  2429. //
  2430. m["com.android.appsearch"] = []string{
  2431. "icing-java-proto-lite",
  2432. "libprotobuf-java-lite",
  2433. }
  2434. //
  2435. // Module separator
  2436. //
  2437. m["com.android.bluetooth"] = []string{
  2438. "android.hardware.audio.common@5.0",
  2439. "android.hardware.bluetooth.a2dp@1.0",
  2440. "android.hardware.bluetooth.audio@2.0",
  2441. "android.hardware.bluetooth@1.0",
  2442. "android.hardware.bluetooth@1.1",
  2443. "android.hardware.graphics.bufferqueue@1.0",
  2444. "android.hardware.graphics.bufferqueue@2.0",
  2445. "android.hardware.graphics.common@1.0",
  2446. "android.hardware.graphics.common@1.1",
  2447. "android.hardware.graphics.common@1.2",
  2448. "android.hardware.media@1.0",
  2449. "android.hidl.safe_union@1.0",
  2450. "android.hidl.token@1.0",
  2451. "android.hidl.token@1.0-utils",
  2452. "avrcp-target-service",
  2453. "avrcp_headers",
  2454. "bluetooth-protos-lite",
  2455. "bluetooth.mapsapi",
  2456. "com.android.vcard",
  2457. "dnsresolver_aidl_interface-V2-java",
  2458. "ipmemorystore-aidl-interfaces-V5-java",
  2459. "ipmemorystore-aidl-interfaces-java",
  2460. "internal_include_headers",
  2461. "lib-bt-packets",
  2462. "lib-bt-packets-avrcp",
  2463. "lib-bt-packets-base",
  2464. "libFraunhoferAAC",
  2465. "libaudio-a2dp-hw-utils",
  2466. "libaudio-hearing-aid-hw-utils",
  2467. "libbluetooth",
  2468. "libbluetooth-types",
  2469. "libbluetooth-types-header",
  2470. "libbluetooth_gd",
  2471. "libbluetooth_headers",
  2472. "libbluetooth_jni",
  2473. "libbt-audio-hal-interface",
  2474. "libbt-bta",
  2475. "libbt-common",
  2476. "libbt-hci",
  2477. "libbt-platform-protos-lite",
  2478. "libbt-protos-lite",
  2479. "libbt-sbc-decoder",
  2480. "libbt-sbc-encoder",
  2481. "libbt-stack",
  2482. "libbt-utils",
  2483. "libbtcore",
  2484. "libbtdevice",
  2485. "libbte",
  2486. "libbtif",
  2487. "libchrome",
  2488. "libevent",
  2489. "libfmq",
  2490. "libg722codec",
  2491. "libgui_headers",
  2492. "libmedia_headers",
  2493. "libmodpb64",
  2494. "libosi",
  2495. "libstagefright_foundation_headers",
  2496. "libstagefright_headers",
  2497. "libstatslog",
  2498. "libstatssocket",
  2499. "libtinyxml2",
  2500. "libudrv-uipc",
  2501. "libz",
  2502. "media_plugin_headers",
  2503. "net-utils-services-common",
  2504. "netd_aidl_interface-unstable-java",
  2505. "netd_event_listener_interface-java",
  2506. "netlink-client",
  2507. "networkstack-client",
  2508. "sap-api-java-static",
  2509. "services.net",
  2510. }
  2511. //
  2512. // Module separator
  2513. //
  2514. m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
  2515. //
  2516. // Module separator
  2517. //
  2518. m["com.android.extservices"] = []string{
  2519. "error_prone_annotations",
  2520. "ExtServices-core",
  2521. "ExtServices",
  2522. "libtextclassifier-java",
  2523. "libz_current",
  2524. "textclassifier-statsd",
  2525. "TextClassifierNotificationLibNoManifest",
  2526. "TextClassifierServiceLibNoManifest",
  2527. }
  2528. //
  2529. // Module separator
  2530. //
  2531. m["com.android.neuralnetworks"] = []string{
  2532. "android.hardware.neuralnetworks@1.0",
  2533. "android.hardware.neuralnetworks@1.1",
  2534. "android.hardware.neuralnetworks@1.2",
  2535. "android.hardware.neuralnetworks@1.3",
  2536. "android.hidl.allocator@1.0",
  2537. "android.hidl.memory.token@1.0",
  2538. "android.hidl.memory@1.0",
  2539. "android.hidl.safe_union@1.0",
  2540. "libarect",
  2541. "libbuildversion",
  2542. "libmath",
  2543. "libprocpartition",
  2544. }
  2545. //
  2546. // Module separator
  2547. //
  2548. m["com.android.media"] = []string{
  2549. "android.frameworks.bufferhub@1.0",
  2550. "android.hardware.cas.native@1.0",
  2551. "android.hardware.cas@1.0",
  2552. "android.hardware.configstore-utils",
  2553. "android.hardware.configstore@1.0",
  2554. "android.hardware.configstore@1.1",
  2555. "android.hardware.graphics.allocator@2.0",
  2556. "android.hardware.graphics.allocator@3.0",
  2557. "android.hardware.graphics.bufferqueue@1.0",
  2558. "android.hardware.graphics.bufferqueue@2.0",
  2559. "android.hardware.graphics.common@1.0",
  2560. "android.hardware.graphics.common@1.1",
  2561. "android.hardware.graphics.common@1.2",
  2562. "android.hardware.graphics.mapper@2.0",
  2563. "android.hardware.graphics.mapper@2.1",
  2564. "android.hardware.graphics.mapper@3.0",
  2565. "android.hardware.media.omx@1.0",
  2566. "android.hardware.media@1.0",
  2567. "android.hidl.allocator@1.0",
  2568. "android.hidl.memory.token@1.0",
  2569. "android.hidl.memory@1.0",
  2570. "android.hidl.token@1.0",
  2571. "android.hidl.token@1.0-utils",
  2572. "bionic_libc_platform_headers",
  2573. "exoplayer2-extractor",
  2574. "exoplayer2-extractor-annotation-stubs",
  2575. "gl_headers",
  2576. "jsr305",
  2577. "libEGL",
  2578. "libEGL_blobCache",
  2579. "libEGL_getProcAddress",
  2580. "libFLAC",
  2581. "libFLAC-config",
  2582. "libFLAC-headers",
  2583. "libGLESv2",
  2584. "libaacextractor",
  2585. "libamrextractor",
  2586. "libarect",
  2587. "libaudio_system_headers",
  2588. "libaudioclient",
  2589. "libaudioclient_headers",
  2590. "libaudiofoundation",
  2591. "libaudiofoundation_headers",
  2592. "libaudiomanager",
  2593. "libaudiopolicy",
  2594. "libaudioutils",
  2595. "libaudioutils_fixedfft",
  2596. "libbluetooth-types-header",
  2597. "libbufferhub",
  2598. "libbufferhub_headers",
  2599. "libbufferhubqueue",
  2600. "libc_malloc_debug_backtrace",
  2601. "libcamera_client",
  2602. "libcamera_metadata",
  2603. "libdvr_headers",
  2604. "libexpat",
  2605. "libfifo",
  2606. "libflacextractor",
  2607. "libgrallocusage",
  2608. "libgraphicsenv",
  2609. "libgui",
  2610. "libgui_headers",
  2611. "libhardware_headers",
  2612. "libinput",
  2613. "liblzma",
  2614. "libmath",
  2615. "libmedia",
  2616. "libmedia_codeclist",
  2617. "libmedia_headers",
  2618. "libmedia_helper",
  2619. "libmedia_helper_headers",
  2620. "libmedia_midiiowrapper",
  2621. "libmedia_omx",
  2622. "libmediautils",
  2623. "libmidiextractor",
  2624. "libmkvextractor",
  2625. "libmp3extractor",
  2626. "libmp4extractor",
  2627. "libmpeg2extractor",
  2628. "libnativebase_headers",
  2629. "libnativewindow_headers",
  2630. "libnblog",
  2631. "liboggextractor",
  2632. "libpackagelistparser",
  2633. "libpdx",
  2634. "libpdx_default_transport",
  2635. "libpdx_headers",
  2636. "libpdx_uds",
  2637. "libprocinfo",
  2638. "libspeexresampler",
  2639. "libspeexresampler",
  2640. "libstagefright_esds",
  2641. "libstagefright_flacdec",
  2642. "libstagefright_flacdec",
  2643. "libstagefright_foundation",
  2644. "libstagefright_foundation_headers",
  2645. "libstagefright_foundation_without_imemory",
  2646. "libstagefright_headers",
  2647. "libstagefright_id3",
  2648. "libstagefright_metadatautils",
  2649. "libstagefright_mpeg2extractor",
  2650. "libstagefright_mpeg2support",
  2651. "libui",
  2652. "libui_headers",
  2653. "libunwindstack",
  2654. "libvibrator",
  2655. "libvorbisidec",
  2656. "libwavextractor",
  2657. "libwebm",
  2658. "media_ndk_headers",
  2659. "media_plugin_headers",
  2660. "updatable-media",
  2661. }
  2662. //
  2663. // Module separator
  2664. //
  2665. m["com.android.media.swcodec"] = []string{
  2666. "android.frameworks.bufferhub@1.0",
  2667. "android.hardware.common-ndk_platform",
  2668. "android.hardware.configstore-utils",
  2669. "android.hardware.configstore@1.0",
  2670. "android.hardware.configstore@1.1",
  2671. "android.hardware.graphics.allocator@2.0",
  2672. "android.hardware.graphics.allocator@3.0",
  2673. "android.hardware.graphics.allocator@4.0",
  2674. "android.hardware.graphics.bufferqueue@1.0",
  2675. "android.hardware.graphics.bufferqueue@2.0",
  2676. "android.hardware.graphics.common-ndk_platform",
  2677. "android.hardware.graphics.common@1.0",
  2678. "android.hardware.graphics.common@1.1",
  2679. "android.hardware.graphics.common@1.2",
  2680. "android.hardware.graphics.mapper@2.0",
  2681. "android.hardware.graphics.mapper@2.1",
  2682. "android.hardware.graphics.mapper@3.0",
  2683. "android.hardware.graphics.mapper@4.0",
  2684. "android.hardware.media.bufferpool@2.0",
  2685. "android.hardware.media.c2@1.0",
  2686. "android.hardware.media.c2@1.1",
  2687. "android.hardware.media.omx@1.0",
  2688. "android.hardware.media@1.0",
  2689. "android.hardware.media@1.0",
  2690. "android.hidl.memory.token@1.0",
  2691. "android.hidl.memory@1.0",
  2692. "android.hidl.safe_union@1.0",
  2693. "android.hidl.token@1.0",
  2694. "android.hidl.token@1.0-utils",
  2695. "libEGL",
  2696. "libFLAC",
  2697. "libFLAC-config",
  2698. "libFLAC-headers",
  2699. "libFraunhoferAAC",
  2700. "libLibGuiProperties",
  2701. "libarect",
  2702. "libaudio_system_headers",
  2703. "libaudioutils",
  2704. "libaudioutils",
  2705. "libaudioutils_fixedfft",
  2706. "libavcdec",
  2707. "libavcenc",
  2708. "libavservices_minijail",
  2709. "libavservices_minijail",
  2710. "libbinderthreadstateutils",
  2711. "libbluetooth-types-header",
  2712. "libbufferhub_headers",
  2713. "libcodec2",
  2714. "libcodec2_headers",
  2715. "libcodec2_hidl@1.0",
  2716. "libcodec2_hidl@1.1",
  2717. "libcodec2_internal",
  2718. "libcodec2_soft_aacdec",
  2719. "libcodec2_soft_aacenc",
  2720. "libcodec2_soft_amrnbdec",
  2721. "libcodec2_soft_amrnbenc",
  2722. "libcodec2_soft_amrwbdec",
  2723. "libcodec2_soft_amrwbenc",
  2724. "libcodec2_soft_av1dec_gav1",
  2725. "libcodec2_soft_avcdec",
  2726. "libcodec2_soft_avcenc",
  2727. "libcodec2_soft_common",
  2728. "libcodec2_soft_flacdec",
  2729. "libcodec2_soft_flacenc",
  2730. "libcodec2_soft_g711alawdec",
  2731. "libcodec2_soft_g711mlawdec",
  2732. "libcodec2_soft_gsmdec",
  2733. "libcodec2_soft_h263dec",
  2734. "libcodec2_soft_h263enc",
  2735. "libcodec2_soft_hevcdec",
  2736. "libcodec2_soft_hevcenc",
  2737. "libcodec2_soft_mp3dec",
  2738. "libcodec2_soft_mpeg2dec",
  2739. "libcodec2_soft_mpeg4dec",
  2740. "libcodec2_soft_mpeg4enc",
  2741. "libcodec2_soft_opusdec",
  2742. "libcodec2_soft_opusenc",
  2743. "libcodec2_soft_rawdec",
  2744. "libcodec2_soft_vorbisdec",
  2745. "libcodec2_soft_vp8dec",
  2746. "libcodec2_soft_vp8enc",
  2747. "libcodec2_soft_vp9dec",
  2748. "libcodec2_soft_vp9enc",
  2749. "libcodec2_vndk",
  2750. "libdvr_headers",
  2751. "libfmq",
  2752. "libfmq",
  2753. "libgav1",
  2754. "libgralloctypes",
  2755. "libgrallocusage",
  2756. "libgraphicsenv",
  2757. "libgsm",
  2758. "libgui_bufferqueue_static",
  2759. "libgui_headers",
  2760. "libhardware",
  2761. "libhardware_headers",
  2762. "libhevcdec",
  2763. "libhevcenc",
  2764. "libion",
  2765. "libjpeg",
  2766. "liblzma",
  2767. "libmath",
  2768. "libmedia_codecserviceregistrant",
  2769. "libmedia_headers",
  2770. "libmpeg2dec",
  2771. "libnativebase_headers",
  2772. "libnativewindow_headers",
  2773. "libpdx_headers",
  2774. "libscudo_wrapper",
  2775. "libsfplugin_ccodec_utils",
  2776. "libspeexresampler",
  2777. "libstagefright_amrnb_common",
  2778. "libstagefright_amrnbdec",
  2779. "libstagefright_amrnbenc",
  2780. "libstagefright_amrwbdec",
  2781. "libstagefright_amrwbenc",
  2782. "libstagefright_bufferpool@2.0.1",
  2783. "libstagefright_enc_common",
  2784. "libstagefright_flacdec",
  2785. "libstagefright_foundation",
  2786. "libstagefright_foundation_headers",
  2787. "libstagefright_headers",
  2788. "libstagefright_m4vh263dec",
  2789. "libstagefright_m4vh263enc",
  2790. "libstagefright_mp3dec",
  2791. "libui",
  2792. "libui_headers",
  2793. "libunwindstack",
  2794. "libvorbisidec",
  2795. "libvpx",
  2796. "libyuv",
  2797. "libyuv_static",
  2798. "media_ndk_headers",
  2799. "media_plugin_headers",
  2800. "mediaswcodec",
  2801. }
  2802. //
  2803. // Module separator
  2804. //
  2805. m["com.android.mediaprovider"] = []string{
  2806. "MediaProvider",
  2807. "MediaProviderGoogle",
  2808. "fmtlib_ndk",
  2809. "libbase_ndk",
  2810. "libfuse",
  2811. "libfuse_jni",
  2812. }
  2813. //
  2814. // Module separator
  2815. //
  2816. m["com.android.permission"] = []string{
  2817. "car-ui-lib",
  2818. "iconloader",
  2819. "kotlin-annotations",
  2820. "kotlin-stdlib",
  2821. "kotlin-stdlib-jdk7",
  2822. "kotlin-stdlib-jdk8",
  2823. "kotlinx-coroutines-android",
  2824. "kotlinx-coroutines-android-nodeps",
  2825. "kotlinx-coroutines-core",
  2826. "kotlinx-coroutines-core-nodeps",
  2827. "permissioncontroller-statsd",
  2828. "GooglePermissionController",
  2829. "PermissionController",
  2830. "SettingsLibActionBarShadow",
  2831. "SettingsLibAppPreference",
  2832. "SettingsLibBarChartPreference",
  2833. "SettingsLibLayoutPreference",
  2834. "SettingsLibProgressBar",
  2835. "SettingsLibSearchWidget",
  2836. "SettingsLibSettingsTheme",
  2837. "SettingsLibRestrictedLockUtils",
  2838. "SettingsLibHelpUtils",
  2839. }
  2840. //
  2841. // Module separator
  2842. //
  2843. m["com.android.runtime"] = []string{
  2844. "bionic_libc_platform_headers",
  2845. "libarm-optimized-routines-math",
  2846. "libc_aeabi",
  2847. "libc_bionic",
  2848. "libc_bionic_ndk",
  2849. "libc_bootstrap",
  2850. "libc_common",
  2851. "libc_common_shared",
  2852. "libc_common_static",
  2853. "libc_dns",
  2854. "libc_dynamic_dispatch",
  2855. "libc_fortify",
  2856. "libc_freebsd",
  2857. "libc_freebsd_large_stack",
  2858. "libc_gdtoa",
  2859. "libc_init_dynamic",
  2860. "libc_init_static",
  2861. "libc_jemalloc_wrapper",
  2862. "libc_netbsd",
  2863. "libc_nomalloc",
  2864. "libc_nopthread",
  2865. "libc_openbsd",
  2866. "libc_openbsd_large_stack",
  2867. "libc_openbsd_ndk",
  2868. "libc_pthread",
  2869. "libc_static_dispatch",
  2870. "libc_syscalls",
  2871. "libc_tzcode",
  2872. "libc_unwind_static",
  2873. "libdebuggerd",
  2874. "libdebuggerd_common_headers",
  2875. "libdebuggerd_handler_core",
  2876. "libdebuggerd_handler_fallback",
  2877. "libdl_static",
  2878. "libjemalloc5",
  2879. "liblinker_main",
  2880. "liblinker_malloc",
  2881. "liblz4",
  2882. "liblzma",
  2883. "libprocinfo",
  2884. "libpropertyinfoparser",
  2885. "libscudo",
  2886. "libstdc++",
  2887. "libsystemproperties",
  2888. "libtombstoned_client_static",
  2889. "libunwindstack",
  2890. "libz",
  2891. "libziparchive",
  2892. }
  2893. //
  2894. // Module separator
  2895. //
  2896. m["com.android.tethering"] = []string{
  2897. "android.hardware.tetheroffload.config-V1.0-java",
  2898. "android.hardware.tetheroffload.control-V1.0-java",
  2899. "android.hidl.base-V1.0-java",
  2900. "libcgrouprc",
  2901. "libcgrouprc_format",
  2902. "libtetherutilsjni",
  2903. "libvndksupport",
  2904. "net-utils-framework-common",
  2905. "netd_aidl_interface-V3-java",
  2906. "netlink-client",
  2907. "networkstack-aidl-interfaces-java",
  2908. "tethering-aidl-interfaces-java",
  2909. "TetheringApiCurrentLib",
  2910. }
  2911. //
  2912. // Module separator
  2913. //
  2914. m["com.android.wifi"] = []string{
  2915. "PlatformProperties",
  2916. "android.hardware.wifi-V1.0-java",
  2917. "android.hardware.wifi-V1.0-java-constants",
  2918. "android.hardware.wifi-V1.1-java",
  2919. "android.hardware.wifi-V1.2-java",
  2920. "android.hardware.wifi-V1.3-java",
  2921. "android.hardware.wifi-V1.4-java",
  2922. "android.hardware.wifi.hostapd-V1.0-java",
  2923. "android.hardware.wifi.hostapd-V1.1-java",
  2924. "android.hardware.wifi.hostapd-V1.2-java",
  2925. "android.hardware.wifi.supplicant-V1.0-java",
  2926. "android.hardware.wifi.supplicant-V1.1-java",
  2927. "android.hardware.wifi.supplicant-V1.2-java",
  2928. "android.hardware.wifi.supplicant-V1.3-java",
  2929. "android.hidl.base-V1.0-java",
  2930. "android.hidl.manager-V1.0-java",
  2931. "android.hidl.manager-V1.1-java",
  2932. "android.hidl.manager-V1.2-java",
  2933. "bouncycastle-unbundled",
  2934. "dnsresolver_aidl_interface-V2-java",
  2935. "error_prone_annotations",
  2936. "framework-wifi-pre-jarjar",
  2937. "framework-wifi-util-lib",
  2938. "ipmemorystore-aidl-interfaces-V3-java",
  2939. "ipmemorystore-aidl-interfaces-java",
  2940. "ksoap2",
  2941. "libnanohttpd",
  2942. "libwifi-jni",
  2943. "net-utils-services-common",
  2944. "netd_aidl_interface-V2-java",
  2945. "netd_aidl_interface-unstable-java",
  2946. "netd_event_listener_interface-java",
  2947. "netlink-client",
  2948. "networkstack-client",
  2949. "services.net",
  2950. "wifi-lite-protos",
  2951. "wifi-nano-protos",
  2952. "wifi-service-pre-jarjar",
  2953. "wifi-service-resources",
  2954. }
  2955. //
  2956. // Module separator
  2957. //
  2958. m["com.android.os.statsd"] = []string{
  2959. "libstatssocket",
  2960. }
  2961. //
  2962. // Module separator
  2963. //
  2964. m[android.AvailableToAnyApex] = []string{
  2965. // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
  2966. "androidx",
  2967. "androidx-constraintlayout_constraintlayout",
  2968. "androidx-constraintlayout_constraintlayout-nodeps",
  2969. "androidx-constraintlayout_constraintlayout-solver",
  2970. "androidx-constraintlayout_constraintlayout-solver-nodeps",
  2971. "com.google.android.material_material",
  2972. "com.google.android.material_material-nodeps",
  2973. "libclang_rt",
  2974. "libprofile-clang-extras",
  2975. "libprofile-clang-extras_ndk",
  2976. "libprofile-extras",
  2977. "libprofile-extras_ndk",
  2978. "libunwind",
  2979. }
  2980. return m
  2981. }
  2982. func init() {
  2983. android.AddNeverAllowRules(createBcpPermittedPackagesRules(qBcpPackages())...)
  2984. android.AddNeverAllowRules(createBcpPermittedPackagesRules(rBcpPackages())...)
  2985. }
  2986. func createBcpPermittedPackagesRules(bcpPermittedPackages map[string][]string) []android.Rule {
  2987. rules := make([]android.Rule, 0, len(bcpPermittedPackages))
  2988. for jar, permittedPackages := range bcpPermittedPackages {
  2989. permittedPackagesRule := android.NeverAllow().
  2990. With("name", jar).
  2991. WithMatcher("permitted_packages", android.NotInList(permittedPackages)).
  2992. Because(jar +
  2993. " bootjar may only use these package prefixes: " + strings.Join(permittedPackages, ",") +
  2994. ". Please consider the following alternatives:\n" +
  2995. " 1. If the offending code is from a statically linked library, consider " +
  2996. "removing that dependency and using an alternative already in the " +
  2997. "bootclasspath, or perhaps a shared library." +
  2998. " 2. Move the offending code into an allowed package.\n" +
  2999. " 3. Jarjar the offending code. Please be mindful of the potential system " +
  3000. "health implications of bundling that code, particularly if the offending jar " +
  3001. "is part of the bootclasspath.")
  3002. rules = append(rules, permittedPackagesRule)
  3003. }
  3004. return rules
  3005. }
  3006. // DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
  3007. // Adding code to the bootclasspath in new packages will cause issues on module update.
  3008. func qBcpPackages() map[string][]string {
  3009. return map[string][]string{
  3010. "conscrypt": []string{
  3011. "android.net.ssl",
  3012. "com.android.org.conscrypt",
  3013. },
  3014. "updatable-media": []string{
  3015. "android.media",
  3016. },
  3017. }
  3018. }
  3019. // DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
  3020. // Adding code to the bootclasspath in new packages will cause issues on module update.
  3021. func rBcpPackages() map[string][]string {
  3022. return map[string][]string{
  3023. "framework-mediaprovider": []string{
  3024. "android.provider",
  3025. },
  3026. "framework-permission": []string{
  3027. "android.permission",
  3028. "android.app.role",
  3029. "com.android.permission",
  3030. "com.android.role",
  3031. },
  3032. "framework-sdkextensions": []string{
  3033. "android.os.ext",
  3034. },
  3035. "framework-statsd": []string{
  3036. "android.app",
  3037. "android.os",
  3038. "android.util",
  3039. "com.android.internal.statsd",
  3040. "com.android.server.stats",
  3041. },
  3042. "framework-wifi": []string{
  3043. "com.android.server.wifi",
  3044. "com.android.wifi.x",
  3045. "android.hardware.wifi",
  3046. "android.net.wifi",
  3047. },
  3048. "framework-tethering": []string{
  3049. "android.net",
  3050. },
  3051. }
  3052. }
  3053. // For Bazel / bp2build
  3054. type bazelApexBundleAttributes struct {
  3055. Manifest bazel.LabelAttribute
  3056. Android_manifest bazel.LabelAttribute
  3057. File_contexts bazel.LabelAttribute
  3058. Key bazel.LabelAttribute
  3059. Certificate bazel.LabelAttribute
  3060. Min_sdk_version *string
  3061. Updatable bazel.BoolAttribute
  3062. Installable bazel.BoolAttribute
  3063. Binaries bazel.LabelListAttribute
  3064. Prebuilts bazel.LabelListAttribute
  3065. Native_shared_libs_32 bazel.LabelListAttribute
  3066. Native_shared_libs_64 bazel.LabelListAttribute
  3067. Compressible bazel.BoolAttribute
  3068. }
  3069. type convertedNativeSharedLibs struct {
  3070. Native_shared_libs_32 bazel.LabelListAttribute
  3071. Native_shared_libs_64 bazel.LabelListAttribute
  3072. }
  3073. // ConvertWithBp2build performs bp2build conversion of an apex
  3074. func (a *apexBundle) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
  3075. // We do not convert apex_test modules at this time
  3076. if ctx.ModuleType() != "apex" {
  3077. return
  3078. }
  3079. var manifestLabelAttribute bazel.LabelAttribute
  3080. if a.properties.Manifest != nil {
  3081. manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.Manifest))
  3082. }
  3083. var androidManifestLabelAttribute bazel.LabelAttribute
  3084. if a.properties.AndroidManifest != nil {
  3085. androidManifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.AndroidManifest))
  3086. }
  3087. var fileContextsLabelAttribute bazel.LabelAttribute
  3088. if a.properties.File_contexts != nil {
  3089. fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.properties.File_contexts))
  3090. }
  3091. // TODO(b/219503907) this would need to be set to a.MinSdkVersionValue(ctx) but
  3092. // given it's coming via config, we probably don't want to put it in here.
  3093. var minSdkVersion *string
  3094. if a.properties.Min_sdk_version != nil {
  3095. minSdkVersion = a.properties.Min_sdk_version
  3096. }
  3097. var keyLabelAttribute bazel.LabelAttribute
  3098. if a.overridableProperties.Key != nil {
  3099. keyLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Key))
  3100. }
  3101. var certificateLabelAttribute bazel.LabelAttribute
  3102. if a.overridableProperties.Certificate != nil {
  3103. certificateLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Certificate))
  3104. }
  3105. nativeSharedLibs := &convertedNativeSharedLibs{
  3106. Native_shared_libs_32: bazel.LabelListAttribute{},
  3107. Native_shared_libs_64: bazel.LabelListAttribute{},
  3108. }
  3109. compileMultilib := "both"
  3110. if a.CompileMultilib() != nil {
  3111. compileMultilib = *a.CompileMultilib()
  3112. }
  3113. // properties.Native_shared_libs is treated as "both"
  3114. convertBothLibs(ctx, compileMultilib, a.properties.Native_shared_libs, nativeSharedLibs)
  3115. convertBothLibs(ctx, compileMultilib, a.properties.Multilib.Both.Native_shared_libs, nativeSharedLibs)
  3116. convert32Libs(ctx, compileMultilib, a.properties.Multilib.Lib32.Native_shared_libs, nativeSharedLibs)
  3117. convert64Libs(ctx, compileMultilib, a.properties.Multilib.Lib64.Native_shared_libs, nativeSharedLibs)
  3118. convertFirstLibs(ctx, compileMultilib, a.properties.Multilib.First.Native_shared_libs, nativeSharedLibs)
  3119. prebuilts := a.overridableProperties.Prebuilts
  3120. prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, prebuilts)
  3121. prebuiltsLabelListAttribute := bazel.MakeLabelListAttribute(prebuiltsLabelList)
  3122. binaries := android.BazelLabelForModuleDeps(ctx, a.properties.ApexNativeDependencies.Binaries)
  3123. binariesLabelListAttribute := bazel.MakeLabelListAttribute(binaries)
  3124. var updatableAttribute bazel.BoolAttribute
  3125. if a.properties.Updatable != nil {
  3126. updatableAttribute.Value = a.properties.Updatable
  3127. }
  3128. var installableAttribute bazel.BoolAttribute
  3129. if a.properties.Installable != nil {
  3130. installableAttribute.Value = a.properties.Installable
  3131. }
  3132. var compressibleAttribute bazel.BoolAttribute
  3133. if a.overridableProperties.Compressible != nil {
  3134. compressibleAttribute.Value = a.overridableProperties.Compressible
  3135. }
  3136. attrs := &bazelApexBundleAttributes{
  3137. Manifest: manifestLabelAttribute,
  3138. Android_manifest: androidManifestLabelAttribute,
  3139. File_contexts: fileContextsLabelAttribute,
  3140. Min_sdk_version: minSdkVersion,
  3141. Key: keyLabelAttribute,
  3142. Certificate: certificateLabelAttribute,
  3143. Updatable: updatableAttribute,
  3144. Installable: installableAttribute,
  3145. Native_shared_libs_32: nativeSharedLibs.Native_shared_libs_32,
  3146. Native_shared_libs_64: nativeSharedLibs.Native_shared_libs_64,
  3147. Binaries: binariesLabelListAttribute,
  3148. Prebuilts: prebuiltsLabelListAttribute,
  3149. Compressible: compressibleAttribute,
  3150. }
  3151. props := bazel.BazelTargetModuleProperties{
  3152. Rule_class: "apex",
  3153. Bzl_load_location: "//build/bazel/rules:apex.bzl",
  3154. }
  3155. ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: a.Name()}, attrs)
  3156. }
  3157. // The following conversions are based on this table where the rows are the compile_multilib
  3158. // values and the columns are the properties.Multilib.*.Native_shared_libs. Each cell
  3159. // represents how the libs should be compiled for a 64-bit/32-bit device: 32 means it
  3160. // should be compiled as 32-bit, 64 means it should be compiled as 64-bit, none means it
  3161. // should not be compiled.
  3162. // multib/compile_multilib, 32, 64, both, first
  3163. // 32, 32/32, none/none, 32/32, none/32
  3164. // 64, none/none, 64/none, 64/none, 64/none
  3165. // both, 32/32, 64/none, 32&64/32, 64/32
  3166. // first, 32/32, 64/none, 64/32, 64/32
  3167. func convert32Libs(ctx android.TopDownMutatorContext, compileMultilb string,
  3168. libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
  3169. libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
  3170. switch compileMultilb {
  3171. case "both", "32":
  3172. makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
  3173. case "first":
  3174. make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
  3175. case "64":
  3176. // Incompatible, ignore
  3177. default:
  3178. invalidCompileMultilib(ctx, compileMultilb)
  3179. }
  3180. }
  3181. func convert64Libs(ctx android.TopDownMutatorContext, compileMultilb string,
  3182. libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
  3183. libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
  3184. switch compileMultilb {
  3185. case "both", "64", "first":
  3186. make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
  3187. case "32":
  3188. // Incompatible, ignore
  3189. default:
  3190. invalidCompileMultilib(ctx, compileMultilb)
  3191. }
  3192. }
  3193. func convertBothLibs(ctx android.TopDownMutatorContext, compileMultilb string,
  3194. libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
  3195. libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
  3196. switch compileMultilb {
  3197. case "both":
  3198. makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
  3199. make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
  3200. case "first":
  3201. makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
  3202. case "32":
  3203. makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
  3204. case "64":
  3205. make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
  3206. default:
  3207. invalidCompileMultilib(ctx, compileMultilb)
  3208. }
  3209. }
  3210. func convertFirstLibs(ctx android.TopDownMutatorContext, compileMultilb string,
  3211. libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
  3212. libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
  3213. switch compileMultilb {
  3214. case "both", "first":
  3215. makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
  3216. case "32":
  3217. make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
  3218. case "64":
  3219. make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
  3220. default:
  3221. invalidCompileMultilib(ctx, compileMultilb)
  3222. }
  3223. }
  3224. func makeFirstSharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
  3225. make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
  3226. make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
  3227. }
  3228. func makeNoConfig32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
  3229. list := bazel.LabelListAttribute{}
  3230. list.SetSelectValue(bazel.NoConfigAxis, "", libsLabelList)
  3231. nativeSharedLibs.Native_shared_libs_32.Append(list)
  3232. }
  3233. func make32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
  3234. makeSharedLibsAttributes("x86", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
  3235. makeSharedLibsAttributes("arm", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
  3236. }
  3237. func make64SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
  3238. makeSharedLibsAttributes("x86_64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
  3239. makeSharedLibsAttributes("arm64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
  3240. }
  3241. func makeSharedLibsAttributes(config string, libsLabelList bazel.LabelList,
  3242. labelListAttr *bazel.LabelListAttribute) {
  3243. list := bazel.LabelListAttribute{}
  3244. list.SetSelectValue(bazel.ArchConfigurationAxis, config, libsLabelList)
  3245. labelListAttr.Append(list)
  3246. }
  3247. func invalidCompileMultilib(ctx android.TopDownMutatorContext, value string) {
  3248. ctx.PropertyErrorf("compile_multilib", "Invalid value: %s", value)
  3249. }