cc.go 134 KB

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