cc_sdk_test.go 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204
  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. "fmt"
  17. "testing"
  18. "android/soong/android"
  19. "android/soong/cc"
  20. )
  21. var ccTestFs = android.MockFS{
  22. "Test.cpp": nil,
  23. "myinclude/Test.h": nil,
  24. "myinclude-android/AndroidTest.h": nil,
  25. "myinclude-host/HostTest.h": nil,
  26. "arm64/include/Arm64Test.h": nil,
  27. "libfoo.so": nil,
  28. "aidl/foo/bar/Test.aidl": nil,
  29. "some/where/stubslib.map.txt": nil,
  30. }
  31. // Adds a native bridge target to the configured list of targets.
  32. var prepareForTestWithNativeBridgeTarget = android.FixtureModifyConfig(func(config android.Config) {
  33. config.Targets[android.Android] = append(config.Targets[android.Android], android.Target{
  34. Os: android.Android,
  35. Arch: android.Arch{
  36. ArchType: android.Arm64,
  37. ArchVariant: "armv8-a",
  38. CpuVariant: "cpu",
  39. Abi: nil,
  40. ArchFeatures: nil,
  41. },
  42. NativeBridge: android.NativeBridgeEnabled,
  43. NativeBridgeHostArchName: "x86_64",
  44. NativeBridgeRelativePath: "native_bridge",
  45. })
  46. })
  47. func testSdkWithCc(t *testing.T, bp string) *android.TestResult {
  48. t.Helper()
  49. return testSdkWithFs(t, bp, ccTestFs)
  50. }
  51. // Contains tests for SDK members provided by the cc package.
  52. func TestSingleDeviceOsAssumption(t *testing.T) {
  53. // Mock a module with DeviceSupported() == true.
  54. s := &sdk{}
  55. android.InitAndroidArchModule(s, android.DeviceSupported, android.MultilibCommon)
  56. osTypes := s.getPossibleOsTypes()
  57. if len(osTypes) != 1 {
  58. // The snapshot generation assumes there is a single device OS. If more are
  59. // added it might need to disable them by default, like it does for host
  60. // OS'es.
  61. t.Errorf("expected a single device OS, got %v", osTypes)
  62. }
  63. }
  64. func TestSdkIsCompileMultilibBoth(t *testing.T) {
  65. result := testSdkWithCc(t, `
  66. sdk {
  67. name: "mysdk",
  68. native_shared_libs: ["sdkmember"],
  69. }
  70. cc_library_shared {
  71. name: "sdkmember",
  72. srcs: ["Test.cpp"],
  73. stl: "none",
  74. }
  75. `)
  76. armOutput := result.Module("sdkmember", "android_arm_armv7-a-neon_shared").(*cc.Module).OutputFile()
  77. arm64Output := result.Module("sdkmember", "android_arm64_armv8-a_shared").(*cc.Module).OutputFile()
  78. var inputs []string
  79. buildParams := result.Module("mysdk", android.CommonOS.Name).BuildParamsForTests()
  80. for _, bp := range buildParams {
  81. if bp.Input != nil {
  82. inputs = append(inputs, bp.Input.String())
  83. }
  84. }
  85. // ensure that both 32/64 outputs are inputs of the sdk snapshot
  86. ensureListContains(t, inputs, armOutput.String())
  87. ensureListContains(t, inputs, arm64Output.String())
  88. }
  89. func TestSdkCompileMultilibOverride(t *testing.T) {
  90. result := testSdkWithCc(t, `
  91. sdk {
  92. name: "mysdk",
  93. host_supported: true,
  94. native_shared_libs: ["sdkmember"],
  95. compile_multilib: "64",
  96. }
  97. cc_library_shared {
  98. name: "sdkmember",
  99. host_supported: true,
  100. srcs: ["Test.cpp"],
  101. stl: "none",
  102. compile_multilib: "64",
  103. }
  104. `)
  105. CheckSnapshot(t, result, "mysdk", "",
  106. checkAndroidBpContents(`
  107. // This is auto-generated. DO NOT EDIT.
  108. cc_prebuilt_library_shared {
  109. name: "sdkmember",
  110. prefer: false,
  111. visibility: ["//visibility:public"],
  112. apex_available: ["//apex_available:platform"],
  113. host_supported: true,
  114. stl: "none",
  115. compile_multilib: "64",
  116. target: {
  117. host: {
  118. enabled: false,
  119. },
  120. android_arm64: {
  121. srcs: ["android/arm64/lib/sdkmember.so"],
  122. },
  123. linux_glibc_x86_64: {
  124. enabled: true,
  125. srcs: ["linux_glibc/x86_64/lib/sdkmember.so"],
  126. },
  127. },
  128. }
  129. `),
  130. checkAllCopyRules(`
  131. .intermediates/sdkmember/android_arm64_armv8-a_shared/sdkmember.so -> android/arm64/lib/sdkmember.so
  132. .intermediates/sdkmember/linux_glibc_x86_64_shared/sdkmember.so -> linux_glibc/x86_64/lib/sdkmember.so
  133. `))
  134. }
  135. // Make sure the sdk can use host specific cc libraries static/shared and both.
  136. func TestHostSdkWithCc(t *testing.T) {
  137. testSdkWithCc(t, `
  138. sdk {
  139. name: "mysdk",
  140. device_supported: false,
  141. host_supported: true,
  142. native_shared_libs: ["sdkshared"],
  143. native_static_libs: ["sdkstatic"],
  144. }
  145. cc_library_host_shared {
  146. name: "sdkshared",
  147. stl: "none",
  148. }
  149. cc_library_host_static {
  150. name: "sdkstatic",
  151. stl: "none",
  152. }
  153. `)
  154. }
  155. // Make sure the sdk can use cc libraries static/shared and both.
  156. func TestSdkWithCc(t *testing.T) {
  157. testSdkWithCc(t, `
  158. sdk {
  159. name: "mysdk",
  160. native_shared_libs: ["sdkshared", "sdkboth1"],
  161. native_static_libs: ["sdkstatic", "sdkboth2"],
  162. }
  163. cc_library_shared {
  164. name: "sdkshared",
  165. stl: "none",
  166. }
  167. cc_library_static {
  168. name: "sdkstatic",
  169. stl: "none",
  170. }
  171. cc_library {
  172. name: "sdkboth1",
  173. stl: "none",
  174. }
  175. cc_library {
  176. name: "sdkboth2",
  177. stl: "none",
  178. }
  179. `)
  180. }
  181. func TestSnapshotWithObject(t *testing.T) {
  182. result := testSdkWithCc(t, `
  183. sdk {
  184. name: "mysdk",
  185. native_objects: ["crtobj"],
  186. }
  187. cc_object {
  188. name: "crtobj",
  189. stl: "none",
  190. system_shared_libs: [],
  191. sanitize: {
  192. never: true,
  193. },
  194. }
  195. `)
  196. CheckSnapshot(t, result, "mysdk", "",
  197. checkAndroidBpContents(`
  198. // This is auto-generated. DO NOT EDIT.
  199. cc_prebuilt_object {
  200. name: "crtobj",
  201. prefer: false,
  202. visibility: ["//visibility:public"],
  203. apex_available: ["//apex_available:platform"],
  204. stl: "none",
  205. compile_multilib: "both",
  206. system_shared_libs: [],
  207. sanitize: {
  208. never: true,
  209. },
  210. arch: {
  211. arm64: {
  212. srcs: ["arm64/lib/crtobj.o"],
  213. },
  214. arm: {
  215. srcs: ["arm/lib/crtobj.o"],
  216. },
  217. },
  218. }
  219. `),
  220. checkAllCopyRules(`
  221. .intermediates/crtobj/android_arm64_armv8-a/crtobj.o -> arm64/lib/crtobj.o
  222. .intermediates/crtobj/android_arm_armv7-a-neon/crtobj.o -> arm/lib/crtobj.o
  223. `),
  224. )
  225. }
  226. func TestSnapshotWithCcDuplicateHeaders(t *testing.T) {
  227. result := testSdkWithCc(t, `
  228. sdk {
  229. name: "mysdk",
  230. native_shared_libs: ["mynativelib1", "mynativelib2"],
  231. }
  232. cc_library_shared {
  233. name: "mynativelib1",
  234. srcs: [
  235. "Test.cpp",
  236. ],
  237. export_include_dirs: ["myinclude"],
  238. stl: "none",
  239. }
  240. cc_library_shared {
  241. name: "mynativelib2",
  242. srcs: [
  243. "Test.cpp",
  244. ],
  245. export_include_dirs: ["myinclude"],
  246. stl: "none",
  247. }
  248. `)
  249. CheckSnapshot(t, result, "mysdk", "",
  250. checkAllCopyRules(`
  251. myinclude/Test.h -> include/myinclude/Test.h
  252. .intermediates/mynativelib1/android_arm64_armv8-a_shared/mynativelib1.so -> arm64/lib/mynativelib1.so
  253. .intermediates/mynativelib1/android_arm_armv7-a-neon_shared/mynativelib1.so -> arm/lib/mynativelib1.so
  254. .intermediates/mynativelib2/android_arm64_armv8-a_shared/mynativelib2.so -> arm64/lib/mynativelib2.so
  255. .intermediates/mynativelib2/android_arm_armv7-a-neon_shared/mynativelib2.so -> arm/lib/mynativelib2.so
  256. `),
  257. )
  258. }
  259. func TestSnapshotWithCcExportGeneratedHeaders(t *testing.T) {
  260. result := testSdkWithCc(t, `
  261. sdk {
  262. name: "mysdk",
  263. native_shared_libs: ["mynativelib"],
  264. }
  265. cc_library_shared {
  266. name: "mynativelib",
  267. srcs: [
  268. "Test.cpp",
  269. ],
  270. generated_headers: [
  271. "generated_foo",
  272. ],
  273. export_generated_headers: [
  274. "generated_foo",
  275. ],
  276. export_include_dirs: ["myinclude"],
  277. stl: "none",
  278. }
  279. genrule {
  280. name: "generated_foo",
  281. cmd: "generate-foo",
  282. out: [
  283. "generated_foo/protos/foo/bar.h",
  284. ],
  285. export_include_dirs: [
  286. ".",
  287. "protos",
  288. ],
  289. }
  290. `)
  291. // TODO(b/183322862): Remove this and fix the issue.
  292. errorHandler := android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module source path "snapshot/include_gen/generated_foo/gen/protos" does not exist`)
  293. CheckSnapshot(t, result, "mysdk", "",
  294. checkAndroidBpContents(`
  295. // This is auto-generated. DO NOT EDIT.
  296. cc_prebuilt_library_shared {
  297. name: "mynativelib",
  298. prefer: false,
  299. visibility: ["//visibility:public"],
  300. apex_available: ["//apex_available:platform"],
  301. stl: "none",
  302. compile_multilib: "both",
  303. export_include_dirs: [
  304. "include/myinclude",
  305. "include_gen/generated_foo/gen",
  306. "include_gen/generated_foo/gen/protos",
  307. ],
  308. arch: {
  309. arm64: {
  310. srcs: ["arm64/lib/mynativelib.so"],
  311. },
  312. arm: {
  313. srcs: ["arm/lib/mynativelib.so"],
  314. },
  315. },
  316. }
  317. `),
  318. checkAllCopyRules(`
  319. myinclude/Test.h -> include/myinclude/Test.h
  320. .intermediates/generated_foo/gen/generated_foo/protos/foo/bar.h -> include_gen/generated_foo/gen/generated_foo/protos/foo/bar.h
  321. .intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
  322. .intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
  323. `),
  324. snapshotTestErrorHandler(checkSnapshotWithoutSource, errorHandler),
  325. snapshotTestErrorHandler(checkSnapshotWithSourcePreferred, errorHandler),
  326. snapshotTestErrorHandler(checkSnapshotPreferredWithSource, errorHandler),
  327. )
  328. }
  329. // Verify that when the shared library has some common and some arch specific
  330. // properties that the generated snapshot is optimized properly. Substruct
  331. // handling is tested with the sanitize clauses (but note there's a lot of
  332. // built-in logic in sanitize.go that can affect those flags).
  333. func TestSnapshotWithCcSharedLibraryCommonProperties(t *testing.T) {
  334. result := testSdkWithCc(t, `
  335. sdk {
  336. name: "mysdk",
  337. native_shared_libs: ["mynativelib"],
  338. }
  339. cc_library_shared {
  340. name: "mynativelib",
  341. srcs: [
  342. "Test.cpp",
  343. "aidl/foo/bar/Test.aidl",
  344. ],
  345. export_include_dirs: ["myinclude"],
  346. sanitize: {
  347. fuzzer: false,
  348. integer_overflow: true,
  349. diag: { undefined: false },
  350. },
  351. arch: {
  352. arm64: {
  353. export_system_include_dirs: ["arm64/include"],
  354. sanitize: {
  355. integer_overflow: false,
  356. },
  357. },
  358. },
  359. stl: "none",
  360. }
  361. `)
  362. CheckSnapshot(t, result, "mysdk", "",
  363. checkAndroidBpContents(`
  364. // This is auto-generated. DO NOT EDIT.
  365. cc_prebuilt_library_shared {
  366. name: "mynativelib",
  367. prefer: false,
  368. visibility: ["//visibility:public"],
  369. apex_available: ["//apex_available:platform"],
  370. stl: "none",
  371. compile_multilib: "both",
  372. export_include_dirs: ["include/myinclude"],
  373. sanitize: {
  374. fuzzer: false,
  375. diag: {
  376. undefined: false,
  377. },
  378. },
  379. arch: {
  380. arm64: {
  381. srcs: ["arm64/lib/mynativelib.so"],
  382. export_system_include_dirs: ["arm64/include/arm64/include"],
  383. sanitize: {
  384. integer_overflow: false,
  385. },
  386. },
  387. arm: {
  388. srcs: ["arm/lib/mynativelib.so"],
  389. sanitize: {
  390. integer_overflow: true,
  391. },
  392. },
  393. },
  394. }
  395. `),
  396. checkAllCopyRules(`
  397. myinclude/Test.h -> include/myinclude/Test.h
  398. .intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
  399. arm64/include/Arm64Test.h -> arm64/include/arm64/include/Arm64Test.h
  400. .intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
  401. )
  402. }
  403. func TestSnapshotWithCcBinary(t *testing.T) {
  404. result := testSdkWithCc(t, `
  405. module_exports {
  406. name: "mymodule_exports",
  407. native_binaries: ["mynativebinary"],
  408. }
  409. cc_binary {
  410. name: "mynativebinary",
  411. srcs: [
  412. "Test.cpp",
  413. ],
  414. compile_multilib: "both",
  415. }
  416. `)
  417. CheckSnapshot(t, result, "mymodule_exports", "",
  418. checkAndroidBpContents(`
  419. // This is auto-generated. DO NOT EDIT.
  420. cc_prebuilt_binary {
  421. name: "mynativebinary",
  422. prefer: false,
  423. visibility: ["//visibility:public"],
  424. apex_available: ["//apex_available:platform"],
  425. compile_multilib: "both",
  426. arch: {
  427. arm64: {
  428. srcs: ["arm64/bin/mynativebinary"],
  429. },
  430. arm: {
  431. srcs: ["arm/bin/mynativebinary"],
  432. },
  433. },
  434. }
  435. `),
  436. checkAllCopyRules(`
  437. .intermediates/mynativebinary/android_arm64_armv8-a/mynativebinary -> arm64/bin/mynativebinary
  438. .intermediates/mynativebinary/android_arm_armv7-a-neon/mynativebinary -> arm/bin/mynativebinary
  439. `),
  440. )
  441. }
  442. func TestMultipleHostOsTypesSnapshotWithCcBinary(t *testing.T) {
  443. result := testSdkWithCc(t, `
  444. module_exports {
  445. name: "myexports",
  446. device_supported: false,
  447. host_supported: true,
  448. native_binaries: ["mynativebinary"],
  449. target: {
  450. windows: {
  451. enabled: true,
  452. },
  453. },
  454. }
  455. cc_binary {
  456. name: "mynativebinary",
  457. device_supported: false,
  458. host_supported: true,
  459. srcs: [
  460. "Test.cpp",
  461. ],
  462. compile_multilib: "both",
  463. stl: "none",
  464. target: {
  465. windows: {
  466. enabled: true,
  467. },
  468. },
  469. }
  470. `)
  471. CheckSnapshot(t, result, "myexports", "",
  472. checkAndroidBpContents(`
  473. // This is auto-generated. DO NOT EDIT.
  474. cc_prebuilt_binary {
  475. name: "mynativebinary",
  476. prefer: false,
  477. visibility: ["//visibility:public"],
  478. apex_available: ["//apex_available:platform"],
  479. device_supported: false,
  480. host_supported: true,
  481. stl: "none",
  482. target: {
  483. host: {
  484. enabled: false,
  485. },
  486. linux_glibc: {
  487. compile_multilib: "both",
  488. },
  489. linux_glibc_x86_64: {
  490. enabled: true,
  491. srcs: ["linux_glibc/x86_64/bin/mynativebinary"],
  492. },
  493. linux_glibc_x86: {
  494. enabled: true,
  495. srcs: ["linux_glibc/x86/bin/mynativebinary"],
  496. },
  497. windows: {
  498. compile_multilib: "64",
  499. },
  500. windows_x86_64: {
  501. enabled: true,
  502. srcs: ["windows/x86_64/bin/mynativebinary.exe"],
  503. },
  504. },
  505. }
  506. `),
  507. checkAllCopyRules(`
  508. .intermediates/mynativebinary/linux_glibc_x86_64/mynativebinary -> linux_glibc/x86_64/bin/mynativebinary
  509. .intermediates/mynativebinary/linux_glibc_x86/mynativebinary -> linux_glibc/x86/bin/mynativebinary
  510. .intermediates/mynativebinary/windows_x86_64/mynativebinary.exe -> windows/x86_64/bin/mynativebinary.exe
  511. `),
  512. )
  513. }
  514. func TestSnapshotWithSingleHostOsType(t *testing.T) {
  515. result := android.GroupFixturePreparers(
  516. prepareForSdkTest,
  517. ccTestFs.AddToFixture(),
  518. cc.PrepareForTestOnLinuxBionic,
  519. android.FixtureModifyConfig(func(config android.Config) {
  520. config.Targets[android.LinuxBionic] = []android.Target{
  521. {android.LinuxBionic, android.Arch{ArchType: android.X86_64}, android.NativeBridgeDisabled, "", "", false},
  522. }
  523. }),
  524. ).RunTestWithBp(t, `
  525. cc_defaults {
  526. name: "mydefaults",
  527. device_supported: false,
  528. host_supported: true,
  529. compile_multilib: "64",
  530. target: {
  531. host: {
  532. enabled: false,
  533. },
  534. linux_bionic: {
  535. enabled: true,
  536. },
  537. },
  538. }
  539. module_exports {
  540. name: "myexports",
  541. defaults: ["mydefaults"],
  542. native_shared_libs: ["mynativelib"],
  543. native_binaries: ["mynativebinary"],
  544. compile_multilib: "64", // The built-in default in sdk.go overrides mydefaults.
  545. }
  546. cc_library {
  547. name: "mynativelib",
  548. defaults: ["mydefaults"],
  549. srcs: [
  550. "Test.cpp",
  551. ],
  552. stl: "none",
  553. }
  554. cc_binary {
  555. name: "mynativebinary",
  556. defaults: ["mydefaults"],
  557. srcs: [
  558. "Test.cpp",
  559. ],
  560. stl: "none",
  561. }
  562. `)
  563. CheckSnapshot(t, result, "myexports", "",
  564. checkAndroidBpContents(`
  565. // This is auto-generated. DO NOT EDIT.
  566. cc_prebuilt_binary {
  567. name: "mynativebinary",
  568. prefer: false,
  569. visibility: ["//visibility:public"],
  570. apex_available: ["//apex_available:platform"],
  571. device_supported: false,
  572. host_supported: true,
  573. stl: "none",
  574. compile_multilib: "64",
  575. target: {
  576. host: {
  577. enabled: false,
  578. },
  579. linux_bionic_x86_64: {
  580. enabled: true,
  581. srcs: ["x86_64/bin/mynativebinary"],
  582. },
  583. },
  584. }
  585. cc_prebuilt_library_shared {
  586. name: "mynativelib",
  587. prefer: false,
  588. visibility: ["//visibility:public"],
  589. apex_available: ["//apex_available:platform"],
  590. device_supported: false,
  591. host_supported: true,
  592. stl: "none",
  593. compile_multilib: "64",
  594. target: {
  595. host: {
  596. enabled: false,
  597. },
  598. linux_bionic_x86_64: {
  599. enabled: true,
  600. srcs: ["x86_64/lib/mynativelib.so"],
  601. },
  602. },
  603. }
  604. `),
  605. checkAllCopyRules(`
  606. .intermediates/mynativebinary/linux_bionic_x86_64/mynativebinary -> x86_64/bin/mynativebinary
  607. .intermediates/mynativelib/linux_bionic_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
  608. `),
  609. )
  610. }
  611. // Test that we support the necessary flags for the linker binary, which is
  612. // special in several ways.
  613. func TestSnapshotWithCcStaticNocrtBinary(t *testing.T) {
  614. result := testSdkWithCc(t, `
  615. module_exports {
  616. name: "mymodule_exports",
  617. host_supported: true,
  618. device_supported: false,
  619. native_binaries: ["linker"],
  620. }
  621. cc_binary {
  622. name: "linker",
  623. host_supported: true,
  624. static_executable: true,
  625. nocrt: true,
  626. stl: "none",
  627. srcs: [
  628. "Test.cpp",
  629. ],
  630. compile_multilib: "both",
  631. }
  632. `)
  633. CheckSnapshot(t, result, "mymodule_exports", "",
  634. checkAndroidBpContents(`
  635. // This is auto-generated. DO NOT EDIT.
  636. cc_prebuilt_binary {
  637. name: "linker",
  638. prefer: false,
  639. visibility: ["//visibility:public"],
  640. apex_available: ["//apex_available:platform"],
  641. device_supported: false,
  642. host_supported: true,
  643. stl: "none",
  644. compile_multilib: "both",
  645. static_executable: true,
  646. nocrt: true,
  647. target: {
  648. host: {
  649. enabled: false,
  650. },
  651. linux_glibc_x86_64: {
  652. enabled: true,
  653. srcs: ["x86_64/bin/linker"],
  654. },
  655. linux_glibc_x86: {
  656. enabled: true,
  657. srcs: ["x86/bin/linker"],
  658. },
  659. },
  660. }
  661. `),
  662. checkAllCopyRules(`
  663. .intermediates/linker/linux_glibc_x86_64/linker -> x86_64/bin/linker
  664. .intermediates/linker/linux_glibc_x86/linker -> x86/bin/linker
  665. `),
  666. )
  667. }
  668. func TestSnapshotWithCcSharedLibrary(t *testing.T) {
  669. result := testSdkWithCc(t, `
  670. sdk {
  671. name: "mysdk",
  672. native_shared_libs: ["mynativelib"],
  673. }
  674. cc_library_shared {
  675. name: "mynativelib",
  676. srcs: [
  677. "Test.cpp",
  678. "aidl/foo/bar/Test.aidl",
  679. ],
  680. apex_available: ["apex1", "apex2"],
  681. export_include_dirs: ["myinclude"],
  682. aidl: {
  683. export_aidl_headers: true,
  684. },
  685. stl: "none",
  686. }
  687. `)
  688. CheckSnapshot(t, result, "mysdk", "",
  689. checkAndroidBpContents(`
  690. // This is auto-generated. DO NOT EDIT.
  691. cc_prebuilt_library_shared {
  692. name: "mynativelib",
  693. prefer: false,
  694. visibility: ["//visibility:public"],
  695. apex_available: [
  696. "apex1",
  697. "apex2",
  698. ],
  699. stl: "none",
  700. compile_multilib: "both",
  701. export_include_dirs: ["include/myinclude"],
  702. arch: {
  703. arm64: {
  704. srcs: ["arm64/lib/mynativelib.so"],
  705. export_include_dirs: ["arm64/include_gen/mynativelib/android_arm64_armv8-a_shared/gen/aidl"],
  706. },
  707. arm: {
  708. srcs: ["arm/lib/mynativelib.so"],
  709. export_include_dirs: ["arm/include_gen/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl"],
  710. },
  711. },
  712. }
  713. `),
  714. checkAllCopyRules(`
  715. myinclude/Test.h -> include/myinclude/Test.h
  716. .intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
  717. .intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/Test.h
  718. .intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BnTest.h
  719. .intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BpTest.h
  720. .intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
  721. .intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/Test.h
  722. .intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BnTest.h
  723. .intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm/include_gen/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BpTest.h
  724. `),
  725. )
  726. }
  727. func TestSnapshotWithCcSharedLibrarySharedLibs(t *testing.T) {
  728. result := testSdkWithCc(t, `
  729. sdk {
  730. name: "mysdk",
  731. native_shared_libs: [
  732. "mynativelib",
  733. "myothernativelib",
  734. "mysystemnativelib",
  735. ],
  736. }
  737. cc_library {
  738. name: "mysystemnativelib",
  739. srcs: [
  740. "Test.cpp",
  741. ],
  742. stl: "none",
  743. }
  744. cc_library_shared {
  745. name: "myothernativelib",
  746. srcs: [
  747. "Test.cpp",
  748. ],
  749. system_shared_libs: [
  750. // A reference to a library that is not an sdk member. Uses libm as that
  751. // is in the default set of modules available to this test and so is available
  752. // both here and also when the generated Android.bp file is tested in
  753. // CheckSnapshot(). This ensures that the system_shared_libs property correctly
  754. // handles references to modules that are not sdk members.
  755. "libm",
  756. ],
  757. stl: "none",
  758. }
  759. cc_library {
  760. name: "mynativelib",
  761. srcs: [
  762. "Test.cpp",
  763. ],
  764. shared_libs: [
  765. // A reference to another sdk member.
  766. "myothernativelib",
  767. ],
  768. target: {
  769. android: {
  770. shared: {
  771. shared_libs: [
  772. // A reference to a library that is not an sdk member. The libc library
  773. // is used here to check that the shared_libs property is handled correctly
  774. // in a similar way to how libm is used to check system_shared_libs above.
  775. "libc",
  776. ],
  777. },
  778. },
  779. },
  780. stl: "none",
  781. }
  782. `)
  783. CheckSnapshot(t, result, "mysdk", "",
  784. checkAndroidBpContents(`
  785. // This is auto-generated. DO NOT EDIT.
  786. cc_prebuilt_library_shared {
  787. name: "mynativelib",
  788. prefer: false,
  789. visibility: ["//visibility:public"],
  790. apex_available: ["//apex_available:platform"],
  791. stl: "none",
  792. compile_multilib: "both",
  793. shared_libs: [
  794. "myothernativelib",
  795. "libc",
  796. ],
  797. arch: {
  798. arm64: {
  799. srcs: ["arm64/lib/mynativelib.so"],
  800. },
  801. arm: {
  802. srcs: ["arm/lib/mynativelib.so"],
  803. },
  804. },
  805. }
  806. cc_prebuilt_library_shared {
  807. name: "myothernativelib",
  808. prefer: false,
  809. visibility: ["//visibility:public"],
  810. apex_available: ["//apex_available:platform"],
  811. stl: "none",
  812. compile_multilib: "both",
  813. system_shared_libs: ["libm"],
  814. arch: {
  815. arm64: {
  816. srcs: ["arm64/lib/myothernativelib.so"],
  817. },
  818. arm: {
  819. srcs: ["arm/lib/myothernativelib.so"],
  820. },
  821. },
  822. }
  823. cc_prebuilt_library_shared {
  824. name: "mysystemnativelib",
  825. prefer: false,
  826. visibility: ["//visibility:public"],
  827. apex_available: ["//apex_available:platform"],
  828. stl: "none",
  829. compile_multilib: "both",
  830. arch: {
  831. arm64: {
  832. srcs: ["arm64/lib/mysystemnativelib.so"],
  833. },
  834. arm: {
  835. srcs: ["arm/lib/mysystemnativelib.so"],
  836. },
  837. },
  838. }
  839. `),
  840. checkAllCopyRules(`
  841. .intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
  842. .intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
  843. .intermediates/myothernativelib/android_arm64_armv8-a_shared/myothernativelib.so -> arm64/lib/myothernativelib.so
  844. .intermediates/myothernativelib/android_arm_armv7-a-neon_shared/myothernativelib.so -> arm/lib/myothernativelib.so
  845. .intermediates/mysystemnativelib/android_arm64_armv8-a_shared/mysystemnativelib.so -> arm64/lib/mysystemnativelib.so
  846. .intermediates/mysystemnativelib/android_arm_armv7-a-neon_shared/mysystemnativelib.so -> arm/lib/mysystemnativelib.so
  847. `),
  848. )
  849. }
  850. func TestHostSnapshotWithCcSharedLibrary(t *testing.T) {
  851. result := testSdkWithCc(t, `
  852. sdk {
  853. name: "mysdk",
  854. device_supported: false,
  855. host_supported: true,
  856. native_shared_libs: ["mynativelib"],
  857. }
  858. cc_library_shared {
  859. name: "mynativelib",
  860. device_supported: false,
  861. host_supported: true,
  862. srcs: [
  863. "Test.cpp",
  864. "aidl/foo/bar/Test.aidl",
  865. ],
  866. export_include_dirs: ["myinclude"],
  867. aidl: {
  868. export_aidl_headers: true,
  869. },
  870. stl: "none",
  871. sdk_version: "minimum",
  872. }
  873. `)
  874. CheckSnapshot(t, result, "mysdk", "",
  875. checkAndroidBpContents(`
  876. // This is auto-generated. DO NOT EDIT.
  877. cc_prebuilt_library_shared {
  878. name: "mynativelib",
  879. prefer: false,
  880. visibility: ["//visibility:public"],
  881. apex_available: ["//apex_available:platform"],
  882. device_supported: false,
  883. host_supported: true,
  884. sdk_version: "minimum",
  885. stl: "none",
  886. compile_multilib: "both",
  887. export_include_dirs: ["include/myinclude"],
  888. target: {
  889. host: {
  890. enabled: false,
  891. },
  892. linux_glibc_x86_64: {
  893. enabled: true,
  894. srcs: ["x86_64/lib/mynativelib.so"],
  895. export_include_dirs: ["x86_64/include_gen/mynativelib/linux_glibc_x86_64_shared/gen/aidl"],
  896. },
  897. linux_glibc_x86: {
  898. enabled: true,
  899. srcs: ["x86/lib/mynativelib.so"],
  900. export_include_dirs: ["x86/include_gen/mynativelib/linux_glibc_x86_shared/gen/aidl"],
  901. },
  902. },
  903. }
  904. `),
  905. checkAllCopyRules(`
  906. myinclude/Test.h -> include/myinclude/Test.h
  907. .intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
  908. .intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/Test.h
  909. .intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BnTest.h
  910. .intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BpTest.h
  911. .intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> x86/lib/mynativelib.so
  912. .intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/Test.h
  913. .intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BnTest.h
  914. .intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BpTest.h
  915. `),
  916. )
  917. }
  918. func TestMultipleHostOsTypesSnapshotWithCcSharedLibrary(t *testing.T) {
  919. result := testSdkWithCc(t, `
  920. sdk {
  921. name: "mysdk",
  922. device_supported: false,
  923. host_supported: true,
  924. native_shared_libs: ["mynativelib"],
  925. target: {
  926. windows: {
  927. enabled: true,
  928. },
  929. },
  930. }
  931. cc_library_shared {
  932. name: "mynativelib",
  933. device_supported: false,
  934. host_supported: true,
  935. srcs: [
  936. "Test.cpp",
  937. ],
  938. stl: "none",
  939. target: {
  940. windows: {
  941. enabled: true,
  942. },
  943. },
  944. }
  945. `)
  946. CheckSnapshot(t, result, "mysdk", "",
  947. checkAndroidBpContents(`
  948. // This is auto-generated. DO NOT EDIT.
  949. cc_prebuilt_library_shared {
  950. name: "mynativelib",
  951. prefer: false,
  952. visibility: ["//visibility:public"],
  953. apex_available: ["//apex_available:platform"],
  954. device_supported: false,
  955. host_supported: true,
  956. stl: "none",
  957. target: {
  958. host: {
  959. enabled: false,
  960. },
  961. linux_glibc: {
  962. compile_multilib: "both",
  963. },
  964. linux_glibc_x86_64: {
  965. enabled: true,
  966. srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
  967. },
  968. linux_glibc_x86: {
  969. enabled: true,
  970. srcs: ["linux_glibc/x86/lib/mynativelib.so"],
  971. },
  972. windows: {
  973. compile_multilib: "64",
  974. },
  975. windows_x86_64: {
  976. enabled: true,
  977. srcs: ["windows/x86_64/lib/mynativelib.dll"],
  978. },
  979. },
  980. }
  981. `),
  982. checkAllCopyRules(`
  983. .intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> linux_glibc/x86_64/lib/mynativelib.so
  984. .intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> linux_glibc/x86/lib/mynativelib.so
  985. .intermediates/mynativelib/windows_x86_64_shared/mynativelib.dll -> windows/x86_64/lib/mynativelib.dll
  986. `),
  987. )
  988. }
  989. func TestSnapshotWithCcStaticLibrary(t *testing.T) {
  990. result := testSdkWithCc(t, `
  991. module_exports {
  992. name: "myexports",
  993. native_static_libs: ["mynativelib"],
  994. }
  995. cc_library_static {
  996. name: "mynativelib",
  997. srcs: [
  998. "Test.cpp",
  999. "aidl/foo/bar/Test.aidl",
  1000. ],
  1001. export_include_dirs: ["myinclude"],
  1002. aidl: {
  1003. export_aidl_headers: true,
  1004. },
  1005. stl: "none",
  1006. }
  1007. `)
  1008. CheckSnapshot(t, result, "myexports", "",
  1009. checkAndroidBpContents(`
  1010. // This is auto-generated. DO NOT EDIT.
  1011. cc_prebuilt_library_static {
  1012. name: "mynativelib",
  1013. prefer: false,
  1014. visibility: ["//visibility:public"],
  1015. apex_available: ["//apex_available:platform"],
  1016. stl: "none",
  1017. compile_multilib: "both",
  1018. export_include_dirs: ["include/myinclude"],
  1019. arch: {
  1020. arm64: {
  1021. srcs: ["arm64/lib/mynativelib.a"],
  1022. export_include_dirs: ["arm64/include_gen/mynativelib/android_arm64_armv8-a_static/gen/aidl"],
  1023. },
  1024. arm: {
  1025. srcs: ["arm/lib/mynativelib.a"],
  1026. export_include_dirs: ["arm/include_gen/mynativelib/android_arm_armv7-a-neon_static/gen/aidl"],
  1027. },
  1028. },
  1029. }
  1030. `),
  1031. checkAllCopyRules(`
  1032. myinclude/Test.h -> include/myinclude/Test.h
  1033. .intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
  1034. .intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/Test.h
  1035. .intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BnTest.h
  1036. .intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BpTest.h
  1037. .intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
  1038. .intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/Test.h
  1039. .intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BnTest.h
  1040. .intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm/include_gen/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BpTest.h
  1041. `),
  1042. )
  1043. }
  1044. func TestHostSnapshotWithCcStaticLibrary(t *testing.T) {
  1045. result := testSdkWithCc(t, `
  1046. module_exports {
  1047. name: "myexports",
  1048. device_supported: false,
  1049. host_supported: true,
  1050. native_static_libs: ["mynativelib"],
  1051. }
  1052. cc_library_static {
  1053. name: "mynativelib",
  1054. device_supported: false,
  1055. host_supported: true,
  1056. srcs: [
  1057. "Test.cpp",
  1058. "aidl/foo/bar/Test.aidl",
  1059. ],
  1060. export_include_dirs: ["myinclude"],
  1061. aidl: {
  1062. export_aidl_headers: true,
  1063. },
  1064. stl: "none",
  1065. }
  1066. `)
  1067. CheckSnapshot(t, result, "myexports", "",
  1068. checkAndroidBpContents(`
  1069. // This is auto-generated. DO NOT EDIT.
  1070. cc_prebuilt_library_static {
  1071. name: "mynativelib",
  1072. prefer: false,
  1073. visibility: ["//visibility:public"],
  1074. apex_available: ["//apex_available:platform"],
  1075. device_supported: false,
  1076. host_supported: true,
  1077. stl: "none",
  1078. compile_multilib: "both",
  1079. export_include_dirs: ["include/myinclude"],
  1080. target: {
  1081. host: {
  1082. enabled: false,
  1083. },
  1084. linux_glibc_x86_64: {
  1085. enabled: true,
  1086. srcs: ["x86_64/lib/mynativelib.a"],
  1087. export_include_dirs: ["x86_64/include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl"],
  1088. },
  1089. linux_glibc_x86: {
  1090. enabled: true,
  1091. srcs: ["x86/lib/mynativelib.a"],
  1092. export_include_dirs: ["x86/include_gen/mynativelib/linux_glibc_x86_static/gen/aidl"],
  1093. },
  1094. },
  1095. }
  1096. `),
  1097. checkAllCopyRules(`
  1098. myinclude/Test.h -> include/myinclude/Test.h
  1099. .intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
  1100. .intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h
  1101. .intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h
  1102. .intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h
  1103. .intermediates/mynativelib/linux_glibc_x86_static/mynativelib.a -> x86/lib/mynativelib.a
  1104. .intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/Test.h
  1105. .intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BnTest.h
  1106. .intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BpTest.h
  1107. `),
  1108. )
  1109. }
  1110. func TestSnapshotWithCcLibrary(t *testing.T) {
  1111. result := testSdkWithCc(t, `
  1112. module_exports {
  1113. name: "myexports",
  1114. native_libs: ["mynativelib"],
  1115. }
  1116. cc_library {
  1117. name: "mynativelib",
  1118. srcs: [
  1119. "Test.cpp",
  1120. ],
  1121. export_include_dirs: ["myinclude"],
  1122. stl: "none",
  1123. recovery_available: true,
  1124. vendor_available: true,
  1125. }
  1126. `)
  1127. CheckSnapshot(t, result, "myexports", "",
  1128. checkAndroidBpContents(`
  1129. // This is auto-generated. DO NOT EDIT.
  1130. cc_prebuilt_library {
  1131. name: "mynativelib",
  1132. prefer: false,
  1133. visibility: ["//visibility:public"],
  1134. apex_available: ["//apex_available:platform"],
  1135. vendor_available: true,
  1136. stl: "none",
  1137. compile_multilib: "both",
  1138. export_include_dirs: ["include/myinclude"],
  1139. arch: {
  1140. arm64: {
  1141. static: {
  1142. srcs: ["arm64/lib/mynativelib.a"],
  1143. },
  1144. shared: {
  1145. srcs: ["arm64/lib/mynativelib.so"],
  1146. },
  1147. },
  1148. arm: {
  1149. static: {
  1150. srcs: ["arm/lib/mynativelib.a"],
  1151. },
  1152. shared: {
  1153. srcs: ["arm/lib/mynativelib.so"],
  1154. },
  1155. },
  1156. },
  1157. }
  1158. `),
  1159. checkAllCopyRules(`
  1160. myinclude/Test.h -> include/myinclude/Test.h
  1161. .intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
  1162. .intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
  1163. .intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
  1164. .intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
  1165. `),
  1166. // TODO(b/183315522): Remove this and fix the issue.
  1167. snapshotTestErrorHandler(checkSnapshotPreferredWithSource, android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\Qunrecognized property "arch.arm.shared.export_include_dirs"\E`)),
  1168. )
  1169. }
  1170. func TestSnapshotSameLibraryWithNativeLibsAndNativeSharedLib(t *testing.T) {
  1171. result := testSdkWithCc(t, `
  1172. module_exports {
  1173. host_supported: true,
  1174. name: "myexports",
  1175. target: {
  1176. android: {
  1177. native_shared_libs: [
  1178. "mynativelib",
  1179. ],
  1180. },
  1181. not_windows: {
  1182. native_libs: [
  1183. "mynativelib",
  1184. ],
  1185. },
  1186. },
  1187. }
  1188. cc_library {
  1189. name: "mynativelib",
  1190. host_supported: true,
  1191. srcs: [
  1192. "Test.cpp",
  1193. ],
  1194. stl: "none",
  1195. recovery_available: true,
  1196. vendor_available: true,
  1197. }
  1198. `)
  1199. CheckSnapshot(t, result, "myexports", "",
  1200. checkAndroidBpContents(`
  1201. // This is auto-generated. DO NOT EDIT.
  1202. cc_prebuilt_library {
  1203. name: "mynativelib",
  1204. prefer: false,
  1205. visibility: ["//visibility:public"],
  1206. apex_available: ["//apex_available:platform"],
  1207. host_supported: true,
  1208. vendor_available: true,
  1209. stl: "none",
  1210. compile_multilib: "both",
  1211. target: {
  1212. host: {
  1213. enabled: false,
  1214. },
  1215. android_arm64: {
  1216. shared: {
  1217. srcs: ["android/arm64/lib/mynativelib.so"],
  1218. },
  1219. static: {
  1220. enabled: false,
  1221. },
  1222. },
  1223. android_arm: {
  1224. shared: {
  1225. srcs: ["android/arm/lib/mynativelib.so"],
  1226. },
  1227. static: {
  1228. enabled: false,
  1229. },
  1230. },
  1231. linux_glibc_x86_64: {
  1232. enabled: true,
  1233. static: {
  1234. srcs: ["linux_glibc/x86_64/lib/mynativelib.a"],
  1235. },
  1236. shared: {
  1237. srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
  1238. },
  1239. },
  1240. linux_glibc_x86: {
  1241. enabled: true,
  1242. static: {
  1243. srcs: ["linux_glibc/x86/lib/mynativelib.a"],
  1244. },
  1245. shared: {
  1246. srcs: ["linux_glibc/x86/lib/mynativelib.so"],
  1247. },
  1248. },
  1249. },
  1250. }
  1251. `),
  1252. checkAllCopyRules(`
  1253. .intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> android/arm64/lib/mynativelib.so
  1254. .intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> android/arm/lib/mynativelib.so
  1255. .intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> linux_glibc/x86_64/lib/mynativelib.a
  1256. .intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> linux_glibc/x86_64/lib/mynativelib.so
  1257. .intermediates/mynativelib/linux_glibc_x86_static/mynativelib.a -> linux_glibc/x86/lib/mynativelib.a
  1258. .intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> linux_glibc/x86/lib/mynativelib.so
  1259. `),
  1260. )
  1261. }
  1262. func TestSnapshotSameLibraryWithAndroidNativeLibsAndHostNativeSharedLib(t *testing.T) {
  1263. result := testSdkWithCc(t, `
  1264. module_exports {
  1265. host_supported: true,
  1266. name: "myexports",
  1267. target: {
  1268. android: {
  1269. native_libs: [
  1270. "mynativelib",
  1271. ],
  1272. },
  1273. not_windows: {
  1274. native_shared_libs: [
  1275. "mynativelib",
  1276. ],
  1277. },
  1278. },
  1279. }
  1280. cc_library {
  1281. name: "mynativelib",
  1282. host_supported: true,
  1283. srcs: [
  1284. "Test.cpp",
  1285. ],
  1286. stl: "none",
  1287. recovery_available: true,
  1288. vendor_available: true,
  1289. }
  1290. `)
  1291. CheckSnapshot(t, result, "myexports", "",
  1292. checkAndroidBpContents(`
  1293. // This is auto-generated. DO NOT EDIT.
  1294. cc_prebuilt_library {
  1295. name: "mynativelib",
  1296. prefer: false,
  1297. visibility: ["//visibility:public"],
  1298. apex_available: ["//apex_available:platform"],
  1299. host_supported: true,
  1300. vendor_available: true,
  1301. stl: "none",
  1302. compile_multilib: "both",
  1303. target: {
  1304. host: {
  1305. enabled: false,
  1306. },
  1307. android_arm64: {
  1308. static: {
  1309. srcs: ["android/arm64/lib/mynativelib.a"],
  1310. },
  1311. shared: {
  1312. srcs: ["android/arm64/lib/mynativelib.so"],
  1313. },
  1314. },
  1315. android_arm: {
  1316. static: {
  1317. srcs: ["android/arm/lib/mynativelib.a"],
  1318. },
  1319. shared: {
  1320. srcs: ["android/arm/lib/mynativelib.so"],
  1321. },
  1322. },
  1323. linux_glibc_x86_64: {
  1324. enabled: true,
  1325. shared: {
  1326. srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
  1327. },
  1328. static: {
  1329. enabled: false,
  1330. },
  1331. },
  1332. linux_glibc_x86: {
  1333. enabled: true,
  1334. shared: {
  1335. srcs: ["linux_glibc/x86/lib/mynativelib.so"],
  1336. },
  1337. static: {
  1338. enabled: false,
  1339. },
  1340. },
  1341. },
  1342. }
  1343. `),
  1344. checkAllCopyRules(`
  1345. .intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> android/arm64/lib/mynativelib.a
  1346. .intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> android/arm64/lib/mynativelib.so
  1347. .intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> android/arm/lib/mynativelib.a
  1348. .intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> android/arm/lib/mynativelib.so
  1349. .intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> linux_glibc/x86_64/lib/mynativelib.so
  1350. .intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> linux_glibc/x86/lib/mynativelib.so
  1351. `),
  1352. )
  1353. }
  1354. func TestSnapshotSameLibraryWithNativeStaticLibsAndNativeSharedLib(t *testing.T) {
  1355. testSdkError(t, "Incompatible member types", `
  1356. module_exports {
  1357. host_supported: true,
  1358. name: "myexports",
  1359. target: {
  1360. android: {
  1361. native_shared_libs: [
  1362. "mynativelib",
  1363. ],
  1364. },
  1365. not_windows: {
  1366. native_static_libs: [
  1367. "mynativelib",
  1368. ],
  1369. },
  1370. },
  1371. }
  1372. cc_library {
  1373. name: "mynativelib",
  1374. host_supported: true,
  1375. srcs: [
  1376. ],
  1377. stl: "none",
  1378. recovery_available: true,
  1379. vendor_available: true,
  1380. }
  1381. `)
  1382. }
  1383. func TestHostSnapshotWithMultiLib64(t *testing.T) {
  1384. result := testSdkWithCc(t, `
  1385. module_exports {
  1386. name: "myexports",
  1387. device_supported: false,
  1388. host_supported: true,
  1389. target: {
  1390. host: {
  1391. compile_multilib: "64",
  1392. },
  1393. },
  1394. native_static_libs: ["mynativelib"],
  1395. }
  1396. cc_library_static {
  1397. name: "mynativelib",
  1398. device_supported: false,
  1399. host_supported: true,
  1400. srcs: [
  1401. "Test.cpp",
  1402. "aidl/foo/bar/Test.aidl",
  1403. ],
  1404. export_include_dirs: ["myinclude"],
  1405. aidl: {
  1406. export_aidl_headers: true,
  1407. },
  1408. stl: "none",
  1409. }
  1410. `)
  1411. CheckSnapshot(t, result, "myexports", "",
  1412. checkAndroidBpContents(`
  1413. // This is auto-generated. DO NOT EDIT.
  1414. cc_prebuilt_library_static {
  1415. name: "mynativelib",
  1416. prefer: false,
  1417. visibility: ["//visibility:public"],
  1418. apex_available: ["//apex_available:platform"],
  1419. device_supported: false,
  1420. host_supported: true,
  1421. stl: "none",
  1422. compile_multilib: "64",
  1423. export_include_dirs: [
  1424. "include/myinclude",
  1425. "include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl",
  1426. ],
  1427. target: {
  1428. host: {
  1429. enabled: false,
  1430. },
  1431. linux_glibc_x86_64: {
  1432. enabled: true,
  1433. srcs: ["x86_64/lib/mynativelib.a"],
  1434. },
  1435. },
  1436. }
  1437. `),
  1438. checkAllCopyRules(`
  1439. myinclude/Test.h -> include/myinclude/Test.h
  1440. .intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h
  1441. .intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h
  1442. .intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h
  1443. .intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
  1444. `),
  1445. )
  1446. }
  1447. func TestSnapshotWithCcHeadersLibrary(t *testing.T) {
  1448. result := testSdkWithCc(t, `
  1449. sdk {
  1450. name: "mysdk",
  1451. native_header_libs: ["mynativeheaders"],
  1452. }
  1453. cc_library_headers {
  1454. name: "mynativeheaders",
  1455. export_include_dirs: ["myinclude"],
  1456. stl: "none",
  1457. }
  1458. `)
  1459. CheckSnapshot(t, result, "mysdk", "",
  1460. checkAndroidBpContents(`
  1461. // This is auto-generated. DO NOT EDIT.
  1462. cc_prebuilt_library_headers {
  1463. name: "mynativeheaders",
  1464. prefer: false,
  1465. visibility: ["//visibility:public"],
  1466. apex_available: ["//apex_available:platform"],
  1467. stl: "none",
  1468. compile_multilib: "both",
  1469. export_include_dirs: ["include/myinclude"],
  1470. }
  1471. `),
  1472. checkAllCopyRules(`
  1473. myinclude/Test.h -> include/myinclude/Test.h
  1474. `),
  1475. )
  1476. }
  1477. func TestSnapshotWithCcHeadersLibraryAndNativeBridgeSupport(t *testing.T) {
  1478. result := android.GroupFixturePreparers(
  1479. cc.PrepareForTestWithCcDefaultModules,
  1480. PrepareForTestWithSdkBuildComponents,
  1481. ccTestFs.AddToFixture(),
  1482. prepareForTestWithNativeBridgeTarget,
  1483. ).RunTestWithBp(t, `
  1484. sdk {
  1485. name: "mysdk",
  1486. native_header_libs: ["mynativeheaders"],
  1487. traits: {
  1488. native_bridge_support: ["mynativeheaders"],
  1489. },
  1490. }
  1491. cc_library_headers {
  1492. name: "mynativeheaders",
  1493. export_include_dirs: ["myinclude"],
  1494. stl: "none",
  1495. system_shared_libs: [],
  1496. native_bridge_supported: true,
  1497. }
  1498. `)
  1499. CheckSnapshot(t, result, "mysdk", "",
  1500. checkAndroidBpContents(`
  1501. // This is auto-generated. DO NOT EDIT.
  1502. cc_prebuilt_library_headers {
  1503. name: "mynativeheaders",
  1504. prefer: false,
  1505. visibility: ["//visibility:public"],
  1506. apex_available: ["//apex_available:platform"],
  1507. native_bridge_supported: true,
  1508. stl: "none",
  1509. compile_multilib: "both",
  1510. system_shared_libs: [],
  1511. export_include_dirs: ["include/myinclude"],
  1512. }
  1513. `),
  1514. checkAllCopyRules(`
  1515. myinclude/Test.h -> include/myinclude/Test.h
  1516. `),
  1517. )
  1518. }
  1519. // TestSnapshotWithCcHeadersLibrary_DetectsNativeBridgeSpecificProperties verifies that when a
  1520. // module that has different output files for a native bridge target requests the native bridge
  1521. // variants are copied into the sdk snapshot that it reports an error.
  1522. func TestSnapshotWithCcHeadersLibrary_DetectsNativeBridgeSpecificProperties(t *testing.T) {
  1523. android.GroupFixturePreparers(
  1524. cc.PrepareForTestWithCcDefaultModules,
  1525. PrepareForTestWithSdkBuildComponents,
  1526. ccTestFs.AddToFixture(),
  1527. prepareForTestWithNativeBridgeTarget,
  1528. ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
  1529. `\QArchitecture variant "arm64_native_bridge" of sdk member "mynativeheaders" has properties distinct from other variants; this is not yet supported. The properties are:
  1530. export_include_dirs: [
  1531. "arm64_native_bridge/include/myinclude_nativebridge",
  1532. "arm64_native_bridge/include/myinclude",
  1533. ],\E`)).
  1534. RunTestWithBp(t, `
  1535. sdk {
  1536. name: "mysdk",
  1537. native_header_libs: ["mynativeheaders"],
  1538. traits: {
  1539. native_bridge_support: ["mynativeheaders"],
  1540. },
  1541. }
  1542. cc_library_headers {
  1543. name: "mynativeheaders",
  1544. export_include_dirs: ["myinclude"],
  1545. stl: "none",
  1546. system_shared_libs: [],
  1547. native_bridge_supported: true,
  1548. target: {
  1549. native_bridge: {
  1550. export_include_dirs: ["myinclude_nativebridge"],
  1551. },
  1552. },
  1553. }
  1554. `)
  1555. }
  1556. func TestSnapshotWithCcHeadersLibraryAndImageVariants(t *testing.T) {
  1557. testImageVariant := func(t *testing.T, property, trait string) {
  1558. result := android.GroupFixturePreparers(
  1559. cc.PrepareForTestWithCcDefaultModules,
  1560. PrepareForTestWithSdkBuildComponents,
  1561. ccTestFs.AddToFixture(),
  1562. ).RunTestWithBp(t, fmt.Sprintf(`
  1563. sdk {
  1564. name: "mysdk",
  1565. native_header_libs: ["mynativeheaders"],
  1566. traits: {
  1567. %s: ["mynativeheaders"],
  1568. },
  1569. }
  1570. cc_library_headers {
  1571. name: "mynativeheaders",
  1572. export_include_dirs: ["myinclude"],
  1573. stl: "none",
  1574. system_shared_libs: [],
  1575. %s: true,
  1576. }
  1577. `, trait, property))
  1578. CheckSnapshot(t, result, "mysdk", "",
  1579. checkAndroidBpContents(fmt.Sprintf(`
  1580. // This is auto-generated. DO NOT EDIT.
  1581. cc_prebuilt_library_headers {
  1582. name: "mynativeheaders",
  1583. prefer: false,
  1584. visibility: ["//visibility:public"],
  1585. apex_available: ["//apex_available:platform"],
  1586. %s: true,
  1587. stl: "none",
  1588. compile_multilib: "both",
  1589. system_shared_libs: [],
  1590. export_include_dirs: ["include/myinclude"],
  1591. }
  1592. `, property)),
  1593. checkAllCopyRules(`
  1594. myinclude/Test.h -> include/myinclude/Test.h
  1595. `),
  1596. )
  1597. }
  1598. t.Run("ramdisk", func(t *testing.T) {
  1599. testImageVariant(t, "ramdisk_available", "ramdisk_image_required")
  1600. })
  1601. t.Run("recovery", func(t *testing.T) {
  1602. testImageVariant(t, "recovery_available", "recovery_image_required")
  1603. })
  1604. }
  1605. func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) {
  1606. result := testSdkWithCc(t, `
  1607. sdk {
  1608. name: "mysdk",
  1609. device_supported: false,
  1610. host_supported: true,
  1611. native_header_libs: ["mynativeheaders"],
  1612. }
  1613. cc_library_headers {
  1614. name: "mynativeheaders",
  1615. device_supported: false,
  1616. host_supported: true,
  1617. export_include_dirs: ["myinclude"],
  1618. stl: "none",
  1619. }
  1620. `)
  1621. CheckSnapshot(t, result, "mysdk", "",
  1622. checkAndroidBpContents(`
  1623. // This is auto-generated. DO NOT EDIT.
  1624. cc_prebuilt_library_headers {
  1625. name: "mynativeheaders",
  1626. prefer: false,
  1627. visibility: ["//visibility:public"],
  1628. apex_available: ["//apex_available:platform"],
  1629. device_supported: false,
  1630. host_supported: true,
  1631. stl: "none",
  1632. compile_multilib: "both",
  1633. export_include_dirs: ["include/myinclude"],
  1634. target: {
  1635. host: {
  1636. enabled: false,
  1637. },
  1638. linux_glibc_x86_64: {
  1639. enabled: true,
  1640. },
  1641. linux_glibc_x86: {
  1642. enabled: true,
  1643. },
  1644. },
  1645. }
  1646. `),
  1647. checkAllCopyRules(`
  1648. myinclude/Test.h -> include/myinclude/Test.h
  1649. `),
  1650. )
  1651. }
  1652. func TestDeviceAndHostSnapshotWithCcHeadersLibrary(t *testing.T) {
  1653. result := testSdkWithCc(t, `
  1654. sdk {
  1655. name: "mysdk",
  1656. host_supported: true,
  1657. native_header_libs: ["mynativeheaders"],
  1658. }
  1659. cc_library_headers {
  1660. name: "mynativeheaders",
  1661. host_supported: true,
  1662. stl: "none",
  1663. export_system_include_dirs: ["myinclude"],
  1664. target: {
  1665. android: {
  1666. export_include_dirs: ["myinclude-android"],
  1667. },
  1668. host: {
  1669. export_include_dirs: ["myinclude-host"],
  1670. },
  1671. },
  1672. }
  1673. `)
  1674. CheckSnapshot(t, result, "mysdk", "",
  1675. checkAndroidBpContents(`
  1676. // This is auto-generated. DO NOT EDIT.
  1677. cc_prebuilt_library_headers {
  1678. name: "mynativeheaders",
  1679. prefer: false,
  1680. visibility: ["//visibility:public"],
  1681. apex_available: ["//apex_available:platform"],
  1682. host_supported: true,
  1683. stl: "none",
  1684. compile_multilib: "both",
  1685. export_system_include_dirs: ["common_os/include/myinclude"],
  1686. target: {
  1687. host: {
  1688. enabled: false,
  1689. },
  1690. android: {
  1691. export_include_dirs: ["android/include/myinclude-android"],
  1692. },
  1693. linux_glibc: {
  1694. export_include_dirs: ["linux_glibc/include/myinclude-host"],
  1695. },
  1696. linux_glibc_x86_64: {
  1697. enabled: true,
  1698. },
  1699. linux_glibc_x86: {
  1700. enabled: true,
  1701. },
  1702. },
  1703. }
  1704. `),
  1705. checkAllCopyRules(`
  1706. myinclude/Test.h -> common_os/include/myinclude/Test.h
  1707. myinclude-android/AndroidTest.h -> android/include/myinclude-android/AndroidTest.h
  1708. myinclude-host/HostTest.h -> linux_glibc/include/myinclude-host/HostTest.h
  1709. `),
  1710. )
  1711. }
  1712. func TestSystemSharedLibPropagation(t *testing.T) {
  1713. result := testSdkWithCc(t, `
  1714. sdk {
  1715. name: "mysdk",
  1716. native_shared_libs: ["sslnil", "sslempty", "sslnonempty"],
  1717. }
  1718. cc_library {
  1719. name: "sslnil",
  1720. host_supported: true,
  1721. }
  1722. cc_library {
  1723. name: "sslempty",
  1724. system_shared_libs: [],
  1725. }
  1726. cc_library {
  1727. name: "sslnonempty",
  1728. system_shared_libs: ["sslnil"],
  1729. }
  1730. `)
  1731. CheckSnapshot(t, result, "mysdk", "",
  1732. checkAndroidBpContents(`
  1733. // This is auto-generated. DO NOT EDIT.
  1734. cc_prebuilt_library_shared {
  1735. name: "sslnil",
  1736. prefer: false,
  1737. visibility: ["//visibility:public"],
  1738. apex_available: ["//apex_available:platform"],
  1739. compile_multilib: "both",
  1740. arch: {
  1741. arm64: {
  1742. srcs: ["arm64/lib/sslnil.so"],
  1743. },
  1744. arm: {
  1745. srcs: ["arm/lib/sslnil.so"],
  1746. },
  1747. },
  1748. }
  1749. cc_prebuilt_library_shared {
  1750. name: "sslempty",
  1751. prefer: false,
  1752. visibility: ["//visibility:public"],
  1753. apex_available: ["//apex_available:platform"],
  1754. compile_multilib: "both",
  1755. system_shared_libs: [],
  1756. arch: {
  1757. arm64: {
  1758. srcs: ["arm64/lib/sslempty.so"],
  1759. },
  1760. arm: {
  1761. srcs: ["arm/lib/sslempty.so"],
  1762. },
  1763. },
  1764. }
  1765. cc_prebuilt_library_shared {
  1766. name: "sslnonempty",
  1767. prefer: false,
  1768. visibility: ["//visibility:public"],
  1769. apex_available: ["//apex_available:platform"],
  1770. compile_multilib: "both",
  1771. system_shared_libs: ["sslnil"],
  1772. arch: {
  1773. arm64: {
  1774. srcs: ["arm64/lib/sslnonempty.so"],
  1775. },
  1776. arm: {
  1777. srcs: ["arm/lib/sslnonempty.so"],
  1778. },
  1779. },
  1780. }
  1781. `))
  1782. result = testSdkWithCc(t, `
  1783. sdk {
  1784. name: "mysdk",
  1785. host_supported: true,
  1786. native_shared_libs: ["sslvariants"],
  1787. }
  1788. cc_library {
  1789. name: "sslvariants",
  1790. host_supported: true,
  1791. target: {
  1792. android: {
  1793. system_shared_libs: [],
  1794. },
  1795. },
  1796. }
  1797. `)
  1798. CheckSnapshot(t, result, "mysdk", "",
  1799. checkAndroidBpContents(`
  1800. // This is auto-generated. DO NOT EDIT.
  1801. cc_prebuilt_library_shared {
  1802. name: "sslvariants",
  1803. prefer: false,
  1804. visibility: ["//visibility:public"],
  1805. apex_available: ["//apex_available:platform"],
  1806. host_supported: true,
  1807. compile_multilib: "both",
  1808. target: {
  1809. host: {
  1810. enabled: false,
  1811. },
  1812. android: {
  1813. system_shared_libs: [],
  1814. },
  1815. android_arm64: {
  1816. srcs: ["android/arm64/lib/sslvariants.so"],
  1817. },
  1818. android_arm: {
  1819. srcs: ["android/arm/lib/sslvariants.so"],
  1820. },
  1821. linux_glibc_x86_64: {
  1822. enabled: true,
  1823. srcs: ["linux_glibc/x86_64/lib/sslvariants.so"],
  1824. },
  1825. linux_glibc_x86: {
  1826. enabled: true,
  1827. srcs: ["linux_glibc/x86/lib/sslvariants.so"],
  1828. },
  1829. },
  1830. }
  1831. `),
  1832. )
  1833. }
  1834. func TestStubsLibrary(t *testing.T) {
  1835. result := testSdkWithCc(t, `
  1836. sdk {
  1837. name: "mysdk",
  1838. native_shared_libs: ["stubslib"],
  1839. }
  1840. cc_library {
  1841. name: "internaldep",
  1842. }
  1843. cc_library {
  1844. name: "stubslib",
  1845. shared_libs: ["internaldep"],
  1846. stubs: {
  1847. symbol_file: "some/where/stubslib.map.txt",
  1848. versions: ["1", "2", "3"],
  1849. },
  1850. }
  1851. `)
  1852. CheckSnapshot(t, result, "mysdk", "",
  1853. checkAndroidBpContents(`
  1854. // This is auto-generated. DO NOT EDIT.
  1855. cc_prebuilt_library_shared {
  1856. name: "stubslib",
  1857. prefer: false,
  1858. visibility: ["//visibility:public"],
  1859. apex_available: ["//apex_available:platform"],
  1860. compile_multilib: "both",
  1861. stubs: {
  1862. versions: [
  1863. "1",
  1864. "2",
  1865. "3",
  1866. "current",
  1867. ],
  1868. },
  1869. arch: {
  1870. arm64: {
  1871. srcs: ["arm64/lib/stubslib.so"],
  1872. },
  1873. arm: {
  1874. srcs: ["arm/lib/stubslib.so"],
  1875. },
  1876. },
  1877. }
  1878. `))
  1879. }
  1880. func TestDeviceAndHostSnapshotWithStubsLibrary(t *testing.T) {
  1881. result := testSdkWithCc(t, `
  1882. sdk {
  1883. name: "mysdk",
  1884. host_supported: true,
  1885. native_shared_libs: ["stubslib"],
  1886. }
  1887. cc_library {
  1888. name: "internaldep",
  1889. host_supported: true,
  1890. }
  1891. cc_library {
  1892. name: "stubslib",
  1893. host_supported: true,
  1894. shared_libs: ["internaldep"],
  1895. stubs: {
  1896. symbol_file: "some/where/stubslib.map.txt",
  1897. versions: ["1", "2", "3"],
  1898. },
  1899. }
  1900. `)
  1901. CheckSnapshot(t, result, "mysdk", "",
  1902. checkAndroidBpContents(`
  1903. // This is auto-generated. DO NOT EDIT.
  1904. cc_prebuilt_library_shared {
  1905. name: "stubslib",
  1906. prefer: false,
  1907. visibility: ["//visibility:public"],
  1908. apex_available: ["//apex_available:platform"],
  1909. host_supported: true,
  1910. compile_multilib: "both",
  1911. stubs: {
  1912. versions: [
  1913. "1",
  1914. "2",
  1915. "3",
  1916. "current",
  1917. ],
  1918. },
  1919. target: {
  1920. host: {
  1921. enabled: false,
  1922. },
  1923. android_arm64: {
  1924. srcs: ["android/arm64/lib/stubslib.so"],
  1925. },
  1926. android_arm: {
  1927. srcs: ["android/arm/lib/stubslib.so"],
  1928. },
  1929. linux_glibc_x86_64: {
  1930. enabled: true,
  1931. srcs: ["linux_glibc/x86_64/lib/stubslib.so"],
  1932. },
  1933. linux_glibc_x86: {
  1934. enabled: true,
  1935. srcs: ["linux_glibc/x86/lib/stubslib.so"],
  1936. },
  1937. },
  1938. }
  1939. `),
  1940. )
  1941. }
  1942. func TestUniqueHostSoname(t *testing.T) {
  1943. result := testSdkWithCc(t, `
  1944. sdk {
  1945. name: "mysdk",
  1946. host_supported: true,
  1947. native_shared_libs: ["mylib"],
  1948. }
  1949. cc_library {
  1950. name: "mylib",
  1951. host_supported: true,
  1952. unique_host_soname: true,
  1953. }
  1954. `)
  1955. CheckSnapshot(t, result, "mysdk", "",
  1956. checkAndroidBpContents(`
  1957. // This is auto-generated. DO NOT EDIT.
  1958. cc_prebuilt_library_shared {
  1959. name: "mylib",
  1960. prefer: false,
  1961. visibility: ["//visibility:public"],
  1962. apex_available: ["//apex_available:platform"],
  1963. host_supported: true,
  1964. unique_host_soname: true,
  1965. compile_multilib: "both",
  1966. target: {
  1967. host: {
  1968. enabled: false,
  1969. },
  1970. android_arm64: {
  1971. srcs: ["android/arm64/lib/mylib.so"],
  1972. },
  1973. android_arm: {
  1974. srcs: ["android/arm/lib/mylib.so"],
  1975. },
  1976. linux_glibc_x86_64: {
  1977. enabled: true,
  1978. srcs: ["linux_glibc/x86_64/lib/mylib-host.so"],
  1979. },
  1980. linux_glibc_x86: {
  1981. enabled: true,
  1982. srcs: ["linux_glibc/x86/lib/mylib-host.so"],
  1983. },
  1984. },
  1985. }
  1986. `),
  1987. checkAllCopyRules(`
  1988. .intermediates/mylib/android_arm64_armv8-a_shared/mylib.so -> android/arm64/lib/mylib.so
  1989. .intermediates/mylib/android_arm_armv7-a-neon_shared/mylib.so -> android/arm/lib/mylib.so
  1990. .intermediates/mylib/linux_glibc_x86_64_shared/mylib-host.so -> linux_glibc/x86_64/lib/mylib-host.so
  1991. .intermediates/mylib/linux_glibc_x86_shared/mylib-host.so -> linux_glibc/x86/lib/mylib-host.so
  1992. `),
  1993. )
  1994. }
  1995. func TestNoSanitizerMembers(t *testing.T) {
  1996. result := testSdkWithCc(t, `
  1997. sdk {
  1998. name: "mysdk",
  1999. native_shared_libs: ["mynativelib"],
  2000. }
  2001. cc_library_shared {
  2002. name: "mynativelib",
  2003. srcs: ["Test.cpp"],
  2004. export_include_dirs: ["myinclude"],
  2005. arch: {
  2006. arm64: {
  2007. export_system_include_dirs: ["arm64/include"],
  2008. sanitize: {
  2009. hwaddress: true,
  2010. },
  2011. },
  2012. },
  2013. }
  2014. `)
  2015. CheckSnapshot(t, result, "mysdk", "",
  2016. checkAndroidBpContents(`
  2017. // This is auto-generated. DO NOT EDIT.
  2018. cc_prebuilt_library_shared {
  2019. name: "mynativelib",
  2020. prefer: false,
  2021. visibility: ["//visibility:public"],
  2022. apex_available: ["//apex_available:platform"],
  2023. compile_multilib: "both",
  2024. export_include_dirs: ["include/myinclude"],
  2025. arch: {
  2026. arm64: {
  2027. export_system_include_dirs: ["arm64/include/arm64/include"],
  2028. },
  2029. arm: {
  2030. srcs: ["arm/lib/mynativelib.so"],
  2031. },
  2032. },
  2033. }
  2034. `),
  2035. checkAllCopyRules(`
  2036. myinclude/Test.h -> include/myinclude/Test.h
  2037. arm64/include/Arm64Test.h -> arm64/include/arm64/include/Arm64Test.h
  2038. .intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
  2039. `),
  2040. )
  2041. }