cc_sdk_test.go 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703
  1. // Copyright (C) 2019 The Android Open Source Project
  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 sdk
  15. import (
  16. "testing"
  17. "android/soong/android"
  18. "android/soong/cc"
  19. )
  20. var ccTestFs = map[string][]byte{
  21. "Test.cpp": nil,
  22. "include/Test.h": nil,
  23. "include-android/AndroidTest.h": nil,
  24. "include-host/HostTest.h": nil,
  25. "arm64/include/Arm64Test.h": nil,
  26. "libfoo.so": nil,
  27. "aidl/foo/bar/Test.aidl": nil,
  28. "some/where/stubslib.map.txt": nil,
  29. }
  30. func testSdkWithCc(t *testing.T, bp string) *testSdkResult {
  31. t.Helper()
  32. return testSdkWithFs(t, bp, ccTestFs)
  33. }
  34. // Contains tests for SDK members provided by the cc package.
  35. func TestSingleDeviceOsAssumption(t *testing.T) {
  36. // Mock a module with DeviceSupported() == true.
  37. s := &sdk{}
  38. android.InitAndroidArchModule(s, android.DeviceSupported, android.MultilibCommon)
  39. osTypes := s.getPossibleOsTypes()
  40. if len(osTypes) != 1 {
  41. // The snapshot generation assumes there is a single device OS. If more are
  42. // added it might need to disable them by default, like it does for host
  43. // OS'es.
  44. t.Errorf("expected a single device OS, got %v", osTypes)
  45. }
  46. }
  47. func TestSdkIsCompileMultilibBoth(t *testing.T) {
  48. result := testSdkWithCc(t, `
  49. sdk {
  50. name: "mysdk",
  51. native_shared_libs: ["sdkmember"],
  52. }
  53. cc_library_shared {
  54. name: "sdkmember",
  55. srcs: ["Test.cpp"],
  56. stl: "none",
  57. }
  58. `)
  59. armOutput := result.Module("sdkmember", "android_arm_armv7-a-neon_shared").(*cc.Module).OutputFile()
  60. arm64Output := result.Module("sdkmember", "android_arm64_armv8-a_shared").(*cc.Module).OutputFile()
  61. var inputs []string
  62. buildParams := result.Module("mysdk", android.CommonOS.Name).BuildParamsForTests()
  63. for _, bp := range buildParams {
  64. if bp.Input != nil {
  65. inputs = append(inputs, bp.Input.String())
  66. }
  67. }
  68. // ensure that both 32/64 outputs are inputs of the sdk snapshot
  69. ensureListContains(t, inputs, armOutput.String())
  70. ensureListContains(t, inputs, arm64Output.String())
  71. }
  72. func TestSdkCompileMultilibOverride(t *testing.T) {
  73. result := testSdkWithCc(t, `
  74. sdk {
  75. name: "mysdk",
  76. host_supported: true,
  77. native_shared_libs: ["sdkmember"],
  78. compile_multilib: "64",
  79. }
  80. cc_library_shared {
  81. name: "sdkmember",
  82. host_supported: true,
  83. srcs: ["Test.cpp"],
  84. stl: "none",
  85. compile_multilib: "64",
  86. }
  87. `)
  88. result.CheckSnapshot("mysdk", "",
  89. checkAndroidBpContents(`
  90. // This is auto-generated. DO NOT EDIT.
  91. cc_prebuilt_library_shared {
  92. name: "mysdk_sdkmember@current",
  93. sdk_member_name: "sdkmember",
  94. visibility: ["//visibility:public"],
  95. host_supported: true,
  96. installable: false,
  97. stl: "none",
  98. compile_multilib: "64",
  99. target: {
  100. host: {
  101. enabled: false,
  102. },
  103. android_arm64: {
  104. srcs: ["android/arm64/lib/sdkmember.so"],
  105. },
  106. linux_glibc: {
  107. enabled: true,
  108. },
  109. linux_glibc_x86_64: {
  110. srcs: ["linux_glibc/x86_64/lib/sdkmember.so"],
  111. },
  112. },
  113. }
  114. cc_prebuilt_library_shared {
  115. name: "sdkmember",
  116. prefer: false,
  117. visibility: ["//visibility:public"],
  118. host_supported: true,
  119. stl: "none",
  120. compile_multilib: "64",
  121. target: {
  122. host: {
  123. enabled: false,
  124. },
  125. android_arm64: {
  126. srcs: ["android/arm64/lib/sdkmember.so"],
  127. },
  128. linux_glibc: {
  129. enabled: true,
  130. },
  131. linux_glibc_x86_64: {
  132. srcs: ["linux_glibc/x86_64/lib/sdkmember.so"],
  133. },
  134. },
  135. }
  136. sdk_snapshot {
  137. name: "mysdk@current",
  138. visibility: ["//visibility:public"],
  139. host_supported: true,
  140. native_shared_libs: ["mysdk_sdkmember@current"],
  141. compile_multilib: "64",
  142. target: {
  143. host: {
  144. enabled: false,
  145. },
  146. linux_glibc: {
  147. enabled: true,
  148. },
  149. },
  150. }
  151. `),
  152. checkAllCopyRules(`
  153. .intermediates/sdkmember/android_arm64_armv8-a_shared/sdkmember.so -> android/arm64/lib/sdkmember.so
  154. .intermediates/sdkmember/linux_glibc_x86_64_shared/sdkmember.so -> linux_glibc/x86_64/lib/sdkmember.so
  155. `))
  156. }
  157. func TestBasicSdkWithCc(t *testing.T) {
  158. result := testSdkWithCc(t, `
  159. sdk {
  160. name: "mysdk",
  161. native_shared_libs: ["sdkmember"],
  162. }
  163. cc_library_shared {
  164. name: "sdkmember",
  165. system_shared_libs: [],
  166. stl: "none",
  167. apex_available: ["mysdkapex"],
  168. }
  169. sdk_snapshot {
  170. name: "mysdk@1",
  171. native_shared_libs: ["sdkmember_mysdk_1"],
  172. }
  173. sdk_snapshot {
  174. name: "mysdk@2",
  175. native_shared_libs: ["sdkmember_mysdk_2"],
  176. }
  177. cc_prebuilt_library_shared {
  178. name: "sdkmember",
  179. srcs: ["libfoo.so"],
  180. prefer: false,
  181. system_shared_libs: [],
  182. stl: "none",
  183. }
  184. cc_prebuilt_library_shared {
  185. name: "sdkmember_mysdk_1",
  186. sdk_member_name: "sdkmember",
  187. srcs: ["libfoo.so"],
  188. system_shared_libs: [],
  189. stl: "none",
  190. // TODO: remove //apex_available:platform
  191. apex_available: [
  192. "//apex_available:platform",
  193. "myapex",
  194. ],
  195. }
  196. cc_prebuilt_library_shared {
  197. name: "sdkmember_mysdk_2",
  198. sdk_member_name: "sdkmember",
  199. srcs: ["libfoo.so"],
  200. system_shared_libs: [],
  201. stl: "none",
  202. // TODO: remove //apex_available:platform
  203. apex_available: [
  204. "//apex_available:platform",
  205. "myapex2",
  206. ],
  207. }
  208. cc_library_shared {
  209. name: "mycpplib",
  210. srcs: ["Test.cpp"],
  211. shared_libs: ["sdkmember"],
  212. system_shared_libs: [],
  213. stl: "none",
  214. apex_available: [
  215. "myapex",
  216. "myapex2",
  217. ],
  218. }
  219. apex {
  220. name: "myapex",
  221. native_shared_libs: ["mycpplib"],
  222. uses_sdks: ["mysdk@1"],
  223. key: "myapex.key",
  224. certificate: ":myapex.cert",
  225. }
  226. apex {
  227. name: "myapex2",
  228. native_shared_libs: ["mycpplib"],
  229. uses_sdks: ["mysdk@2"],
  230. key: "myapex.key",
  231. certificate: ":myapex.cert",
  232. }
  233. apex {
  234. name: "mysdkapex",
  235. native_shared_libs: ["sdkmember"],
  236. key: "myapex.key",
  237. certificate: ":myapex.cert",
  238. }
  239. `)
  240. sdkMemberV1 := result.ModuleForTests("sdkmember_mysdk_1", "android_arm64_armv8-a_shared_apex10000_mysdk_1").Rule("toc").Output
  241. sdkMemberV2 := result.ModuleForTests("sdkmember_mysdk_2", "android_arm64_armv8-a_shared_apex10000_mysdk_2").Rule("toc").Output
  242. cpplibForMyApex := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_shared_apex10000_mysdk_1")
  243. cpplibForMyApex2 := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_shared_apex10000_mysdk_2")
  244. // Depending on the uses_sdks value, different libs are linked
  245. ensureListContains(t, pathsToStrings(cpplibForMyApex.Rule("ld").Implicits), sdkMemberV1.String())
  246. ensureListContains(t, pathsToStrings(cpplibForMyApex2.Rule("ld").Implicits), sdkMemberV2.String())
  247. }
  248. // Make sure the sdk can use host specific cc libraries static/shared and both.
  249. func TestHostSdkWithCc(t *testing.T) {
  250. testSdkWithCc(t, `
  251. sdk {
  252. name: "mysdk",
  253. device_supported: false,
  254. host_supported: true,
  255. native_shared_libs: ["sdkshared"],
  256. native_static_libs: ["sdkstatic"],
  257. }
  258. cc_library_host_shared {
  259. name: "sdkshared",
  260. stl: "none",
  261. }
  262. cc_library_host_static {
  263. name: "sdkstatic",
  264. stl: "none",
  265. }
  266. `)
  267. }
  268. // Make sure the sdk can use cc libraries static/shared and both.
  269. func TestSdkWithCc(t *testing.T) {
  270. testSdkWithCc(t, `
  271. sdk {
  272. name: "mysdk",
  273. native_shared_libs: ["sdkshared", "sdkboth1"],
  274. native_static_libs: ["sdkstatic", "sdkboth2"],
  275. }
  276. cc_library_shared {
  277. name: "sdkshared",
  278. stl: "none",
  279. }
  280. cc_library_static {
  281. name: "sdkstatic",
  282. stl: "none",
  283. }
  284. cc_library {
  285. name: "sdkboth1",
  286. stl: "none",
  287. }
  288. cc_library {
  289. name: "sdkboth2",
  290. stl: "none",
  291. }
  292. `)
  293. }
  294. func TestSnapshotWithObject(t *testing.T) {
  295. result := testSdkWithCc(t, `
  296. sdk {
  297. name: "mysdk",
  298. native_objects: ["crtobj"],
  299. }
  300. cc_object {
  301. name: "crtobj",
  302. stl: "none",
  303. sanitize: {
  304. never: true,
  305. },
  306. }
  307. `)
  308. result.CheckSnapshot("mysdk", "",
  309. checkAndroidBpContents(`
  310. // This is auto-generated. DO NOT EDIT.
  311. cc_prebuilt_object {
  312. name: "mysdk_crtobj@current",
  313. sdk_member_name: "crtobj",
  314. visibility: ["//visibility:public"],
  315. stl: "none",
  316. compile_multilib: "both",
  317. sanitize: {
  318. never: true,
  319. },
  320. arch: {
  321. arm64: {
  322. srcs: ["arm64/lib/crtobj.o"],
  323. },
  324. arm: {
  325. srcs: ["arm/lib/crtobj.o"],
  326. },
  327. },
  328. }
  329. cc_prebuilt_object {
  330. name: "crtobj",
  331. prefer: false,
  332. visibility: ["//visibility:public"],
  333. stl: "none",
  334. compile_multilib: "both",
  335. sanitize: {
  336. never: true,
  337. },
  338. arch: {
  339. arm64: {
  340. srcs: ["arm64/lib/crtobj.o"],
  341. },
  342. arm: {
  343. srcs: ["arm/lib/crtobj.o"],
  344. },
  345. },
  346. }
  347. sdk_snapshot {
  348. name: "mysdk@current",
  349. visibility: ["//visibility:public"],
  350. native_objects: ["mysdk_crtobj@current"],
  351. }
  352. `),
  353. checkAllCopyRules(`
  354. .intermediates/crtobj/android_arm64_armv8-a/crtobj.o -> arm64/lib/crtobj.o
  355. .intermediates/crtobj/android_arm_armv7-a-neon/crtobj.o -> arm/lib/crtobj.o
  356. `),
  357. )
  358. }
  359. func TestSnapshotWithCcDuplicateHeaders(t *testing.T) {
  360. result := testSdkWithCc(t, `
  361. sdk {
  362. name: "mysdk",
  363. native_shared_libs: ["mynativelib1", "mynativelib2"],
  364. }
  365. cc_library_shared {
  366. name: "mynativelib1",
  367. srcs: [
  368. "Test.cpp",
  369. ],
  370. export_include_dirs: ["include"],
  371. stl: "none",
  372. }
  373. cc_library_shared {
  374. name: "mynativelib2",
  375. srcs: [
  376. "Test.cpp",
  377. ],
  378. export_include_dirs: ["include"],
  379. stl: "none",
  380. }
  381. `)
  382. result.CheckSnapshot("mysdk", "",
  383. checkAllCopyRules(`
  384. include/Test.h -> include/include/Test.h
  385. .intermediates/mynativelib1/android_arm64_armv8-a_shared/mynativelib1.so -> arm64/lib/mynativelib1.so
  386. .intermediates/mynativelib1/android_arm_armv7-a-neon_shared/mynativelib1.so -> arm/lib/mynativelib1.so
  387. .intermediates/mynativelib2/android_arm64_armv8-a_shared/mynativelib2.so -> arm64/lib/mynativelib2.so
  388. .intermediates/mynativelib2/android_arm_armv7-a-neon_shared/mynativelib2.so -> arm/lib/mynativelib2.so
  389. `),
  390. )
  391. }
  392. // Verify that when the shared library has some common and some arch specific
  393. // properties that the generated snapshot is optimized properly. Substruct
  394. // handling is tested with the sanitize clauses (but note there's a lot of
  395. // built-in logic in sanitize.go that can affect those flags).
  396. func TestSnapshotWithCcSharedLibraryCommonProperties(t *testing.T) {
  397. result := testSdkWithCc(t, `
  398. sdk {
  399. name: "mysdk",
  400. native_shared_libs: ["mynativelib"],
  401. }
  402. cc_library_shared {
  403. name: "mynativelib",
  404. srcs: [
  405. "Test.cpp",
  406. "aidl/foo/bar/Test.aidl",
  407. ],
  408. export_include_dirs: ["include"],
  409. sanitize: {
  410. fuzzer: false,
  411. integer_overflow: true,
  412. diag: { undefined: false },
  413. },
  414. arch: {
  415. arm64: {
  416. export_system_include_dirs: ["arm64/include"],
  417. sanitize: {
  418. hwaddress: true,
  419. integer_overflow: false,
  420. },
  421. },
  422. },
  423. stl: "none",
  424. }
  425. `)
  426. result.CheckSnapshot("mysdk", "",
  427. checkAndroidBpContents(`
  428. // This is auto-generated. DO NOT EDIT.
  429. cc_prebuilt_library_shared {
  430. name: "mysdk_mynativelib@current",
  431. sdk_member_name: "mynativelib",
  432. visibility: ["//visibility:public"],
  433. installable: false,
  434. stl: "none",
  435. compile_multilib: "both",
  436. export_include_dirs: ["include/include"],
  437. sanitize: {
  438. fuzzer: false,
  439. diag: {
  440. undefined: false,
  441. },
  442. },
  443. arch: {
  444. arm64: {
  445. srcs: ["arm64/lib/mynativelib.so"],
  446. export_system_include_dirs: ["arm64/include/arm64/include"],
  447. sanitize: {
  448. hwaddress: true,
  449. integer_overflow: false,
  450. },
  451. },
  452. arm: {
  453. srcs: ["arm/lib/mynativelib.so"],
  454. sanitize: {
  455. integer_overflow: true,
  456. },
  457. },
  458. },
  459. }
  460. cc_prebuilt_library_shared {
  461. name: "mynativelib",
  462. prefer: false,
  463. visibility: ["//visibility:public"],
  464. stl: "none",
  465. compile_multilib: "both",
  466. export_include_dirs: ["include/include"],
  467. sanitize: {
  468. fuzzer: false,
  469. diag: {
  470. undefined: false,
  471. },
  472. },
  473. arch: {
  474. arm64: {
  475. srcs: ["arm64/lib/mynativelib.so"],
  476. export_system_include_dirs: ["arm64/include/arm64/include"],
  477. sanitize: {
  478. hwaddress: true,
  479. integer_overflow: false,
  480. },
  481. },
  482. arm: {
  483. srcs: ["arm/lib/mynativelib.so"],
  484. sanitize: {
  485. integer_overflow: true,
  486. },
  487. },
  488. },
  489. }
  490. sdk_snapshot {
  491. name: "mysdk@current",
  492. visibility: ["//visibility:public"],
  493. native_shared_libs: ["mysdk_mynativelib@current"],
  494. }
  495. `),
  496. checkAllCopyRules(`
  497. include/Test.h -> include/include/Test.h
  498. .intermediates/mynativelib/android_arm64_armv8-a_shared_hwasan/mynativelib.so -> arm64/lib/mynativelib.so
  499. arm64/include/Arm64Test.h -> arm64/include/arm64/include/Arm64Test.h
  500. .intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
  501. )
  502. }
  503. func TestSnapshotWithCcBinary(t *testing.T) {
  504. result := testSdkWithCc(t, `
  505. module_exports {
  506. name: "mymodule_exports",
  507. native_binaries: ["mynativebinary"],
  508. }
  509. cc_binary {
  510. name: "mynativebinary",
  511. srcs: [
  512. "Test.cpp",
  513. ],
  514. compile_multilib: "both",
  515. }
  516. `)
  517. result.CheckSnapshot("mymodule_exports", "",
  518. checkAndroidBpContents(`
  519. // This is auto-generated. DO NOT EDIT.
  520. cc_prebuilt_binary {
  521. name: "mymodule_exports_mynativebinary@current",
  522. sdk_member_name: "mynativebinary",
  523. visibility: ["//visibility:public"],
  524. installable: false,
  525. compile_multilib: "both",
  526. arch: {
  527. arm64: {
  528. srcs: ["arm64/bin/mynativebinary"],
  529. },
  530. arm: {
  531. srcs: ["arm/bin/mynativebinary"],
  532. },
  533. },
  534. }
  535. cc_prebuilt_binary {
  536. name: "mynativebinary",
  537. prefer: false,
  538. visibility: ["//visibility:public"],
  539. compile_multilib: "both",
  540. arch: {
  541. arm64: {
  542. srcs: ["arm64/bin/mynativebinary"],
  543. },
  544. arm: {
  545. srcs: ["arm/bin/mynativebinary"],
  546. },
  547. },
  548. }
  549. module_exports_snapshot {
  550. name: "mymodule_exports@current",
  551. visibility: ["//visibility:public"],
  552. native_binaries: ["mymodule_exports_mynativebinary@current"],
  553. }
  554. `),
  555. checkAllCopyRules(`
  556. .intermediates/mynativebinary/android_arm64_armv8-a/mynativebinary -> arm64/bin/mynativebinary
  557. .intermediates/mynativebinary/android_arm_armv7-a-neon/mynativebinary -> arm/bin/mynativebinary
  558. `),
  559. )
  560. }
  561. func TestMultipleHostOsTypesSnapshotWithCcBinary(t *testing.T) {
  562. result := testSdkWithCc(t, `
  563. module_exports {
  564. name: "myexports",
  565. device_supported: false,
  566. host_supported: true,
  567. native_binaries: ["mynativebinary"],
  568. target: {
  569. windows: {
  570. enabled: true,
  571. },
  572. },
  573. }
  574. cc_binary {
  575. name: "mynativebinary",
  576. device_supported: false,
  577. host_supported: true,
  578. srcs: [
  579. "Test.cpp",
  580. ],
  581. compile_multilib: "both",
  582. stl: "none",
  583. target: {
  584. windows: {
  585. enabled: true,
  586. },
  587. },
  588. }
  589. `)
  590. result.CheckSnapshot("myexports", "",
  591. checkAndroidBpContents(`
  592. // This is auto-generated. DO NOT EDIT.
  593. cc_prebuilt_binary {
  594. name: "myexports_mynativebinary@current",
  595. sdk_member_name: "mynativebinary",
  596. visibility: ["//visibility:public"],
  597. device_supported: false,
  598. host_supported: true,
  599. installable: false,
  600. stl: "none",
  601. target: {
  602. host: {
  603. enabled: false,
  604. },
  605. linux_glibc: {
  606. enabled: true,
  607. compile_multilib: "both",
  608. },
  609. linux_glibc_x86_64: {
  610. srcs: ["linux_glibc/x86_64/bin/mynativebinary"],
  611. },
  612. linux_glibc_x86: {
  613. srcs: ["linux_glibc/x86/bin/mynativebinary"],
  614. },
  615. windows: {
  616. enabled: true,
  617. compile_multilib: "64",
  618. },
  619. windows_x86_64: {
  620. srcs: ["windows/x86_64/bin/mynativebinary.exe"],
  621. },
  622. },
  623. }
  624. cc_prebuilt_binary {
  625. name: "mynativebinary",
  626. prefer: false,
  627. visibility: ["//visibility:public"],
  628. device_supported: false,
  629. host_supported: true,
  630. stl: "none",
  631. target: {
  632. host: {
  633. enabled: false,
  634. },
  635. linux_glibc: {
  636. enabled: true,
  637. compile_multilib: "both",
  638. },
  639. linux_glibc_x86_64: {
  640. srcs: ["linux_glibc/x86_64/bin/mynativebinary"],
  641. },
  642. linux_glibc_x86: {
  643. srcs: ["linux_glibc/x86/bin/mynativebinary"],
  644. },
  645. windows: {
  646. enabled: true,
  647. compile_multilib: "64",
  648. },
  649. windows_x86_64: {
  650. srcs: ["windows/x86_64/bin/mynativebinary.exe"],
  651. },
  652. },
  653. }
  654. module_exports_snapshot {
  655. name: "myexports@current",
  656. visibility: ["//visibility:public"],
  657. device_supported: false,
  658. host_supported: true,
  659. native_binaries: ["myexports_mynativebinary@current"],
  660. target: {
  661. host: {
  662. enabled: false,
  663. },
  664. linux_glibc: {
  665. enabled: true,
  666. },
  667. windows: {
  668. enabled: true,
  669. compile_multilib: "64",
  670. },
  671. },
  672. }
  673. `),
  674. checkAllCopyRules(`
  675. .intermediates/mynativebinary/linux_glibc_x86_64/mynativebinary -> linux_glibc/x86_64/bin/mynativebinary
  676. .intermediates/mynativebinary/linux_glibc_x86/mynativebinary -> linux_glibc/x86/bin/mynativebinary
  677. .intermediates/mynativebinary/windows_x86_64/mynativebinary.exe -> windows/x86_64/bin/mynativebinary.exe
  678. `),
  679. )
  680. }
  681. func TestSnapshotWithSingleHostOsType(t *testing.T) {
  682. ctx, config := testSdkContext(`
  683. cc_defaults {
  684. name: "mydefaults",
  685. device_supported: false,
  686. host_supported: true,
  687. compile_multilib: "64",
  688. target: {
  689. host: {
  690. enabled: false,
  691. },
  692. linux_bionic: {
  693. enabled: true,
  694. },
  695. },
  696. }
  697. module_exports {
  698. name: "myexports",
  699. defaults: ["mydefaults"],
  700. native_shared_libs: ["mynativelib"],
  701. native_binaries: ["mynativebinary"],
  702. compile_multilib: "64", // The built-in default in sdk.go overrides mydefaults.
  703. }
  704. cc_library {
  705. name: "mynativelib",
  706. defaults: ["mydefaults"],
  707. srcs: [
  708. "Test.cpp",
  709. ],
  710. stl: "none",
  711. }
  712. cc_binary {
  713. name: "mynativebinary",
  714. defaults: ["mydefaults"],
  715. srcs: [
  716. "Test.cpp",
  717. ],
  718. stl: "none",
  719. }
  720. `, ccTestFs, []android.OsType{android.LinuxBionic})
  721. result := runTests(t, ctx, config)
  722. result.CheckSnapshot("myexports", "",
  723. checkAndroidBpContents(`
  724. // This is auto-generated. DO NOT EDIT.
  725. cc_prebuilt_binary {
  726. name: "myexports_mynativebinary@current",
  727. sdk_member_name: "mynativebinary",
  728. visibility: ["//visibility:public"],
  729. device_supported: false,
  730. host_supported: true,
  731. installable: false,
  732. stl: "none",
  733. compile_multilib: "64",
  734. target: {
  735. host: {
  736. enabled: false,
  737. },
  738. linux_bionic: {
  739. enabled: true,
  740. },
  741. linux_bionic_x86_64: {
  742. srcs: ["x86_64/bin/mynativebinary"],
  743. },
  744. },
  745. }
  746. cc_prebuilt_binary {
  747. name: "mynativebinary",
  748. prefer: false,
  749. visibility: ["//visibility:public"],
  750. device_supported: false,
  751. host_supported: true,
  752. stl: "none",
  753. compile_multilib: "64",
  754. target: {
  755. host: {
  756. enabled: false,
  757. },
  758. linux_bionic: {
  759. enabled: true,
  760. },
  761. linux_bionic_x86_64: {
  762. srcs: ["x86_64/bin/mynativebinary"],
  763. },
  764. },
  765. }
  766. cc_prebuilt_library_shared {
  767. name: "myexports_mynativelib@current",
  768. sdk_member_name: "mynativelib",
  769. visibility: ["//visibility:public"],
  770. device_supported: false,
  771. host_supported: true,
  772. installable: false,
  773. stl: "none",
  774. compile_multilib: "64",
  775. target: {
  776. host: {
  777. enabled: false,
  778. },
  779. linux_bionic: {
  780. enabled: true,
  781. },
  782. linux_bionic_x86_64: {
  783. srcs: ["x86_64/lib/mynativelib.so"],
  784. },
  785. },
  786. }
  787. cc_prebuilt_library_shared {
  788. name: "mynativelib",
  789. prefer: false,
  790. visibility: ["//visibility:public"],
  791. device_supported: false,
  792. host_supported: true,
  793. stl: "none",
  794. compile_multilib: "64",
  795. target: {
  796. host: {
  797. enabled: false,
  798. },
  799. linux_bionic: {
  800. enabled: true,
  801. },
  802. linux_bionic_x86_64: {
  803. srcs: ["x86_64/lib/mynativelib.so"],
  804. },
  805. },
  806. }
  807. module_exports_snapshot {
  808. name: "myexports@current",
  809. visibility: ["//visibility:public"],
  810. device_supported: false,
  811. host_supported: true,
  812. native_binaries: ["myexports_mynativebinary@current"],
  813. native_shared_libs: ["myexports_mynativelib@current"],
  814. compile_multilib: "64",
  815. target: {
  816. host: {
  817. enabled: false,
  818. },
  819. linux_bionic: {
  820. enabled: true,
  821. },
  822. },
  823. }
  824. `),
  825. checkAllCopyRules(`
  826. .intermediates/mynativebinary/linux_bionic_x86_64/mynativebinary -> x86_64/bin/mynativebinary
  827. .intermediates/mynativelib/linux_bionic_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
  828. `),
  829. )
  830. }
  831. // Test that we support the necessary flags for the linker binary, which is
  832. // special in several ways.
  833. func TestSnapshotWithCcStaticNocrtBinary(t *testing.T) {
  834. result := testSdkWithCc(t, `
  835. module_exports {
  836. name: "mymodule_exports",
  837. host_supported: true,
  838. device_supported: false,
  839. native_binaries: ["linker"],
  840. }
  841. cc_binary {
  842. name: "linker",
  843. host_supported: true,
  844. static_executable: true,
  845. nocrt: true,
  846. stl: "none",
  847. srcs: [
  848. "Test.cpp",
  849. ],
  850. compile_multilib: "both",
  851. }
  852. `)
  853. result.CheckSnapshot("mymodule_exports", "",
  854. checkAndroidBpContents(`
  855. // This is auto-generated. DO NOT EDIT.
  856. cc_prebuilt_binary {
  857. name: "mymodule_exports_linker@current",
  858. sdk_member_name: "linker",
  859. visibility: ["//visibility:public"],
  860. device_supported: false,
  861. host_supported: true,
  862. installable: false,
  863. stl: "none",
  864. compile_multilib: "both",
  865. static_executable: true,
  866. nocrt: true,
  867. target: {
  868. host: {
  869. enabled: false,
  870. },
  871. linux_glibc: {
  872. enabled: true,
  873. },
  874. linux_glibc_x86_64: {
  875. srcs: ["x86_64/bin/linker"],
  876. },
  877. linux_glibc_x86: {
  878. srcs: ["x86/bin/linker"],
  879. },
  880. },
  881. }
  882. cc_prebuilt_binary {
  883. name: "linker",
  884. prefer: false,
  885. visibility: ["//visibility:public"],
  886. device_supported: false,
  887. host_supported: true,
  888. stl: "none",
  889. compile_multilib: "both",
  890. static_executable: true,
  891. nocrt: true,
  892. target: {
  893. host: {
  894. enabled: false,
  895. },
  896. linux_glibc: {
  897. enabled: true,
  898. },
  899. linux_glibc_x86_64: {
  900. srcs: ["x86_64/bin/linker"],
  901. },
  902. linux_glibc_x86: {
  903. srcs: ["x86/bin/linker"],
  904. },
  905. },
  906. }
  907. module_exports_snapshot {
  908. name: "mymodule_exports@current",
  909. visibility: ["//visibility:public"],
  910. device_supported: false,
  911. host_supported: true,
  912. native_binaries: ["mymodule_exports_linker@current"],
  913. target: {
  914. host: {
  915. enabled: false,
  916. },
  917. linux_glibc: {
  918. enabled: true,
  919. },
  920. },
  921. }
  922. `),
  923. checkAllCopyRules(`
  924. .intermediates/linker/linux_glibc_x86_64/linker -> x86_64/bin/linker
  925. .intermediates/linker/linux_glibc_x86/linker -> x86/bin/linker
  926. `),
  927. )
  928. }
  929. func TestSnapshotWithCcSharedLibrary(t *testing.T) {
  930. result := testSdkWithCc(t, `
  931. sdk {
  932. name: "mysdk",
  933. native_shared_libs: ["mynativelib"],
  934. }
  935. cc_library_shared {
  936. name: "mynativelib",
  937. srcs: [
  938. "Test.cpp",
  939. "aidl/foo/bar/Test.aidl",
  940. ],
  941. apex_available: ["apex1", "apex2"],
  942. export_include_dirs: ["include"],
  943. aidl: {
  944. export_aidl_headers: true,
  945. },
  946. stl: "none",
  947. }
  948. `)
  949. result.CheckSnapshot("mysdk", "",
  950. checkAndroidBpContents(`
  951. // This is auto-generated. DO NOT EDIT.
  952. cc_prebuilt_library_shared {
  953. name: "mysdk_mynativelib@current",
  954. sdk_member_name: "mynativelib",
  955. visibility: ["//visibility:public"],
  956. apex_available: [
  957. "apex1",
  958. "apex2",
  959. ],
  960. installable: false,
  961. stl: "none",
  962. compile_multilib: "both",
  963. export_include_dirs: ["include/include"],
  964. arch: {
  965. arm64: {
  966. srcs: ["arm64/lib/mynativelib.so"],
  967. export_include_dirs: ["arm64/include_gen/mynativelib"],
  968. },
  969. arm: {
  970. srcs: ["arm/lib/mynativelib.so"],
  971. export_include_dirs: ["arm/include_gen/mynativelib"],
  972. },
  973. },
  974. }
  975. cc_prebuilt_library_shared {
  976. name: "mynativelib",
  977. prefer: false,
  978. visibility: ["//visibility:public"],
  979. apex_available: [
  980. "apex1",
  981. "apex2",
  982. ],
  983. stl: "none",
  984. compile_multilib: "both",
  985. export_include_dirs: ["include/include"],
  986. arch: {
  987. arm64: {
  988. srcs: ["arm64/lib/mynativelib.so"],
  989. export_include_dirs: ["arm64/include_gen/mynativelib"],
  990. },
  991. arm: {
  992. srcs: ["arm/lib/mynativelib.so"],
  993. export_include_dirs: ["arm/include_gen/mynativelib"],
  994. },
  995. },
  996. }
  997. sdk_snapshot {
  998. name: "mysdk@current",
  999. visibility: ["//visibility:public"],
  1000. native_shared_libs: ["mysdk_mynativelib@current"],
  1001. }
  1002. `),
  1003. checkAllCopyRules(`
  1004. include/Test.h -> include/include/Test.h
  1005. .intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
  1006. .intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
  1007. .intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
  1008. .intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
  1009. .intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
  1010. .intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
  1011. .intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
  1012. .intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BpTest.h
  1013. `),
  1014. )
  1015. }
  1016. func TestSnapshotWithCcSharedLibrarySharedLibs(t *testing.T) {
  1017. result := testSdkWithCc(t, `
  1018. sdk {
  1019. name: "mysdk",
  1020. native_shared_libs: [
  1021. "mynativelib",
  1022. "myothernativelib",
  1023. "mysystemnativelib",
  1024. ],
  1025. }
  1026. cc_library {
  1027. name: "mysystemnativelib",
  1028. srcs: [
  1029. "Test.cpp",
  1030. ],
  1031. stl: "none",
  1032. }
  1033. cc_library_shared {
  1034. name: "myothernativelib",
  1035. srcs: [
  1036. "Test.cpp",
  1037. ],
  1038. system_shared_libs: [
  1039. // A reference to a library that is not an sdk member. Uses libm as that
  1040. // is in the default set of modules available to this test and so is available
  1041. // both here and also when the generated Android.bp file is tested in
  1042. // CheckSnapshot(). This ensures that the system_shared_libs property correctly
  1043. // handles references to modules that are not sdk members.
  1044. "libm",
  1045. ],
  1046. stl: "none",
  1047. }
  1048. cc_library {
  1049. name: "mynativelib",
  1050. srcs: [
  1051. "Test.cpp",
  1052. ],
  1053. shared_libs: [
  1054. // A reference to another sdk member.
  1055. "myothernativelib",
  1056. ],
  1057. target: {
  1058. android: {
  1059. shared: {
  1060. shared_libs: [
  1061. // A reference to a library that is not an sdk member. The libc library
  1062. // is used here to check that the shared_libs property is handled correctly
  1063. // in a similar way to how libm is used to check system_shared_libs above.
  1064. "libc",
  1065. ],
  1066. },
  1067. },
  1068. },
  1069. stl: "none",
  1070. }
  1071. `)
  1072. result.CheckSnapshot("mysdk", "",
  1073. checkAndroidBpContents(`
  1074. // This is auto-generated. DO NOT EDIT.
  1075. cc_prebuilt_library_shared {
  1076. name: "mysdk_mynativelib@current",
  1077. sdk_member_name: "mynativelib",
  1078. visibility: ["//visibility:public"],
  1079. installable: false,
  1080. stl: "none",
  1081. compile_multilib: "both",
  1082. shared_libs: [
  1083. "mysdk_myothernativelib@current",
  1084. "libc",
  1085. ],
  1086. arch: {
  1087. arm64: {
  1088. srcs: ["arm64/lib/mynativelib.so"],
  1089. },
  1090. arm: {
  1091. srcs: ["arm/lib/mynativelib.so"],
  1092. },
  1093. },
  1094. }
  1095. cc_prebuilt_library_shared {
  1096. name: "mynativelib",
  1097. prefer: false,
  1098. visibility: ["//visibility:public"],
  1099. stl: "none",
  1100. compile_multilib: "both",
  1101. shared_libs: [
  1102. "myothernativelib",
  1103. "libc",
  1104. ],
  1105. arch: {
  1106. arm64: {
  1107. srcs: ["arm64/lib/mynativelib.so"],
  1108. },
  1109. arm: {
  1110. srcs: ["arm/lib/mynativelib.so"],
  1111. },
  1112. },
  1113. }
  1114. cc_prebuilt_library_shared {
  1115. name: "mysdk_myothernativelib@current",
  1116. sdk_member_name: "myothernativelib",
  1117. visibility: ["//visibility:public"],
  1118. installable: false,
  1119. stl: "none",
  1120. compile_multilib: "both",
  1121. system_shared_libs: ["libm"],
  1122. arch: {
  1123. arm64: {
  1124. srcs: ["arm64/lib/myothernativelib.so"],
  1125. },
  1126. arm: {
  1127. srcs: ["arm/lib/myothernativelib.so"],
  1128. },
  1129. },
  1130. }
  1131. cc_prebuilt_library_shared {
  1132. name: "myothernativelib",
  1133. prefer: false,
  1134. visibility: ["//visibility:public"],
  1135. stl: "none",
  1136. compile_multilib: "both",
  1137. system_shared_libs: ["libm"],
  1138. arch: {
  1139. arm64: {
  1140. srcs: ["arm64/lib/myothernativelib.so"],
  1141. },
  1142. arm: {
  1143. srcs: ["arm/lib/myothernativelib.so"],
  1144. },
  1145. },
  1146. }
  1147. cc_prebuilt_library_shared {
  1148. name: "mysdk_mysystemnativelib@current",
  1149. sdk_member_name: "mysystemnativelib",
  1150. visibility: ["//visibility:public"],
  1151. installable: false,
  1152. stl: "none",
  1153. compile_multilib: "both",
  1154. arch: {
  1155. arm64: {
  1156. srcs: ["arm64/lib/mysystemnativelib.so"],
  1157. },
  1158. arm: {
  1159. srcs: ["arm/lib/mysystemnativelib.so"],
  1160. },
  1161. },
  1162. }
  1163. cc_prebuilt_library_shared {
  1164. name: "mysystemnativelib",
  1165. prefer: false,
  1166. visibility: ["//visibility:public"],
  1167. stl: "none",
  1168. compile_multilib: "both",
  1169. arch: {
  1170. arm64: {
  1171. srcs: ["arm64/lib/mysystemnativelib.so"],
  1172. },
  1173. arm: {
  1174. srcs: ["arm/lib/mysystemnativelib.so"],
  1175. },
  1176. },
  1177. }
  1178. sdk_snapshot {
  1179. name: "mysdk@current",
  1180. visibility: ["//visibility:public"],
  1181. native_shared_libs: [
  1182. "mysdk_mynativelib@current",
  1183. "mysdk_myothernativelib@current",
  1184. "mysdk_mysystemnativelib@current",
  1185. ],
  1186. }
  1187. `),
  1188. checkAllCopyRules(`
  1189. .intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
  1190. .intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
  1191. .intermediates/myothernativelib/android_arm64_armv8-a_shared/myothernativelib.so -> arm64/lib/myothernativelib.so
  1192. .intermediates/myothernativelib/android_arm_armv7-a-neon_shared/myothernativelib.so -> arm/lib/myothernativelib.so
  1193. .intermediates/mysystemnativelib/android_arm64_armv8-a_shared/mysystemnativelib.so -> arm64/lib/mysystemnativelib.so
  1194. .intermediates/mysystemnativelib/android_arm_armv7-a-neon_shared/mysystemnativelib.so -> arm/lib/mysystemnativelib.so
  1195. `),
  1196. )
  1197. }
  1198. func TestHostSnapshotWithCcSharedLibrary(t *testing.T) {
  1199. result := testSdkWithCc(t, `
  1200. sdk {
  1201. name: "mysdk",
  1202. device_supported: false,
  1203. host_supported: true,
  1204. native_shared_libs: ["mynativelib"],
  1205. }
  1206. cc_library_shared {
  1207. name: "mynativelib",
  1208. device_supported: false,
  1209. host_supported: true,
  1210. srcs: [
  1211. "Test.cpp",
  1212. "aidl/foo/bar/Test.aidl",
  1213. ],
  1214. export_include_dirs: ["include"],
  1215. aidl: {
  1216. export_aidl_headers: true,
  1217. },
  1218. stl: "none",
  1219. sdk_version: "minimum",
  1220. }
  1221. `)
  1222. result.CheckSnapshot("mysdk", "",
  1223. checkAndroidBpContents(`
  1224. // This is auto-generated. DO NOT EDIT.
  1225. cc_prebuilt_library_shared {
  1226. name: "mysdk_mynativelib@current",
  1227. sdk_member_name: "mynativelib",
  1228. visibility: ["//visibility:public"],
  1229. device_supported: false,
  1230. host_supported: true,
  1231. installable: false,
  1232. sdk_version: "minimum",
  1233. stl: "none",
  1234. compile_multilib: "both",
  1235. export_include_dirs: ["include/include"],
  1236. target: {
  1237. host: {
  1238. enabled: false,
  1239. },
  1240. linux_glibc: {
  1241. enabled: true,
  1242. },
  1243. linux_glibc_x86_64: {
  1244. srcs: ["x86_64/lib/mynativelib.so"],
  1245. export_include_dirs: ["x86_64/include_gen/mynativelib"],
  1246. },
  1247. linux_glibc_x86: {
  1248. srcs: ["x86/lib/mynativelib.so"],
  1249. export_include_dirs: ["x86/include_gen/mynativelib"],
  1250. },
  1251. },
  1252. }
  1253. cc_prebuilt_library_shared {
  1254. name: "mynativelib",
  1255. prefer: false,
  1256. visibility: ["//visibility:public"],
  1257. device_supported: false,
  1258. host_supported: true,
  1259. sdk_version: "minimum",
  1260. stl: "none",
  1261. compile_multilib: "both",
  1262. export_include_dirs: ["include/include"],
  1263. target: {
  1264. host: {
  1265. enabled: false,
  1266. },
  1267. linux_glibc: {
  1268. enabled: true,
  1269. },
  1270. linux_glibc_x86_64: {
  1271. srcs: ["x86_64/lib/mynativelib.so"],
  1272. export_include_dirs: ["x86_64/include_gen/mynativelib"],
  1273. },
  1274. linux_glibc_x86: {
  1275. srcs: ["x86/lib/mynativelib.so"],
  1276. export_include_dirs: ["x86/include_gen/mynativelib"],
  1277. },
  1278. },
  1279. }
  1280. sdk_snapshot {
  1281. name: "mysdk@current",
  1282. visibility: ["//visibility:public"],
  1283. device_supported: false,
  1284. host_supported: true,
  1285. native_shared_libs: ["mysdk_mynativelib@current"],
  1286. target: {
  1287. host: {
  1288. enabled: false,
  1289. },
  1290. linux_glibc: {
  1291. enabled: true,
  1292. },
  1293. },
  1294. }
  1295. `),
  1296. checkAllCopyRules(`
  1297. include/Test.h -> include/include/Test.h
  1298. .intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
  1299. .intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
  1300. .intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
  1301. .intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
  1302. .intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> x86/lib/mynativelib.so
  1303. .intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
  1304. .intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
  1305. .intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
  1306. `),
  1307. )
  1308. }
  1309. func TestMultipleHostOsTypesSnapshotWithCcSharedLibrary(t *testing.T) {
  1310. result := testSdkWithCc(t, `
  1311. sdk {
  1312. name: "mysdk",
  1313. device_supported: false,
  1314. host_supported: true,
  1315. native_shared_libs: ["mynativelib"],
  1316. target: {
  1317. windows: {
  1318. enabled: true,
  1319. },
  1320. },
  1321. }
  1322. cc_library_shared {
  1323. name: "mynativelib",
  1324. device_supported: false,
  1325. host_supported: true,
  1326. srcs: [
  1327. "Test.cpp",
  1328. ],
  1329. stl: "none",
  1330. target: {
  1331. windows: {
  1332. enabled: true,
  1333. },
  1334. },
  1335. }
  1336. `)
  1337. result.CheckSnapshot("mysdk", "",
  1338. checkAndroidBpContents(`
  1339. // This is auto-generated. DO NOT EDIT.
  1340. cc_prebuilt_library_shared {
  1341. name: "mysdk_mynativelib@current",
  1342. sdk_member_name: "mynativelib",
  1343. visibility: ["//visibility:public"],
  1344. device_supported: false,
  1345. host_supported: true,
  1346. installable: false,
  1347. stl: "none",
  1348. target: {
  1349. host: {
  1350. enabled: false,
  1351. },
  1352. linux_glibc: {
  1353. enabled: true,
  1354. compile_multilib: "both",
  1355. },
  1356. linux_glibc_x86_64: {
  1357. srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
  1358. },
  1359. linux_glibc_x86: {
  1360. srcs: ["linux_glibc/x86/lib/mynativelib.so"],
  1361. },
  1362. windows: {
  1363. enabled: true,
  1364. compile_multilib: "64",
  1365. },
  1366. windows_x86_64: {
  1367. srcs: ["windows/x86_64/lib/mynativelib.dll"],
  1368. },
  1369. },
  1370. }
  1371. cc_prebuilt_library_shared {
  1372. name: "mynativelib",
  1373. prefer: false,
  1374. visibility: ["//visibility:public"],
  1375. device_supported: false,
  1376. host_supported: true,
  1377. stl: "none",
  1378. target: {
  1379. host: {
  1380. enabled: false,
  1381. },
  1382. linux_glibc: {
  1383. enabled: true,
  1384. compile_multilib: "both",
  1385. },
  1386. linux_glibc_x86_64: {
  1387. srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
  1388. },
  1389. linux_glibc_x86: {
  1390. srcs: ["linux_glibc/x86/lib/mynativelib.so"],
  1391. },
  1392. windows: {
  1393. enabled: true,
  1394. compile_multilib: "64",
  1395. },
  1396. windows_x86_64: {
  1397. srcs: ["windows/x86_64/lib/mynativelib.dll"],
  1398. },
  1399. },
  1400. }
  1401. sdk_snapshot {
  1402. name: "mysdk@current",
  1403. visibility: ["//visibility:public"],
  1404. device_supported: false,
  1405. host_supported: true,
  1406. native_shared_libs: ["mysdk_mynativelib@current"],
  1407. target: {
  1408. host: {
  1409. enabled: false,
  1410. },
  1411. linux_glibc: {
  1412. enabled: true,
  1413. },
  1414. windows: {
  1415. enabled: true,
  1416. compile_multilib: "64",
  1417. },
  1418. },
  1419. }
  1420. `),
  1421. checkAllCopyRules(`
  1422. .intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> linux_glibc/x86_64/lib/mynativelib.so
  1423. .intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> linux_glibc/x86/lib/mynativelib.so
  1424. .intermediates/mynativelib/windows_x86_64_shared/mynativelib.dll -> windows/x86_64/lib/mynativelib.dll
  1425. `),
  1426. )
  1427. }
  1428. func TestSnapshotWithCcStaticLibrary(t *testing.T) {
  1429. result := testSdkWithCc(t, `
  1430. module_exports {
  1431. name: "myexports",
  1432. native_static_libs: ["mynativelib"],
  1433. }
  1434. cc_library_static {
  1435. name: "mynativelib",
  1436. srcs: [
  1437. "Test.cpp",
  1438. "aidl/foo/bar/Test.aidl",
  1439. ],
  1440. export_include_dirs: ["include"],
  1441. aidl: {
  1442. export_aidl_headers: true,
  1443. },
  1444. stl: "none",
  1445. }
  1446. `)
  1447. result.CheckSnapshot("myexports", "",
  1448. checkAndroidBpContents(`
  1449. // This is auto-generated. DO NOT EDIT.
  1450. cc_prebuilt_library_static {
  1451. name: "myexports_mynativelib@current",
  1452. sdk_member_name: "mynativelib",
  1453. visibility: ["//visibility:public"],
  1454. installable: false,
  1455. stl: "none",
  1456. compile_multilib: "both",
  1457. export_include_dirs: ["include/include"],
  1458. arch: {
  1459. arm64: {
  1460. srcs: ["arm64/lib/mynativelib.a"],
  1461. export_include_dirs: ["arm64/include_gen/mynativelib"],
  1462. },
  1463. arm: {
  1464. srcs: ["arm/lib/mynativelib.a"],
  1465. export_include_dirs: ["arm/include_gen/mynativelib"],
  1466. },
  1467. },
  1468. }
  1469. cc_prebuilt_library_static {
  1470. name: "mynativelib",
  1471. prefer: false,
  1472. visibility: ["//visibility:public"],
  1473. stl: "none",
  1474. compile_multilib: "both",
  1475. export_include_dirs: ["include/include"],
  1476. arch: {
  1477. arm64: {
  1478. srcs: ["arm64/lib/mynativelib.a"],
  1479. export_include_dirs: ["arm64/include_gen/mynativelib"],
  1480. },
  1481. arm: {
  1482. srcs: ["arm/lib/mynativelib.a"],
  1483. export_include_dirs: ["arm/include_gen/mynativelib"],
  1484. },
  1485. },
  1486. }
  1487. module_exports_snapshot {
  1488. name: "myexports@current",
  1489. visibility: ["//visibility:public"],
  1490. native_static_libs: ["myexports_mynativelib@current"],
  1491. }
  1492. `),
  1493. checkAllCopyRules(`
  1494. include/Test.h -> include/include/Test.h
  1495. .intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
  1496. .intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
  1497. .intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
  1498. .intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
  1499. .intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
  1500. .intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
  1501. .intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
  1502. .intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BpTest.h
  1503. `),
  1504. )
  1505. }
  1506. func TestHostSnapshotWithCcStaticLibrary(t *testing.T) {
  1507. result := testSdkWithCc(t, `
  1508. module_exports {
  1509. name: "myexports",
  1510. device_supported: false,
  1511. host_supported: true,
  1512. native_static_libs: ["mynativelib"],
  1513. }
  1514. cc_library_static {
  1515. name: "mynativelib",
  1516. device_supported: false,
  1517. host_supported: true,
  1518. srcs: [
  1519. "Test.cpp",
  1520. "aidl/foo/bar/Test.aidl",
  1521. ],
  1522. export_include_dirs: ["include"],
  1523. aidl: {
  1524. export_aidl_headers: true,
  1525. },
  1526. stl: "none",
  1527. }
  1528. `)
  1529. result.CheckSnapshot("myexports", "",
  1530. checkAndroidBpContents(`
  1531. // This is auto-generated. DO NOT EDIT.
  1532. cc_prebuilt_library_static {
  1533. name: "myexports_mynativelib@current",
  1534. sdk_member_name: "mynativelib",
  1535. visibility: ["//visibility:public"],
  1536. device_supported: false,
  1537. host_supported: true,
  1538. installable: false,
  1539. stl: "none",
  1540. compile_multilib: "both",
  1541. export_include_dirs: ["include/include"],
  1542. target: {
  1543. host: {
  1544. enabled: false,
  1545. },
  1546. linux_glibc: {
  1547. enabled: true,
  1548. },
  1549. linux_glibc_x86_64: {
  1550. srcs: ["x86_64/lib/mynativelib.a"],
  1551. export_include_dirs: ["x86_64/include_gen/mynativelib"],
  1552. },
  1553. linux_glibc_x86: {
  1554. srcs: ["x86/lib/mynativelib.a"],
  1555. export_include_dirs: ["x86/include_gen/mynativelib"],
  1556. },
  1557. },
  1558. }
  1559. cc_prebuilt_library_static {
  1560. name: "mynativelib",
  1561. prefer: false,
  1562. visibility: ["//visibility:public"],
  1563. device_supported: false,
  1564. host_supported: true,
  1565. stl: "none",
  1566. compile_multilib: "both",
  1567. export_include_dirs: ["include/include"],
  1568. target: {
  1569. host: {
  1570. enabled: false,
  1571. },
  1572. linux_glibc: {
  1573. enabled: true,
  1574. },
  1575. linux_glibc_x86_64: {
  1576. srcs: ["x86_64/lib/mynativelib.a"],
  1577. export_include_dirs: ["x86_64/include_gen/mynativelib"],
  1578. },
  1579. linux_glibc_x86: {
  1580. srcs: ["x86/lib/mynativelib.a"],
  1581. export_include_dirs: ["x86/include_gen/mynativelib"],
  1582. },
  1583. },
  1584. }
  1585. module_exports_snapshot {
  1586. name: "myexports@current",
  1587. visibility: ["//visibility:public"],
  1588. device_supported: false,
  1589. host_supported: true,
  1590. native_static_libs: ["myexports_mynativelib@current"],
  1591. target: {
  1592. host: {
  1593. enabled: false,
  1594. },
  1595. linux_glibc: {
  1596. enabled: true,
  1597. },
  1598. },
  1599. }
  1600. `),
  1601. checkAllCopyRules(`
  1602. include/Test.h -> include/include/Test.h
  1603. .intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
  1604. .intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
  1605. .intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
  1606. .intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
  1607. .intermediates/mynativelib/linux_glibc_x86_static/mynativelib.a -> x86/lib/mynativelib.a
  1608. .intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
  1609. .intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
  1610. .intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
  1611. `),
  1612. )
  1613. }
  1614. func TestSnapshotWithCcLibrary(t *testing.T) {
  1615. result := testSdkWithCc(t, `
  1616. module_exports {
  1617. name: "myexports",
  1618. native_libs: ["mynativelib"],
  1619. }
  1620. cc_library {
  1621. name: "mynativelib",
  1622. srcs: [
  1623. "Test.cpp",
  1624. ],
  1625. export_include_dirs: ["include"],
  1626. stl: "none",
  1627. recovery_available: true,
  1628. vendor_available: true,
  1629. }
  1630. `)
  1631. result.CheckSnapshot("myexports", "",
  1632. checkAndroidBpContents(`
  1633. // This is auto-generated. DO NOT EDIT.
  1634. cc_prebuilt_library {
  1635. name: "myexports_mynativelib@current",
  1636. sdk_member_name: "mynativelib",
  1637. visibility: ["//visibility:public"],
  1638. installable: false,
  1639. recovery_available: true,
  1640. vendor_available: true,
  1641. stl: "none",
  1642. compile_multilib: "both",
  1643. export_include_dirs: ["include/include"],
  1644. arch: {
  1645. arm64: {
  1646. static: {
  1647. srcs: ["arm64/lib/mynativelib.a"],
  1648. },
  1649. shared: {
  1650. srcs: ["arm64/lib/mynativelib.so"],
  1651. },
  1652. },
  1653. arm: {
  1654. static: {
  1655. srcs: ["arm/lib/mynativelib.a"],
  1656. },
  1657. shared: {
  1658. srcs: ["arm/lib/mynativelib.so"],
  1659. },
  1660. },
  1661. },
  1662. }
  1663. cc_prebuilt_library {
  1664. name: "mynativelib",
  1665. prefer: false,
  1666. visibility: ["//visibility:public"],
  1667. recovery_available: true,
  1668. vendor_available: true,
  1669. stl: "none",
  1670. compile_multilib: "both",
  1671. export_include_dirs: ["include/include"],
  1672. arch: {
  1673. arm64: {
  1674. static: {
  1675. srcs: ["arm64/lib/mynativelib.a"],
  1676. },
  1677. shared: {
  1678. srcs: ["arm64/lib/mynativelib.so"],
  1679. },
  1680. },
  1681. arm: {
  1682. static: {
  1683. srcs: ["arm/lib/mynativelib.a"],
  1684. },
  1685. shared: {
  1686. srcs: ["arm/lib/mynativelib.so"],
  1687. },
  1688. },
  1689. },
  1690. }
  1691. module_exports_snapshot {
  1692. name: "myexports@current",
  1693. visibility: ["//visibility:public"],
  1694. native_libs: ["myexports_mynativelib@current"],
  1695. }
  1696. `),
  1697. checkAllCopyRules(`
  1698. include/Test.h -> include/include/Test.h
  1699. .intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
  1700. .intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
  1701. .intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
  1702. .intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
  1703. )
  1704. }
  1705. func TestHostSnapshotWithMultiLib64(t *testing.T) {
  1706. result := testSdkWithCc(t, `
  1707. module_exports {
  1708. name: "myexports",
  1709. device_supported: false,
  1710. host_supported: true,
  1711. target: {
  1712. host: {
  1713. compile_multilib: "64",
  1714. },
  1715. },
  1716. native_static_libs: ["mynativelib"],
  1717. }
  1718. cc_library_static {
  1719. name: "mynativelib",
  1720. device_supported: false,
  1721. host_supported: true,
  1722. srcs: [
  1723. "Test.cpp",
  1724. "aidl/foo/bar/Test.aidl",
  1725. ],
  1726. export_include_dirs: ["include"],
  1727. aidl: {
  1728. export_aidl_headers: true,
  1729. },
  1730. stl: "none",
  1731. }
  1732. `)
  1733. result.CheckSnapshot("myexports", "",
  1734. checkAndroidBpContents(`
  1735. // This is auto-generated. DO NOT EDIT.
  1736. cc_prebuilt_library_static {
  1737. name: "myexports_mynativelib@current",
  1738. sdk_member_name: "mynativelib",
  1739. visibility: ["//visibility:public"],
  1740. device_supported: false,
  1741. host_supported: true,
  1742. installable: false,
  1743. stl: "none",
  1744. compile_multilib: "64",
  1745. export_include_dirs: ["include/include"],
  1746. target: {
  1747. host: {
  1748. enabled: false,
  1749. },
  1750. linux_glibc: {
  1751. enabled: true,
  1752. },
  1753. linux_glibc_x86_64: {
  1754. srcs: ["x86_64/lib/mynativelib.a"],
  1755. export_include_dirs: ["x86_64/include_gen/mynativelib"],
  1756. },
  1757. },
  1758. }
  1759. cc_prebuilt_library_static {
  1760. name: "mynativelib",
  1761. prefer: false,
  1762. visibility: ["//visibility:public"],
  1763. device_supported: false,
  1764. host_supported: true,
  1765. stl: "none",
  1766. compile_multilib: "64",
  1767. export_include_dirs: ["include/include"],
  1768. target: {
  1769. host: {
  1770. enabled: false,
  1771. },
  1772. linux_glibc: {
  1773. enabled: true,
  1774. },
  1775. linux_glibc_x86_64: {
  1776. srcs: ["x86_64/lib/mynativelib.a"],
  1777. export_include_dirs: ["x86_64/include_gen/mynativelib"],
  1778. },
  1779. },
  1780. }
  1781. module_exports_snapshot {
  1782. name: "myexports@current",
  1783. visibility: ["//visibility:public"],
  1784. device_supported: false,
  1785. host_supported: true,
  1786. native_static_libs: ["myexports_mynativelib@current"],
  1787. compile_multilib: "64",
  1788. target: {
  1789. host: {
  1790. enabled: false,
  1791. },
  1792. linux_glibc: {
  1793. enabled: true,
  1794. },
  1795. },
  1796. }`),
  1797. checkAllCopyRules(`
  1798. include/Test.h -> include/include/Test.h
  1799. .intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
  1800. .intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
  1801. .intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
  1802. .intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
  1803. `),
  1804. )
  1805. }
  1806. func TestSnapshotWithCcHeadersLibrary(t *testing.T) {
  1807. result := testSdkWithCc(t, `
  1808. sdk {
  1809. name: "mysdk",
  1810. native_header_libs: ["mynativeheaders"],
  1811. }
  1812. cc_library_headers {
  1813. name: "mynativeheaders",
  1814. export_include_dirs: ["include"],
  1815. stl: "none",
  1816. }
  1817. `)
  1818. result.CheckSnapshot("mysdk", "",
  1819. checkAndroidBpContents(`
  1820. // This is auto-generated. DO NOT EDIT.
  1821. cc_prebuilt_library_headers {
  1822. name: "mysdk_mynativeheaders@current",
  1823. sdk_member_name: "mynativeheaders",
  1824. visibility: ["//visibility:public"],
  1825. stl: "none",
  1826. compile_multilib: "both",
  1827. export_include_dirs: ["include/include"],
  1828. }
  1829. cc_prebuilt_library_headers {
  1830. name: "mynativeheaders",
  1831. prefer: false,
  1832. visibility: ["//visibility:public"],
  1833. stl: "none",
  1834. compile_multilib: "both",
  1835. export_include_dirs: ["include/include"],
  1836. }
  1837. sdk_snapshot {
  1838. name: "mysdk@current",
  1839. visibility: ["//visibility:public"],
  1840. native_header_libs: ["mysdk_mynativeheaders@current"],
  1841. }
  1842. `),
  1843. checkAllCopyRules(`
  1844. include/Test.h -> include/include/Test.h
  1845. `),
  1846. )
  1847. }
  1848. func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) {
  1849. result := testSdkWithCc(t, `
  1850. sdk {
  1851. name: "mysdk",
  1852. device_supported: false,
  1853. host_supported: true,
  1854. native_header_libs: ["mynativeheaders"],
  1855. }
  1856. cc_library_headers {
  1857. name: "mynativeheaders",
  1858. device_supported: false,
  1859. host_supported: true,
  1860. export_include_dirs: ["include"],
  1861. stl: "none",
  1862. }
  1863. `)
  1864. result.CheckSnapshot("mysdk", "",
  1865. checkAndroidBpContents(`
  1866. // This is auto-generated. DO NOT EDIT.
  1867. cc_prebuilt_library_headers {
  1868. name: "mysdk_mynativeheaders@current",
  1869. sdk_member_name: "mynativeheaders",
  1870. visibility: ["//visibility:public"],
  1871. device_supported: false,
  1872. host_supported: true,
  1873. stl: "none",
  1874. compile_multilib: "both",
  1875. export_include_dirs: ["include/include"],
  1876. target: {
  1877. host: {
  1878. enabled: false,
  1879. },
  1880. linux_glibc: {
  1881. enabled: true,
  1882. },
  1883. },
  1884. }
  1885. cc_prebuilt_library_headers {
  1886. name: "mynativeheaders",
  1887. prefer: false,
  1888. visibility: ["//visibility:public"],
  1889. device_supported: false,
  1890. host_supported: true,
  1891. stl: "none",
  1892. compile_multilib: "both",
  1893. export_include_dirs: ["include/include"],
  1894. target: {
  1895. host: {
  1896. enabled: false,
  1897. },
  1898. linux_glibc: {
  1899. enabled: true,
  1900. },
  1901. },
  1902. }
  1903. sdk_snapshot {
  1904. name: "mysdk@current",
  1905. visibility: ["//visibility:public"],
  1906. device_supported: false,
  1907. host_supported: true,
  1908. native_header_libs: ["mysdk_mynativeheaders@current"],
  1909. target: {
  1910. host: {
  1911. enabled: false,
  1912. },
  1913. linux_glibc: {
  1914. enabled: true,
  1915. },
  1916. },
  1917. }
  1918. `),
  1919. checkAllCopyRules(`
  1920. include/Test.h -> include/include/Test.h
  1921. `),
  1922. )
  1923. }
  1924. func TestDeviceAndHostSnapshotWithCcHeadersLibrary(t *testing.T) {
  1925. result := testSdkWithCc(t, `
  1926. sdk {
  1927. name: "mysdk",
  1928. host_supported: true,
  1929. native_header_libs: ["mynativeheaders"],
  1930. }
  1931. cc_library_headers {
  1932. name: "mynativeheaders",
  1933. host_supported: true,
  1934. stl: "none",
  1935. export_system_include_dirs: ["include"],
  1936. target: {
  1937. android: {
  1938. export_include_dirs: ["include-android"],
  1939. },
  1940. host: {
  1941. export_include_dirs: ["include-host"],
  1942. },
  1943. },
  1944. }
  1945. `)
  1946. result.CheckSnapshot("mysdk", "",
  1947. checkAndroidBpContents(`
  1948. // This is auto-generated. DO NOT EDIT.
  1949. cc_prebuilt_library_headers {
  1950. name: "mysdk_mynativeheaders@current",
  1951. sdk_member_name: "mynativeheaders",
  1952. visibility: ["//visibility:public"],
  1953. host_supported: true,
  1954. stl: "none",
  1955. compile_multilib: "both",
  1956. export_system_include_dirs: ["common_os/include/include"],
  1957. target: {
  1958. host: {
  1959. enabled: false,
  1960. },
  1961. android: {
  1962. export_include_dirs: ["android/include/include-android"],
  1963. },
  1964. linux_glibc: {
  1965. enabled: true,
  1966. export_include_dirs: ["linux_glibc/include/include-host"],
  1967. },
  1968. },
  1969. }
  1970. cc_prebuilt_library_headers {
  1971. name: "mynativeheaders",
  1972. prefer: false,
  1973. visibility: ["//visibility:public"],
  1974. host_supported: true,
  1975. stl: "none",
  1976. compile_multilib: "both",
  1977. export_system_include_dirs: ["common_os/include/include"],
  1978. target: {
  1979. host: {
  1980. enabled: false,
  1981. },
  1982. android: {
  1983. export_include_dirs: ["android/include/include-android"],
  1984. },
  1985. linux_glibc: {
  1986. enabled: true,
  1987. export_include_dirs: ["linux_glibc/include/include-host"],
  1988. },
  1989. },
  1990. }
  1991. sdk_snapshot {
  1992. name: "mysdk@current",
  1993. visibility: ["//visibility:public"],
  1994. host_supported: true,
  1995. native_header_libs: ["mysdk_mynativeheaders@current"],
  1996. target: {
  1997. host: {
  1998. enabled: false,
  1999. },
  2000. linux_glibc: {
  2001. enabled: true,
  2002. },
  2003. },
  2004. }
  2005. `),
  2006. checkAllCopyRules(`
  2007. include/Test.h -> common_os/include/include/Test.h
  2008. include-android/AndroidTest.h -> android/include/include-android/AndroidTest.h
  2009. include-host/HostTest.h -> linux_glibc/include/include-host/HostTest.h
  2010. `),
  2011. )
  2012. }
  2013. func TestSystemSharedLibPropagation(t *testing.T) {
  2014. result := testSdkWithCc(t, `
  2015. sdk {
  2016. name: "mysdk",
  2017. native_shared_libs: ["sslnil", "sslempty", "sslnonempty"],
  2018. }
  2019. cc_library {
  2020. name: "sslnil",
  2021. host_supported: true,
  2022. }
  2023. cc_library {
  2024. name: "sslempty",
  2025. system_shared_libs: [],
  2026. }
  2027. cc_library {
  2028. name: "sslnonempty",
  2029. system_shared_libs: ["sslnil"],
  2030. }
  2031. `)
  2032. result.CheckSnapshot("mysdk", "",
  2033. checkAndroidBpContents(`
  2034. // This is auto-generated. DO NOT EDIT.
  2035. cc_prebuilt_library_shared {
  2036. name: "mysdk_sslnil@current",
  2037. sdk_member_name: "sslnil",
  2038. visibility: ["//visibility:public"],
  2039. installable: false,
  2040. compile_multilib: "both",
  2041. arch: {
  2042. arm64: {
  2043. srcs: ["arm64/lib/sslnil.so"],
  2044. },
  2045. arm: {
  2046. srcs: ["arm/lib/sslnil.so"],
  2047. },
  2048. },
  2049. }
  2050. cc_prebuilt_library_shared {
  2051. name: "sslnil",
  2052. prefer: false,
  2053. visibility: ["//visibility:public"],
  2054. compile_multilib: "both",
  2055. arch: {
  2056. arm64: {
  2057. srcs: ["arm64/lib/sslnil.so"],
  2058. },
  2059. arm: {
  2060. srcs: ["arm/lib/sslnil.so"],
  2061. },
  2062. },
  2063. }
  2064. cc_prebuilt_library_shared {
  2065. name: "mysdk_sslempty@current",
  2066. sdk_member_name: "sslempty",
  2067. visibility: ["//visibility:public"],
  2068. installable: false,
  2069. compile_multilib: "both",
  2070. system_shared_libs: [],
  2071. arch: {
  2072. arm64: {
  2073. srcs: ["arm64/lib/sslempty.so"],
  2074. },
  2075. arm: {
  2076. srcs: ["arm/lib/sslempty.so"],
  2077. },
  2078. },
  2079. }
  2080. cc_prebuilt_library_shared {
  2081. name: "sslempty",
  2082. prefer: false,
  2083. visibility: ["//visibility:public"],
  2084. compile_multilib: "both",
  2085. system_shared_libs: [],
  2086. arch: {
  2087. arm64: {
  2088. srcs: ["arm64/lib/sslempty.so"],
  2089. },
  2090. arm: {
  2091. srcs: ["arm/lib/sslempty.so"],
  2092. },
  2093. },
  2094. }
  2095. cc_prebuilt_library_shared {
  2096. name: "mysdk_sslnonempty@current",
  2097. sdk_member_name: "sslnonempty",
  2098. visibility: ["//visibility:public"],
  2099. installable: false,
  2100. compile_multilib: "both",
  2101. system_shared_libs: ["mysdk_sslnil@current"],
  2102. arch: {
  2103. arm64: {
  2104. srcs: ["arm64/lib/sslnonempty.so"],
  2105. },
  2106. arm: {
  2107. srcs: ["arm/lib/sslnonempty.so"],
  2108. },
  2109. },
  2110. }
  2111. cc_prebuilt_library_shared {
  2112. name: "sslnonempty",
  2113. prefer: false,
  2114. visibility: ["//visibility:public"],
  2115. compile_multilib: "both",
  2116. system_shared_libs: ["sslnil"],
  2117. arch: {
  2118. arm64: {
  2119. srcs: ["arm64/lib/sslnonempty.so"],
  2120. },
  2121. arm: {
  2122. srcs: ["arm/lib/sslnonempty.so"],
  2123. },
  2124. },
  2125. }
  2126. sdk_snapshot {
  2127. name: "mysdk@current",
  2128. visibility: ["//visibility:public"],
  2129. native_shared_libs: [
  2130. "mysdk_sslnil@current",
  2131. "mysdk_sslempty@current",
  2132. "mysdk_sslnonempty@current",
  2133. ],
  2134. }
  2135. `))
  2136. result = testSdkWithCc(t, `
  2137. sdk {
  2138. name: "mysdk",
  2139. host_supported: true,
  2140. native_shared_libs: ["sslvariants"],
  2141. }
  2142. cc_library {
  2143. name: "sslvariants",
  2144. host_supported: true,
  2145. target: {
  2146. android: {
  2147. system_shared_libs: [],
  2148. },
  2149. },
  2150. }
  2151. `)
  2152. result.CheckSnapshot("mysdk", "",
  2153. checkAndroidBpContents(`
  2154. // This is auto-generated. DO NOT EDIT.
  2155. cc_prebuilt_library_shared {
  2156. name: "mysdk_sslvariants@current",
  2157. sdk_member_name: "sslvariants",
  2158. visibility: ["//visibility:public"],
  2159. host_supported: true,
  2160. installable: false,
  2161. compile_multilib: "both",
  2162. target: {
  2163. host: {
  2164. enabled: false,
  2165. },
  2166. android: {
  2167. system_shared_libs: [],
  2168. },
  2169. android_arm64: {
  2170. srcs: ["android/arm64/lib/sslvariants.so"],
  2171. },
  2172. android_arm: {
  2173. srcs: ["android/arm/lib/sslvariants.so"],
  2174. },
  2175. linux_glibc: {
  2176. enabled: true,
  2177. },
  2178. linux_glibc_x86_64: {
  2179. srcs: ["linux_glibc/x86_64/lib/sslvariants.so"],
  2180. },
  2181. linux_glibc_x86: {
  2182. srcs: ["linux_glibc/x86/lib/sslvariants.so"],
  2183. },
  2184. },
  2185. }
  2186. cc_prebuilt_library_shared {
  2187. name: "sslvariants",
  2188. prefer: false,
  2189. visibility: ["//visibility:public"],
  2190. host_supported: true,
  2191. compile_multilib: "both",
  2192. target: {
  2193. host: {
  2194. enabled: false,
  2195. },
  2196. android: {
  2197. system_shared_libs: [],
  2198. },
  2199. android_arm64: {
  2200. srcs: ["android/arm64/lib/sslvariants.so"],
  2201. },
  2202. android_arm: {
  2203. srcs: ["android/arm/lib/sslvariants.so"],
  2204. },
  2205. linux_glibc: {
  2206. enabled: true,
  2207. },
  2208. linux_glibc_x86_64: {
  2209. srcs: ["linux_glibc/x86_64/lib/sslvariants.so"],
  2210. },
  2211. linux_glibc_x86: {
  2212. srcs: ["linux_glibc/x86/lib/sslvariants.so"],
  2213. },
  2214. },
  2215. }
  2216. sdk_snapshot {
  2217. name: "mysdk@current",
  2218. visibility: ["//visibility:public"],
  2219. host_supported: true,
  2220. native_shared_libs: ["mysdk_sslvariants@current"],
  2221. target: {
  2222. host: {
  2223. enabled: false,
  2224. },
  2225. linux_glibc: {
  2226. enabled: true,
  2227. },
  2228. },
  2229. }
  2230. `))
  2231. }
  2232. func TestStubsLibrary(t *testing.T) {
  2233. result := testSdkWithCc(t, `
  2234. sdk {
  2235. name: "mysdk",
  2236. native_shared_libs: ["stubslib"],
  2237. }
  2238. cc_library {
  2239. name: "internaldep",
  2240. }
  2241. cc_library {
  2242. name: "stubslib",
  2243. shared_libs: ["internaldep"],
  2244. stubs: {
  2245. symbol_file: "some/where/stubslib.map.txt",
  2246. versions: ["1", "2", "3"],
  2247. },
  2248. }
  2249. `)
  2250. result.CheckSnapshot("mysdk", "",
  2251. checkAndroidBpContents(`
  2252. // This is auto-generated. DO NOT EDIT.
  2253. cc_prebuilt_library_shared {
  2254. name: "mysdk_stubslib@current",
  2255. sdk_member_name: "stubslib",
  2256. visibility: ["//visibility:public"],
  2257. installable: false,
  2258. compile_multilib: "both",
  2259. stubs: {
  2260. versions: [
  2261. "1",
  2262. "2",
  2263. "3",
  2264. ],
  2265. },
  2266. arch: {
  2267. arm64: {
  2268. srcs: ["arm64/lib/stubslib.so"],
  2269. },
  2270. arm: {
  2271. srcs: ["arm/lib/stubslib.so"],
  2272. },
  2273. },
  2274. }
  2275. cc_prebuilt_library_shared {
  2276. name: "stubslib",
  2277. prefer: false,
  2278. visibility: ["//visibility:public"],
  2279. compile_multilib: "both",
  2280. stubs: {
  2281. versions: [
  2282. "1",
  2283. "2",
  2284. "3",
  2285. ],
  2286. },
  2287. arch: {
  2288. arm64: {
  2289. srcs: ["arm64/lib/stubslib.so"],
  2290. },
  2291. arm: {
  2292. srcs: ["arm/lib/stubslib.so"],
  2293. },
  2294. },
  2295. }
  2296. sdk_snapshot {
  2297. name: "mysdk@current",
  2298. visibility: ["//visibility:public"],
  2299. native_shared_libs: ["mysdk_stubslib@current"],
  2300. }
  2301. `))
  2302. }
  2303. func TestDeviceAndHostSnapshotWithStubsLibrary(t *testing.T) {
  2304. result := testSdkWithCc(t, `
  2305. sdk {
  2306. name: "mysdk",
  2307. host_supported: true,
  2308. native_shared_libs: ["stubslib"],
  2309. }
  2310. cc_library {
  2311. name: "internaldep",
  2312. host_supported: true,
  2313. }
  2314. cc_library {
  2315. name: "stubslib",
  2316. host_supported: true,
  2317. shared_libs: ["internaldep"],
  2318. stubs: {
  2319. symbol_file: "some/where/stubslib.map.txt",
  2320. versions: ["1", "2", "3"],
  2321. },
  2322. }
  2323. `)
  2324. result.CheckSnapshot("mysdk", "",
  2325. checkAndroidBpContents(`
  2326. // This is auto-generated. DO NOT EDIT.
  2327. cc_prebuilt_library_shared {
  2328. name: "mysdk_stubslib@current",
  2329. sdk_member_name: "stubslib",
  2330. visibility: ["//visibility:public"],
  2331. host_supported: true,
  2332. installable: false,
  2333. compile_multilib: "both",
  2334. stubs: {
  2335. versions: [
  2336. "1",
  2337. "2",
  2338. "3",
  2339. ],
  2340. },
  2341. target: {
  2342. host: {
  2343. enabled: false,
  2344. },
  2345. android_arm64: {
  2346. srcs: ["android/arm64/lib/stubslib.so"],
  2347. },
  2348. android_arm: {
  2349. srcs: ["android/arm/lib/stubslib.so"],
  2350. },
  2351. linux_glibc: {
  2352. enabled: true,
  2353. },
  2354. linux_glibc_x86_64: {
  2355. srcs: ["linux_glibc/x86_64/lib/stubslib.so"],
  2356. },
  2357. linux_glibc_x86: {
  2358. srcs: ["linux_glibc/x86/lib/stubslib.so"],
  2359. },
  2360. },
  2361. }
  2362. cc_prebuilt_library_shared {
  2363. name: "stubslib",
  2364. prefer: false,
  2365. visibility: ["//visibility:public"],
  2366. host_supported: true,
  2367. compile_multilib: "both",
  2368. stubs: {
  2369. versions: [
  2370. "1",
  2371. "2",
  2372. "3",
  2373. ],
  2374. },
  2375. target: {
  2376. host: {
  2377. enabled: false,
  2378. },
  2379. android_arm64: {
  2380. srcs: ["android/arm64/lib/stubslib.so"],
  2381. },
  2382. android_arm: {
  2383. srcs: ["android/arm/lib/stubslib.so"],
  2384. },
  2385. linux_glibc: {
  2386. enabled: true,
  2387. },
  2388. linux_glibc_x86_64: {
  2389. srcs: ["linux_glibc/x86_64/lib/stubslib.so"],
  2390. },
  2391. linux_glibc_x86: {
  2392. srcs: ["linux_glibc/x86/lib/stubslib.so"],
  2393. },
  2394. },
  2395. }
  2396. sdk_snapshot {
  2397. name: "mysdk@current",
  2398. visibility: ["//visibility:public"],
  2399. host_supported: true,
  2400. native_shared_libs: ["mysdk_stubslib@current"],
  2401. target: {
  2402. host: {
  2403. enabled: false,
  2404. },
  2405. linux_glibc: {
  2406. enabled: true,
  2407. },
  2408. },
  2409. }
  2410. `))
  2411. }
  2412. func TestUniqueHostSoname(t *testing.T) {
  2413. result := testSdkWithCc(t, `
  2414. sdk {
  2415. name: "mysdk",
  2416. host_supported: true,
  2417. native_shared_libs: ["mylib"],
  2418. }
  2419. cc_library {
  2420. name: "mylib",
  2421. host_supported: true,
  2422. unique_host_soname: true,
  2423. }
  2424. `)
  2425. result.CheckSnapshot("mysdk", "",
  2426. checkAndroidBpContents(`
  2427. // This is auto-generated. DO NOT EDIT.
  2428. cc_prebuilt_library_shared {
  2429. name: "mysdk_mylib@current",
  2430. sdk_member_name: "mylib",
  2431. visibility: ["//visibility:public"],
  2432. host_supported: true,
  2433. installable: false,
  2434. unique_host_soname: true,
  2435. compile_multilib: "both",
  2436. target: {
  2437. host: {
  2438. enabled: false,
  2439. },
  2440. android_arm64: {
  2441. srcs: ["android/arm64/lib/mylib.so"],
  2442. },
  2443. android_arm: {
  2444. srcs: ["android/arm/lib/mylib.so"],
  2445. },
  2446. linux_glibc: {
  2447. enabled: true,
  2448. },
  2449. linux_glibc_x86_64: {
  2450. srcs: ["linux_glibc/x86_64/lib/mylib-host.so"],
  2451. },
  2452. linux_glibc_x86: {
  2453. srcs: ["linux_glibc/x86/lib/mylib-host.so"],
  2454. },
  2455. },
  2456. }
  2457. cc_prebuilt_library_shared {
  2458. name: "mylib",
  2459. prefer: false,
  2460. visibility: ["//visibility:public"],
  2461. host_supported: true,
  2462. unique_host_soname: true,
  2463. compile_multilib: "both",
  2464. target: {
  2465. host: {
  2466. enabled: false,
  2467. },
  2468. android_arm64: {
  2469. srcs: ["android/arm64/lib/mylib.so"],
  2470. },
  2471. android_arm: {
  2472. srcs: ["android/arm/lib/mylib.so"],
  2473. },
  2474. linux_glibc: {
  2475. enabled: true,
  2476. },
  2477. linux_glibc_x86_64: {
  2478. srcs: ["linux_glibc/x86_64/lib/mylib-host.so"],
  2479. },
  2480. linux_glibc_x86: {
  2481. srcs: ["linux_glibc/x86/lib/mylib-host.so"],
  2482. },
  2483. },
  2484. }
  2485. sdk_snapshot {
  2486. name: "mysdk@current",
  2487. visibility: ["//visibility:public"],
  2488. host_supported: true,
  2489. native_shared_libs: ["mysdk_mylib@current"],
  2490. target: {
  2491. host: {
  2492. enabled: false,
  2493. },
  2494. linux_glibc: {
  2495. enabled: true,
  2496. },
  2497. },
  2498. }
  2499. `),
  2500. checkAllCopyRules(`
  2501. .intermediates/mylib/android_arm64_armv8-a_shared/mylib.so -> android/arm64/lib/mylib.so
  2502. .intermediates/mylib/android_arm_armv7-a-neon_shared/mylib.so -> android/arm/lib/mylib.so
  2503. .intermediates/mylib/linux_glibc_x86_64_shared/mylib-host.so -> linux_glibc/x86_64/lib/mylib-host.so
  2504. .intermediates/mylib/linux_glibc_x86_shared/mylib-host.so -> linux_glibc/x86/lib/mylib-host.so
  2505. `),
  2506. )
  2507. }