cc_test.go 146 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619
  1. // Copyright 2017 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. import (
  16. "fmt"
  17. "os"
  18. "path/filepath"
  19. "reflect"
  20. "regexp"
  21. "runtime"
  22. "strings"
  23. "testing"
  24. "android/soong/aidl_library"
  25. "android/soong/android"
  26. "android/soong/bazel/cquery"
  27. )
  28. func init() {
  29. registerTestMutators(android.InitRegistrationContext)
  30. }
  31. func TestMain(m *testing.M) {
  32. os.Exit(m.Run())
  33. }
  34. var prepareForCcTest = android.GroupFixturePreparers(
  35. PrepareForTestWithCcIncludeVndk,
  36. android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
  37. variables.DeviceVndkVersion = StringPtr("current")
  38. variables.ProductVndkVersion = StringPtr("current")
  39. variables.Platform_vndk_version = StringPtr("29")
  40. }),
  41. )
  42. var ccLibInApex = "cc_lib_in_apex"
  43. var apexVariationName = "apex28"
  44. var apexVersion = "28"
  45. func registerTestMutators(ctx android.RegistrationContext) {
  46. ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
  47. ctx.BottomUp("apex", testApexMutator).Parallel()
  48. ctx.BottomUp("mixed_builds_prep", mixedBuildsPrepareMutator).Parallel()
  49. })
  50. }
  51. func mixedBuildsPrepareMutator(ctx android.BottomUpMutatorContext) {
  52. if m := ctx.Module(); m.Enabled() {
  53. if mixedBuildMod, ok := m.(android.MixedBuildBuildable); ok {
  54. if mixedBuildMod.IsMixedBuildSupported(ctx) && android.MixedBuildsEnabled(ctx) == android.MixedBuildEnabled {
  55. mixedBuildMod.QueueBazelCall(ctx)
  56. }
  57. }
  58. }
  59. }
  60. func testApexMutator(mctx android.BottomUpMutatorContext) {
  61. modules := mctx.CreateVariations(apexVariationName)
  62. apexInfo := android.ApexInfo{
  63. ApexVariationName: apexVariationName,
  64. MinSdkVersion: android.ApiLevelForTest(apexVersion),
  65. }
  66. mctx.SetVariationProvider(modules[0], android.ApexInfoProvider, apexInfo)
  67. }
  68. // testCcWithConfig runs tests using the prepareForCcTest
  69. //
  70. // See testCc for an explanation as to how to stop using this deprecated method.
  71. //
  72. // deprecated
  73. func testCcWithConfig(t *testing.T, config android.Config) *android.TestContext {
  74. t.Helper()
  75. result := prepareForCcTest.RunTestWithConfig(t, config)
  76. return result.TestContext
  77. }
  78. // testCc runs tests using the prepareForCcTest
  79. //
  80. // Do not add any new usages of this, instead use the prepareForCcTest directly as it makes it much
  81. // easier to customize the test behavior.
  82. //
  83. // If it is necessary to customize the behavior of an existing test that uses this then please first
  84. // convert the test to using prepareForCcTest first and then in a following change add the
  85. // appropriate fixture preparers. Keeping the conversion change separate makes it easy to verify
  86. // that it did not change the test behavior unexpectedly.
  87. //
  88. // deprecated
  89. func testCc(t *testing.T, bp string) *android.TestContext {
  90. t.Helper()
  91. result := prepareForCcTest.RunTestWithBp(t, bp)
  92. return result.TestContext
  93. }
  94. // testCcNoVndk runs tests using the prepareForCcTest
  95. //
  96. // See testCc for an explanation as to how to stop using this deprecated method.
  97. //
  98. // deprecated
  99. func testCcNoVndk(t *testing.T, bp string) *android.TestContext {
  100. t.Helper()
  101. config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
  102. config.TestProductVariables.Platform_vndk_version = StringPtr("29")
  103. return testCcWithConfig(t, config)
  104. }
  105. // testCcNoProductVndk runs tests using the prepareForCcTest
  106. //
  107. // See testCc for an explanation as to how to stop using this deprecated method.
  108. //
  109. // deprecated
  110. func testCcNoProductVndk(t *testing.T, bp string) *android.TestContext {
  111. t.Helper()
  112. config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
  113. config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
  114. config.TestProductVariables.Platform_vndk_version = StringPtr("29")
  115. return testCcWithConfig(t, config)
  116. }
  117. // testCcErrorWithConfig runs tests using the prepareForCcTest
  118. //
  119. // See testCc for an explanation as to how to stop using this deprecated method.
  120. //
  121. // deprecated
  122. func testCcErrorWithConfig(t *testing.T, pattern string, config android.Config) {
  123. t.Helper()
  124. prepareForCcTest.
  125. ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)).
  126. RunTestWithConfig(t, config)
  127. }
  128. // testCcError runs tests using the prepareForCcTest
  129. //
  130. // See testCc for an explanation as to how to stop using this deprecated method.
  131. //
  132. // deprecated
  133. func testCcError(t *testing.T, pattern string, bp string) {
  134. t.Helper()
  135. config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
  136. config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
  137. config.TestProductVariables.Platform_vndk_version = StringPtr("29")
  138. testCcErrorWithConfig(t, pattern, config)
  139. return
  140. }
  141. // testCcErrorProductVndk runs tests using the prepareForCcTest
  142. //
  143. // See testCc for an explanation as to how to stop using this deprecated method.
  144. //
  145. // deprecated
  146. func testCcErrorProductVndk(t *testing.T, pattern string, bp string) {
  147. t.Helper()
  148. config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
  149. config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
  150. config.TestProductVariables.ProductVndkVersion = StringPtr("current")
  151. config.TestProductVariables.Platform_vndk_version = StringPtr("29")
  152. testCcErrorWithConfig(t, pattern, config)
  153. return
  154. }
  155. const (
  156. coreVariant = "android_arm64_armv8-a_shared"
  157. vendorVariant = "android_vendor.29_arm64_armv8-a_shared"
  158. productVariant = "android_product.29_arm64_armv8-a_shared"
  159. recoveryVariant = "android_recovery_arm64_armv8-a_shared"
  160. )
  161. // Test that the PrepareForTestWithCcDefaultModules provides all the files that it uses by
  162. // running it in a fixture that requires all source files to exist.
  163. func TestPrepareForTestWithCcDefaultModules(t *testing.T) {
  164. android.GroupFixturePreparers(
  165. PrepareForTestWithCcDefaultModules,
  166. android.PrepareForTestDisallowNonExistentPaths,
  167. ).RunTest(t)
  168. }
  169. func TestVendorSrc(t *testing.T) {
  170. t.Parallel()
  171. ctx := testCc(t, `
  172. cc_library {
  173. name: "libTest",
  174. srcs: ["foo.c"],
  175. no_libcrt: true,
  176. nocrt: true,
  177. system_shared_libs: [],
  178. vendor_available: true,
  179. target: {
  180. vendor: {
  181. srcs: ["bar.c"],
  182. },
  183. },
  184. }
  185. `)
  186. ld := ctx.ModuleForTests("libTest", vendorVariant).Rule("ld")
  187. var objs []string
  188. for _, o := range ld.Inputs {
  189. objs = append(objs, o.Base())
  190. }
  191. if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
  192. t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
  193. }
  194. }
  195. func checkInstallPartition(t *testing.T, ctx *android.TestContext, name, variant, expected string) {
  196. mod := ctx.ModuleForTests(name, variant).Module().(*Module)
  197. partitionDefined := false
  198. checkPartition := func(specific bool, partition string) {
  199. if specific {
  200. if expected != partition && !partitionDefined {
  201. // The variant is installed to the 'partition'
  202. t.Errorf("%s variant of %q must not be installed to %s partition", variant, name, partition)
  203. }
  204. partitionDefined = true
  205. } else {
  206. // The variant is not installed to the 'partition'
  207. if expected == partition {
  208. t.Errorf("%s variant of %q must be installed to %s partition", variant, name, partition)
  209. }
  210. }
  211. }
  212. socSpecific := func(m *Module) bool {
  213. return m.SocSpecific() || m.socSpecificModuleContext()
  214. }
  215. deviceSpecific := func(m *Module) bool {
  216. return m.DeviceSpecific() || m.deviceSpecificModuleContext()
  217. }
  218. productSpecific := func(m *Module) bool {
  219. return m.ProductSpecific() || m.productSpecificModuleContext()
  220. }
  221. systemExtSpecific := func(m *Module) bool {
  222. return m.SystemExtSpecific()
  223. }
  224. checkPartition(socSpecific(mod), "vendor")
  225. checkPartition(deviceSpecific(mod), "odm")
  226. checkPartition(productSpecific(mod), "product")
  227. checkPartition(systemExtSpecific(mod), "system_ext")
  228. if !partitionDefined && expected != "system" {
  229. t.Errorf("%s variant of %q is expected to be installed to %s partition,"+
  230. " but installed to system partition", variant, name, expected)
  231. }
  232. }
  233. func TestInstallPartition(t *testing.T) {
  234. t.Parallel()
  235. t.Helper()
  236. ctx := prepareForCcTest.RunTestWithBp(t, `
  237. cc_library {
  238. name: "libsystem",
  239. }
  240. cc_library {
  241. name: "libsystem_ext",
  242. system_ext_specific: true,
  243. }
  244. cc_library {
  245. name: "libproduct",
  246. product_specific: true,
  247. }
  248. cc_library {
  249. name: "libvendor",
  250. vendor: true,
  251. }
  252. cc_library {
  253. name: "libodm",
  254. device_specific: true,
  255. }
  256. cc_library {
  257. name: "liball_available",
  258. vendor_available: true,
  259. product_available: true,
  260. }
  261. cc_library {
  262. name: "libsystem_ext_all_available",
  263. system_ext_specific: true,
  264. vendor_available: true,
  265. product_available: true,
  266. }
  267. cc_library {
  268. name: "liball_available_odm",
  269. odm_available: true,
  270. product_available: true,
  271. }
  272. cc_library {
  273. name: "libproduct_vendoravailable",
  274. product_specific: true,
  275. vendor_available: true,
  276. }
  277. cc_library {
  278. name: "libproduct_odmavailable",
  279. product_specific: true,
  280. odm_available: true,
  281. }
  282. `).TestContext
  283. checkInstallPartition(t, ctx, "libsystem", coreVariant, "system")
  284. checkInstallPartition(t, ctx, "libsystem_ext", coreVariant, "system_ext")
  285. checkInstallPartition(t, ctx, "libproduct", productVariant, "product")
  286. checkInstallPartition(t, ctx, "libvendor", vendorVariant, "vendor")
  287. checkInstallPartition(t, ctx, "libodm", vendorVariant, "odm")
  288. checkInstallPartition(t, ctx, "liball_available", coreVariant, "system")
  289. checkInstallPartition(t, ctx, "liball_available", productVariant, "product")
  290. checkInstallPartition(t, ctx, "liball_available", vendorVariant, "vendor")
  291. checkInstallPartition(t, ctx, "libsystem_ext_all_available", coreVariant, "system_ext")
  292. checkInstallPartition(t, ctx, "libsystem_ext_all_available", productVariant, "product")
  293. checkInstallPartition(t, ctx, "libsystem_ext_all_available", vendorVariant, "vendor")
  294. checkInstallPartition(t, ctx, "liball_available_odm", coreVariant, "system")
  295. checkInstallPartition(t, ctx, "liball_available_odm", productVariant, "product")
  296. checkInstallPartition(t, ctx, "liball_available_odm", vendorVariant, "odm")
  297. checkInstallPartition(t, ctx, "libproduct_vendoravailable", productVariant, "product")
  298. checkInstallPartition(t, ctx, "libproduct_vendoravailable", vendorVariant, "vendor")
  299. checkInstallPartition(t, ctx, "libproduct_odmavailable", productVariant, "product")
  300. checkInstallPartition(t, ctx, "libproduct_odmavailable", vendorVariant, "odm")
  301. }
  302. func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string,
  303. isVndkSp bool, extends string, variant string) {
  304. t.Helper()
  305. mod := ctx.ModuleForTests(name, variant).Module().(*Module)
  306. // Check library properties.
  307. lib, ok := mod.compiler.(*libraryDecorator)
  308. if !ok {
  309. t.Errorf("%q must have libraryDecorator", name)
  310. } else if lib.baseInstaller.subDir != subDir {
  311. t.Errorf("%q must use %q as subdir but it is using %q", name, subDir,
  312. lib.baseInstaller.subDir)
  313. }
  314. // Check VNDK properties.
  315. if mod.vndkdep == nil {
  316. t.Fatalf("%q must have `vndkdep`", name)
  317. }
  318. if !mod.IsVndk() {
  319. t.Errorf("%q IsVndk() must equal to true", name)
  320. }
  321. if mod.IsVndkSp() != isVndkSp {
  322. t.Errorf("%q IsVndkSp() must equal to %t", name, isVndkSp)
  323. }
  324. // Check VNDK extension properties.
  325. isVndkExt := extends != ""
  326. if mod.IsVndkExt() != isVndkExt {
  327. t.Errorf("%q IsVndkExt() must equal to %t", name, isVndkExt)
  328. }
  329. if actualExtends := mod.getVndkExtendsModuleName(); actualExtends != extends {
  330. t.Errorf("%q must extend from %q but get %q", name, extends, actualExtends)
  331. }
  332. }
  333. func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) {
  334. t.Helper()
  335. content := android.ContentFromFileRuleForTests(t, params)
  336. actual := strings.FieldsFunc(content, func(r rune) bool { return r == '\n' })
  337. assertArrayString(t, actual, expected)
  338. }
  339. func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) {
  340. t.Helper()
  341. vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
  342. checkWriteFileOutput(t, vndkSnapshot.Output(output), expected)
  343. }
  344. func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) {
  345. t.Helper()
  346. got := ctx.ModuleForTests(module, "android_common").Module().(*vndkLibrariesTxt).fileNames
  347. assertArrayString(t, got, expected)
  348. }
  349. func TestVndk(t *testing.T) {
  350. t.Parallel()
  351. bp := `
  352. cc_library {
  353. name: "libvndk",
  354. vendor_available: true,
  355. vndk: {
  356. enabled: true,
  357. },
  358. nocrt: true,
  359. }
  360. cc_library {
  361. name: "libvndk_private",
  362. vendor_available: true,
  363. vndk: {
  364. enabled: true,
  365. private: true,
  366. },
  367. nocrt: true,
  368. stem: "libvndk-private",
  369. }
  370. cc_library {
  371. name: "libvndk_product",
  372. vendor_available: true,
  373. product_available: true,
  374. vndk: {
  375. enabled: true,
  376. },
  377. nocrt: true,
  378. target: {
  379. vendor: {
  380. cflags: ["-DTEST"],
  381. },
  382. product: {
  383. cflags: ["-DTEST"],
  384. },
  385. },
  386. }
  387. cc_library {
  388. name: "libvndk_sp",
  389. vendor_available: true,
  390. vndk: {
  391. enabled: true,
  392. support_system_process: true,
  393. },
  394. nocrt: true,
  395. suffix: "-x",
  396. }
  397. cc_library {
  398. name: "libvndk_sp_private",
  399. vendor_available: true,
  400. vndk: {
  401. enabled: true,
  402. support_system_process: true,
  403. private: true,
  404. },
  405. nocrt: true,
  406. target: {
  407. vendor: {
  408. suffix: "-x",
  409. },
  410. },
  411. }
  412. cc_library {
  413. name: "libvndk_sp_product_private",
  414. vendor_available: true,
  415. product_available: true,
  416. vndk: {
  417. enabled: true,
  418. support_system_process: true,
  419. private: true,
  420. },
  421. nocrt: true,
  422. target: {
  423. vendor: {
  424. suffix: "-x",
  425. },
  426. product: {
  427. suffix: "-x",
  428. },
  429. },
  430. }
  431. cc_library {
  432. name: "libllndk",
  433. llndk: {
  434. symbol_file: "libllndk.map.txt",
  435. export_llndk_headers: ["libllndk_headers"],
  436. }
  437. }
  438. cc_library {
  439. name: "libclang_rt.hwasan-llndk",
  440. llndk: {
  441. symbol_file: "libclang_rt.hwasan.map.txt",
  442. }
  443. }
  444. cc_library_headers {
  445. name: "libllndk_headers",
  446. llndk: {
  447. llndk_headers: true,
  448. },
  449. export_include_dirs: ["include"],
  450. }
  451. llndk_libraries_txt {
  452. name: "llndk.libraries.txt",
  453. }
  454. vndkcore_libraries_txt {
  455. name: "vndkcore.libraries.txt",
  456. }
  457. vndksp_libraries_txt {
  458. name: "vndksp.libraries.txt",
  459. }
  460. vndkprivate_libraries_txt {
  461. name: "vndkprivate.libraries.txt",
  462. }
  463. vndkproduct_libraries_txt {
  464. name: "vndkproduct.libraries.txt",
  465. }
  466. vndkcorevariant_libraries_txt {
  467. name: "vndkcorevariant.libraries.txt",
  468. insert_vndk_version: false,
  469. }
  470. `
  471. config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
  472. config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
  473. config.TestProductVariables.ProductVndkVersion = StringPtr("current")
  474. config.TestProductVariables.Platform_vndk_version = StringPtr("29")
  475. ctx := testCcWithConfig(t, config)
  476. // subdir == "" because VNDK libs are not supposed to be installed separately.
  477. // They are installed as part of VNDK APEX instead.
  478. checkVndkModule(t, ctx, "libvndk", "", false, "", vendorVariant)
  479. checkVndkModule(t, ctx, "libvndk_private", "", false, "", vendorVariant)
  480. checkVndkModule(t, ctx, "libvndk_product", "", false, "", vendorVariant)
  481. checkVndkModule(t, ctx, "libvndk_sp", "", true, "", vendorVariant)
  482. checkVndkModule(t, ctx, "libvndk_sp_private", "", true, "", vendorVariant)
  483. checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", vendorVariant)
  484. checkVndkModule(t, ctx, "libvndk_product", "", false, "", productVariant)
  485. checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", productVariant)
  486. // Check VNDK snapshot output.
  487. snapshotDir := "vndk-snapshot"
  488. snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
  489. vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
  490. "arm64", "armv8-a"))
  491. vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
  492. "arm", "armv7-a-neon"))
  493. vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core")
  494. vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp")
  495. llndkLibPath := filepath.Join(vndkLibPath, "shared", "llndk-stub")
  496. vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core")
  497. vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp")
  498. llndkLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "llndk-stub")
  499. variant := "android_vendor.29_arm64_armv8-a_shared"
  500. variant2nd := "android_vendor.29_arm_armv7-a-neon_shared"
  501. snapshotSingleton := ctx.SingletonForTests("vndk-snapshot")
  502. CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLibPath, variant)
  503. CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd)
  504. CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLibPath, variant)
  505. CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLib2ndPath, variant2nd)
  506. CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant)
  507. CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd)
  508. CheckSnapshot(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", llndkLibPath, variant)
  509. CheckSnapshot(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", llndkLib2ndPath, variant2nd)
  510. snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs")
  511. CheckSnapshot(t, ctx, snapshotSingleton, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "android_common")
  512. CheckSnapshot(t, ctx, snapshotSingleton, "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "android_common")
  513. CheckSnapshot(t, ctx, snapshotSingleton, "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "android_common")
  514. CheckSnapshot(t, ctx, snapshotSingleton, "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "android_common")
  515. CheckSnapshot(t, ctx, snapshotSingleton, "vndkproduct.libraries.txt", "vndkproduct.libraries.txt", snapshotConfigsPath, "android_common")
  516. checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
  517. "LLNDK: libc.so",
  518. "LLNDK: libdl.so",
  519. "LLNDK: libft2.so",
  520. "LLNDK: libllndk.so",
  521. "LLNDK: libm.so",
  522. "VNDK-SP: libc++.so",
  523. "VNDK-SP: libvndk_sp-x.so",
  524. "VNDK-SP: libvndk_sp_private-x.so",
  525. "VNDK-SP: libvndk_sp_product_private-x.so",
  526. "VNDK-core: libvndk-private.so",
  527. "VNDK-core: libvndk.so",
  528. "VNDK-core: libvndk_product.so",
  529. "VNDK-private: libft2.so",
  530. "VNDK-private: libvndk-private.so",
  531. "VNDK-private: libvndk_sp_private-x.so",
  532. "VNDK-private: libvndk_sp_product_private-x.so",
  533. "VNDK-product: libc++.so",
  534. "VNDK-product: libvndk_product.so",
  535. "VNDK-product: libvndk_sp_product_private-x.so",
  536. })
  537. checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libclang_rt.hwasan-llndk.so", "libdl.so", "libft2.so", "libllndk.so", "libm.so"})
  538. checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so", "libvndk_product.so"})
  539. checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"})
  540. checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt", []string{"libft2.so", "libvndk-private.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"})
  541. checkVndkLibrariesOutput(t, ctx, "vndkproduct.libraries.txt", []string{"libc++.so", "libvndk_product.so", "libvndk_sp_product_private-x.so"})
  542. checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil)
  543. }
  544. func TestVndkWithHostSupported(t *testing.T) {
  545. t.Parallel()
  546. ctx := testCc(t, `
  547. cc_library {
  548. name: "libvndk_host_supported",
  549. vendor_available: true,
  550. product_available: true,
  551. vndk: {
  552. enabled: true,
  553. },
  554. host_supported: true,
  555. }
  556. cc_library {
  557. name: "libvndk_host_supported_but_disabled_on_device",
  558. vendor_available: true,
  559. product_available: true,
  560. vndk: {
  561. enabled: true,
  562. },
  563. host_supported: true,
  564. enabled: false,
  565. target: {
  566. host: {
  567. enabled: true,
  568. }
  569. }
  570. }
  571. vndkcore_libraries_txt {
  572. name: "vndkcore.libraries.txt",
  573. }
  574. `)
  575. checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk_host_supported.so"})
  576. }
  577. func TestVndkLibrariesTxtAndroidMk(t *testing.T) {
  578. t.Parallel()
  579. bp := `
  580. llndk_libraries_txt {
  581. name: "llndk.libraries.txt",
  582. insert_vndk_version: true,
  583. }`
  584. config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
  585. config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
  586. config.TestProductVariables.Platform_vndk_version = StringPtr("29")
  587. ctx := testCcWithConfig(t, config)
  588. module := ctx.ModuleForTests("llndk.libraries.txt", "android_common")
  589. entries := android.AndroidMkEntriesForTest(t, ctx, module.Module())[0]
  590. assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.29.txt"})
  591. }
  592. func TestVndkUsingCoreVariant(t *testing.T) {
  593. t.Parallel()
  594. bp := `
  595. cc_library {
  596. name: "libvndk",
  597. vendor_available: true,
  598. product_available: true,
  599. vndk: {
  600. enabled: true,
  601. },
  602. nocrt: true,
  603. }
  604. cc_library {
  605. name: "libvndk_sp",
  606. vendor_available: true,
  607. product_available: true,
  608. vndk: {
  609. enabled: true,
  610. support_system_process: true,
  611. },
  612. nocrt: true,
  613. }
  614. cc_library {
  615. name: "libvndk2",
  616. vendor_available: true,
  617. product_available: true,
  618. vndk: {
  619. enabled: true,
  620. private: true,
  621. },
  622. nocrt: true,
  623. }
  624. vndkcorevariant_libraries_txt {
  625. name: "vndkcorevariant.libraries.txt",
  626. insert_vndk_version: false,
  627. }
  628. `
  629. config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
  630. config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
  631. config.TestProductVariables.Platform_vndk_version = StringPtr("29")
  632. config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
  633. setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"})
  634. ctx := testCcWithConfig(t, config)
  635. checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", []string{"libc++.so", "libvndk2.so", "libvndk_sp.so"})
  636. }
  637. func TestDataLibs(t *testing.T) {
  638. t.Parallel()
  639. bp := `
  640. cc_test_library {
  641. name: "test_lib",
  642. srcs: ["test_lib.cpp"],
  643. gtest: false,
  644. }
  645. cc_test {
  646. name: "main_test",
  647. data_libs: ["test_lib"],
  648. gtest: false,
  649. }
  650. `
  651. config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
  652. config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
  653. config.TestProductVariables.Platform_vndk_version = StringPtr("29")
  654. config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
  655. ctx := testCcWithConfig(t, config)
  656. module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
  657. testBinary := module.(*Module).linker.(*testBinary)
  658. outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
  659. if err != nil {
  660. t.Errorf("Expected cc_test to produce output files, error: %s", err)
  661. return
  662. }
  663. if len(outputFiles) != 1 {
  664. t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
  665. return
  666. }
  667. if len(testBinary.dataPaths()) != 1 {
  668. t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
  669. return
  670. }
  671. outputPath := outputFiles[0].String()
  672. testBinaryPath := testBinary.dataPaths()[0].SrcPath.String()
  673. if !strings.HasSuffix(outputPath, "/main_test") {
  674. t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
  675. return
  676. }
  677. if !strings.HasSuffix(testBinaryPath, "/test_lib.so") {
  678. t.Errorf("expected test data file to be 'test_lib.so', but was '%s'", testBinaryPath)
  679. return
  680. }
  681. }
  682. func TestDataLibsRelativeInstallPath(t *testing.T) {
  683. t.Parallel()
  684. bp := `
  685. cc_test_library {
  686. name: "test_lib",
  687. srcs: ["test_lib.cpp"],
  688. relative_install_path: "foo/bar/baz",
  689. gtest: false,
  690. }
  691. cc_binary {
  692. name: "test_bin",
  693. relative_install_path: "foo/bar/baz",
  694. compile_multilib: "both",
  695. }
  696. cc_test {
  697. name: "main_test",
  698. data_libs: ["test_lib"],
  699. data_bins: ["test_bin"],
  700. gtest: false,
  701. }
  702. `
  703. config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
  704. config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
  705. config.TestProductVariables.Platform_vndk_version = StringPtr("29")
  706. config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
  707. ctx := testCcWithConfig(t, config)
  708. module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
  709. testBinary := module.(*Module).linker.(*testBinary)
  710. outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
  711. if err != nil {
  712. t.Fatalf("Expected cc_test to produce output files, error: %s", err)
  713. }
  714. if len(outputFiles) != 1 {
  715. t.Fatalf("expected exactly one output file. output files: [%s]", outputFiles)
  716. }
  717. if len(testBinary.dataPaths()) != 2 {
  718. t.Fatalf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
  719. }
  720. outputPath := outputFiles[0].String()
  721. if !strings.HasSuffix(outputPath, "/main_test") {
  722. t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
  723. }
  724. entries := android.AndroidMkEntriesForTest(t, ctx, module)[0]
  725. if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
  726. t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
  727. " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
  728. }
  729. if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][1], ":test_bin:foo/bar/baz") {
  730. t.Errorf("expected LOCAL_TEST_DATA to end with `:test_bin:foo/bar/baz`,"+
  731. " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][1])
  732. }
  733. }
  734. func TestTestBinaryTestSuites(t *testing.T) {
  735. t.Parallel()
  736. bp := `
  737. cc_test {
  738. name: "main_test",
  739. srcs: ["main_test.cpp"],
  740. test_suites: [
  741. "suite_1",
  742. "suite_2",
  743. ],
  744. gtest: false,
  745. }
  746. `
  747. ctx := prepareForCcTest.RunTestWithBp(t, bp).TestContext
  748. module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
  749. entries := android.AndroidMkEntriesForTest(t, ctx, module)[0]
  750. compatEntries := entries.EntryMap["LOCAL_COMPATIBILITY_SUITE"]
  751. if len(compatEntries) != 2 {
  752. t.Errorf("expected two elements in LOCAL_COMPATIBILITY_SUITE. got %d", len(compatEntries))
  753. }
  754. if compatEntries[0] != "suite_1" {
  755. t.Errorf("expected LOCAL_COMPATIBILITY_SUITE to be`suite_1`,"+
  756. " but was '%s'", compatEntries[0])
  757. }
  758. if compatEntries[1] != "suite_2" {
  759. t.Errorf("expected LOCAL_COMPATIBILITY_SUITE to be`suite_2`,"+
  760. " but was '%s'", compatEntries[1])
  761. }
  762. }
  763. func TestTestLibraryTestSuites(t *testing.T) {
  764. t.Parallel()
  765. bp := `
  766. cc_test_library {
  767. name: "main_test_lib",
  768. srcs: ["main_test_lib.cpp"],
  769. test_suites: [
  770. "suite_1",
  771. "suite_2",
  772. ],
  773. gtest: false,
  774. }
  775. `
  776. ctx := prepareForCcTest.RunTestWithBp(t, bp).TestContext
  777. module := ctx.ModuleForTests("main_test_lib", "android_arm_armv7-a-neon_shared").Module()
  778. entries := android.AndroidMkEntriesForTest(t, ctx, module)[0]
  779. compatEntries := entries.EntryMap["LOCAL_COMPATIBILITY_SUITE"]
  780. if len(compatEntries) != 2 {
  781. t.Errorf("expected two elements in LOCAL_COMPATIBILITY_SUITE. got %d", len(compatEntries))
  782. }
  783. if compatEntries[0] != "suite_1" {
  784. t.Errorf("expected LOCAL_COMPATIBILITY_SUITE to be`suite_1`,"+
  785. " but was '%s'", compatEntries[0])
  786. }
  787. if compatEntries[1] != "suite_2" {
  788. t.Errorf("expected LOCAL_COMPATIBILITY_SUITE to be`suite_2`,"+
  789. " but was '%s'", compatEntries[1])
  790. }
  791. }
  792. func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
  793. t.Parallel()
  794. ctx := testCcNoVndk(t, `
  795. cc_library {
  796. name: "libvndk",
  797. vendor_available: true,
  798. product_available: true,
  799. vndk: {
  800. enabled: true,
  801. },
  802. nocrt: true,
  803. }
  804. cc_library {
  805. name: "libvndk-private",
  806. vendor_available: true,
  807. product_available: true,
  808. vndk: {
  809. enabled: true,
  810. private: true,
  811. },
  812. nocrt: true,
  813. }
  814. cc_library {
  815. name: "libllndk",
  816. llndk: {
  817. symbol_file: "libllndk.map.txt",
  818. export_llndk_headers: ["libllndk_headers"],
  819. }
  820. }
  821. cc_library_headers {
  822. name: "libllndk_headers",
  823. llndk: {
  824. symbol_file: "libllndk.map.txt",
  825. },
  826. export_include_dirs: ["include"],
  827. }
  828. `)
  829. checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
  830. "LLNDK: libc.so",
  831. "LLNDK: libdl.so",
  832. "LLNDK: libft2.so",
  833. "LLNDK: libllndk.so",
  834. "LLNDK: libm.so",
  835. "VNDK-SP: libc++.so",
  836. "VNDK-core: libvndk-private.so",
  837. "VNDK-core: libvndk.so",
  838. "VNDK-private: libft2.so",
  839. "VNDK-private: libvndk-private.so",
  840. "VNDK-product: libc++.so",
  841. "VNDK-product: libvndk-private.so",
  842. "VNDK-product: libvndk.so",
  843. })
  844. }
  845. func TestVndkModuleError(t *testing.T) {
  846. t.Parallel()
  847. // Check the error message for vendor_available and product_available properties.
  848. testCcErrorProductVndk(t, "vndk: vendor_available must be set to true when `vndk: {enabled: true}`", `
  849. cc_library {
  850. name: "libvndk",
  851. vndk: {
  852. enabled: true,
  853. },
  854. nocrt: true,
  855. }
  856. `)
  857. testCcErrorProductVndk(t, "vndk: vendor_available must be set to true when `vndk: {enabled: true}`", `
  858. cc_library {
  859. name: "libvndk",
  860. product_available: true,
  861. vndk: {
  862. enabled: true,
  863. },
  864. nocrt: true,
  865. }
  866. `)
  867. testCcErrorProductVndk(t, "product properties must have the same values with the vendor properties for VNDK modules", `
  868. cc_library {
  869. name: "libvndkprop",
  870. vendor_available: true,
  871. product_available: true,
  872. vndk: {
  873. enabled: true,
  874. },
  875. nocrt: true,
  876. target: {
  877. vendor: {
  878. cflags: ["-DTEST",],
  879. },
  880. },
  881. }
  882. `)
  883. }
  884. func TestVndkDepError(t *testing.T) {
  885. t.Parallel()
  886. // Check whether an error is emitted when a VNDK lib depends on a system lib.
  887. testCcError(t, "dependency \".*\" of \".*\" missing variant", `
  888. cc_library {
  889. name: "libvndk",
  890. vendor_available: true,
  891. product_available: true,
  892. vndk: {
  893. enabled: true,
  894. },
  895. shared_libs: ["libfwk"], // Cause error
  896. nocrt: true,
  897. }
  898. cc_library {
  899. name: "libfwk",
  900. nocrt: true,
  901. }
  902. `)
  903. // Check whether an error is emitted when a VNDK lib depends on a vendor lib.
  904. testCcError(t, "dependency \".*\" of \".*\" missing variant", `
  905. cc_library {
  906. name: "libvndk",
  907. vendor_available: true,
  908. product_available: true,
  909. vndk: {
  910. enabled: true,
  911. },
  912. shared_libs: ["libvendor"], // Cause error
  913. nocrt: true,
  914. }
  915. cc_library {
  916. name: "libvendor",
  917. vendor: true,
  918. nocrt: true,
  919. }
  920. `)
  921. // Check whether an error is emitted when a VNDK-SP lib depends on a system lib.
  922. testCcError(t, "dependency \".*\" of \".*\" missing variant", `
  923. cc_library {
  924. name: "libvndk_sp",
  925. vendor_available: true,
  926. product_available: true,
  927. vndk: {
  928. enabled: true,
  929. support_system_process: true,
  930. },
  931. shared_libs: ["libfwk"], // Cause error
  932. nocrt: true,
  933. }
  934. cc_library {
  935. name: "libfwk",
  936. nocrt: true,
  937. }
  938. `)
  939. // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib.
  940. testCcError(t, "dependency \".*\" of \".*\" missing variant", `
  941. cc_library {
  942. name: "libvndk_sp",
  943. vendor_available: true,
  944. product_available: true,
  945. vndk: {
  946. enabled: true,
  947. support_system_process: true,
  948. },
  949. shared_libs: ["libvendor"], // Cause error
  950. nocrt: true,
  951. }
  952. cc_library {
  953. name: "libvendor",
  954. vendor: true,
  955. nocrt: true,
  956. }
  957. `)
  958. // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib.
  959. testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
  960. cc_library {
  961. name: "libvndk_sp",
  962. vendor_available: true,
  963. product_available: true,
  964. vndk: {
  965. enabled: true,
  966. support_system_process: true,
  967. },
  968. shared_libs: ["libvndk"], // Cause error
  969. nocrt: true,
  970. }
  971. cc_library {
  972. name: "libvndk",
  973. vendor_available: true,
  974. product_available: true,
  975. vndk: {
  976. enabled: true,
  977. },
  978. nocrt: true,
  979. }
  980. `)
  981. // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib.
  982. testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
  983. cc_library {
  984. name: "libvndk",
  985. vendor_available: true,
  986. product_available: true,
  987. vndk: {
  988. enabled: true,
  989. },
  990. shared_libs: ["libnonvndk"],
  991. nocrt: true,
  992. }
  993. cc_library {
  994. name: "libnonvndk",
  995. vendor_available: true,
  996. nocrt: true,
  997. }
  998. `)
  999. // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib.
  1000. testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
  1001. cc_library {
  1002. name: "libvndkprivate",
  1003. vendor_available: true,
  1004. product_available: true,
  1005. vndk: {
  1006. enabled: true,
  1007. private: true,
  1008. },
  1009. shared_libs: ["libnonvndk"],
  1010. nocrt: true,
  1011. }
  1012. cc_library {
  1013. name: "libnonvndk",
  1014. vendor_available: true,
  1015. nocrt: true,
  1016. }
  1017. `)
  1018. // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib.
  1019. testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
  1020. cc_library {
  1021. name: "libvndksp",
  1022. vendor_available: true,
  1023. product_available: true,
  1024. vndk: {
  1025. enabled: true,
  1026. support_system_process: true,
  1027. },
  1028. shared_libs: ["libnonvndk"],
  1029. nocrt: true,
  1030. }
  1031. cc_library {
  1032. name: "libnonvndk",
  1033. vendor_available: true,
  1034. nocrt: true,
  1035. }
  1036. `)
  1037. // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib.
  1038. testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
  1039. cc_library {
  1040. name: "libvndkspprivate",
  1041. vendor_available: true,
  1042. product_available: true,
  1043. vndk: {
  1044. enabled: true,
  1045. support_system_process: true,
  1046. private: true,
  1047. },
  1048. shared_libs: ["libnonvndk"],
  1049. nocrt: true,
  1050. }
  1051. cc_library {
  1052. name: "libnonvndk",
  1053. vendor_available: true,
  1054. nocrt: true,
  1055. }
  1056. `)
  1057. }
  1058. func TestDoubleLoadbleDep(t *testing.T) {
  1059. t.Parallel()
  1060. // okay to link : LLNDK -> double_loadable VNDK
  1061. testCc(t, `
  1062. cc_library {
  1063. name: "libllndk",
  1064. shared_libs: ["libdoubleloadable"],
  1065. llndk: {
  1066. symbol_file: "libllndk.map.txt",
  1067. }
  1068. }
  1069. cc_library {
  1070. name: "libdoubleloadable",
  1071. vendor_available: true,
  1072. product_available: true,
  1073. vndk: {
  1074. enabled: true,
  1075. },
  1076. double_loadable: true,
  1077. }
  1078. `)
  1079. // okay to link : LLNDK -> VNDK-SP
  1080. testCc(t, `
  1081. cc_library {
  1082. name: "libllndk",
  1083. shared_libs: ["libvndksp"],
  1084. llndk: {
  1085. symbol_file: "libllndk.map.txt",
  1086. }
  1087. }
  1088. cc_library {
  1089. name: "libvndksp",
  1090. vendor_available: true,
  1091. product_available: true,
  1092. vndk: {
  1093. enabled: true,
  1094. support_system_process: true,
  1095. },
  1096. }
  1097. `)
  1098. // okay to link : double_loadable -> double_loadable
  1099. testCc(t, `
  1100. cc_library {
  1101. name: "libdoubleloadable1",
  1102. shared_libs: ["libdoubleloadable2"],
  1103. vendor_available: true,
  1104. double_loadable: true,
  1105. }
  1106. cc_library {
  1107. name: "libdoubleloadable2",
  1108. vendor_available: true,
  1109. double_loadable: true,
  1110. }
  1111. `)
  1112. // okay to link : double_loadable VNDK -> double_loadable VNDK private
  1113. testCc(t, `
  1114. cc_library {
  1115. name: "libdoubleloadable",
  1116. vendor_available: true,
  1117. product_available: true,
  1118. vndk: {
  1119. enabled: true,
  1120. },
  1121. double_loadable: true,
  1122. shared_libs: ["libnondoubleloadable"],
  1123. }
  1124. cc_library {
  1125. name: "libnondoubleloadable",
  1126. vendor_available: true,
  1127. product_available: true,
  1128. vndk: {
  1129. enabled: true,
  1130. private: true,
  1131. },
  1132. double_loadable: true,
  1133. }
  1134. `)
  1135. // okay to link : LLNDK -> core-only -> vendor_available & double_loadable
  1136. testCc(t, `
  1137. cc_library {
  1138. name: "libllndk",
  1139. shared_libs: ["libcoreonly"],
  1140. llndk: {
  1141. symbol_file: "libllndk.map.txt",
  1142. }
  1143. }
  1144. cc_library {
  1145. name: "libcoreonly",
  1146. shared_libs: ["libvendoravailable"],
  1147. }
  1148. // indirect dependency of LLNDK
  1149. cc_library {
  1150. name: "libvendoravailable",
  1151. vendor_available: true,
  1152. double_loadable: true,
  1153. }
  1154. `)
  1155. }
  1156. func TestDoubleLoadableDepError(t *testing.T) {
  1157. t.Parallel()
  1158. // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib.
  1159. testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
  1160. cc_library {
  1161. name: "libllndk",
  1162. shared_libs: ["libnondoubleloadable"],
  1163. llndk: {
  1164. symbol_file: "libllndk.map.txt",
  1165. }
  1166. }
  1167. cc_library {
  1168. name: "libnondoubleloadable",
  1169. vendor_available: true,
  1170. product_available: true,
  1171. vndk: {
  1172. enabled: true,
  1173. },
  1174. }
  1175. `)
  1176. // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib.
  1177. testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
  1178. cc_library {
  1179. name: "libllndk",
  1180. no_libcrt: true,
  1181. shared_libs: ["libnondoubleloadable"],
  1182. llndk: {
  1183. symbol_file: "libllndk.map.txt",
  1184. }
  1185. }
  1186. cc_library {
  1187. name: "libnondoubleloadable",
  1188. vendor_available: true,
  1189. }
  1190. `)
  1191. // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly.
  1192. testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
  1193. cc_library {
  1194. name: "libllndk",
  1195. shared_libs: ["libcoreonly"],
  1196. llndk: {
  1197. symbol_file: "libllndk.map.txt",
  1198. }
  1199. }
  1200. cc_library {
  1201. name: "libcoreonly",
  1202. shared_libs: ["libvendoravailable"],
  1203. }
  1204. // indirect dependency of LLNDK
  1205. cc_library {
  1206. name: "libvendoravailable",
  1207. vendor_available: true,
  1208. }
  1209. `)
  1210. // The error is not from 'client' but from 'libllndk'
  1211. testCcError(t, "module \"libllndk\".* links a library \"libnondoubleloadable\".*double_loadable", `
  1212. cc_library {
  1213. name: "client",
  1214. vendor_available: true,
  1215. double_loadable: true,
  1216. shared_libs: ["libllndk"],
  1217. }
  1218. cc_library {
  1219. name: "libllndk",
  1220. shared_libs: ["libnondoubleloadable"],
  1221. llndk: {
  1222. symbol_file: "libllndk.map.txt",
  1223. }
  1224. }
  1225. cc_library {
  1226. name: "libnondoubleloadable",
  1227. vendor_available: true,
  1228. }
  1229. `)
  1230. }
  1231. func TestCheckVndkMembershipBeforeDoubleLoadable(t *testing.T) {
  1232. t.Parallel()
  1233. testCcError(t, "module \"libvndksp\" variant .*: .*: VNDK-SP must only depend on VNDK-SP", `
  1234. cc_library {
  1235. name: "libvndksp",
  1236. shared_libs: ["libanothervndksp"],
  1237. vendor_available: true,
  1238. product_available: true,
  1239. vndk: {
  1240. enabled: true,
  1241. support_system_process: true,
  1242. }
  1243. }
  1244. cc_library {
  1245. name: "libllndk",
  1246. shared_libs: ["libanothervndksp"],
  1247. }
  1248. cc_library {
  1249. name: "libanothervndksp",
  1250. vendor_available: true,
  1251. }
  1252. `)
  1253. }
  1254. func TestVndkExt(t *testing.T) {
  1255. t.Parallel()
  1256. // This test checks the VNDK-Ext properties.
  1257. bp := `
  1258. cc_library {
  1259. name: "libvndk",
  1260. vendor_available: true,
  1261. product_available: true,
  1262. vndk: {
  1263. enabled: true,
  1264. },
  1265. nocrt: true,
  1266. }
  1267. cc_library {
  1268. name: "libvndk2",
  1269. vendor_available: true,
  1270. product_available: true,
  1271. vndk: {
  1272. enabled: true,
  1273. },
  1274. target: {
  1275. vendor: {
  1276. suffix: "-suffix",
  1277. },
  1278. product: {
  1279. suffix: "-suffix",
  1280. },
  1281. },
  1282. nocrt: true,
  1283. }
  1284. cc_library {
  1285. name: "libvndk_ext",
  1286. vendor: true,
  1287. vndk: {
  1288. enabled: true,
  1289. extends: "libvndk",
  1290. },
  1291. nocrt: true,
  1292. }
  1293. cc_library {
  1294. name: "libvndk2_ext",
  1295. vendor: true,
  1296. vndk: {
  1297. enabled: true,
  1298. extends: "libvndk2",
  1299. },
  1300. nocrt: true,
  1301. }
  1302. cc_library {
  1303. name: "libvndk_ext_product",
  1304. product_specific: true,
  1305. vndk: {
  1306. enabled: true,
  1307. extends: "libvndk",
  1308. },
  1309. nocrt: true,
  1310. }
  1311. cc_library {
  1312. name: "libvndk2_ext_product",
  1313. product_specific: true,
  1314. vndk: {
  1315. enabled: true,
  1316. extends: "libvndk2",
  1317. },
  1318. nocrt: true,
  1319. }
  1320. `
  1321. config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
  1322. config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
  1323. config.TestProductVariables.ProductVndkVersion = StringPtr("current")
  1324. config.TestProductVariables.Platform_vndk_version = StringPtr("29")
  1325. ctx := testCcWithConfig(t, config)
  1326. checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant)
  1327. checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant)
  1328. mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module)
  1329. assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so")
  1330. mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module)
  1331. assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so")
  1332. }
  1333. func TestVndkExtWithoutBoardVndkVersion(t *testing.T) {
  1334. t.Parallel()
  1335. // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set.
  1336. ctx := testCcNoVndk(t, `
  1337. cc_library {
  1338. name: "libvndk",
  1339. vendor_available: true,
  1340. product_available: true,
  1341. vndk: {
  1342. enabled: true,
  1343. },
  1344. nocrt: true,
  1345. }
  1346. cc_library {
  1347. name: "libvndk_ext",
  1348. vendor: true,
  1349. vndk: {
  1350. enabled: true,
  1351. extends: "libvndk",
  1352. },
  1353. nocrt: true,
  1354. }
  1355. `)
  1356. // Ensures that the core variant of "libvndk_ext" can be found.
  1357. mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module)
  1358. if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
  1359. t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends)
  1360. }
  1361. }
  1362. func TestVndkExtWithoutProductVndkVersion(t *testing.T) {
  1363. t.Parallel()
  1364. // This test checks the VNDK-Ext properties when PRODUCT_PRODUCT_VNDK_VERSION is not set.
  1365. ctx := testCcNoProductVndk(t, `
  1366. cc_library {
  1367. name: "libvndk",
  1368. vendor_available: true,
  1369. product_available: true,
  1370. vndk: {
  1371. enabled: true,
  1372. },
  1373. nocrt: true,
  1374. }
  1375. cc_library {
  1376. name: "libvndk_ext_product",
  1377. product_specific: true,
  1378. vndk: {
  1379. enabled: true,
  1380. extends: "libvndk",
  1381. },
  1382. nocrt: true,
  1383. }
  1384. `)
  1385. // Ensures that the core variant of "libvndk_ext_product" can be found.
  1386. mod := ctx.ModuleForTests("libvndk_ext_product", coreVariant).Module().(*Module)
  1387. if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
  1388. t.Errorf("\"libvndk_ext_product\" must extend from \"libvndk\" but get %q", extends)
  1389. }
  1390. }
  1391. func TestVndkExtError(t *testing.T) {
  1392. t.Parallel()
  1393. // This test ensures an error is emitted in ill-formed vndk-ext definition.
  1394. testCcError(t, "must set `vendor: true` or `product_specific: true` to set `extends: \".*\"`", `
  1395. cc_library {
  1396. name: "libvndk",
  1397. vendor_available: true,
  1398. product_available: true,
  1399. vndk: {
  1400. enabled: true,
  1401. },
  1402. nocrt: true,
  1403. }
  1404. cc_library {
  1405. name: "libvndk_ext",
  1406. vndk: {
  1407. enabled: true,
  1408. extends: "libvndk",
  1409. },
  1410. nocrt: true,
  1411. }
  1412. `)
  1413. testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
  1414. cc_library {
  1415. name: "libvndk",
  1416. vendor_available: true,
  1417. product_available: true,
  1418. vndk: {
  1419. enabled: true,
  1420. },
  1421. nocrt: true,
  1422. }
  1423. cc_library {
  1424. name: "libvndk_ext",
  1425. vendor: true,
  1426. vndk: {
  1427. enabled: true,
  1428. },
  1429. nocrt: true,
  1430. }
  1431. `)
  1432. testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
  1433. cc_library {
  1434. name: "libvndk",
  1435. vendor_available: true,
  1436. product_available: true,
  1437. vndk: {
  1438. enabled: true,
  1439. },
  1440. nocrt: true,
  1441. }
  1442. cc_library {
  1443. name: "libvndk_ext_product",
  1444. product_specific: true,
  1445. vndk: {
  1446. enabled: true,
  1447. },
  1448. nocrt: true,
  1449. }
  1450. `)
  1451. testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", `
  1452. cc_library {
  1453. name: "libvndk",
  1454. vendor_available: true,
  1455. product_available: true,
  1456. vndk: {
  1457. enabled: true,
  1458. },
  1459. nocrt: true,
  1460. }
  1461. cc_library {
  1462. name: "libvndk_ext_product",
  1463. product_specific: true,
  1464. vendor_available: true,
  1465. product_available: true,
  1466. vndk: {
  1467. enabled: true,
  1468. extends: "libvndk",
  1469. },
  1470. nocrt: true,
  1471. }
  1472. `)
  1473. }
  1474. func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) {
  1475. t.Parallel()
  1476. // This test ensures an error is emitted for inconsistent support_system_process.
  1477. testCcError(t, "module \".*\" with mismatched support_system_process", `
  1478. cc_library {
  1479. name: "libvndk",
  1480. vendor_available: true,
  1481. product_available: true,
  1482. vndk: {
  1483. enabled: true,
  1484. },
  1485. nocrt: true,
  1486. }
  1487. cc_library {
  1488. name: "libvndk_sp_ext",
  1489. vendor: true,
  1490. vndk: {
  1491. enabled: true,
  1492. extends: "libvndk",
  1493. support_system_process: true,
  1494. },
  1495. nocrt: true,
  1496. }
  1497. `)
  1498. testCcError(t, "module \".*\" with mismatched support_system_process", `
  1499. cc_library {
  1500. name: "libvndk_sp",
  1501. vendor_available: true,
  1502. product_available: true,
  1503. vndk: {
  1504. enabled: true,
  1505. support_system_process: true,
  1506. },
  1507. nocrt: true,
  1508. }
  1509. cc_library {
  1510. name: "libvndk_ext",
  1511. vendor: true,
  1512. vndk: {
  1513. enabled: true,
  1514. extends: "libvndk_sp",
  1515. },
  1516. nocrt: true,
  1517. }
  1518. `)
  1519. }
  1520. func TestVndkExtVendorAvailableFalseError(t *testing.T) {
  1521. t.Parallel()
  1522. // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library
  1523. // with `private: true`.
  1524. testCcError(t, "`extends` refers module \".*\" which has `private: true`", `
  1525. cc_library {
  1526. name: "libvndk",
  1527. vendor_available: true,
  1528. product_available: true,
  1529. vndk: {
  1530. enabled: true,
  1531. private: true,
  1532. },
  1533. nocrt: true,
  1534. }
  1535. cc_library {
  1536. name: "libvndk_ext",
  1537. vendor: true,
  1538. vndk: {
  1539. enabled: true,
  1540. extends: "libvndk",
  1541. },
  1542. nocrt: true,
  1543. }
  1544. `)
  1545. testCcErrorProductVndk(t, "`extends` refers module \".*\" which has `private: true`", `
  1546. cc_library {
  1547. name: "libvndk",
  1548. vendor_available: true,
  1549. product_available: true,
  1550. vndk: {
  1551. enabled: true,
  1552. private: true,
  1553. },
  1554. nocrt: true,
  1555. }
  1556. cc_library {
  1557. name: "libvndk_ext_product",
  1558. product_specific: true,
  1559. vndk: {
  1560. enabled: true,
  1561. extends: "libvndk",
  1562. },
  1563. nocrt: true,
  1564. }
  1565. `)
  1566. }
  1567. func TestVendorModuleUseVndkExt(t *testing.T) {
  1568. t.Parallel()
  1569. // This test ensures a vendor module can depend on a VNDK-Ext library.
  1570. testCc(t, `
  1571. cc_library {
  1572. name: "libvndk",
  1573. vendor_available: true,
  1574. product_available: true,
  1575. vndk: {
  1576. enabled: true,
  1577. },
  1578. nocrt: true,
  1579. }
  1580. cc_library {
  1581. name: "libvndk_ext",
  1582. vendor: true,
  1583. vndk: {
  1584. enabled: true,
  1585. extends: "libvndk",
  1586. },
  1587. nocrt: true,
  1588. }
  1589. cc_library {
  1590. name: "libvndk_sp",
  1591. vendor_available: true,
  1592. product_available: true,
  1593. vndk: {
  1594. enabled: true,
  1595. support_system_process: true,
  1596. },
  1597. nocrt: true,
  1598. }
  1599. cc_library {
  1600. name: "libvndk_sp_ext",
  1601. vendor: true,
  1602. vndk: {
  1603. enabled: true,
  1604. extends: "libvndk_sp",
  1605. support_system_process: true,
  1606. },
  1607. nocrt: true,
  1608. }
  1609. cc_library {
  1610. name: "libvendor",
  1611. vendor: true,
  1612. shared_libs: ["libvndk_ext", "libvndk_sp_ext"],
  1613. nocrt: true,
  1614. }
  1615. `)
  1616. }
  1617. func TestVndkExtUseVendorLib(t *testing.T) {
  1618. t.Parallel()
  1619. // This test ensures a VNDK-Ext library can depend on a vendor library.
  1620. testCc(t, `
  1621. cc_library {
  1622. name: "libvndk",
  1623. vendor_available: true,
  1624. product_available: true,
  1625. vndk: {
  1626. enabled: true,
  1627. },
  1628. nocrt: true,
  1629. }
  1630. cc_library {
  1631. name: "libvndk_ext",
  1632. vendor: true,
  1633. vndk: {
  1634. enabled: true,
  1635. extends: "libvndk",
  1636. },
  1637. shared_libs: ["libvendor"],
  1638. nocrt: true,
  1639. }
  1640. cc_library {
  1641. name: "libvendor",
  1642. vendor: true,
  1643. nocrt: true,
  1644. }
  1645. `)
  1646. // This test ensures a VNDK-SP-Ext library can depend on a vendor library.
  1647. testCc(t, `
  1648. cc_library {
  1649. name: "libvndk_sp",
  1650. vendor_available: true,
  1651. product_available: true,
  1652. vndk: {
  1653. enabled: true,
  1654. support_system_process: true,
  1655. },
  1656. nocrt: true,
  1657. }
  1658. cc_library {
  1659. name: "libvndk_sp_ext",
  1660. vendor: true,
  1661. vndk: {
  1662. enabled: true,
  1663. extends: "libvndk_sp",
  1664. support_system_process: true,
  1665. },
  1666. shared_libs: ["libvendor"], // Cause an error
  1667. nocrt: true,
  1668. }
  1669. cc_library {
  1670. name: "libvendor",
  1671. vendor: true,
  1672. nocrt: true,
  1673. }
  1674. `)
  1675. }
  1676. func TestProductVndkExtDependency(t *testing.T) {
  1677. t.Parallel()
  1678. bp := `
  1679. cc_library {
  1680. name: "libvndk",
  1681. vendor_available: true,
  1682. product_available: true,
  1683. vndk: {
  1684. enabled: true,
  1685. },
  1686. nocrt: true,
  1687. }
  1688. cc_library {
  1689. name: "libvndk_ext_product",
  1690. product_specific: true,
  1691. vndk: {
  1692. enabled: true,
  1693. extends: "libvndk",
  1694. },
  1695. shared_libs: ["libproduct_for_vndklibs"],
  1696. nocrt: true,
  1697. }
  1698. cc_library {
  1699. name: "libvndk_sp",
  1700. vendor_available: true,
  1701. product_available: true,
  1702. vndk: {
  1703. enabled: true,
  1704. support_system_process: true,
  1705. },
  1706. nocrt: true,
  1707. }
  1708. cc_library {
  1709. name: "libvndk_sp_ext_product",
  1710. product_specific: true,
  1711. vndk: {
  1712. enabled: true,
  1713. extends: "libvndk_sp",
  1714. support_system_process: true,
  1715. },
  1716. shared_libs: ["libproduct_for_vndklibs"],
  1717. nocrt: true,
  1718. }
  1719. cc_library {
  1720. name: "libproduct",
  1721. product_specific: true,
  1722. shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"],
  1723. nocrt: true,
  1724. }
  1725. cc_library {
  1726. name: "libproduct_for_vndklibs",
  1727. product_specific: true,
  1728. nocrt: true,
  1729. }
  1730. `
  1731. config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
  1732. config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
  1733. config.TestProductVariables.ProductVndkVersion = StringPtr("current")
  1734. config.TestProductVariables.Platform_vndk_version = StringPtr("29")
  1735. testCcWithConfig(t, config)
  1736. }
  1737. func TestVndkSpExtUseVndkError(t *testing.T) {
  1738. t.Parallel()
  1739. // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK
  1740. // library.
  1741. testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
  1742. cc_library {
  1743. name: "libvndk",
  1744. vendor_available: true,
  1745. product_available: true,
  1746. vndk: {
  1747. enabled: true,
  1748. },
  1749. nocrt: true,
  1750. }
  1751. cc_library {
  1752. name: "libvndk_sp",
  1753. vendor_available: true,
  1754. product_available: true,
  1755. vndk: {
  1756. enabled: true,
  1757. support_system_process: true,
  1758. },
  1759. nocrt: true,
  1760. }
  1761. cc_library {
  1762. name: "libvndk_sp_ext",
  1763. vendor: true,
  1764. vndk: {
  1765. enabled: true,
  1766. extends: "libvndk_sp",
  1767. support_system_process: true,
  1768. },
  1769. shared_libs: ["libvndk"], // Cause an error
  1770. nocrt: true,
  1771. }
  1772. `)
  1773. // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext
  1774. // library.
  1775. testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
  1776. cc_library {
  1777. name: "libvndk",
  1778. vendor_available: true,
  1779. product_available: true,
  1780. vndk: {
  1781. enabled: true,
  1782. },
  1783. nocrt: true,
  1784. }
  1785. cc_library {
  1786. name: "libvndk_ext",
  1787. vendor: true,
  1788. vndk: {
  1789. enabled: true,
  1790. extends: "libvndk",
  1791. },
  1792. nocrt: true,
  1793. }
  1794. cc_library {
  1795. name: "libvndk_sp",
  1796. vendor_available: true,
  1797. product_available: true,
  1798. vndk: {
  1799. enabled: true,
  1800. support_system_process: true,
  1801. },
  1802. nocrt: true,
  1803. }
  1804. cc_library {
  1805. name: "libvndk_sp_ext",
  1806. vendor: true,
  1807. vndk: {
  1808. enabled: true,
  1809. extends: "libvndk_sp",
  1810. support_system_process: true,
  1811. },
  1812. shared_libs: ["libvndk_ext"], // Cause an error
  1813. nocrt: true,
  1814. }
  1815. `)
  1816. }
  1817. func TestVndkUseVndkExtError(t *testing.T) {
  1818. t.Parallel()
  1819. // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a
  1820. // VNDK-Ext/VNDK-SP-Ext library.
  1821. testCcError(t, "dependency \".*\" of \".*\" missing variant", `
  1822. cc_library {
  1823. name: "libvndk",
  1824. vendor_available: true,
  1825. product_available: true,
  1826. vndk: {
  1827. enabled: true,
  1828. },
  1829. nocrt: true,
  1830. }
  1831. cc_library {
  1832. name: "libvndk_ext",
  1833. vendor: true,
  1834. vndk: {
  1835. enabled: true,
  1836. extends: "libvndk",
  1837. },
  1838. nocrt: true,
  1839. }
  1840. cc_library {
  1841. name: "libvndk2",
  1842. vendor_available: true,
  1843. product_available: true,
  1844. vndk: {
  1845. enabled: true,
  1846. },
  1847. shared_libs: ["libvndk_ext"],
  1848. nocrt: true,
  1849. }
  1850. `)
  1851. testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
  1852. cc_library {
  1853. name: "libvndk",
  1854. vendor_available: true,
  1855. product_available: true,
  1856. vndk: {
  1857. enabled: true,
  1858. },
  1859. nocrt: true,
  1860. }
  1861. cc_library {
  1862. name: "libvndk_ext",
  1863. vendor: true,
  1864. vndk: {
  1865. enabled: true,
  1866. extends: "libvndk",
  1867. },
  1868. nocrt: true,
  1869. }
  1870. cc_library {
  1871. name: "libvndk2",
  1872. vendor_available: true,
  1873. vndk: {
  1874. enabled: true,
  1875. },
  1876. target: {
  1877. vendor: {
  1878. shared_libs: ["libvndk_ext"],
  1879. },
  1880. },
  1881. nocrt: true,
  1882. }
  1883. `)
  1884. testCcError(t, "dependency \".*\" of \".*\" missing variant", `
  1885. cc_library {
  1886. name: "libvndk_sp",
  1887. vendor_available: true,
  1888. product_available: true,
  1889. vndk: {
  1890. enabled: true,
  1891. support_system_process: true,
  1892. },
  1893. nocrt: true,
  1894. }
  1895. cc_library {
  1896. name: "libvndk_sp_ext",
  1897. vendor: true,
  1898. vndk: {
  1899. enabled: true,
  1900. extends: "libvndk_sp",
  1901. support_system_process: true,
  1902. },
  1903. nocrt: true,
  1904. }
  1905. cc_library {
  1906. name: "libvndk_sp_2",
  1907. vendor_available: true,
  1908. product_available: true,
  1909. vndk: {
  1910. enabled: true,
  1911. support_system_process: true,
  1912. },
  1913. shared_libs: ["libvndk_sp_ext"],
  1914. nocrt: true,
  1915. }
  1916. `)
  1917. testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
  1918. cc_library {
  1919. name: "libvndk_sp",
  1920. vendor_available: true,
  1921. product_available: true,
  1922. vndk: {
  1923. enabled: true,
  1924. },
  1925. nocrt: true,
  1926. }
  1927. cc_library {
  1928. name: "libvndk_sp_ext",
  1929. vendor: true,
  1930. vndk: {
  1931. enabled: true,
  1932. extends: "libvndk_sp",
  1933. },
  1934. nocrt: true,
  1935. }
  1936. cc_library {
  1937. name: "libvndk_sp2",
  1938. vendor_available: true,
  1939. vndk: {
  1940. enabled: true,
  1941. },
  1942. target: {
  1943. vendor: {
  1944. shared_libs: ["libvndk_sp_ext"],
  1945. },
  1946. },
  1947. nocrt: true,
  1948. }
  1949. `)
  1950. }
  1951. func TestEnforceProductVndkVersion(t *testing.T) {
  1952. t.Parallel()
  1953. bp := `
  1954. cc_library {
  1955. name: "libllndk",
  1956. llndk: {
  1957. symbol_file: "libllndk.map.txt",
  1958. }
  1959. }
  1960. cc_library {
  1961. name: "libvndk",
  1962. vendor_available: true,
  1963. product_available: true,
  1964. vndk: {
  1965. enabled: true,
  1966. },
  1967. nocrt: true,
  1968. }
  1969. cc_library {
  1970. name: "libvndk_sp",
  1971. vendor_available: true,
  1972. product_available: true,
  1973. vndk: {
  1974. enabled: true,
  1975. support_system_process: true,
  1976. },
  1977. nocrt: true,
  1978. }
  1979. cc_library {
  1980. name: "libva",
  1981. vendor_available: true,
  1982. nocrt: true,
  1983. }
  1984. cc_library {
  1985. name: "libpa",
  1986. product_available: true,
  1987. nocrt: true,
  1988. }
  1989. cc_library {
  1990. name: "libboth_available",
  1991. vendor_available: true,
  1992. product_available: true,
  1993. nocrt: true,
  1994. srcs: ["foo.c"],
  1995. target: {
  1996. vendor: {
  1997. suffix: "-vendor",
  1998. },
  1999. product: {
  2000. suffix: "-product",
  2001. },
  2002. }
  2003. }
  2004. cc_library {
  2005. name: "libproduct_va",
  2006. product_specific: true,
  2007. vendor_available: true,
  2008. nocrt: true,
  2009. }
  2010. cc_library {
  2011. name: "libprod",
  2012. product_specific: true,
  2013. shared_libs: [
  2014. "libllndk",
  2015. "libvndk",
  2016. "libvndk_sp",
  2017. "libpa",
  2018. "libboth_available",
  2019. "libproduct_va",
  2020. ],
  2021. nocrt: true,
  2022. }
  2023. cc_library {
  2024. name: "libvendor",
  2025. vendor: true,
  2026. shared_libs: [
  2027. "libllndk",
  2028. "libvndk",
  2029. "libvndk_sp",
  2030. "libva",
  2031. "libboth_available",
  2032. "libproduct_va",
  2033. ],
  2034. nocrt: true,
  2035. }
  2036. `
  2037. ctx := prepareForCcTest.RunTestWithBp(t, bp).TestContext
  2038. checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant)
  2039. checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant)
  2040. mod_vendor := ctx.ModuleForTests("libboth_available", vendorVariant).Module().(*Module)
  2041. assertString(t, mod_vendor.outputFile.Path().Base(), "libboth_available-vendor.so")
  2042. mod_product := ctx.ModuleForTests("libboth_available", productVariant).Module().(*Module)
  2043. assertString(t, mod_product.outputFile.Path().Base(), "libboth_available-product.so")
  2044. ensureStringContains := func(t *testing.T, str string, substr string) {
  2045. t.Helper()
  2046. if !strings.Contains(str, substr) {
  2047. t.Errorf("%q is not found in %v", substr, str)
  2048. }
  2049. }
  2050. ensureStringNotContains := func(t *testing.T, str string, substr string) {
  2051. t.Helper()
  2052. if strings.Contains(str, substr) {
  2053. t.Errorf("%q is found in %v", substr, str)
  2054. }
  2055. }
  2056. // _static variant is used since _shared reuses *.o from the static variant
  2057. vendor_static := ctx.ModuleForTests("libboth_available", strings.Replace(vendorVariant, "_shared", "_static", 1))
  2058. product_static := ctx.ModuleForTests("libboth_available", strings.Replace(productVariant, "_shared", "_static", 1))
  2059. vendor_cflags := vendor_static.Rule("cc").Args["cFlags"]
  2060. ensureStringContains(t, vendor_cflags, "-D__ANDROID_VNDK__")
  2061. ensureStringContains(t, vendor_cflags, "-D__ANDROID_VENDOR__")
  2062. ensureStringNotContains(t, vendor_cflags, "-D__ANDROID_PRODUCT__")
  2063. product_cflags := product_static.Rule("cc").Args["cFlags"]
  2064. ensureStringContains(t, product_cflags, "-D__ANDROID_VNDK__")
  2065. ensureStringContains(t, product_cflags, "-D__ANDROID_PRODUCT__")
  2066. ensureStringNotContains(t, product_cflags, "-D__ANDROID_VENDOR__")
  2067. }
  2068. func TestEnforceProductVndkVersionErrors(t *testing.T) {
  2069. t.Parallel()
  2070. testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", `
  2071. cc_library {
  2072. name: "libprod",
  2073. product_specific: true,
  2074. shared_libs: [
  2075. "libvendor",
  2076. ],
  2077. nocrt: true,
  2078. }
  2079. cc_library {
  2080. name: "libvendor",
  2081. vendor: true,
  2082. nocrt: true,
  2083. }
  2084. `)
  2085. testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", `
  2086. cc_library {
  2087. name: "libprod",
  2088. product_specific: true,
  2089. shared_libs: [
  2090. "libsystem",
  2091. ],
  2092. nocrt: true,
  2093. }
  2094. cc_library {
  2095. name: "libsystem",
  2096. nocrt: true,
  2097. }
  2098. `)
  2099. testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", `
  2100. cc_library {
  2101. name: "libprod",
  2102. product_specific: true,
  2103. shared_libs: [
  2104. "libva",
  2105. ],
  2106. nocrt: true,
  2107. }
  2108. cc_library {
  2109. name: "libva",
  2110. vendor_available: true,
  2111. nocrt: true,
  2112. }
  2113. `)
  2114. testCcErrorProductVndk(t, "non-VNDK module should not link to \".*\" which has `private: true`", `
  2115. cc_library {
  2116. name: "libprod",
  2117. product_specific: true,
  2118. shared_libs: [
  2119. "libvndk_private",
  2120. ],
  2121. nocrt: true,
  2122. }
  2123. cc_library {
  2124. name: "libvndk_private",
  2125. vendor_available: true,
  2126. product_available: true,
  2127. vndk: {
  2128. enabled: true,
  2129. private: true,
  2130. },
  2131. nocrt: true,
  2132. }
  2133. `)
  2134. testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", `
  2135. cc_library {
  2136. name: "libprod",
  2137. product_specific: true,
  2138. shared_libs: [
  2139. "libsystem_ext",
  2140. ],
  2141. nocrt: true,
  2142. }
  2143. cc_library {
  2144. name: "libsystem_ext",
  2145. system_ext_specific: true,
  2146. nocrt: true,
  2147. }
  2148. `)
  2149. testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", `
  2150. cc_library {
  2151. name: "libsystem",
  2152. shared_libs: [
  2153. "libproduct_va",
  2154. ],
  2155. nocrt: true,
  2156. }
  2157. cc_library {
  2158. name: "libproduct_va",
  2159. product_specific: true,
  2160. vendor_available: true,
  2161. nocrt: true,
  2162. }
  2163. `)
  2164. }
  2165. func TestMakeLinkType(t *testing.T) {
  2166. t.Parallel()
  2167. bp := `
  2168. cc_library {
  2169. name: "libvndk",
  2170. vendor_available: true,
  2171. product_available: true,
  2172. vndk: {
  2173. enabled: true,
  2174. },
  2175. }
  2176. cc_library {
  2177. name: "libvndksp",
  2178. vendor_available: true,
  2179. product_available: true,
  2180. vndk: {
  2181. enabled: true,
  2182. support_system_process: true,
  2183. },
  2184. }
  2185. cc_library {
  2186. name: "libvndkprivate",
  2187. vendor_available: true,
  2188. product_available: true,
  2189. vndk: {
  2190. enabled: true,
  2191. private: true,
  2192. },
  2193. }
  2194. cc_library {
  2195. name: "libvendor",
  2196. vendor: true,
  2197. }
  2198. cc_library {
  2199. name: "libvndkext",
  2200. vendor: true,
  2201. vndk: {
  2202. enabled: true,
  2203. extends: "libvndk",
  2204. },
  2205. }
  2206. vndk_prebuilt_shared {
  2207. name: "prevndk",
  2208. version: "27",
  2209. target_arch: "arm",
  2210. binder32bit: true,
  2211. vendor_available: true,
  2212. product_available: true,
  2213. vndk: {
  2214. enabled: true,
  2215. },
  2216. arch: {
  2217. arm: {
  2218. srcs: ["liba.so"],
  2219. },
  2220. },
  2221. }
  2222. cc_library {
  2223. name: "libllndk",
  2224. llndk: {
  2225. symbol_file: "libllndk.map.txt",
  2226. }
  2227. }
  2228. cc_library {
  2229. name: "libllndkprivate",
  2230. llndk: {
  2231. symbol_file: "libllndkprivate.map.txt",
  2232. private: true,
  2233. }
  2234. }
  2235. llndk_libraries_txt {
  2236. name: "llndk.libraries.txt",
  2237. }
  2238. vndkcore_libraries_txt {
  2239. name: "vndkcore.libraries.txt",
  2240. }
  2241. vndksp_libraries_txt {
  2242. name: "vndksp.libraries.txt",
  2243. }
  2244. vndkprivate_libraries_txt {
  2245. name: "vndkprivate.libraries.txt",
  2246. }
  2247. vndkcorevariant_libraries_txt {
  2248. name: "vndkcorevariant.libraries.txt",
  2249. insert_vndk_version: false,
  2250. }
  2251. `
  2252. config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
  2253. config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
  2254. config.TestProductVariables.Platform_vndk_version = StringPtr("29")
  2255. // native:vndk
  2256. ctx := testCcWithConfig(t, config)
  2257. checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt",
  2258. []string{"libvndk.so", "libvndkprivate.so"})
  2259. checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt",
  2260. []string{"libc++.so", "libvndksp.so"})
  2261. checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt",
  2262. []string{"libc.so", "libdl.so", "libft2.so", "libllndk.so", "libllndkprivate.so", "libm.so"})
  2263. checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt",
  2264. []string{"libft2.so", "libllndkprivate.so", "libvndkprivate.so"})
  2265. vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared"
  2266. tests := []struct {
  2267. variant string
  2268. name string
  2269. expected string
  2270. }{
  2271. {vendorVariant, "libvndk", "native:vndk"},
  2272. {vendorVariant, "libvndksp", "native:vndk"},
  2273. {vendorVariant, "libvndkprivate", "native:vndk_private"},
  2274. {vendorVariant, "libvendor", "native:vendor"},
  2275. {vendorVariant, "libvndkext", "native:vendor"},
  2276. {vendorVariant, "libllndk", "native:vndk"},
  2277. {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"},
  2278. {coreVariant, "libvndk", "native:platform"},
  2279. {coreVariant, "libvndkprivate", "native:platform"},
  2280. {coreVariant, "libllndk", "native:platform"},
  2281. }
  2282. for _, test := range tests {
  2283. t.Run(test.name, func(t *testing.T) {
  2284. module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module)
  2285. assertString(t, module.makeLinkType, test.expected)
  2286. })
  2287. }
  2288. }
  2289. var staticLinkDepOrderTestCases = []struct {
  2290. // This is a string representation of a map[moduleName][]moduleDependency .
  2291. // It models the dependencies declared in an Android.bp file.
  2292. inStatic string
  2293. // This is a string representation of a map[moduleName][]moduleDependency .
  2294. // It models the dependencies declared in an Android.bp file.
  2295. inShared string
  2296. // allOrdered is a string representation of a map[moduleName][]moduleDependency .
  2297. // The keys of allOrdered specify which modules we would like to check.
  2298. // The values of allOrdered specify the expected result (of the transitive closure of all
  2299. // dependencies) for each module to test
  2300. allOrdered string
  2301. // outOrdered is a string representation of a map[moduleName][]moduleDependency .
  2302. // The keys of outOrdered specify which modules we would like to check.
  2303. // The values of outOrdered specify the expected result (of the ordered linker command line)
  2304. // for each module to test.
  2305. outOrdered string
  2306. }{
  2307. // Simple tests
  2308. {
  2309. inStatic: "",
  2310. outOrdered: "",
  2311. },
  2312. {
  2313. inStatic: "a:",
  2314. outOrdered: "a:",
  2315. },
  2316. {
  2317. inStatic: "a:b; b:",
  2318. outOrdered: "a:b; b:",
  2319. },
  2320. // Tests of reordering
  2321. {
  2322. // diamond example
  2323. inStatic: "a:d,b,c; b:d; c:d; d:",
  2324. outOrdered: "a:b,c,d; b:d; c:d; d:",
  2325. },
  2326. {
  2327. // somewhat real example
  2328. inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b",
  2329. outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b",
  2330. },
  2331. {
  2332. // multiple reorderings
  2333. inStatic: "a:b,c,d,e; d:b; e:c",
  2334. outOrdered: "a:d,b,e,c; d:b; e:c",
  2335. },
  2336. {
  2337. // should reorder without adding new transitive dependencies
  2338. inStatic: "bin:lib2,lib1; lib1:lib2,liboptional",
  2339. allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional",
  2340. outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional",
  2341. },
  2342. {
  2343. // multiple levels of dependencies
  2344. inStatic: "a:b,c,d,e,f,g,h; f:b,c,d; b:c,d; c:d",
  2345. allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
  2346. outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
  2347. },
  2348. // shared dependencies
  2349. {
  2350. // Note that this test doesn't recurse, to minimize the amount of logic it tests.
  2351. // So, we don't actually have to check that a shared dependency of c will change the order
  2352. // of a library that depends statically on b and on c. We only need to check that if c has
  2353. // a shared dependency on b, that that shows up in allOrdered.
  2354. inShared: "c:b",
  2355. allOrdered: "c:b",
  2356. outOrdered: "c:",
  2357. },
  2358. {
  2359. // This test doesn't actually include any shared dependencies but it's a reminder of what
  2360. // the second phase of the above test would look like
  2361. inStatic: "a:b,c; c:b",
  2362. allOrdered: "a:c,b; c:b",
  2363. outOrdered: "a:c,b; c:b",
  2364. },
  2365. // tiebreakers for when two modules specifying different orderings and there is no dependency
  2366. // to dictate an order
  2367. {
  2368. // if the tie is between two modules at the end of a's deps, then a's order wins
  2369. inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
  2370. outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
  2371. },
  2372. {
  2373. // if the tie is between two modules at the start of a's deps, then c's order is used
  2374. inStatic: "a1:d,e,b1,c1; b1:d,e; c1:e,d; a2:d,e,b2,c2; b2:d,e; c2:d,e",
  2375. outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e",
  2376. },
  2377. // Tests involving duplicate dependencies
  2378. {
  2379. // simple duplicate
  2380. inStatic: "a:b,c,c,b",
  2381. outOrdered: "a:c,b",
  2382. },
  2383. {
  2384. // duplicates with reordering
  2385. inStatic: "a:b,c,d,c; c:b",
  2386. outOrdered: "a:d,c,b",
  2387. },
  2388. // Tests to confirm the nonexistence of infinite loops.
  2389. // These cases should never happen, so as long as the test terminates and the
  2390. // result is deterministic then that should be fine.
  2391. {
  2392. inStatic: "a:a",
  2393. outOrdered: "a:a",
  2394. },
  2395. {
  2396. inStatic: "a:b; b:c; c:a",
  2397. allOrdered: "a:b,c; b:c,a; c:a,b",
  2398. outOrdered: "a:b; b:c; c:a",
  2399. },
  2400. {
  2401. inStatic: "a:b,c; b:c,a; c:a,b",
  2402. allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a",
  2403. outOrdered: "a:c,b; b:a,c; c:b,a",
  2404. },
  2405. }
  2406. // converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}])
  2407. func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) {
  2408. // convert from "a:b,c; d:e" to "a:b,c;d:e"
  2409. strippedText := strings.Replace(text, " ", "", -1)
  2410. if len(strippedText) < 1 {
  2411. return []android.Path{}, make(map[android.Path][]android.Path, 0)
  2412. }
  2413. allDeps = make(map[android.Path][]android.Path, 0)
  2414. // convert from "a:b,c;d:e" to ["a:b,c", "d:e"]
  2415. moduleTexts := strings.Split(strippedText, ";")
  2416. outputForModuleName := func(moduleName string) android.Path {
  2417. return android.PathForTesting(moduleName)
  2418. }
  2419. for _, moduleText := range moduleTexts {
  2420. // convert from "a:b,c" to ["a", "b,c"]
  2421. components := strings.Split(moduleText, ":")
  2422. if len(components) != 2 {
  2423. panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1))
  2424. }
  2425. moduleName := components[0]
  2426. moduleOutput := outputForModuleName(moduleName)
  2427. modulesInOrder = append(modulesInOrder, moduleOutput)
  2428. depString := components[1]
  2429. // convert from "b,c" to ["b", "c"]
  2430. depNames := strings.Split(depString, ",")
  2431. if len(depString) < 1 {
  2432. depNames = []string{}
  2433. }
  2434. var deps []android.Path
  2435. for _, depName := range depNames {
  2436. deps = append(deps, outputForModuleName(depName))
  2437. }
  2438. allDeps[moduleOutput] = deps
  2439. }
  2440. return modulesInOrder, allDeps
  2441. }
  2442. func TestStaticLibDepReordering(t *testing.T) {
  2443. t.Parallel()
  2444. ctx := testCc(t, `
  2445. cc_library {
  2446. name: "a",
  2447. static_libs: ["b", "c", "d"],
  2448. stl: "none",
  2449. }
  2450. cc_library {
  2451. name: "b",
  2452. stl: "none",
  2453. }
  2454. cc_library {
  2455. name: "c",
  2456. static_libs: ["b"],
  2457. stl: "none",
  2458. }
  2459. cc_library {
  2460. name: "d",
  2461. stl: "none",
  2462. }
  2463. `)
  2464. variant := "android_arm64_armv8-a_static"
  2465. moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
  2466. actual := android.Paths(ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).
  2467. TransitiveStaticLibrariesForOrdering.ToList()).RelativeToTop()
  2468. expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b", "d"})
  2469. if !reflect.DeepEqual(actual, expected) {
  2470. t.Errorf("staticDeps orderings were not propagated correctly"+
  2471. "\nactual: %v"+
  2472. "\nexpected: %v",
  2473. actual,
  2474. expected,
  2475. )
  2476. }
  2477. }
  2478. func TestStaticLibDepReorderingWithShared(t *testing.T) {
  2479. t.Parallel()
  2480. ctx := testCc(t, `
  2481. cc_library {
  2482. name: "a",
  2483. static_libs: ["b", "c"],
  2484. stl: "none",
  2485. }
  2486. cc_library {
  2487. name: "b",
  2488. stl: "none",
  2489. }
  2490. cc_library {
  2491. name: "c",
  2492. shared_libs: ["b"],
  2493. stl: "none",
  2494. }
  2495. `)
  2496. variant := "android_arm64_armv8-a_static"
  2497. moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
  2498. actual := android.Paths(ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).
  2499. TransitiveStaticLibrariesForOrdering.ToList()).RelativeToTop()
  2500. expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b"})
  2501. if !reflect.DeepEqual(actual, expected) {
  2502. t.Errorf("staticDeps orderings did not account for shared libs"+
  2503. "\nactual: %v"+
  2504. "\nexpected: %v",
  2505. actual,
  2506. expected,
  2507. )
  2508. }
  2509. }
  2510. func checkEquals(t *testing.T, message string, expected, actual interface{}) {
  2511. t.Helper()
  2512. if !reflect.DeepEqual(actual, expected) {
  2513. t.Errorf(message+
  2514. "\nactual: %v"+
  2515. "\nexpected: %v",
  2516. actual,
  2517. expected,
  2518. )
  2519. }
  2520. }
  2521. func TestLlndkLibrary(t *testing.T) {
  2522. t.Parallel()
  2523. result := prepareForCcTest.RunTestWithBp(t, `
  2524. cc_library {
  2525. name: "libllndk",
  2526. stubs: { versions: ["1", "2"] },
  2527. llndk: {
  2528. symbol_file: "libllndk.map.txt",
  2529. },
  2530. export_include_dirs: ["include"],
  2531. }
  2532. cc_prebuilt_library_shared {
  2533. name: "libllndkprebuilt",
  2534. stubs: { versions: ["1", "2"] },
  2535. llndk: {
  2536. symbol_file: "libllndkprebuilt.map.txt",
  2537. },
  2538. }
  2539. cc_library {
  2540. name: "libllndk_with_external_headers",
  2541. stubs: { versions: ["1", "2"] },
  2542. llndk: {
  2543. symbol_file: "libllndk.map.txt",
  2544. export_llndk_headers: ["libexternal_llndk_headers"],
  2545. },
  2546. header_libs: ["libexternal_headers"],
  2547. export_header_lib_headers: ["libexternal_headers"],
  2548. }
  2549. cc_library_headers {
  2550. name: "libexternal_headers",
  2551. export_include_dirs: ["include"],
  2552. vendor_available: true,
  2553. }
  2554. cc_library_headers {
  2555. name: "libexternal_llndk_headers",
  2556. export_include_dirs: ["include_llndk"],
  2557. llndk: {
  2558. symbol_file: "libllndk.map.txt",
  2559. },
  2560. vendor_available: true,
  2561. }
  2562. cc_library {
  2563. name: "libllndk_with_override_headers",
  2564. stubs: { versions: ["1", "2"] },
  2565. llndk: {
  2566. symbol_file: "libllndk.map.txt",
  2567. override_export_include_dirs: ["include_llndk"],
  2568. },
  2569. export_include_dirs: ["include"],
  2570. }
  2571. `)
  2572. actual := result.ModuleVariantsForTests("libllndk")
  2573. for i := 0; i < len(actual); i++ {
  2574. if !strings.HasPrefix(actual[i], "android_vendor.29_") {
  2575. actual = append(actual[:i], actual[i+1:]...)
  2576. i--
  2577. }
  2578. }
  2579. expected := []string{
  2580. "android_vendor.29_arm64_armv8-a_shared_current",
  2581. "android_vendor.29_arm64_armv8-a_shared",
  2582. "android_vendor.29_arm_armv7-a-neon_shared_current",
  2583. "android_vendor.29_arm_armv7-a-neon_shared",
  2584. }
  2585. android.AssertArrayString(t, "variants for llndk stubs", expected, actual)
  2586. params := result.ModuleForTests("libllndk", "android_vendor.29_arm_armv7-a-neon_shared").Description("generate stub")
  2587. android.AssertSame(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"])
  2588. checkExportedIncludeDirs := func(module, variant string, expectedDirs ...string) {
  2589. t.Helper()
  2590. m := result.ModuleForTests(module, variant).Module()
  2591. f := result.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo)
  2592. android.AssertPathsRelativeToTopEquals(t, "exported include dirs for "+module+"["+variant+"]",
  2593. expectedDirs, f.IncludeDirs)
  2594. }
  2595. checkExportedIncludeDirs("libllndk", "android_arm64_armv8-a_shared", "include")
  2596. checkExportedIncludeDirs("libllndk", "android_vendor.29_arm64_armv8-a_shared", "include")
  2597. checkExportedIncludeDirs("libllndk_with_external_headers", "android_arm64_armv8-a_shared", "include")
  2598. checkExportedIncludeDirs("libllndk_with_external_headers", "android_vendor.29_arm64_armv8-a_shared", "include_llndk")
  2599. checkExportedIncludeDirs("libllndk_with_override_headers", "android_arm64_armv8-a_shared", "include")
  2600. checkExportedIncludeDirs("libllndk_with_override_headers", "android_vendor.29_arm64_armv8-a_shared", "include_llndk")
  2601. }
  2602. func TestLlndkHeaders(t *testing.T) {
  2603. t.Parallel()
  2604. ctx := testCc(t, `
  2605. cc_library_headers {
  2606. name: "libllndk_headers",
  2607. export_include_dirs: ["my_include"],
  2608. llndk: {
  2609. llndk_headers: true,
  2610. },
  2611. }
  2612. cc_library {
  2613. name: "libllndk",
  2614. llndk: {
  2615. symbol_file: "libllndk.map.txt",
  2616. export_llndk_headers: ["libllndk_headers"],
  2617. }
  2618. }
  2619. cc_library {
  2620. name: "libvendor",
  2621. shared_libs: ["libllndk"],
  2622. vendor: true,
  2623. srcs: ["foo.c"],
  2624. no_libcrt: true,
  2625. nocrt: true,
  2626. }
  2627. `)
  2628. // _static variant is used since _shared reuses *.o from the static variant
  2629. cc := ctx.ModuleForTests("libvendor", "android_vendor.29_arm_armv7-a-neon_static").Rule("cc")
  2630. cflags := cc.Args["cFlags"]
  2631. if !strings.Contains(cflags, "-Imy_include") {
  2632. t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags)
  2633. }
  2634. }
  2635. func checkRuntimeLibs(t *testing.T, expected []string, module *Module) {
  2636. actual := module.Properties.AndroidMkRuntimeLibs
  2637. if !reflect.DeepEqual(actual, expected) {
  2638. t.Errorf("incorrect runtime_libs for shared libs"+
  2639. "\nactual: %v"+
  2640. "\nexpected: %v",
  2641. actual,
  2642. expected,
  2643. )
  2644. }
  2645. }
  2646. const runtimeLibAndroidBp = `
  2647. cc_library {
  2648. name: "liball_available",
  2649. vendor_available: true,
  2650. product_available: true,
  2651. no_libcrt : true,
  2652. nocrt : true,
  2653. system_shared_libs : [],
  2654. }
  2655. cc_library {
  2656. name: "libvendor_available1",
  2657. vendor_available: true,
  2658. runtime_libs: ["liball_available"],
  2659. no_libcrt : true,
  2660. nocrt : true,
  2661. system_shared_libs : [],
  2662. }
  2663. cc_library {
  2664. name: "libvendor_available2",
  2665. vendor_available: true,
  2666. runtime_libs: ["liball_available"],
  2667. target: {
  2668. vendor: {
  2669. exclude_runtime_libs: ["liball_available"],
  2670. }
  2671. },
  2672. no_libcrt : true,
  2673. nocrt : true,
  2674. system_shared_libs : [],
  2675. }
  2676. cc_library {
  2677. name: "libproduct_vendor",
  2678. product_specific: true,
  2679. vendor_available: true,
  2680. no_libcrt : true,
  2681. nocrt : true,
  2682. system_shared_libs : [],
  2683. }
  2684. cc_library {
  2685. name: "libcore",
  2686. runtime_libs: ["liball_available"],
  2687. no_libcrt : true,
  2688. nocrt : true,
  2689. system_shared_libs : [],
  2690. }
  2691. cc_library {
  2692. name: "libvendor1",
  2693. vendor: true,
  2694. no_libcrt : true,
  2695. nocrt : true,
  2696. system_shared_libs : [],
  2697. }
  2698. cc_library {
  2699. name: "libvendor2",
  2700. vendor: true,
  2701. runtime_libs: ["liball_available", "libvendor1", "libproduct_vendor"],
  2702. no_libcrt : true,
  2703. nocrt : true,
  2704. system_shared_libs : [],
  2705. }
  2706. cc_library {
  2707. name: "libproduct_available1",
  2708. product_available: true,
  2709. runtime_libs: ["liball_available"],
  2710. no_libcrt : true,
  2711. nocrt : true,
  2712. system_shared_libs : [],
  2713. }
  2714. cc_library {
  2715. name: "libproduct1",
  2716. product_specific: true,
  2717. no_libcrt : true,
  2718. nocrt : true,
  2719. system_shared_libs : [],
  2720. }
  2721. cc_library {
  2722. name: "libproduct2",
  2723. product_specific: true,
  2724. runtime_libs: ["liball_available", "libproduct1", "libproduct_vendor"],
  2725. no_libcrt : true,
  2726. nocrt : true,
  2727. system_shared_libs : [],
  2728. }
  2729. `
  2730. func TestRuntimeLibs(t *testing.T) {
  2731. t.Parallel()
  2732. ctx := testCc(t, runtimeLibAndroidBp)
  2733. // runtime_libs for core variants use the module names without suffixes.
  2734. variant := "android_arm64_armv8-a_shared"
  2735. module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
  2736. checkRuntimeLibs(t, []string{"liball_available"}, module)
  2737. module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
  2738. checkRuntimeLibs(t, []string{"liball_available"}, module)
  2739. module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
  2740. checkRuntimeLibs(t, []string{"liball_available"}, module)
  2741. // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
  2742. // and vendor variants.
  2743. variant = "android_vendor.29_arm64_armv8-a_shared"
  2744. module = ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
  2745. checkRuntimeLibs(t, []string{"liball_available.vendor"}, module)
  2746. module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
  2747. checkRuntimeLibs(t, []string{"liball_available.vendor", "libvendor1", "libproduct_vendor.vendor"}, module)
  2748. // runtime_libs for product variants have '.product' suffixes if the modules have both core
  2749. // and product variants.
  2750. variant = "android_product.29_arm64_armv8-a_shared"
  2751. module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
  2752. checkRuntimeLibs(t, []string{"liball_available.product"}, module)
  2753. module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
  2754. checkRuntimeLibs(t, []string{"liball_available.product", "libproduct1", "libproduct_vendor"}, module)
  2755. }
  2756. func TestExcludeRuntimeLibs(t *testing.T) {
  2757. t.Parallel()
  2758. ctx := testCc(t, runtimeLibAndroidBp)
  2759. variant := "android_arm64_armv8-a_shared"
  2760. module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
  2761. checkRuntimeLibs(t, []string{"liball_available"}, module)
  2762. variant = "android_vendor.29_arm64_armv8-a_shared"
  2763. module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
  2764. checkRuntimeLibs(t, nil, module)
  2765. }
  2766. func TestRuntimeLibsNoVndk(t *testing.T) {
  2767. t.Parallel()
  2768. ctx := testCcNoVndk(t, runtimeLibAndroidBp)
  2769. // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
  2770. variant := "android_arm64_armv8-a_shared"
  2771. module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
  2772. checkRuntimeLibs(t, []string{"liball_available"}, module)
  2773. module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
  2774. checkRuntimeLibs(t, []string{"liball_available", "libvendor1", "libproduct_vendor"}, module)
  2775. module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
  2776. checkRuntimeLibs(t, []string{"liball_available", "libproduct1", "libproduct_vendor"}, module)
  2777. }
  2778. func checkStaticLibs(t *testing.T, expected []string, module *Module) {
  2779. t.Helper()
  2780. actual := module.Properties.AndroidMkStaticLibs
  2781. if !reflect.DeepEqual(actual, expected) {
  2782. t.Errorf("incorrect static_libs"+
  2783. "\nactual: %v"+
  2784. "\nexpected: %v",
  2785. actual,
  2786. expected,
  2787. )
  2788. }
  2789. }
  2790. const staticLibAndroidBp = `
  2791. cc_library {
  2792. name: "lib1",
  2793. }
  2794. cc_library {
  2795. name: "lib2",
  2796. static_libs: ["lib1"],
  2797. }
  2798. `
  2799. func TestStaticLibDepExport(t *testing.T) {
  2800. t.Parallel()
  2801. ctx := testCc(t, staticLibAndroidBp)
  2802. // Check the shared version of lib2.
  2803. variant := "android_arm64_armv8-a_shared"
  2804. module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
  2805. checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins"}, module)
  2806. // Check the static version of lib2.
  2807. variant = "android_arm64_armv8-a_static"
  2808. module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
  2809. // libc++_static is linked additionally.
  2810. checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins"}, module)
  2811. }
  2812. func TestLibDepAndroidMkExportInMixedBuilds(t *testing.T) {
  2813. bp := `
  2814. cc_library {
  2815. name: "static_dep",
  2816. }
  2817. cc_library {
  2818. name: "whole_static_dep",
  2819. }
  2820. cc_library {
  2821. name: "shared_dep",
  2822. }
  2823. cc_library {
  2824. name: "lib",
  2825. bazel_module: { label: "//:lib" },
  2826. static_libs: ["static_dep"],
  2827. whole_static_libs: ["whole_static_dep"],
  2828. shared_libs: ["shared_dep"],
  2829. }
  2830. cc_test {
  2831. name: "test",
  2832. bazel_module: { label: "//:test" },
  2833. static_libs: ["static_dep"],
  2834. whole_static_libs: ["whole_static_dep"],
  2835. shared_libs: ["shared_dep"],
  2836. gtest: false,
  2837. sanitize: {
  2838. // cc_test modules default to memtag_heap: true,
  2839. // but this adds extra dependencies that we don't care about
  2840. never: true,
  2841. }
  2842. }
  2843. cc_binary {
  2844. name: "binary",
  2845. bazel_module: { label: "//:binary" },
  2846. static_libs: ["static_dep"],
  2847. whole_static_libs: ["whole_static_dep"],
  2848. shared_libs: ["shared_dep"],
  2849. }
  2850. cc_library_headers {
  2851. name: "lib_headers",
  2852. bazel_module: { label: "//:lib_headers" },
  2853. static_libs: ["static_dep"],
  2854. whole_static_libs: ["whole_static_dep"],
  2855. shared_libs: ["shared_dep"],
  2856. }
  2857. cc_prebuilt_library {
  2858. name: "lib_prebuilt",
  2859. bazel_module: { label: "//:lib_prebuilt" },
  2860. static_libs: ["static_dep"],
  2861. whole_static_libs: ["whole_static_dep"],
  2862. shared_libs: ["shared_dep"],
  2863. }
  2864. `
  2865. testCases := []struct {
  2866. name string
  2867. moduleName string
  2868. variant string
  2869. androidMkInfo cquery.CcAndroidMkInfo
  2870. }{
  2871. {
  2872. name: "shared lib",
  2873. moduleName: "lib",
  2874. variant: "android_arm64_armv8-a_shared",
  2875. androidMkInfo: cquery.CcAndroidMkInfo{
  2876. LocalStaticLibs: []string{"static_dep"},
  2877. LocalWholeStaticLibs: []string{"whole_static_dep"},
  2878. LocalSharedLibs: []string{"shared_dep"},
  2879. },
  2880. },
  2881. {
  2882. name: "static lib",
  2883. moduleName: "lib",
  2884. variant: "android_arm64_armv8-a_static",
  2885. androidMkInfo: cquery.CcAndroidMkInfo{
  2886. LocalStaticLibs: []string{"static_dep"},
  2887. LocalWholeStaticLibs: []string{"whole_static_dep"},
  2888. LocalSharedLibs: []string{"shared_dep"},
  2889. },
  2890. },
  2891. {
  2892. name: "cc_test arm64",
  2893. moduleName: "test",
  2894. variant: "android_arm64_armv8-a",
  2895. androidMkInfo: cquery.CcAndroidMkInfo{
  2896. LocalStaticLibs: []string{"static_dep"},
  2897. LocalWholeStaticLibs: []string{"whole_static_dep"},
  2898. LocalSharedLibs: []string{"shared_dep"},
  2899. },
  2900. },
  2901. {
  2902. name: "cc_test arm",
  2903. moduleName: "test",
  2904. variant: "android_arm_armv7-a-neon",
  2905. androidMkInfo: cquery.CcAndroidMkInfo{
  2906. LocalStaticLibs: []string{"static_dep"},
  2907. LocalWholeStaticLibs: []string{"whole_static_dep"},
  2908. LocalSharedLibs: []string{"shared_dep"},
  2909. },
  2910. },
  2911. {
  2912. name: "cc_binary",
  2913. moduleName: "binary",
  2914. variant: "android_arm64_armv8-a",
  2915. androidMkInfo: cquery.CcAndroidMkInfo{
  2916. LocalStaticLibs: []string{"static_dep"},
  2917. LocalWholeStaticLibs: []string{"whole_static_dep"},
  2918. LocalSharedLibs: []string{"shared_dep"},
  2919. },
  2920. },
  2921. {
  2922. name: "cc_library_headers",
  2923. moduleName: "lib_headers",
  2924. variant: "android_arm64_armv8-a",
  2925. androidMkInfo: cquery.CcAndroidMkInfo{
  2926. LocalStaticLibs: []string{"static_dep"},
  2927. LocalWholeStaticLibs: []string{"whole_static_dep"},
  2928. LocalSharedLibs: []string{"shared_dep"},
  2929. },
  2930. },
  2931. {
  2932. name: "prebuilt lib static",
  2933. moduleName: "lib_prebuilt",
  2934. variant: "android_arm64_armv8-a_static",
  2935. androidMkInfo: cquery.CcAndroidMkInfo{
  2936. LocalStaticLibs: []string{"static_dep"},
  2937. LocalWholeStaticLibs: []string{"whole_static_dep"},
  2938. LocalSharedLibs: []string{"shared_dep"},
  2939. },
  2940. },
  2941. {
  2942. name: "prebuilt lib shared",
  2943. moduleName: "lib_prebuilt",
  2944. variant: "android_arm64_armv8-a_shared",
  2945. androidMkInfo: cquery.CcAndroidMkInfo{
  2946. LocalStaticLibs: []string{"static_dep"},
  2947. LocalWholeStaticLibs: []string{"whole_static_dep"},
  2948. LocalSharedLibs: []string{"shared_dep"},
  2949. },
  2950. },
  2951. }
  2952. outputBaseDir := "out/bazel"
  2953. for _, tc := range testCases {
  2954. t.Run(tc.name, func(t *testing.T) {
  2955. result := android.GroupFixturePreparers(
  2956. prepareForCcTest,
  2957. android.FixtureModifyConfig(func(config android.Config) {
  2958. config.BazelContext = android.MockBazelContext{
  2959. OutputBaseDir: outputBaseDir,
  2960. LabelToCcInfo: map[string]cquery.CcInfo{
  2961. "//:lib": cquery.CcInfo{
  2962. CcAndroidMkInfo: tc.androidMkInfo,
  2963. RootDynamicLibraries: []string{""},
  2964. },
  2965. "//:lib_bp2build_cc_library_static": cquery.CcInfo{
  2966. CcAndroidMkInfo: tc.androidMkInfo,
  2967. RootStaticArchives: []string{""},
  2968. },
  2969. "//:lib_headers": cquery.CcInfo{
  2970. CcAndroidMkInfo: tc.androidMkInfo,
  2971. OutputFiles: []string{""},
  2972. },
  2973. "//:lib_prebuilt": cquery.CcInfo{
  2974. CcAndroidMkInfo: tc.androidMkInfo,
  2975. },
  2976. "//:lib_prebuilt_bp2build_cc_library_static": cquery.CcInfo{
  2977. CcAndroidMkInfo: tc.androidMkInfo,
  2978. },
  2979. },
  2980. LabelToCcBinary: map[string]cquery.CcUnstrippedInfo{
  2981. "//:test": cquery.CcUnstrippedInfo{
  2982. CcAndroidMkInfo: tc.androidMkInfo,
  2983. },
  2984. "//:binary": cquery.CcUnstrippedInfo{
  2985. CcAndroidMkInfo: tc.androidMkInfo,
  2986. },
  2987. },
  2988. }
  2989. }),
  2990. ).RunTestWithBp(t, bp)
  2991. ctx := result.TestContext
  2992. module := ctx.ModuleForTests(tc.moduleName, tc.variant).Module().(*Module)
  2993. entries := android.AndroidMkEntriesForTest(t, ctx, module)[0]
  2994. if !reflect.DeepEqual(module.Properties.AndroidMkStaticLibs, tc.androidMkInfo.LocalStaticLibs) {
  2995. t.Errorf("incorrect static_libs"+
  2996. "\nactual: %v"+
  2997. "\nexpected: %v",
  2998. module.Properties.AndroidMkStaticLibs,
  2999. tc.androidMkInfo.LocalStaticLibs,
  3000. )
  3001. }
  3002. staticDepsDiffer, missingStaticDeps, additionalStaticDeps := android.ListSetDifference(
  3003. entries.EntryMap["LOCAL_STATIC_LIBRARIES"],
  3004. tc.androidMkInfo.LocalStaticLibs,
  3005. )
  3006. if staticDepsDiffer {
  3007. t.Errorf(
  3008. "expected LOCAL_STATIC_LIBRARIES to be %q but was %q; missing: %q; extra %q",
  3009. tc.androidMkInfo.LocalStaticLibs,
  3010. entries.EntryMap["LOCAL_STATIC_LIBRARIES"],
  3011. missingStaticDeps,
  3012. additionalStaticDeps,
  3013. )
  3014. }
  3015. if !reflect.DeepEqual(module.Properties.AndroidMkWholeStaticLibs, tc.androidMkInfo.LocalWholeStaticLibs) {
  3016. t.Errorf("expected module.Properties.AndroidMkWholeStaticLibs to be %q, but was %q",
  3017. tc.androidMkInfo.LocalWholeStaticLibs,
  3018. module.Properties.AndroidMkWholeStaticLibs,
  3019. )
  3020. }
  3021. wholeStaticDepsDiffer, missingWholeStaticDeps, additionalWholeStaticDeps := android.ListSetDifference(
  3022. entries.EntryMap["LOCAL_WHOLE_STATIC_LIBRARIES"],
  3023. tc.androidMkInfo.LocalWholeStaticLibs,
  3024. )
  3025. if wholeStaticDepsDiffer {
  3026. t.Errorf(
  3027. "expected LOCAL_WHOLE_STATIC_LIBRARIES to be %q but was %q; missing: %q; extra %q",
  3028. tc.androidMkInfo.LocalWholeStaticLibs,
  3029. entries.EntryMap["LOCAL_WHOLE_STATIC_LIBRARIES"],
  3030. missingWholeStaticDeps,
  3031. additionalWholeStaticDeps,
  3032. )
  3033. }
  3034. if !reflect.DeepEqual(module.Properties.AndroidMkSharedLibs, tc.androidMkInfo.LocalSharedLibs) {
  3035. t.Errorf("incorrect shared_libs"+
  3036. "\nactual: %v"+
  3037. "\nexpected: %v",
  3038. module.Properties.AndroidMkSharedLibs,
  3039. tc.androidMkInfo.LocalSharedLibs,
  3040. )
  3041. }
  3042. sharedDepsDiffer, missingSharedDeps, additionalSharedDeps := android.ListSetDifference(
  3043. entries.EntryMap["LOCAL_SHARED_LIBRARIES"],
  3044. tc.androidMkInfo.LocalSharedLibs,
  3045. )
  3046. if sharedDepsDiffer {
  3047. t.Errorf(
  3048. "expected LOCAL_SHARED_LIBRARIES to be %q but was %q; missing %q; extra %q",
  3049. tc.androidMkInfo.LocalSharedLibs,
  3050. entries.EntryMap["LOCAL_SHARED_LIBRARIES"],
  3051. missingSharedDeps,
  3052. additionalSharedDeps,
  3053. )
  3054. }
  3055. })
  3056. }
  3057. }
  3058. var compilerFlagsTestCases = []struct {
  3059. in string
  3060. out bool
  3061. }{
  3062. {
  3063. in: "a",
  3064. out: false,
  3065. },
  3066. {
  3067. in: "-a",
  3068. out: true,
  3069. },
  3070. {
  3071. in: "-Ipath/to/something",
  3072. out: false,
  3073. },
  3074. {
  3075. in: "-isystempath/to/something",
  3076. out: false,
  3077. },
  3078. {
  3079. in: "--coverage",
  3080. out: false,
  3081. },
  3082. {
  3083. in: "-include a/b",
  3084. out: true,
  3085. },
  3086. {
  3087. in: "-include a/b c/d",
  3088. out: false,
  3089. },
  3090. {
  3091. in: "-DMACRO",
  3092. out: true,
  3093. },
  3094. {
  3095. in: "-DMAC RO",
  3096. out: false,
  3097. },
  3098. {
  3099. in: "-a -b",
  3100. out: false,
  3101. },
  3102. {
  3103. in: "-DMACRO=definition",
  3104. out: true,
  3105. },
  3106. {
  3107. in: "-DMACRO=defi nition",
  3108. out: true, // TODO(jiyong): this should be false
  3109. },
  3110. {
  3111. in: "-DMACRO(x)=x + 1",
  3112. out: true,
  3113. },
  3114. {
  3115. in: "-DMACRO=\"defi nition\"",
  3116. out: true,
  3117. },
  3118. }
  3119. type mockContext struct {
  3120. BaseModuleContext
  3121. result bool
  3122. }
  3123. func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
  3124. // CheckBadCompilerFlags calls this function when the flag should be rejected
  3125. ctx.result = false
  3126. }
  3127. func TestCompilerFlags(t *testing.T) {
  3128. t.Parallel()
  3129. for _, testCase := range compilerFlagsTestCases {
  3130. ctx := &mockContext{result: true}
  3131. CheckBadCompilerFlags(ctx, "", []string{testCase.in})
  3132. if ctx.result != testCase.out {
  3133. t.Errorf("incorrect output:")
  3134. t.Errorf(" input: %#v", testCase.in)
  3135. t.Errorf(" expected: %#v", testCase.out)
  3136. t.Errorf(" got: %#v", ctx.result)
  3137. }
  3138. }
  3139. }
  3140. func TestRecovery(t *testing.T) {
  3141. t.Parallel()
  3142. ctx := testCc(t, `
  3143. cc_library_shared {
  3144. name: "librecovery",
  3145. recovery: true,
  3146. }
  3147. cc_library_shared {
  3148. name: "librecovery32",
  3149. recovery: true,
  3150. compile_multilib:"32",
  3151. }
  3152. cc_library_shared {
  3153. name: "libHalInRecovery",
  3154. recovery_available: true,
  3155. vendor: true,
  3156. }
  3157. `)
  3158. variants := ctx.ModuleVariantsForTests("librecovery")
  3159. const arm64 = "android_recovery_arm64_armv8-a_shared"
  3160. if len(variants) != 1 || !android.InList(arm64, variants) {
  3161. t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
  3162. }
  3163. variants = ctx.ModuleVariantsForTests("librecovery32")
  3164. if android.InList(arm64, variants) {
  3165. t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
  3166. }
  3167. recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
  3168. if !recoveryModule.Platform() {
  3169. t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
  3170. }
  3171. }
  3172. func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) {
  3173. t.Parallel()
  3174. bp := `
  3175. cc_prebuilt_test_library_shared {
  3176. name: "test_lib",
  3177. relative_install_path: "foo/bar/baz",
  3178. srcs: ["srcpath/dontusethispath/baz.so"],
  3179. }
  3180. cc_test {
  3181. name: "main_test",
  3182. data_libs: ["test_lib"],
  3183. gtest: false,
  3184. }
  3185. `
  3186. config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
  3187. config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
  3188. config.TestProductVariables.Platform_vndk_version = StringPtr("29")
  3189. config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
  3190. ctx := testCcWithConfig(t, config)
  3191. module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
  3192. testBinary := module.(*Module).linker.(*testBinary)
  3193. outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
  3194. if err != nil {
  3195. t.Fatalf("Expected cc_test to produce output files, error: %s", err)
  3196. }
  3197. if len(outputFiles) != 1 {
  3198. t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
  3199. }
  3200. if len(testBinary.dataPaths()) != 1 {
  3201. t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
  3202. }
  3203. outputPath := outputFiles[0].String()
  3204. if !strings.HasSuffix(outputPath, "/main_test") {
  3205. t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
  3206. }
  3207. entries := android.AndroidMkEntriesForTest(t, ctx, module)[0]
  3208. if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
  3209. t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
  3210. " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
  3211. }
  3212. }
  3213. func TestVersionedStubs(t *testing.T) {
  3214. t.Parallel()
  3215. ctx := testCc(t, `
  3216. cc_library_shared {
  3217. name: "libFoo",
  3218. srcs: ["foo.c"],
  3219. stubs: {
  3220. symbol_file: "foo.map.txt",
  3221. versions: ["1", "2", "3"],
  3222. },
  3223. }
  3224. cc_library_shared {
  3225. name: "libBar",
  3226. srcs: ["bar.c"],
  3227. shared_libs: ["libFoo#1"],
  3228. }`)
  3229. variants := ctx.ModuleVariantsForTests("libFoo")
  3230. expectedVariants := []string{
  3231. "android_arm64_armv8-a_shared",
  3232. "android_arm64_armv8-a_shared_1",
  3233. "android_arm64_armv8-a_shared_2",
  3234. "android_arm64_armv8-a_shared_3",
  3235. "android_arm64_armv8-a_shared_current",
  3236. "android_arm_armv7-a-neon_shared",
  3237. "android_arm_armv7-a-neon_shared_1",
  3238. "android_arm_armv7-a-neon_shared_2",
  3239. "android_arm_armv7-a-neon_shared_3",
  3240. "android_arm_armv7-a-neon_shared_current",
  3241. }
  3242. variantsMismatch := false
  3243. if len(variants) != len(expectedVariants) {
  3244. variantsMismatch = true
  3245. } else {
  3246. for _, v := range expectedVariants {
  3247. if !inList(v, variants) {
  3248. variantsMismatch = false
  3249. }
  3250. }
  3251. }
  3252. if variantsMismatch {
  3253. t.Errorf("variants of libFoo expected:\n")
  3254. for _, v := range expectedVariants {
  3255. t.Errorf("%q\n", v)
  3256. }
  3257. t.Errorf(", but got:\n")
  3258. for _, v := range variants {
  3259. t.Errorf("%q\n", v)
  3260. }
  3261. }
  3262. libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld")
  3263. libFlags := libBarLinkRule.Args["libFlags"]
  3264. libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so"
  3265. if !strings.Contains(libFlags, libFoo1StubPath) {
  3266. t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
  3267. }
  3268. libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc")
  3269. cFlags := libBarCompileRule.Args["cFlags"]
  3270. libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
  3271. if !strings.Contains(cFlags, libFoo1VersioningMacro) {
  3272. t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
  3273. }
  3274. }
  3275. func TestStubsForLibraryInMultipleApexes(t *testing.T) {
  3276. t.Parallel()
  3277. ctx := testCc(t, `
  3278. cc_library_shared {
  3279. name: "libFoo",
  3280. srcs: ["foo.c"],
  3281. stubs: {
  3282. symbol_file: "foo.map.txt",
  3283. versions: ["current"],
  3284. },
  3285. apex_available: ["bar", "a1"],
  3286. }
  3287. cc_library_shared {
  3288. name: "libBar",
  3289. srcs: ["bar.c"],
  3290. shared_libs: ["libFoo"],
  3291. apex_available: ["a1"],
  3292. }
  3293. cc_library_shared {
  3294. name: "libA1",
  3295. srcs: ["a1.c"],
  3296. shared_libs: ["libFoo"],
  3297. apex_available: ["a1"],
  3298. }
  3299. cc_library_shared {
  3300. name: "libBarA1",
  3301. srcs: ["bara1.c"],
  3302. shared_libs: ["libFoo"],
  3303. apex_available: ["bar", "a1"],
  3304. }
  3305. cc_library_shared {
  3306. name: "libAnyApex",
  3307. srcs: ["anyApex.c"],
  3308. shared_libs: ["libFoo"],
  3309. apex_available: ["//apex_available:anyapex"],
  3310. }
  3311. cc_library_shared {
  3312. name: "libBaz",
  3313. srcs: ["baz.c"],
  3314. shared_libs: ["libFoo"],
  3315. apex_available: ["baz"],
  3316. }
  3317. cc_library_shared {
  3318. name: "libQux",
  3319. srcs: ["qux.c"],
  3320. shared_libs: ["libFoo"],
  3321. apex_available: ["qux", "bar"],
  3322. }`)
  3323. variants := ctx.ModuleVariantsForTests("libFoo")
  3324. expectedVariants := []string{
  3325. "android_arm64_armv8-a_shared",
  3326. "android_arm64_armv8-a_shared_current",
  3327. "android_arm_armv7-a-neon_shared",
  3328. "android_arm_armv7-a-neon_shared_current",
  3329. }
  3330. variantsMismatch := false
  3331. if len(variants) != len(expectedVariants) {
  3332. variantsMismatch = true
  3333. } else {
  3334. for _, v := range expectedVariants {
  3335. if !inList(v, variants) {
  3336. variantsMismatch = false
  3337. }
  3338. }
  3339. }
  3340. if variantsMismatch {
  3341. t.Errorf("variants of libFoo expected:\n")
  3342. for _, v := range expectedVariants {
  3343. t.Errorf("%q\n", v)
  3344. }
  3345. t.Errorf(", but got:\n")
  3346. for _, v := range variants {
  3347. t.Errorf("%q\n", v)
  3348. }
  3349. }
  3350. linkAgainstFoo := []string{"libBarA1"}
  3351. linkAgainstFooStubs := []string{"libBar", "libA1", "libBaz", "libQux", "libAnyApex"}
  3352. libFooPath := "libFoo/android_arm64_armv8-a_shared/libFoo.so"
  3353. for _, lib := range linkAgainstFoo {
  3354. libLinkRule := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld")
  3355. libFlags := libLinkRule.Args["libFlags"]
  3356. if !strings.Contains(libFlags, libFooPath) {
  3357. t.Errorf("%q: %q is not found in %q", lib, libFooPath, libFlags)
  3358. }
  3359. }
  3360. libFooStubPath := "libFoo/android_arm64_armv8-a_shared_current/libFoo.so"
  3361. for _, lib := range linkAgainstFooStubs {
  3362. libLinkRule := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld")
  3363. libFlags := libLinkRule.Args["libFlags"]
  3364. if !strings.Contains(libFlags, libFooStubPath) {
  3365. t.Errorf("%q: %q is not found in %q", lib, libFooStubPath, libFlags)
  3366. }
  3367. }
  3368. }
  3369. func TestMixedBuildUsesStubs(t *testing.T) {
  3370. t.Parallel()
  3371. bp := `
  3372. cc_library_shared {
  3373. name: "libFoo",
  3374. bazel_module: { label: "//:libFoo" },
  3375. srcs: ["foo.c"],
  3376. stubs: {
  3377. symbol_file: "foo.map.txt",
  3378. versions: ["current"],
  3379. },
  3380. apex_available: ["bar", "a1"],
  3381. }
  3382. cc_library_shared {
  3383. name: "libBar",
  3384. srcs: ["bar.c"],
  3385. shared_libs: ["libFoo"],
  3386. apex_available: ["a1"],
  3387. }
  3388. cc_library_shared {
  3389. name: "libA1",
  3390. srcs: ["a1.c"],
  3391. shared_libs: ["libFoo"],
  3392. apex_available: ["a1"],
  3393. }
  3394. cc_library_shared {
  3395. name: "libBarA1",
  3396. srcs: ["bara1.c"],
  3397. shared_libs: ["libFoo"],
  3398. apex_available: ["bar", "a1"],
  3399. }
  3400. cc_library_shared {
  3401. name: "libAnyApex",
  3402. srcs: ["anyApex.c"],
  3403. shared_libs: ["libFoo"],
  3404. apex_available: ["//apex_available:anyapex"],
  3405. }
  3406. cc_library_shared {
  3407. name: "libBaz",
  3408. srcs: ["baz.c"],
  3409. shared_libs: ["libFoo"],
  3410. apex_available: ["baz"],
  3411. }
  3412. cc_library_shared {
  3413. name: "libQux",
  3414. srcs: ["qux.c"],
  3415. shared_libs: ["libFoo"],
  3416. apex_available: ["qux", "bar"],
  3417. }`
  3418. result := android.GroupFixturePreparers(
  3419. prepareForCcTest,
  3420. android.FixtureModifyConfig(func(config android.Config) {
  3421. config.BazelContext = android.MockBazelContext{
  3422. OutputBaseDir: "out/bazel",
  3423. LabelToCcInfo: map[string]cquery.CcInfo{
  3424. "//:libFoo": {
  3425. RootDynamicLibraries: []string{"libFoo.so"},
  3426. },
  3427. "//:libFoo_stub_libs-current": {
  3428. RootDynamicLibraries: []string{"libFoo_stub_libs-current.so"},
  3429. },
  3430. },
  3431. }
  3432. }),
  3433. ).RunTestWithBp(t, bp)
  3434. ctx := result.TestContext
  3435. variants := ctx.ModuleVariantsForTests("libFoo")
  3436. expectedVariants := []string{
  3437. "android_arm64_armv8-a_shared",
  3438. "android_arm64_armv8-a_shared_current",
  3439. "android_arm_armv7-a-neon_shared",
  3440. "android_arm_armv7-a-neon_shared_current",
  3441. }
  3442. variantsMismatch := false
  3443. if len(variants) != len(expectedVariants) {
  3444. variantsMismatch = true
  3445. } else {
  3446. for _, v := range expectedVariants {
  3447. if !inList(v, variants) {
  3448. variantsMismatch = false
  3449. }
  3450. }
  3451. }
  3452. if variantsMismatch {
  3453. t.Errorf("variants of libFoo expected:\n")
  3454. for _, v := range expectedVariants {
  3455. t.Errorf("%q\n", v)
  3456. }
  3457. t.Errorf(", but got:\n")
  3458. for _, v := range variants {
  3459. t.Errorf("%q\n", v)
  3460. }
  3461. }
  3462. linkAgainstFoo := []string{"libBarA1"}
  3463. linkAgainstFooStubs := []string{"libBar", "libA1", "libBaz", "libQux", "libAnyApex"}
  3464. libFooPath := "out/bazel/execroot/__main__/libFoo.so"
  3465. for _, lib := range linkAgainstFoo {
  3466. libLinkRule := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld")
  3467. libFlags := libLinkRule.Args["libFlags"]
  3468. if !strings.Contains(libFlags, libFooPath) {
  3469. t.Errorf("%q: %q is not found in %q", lib, libFooPath, libFlags)
  3470. }
  3471. }
  3472. libFooStubPath := "out/bazel/execroot/__main__/libFoo_stub_libs-current.so"
  3473. for _, lib := range linkAgainstFooStubs {
  3474. libLinkRule := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld")
  3475. libFlags := libLinkRule.Args["libFlags"]
  3476. if !strings.Contains(libFlags, libFooStubPath) {
  3477. t.Errorf("%q: %q is not found in %q", lib, libFooStubPath, libFlags)
  3478. }
  3479. }
  3480. }
  3481. func TestVersioningMacro(t *testing.T) {
  3482. t.Parallel()
  3483. for _, tc := range []struct{ moduleName, expected string }{
  3484. {"libc", "__LIBC_API__"},
  3485. {"libfoo", "__LIBFOO_API__"},
  3486. {"libfoo@1", "__LIBFOO_1_API__"},
  3487. {"libfoo-v1", "__LIBFOO_V1_API__"},
  3488. {"libfoo.v1", "__LIBFOO_V1_API__"},
  3489. } {
  3490. checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName))
  3491. }
  3492. }
  3493. func pathsToBase(paths android.Paths) []string {
  3494. var ret []string
  3495. for _, p := range paths {
  3496. ret = append(ret, p.Base())
  3497. }
  3498. return ret
  3499. }
  3500. func TestStaticLibArchiveArgs(t *testing.T) {
  3501. t.Parallel()
  3502. ctx := testCc(t, `
  3503. cc_library_static {
  3504. name: "foo",
  3505. srcs: ["foo.c"],
  3506. }
  3507. cc_library_static {
  3508. name: "bar",
  3509. srcs: ["bar.c"],
  3510. }
  3511. cc_library_shared {
  3512. name: "qux",
  3513. srcs: ["qux.c"],
  3514. }
  3515. cc_library_static {
  3516. name: "baz",
  3517. srcs: ["baz.c"],
  3518. static_libs: ["foo"],
  3519. shared_libs: ["qux"],
  3520. whole_static_libs: ["bar"],
  3521. }`)
  3522. variant := "android_arm64_armv8-a_static"
  3523. arRule := ctx.ModuleForTests("baz", variant).Rule("ar")
  3524. // For static libraries, the object files of a whole static dep are included in the archive
  3525. // directly
  3526. if g, w := pathsToBase(arRule.Inputs), []string{"bar.o", "baz.o"}; !reflect.DeepEqual(w, g) {
  3527. t.Errorf("Expected input objects %q, got %q", w, g)
  3528. }
  3529. // non whole static dependencies are not linked into the archive
  3530. if len(arRule.Implicits) > 0 {
  3531. t.Errorf("Expected 0 additional deps, got %q", arRule.Implicits)
  3532. }
  3533. }
  3534. func TestSharedLibLinkingArgs(t *testing.T) {
  3535. t.Parallel()
  3536. ctx := testCc(t, `
  3537. cc_library_static {
  3538. name: "foo",
  3539. srcs: ["foo.c"],
  3540. }
  3541. cc_library_static {
  3542. name: "bar",
  3543. srcs: ["bar.c"],
  3544. }
  3545. cc_library_shared {
  3546. name: "qux",
  3547. srcs: ["qux.c"],
  3548. }
  3549. cc_library_shared {
  3550. name: "baz",
  3551. srcs: ["baz.c"],
  3552. static_libs: ["foo"],
  3553. shared_libs: ["qux"],
  3554. whole_static_libs: ["bar"],
  3555. }`)
  3556. variant := "android_arm64_armv8-a_shared"
  3557. linkRule := ctx.ModuleForTests("baz", variant).Rule("ld")
  3558. libFlags := linkRule.Args["libFlags"]
  3559. // When dynamically linking, we expect static dependencies to be found on the command line
  3560. if expected := "foo.a"; !strings.Contains(libFlags, expected) {
  3561. t.Errorf("Static lib %q was not found in %q", expected, libFlags)
  3562. }
  3563. // When dynamically linking, we expect whole static dependencies to be found on the command line
  3564. if expected := "bar.a"; !strings.Contains(libFlags, expected) {
  3565. t.Errorf("Static lib %q was not found in %q", expected, libFlags)
  3566. }
  3567. // When dynamically linking, we expect shared dependencies to be found on the command line
  3568. if expected := "qux.so"; !strings.Contains(libFlags, expected) {
  3569. t.Errorf("Shared lib %q was not found in %q", expected, libFlags)
  3570. }
  3571. // We should only have the objects from the shared library srcs, not the whole static dependencies
  3572. if g, w := pathsToBase(linkRule.Inputs), []string{"baz.o"}; !reflect.DeepEqual(w, g) {
  3573. t.Errorf("Expected input objects %q, got %q", w, g)
  3574. }
  3575. }
  3576. func TestStaticExecutable(t *testing.T) {
  3577. t.Parallel()
  3578. ctx := testCc(t, `
  3579. cc_binary {
  3580. name: "static_test",
  3581. srcs: ["foo.c", "baz.o"],
  3582. static_executable: true,
  3583. }`)
  3584. variant := "android_arm64_armv8-a"
  3585. binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
  3586. libFlags := binModuleRule.Args["libFlags"]
  3587. systemStaticLibs := []string{"libc.a", "libm.a"}
  3588. for _, lib := range systemStaticLibs {
  3589. if !strings.Contains(libFlags, lib) {
  3590. t.Errorf("Static lib %q was not found in %q", lib, libFlags)
  3591. }
  3592. }
  3593. systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
  3594. for _, lib := range systemSharedLibs {
  3595. if strings.Contains(libFlags, lib) {
  3596. t.Errorf("Shared lib %q was found in %q", lib, libFlags)
  3597. }
  3598. }
  3599. }
  3600. func TestStaticDepsOrderWithStubs(t *testing.T) {
  3601. t.Parallel()
  3602. ctx := testCc(t, `
  3603. cc_binary {
  3604. name: "mybin",
  3605. srcs: ["foo.c"],
  3606. static_libs: ["libfooC", "libfooB"],
  3607. static_executable: true,
  3608. stl: "none",
  3609. }
  3610. cc_library {
  3611. name: "libfooB",
  3612. srcs: ["foo.c"],
  3613. shared_libs: ["libfooC"],
  3614. stl: "none",
  3615. }
  3616. cc_library {
  3617. name: "libfooC",
  3618. srcs: ["foo.c"],
  3619. stl: "none",
  3620. stubs: {
  3621. versions: ["1"],
  3622. },
  3623. }`)
  3624. mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld")
  3625. actual := mybin.Implicits[:2]
  3626. expected := GetOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"})
  3627. if !reflect.DeepEqual(actual, expected) {
  3628. t.Errorf("staticDeps orderings were not propagated correctly"+
  3629. "\nactual: %v"+
  3630. "\nexpected: %v",
  3631. actual,
  3632. expected,
  3633. )
  3634. }
  3635. }
  3636. func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) {
  3637. t.Parallel()
  3638. testCcError(t, `module "libA" .* depends on disabled module "libB"`, `
  3639. cc_library {
  3640. name: "libA",
  3641. srcs: ["foo.c"],
  3642. shared_libs: ["libB"],
  3643. stl: "none",
  3644. }
  3645. cc_library {
  3646. name: "libB",
  3647. srcs: ["foo.c"],
  3648. enabled: false,
  3649. stl: "none",
  3650. }
  3651. `)
  3652. }
  3653. func VerifyAFLFuzzTargetVariant(t *testing.T, variant string) {
  3654. bp := `
  3655. cc_fuzz {
  3656. name: "test_afl_fuzz_target",
  3657. srcs: ["foo.c"],
  3658. host_supported: true,
  3659. static_libs: [
  3660. "afl_fuzz_static_lib",
  3661. ],
  3662. shared_libs: [
  3663. "afl_fuzz_shared_lib",
  3664. ],
  3665. fuzzing_frameworks: {
  3666. afl: true,
  3667. libfuzzer: false,
  3668. },
  3669. }
  3670. cc_library {
  3671. name: "afl_fuzz_static_lib",
  3672. host_supported: true,
  3673. srcs: ["static_file.c"],
  3674. }
  3675. cc_library {
  3676. name: "libfuzzer_only_static_lib",
  3677. host_supported: true,
  3678. srcs: ["static_file.c"],
  3679. }
  3680. cc_library {
  3681. name: "afl_fuzz_shared_lib",
  3682. host_supported: true,
  3683. srcs: ["shared_file.c"],
  3684. static_libs: [
  3685. "second_static_lib",
  3686. ],
  3687. }
  3688. cc_library_headers {
  3689. name: "libafl_headers",
  3690. vendor_available: true,
  3691. host_supported: true,
  3692. export_include_dirs: [
  3693. "include",
  3694. "instrumentation",
  3695. ],
  3696. }
  3697. cc_object {
  3698. name: "afl-compiler-rt",
  3699. vendor_available: true,
  3700. host_supported: true,
  3701. cflags: [
  3702. "-fPIC",
  3703. ],
  3704. srcs: [
  3705. "instrumentation/afl-compiler-rt.o.c",
  3706. ],
  3707. }
  3708. cc_library {
  3709. name: "second_static_lib",
  3710. host_supported: true,
  3711. srcs: ["second_file.c"],
  3712. }
  3713. cc_object {
  3714. name: "aflpp_driver",
  3715. host_supported: true,
  3716. srcs: [
  3717. "aflpp_driver.c",
  3718. ],
  3719. }`
  3720. testEnv := map[string]string{
  3721. "FUZZ_FRAMEWORK": "AFL",
  3722. }
  3723. ctx := android.GroupFixturePreparers(prepareForCcTest, android.FixtureMergeEnv(testEnv)).RunTestWithBp(t, bp)
  3724. checkPcGuardFlag := func(
  3725. modName string, variantName string, shouldHave bool) {
  3726. cc := ctx.ModuleForTests(modName, variantName).Rule("cc")
  3727. cFlags, ok := cc.Args["cFlags"]
  3728. if !ok {
  3729. t.Errorf("Could not find cFlags for module %s and variant %s",
  3730. modName, variantName)
  3731. }
  3732. if strings.Contains(
  3733. cFlags, "-fsanitize-coverage=trace-pc-guard") != shouldHave {
  3734. t.Errorf("Flag was found: %t. Expected to find flag: %t. "+
  3735. "Test failed for module %s and variant %s",
  3736. !shouldHave, shouldHave, modName, variantName)
  3737. }
  3738. }
  3739. moduleName := "test_afl_fuzz_target"
  3740. checkPcGuardFlag(moduleName, variant+"_fuzzer", true)
  3741. moduleName = "afl_fuzz_static_lib"
  3742. checkPcGuardFlag(moduleName, variant+"_static", false)
  3743. checkPcGuardFlag(moduleName, variant+"_static_fuzzer", true)
  3744. moduleName = "second_static_lib"
  3745. checkPcGuardFlag(moduleName, variant+"_static", false)
  3746. checkPcGuardFlag(moduleName, variant+"_static_fuzzer", true)
  3747. ctx.ModuleForTests("afl_fuzz_shared_lib",
  3748. "android_arm64_armv8-a_shared").Rule("cc")
  3749. ctx.ModuleForTests("afl_fuzz_shared_lib",
  3750. "android_arm64_armv8-a_shared_fuzzer").Rule("cc")
  3751. }
  3752. func TestAFLFuzzTargetForDevice(t *testing.T) {
  3753. t.Parallel()
  3754. VerifyAFLFuzzTargetVariant(t, "android_arm64_armv8-a")
  3755. }
  3756. func TestAFLFuzzTargetForLinuxHost(t *testing.T) {
  3757. t.Parallel()
  3758. if runtime.GOOS != "linux" {
  3759. t.Skip("requires linux")
  3760. }
  3761. VerifyAFLFuzzTargetVariant(t, "linux_glibc_x86_64")
  3762. }
  3763. // Simple smoke test for the cc_fuzz target that ensures the rule compiles
  3764. // correctly.
  3765. func TestFuzzTarget(t *testing.T) {
  3766. t.Parallel()
  3767. ctx := testCc(t, `
  3768. cc_fuzz {
  3769. name: "fuzz_smoke_test",
  3770. srcs: ["foo.c"],
  3771. }`)
  3772. variant := "android_arm64_armv8-a_fuzzer"
  3773. ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc")
  3774. }
  3775. func assertString(t *testing.T, got, expected string) {
  3776. t.Helper()
  3777. if got != expected {
  3778. t.Errorf("expected %q got %q", expected, got)
  3779. }
  3780. }
  3781. func assertArrayString(t *testing.T, got, expected []string) {
  3782. t.Helper()
  3783. if len(got) != len(expected) {
  3784. t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got)
  3785. return
  3786. }
  3787. for i := range got {
  3788. if got[i] != expected[i] {
  3789. t.Errorf("expected %d-th %q (%q) got %q (%q)",
  3790. i, expected[i], expected, got[i], got)
  3791. return
  3792. }
  3793. }
  3794. }
  3795. func assertMapKeys(t *testing.T, m map[string]string, expected []string) {
  3796. t.Helper()
  3797. assertArrayString(t, android.SortedKeys(m), expected)
  3798. }
  3799. func TestDefaults(t *testing.T) {
  3800. t.Parallel()
  3801. ctx := testCc(t, `
  3802. cc_defaults {
  3803. name: "defaults",
  3804. srcs: ["foo.c"],
  3805. static: {
  3806. srcs: ["bar.c"],
  3807. },
  3808. shared: {
  3809. srcs: ["baz.c"],
  3810. },
  3811. bazel_module: {
  3812. bp2build_available: true,
  3813. },
  3814. }
  3815. cc_library_static {
  3816. name: "libstatic",
  3817. defaults: ["defaults"],
  3818. }
  3819. cc_library_shared {
  3820. name: "libshared",
  3821. defaults: ["defaults"],
  3822. }
  3823. cc_library {
  3824. name: "libboth",
  3825. defaults: ["defaults"],
  3826. }
  3827. cc_binary {
  3828. name: "binary",
  3829. defaults: ["defaults"],
  3830. }`)
  3831. shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld")
  3832. if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
  3833. t.Errorf("libshared ld rule wanted %q, got %q", w, g)
  3834. }
  3835. bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld")
  3836. if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
  3837. t.Errorf("libboth ld rule wanted %q, got %q", w, g)
  3838. }
  3839. binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld")
  3840. if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
  3841. t.Errorf("binary ld rule wanted %q, got %q", w, g)
  3842. }
  3843. static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar")
  3844. if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
  3845. t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
  3846. }
  3847. bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar")
  3848. if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
  3849. t.Errorf("libboth ar rule wanted %q, got %q", w, g)
  3850. }
  3851. }
  3852. func TestProductVariableDefaults(t *testing.T) {
  3853. t.Parallel()
  3854. bp := `
  3855. cc_defaults {
  3856. name: "libfoo_defaults",
  3857. srcs: ["foo.c"],
  3858. cppflags: ["-DFOO"],
  3859. product_variables: {
  3860. debuggable: {
  3861. cppflags: ["-DBAR"],
  3862. },
  3863. },
  3864. }
  3865. cc_library {
  3866. name: "libfoo",
  3867. defaults: ["libfoo_defaults"],
  3868. }
  3869. `
  3870. result := android.GroupFixturePreparers(
  3871. prepareForCcTest,
  3872. android.PrepareForTestWithVariables,
  3873. android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
  3874. variables.Debuggable = BoolPtr(true)
  3875. }),
  3876. ).RunTestWithBp(t, bp)
  3877. libfoo := result.Module("libfoo", "android_arm64_armv8-a_static").(*Module)
  3878. android.AssertStringListContains(t, "cppflags", libfoo.flags.Local.CppFlags, "-DBAR")
  3879. }
  3880. func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
  3881. t.Parallel()
  3882. bp := `
  3883. cc_library_static {
  3884. name: "libfoo",
  3885. srcs: ["foo.c"],
  3886. whole_static_libs: ["libbar"],
  3887. }
  3888. cc_library_static {
  3889. name: "libbar",
  3890. whole_static_libs: ["libmissing"],
  3891. }
  3892. `
  3893. result := android.GroupFixturePreparers(
  3894. prepareForCcTest,
  3895. android.PrepareForTestWithAllowMissingDependencies,
  3896. ).RunTestWithBp(t, bp)
  3897. libbar := result.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
  3898. android.AssertDeepEquals(t, "libbar rule", android.ErrorRule, libbar.Rule)
  3899. android.AssertStringDoesContain(t, "libbar error", libbar.Args["error"], "missing dependencies: libmissing")
  3900. libfoo := result.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
  3901. android.AssertStringListContains(t, "libfoo.a dependencies", libfoo.Inputs.Strings(), libbar.Output.String())
  3902. }
  3903. func TestInstallSharedLibs(t *testing.T) {
  3904. t.Parallel()
  3905. bp := `
  3906. cc_binary {
  3907. name: "bin",
  3908. host_supported: true,
  3909. shared_libs: ["libshared"],
  3910. runtime_libs: ["libruntime"],
  3911. srcs: [":gen"],
  3912. }
  3913. cc_library_shared {
  3914. name: "libshared",
  3915. host_supported: true,
  3916. shared_libs: ["libtransitive"],
  3917. }
  3918. cc_library_shared {
  3919. name: "libtransitive",
  3920. host_supported: true,
  3921. }
  3922. cc_library_shared {
  3923. name: "libruntime",
  3924. host_supported: true,
  3925. }
  3926. cc_binary_host {
  3927. name: "tool",
  3928. srcs: ["foo.cpp"],
  3929. }
  3930. genrule {
  3931. name: "gen",
  3932. tools: ["tool"],
  3933. out: ["gen.cpp"],
  3934. cmd: "$(location tool) $(out)",
  3935. }
  3936. `
  3937. config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
  3938. ctx := testCcWithConfig(t, config)
  3939. hostBin := ctx.ModuleForTests("bin", config.BuildOSTarget.String()).Description("install")
  3940. hostShared := ctx.ModuleForTests("libshared", config.BuildOSTarget.String()+"_shared").Description("install")
  3941. hostRuntime := ctx.ModuleForTests("libruntime", config.BuildOSTarget.String()+"_shared").Description("install")
  3942. hostTransitive := ctx.ModuleForTests("libtransitive", config.BuildOSTarget.String()+"_shared").Description("install")
  3943. hostTool := ctx.ModuleForTests("tool", config.BuildOSTarget.String()).Description("install")
  3944. if g, w := hostBin.Implicits.Strings(), hostShared.Output.String(); !android.InList(w, g) {
  3945. t.Errorf("expected host bin dependency %q, got %q", w, g)
  3946. }
  3947. if g, w := hostBin.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
  3948. t.Errorf("expected host bin dependency %q, got %q", w, g)
  3949. }
  3950. if g, w := hostShared.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
  3951. t.Errorf("expected host bin dependency %q, got %q", w, g)
  3952. }
  3953. if g, w := hostBin.Implicits.Strings(), hostRuntime.Output.String(); !android.InList(w, g) {
  3954. t.Errorf("expected host bin dependency %q, got %q", w, g)
  3955. }
  3956. if g, w := hostBin.Implicits.Strings(), hostTool.Output.String(); android.InList(w, g) {
  3957. t.Errorf("expected no host bin dependency %q, got %q", w, g)
  3958. }
  3959. deviceBin := ctx.ModuleForTests("bin", "android_arm64_armv8-a").Description("install")
  3960. deviceShared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Description("install")
  3961. deviceTransitive := ctx.ModuleForTests("libtransitive", "android_arm64_armv8-a_shared").Description("install")
  3962. deviceRuntime := ctx.ModuleForTests("libruntime", "android_arm64_armv8-a_shared").Description("install")
  3963. if g, w := deviceBin.OrderOnly.Strings(), deviceShared.Output.String(); !android.InList(w, g) {
  3964. t.Errorf("expected device bin dependency %q, got %q", w, g)
  3965. }
  3966. if g, w := deviceBin.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
  3967. t.Errorf("expected device bin dependency %q, got %q", w, g)
  3968. }
  3969. if g, w := deviceShared.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
  3970. t.Errorf("expected device bin dependency %q, got %q", w, g)
  3971. }
  3972. if g, w := deviceBin.OrderOnly.Strings(), deviceRuntime.Output.String(); !android.InList(w, g) {
  3973. t.Errorf("expected device bin dependency %q, got %q", w, g)
  3974. }
  3975. if g, w := deviceBin.OrderOnly.Strings(), hostTool.Output.String(); android.InList(w, g) {
  3976. t.Errorf("expected no device bin dependency %q, got %q", w, g)
  3977. }
  3978. }
  3979. func TestStubsLibReexportsHeaders(t *testing.T) {
  3980. t.Parallel()
  3981. ctx := testCc(t, `
  3982. cc_library_shared {
  3983. name: "libclient",
  3984. srcs: ["foo.c"],
  3985. shared_libs: ["libfoo#1"],
  3986. }
  3987. cc_library_shared {
  3988. name: "libfoo",
  3989. srcs: ["foo.c"],
  3990. shared_libs: ["libbar"],
  3991. export_shared_lib_headers: ["libbar"],
  3992. stubs: {
  3993. symbol_file: "foo.map.txt",
  3994. versions: ["1", "2", "3"],
  3995. },
  3996. }
  3997. cc_library_shared {
  3998. name: "libbar",
  3999. export_include_dirs: ["include/libbar"],
  4000. srcs: ["foo.c"],
  4001. }`)
  4002. cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
  4003. if !strings.Contains(cFlags, "-Iinclude/libbar") {
  4004. t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags)
  4005. }
  4006. }
  4007. func TestAidlLibraryWithHeaders(t *testing.T) {
  4008. t.Parallel()
  4009. ctx := android.GroupFixturePreparers(
  4010. prepareForCcTest,
  4011. aidl_library.PrepareForTestWithAidlLibrary,
  4012. android.MockFS{
  4013. "package_bar/Android.bp": []byte(`
  4014. aidl_library {
  4015. name: "bar",
  4016. srcs: ["x/y/Bar.aidl"],
  4017. hdrs: ["x/HeaderBar.aidl"],
  4018. strip_import_prefix: "x",
  4019. }
  4020. `)}.AddToFixture(),
  4021. android.MockFS{
  4022. "package_foo/Android.bp": []byte(`
  4023. aidl_library {
  4024. name: "foo",
  4025. srcs: ["a/b/Foo.aidl"],
  4026. hdrs: ["a/HeaderFoo.aidl"],
  4027. strip_import_prefix: "a",
  4028. deps: ["bar"],
  4029. }
  4030. cc_library {
  4031. name: "libfoo",
  4032. aidl: {
  4033. libs: ["foo"],
  4034. }
  4035. }
  4036. `),
  4037. }.AddToFixture(),
  4038. ).RunTest(t).TestContext
  4039. libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static")
  4040. android.AssertPathsRelativeToTopEquals(
  4041. t,
  4042. "aidl headers",
  4043. []string{
  4044. "package_bar/x/HeaderBar.aidl",
  4045. "package_foo/a/HeaderFoo.aidl",
  4046. "package_foo/a/b/Foo.aidl",
  4047. "out/soong/.intermediates/package_foo/libfoo/android_arm64_armv8-a_static/gen/aidl_library.sbox.textproto",
  4048. },
  4049. libfoo.Rule("aidl_library").Implicits,
  4050. )
  4051. manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl_library.sbox.textproto"))
  4052. aidlCommand := manifest.Commands[0].GetCommand()
  4053. expectedAidlFlags := "-Ipackage_foo/a -Ipackage_bar/x"
  4054. if !strings.Contains(aidlCommand, expectedAidlFlags) {
  4055. t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlags)
  4056. }
  4057. outputs := strings.Join(libfoo.AllOutputs(), " ")
  4058. android.AssertStringDoesContain(t, "aidl-generated header", outputs, "gen/aidl_library/b/BpFoo.h")
  4059. android.AssertStringDoesContain(t, "aidl-generated header", outputs, "gen/aidl_library/b/BnFoo.h")
  4060. android.AssertStringDoesContain(t, "aidl-generated header", outputs, "gen/aidl_library/b/Foo.h")
  4061. android.AssertStringDoesContain(t, "aidl-generated cpp", outputs, "b/Foo.cpp")
  4062. // Confirm that the aidl header doesn't get compiled to cpp and h files
  4063. android.AssertStringDoesNotContain(t, "aidl-generated header", outputs, "gen/aidl_library/y/BpBar.h")
  4064. android.AssertStringDoesNotContain(t, "aidl-generated header", outputs, "gen/aidl_library/y/BnBar.h")
  4065. android.AssertStringDoesNotContain(t, "aidl-generated header", outputs, "gen/aidl_library/y/Bar.h")
  4066. android.AssertStringDoesNotContain(t, "aidl-generated cpp", outputs, "y/Bar.cpp")
  4067. }
  4068. func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) {
  4069. t.Parallel()
  4070. ctx := android.GroupFixturePreparers(
  4071. prepareForCcTest,
  4072. aidl_library.PrepareForTestWithAidlLibrary,
  4073. ).RunTestWithBp(t, `
  4074. cc_library {
  4075. name: "libfoo",
  4076. srcs: ["a/Foo.aidl"],
  4077. aidl: { flags: ["-Werror"], },
  4078. }
  4079. `)
  4080. libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static")
  4081. manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto"))
  4082. aidlCommand := manifest.Commands[0].GetCommand()
  4083. expectedAidlFlag := "-Werror"
  4084. if !strings.Contains(aidlCommand, expectedAidlFlag) {
  4085. t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
  4086. }
  4087. }
  4088. func TestAidlFlagsWithMinSdkVersion(t *testing.T) {
  4089. t.Parallel()
  4090. for _, tc := range []struct {
  4091. name string
  4092. sdkVersion string
  4093. variant string
  4094. expected string
  4095. }{
  4096. {
  4097. name: "default is current",
  4098. sdkVersion: "",
  4099. variant: "android_arm64_armv8-a_static",
  4100. expected: "platform_apis",
  4101. },
  4102. {
  4103. name: "use sdk_version",
  4104. sdkVersion: `sdk_version: "29"`,
  4105. variant: "android_arm64_armv8-a_static",
  4106. expected: "platform_apis",
  4107. },
  4108. {
  4109. name: "use sdk_version(sdk variant)",
  4110. sdkVersion: `sdk_version: "29"`,
  4111. variant: "android_arm64_armv8-a_sdk_static",
  4112. expected: "29",
  4113. },
  4114. {
  4115. name: "use min_sdk_version",
  4116. sdkVersion: `min_sdk_version: "29"`,
  4117. variant: "android_arm64_armv8-a_static",
  4118. expected: "29",
  4119. },
  4120. } {
  4121. t.Run(tc.name, func(t *testing.T) {
  4122. ctx := testCc(t, `
  4123. cc_library {
  4124. name: "libfoo",
  4125. stl: "none",
  4126. srcs: ["a/Foo.aidl"],
  4127. `+tc.sdkVersion+`
  4128. }
  4129. `)
  4130. libfoo := ctx.ModuleForTests("libfoo", tc.variant)
  4131. manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto"))
  4132. aidlCommand := manifest.Commands[0].GetCommand()
  4133. expectedAidlFlag := "--min_sdk_version=" + tc.expected
  4134. if !strings.Contains(aidlCommand, expectedAidlFlag) {
  4135. t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
  4136. }
  4137. })
  4138. }
  4139. }
  4140. func TestInvalidAidlProp(t *testing.T) {
  4141. t.Parallel()
  4142. testCases := []struct {
  4143. description string
  4144. bp string
  4145. }{
  4146. {
  4147. description: "Invalid use of aidl.libs and aidl.include_dirs",
  4148. bp: `
  4149. cc_library {
  4150. name: "foo",
  4151. aidl: {
  4152. libs: ["foo_aidl"],
  4153. include_dirs: ["bar/include"],
  4154. }
  4155. }
  4156. `,
  4157. },
  4158. {
  4159. description: "Invalid use of aidl.libs and aidl.local_include_dirs",
  4160. bp: `
  4161. cc_library {
  4162. name: "foo",
  4163. aidl: {
  4164. libs: ["foo_aidl"],
  4165. local_include_dirs: ["include"],
  4166. }
  4167. }
  4168. `,
  4169. },
  4170. }
  4171. for _, testCase := range testCases {
  4172. t.Run(testCase.description, func(t *testing.T) {
  4173. bp := `
  4174. aidl_library {
  4175. name: "foo_aidl",
  4176. srcs: ["Foo.aidl"],
  4177. } ` + testCase.bp
  4178. android.GroupFixturePreparers(
  4179. prepareForCcTest,
  4180. aidl_library.PrepareForTestWithAidlLibrary.
  4181. ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern("For aidl headers, please only use aidl.libs prop")),
  4182. ).RunTestWithBp(t, bp)
  4183. })
  4184. }
  4185. }
  4186. func TestMinSdkVersionInClangTriple(t *testing.T) {
  4187. t.Parallel()
  4188. ctx := testCc(t, `
  4189. cc_library_shared {
  4190. name: "libfoo",
  4191. srcs: ["foo.c"],
  4192. min_sdk_version: "29",
  4193. }`)
  4194. cFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
  4195. android.AssertStringDoesContain(t, "min sdk version", cFlags, "-target aarch64-linux-android29")
  4196. }
  4197. func TestNonDigitMinSdkVersionInClangTriple(t *testing.T) {
  4198. t.Parallel()
  4199. bp := `
  4200. cc_library_shared {
  4201. name: "libfoo",
  4202. srcs: ["foo.c"],
  4203. min_sdk_version: "S",
  4204. }
  4205. `
  4206. result := android.GroupFixturePreparers(
  4207. prepareForCcTest,
  4208. android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
  4209. variables.Platform_version_active_codenames = []string{"UpsideDownCake", "Tiramisu"}
  4210. }),
  4211. ).RunTestWithBp(t, bp)
  4212. ctx := result.TestContext
  4213. cFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
  4214. android.AssertStringDoesContain(t, "min sdk version", cFlags, "-target aarch64-linux-android31")
  4215. }
  4216. func TestIncludeDirsExporting(t *testing.T) {
  4217. t.Parallel()
  4218. // Trim spaces from the beginning, end and immediately after any newline characters. Leaves
  4219. // embedded newline characters alone.
  4220. trimIndentingSpaces := func(s string) string {
  4221. return strings.TrimSpace(regexp.MustCompile("(^|\n)\\s+").ReplaceAllString(s, "$1"))
  4222. }
  4223. checkPaths := func(t *testing.T, message string, expected string, paths android.Paths) {
  4224. t.Helper()
  4225. expected = trimIndentingSpaces(expected)
  4226. actual := trimIndentingSpaces(strings.Join(android.FirstUniqueStrings(android.NormalizePathsForTesting(paths)), "\n"))
  4227. if expected != actual {
  4228. t.Errorf("%s: expected:\n%s\n actual:\n%s\n", message, expected, actual)
  4229. }
  4230. }
  4231. type exportedChecker func(t *testing.T, name string, exported FlagExporterInfo)
  4232. checkIncludeDirs := func(t *testing.T, ctx *android.TestContext, module android.Module, checkers ...exportedChecker) {
  4233. t.Helper()
  4234. exported := ctx.ModuleProvider(module, FlagExporterInfoProvider).(FlagExporterInfo)
  4235. name := module.Name()
  4236. for _, checker := range checkers {
  4237. checker(t, name, exported)
  4238. }
  4239. }
  4240. expectedIncludeDirs := func(expectedPaths string) exportedChecker {
  4241. return func(t *testing.T, name string, exported FlagExporterInfo) {
  4242. t.Helper()
  4243. checkPaths(t, fmt.Sprintf("%s: include dirs", name), expectedPaths, exported.IncludeDirs)
  4244. }
  4245. }
  4246. expectedSystemIncludeDirs := func(expectedPaths string) exportedChecker {
  4247. return func(t *testing.T, name string, exported FlagExporterInfo) {
  4248. t.Helper()
  4249. checkPaths(t, fmt.Sprintf("%s: system include dirs", name), expectedPaths, exported.SystemIncludeDirs)
  4250. }
  4251. }
  4252. expectedGeneratedHeaders := func(expectedPaths string) exportedChecker {
  4253. return func(t *testing.T, name string, exported FlagExporterInfo) {
  4254. t.Helper()
  4255. checkPaths(t, fmt.Sprintf("%s: generated headers", name), expectedPaths, exported.GeneratedHeaders)
  4256. }
  4257. }
  4258. expectedOrderOnlyDeps := func(expectedPaths string) exportedChecker {
  4259. return func(t *testing.T, name string, exported FlagExporterInfo) {
  4260. t.Helper()
  4261. checkPaths(t, fmt.Sprintf("%s: order only deps", name), expectedPaths, exported.Deps)
  4262. }
  4263. }
  4264. genRuleModules := `
  4265. genrule {
  4266. name: "genrule_foo",
  4267. cmd: "generate-foo",
  4268. out: [
  4269. "generated_headers/foo/generated_header.h",
  4270. ],
  4271. export_include_dirs: [
  4272. "generated_headers",
  4273. ],
  4274. }
  4275. genrule {
  4276. name: "genrule_bar",
  4277. cmd: "generate-bar",
  4278. out: [
  4279. "generated_headers/bar/generated_header.h",
  4280. ],
  4281. export_include_dirs: [
  4282. "generated_headers",
  4283. ],
  4284. }
  4285. `
  4286. t.Run("ensure exported include dirs are not automatically re-exported from shared_libs", func(t *testing.T) {
  4287. ctx := testCc(t, genRuleModules+`
  4288. cc_library {
  4289. name: "libfoo",
  4290. srcs: ["foo.c"],
  4291. export_include_dirs: ["foo/standard"],
  4292. export_system_include_dirs: ["foo/system"],
  4293. generated_headers: ["genrule_foo"],
  4294. export_generated_headers: ["genrule_foo"],
  4295. }
  4296. cc_library {
  4297. name: "libbar",
  4298. srcs: ["bar.c"],
  4299. shared_libs: ["libfoo"],
  4300. export_include_dirs: ["bar/standard"],
  4301. export_system_include_dirs: ["bar/system"],
  4302. generated_headers: ["genrule_bar"],
  4303. export_generated_headers: ["genrule_bar"],
  4304. }
  4305. `)
  4306. foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
  4307. checkIncludeDirs(t, ctx, foo,
  4308. expectedIncludeDirs(`
  4309. foo/standard
  4310. .intermediates/genrule_foo/gen/generated_headers
  4311. `),
  4312. expectedSystemIncludeDirs(`foo/system`),
  4313. expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
  4314. expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
  4315. )
  4316. bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module()
  4317. checkIncludeDirs(t, ctx, bar,
  4318. expectedIncludeDirs(`
  4319. bar/standard
  4320. .intermediates/genrule_bar/gen/generated_headers
  4321. `),
  4322. expectedSystemIncludeDirs(`bar/system`),
  4323. expectedGeneratedHeaders(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`),
  4324. expectedOrderOnlyDeps(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`),
  4325. )
  4326. })
  4327. t.Run("ensure exported include dirs are automatically re-exported from whole_static_libs", func(t *testing.T) {
  4328. ctx := testCc(t, genRuleModules+`
  4329. cc_library {
  4330. name: "libfoo",
  4331. srcs: ["foo.c"],
  4332. export_include_dirs: ["foo/standard"],
  4333. export_system_include_dirs: ["foo/system"],
  4334. generated_headers: ["genrule_foo"],
  4335. export_generated_headers: ["genrule_foo"],
  4336. }
  4337. cc_library {
  4338. name: "libbar",
  4339. srcs: ["bar.c"],
  4340. whole_static_libs: ["libfoo"],
  4341. export_include_dirs: ["bar/standard"],
  4342. export_system_include_dirs: ["bar/system"],
  4343. generated_headers: ["genrule_bar"],
  4344. export_generated_headers: ["genrule_bar"],
  4345. }
  4346. `)
  4347. foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
  4348. checkIncludeDirs(t, ctx, foo,
  4349. expectedIncludeDirs(`
  4350. foo/standard
  4351. .intermediates/genrule_foo/gen/generated_headers
  4352. `),
  4353. expectedSystemIncludeDirs(`foo/system`),
  4354. expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
  4355. expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
  4356. )
  4357. bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module()
  4358. checkIncludeDirs(t, ctx, bar,
  4359. expectedIncludeDirs(`
  4360. bar/standard
  4361. foo/standard
  4362. .intermediates/genrule_foo/gen/generated_headers
  4363. .intermediates/genrule_bar/gen/generated_headers
  4364. `),
  4365. expectedSystemIncludeDirs(`
  4366. bar/system
  4367. foo/system
  4368. `),
  4369. expectedGeneratedHeaders(`
  4370. .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h
  4371. .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h
  4372. `),
  4373. expectedOrderOnlyDeps(`
  4374. .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h
  4375. .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h
  4376. `),
  4377. )
  4378. })
  4379. t.Run("ensure only aidl headers are exported", func(t *testing.T) {
  4380. ctx := android.GroupFixturePreparers(
  4381. prepareForCcTest,
  4382. aidl_library.PrepareForTestWithAidlLibrary,
  4383. ).RunTestWithBp(t, `
  4384. aidl_library {
  4385. name: "libfoo_aidl",
  4386. srcs: ["x/y/Bar.aidl"],
  4387. strip_import_prefix: "x",
  4388. }
  4389. cc_library_shared {
  4390. name: "libfoo",
  4391. srcs: [
  4392. "foo.c",
  4393. "b.aidl",
  4394. "a.proto",
  4395. ],
  4396. aidl: {
  4397. libs: ["libfoo_aidl"],
  4398. export_aidl_headers: true,
  4399. }
  4400. }
  4401. `).TestContext
  4402. foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
  4403. checkIncludeDirs(t, ctx, foo,
  4404. expectedIncludeDirs(`
  4405. .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl
  4406. .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library
  4407. `),
  4408. expectedSystemIncludeDirs(``),
  4409. expectedGeneratedHeaders(`
  4410. .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
  4411. .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
  4412. .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
  4413. .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/Bar.h
  4414. .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/BnBar.h
  4415. .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/BpBar.h
  4416. `),
  4417. expectedOrderOnlyDeps(`
  4418. .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
  4419. .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
  4420. .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
  4421. .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/Bar.h
  4422. .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/BnBar.h
  4423. .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/BpBar.h
  4424. `),
  4425. )
  4426. })
  4427. t.Run("ensure only proto headers are exported", func(t *testing.T) {
  4428. ctx := testCc(t, genRuleModules+`
  4429. cc_library_shared {
  4430. name: "libfoo",
  4431. srcs: [
  4432. "foo.c",
  4433. "b.aidl",
  4434. "a.proto",
  4435. ],
  4436. proto: {
  4437. export_proto_headers: true,
  4438. }
  4439. }
  4440. `)
  4441. foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
  4442. checkIncludeDirs(t, ctx, foo,
  4443. expectedIncludeDirs(`
  4444. .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto
  4445. `),
  4446. expectedSystemIncludeDirs(``),
  4447. expectedGeneratedHeaders(`
  4448. .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h
  4449. `),
  4450. expectedOrderOnlyDeps(`
  4451. .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h
  4452. `),
  4453. )
  4454. })
  4455. t.Run("ensure only sysprop headers are exported", func(t *testing.T) {
  4456. ctx := testCc(t, genRuleModules+`
  4457. cc_library_shared {
  4458. name: "libfoo",
  4459. srcs: [
  4460. "foo.c",
  4461. "path/to/a.sysprop",
  4462. "b.aidl",
  4463. "a.proto",
  4464. ],
  4465. }
  4466. `)
  4467. foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
  4468. checkIncludeDirs(t, ctx, foo,
  4469. expectedIncludeDirs(`
  4470. .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include
  4471. `),
  4472. expectedSystemIncludeDirs(``),
  4473. expectedGeneratedHeaders(`
  4474. .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include/path/to/a.sysprop.h
  4475. `),
  4476. expectedOrderOnlyDeps(`
  4477. .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include/path/to/a.sysprop.h
  4478. .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/public/include/path/to/a.sysprop.h
  4479. `),
  4480. )
  4481. })
  4482. }
  4483. func TestIncludeDirectoryOrdering(t *testing.T) {
  4484. t.Parallel()
  4485. baseExpectedFlags := []string{
  4486. "${config.ArmThumbCflags}",
  4487. "${config.ArmCflags}",
  4488. "${config.CommonGlobalCflags}",
  4489. "${config.DeviceGlobalCflags}",
  4490. "${config.ExternalCflags}",
  4491. "${config.ArmToolchainCflags}",
  4492. "${config.ArmArmv7ANeonCflags}",
  4493. "${config.ArmGenericCflags}",
  4494. "-target",
  4495. "armv7a-linux-androideabi21",
  4496. }
  4497. expectedIncludes := []string{
  4498. "external/foo/android_arm_export_include_dirs",
  4499. "external/foo/lib32_export_include_dirs",
  4500. "external/foo/arm_export_include_dirs",
  4501. "external/foo/android_export_include_dirs",
  4502. "external/foo/linux_export_include_dirs",
  4503. "external/foo/export_include_dirs",
  4504. "external/foo/android_arm_local_include_dirs",
  4505. "external/foo/lib32_local_include_dirs",
  4506. "external/foo/arm_local_include_dirs",
  4507. "external/foo/android_local_include_dirs",
  4508. "external/foo/linux_local_include_dirs",
  4509. "external/foo/local_include_dirs",
  4510. "external/foo",
  4511. "external/foo/libheader1",
  4512. "external/foo/libheader2",
  4513. "external/foo/libwhole1",
  4514. "external/foo/libwhole2",
  4515. "external/foo/libstatic1",
  4516. "external/foo/libstatic2",
  4517. "external/foo/libshared1",
  4518. "external/foo/libshared2",
  4519. "external/foo/liblinux",
  4520. "external/foo/libandroid",
  4521. "external/foo/libarm",
  4522. "external/foo/lib32",
  4523. "external/foo/libandroid_arm",
  4524. "defaults/cc/common/ndk_libc++_shared",
  4525. }
  4526. conly := []string{"-fPIC", "${config.CommonGlobalConlyflags}"}
  4527. cppOnly := []string{"-fPIC", "${config.CommonGlobalCppflags}", "${config.DeviceGlobalCppflags}", "${config.ArmCppflags}"}
  4528. cflags := []string{"-Werror", "-std=candcpp"}
  4529. cstd := []string{"-std=gnu17", "-std=conly"}
  4530. cppstd := []string{"-std=gnu++17", "-std=cpp", "-fno-rtti"}
  4531. lastIncludes := []string{
  4532. "out/soong/ndk/sysroot/usr/include",
  4533. "out/soong/ndk/sysroot/usr/include/arm-linux-androideabi",
  4534. }
  4535. combineSlices := func(slices ...[]string) []string {
  4536. var ret []string
  4537. for _, s := range slices {
  4538. ret = append(ret, s...)
  4539. }
  4540. return ret
  4541. }
  4542. testCases := []struct {
  4543. name string
  4544. src string
  4545. expected []string
  4546. }{
  4547. {
  4548. name: "c",
  4549. src: "foo.c",
  4550. expected: combineSlices(baseExpectedFlags, conly, expectedIncludes, cflags, cstd, lastIncludes, []string{"${config.NoOverrideGlobalCflags}", "${config.NoOverrideExternalGlobalCflags}"}),
  4551. },
  4552. {
  4553. name: "cc",
  4554. src: "foo.cc",
  4555. expected: combineSlices(baseExpectedFlags, cppOnly, expectedIncludes, cflags, cppstd, lastIncludes, []string{"${config.NoOverrideGlobalCflags}", "${config.NoOverrideExternalGlobalCflags}"}),
  4556. },
  4557. {
  4558. name: "assemble",
  4559. src: "foo.s",
  4560. expected: combineSlices(baseExpectedFlags, []string{"${config.CommonGlobalAsflags}"}, expectedIncludes, lastIncludes),
  4561. },
  4562. }
  4563. for _, tc := range testCases {
  4564. t.Run(tc.name, func(t *testing.T) {
  4565. bp := fmt.Sprintf(`
  4566. cc_library {
  4567. name: "libfoo",
  4568. srcs: ["%s"],
  4569. cflags: ["-std=candcpp"],
  4570. conlyflags: ["-std=conly"],
  4571. cppflags: ["-std=cpp"],
  4572. local_include_dirs: ["local_include_dirs"],
  4573. export_include_dirs: ["export_include_dirs"],
  4574. export_system_include_dirs: ["export_system_include_dirs"],
  4575. static_libs: ["libstatic1", "libstatic2"],
  4576. whole_static_libs: ["libwhole1", "libwhole2"],
  4577. shared_libs: ["libshared1", "libshared2"],
  4578. header_libs: ["libheader1", "libheader2"],
  4579. target: {
  4580. android: {
  4581. shared_libs: ["libandroid"],
  4582. local_include_dirs: ["android_local_include_dirs"],
  4583. export_include_dirs: ["android_export_include_dirs"],
  4584. },
  4585. android_arm: {
  4586. shared_libs: ["libandroid_arm"],
  4587. local_include_dirs: ["android_arm_local_include_dirs"],
  4588. export_include_dirs: ["android_arm_export_include_dirs"],
  4589. },
  4590. linux: {
  4591. shared_libs: ["liblinux"],
  4592. local_include_dirs: ["linux_local_include_dirs"],
  4593. export_include_dirs: ["linux_export_include_dirs"],
  4594. },
  4595. },
  4596. multilib: {
  4597. lib32: {
  4598. shared_libs: ["lib32"],
  4599. local_include_dirs: ["lib32_local_include_dirs"],
  4600. export_include_dirs: ["lib32_export_include_dirs"],
  4601. },
  4602. },
  4603. arch: {
  4604. arm: {
  4605. shared_libs: ["libarm"],
  4606. local_include_dirs: ["arm_local_include_dirs"],
  4607. export_include_dirs: ["arm_export_include_dirs"],
  4608. },
  4609. },
  4610. stl: "libc++",
  4611. sdk_version: "minimum",
  4612. }
  4613. cc_library_headers {
  4614. name: "libheader1",
  4615. export_include_dirs: ["libheader1"],
  4616. sdk_version: "minimum",
  4617. stl: "none",
  4618. }
  4619. cc_library_headers {
  4620. name: "libheader2",
  4621. export_include_dirs: ["libheader2"],
  4622. sdk_version: "minimum",
  4623. stl: "none",
  4624. }
  4625. `, tc.src)
  4626. libs := []string{
  4627. "libstatic1",
  4628. "libstatic2",
  4629. "libwhole1",
  4630. "libwhole2",
  4631. "libshared1",
  4632. "libshared2",
  4633. "libandroid",
  4634. "libandroid_arm",
  4635. "liblinux",
  4636. "lib32",
  4637. "libarm",
  4638. }
  4639. for _, lib := range libs {
  4640. bp += fmt.Sprintf(`
  4641. cc_library {
  4642. name: "%s",
  4643. export_include_dirs: ["%s"],
  4644. sdk_version: "minimum",
  4645. stl: "none",
  4646. }
  4647. `, lib, lib)
  4648. }
  4649. ctx := android.GroupFixturePreparers(
  4650. PrepareForIntegrationTestWithCc,
  4651. android.FixtureAddTextFile("external/foo/Android.bp", bp),
  4652. ).RunTest(t)
  4653. // Use the arm variant instead of the arm64 variant so that it gets headers from
  4654. // ndk_libandroid_support to test LateStaticLibs.
  4655. cflags := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_sdk_static").Output("obj/external/foo/foo.o").Args["cFlags"]
  4656. var includes []string
  4657. flags := strings.Split(cflags, " ")
  4658. for _, flag := range flags {
  4659. if strings.HasPrefix(flag, "-I") {
  4660. includes = append(includes, strings.TrimPrefix(flag, "-I"))
  4661. } else if flag == "-isystem" {
  4662. // skip isystem, include next
  4663. } else if len(flag) > 0 {
  4664. includes = append(includes, flag)
  4665. }
  4666. }
  4667. android.AssertArrayString(t, "includes", tc.expected, includes)
  4668. })
  4669. }
  4670. }
  4671. func TestAddnoOverride64GlobalCflags(t *testing.T) {
  4672. t.Parallel()
  4673. ctx := testCc(t, `
  4674. cc_library_shared {
  4675. name: "libclient",
  4676. srcs: ["foo.c"],
  4677. shared_libs: ["libfoo#1"],
  4678. }
  4679. cc_library_shared {
  4680. name: "libfoo",
  4681. srcs: ["foo.c"],
  4682. shared_libs: ["libbar"],
  4683. export_shared_lib_headers: ["libbar"],
  4684. stubs: {
  4685. symbol_file: "foo.map.txt",
  4686. versions: ["1", "2", "3"],
  4687. },
  4688. }
  4689. cc_library_shared {
  4690. name: "libbar",
  4691. export_include_dirs: ["include/libbar"],
  4692. srcs: ["foo.c"],
  4693. }`)
  4694. cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
  4695. if !strings.Contains(cFlags, "${config.NoOverride64GlobalCflags}") {
  4696. t.Errorf("expected %q in cflags, got %q", "${config.NoOverride64GlobalCflags}", cFlags)
  4697. }
  4698. }
  4699. func TestCcBuildBrokenClangProperty(t *testing.T) {
  4700. t.Parallel()
  4701. tests := []struct {
  4702. name string
  4703. clang bool
  4704. BuildBrokenClangProperty bool
  4705. err string
  4706. }{
  4707. {
  4708. name: "error when clang is set to false",
  4709. clang: false,
  4710. err: "is no longer supported",
  4711. },
  4712. {
  4713. name: "error when clang is set to true",
  4714. clang: true,
  4715. err: "property is deprecated, see Changes.md",
  4716. },
  4717. {
  4718. name: "no error when BuildBrokenClangProperty is explicitly set to true",
  4719. clang: true,
  4720. BuildBrokenClangProperty: true,
  4721. },
  4722. }
  4723. for _, test := range tests {
  4724. t.Run(test.name, func(t *testing.T) {
  4725. bp := fmt.Sprintf(`
  4726. cc_library {
  4727. name: "foo",
  4728. clang: %t,
  4729. }`, test.clang)
  4730. if test.err == "" {
  4731. android.GroupFixturePreparers(
  4732. prepareForCcTest,
  4733. android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
  4734. if test.BuildBrokenClangProperty {
  4735. variables.BuildBrokenClangProperty = test.BuildBrokenClangProperty
  4736. }
  4737. }),
  4738. ).RunTestWithBp(t, bp)
  4739. } else {
  4740. prepareForCcTest.
  4741. ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(test.err)).
  4742. RunTestWithBp(t, bp)
  4743. }
  4744. })
  4745. }
  4746. }
  4747. func TestCcBuildBrokenClangAsFlags(t *testing.T) {
  4748. t.Parallel()
  4749. tests := []struct {
  4750. name string
  4751. clangAsFlags []string
  4752. BuildBrokenClangAsFlags bool
  4753. err string
  4754. }{
  4755. {
  4756. name: "error when clang_asflags is set",
  4757. clangAsFlags: []string{"-a", "-b"},
  4758. err: "clang_asflags: property is deprecated",
  4759. },
  4760. {
  4761. name: "no error when BuildBrokenClangAsFlags is explicitly set to true",
  4762. clangAsFlags: []string{"-a", "-b"},
  4763. BuildBrokenClangAsFlags: true,
  4764. },
  4765. }
  4766. for _, test := range tests {
  4767. t.Run(test.name, func(t *testing.T) {
  4768. bp := fmt.Sprintf(`
  4769. cc_library {
  4770. name: "foo",
  4771. clang_asflags: %s,
  4772. }`, `["`+strings.Join(test.clangAsFlags, `","`)+`"]`)
  4773. if test.err == "" {
  4774. android.GroupFixturePreparers(
  4775. prepareForCcTest,
  4776. android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
  4777. if test.BuildBrokenClangAsFlags {
  4778. variables.BuildBrokenClangAsFlags = test.BuildBrokenClangAsFlags
  4779. }
  4780. }),
  4781. ).RunTestWithBp(t, bp)
  4782. } else {
  4783. prepareForCcTest.
  4784. ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(test.err)).
  4785. RunTestWithBp(t, bp)
  4786. }
  4787. })
  4788. }
  4789. }
  4790. func TestCcBuildBrokenClangCFlags(t *testing.T) {
  4791. t.Parallel()
  4792. tests := []struct {
  4793. name string
  4794. clangCFlags []string
  4795. BuildBrokenClangCFlags bool
  4796. err string
  4797. }{
  4798. {
  4799. name: "error when clang_cflags is set",
  4800. clangCFlags: []string{"-a", "-b"},
  4801. err: "clang_cflags: property is deprecated",
  4802. },
  4803. {
  4804. name: "no error when BuildBrokenClangCFlags is explicitly set to true",
  4805. clangCFlags: []string{"-a", "-b"},
  4806. BuildBrokenClangCFlags: true,
  4807. },
  4808. }
  4809. for _, test := range tests {
  4810. t.Run(test.name, func(t *testing.T) {
  4811. bp := fmt.Sprintf(`
  4812. cc_library {
  4813. name: "foo",
  4814. clang_cflags: %s,
  4815. }`, `["`+strings.Join(test.clangCFlags, `","`)+`"]`)
  4816. if test.err == "" {
  4817. android.GroupFixturePreparers(
  4818. prepareForCcTest,
  4819. android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
  4820. if test.BuildBrokenClangCFlags {
  4821. variables.BuildBrokenClangCFlags = test.BuildBrokenClangCFlags
  4822. }
  4823. }),
  4824. ).RunTestWithBp(t, bp)
  4825. } else {
  4826. prepareForCcTest.
  4827. ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(test.err)).
  4828. RunTestWithBp(t, bp)
  4829. }
  4830. })
  4831. }
  4832. }
  4833. func TestDclaLibraryInApex(t *testing.T) {
  4834. t.Parallel()
  4835. bp := `
  4836. cc_library_shared {
  4837. name: "cc_lib_in_apex",
  4838. srcs: ["foo.cc"],
  4839. apex_available: ["myapex"],
  4840. bazel_module: { label: "//foo/bar:bar" },
  4841. }`
  4842. label := "//foo/bar:bar"
  4843. arch64 := "arm64_armv8-a"
  4844. arch32 := "arm_armv7-a-neon"
  4845. apexCfgKey := android.ApexConfigKey{
  4846. WithinApex: true,
  4847. ApexSdkVersion: "28",
  4848. }
  4849. result := android.GroupFixturePreparers(
  4850. prepareForCcTest,
  4851. android.FixtureRegisterWithContext(registerTestMutators),
  4852. android.FixtureModifyConfig(func(config android.Config) {
  4853. config.BazelContext = android.MockBazelContext{
  4854. OutputBaseDir: "outputbase",
  4855. LabelToCcInfo: map[string]cquery.CcInfo{
  4856. android.BuildMockBazelContextResultKey(label, arch32, android.Android, apexCfgKey): cquery.CcInfo{
  4857. RootDynamicLibraries: []string{"foo.so"},
  4858. },
  4859. android.BuildMockBazelContextResultKey(label, arch64, android.Android, apexCfgKey): cquery.CcInfo{
  4860. RootDynamicLibraries: []string{"foo.so"},
  4861. },
  4862. },
  4863. BazelRequests: make(map[string]bool),
  4864. }
  4865. }),
  4866. ).RunTestWithBp(t, bp)
  4867. ctx := result.TestContext
  4868. // Test if the bazel request is queued correctly
  4869. key := android.BuildMockBazelContextRequestKey(label, cquery.GetCcInfo, arch32, android.Android, apexCfgKey)
  4870. if !ctx.Config().BazelContext.(android.MockBazelContext).BazelRequests[key] {
  4871. t.Errorf("Bazel request was not queued: %s", key)
  4872. }
  4873. sharedFoo := ctx.ModuleForTests(ccLibInApex, "android_arm_armv7-a-neon_shared_"+apexVariationName).Module()
  4874. producer := sharedFoo.(android.OutputFileProducer)
  4875. outputFiles, err := producer.OutputFiles("")
  4876. if err != nil {
  4877. t.Errorf("Unexpected error getting cc_object outputfiles %s", err)
  4878. }
  4879. expectedOutputFiles := []string{"outputbase/execroot/__main__/foo.so"}
  4880. android.AssertDeepEquals(t, "output files", expectedOutputFiles, outputFiles.Strings())
  4881. }
  4882. func TestDisableSanitizerVariantsInMixedBuilds(t *testing.T) {
  4883. t.Parallel()
  4884. bp := `
  4885. cc_library_static {
  4886. name: "foo_ubsan_minimal",
  4887. srcs: ["foo.cc"],
  4888. bazel_module: { label: "//foo_ubsan_minimal" },
  4889. sanitize: {
  4890. all_undefined: true,
  4891. integer_overflow: true,
  4892. },
  4893. }
  4894. cc_library_static {
  4895. name: "foo",
  4896. srcs: ["foo.cc"],
  4897. bazel_module: { label: "//foo" },
  4898. sanitize: {
  4899. address: true,
  4900. hwaddress: true,
  4901. fuzzer: true,
  4902. integer_overflow: true,
  4903. scs: true,
  4904. },
  4905. }
  4906. cc_library_static {
  4907. name: "foo_tsan",
  4908. srcs: ["foo.cc"],
  4909. bazel_module: { label: "//foo_tsan" },
  4910. sanitize: {
  4911. thread: true,
  4912. },
  4913. }
  4914. cc_library_static {
  4915. name: "foo_cfi",
  4916. srcs: ["foo.cc"],
  4917. bazel_module: { label: "//foo_cfi" },
  4918. sanitize: {
  4919. cfi: true,
  4920. },
  4921. }
  4922. cc_library_static {
  4923. name: "foo_memtag_stack",
  4924. srcs: ["foo.cc"],
  4925. bazel_module: { label: "//foo_memtag_stack" },
  4926. sanitize: {
  4927. memtag_stack: true,
  4928. },
  4929. }
  4930. cc_library_static {
  4931. name: "foo_memtag_heap",
  4932. srcs: ["foo.cc"],
  4933. bazel_module: { label: "//foo_memtag_heap" },
  4934. sanitize: {
  4935. memtag_heap: true,
  4936. },
  4937. }
  4938. cc_library_static {
  4939. name: "foo_safestack",
  4940. srcs: ["foo.cc"],
  4941. bazel_module: { label: "//foo_safestack" },
  4942. sanitize: {
  4943. safestack: true,
  4944. },
  4945. }
  4946. cc_library_static {
  4947. name: "foo_scudo",
  4948. srcs: ["foo.cc"],
  4949. bazel_module: { label: "//foo_scudo" },
  4950. sanitize: {
  4951. scudo: true,
  4952. },
  4953. }
  4954. `
  4955. testcases := []struct {
  4956. name string
  4957. variant string
  4958. expectedOutputPaths []string
  4959. }{
  4960. {
  4961. name: "foo_ubsan_minimal",
  4962. variant: "android_arm64_armv8-a_static_apex28",
  4963. expectedOutputPaths: []string{
  4964. "outputbase/execroot/__main__/foo_ubsan_minimal.a",
  4965. },
  4966. },
  4967. {
  4968. name: "foo",
  4969. variant: "android_arm64_armv8-a_static_apex28",
  4970. expectedOutputPaths: []string{
  4971. "outputbase/execroot/__main__/foo.a",
  4972. },
  4973. },
  4974. {
  4975. name: "foo",
  4976. variant: "android_arm_armv7-a-neon_static_asan_apex28",
  4977. expectedOutputPaths: []string{
  4978. "out/soong/.intermediates/foo/android_arm_armv7-a-neon_static_asan_apex28/foo.a",
  4979. },
  4980. },
  4981. {
  4982. name: "foo",
  4983. variant: "android_arm64_armv8-a_static_hwasan_apex28",
  4984. expectedOutputPaths: []string{
  4985. "out/soong/.intermediates/foo/android_arm64_armv8-a_static_hwasan_apex28/foo.a",
  4986. },
  4987. },
  4988. {
  4989. name: "foo",
  4990. variant: "android_arm64_armv8-a_static_fuzzer_apex28",
  4991. expectedOutputPaths: []string{
  4992. "out/soong/.intermediates/foo/android_arm64_armv8-a_static_fuzzer_apex28/foo.a",
  4993. },
  4994. },
  4995. {
  4996. name: "foo",
  4997. variant: "android_arm_armv7-a-neon_static_asan_fuzzer_apex28",
  4998. expectedOutputPaths: []string{
  4999. "out/soong/.intermediates/foo/android_arm_armv7-a-neon_static_asan_fuzzer_apex28/foo.a",
  5000. },
  5001. },
  5002. {
  5003. name: "foo",
  5004. variant: "android_arm64_armv8-a_static_hwasan_fuzzer_apex28",
  5005. expectedOutputPaths: []string{
  5006. "out/soong/.intermediates/foo/android_arm64_armv8-a_static_hwasan_fuzzer_apex28/foo.a",
  5007. },
  5008. },
  5009. {
  5010. name: "foo",
  5011. variant: "android_arm64_armv8-a_static_scs_apex28",
  5012. expectedOutputPaths: []string{
  5013. "out/soong/.intermediates/foo/android_arm64_armv8-a_static_scs_apex28/foo.a",
  5014. },
  5015. },
  5016. {
  5017. name: "foo",
  5018. variant: "android_arm64_armv8-a_static_hwasan_scs_apex28",
  5019. expectedOutputPaths: []string{
  5020. "out/soong/.intermediates/foo/android_arm64_armv8-a_static_hwasan_scs_apex28/foo.a",
  5021. },
  5022. },
  5023. {
  5024. name: "foo",
  5025. variant: "android_arm64_armv8-a_static_hwasan_scs_fuzzer_apex28",
  5026. expectedOutputPaths: []string{
  5027. "out/soong/.intermediates/foo/android_arm64_armv8-a_static_hwasan_scs_fuzzer_apex28/foo.a",
  5028. },
  5029. },
  5030. {
  5031. name: "foo_tsan",
  5032. variant: "android_arm64_armv8-a_static_apex28",
  5033. expectedOutputPaths: []string{
  5034. "outputbase/execroot/__main__/foo_tsan.a",
  5035. },
  5036. },
  5037. {
  5038. name: "foo_tsan",
  5039. variant: "android_arm64_armv8-a_static_tsan_apex28",
  5040. expectedOutputPaths: []string{
  5041. "out/soong/.intermediates/foo_tsan/android_arm64_armv8-a_static_tsan_apex28/foo_tsan.a",
  5042. },
  5043. },
  5044. {
  5045. name: "foo_cfi",
  5046. variant: "android_arm64_armv8-a_static_apex28",
  5047. expectedOutputPaths: []string{
  5048. "outputbase/execroot/__main__/foo_cfi.a",
  5049. },
  5050. },
  5051. {
  5052. name: "foo_cfi",
  5053. variant: "android_arm64_armv8-a_static_cfi_apex28",
  5054. expectedOutputPaths: []string{
  5055. "outputbase/execroot/__main__/foo_cfi.a",
  5056. },
  5057. },
  5058. {
  5059. name: "foo_memtag_stack",
  5060. variant: "android_arm64_armv8-a_static_apex28",
  5061. expectedOutputPaths: []string{
  5062. "out/soong/.intermediates/foo_memtag_stack/android_arm64_armv8-a_static_apex28/foo_memtag_stack.a",
  5063. },
  5064. },
  5065. {
  5066. name: "foo_memtag_heap",
  5067. variant: "android_arm64_armv8-a_static_apex28",
  5068. expectedOutputPaths: []string{
  5069. "out/soong/.intermediates/foo_memtag_heap/android_arm64_armv8-a_static_apex28/foo_memtag_heap.a",
  5070. },
  5071. },
  5072. {
  5073. name: "foo_safestack",
  5074. variant: "android_arm64_armv8-a_static_apex28",
  5075. expectedOutputPaths: []string{
  5076. "out/soong/.intermediates/foo_safestack/android_arm64_armv8-a_static_apex28/foo_safestack.a",
  5077. },
  5078. },
  5079. {
  5080. name: "foo_scudo",
  5081. variant: "android_arm64_armv8-a_static_apex28",
  5082. expectedOutputPaths: []string{
  5083. "out/soong/.intermediates/foo_scudo/android_arm64_armv8-a_static_apex28/foo_scudo.a",
  5084. },
  5085. },
  5086. }
  5087. ctx := android.GroupFixturePreparers(
  5088. prepareForCcTest,
  5089. prepareForAsanTest,
  5090. android.FixtureRegisterWithContext(registerTestMutators),
  5091. android.FixtureModifyConfig(func(config android.Config) {
  5092. config.BazelContext = android.MockBazelContext{
  5093. OutputBaseDir: "outputbase",
  5094. LabelToCcInfo: map[string]cquery.CcInfo{
  5095. "//foo_ubsan_minimal": {
  5096. RootStaticArchives: []string{"foo_ubsan_minimal.a"},
  5097. },
  5098. "//foo": {
  5099. RootStaticArchives: []string{"foo.a"},
  5100. },
  5101. "//foo_tsan": {
  5102. RootStaticArchives: []string{"foo_tsan.a"},
  5103. },
  5104. "//foo_cfi": {
  5105. RootStaticArchives: []string{"foo_cfi.a"},
  5106. },
  5107. "//foo_memtag_stack": {
  5108. RootStaticArchives: []string{"INVALID_ARCHIVE.a"},
  5109. },
  5110. "//foo_memtag_heap": {
  5111. RootStaticArchives: []string{"INVALID_ARCHIVE.a"},
  5112. },
  5113. "//foo_safestack": {
  5114. RootStaticArchives: []string{"INVALID_ARCHIVE.a"},
  5115. },
  5116. "//foo_scudo": {
  5117. RootStaticArchives: []string{"INVALID_ARCHIVE.a"},
  5118. },
  5119. },
  5120. }
  5121. }),
  5122. ).RunTestWithBp(t, bp).TestContext
  5123. for _, tc := range testcases {
  5124. fooMod := ctx.ModuleForTests(tc.name, tc.variant).Module()
  5125. outputFiles, err := fooMod.(android.OutputFileProducer).OutputFiles("")
  5126. if err != nil {
  5127. t.Errorf("Unexpected error getting cc_object outputfiles %s", err)
  5128. }
  5129. android.AssertPathsRelativeToTopEquals(t, "output files", tc.expectedOutputPaths, outputFiles)
  5130. }
  5131. }