cc.go 126 KB

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