apex.go 119 KB

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