cc.go 126 KB

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