cc.go 131 KB

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