cc.go 122 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835
  1. // Copyright 2015 Google Inc. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package cc
  15. // This file contains the module types for compiling C/C++ for Android, and converts the properties
  16. // into the flags and filenames necessary to pass to the compiler. The final creation of the rules
  17. // is handled in builder.go
  18. import (
  19. "fmt"
  20. "io"
  21. "strconv"
  22. "strings"
  23. "github.com/google/blueprint"
  24. "github.com/google/blueprint/proptools"
  25. "android/soong/android"
  26. "android/soong/cc/config"
  27. "android/soong/fuzz"
  28. "android/soong/genrule"
  29. "android/soong/multitree"
  30. "android/soong/snapshot"
  31. )
  32. func init() {
  33. RegisterCCBuildComponents(android.InitRegistrationContext)
  34. pctx.Import("android/soong/cc/config")
  35. }
  36. func RegisterCCBuildComponents(ctx android.RegistrationContext) {
  37. ctx.RegisterModuleType("cc_defaults", defaultsFactory)
  38. ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
  39. ctx.BottomUp("sdk", sdkMutator).Parallel()
  40. ctx.BottomUp("vndk", VndkMutator).Parallel()
  41. ctx.BottomUp("link", LinkageMutator).Parallel()
  42. ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
  43. ctx.BottomUp("version", versionMutator).Parallel()
  44. ctx.BottomUp("begin", BeginMutator).Parallel()
  45. })
  46. ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
  47. for _, san := range Sanitizers {
  48. san.registerMutators(ctx)
  49. }
  50. ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
  51. ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
  52. ctx.TopDown("fuzz_deps", fuzzMutatorDeps)
  53. ctx.BottomUp("coverage", coverageMutator).Parallel()
  54. ctx.TopDown("afdo_deps", afdoDepsMutator)
  55. ctx.BottomUp("afdo", afdoMutator).Parallel()
  56. ctx.TopDown("lto_deps", ltoDepsMutator)
  57. ctx.BottomUp("lto", ltoMutator).Parallel()
  58. ctx.BottomUp("check_linktype", checkLinkTypeMutator).Parallel()
  59. ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
  60. })
  61. ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) {
  62. // sabi mutator needs to be run after apex mutator finishes.
  63. ctx.TopDown("sabi_deps", sabiDepsMutator)
  64. })
  65. ctx.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
  66. }
  67. // Deps is a struct containing module names of dependencies, separated by the kind of dependency.
  68. // Mutators should use `AddVariationDependencies` or its sibling methods to add actual dependency
  69. // edges to these modules.
  70. // This object is constructed in DepsMutator, by calling to various module delegates to set
  71. // relevant fields. For example, `module.compiler.compilerDeps()` may append type-specific
  72. // dependencies.
  73. // This is then consumed by the same DepsMutator, which will call `ctx.AddVariationDependencies()`
  74. // (or its sibling methods) to set real dependencies on the given modules.
  75. type Deps struct {
  76. SharedLibs, LateSharedLibs []string
  77. StaticLibs, LateStaticLibs, WholeStaticLibs []string
  78. HeaderLibs []string
  79. RuntimeLibs []string
  80. // UnexportedStaticLibs are static libraries that are also passed to -Wl,--exclude-libs= to
  81. // prevent automatically exporting symbols.
  82. UnexportedStaticLibs []string
  83. // Used for data dependencies adjacent to tests
  84. DataLibs []string
  85. DataBins []string
  86. // Used by DepsMutator to pass system_shared_libs information to check_elf_file.py.
  87. SystemSharedLibs []string
  88. // If true, statically link the unwinder into native libraries/binaries.
  89. StaticUnwinderIfLegacy bool
  90. ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
  91. ObjFiles []string
  92. GeneratedSources []string
  93. GeneratedHeaders []string
  94. GeneratedDeps []string
  95. ReexportGeneratedHeaders []string
  96. CrtBegin, CrtEnd []string
  97. // Used for host bionic
  98. DynamicLinker string
  99. // List of libs that need to be excluded for APEX variant
  100. ExcludeLibsForApex []string
  101. }
  102. // PathDeps is a struct containing file paths to dependencies of a module.
  103. // It's constructed in depsToPath() by traversing the direct dependencies of the current module.
  104. // It's used to construct flags for various build statements (such as for compiling and linking).
  105. // It is then passed to module decorator functions responsible for registering build statements
  106. // (such as `module.compiler.compile()`).`
  107. type PathDeps struct {
  108. // Paths to .so files
  109. SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
  110. // Paths to the dependencies to use for .so files (.so.toc files)
  111. SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
  112. // Paths to .a files
  113. StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
  114. // Transitive static library dependencies of static libraries for use in ordering.
  115. TranstiveStaticLibrariesForOrdering *android.DepSet
  116. // Paths to .o files
  117. Objs Objects
  118. // Paths to .o files in dependencies that provide them. Note that these lists
  119. // aren't complete since prebuilt modules don't provide the .o files.
  120. StaticLibObjs Objects
  121. WholeStaticLibObjs Objects
  122. // Paths to .a files in prebuilts. Complements WholeStaticLibObjs to contain
  123. // the libs from all whole_static_lib dependencies.
  124. WholeStaticLibsFromPrebuilts android.Paths
  125. // Paths to generated source files
  126. GeneratedSources android.Paths
  127. GeneratedDeps android.Paths
  128. Flags []string
  129. LdFlags []string
  130. IncludeDirs android.Paths
  131. SystemIncludeDirs android.Paths
  132. ReexportedDirs android.Paths
  133. ReexportedSystemDirs android.Paths
  134. ReexportedFlags []string
  135. ReexportedGeneratedHeaders android.Paths
  136. ReexportedDeps android.Paths
  137. // Paths to crt*.o files
  138. CrtBegin, CrtEnd android.Paths
  139. // Path to the dynamic linker binary
  140. DynamicLinker android.OptionalPath
  141. // For Darwin builds, the path to the second architecture's output that should
  142. // be combined with this architectures's output into a FAT MachO file.
  143. DarwinSecondArchOutput android.OptionalPath
  144. }
  145. // LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
  146. // tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
  147. // command line so they can be overridden by the local module flags).
  148. type LocalOrGlobalFlags struct {
  149. CommonFlags []string // Flags that apply to C, C++, and assembly source files
  150. AsFlags []string // Flags that apply to assembly source files
  151. YasmFlags []string // Flags that apply to yasm assembly source files
  152. CFlags []string // Flags that apply to C and C++ source files
  153. ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
  154. ConlyFlags []string // Flags that apply to C source files
  155. CppFlags []string // Flags that apply to C++ source files
  156. ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
  157. LdFlags []string // Flags that apply to linker command lines
  158. }
  159. // Flags contains various types of command line flags (and settings) for use in building build
  160. // statements related to C++.
  161. type Flags struct {
  162. // Local flags (which individual modules are responsible for). These may override global flags.
  163. Local LocalOrGlobalFlags
  164. // Global flags (which build system or toolchain is responsible for).
  165. Global LocalOrGlobalFlags
  166. aidlFlags []string // Flags that apply to aidl source files
  167. rsFlags []string // Flags that apply to renderscript source files
  168. libFlags []string // Flags to add libraries early to the link order
  169. extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
  170. TidyFlags []string // Flags that apply to clang-tidy
  171. SAbiFlags []string // Flags that apply to header-abi-dumper
  172. // Global include flags that apply to C, C++, and assembly source files
  173. // These must be after any module include flags, which will be in CommonFlags.
  174. SystemIncludeFlags []string
  175. Toolchain config.Toolchain
  176. Tidy bool // True if ninja .tidy rules should be generated.
  177. NeedTidyFiles bool // True if module link should depend on .tidy files
  178. GcovCoverage bool // True if coverage files should be generated.
  179. SAbiDump bool // True if header abi dumps should be generated.
  180. EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
  181. // The instruction set required for clang ("arm" or "thumb").
  182. RequiredInstructionSet string
  183. // The target-device system path to the dynamic linker.
  184. DynamicLinker string
  185. CFlagsDeps android.Paths // Files depended on by compiler flags
  186. LdFlagsDeps android.Paths // Files depended on by linker flags
  187. // True if .s files should be processed with the c preprocessor.
  188. AssemblerWithCpp bool
  189. proto android.ProtoFlags
  190. protoC bool // Whether to use C instead of C++
  191. protoOptionsFile bool // Whether to look for a .options file next to the .proto
  192. Yacc *YaccProperties
  193. Lex *LexProperties
  194. }
  195. // Properties used to compile all C or C++ modules
  196. type BaseProperties struct {
  197. // Deprecated. true is the default, false is invalid.
  198. Clang *bool `android:"arch_variant"`
  199. // The API level that this module is built against. The APIs of this API level will be
  200. // visible at build time, but use of any APIs newer than min_sdk_version will render the
  201. // module unloadable on older devices. In the future it will be possible to weakly-link new
  202. // APIs, making the behavior match Java: such modules will load on older devices, but
  203. // calling new APIs on devices that do not support them will result in a crash.
  204. //
  205. // This property has the same behavior as sdk_version does for Java modules. For those
  206. // familiar with Android Gradle, the property behaves similarly to how compileSdkVersion
  207. // does for Java code.
  208. //
  209. // In addition, setting this property causes two variants to be built, one for the platform
  210. // and one for apps.
  211. Sdk_version *string
  212. // Minimum OS API level supported by this C or C++ module. This property becomes the value
  213. // of the __ANDROID_API__ macro. When the C or C++ module is included in an APEX or an APK,
  214. // this property is also used to ensure that the min_sdk_version of the containing module is
  215. // not older (i.e. less) than this module's min_sdk_version. When not set, this property
  216. // defaults to the value of sdk_version. When this is set to "apex_inherit", this tracks
  217. // min_sdk_version of the containing APEX. When the module
  218. // is not built for an APEX, "apex_inherit" defaults to sdk_version.
  219. Min_sdk_version *string
  220. // If true, always create an sdk variant and don't create a platform variant.
  221. Sdk_variant_only *bool
  222. AndroidMkSharedLibs []string `blueprint:"mutated"`
  223. AndroidMkStaticLibs []string `blueprint:"mutated"`
  224. AndroidMkRuntimeLibs []string `blueprint:"mutated"`
  225. AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
  226. AndroidMkHeaderLibs []string `blueprint:"mutated"`
  227. HideFromMake bool `blueprint:"mutated"`
  228. PreventInstall bool `blueprint:"mutated"`
  229. ApexesProvidingSharedLibs []string `blueprint:"mutated"`
  230. // Set by DepsMutator.
  231. AndroidMkSystemSharedLibs []string `blueprint:"mutated"`
  232. // The name of the image this module is built for, suffixed with a '.'
  233. ImageVariationPrefix string `blueprint:"mutated"`
  234. // The VNDK version this module is built against. If empty, the module is not
  235. // build against the VNDK.
  236. VndkVersion string `blueprint:"mutated"`
  237. // Suffix for the name of Android.mk entries generated by this module
  238. SubName string `blueprint:"mutated"`
  239. // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
  240. // file
  241. Logtags []string
  242. // Make this module available when building for ramdisk.
  243. // On device without a dedicated recovery partition, the module is only
  244. // available after switching root into
  245. // /first_stage_ramdisk. To expose the module before switching root, install
  246. // the recovery variant instead.
  247. Ramdisk_available *bool
  248. // Make this module available when building for vendor ramdisk.
  249. // On device without a dedicated recovery partition, the module is only
  250. // available after switching root into
  251. // /first_stage_ramdisk. To expose the module before switching root, install
  252. // the recovery variant instead.
  253. Vendor_ramdisk_available *bool
  254. // Make this module available when building for recovery
  255. Recovery_available *bool
  256. // Used by imageMutator, set by ImageMutatorBegin()
  257. CoreVariantNeeded bool `blueprint:"mutated"`
  258. RamdiskVariantNeeded bool `blueprint:"mutated"`
  259. VendorRamdiskVariantNeeded bool `blueprint:"mutated"`
  260. RecoveryVariantNeeded bool `blueprint:"mutated"`
  261. // A list of variations for the "image" mutator of the form
  262. //<image name> '.' <version char>, for example, 'vendor.S'
  263. ExtraVersionedImageVariations []string `blueprint:"mutated"`
  264. // Allows this module to use non-APEX version of libraries. Useful
  265. // for building binaries that are started before APEXes are activated.
  266. Bootstrap *bool
  267. // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
  268. // see soong/cc/config/vndk.go
  269. MustUseVendorVariant bool `blueprint:"mutated"`
  270. // Used by vendor snapshot to record dependencies from snapshot modules.
  271. SnapshotSharedLibs []string `blueprint:"mutated"`
  272. SnapshotStaticLibs []string `blueprint:"mutated"`
  273. SnapshotRuntimeLibs []string `blueprint:"mutated"`
  274. Installable *bool `android:"arch_variant"`
  275. // Set by factories of module types that can only be referenced from variants compiled against
  276. // the SDK.
  277. AlwaysSdk bool `blueprint:"mutated"`
  278. // Variant is an SDK variant created by sdkMutator
  279. IsSdkVariant bool `blueprint:"mutated"`
  280. // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK
  281. // variant to have a ".sdk" suffix.
  282. SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"`
  283. // Normally Soong uses the directory structure to decide which modules
  284. // should be included (framework) or excluded (non-framework) from the
  285. // different snapshots (vendor, recovery, etc.), but this property
  286. // allows a partner to exclude a module normally thought of as a
  287. // framework module from the vendor snapshot.
  288. Exclude_from_vendor_snapshot *bool
  289. // Normally Soong uses the directory structure to decide which modules
  290. // should be included (framework) or excluded (non-framework) from the
  291. // different snapshots (vendor, recovery, etc.), but this property
  292. // allows a partner to exclude a module normally thought of as a
  293. // framework module from the recovery snapshot.
  294. Exclude_from_recovery_snapshot *bool
  295. // List of APEXes that this module has private access to for testing purpose. The module
  296. // can depend on libraries that are not exported by the APEXes and use private symbols
  297. // from the exported libraries.
  298. Test_for []string `android:"arch_variant"`
  299. Target struct {
  300. Platform struct {
  301. // List of modules required by the core variant.
  302. Required []string `android:"arch_variant"`
  303. // List of modules not required by the core variant.
  304. Exclude_required []string `android:"arch_variant"`
  305. } `android:"arch_variant"`
  306. Recovery struct {
  307. // List of modules required by the recovery variant.
  308. Required []string `android:"arch_variant"`
  309. // List of modules not required by the recovery variant.
  310. Exclude_required []string `android:"arch_variant"`
  311. } `android:"arch_variant"`
  312. } `android:"arch_variant"`
  313. }
  314. type VendorProperties struct {
  315. // whether this module should be allowed to be directly depended by other
  316. // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
  317. // If set to true, two variants will be built separately, one like
  318. // normal, and the other limited to the set of libraries and headers
  319. // that are exposed to /vendor modules.
  320. //
  321. // The vendor variant may be used with a different (newer) /system,
  322. // so it shouldn't have any unversioned runtime dependencies, or
  323. // make assumptions about the system that may not be true in the
  324. // future.
  325. //
  326. // If set to false, this module becomes inaccessible from /vendor modules.
  327. //
  328. // The modules with vndk: {enabled: true} must define 'vendor_available'
  329. // to 'true'.
  330. //
  331. // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
  332. Vendor_available *bool
  333. // This is the same as the "vendor_available" except that the install path
  334. // of the vendor variant is /odm or /vendor/odm.
  335. // By replacing "vendor_available: true" with "odm_available: true", the
  336. // module will install its vendor variant to the /odm partition or /vendor/odm.
  337. // As the modules with "odm_available: true" still create the vendor variants,
  338. // they can link to the other vendor modules as the vendor_available modules do.
  339. // Also, the vendor modules can link to odm_available modules.
  340. //
  341. // It may not be used for VNDK modules.
  342. Odm_available *bool
  343. // whether this module should be allowed to be directly depended by other
  344. // modules with `product_specific: true` or `product_available: true`.
  345. // If set to true, an additional product variant will be built separately
  346. // that is limited to the set of libraries and headers that are exposed to
  347. // /product modules.
  348. //
  349. // The product variant may be used with a different (newer) /system,
  350. // so it shouldn't have any unversioned runtime dependencies, or
  351. // make assumptions about the system that may not be true in the
  352. // future.
  353. //
  354. // If set to false, this module becomes inaccessible from /product modules.
  355. //
  356. // Different from the 'vendor_available' property, the modules with
  357. // vndk: {enabled: true} don't have to define 'product_available'. The VNDK
  358. // library without 'product_available' may not be depended on by any other
  359. // modules that has product variants including the product available VNDKs.
  360. //
  361. // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
  362. // and PRODUCT_PRODUCT_VNDK_VERSION isn't set.
  363. Product_available *bool
  364. // whether this module is capable of being loaded with other instance
  365. // (possibly an older version) of the same module in the same process.
  366. // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
  367. // can be double loaded in a vendor process if the library is also a
  368. // (direct and indirect) dependency of an LLNDK library. Such libraries must be
  369. // explicitly marked as `double_loadable: true` by the owner, or the dependency
  370. // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
  371. Double_loadable *bool
  372. // IsLLNDK is set to true for the vendor variant of a cc_library module that has LLNDK stubs.
  373. IsLLNDK bool `blueprint:"mutated"`
  374. // IsVNDKUsingCoreVariant is true for VNDK modules if the global VndkUseCoreVariant option is
  375. // set and the module is not listed in VndkMustUseVendorVariantList.
  376. IsVNDKUsingCoreVariant bool `blueprint:"mutated"`
  377. // IsVNDKCore is set if a VNDK module does not set the vndk.support_system_process property.
  378. IsVNDKCore bool `blueprint:"mutated"`
  379. // IsVNDKSP is set if a VNDK module sets the vndk.support_system_process property.
  380. IsVNDKSP bool `blueprint:"mutated"`
  381. // IsVNDKPrivate is set if a VNDK module sets the vndk.private property or an LLNDK
  382. // module sets the llndk.private property.
  383. IsVNDKPrivate bool `blueprint:"mutated"`
  384. // IsVNDKProduct is set if a VNDK module sets the product_available property.
  385. IsVNDKProduct bool `blueprint:"mutated"`
  386. // IsVendorPublicLibrary is set for the core and product variants of a library that has
  387. // vendor_public_library stubs.
  388. IsVendorPublicLibrary bool `blueprint:"mutated"`
  389. }
  390. // ModuleContextIntf is an interface (on a module context helper) consisting of functions related
  391. // to understanding details about the type of the current module.
  392. // For example, one might call these functions to determine whether the current module is a static
  393. // library and/or is installed in vendor directories.
  394. type ModuleContextIntf interface {
  395. static() bool
  396. staticBinary() bool
  397. testBinary() bool
  398. testLibrary() bool
  399. header() bool
  400. binary() bool
  401. object() bool
  402. toolchain() config.Toolchain
  403. canUseSdk() bool
  404. useSdk() bool
  405. sdkVersion() string
  406. minSdkVersion() string
  407. isSdkVariant() bool
  408. useVndk() bool
  409. isNdk(config android.Config) bool
  410. IsLlndk() bool
  411. IsLlndkPublic() bool
  412. isImplementationForLLNDKPublic() bool
  413. IsVndkPrivate() bool
  414. isVndk() bool
  415. isVndkSp() bool
  416. IsVndkExt() bool
  417. IsVendorPublicLibrary() bool
  418. inProduct() bool
  419. inVendor() bool
  420. inRamdisk() bool
  421. inVendorRamdisk() bool
  422. inRecovery() bool
  423. selectedStl() string
  424. baseModuleName() string
  425. getVndkExtendsModuleName() string
  426. isAfdoCompile() bool
  427. isPgoCompile() bool
  428. isCfi() bool
  429. isNDKStubLibrary() bool
  430. useClangLld(actx ModuleContext) bool
  431. isForPlatform() bool
  432. apexVariationName() string
  433. apexSdkVersion() android.ApiLevel
  434. bootstrap() bool
  435. mustUseVendorVariant() bool
  436. nativeCoverage() bool
  437. directlyInAnyApex() bool
  438. isPreventInstall() bool
  439. isCfiAssemblySupportEnabled() bool
  440. getSharedFlags() *SharedFlags
  441. }
  442. type SharedFlags struct {
  443. numSharedFlags int
  444. flagsMap map[string]string
  445. }
  446. type ModuleContext interface {
  447. android.ModuleContext
  448. ModuleContextIntf
  449. }
  450. type BaseModuleContext interface {
  451. android.BaseModuleContext
  452. ModuleContextIntf
  453. }
  454. type DepsContext interface {
  455. android.BottomUpMutatorContext
  456. ModuleContextIntf
  457. }
  458. // feature represents additional (optional) steps to building cc-related modules, such as invocation
  459. // of clang-tidy.
  460. type feature interface {
  461. flags(ctx ModuleContext, flags Flags) Flags
  462. props() []interface{}
  463. }
  464. // compiler is the interface for a compiler helper object. Different module decorators may implement
  465. // this helper differently.
  466. type compiler interface {
  467. compilerInit(ctx BaseModuleContext)
  468. compilerDeps(ctx DepsContext, deps Deps) Deps
  469. compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
  470. compilerProps() []interface{}
  471. appendCflags([]string)
  472. appendAsflags([]string)
  473. compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
  474. }
  475. // linker is the interface for a linker decorator object. Individual module types can provide
  476. // their own implementation for this decorator, and thus specify custom logic regarding build
  477. // statements pertaining to linking.
  478. type linker interface {
  479. linkerInit(ctx BaseModuleContext)
  480. linkerDeps(ctx DepsContext, deps Deps) Deps
  481. linkerFlags(ctx ModuleContext, flags Flags) Flags
  482. linkerProps() []interface{}
  483. useClangLld(actx ModuleContext) bool
  484. link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
  485. appendLdflags([]string)
  486. unstrippedOutputFilePath() android.Path
  487. nativeCoverage() bool
  488. coverageOutputFilePath() android.OptionalPath
  489. // Get the deps that have been explicitly specified in the properties.
  490. linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
  491. }
  492. // specifiedDeps is a tuple struct representing dependencies of a linked binary owned by the linker.
  493. type specifiedDeps struct {
  494. sharedLibs []string
  495. // Note nil and [] are semantically distinct. [] prevents linking against the defaults (usually
  496. // libc, libm, etc.)
  497. systemSharedLibs []string
  498. }
  499. // installer is the interface for an installer helper object. This helper is responsible for
  500. // copying build outputs to the appropriate locations so that they may be installed on device.
  501. type installer interface {
  502. installerProps() []interface{}
  503. install(ctx ModuleContext, path android.Path)
  504. everInstallable() bool
  505. inData() bool
  506. inSanitizerDir() bool
  507. hostToolPath() android.OptionalPath
  508. relativeInstallPath() string
  509. makeUninstallable(mod *Module)
  510. installInRoot() bool
  511. }
  512. type xref interface {
  513. XrefCcFiles() android.Paths
  514. }
  515. type libraryDependencyKind int
  516. const (
  517. headerLibraryDependency = iota
  518. sharedLibraryDependency
  519. staticLibraryDependency
  520. )
  521. func (k libraryDependencyKind) String() string {
  522. switch k {
  523. case headerLibraryDependency:
  524. return "headerLibraryDependency"
  525. case sharedLibraryDependency:
  526. return "sharedLibraryDependency"
  527. case staticLibraryDependency:
  528. return "staticLibraryDependency"
  529. default:
  530. panic(fmt.Errorf("unknown libraryDependencyKind %d", k))
  531. }
  532. }
  533. type libraryDependencyOrder int
  534. const (
  535. earlyLibraryDependency = -1
  536. normalLibraryDependency = 0
  537. lateLibraryDependency = 1
  538. )
  539. func (o libraryDependencyOrder) String() string {
  540. switch o {
  541. case earlyLibraryDependency:
  542. return "earlyLibraryDependency"
  543. case normalLibraryDependency:
  544. return "normalLibraryDependency"
  545. case lateLibraryDependency:
  546. return "lateLibraryDependency"
  547. default:
  548. panic(fmt.Errorf("unknown libraryDependencyOrder %d", o))
  549. }
  550. }
  551. // libraryDependencyTag is used to tag dependencies on libraries. Unlike many dependency
  552. // tags that have a set of predefined tag objects that are reused for each dependency, a
  553. // libraryDependencyTag is designed to contain extra metadata and is constructed as needed.
  554. // That means that comparing a libraryDependencyTag for equality will only be equal if all
  555. // of the metadata is equal. Most usages will want to type assert to libraryDependencyTag and
  556. // then check individual metadata fields instead.
  557. type libraryDependencyTag struct {
  558. blueprint.BaseDependencyTag
  559. // These are exported so that fmt.Printf("%#v") can call their String methods.
  560. Kind libraryDependencyKind
  561. Order libraryDependencyOrder
  562. wholeStatic bool
  563. reexportFlags bool
  564. explicitlyVersioned bool
  565. dataLib bool
  566. ndk bool
  567. staticUnwinder bool
  568. makeSuffix string
  569. // Whether or not this dependency should skip the apex dependency check
  570. skipApexAllowedDependenciesCheck bool
  571. // Whether or not this dependency has to be followed for the apex variants
  572. excludeInApex bool
  573. // If true, don't automatically export symbols from the static library into a shared library.
  574. unexportedSymbols bool
  575. }
  576. // header returns true if the libraryDependencyTag is tagging a header lib dependency.
  577. func (d libraryDependencyTag) header() bool {
  578. return d.Kind == headerLibraryDependency
  579. }
  580. // shared returns true if the libraryDependencyTag is tagging a shared lib dependency.
  581. func (d libraryDependencyTag) shared() bool {
  582. return d.Kind == sharedLibraryDependency
  583. }
  584. // shared returns true if the libraryDependencyTag is tagging a static lib dependency.
  585. func (d libraryDependencyTag) static() bool {
  586. return d.Kind == staticLibraryDependency
  587. }
  588. func (d libraryDependencyTag) LicenseAnnotations() []android.LicenseAnnotation {
  589. if d.shared() {
  590. return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency}
  591. }
  592. return nil
  593. }
  594. var _ android.LicenseAnnotationsDependencyTag = libraryDependencyTag{}
  595. // InstallDepNeeded returns true for shared libraries so that shared library dependencies of
  596. // binaries or other shared libraries are installed as dependencies.
  597. func (d libraryDependencyTag) InstallDepNeeded() bool {
  598. return d.shared()
  599. }
  600. var _ android.InstallNeededDependencyTag = libraryDependencyTag{}
  601. // dependencyTag is used for tagging miscellaneous dependency types that don't fit into
  602. // libraryDependencyTag. Each tag object is created globally and reused for multiple
  603. // dependencies (although since the object contains no references, assigning a tag to a
  604. // variable and modifying it will not modify the original). Users can compare the tag
  605. // returned by ctx.OtherModuleDependencyTag against the global original
  606. type dependencyTag struct {
  607. blueprint.BaseDependencyTag
  608. name string
  609. }
  610. // installDependencyTag is used for tagging miscellaneous dependency types that don't fit into
  611. // libraryDependencyTag, but where the dependency needs to be installed when the parent is
  612. // installed.
  613. type installDependencyTag struct {
  614. blueprint.BaseDependencyTag
  615. android.InstallAlwaysNeededDependencyTag
  616. name string
  617. }
  618. var (
  619. genSourceDepTag = dependencyTag{name: "gen source"}
  620. genHeaderDepTag = dependencyTag{name: "gen header"}
  621. genHeaderExportDepTag = dependencyTag{name: "gen header export"}
  622. objDepTag = dependencyTag{name: "obj"}
  623. dynamicLinkerDepTag = installDependencyTag{name: "dynamic linker"}
  624. reuseObjTag = dependencyTag{name: "reuse objects"}
  625. staticVariantTag = dependencyTag{name: "static variant"}
  626. vndkExtDepTag = dependencyTag{name: "vndk extends"}
  627. dataLibDepTag = dependencyTag{name: "data lib"}
  628. dataBinDepTag = dependencyTag{name: "data bin"}
  629. runtimeDepTag = installDependencyTag{name: "runtime lib"}
  630. testPerSrcDepTag = dependencyTag{name: "test_per_src"}
  631. stubImplDepTag = dependencyTag{name: "stub_impl"}
  632. JniFuzzLibTag = dependencyTag{name: "jni_fuzz_lib_tag"}
  633. )
  634. func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
  635. ccLibDepTag, ok := depTag.(libraryDependencyTag)
  636. return ok && ccLibDepTag.shared()
  637. }
  638. func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
  639. ccLibDepTag, ok := depTag.(libraryDependencyTag)
  640. return ok && ccLibDepTag.static()
  641. }
  642. func IsHeaderDepTag(depTag blueprint.DependencyTag) bool {
  643. ccLibDepTag, ok := depTag.(libraryDependencyTag)
  644. return ok && ccLibDepTag.header()
  645. }
  646. func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
  647. return depTag == runtimeDepTag
  648. }
  649. func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
  650. ccDepTag, ok := depTag.(dependencyTag)
  651. return ok && ccDepTag == testPerSrcDepTag
  652. }
  653. // bazelHandler is the interface for a helper object related to deferring to Bazel for
  654. // processing a cc module (during Bazel mixed builds). Individual module types should define
  655. // their own bazel handler if they support being handled by Bazel.
  656. type BazelHandler interface {
  657. // QueueBazelCall invokes request-queueing functions on the BazelContext
  658. //so that these requests are handled when Bazel's cquery is invoked.
  659. QueueBazelCall(ctx android.BaseModuleContext, label string)
  660. // ProcessBazelQueryResponse uses information retrieved from Bazel to set properties
  661. // on the current module with given label.
  662. ProcessBazelQueryResponse(ctx android.ModuleContext, label string)
  663. }
  664. // Module contains the properties and members used by all C/C++ module types, and implements
  665. // the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
  666. // to construct the output file. Behavior can be customized with a Customizer, or "decorator",
  667. // interface.
  668. //
  669. // To define a C/C++ related module, construct a new Module object and point its delegates to
  670. // type-specific structs. These delegates will be invoked to register module-specific build
  671. // statements which may be unique to the module type. For example, module.compiler.compile() should
  672. // be defined so as to register build statements which are responsible for compiling the module.
  673. //
  674. // Another example: to construct a cc_binary module, one can create a `cc.binaryDecorator` struct
  675. // which implements the `linker` and `installer` interfaces, and points the `linker` and `installer`
  676. // members of the cc.Module to this decorator. Thus, a cc_binary module has custom linker and
  677. // installer logic.
  678. type Module struct {
  679. fuzz.FuzzModule
  680. android.SdkBase
  681. android.BazelModuleBase
  682. VendorProperties VendorProperties
  683. Properties BaseProperties
  684. // initialize before calling Init
  685. hod android.HostOrDeviceSupported
  686. multilib android.Multilib
  687. bazelable bool
  688. // Allowable SdkMemberTypes of this module type.
  689. sdkMemberTypes []android.SdkMemberType
  690. // decorator delegates, initialize before calling Init
  691. // these may contain module-specific implementations, and effectively allow for custom
  692. // type-specific logic. These members may reference different objects or the same object.
  693. // Functions of these decorators will be invoked to initialize and register type-specific
  694. // build statements.
  695. compiler compiler
  696. linker linker
  697. installer installer
  698. bazelHandler BazelHandler
  699. features []feature
  700. stl *stl
  701. sanitize *sanitize
  702. coverage *coverage
  703. fuzzer *fuzzer
  704. sabi *sabi
  705. vndkdep *vndkdep
  706. lto *lto
  707. afdo *afdo
  708. pgo *pgo
  709. library libraryInterface
  710. outputFile android.OptionalPath
  711. cachedToolchain config.Toolchain
  712. subAndroidMkOnce map[subAndroidMkProvider]bool
  713. // Flags used to compile this module
  714. flags Flags
  715. // Shared flags among build rules of this module
  716. sharedFlags SharedFlags
  717. // only non-nil when this is a shared library that reuses the objects of a static library
  718. staticAnalogue *StaticLibraryInfo
  719. makeLinkType string
  720. // Kythe (source file indexer) paths for this compilation module
  721. kytheFiles android.Paths
  722. // Object .o file output paths for this compilation module
  723. objFiles android.Paths
  724. // Tidy .tidy file output paths for this compilation module
  725. tidyFiles android.Paths
  726. // For apex variants, this is set as apex.min_sdk_version
  727. apexSdkVersion android.ApiLevel
  728. hideApexVariantFromMake bool
  729. }
  730. func (c *Module) AddJSONData(d *map[string]interface{}) {
  731. var hasAidl, hasLex, hasProto, hasRenderscript, hasSysprop, hasWinMsg, hasYacc bool
  732. if b, ok := c.compiler.(*baseCompiler); ok {
  733. hasAidl = b.hasSrcExt(".aidl")
  734. hasLex = b.hasSrcExt(".l") || b.hasSrcExt(".ll")
  735. hasProto = b.hasSrcExt(".proto")
  736. hasRenderscript = b.hasSrcExt(".rscript") || b.hasSrcExt(".fs")
  737. hasSysprop = b.hasSrcExt(".sysprop")
  738. hasWinMsg = b.hasSrcExt(".mc")
  739. hasYacc = b.hasSrcExt(".y") || b.hasSrcExt(".yy")
  740. }
  741. c.AndroidModuleBase().AddJSONData(d)
  742. (*d)["Cc"] = map[string]interface{}{
  743. "SdkVersion": c.SdkVersion(),
  744. "MinSdkVersion": c.MinSdkVersion(),
  745. "VndkVersion": c.VndkVersion(),
  746. "ProductSpecific": c.ProductSpecific(),
  747. "SocSpecific": c.SocSpecific(),
  748. "DeviceSpecific": c.DeviceSpecific(),
  749. "InProduct": c.InProduct(),
  750. "InVendor": c.InVendor(),
  751. "InRamdisk": c.InRamdisk(),
  752. "InVendorRamdisk": c.InVendorRamdisk(),
  753. "InRecovery": c.InRecovery(),
  754. "VendorAvailable": c.VendorAvailable(),
  755. "ProductAvailable": c.ProductAvailable(),
  756. "RamdiskAvailable": c.RamdiskAvailable(),
  757. "VendorRamdiskAvailable": c.VendorRamdiskAvailable(),
  758. "RecoveryAvailable": c.RecoveryAvailable(),
  759. "OdmAvailable": c.OdmAvailable(),
  760. "InstallInData": c.InstallInData(),
  761. "InstallInRamdisk": c.InstallInRamdisk(),
  762. "InstallInSanitizerDir": c.InstallInSanitizerDir(),
  763. "InstallInVendorRamdisk": c.InstallInVendorRamdisk(),
  764. "InstallInRecovery": c.InstallInRecovery(),
  765. "InstallInRoot": c.InstallInRoot(),
  766. "IsVndk": c.IsVndk(),
  767. "IsVndkExt": c.IsVndkExt(),
  768. "IsVndkPrivate": c.IsVndkPrivate(),
  769. "IsVndkSp": c.IsVndkSp(),
  770. "IsLlndk": c.IsLlndk(),
  771. "IsLlndkPublic": c.IsLlndkPublic(),
  772. "IsSnapshotLibrary": c.IsSnapshotLibrary(),
  773. "IsSnapshotPrebuilt": c.IsSnapshotPrebuilt(),
  774. "IsVendorPublicLibrary": c.IsVendorPublicLibrary(),
  775. "ApexSdkVersion": c.apexSdkVersion,
  776. "TestFor": c.TestFor(),
  777. "AidlSrcs": hasAidl,
  778. "LexSrcs": hasLex,
  779. "ProtoSrcs": hasProto,
  780. "RenderscriptSrcs": hasRenderscript,
  781. "SyspropSrcs": hasSysprop,
  782. "WinMsgSrcs": hasWinMsg,
  783. "YaccSrsc": hasYacc,
  784. "OnlyCSrcs": !(hasAidl || hasLex || hasProto || hasRenderscript || hasSysprop || hasWinMsg || hasYacc),
  785. }
  786. }
  787. func (c *Module) SetPreventInstall() {
  788. c.Properties.PreventInstall = true
  789. }
  790. func (c *Module) SetHideFromMake() {
  791. c.Properties.HideFromMake = true
  792. }
  793. func (c *Module) HiddenFromMake() bool {
  794. return c.Properties.HideFromMake
  795. }
  796. func (c *Module) RequiredModuleNames() []string {
  797. required := android.CopyOf(c.ModuleBase.RequiredModuleNames())
  798. if c.ImageVariation().Variation == android.CoreVariation {
  799. required = append(required, c.Properties.Target.Platform.Required...)
  800. required = removeListFromList(required, c.Properties.Target.Platform.Exclude_required)
  801. } else if c.InRecovery() {
  802. required = append(required, c.Properties.Target.Recovery.Required...)
  803. required = removeListFromList(required, c.Properties.Target.Recovery.Exclude_required)
  804. }
  805. return android.FirstUniqueStrings(required)
  806. }
  807. func (c *Module) Toc() android.OptionalPath {
  808. if c.linker != nil {
  809. if library, ok := c.linker.(libraryInterface); ok {
  810. return library.toc()
  811. }
  812. }
  813. panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
  814. }
  815. func (c *Module) ApiLevel() string {
  816. if c.linker != nil {
  817. if stub, ok := c.linker.(*stubDecorator); ok {
  818. return stub.apiLevel.String()
  819. }
  820. }
  821. panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
  822. }
  823. func (c *Module) Static() bool {
  824. if c.linker != nil {
  825. if library, ok := c.linker.(libraryInterface); ok {
  826. return library.static()
  827. }
  828. }
  829. panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
  830. }
  831. func (c *Module) Shared() bool {
  832. if c.linker != nil {
  833. if library, ok := c.linker.(libraryInterface); ok {
  834. return library.shared()
  835. }
  836. }
  837. panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
  838. }
  839. func (c *Module) SelectedStl() string {
  840. if c.stl != nil {
  841. return c.stl.Properties.SelectedStl
  842. }
  843. return ""
  844. }
  845. func (c *Module) NdkPrebuiltStl() bool {
  846. if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
  847. return true
  848. }
  849. return false
  850. }
  851. func (c *Module) StubDecorator() bool {
  852. if _, ok := c.linker.(*stubDecorator); ok {
  853. return true
  854. }
  855. return false
  856. }
  857. func (c *Module) SdkVersion() string {
  858. return String(c.Properties.Sdk_version)
  859. }
  860. func (c *Module) MinSdkVersion() string {
  861. return String(c.Properties.Min_sdk_version)
  862. }
  863. func (c *Module) isCrt() bool {
  864. if linker, ok := c.linker.(*objectLinker); ok {
  865. return linker.isCrt()
  866. }
  867. return false
  868. }
  869. func (c *Module) SplitPerApiLevel() bool {
  870. return c.canUseSdk() && c.isCrt()
  871. }
  872. func (c *Module) AlwaysSdk() bool {
  873. return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
  874. }
  875. func (c *Module) CcLibrary() bool {
  876. if c.linker != nil {
  877. if _, ok := c.linker.(*libraryDecorator); ok {
  878. return true
  879. }
  880. if _, ok := c.linker.(*prebuiltLibraryLinker); ok {
  881. return true
  882. }
  883. }
  884. return false
  885. }
  886. func (c *Module) CcLibraryInterface() bool {
  887. if _, ok := c.linker.(libraryInterface); ok {
  888. return true
  889. }
  890. return false
  891. }
  892. func (c *Module) NonCcVariants() bool {
  893. return false
  894. }
  895. func (c *Module) SetStatic() {
  896. if c.linker != nil {
  897. if library, ok := c.linker.(libraryInterface); ok {
  898. library.setStatic()
  899. return
  900. }
  901. }
  902. panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
  903. }
  904. func (c *Module) SetShared() {
  905. if c.linker != nil {
  906. if library, ok := c.linker.(libraryInterface); ok {
  907. library.setShared()
  908. return
  909. }
  910. }
  911. panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
  912. }
  913. func (c *Module) BuildStaticVariant() bool {
  914. if c.linker != nil {
  915. if library, ok := c.linker.(libraryInterface); ok {
  916. return library.buildStatic()
  917. }
  918. }
  919. panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
  920. }
  921. func (c *Module) BuildSharedVariant() bool {
  922. if c.linker != nil {
  923. if library, ok := c.linker.(libraryInterface); ok {
  924. return library.buildShared()
  925. }
  926. }
  927. panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
  928. }
  929. func (c *Module) Module() android.Module {
  930. return c
  931. }
  932. func (c *Module) OutputFile() android.OptionalPath {
  933. return c.outputFile
  934. }
  935. func (c *Module) CoverageFiles() android.Paths {
  936. if c.linker != nil {
  937. if library, ok := c.linker.(libraryInterface); ok {
  938. return library.objs().coverageFiles
  939. }
  940. }
  941. panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
  942. }
  943. var _ LinkableInterface = (*Module)(nil)
  944. func (c *Module) UnstrippedOutputFile() android.Path {
  945. if c.linker != nil {
  946. return c.linker.unstrippedOutputFilePath()
  947. }
  948. return nil
  949. }
  950. func (c *Module) CoverageOutputFile() android.OptionalPath {
  951. if c.linker != nil {
  952. return c.linker.coverageOutputFilePath()
  953. }
  954. return android.OptionalPath{}
  955. }
  956. func (c *Module) RelativeInstallPath() string {
  957. if c.installer != nil {
  958. return c.installer.relativeInstallPath()
  959. }
  960. return ""
  961. }
  962. func (c *Module) VndkVersion() string {
  963. return c.Properties.VndkVersion
  964. }
  965. func (c *Module) Init() android.Module {
  966. c.AddProperties(&c.Properties, &c.VendorProperties)
  967. if c.compiler != nil {
  968. c.AddProperties(c.compiler.compilerProps()...)
  969. }
  970. if c.linker != nil {
  971. c.AddProperties(c.linker.linkerProps()...)
  972. }
  973. if c.installer != nil {
  974. c.AddProperties(c.installer.installerProps()...)
  975. }
  976. if c.stl != nil {
  977. c.AddProperties(c.stl.props()...)
  978. }
  979. if c.sanitize != nil {
  980. c.AddProperties(c.sanitize.props()...)
  981. }
  982. if c.coverage != nil {
  983. c.AddProperties(c.coverage.props()...)
  984. }
  985. if c.fuzzer != nil {
  986. c.AddProperties(c.fuzzer.props()...)
  987. }
  988. if c.sabi != nil {
  989. c.AddProperties(c.sabi.props()...)
  990. }
  991. if c.vndkdep != nil {
  992. c.AddProperties(c.vndkdep.props()...)
  993. }
  994. if c.lto != nil {
  995. c.AddProperties(c.lto.props()...)
  996. }
  997. if c.afdo != nil {
  998. c.AddProperties(c.afdo.props()...)
  999. }
  1000. if c.pgo != nil {
  1001. c.AddProperties(c.pgo.props()...)
  1002. }
  1003. for _, feature := range c.features {
  1004. c.AddProperties(feature.props()...)
  1005. }
  1006. android.InitAndroidArchModule(c, c.hod, c.multilib)
  1007. if c.bazelable {
  1008. android.InitBazelModule(c)
  1009. }
  1010. android.InitApexModule(c)
  1011. android.InitSdkAwareModule(c)
  1012. android.InitDefaultableModule(c)
  1013. return c
  1014. }
  1015. func (c *Module) UseVndk() bool {
  1016. return c.Properties.VndkVersion != ""
  1017. }
  1018. func (c *Module) canUseSdk() bool {
  1019. return c.Os() == android.Android && c.Target().NativeBridge == android.NativeBridgeDisabled &&
  1020. !c.UseVndk() && !c.InRamdisk() && !c.InRecovery() && !c.InVendorRamdisk()
  1021. }
  1022. func (c *Module) UseSdk() bool {
  1023. if c.canUseSdk() {
  1024. return String(c.Properties.Sdk_version) != ""
  1025. }
  1026. return false
  1027. }
  1028. func (c *Module) isCoverageVariant() bool {
  1029. return c.coverage.Properties.IsCoverageVariant
  1030. }
  1031. func (c *Module) IsNdk(config android.Config) bool {
  1032. return inList(c.BaseModuleName(), *getNDKKnownLibs(config))
  1033. }
  1034. func (c *Module) IsLlndk() bool {
  1035. return c.VendorProperties.IsLLNDK
  1036. }
  1037. func (c *Module) IsLlndkPublic() bool {
  1038. return c.VendorProperties.IsLLNDK && !c.VendorProperties.IsVNDKPrivate
  1039. }
  1040. func (m *Module) NeedsLlndkVariants() bool {
  1041. lib := moduleLibraryInterface(m)
  1042. return lib != nil && (lib.hasLLNDKStubs() || lib.hasLLNDKHeaders())
  1043. }
  1044. func (m *Module) NeedsVendorPublicLibraryVariants() bool {
  1045. lib := moduleLibraryInterface(m)
  1046. return lib != nil && (lib.hasVendorPublicLibrary())
  1047. }
  1048. // IsVendorPublicLibrary returns true for vendor public libraries.
  1049. func (c *Module) IsVendorPublicLibrary() bool {
  1050. return c.VendorProperties.IsVendorPublicLibrary
  1051. }
  1052. func (c *Module) IsVndkPrebuiltLibrary() bool {
  1053. if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
  1054. return true
  1055. }
  1056. return false
  1057. }
  1058. func (c *Module) SdkAndPlatformVariantVisibleToMake() bool {
  1059. return c.Properties.SdkAndPlatformVariantVisibleToMake
  1060. }
  1061. func (c *Module) HasLlndkStubs() bool {
  1062. lib := moduleLibraryInterface(c)
  1063. return lib != nil && lib.hasLLNDKStubs()
  1064. }
  1065. func (c *Module) StubsVersion() string {
  1066. if lib, ok := c.linker.(versionedInterface); ok {
  1067. return lib.stubsVersion()
  1068. }
  1069. panic(fmt.Errorf("StubsVersion called on non-versioned module: %q", c.BaseModuleName()))
  1070. }
  1071. // isImplementationForLLNDKPublic returns true for any variant of a cc_library that has LLNDK stubs
  1072. // and does not set llndk.vendor_available: false.
  1073. func (c *Module) isImplementationForLLNDKPublic() bool {
  1074. library, _ := c.library.(*libraryDecorator)
  1075. return library != nil && library.hasLLNDKStubs() &&
  1076. !Bool(library.Properties.Llndk.Private)
  1077. }
  1078. // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
  1079. func (c *Module) IsVndkPrivate() bool {
  1080. // Check if VNDK-core-private or VNDK-SP-private
  1081. if c.IsVndk() {
  1082. return Bool(c.vndkdep.Properties.Vndk.Private)
  1083. }
  1084. // Check if LLNDK-private
  1085. if library, ok := c.library.(*libraryDecorator); ok && c.IsLlndk() {
  1086. return Bool(library.Properties.Llndk.Private)
  1087. }
  1088. return false
  1089. }
  1090. func (c *Module) IsVndk() bool {
  1091. if vndkdep := c.vndkdep; vndkdep != nil {
  1092. return vndkdep.isVndk()
  1093. }
  1094. return false
  1095. }
  1096. func (c *Module) isAfdoCompile() bool {
  1097. if afdo := c.afdo; afdo != nil {
  1098. return afdo.Properties.AfdoTarget != nil
  1099. }
  1100. return false
  1101. }
  1102. func (c *Module) isPgoCompile() bool {
  1103. if pgo := c.pgo; pgo != nil {
  1104. return pgo.Properties.PgoCompile
  1105. }
  1106. return false
  1107. }
  1108. func (c *Module) isCfi() bool {
  1109. if sanitize := c.sanitize; sanitize != nil {
  1110. return Bool(sanitize.Properties.Sanitize.Cfi)
  1111. }
  1112. return false
  1113. }
  1114. func (c *Module) isNDKStubLibrary() bool {
  1115. if _, ok := c.compiler.(*stubDecorator); ok {
  1116. return true
  1117. }
  1118. return false
  1119. }
  1120. func (c *Module) IsVndkSp() bool {
  1121. if vndkdep := c.vndkdep; vndkdep != nil {
  1122. return vndkdep.isVndkSp()
  1123. }
  1124. return false
  1125. }
  1126. func (c *Module) IsVndkExt() bool {
  1127. if vndkdep := c.vndkdep; vndkdep != nil {
  1128. return vndkdep.isVndkExt()
  1129. }
  1130. return false
  1131. }
  1132. func (c *Module) SubName() string {
  1133. return c.Properties.SubName
  1134. }
  1135. func (c *Module) MustUseVendorVariant() bool {
  1136. return c.IsVndkSp() || c.Properties.MustUseVendorVariant
  1137. }
  1138. func (c *Module) getVndkExtendsModuleName() string {
  1139. if vndkdep := c.vndkdep; vndkdep != nil {
  1140. return vndkdep.getVndkExtendsModuleName()
  1141. }
  1142. return ""
  1143. }
  1144. func (c *Module) IsStubs() bool {
  1145. if lib := c.library; lib != nil {
  1146. return lib.buildStubs()
  1147. }
  1148. return false
  1149. }
  1150. func (c *Module) HasStubsVariants() bool {
  1151. if lib := c.library; lib != nil {
  1152. return lib.hasStubsVariants()
  1153. }
  1154. return false
  1155. }
  1156. // If this is a stubs library, ImplementationModuleName returns the name of the module that contains
  1157. // the implementation. If it is an implementation library it returns its own name.
  1158. func (c *Module) ImplementationModuleName(ctx android.BaseModuleContext) string {
  1159. name := ctx.OtherModuleName(c)
  1160. if versioned, ok := c.linker.(versionedInterface); ok {
  1161. name = versioned.implementationModuleName(name)
  1162. }
  1163. return name
  1164. }
  1165. // Similar to ImplementationModuleName, but uses the Make variant of the module
  1166. // name as base name, for use in AndroidMk output. E.g. for a prebuilt module
  1167. // where the Soong name is prebuilt_foo, this returns foo (which works in Make
  1168. // under the premise that the prebuilt module overrides its source counterpart
  1169. // if it is exposed to Make).
  1170. func (c *Module) ImplementationModuleNameForMake(ctx android.BaseModuleContext) string {
  1171. name := c.BaseModuleName()
  1172. if versioned, ok := c.linker.(versionedInterface); ok {
  1173. name = versioned.implementationModuleName(name)
  1174. }
  1175. return name
  1176. }
  1177. func (c *Module) Bootstrap() bool {
  1178. return Bool(c.Properties.Bootstrap)
  1179. }
  1180. func (c *Module) nativeCoverage() bool {
  1181. // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
  1182. if c.Target().NativeBridge == android.NativeBridgeEnabled {
  1183. return false
  1184. }
  1185. return c.linker != nil && c.linker.nativeCoverage()
  1186. }
  1187. func (c *Module) IsSnapshotPrebuilt() bool {
  1188. if p, ok := c.linker.(SnapshotInterface); ok {
  1189. return p.IsSnapshotPrebuilt()
  1190. }
  1191. return false
  1192. }
  1193. func (c *Module) ExcludeFromVendorSnapshot() bool {
  1194. return Bool(c.Properties.Exclude_from_vendor_snapshot)
  1195. }
  1196. func (c *Module) ExcludeFromRecoverySnapshot() bool {
  1197. return Bool(c.Properties.Exclude_from_recovery_snapshot)
  1198. }
  1199. func isBionic(name string) bool {
  1200. switch name {
  1201. case "libc", "libm", "libdl", "libdl_android", "linker", "linkerconfig":
  1202. return true
  1203. }
  1204. return false
  1205. }
  1206. func InstallToBootstrap(name string, config android.Config) bool {
  1207. if name == "libclang_rt.hwasan" {
  1208. return true
  1209. }
  1210. return isBionic(name)
  1211. }
  1212. func (c *Module) XrefCcFiles() android.Paths {
  1213. return c.kytheFiles
  1214. }
  1215. func (c *Module) isCfiAssemblySupportEnabled() bool {
  1216. return c.sanitize != nil &&
  1217. Bool(c.sanitize.Properties.Sanitize.Config.Cfi_assembly_support)
  1218. }
  1219. func (c *Module) InstallInRoot() bool {
  1220. return c.installer != nil && c.installer.installInRoot()
  1221. }
  1222. type baseModuleContext struct {
  1223. android.BaseModuleContext
  1224. moduleContextImpl
  1225. }
  1226. type depsContext struct {
  1227. android.BottomUpMutatorContext
  1228. moduleContextImpl
  1229. }
  1230. type moduleContext struct {
  1231. android.ModuleContext
  1232. moduleContextImpl
  1233. }
  1234. type moduleContextImpl struct {
  1235. mod *Module
  1236. ctx BaseModuleContext
  1237. }
  1238. func (ctx *moduleContextImpl) toolchain() config.Toolchain {
  1239. return ctx.mod.toolchain(ctx.ctx)
  1240. }
  1241. func (ctx *moduleContextImpl) static() bool {
  1242. return ctx.mod.static()
  1243. }
  1244. func (ctx *moduleContextImpl) staticBinary() bool {
  1245. return ctx.mod.staticBinary()
  1246. }
  1247. func (ctx *moduleContextImpl) testBinary() bool {
  1248. return ctx.mod.testBinary()
  1249. }
  1250. func (ctx *moduleContextImpl) testLibrary() bool {
  1251. return ctx.mod.testLibrary()
  1252. }
  1253. func (ctx *moduleContextImpl) header() bool {
  1254. return ctx.mod.Header()
  1255. }
  1256. func (ctx *moduleContextImpl) binary() bool {
  1257. return ctx.mod.Binary()
  1258. }
  1259. func (ctx *moduleContextImpl) object() bool {
  1260. return ctx.mod.Object()
  1261. }
  1262. func (ctx *moduleContextImpl) canUseSdk() bool {
  1263. return ctx.mod.canUseSdk()
  1264. }
  1265. func (ctx *moduleContextImpl) useSdk() bool {
  1266. return ctx.mod.UseSdk()
  1267. }
  1268. func (ctx *moduleContextImpl) sdkVersion() string {
  1269. if ctx.ctx.Device() {
  1270. if ctx.useVndk() {
  1271. vndkVer := ctx.mod.VndkVersion()
  1272. if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
  1273. return "current"
  1274. }
  1275. return vndkVer
  1276. }
  1277. return String(ctx.mod.Properties.Sdk_version)
  1278. }
  1279. return ""
  1280. }
  1281. func (ctx *moduleContextImpl) minSdkVersion() string {
  1282. ver := ctx.mod.MinSdkVersion()
  1283. if ver == "apex_inherit" && !ctx.isForPlatform() {
  1284. ver = ctx.apexSdkVersion().String()
  1285. }
  1286. if ver == "apex_inherit" || ver == "" {
  1287. ver = ctx.sdkVersion()
  1288. }
  1289. // For crt objects, the meaning of min_sdk_version is very different from other types of
  1290. // module. For them, min_sdk_version defines the oldest version that the build system will
  1291. // create versioned variants for. For example, if min_sdk_version is 16, then sdk variant of
  1292. // the crt object has local variants of 16, 17, ..., up to the latest version. sdk_version
  1293. // and min_sdk_version properties of the variants are set to the corresponding version
  1294. // numbers. However, the non-sdk variant (for apex or platform) of the crt object is left
  1295. // untouched. min_sdk_version: 16 doesn't actually mean that the non-sdk variant has to
  1296. // support such an old version. The version is set to the later version in case when the
  1297. // non-sdk variant is for the platform, or the min_sdk_version of the containing APEX if
  1298. // it's for an APEX.
  1299. if ctx.mod.isCrt() && !ctx.isSdkVariant() {
  1300. if ctx.isForPlatform() {
  1301. ver = strconv.Itoa(android.FutureApiLevelInt)
  1302. } else { // for apex
  1303. ver = ctx.apexSdkVersion().String()
  1304. if ver == "" { // in case when min_sdk_version was not set by the APEX
  1305. ver = ctx.sdkVersion()
  1306. }
  1307. }
  1308. }
  1309. // Also make sure that minSdkVersion is not greater than sdkVersion, if they are both numbers
  1310. sdkVersionInt, err := strconv.Atoi(ctx.sdkVersion())
  1311. minSdkVersionInt, err2 := strconv.Atoi(ver)
  1312. if err == nil && err2 == nil {
  1313. if sdkVersionInt < minSdkVersionInt {
  1314. return strconv.Itoa(sdkVersionInt)
  1315. }
  1316. }
  1317. return ver
  1318. }
  1319. func (ctx *moduleContextImpl) isSdkVariant() bool {
  1320. return ctx.mod.IsSdkVariant()
  1321. }
  1322. func (ctx *moduleContextImpl) useVndk() bool {
  1323. return ctx.mod.UseVndk()
  1324. }
  1325. func (ctx *moduleContextImpl) isNdk(config android.Config) bool {
  1326. return ctx.mod.IsNdk(config)
  1327. }
  1328. func (ctx *moduleContextImpl) IsLlndk() bool {
  1329. return ctx.mod.IsLlndk()
  1330. }
  1331. func (ctx *moduleContextImpl) IsLlndkPublic() bool {
  1332. return ctx.mod.IsLlndkPublic()
  1333. }
  1334. func (ctx *moduleContextImpl) isImplementationForLLNDKPublic() bool {
  1335. return ctx.mod.isImplementationForLLNDKPublic()
  1336. }
  1337. func (ctx *moduleContextImpl) IsVndkPrivate() bool {
  1338. return ctx.mod.IsVndkPrivate()
  1339. }
  1340. func (ctx *moduleContextImpl) isVndk() bool {
  1341. return ctx.mod.IsVndk()
  1342. }
  1343. func (ctx *moduleContextImpl) isAfdoCompile() bool {
  1344. return ctx.mod.isAfdoCompile()
  1345. }
  1346. func (ctx *moduleContextImpl) isPgoCompile() bool {
  1347. return ctx.mod.isPgoCompile()
  1348. }
  1349. func (ctx *moduleContextImpl) isCfi() bool {
  1350. return ctx.mod.isCfi()
  1351. }
  1352. func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
  1353. return ctx.mod.isNDKStubLibrary()
  1354. }
  1355. func (ctx *moduleContextImpl) isVndkSp() bool {
  1356. return ctx.mod.IsVndkSp()
  1357. }
  1358. func (ctx *moduleContextImpl) IsVndkExt() bool {
  1359. return ctx.mod.IsVndkExt()
  1360. }
  1361. func (ctx *moduleContextImpl) IsVendorPublicLibrary() bool {
  1362. return ctx.mod.IsVendorPublicLibrary()
  1363. }
  1364. func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
  1365. return ctx.mod.MustUseVendorVariant()
  1366. }
  1367. func (ctx *moduleContextImpl) selectedStl() string {
  1368. if stl := ctx.mod.stl; stl != nil {
  1369. return stl.Properties.SelectedStl
  1370. }
  1371. return ""
  1372. }
  1373. func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
  1374. return ctx.mod.linker.useClangLld(actx)
  1375. }
  1376. func (ctx *moduleContextImpl) baseModuleName() string {
  1377. return ctx.mod.ModuleBase.BaseModuleName()
  1378. }
  1379. func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
  1380. return ctx.mod.getVndkExtendsModuleName()
  1381. }
  1382. func (ctx *moduleContextImpl) isForPlatform() bool {
  1383. return ctx.ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
  1384. }
  1385. func (ctx *moduleContextImpl) apexVariationName() string {
  1386. return ctx.ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).ApexVariationName
  1387. }
  1388. func (ctx *moduleContextImpl) apexSdkVersion() android.ApiLevel {
  1389. return ctx.mod.apexSdkVersion
  1390. }
  1391. func (ctx *moduleContextImpl) bootstrap() bool {
  1392. return ctx.mod.Bootstrap()
  1393. }
  1394. func (ctx *moduleContextImpl) nativeCoverage() bool {
  1395. return ctx.mod.nativeCoverage()
  1396. }
  1397. func (ctx *moduleContextImpl) directlyInAnyApex() bool {
  1398. return ctx.mod.DirectlyInAnyApex()
  1399. }
  1400. func (ctx *moduleContextImpl) isPreventInstall() bool {
  1401. return ctx.mod.Properties.PreventInstall
  1402. }
  1403. func (ctx *moduleContextImpl) getSharedFlags() *SharedFlags {
  1404. shared := &ctx.mod.sharedFlags
  1405. if shared.flagsMap == nil {
  1406. shared.numSharedFlags = 0
  1407. shared.flagsMap = make(map[string]string)
  1408. }
  1409. return shared
  1410. }
  1411. func (ctx *moduleContextImpl) isCfiAssemblySupportEnabled() bool {
  1412. return ctx.mod.isCfiAssemblySupportEnabled()
  1413. }
  1414. func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
  1415. return &Module{
  1416. hod: hod,
  1417. multilib: multilib,
  1418. }
  1419. }
  1420. func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
  1421. module := newBaseModule(hod, multilib)
  1422. module.features = []feature{
  1423. &tidyFeature{},
  1424. }
  1425. module.stl = &stl{}
  1426. module.sanitize = &sanitize{}
  1427. module.coverage = &coverage{}
  1428. module.fuzzer = &fuzzer{}
  1429. module.sabi = &sabi{}
  1430. module.vndkdep = &vndkdep{}
  1431. module.lto = &lto{}
  1432. module.afdo = &afdo{}
  1433. module.pgo = &pgo{}
  1434. return module
  1435. }
  1436. func (c *Module) Prebuilt() *android.Prebuilt {
  1437. if p, ok := c.linker.(prebuiltLinkerInterface); ok {
  1438. return p.prebuilt()
  1439. }
  1440. return nil
  1441. }
  1442. func (c *Module) IsPrebuilt() bool {
  1443. return c.Prebuilt() != nil
  1444. }
  1445. func (c *Module) Name() string {
  1446. name := c.ModuleBase.Name()
  1447. if p, ok := c.linker.(interface {
  1448. Name(string) string
  1449. }); ok {
  1450. name = p.Name(name)
  1451. }
  1452. return name
  1453. }
  1454. func (c *Module) Symlinks() []string {
  1455. if p, ok := c.installer.(interface {
  1456. symlinkList() []string
  1457. }); ok {
  1458. return p.symlinkList()
  1459. }
  1460. return nil
  1461. }
  1462. func (c *Module) IsTestPerSrcAllTestsVariation() bool {
  1463. test, ok := c.linker.(testPerSrc)
  1464. return ok && test.isAllTestsVariation()
  1465. }
  1466. func (c *Module) DataPaths() []android.DataPath {
  1467. if p, ok := c.installer.(interface {
  1468. dataPaths() []android.DataPath
  1469. }); ok {
  1470. return p.dataPaths()
  1471. }
  1472. return nil
  1473. }
  1474. func getNameSuffixWithVndkVersion(ctx android.ModuleContext, c LinkableInterface) string {
  1475. // Returns the name suffix for product and vendor variants. If the VNDK version is not
  1476. // "current", it will append the VNDK version to the name suffix.
  1477. var vndkVersion string
  1478. var nameSuffix string
  1479. if c.InProduct() {
  1480. if c.ProductSpecific() {
  1481. // If the module is product specific with 'product_specific: true',
  1482. // do not add a name suffix because it is a base module.
  1483. return ""
  1484. }
  1485. vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
  1486. nameSuffix = ProductSuffix
  1487. } else {
  1488. vndkVersion = ctx.DeviceConfig().VndkVersion()
  1489. nameSuffix = VendorSuffix
  1490. }
  1491. if vndkVersion == "current" {
  1492. vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
  1493. }
  1494. if c.VndkVersion() != vndkVersion && c.VndkVersion() != "" {
  1495. // add version suffix only if the module is using different vndk version than the
  1496. // version in product or vendor partition.
  1497. nameSuffix += "." + c.VndkVersion()
  1498. }
  1499. return nameSuffix
  1500. }
  1501. func GetSubnameProperty(actx android.ModuleContext, c LinkableInterface) string {
  1502. var subName = ""
  1503. if c.Target().NativeBridge == android.NativeBridgeEnabled {
  1504. subName += NativeBridgeSuffix
  1505. }
  1506. llndk := c.IsLlndk()
  1507. if llndk || (c.UseVndk() && c.HasNonSystemVariants()) {
  1508. // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
  1509. // added for product variant only when we have vendor and product variants with core
  1510. // variant. The suffix is not added for vendor-only or product-only module.
  1511. subName += getNameSuffixWithVndkVersion(actx, c)
  1512. } else if c.IsVendorPublicLibrary() {
  1513. subName += vendorPublicLibrarySuffix
  1514. } else if c.IsVndkPrebuiltLibrary() {
  1515. // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
  1516. // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
  1517. subName += VendorSuffix
  1518. } else if c.InRamdisk() && !c.OnlyInRamdisk() {
  1519. subName += RamdiskSuffix
  1520. } else if c.InVendorRamdisk() && !c.OnlyInVendorRamdisk() {
  1521. subName += VendorRamdiskSuffix
  1522. } else if c.InRecovery() && !c.OnlyInRecovery() {
  1523. subName += RecoverySuffix
  1524. } else if c.IsSdkVariant() && (c.SdkAndPlatformVariantVisibleToMake() || c.SplitPerApiLevel()) {
  1525. subName += sdkSuffix
  1526. if c.SplitPerApiLevel() {
  1527. subName += "." + c.SdkVersion()
  1528. }
  1529. }
  1530. return subName
  1531. }
  1532. var _ android.MixedBuildBuildable = (*Module)(nil)
  1533. func (c *Module) getBazelModuleLabel(ctx android.BaseModuleContext) string {
  1534. var bazelModuleLabel string
  1535. if c.typ() == fullLibrary && c.static() {
  1536. // cc_library is a special case in bp2build; two targets are generated -- one for each
  1537. // of the shared and static variants. The shared variant keeps the module name, but the
  1538. // static variant uses a different suffixed name.
  1539. bazelModuleLabel = bazelLabelForStaticModule(ctx, c)
  1540. } else {
  1541. bazelModuleLabel = c.GetBazelLabel(ctx, c)
  1542. }
  1543. labelNoPrebuilt := bazelModuleLabel
  1544. if c.IsPrebuilt() {
  1545. labelNoPrebuilt = android.RemoveOptionalPrebuiltPrefixFromBazelLabel(bazelModuleLabel)
  1546. }
  1547. return labelNoPrebuilt
  1548. }
  1549. func (c *Module) QueueBazelCall(ctx android.BaseModuleContext) {
  1550. c.bazelHandler.QueueBazelCall(ctx, c.getBazelModuleLabel(ctx))
  1551. }
  1552. func (c *Module) IsMixedBuildSupported(ctx android.BaseModuleContext) bool {
  1553. return c.bazelHandler != nil
  1554. }
  1555. func (c *Module) ProcessBazelQueryResponse(ctx android.ModuleContext) {
  1556. bazelModuleLabel := c.getBazelModuleLabel(ctx)
  1557. c.bazelHandler.ProcessBazelQueryResponse(ctx, bazelModuleLabel)
  1558. c.Properties.SubName = GetSubnameProperty(ctx, c)
  1559. apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
  1560. if !apexInfo.IsForPlatform() {
  1561. c.hideApexVariantFromMake = true
  1562. }
  1563. c.makeLinkType = GetMakeLinkType(ctx, c)
  1564. mctx := &moduleContext{
  1565. ModuleContext: ctx,
  1566. moduleContextImpl: moduleContextImpl{
  1567. mod: c,
  1568. },
  1569. }
  1570. mctx.ctx = mctx
  1571. c.maybeInstall(mctx, apexInfo)
  1572. }
  1573. func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
  1574. // Handle the case of a test module split by `test_per_src` mutator.
  1575. //
  1576. // The `test_per_src` mutator adds an extra variation named "", depending on all the other
  1577. // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
  1578. // module and return early, as this module does not produce an output file per se.
  1579. if c.IsTestPerSrcAllTestsVariation() {
  1580. c.outputFile = android.OptionalPath{}
  1581. return
  1582. }
  1583. c.Properties.SubName = GetSubnameProperty(actx, c)
  1584. apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
  1585. if !apexInfo.IsForPlatform() {
  1586. c.hideApexVariantFromMake = true
  1587. }
  1588. c.makeLinkType = GetMakeLinkType(actx, c)
  1589. ctx := &moduleContext{
  1590. ModuleContext: actx,
  1591. moduleContextImpl: moduleContextImpl{
  1592. mod: c,
  1593. },
  1594. }
  1595. ctx.ctx = ctx
  1596. deps := c.depsToPaths(ctx)
  1597. if ctx.Failed() {
  1598. return
  1599. }
  1600. if c.Properties.Clang != nil && *c.Properties.Clang == false {
  1601. ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
  1602. } else if c.Properties.Clang != nil && !ctx.DeviceConfig().BuildBrokenClangProperty() {
  1603. ctx.PropertyErrorf("clang", "property is deprecated, see Changes.md file")
  1604. }
  1605. flags := Flags{
  1606. Toolchain: c.toolchain(ctx),
  1607. EmitXrefs: ctx.Config().EmitXrefRules(),
  1608. }
  1609. if c.compiler != nil {
  1610. flags = c.compiler.compilerFlags(ctx, flags, deps)
  1611. }
  1612. if c.linker != nil {
  1613. flags = c.linker.linkerFlags(ctx, flags)
  1614. }
  1615. if c.stl != nil {
  1616. flags = c.stl.flags(ctx, flags)
  1617. }
  1618. if c.sanitize != nil {
  1619. flags = c.sanitize.flags(ctx, flags)
  1620. }
  1621. if c.coverage != nil {
  1622. flags, deps = c.coverage.flags(ctx, flags, deps)
  1623. }
  1624. if c.fuzzer != nil {
  1625. flags = c.fuzzer.flags(ctx, flags)
  1626. }
  1627. if c.lto != nil {
  1628. flags = c.lto.flags(ctx, flags)
  1629. }
  1630. if c.afdo != nil {
  1631. flags = c.afdo.flags(ctx, flags)
  1632. }
  1633. if c.pgo != nil {
  1634. flags = c.pgo.flags(ctx, flags)
  1635. }
  1636. for _, feature := range c.features {
  1637. flags = feature.flags(ctx, flags)
  1638. }
  1639. if ctx.Failed() {
  1640. return
  1641. }
  1642. flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
  1643. flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
  1644. flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
  1645. flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
  1646. for _, dir := range deps.IncludeDirs {
  1647. flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
  1648. }
  1649. for _, dir := range deps.SystemIncludeDirs {
  1650. flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
  1651. }
  1652. flags.Local.LdFlags = append(flags.Local.LdFlags, deps.LdFlags...)
  1653. c.flags = flags
  1654. // We need access to all the flags seen by a source file.
  1655. if c.sabi != nil {
  1656. flags = c.sabi.flags(ctx, flags)
  1657. }
  1658. flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
  1659. var objs Objects
  1660. if c.compiler != nil {
  1661. objs = c.compiler.compile(ctx, flags, deps)
  1662. if ctx.Failed() {
  1663. return
  1664. }
  1665. c.kytheFiles = objs.kytheFiles
  1666. c.objFiles = objs.objFiles
  1667. c.tidyFiles = objs.tidyFiles
  1668. }
  1669. if c.linker != nil {
  1670. outputFile := c.linker.link(ctx, flags, deps, objs)
  1671. if ctx.Failed() {
  1672. return
  1673. }
  1674. c.outputFile = android.OptionalPathForPath(outputFile)
  1675. c.maybeUnhideFromMake()
  1676. // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current or
  1677. // RECOVERY_SNAPSHOT_VERSION is current.
  1678. if i, ok := c.linker.(snapshotLibraryInterface); ok {
  1679. if ShouldCollectHeadersForSnapshot(ctx, c, apexInfo) {
  1680. i.collectHeadersForSnapshot(ctx)
  1681. }
  1682. }
  1683. }
  1684. c.maybeInstall(ctx, apexInfo)
  1685. }
  1686. func (c *Module) maybeUnhideFromMake() {
  1687. // If a lib is directly included in any of the APEXes or is not available to the
  1688. // platform (which is often the case when the stub is provided as a prebuilt),
  1689. // unhide the stubs variant having the latest version gets visible to make. In
  1690. // addition, the non-stubs variant is renamed to <libname>.bootstrap. This is to
  1691. // force anything in the make world to link against the stubs library. (unless it
  1692. // is explicitly referenced via .bootstrap suffix or the module is marked with
  1693. // 'bootstrap: true').
  1694. if c.HasStubsVariants() && c.NotInPlatform() && !c.InRamdisk() &&
  1695. !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
  1696. c.IsStubs() && !c.InVendorRamdisk() {
  1697. c.Properties.HideFromMake = false // unhide
  1698. // Note: this is still non-installable
  1699. }
  1700. }
  1701. func (c *Module) maybeInstall(ctx ModuleContext, apexInfo android.ApexInfo) {
  1702. if !proptools.BoolDefault(c.Installable(), true) {
  1703. // If the module has been specifically configure to not be installed then
  1704. // hide from make as otherwise it will break when running inside make
  1705. // as the output path to install will not be specified. Not all uninstallable
  1706. // modules can be hidden from make as some are needed for resolving make side
  1707. // dependencies.
  1708. c.HideFromMake()
  1709. } else if !installable(c, apexInfo) {
  1710. c.SkipInstall()
  1711. }
  1712. // Still call c.installer.install though, the installs will be stored as PackageSpecs
  1713. // to allow using the outputs in a genrule.
  1714. if c.installer != nil && c.outputFile.Valid() {
  1715. c.installer.install(ctx, c.outputFile.Path())
  1716. if ctx.Failed() {
  1717. return
  1718. }
  1719. }
  1720. }
  1721. func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
  1722. if c.cachedToolchain == nil {
  1723. c.cachedToolchain = config.FindToolchainWithContext(ctx)
  1724. }
  1725. return c.cachedToolchain
  1726. }
  1727. func (c *Module) begin(ctx BaseModuleContext) {
  1728. if c.compiler != nil {
  1729. c.compiler.compilerInit(ctx)
  1730. }
  1731. if c.linker != nil {
  1732. c.linker.linkerInit(ctx)
  1733. }
  1734. if c.stl != nil {
  1735. c.stl.begin(ctx)
  1736. }
  1737. if c.sanitize != nil {
  1738. c.sanitize.begin(ctx)
  1739. }
  1740. if c.coverage != nil {
  1741. c.coverage.begin(ctx)
  1742. }
  1743. if c.lto != nil {
  1744. c.lto.begin(ctx)
  1745. }
  1746. if c.afdo != nil {
  1747. c.afdo.begin(ctx)
  1748. }
  1749. if c.pgo != nil {
  1750. c.pgo.begin(ctx)
  1751. }
  1752. if ctx.useSdk() && c.IsSdkVariant() {
  1753. version, err := nativeApiLevelFromUser(ctx, ctx.sdkVersion())
  1754. if err != nil {
  1755. ctx.PropertyErrorf("sdk_version", err.Error())
  1756. c.Properties.Sdk_version = nil
  1757. } else {
  1758. c.Properties.Sdk_version = StringPtr(version.String())
  1759. }
  1760. }
  1761. }
  1762. func (c *Module) deps(ctx DepsContext) Deps {
  1763. deps := Deps{}
  1764. if c.compiler != nil {
  1765. deps = c.compiler.compilerDeps(ctx, deps)
  1766. }
  1767. if c.linker != nil {
  1768. deps = c.linker.linkerDeps(ctx, deps)
  1769. }
  1770. if c.stl != nil {
  1771. deps = c.stl.deps(ctx, deps)
  1772. }
  1773. if c.coverage != nil {
  1774. deps = c.coverage.deps(ctx, deps)
  1775. }
  1776. deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
  1777. deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
  1778. deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
  1779. deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
  1780. deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
  1781. deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
  1782. deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
  1783. for _, lib := range deps.ReexportSharedLibHeaders {
  1784. if !inList(lib, deps.SharedLibs) {
  1785. ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
  1786. }
  1787. }
  1788. for _, lib := range deps.ReexportStaticLibHeaders {
  1789. if !inList(lib, deps.StaticLibs) && !inList(lib, deps.WholeStaticLibs) {
  1790. ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs or whole_static_libs: '%s'", lib)
  1791. }
  1792. }
  1793. for _, lib := range deps.ReexportHeaderLibHeaders {
  1794. if !inList(lib, deps.HeaderLibs) {
  1795. ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
  1796. }
  1797. }
  1798. for _, gen := range deps.ReexportGeneratedHeaders {
  1799. if !inList(gen, deps.GeneratedHeaders) {
  1800. ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
  1801. }
  1802. }
  1803. return deps
  1804. }
  1805. func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
  1806. ctx := &baseModuleContext{
  1807. BaseModuleContext: actx,
  1808. moduleContextImpl: moduleContextImpl{
  1809. mod: c,
  1810. },
  1811. }
  1812. ctx.ctx = ctx
  1813. c.begin(ctx)
  1814. }
  1815. // Split name#version into name and version
  1816. func StubsLibNameAndVersion(name string) (string, string) {
  1817. if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
  1818. version := name[sharp+1:]
  1819. libname := name[:sharp]
  1820. return libname, version
  1821. }
  1822. return name, ""
  1823. }
  1824. func GetCrtVariations(ctx android.BottomUpMutatorContext,
  1825. m LinkableInterface) []blueprint.Variation {
  1826. if ctx.Os() != android.Android {
  1827. return nil
  1828. }
  1829. if m.UseSdk() {
  1830. // Choose the CRT that best satisfies the min_sdk_version requirement of this module
  1831. minSdkVersion := m.MinSdkVersion()
  1832. if minSdkVersion == "" || minSdkVersion == "apex_inherit" {
  1833. minSdkVersion = m.SdkVersion()
  1834. }
  1835. apiLevel, err := android.ApiLevelFromUser(ctx, minSdkVersion)
  1836. if err != nil {
  1837. ctx.PropertyErrorf("min_sdk_version", err.Error())
  1838. }
  1839. return []blueprint.Variation{
  1840. {Mutator: "sdk", Variation: "sdk"},
  1841. {Mutator: "version", Variation: apiLevel.String()},
  1842. }
  1843. }
  1844. return []blueprint.Variation{
  1845. {Mutator: "sdk", Variation: ""},
  1846. }
  1847. }
  1848. func AddSharedLibDependenciesWithVersions(ctx android.BottomUpMutatorContext, mod LinkableInterface,
  1849. variations []blueprint.Variation, depTag blueprint.DependencyTag, name, version string, far bool) {
  1850. variations = append([]blueprint.Variation(nil), variations...)
  1851. if version != "" && canBeOrLinkAgainstVersionVariants(mod) {
  1852. // Version is explicitly specified. i.e. libFoo#30
  1853. variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
  1854. if tag, ok := depTag.(libraryDependencyTag); ok {
  1855. tag.explicitlyVersioned = true
  1856. } else {
  1857. panic(fmt.Errorf("Unexpected dependency tag: %T", depTag))
  1858. }
  1859. }
  1860. if far {
  1861. ctx.AddFarVariationDependencies(variations, depTag, name)
  1862. } else {
  1863. ctx.AddVariationDependencies(variations, depTag, name)
  1864. }
  1865. }
  1866. func GetApiImports(c LinkableInterface, actx android.BottomUpMutatorContext) multitree.ApiImportInfo {
  1867. apiImportInfo := multitree.ApiImportInfo{}
  1868. if c.Device() {
  1869. var apiImportModule []blueprint.Module
  1870. if actx.OtherModuleExists("api_imports") {
  1871. apiImportModule = actx.AddDependency(c, nil, "api_imports")
  1872. if len(apiImportModule) > 0 && apiImportModule[0] != nil {
  1873. apiInfo := actx.OtherModuleProvider(apiImportModule[0], multitree.ApiImportsProvider).(multitree.ApiImportInfo)
  1874. apiImportInfo = apiInfo
  1875. actx.SetProvider(multitree.ApiImportsProvider, apiInfo)
  1876. }
  1877. }
  1878. }
  1879. return apiImportInfo
  1880. }
  1881. func GetSnapshot(c LinkableInterface, snapshotInfo **SnapshotInfo, actx android.BottomUpMutatorContext) SnapshotInfo {
  1882. // Only device modules with BOARD_VNDK_VERSION uses snapshot. Others use the zero value of
  1883. // SnapshotInfo, which provides no mappings.
  1884. if *snapshotInfo == nil && c.Device() {
  1885. // Only retrieve the snapshot on demand in order to avoid circular dependencies
  1886. // between the modules in the snapshot and the snapshot itself.
  1887. var snapshotModule []blueprint.Module
  1888. if c.InVendor() && c.VndkVersion() == actx.DeviceConfig().VndkVersion() {
  1889. snapshotModule = actx.AddVariationDependencies(nil, nil, "vendor_snapshot")
  1890. } else if recoverySnapshotVersion := actx.DeviceConfig().RecoverySnapshotVersion(); recoverySnapshotVersion != "current" && recoverySnapshotVersion != "" && c.InRecovery() {
  1891. snapshotModule = actx.AddVariationDependencies(nil, nil, "recovery_snapshot")
  1892. }
  1893. if len(snapshotModule) > 0 && snapshotModule[0] != nil {
  1894. snapshot := actx.OtherModuleProvider(snapshotModule[0], SnapshotInfoProvider).(SnapshotInfo)
  1895. *snapshotInfo = &snapshot
  1896. // republish the snapshot for use in later mutators on this module
  1897. actx.SetProvider(SnapshotInfoProvider, snapshot)
  1898. }
  1899. }
  1900. if *snapshotInfo == nil {
  1901. *snapshotInfo = &SnapshotInfo{}
  1902. }
  1903. return **snapshotInfo
  1904. }
  1905. func GetReplaceModuleName(lib string, replaceMap map[string]string) string {
  1906. if snapshot, ok := replaceMap[lib]; ok {
  1907. return snapshot
  1908. }
  1909. return lib
  1910. }
  1911. // RewriteLibs takes a list of names of shared libraries and scans it for three types
  1912. // of names:
  1913. //
  1914. // 1. Name of an NDK library that refers to a prebuilt module.
  1915. //
  1916. // For each of these, it adds the name of the prebuilt module (which will be in
  1917. // prebuilts/ndk) to the list of nonvariant libs.
  1918. //
  1919. // 2. Name of an NDK library that refers to an ndk_library module.
  1920. //
  1921. // For each of these, it adds the name of the ndk_library module to the list of
  1922. // variant libs.
  1923. //
  1924. // 3. Anything else (so anything that isn't an NDK library).
  1925. //
  1926. // It adds these to the nonvariantLibs list.
  1927. //
  1928. // The caller can then know to add the variantLibs dependencies differently from the
  1929. // nonvariantLibs
  1930. func RewriteLibs(c LinkableInterface, snapshotInfo **SnapshotInfo, actx android.BottomUpMutatorContext, config android.Config, list []string) (nonvariantLibs []string, variantLibs []string) {
  1931. variantLibs = []string{}
  1932. nonvariantLibs = []string{}
  1933. for _, entry := range list {
  1934. // strip #version suffix out
  1935. name, _ := StubsLibNameAndVersion(entry)
  1936. if c.InRecovery() {
  1937. nonvariantLibs = append(nonvariantLibs, GetReplaceModuleName(entry, GetSnapshot(c, snapshotInfo, actx).SharedLibs))
  1938. } else if c.UseSdk() && inList(name, *getNDKKnownLibs(config)) {
  1939. variantLibs = append(variantLibs, name+ndkLibrarySuffix)
  1940. } else if c.UseVndk() {
  1941. nonvariantLibs = append(nonvariantLibs, GetReplaceModuleName(entry, GetSnapshot(c, snapshotInfo, actx).SharedLibs))
  1942. } else {
  1943. // put name#version back
  1944. nonvariantLibs = append(nonvariantLibs, entry)
  1945. }
  1946. }
  1947. return nonvariantLibs, variantLibs
  1948. }
  1949. func updateDepsWithApiImports(deps Deps, apiImports multitree.ApiImportInfo) Deps {
  1950. for idx, lib := range deps.SharedLibs {
  1951. deps.SharedLibs[idx] = GetReplaceModuleName(lib, apiImports.SharedLibs)
  1952. }
  1953. for idx, lib := range deps.LateSharedLibs {
  1954. deps.LateSharedLibs[idx] = GetReplaceModuleName(lib, apiImports.SharedLibs)
  1955. }
  1956. for idx, lib := range deps.RuntimeLibs {
  1957. deps.RuntimeLibs[idx] = GetReplaceModuleName(lib, apiImports.SharedLibs)
  1958. }
  1959. for idx, lib := range deps.SystemSharedLibs {
  1960. deps.SystemSharedLibs[idx] = GetReplaceModuleName(lib, apiImports.SharedLibs)
  1961. }
  1962. for idx, lib := range deps.ReexportSharedLibHeaders {
  1963. deps.ReexportSharedLibHeaders[idx] = GetReplaceModuleName(lib, apiImports.SharedLibs)
  1964. }
  1965. return deps
  1966. }
  1967. func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
  1968. if !c.Enabled() {
  1969. return
  1970. }
  1971. ctx := &depsContext{
  1972. BottomUpMutatorContext: actx,
  1973. moduleContextImpl: moduleContextImpl{
  1974. mod: c,
  1975. },
  1976. }
  1977. ctx.ctx = ctx
  1978. deps := c.deps(ctx)
  1979. apiImportInfo := GetApiImports(c, actx)
  1980. deps = updateDepsWithApiImports(deps, apiImportInfo)
  1981. c.Properties.AndroidMkSystemSharedLibs = deps.SystemSharedLibs
  1982. var snapshotInfo *SnapshotInfo
  1983. variantNdkLibs := []string{}
  1984. variantLateNdkLibs := []string{}
  1985. if ctx.Os() == android.Android {
  1986. deps.SharedLibs, variantNdkLibs = RewriteLibs(c, &snapshotInfo, actx, ctx.Config(), deps.SharedLibs)
  1987. deps.LateSharedLibs, variantLateNdkLibs = RewriteLibs(c, &snapshotInfo, actx, ctx.Config(), deps.LateSharedLibs)
  1988. deps.ReexportSharedLibHeaders, _ = RewriteLibs(c, &snapshotInfo, actx, ctx.Config(), deps.ReexportSharedLibHeaders)
  1989. for idx, lib := range deps.RuntimeLibs {
  1990. deps.RuntimeLibs[idx] = GetReplaceModuleName(lib, GetSnapshot(c, &snapshotInfo, actx).SharedLibs)
  1991. }
  1992. }
  1993. for _, lib := range deps.HeaderLibs {
  1994. depTag := libraryDependencyTag{Kind: headerLibraryDependency}
  1995. if inList(lib, deps.ReexportHeaderLibHeaders) {
  1996. depTag.reexportFlags = true
  1997. }
  1998. // Check header lib replacement from API surface first, and then check again with VSDK
  1999. lib = GetReplaceModuleName(lib, apiImportInfo.HeaderLibs)
  2000. lib = GetReplaceModuleName(lib, GetSnapshot(c, &snapshotInfo, actx).HeaderLibs)
  2001. if c.isNDKStubLibrary() {
  2002. // ndk_headers do not have any variations
  2003. actx.AddFarVariationDependencies([]blueprint.Variation{}, depTag, lib)
  2004. } else if c.IsStubs() && !c.isImportedApiLibrary() {
  2005. actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
  2006. depTag, lib)
  2007. } else {
  2008. actx.AddVariationDependencies(nil, depTag, lib)
  2009. }
  2010. }
  2011. if c.isNDKStubLibrary() {
  2012. // NDK stubs depend on their implementation because the ABI dumps are
  2013. // generated from the implementation library.
  2014. apiImportName := c.BaseModuleName() + multitree.GetApiImportSuffix()
  2015. // If original library exists as imported API, set dependency on the imported library
  2016. if actx.OtherModuleExists(apiImportName) {
  2017. actx.AddFarVariationDependencies(append(ctx.Target().Variations(),
  2018. c.ImageVariation(),
  2019. blueprint.Variation{Mutator: "link", Variation: "shared"},
  2020. ), stubImplementation, apiImportName)
  2021. } else {
  2022. actx.AddFarVariationDependencies(append(ctx.Target().Variations(),
  2023. c.ImageVariation(),
  2024. blueprint.Variation{Mutator: "link", Variation: "shared"},
  2025. ), stubImplementation, c.BaseModuleName())
  2026. }
  2027. }
  2028. for _, lib := range deps.WholeStaticLibs {
  2029. depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
  2030. lib = GetReplaceModuleName(lib, GetSnapshot(c, &snapshotInfo, actx).StaticLibs)
  2031. actx.AddVariationDependencies([]blueprint.Variation{
  2032. {Mutator: "link", Variation: "static"},
  2033. }, depTag, lib)
  2034. }
  2035. for _, lib := range deps.StaticLibs {
  2036. depTag := libraryDependencyTag{Kind: staticLibraryDependency}
  2037. if inList(lib, deps.ReexportStaticLibHeaders) {
  2038. depTag.reexportFlags = true
  2039. }
  2040. if inList(lib, deps.ExcludeLibsForApex) {
  2041. depTag.excludeInApex = true
  2042. }
  2043. lib = GetReplaceModuleName(lib, GetSnapshot(c, &snapshotInfo, actx).StaticLibs)
  2044. actx.AddVariationDependencies([]blueprint.Variation{
  2045. {Mutator: "link", Variation: "static"},
  2046. }, depTag, lib)
  2047. }
  2048. // staticUnwinderDep is treated as staticDep for Q apexes
  2049. // so that native libraries/binaries are linked with static unwinder
  2050. // because Q libc doesn't have unwinder APIs
  2051. if deps.StaticUnwinderIfLegacy {
  2052. depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
  2053. actx.AddVariationDependencies([]blueprint.Variation{
  2054. {Mutator: "link", Variation: "static"},
  2055. }, depTag, GetReplaceModuleName(staticUnwinder(actx), GetSnapshot(c, &snapshotInfo, actx).StaticLibs))
  2056. }
  2057. // shared lib names without the #version suffix
  2058. var sharedLibNames []string
  2059. for _, lib := range deps.SharedLibs {
  2060. depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
  2061. if inList(lib, deps.ReexportSharedLibHeaders) {
  2062. depTag.reexportFlags = true
  2063. }
  2064. if inList(lib, deps.ExcludeLibsForApex) {
  2065. depTag.excludeInApex = true
  2066. }
  2067. name, version := StubsLibNameAndVersion(lib)
  2068. sharedLibNames = append(sharedLibNames, name)
  2069. variations := []blueprint.Variation{
  2070. {Mutator: "link", Variation: "shared"},
  2071. }
  2072. AddSharedLibDependenciesWithVersions(ctx, c, variations, depTag, name, version, false)
  2073. }
  2074. for _, lib := range deps.LateStaticLibs {
  2075. depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
  2076. actx.AddVariationDependencies([]blueprint.Variation{
  2077. {Mutator: "link", Variation: "static"},
  2078. }, depTag, GetReplaceModuleName(lib, GetSnapshot(c, &snapshotInfo, actx).StaticLibs))
  2079. }
  2080. for _, lib := range deps.UnexportedStaticLibs {
  2081. depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency, unexportedSymbols: true}
  2082. actx.AddVariationDependencies([]blueprint.Variation{
  2083. {Mutator: "link", Variation: "static"},
  2084. }, depTag, GetReplaceModuleName(lib, GetSnapshot(c, &snapshotInfo, actx).StaticLibs))
  2085. }
  2086. for _, lib := range deps.LateSharedLibs {
  2087. if inList(lib, sharedLibNames) {
  2088. // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
  2089. // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
  2090. // linking against both the stubs lib and the non-stubs lib at the same time.
  2091. continue
  2092. }
  2093. depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
  2094. variations := []blueprint.Variation{
  2095. {Mutator: "link", Variation: "shared"},
  2096. }
  2097. AddSharedLibDependenciesWithVersions(ctx, c, variations, depTag, lib, "", false)
  2098. }
  2099. actx.AddVariationDependencies([]blueprint.Variation{
  2100. {Mutator: "link", Variation: "shared"},
  2101. }, dataLibDepTag, deps.DataLibs...)
  2102. actx.AddVariationDependencies(nil, dataBinDepTag, deps.DataBins...)
  2103. actx.AddVariationDependencies([]blueprint.Variation{
  2104. {Mutator: "link", Variation: "shared"},
  2105. }, runtimeDepTag, deps.RuntimeLibs...)
  2106. actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
  2107. for _, gen := range deps.GeneratedHeaders {
  2108. depTag := genHeaderDepTag
  2109. if inList(gen, deps.ReexportGeneratedHeaders) {
  2110. depTag = genHeaderExportDepTag
  2111. }
  2112. actx.AddDependency(c, depTag, gen)
  2113. }
  2114. crtVariations := GetCrtVariations(ctx, c)
  2115. actx.AddVariationDependencies(crtVariations, objDepTag, deps.ObjFiles...)
  2116. for _, crt := range deps.CrtBegin {
  2117. actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
  2118. GetReplaceModuleName(crt, GetSnapshot(c, &snapshotInfo, actx).Objects))
  2119. }
  2120. for _, crt := range deps.CrtEnd {
  2121. actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
  2122. GetReplaceModuleName(crt, GetSnapshot(c, &snapshotInfo, actx).Objects))
  2123. }
  2124. if deps.DynamicLinker != "" {
  2125. actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
  2126. }
  2127. version := ctx.sdkVersion()
  2128. ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
  2129. actx.AddVariationDependencies([]blueprint.Variation{
  2130. {Mutator: "version", Variation: version},
  2131. {Mutator: "link", Variation: "shared"},
  2132. }, ndkStubDepTag, variantNdkLibs...)
  2133. ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
  2134. actx.AddVariationDependencies([]blueprint.Variation{
  2135. {Mutator: "version", Variation: version},
  2136. {Mutator: "link", Variation: "shared"},
  2137. }, ndkLateStubDepTag, variantLateNdkLibs...)
  2138. if vndkdep := c.vndkdep; vndkdep != nil {
  2139. if vndkdep.isVndkExt() {
  2140. actx.AddVariationDependencies([]blueprint.Variation{
  2141. c.ImageVariation(),
  2142. {Mutator: "link", Variation: "shared"},
  2143. }, vndkExtDepTag, GetReplaceModuleName(vndkdep.getVndkExtendsModuleName(), GetSnapshot(c, &snapshotInfo, actx).SharedLibs))
  2144. }
  2145. }
  2146. }
  2147. func BeginMutator(ctx android.BottomUpMutatorContext) {
  2148. if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
  2149. c.beginMutator(ctx)
  2150. }
  2151. }
  2152. // Whether a module can link to another module, taking into
  2153. // account NDK linking.
  2154. func checkLinkType(ctx android.BaseModuleContext, from LinkableInterface, to LinkableInterface,
  2155. tag blueprint.DependencyTag) {
  2156. switch t := tag.(type) {
  2157. case dependencyTag:
  2158. if t != vndkExtDepTag {
  2159. return
  2160. }
  2161. case libraryDependencyTag:
  2162. default:
  2163. return
  2164. }
  2165. if from.Target().Os != android.Android {
  2166. // Host code is not restricted
  2167. return
  2168. }
  2169. // VNDK is cc.Module supported only for now.
  2170. if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
  2171. // Though allowed dependency is limited by the image mutator,
  2172. // each vendor and product module needs to check link-type
  2173. // for VNDK.
  2174. if ccTo, ok := to.(*Module); ok {
  2175. if ccFrom.vndkdep != nil {
  2176. ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
  2177. }
  2178. } else if _, ok := to.(LinkableInterface); !ok {
  2179. ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
  2180. }
  2181. return
  2182. }
  2183. if from.SdkVersion() == "" {
  2184. // Platform code can link to anything
  2185. return
  2186. }
  2187. if from.InRamdisk() {
  2188. // Ramdisk code is not NDK
  2189. return
  2190. }
  2191. if from.InVendorRamdisk() {
  2192. // Vendor ramdisk code is not NDK
  2193. return
  2194. }
  2195. if from.InRecovery() {
  2196. // Recovery code is not NDK
  2197. return
  2198. }
  2199. if c, ok := to.(*Module); ok {
  2200. if c.NdkPrebuiltStl() {
  2201. // These are allowed, but they don't set sdk_version
  2202. return
  2203. }
  2204. if c.StubDecorator() {
  2205. // These aren't real libraries, but are the stub shared libraries that are included in
  2206. // the NDK.
  2207. return
  2208. }
  2209. }
  2210. if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
  2211. // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
  2212. // to link to libc++ (non-NDK and without sdk_version).
  2213. return
  2214. }
  2215. if to.SdkVersion() == "" {
  2216. // NDK code linking to platform code is never okay.
  2217. ctx.ModuleErrorf("depends on non-NDK-built library %q",
  2218. ctx.OtherModuleName(to.Module()))
  2219. return
  2220. }
  2221. // At this point we know we have two NDK libraries, but we need to
  2222. // check that we're not linking against anything built against a higher
  2223. // API level, as it is only valid to link against older or equivalent
  2224. // APIs.
  2225. // Current can link against anything.
  2226. if from.SdkVersion() != "current" {
  2227. // Otherwise we need to check.
  2228. if to.SdkVersion() == "current" {
  2229. // Current can't be linked against by anything else.
  2230. ctx.ModuleErrorf("links %q built against newer API version %q",
  2231. ctx.OtherModuleName(to.Module()), "current")
  2232. } else {
  2233. fromApi, err := strconv.Atoi(from.SdkVersion())
  2234. if err != nil {
  2235. ctx.PropertyErrorf("sdk_version",
  2236. "Invalid sdk_version value (must be int or current): %q",
  2237. from.SdkVersion())
  2238. }
  2239. toApi, err := strconv.Atoi(to.SdkVersion())
  2240. if err != nil {
  2241. ctx.PropertyErrorf("sdk_version",
  2242. "Invalid sdk_version value (must be int or current): %q",
  2243. to.SdkVersion())
  2244. }
  2245. if toApi > fromApi {
  2246. ctx.ModuleErrorf("links %q built against newer API version %q",
  2247. ctx.OtherModuleName(to.Module()), to.SdkVersion())
  2248. }
  2249. }
  2250. }
  2251. // Also check that the two STL choices are compatible.
  2252. fromStl := from.SelectedStl()
  2253. toStl := to.SelectedStl()
  2254. if fromStl == "" || toStl == "" {
  2255. // Libraries that don't use the STL are unrestricted.
  2256. } else if fromStl == "ndk_system" || toStl == "ndk_system" {
  2257. // We can be permissive with the system "STL" since it is only the C++
  2258. // ABI layer, but in the future we should make sure that everyone is
  2259. // using either libc++ or nothing.
  2260. } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
  2261. ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
  2262. from.SelectedStl(), ctx.OtherModuleName(to.Module()),
  2263. to.SelectedStl())
  2264. }
  2265. }
  2266. func checkLinkTypeMutator(ctx android.BottomUpMutatorContext) {
  2267. if c, ok := ctx.Module().(*Module); ok {
  2268. ctx.VisitDirectDeps(func(dep android.Module) {
  2269. depTag := ctx.OtherModuleDependencyTag(dep)
  2270. ccDep, ok := dep.(LinkableInterface)
  2271. if ok {
  2272. checkLinkType(ctx, c, ccDep, depTag)
  2273. }
  2274. })
  2275. }
  2276. }
  2277. // Tests whether the dependent library is okay to be double loaded inside a single process.
  2278. // If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
  2279. // it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
  2280. // or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
  2281. func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
  2282. check := func(child, parent android.Module) bool {
  2283. to, ok := child.(*Module)
  2284. if !ok {
  2285. return false
  2286. }
  2287. if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
  2288. return false
  2289. }
  2290. // These dependencies are not excercised at runtime. Tracking these will give us
  2291. // false negative, so skip.
  2292. depTag := ctx.OtherModuleDependencyTag(child)
  2293. if IsHeaderDepTag(depTag) {
  2294. return false
  2295. }
  2296. if depTag == staticVariantTag {
  2297. return false
  2298. }
  2299. if depTag == stubImplDepTag {
  2300. return false
  2301. }
  2302. // Even if target lib has no vendor variant, keep checking dependency
  2303. // graph in case it depends on vendor_available or product_available
  2304. // but not double_loadable transtively.
  2305. if !to.HasNonSystemVariants() {
  2306. return true
  2307. }
  2308. // The happy path. Keep tracking dependencies until we hit a non double-loadable
  2309. // one.
  2310. if Bool(to.VendorProperties.Double_loadable) {
  2311. return true
  2312. }
  2313. if to.IsVndkSp() || to.IsLlndk() {
  2314. return false
  2315. }
  2316. ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
  2317. "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
  2318. "Dependency list: %s", ctx.OtherModuleName(to), ctx.GetPathString(false))
  2319. return false
  2320. }
  2321. if module, ok := ctx.Module().(*Module); ok {
  2322. if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
  2323. if lib.hasLLNDKStubs() {
  2324. ctx.WalkDeps(check)
  2325. }
  2326. }
  2327. }
  2328. }
  2329. // Convert dependencies to paths. Returns a PathDeps containing paths
  2330. func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
  2331. var depPaths PathDeps
  2332. var directStaticDeps []StaticLibraryInfo
  2333. var directSharedDeps []SharedLibraryInfo
  2334. reexportExporter := func(exporter FlagExporterInfo) {
  2335. depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.IncludeDirs...)
  2336. depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.SystemIncludeDirs...)
  2337. depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.Flags...)
  2338. depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.Deps...)
  2339. depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.GeneratedHeaders...)
  2340. }
  2341. // For the dependency from platform to apex, use the latest stubs
  2342. c.apexSdkVersion = android.FutureApiLevel
  2343. apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
  2344. if !apexInfo.IsForPlatform() {
  2345. c.apexSdkVersion = apexInfo.MinSdkVersion
  2346. }
  2347. if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
  2348. // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
  2349. // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
  2350. // (b/144430859)
  2351. c.apexSdkVersion = android.FutureApiLevel
  2352. }
  2353. ctx.VisitDirectDeps(func(dep android.Module) {
  2354. depName := ctx.OtherModuleName(dep)
  2355. depTag := ctx.OtherModuleDependencyTag(dep)
  2356. if depTag == android.DarwinUniversalVariantTag {
  2357. depPaths.DarwinSecondArchOutput = dep.(*Module).OutputFile()
  2358. return
  2359. }
  2360. ccDep, ok := dep.(LinkableInterface)
  2361. if !ok {
  2362. // handling for a few module types that aren't cc Module but that are also supported
  2363. switch depTag {
  2364. case genSourceDepTag:
  2365. if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
  2366. depPaths.GeneratedSources = append(depPaths.GeneratedSources,
  2367. genRule.GeneratedSourceFiles()...)
  2368. } else {
  2369. ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
  2370. }
  2371. // Support exported headers from a generated_sources dependency
  2372. fallthrough
  2373. case genHeaderDepTag, genHeaderExportDepTag:
  2374. if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
  2375. depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
  2376. genRule.GeneratedDeps()...)
  2377. dirs := genRule.GeneratedHeaderDirs()
  2378. depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
  2379. if depTag == genHeaderExportDepTag {
  2380. depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
  2381. depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
  2382. genRule.GeneratedSourceFiles()...)
  2383. depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
  2384. // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
  2385. c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
  2386. }
  2387. } else {
  2388. ctx.ModuleErrorf("module %q is not a genrule", depName)
  2389. }
  2390. case CrtBeginDepTag:
  2391. depPaths.CrtBegin = append(depPaths.CrtBegin, android.OutputFileForModule(ctx, dep, ""))
  2392. case CrtEndDepTag:
  2393. depPaths.CrtEnd = append(depPaths.CrtEnd, android.OutputFileForModule(ctx, dep, ""))
  2394. }
  2395. return
  2396. }
  2397. if depTag == android.ProtoPluginDepTag {
  2398. return
  2399. }
  2400. if dep.Target().Os != ctx.Os() {
  2401. ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
  2402. return
  2403. }
  2404. if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
  2405. ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
  2406. ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
  2407. return
  2408. }
  2409. if depTag == reuseObjTag {
  2410. // Skip reused objects for stub libraries, they use their own stub object file instead.
  2411. // The reuseObjTag dependency still exists because the LinkageMutator runs before the
  2412. // version mutator, so the stubs variant is created from the shared variant that
  2413. // already has the reuseObjTag dependency on the static variant.
  2414. if !c.library.buildStubs() {
  2415. staticAnalogue := ctx.OtherModuleProvider(dep, StaticLibraryInfoProvider).(StaticLibraryInfo)
  2416. objs := staticAnalogue.ReuseObjects
  2417. depPaths.Objs = depPaths.Objs.Append(objs)
  2418. depExporterInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
  2419. reexportExporter(depExporterInfo)
  2420. }
  2421. return
  2422. }
  2423. linkFile := ccDep.OutputFile()
  2424. if libDepTag, ok := depTag.(libraryDependencyTag); ok {
  2425. // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
  2426. if libDepTag.staticUnwinder && c.apexSdkVersion.GreaterThan(android.SdkVersion_Android10) {
  2427. return
  2428. }
  2429. if !apexInfo.IsForPlatform() && libDepTag.excludeInApex {
  2430. return
  2431. }
  2432. depExporterInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
  2433. var ptr *android.Paths
  2434. var depPtr *android.Paths
  2435. depFile := android.OptionalPath{}
  2436. switch {
  2437. case libDepTag.header():
  2438. if !ctx.OtherModuleHasProvider(dep, HeaderLibraryInfoProvider) {
  2439. if !ctx.Config().AllowMissingDependencies() {
  2440. ctx.ModuleErrorf("module %q is not a header library", depName)
  2441. } else {
  2442. ctx.AddMissingDependencies([]string{depName})
  2443. }
  2444. return
  2445. }
  2446. case libDepTag.shared():
  2447. if !ctx.OtherModuleHasProvider(dep, SharedLibraryInfoProvider) {
  2448. if !ctx.Config().AllowMissingDependencies() {
  2449. ctx.ModuleErrorf("module %q is not a shared library", depName)
  2450. } else {
  2451. ctx.AddMissingDependencies([]string{depName})
  2452. }
  2453. return
  2454. }
  2455. sharedLibraryInfo, returnedDepExporterInfo := ChooseStubOrImpl(ctx, dep)
  2456. depExporterInfo = returnedDepExporterInfo
  2457. // Stubs lib doesn't link to the shared lib dependencies. Don't set
  2458. // linkFile, depFile, and ptr.
  2459. if c.IsStubs() {
  2460. break
  2461. }
  2462. linkFile = android.OptionalPathForPath(sharedLibraryInfo.SharedLibrary)
  2463. depFile = sharedLibraryInfo.TableOfContents
  2464. ptr = &depPaths.SharedLibs
  2465. switch libDepTag.Order {
  2466. case earlyLibraryDependency:
  2467. ptr = &depPaths.EarlySharedLibs
  2468. depPtr = &depPaths.EarlySharedLibsDeps
  2469. case normalLibraryDependency:
  2470. ptr = &depPaths.SharedLibs
  2471. depPtr = &depPaths.SharedLibsDeps
  2472. directSharedDeps = append(directSharedDeps, sharedLibraryInfo)
  2473. case lateLibraryDependency:
  2474. ptr = &depPaths.LateSharedLibs
  2475. depPtr = &depPaths.LateSharedLibsDeps
  2476. default:
  2477. panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
  2478. }
  2479. case libDepTag.static():
  2480. if !ctx.OtherModuleHasProvider(dep, StaticLibraryInfoProvider) {
  2481. if !ctx.Config().AllowMissingDependencies() {
  2482. ctx.ModuleErrorf("module %q is not a static library", depName)
  2483. } else {
  2484. ctx.AddMissingDependencies([]string{depName})
  2485. }
  2486. return
  2487. }
  2488. // Stubs lib doesn't link to the static lib dependencies. Don't set
  2489. // linkFile, depFile, and ptr.
  2490. if c.IsStubs() {
  2491. break
  2492. }
  2493. staticLibraryInfo := ctx.OtherModuleProvider(dep, StaticLibraryInfoProvider).(StaticLibraryInfo)
  2494. linkFile = android.OptionalPathForPath(staticLibraryInfo.StaticLibrary)
  2495. if libDepTag.wholeStatic {
  2496. ptr = &depPaths.WholeStaticLibs
  2497. if len(staticLibraryInfo.Objects.objFiles) > 0 {
  2498. depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLibraryInfo.Objects)
  2499. } else {
  2500. // This case normally catches prebuilt static
  2501. // libraries, but it can also occur when
  2502. // AllowMissingDependencies is on and the
  2503. // dependencies has no sources of its own
  2504. // but has a whole_static_libs dependency
  2505. // on a missing library. We want to depend
  2506. // on the .a file so that there is something
  2507. // in the dependency tree that contains the
  2508. // error rule for the missing transitive
  2509. // dependency.
  2510. depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
  2511. }
  2512. depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts,
  2513. staticLibraryInfo.WholeStaticLibsFromPrebuilts...)
  2514. } else {
  2515. switch libDepTag.Order {
  2516. case earlyLibraryDependency:
  2517. panic(fmt.Errorf("early static libs not suppported"))
  2518. case normalLibraryDependency:
  2519. // static dependencies will be handled separately so they can be ordered
  2520. // using transitive dependencies.
  2521. ptr = nil
  2522. directStaticDeps = append(directStaticDeps, staticLibraryInfo)
  2523. case lateLibraryDependency:
  2524. ptr = &depPaths.LateStaticLibs
  2525. default:
  2526. panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
  2527. }
  2528. }
  2529. if libDepTag.unexportedSymbols {
  2530. depPaths.LdFlags = append(depPaths.LdFlags,
  2531. "-Wl,--exclude-libs="+staticLibraryInfo.StaticLibrary.Base())
  2532. }
  2533. }
  2534. if libDepTag.static() && !libDepTag.wholeStatic {
  2535. if !ccDep.CcLibraryInterface() || !ccDep.Static() {
  2536. ctx.ModuleErrorf("module %q not a static library", depName)
  2537. return
  2538. }
  2539. // When combining coverage files for shared libraries and executables, coverage files
  2540. // in static libraries act as if they were whole static libraries. The same goes for
  2541. // source based Abi dump files.
  2542. if c, ok := ccDep.(*Module); ok {
  2543. staticLib := c.linker.(libraryInterface)
  2544. depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
  2545. staticLib.objs().coverageFiles...)
  2546. depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
  2547. staticLib.objs().sAbiDumpFiles...)
  2548. } else {
  2549. // Handle non-CC modules here
  2550. depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
  2551. ccDep.CoverageFiles()...)
  2552. }
  2553. }
  2554. if ptr != nil {
  2555. if !linkFile.Valid() {
  2556. if !ctx.Config().AllowMissingDependencies() {
  2557. ctx.ModuleErrorf("module %q missing output file", depName)
  2558. } else {
  2559. ctx.AddMissingDependencies([]string{depName})
  2560. }
  2561. return
  2562. }
  2563. *ptr = append(*ptr, linkFile.Path())
  2564. }
  2565. if depPtr != nil {
  2566. dep := depFile
  2567. if !dep.Valid() {
  2568. dep = linkFile
  2569. }
  2570. *depPtr = append(*depPtr, dep.Path())
  2571. }
  2572. depPaths.IncludeDirs = append(depPaths.IncludeDirs, depExporterInfo.IncludeDirs...)
  2573. depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, depExporterInfo.SystemIncludeDirs...)
  2574. depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, depExporterInfo.Deps...)
  2575. depPaths.Flags = append(depPaths.Flags, depExporterInfo.Flags...)
  2576. if libDepTag.reexportFlags {
  2577. reexportExporter(depExporterInfo)
  2578. // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
  2579. // Re-exported shared library headers must be included as well since they can help us with type information
  2580. // about template instantiations (instantiated from their headers).
  2581. // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
  2582. // scripts.
  2583. c.sabi.Properties.ReexportedIncludes = append(
  2584. c.sabi.Properties.ReexportedIncludes, depExporterInfo.IncludeDirs.Strings()...)
  2585. }
  2586. makeLibName := MakeLibName(ctx, c, ccDep, depName) + libDepTag.makeSuffix
  2587. switch {
  2588. case libDepTag.header():
  2589. c.Properties.AndroidMkHeaderLibs = append(
  2590. c.Properties.AndroidMkHeaderLibs, makeLibName)
  2591. case libDepTag.shared():
  2592. if lib := moduleLibraryInterface(dep); lib != nil {
  2593. if lib.buildStubs() && dep.(android.ApexModule).InAnyApex() {
  2594. // Add the dependency to the APEX(es) providing the library so that
  2595. // m <module> can trigger building the APEXes as well.
  2596. depApexInfo := ctx.OtherModuleProvider(dep, android.ApexInfoProvider).(android.ApexInfo)
  2597. for _, an := range depApexInfo.InApexVariants {
  2598. c.Properties.ApexesProvidingSharedLibs = append(
  2599. c.Properties.ApexesProvidingSharedLibs, an)
  2600. }
  2601. }
  2602. }
  2603. // Note: the order of libs in this list is not important because
  2604. // they merely serve as Make dependencies and do not affect this lib itself.
  2605. c.Properties.AndroidMkSharedLibs = append(
  2606. c.Properties.AndroidMkSharedLibs, makeLibName)
  2607. // Record BaseLibName for snapshots.
  2608. c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, BaseLibName(depName))
  2609. case libDepTag.static():
  2610. if libDepTag.wholeStatic {
  2611. c.Properties.AndroidMkWholeStaticLibs = append(
  2612. c.Properties.AndroidMkWholeStaticLibs, makeLibName)
  2613. } else {
  2614. c.Properties.AndroidMkStaticLibs = append(
  2615. c.Properties.AndroidMkStaticLibs, makeLibName)
  2616. }
  2617. // Record BaseLibName for snapshots.
  2618. c.Properties.SnapshotStaticLibs = append(c.Properties.SnapshotStaticLibs, BaseLibName(depName))
  2619. }
  2620. } else if !c.IsStubs() {
  2621. // Stubs lib doesn't link to the runtime lib, object, crt, etc. dependencies.
  2622. switch depTag {
  2623. case runtimeDepTag:
  2624. c.Properties.AndroidMkRuntimeLibs = append(
  2625. c.Properties.AndroidMkRuntimeLibs, MakeLibName(ctx, c, ccDep, depName)+libDepTag.makeSuffix)
  2626. // Record BaseLibName for snapshots.
  2627. c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, BaseLibName(depName))
  2628. case objDepTag:
  2629. depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
  2630. case CrtBeginDepTag:
  2631. depPaths.CrtBegin = append(depPaths.CrtBegin, linkFile.Path())
  2632. case CrtEndDepTag:
  2633. depPaths.CrtEnd = append(depPaths.CrtEnd, linkFile.Path())
  2634. case dynamicLinkerDepTag:
  2635. depPaths.DynamicLinker = linkFile
  2636. }
  2637. }
  2638. })
  2639. // use the ordered dependencies as this module's dependencies
  2640. orderedStaticPaths, transitiveStaticLibs := orderStaticModuleDeps(directStaticDeps, directSharedDeps)
  2641. depPaths.TranstiveStaticLibrariesForOrdering = transitiveStaticLibs
  2642. depPaths.StaticLibs = append(depPaths.StaticLibs, orderedStaticPaths...)
  2643. // Dedup exported flags from dependencies
  2644. depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
  2645. depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
  2646. depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
  2647. depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
  2648. depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
  2649. depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
  2650. depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
  2651. depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
  2652. depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
  2653. if c.sabi != nil {
  2654. c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
  2655. }
  2656. return depPaths
  2657. }
  2658. // ChooseStubOrImpl determines whether a given dependency should be redirected to the stub variant
  2659. // of the dependency or not, and returns the SharedLibraryInfo and FlagExporterInfo for the right
  2660. // dependency. The stub variant is selected when the dependency crosses a boundary where each side
  2661. // has different level of updatability. For example, if a library foo in an APEX depends on a
  2662. // library bar which provides stable interface and exists in the platform, foo uses the stub variant
  2663. // of bar. If bar doesn't provide a stable interface (i.e. buildStubs() == false) or is in the
  2664. // same APEX as foo, the non-stub variant of bar is used.
  2665. func ChooseStubOrImpl(ctx android.ModuleContext, dep android.Module) (SharedLibraryInfo, FlagExporterInfo) {
  2666. depName := ctx.OtherModuleName(dep)
  2667. depTag := ctx.OtherModuleDependencyTag(dep)
  2668. libDepTag, ok := depTag.(libraryDependencyTag)
  2669. if !ok || !libDepTag.shared() {
  2670. panic(fmt.Errorf("Unexpected dependency tag: %T", depTag))
  2671. }
  2672. thisModule, ok := ctx.Module().(android.ApexModule)
  2673. if !ok {
  2674. panic(fmt.Errorf("Not an APEX module: %q", ctx.ModuleName()))
  2675. }
  2676. useVndk := false
  2677. bootstrap := false
  2678. if linkable, ok := ctx.Module().(LinkableInterface); !ok {
  2679. panic(fmt.Errorf("Not a Linkable module: %q", ctx.ModuleName()))
  2680. } else {
  2681. useVndk = linkable.UseVndk()
  2682. bootstrap = linkable.Bootstrap()
  2683. }
  2684. sharedLibraryInfo := ctx.OtherModuleProvider(dep, SharedLibraryInfoProvider).(SharedLibraryInfo)
  2685. depExporterInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
  2686. sharedLibraryStubsInfo := ctx.OtherModuleProvider(dep, SharedLibraryStubsProvider).(SharedLibraryStubsInfo)
  2687. apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
  2688. if !libDepTag.explicitlyVersioned && len(sharedLibraryStubsInfo.SharedStubLibraries) > 0 {
  2689. useStubs := false
  2690. if lib := moduleLibraryInterface(dep); lib.buildStubs() && useVndk { // LLNDK
  2691. if !apexInfo.IsForPlatform() {
  2692. // For platform libraries, use current version of LLNDK
  2693. // If this is for use_vendor apex we will apply the same rules
  2694. // of apex sdk enforcement below to choose right version.
  2695. useStubs = true
  2696. }
  2697. } else if apexInfo.IsForPlatform() || apexInfo.UsePlatformApis {
  2698. // If not building for APEX or the containing APEX allows the use of
  2699. // platform APIs, use stubs only when it is from an APEX (and not from
  2700. // platform) However, for host, ramdisk, vendor_ramdisk, recovery or
  2701. // bootstrap modules, always link to non-stub variant
  2702. useStubs = dep.(android.ApexModule).NotInPlatform() && !bootstrap
  2703. if useStubs {
  2704. // Another exception: if this module is a test for an APEX, then
  2705. // it is linked with the non-stub variant of a module in the APEX
  2706. // as if this is part of the APEX.
  2707. testFor := ctx.Provider(android.ApexTestForInfoProvider).(android.ApexTestForInfo)
  2708. for _, apexContents := range testFor.ApexContents {
  2709. if apexContents.DirectlyInApex(depName) {
  2710. useStubs = false
  2711. break
  2712. }
  2713. }
  2714. }
  2715. if useStubs {
  2716. // Yet another exception: If this module and the dependency are
  2717. // available to the same APEXes then skip stubs between their
  2718. // platform variants. This complements the test_for case above,
  2719. // which avoids the stubs on a direct APEX library dependency, by
  2720. // avoiding stubs for indirect test dependencies as well.
  2721. //
  2722. // TODO(b/183882457): This doesn't work if the two libraries have
  2723. // only partially overlapping apex_available. For that test_for
  2724. // modules would need to be split into APEX variants and resolved
  2725. // separately for each APEX they have access to.
  2726. if android.AvailableToSameApexes(thisModule, dep.(android.ApexModule)) {
  2727. useStubs = false
  2728. }
  2729. }
  2730. } else {
  2731. // If building for APEX, use stubs when the parent is in any APEX that
  2732. // the child is not in.
  2733. useStubs = !android.DirectlyInAllApexes(apexInfo, depName)
  2734. }
  2735. // when to use (unspecified) stubs, use the latest one.
  2736. if useStubs {
  2737. stubs := sharedLibraryStubsInfo.SharedStubLibraries
  2738. toUse := stubs[len(stubs)-1]
  2739. sharedLibraryInfo = toUse.SharedLibraryInfo
  2740. depExporterInfo = toUse.FlagExporterInfo
  2741. }
  2742. }
  2743. return sharedLibraryInfo, depExporterInfo
  2744. }
  2745. // orderStaticModuleDeps rearranges the order of the static library dependencies of the module
  2746. // to match the topological order of the dependency tree, including any static analogues of
  2747. // direct shared libraries. It returns the ordered static dependencies, and an android.DepSet
  2748. // of the transitive dependencies.
  2749. func orderStaticModuleDeps(staticDeps []StaticLibraryInfo, sharedDeps []SharedLibraryInfo) (ordered android.Paths, transitive *android.DepSet) {
  2750. transitiveStaticLibsBuilder := android.NewDepSetBuilder(android.TOPOLOGICAL)
  2751. var staticPaths android.Paths
  2752. for _, staticDep := range staticDeps {
  2753. staticPaths = append(staticPaths, staticDep.StaticLibrary)
  2754. transitiveStaticLibsBuilder.Transitive(staticDep.TransitiveStaticLibrariesForOrdering)
  2755. }
  2756. for _, sharedDep := range sharedDeps {
  2757. if sharedDep.TransitiveStaticLibrariesForOrdering != nil {
  2758. transitiveStaticLibsBuilder.Transitive(sharedDep.TransitiveStaticLibrariesForOrdering)
  2759. }
  2760. }
  2761. transitiveStaticLibs := transitiveStaticLibsBuilder.Build()
  2762. orderedTransitiveStaticLibs := transitiveStaticLibs.ToList()
  2763. // reorder the dependencies based on transitive dependencies
  2764. staticPaths = android.FirstUniquePaths(staticPaths)
  2765. _, orderedStaticPaths := android.FilterPathList(orderedTransitiveStaticLibs, staticPaths)
  2766. if len(orderedStaticPaths) != len(staticPaths) {
  2767. missing, _ := android.FilterPathList(staticPaths, orderedStaticPaths)
  2768. panic(fmt.Errorf("expected %d ordered static paths , got %d, missing %q %q %q", len(staticPaths), len(orderedStaticPaths), missing, orderedStaticPaths, staticPaths))
  2769. }
  2770. return orderedStaticPaths, transitiveStaticLibs
  2771. }
  2772. // BaseLibName trims known prefixes and suffixes
  2773. func BaseLibName(depName string) string {
  2774. libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
  2775. libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
  2776. libName = android.RemoveOptionalPrebuiltPrefix(libName)
  2777. return libName
  2778. }
  2779. func MakeLibName(ctx android.ModuleContext, c LinkableInterface, ccDep LinkableInterface, depName string) string {
  2780. libName := BaseLibName(depName)
  2781. ccDepModule, _ := ccDep.(*Module)
  2782. isLLndk := ccDepModule != nil && ccDepModule.IsLlndk()
  2783. nonSystemVariantsExist := ccDep.HasNonSystemVariants() || isLLndk
  2784. if ccDepModule != nil {
  2785. // TODO(ivanlozano) Support snapshots for Rust-produced C library variants.
  2786. // Use base module name for snapshots when exporting to Makefile.
  2787. if snapshotPrebuilt, ok := ccDepModule.linker.(SnapshotInterface); ok {
  2788. baseName := ccDepModule.BaseModuleName()
  2789. return baseName + snapshotPrebuilt.SnapshotAndroidMkSuffix()
  2790. }
  2791. }
  2792. if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() &&
  2793. !c.InRamdisk() && !c.InVendorRamdisk() && !c.InRecovery() {
  2794. // The vendor module is a no-vendor-variant VNDK library. Depend on the
  2795. // core module instead.
  2796. return libName
  2797. } else if ccDep.UseVndk() && nonSystemVariantsExist {
  2798. // The vendor and product modules in Make will have been renamed to not conflict with the
  2799. // core module, so update the dependency name here accordingly.
  2800. return libName + ccDep.SubName()
  2801. } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
  2802. return libName + RamdiskSuffix
  2803. } else if ccDep.InVendorRamdisk() && !ccDep.OnlyInVendorRamdisk() {
  2804. return libName + VendorRamdiskSuffix
  2805. } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
  2806. return libName + RecoverySuffix
  2807. } else if ccDep.Target().NativeBridge == android.NativeBridgeEnabled {
  2808. return libName + NativeBridgeSuffix
  2809. } else {
  2810. return libName
  2811. }
  2812. }
  2813. func (c *Module) InstallInData() bool {
  2814. if c.installer == nil {
  2815. return false
  2816. }
  2817. return c.installer.inData()
  2818. }
  2819. func (c *Module) InstallInSanitizerDir() bool {
  2820. if c.installer == nil {
  2821. return false
  2822. }
  2823. if c.sanitize != nil && c.sanitize.inSanitizerDir() {
  2824. return true
  2825. }
  2826. return c.installer.inSanitizerDir()
  2827. }
  2828. func (c *Module) InstallInRamdisk() bool {
  2829. return c.InRamdisk()
  2830. }
  2831. func (c *Module) InstallInVendorRamdisk() bool {
  2832. return c.InVendorRamdisk()
  2833. }
  2834. func (c *Module) InstallInRecovery() bool {
  2835. return c.InRecovery()
  2836. }
  2837. func (c *Module) MakeUninstallable() {
  2838. if c.installer == nil {
  2839. c.ModuleBase.MakeUninstallable()
  2840. return
  2841. }
  2842. c.installer.makeUninstallable(c)
  2843. }
  2844. func (c *Module) HostToolPath() android.OptionalPath {
  2845. if c.installer == nil {
  2846. return android.OptionalPath{}
  2847. }
  2848. return c.installer.hostToolPath()
  2849. }
  2850. func (c *Module) IntermPathForModuleOut() android.OptionalPath {
  2851. return c.outputFile
  2852. }
  2853. func (c *Module) OutputFiles(tag string) (android.Paths, error) {
  2854. switch tag {
  2855. case "":
  2856. if c.outputFile.Valid() {
  2857. return android.Paths{c.outputFile.Path()}, nil
  2858. }
  2859. return android.Paths{}, nil
  2860. default:
  2861. return nil, fmt.Errorf("unsupported module reference tag %q", tag)
  2862. }
  2863. }
  2864. func (c *Module) static() bool {
  2865. if static, ok := c.linker.(interface {
  2866. static() bool
  2867. }); ok {
  2868. return static.static()
  2869. }
  2870. return false
  2871. }
  2872. func (c *Module) staticBinary() bool {
  2873. if static, ok := c.linker.(interface {
  2874. staticBinary() bool
  2875. }); ok {
  2876. return static.staticBinary()
  2877. }
  2878. return false
  2879. }
  2880. func (c *Module) testBinary() bool {
  2881. if test, ok := c.linker.(interface {
  2882. testBinary() bool
  2883. }); ok {
  2884. return test.testBinary()
  2885. }
  2886. return false
  2887. }
  2888. func (c *Module) testLibrary() bool {
  2889. if test, ok := c.linker.(interface {
  2890. testLibrary() bool
  2891. }); ok {
  2892. return test.testLibrary()
  2893. }
  2894. return false
  2895. }
  2896. func (c *Module) benchmarkBinary() bool {
  2897. if b, ok := c.linker.(interface {
  2898. benchmarkBinary() bool
  2899. }); ok {
  2900. return b.benchmarkBinary()
  2901. }
  2902. return false
  2903. }
  2904. func (c *Module) fuzzBinary() bool {
  2905. if f, ok := c.linker.(interface {
  2906. fuzzBinary() bool
  2907. }); ok {
  2908. return f.fuzzBinary()
  2909. }
  2910. return false
  2911. }
  2912. // Header returns true if the module is a header-only variant. (See cc/library.go header()).
  2913. func (c *Module) Header() bool {
  2914. if h, ok := c.linker.(interface {
  2915. header() bool
  2916. }); ok {
  2917. return h.header()
  2918. }
  2919. return false
  2920. }
  2921. func (c *Module) Binary() bool {
  2922. if b, ok := c.linker.(interface {
  2923. binary() bool
  2924. }); ok {
  2925. return b.binary()
  2926. }
  2927. return false
  2928. }
  2929. func (c *Module) StaticExecutable() bool {
  2930. if b, ok := c.linker.(*binaryDecorator); ok {
  2931. return b.static()
  2932. }
  2933. return false
  2934. }
  2935. func (c *Module) Object() bool {
  2936. if o, ok := c.linker.(interface {
  2937. object() bool
  2938. }); ok {
  2939. return o.object()
  2940. }
  2941. return false
  2942. }
  2943. func GetMakeLinkType(actx android.ModuleContext, c LinkableInterface) string {
  2944. if c.UseVndk() {
  2945. if c.IsLlndk() {
  2946. if !c.IsLlndkPublic() {
  2947. return "native:vndk_private"
  2948. }
  2949. return "native:vndk"
  2950. }
  2951. if c.IsVndk() && !c.IsVndkExt() {
  2952. if c.IsVndkPrivate() {
  2953. return "native:vndk_private"
  2954. }
  2955. return "native:vndk"
  2956. }
  2957. if c.InProduct() {
  2958. return "native:product"
  2959. }
  2960. return "native:vendor"
  2961. } else if c.InRamdisk() {
  2962. return "native:ramdisk"
  2963. } else if c.InVendorRamdisk() {
  2964. return "native:vendor_ramdisk"
  2965. } else if c.InRecovery() {
  2966. return "native:recovery"
  2967. } else if c.Target().Os == android.Android && c.SdkVersion() != "" {
  2968. return "native:ndk:none:none"
  2969. // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
  2970. //family, link := getNdkStlFamilyAndLinkType(c)
  2971. //return fmt.Sprintf("native:ndk:%s:%s", family, link)
  2972. } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
  2973. return "native:platform_vndk"
  2974. } else {
  2975. return "native:platform"
  2976. }
  2977. }
  2978. // Overrides ApexModule.IsInstallabeToApex()
  2979. // Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
  2980. func (c *Module) IsInstallableToApex() bool {
  2981. if lib := c.library; lib != nil {
  2982. // Stub libs and prebuilt libs in a versioned SDK are not
  2983. // installable to APEX even though they are shared libs.
  2984. return lib.shared() && !lib.buildStubs() && c.ContainingSdk().Unversioned()
  2985. } else if _, ok := c.linker.(testPerSrc); ok {
  2986. return true
  2987. }
  2988. return false
  2989. }
  2990. func (c *Module) AvailableFor(what string) bool {
  2991. if linker, ok := c.linker.(interface {
  2992. availableFor(string) bool
  2993. }); ok {
  2994. return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
  2995. } else {
  2996. return c.ApexModuleBase.AvailableFor(what)
  2997. }
  2998. }
  2999. func (c *Module) TestFor() []string {
  3000. return c.Properties.Test_for
  3001. }
  3002. func (c *Module) EverInstallable() bool {
  3003. return c.installer != nil &&
  3004. // Check to see whether the module is actually ever installable.
  3005. c.installer.everInstallable()
  3006. }
  3007. func (c *Module) PreventInstall() bool {
  3008. return c.Properties.PreventInstall
  3009. }
  3010. func (c *Module) Installable() *bool {
  3011. if c.library != nil {
  3012. if i := c.library.installable(); i != nil {
  3013. return i
  3014. }
  3015. }
  3016. return c.Properties.Installable
  3017. }
  3018. func installable(c LinkableInterface, apexInfo android.ApexInfo) bool {
  3019. ret := c.EverInstallable() &&
  3020. // Check to see whether the module has been configured to not be installed.
  3021. proptools.BoolDefault(c.Installable(), true) &&
  3022. !c.PreventInstall() && c.OutputFile().Valid()
  3023. // The platform variant doesn't need further condition. Apex variants however might not
  3024. // be installable because it will likely to be included in the APEX and won't appear
  3025. // in the system partition.
  3026. if apexInfo.IsForPlatform() {
  3027. return ret
  3028. }
  3029. // Special case for modules that are configured to be installed to /data, which includes
  3030. // test modules. For these modules, both APEX and non-APEX variants are considered as
  3031. // installable. This is because even the APEX variants won't be included in the APEX, but
  3032. // will anyway be installed to /data/*.
  3033. // See b/146995717
  3034. if c.InstallInData() {
  3035. return ret
  3036. }
  3037. return false
  3038. }
  3039. func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
  3040. if c.linker != nil {
  3041. if library, ok := c.linker.(*libraryDecorator); ok {
  3042. library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
  3043. }
  3044. }
  3045. }
  3046. var _ android.ApexModule = (*Module)(nil)
  3047. // Implements android.ApexModule
  3048. func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
  3049. depTag := ctx.OtherModuleDependencyTag(dep)
  3050. libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
  3051. if cc, ok := dep.(*Module); ok {
  3052. if cc.HasStubsVariants() {
  3053. if isLibDepTag && libDepTag.shared() {
  3054. // dynamic dep to a stubs lib crosses APEX boundary
  3055. return false
  3056. }
  3057. if IsRuntimeDepTag(depTag) {
  3058. // runtime dep to a stubs lib also crosses APEX boundary
  3059. return false
  3060. }
  3061. }
  3062. if cc.IsLlndk() {
  3063. return false
  3064. }
  3065. if isLibDepTag && c.static() && libDepTag.shared() {
  3066. // shared_lib dependency from a static lib is considered as crossing
  3067. // the APEX boundary because the dependency doesn't actually is
  3068. // linked; the dependency is used only during the compilation phase.
  3069. return false
  3070. }
  3071. if isLibDepTag && libDepTag.excludeInApex {
  3072. return false
  3073. }
  3074. }
  3075. if depTag == stubImplDepTag {
  3076. // We don't track from an implementation library to its stubs.
  3077. return false
  3078. }
  3079. if depTag == staticVariantTag {
  3080. // This dependency is for optimization (reuse *.o from the static lib). It doesn't
  3081. // actually mean that the static lib (and its dependencies) are copied into the
  3082. // APEX.
  3083. return false
  3084. }
  3085. return true
  3086. }
  3087. // Implements android.ApexModule
  3088. func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
  3089. sdkVersion android.ApiLevel) error {
  3090. // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
  3091. if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
  3092. return nil
  3093. }
  3094. // We don't check for prebuilt modules
  3095. if _, ok := c.linker.(prebuiltLinkerInterface); ok {
  3096. return nil
  3097. }
  3098. minSdkVersion := c.MinSdkVersion()
  3099. if minSdkVersion == "apex_inherit" {
  3100. return nil
  3101. }
  3102. if minSdkVersion == "" {
  3103. // JNI libs within APK-in-APEX fall into here
  3104. // Those are okay to set sdk_version instead
  3105. // We don't have to check if this is a SDK variant because
  3106. // non-SDK variant resets sdk_version, which works too.
  3107. minSdkVersion = c.SdkVersion()
  3108. }
  3109. if minSdkVersion == "" {
  3110. return fmt.Errorf("neither min_sdk_version nor sdk_version specificed")
  3111. }
  3112. // Not using nativeApiLevelFromUser because the context here is not
  3113. // necessarily a native context.
  3114. ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
  3115. if err != nil {
  3116. return err
  3117. }
  3118. if ver.GreaterThan(sdkVersion) {
  3119. return fmt.Errorf("newer SDK(%v)", ver)
  3120. }
  3121. return nil
  3122. }
  3123. // Implements android.ApexModule
  3124. func (c *Module) AlwaysRequiresPlatformApexVariant() bool {
  3125. // stub libraries and native bridge libraries are always available to platform
  3126. return c.IsStubs() || c.Target().NativeBridge == android.NativeBridgeEnabled
  3127. }
  3128. // Overrides android.ApexModuleBase.UniqueApexVariations
  3129. func (c *Module) UniqueApexVariations() bool {
  3130. // When a vendor APEX needs a VNDK lib in it (use_vndk_as_stable: false), it should be a unique
  3131. // APEX variation. Otherwise, another vendor APEX with use_vndk_as_stable:true may use a wrong
  3132. // variation of the VNDK lib because APEX variations are merged/grouped.
  3133. return c.UseVndk() && c.IsVndk()
  3134. }
  3135. var _ snapshot.RelativeInstallPath = (*Module)(nil)
  3136. type moduleType int
  3137. const (
  3138. unknownType moduleType = iota
  3139. binary
  3140. object
  3141. fullLibrary
  3142. staticLibrary
  3143. sharedLibrary
  3144. headerLibrary
  3145. testBin // testBinary already declared
  3146. ndkLibrary
  3147. )
  3148. func (c *Module) typ() moduleType {
  3149. if c.testBinary() {
  3150. // testBinary is also a binary, so this comes before the c.Binary()
  3151. // conditional. A testBinary has additional implicit dependencies and
  3152. // other test-only semantics.
  3153. return testBin
  3154. } else if c.Binary() {
  3155. return binary
  3156. } else if c.Object() {
  3157. return object
  3158. } else if c.testLibrary() {
  3159. // TODO(b/244431896) properly convert cc_test_library to its own macro. This
  3160. // will let them add implicit compile deps on gtest, for example.
  3161. //
  3162. // For now, treat them as regular shared libraries.
  3163. return sharedLibrary
  3164. } else if c.CcLibrary() {
  3165. static := false
  3166. shared := false
  3167. if library, ok := c.linker.(*libraryDecorator); ok {
  3168. static = library.MutatedProperties.BuildStatic
  3169. shared = library.MutatedProperties.BuildShared
  3170. } else if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
  3171. static = library.MutatedProperties.BuildStatic
  3172. shared = library.MutatedProperties.BuildShared
  3173. }
  3174. if static && shared {
  3175. return fullLibrary
  3176. } else if !static && !shared {
  3177. return headerLibrary
  3178. } else if static {
  3179. return staticLibrary
  3180. }
  3181. return sharedLibrary
  3182. } else if c.isNDKStubLibrary() {
  3183. return ndkLibrary
  3184. }
  3185. return unknownType
  3186. }
  3187. // ConvertWithBp2build converts Module to Bazel for bp2build.
  3188. func (c *Module) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
  3189. prebuilt := c.IsPrebuilt()
  3190. switch c.typ() {
  3191. case binary:
  3192. if !prebuilt {
  3193. binaryBp2build(ctx, c)
  3194. }
  3195. case testBin:
  3196. if !prebuilt {
  3197. testBinaryBp2build(ctx, c)
  3198. }
  3199. case object:
  3200. if !prebuilt {
  3201. objectBp2Build(ctx, c)
  3202. }
  3203. case fullLibrary:
  3204. if !prebuilt {
  3205. libraryBp2Build(ctx, c)
  3206. } else {
  3207. prebuiltLibraryBp2Build(ctx, c)
  3208. }
  3209. case headerLibrary:
  3210. libraryHeadersBp2Build(ctx, c)
  3211. case staticLibrary:
  3212. if prebuilt {
  3213. prebuiltLibraryStaticBp2Build(ctx, c, false)
  3214. } else {
  3215. sharedOrStaticLibraryBp2Build(ctx, c, true)
  3216. }
  3217. case sharedLibrary:
  3218. if prebuilt {
  3219. prebuiltLibrarySharedBp2Build(ctx, c)
  3220. } else {
  3221. sharedOrStaticLibraryBp2Build(ctx, c, false)
  3222. }
  3223. }
  3224. }
  3225. var _ android.ApiProvider = (*Module)(nil)
  3226. func (c *Module) ConvertWithApiBp2build(ctx android.TopDownMutatorContext) {
  3227. switch c.typ() {
  3228. case ndkLibrary:
  3229. ndkLibraryBp2build(ctx, c)
  3230. }
  3231. }
  3232. // Defaults
  3233. type Defaults struct {
  3234. android.ModuleBase
  3235. android.DefaultsModuleBase
  3236. android.ApexModuleBase
  3237. }
  3238. // cc_defaults provides a set of properties that can be inherited by other cc
  3239. // modules. A module can use the properties from a cc_defaults using
  3240. // `defaults: ["<:default_module_name>"]`. Properties of both modules are
  3241. // merged (when possible) by prepending the default module's values to the
  3242. // depending module's values.
  3243. func defaultsFactory() android.Module {
  3244. return DefaultsFactory()
  3245. }
  3246. func DefaultsFactory(props ...interface{}) android.Module {
  3247. module := &Defaults{}
  3248. module.AddProperties(props...)
  3249. module.AddProperties(
  3250. &BaseProperties{},
  3251. &VendorProperties{},
  3252. &BaseCompilerProperties{},
  3253. &BaseLinkerProperties{},
  3254. &ObjectLinkerProperties{},
  3255. &LibraryProperties{},
  3256. &StaticProperties{},
  3257. &SharedProperties{},
  3258. &FlagExporterProperties{},
  3259. &BinaryLinkerProperties{},
  3260. &TestLinkerProperties{},
  3261. &TestInstallerProperties{},
  3262. &TestBinaryProperties{},
  3263. &BenchmarkProperties{},
  3264. &fuzz.FuzzProperties{},
  3265. &StlProperties{},
  3266. &SanitizeProperties{},
  3267. &StripProperties{},
  3268. &InstallerProperties{},
  3269. &TidyProperties{},
  3270. &CoverageProperties{},
  3271. &SAbiProperties{},
  3272. &VndkProperties{},
  3273. &LTOProperties{},
  3274. &AfdoProperties{},
  3275. &PgoProperties{},
  3276. &android.ProtoProperties{},
  3277. // RustBindgenProperties is included here so that cc_defaults can be used for rust_bindgen modules.
  3278. &RustBindgenClangProperties{},
  3279. &prebuiltLinkerProperties{},
  3280. )
  3281. android.InitDefaultsModule(module)
  3282. return module
  3283. }
  3284. func (c *Module) IsSdkVariant() bool {
  3285. return c.Properties.IsSdkVariant
  3286. }
  3287. func (c *Module) isImportedApiLibrary() bool {
  3288. _, ok := c.linker.(*apiLibraryDecorator)
  3289. return ok
  3290. }
  3291. func kytheExtractAllFactory() android.Singleton {
  3292. return &kytheExtractAllSingleton{}
  3293. }
  3294. type kytheExtractAllSingleton struct {
  3295. }
  3296. func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
  3297. var xrefTargets android.Paths
  3298. ctx.VisitAllModules(func(module android.Module) {
  3299. if ccModule, ok := module.(xref); ok {
  3300. xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
  3301. }
  3302. })
  3303. // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
  3304. if len(xrefTargets) > 0 {
  3305. ctx.Phony("xref_cxx", xrefTargets...)
  3306. }
  3307. }
  3308. var Bool = proptools.Bool
  3309. var BoolDefault = proptools.BoolDefault
  3310. var BoolPtr = proptools.BoolPtr
  3311. var String = proptools.String
  3312. var StringPtr = proptools.StringPtr