blob: 2ee9c99f9ccc5513269c856a5644b6fafd46d460 [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)
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000035}
36
Sam Delmerico3177a6e2022-06-21 19:28:33 +000037func runCcLibrarySharedTestCase(t *testing.T, tc Bp2buildTestCase) {
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000038 t.Helper()
Alex Márquez Pérez Muñíz Díaz Puras Thaureauxc641cc42023-03-16 17:03:43 +000039 t.Parallel()
Sam Delmerico3177a6e2022-06-21 19:28:33 +000040 (&tc).ModuleTypeUnderTest = "cc_library_shared"
41 (&tc).ModuleTypeUnderTestFactory = cc.LibrarySharedFactory
42 RunBp2BuildTestCase(t, registerCcLibrarySharedModuleTypes, tc)
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000043}
44
45func TestCcLibrarySharedSimple(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000046 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
47 Description: "cc_library_shared simple overall test",
48 Filesystem: map[string]string{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000049 // NOTE: include_dir headers *should not* appear in Bazel hdrs later (?)
50 "include_dir_1/include_dir_1_a.h": "",
51 "include_dir_1/include_dir_1_b.h": "",
52 "include_dir_2/include_dir_2_a.h": "",
53 "include_dir_2/include_dir_2_b.h": "",
54 // NOTE: local_include_dir headers *should not* appear in Bazel hdrs later (?)
55 "local_include_dir_1/local_include_dir_1_a.h": "",
56 "local_include_dir_1/local_include_dir_1_b.h": "",
57 "local_include_dir_2/local_include_dir_2_a.h": "",
58 "local_include_dir_2/local_include_dir_2_b.h": "",
59 // NOTE: export_include_dir headers *should* appear in Bazel hdrs later
60 "export_include_dir_1/export_include_dir_1_a.h": "",
61 "export_include_dir_1/export_include_dir_1_b.h": "",
62 "export_include_dir_2/export_include_dir_2_a.h": "",
63 "export_include_dir_2/export_include_dir_2_b.h": "",
64 // NOTE: Soong implicitly includes headers in the current directory
65 "implicit_include_1.h": "",
66 "implicit_include_2.h": "",
67 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +000068 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000069cc_library_headers {
70 name: "header_lib_1",
71 export_include_dirs: ["header_lib_1"],
72 bazel_module: { bp2build_available: false },
73}
74
75cc_library_headers {
76 name: "header_lib_2",
77 export_include_dirs: ["header_lib_2"],
78 bazel_module: { bp2build_available: false },
79}
80
81cc_library_shared {
82 name: "shared_lib_1",
83 srcs: ["shared_lib_1.cc"],
84 bazel_module: { bp2build_available: false },
85}
86
87cc_library_shared {
88 name: "shared_lib_2",
89 srcs: ["shared_lib_2.cc"],
90 bazel_module: { bp2build_available: false },
91}
92
93cc_library_static {
94 name: "whole_static_lib_1",
95 srcs: ["whole_static_lib_1.cc"],
96 bazel_module: { bp2build_available: false },
97}
98
99cc_library_static {
100 name: "whole_static_lib_2",
101 srcs: ["whole_static_lib_2.cc"],
102 bazel_module: { bp2build_available: false },
103}
104
105cc_library_shared {
106 name: "foo_shared",
107 srcs: [
108 "foo_shared1.cc",
109 "foo_shared2.cc",
110 ],
111 cflags: [
112 "-Dflag1",
113 "-Dflag2"
114 ],
115 shared_libs: [
116 "shared_lib_1",
117 "shared_lib_2"
118 ],
119 whole_static_libs: [
120 "whole_static_lib_1",
121 "whole_static_lib_2"
122 ],
123 include_dirs: [
124 "include_dir_1",
125 "include_dir_2",
126 ],
127 local_include_dirs: [
128 "local_include_dir_1",
129 "local_include_dir_2",
130 ],
131 export_include_dirs: [
132 "export_include_dir_1",
133 "export_include_dir_2"
134 ],
135 header_libs: [
136 "header_lib_1",
137 "header_lib_2"
138 ],
Yu Liufc603162022-03-01 15:44:08 -0800139 sdk_version: "current",
140 min_sdk_version: "29",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000141
142 // TODO: Also support export_header_lib_headers
143}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000144 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000145 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500146 "absolute_includes": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000147 "include_dir_1",
148 "include_dir_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500149 ]`,
150 "copts": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000151 "-Dflag1",
152 "-Dflag2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500153 ]`,
154 "export_includes": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000155 "export_include_dir_1",
156 "export_include_dir_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500157 ]`,
158 "implementation_deps": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000159 ":header_lib_1",
160 ":header_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500161 ]`,
162 "implementation_dynamic_deps": `[
Liz Kammer7a210ac2021-09-22 15:52:58 -0400163 ":shared_lib_1",
164 ":shared_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500165 ]`,
166 "local_includes": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000167 "local_include_dir_1",
168 "local_include_dir_2",
169 ".",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500170 ]`,
171 "srcs": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000172 "foo_shared1.cc",
173 "foo_shared2.cc",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500174 ]`,
175 "whole_archive_deps": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000176 ":whole_static_lib_1",
177 ":whole_static_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500178 ]`,
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000179 "sdk_version": `"current"`,
180 "min_sdk_version": `"29"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500181 }),
182 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000183 })
184}
185
186func TestCcLibrarySharedArchSpecificSharedLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000187 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
188 Description: "cc_library_shared arch-specific shared_libs with whole_static_libs",
189 Filesystem: map[string]string{},
190 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000191cc_library_static {
192 name: "static_dep",
193 bazel_module: { bp2build_available: false },
194}
195cc_library_shared {
196 name: "shared_dep",
197 bazel_module: { bp2build_available: false },
198}
199cc_library_shared {
200 name: "foo_shared",
201 arch: { arm64: { shared_libs: ["shared_dep"], whole_static_libs: ["static_dep"] } },
202 include_build_directory: false,
203}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000204 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000205 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500206 "implementation_dynamic_deps": `select({
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000207 "//build/bazel/platforms/arch:arm64": [":shared_dep"],
208 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500209 })`,
210 "whole_archive_deps": `select({
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000211 "//build/bazel/platforms/arch:arm64": [":static_dep"],
212 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500213 })`,
214 }),
215 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000216 })
217}
218
219func TestCcLibrarySharedOsSpecificSharedLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000220 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
221 Description: "cc_library_shared os-specific shared_libs",
222 Filesystem: map[string]string{},
223 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000224cc_library_shared {
225 name: "shared_dep",
226 bazel_module: { bp2build_available: false },
227}
228cc_library_shared {
229 name: "foo_shared",
230 target: { android: { shared_libs: ["shared_dep"], } },
231 include_build_directory: false,
232}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000233 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000234 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500235 "implementation_dynamic_deps": `select({
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000236 "//build/bazel/platforms/os:android": [":shared_dep"],
237 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500238 })`,
239 }),
240 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000241 })
242}
243
244func TestCcLibrarySharedBaseArchOsSpecificSharedLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000245 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
246 Description: "cc_library_shared base, arch, and os-specific shared_libs",
247 Filesystem: map[string]string{},
248 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000249cc_library_shared {
250 name: "shared_dep",
251 bazel_module: { bp2build_available: false },
252}
253cc_library_shared {
254 name: "shared_dep2",
255 bazel_module: { bp2build_available: false },
256}
257cc_library_shared {
258 name: "shared_dep3",
259 bazel_module: { bp2build_available: false },
260}
261cc_library_shared {
262 name: "foo_shared",
263 shared_libs: ["shared_dep"],
264 target: { android: { shared_libs: ["shared_dep2"] } },
265 arch: { arm64: { shared_libs: ["shared_dep3"] } },
266 include_build_directory: false,
267}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000268 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000269 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500270 "implementation_dynamic_deps": `[":shared_dep"] + select({
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000271 "//build/bazel/platforms/arch:arm64": [":shared_dep3"],
272 "//conditions:default": [],
273 }) + select({
274 "//build/bazel/platforms/os:android": [":shared_dep2"],
275 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500276 })`,
277 }),
278 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000279 })
280}
281
282func TestCcLibrarySharedSimpleExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000283 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
284 Description: "cc_library_shared simple exclude_srcs",
285 Filesystem: map[string]string{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000286 "common.c": "",
287 "foo-a.c": "",
288 "foo-excluded.c": "",
289 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000290 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000291cc_library_shared {
292 name: "foo_shared",
293 srcs: ["common.c", "foo-*.c"],
294 exclude_srcs: ["foo-excluded.c"],
295 include_build_directory: false,
296}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000297 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000298 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500299 "srcs_c": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000300 "common.c",
301 "foo-a.c",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500302 ]`,
303 }),
304 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000305 })
306}
307
308func TestCcLibrarySharedStrip(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000309 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
310 Description: "cc_library_shared stripping",
311 Filesystem: map[string]string{},
312 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000313cc_library_shared {
314 name: "foo_shared",
315 strip: {
316 keep_symbols: false,
317 keep_symbols_and_debug_frame: true,
318 keep_symbols_list: ["sym", "sym2"],
319 all: true,
320 none: false,
321 },
322 include_build_directory: false,
323}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000324 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000325 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500326 "strip": `{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000327 "all": True,
328 "keep_symbols": False,
329 "keep_symbols_and_debug_frame": True,
330 "keep_symbols_list": [
331 "sym",
332 "sym2",
333 ],
334 "none": False,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500335 }`,
336 }),
337 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000338 })
339}
340
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +0000341func TestCcLibrarySharedVersionScriptAndDynamicList(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000342 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +0000343 Description: "cc_library_shared version script and dynamic list",
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000344 Filesystem: map[string]string{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000345 "version_script": "",
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +0000346 "dynamic.list": "",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000347 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000348 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000349cc_library_shared {
350 name: "foo_shared",
351 version_script: "version_script",
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +0000352 dynamic_list: "dynamic.list",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000353 include_build_directory: false,
354}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000355 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000356 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +0000357 "additional_linker_inputs": `[
358 "version_script",
359 "dynamic.list",
360 ]`,
361 "linkopts": `[
362 "-Wl,--version-script,$(location version_script)",
363 "-Wl,--dynamic-list,$(location dynamic.list)",
364 ]`,
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 ]`,
401 }),
402 },
403 })
404}
405
Jingwen Chen6ada5892021-09-17 11:38:09 +0000406func TestCcLibrarySharedNoCrtTrue(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000407 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux01ec55e2023-01-30 22:53:04 +0000408 Description: "cc_library_shared - nocrt: true disables feature",
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000409 Filesystem: map[string]string{
Jingwen Chen6ada5892021-09-17 11:38:09 +0000410 "impl.cpp": "",
411 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000412 Blueprint: soongCcLibraryPreamble + `
Jingwen Chen6ada5892021-09-17 11:38:09 +0000413cc_library_shared {
414 name: "foo_shared",
415 srcs: ["impl.cpp"],
416 nocrt: true,
417 include_build_directory: false,
418}
419`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000420 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000421 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux01ec55e2023-01-30 22:53:04 +0000422 "features": `["-link_crt"]`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500423 "srcs": `["impl.cpp"]`,
424 }),
425 },
426 })
Jingwen Chen6ada5892021-09-17 11:38:09 +0000427}
428
429func TestCcLibrarySharedNoCrtFalse(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000430 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux01ec55e2023-01-30 22:53:04 +0000431 Description: "cc_library_shared - nocrt: false doesn't disable feature",
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000432 Filesystem: map[string]string{
Jingwen Chen6ada5892021-09-17 11:38:09 +0000433 "impl.cpp": "",
434 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000435 Blueprint: soongCcLibraryPreamble + `
Jingwen Chen6ada5892021-09-17 11:38:09 +0000436cc_library_shared {
437 name: "foo_shared",
438 srcs: ["impl.cpp"],
439 nocrt: false,
440 include_build_directory: false,
441}
442`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000443 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000444 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500445 "srcs": `["impl.cpp"]`,
446 }),
447 },
448 })
Jingwen Chen6ada5892021-09-17 11:38:09 +0000449}
450
451func TestCcLibrarySharedNoCrtArchVariant(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000452 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
453 Description: "cc_library_shared - nocrt in select",
454 Filesystem: map[string]string{
Jingwen Chen6ada5892021-09-17 11:38:09 +0000455 "impl.cpp": "",
456 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000457 Blueprint: soongCcLibraryPreamble + `
Jingwen Chen6ada5892021-09-17 11:38:09 +0000458cc_library_shared {
459 name: "foo_shared",
460 srcs: ["impl.cpp"],
461 arch: {
462 arm: {
463 nocrt: true,
464 },
465 x86: {
466 nocrt: false,
467 },
468 },
469 include_build_directory: false,
470}
471`,
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux01ec55e2023-01-30 22:53:04 +0000472 ExpectedBazelTargets: []string{
473 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
474 "features": `select({
475 "//build/bazel/platforms/arch:arm": ["-link_crt"],
476 "//conditions:default": [],
477 })`,
478 "srcs": `["impl.cpp"]`,
479 }),
480 },
Jingwen Chen6ada5892021-09-17 11:38:09 +0000481 })
482}
Liz Kammer12615db2021-09-28 09:19:17 -0400483
484func TestCcLibrarySharedProto(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000485 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
486 Blueprint: soongCcProtoPreamble + `cc_library_shared {
Liz Kammer12615db2021-09-28 09:19:17 -0400487 name: "foo",
488 srcs: ["foo.proto"],
489 proto: {
Liz Kammer12615db2021-09-28 09:19:17 -0400490 export_proto_headers: true,
491 },
492 include_build_directory: false,
493}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000494 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000495 MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -0400496 "srcs": `["foo.proto"]`,
Alixe06d75b2022-08-31 18:28:19 +0000497 }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -0400498 "deps": `[":foo_proto"]`,
Alixe06d75b2022-08-31 18:28:19 +0000499 }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -0400500 "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
501 "whole_archive_deps": `[":foo_cc_proto_lite"]`,
502 }),
503 },
504 })
505}
Rupert Shuttleworth484aa252021-12-10 07:22:53 -0500506
507func TestCcLibrarySharedUseVersionLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000508 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Liz Kammerbaced712022-09-16 09:01:29 -0400509 Filesystem: map[string]string{
510 soongCcVersionLibBpPath: soongCcVersionLibBp,
511 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000512 Blueprint: soongCcProtoPreamble + `cc_library_shared {
Rupert Shuttleworth484aa252021-12-10 07:22:53 -0500513 name: "foo",
514 use_version_lib: true,
515 include_build_directory: false,
516}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000517 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000518 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Yu Liufe978fd2023-04-24 16:37:18 -0700519 "use_version_lib": "True",
520 "whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
Rupert Shuttleworth484aa252021-12-10 07:22:53 -0500521 }),
522 },
523 })
524}
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000525
526func TestCcLibrarySharedStubs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000527 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
528 Description: "cc_library_shared stubs",
529 ModuleTypeUnderTest: "cc_library_shared",
530 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
531 Dir: "foo/bar",
532 Filesystem: map[string]string{
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000533 "foo/bar/Android.bp": `
534cc_library_shared {
535 name: "a",
536 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
537 bazel_module: { bp2build_available: true },
538 include_build_directory: false,
539}
540`,
541 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000542 Blueprint: soongCcLibraryPreamble,
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000543 ExpectedBazelTargets: []string{makeCcStubSuiteTargets("a", AttrNameToString{
Sam Delmerico5f906492023-03-15 18:06:18 -0400544 "soname": `"a.so"`,
545 "source_library_label": `"//foo/bar:a"`,
546 "stubs_symbol_file": `"a.map.txt"`,
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000547 "stubs_versions": `[
Trevor Radcliffe087af542022-09-16 15:36:10 +0000548 "28",
549 "29",
550 "current",
551 ]`,
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000552 }),
553 MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
Yu Liu56ccb1a2022-11-12 10:47:07 -0800554 "stubs_symbol_file": `"a.map.txt"`,
Trevor Radcliffe087af542022-09-16 15:36:10 +0000555 }),
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000556 },
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000557 })
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000558}
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000559
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400560func TestCcLibrarySharedStubs_UseImplementationInSameApex(t *testing.T) {
561 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
562 Description: "cc_library_shared stubs",
563 ModuleTypeUnderTest: "cc_library_shared",
564 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
565 Blueprint: soongCcLibrarySharedPreamble + `
566cc_library_shared {
567 name: "a",
568 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
569 bazel_module: { bp2build_available: false },
570 include_build_directory: false,
571 apex_available: ["made_up_apex"],
572}
573cc_library_shared {
574 name: "b",
575 shared_libs: [":a"],
576 include_build_directory: false,
577 apex_available: ["made_up_apex"],
578}
579`,
580 ExpectedBazelTargets: []string{
581 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
582 "implementation_dynamic_deps": `[":a"]`,
583 "tags": `["apex_available=made_up_apex"]`,
584 }),
585 },
586 })
587}
588
589func TestCcLibrarySharedStubs_UseStubsInDifferentApex(t *testing.T) {
590 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
591 Description: "cc_library_shared stubs",
592 ModuleTypeUnderTest: "cc_library_shared",
593 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
594 Blueprint: soongCcLibrarySharedPreamble + `
595cc_library_shared {
596 name: "a",
597 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
598 bazel_module: { bp2build_available: false },
599 include_build_directory: false,
600 apex_available: ["apex_a"],
601}
602cc_library_shared {
603 name: "b",
604 shared_libs: [":a"],
605 include_build_directory: false,
606 apex_available: ["apex_b"],
607}
608`,
609 ExpectedBazelTargets: []string{
610 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
611 "implementation_dynamic_deps": `select({
Spandan Das6d4d9da2023-04-18 06:20:40 +0000612 "//build/bazel/rules/apex:apex_b": ["@api_surfaces//module-libapi/current:a"],
613 "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400614 "//conditions:default": [":a"],
615 })`,
616 "tags": `["apex_available=apex_b"]`,
617 }),
618 },
619 })
620}
621
Spandan Das6d4d9da2023-04-18 06:20:40 +0000622// Tests that library in apexfoo links against stubs of platform_lib and otherapex_lib
623func TestCcLibrarySharedStubs_UseStubsFromMultipleApiDomains(t *testing.T) {
624 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
625 Description: "cc_library_shared stubs",
626 ModuleTypeUnderTest: "cc_library_shared",
627 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
628 Blueprint: soongCcLibrarySharedPreamble + `
629cc_library_shared {
630 name: "libplatform_stable",
631 stubs: { symbol_file: "libplatform_stable.map.txt", versions: ["28", "29", "current"] },
632 apex_available: ["//apex_available:platform"],
633 bazel_module: { bp2build_available: false },
634 include_build_directory: false,
635}
636cc_library_shared {
637 name: "libapexfoo_stable",
638 stubs: { symbol_file: "libapexfoo_stable.map.txt", versions: ["28", "29", "current"] },
639 apex_available: ["apexfoo"],
640 bazel_module: { bp2build_available: false },
641 include_build_directory: false,
642}
643cc_library_shared {
644 name: "libutils",
645 shared_libs: ["libplatform_stable", "libapexfoo_stable",],
646 apex_available: ["//apex_available:platform", "apexfoo", "apexbar"],
647 include_build_directory: false,
648}
649`,
650 ExpectedBazelTargets: []string{
651 MakeBazelTarget("cc_library_shared", "libutils", AttrNameToString{
652 "implementation_dynamic_deps": `select({
653 "//build/bazel/rules/apex:apexbar": [
654 "@api_surfaces//module-libapi/current:libplatform_stable",
655 "@api_surfaces//module-libapi/current:libapexfoo_stable",
656 ],
657 "//build/bazel/rules/apex:apexfoo": [
658 "@api_surfaces//module-libapi/current:libplatform_stable",
659 ":libapexfoo_stable",
660 ],
661 "//build/bazel/rules/apex:system": [
662 "@api_surfaces//module-libapi/current:libplatform_stable",
663 "@api_surfaces//module-libapi/current:libapexfoo_stable",
664 ],
665 "//conditions:default": [
666 ":libplatform_stable",
667 ":libapexfoo_stable",
668 ],
669 })`,
670 "tags": `[
671 "apex_available=//apex_available:platform",
672 "apex_available=apexfoo",
673 "apex_available=apexbar",
674 ]`,
675 }),
676 },
677 })
678}
679
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400680func TestCcLibrarySharedStubs_IgnorePlatformAvailable(t *testing.T) {
681 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
682 Description: "cc_library_shared stubs",
683 ModuleTypeUnderTest: "cc_library_shared",
684 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
685 Blueprint: soongCcLibrarySharedPreamble + `
686cc_library_shared {
687 name: "a",
688 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
689 bazel_module: { bp2build_available: false },
690 include_build_directory: false,
691 apex_available: ["//apex_available:platform", "apex_a"],
692}
693cc_library_shared {
694 name: "b",
695 shared_libs: [":a"],
696 include_build_directory: false,
697 apex_available: ["//apex_available:platform", "apex_b"],
698}
699`,
700 ExpectedBazelTargets: []string{
701 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
702 "implementation_dynamic_deps": `select({
Spandan Das6d4d9da2023-04-18 06:20:40 +0000703 "//build/bazel/rules/apex:apex_b": ["@api_surfaces//module-libapi/current:a"],
704 "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400705 "//conditions:default": [":a"],
706 })`,
707 "tags": `[
708 "apex_available=//apex_available:platform",
709 "apex_available=apex_b",
710 ]`,
711 }),
712 },
713 })
714}
715
Spandan Das6d4d9da2023-04-18 06:20:40 +0000716func TestCcLibraryDoesNotDropStubDepIfNoVariationAcrossAxis(t *testing.T) {
717 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
718 Description: "cc_library depeends on impl for all configurations",
719 ModuleTypeUnderTest: "cc_library_shared",
720 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
721 Blueprint: soongCcLibrarySharedPreamble + `
722cc_library_shared {
723 name: "a",
724 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
725 bazel_module: { bp2build_available: false },
726 apex_available: ["//apex_available:platform"],
727}
728cc_library_shared {
729 name: "b",
730 shared_libs: [":a"],
731 include_build_directory: false,
732 apex_available: ["//apex_available:platform"],
733}
734`,
735 ExpectedBazelTargets: []string{
736 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
737 "implementation_dynamic_deps": `[":a"]`,
738 "tags": `["apex_available=//apex_available:platform"]`,
739 }),
740 },
741 })
742}
743
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400744func TestCcLibrarySharedStubs_MultipleApexAvailable(t *testing.T) {
745 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
746 ModuleTypeUnderTest: "cc_library_shared",
747 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
748 Blueprint: soongCcLibrarySharedPreamble + `
749cc_library_shared {
750 name: "a",
751 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
752 bazel_module: { bp2build_available: false },
753 include_build_directory: false,
754 apex_available: ["//apex_available:platform", "apex_a", "apex_b"],
755}
756cc_library_shared {
757 name: "b",
758 shared_libs: [":a"],
759 include_build_directory: false,
760 apex_available: ["//apex_available:platform", "apex_b"],
761}
762
763cc_library_shared {
764 name: "c",
765 shared_libs: [":a"],
766 include_build_directory: false,
767 apex_available: ["//apex_available:platform", "apex_a", "apex_b"],
768}
769`,
770 ExpectedBazelTargets: []string{
771 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
772 "implementation_dynamic_deps": `select({
Spandan Das6d4d9da2023-04-18 06:20:40 +0000773 "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400774 "//conditions:default": [":a"],
775 })`,
776 "tags": `[
777 "apex_available=//apex_available:platform",
778 "apex_available=apex_b",
779 ]`,
780 }),
781 MakeBazelTarget("cc_library_shared", "c", AttrNameToString{
782 "implementation_dynamic_deps": `[":a"]`,
783 "tags": `[
784 "apex_available=//apex_available:platform",
785 "apex_available=apex_a",
786 "apex_available=apex_b",
787 ]`,
788 }),
789 },
790 })
791}
792
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000793func TestCcLibrarySharedSystemSharedLibsSharedEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000794 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
795 Description: "cc_library_shared system_shared_libs empty shared default",
796 ModuleTypeUnderTest: "cc_library_shared",
797 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
798 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000799cc_defaults {
800 name: "empty_defaults",
801 shared: {
802 system_shared_libs: [],
803 },
804 include_build_directory: false,
805}
806cc_library_shared {
807 name: "empty",
808 defaults: ["empty_defaults"],
809}
810`,
Alixe06d75b2022-08-31 18:28:19 +0000811 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 +0000812 "system_dynamic_deps": "[]",
813 })},
814 })
815}
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000816
817func TestCcLibrarySharedConvertLex(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000818 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
819 Description: "cc_library_shared with lex files",
820 ModuleTypeUnderTest: "cc_library_shared",
821 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
822 Filesystem: map[string]string{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000823 "foo.c": "",
824 "bar.cc": "",
825 "foo1.l": "",
826 "bar1.ll": "",
827 "foo2.l": "",
828 "bar2.ll": "",
829 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000830 Blueprint: `cc_library_shared {
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000831 name: "foo_lib",
832 srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"],
833 lex: { flags: ["--foo_flags"] },
834 include_build_directory: false,
835 bazel_module: { bp2build_available: true },
836}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000837 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000838 MakeBazelTarget("genlex", "foo_lib_genlex_l", AttrNameToString{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000839 "srcs": `[
840 "foo1.l",
841 "foo2.l",
842 ]`,
843 "lexopts": `["--foo_flags"]`,
844 }),
Alixe06d75b2022-08-31 18:28:19 +0000845 MakeBazelTarget("genlex", "foo_lib_genlex_ll", AttrNameToString{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000846 "srcs": `[
847 "bar1.ll",
848 "bar2.ll",
849 ]`,
850 "lexopts": `["--foo_flags"]`,
851 }),
Alixe06d75b2022-08-31 18:28:19 +0000852 MakeBazelTarget("cc_library_shared", "foo_lib", AttrNameToString{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000853 "srcs": `[
854 "bar.cc",
855 ":foo_lib_genlex_ll",
856 ]`,
857 "srcs_c": `[
858 "foo.c",
859 ":foo_lib_genlex_l",
860 ]`,
861 }),
862 },
863 })
864}
Alix1be00d42022-05-16 22:56:04 +0000865
866func TestCcLibrarySharedClangUnknownFlags(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000867 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
868 Blueprint: soongCcProtoPreamble + `cc_library_shared {
Alix1be00d42022-05-16 22:56:04 +0000869 name: "foo",
870 conlyflags: ["-a", "-finline-functions"],
871 cflags: ["-b","-finline-functions"],
872 cppflags: ["-c", "-finline-functions"],
873 ldflags: ["-d","-finline-functions", "-e"],
874 include_build_directory: false,
875}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000876 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000877 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Alix1be00d42022-05-16 22:56:04 +0000878 "conlyflags": `["-a"]`,
879 "copts": `["-b"]`,
880 "cppflags": `["-c"]`,
881 "linkopts": `[
882 "-d",
883 "-e",
884 ]`,
885 }),
886 },
887 })
888}
889
890func TestCCLibraryFlagSpaceSplitting(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000891 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
892 Blueprint: soongCcProtoPreamble + `cc_library_shared {
Alix1be00d42022-05-16 22:56:04 +0000893 name: "foo",
894 conlyflags: [ "-include header.h"],
895 cflags: ["-include header.h"],
896 cppflags: ["-include header.h"],
897 version_script: "version_script",
898 include_build_directory: false,
899}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000900 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000901 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Alix1be00d42022-05-16 22:56:04 +0000902 "additional_linker_inputs": `["version_script"]`,
903 "conlyflags": `[
904 "-include",
905 "header.h",
906 ]`,
907 "copts": `[
908 "-include",
909 "header.h",
910 ]`,
911 "cppflags": `[
912 "-include",
913 "header.h",
914 ]`,
915 "linkopts": `["-Wl,--version-script,$(location version_script)"]`,
916 }),
917 },
918 })
919}
Cole Faust6b29f592022-08-09 09:50:56 -0700920
921func TestCCLibrarySharedRuntimeDeps(t *testing.T) {
922 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
923 Blueprint: `cc_library_shared {
924 name: "bar",
925}
926
927cc_library_shared {
928 name: "foo",
929 runtime_libs: ["foo"],
930}`,
931 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000932 MakeBazelTarget("cc_library_shared", "bar", AttrNameToString{
Cole Faust6b29f592022-08-09 09:50:56 -0700933 "local_includes": `["."]`,
934 }),
Alixe06d75b2022-08-31 18:28:19 +0000935 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Cole Faust6b29f592022-08-09 09:50:56 -0700936 "runtime_deps": `[":foo"]`,
937 "local_includes": `["."]`,
938 }),
939 },
940 })
941}
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -0500942
943func TestCcLibrarySharedEmptySuffix(t *testing.T) {
944 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
945 Description: "cc_library_shared with empty suffix",
946 Filesystem: map[string]string{
947 "foo.c": "",
948 },
949 Blueprint: soongCcLibrarySharedPreamble + `
950cc_library_shared {
951 name: "foo_shared",
952 suffix: "",
953 srcs: ["foo.c"],
954 include_build_directory: false,
955}`,
956 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000957 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -0500958 "srcs_c": `["foo.c"]`,
959 "suffix": `""`,
960 }),
961 },
962 })
963}
964
965func TestCcLibrarySharedSuffix(t *testing.T) {
966 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
967 Description: "cc_library_shared with suffix",
968 Filesystem: map[string]string{
969 "foo.c": "",
970 },
971 Blueprint: soongCcLibrarySharedPreamble + `
972cc_library_shared {
973 name: "foo_shared",
974 suffix: "-suf",
975 srcs: ["foo.c"],
976 include_build_directory: false,
977}`,
978 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000979 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -0500980 "srcs_c": `["foo.c"]`,
981 "suffix": `"-suf"`,
982 }),
983 },
984 })
985}
986
987func TestCcLibrarySharedArchVariantSuffix(t *testing.T) {
988 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
989 Description: "cc_library_shared with arch-variant suffix",
990 Filesystem: map[string]string{
991 "foo.c": "",
992 },
993 Blueprint: soongCcLibrarySharedPreamble + `
994cc_library_shared {
995 name: "foo_shared",
996 arch: {
997 arm64: { suffix: "-64" },
998 arm: { suffix: "-32" },
999 },
1000 srcs: ["foo.c"],
1001 include_build_directory: false,
1002}`,
1003 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001004 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -05001005 "srcs_c": `["foo.c"]`,
1006 "suffix": `select({
1007 "//build/bazel/platforms/arch:arm": "-32",
1008 "//build/bazel/platforms/arch:arm64": "-64",
1009 "//conditions:default": None,
1010 })`,
1011 }),
1012 },
1013 })
1014}
Trevor Radcliffecee4e052022-09-06 19:31:25 +00001015
1016func TestCcLibrarySharedWithSyspropSrcs(t *testing.T) {
1017 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1018 Description: "cc_library_shared with sysprop sources",
1019 Blueprint: `
1020cc_library_shared {
1021 name: "foo",
1022 srcs: [
1023 "bar.sysprop",
1024 "baz.sysprop",
1025 "blah.cpp",
1026 ],
1027 min_sdk_version: "5",
1028}`,
1029 ExpectedBazelTargets: []string{
1030 MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
1031 "srcs": `[
1032 "bar.sysprop",
1033 "baz.sysprop",
1034 ]`,
1035 }),
1036 MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
1037 "dep": `":foo_sysprop_library"`,
1038 "min_sdk_version": `"5"`,
1039 }),
1040 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1041 "srcs": `["blah.cpp"]`,
1042 "local_includes": `["."]`,
1043 "min_sdk_version": `"5"`,
1044 "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`,
1045 }),
1046 },
1047 })
1048}
1049
1050func TestCcLibrarySharedWithSyspropSrcsSomeConfigs(t *testing.T) {
1051 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1052 Description: "cc_library_shared with sysprop sources in some configs but not others",
1053 Blueprint: `
1054cc_library_shared {
1055 name: "foo",
1056 srcs: [
1057 "blah.cpp",
1058 ],
1059 target: {
1060 android: {
1061 srcs: ["bar.sysprop"],
1062 },
1063 },
1064 min_sdk_version: "5",
1065}`,
1066 ExpectedBazelTargets: []string{
1067 MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
1068 "srcs": `select({
1069 "//build/bazel/platforms/os:android": ["bar.sysprop"],
1070 "//conditions:default": [],
1071 })`,
1072 }),
1073 MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
1074 "dep": `":foo_sysprop_library"`,
1075 "min_sdk_version": `"5"`,
1076 }),
1077 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1078 "srcs": `["blah.cpp"]`,
1079 "local_includes": `["."]`,
1080 "min_sdk_version": `"5"`,
1081 "whole_archive_deps": `select({
1082 "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"],
1083 "//conditions:default": [],
1084 })`,
1085 }),
1086 },
1087 })
1088}
Yu Liu56ccb1a2022-11-12 10:47:07 -08001089
1090func TestCcLibrarySharedHeaderAbiChecker(t *testing.T) {
1091 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1092 Description: "cc_library_shared with header abi checker",
1093 Blueprint: `cc_library_shared {
1094 name: "foo",
1095 header_abi_checker: {
1096 enabled: true,
1097 symbol_file: "a.map.txt",
1098 exclude_symbol_versions: [
1099 "29",
1100 "30",
1101 ],
1102 exclude_symbol_tags: [
1103 "tag1",
1104 "tag2",
1105 ],
1106 check_all_apis: true,
1107 diff_flags: ["-allow-adding-removing-weak-symbols"],
1108 },
1109 include_build_directory: false,
1110}`,
1111 ExpectedBazelTargets: []string{
1112 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1113 "abi_checker_enabled": `True`,
1114 "abi_checker_symbol_file": `"a.map.txt"`,
1115 "abi_checker_exclude_symbol_versions": `[
1116 "29",
1117 "30",
1118 ]`,
1119 "abi_checker_exclude_symbol_tags": `[
1120 "tag1",
1121 "tag2",
1122 ]`,
1123 "abi_checker_check_all_apis": `True`,
1124 "abi_checker_diff_flags": `["-allow-adding-removing-weak-symbols"]`,
1125 }),
1126 },
1127 })
1128}
Trevor Radcliffedb7e0262022-10-28 16:48:18 +00001129
1130func TestCcLibrarySharedWithIntegerOverflowProperty(t *testing.T) {
1131 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1132 Description: "cc_library_shared has correct features when integer_overflow property is provided",
1133 Blueprint: `
1134cc_library_shared {
1135 name: "foo",
1136 sanitize: {
1137 integer_overflow: true,
1138 },
1139}
1140`,
1141 ExpectedBazelTargets: []string{
1142 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1143 "features": `["ubsan_integer_overflow"]`,
1144 "local_includes": `["."]`,
1145 }),
1146 },
1147 })
1148}
1149
1150func TestCcLibrarySharedWithMiscUndefinedProperty(t *testing.T) {
1151 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1152 Description: "cc_library_shared has correct features when misc_undefined property is provided",
1153 Blueprint: `
1154cc_library_shared {
1155 name: "foo",
1156 sanitize: {
1157 misc_undefined: ["undefined", "nullability"],
1158 },
1159}
1160`,
1161 ExpectedBazelTargets: []string{
1162 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1163 "features": `[
1164 "ubsan_undefined",
1165 "ubsan_nullability",
1166 ]`,
1167 "local_includes": `["."]`,
1168 }),
1169 },
1170 })
1171}
1172
1173func TestCcLibrarySharedWithUBSanPropertiesArchSpecific(t *testing.T) {
1174 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1175 Description: "cc_library_shared has correct feature select when UBSan props are specified in arch specific blocks",
1176 Blueprint: `
1177cc_library_shared {
1178 name: "foo",
1179 sanitize: {
1180 misc_undefined: ["undefined", "nullability"],
1181 },
1182 target: {
1183 android: {
1184 sanitize: {
1185 misc_undefined: ["alignment"],
1186 },
1187 },
1188 linux_glibc: {
1189 sanitize: {
1190 integer_overflow: true,
1191 },
1192 },
1193 },
1194}
1195`,
1196 ExpectedBazelTargets: []string{
1197 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1198 "features": `[
1199 "ubsan_undefined",
1200 "ubsan_nullability",
1201 ] + select({
1202 "//build/bazel/platforms/os:android": ["ubsan_alignment"],
1203 "//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"],
1204 "//conditions:default": [],
1205 })`,
1206 "local_includes": `["."]`,
1207 }),
1208 },
1209 })
1210}
Trevor Radcliffe56b1a2b2023-02-06 21:58:30 +00001211
1212func TestCcLibrarySharedWithThinLto(t *testing.T) {
1213 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1214 Description: "cc_library_shared has correct features when thin lto is enabled",
1215 Blueprint: `
1216cc_library_shared {
1217 name: "foo",
1218 lto: {
1219 thin: true,
1220 },
1221}
1222`,
1223 ExpectedBazelTargets: []string{
1224 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1225 "features": `["android_thin_lto"]`,
1226 "local_includes": `["."]`,
1227 }),
1228 },
1229 })
1230}
1231
1232func TestCcLibrarySharedWithLtoNever(t *testing.T) {
1233 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1234 Description: "cc_library_shared has correct features when thin lto is enabled",
1235 Blueprint: `
1236cc_library_shared {
1237 name: "foo",
1238 lto: {
1239 never: true,
1240 },
1241}
1242`,
1243 ExpectedBazelTargets: []string{
1244 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1245 "features": `["-android_thin_lto"]`,
1246 "local_includes": `["."]`,
1247 }),
1248 },
1249 })
1250}
1251
1252func TestCcLibrarySharedWithThinLtoArchSpecific(t *testing.T) {
1253 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1254 Description: "cc_library_shared has correct features when LTO differs across arch and os variants",
1255 Blueprint: `
1256cc_library_shared {
1257 name: "foo",
1258 target: {
1259 android: {
1260 lto: {
1261 thin: true,
1262 },
1263 },
1264 },
1265 arch: {
1266 riscv64: {
1267 lto: {
1268 thin: false,
1269 },
1270 },
1271 },
1272}`,
1273 ExpectedBazelTargets: []string{
1274 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1275 "local_includes": `["."]`,
1276 "features": `select({
1277 "//build/bazel/platforms/os_arch:android_arm": ["android_thin_lto"],
1278 "//build/bazel/platforms/os_arch:android_arm64": ["android_thin_lto"],
1279 "//build/bazel/platforms/os_arch:android_riscv64": ["-android_thin_lto"],
1280 "//build/bazel/platforms/os_arch:android_x86": ["android_thin_lto"],
1281 "//build/bazel/platforms/os_arch:android_x86_64": ["android_thin_lto"],
1282 "//conditions:default": [],
1283 })`}),
1284 },
1285 })
1286}
1287
1288func TestCcLibrarySharedWithThinLtoDisabledDefaultEnabledVariant(t *testing.T) {
1289 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1290 Description: "cc_library_shared with thin lto disabled by default but enabled on a particular variant",
1291 Blueprint: `
1292cc_library_shared {
1293 name: "foo",
1294 lto: {
1295 never: true,
1296 },
1297 target: {
1298 android: {
1299 lto: {
1300 thin: true,
1301 never: false,
1302 },
1303 },
1304 },
1305}`,
1306 ExpectedBazelTargets: []string{
1307 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1308 "local_includes": `["."]`,
1309 "features": `select({
1310 "//build/bazel/platforms/os:android": ["android_thin_lto"],
1311 "//conditions:default": ["-android_thin_lto"],
1312 })`,
1313 }),
1314 },
1315 })
1316}
1317
1318func TestCcLibrarySharedWithThinLtoAndWholeProgramVtables(t *testing.T) {
1319 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1320 Description: "cc_library_shared has correct features when thin LTO is enabled with whole_program_vtables",
1321 Blueprint: `
1322cc_library_shared {
1323 name: "foo",
1324 lto: {
1325 thin: true,
1326 },
1327 whole_program_vtables: true,
1328}
1329`,
1330 ExpectedBazelTargets: []string{
1331 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1332 "features": `[
1333 "android_thin_lto",
1334 "android_thin_lto_whole_program_vtables",
1335 ]`,
1336 "local_includes": `["."]`,
1337 }),
1338 },
1339 })
1340}
Trevor Radcliffea8b44162023-04-14 18:25:24 +00001341
1342func TestCcLibrarySharedHiddenVisibilityConvertedToFeature(t *testing.T) {
1343 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1344 Description: "cc_library_shared changes hidden visibility flag to feature",
1345 Blueprint: `
1346cc_library_shared{
1347 name: "foo",
1348 cflags: ["-fvisibility=hidden"],
1349}`,
1350 ExpectedBazelTargets: []string{
1351 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1352 "features": `["visibility_hidden"]`,
1353 "local_includes": `["."]`,
1354 }),
1355 },
1356 })
1357}
1358
1359func TestCcLibrarySharedHiddenVisibilityConvertedToFeatureOsSpecific(t *testing.T) {
1360 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1361 Description: "cc_library_shared changes hidden visibility flag to feature for specific os",
1362 Blueprint: `
1363cc_library_shared{
1364 name: "foo",
1365 target: {
1366 android: {
1367 cflags: ["-fvisibility=hidden"],
1368 },
1369 },
1370}`,
1371 ExpectedBazelTargets: []string{
1372 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1373 "features": `select({
1374 "//build/bazel/platforms/os:android": ["visibility_hidden"],
1375 "//conditions:default": [],
1376 })`,
1377 "local_includes": `["."]`,
1378 }),
1379 },
1380 })
1381}
Sam Delmerico75dbca22023-04-20 13:13:25 +00001382
1383func TestCcLibrarySharedStubsDessertVersionConversion(t *testing.T) {
1384 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1385 Description: "cc_library_shared converts dessert codename versions to numerical versions",
1386 Blueprint: `
1387cc_library_shared {
1388 name: "a",
1389 include_build_directory: false,
1390 stubs: {
1391 symbol_file: "a.map.txt",
1392 versions: [
1393 "Q",
1394 "R",
1395 "31",
1396 ],
1397 },
1398}
1399cc_library_shared {
1400 name: "b",
1401 include_build_directory: false,
1402 stubs: {
1403 symbol_file: "b.map.txt",
1404 versions: [
1405 "Q",
1406 "R",
1407 "31",
1408 "current",
1409 ],
1410 },
1411}
1412`,
1413 ExpectedBazelTargets: []string{
1414 makeCcStubSuiteTargets("a", AttrNameToString{
1415 "soname": `"a.so"`,
1416 "source_library_label": `"//:a"`,
1417 "stubs_symbol_file": `"a.map.txt"`,
1418 "stubs_versions": `[
1419 "29",
1420 "30",
1421 "31",
1422 "current",
1423 ]`,
1424 }),
1425 MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
1426 "stubs_symbol_file": `"a.map.txt"`,
1427 }),
1428 makeCcStubSuiteTargets("b", AttrNameToString{
1429 "soname": `"b.so"`,
1430 "source_library_label": `"//:b"`,
1431 "stubs_symbol_file": `"b.map.txt"`,
1432 "stubs_versions": `[
1433 "29",
1434 "30",
1435 "31",
1436 "current",
1437 ]`,
1438 }),
1439 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
1440 "stubs_symbol_file": `"b.map.txt"`,
1441 }),
1442 },
1443 })
1444}