blob: 8e0a728ab6dbc38f1be4247c4b57fc9aaecedf3d [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()
Sam Delmerico3177a6e2022-06-21 19:28:33 +000039 (&tc).ModuleTypeUnderTest = "cc_library_shared"
40 (&tc).ModuleTypeUnderTestFactory = cc.LibrarySharedFactory
41 RunBp2BuildTestCase(t, registerCcLibrarySharedModuleTypes, tc)
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000042}
43
44func TestCcLibrarySharedSimple(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000045 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
46 Description: "cc_library_shared simple overall test",
47 Filesystem: map[string]string{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000048 // NOTE: include_dir headers *should not* appear in Bazel hdrs later (?)
49 "include_dir_1/include_dir_1_a.h": "",
50 "include_dir_1/include_dir_1_b.h": "",
51 "include_dir_2/include_dir_2_a.h": "",
52 "include_dir_2/include_dir_2_b.h": "",
53 // NOTE: local_include_dir headers *should not* appear in Bazel hdrs later (?)
54 "local_include_dir_1/local_include_dir_1_a.h": "",
55 "local_include_dir_1/local_include_dir_1_b.h": "",
56 "local_include_dir_2/local_include_dir_2_a.h": "",
57 "local_include_dir_2/local_include_dir_2_b.h": "",
58 // NOTE: export_include_dir headers *should* appear in Bazel hdrs later
59 "export_include_dir_1/export_include_dir_1_a.h": "",
60 "export_include_dir_1/export_include_dir_1_b.h": "",
61 "export_include_dir_2/export_include_dir_2_a.h": "",
62 "export_include_dir_2/export_include_dir_2_b.h": "",
63 // NOTE: Soong implicitly includes headers in the current directory
64 "implicit_include_1.h": "",
65 "implicit_include_2.h": "",
66 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +000067 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000068cc_library_headers {
69 name: "header_lib_1",
70 export_include_dirs: ["header_lib_1"],
71 bazel_module: { bp2build_available: false },
72}
73
74cc_library_headers {
75 name: "header_lib_2",
76 export_include_dirs: ["header_lib_2"],
77 bazel_module: { bp2build_available: false },
78}
79
80cc_library_shared {
81 name: "shared_lib_1",
82 srcs: ["shared_lib_1.cc"],
83 bazel_module: { bp2build_available: false },
84}
85
86cc_library_shared {
87 name: "shared_lib_2",
88 srcs: ["shared_lib_2.cc"],
89 bazel_module: { bp2build_available: false },
90}
91
92cc_library_static {
93 name: "whole_static_lib_1",
94 srcs: ["whole_static_lib_1.cc"],
95 bazel_module: { bp2build_available: false },
96}
97
98cc_library_static {
99 name: "whole_static_lib_2",
100 srcs: ["whole_static_lib_2.cc"],
101 bazel_module: { bp2build_available: false },
102}
103
104cc_library_shared {
105 name: "foo_shared",
106 srcs: [
107 "foo_shared1.cc",
108 "foo_shared2.cc",
109 ],
110 cflags: [
111 "-Dflag1",
112 "-Dflag2"
113 ],
114 shared_libs: [
115 "shared_lib_1",
116 "shared_lib_2"
117 ],
118 whole_static_libs: [
119 "whole_static_lib_1",
120 "whole_static_lib_2"
121 ],
122 include_dirs: [
123 "include_dir_1",
124 "include_dir_2",
125 ],
126 local_include_dirs: [
127 "local_include_dir_1",
128 "local_include_dir_2",
129 ],
130 export_include_dirs: [
131 "export_include_dir_1",
132 "export_include_dir_2"
133 ],
134 header_libs: [
135 "header_lib_1",
136 "header_lib_2"
137 ],
Yu Liufc603162022-03-01 15:44:08 -0800138 sdk_version: "current",
139 min_sdk_version: "29",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000140
141 // TODO: Also support export_header_lib_headers
142}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000143 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000144 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500145 "absolute_includes": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000146 "include_dir_1",
147 "include_dir_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500148 ]`,
149 "copts": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000150 "-Dflag1",
151 "-Dflag2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500152 ]`,
153 "export_includes": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000154 "export_include_dir_1",
155 "export_include_dir_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500156 ]`,
157 "implementation_deps": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000158 ":header_lib_1",
159 ":header_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500160 ]`,
161 "implementation_dynamic_deps": `[
Liz Kammer7a210ac2021-09-22 15:52:58 -0400162 ":shared_lib_1",
163 ":shared_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500164 ]`,
165 "local_includes": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000166 "local_include_dir_1",
167 "local_include_dir_2",
168 ".",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500169 ]`,
170 "srcs": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000171 "foo_shared1.cc",
172 "foo_shared2.cc",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500173 ]`,
174 "whole_archive_deps": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000175 ":whole_static_lib_1",
176 ":whole_static_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500177 ]`,
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000178 "sdk_version": `"current"`,
179 "min_sdk_version": `"29"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500180 }),
181 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000182 })
183}
184
185func TestCcLibrarySharedArchSpecificSharedLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000186 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
187 Description: "cc_library_shared arch-specific shared_libs with whole_static_libs",
188 Filesystem: map[string]string{},
189 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000190cc_library_static {
191 name: "static_dep",
192 bazel_module: { bp2build_available: false },
193}
194cc_library_shared {
195 name: "shared_dep",
196 bazel_module: { bp2build_available: false },
197}
198cc_library_shared {
199 name: "foo_shared",
200 arch: { arm64: { shared_libs: ["shared_dep"], whole_static_libs: ["static_dep"] } },
201 include_build_directory: false,
202}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000203 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000204 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500205 "implementation_dynamic_deps": `select({
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000206 "//build/bazel/platforms/arch:arm64": [":shared_dep"],
207 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500208 })`,
209 "whole_archive_deps": `select({
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000210 "//build/bazel/platforms/arch:arm64": [":static_dep"],
211 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500212 })`,
213 }),
214 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000215 })
216}
217
218func TestCcLibrarySharedOsSpecificSharedLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000219 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
220 Description: "cc_library_shared os-specific shared_libs",
221 Filesystem: map[string]string{},
222 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000223cc_library_shared {
224 name: "shared_dep",
225 bazel_module: { bp2build_available: false },
226}
227cc_library_shared {
228 name: "foo_shared",
229 target: { android: { shared_libs: ["shared_dep"], } },
230 include_build_directory: false,
231}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000232 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000233 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500234 "implementation_dynamic_deps": `select({
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000235 "//build/bazel/platforms/os:android": [":shared_dep"],
236 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500237 })`,
238 }),
239 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000240 })
241}
242
243func TestCcLibrarySharedBaseArchOsSpecificSharedLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000244 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
245 Description: "cc_library_shared base, arch, and os-specific shared_libs",
246 Filesystem: map[string]string{},
247 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000248cc_library_shared {
249 name: "shared_dep",
250 bazel_module: { bp2build_available: false },
251}
252cc_library_shared {
253 name: "shared_dep2",
254 bazel_module: { bp2build_available: false },
255}
256cc_library_shared {
257 name: "shared_dep3",
258 bazel_module: { bp2build_available: false },
259}
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 ]`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500364 }),
365 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000366 })
367}
Jingwen Chen6ada5892021-09-17 11:38:09 +0000368
Trevor Radcliffeea6a45d2022-09-20 18:58:01 +0000369func TestCcLibraryLdflagsSplitBySpaceSoongAdded(t *testing.T) {
370 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
371 Description: "ldflags are split by spaces except for the ones added by soong (version script and dynamic list)",
372 Filesystem: map[string]string{
373 "version_script": "",
374 "dynamic.list": "",
375 },
376 Blueprint: `
377cc_library_shared {
378 name: "foo",
379 ldflags: [
380 "--nospace_flag",
381 "-z spaceflag",
382 ],
383 version_script: "version_script",
384 dynamic_list: "dynamic.list",
385 include_build_directory: false,
386}`,
387 ExpectedBazelTargets: []string{
388 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
389 "additional_linker_inputs": `[
390 "version_script",
391 "dynamic.list",
392 ]`,
393 "linkopts": `[
394 "--nospace_flag",
395 "-z",
396 "spaceflag",
397 "-Wl,--version-script,$(location version_script)",
398 "-Wl,--dynamic-list,$(location dynamic.list)",
399 ]`,
400 }),
401 },
402 })
403}
404
Jingwen Chen6ada5892021-09-17 11:38:09 +0000405func TestCcLibrarySharedNoCrtTrue(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000406 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux01ec55e2023-01-30 22:53:04 +0000407 Description: "cc_library_shared - nocrt: true disables feature",
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000408 Filesystem: map[string]string{
Jingwen Chen6ada5892021-09-17 11:38:09 +0000409 "impl.cpp": "",
410 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000411 Blueprint: soongCcLibraryPreamble + `
Jingwen Chen6ada5892021-09-17 11:38:09 +0000412cc_library_shared {
413 name: "foo_shared",
414 srcs: ["impl.cpp"],
415 nocrt: true,
416 include_build_directory: false,
417}
418`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000419 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000420 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux01ec55e2023-01-30 22:53:04 +0000421 "features": `["-link_crt"]`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500422 "srcs": `["impl.cpp"]`,
423 }),
424 },
425 })
Jingwen Chen6ada5892021-09-17 11:38:09 +0000426}
427
428func TestCcLibrarySharedNoCrtFalse(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000429 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux01ec55e2023-01-30 22:53:04 +0000430 Description: "cc_library_shared - nocrt: false doesn't disable feature",
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000431 Filesystem: map[string]string{
Jingwen Chen6ada5892021-09-17 11:38:09 +0000432 "impl.cpp": "",
433 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000434 Blueprint: soongCcLibraryPreamble + `
Jingwen Chen6ada5892021-09-17 11:38:09 +0000435cc_library_shared {
436 name: "foo_shared",
437 srcs: ["impl.cpp"],
438 nocrt: false,
439 include_build_directory: false,
440}
441`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000442 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000443 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500444 "srcs": `["impl.cpp"]`,
445 }),
446 },
447 })
Jingwen Chen6ada5892021-09-17 11:38:09 +0000448}
449
450func TestCcLibrarySharedNoCrtArchVariant(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000451 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
452 Description: "cc_library_shared - nocrt in select",
453 Filesystem: map[string]string{
Jingwen Chen6ada5892021-09-17 11:38:09 +0000454 "impl.cpp": "",
455 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000456 Blueprint: soongCcLibraryPreamble + `
Jingwen Chen6ada5892021-09-17 11:38:09 +0000457cc_library_shared {
458 name: "foo_shared",
459 srcs: ["impl.cpp"],
460 arch: {
461 arm: {
462 nocrt: true,
463 },
464 x86: {
465 nocrt: false,
466 },
467 },
468 include_build_directory: false,
469}
470`,
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux01ec55e2023-01-30 22:53:04 +0000471 ExpectedBazelTargets: []string{
472 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
473 "features": `select({
474 "//build/bazel/platforms/arch:arm": ["-link_crt"],
475 "//conditions:default": [],
476 })`,
477 "srcs": `["impl.cpp"]`,
478 }),
479 },
Jingwen Chen6ada5892021-09-17 11:38:09 +0000480 })
481}
Liz Kammer12615db2021-09-28 09:19:17 -0400482
483func TestCcLibrarySharedProto(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000484 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
485 Blueprint: soongCcProtoPreamble + `cc_library_shared {
Liz Kammer12615db2021-09-28 09:19:17 -0400486 name: "foo",
487 srcs: ["foo.proto"],
488 proto: {
Liz Kammer12615db2021-09-28 09:19:17 -0400489 export_proto_headers: true,
490 },
491 include_build_directory: false,
492}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000493 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000494 MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -0400495 "srcs": `["foo.proto"]`,
Alixe06d75b2022-08-31 18:28:19 +0000496 }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -0400497 "deps": `[":foo_proto"]`,
Alixe06d75b2022-08-31 18:28:19 +0000498 }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -0400499 "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
500 "whole_archive_deps": `[":foo_cc_proto_lite"]`,
501 }),
502 },
503 })
504}
Rupert Shuttleworth484aa252021-12-10 07:22:53 -0500505
506func TestCcLibrarySharedUseVersionLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000507 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Liz Kammerbaced712022-09-16 09:01:29 -0400508 Filesystem: map[string]string{
509 soongCcVersionLibBpPath: soongCcVersionLibBp,
510 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000511 Blueprint: soongCcProtoPreamble + `cc_library_shared {
Rupert Shuttleworth484aa252021-12-10 07:22:53 -0500512 name: "foo",
513 use_version_lib: true,
514 include_build_directory: false,
515}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000516 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000517 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Liz Kammerbaced712022-09-16 09:01:29 -0400518 "use_version_lib": "True",
519 "implementation_whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
Rupert Shuttleworth484aa252021-12-10 07:22:53 -0500520 }),
521 },
522 })
523}
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000524
525func TestCcLibrarySharedStubs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000526 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
527 Description: "cc_library_shared stubs",
528 ModuleTypeUnderTest: "cc_library_shared",
529 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
530 Dir: "foo/bar",
531 Filesystem: map[string]string{
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000532 "foo/bar/Android.bp": `
533cc_library_shared {
534 name: "a",
535 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
536 bazel_module: { bp2build_available: true },
537 include_build_directory: false,
538}
539`,
540 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000541 Blueprint: soongCcLibraryPreamble,
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000542 ExpectedBazelTargets: []string{makeCcStubSuiteTargets("a", AttrNameToString{
Sam Delmerico5f906492023-03-15 18:06:18 -0400543 "soname": `"a.so"`,
544 "source_library_label": `"//foo/bar:a"`,
545 "stubs_symbol_file": `"a.map.txt"`,
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000546 "stubs_versions": `[
Trevor Radcliffe087af542022-09-16 15:36:10 +0000547 "28",
548 "29",
549 "current",
550 ]`,
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000551 }),
552 MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
Yu Liu56ccb1a2022-11-12 10:47:07 -0800553 "stubs_symbol_file": `"a.map.txt"`,
Trevor Radcliffe087af542022-09-16 15:36:10 +0000554 }),
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000555 },
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000556 })
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000557}
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000558
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400559func TestCcLibrarySharedStubs_UseImplementationInSameApex(t *testing.T) {
560 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
561 Description: "cc_library_shared stubs",
562 ModuleTypeUnderTest: "cc_library_shared",
563 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
564 Blueprint: soongCcLibrarySharedPreamble + `
565cc_library_shared {
566 name: "a",
567 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
568 bazel_module: { bp2build_available: false },
569 include_build_directory: false,
570 apex_available: ["made_up_apex"],
571}
572cc_library_shared {
573 name: "b",
574 shared_libs: [":a"],
575 include_build_directory: false,
576 apex_available: ["made_up_apex"],
577}
578`,
579 ExpectedBazelTargets: []string{
580 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
581 "implementation_dynamic_deps": `[":a"]`,
582 "tags": `["apex_available=made_up_apex"]`,
583 }),
584 },
585 })
586}
587
588func TestCcLibrarySharedStubs_UseStubsInDifferentApex(t *testing.T) {
589 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
590 Description: "cc_library_shared stubs",
591 ModuleTypeUnderTest: "cc_library_shared",
592 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
593 Blueprint: soongCcLibrarySharedPreamble + `
594cc_library_shared {
595 name: "a",
596 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
597 bazel_module: { bp2build_available: false },
598 include_build_directory: false,
599 apex_available: ["apex_a"],
600}
601cc_library_shared {
602 name: "b",
603 shared_libs: [":a"],
604 include_build_directory: false,
605 apex_available: ["apex_b"],
606}
607`,
608 ExpectedBazelTargets: []string{
609 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
610 "implementation_dynamic_deps": `select({
611 "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:a"],
612 "//conditions:default": [":a"],
613 })`,
614 "tags": `["apex_available=apex_b"]`,
615 }),
616 },
617 })
618}
619
620func TestCcLibrarySharedStubs_IgnorePlatformAvailable(t *testing.T) {
621 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
622 Description: "cc_library_shared stubs",
623 ModuleTypeUnderTest: "cc_library_shared",
624 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
625 Blueprint: soongCcLibrarySharedPreamble + `
626cc_library_shared {
627 name: "a",
628 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
629 bazel_module: { bp2build_available: false },
630 include_build_directory: false,
631 apex_available: ["//apex_available:platform", "apex_a"],
632}
633cc_library_shared {
634 name: "b",
635 shared_libs: [":a"],
636 include_build_directory: false,
637 apex_available: ["//apex_available:platform", "apex_b"],
638}
639`,
640 ExpectedBazelTargets: []string{
641 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
642 "implementation_dynamic_deps": `select({
643 "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:a"],
644 "//conditions:default": [":a"],
645 })`,
646 "tags": `[
647 "apex_available=//apex_available:platform",
648 "apex_available=apex_b",
649 ]`,
650 }),
651 },
652 })
653}
654
655func TestCcLibrarySharedStubs_MultipleApexAvailable(t *testing.T) {
656 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
657 ModuleTypeUnderTest: "cc_library_shared",
658 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
659 Blueprint: soongCcLibrarySharedPreamble + `
660cc_library_shared {
661 name: "a",
662 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
663 bazel_module: { bp2build_available: false },
664 include_build_directory: false,
665 apex_available: ["//apex_available:platform", "apex_a", "apex_b"],
666}
667cc_library_shared {
668 name: "b",
669 shared_libs: [":a"],
670 include_build_directory: false,
671 apex_available: ["//apex_available:platform", "apex_b"],
672}
673
674cc_library_shared {
675 name: "c",
676 shared_libs: [":a"],
677 include_build_directory: false,
678 apex_available: ["//apex_available:platform", "apex_a", "apex_b"],
679}
680`,
681 ExpectedBazelTargets: []string{
682 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
683 "implementation_dynamic_deps": `select({
684 "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:a"],
685 "//conditions:default": [":a"],
686 })`,
687 "tags": `[
688 "apex_available=//apex_available:platform",
689 "apex_available=apex_b",
690 ]`,
691 }),
692 MakeBazelTarget("cc_library_shared", "c", AttrNameToString{
693 "implementation_dynamic_deps": `[":a"]`,
694 "tags": `[
695 "apex_available=//apex_available:platform",
696 "apex_available=apex_a",
697 "apex_available=apex_b",
698 ]`,
699 }),
700 },
701 })
702}
703
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000704func TestCcLibrarySharedSystemSharedLibsSharedEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000705 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
706 Description: "cc_library_shared system_shared_libs empty shared default",
707 ModuleTypeUnderTest: "cc_library_shared",
708 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
709 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000710cc_defaults {
711 name: "empty_defaults",
712 shared: {
713 system_shared_libs: [],
714 },
715 include_build_directory: false,
716}
717cc_library_shared {
718 name: "empty",
719 defaults: ["empty_defaults"],
720}
721`,
Alixe06d75b2022-08-31 18:28:19 +0000722 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 +0000723 "system_dynamic_deps": "[]",
724 })},
725 })
726}
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000727
728func TestCcLibrarySharedConvertLex(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000729 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
730 Description: "cc_library_shared with lex files",
731 ModuleTypeUnderTest: "cc_library_shared",
732 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
733 Filesystem: map[string]string{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000734 "foo.c": "",
735 "bar.cc": "",
736 "foo1.l": "",
737 "bar1.ll": "",
738 "foo2.l": "",
739 "bar2.ll": "",
740 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000741 Blueprint: `cc_library_shared {
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000742 name: "foo_lib",
743 srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"],
744 lex: { flags: ["--foo_flags"] },
745 include_build_directory: false,
746 bazel_module: { bp2build_available: true },
747}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000748 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000749 MakeBazelTarget("genlex", "foo_lib_genlex_l", AttrNameToString{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000750 "srcs": `[
751 "foo1.l",
752 "foo2.l",
753 ]`,
754 "lexopts": `["--foo_flags"]`,
755 }),
Alixe06d75b2022-08-31 18:28:19 +0000756 MakeBazelTarget("genlex", "foo_lib_genlex_ll", AttrNameToString{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000757 "srcs": `[
758 "bar1.ll",
759 "bar2.ll",
760 ]`,
761 "lexopts": `["--foo_flags"]`,
762 }),
Alixe06d75b2022-08-31 18:28:19 +0000763 MakeBazelTarget("cc_library_shared", "foo_lib", AttrNameToString{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000764 "srcs": `[
765 "bar.cc",
766 ":foo_lib_genlex_ll",
767 ]`,
768 "srcs_c": `[
769 "foo.c",
770 ":foo_lib_genlex_l",
771 ]`,
772 }),
773 },
774 })
775}
Alix1be00d42022-05-16 22:56:04 +0000776
777func TestCcLibrarySharedClangUnknownFlags(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000778 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
779 Blueprint: soongCcProtoPreamble + `cc_library_shared {
Alix1be00d42022-05-16 22:56:04 +0000780 name: "foo",
781 conlyflags: ["-a", "-finline-functions"],
782 cflags: ["-b","-finline-functions"],
783 cppflags: ["-c", "-finline-functions"],
784 ldflags: ["-d","-finline-functions", "-e"],
785 include_build_directory: false,
786}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000787 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000788 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Alix1be00d42022-05-16 22:56:04 +0000789 "conlyflags": `["-a"]`,
790 "copts": `["-b"]`,
791 "cppflags": `["-c"]`,
792 "linkopts": `[
793 "-d",
794 "-e",
795 ]`,
796 }),
797 },
798 })
799}
800
801func TestCCLibraryFlagSpaceSplitting(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000802 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
803 Blueprint: soongCcProtoPreamble + `cc_library_shared {
Alix1be00d42022-05-16 22:56:04 +0000804 name: "foo",
805 conlyflags: [ "-include header.h"],
806 cflags: ["-include header.h"],
807 cppflags: ["-include header.h"],
808 version_script: "version_script",
809 include_build_directory: false,
810}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000811 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000812 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Alix1be00d42022-05-16 22:56:04 +0000813 "additional_linker_inputs": `["version_script"]`,
814 "conlyflags": `[
815 "-include",
816 "header.h",
817 ]`,
818 "copts": `[
819 "-include",
820 "header.h",
821 ]`,
822 "cppflags": `[
823 "-include",
824 "header.h",
825 ]`,
826 "linkopts": `["-Wl,--version-script,$(location version_script)"]`,
827 }),
828 },
829 })
830}
Cole Faust6b29f592022-08-09 09:50:56 -0700831
832func TestCCLibrarySharedRuntimeDeps(t *testing.T) {
833 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
834 Blueprint: `cc_library_shared {
835 name: "bar",
836}
837
838cc_library_shared {
839 name: "foo",
840 runtime_libs: ["foo"],
841}`,
842 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000843 MakeBazelTarget("cc_library_shared", "bar", AttrNameToString{
Cole Faust6b29f592022-08-09 09:50:56 -0700844 "local_includes": `["."]`,
845 }),
Alixe06d75b2022-08-31 18:28:19 +0000846 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Cole Faust6b29f592022-08-09 09:50:56 -0700847 "runtime_deps": `[":foo"]`,
848 "local_includes": `["."]`,
849 }),
850 },
851 })
852}
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -0500853
854func TestCcLibrarySharedEmptySuffix(t *testing.T) {
855 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
856 Description: "cc_library_shared with empty suffix",
857 Filesystem: map[string]string{
858 "foo.c": "",
859 },
860 Blueprint: soongCcLibrarySharedPreamble + `
861cc_library_shared {
862 name: "foo_shared",
863 suffix: "",
864 srcs: ["foo.c"],
865 include_build_directory: false,
866}`,
867 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000868 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -0500869 "srcs_c": `["foo.c"]`,
870 "suffix": `""`,
871 }),
872 },
873 })
874}
875
876func TestCcLibrarySharedSuffix(t *testing.T) {
877 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
878 Description: "cc_library_shared with suffix",
879 Filesystem: map[string]string{
880 "foo.c": "",
881 },
882 Blueprint: soongCcLibrarySharedPreamble + `
883cc_library_shared {
884 name: "foo_shared",
885 suffix: "-suf",
886 srcs: ["foo.c"],
887 include_build_directory: false,
888}`,
889 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000890 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -0500891 "srcs_c": `["foo.c"]`,
892 "suffix": `"-suf"`,
893 }),
894 },
895 })
896}
897
898func TestCcLibrarySharedArchVariantSuffix(t *testing.T) {
899 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
900 Description: "cc_library_shared with arch-variant suffix",
901 Filesystem: map[string]string{
902 "foo.c": "",
903 },
904 Blueprint: soongCcLibrarySharedPreamble + `
905cc_library_shared {
906 name: "foo_shared",
907 arch: {
908 arm64: { suffix: "-64" },
909 arm: { suffix: "-32" },
910 },
911 srcs: ["foo.c"],
912 include_build_directory: false,
913}`,
914 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000915 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -0500916 "srcs_c": `["foo.c"]`,
917 "suffix": `select({
918 "//build/bazel/platforms/arch:arm": "-32",
919 "//build/bazel/platforms/arch:arm64": "-64",
920 "//conditions:default": None,
921 })`,
922 }),
923 },
924 })
925}
Trevor Radcliffecee4e052022-09-06 19:31:25 +0000926
927func TestCcLibrarySharedWithSyspropSrcs(t *testing.T) {
928 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
929 Description: "cc_library_shared with sysprop sources",
930 Blueprint: `
931cc_library_shared {
932 name: "foo",
933 srcs: [
934 "bar.sysprop",
935 "baz.sysprop",
936 "blah.cpp",
937 ],
938 min_sdk_version: "5",
939}`,
940 ExpectedBazelTargets: []string{
941 MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
942 "srcs": `[
943 "bar.sysprop",
944 "baz.sysprop",
945 ]`,
946 }),
947 MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
948 "dep": `":foo_sysprop_library"`,
949 "min_sdk_version": `"5"`,
950 }),
951 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
952 "srcs": `["blah.cpp"]`,
953 "local_includes": `["."]`,
954 "min_sdk_version": `"5"`,
955 "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`,
956 }),
957 },
958 })
959}
960
961func TestCcLibrarySharedWithSyspropSrcsSomeConfigs(t *testing.T) {
962 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
963 Description: "cc_library_shared with sysprop sources in some configs but not others",
964 Blueprint: `
965cc_library_shared {
966 name: "foo",
967 srcs: [
968 "blah.cpp",
969 ],
970 target: {
971 android: {
972 srcs: ["bar.sysprop"],
973 },
974 },
975 min_sdk_version: "5",
976}`,
977 ExpectedBazelTargets: []string{
978 MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
979 "srcs": `select({
980 "//build/bazel/platforms/os:android": ["bar.sysprop"],
981 "//conditions:default": [],
982 })`,
983 }),
984 MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
985 "dep": `":foo_sysprop_library"`,
986 "min_sdk_version": `"5"`,
987 }),
988 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
989 "srcs": `["blah.cpp"]`,
990 "local_includes": `["."]`,
991 "min_sdk_version": `"5"`,
992 "whole_archive_deps": `select({
993 "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"],
994 "//conditions:default": [],
995 })`,
996 }),
997 },
998 })
999}
Yu Liu56ccb1a2022-11-12 10:47:07 -08001000
1001func TestCcLibrarySharedHeaderAbiChecker(t *testing.T) {
1002 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1003 Description: "cc_library_shared with header abi checker",
1004 Blueprint: `cc_library_shared {
1005 name: "foo",
1006 header_abi_checker: {
1007 enabled: true,
1008 symbol_file: "a.map.txt",
1009 exclude_symbol_versions: [
1010 "29",
1011 "30",
1012 ],
1013 exclude_symbol_tags: [
1014 "tag1",
1015 "tag2",
1016 ],
1017 check_all_apis: true,
1018 diff_flags: ["-allow-adding-removing-weak-symbols"],
1019 },
1020 include_build_directory: false,
1021}`,
1022 ExpectedBazelTargets: []string{
1023 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1024 "abi_checker_enabled": `True`,
1025 "abi_checker_symbol_file": `"a.map.txt"`,
1026 "abi_checker_exclude_symbol_versions": `[
1027 "29",
1028 "30",
1029 ]`,
1030 "abi_checker_exclude_symbol_tags": `[
1031 "tag1",
1032 "tag2",
1033 ]`,
1034 "abi_checker_check_all_apis": `True`,
1035 "abi_checker_diff_flags": `["-allow-adding-removing-weak-symbols"]`,
1036 }),
1037 },
1038 })
1039}
Trevor Radcliffedb7e0262022-10-28 16:48:18 +00001040
1041func TestCcLibrarySharedWithIntegerOverflowProperty(t *testing.T) {
1042 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1043 Description: "cc_library_shared has correct features when integer_overflow property is provided",
1044 Blueprint: `
1045cc_library_shared {
1046 name: "foo",
1047 sanitize: {
1048 integer_overflow: true,
1049 },
1050}
1051`,
1052 ExpectedBazelTargets: []string{
1053 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1054 "features": `["ubsan_integer_overflow"]`,
1055 "local_includes": `["."]`,
1056 }),
1057 },
1058 })
1059}
1060
1061func TestCcLibrarySharedWithMiscUndefinedProperty(t *testing.T) {
1062 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1063 Description: "cc_library_shared has correct features when misc_undefined property is provided",
1064 Blueprint: `
1065cc_library_shared {
1066 name: "foo",
1067 sanitize: {
1068 misc_undefined: ["undefined", "nullability"],
1069 },
1070}
1071`,
1072 ExpectedBazelTargets: []string{
1073 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1074 "features": `[
1075 "ubsan_undefined",
1076 "ubsan_nullability",
1077 ]`,
1078 "local_includes": `["."]`,
1079 }),
1080 },
1081 })
1082}
1083
1084func TestCcLibrarySharedWithUBSanPropertiesArchSpecific(t *testing.T) {
1085 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1086 Description: "cc_library_shared has correct feature select when UBSan props are specified in arch specific blocks",
1087 Blueprint: `
1088cc_library_shared {
1089 name: "foo",
1090 sanitize: {
1091 misc_undefined: ["undefined", "nullability"],
1092 },
1093 target: {
1094 android: {
1095 sanitize: {
1096 misc_undefined: ["alignment"],
1097 },
1098 },
1099 linux_glibc: {
1100 sanitize: {
1101 integer_overflow: true,
1102 },
1103 },
1104 },
1105}
1106`,
1107 ExpectedBazelTargets: []string{
1108 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1109 "features": `[
1110 "ubsan_undefined",
1111 "ubsan_nullability",
1112 ] + select({
1113 "//build/bazel/platforms/os:android": ["ubsan_alignment"],
1114 "//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"],
1115 "//conditions:default": [],
1116 })`,
1117 "local_includes": `["."]`,
1118 }),
1119 },
1120 })
1121}
Trevor Radcliffe56b1a2b2023-02-06 21:58:30 +00001122
1123func TestCcLibrarySharedWithThinLto(t *testing.T) {
1124 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1125 Description: "cc_library_shared has correct features when thin lto is enabled",
1126 Blueprint: `
1127cc_library_shared {
1128 name: "foo",
1129 lto: {
1130 thin: true,
1131 },
1132}
1133`,
1134 ExpectedBazelTargets: []string{
1135 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1136 "features": `["android_thin_lto"]`,
1137 "local_includes": `["."]`,
1138 }),
1139 },
1140 })
1141}
1142
1143func TestCcLibrarySharedWithLtoNever(t *testing.T) {
1144 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1145 Description: "cc_library_shared has correct features when thin lto is enabled",
1146 Blueprint: `
1147cc_library_shared {
1148 name: "foo",
1149 lto: {
1150 never: true,
1151 },
1152}
1153`,
1154 ExpectedBazelTargets: []string{
1155 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1156 "features": `["-android_thin_lto"]`,
1157 "local_includes": `["."]`,
1158 }),
1159 },
1160 })
1161}
1162
1163func TestCcLibrarySharedWithThinLtoArchSpecific(t *testing.T) {
1164 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1165 Description: "cc_library_shared has correct features when LTO differs across arch and os variants",
1166 Blueprint: `
1167cc_library_shared {
1168 name: "foo",
1169 target: {
1170 android: {
1171 lto: {
1172 thin: true,
1173 },
1174 },
1175 },
1176 arch: {
1177 riscv64: {
1178 lto: {
1179 thin: false,
1180 },
1181 },
1182 },
1183}`,
1184 ExpectedBazelTargets: []string{
1185 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1186 "local_includes": `["."]`,
1187 "features": `select({
1188 "//build/bazel/platforms/os_arch:android_arm": ["android_thin_lto"],
1189 "//build/bazel/platforms/os_arch:android_arm64": ["android_thin_lto"],
1190 "//build/bazel/platforms/os_arch:android_riscv64": ["-android_thin_lto"],
1191 "//build/bazel/platforms/os_arch:android_x86": ["android_thin_lto"],
1192 "//build/bazel/platforms/os_arch:android_x86_64": ["android_thin_lto"],
1193 "//conditions:default": [],
1194 })`}),
1195 },
1196 })
1197}
1198
1199func TestCcLibrarySharedWithThinLtoDisabledDefaultEnabledVariant(t *testing.T) {
1200 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1201 Description: "cc_library_shared with thin lto disabled by default but enabled on a particular variant",
1202 Blueprint: `
1203cc_library_shared {
1204 name: "foo",
1205 lto: {
1206 never: true,
1207 },
1208 target: {
1209 android: {
1210 lto: {
1211 thin: true,
1212 never: false,
1213 },
1214 },
1215 },
1216}`,
1217 ExpectedBazelTargets: []string{
1218 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1219 "local_includes": `["."]`,
1220 "features": `select({
1221 "//build/bazel/platforms/os:android": ["android_thin_lto"],
1222 "//conditions:default": ["-android_thin_lto"],
1223 })`,
1224 }),
1225 },
1226 })
1227}
1228
1229func TestCcLibrarySharedWithThinLtoAndWholeProgramVtables(t *testing.T) {
1230 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1231 Description: "cc_library_shared has correct features when thin LTO is enabled with whole_program_vtables",
1232 Blueprint: `
1233cc_library_shared {
1234 name: "foo",
1235 lto: {
1236 thin: true,
1237 },
1238 whole_program_vtables: true,
1239}
1240`,
1241 ExpectedBazelTargets: []string{
1242 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1243 "features": `[
1244 "android_thin_lto",
1245 "android_thin_lto_whole_program_vtables",
1246 ]`,
1247 "local_includes": `["."]`,
1248 }),
1249 },
1250 })
1251}