blob: b3dd6b1773de3dfbfec3d419fca17e3b7d5e4f92 [file] [log] [blame]
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +00001// 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
15package bp2build
16
17import (
18 "testing"
19
20 "android/soong/android"
21 "android/soong/cc"
22)
23
24const (
25 // See cc/testing.go for more context
26 // TODO(alexmarquez): Split out the preamble into common code?
27 soongCcLibrarySharedPreamble = soongCcLibraryStaticPreamble
28)
29
30func registerCcLibrarySharedModuleTypes(ctx android.RegistrationContext) {
31 cc.RegisterCCBuildComponents(ctx)
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000032 ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
33 ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory)
Liz Kammer12615db2021-09-28 09:19:17 -040034 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
Spandan Das1f65f9e2023-09-15 01:08:23 +000035 ctx.RegisterModuleType("ndk_library", cc.NdkLibraryFactory)
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000036}
37
Sam Delmerico3177a6e2022-06-21 19:28:33 +000038func runCcLibrarySharedTestCase(t *testing.T, tc Bp2buildTestCase) {
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000039 t.Helper()
Alex Márquez Pérez Muñíz Díaz Puras Thaureauxc641cc42023-03-16 17:03:43 +000040 t.Parallel()
Sam Delmerico3177a6e2022-06-21 19:28:33 +000041 (&tc).ModuleTypeUnderTest = "cc_library_shared"
42 (&tc).ModuleTypeUnderTestFactory = cc.LibrarySharedFactory
43 RunBp2BuildTestCase(t, registerCcLibrarySharedModuleTypes, tc)
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000044}
45
46func TestCcLibrarySharedSimple(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000047 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
48 Description: "cc_library_shared simple overall test",
49 Filesystem: map[string]string{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000050 // NOTE: include_dir headers *should not* appear in Bazel hdrs later (?)
51 "include_dir_1/include_dir_1_a.h": "",
52 "include_dir_1/include_dir_1_b.h": "",
53 "include_dir_2/include_dir_2_a.h": "",
54 "include_dir_2/include_dir_2_b.h": "",
55 // NOTE: local_include_dir headers *should not* appear in Bazel hdrs later (?)
56 "local_include_dir_1/local_include_dir_1_a.h": "",
57 "local_include_dir_1/local_include_dir_1_b.h": "",
58 "local_include_dir_2/local_include_dir_2_a.h": "",
59 "local_include_dir_2/local_include_dir_2_b.h": "",
60 // NOTE: export_include_dir headers *should* appear in Bazel hdrs later
61 "export_include_dir_1/export_include_dir_1_a.h": "",
62 "export_include_dir_1/export_include_dir_1_b.h": "",
63 "export_include_dir_2/export_include_dir_2_a.h": "",
64 "export_include_dir_2/export_include_dir_2_b.h": "",
65 // NOTE: Soong implicitly includes headers in the current directory
66 "implicit_include_1.h": "",
67 "implicit_include_2.h": "",
68 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +000069 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000070cc_library_headers {
71 name: "header_lib_1",
72 export_include_dirs: ["header_lib_1"],
73 bazel_module: { bp2build_available: false },
74}
75
76cc_library_headers {
77 name: "header_lib_2",
78 export_include_dirs: ["header_lib_2"],
79 bazel_module: { bp2build_available: false },
80}
81
82cc_library_shared {
83 name: "shared_lib_1",
84 srcs: ["shared_lib_1.cc"],
85 bazel_module: { bp2build_available: false },
86}
87
88cc_library_shared {
89 name: "shared_lib_2",
90 srcs: ["shared_lib_2.cc"],
91 bazel_module: { bp2build_available: false },
92}
93
94cc_library_static {
95 name: "whole_static_lib_1",
96 srcs: ["whole_static_lib_1.cc"],
97 bazel_module: { bp2build_available: false },
98}
99
100cc_library_static {
101 name: "whole_static_lib_2",
102 srcs: ["whole_static_lib_2.cc"],
103 bazel_module: { bp2build_available: false },
104}
105
106cc_library_shared {
107 name: "foo_shared",
108 srcs: [
109 "foo_shared1.cc",
110 "foo_shared2.cc",
111 ],
112 cflags: [
113 "-Dflag1",
114 "-Dflag2"
115 ],
116 shared_libs: [
117 "shared_lib_1",
118 "shared_lib_2"
119 ],
120 whole_static_libs: [
121 "whole_static_lib_1",
122 "whole_static_lib_2"
123 ],
124 include_dirs: [
125 "include_dir_1",
126 "include_dir_2",
127 ],
128 local_include_dirs: [
129 "local_include_dir_1",
130 "local_include_dir_2",
131 ],
132 export_include_dirs: [
133 "export_include_dir_1",
134 "export_include_dir_2"
135 ],
136 header_libs: [
137 "header_lib_1",
138 "header_lib_2"
139 ],
Yu Liufc603162022-03-01 15:44:08 -0800140 sdk_version: "current",
141 min_sdk_version: "29",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000142
143 // TODO: Also support export_header_lib_headers
144}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000145 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000146 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500147 "absolute_includes": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000148 "include_dir_1",
149 "include_dir_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500150 ]`,
151 "copts": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000152 "-Dflag1",
153 "-Dflag2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500154 ]`,
155 "export_includes": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000156 "export_include_dir_1",
157 "export_include_dir_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500158 ]`,
159 "implementation_deps": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000160 ":header_lib_1",
161 ":header_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500162 ]`,
163 "implementation_dynamic_deps": `[
Liz Kammer7a210ac2021-09-22 15:52:58 -0400164 ":shared_lib_1",
165 ":shared_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500166 ]`,
167 "local_includes": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000168 "local_include_dir_1",
169 "local_include_dir_2",
170 ".",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500171 ]`,
172 "srcs": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000173 "foo_shared1.cc",
174 "foo_shared2.cc",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500175 ]`,
176 "whole_archive_deps": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000177 ":whole_static_lib_1",
178 ":whole_static_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500179 ]`,
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000180 "sdk_version": `"current"`,
181 "min_sdk_version": `"29"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500182 }),
183 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000184 })
185}
186
187func TestCcLibrarySharedArchSpecificSharedLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000188 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
189 Description: "cc_library_shared arch-specific shared_libs with whole_static_libs",
190 Filesystem: map[string]string{},
191 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000192cc_library_static {
193 name: "static_dep",
194 bazel_module: { bp2build_available: false },
195}
196cc_library_shared {
197 name: "shared_dep",
198 bazel_module: { bp2build_available: false },
199}
200cc_library_shared {
201 name: "foo_shared",
202 arch: { arm64: { shared_libs: ["shared_dep"], whole_static_libs: ["static_dep"] } },
203 include_build_directory: false,
204}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000205 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000206 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500207 "implementation_dynamic_deps": `select({
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000208 "//build/bazel/platforms/arch:arm64": [":shared_dep"],
209 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500210 })`,
211 "whole_archive_deps": `select({
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000212 "//build/bazel/platforms/arch:arm64": [":static_dep"],
213 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500214 })`,
215 }),
216 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000217 })
218}
219
220func TestCcLibrarySharedOsSpecificSharedLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000221 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Chris Parsons5011e612023-09-13 23:33:20 +0000222 StubbedBuildDefinitions: []string{"shared_dep"},
223 Description: "cc_library_shared os-specific shared_libs",
224 Filesystem: map[string]string{},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000225 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000226cc_library_shared {
227 name: "shared_dep",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000228}
229cc_library_shared {
230 name: "foo_shared",
231 target: { android: { shared_libs: ["shared_dep"], } },
232 include_build_directory: false,
233}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000234 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000235 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500236 "implementation_dynamic_deps": `select({
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000237 "//build/bazel/platforms/os:android": [":shared_dep"],
238 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500239 })`,
240 }),
241 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000242 })
243}
244
245func TestCcLibrarySharedBaseArchOsSpecificSharedLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000246 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Chris Parsons5011e612023-09-13 23:33:20 +0000247 StubbedBuildDefinitions: []string{"shared_dep", "shared_dep2", "shared_dep3"},
248 Description: "cc_library_shared base, arch, and os-specific shared_libs",
249 Filesystem: map[string]string{},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000250 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000251cc_library_shared {
252 name: "shared_dep",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000253}
254cc_library_shared {
255 name: "shared_dep2",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000256}
257cc_library_shared {
258 name: "shared_dep3",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000259}
260cc_library_shared {
261 name: "foo_shared",
262 shared_libs: ["shared_dep"],
263 target: { android: { shared_libs: ["shared_dep2"] } },
264 arch: { arm64: { shared_libs: ["shared_dep3"] } },
265 include_build_directory: false,
266}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000267 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000268 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500269 "implementation_dynamic_deps": `[":shared_dep"] + select({
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000270 "//build/bazel/platforms/arch:arm64": [":shared_dep3"],
271 "//conditions:default": [],
272 }) + select({
273 "//build/bazel/platforms/os:android": [":shared_dep2"],
274 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500275 })`,
276 }),
277 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000278 })
279}
280
281func TestCcLibrarySharedSimpleExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000282 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
283 Description: "cc_library_shared simple exclude_srcs",
284 Filesystem: map[string]string{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000285 "common.c": "",
286 "foo-a.c": "",
287 "foo-excluded.c": "",
288 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000289 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000290cc_library_shared {
291 name: "foo_shared",
292 srcs: ["common.c", "foo-*.c"],
293 exclude_srcs: ["foo-excluded.c"],
294 include_build_directory: false,
295}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000296 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000297 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500298 "srcs_c": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000299 "common.c",
300 "foo-a.c",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500301 ]`,
302 }),
303 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000304 })
305}
306
307func TestCcLibrarySharedStrip(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000308 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
309 Description: "cc_library_shared stripping",
310 Filesystem: map[string]string{},
311 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000312cc_library_shared {
313 name: "foo_shared",
314 strip: {
315 keep_symbols: false,
316 keep_symbols_and_debug_frame: true,
317 keep_symbols_list: ["sym", "sym2"],
318 all: true,
319 none: false,
320 },
321 include_build_directory: false,
322}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000323 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000324 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500325 "strip": `{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000326 "all": True,
327 "keep_symbols": False,
328 "keep_symbols_and_debug_frame": True,
329 "keep_symbols_list": [
330 "sym",
331 "sym2",
332 ],
333 "none": False,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500334 }`,
335 }),
336 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000337 })
338}
339
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +0000340func TestCcLibrarySharedVersionScriptAndDynamicList(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000341 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +0000342 Description: "cc_library_shared version script and dynamic list",
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000343 Filesystem: map[string]string{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000344 "version_script": "",
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +0000345 "dynamic.list": "",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000346 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000347 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000348cc_library_shared {
349 name: "foo_shared",
350 version_script: "version_script",
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +0000351 dynamic_list: "dynamic.list",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000352 include_build_directory: false,
353}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000354 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000355 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +0000356 "additional_linker_inputs": `[
357 "version_script",
358 "dynamic.list",
359 ]`,
360 "linkopts": `[
361 "-Wl,--version-script,$(location version_script)",
362 "-Wl,--dynamic-list,$(location dynamic.list)",
363 ]`,
Trevor Radcliffef06dd912023-05-19 14:51:41 +0000364 "features": `["android_cfi_exports_map"]`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500365 }),
366 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000367 })
368}
Jingwen Chen6ada5892021-09-17 11:38:09 +0000369
Trevor Radcliffeea6a45d2022-09-20 18:58:01 +0000370func TestCcLibraryLdflagsSplitBySpaceSoongAdded(t *testing.T) {
371 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
372 Description: "ldflags are split by spaces except for the ones added by soong (version script and dynamic list)",
373 Filesystem: map[string]string{
374 "version_script": "",
375 "dynamic.list": "",
376 },
377 Blueprint: `
378cc_library_shared {
379 name: "foo",
380 ldflags: [
381 "--nospace_flag",
382 "-z spaceflag",
383 ],
384 version_script: "version_script",
385 dynamic_list: "dynamic.list",
386 include_build_directory: false,
387}`,
388 ExpectedBazelTargets: []string{
389 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
390 "additional_linker_inputs": `[
391 "version_script",
392 "dynamic.list",
393 ]`,
394 "linkopts": `[
395 "--nospace_flag",
396 "-z",
397 "spaceflag",
398 "-Wl,--version-script,$(location version_script)",
399 "-Wl,--dynamic-list,$(location dynamic.list)",
400 ]`,
Trevor Radcliffef06dd912023-05-19 14:51:41 +0000401 "features": `["android_cfi_exports_map"]`,
Trevor Radcliffeea6a45d2022-09-20 18:58:01 +0000402 }),
403 },
404 })
405}
406
Jingwen Chen6ada5892021-09-17 11:38:09 +0000407func TestCcLibrarySharedNoCrtTrue(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000408 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux01ec55e2023-01-30 22:53:04 +0000409 Description: "cc_library_shared - nocrt: true disables feature",
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000410 Filesystem: map[string]string{
Jingwen Chen6ada5892021-09-17 11:38:09 +0000411 "impl.cpp": "",
412 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000413 Blueprint: soongCcLibraryPreamble + `
Jingwen Chen6ada5892021-09-17 11:38:09 +0000414cc_library_shared {
415 name: "foo_shared",
416 srcs: ["impl.cpp"],
417 nocrt: true,
418 include_build_directory: false,
419}
420`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000421 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000422 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux01ec55e2023-01-30 22:53:04 +0000423 "features": `["-link_crt"]`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500424 "srcs": `["impl.cpp"]`,
425 }),
426 },
427 })
Jingwen Chen6ada5892021-09-17 11:38:09 +0000428}
429
430func TestCcLibrarySharedNoCrtFalse(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000431 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux01ec55e2023-01-30 22:53:04 +0000432 Description: "cc_library_shared - nocrt: false doesn't disable feature",
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000433 Filesystem: map[string]string{
Jingwen Chen6ada5892021-09-17 11:38:09 +0000434 "impl.cpp": "",
435 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000436 Blueprint: soongCcLibraryPreamble + `
Jingwen Chen6ada5892021-09-17 11:38:09 +0000437cc_library_shared {
438 name: "foo_shared",
439 srcs: ["impl.cpp"],
440 nocrt: false,
441 include_build_directory: false,
442}
443`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000444 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000445 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500446 "srcs": `["impl.cpp"]`,
447 }),
448 },
449 })
Jingwen Chen6ada5892021-09-17 11:38:09 +0000450}
451
452func TestCcLibrarySharedNoCrtArchVariant(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000453 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
454 Description: "cc_library_shared - nocrt in select",
455 Filesystem: map[string]string{
Jingwen Chen6ada5892021-09-17 11:38:09 +0000456 "impl.cpp": "",
457 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000458 Blueprint: soongCcLibraryPreamble + `
Jingwen Chen6ada5892021-09-17 11:38:09 +0000459cc_library_shared {
460 name: "foo_shared",
461 srcs: ["impl.cpp"],
462 arch: {
463 arm: {
464 nocrt: true,
465 },
466 x86: {
467 nocrt: false,
468 },
469 },
470 include_build_directory: false,
471}
472`,
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux01ec55e2023-01-30 22:53:04 +0000473 ExpectedBazelTargets: []string{
474 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
475 "features": `select({
476 "//build/bazel/platforms/arch:arm": ["-link_crt"],
477 "//conditions:default": [],
478 })`,
479 "srcs": `["impl.cpp"]`,
480 }),
481 },
Jingwen Chen6ada5892021-09-17 11:38:09 +0000482 })
483}
Liz Kammer12615db2021-09-28 09:19:17 -0400484
485func TestCcLibrarySharedProto(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000486 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
487 Blueprint: soongCcProtoPreamble + `cc_library_shared {
Liz Kammer12615db2021-09-28 09:19:17 -0400488 name: "foo",
489 srcs: ["foo.proto"],
490 proto: {
Liz Kammer12615db2021-09-28 09:19:17 -0400491 export_proto_headers: true,
492 },
493 include_build_directory: false,
494}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000495 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000496 MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -0400497 "srcs": `["foo.proto"]`,
Alixe06d75b2022-08-31 18:28:19 +0000498 }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -0400499 "deps": `[":foo_proto"]`,
Alixe06d75b2022-08-31 18:28:19 +0000500 }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -0400501 "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
502 "whole_archive_deps": `[":foo_cc_proto_lite"]`,
503 }),
504 },
505 })
506}
Rupert Shuttleworth484aa252021-12-10 07:22:53 -0500507
508func TestCcLibrarySharedUseVersionLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000509 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Liz Kammerbaced712022-09-16 09:01:29 -0400510 Filesystem: map[string]string{
511 soongCcVersionLibBpPath: soongCcVersionLibBp,
512 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000513 Blueprint: soongCcProtoPreamble + `cc_library_shared {
Rupert Shuttleworth484aa252021-12-10 07:22:53 -0500514 name: "foo",
515 use_version_lib: true,
516 include_build_directory: false,
517}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000518 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000519 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Yu Liufe978fd2023-04-24 16:37:18 -0700520 "use_version_lib": "True",
521 "whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
Rupert Shuttleworth484aa252021-12-10 07:22:53 -0500522 }),
523 },
524 })
525}
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000526
527func TestCcLibrarySharedStubs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000528 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
529 Description: "cc_library_shared stubs",
530 ModuleTypeUnderTest: "cc_library_shared",
531 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
532 Dir: "foo/bar",
533 Filesystem: map[string]string{
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000534 "foo/bar/Android.bp": `
535cc_library_shared {
536 name: "a",
537 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
538 bazel_module: { bp2build_available: true },
539 include_build_directory: false,
540}
541`,
542 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000543 Blueprint: soongCcLibraryPreamble,
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000544 ExpectedBazelTargets: []string{makeCcStubSuiteTargets("a", AttrNameToString{
Spandan Das04f9f4c2023-09-13 23:59:05 +0000545 "api_surface": `"module-libapi"`,
Sam Delmerico5f906492023-03-15 18:06:18 -0400546 "soname": `"a.so"`,
547 "source_library_label": `"//foo/bar:a"`,
548 "stubs_symbol_file": `"a.map.txt"`,
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000549 "stubs_versions": `[
Trevor Radcliffe087af542022-09-16 15:36:10 +0000550 "28",
551 "29",
552 "current",
553 ]`,
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000554 }),
555 MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
Yu Liu56ccb1a2022-11-12 10:47:07 -0800556 "stubs_symbol_file": `"a.map.txt"`,
Trevor Radcliffe087af542022-09-16 15:36:10 +0000557 }),
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000558 },
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000559 })
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000560}
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000561
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400562func TestCcLibrarySharedStubs_UseImplementationInSameApex(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 + `
568cc_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: ["made_up_apex"],
574}
575cc_library_shared {
576 name: "b",
577 shared_libs: [":a"],
578 include_build_directory: false,
579 apex_available: ["made_up_apex"],
580}
581`,
582 ExpectedBazelTargets: []string{
583 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
584 "implementation_dynamic_deps": `[":a"]`,
585 "tags": `["apex_available=made_up_apex"]`,
586 }),
587 },
588 })
589}
590
591func TestCcLibrarySharedStubs_UseStubsInDifferentApex(t *testing.T) {
592 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
593 Description: "cc_library_shared stubs",
594 ModuleTypeUnderTest: "cc_library_shared",
595 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
596 Blueprint: soongCcLibrarySharedPreamble + `
597cc_library_shared {
598 name: "a",
599 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
600 bazel_module: { bp2build_available: false },
601 include_build_directory: false,
602 apex_available: ["apex_a"],
603}
604cc_library_shared {
605 name: "b",
606 shared_libs: [":a"],
607 include_build_directory: false,
608 apex_available: ["apex_b"],
609}
610`,
611 ExpectedBazelTargets: []string{
612 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
613 "implementation_dynamic_deps": `select({
Spandan Das6d4d9da2023-04-18 06:20:40 +0000614 "//build/bazel/rules/apex:apex_b": ["@api_surfaces//module-libapi/current:a"],
615 "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400616 "//conditions:default": [":a"],
617 })`,
618 "tags": `["apex_available=apex_b"]`,
619 }),
620 },
621 })
622}
623
Spandan Das6d4d9da2023-04-18 06:20:40 +0000624// Tests that library in apexfoo links against stubs of platform_lib and otherapex_lib
625func TestCcLibrarySharedStubs_UseStubsFromMultipleApiDomains(t *testing.T) {
626 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
627 Description: "cc_library_shared stubs",
628 ModuleTypeUnderTest: "cc_library_shared",
629 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
630 Blueprint: soongCcLibrarySharedPreamble + `
631cc_library_shared {
632 name: "libplatform_stable",
633 stubs: { symbol_file: "libplatform_stable.map.txt", versions: ["28", "29", "current"] },
634 apex_available: ["//apex_available:platform"],
635 bazel_module: { bp2build_available: false },
636 include_build_directory: false,
637}
638cc_library_shared {
639 name: "libapexfoo_stable",
640 stubs: { symbol_file: "libapexfoo_stable.map.txt", versions: ["28", "29", "current"] },
641 apex_available: ["apexfoo"],
642 bazel_module: { bp2build_available: false },
643 include_build_directory: false,
644}
645cc_library_shared {
646 name: "libutils",
647 shared_libs: ["libplatform_stable", "libapexfoo_stable",],
648 apex_available: ["//apex_available:platform", "apexfoo", "apexbar"],
649 include_build_directory: false,
650}
651`,
652 ExpectedBazelTargets: []string{
653 MakeBazelTarget("cc_library_shared", "libutils", AttrNameToString{
654 "implementation_dynamic_deps": `select({
655 "//build/bazel/rules/apex:apexbar": [
656 "@api_surfaces//module-libapi/current:libplatform_stable",
657 "@api_surfaces//module-libapi/current:libapexfoo_stable",
658 ],
659 "//build/bazel/rules/apex:apexfoo": [
660 "@api_surfaces//module-libapi/current:libplatform_stable",
661 ":libapexfoo_stable",
662 ],
663 "//build/bazel/rules/apex:system": [
Spandan Dasf7bae9a2023-09-06 22:07:15 +0000664 ":libplatform_stable",
Spandan Das6d4d9da2023-04-18 06:20:40 +0000665 "@api_surfaces//module-libapi/current:libapexfoo_stable",
666 ],
667 "//conditions:default": [
668 ":libplatform_stable",
669 ":libapexfoo_stable",
670 ],
671 })`,
672 "tags": `[
673 "apex_available=//apex_available:platform",
674 "apex_available=apexfoo",
675 "apex_available=apexbar",
676 ]`,
677 }),
678 },
679 })
680}
681
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400682func TestCcLibrarySharedStubs_IgnorePlatformAvailable(t *testing.T) {
683 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
684 Description: "cc_library_shared stubs",
685 ModuleTypeUnderTest: "cc_library_shared",
686 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
687 Blueprint: soongCcLibrarySharedPreamble + `
688cc_library_shared {
689 name: "a",
690 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
691 bazel_module: { bp2build_available: false },
692 include_build_directory: false,
693 apex_available: ["//apex_available:platform", "apex_a"],
694}
695cc_library_shared {
696 name: "b",
697 shared_libs: [":a"],
698 include_build_directory: false,
699 apex_available: ["//apex_available:platform", "apex_b"],
700}
701`,
702 ExpectedBazelTargets: []string{
703 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
704 "implementation_dynamic_deps": `select({
Spandan Das6d4d9da2023-04-18 06:20:40 +0000705 "//build/bazel/rules/apex:apex_b": ["@api_surfaces//module-libapi/current:a"],
706 "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400707 "//conditions:default": [":a"],
708 })`,
709 "tags": `[
710 "apex_available=//apex_available:platform",
711 "apex_available=apex_b",
712 ]`,
713 }),
714 },
715 })
716}
717
Spandan Das6d4d9da2023-04-18 06:20:40 +0000718func TestCcLibraryDoesNotDropStubDepIfNoVariationAcrossAxis(t *testing.T) {
719 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
720 Description: "cc_library depeends on impl for all configurations",
721 ModuleTypeUnderTest: "cc_library_shared",
722 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
723 Blueprint: soongCcLibrarySharedPreamble + `
724cc_library_shared {
725 name: "a",
726 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
727 bazel_module: { bp2build_available: false },
728 apex_available: ["//apex_available:platform"],
729}
730cc_library_shared {
731 name: "b",
732 shared_libs: [":a"],
733 include_build_directory: false,
734 apex_available: ["//apex_available:platform"],
735}
736`,
737 ExpectedBazelTargets: []string{
738 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
739 "implementation_dynamic_deps": `[":a"]`,
740 "tags": `["apex_available=//apex_available:platform"]`,
741 }),
742 },
743 })
744}
745
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400746func TestCcLibrarySharedStubs_MultipleApexAvailable(t *testing.T) {
747 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
748 ModuleTypeUnderTest: "cc_library_shared",
749 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
750 Blueprint: soongCcLibrarySharedPreamble + `
751cc_library_shared {
752 name: "a",
753 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
754 bazel_module: { bp2build_available: false },
755 include_build_directory: false,
756 apex_available: ["//apex_available:platform", "apex_a", "apex_b"],
757}
758cc_library_shared {
759 name: "b",
760 shared_libs: [":a"],
761 include_build_directory: false,
762 apex_available: ["//apex_available:platform", "apex_b"],
763}
764
765cc_library_shared {
766 name: "c",
767 shared_libs: [":a"],
768 include_build_directory: false,
769 apex_available: ["//apex_available:platform", "apex_a", "apex_b"],
770}
771`,
772 ExpectedBazelTargets: []string{
773 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
774 "implementation_dynamic_deps": `select({
Spandan Das6d4d9da2023-04-18 06:20:40 +0000775 "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400776 "//conditions:default": [":a"],
777 })`,
778 "tags": `[
779 "apex_available=//apex_available:platform",
780 "apex_available=apex_b",
781 ]`,
782 }),
783 MakeBazelTarget("cc_library_shared", "c", AttrNameToString{
784 "implementation_dynamic_deps": `[":a"]`,
785 "tags": `[
786 "apex_available=//apex_available:platform",
787 "apex_available=apex_a",
788 "apex_available=apex_b",
789 ]`,
790 }),
791 },
792 })
793}
794
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000795func TestCcLibrarySharedSystemSharedLibsSharedEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000796 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
797 Description: "cc_library_shared system_shared_libs empty shared default",
798 ModuleTypeUnderTest: "cc_library_shared",
799 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
800 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000801cc_defaults {
802 name: "empty_defaults",
803 shared: {
804 system_shared_libs: [],
805 },
806 include_build_directory: false,
807}
808cc_library_shared {
809 name: "empty",
810 defaults: ["empty_defaults"],
811}
812`,
Alixe06d75b2022-08-31 18:28:19 +0000813 ExpectedBazelTargets: []string{MakeBazelTarget("cc_library_shared", "empty", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000814 "system_dynamic_deps": "[]",
815 })},
816 })
817}
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000818
819func TestCcLibrarySharedConvertLex(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000820 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
821 Description: "cc_library_shared with lex files",
822 ModuleTypeUnderTest: "cc_library_shared",
823 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
824 Filesystem: map[string]string{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000825 "foo.c": "",
826 "bar.cc": "",
827 "foo1.l": "",
828 "bar1.ll": "",
829 "foo2.l": "",
830 "bar2.ll": "",
831 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000832 Blueprint: `cc_library_shared {
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000833 name: "foo_lib",
834 srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"],
835 lex: { flags: ["--foo_flags"] },
836 include_build_directory: false,
837 bazel_module: { bp2build_available: true },
838}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000839 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000840 MakeBazelTarget("genlex", "foo_lib_genlex_l", AttrNameToString{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000841 "srcs": `[
842 "foo1.l",
843 "foo2.l",
844 ]`,
845 "lexopts": `["--foo_flags"]`,
846 }),
Alixe06d75b2022-08-31 18:28:19 +0000847 MakeBazelTarget("genlex", "foo_lib_genlex_ll", AttrNameToString{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000848 "srcs": `[
849 "bar1.ll",
850 "bar2.ll",
851 ]`,
852 "lexopts": `["--foo_flags"]`,
853 }),
Alixe06d75b2022-08-31 18:28:19 +0000854 MakeBazelTarget("cc_library_shared", "foo_lib", AttrNameToString{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000855 "srcs": `[
856 "bar.cc",
857 ":foo_lib_genlex_ll",
858 ]`,
859 "srcs_c": `[
860 "foo.c",
861 ":foo_lib_genlex_l",
862 ]`,
863 }),
864 },
865 })
866}
Alix1be00d42022-05-16 22:56:04 +0000867
868func TestCcLibrarySharedClangUnknownFlags(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000869 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
870 Blueprint: soongCcProtoPreamble + `cc_library_shared {
Alix1be00d42022-05-16 22:56:04 +0000871 name: "foo",
872 conlyflags: ["-a", "-finline-functions"],
873 cflags: ["-b","-finline-functions"],
874 cppflags: ["-c", "-finline-functions"],
875 ldflags: ["-d","-finline-functions", "-e"],
876 include_build_directory: false,
877}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000878 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000879 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Alix1be00d42022-05-16 22:56:04 +0000880 "conlyflags": `["-a"]`,
881 "copts": `["-b"]`,
882 "cppflags": `["-c"]`,
883 "linkopts": `[
884 "-d",
885 "-e",
886 ]`,
887 }),
888 },
889 })
890}
891
892func TestCCLibraryFlagSpaceSplitting(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000893 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
894 Blueprint: soongCcProtoPreamble + `cc_library_shared {
Alix1be00d42022-05-16 22:56:04 +0000895 name: "foo",
896 conlyflags: [ "-include header.h"],
897 cflags: ["-include header.h"],
898 cppflags: ["-include header.h"],
899 version_script: "version_script",
900 include_build_directory: false,
901}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000902 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000903 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Alix1be00d42022-05-16 22:56:04 +0000904 "additional_linker_inputs": `["version_script"]`,
905 "conlyflags": `[
906 "-include",
907 "header.h",
908 ]`,
909 "copts": `[
910 "-include",
911 "header.h",
912 ]`,
913 "cppflags": `[
914 "-include",
915 "header.h",
916 ]`,
917 "linkopts": `["-Wl,--version-script,$(location version_script)"]`,
Trevor Radcliffef06dd912023-05-19 14:51:41 +0000918 "features": `["android_cfi_exports_map"]`,
Alix1be00d42022-05-16 22:56:04 +0000919 }),
920 },
921 })
922}
Cole Faust6b29f592022-08-09 09:50:56 -0700923
924func TestCCLibrarySharedRuntimeDeps(t *testing.T) {
925 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
926 Blueprint: `cc_library_shared {
927 name: "bar",
928}
929
930cc_library_shared {
931 name: "foo",
932 runtime_libs: ["foo"],
933}`,
934 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000935 MakeBazelTarget("cc_library_shared", "bar", AttrNameToString{
Cole Faust6b29f592022-08-09 09:50:56 -0700936 "local_includes": `["."]`,
937 }),
Alixe06d75b2022-08-31 18:28:19 +0000938 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Cole Faust6b29f592022-08-09 09:50:56 -0700939 "runtime_deps": `[":foo"]`,
940 "local_includes": `["."]`,
941 }),
942 },
943 })
944}
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -0500945
946func TestCcLibrarySharedEmptySuffix(t *testing.T) {
947 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
948 Description: "cc_library_shared with empty suffix",
949 Filesystem: map[string]string{
950 "foo.c": "",
951 },
952 Blueprint: soongCcLibrarySharedPreamble + `
953cc_library_shared {
954 name: "foo_shared",
955 suffix: "",
956 srcs: ["foo.c"],
957 include_build_directory: false,
958}`,
959 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000960 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -0500961 "srcs_c": `["foo.c"]`,
962 "suffix": `""`,
963 }),
964 },
965 })
966}
967
968func TestCcLibrarySharedSuffix(t *testing.T) {
969 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
970 Description: "cc_library_shared with suffix",
971 Filesystem: map[string]string{
972 "foo.c": "",
973 },
974 Blueprint: soongCcLibrarySharedPreamble + `
975cc_library_shared {
976 name: "foo_shared",
977 suffix: "-suf",
978 srcs: ["foo.c"],
979 include_build_directory: false,
980}`,
981 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000982 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -0500983 "srcs_c": `["foo.c"]`,
984 "suffix": `"-suf"`,
985 }),
986 },
987 })
988}
989
990func TestCcLibrarySharedArchVariantSuffix(t *testing.T) {
991 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
992 Description: "cc_library_shared with arch-variant suffix",
993 Filesystem: map[string]string{
994 "foo.c": "",
995 },
996 Blueprint: soongCcLibrarySharedPreamble + `
997cc_library_shared {
998 name: "foo_shared",
999 arch: {
1000 arm64: { suffix: "-64" },
1001 arm: { suffix: "-32" },
1002 },
1003 srcs: ["foo.c"],
1004 include_build_directory: false,
1005}`,
1006 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001007 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -05001008 "srcs_c": `["foo.c"]`,
1009 "suffix": `select({
1010 "//build/bazel/platforms/arch:arm": "-32",
1011 "//build/bazel/platforms/arch:arm64": "-64",
1012 "//conditions:default": None,
1013 })`,
1014 }),
1015 },
1016 })
1017}
Trevor Radcliffecee4e052022-09-06 19:31:25 +00001018
1019func TestCcLibrarySharedWithSyspropSrcs(t *testing.T) {
1020 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1021 Description: "cc_library_shared with sysprop sources",
1022 Blueprint: `
1023cc_library_shared {
1024 name: "foo",
1025 srcs: [
1026 "bar.sysprop",
1027 "baz.sysprop",
1028 "blah.cpp",
1029 ],
1030 min_sdk_version: "5",
1031}`,
1032 ExpectedBazelTargets: []string{
1033 MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
1034 "srcs": `[
1035 "bar.sysprop",
1036 "baz.sysprop",
1037 ]`,
1038 }),
1039 MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
1040 "dep": `":foo_sysprop_library"`,
1041 "min_sdk_version": `"5"`,
1042 }),
1043 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1044 "srcs": `["blah.cpp"]`,
1045 "local_includes": `["."]`,
1046 "min_sdk_version": `"5"`,
1047 "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`,
1048 }),
1049 },
1050 })
1051}
1052
1053func TestCcLibrarySharedWithSyspropSrcsSomeConfigs(t *testing.T) {
1054 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1055 Description: "cc_library_shared with sysprop sources in some configs but not others",
1056 Blueprint: `
1057cc_library_shared {
1058 name: "foo",
1059 srcs: [
1060 "blah.cpp",
1061 ],
1062 target: {
1063 android: {
1064 srcs: ["bar.sysprop"],
1065 },
1066 },
1067 min_sdk_version: "5",
1068}`,
1069 ExpectedBazelTargets: []string{
1070 MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
1071 "srcs": `select({
1072 "//build/bazel/platforms/os:android": ["bar.sysprop"],
1073 "//conditions:default": [],
1074 })`,
1075 }),
1076 MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
1077 "dep": `":foo_sysprop_library"`,
1078 "min_sdk_version": `"5"`,
1079 }),
1080 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1081 "srcs": `["blah.cpp"]`,
1082 "local_includes": `["."]`,
1083 "min_sdk_version": `"5"`,
1084 "whole_archive_deps": `select({
1085 "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"],
1086 "//conditions:default": [],
1087 })`,
1088 }),
1089 },
1090 })
1091}
Yu Liu56ccb1a2022-11-12 10:47:07 -08001092
1093func TestCcLibrarySharedHeaderAbiChecker(t *testing.T) {
1094 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1095 Description: "cc_library_shared with header abi checker",
1096 Blueprint: `cc_library_shared {
1097 name: "foo",
1098 header_abi_checker: {
1099 enabled: true,
1100 symbol_file: "a.map.txt",
1101 exclude_symbol_versions: [
1102 "29",
1103 "30",
1104 ],
1105 exclude_symbol_tags: [
1106 "tag1",
1107 "tag2",
1108 ],
1109 check_all_apis: true,
1110 diff_flags: ["-allow-adding-removing-weak-symbols"],
1111 },
1112 include_build_directory: false,
1113}`,
1114 ExpectedBazelTargets: []string{
1115 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1116 "abi_checker_enabled": `True`,
1117 "abi_checker_symbol_file": `"a.map.txt"`,
1118 "abi_checker_exclude_symbol_versions": `[
1119 "29",
1120 "30",
1121 ]`,
1122 "abi_checker_exclude_symbol_tags": `[
1123 "tag1",
1124 "tag2",
1125 ]`,
1126 "abi_checker_check_all_apis": `True`,
1127 "abi_checker_diff_flags": `["-allow-adding-removing-weak-symbols"]`,
1128 }),
1129 },
1130 })
1131}
Trevor Radcliffedb7e0262022-10-28 16:48:18 +00001132
1133func TestCcLibrarySharedWithIntegerOverflowProperty(t *testing.T) {
1134 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1135 Description: "cc_library_shared has correct features when integer_overflow property is provided",
1136 Blueprint: `
1137cc_library_shared {
1138 name: "foo",
1139 sanitize: {
1140 integer_overflow: true,
1141 },
1142}
1143`,
1144 ExpectedBazelTargets: []string{
1145 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1146 "features": `["ubsan_integer_overflow"]`,
1147 "local_includes": `["."]`,
1148 }),
1149 },
1150 })
1151}
1152
1153func TestCcLibrarySharedWithMiscUndefinedProperty(t *testing.T) {
1154 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1155 Description: "cc_library_shared has correct features when misc_undefined property is provided",
1156 Blueprint: `
1157cc_library_shared {
1158 name: "foo",
1159 sanitize: {
1160 misc_undefined: ["undefined", "nullability"],
1161 },
1162}
1163`,
1164 ExpectedBazelTargets: []string{
1165 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1166 "features": `[
1167 "ubsan_undefined",
1168 "ubsan_nullability",
1169 ]`,
1170 "local_includes": `["."]`,
1171 }),
1172 },
1173 })
1174}
1175
1176func TestCcLibrarySharedWithUBSanPropertiesArchSpecific(t *testing.T) {
1177 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1178 Description: "cc_library_shared has correct feature select when UBSan props are specified in arch specific blocks",
1179 Blueprint: `
1180cc_library_shared {
1181 name: "foo",
1182 sanitize: {
1183 misc_undefined: ["undefined", "nullability"],
1184 },
1185 target: {
1186 android: {
1187 sanitize: {
1188 misc_undefined: ["alignment"],
1189 },
1190 },
1191 linux_glibc: {
1192 sanitize: {
1193 integer_overflow: true,
1194 },
1195 },
1196 },
1197}
1198`,
1199 ExpectedBazelTargets: []string{
1200 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1201 "features": `[
1202 "ubsan_undefined",
1203 "ubsan_nullability",
1204 ] + select({
1205 "//build/bazel/platforms/os:android": ["ubsan_alignment"],
1206 "//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"],
1207 "//conditions:default": [],
1208 })`,
1209 "local_includes": `["."]`,
1210 }),
1211 },
1212 })
1213}
Trevor Radcliffe56b1a2b2023-02-06 21:58:30 +00001214
Trevor Radcliffeded095c2023-06-12 19:18:28 +00001215func TestCcLibrarySharedWithSanitizerBlocklist(t *testing.T) {
1216 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1217 Description: "cc_library_shared has correct features when sanitize.blocklist is provided",
1218 Blueprint: `
1219cc_library_shared {
1220 name: "foo",
1221 sanitize: {
1222 blocklist: "foo_blocklist.txt",
1223 },
1224}
1225`,
1226 ExpectedBazelTargets: []string{
1227 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Trevor Radcliffed9b7f172023-08-09 22:21:38 +00001228 "copts": `select({
1229 "//build/bazel/rules/cc:sanitizers_enabled": ["-fsanitize-ignorelist=$(location foo_blocklist.txt)"],
1230 "//conditions:default": [],
1231 })`,
1232 "additional_compiler_inputs": `select({
1233 "//build/bazel/rules/cc:sanitizers_enabled": [":foo_blocklist.txt"],
1234 "//conditions:default": [],
1235 })`,
Trevor Radcliffeded095c2023-06-12 19:18:28 +00001236 "local_includes": `["."]`,
1237 }),
1238 },
1239 })
1240}
1241
Trevor Radcliffe56b1a2b2023-02-06 21:58:30 +00001242func TestCcLibrarySharedWithThinLto(t *testing.T) {
1243 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1244 Description: "cc_library_shared has correct features when thin lto is enabled",
1245 Blueprint: `
1246cc_library_shared {
1247 name: "foo",
1248 lto: {
1249 thin: true,
1250 },
1251}
1252`,
1253 ExpectedBazelTargets: []string{
1254 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1255 "features": `["android_thin_lto"]`,
1256 "local_includes": `["."]`,
1257 }),
1258 },
1259 })
1260}
1261
1262func TestCcLibrarySharedWithLtoNever(t *testing.T) {
1263 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1264 Description: "cc_library_shared has correct features when thin lto is enabled",
1265 Blueprint: `
1266cc_library_shared {
1267 name: "foo",
1268 lto: {
1269 never: true,
1270 },
1271}
1272`,
1273 ExpectedBazelTargets: []string{
1274 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1275 "features": `["-android_thin_lto"]`,
1276 "local_includes": `["."]`,
1277 }),
1278 },
1279 })
1280}
1281
1282func TestCcLibrarySharedWithThinLtoArchSpecific(t *testing.T) {
1283 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1284 Description: "cc_library_shared has correct features when LTO differs across arch and os variants",
1285 Blueprint: `
1286cc_library_shared {
1287 name: "foo",
1288 target: {
1289 android: {
1290 lto: {
1291 thin: true,
1292 },
1293 },
1294 },
1295 arch: {
1296 riscv64: {
1297 lto: {
1298 thin: false,
1299 },
1300 },
1301 },
1302}`,
1303 ExpectedBazelTargets: []string{
1304 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1305 "local_includes": `["."]`,
1306 "features": `select({
1307 "//build/bazel/platforms/os_arch:android_arm": ["android_thin_lto"],
1308 "//build/bazel/platforms/os_arch:android_arm64": ["android_thin_lto"],
1309 "//build/bazel/platforms/os_arch:android_riscv64": ["-android_thin_lto"],
1310 "//build/bazel/platforms/os_arch:android_x86": ["android_thin_lto"],
1311 "//build/bazel/platforms/os_arch:android_x86_64": ["android_thin_lto"],
1312 "//conditions:default": [],
1313 })`}),
1314 },
1315 })
1316}
1317
1318func TestCcLibrarySharedWithThinLtoDisabledDefaultEnabledVariant(t *testing.T) {
1319 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1320 Description: "cc_library_shared with thin lto disabled by default but enabled on a particular variant",
1321 Blueprint: `
1322cc_library_shared {
1323 name: "foo",
1324 lto: {
1325 never: true,
1326 },
1327 target: {
1328 android: {
1329 lto: {
1330 thin: true,
1331 never: false,
1332 },
1333 },
1334 },
1335}`,
1336 ExpectedBazelTargets: []string{
1337 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1338 "local_includes": `["."]`,
1339 "features": `select({
1340 "//build/bazel/platforms/os:android": ["android_thin_lto"],
1341 "//conditions:default": ["-android_thin_lto"],
1342 })`,
1343 }),
1344 },
1345 })
1346}
1347
1348func TestCcLibrarySharedWithThinLtoAndWholeProgramVtables(t *testing.T) {
1349 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1350 Description: "cc_library_shared has correct features when thin LTO is enabled with whole_program_vtables",
1351 Blueprint: `
1352cc_library_shared {
1353 name: "foo",
1354 lto: {
1355 thin: true,
1356 },
1357 whole_program_vtables: true,
1358}
1359`,
1360 ExpectedBazelTargets: []string{
1361 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1362 "features": `[
1363 "android_thin_lto",
1364 "android_thin_lto_whole_program_vtables",
1365 ]`,
1366 "local_includes": `["."]`,
1367 }),
1368 },
1369 })
1370}
Trevor Radcliffea8b44162023-04-14 18:25:24 +00001371
1372func TestCcLibrarySharedHiddenVisibilityConvertedToFeature(t *testing.T) {
1373 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1374 Description: "cc_library_shared changes hidden visibility flag to feature",
1375 Blueprint: `
1376cc_library_shared{
1377 name: "foo",
1378 cflags: ["-fvisibility=hidden"],
1379}`,
1380 ExpectedBazelTargets: []string{
1381 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1382 "features": `["visibility_hidden"]`,
1383 "local_includes": `["."]`,
1384 }),
1385 },
1386 })
1387}
1388
1389func TestCcLibrarySharedHiddenVisibilityConvertedToFeatureOsSpecific(t *testing.T) {
1390 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1391 Description: "cc_library_shared changes hidden visibility flag to feature for specific os",
1392 Blueprint: `
1393cc_library_shared{
1394 name: "foo",
1395 target: {
1396 android: {
1397 cflags: ["-fvisibility=hidden"],
1398 },
1399 },
1400}`,
1401 ExpectedBazelTargets: []string{
1402 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1403 "features": `select({
1404 "//build/bazel/platforms/os:android": ["visibility_hidden"],
1405 "//conditions:default": [],
1406 })`,
1407 "local_includes": `["."]`,
1408 }),
1409 },
1410 })
1411}
Sam Delmerico75dbca22023-04-20 13:13:25 +00001412
1413func TestCcLibrarySharedStubsDessertVersionConversion(t *testing.T) {
1414 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1415 Description: "cc_library_shared converts dessert codename versions to numerical versions",
1416 Blueprint: `
1417cc_library_shared {
1418 name: "a",
1419 include_build_directory: false,
1420 stubs: {
1421 symbol_file: "a.map.txt",
1422 versions: [
1423 "Q",
1424 "R",
1425 "31",
1426 ],
1427 },
1428}
1429cc_library_shared {
1430 name: "b",
1431 include_build_directory: false,
1432 stubs: {
1433 symbol_file: "b.map.txt",
1434 versions: [
1435 "Q",
1436 "R",
1437 "31",
1438 "current",
1439 ],
1440 },
1441}
1442`,
1443 ExpectedBazelTargets: []string{
1444 makeCcStubSuiteTargets("a", AttrNameToString{
Spandan Das04f9f4c2023-09-13 23:59:05 +00001445 "api_surface": `"module-libapi"`,
Sam Delmerico75dbca22023-04-20 13:13:25 +00001446 "soname": `"a.so"`,
1447 "source_library_label": `"//:a"`,
1448 "stubs_symbol_file": `"a.map.txt"`,
1449 "stubs_versions": `[
1450 "29",
1451 "30",
1452 "31",
1453 "current",
1454 ]`,
1455 }),
1456 MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
1457 "stubs_symbol_file": `"a.map.txt"`,
1458 }),
1459 makeCcStubSuiteTargets("b", AttrNameToString{
Spandan Das04f9f4c2023-09-13 23:59:05 +00001460 "api_surface": `"module-libapi"`,
Sam Delmerico75dbca22023-04-20 13:13:25 +00001461 "soname": `"b.so"`,
1462 "source_library_label": `"//:b"`,
1463 "stubs_symbol_file": `"b.map.txt"`,
1464 "stubs_versions": `[
1465 "29",
1466 "30",
1467 "31",
1468 "current",
1469 ]`,
1470 }),
1471 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
1472 "stubs_symbol_file": `"b.map.txt"`,
1473 }),
1474 },
1475 })
1476}
Trevor Radcliffe27669c02023-03-28 20:47:10 +00001477
1478func TestCcLibrarySharedWithCfi(t *testing.T) {
1479 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1480 Description: "cc_library_shared has correct features when cfi is enabled for specific variants",
1481 Blueprint: `
1482cc_library_shared {
1483 name: "foo",
1484 sanitize: {
1485 cfi: true,
1486 },
1487}`,
1488 ExpectedBazelTargets: []string{
1489 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1490 "features": `["android_cfi"]`,
1491 "local_includes": `["."]`,
1492 }),
1493 },
1494 })
1495}
1496
1497func TestCcLibrarySharedWithCfiOsSpecific(t *testing.T) {
1498 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1499 Description: "cc_library_shared has correct features when cfi is enabled",
1500 Blueprint: `
1501cc_library_shared {
1502 name: "foo",
1503 target: {
1504 android: {
1505 sanitize: {
1506 cfi: true,
1507 },
1508 },
1509 },
1510}`,
1511 ExpectedBazelTargets: []string{
1512 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1513 "features": `select({
1514 "//build/bazel/platforms/os:android": ["android_cfi"],
1515 "//conditions:default": [],
1516 })`,
1517 "local_includes": `["."]`,
1518 }),
1519 },
1520 })
1521}
1522
1523func TestCcLibrarySharedWithCfiAndCfiAssemblySupport(t *testing.T) {
1524 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1525 Description: "cc_library_shared has correct features when cfi is enabled with cfi assembly support",
1526 Blueprint: `
1527cc_library_static {
1528 name: "foo",
1529 sanitize: {
1530 cfi: true,
1531 config: {
1532 cfi_assembly_support: true,
1533 },
1534 },
1535}`,
1536 ExpectedBazelTargets: []string{
1537 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1538 "features": `[
1539 "android_cfi",
1540 "android_cfi_assembly_support",
1541 ]`,
1542 "local_includes": `["."]`,
1543 }),
1544 },
1545 })
1546}
Trevor Radcliffe523c5c62023-06-16 20:15:45 +00001547
1548func TestCcLibrarySharedExplicitlyDisablesCfiWhenFalse(t *testing.T) {
1549 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1550 Description: "cc_library_shared disables cfi when explciitly set to false in the bp",
1551 Blueprint: `
1552cc_library_shared {
1553 name: "foo",
1554 sanitize: {
1555 cfi: false,
1556 },
1557}
1558`,
1559 ExpectedBazelTargets: []string{
1560 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1561 "features": `["-android_cfi"]`,
1562 "local_includes": `["."]`,
1563 }),
1564 },
1565 })
1566}
Alixe2667872023-04-24 14:57:32 +00001567
1568func TestCCLibrarySharedRscriptSrc(t *testing.T) {
1569 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1570 Description: ``,
1571 Blueprint: `
1572cc_library_shared{
1573 name : "foo",
1574 srcs : [
1575 "ccSrc.cc",
1576 "rsSrc.rscript",
1577 ],
1578 include_build_directory: false,
1579}
1580`,
1581 ExpectedBazelTargets: []string{
1582 MakeBazelTarget("rscript_to_cpp", "foo_renderscript", AttrNameToString{
1583 "srcs": `["rsSrc.rscript"]`,
1584 }),
1585 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1586 "absolute_includes": `[
1587 "frameworks/rs",
1588 "frameworks/rs/cpp",
1589 ]`,
1590 "local_includes": `["."]`,
1591 "srcs": `[
1592 "ccSrc.cc",
1593 "foo_renderscript",
1594 ]`,
1595 })}})
1596}
Spandan Das1f65f9e2023-09-15 01:08:23 +00001597
1598func TestCcLibrarySdkVariantUsesStubs(t *testing.T) {
1599 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1600 Description: "cc_library_shared stubs",
1601 ModuleTypeUnderTest: "cc_library_shared",
1602 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
1603 Blueprint: soongCcLibrarySharedPreamble + `
1604cc_library_shared {
1605 name: "libUsesSdk",
1606 sdk_version: "current",
1607 shared_libs: [
1608 "libNoStubs",
1609 "libHasApexStubs",
1610 "libHasApexAndNdkStubs",
1611 ]
1612}
1613cc_library_shared {
1614 name: "libNoStubs",
1615 bazel_module: { bp2build_available: false },
1616}
1617cc_library_shared {
1618 name: "libHasApexStubs",
1619 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
1620 bazel_module: { bp2build_available: false },
1621 apex_available: ["apex_a"],
1622}
1623cc_library_shared {
1624 name: "libHasApexAndNdkStubs",
1625 stubs: { symbol_file: "b.map.txt", versions: ["28", "29", "current"] },
1626 bazel_module: { bp2build_available: false },
1627 apex_available: ["apex_b"],
1628}
1629ndk_library {
1630 name: "libHasApexAndNdkStubs",
1631 bazel_module: { bp2build_available: false },
1632}
1633`,
1634 ExpectedBazelTargets: []string{
1635 MakeBazelTarget("cc_library_shared", "libUsesSdk", AttrNameToString{
1636 "implementation_dynamic_deps": `[":libNoStubs"] + select({
1637 "//build/bazel/rules/apex:system": [
1638 "@api_surfaces//module-libapi/current:libHasApexStubs",
1639 "@api_surfaces//module-libapi/current:libHasApexAndNdkStubs",
1640 ],
1641 "//build/bazel/rules/apex:unbundled_app": [
1642 ":libHasApexStubs",
1643 "//.:libHasApexAndNdkStubs.ndk_stub_libs",
1644 ],
1645 "//conditions:default": [
1646 ":libHasApexStubs",
1647 ":libHasApexAndNdkStubs",
1648 ],
1649 })`,
1650 "local_includes": `["."]`,
1651 "sdk_version": `"current"`,
1652 }),
1653 },
1654 })
1655}