cc_library_shared_conversion_test.go 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587
  1. // Copyright 2021 Google Inc. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package bp2build
  15. import (
  16. "testing"
  17. "android/soong/android"
  18. "android/soong/cc"
  19. )
  20. const (
  21. // See cc/testing.go for more context
  22. // TODO(alexmarquez): Split out the preamble into common code?
  23. soongCcLibrarySharedPreamble = soongCcLibraryStaticPreamble
  24. )
  25. func registerCcLibrarySharedModuleTypes(ctx android.RegistrationContext) {
  26. cc.RegisterCCBuildComponents(ctx)
  27. ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
  28. ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory)
  29. ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
  30. }
  31. func runCcLibrarySharedTestCase(t *testing.T, tc Bp2buildTestCase) {
  32. t.Helper()
  33. t.Parallel()
  34. (&tc).ModuleTypeUnderTest = "cc_library_shared"
  35. (&tc).ModuleTypeUnderTestFactory = cc.LibrarySharedFactory
  36. RunBp2BuildTestCase(t, registerCcLibrarySharedModuleTypes, tc)
  37. }
  38. func TestCcLibrarySharedSimple(t *testing.T) {
  39. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  40. Description: "cc_library_shared simple overall test",
  41. Filesystem: map[string]string{
  42. // NOTE: include_dir headers *should not* appear in Bazel hdrs later (?)
  43. "include_dir_1/include_dir_1_a.h": "",
  44. "include_dir_1/include_dir_1_b.h": "",
  45. "include_dir_2/include_dir_2_a.h": "",
  46. "include_dir_2/include_dir_2_b.h": "",
  47. // NOTE: local_include_dir headers *should not* appear in Bazel hdrs later (?)
  48. "local_include_dir_1/local_include_dir_1_a.h": "",
  49. "local_include_dir_1/local_include_dir_1_b.h": "",
  50. "local_include_dir_2/local_include_dir_2_a.h": "",
  51. "local_include_dir_2/local_include_dir_2_b.h": "",
  52. // NOTE: export_include_dir headers *should* appear in Bazel hdrs later
  53. "export_include_dir_1/export_include_dir_1_a.h": "",
  54. "export_include_dir_1/export_include_dir_1_b.h": "",
  55. "export_include_dir_2/export_include_dir_2_a.h": "",
  56. "export_include_dir_2/export_include_dir_2_b.h": "",
  57. // NOTE: Soong implicitly includes headers in the current directory
  58. "implicit_include_1.h": "",
  59. "implicit_include_2.h": "",
  60. },
  61. Blueprint: soongCcLibrarySharedPreamble + `
  62. cc_library_headers {
  63. name: "header_lib_1",
  64. export_include_dirs: ["header_lib_1"],
  65. bazel_module: { bp2build_available: false },
  66. }
  67. cc_library_headers {
  68. name: "header_lib_2",
  69. export_include_dirs: ["header_lib_2"],
  70. bazel_module: { bp2build_available: false },
  71. }
  72. cc_library_shared {
  73. name: "shared_lib_1",
  74. srcs: ["shared_lib_1.cc"],
  75. bazel_module: { bp2build_available: false },
  76. }
  77. cc_library_shared {
  78. name: "shared_lib_2",
  79. srcs: ["shared_lib_2.cc"],
  80. bazel_module: { bp2build_available: false },
  81. }
  82. cc_library_static {
  83. name: "whole_static_lib_1",
  84. srcs: ["whole_static_lib_1.cc"],
  85. bazel_module: { bp2build_available: false },
  86. }
  87. cc_library_static {
  88. name: "whole_static_lib_2",
  89. srcs: ["whole_static_lib_2.cc"],
  90. bazel_module: { bp2build_available: false },
  91. }
  92. cc_library_shared {
  93. name: "foo_shared",
  94. srcs: [
  95. "foo_shared1.cc",
  96. "foo_shared2.cc",
  97. ],
  98. cflags: [
  99. "-Dflag1",
  100. "-Dflag2"
  101. ],
  102. shared_libs: [
  103. "shared_lib_1",
  104. "shared_lib_2"
  105. ],
  106. whole_static_libs: [
  107. "whole_static_lib_1",
  108. "whole_static_lib_2"
  109. ],
  110. include_dirs: [
  111. "include_dir_1",
  112. "include_dir_2",
  113. ],
  114. local_include_dirs: [
  115. "local_include_dir_1",
  116. "local_include_dir_2",
  117. ],
  118. export_include_dirs: [
  119. "export_include_dir_1",
  120. "export_include_dir_2"
  121. ],
  122. header_libs: [
  123. "header_lib_1",
  124. "header_lib_2"
  125. ],
  126. sdk_version: "current",
  127. min_sdk_version: "29",
  128. // TODO: Also support export_header_lib_headers
  129. }`,
  130. ExpectedBazelTargets: []string{
  131. MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
  132. "absolute_includes": `[
  133. "include_dir_1",
  134. "include_dir_2",
  135. ]`,
  136. "copts": `[
  137. "-Dflag1",
  138. "-Dflag2",
  139. ]`,
  140. "export_includes": `[
  141. "export_include_dir_1",
  142. "export_include_dir_2",
  143. ]`,
  144. "implementation_deps": `[
  145. ":header_lib_1",
  146. ":header_lib_2",
  147. ]`,
  148. "implementation_dynamic_deps": `[
  149. ":shared_lib_1",
  150. ":shared_lib_2",
  151. ]`,
  152. "local_includes": `[
  153. "local_include_dir_1",
  154. "local_include_dir_2",
  155. ".",
  156. ]`,
  157. "srcs": `[
  158. "foo_shared1.cc",
  159. "foo_shared2.cc",
  160. ]`,
  161. "whole_archive_deps": `[
  162. ":whole_static_lib_1",
  163. ":whole_static_lib_2",
  164. ]`,
  165. "sdk_version": `"current"`,
  166. "min_sdk_version": `"29"`,
  167. }),
  168. },
  169. })
  170. }
  171. func TestCcLibrarySharedArchSpecificSharedLib(t *testing.T) {
  172. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  173. Description: "cc_library_shared arch-specific shared_libs with whole_static_libs",
  174. Filesystem: map[string]string{},
  175. Blueprint: soongCcLibrarySharedPreamble + `
  176. cc_library_static {
  177. name: "static_dep",
  178. bazel_module: { bp2build_available: false },
  179. }
  180. cc_library_shared {
  181. name: "shared_dep",
  182. bazel_module: { bp2build_available: false },
  183. }
  184. cc_library_shared {
  185. name: "foo_shared",
  186. arch: { arm64: { shared_libs: ["shared_dep"], whole_static_libs: ["static_dep"] } },
  187. include_build_directory: false,
  188. }`,
  189. ExpectedBazelTargets: []string{
  190. MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
  191. "implementation_dynamic_deps": `select({
  192. "//build/bazel/platforms/arch:arm64": [":shared_dep"],
  193. "//conditions:default": [],
  194. })`,
  195. "whole_archive_deps": `select({
  196. "//build/bazel/platforms/arch:arm64": [":static_dep"],
  197. "//conditions:default": [],
  198. })`,
  199. }),
  200. },
  201. })
  202. }
  203. func TestCcLibrarySharedOsSpecificSharedLib(t *testing.T) {
  204. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  205. Description: "cc_library_shared os-specific shared_libs",
  206. Filesystem: map[string]string{},
  207. Blueprint: soongCcLibrarySharedPreamble + `
  208. cc_library_shared {
  209. name: "shared_dep",
  210. bazel_module: { bp2build_available: false },
  211. }
  212. cc_library_shared {
  213. name: "foo_shared",
  214. target: { android: { shared_libs: ["shared_dep"], } },
  215. include_build_directory: false,
  216. }`,
  217. ExpectedBazelTargets: []string{
  218. MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
  219. "implementation_dynamic_deps": `select({
  220. "//build/bazel/platforms/os:android": [":shared_dep"],
  221. "//conditions:default": [],
  222. })`,
  223. }),
  224. },
  225. })
  226. }
  227. func TestCcLibrarySharedBaseArchOsSpecificSharedLib(t *testing.T) {
  228. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  229. Description: "cc_library_shared base, arch, and os-specific shared_libs",
  230. Filesystem: map[string]string{},
  231. Blueprint: soongCcLibrarySharedPreamble + `
  232. cc_library_shared {
  233. name: "shared_dep",
  234. bazel_module: { bp2build_available: false },
  235. }
  236. cc_library_shared {
  237. name: "shared_dep2",
  238. bazel_module: { bp2build_available: false },
  239. }
  240. cc_library_shared {
  241. name: "shared_dep3",
  242. bazel_module: { bp2build_available: false },
  243. }
  244. cc_library_shared {
  245. name: "foo_shared",
  246. shared_libs: ["shared_dep"],
  247. target: { android: { shared_libs: ["shared_dep2"] } },
  248. arch: { arm64: { shared_libs: ["shared_dep3"] } },
  249. include_build_directory: false,
  250. }`,
  251. ExpectedBazelTargets: []string{
  252. MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
  253. "implementation_dynamic_deps": `[":shared_dep"] + select({
  254. "//build/bazel/platforms/arch:arm64": [":shared_dep3"],
  255. "//conditions:default": [],
  256. }) + select({
  257. "//build/bazel/platforms/os:android": [":shared_dep2"],
  258. "//conditions:default": [],
  259. })`,
  260. }),
  261. },
  262. })
  263. }
  264. func TestCcLibrarySharedSimpleExcludeSrcs(t *testing.T) {
  265. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  266. Description: "cc_library_shared simple exclude_srcs",
  267. Filesystem: map[string]string{
  268. "common.c": "",
  269. "foo-a.c": "",
  270. "foo-excluded.c": "",
  271. },
  272. Blueprint: soongCcLibrarySharedPreamble + `
  273. cc_library_shared {
  274. name: "foo_shared",
  275. srcs: ["common.c", "foo-*.c"],
  276. exclude_srcs: ["foo-excluded.c"],
  277. include_build_directory: false,
  278. }`,
  279. ExpectedBazelTargets: []string{
  280. MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
  281. "srcs_c": `[
  282. "common.c",
  283. "foo-a.c",
  284. ]`,
  285. }),
  286. },
  287. })
  288. }
  289. func TestCcLibrarySharedStrip(t *testing.T) {
  290. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  291. Description: "cc_library_shared stripping",
  292. Filesystem: map[string]string{},
  293. Blueprint: soongCcLibrarySharedPreamble + `
  294. cc_library_shared {
  295. name: "foo_shared",
  296. strip: {
  297. keep_symbols: false,
  298. keep_symbols_and_debug_frame: true,
  299. keep_symbols_list: ["sym", "sym2"],
  300. all: true,
  301. none: false,
  302. },
  303. include_build_directory: false,
  304. }`,
  305. ExpectedBazelTargets: []string{
  306. MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
  307. "strip": `{
  308. "all": True,
  309. "keep_symbols": False,
  310. "keep_symbols_and_debug_frame": True,
  311. "keep_symbols_list": [
  312. "sym",
  313. "sym2",
  314. ],
  315. "none": False,
  316. }`,
  317. }),
  318. },
  319. })
  320. }
  321. func TestCcLibrarySharedVersionScriptAndDynamicList(t *testing.T) {
  322. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  323. Description: "cc_library_shared version script and dynamic list",
  324. Filesystem: map[string]string{
  325. "version_script": "",
  326. "dynamic.list": "",
  327. },
  328. Blueprint: soongCcLibrarySharedPreamble + `
  329. cc_library_shared {
  330. name: "foo_shared",
  331. version_script: "version_script",
  332. dynamic_list: "dynamic.list",
  333. include_build_directory: false,
  334. }`,
  335. ExpectedBazelTargets: []string{
  336. MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
  337. "additional_linker_inputs": `[
  338. "version_script",
  339. "dynamic.list",
  340. ]`,
  341. "linkopts": `[
  342. "-Wl,--version-script,$(location version_script)",
  343. "-Wl,--dynamic-list,$(location dynamic.list)",
  344. ]`,
  345. "features": `["android_cfi_exports_map"]`,
  346. }),
  347. },
  348. })
  349. }
  350. func TestCcLibraryLdflagsSplitBySpaceSoongAdded(t *testing.T) {
  351. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  352. Description: "ldflags are split by spaces except for the ones added by soong (version script and dynamic list)",
  353. Filesystem: map[string]string{
  354. "version_script": "",
  355. "dynamic.list": "",
  356. },
  357. Blueprint: `
  358. cc_library_shared {
  359. name: "foo",
  360. ldflags: [
  361. "--nospace_flag",
  362. "-z spaceflag",
  363. ],
  364. version_script: "version_script",
  365. dynamic_list: "dynamic.list",
  366. include_build_directory: false,
  367. }`,
  368. ExpectedBazelTargets: []string{
  369. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  370. "additional_linker_inputs": `[
  371. "version_script",
  372. "dynamic.list",
  373. ]`,
  374. "linkopts": `[
  375. "--nospace_flag",
  376. "-z",
  377. "spaceflag",
  378. "-Wl,--version-script,$(location version_script)",
  379. "-Wl,--dynamic-list,$(location dynamic.list)",
  380. ]`,
  381. "features": `["android_cfi_exports_map"]`,
  382. }),
  383. },
  384. })
  385. }
  386. func TestCcLibrarySharedNoCrtTrue(t *testing.T) {
  387. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  388. Description: "cc_library_shared - nocrt: true disables feature",
  389. Filesystem: map[string]string{
  390. "impl.cpp": "",
  391. },
  392. Blueprint: soongCcLibraryPreamble + `
  393. cc_library_shared {
  394. name: "foo_shared",
  395. srcs: ["impl.cpp"],
  396. nocrt: true,
  397. include_build_directory: false,
  398. }
  399. `,
  400. ExpectedBazelTargets: []string{
  401. MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
  402. "features": `["-link_crt"]`,
  403. "srcs": `["impl.cpp"]`,
  404. }),
  405. },
  406. })
  407. }
  408. func TestCcLibrarySharedNoCrtFalse(t *testing.T) {
  409. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  410. Description: "cc_library_shared - nocrt: false doesn't disable feature",
  411. Filesystem: map[string]string{
  412. "impl.cpp": "",
  413. },
  414. Blueprint: soongCcLibraryPreamble + `
  415. cc_library_shared {
  416. name: "foo_shared",
  417. srcs: ["impl.cpp"],
  418. nocrt: false,
  419. include_build_directory: false,
  420. }
  421. `,
  422. ExpectedBazelTargets: []string{
  423. MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
  424. "srcs": `["impl.cpp"]`,
  425. }),
  426. },
  427. })
  428. }
  429. func TestCcLibrarySharedNoCrtArchVariant(t *testing.T) {
  430. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  431. Description: "cc_library_shared - nocrt in select",
  432. Filesystem: map[string]string{
  433. "impl.cpp": "",
  434. },
  435. Blueprint: soongCcLibraryPreamble + `
  436. cc_library_shared {
  437. name: "foo_shared",
  438. srcs: ["impl.cpp"],
  439. arch: {
  440. arm: {
  441. nocrt: true,
  442. },
  443. x86: {
  444. nocrt: false,
  445. },
  446. },
  447. include_build_directory: false,
  448. }
  449. `,
  450. ExpectedBazelTargets: []string{
  451. MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
  452. "features": `select({
  453. "//build/bazel/platforms/arch:arm": ["-link_crt"],
  454. "//conditions:default": [],
  455. })`,
  456. "srcs": `["impl.cpp"]`,
  457. }),
  458. },
  459. })
  460. }
  461. func TestCcLibrarySharedProto(t *testing.T) {
  462. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  463. Blueprint: soongCcProtoPreamble + `cc_library_shared {
  464. name: "foo",
  465. srcs: ["foo.proto"],
  466. proto: {
  467. export_proto_headers: true,
  468. },
  469. include_build_directory: false,
  470. }`,
  471. ExpectedBazelTargets: []string{
  472. MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
  473. "srcs": `["foo.proto"]`,
  474. }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{
  475. "deps": `[":foo_proto"]`,
  476. }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  477. "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
  478. "whole_archive_deps": `[":foo_cc_proto_lite"]`,
  479. }),
  480. },
  481. })
  482. }
  483. func TestCcLibrarySharedUseVersionLib(t *testing.T) {
  484. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  485. Filesystem: map[string]string{
  486. soongCcVersionLibBpPath: soongCcVersionLibBp,
  487. },
  488. Blueprint: soongCcProtoPreamble + `cc_library_shared {
  489. name: "foo",
  490. use_version_lib: true,
  491. include_build_directory: false,
  492. }`,
  493. ExpectedBazelTargets: []string{
  494. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  495. "use_version_lib": "True",
  496. "whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
  497. }),
  498. },
  499. })
  500. }
  501. func TestCcLibrarySharedStubs(t *testing.T) {
  502. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  503. Description: "cc_library_shared stubs",
  504. ModuleTypeUnderTest: "cc_library_shared",
  505. ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
  506. Dir: "foo/bar",
  507. Filesystem: map[string]string{
  508. "foo/bar/Android.bp": `
  509. cc_library_shared {
  510. name: "a",
  511. stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
  512. bazel_module: { bp2build_available: true },
  513. include_build_directory: false,
  514. }
  515. `,
  516. },
  517. Blueprint: soongCcLibraryPreamble,
  518. ExpectedBazelTargets: []string{makeCcStubSuiteTargets("a", AttrNameToString{
  519. "soname": `"a.so"`,
  520. "source_library_label": `"//foo/bar:a"`,
  521. "stubs_symbol_file": `"a.map.txt"`,
  522. "stubs_versions": `[
  523. "28",
  524. "29",
  525. "current",
  526. ]`,
  527. }),
  528. MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
  529. "stubs_symbol_file": `"a.map.txt"`,
  530. }),
  531. },
  532. })
  533. }
  534. func TestCcLibrarySharedStubs_UseImplementationInSameApex(t *testing.T) {
  535. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  536. Description: "cc_library_shared stubs",
  537. ModuleTypeUnderTest: "cc_library_shared",
  538. ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
  539. Blueprint: soongCcLibrarySharedPreamble + `
  540. cc_library_shared {
  541. name: "a",
  542. stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
  543. bazel_module: { bp2build_available: false },
  544. include_build_directory: false,
  545. apex_available: ["made_up_apex"],
  546. }
  547. cc_library_shared {
  548. name: "b",
  549. shared_libs: [":a"],
  550. include_build_directory: false,
  551. apex_available: ["made_up_apex"],
  552. }
  553. `,
  554. ExpectedBazelTargets: []string{
  555. MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
  556. "implementation_dynamic_deps": `[":a"]`,
  557. "tags": `["apex_available=made_up_apex"]`,
  558. }),
  559. },
  560. })
  561. }
  562. func TestCcLibrarySharedStubs_UseStubsInDifferentApex(t *testing.T) {
  563. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  564. Description: "cc_library_shared stubs",
  565. ModuleTypeUnderTest: "cc_library_shared",
  566. ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
  567. Blueprint: soongCcLibrarySharedPreamble + `
  568. cc_library_shared {
  569. name: "a",
  570. stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
  571. bazel_module: { bp2build_available: false },
  572. include_build_directory: false,
  573. apex_available: ["apex_a"],
  574. }
  575. cc_library_shared {
  576. name: "b",
  577. shared_libs: [":a"],
  578. include_build_directory: false,
  579. apex_available: ["apex_b"],
  580. }
  581. `,
  582. ExpectedBazelTargets: []string{
  583. MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
  584. "implementation_dynamic_deps": `select({
  585. "//build/bazel/rules/apex:apex_b": ["@api_surfaces//module-libapi/current:a"],
  586. "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
  587. "//conditions:default": [":a"],
  588. })`,
  589. "tags": `["apex_available=apex_b"]`,
  590. }),
  591. },
  592. })
  593. }
  594. // Tests that library in apexfoo links against stubs of platform_lib and otherapex_lib
  595. func TestCcLibrarySharedStubs_UseStubsFromMultipleApiDomains(t *testing.T) {
  596. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  597. Description: "cc_library_shared stubs",
  598. ModuleTypeUnderTest: "cc_library_shared",
  599. ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
  600. Blueprint: soongCcLibrarySharedPreamble + `
  601. cc_library_shared {
  602. name: "libplatform_stable",
  603. stubs: { symbol_file: "libplatform_stable.map.txt", versions: ["28", "29", "current"] },
  604. apex_available: ["//apex_available:platform"],
  605. bazel_module: { bp2build_available: false },
  606. include_build_directory: false,
  607. }
  608. cc_library_shared {
  609. name: "libapexfoo_stable",
  610. stubs: { symbol_file: "libapexfoo_stable.map.txt", versions: ["28", "29", "current"] },
  611. apex_available: ["apexfoo"],
  612. bazel_module: { bp2build_available: false },
  613. include_build_directory: false,
  614. }
  615. cc_library_shared {
  616. name: "libutils",
  617. shared_libs: ["libplatform_stable", "libapexfoo_stable",],
  618. apex_available: ["//apex_available:platform", "apexfoo", "apexbar"],
  619. include_build_directory: false,
  620. }
  621. `,
  622. ExpectedBazelTargets: []string{
  623. MakeBazelTarget("cc_library_shared", "libutils", AttrNameToString{
  624. "implementation_dynamic_deps": `select({
  625. "//build/bazel/rules/apex:apexbar": [
  626. "@api_surfaces//module-libapi/current:libplatform_stable",
  627. "@api_surfaces//module-libapi/current:libapexfoo_stable",
  628. ],
  629. "//build/bazel/rules/apex:apexfoo": [
  630. "@api_surfaces//module-libapi/current:libplatform_stable",
  631. ":libapexfoo_stable",
  632. ],
  633. "//build/bazel/rules/apex:system": [
  634. "@api_surfaces//module-libapi/current:libplatform_stable",
  635. "@api_surfaces//module-libapi/current:libapexfoo_stable",
  636. ],
  637. "//conditions:default": [
  638. ":libplatform_stable",
  639. ":libapexfoo_stable",
  640. ],
  641. })`,
  642. "tags": `[
  643. "apex_available=//apex_available:platform",
  644. "apex_available=apexfoo",
  645. "apex_available=apexbar",
  646. ]`,
  647. }),
  648. },
  649. })
  650. }
  651. func TestCcLibrarySharedStubs_IgnorePlatformAvailable(t *testing.T) {
  652. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  653. Description: "cc_library_shared stubs",
  654. ModuleTypeUnderTest: "cc_library_shared",
  655. ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
  656. Blueprint: soongCcLibrarySharedPreamble + `
  657. cc_library_shared {
  658. name: "a",
  659. stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
  660. bazel_module: { bp2build_available: false },
  661. include_build_directory: false,
  662. apex_available: ["//apex_available:platform", "apex_a"],
  663. }
  664. cc_library_shared {
  665. name: "b",
  666. shared_libs: [":a"],
  667. include_build_directory: false,
  668. apex_available: ["//apex_available:platform", "apex_b"],
  669. }
  670. `,
  671. ExpectedBazelTargets: []string{
  672. MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
  673. "implementation_dynamic_deps": `select({
  674. "//build/bazel/rules/apex:apex_b": ["@api_surfaces//module-libapi/current:a"],
  675. "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
  676. "//conditions:default": [":a"],
  677. })`,
  678. "tags": `[
  679. "apex_available=//apex_available:platform",
  680. "apex_available=apex_b",
  681. ]`,
  682. }),
  683. },
  684. })
  685. }
  686. func TestCcLibraryDoesNotDropStubDepIfNoVariationAcrossAxis(t *testing.T) {
  687. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  688. Description: "cc_library depeends on impl for all configurations",
  689. ModuleTypeUnderTest: "cc_library_shared",
  690. ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
  691. Blueprint: soongCcLibrarySharedPreamble + `
  692. cc_library_shared {
  693. name: "a",
  694. stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
  695. bazel_module: { bp2build_available: false },
  696. apex_available: ["//apex_available:platform"],
  697. }
  698. cc_library_shared {
  699. name: "b",
  700. shared_libs: [":a"],
  701. include_build_directory: false,
  702. apex_available: ["//apex_available:platform"],
  703. }
  704. `,
  705. ExpectedBazelTargets: []string{
  706. MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
  707. "implementation_dynamic_deps": `[":a"]`,
  708. "tags": `["apex_available=//apex_available:platform"]`,
  709. }),
  710. },
  711. })
  712. }
  713. func TestCcLibrarySharedStubs_MultipleApexAvailable(t *testing.T) {
  714. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  715. ModuleTypeUnderTest: "cc_library_shared",
  716. ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
  717. Blueprint: soongCcLibrarySharedPreamble + `
  718. cc_library_shared {
  719. name: "a",
  720. stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
  721. bazel_module: { bp2build_available: false },
  722. include_build_directory: false,
  723. apex_available: ["//apex_available:platform", "apex_a", "apex_b"],
  724. }
  725. cc_library_shared {
  726. name: "b",
  727. shared_libs: [":a"],
  728. include_build_directory: false,
  729. apex_available: ["//apex_available:platform", "apex_b"],
  730. }
  731. cc_library_shared {
  732. name: "c",
  733. shared_libs: [":a"],
  734. include_build_directory: false,
  735. apex_available: ["//apex_available:platform", "apex_a", "apex_b"],
  736. }
  737. `,
  738. ExpectedBazelTargets: []string{
  739. MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
  740. "implementation_dynamic_deps": `select({
  741. "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
  742. "//conditions:default": [":a"],
  743. })`,
  744. "tags": `[
  745. "apex_available=//apex_available:platform",
  746. "apex_available=apex_b",
  747. ]`,
  748. }),
  749. MakeBazelTarget("cc_library_shared", "c", AttrNameToString{
  750. "implementation_dynamic_deps": `[":a"]`,
  751. "tags": `[
  752. "apex_available=//apex_available:platform",
  753. "apex_available=apex_a",
  754. "apex_available=apex_b",
  755. ]`,
  756. }),
  757. },
  758. })
  759. }
  760. func TestCcLibrarySharedSystemSharedLibsSharedEmpty(t *testing.T) {
  761. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  762. Description: "cc_library_shared system_shared_libs empty shared default",
  763. ModuleTypeUnderTest: "cc_library_shared",
  764. ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
  765. Blueprint: soongCcLibrarySharedPreamble + `
  766. cc_defaults {
  767. name: "empty_defaults",
  768. shared: {
  769. system_shared_libs: [],
  770. },
  771. include_build_directory: false,
  772. }
  773. cc_library_shared {
  774. name: "empty",
  775. defaults: ["empty_defaults"],
  776. }
  777. `,
  778. ExpectedBazelTargets: []string{MakeBazelTarget("cc_library_shared", "empty", AttrNameToString{
  779. "system_dynamic_deps": "[]",
  780. })},
  781. })
  782. }
  783. func TestCcLibrarySharedConvertLex(t *testing.T) {
  784. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  785. Description: "cc_library_shared with lex files",
  786. ModuleTypeUnderTest: "cc_library_shared",
  787. ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
  788. Filesystem: map[string]string{
  789. "foo.c": "",
  790. "bar.cc": "",
  791. "foo1.l": "",
  792. "bar1.ll": "",
  793. "foo2.l": "",
  794. "bar2.ll": "",
  795. },
  796. Blueprint: `cc_library_shared {
  797. name: "foo_lib",
  798. srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"],
  799. lex: { flags: ["--foo_flags"] },
  800. include_build_directory: false,
  801. bazel_module: { bp2build_available: true },
  802. }`,
  803. ExpectedBazelTargets: []string{
  804. MakeBazelTarget("genlex", "foo_lib_genlex_l", AttrNameToString{
  805. "srcs": `[
  806. "foo1.l",
  807. "foo2.l",
  808. ]`,
  809. "lexopts": `["--foo_flags"]`,
  810. }),
  811. MakeBazelTarget("genlex", "foo_lib_genlex_ll", AttrNameToString{
  812. "srcs": `[
  813. "bar1.ll",
  814. "bar2.ll",
  815. ]`,
  816. "lexopts": `["--foo_flags"]`,
  817. }),
  818. MakeBazelTarget("cc_library_shared", "foo_lib", AttrNameToString{
  819. "srcs": `[
  820. "bar.cc",
  821. ":foo_lib_genlex_ll",
  822. ]`,
  823. "srcs_c": `[
  824. "foo.c",
  825. ":foo_lib_genlex_l",
  826. ]`,
  827. }),
  828. },
  829. })
  830. }
  831. func TestCcLibrarySharedClangUnknownFlags(t *testing.T) {
  832. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  833. Blueprint: soongCcProtoPreamble + `cc_library_shared {
  834. name: "foo",
  835. conlyflags: ["-a", "-finline-functions"],
  836. cflags: ["-b","-finline-functions"],
  837. cppflags: ["-c", "-finline-functions"],
  838. ldflags: ["-d","-finline-functions", "-e"],
  839. include_build_directory: false,
  840. }`,
  841. ExpectedBazelTargets: []string{
  842. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  843. "conlyflags": `["-a"]`,
  844. "copts": `["-b"]`,
  845. "cppflags": `["-c"]`,
  846. "linkopts": `[
  847. "-d",
  848. "-e",
  849. ]`,
  850. }),
  851. },
  852. })
  853. }
  854. func TestCCLibraryFlagSpaceSplitting(t *testing.T) {
  855. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  856. Blueprint: soongCcProtoPreamble + `cc_library_shared {
  857. name: "foo",
  858. conlyflags: [ "-include header.h"],
  859. cflags: ["-include header.h"],
  860. cppflags: ["-include header.h"],
  861. version_script: "version_script",
  862. include_build_directory: false,
  863. }`,
  864. ExpectedBazelTargets: []string{
  865. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  866. "additional_linker_inputs": `["version_script"]`,
  867. "conlyflags": `[
  868. "-include",
  869. "header.h",
  870. ]`,
  871. "copts": `[
  872. "-include",
  873. "header.h",
  874. ]`,
  875. "cppflags": `[
  876. "-include",
  877. "header.h",
  878. ]`,
  879. "linkopts": `["-Wl,--version-script,$(location version_script)"]`,
  880. "features": `["android_cfi_exports_map"]`,
  881. }),
  882. },
  883. })
  884. }
  885. func TestCCLibrarySharedRuntimeDeps(t *testing.T) {
  886. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  887. Blueprint: `cc_library_shared {
  888. name: "bar",
  889. }
  890. cc_library_shared {
  891. name: "foo",
  892. runtime_libs: ["foo"],
  893. }`,
  894. ExpectedBazelTargets: []string{
  895. MakeBazelTarget("cc_library_shared", "bar", AttrNameToString{
  896. "local_includes": `["."]`,
  897. }),
  898. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  899. "runtime_deps": `[":foo"]`,
  900. "local_includes": `["."]`,
  901. }),
  902. },
  903. })
  904. }
  905. func TestCcLibrarySharedEmptySuffix(t *testing.T) {
  906. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  907. Description: "cc_library_shared with empty suffix",
  908. Filesystem: map[string]string{
  909. "foo.c": "",
  910. },
  911. Blueprint: soongCcLibrarySharedPreamble + `
  912. cc_library_shared {
  913. name: "foo_shared",
  914. suffix: "",
  915. srcs: ["foo.c"],
  916. include_build_directory: false,
  917. }`,
  918. ExpectedBazelTargets: []string{
  919. MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
  920. "srcs_c": `["foo.c"]`,
  921. "suffix": `""`,
  922. }),
  923. },
  924. })
  925. }
  926. func TestCcLibrarySharedSuffix(t *testing.T) {
  927. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  928. Description: "cc_library_shared with suffix",
  929. Filesystem: map[string]string{
  930. "foo.c": "",
  931. },
  932. Blueprint: soongCcLibrarySharedPreamble + `
  933. cc_library_shared {
  934. name: "foo_shared",
  935. suffix: "-suf",
  936. srcs: ["foo.c"],
  937. include_build_directory: false,
  938. }`,
  939. ExpectedBazelTargets: []string{
  940. MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
  941. "srcs_c": `["foo.c"]`,
  942. "suffix": `"-suf"`,
  943. }),
  944. },
  945. })
  946. }
  947. func TestCcLibrarySharedArchVariantSuffix(t *testing.T) {
  948. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  949. Description: "cc_library_shared with arch-variant suffix",
  950. Filesystem: map[string]string{
  951. "foo.c": "",
  952. },
  953. Blueprint: soongCcLibrarySharedPreamble + `
  954. cc_library_shared {
  955. name: "foo_shared",
  956. arch: {
  957. arm64: { suffix: "-64" },
  958. arm: { suffix: "-32" },
  959. },
  960. srcs: ["foo.c"],
  961. include_build_directory: false,
  962. }`,
  963. ExpectedBazelTargets: []string{
  964. MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
  965. "srcs_c": `["foo.c"]`,
  966. "suffix": `select({
  967. "//build/bazel/platforms/arch:arm": "-32",
  968. "//build/bazel/platforms/arch:arm64": "-64",
  969. "//conditions:default": None,
  970. })`,
  971. }),
  972. },
  973. })
  974. }
  975. func TestCcLibrarySharedWithSyspropSrcs(t *testing.T) {
  976. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  977. Description: "cc_library_shared with sysprop sources",
  978. Blueprint: `
  979. cc_library_shared {
  980. name: "foo",
  981. srcs: [
  982. "bar.sysprop",
  983. "baz.sysprop",
  984. "blah.cpp",
  985. ],
  986. min_sdk_version: "5",
  987. }`,
  988. ExpectedBazelTargets: []string{
  989. MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
  990. "srcs": `[
  991. "bar.sysprop",
  992. "baz.sysprop",
  993. ]`,
  994. }),
  995. MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
  996. "dep": `":foo_sysprop_library"`,
  997. "min_sdk_version": `"5"`,
  998. }),
  999. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  1000. "srcs": `["blah.cpp"]`,
  1001. "local_includes": `["."]`,
  1002. "min_sdk_version": `"5"`,
  1003. "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`,
  1004. }),
  1005. },
  1006. })
  1007. }
  1008. func TestCcLibrarySharedWithSyspropSrcsSomeConfigs(t *testing.T) {
  1009. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  1010. Description: "cc_library_shared with sysprop sources in some configs but not others",
  1011. Blueprint: `
  1012. cc_library_shared {
  1013. name: "foo",
  1014. srcs: [
  1015. "blah.cpp",
  1016. ],
  1017. target: {
  1018. android: {
  1019. srcs: ["bar.sysprop"],
  1020. },
  1021. },
  1022. min_sdk_version: "5",
  1023. }`,
  1024. ExpectedBazelTargets: []string{
  1025. MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
  1026. "srcs": `select({
  1027. "//build/bazel/platforms/os:android": ["bar.sysprop"],
  1028. "//conditions:default": [],
  1029. })`,
  1030. }),
  1031. MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
  1032. "dep": `":foo_sysprop_library"`,
  1033. "min_sdk_version": `"5"`,
  1034. }),
  1035. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  1036. "srcs": `["blah.cpp"]`,
  1037. "local_includes": `["."]`,
  1038. "min_sdk_version": `"5"`,
  1039. "whole_archive_deps": `select({
  1040. "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"],
  1041. "//conditions:default": [],
  1042. })`,
  1043. }),
  1044. },
  1045. })
  1046. }
  1047. func TestCcLibrarySharedHeaderAbiChecker(t *testing.T) {
  1048. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  1049. Description: "cc_library_shared with header abi checker",
  1050. Blueprint: `cc_library_shared {
  1051. name: "foo",
  1052. header_abi_checker: {
  1053. enabled: true,
  1054. symbol_file: "a.map.txt",
  1055. exclude_symbol_versions: [
  1056. "29",
  1057. "30",
  1058. ],
  1059. exclude_symbol_tags: [
  1060. "tag1",
  1061. "tag2",
  1062. ],
  1063. check_all_apis: true,
  1064. diff_flags: ["-allow-adding-removing-weak-symbols"],
  1065. },
  1066. include_build_directory: false,
  1067. }`,
  1068. ExpectedBazelTargets: []string{
  1069. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  1070. "abi_checker_enabled": `True`,
  1071. "abi_checker_symbol_file": `"a.map.txt"`,
  1072. "abi_checker_exclude_symbol_versions": `[
  1073. "29",
  1074. "30",
  1075. ]`,
  1076. "abi_checker_exclude_symbol_tags": `[
  1077. "tag1",
  1078. "tag2",
  1079. ]`,
  1080. "abi_checker_check_all_apis": `True`,
  1081. "abi_checker_diff_flags": `["-allow-adding-removing-weak-symbols"]`,
  1082. }),
  1083. },
  1084. })
  1085. }
  1086. func TestCcLibrarySharedWithIntegerOverflowProperty(t *testing.T) {
  1087. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  1088. Description: "cc_library_shared has correct features when integer_overflow property is provided",
  1089. Blueprint: `
  1090. cc_library_shared {
  1091. name: "foo",
  1092. sanitize: {
  1093. integer_overflow: true,
  1094. },
  1095. }
  1096. `,
  1097. ExpectedBazelTargets: []string{
  1098. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  1099. "features": `["ubsan_integer_overflow"]`,
  1100. "local_includes": `["."]`,
  1101. }),
  1102. },
  1103. })
  1104. }
  1105. func TestCcLibrarySharedWithMiscUndefinedProperty(t *testing.T) {
  1106. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  1107. Description: "cc_library_shared has correct features when misc_undefined property is provided",
  1108. Blueprint: `
  1109. cc_library_shared {
  1110. name: "foo",
  1111. sanitize: {
  1112. misc_undefined: ["undefined", "nullability"],
  1113. },
  1114. }
  1115. `,
  1116. ExpectedBazelTargets: []string{
  1117. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  1118. "features": `[
  1119. "ubsan_undefined",
  1120. "ubsan_nullability",
  1121. ]`,
  1122. "local_includes": `["."]`,
  1123. }),
  1124. },
  1125. })
  1126. }
  1127. func TestCcLibrarySharedWithUBSanPropertiesArchSpecific(t *testing.T) {
  1128. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  1129. Description: "cc_library_shared has correct feature select when UBSan props are specified in arch specific blocks",
  1130. Blueprint: `
  1131. cc_library_shared {
  1132. name: "foo",
  1133. sanitize: {
  1134. misc_undefined: ["undefined", "nullability"],
  1135. },
  1136. target: {
  1137. android: {
  1138. sanitize: {
  1139. misc_undefined: ["alignment"],
  1140. },
  1141. },
  1142. linux_glibc: {
  1143. sanitize: {
  1144. integer_overflow: true,
  1145. },
  1146. },
  1147. },
  1148. }
  1149. `,
  1150. ExpectedBazelTargets: []string{
  1151. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  1152. "features": `[
  1153. "ubsan_undefined",
  1154. "ubsan_nullability",
  1155. ] + select({
  1156. "//build/bazel/platforms/os:android": ["ubsan_alignment"],
  1157. "//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"],
  1158. "//conditions:default": [],
  1159. })`,
  1160. "local_includes": `["."]`,
  1161. }),
  1162. },
  1163. })
  1164. }
  1165. func TestCcLibrarySharedWithSanitizerBlocklist(t *testing.T) {
  1166. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  1167. Description: "cc_library_shared has correct features when sanitize.blocklist is provided",
  1168. Blueprint: `
  1169. cc_library_shared {
  1170. name: "foo",
  1171. sanitize: {
  1172. blocklist: "foo_blocklist.txt",
  1173. },
  1174. }
  1175. `,
  1176. ExpectedBazelTargets: []string{
  1177. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  1178. "features": `["ubsan_blocklist_foo_blocklist_txt"]`,
  1179. "local_includes": `["."]`,
  1180. }),
  1181. },
  1182. })
  1183. }
  1184. func TestCcLibrarySharedWithThinLto(t *testing.T) {
  1185. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  1186. Description: "cc_library_shared has correct features when thin lto is enabled",
  1187. Blueprint: `
  1188. cc_library_shared {
  1189. name: "foo",
  1190. lto: {
  1191. thin: true,
  1192. },
  1193. }
  1194. `,
  1195. ExpectedBazelTargets: []string{
  1196. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  1197. "features": `["android_thin_lto"]`,
  1198. "local_includes": `["."]`,
  1199. }),
  1200. },
  1201. })
  1202. }
  1203. func TestCcLibrarySharedWithLtoNever(t *testing.T) {
  1204. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  1205. Description: "cc_library_shared has correct features when thin lto is enabled",
  1206. Blueprint: `
  1207. cc_library_shared {
  1208. name: "foo",
  1209. lto: {
  1210. never: true,
  1211. },
  1212. }
  1213. `,
  1214. ExpectedBazelTargets: []string{
  1215. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  1216. "features": `["-android_thin_lto"]`,
  1217. "local_includes": `["."]`,
  1218. }),
  1219. },
  1220. })
  1221. }
  1222. func TestCcLibrarySharedWithThinLtoArchSpecific(t *testing.T) {
  1223. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  1224. Description: "cc_library_shared has correct features when LTO differs across arch and os variants",
  1225. Blueprint: `
  1226. cc_library_shared {
  1227. name: "foo",
  1228. target: {
  1229. android: {
  1230. lto: {
  1231. thin: true,
  1232. },
  1233. },
  1234. },
  1235. arch: {
  1236. riscv64: {
  1237. lto: {
  1238. thin: false,
  1239. },
  1240. },
  1241. },
  1242. }`,
  1243. ExpectedBazelTargets: []string{
  1244. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  1245. "local_includes": `["."]`,
  1246. "features": `select({
  1247. "//build/bazel/platforms/os_arch:android_arm": ["android_thin_lto"],
  1248. "//build/bazel/platforms/os_arch:android_arm64": ["android_thin_lto"],
  1249. "//build/bazel/platforms/os_arch:android_riscv64": ["-android_thin_lto"],
  1250. "//build/bazel/platforms/os_arch:android_x86": ["android_thin_lto"],
  1251. "//build/bazel/platforms/os_arch:android_x86_64": ["android_thin_lto"],
  1252. "//conditions:default": [],
  1253. })`}),
  1254. },
  1255. })
  1256. }
  1257. func TestCcLibrarySharedWithThinLtoDisabledDefaultEnabledVariant(t *testing.T) {
  1258. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  1259. Description: "cc_library_shared with thin lto disabled by default but enabled on a particular variant",
  1260. Blueprint: `
  1261. cc_library_shared {
  1262. name: "foo",
  1263. lto: {
  1264. never: true,
  1265. },
  1266. target: {
  1267. android: {
  1268. lto: {
  1269. thin: true,
  1270. never: false,
  1271. },
  1272. },
  1273. },
  1274. }`,
  1275. ExpectedBazelTargets: []string{
  1276. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  1277. "local_includes": `["."]`,
  1278. "features": `select({
  1279. "//build/bazel/platforms/os:android": ["android_thin_lto"],
  1280. "//conditions:default": ["-android_thin_lto"],
  1281. })`,
  1282. }),
  1283. },
  1284. })
  1285. }
  1286. func TestCcLibrarySharedWithThinLtoAndWholeProgramVtables(t *testing.T) {
  1287. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  1288. Description: "cc_library_shared has correct features when thin LTO is enabled with whole_program_vtables",
  1289. Blueprint: `
  1290. cc_library_shared {
  1291. name: "foo",
  1292. lto: {
  1293. thin: true,
  1294. },
  1295. whole_program_vtables: true,
  1296. }
  1297. `,
  1298. ExpectedBazelTargets: []string{
  1299. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  1300. "features": `[
  1301. "android_thin_lto",
  1302. "android_thin_lto_whole_program_vtables",
  1303. ]`,
  1304. "local_includes": `["."]`,
  1305. }),
  1306. },
  1307. })
  1308. }
  1309. func TestCcLibrarySharedHiddenVisibilityConvertedToFeature(t *testing.T) {
  1310. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  1311. Description: "cc_library_shared changes hidden visibility flag to feature",
  1312. Blueprint: `
  1313. cc_library_shared{
  1314. name: "foo",
  1315. cflags: ["-fvisibility=hidden"],
  1316. }`,
  1317. ExpectedBazelTargets: []string{
  1318. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  1319. "features": `["visibility_hidden"]`,
  1320. "local_includes": `["."]`,
  1321. }),
  1322. },
  1323. })
  1324. }
  1325. func TestCcLibrarySharedHiddenVisibilityConvertedToFeatureOsSpecific(t *testing.T) {
  1326. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  1327. Description: "cc_library_shared changes hidden visibility flag to feature for specific os",
  1328. Blueprint: `
  1329. cc_library_shared{
  1330. name: "foo",
  1331. target: {
  1332. android: {
  1333. cflags: ["-fvisibility=hidden"],
  1334. },
  1335. },
  1336. }`,
  1337. ExpectedBazelTargets: []string{
  1338. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  1339. "features": `select({
  1340. "//build/bazel/platforms/os:android": ["visibility_hidden"],
  1341. "//conditions:default": [],
  1342. })`,
  1343. "local_includes": `["."]`,
  1344. }),
  1345. },
  1346. })
  1347. }
  1348. func TestCcLibrarySharedStubsDessertVersionConversion(t *testing.T) {
  1349. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  1350. Description: "cc_library_shared converts dessert codename versions to numerical versions",
  1351. Blueprint: `
  1352. cc_library_shared {
  1353. name: "a",
  1354. include_build_directory: false,
  1355. stubs: {
  1356. symbol_file: "a.map.txt",
  1357. versions: [
  1358. "Q",
  1359. "R",
  1360. "31",
  1361. ],
  1362. },
  1363. }
  1364. cc_library_shared {
  1365. name: "b",
  1366. include_build_directory: false,
  1367. stubs: {
  1368. symbol_file: "b.map.txt",
  1369. versions: [
  1370. "Q",
  1371. "R",
  1372. "31",
  1373. "current",
  1374. ],
  1375. },
  1376. }
  1377. `,
  1378. ExpectedBazelTargets: []string{
  1379. makeCcStubSuiteTargets("a", AttrNameToString{
  1380. "soname": `"a.so"`,
  1381. "source_library_label": `"//:a"`,
  1382. "stubs_symbol_file": `"a.map.txt"`,
  1383. "stubs_versions": `[
  1384. "29",
  1385. "30",
  1386. "31",
  1387. "current",
  1388. ]`,
  1389. }),
  1390. MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
  1391. "stubs_symbol_file": `"a.map.txt"`,
  1392. }),
  1393. makeCcStubSuiteTargets("b", AttrNameToString{
  1394. "soname": `"b.so"`,
  1395. "source_library_label": `"//:b"`,
  1396. "stubs_symbol_file": `"b.map.txt"`,
  1397. "stubs_versions": `[
  1398. "29",
  1399. "30",
  1400. "31",
  1401. "current",
  1402. ]`,
  1403. }),
  1404. MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
  1405. "stubs_symbol_file": `"b.map.txt"`,
  1406. }),
  1407. },
  1408. })
  1409. }
  1410. func TestCcLibrarySharedWithCfi(t *testing.T) {
  1411. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  1412. Description: "cc_library_shared has correct features when cfi is enabled for specific variants",
  1413. Blueprint: `
  1414. cc_library_shared {
  1415. name: "foo",
  1416. sanitize: {
  1417. cfi: true,
  1418. },
  1419. }`,
  1420. ExpectedBazelTargets: []string{
  1421. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  1422. "features": `["android_cfi"]`,
  1423. "local_includes": `["."]`,
  1424. }),
  1425. },
  1426. })
  1427. }
  1428. func TestCcLibrarySharedWithCfiOsSpecific(t *testing.T) {
  1429. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  1430. Description: "cc_library_shared has correct features when cfi is enabled",
  1431. Blueprint: `
  1432. cc_library_shared {
  1433. name: "foo",
  1434. target: {
  1435. android: {
  1436. sanitize: {
  1437. cfi: true,
  1438. },
  1439. },
  1440. },
  1441. }`,
  1442. ExpectedBazelTargets: []string{
  1443. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  1444. "features": `select({
  1445. "//build/bazel/platforms/os:android": ["android_cfi"],
  1446. "//conditions:default": [],
  1447. })`,
  1448. "local_includes": `["."]`,
  1449. }),
  1450. },
  1451. })
  1452. }
  1453. func TestCcLibrarySharedWithCfiAndCfiAssemblySupport(t *testing.T) {
  1454. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  1455. Description: "cc_library_shared has correct features when cfi is enabled with cfi assembly support",
  1456. Blueprint: `
  1457. cc_library_static {
  1458. name: "foo",
  1459. sanitize: {
  1460. cfi: true,
  1461. config: {
  1462. cfi_assembly_support: true,
  1463. },
  1464. },
  1465. }`,
  1466. ExpectedBazelTargets: []string{
  1467. MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
  1468. "features": `[
  1469. "android_cfi",
  1470. "android_cfi_assembly_support",
  1471. ]`,
  1472. "local_includes": `["."]`,
  1473. }),
  1474. },
  1475. })
  1476. }
  1477. func TestCcLibrarySharedExplicitlyDisablesCfiWhenFalse(t *testing.T) {
  1478. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  1479. Description: "cc_library_shared disables cfi when explciitly set to false in the bp",
  1480. Blueprint: `
  1481. cc_library_shared {
  1482. name: "foo",
  1483. sanitize: {
  1484. cfi: false,
  1485. },
  1486. }
  1487. `,
  1488. ExpectedBazelTargets: []string{
  1489. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  1490. "features": `["-android_cfi"]`,
  1491. "local_includes": `["."]`,
  1492. }),
  1493. },
  1494. })
  1495. }
  1496. func TestCCLibrarySharedRscriptSrc(t *testing.T) {
  1497. runCcLibrarySharedTestCase(t, Bp2buildTestCase{
  1498. Description: ``,
  1499. Blueprint: `
  1500. cc_library_shared{
  1501. name : "foo",
  1502. srcs : [
  1503. "ccSrc.cc",
  1504. "rsSrc.rscript",
  1505. ],
  1506. include_build_directory: false,
  1507. }
  1508. `,
  1509. ExpectedBazelTargets: []string{
  1510. MakeBazelTarget("rscript_to_cpp", "foo_renderscript", AttrNameToString{
  1511. "srcs": `["rsSrc.rscript"]`,
  1512. }),
  1513. MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
  1514. "absolute_includes": `[
  1515. "frameworks/rs",
  1516. "frameworks/rs/cpp",
  1517. ]`,
  1518. "local_includes": `["."]`,
  1519. "srcs": `[
  1520. "ccSrc.cc",
  1521. "foo_renderscript",
  1522. ]`,
  1523. })}})
  1524. }