cc.go 127 KB

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