cc.go 113 KB

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