blob: 2c5305f721c474ffa5b755706978ee7db8a68a40 [file] [log] [blame]
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +00001// Copyright 2021 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package bp2build
16
17import (
18 "testing"
19
20 "android/soong/android"
21 "android/soong/cc"
22)
23
24const (
25 // See cc/testing.go for more context
26 // TODO(alexmarquez): Split out the preamble into common code?
27 soongCcLibrarySharedPreamble = soongCcLibraryStaticPreamble
28)
29
30func registerCcLibrarySharedModuleTypes(ctx android.RegistrationContext) {
31 cc.RegisterCCBuildComponents(ctx)
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000032 ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
33 ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory)
Liz Kammer12615db2021-09-28 09:19:17 -040034 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
Spandan Das1f65f9e2023-09-15 01:08:23 +000035 ctx.RegisterModuleType("ndk_library", cc.NdkLibraryFactory)
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000036}
37
Sam Delmerico3177a6e2022-06-21 19:28:33 +000038func runCcLibrarySharedTestCase(t *testing.T, tc Bp2buildTestCase) {
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000039 t.Helper()
Alex Márquez Pérez Muñíz Díaz Puras Thaureauxc641cc42023-03-16 17:03:43 +000040 t.Parallel()
Chris Parsonscd209032023-09-19 01:12:48 +000041 tc.StubbedBuildDefinitions = append(tc.StubbedBuildDefinitions, "libbuildversion", "libprotobuf-cpp-lite", "libprotobuf-cpp-full")
Sam Delmerico3177a6e2022-06-21 19:28:33 +000042 (&tc).ModuleTypeUnderTest = "cc_library_shared"
43 (&tc).ModuleTypeUnderTestFactory = cc.LibrarySharedFactory
44 RunBp2BuildTestCase(t, registerCcLibrarySharedModuleTypes, tc)
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000045}
46
47func TestCcLibrarySharedSimple(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000048 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +000049 Description: "cc_library_shared simple overall test",
50 StubbedBuildDefinitions: []string{"header_lib_1", "header_lib_2", "whole_static_lib_1", "whole_static_lib_2", "shared_lib_1", "shared_lib_2"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +000051 Filesystem: map[string]string{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000052 // NOTE: include_dir headers *should not* appear in Bazel hdrs later (?)
53 "include_dir_1/include_dir_1_a.h": "",
54 "include_dir_1/include_dir_1_b.h": "",
55 "include_dir_2/include_dir_2_a.h": "",
56 "include_dir_2/include_dir_2_b.h": "",
57 // NOTE: local_include_dir headers *should not* appear in Bazel hdrs later (?)
58 "local_include_dir_1/local_include_dir_1_a.h": "",
59 "local_include_dir_1/local_include_dir_1_b.h": "",
60 "local_include_dir_2/local_include_dir_2_a.h": "",
61 "local_include_dir_2/local_include_dir_2_b.h": "",
62 // NOTE: export_include_dir headers *should* appear in Bazel hdrs later
63 "export_include_dir_1/export_include_dir_1_a.h": "",
64 "export_include_dir_1/export_include_dir_1_b.h": "",
65 "export_include_dir_2/export_include_dir_2_a.h": "",
66 "export_include_dir_2/export_include_dir_2_b.h": "",
67 // NOTE: Soong implicitly includes headers in the current directory
68 "implicit_include_1.h": "",
69 "implicit_include_2.h": "",
70 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +000071 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000072cc_library_headers {
73 name: "header_lib_1",
74 export_include_dirs: ["header_lib_1"],
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000075}
76
77cc_library_headers {
78 name: "header_lib_2",
79 export_include_dirs: ["header_lib_2"],
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000080}
81
82cc_library_shared {
83 name: "shared_lib_1",
84 srcs: ["shared_lib_1.cc"],
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000085}
86
87cc_library_shared {
88 name: "shared_lib_2",
89 srcs: ["shared_lib_2.cc"],
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000090}
91
92cc_library_static {
93 name: "whole_static_lib_1",
94 srcs: ["whole_static_lib_1.cc"],
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000095}
96
97cc_library_static {
98 name: "whole_static_lib_2",
99 srcs: ["whole_static_lib_2.cc"],
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000100}
101
102cc_library_shared {
103 name: "foo_shared",
104 srcs: [
105 "foo_shared1.cc",
106 "foo_shared2.cc",
107 ],
108 cflags: [
109 "-Dflag1",
110 "-Dflag2"
111 ],
112 shared_libs: [
113 "shared_lib_1",
114 "shared_lib_2"
115 ],
116 whole_static_libs: [
117 "whole_static_lib_1",
118 "whole_static_lib_2"
119 ],
120 include_dirs: [
121 "include_dir_1",
122 "include_dir_2",
123 ],
124 local_include_dirs: [
125 "local_include_dir_1",
126 "local_include_dir_2",
127 ],
128 export_include_dirs: [
129 "export_include_dir_1",
130 "export_include_dir_2"
131 ],
132 header_libs: [
133 "header_lib_1",
134 "header_lib_2"
135 ],
Yu Liufc603162022-03-01 15:44:08 -0800136 sdk_version: "current",
137 min_sdk_version: "29",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000138
139 // TODO: Also support export_header_lib_headers
140}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000141 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000142 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500143 "absolute_includes": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000144 "include_dir_1",
145 "include_dir_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500146 ]`,
147 "copts": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000148 "-Dflag1",
149 "-Dflag2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500150 ]`,
151 "export_includes": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000152 "export_include_dir_1",
153 "export_include_dir_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500154 ]`,
155 "implementation_deps": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000156 ":header_lib_1",
157 ":header_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500158 ]`,
159 "implementation_dynamic_deps": `[
Liz Kammer7a210ac2021-09-22 15:52:58 -0400160 ":shared_lib_1",
161 ":shared_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500162 ]`,
163 "local_includes": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000164 "local_include_dir_1",
165 "local_include_dir_2",
166 ".",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500167 ]`,
168 "srcs": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000169 "foo_shared1.cc",
170 "foo_shared2.cc",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500171 ]`,
172 "whole_archive_deps": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000173 ":whole_static_lib_1",
174 ":whole_static_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500175 ]`,
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000176 "sdk_version": `"current"`,
177 "min_sdk_version": `"29"`,
Spandan Dasaf725832023-09-19 19:51:52 +0000178 "deps": `select({
179 "//build/bazel/rules/apex:unbundled_app": ["//build/bazel/rules/cc:ndk_sysroot"],
180 "//conditions:default": [],
181 })`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500182 }),
183 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000184 })
185}
186
187func TestCcLibrarySharedArchSpecificSharedLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000188 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +0000189 Description: "cc_library_shared arch-specific shared_libs with whole_static_libs",
190 Filesystem: map[string]string{},
191 StubbedBuildDefinitions: []string{"static_dep", "shared_dep"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000192 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000193cc_library_static {
194 name: "static_dep",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000195}
196cc_library_shared {
197 name: "shared_dep",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000198}
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{
Chris Parsons5011e612023-09-13 23:33:20 +0000221 StubbedBuildDefinitions: []string{"shared_dep"},
222 Description: "cc_library_shared os-specific shared_libs",
223 Filesystem: map[string]string{},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000224 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000225cc_library_shared {
226 name: "shared_dep",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000227}
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{
Chris Parsons5011e612023-09-13 23:33:20 +0000246 StubbedBuildDefinitions: []string{"shared_dep", "shared_dep2", "shared_dep3"},
247 Description: "cc_library_shared base, arch, and os-specific shared_libs",
248 Filesystem: map[string]string{},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000249 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000250cc_library_shared {
251 name: "shared_dep",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000252}
253cc_library_shared {
254 name: "shared_dep2",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000255}
256cc_library_shared {
257 name: "shared_dep3",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000258}
259cc_library_shared {
260 name: "foo_shared",
261 shared_libs: ["shared_dep"],
262 target: { android: { shared_libs: ["shared_dep2"] } },
263 arch: { arm64: { shared_libs: ["shared_dep3"] } },
264 include_build_directory: false,
265}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000266 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000267 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500268 "implementation_dynamic_deps": `[":shared_dep"] + select({
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000269 "//build/bazel/platforms/arch:arm64": [":shared_dep3"],
270 "//conditions:default": [],
271 }) + select({
272 "//build/bazel/platforms/os:android": [":shared_dep2"],
273 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500274 })`,
275 }),
276 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000277 })
278}
279
280func TestCcLibrarySharedSimpleExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000281 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
282 Description: "cc_library_shared simple exclude_srcs",
283 Filesystem: map[string]string{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000284 "common.c": "",
285 "foo-a.c": "",
286 "foo-excluded.c": "",
287 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000288 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000289cc_library_shared {
290 name: "foo_shared",
291 srcs: ["common.c", "foo-*.c"],
292 exclude_srcs: ["foo-excluded.c"],
293 include_build_directory: false,
294}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000295 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000296 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500297 "srcs_c": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000298 "common.c",
299 "foo-a.c",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500300 ]`,
301 }),
302 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000303 })
304}
305
306func TestCcLibrarySharedStrip(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000307 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
308 Description: "cc_library_shared stripping",
309 Filesystem: map[string]string{},
310 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000311cc_library_shared {
312 name: "foo_shared",
313 strip: {
314 keep_symbols: false,
315 keep_symbols_and_debug_frame: true,
316 keep_symbols_list: ["sym", "sym2"],
317 all: true,
318 none: false,
319 },
320 include_build_directory: false,
321}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000322 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000323 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500324 "strip": `{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000325 "all": True,
326 "keep_symbols": False,
327 "keep_symbols_and_debug_frame": True,
328 "keep_symbols_list": [
329 "sym",
330 "sym2",
331 ],
332 "none": False,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500333 }`,
334 }),
335 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000336 })
337}
338
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +0000339func TestCcLibrarySharedVersionScriptAndDynamicList(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000340 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +0000341 Description: "cc_library_shared version script and dynamic list",
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000342 Filesystem: map[string]string{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000343 "version_script": "",
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +0000344 "dynamic.list": "",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000345 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000346 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000347cc_library_shared {
348 name: "foo_shared",
349 version_script: "version_script",
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +0000350 dynamic_list: "dynamic.list",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000351 include_build_directory: false,
352}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000353 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000354 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +0000355 "additional_linker_inputs": `[
356 "version_script",
357 "dynamic.list",
358 ]`,
359 "linkopts": `[
360 "-Wl,--version-script,$(location version_script)",
361 "-Wl,--dynamic-list,$(location dynamic.list)",
362 ]`,
Trevor Radcliffef06dd912023-05-19 14:51:41 +0000363 "features": `["android_cfi_exports_map"]`,
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 ]`,
Trevor Radcliffef06dd912023-05-19 14:51:41 +0000400 "features": `["android_cfi_exports_map"]`,
Trevor Radcliffeea6a45d2022-09-20 18:58:01 +0000401 }),
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 },
Chris Parsonscd209032023-09-19 01:12:48 +0000512 StubbedBuildDefinitions: []string{"//build/soong/cc/libbuildversion:libbuildversion"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000513 Blueprint: soongCcProtoPreamble + `cc_library_shared {
Rupert Shuttleworth484aa252021-12-10 07:22:53 -0500514 name: "foo",
515 use_version_lib: true,
516 include_build_directory: false,
517}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000518 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000519 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Yu Liufe978fd2023-04-24 16:37:18 -0700520 "use_version_lib": "True",
521 "whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
Rupert Shuttleworth484aa252021-12-10 07:22:53 -0500522 }),
523 },
524 })
525}
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000526
527func TestCcLibrarySharedStubs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000528 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
529 Description: "cc_library_shared stubs",
530 ModuleTypeUnderTest: "cc_library_shared",
531 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
532 Dir: "foo/bar",
533 Filesystem: map[string]string{
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000534 "foo/bar/Android.bp": `
535cc_library_shared {
536 name: "a",
537 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
538 bazel_module: { bp2build_available: true },
539 include_build_directory: false,
540}
541`,
542 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000543 Blueprint: soongCcLibraryPreamble,
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000544 ExpectedBazelTargets: []string{makeCcStubSuiteTargets("a", AttrNameToString{
Spandan Das04f9f4c2023-09-13 23:59:05 +0000545 "api_surface": `"module-libapi"`,
Sam Delmerico5f906492023-03-15 18:06:18 -0400546 "soname": `"a.so"`,
547 "source_library_label": `"//foo/bar:a"`,
548 "stubs_symbol_file": `"a.map.txt"`,
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000549 "stubs_versions": `[
Trevor Radcliffe087af542022-09-16 15:36:10 +0000550 "28",
551 "29",
552 "current",
553 ]`,
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000554 }),
555 MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
Yu Liu56ccb1a2022-11-12 10:47:07 -0800556 "stubs_symbol_file": `"a.map.txt"`,
Trevor Radcliffe087af542022-09-16 15:36:10 +0000557 }),
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000558 },
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000559 })
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000560}
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000561
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400562func TestCcLibrarySharedStubs_UseImplementationInSameApex(t *testing.T) {
563 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
564 Description: "cc_library_shared stubs",
565 ModuleTypeUnderTest: "cc_library_shared",
566 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000567 StubbedBuildDefinitions: []string{"a"},
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400568 Blueprint: soongCcLibrarySharedPreamble + `
569cc_library_shared {
570 name: "a",
571 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400572 include_build_directory: false,
573 apex_available: ["made_up_apex"],
574}
575cc_library_shared {
576 name: "b",
577 shared_libs: [":a"],
578 include_build_directory: false,
579 apex_available: ["made_up_apex"],
580}
581`,
582 ExpectedBazelTargets: []string{
583 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
584 "implementation_dynamic_deps": `[":a"]`,
585 "tags": `["apex_available=made_up_apex"]`,
586 }),
587 },
588 })
589}
590
591func TestCcLibrarySharedStubs_UseStubsInDifferentApex(t *testing.T) {
592 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
593 Description: "cc_library_shared stubs",
594 ModuleTypeUnderTest: "cc_library_shared",
595 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000596 StubbedBuildDefinitions: []string{"a"},
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400597 Blueprint: soongCcLibrarySharedPreamble + `
598cc_library_shared {
599 name: "a",
600 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400601 include_build_directory: false,
602 apex_available: ["apex_a"],
603}
604cc_library_shared {
605 name: "b",
606 shared_libs: [":a"],
607 include_build_directory: false,
608 apex_available: ["apex_b"],
609}
610`,
611 ExpectedBazelTargets: []string{
612 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
613 "implementation_dynamic_deps": `select({
Spandan Das6d4d9da2023-04-18 06:20:40 +0000614 "//build/bazel/rules/apex:apex_b": ["@api_surfaces//module-libapi/current:a"],
615 "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400616 "//conditions:default": [":a"],
617 })`,
618 "tags": `["apex_available=apex_b"]`,
619 }),
620 },
621 })
622}
623
Spandan Das6d4d9da2023-04-18 06:20:40 +0000624// Tests that library in apexfoo links against stubs of platform_lib and otherapex_lib
625func TestCcLibrarySharedStubs_UseStubsFromMultipleApiDomains(t *testing.T) {
626 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
627 Description: "cc_library_shared stubs",
628 ModuleTypeUnderTest: "cc_library_shared",
629 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000630 StubbedBuildDefinitions: []string{"libplatform_stable", "libapexfoo_stable"},
Spandan Das6d4d9da2023-04-18 06:20:40 +0000631 Blueprint: soongCcLibrarySharedPreamble + `
632cc_library_shared {
633 name: "libplatform_stable",
634 stubs: { symbol_file: "libplatform_stable.map.txt", versions: ["28", "29", "current"] },
635 apex_available: ["//apex_available:platform"],
Spandan Das6d4d9da2023-04-18 06:20:40 +0000636 include_build_directory: false,
637}
638cc_library_shared {
639 name: "libapexfoo_stable",
640 stubs: { symbol_file: "libapexfoo_stable.map.txt", versions: ["28", "29", "current"] },
641 apex_available: ["apexfoo"],
Spandan Das6d4d9da2023-04-18 06:20:40 +0000642 include_build_directory: false,
643}
644cc_library_shared {
645 name: "libutils",
646 shared_libs: ["libplatform_stable", "libapexfoo_stable",],
647 apex_available: ["//apex_available:platform", "apexfoo", "apexbar"],
648 include_build_directory: false,
649}
650`,
651 ExpectedBazelTargets: []string{
652 MakeBazelTarget("cc_library_shared", "libutils", AttrNameToString{
653 "implementation_dynamic_deps": `select({
654 "//build/bazel/rules/apex:apexbar": [
655 "@api_surfaces//module-libapi/current:libplatform_stable",
656 "@api_surfaces//module-libapi/current:libapexfoo_stable",
657 ],
658 "//build/bazel/rules/apex:apexfoo": [
659 "@api_surfaces//module-libapi/current:libplatform_stable",
660 ":libapexfoo_stable",
661 ],
662 "//build/bazel/rules/apex:system": [
Spandan Dasf7bae9a2023-09-06 22:07:15 +0000663 ":libplatform_stable",
Spandan Das6d4d9da2023-04-18 06:20:40 +0000664 "@api_surfaces//module-libapi/current:libapexfoo_stable",
665 ],
666 "//conditions:default": [
667 ":libplatform_stable",
668 ":libapexfoo_stable",
669 ],
670 })`,
671 "tags": `[
672 "apex_available=//apex_available:platform",
673 "apex_available=apexfoo",
674 "apex_available=apexbar",
675 ]`,
676 }),
677 },
678 })
679}
680
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400681func TestCcLibrarySharedStubs_IgnorePlatformAvailable(t *testing.T) {
682 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
683 Description: "cc_library_shared stubs",
684 ModuleTypeUnderTest: "cc_library_shared",
685 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000686 StubbedBuildDefinitions: []string{"a"},
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400687 Blueprint: soongCcLibrarySharedPreamble + `
688cc_library_shared {
689 name: "a",
690 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400691 include_build_directory: false,
692 apex_available: ["//apex_available:platform", "apex_a"],
693}
694cc_library_shared {
695 name: "b",
696 shared_libs: [":a"],
697 include_build_directory: false,
698 apex_available: ["//apex_available:platform", "apex_b"],
699}
700`,
701 ExpectedBazelTargets: []string{
702 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
703 "implementation_dynamic_deps": `select({
Spandan Das6d4d9da2023-04-18 06:20:40 +0000704 "//build/bazel/rules/apex:apex_b": ["@api_surfaces//module-libapi/current:a"],
705 "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400706 "//conditions:default": [":a"],
707 })`,
708 "tags": `[
709 "apex_available=//apex_available:platform",
710 "apex_available=apex_b",
711 ]`,
712 }),
713 },
714 })
715}
716
Spandan Das6d4d9da2023-04-18 06:20:40 +0000717func TestCcLibraryDoesNotDropStubDepIfNoVariationAcrossAxis(t *testing.T) {
718 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
719 Description: "cc_library depeends on impl for all configurations",
720 ModuleTypeUnderTest: "cc_library_shared",
721 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000722 StubbedBuildDefinitions: []string{"a"},
Spandan Das6d4d9da2023-04-18 06:20:40 +0000723 Blueprint: soongCcLibrarySharedPreamble + `
724cc_library_shared {
725 name: "a",
726 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
Spandan Das6d4d9da2023-04-18 06:20:40 +0000727 apex_available: ["//apex_available:platform"],
728}
729cc_library_shared {
730 name: "b",
731 shared_libs: [":a"],
732 include_build_directory: false,
733 apex_available: ["//apex_available:platform"],
734}
735`,
736 ExpectedBazelTargets: []string{
737 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
738 "implementation_dynamic_deps": `[":a"]`,
739 "tags": `["apex_available=//apex_available:platform"]`,
740 }),
741 },
742 })
743}
744
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400745func TestCcLibrarySharedStubs_MultipleApexAvailable(t *testing.T) {
746 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
747 ModuleTypeUnderTest: "cc_library_shared",
748 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000749 StubbedBuildDefinitions: []string{"a"},
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400750 Blueprint: soongCcLibrarySharedPreamble + `
751cc_library_shared {
752 name: "a",
753 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400754 include_build_directory: false,
755 apex_available: ["//apex_available:platform", "apex_a", "apex_b"],
756}
757cc_library_shared {
758 name: "b",
759 shared_libs: [":a"],
760 include_build_directory: false,
761 apex_available: ["//apex_available:platform", "apex_b"],
762}
763
764cc_library_shared {
765 name: "c",
766 shared_libs: [":a"],
767 include_build_directory: false,
768 apex_available: ["//apex_available:platform", "apex_a", "apex_b"],
769}
770`,
771 ExpectedBazelTargets: []string{
772 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
773 "implementation_dynamic_deps": `select({
Spandan Das6d4d9da2023-04-18 06:20:40 +0000774 "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400775 "//conditions:default": [":a"],
776 })`,
777 "tags": `[
778 "apex_available=//apex_available:platform",
779 "apex_available=apex_b",
780 ]`,
781 }),
782 MakeBazelTarget("cc_library_shared", "c", AttrNameToString{
783 "implementation_dynamic_deps": `[":a"]`,
784 "tags": `[
785 "apex_available=//apex_available:platform",
786 "apex_available=apex_a",
787 "apex_available=apex_b",
788 ]`,
789 }),
790 },
791 })
792}
793
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000794func TestCcLibrarySharedSystemSharedLibsSharedEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000795 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
796 Description: "cc_library_shared system_shared_libs empty shared default",
797 ModuleTypeUnderTest: "cc_library_shared",
798 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
799 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000800cc_defaults {
801 name: "empty_defaults",
802 shared: {
803 system_shared_libs: [],
804 },
805 include_build_directory: false,
806}
807cc_library_shared {
808 name: "empty",
809 defaults: ["empty_defaults"],
810}
811`,
Alixe06d75b2022-08-31 18:28:19 +0000812 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 +0000813 "system_dynamic_deps": "[]",
814 })},
815 })
816}
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000817
818func TestCcLibrarySharedConvertLex(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000819 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
820 Description: "cc_library_shared with lex files",
821 ModuleTypeUnderTest: "cc_library_shared",
822 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
823 Filesystem: map[string]string{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000824 "foo.c": "",
825 "bar.cc": "",
826 "foo1.l": "",
827 "bar1.ll": "",
828 "foo2.l": "",
829 "bar2.ll": "",
830 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000831 Blueprint: `cc_library_shared {
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000832 name: "foo_lib",
833 srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"],
834 lex: { flags: ["--foo_flags"] },
835 include_build_directory: false,
836 bazel_module: { bp2build_available: true },
837}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000838 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000839 MakeBazelTarget("genlex", "foo_lib_genlex_l", AttrNameToString{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000840 "srcs": `[
841 "foo1.l",
842 "foo2.l",
843 ]`,
844 "lexopts": `["--foo_flags"]`,
845 }),
Alixe06d75b2022-08-31 18:28:19 +0000846 MakeBazelTarget("genlex", "foo_lib_genlex_ll", AttrNameToString{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000847 "srcs": `[
848 "bar1.ll",
849 "bar2.ll",
850 ]`,
851 "lexopts": `["--foo_flags"]`,
852 }),
Alixe06d75b2022-08-31 18:28:19 +0000853 MakeBazelTarget("cc_library_shared", "foo_lib", AttrNameToString{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000854 "srcs": `[
855 "bar.cc",
856 ":foo_lib_genlex_ll",
857 ]`,
858 "srcs_c": `[
859 "foo.c",
860 ":foo_lib_genlex_l",
861 ]`,
862 }),
863 },
864 })
865}
Alix1be00d42022-05-16 22:56:04 +0000866
867func TestCcLibrarySharedClangUnknownFlags(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000868 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
869 Blueprint: soongCcProtoPreamble + `cc_library_shared {
Alix1be00d42022-05-16 22:56:04 +0000870 name: "foo",
871 conlyflags: ["-a", "-finline-functions"],
872 cflags: ["-b","-finline-functions"],
873 cppflags: ["-c", "-finline-functions"],
874 ldflags: ["-d","-finline-functions", "-e"],
875 include_build_directory: false,
876}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000877 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000878 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Alix1be00d42022-05-16 22:56:04 +0000879 "conlyflags": `["-a"]`,
880 "copts": `["-b"]`,
881 "cppflags": `["-c"]`,
882 "linkopts": `[
883 "-d",
884 "-e",
885 ]`,
886 }),
887 },
888 })
889}
890
891func TestCCLibraryFlagSpaceSplitting(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000892 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
893 Blueprint: soongCcProtoPreamble + `cc_library_shared {
Alix1be00d42022-05-16 22:56:04 +0000894 name: "foo",
895 conlyflags: [ "-include header.h"],
896 cflags: ["-include header.h"],
897 cppflags: ["-include header.h"],
898 version_script: "version_script",
899 include_build_directory: false,
900}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000901 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000902 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Alix1be00d42022-05-16 22:56:04 +0000903 "additional_linker_inputs": `["version_script"]`,
904 "conlyflags": `[
905 "-include",
906 "header.h",
907 ]`,
908 "copts": `[
909 "-include",
910 "header.h",
911 ]`,
912 "cppflags": `[
913 "-include",
914 "header.h",
915 ]`,
916 "linkopts": `["-Wl,--version-script,$(location version_script)"]`,
Trevor Radcliffef06dd912023-05-19 14:51:41 +0000917 "features": `["android_cfi_exports_map"]`,
Alix1be00d42022-05-16 22:56:04 +0000918 }),
919 },
920 })
921}
Cole Faust6b29f592022-08-09 09:50:56 -0700922
923func TestCCLibrarySharedRuntimeDeps(t *testing.T) {
924 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
925 Blueprint: `cc_library_shared {
926 name: "bar",
927}
928
929cc_library_shared {
930 name: "foo",
Chris Parsonscd209032023-09-19 01:12:48 +0000931 runtime_libs: ["bar"],
Cole Faust6b29f592022-08-09 09:50:56 -0700932}`,
933 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000934 MakeBazelTarget("cc_library_shared", "bar", AttrNameToString{
Cole Faust6b29f592022-08-09 09:50:56 -0700935 "local_includes": `["."]`,
936 }),
Alixe06d75b2022-08-31 18:28:19 +0000937 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Chris Parsonscd209032023-09-19 01:12:48 +0000938 "runtime_deps": `[":bar"]`,
Cole Faust6b29f592022-08-09 09:50:56 -0700939 "local_includes": `["."]`,
940 }),
941 },
942 })
943}
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -0500944
945func TestCcLibrarySharedEmptySuffix(t *testing.T) {
946 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
947 Description: "cc_library_shared with empty suffix",
948 Filesystem: map[string]string{
949 "foo.c": "",
950 },
951 Blueprint: soongCcLibrarySharedPreamble + `
952cc_library_shared {
953 name: "foo_shared",
954 suffix: "",
955 srcs: ["foo.c"],
956 include_build_directory: false,
957}`,
958 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000959 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -0500960 "srcs_c": `["foo.c"]`,
961 "suffix": `""`,
962 }),
963 },
964 })
965}
966
967func TestCcLibrarySharedSuffix(t *testing.T) {
968 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
969 Description: "cc_library_shared with suffix",
970 Filesystem: map[string]string{
971 "foo.c": "",
972 },
973 Blueprint: soongCcLibrarySharedPreamble + `
974cc_library_shared {
975 name: "foo_shared",
976 suffix: "-suf",
977 srcs: ["foo.c"],
978 include_build_directory: false,
979}`,
980 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000981 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -0500982 "srcs_c": `["foo.c"]`,
983 "suffix": `"-suf"`,
984 }),
985 },
986 })
987}
988
989func TestCcLibrarySharedArchVariantSuffix(t *testing.T) {
990 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
991 Description: "cc_library_shared with arch-variant suffix",
992 Filesystem: map[string]string{
993 "foo.c": "",
994 },
995 Blueprint: soongCcLibrarySharedPreamble + `
996cc_library_shared {
997 name: "foo_shared",
998 arch: {
999 arm64: { suffix: "-64" },
1000 arm: { suffix: "-32" },
1001 },
1002 srcs: ["foo.c"],
1003 include_build_directory: false,
1004}`,
1005 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001006 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -05001007 "srcs_c": `["foo.c"]`,
1008 "suffix": `select({
1009 "//build/bazel/platforms/arch:arm": "-32",
1010 "//build/bazel/platforms/arch:arm64": "-64",
1011 "//conditions:default": None,
1012 })`,
1013 }),
1014 },
1015 })
1016}
Trevor Radcliffecee4e052022-09-06 19:31:25 +00001017
1018func TestCcLibrarySharedWithSyspropSrcs(t *testing.T) {
1019 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1020 Description: "cc_library_shared with sysprop sources",
1021 Blueprint: `
1022cc_library_shared {
1023 name: "foo",
1024 srcs: [
1025 "bar.sysprop",
1026 "baz.sysprop",
1027 "blah.cpp",
1028 ],
1029 min_sdk_version: "5",
1030}`,
1031 ExpectedBazelTargets: []string{
1032 MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
1033 "srcs": `[
1034 "bar.sysprop",
1035 "baz.sysprop",
1036 ]`,
1037 }),
1038 MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
1039 "dep": `":foo_sysprop_library"`,
1040 "min_sdk_version": `"5"`,
1041 }),
1042 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1043 "srcs": `["blah.cpp"]`,
1044 "local_includes": `["."]`,
1045 "min_sdk_version": `"5"`,
1046 "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`,
1047 }),
1048 },
1049 })
1050}
1051
1052func TestCcLibrarySharedWithSyspropSrcsSomeConfigs(t *testing.T) {
1053 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1054 Description: "cc_library_shared with sysprop sources in some configs but not others",
1055 Blueprint: `
1056cc_library_shared {
1057 name: "foo",
1058 srcs: [
1059 "blah.cpp",
1060 ],
1061 target: {
1062 android: {
1063 srcs: ["bar.sysprop"],
1064 },
1065 },
1066 min_sdk_version: "5",
1067}`,
1068 ExpectedBazelTargets: []string{
1069 MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
1070 "srcs": `select({
1071 "//build/bazel/platforms/os:android": ["bar.sysprop"],
1072 "//conditions:default": [],
1073 })`,
1074 }),
1075 MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
1076 "dep": `":foo_sysprop_library"`,
1077 "min_sdk_version": `"5"`,
1078 }),
1079 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1080 "srcs": `["blah.cpp"]`,
1081 "local_includes": `["."]`,
1082 "min_sdk_version": `"5"`,
1083 "whole_archive_deps": `select({
1084 "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"],
1085 "//conditions:default": [],
1086 })`,
1087 }),
1088 },
1089 })
1090}
Yu Liu56ccb1a2022-11-12 10:47:07 -08001091
1092func TestCcLibrarySharedHeaderAbiChecker(t *testing.T) {
1093 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1094 Description: "cc_library_shared with header abi checker",
1095 Blueprint: `cc_library_shared {
1096 name: "foo",
1097 header_abi_checker: {
1098 enabled: true,
1099 symbol_file: "a.map.txt",
1100 exclude_symbol_versions: [
1101 "29",
1102 "30",
1103 ],
1104 exclude_symbol_tags: [
1105 "tag1",
1106 "tag2",
1107 ],
1108 check_all_apis: true,
1109 diff_flags: ["-allow-adding-removing-weak-symbols"],
1110 },
1111 include_build_directory: false,
1112}`,
1113 ExpectedBazelTargets: []string{
1114 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1115 "abi_checker_enabled": `True`,
1116 "abi_checker_symbol_file": `"a.map.txt"`,
1117 "abi_checker_exclude_symbol_versions": `[
1118 "29",
1119 "30",
1120 ]`,
1121 "abi_checker_exclude_symbol_tags": `[
1122 "tag1",
1123 "tag2",
1124 ]`,
1125 "abi_checker_check_all_apis": `True`,
1126 "abi_checker_diff_flags": `["-allow-adding-removing-weak-symbols"]`,
1127 }),
1128 },
1129 })
1130}
Trevor Radcliffedb7e0262022-10-28 16:48:18 +00001131
1132func TestCcLibrarySharedWithIntegerOverflowProperty(t *testing.T) {
1133 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1134 Description: "cc_library_shared has correct features when integer_overflow property is provided",
1135 Blueprint: `
1136cc_library_shared {
1137 name: "foo",
1138 sanitize: {
1139 integer_overflow: true,
1140 },
1141}
1142`,
1143 ExpectedBazelTargets: []string{
1144 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1145 "features": `["ubsan_integer_overflow"]`,
1146 "local_includes": `["."]`,
1147 }),
1148 },
1149 })
1150}
1151
1152func TestCcLibrarySharedWithMiscUndefinedProperty(t *testing.T) {
1153 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1154 Description: "cc_library_shared has correct features when misc_undefined property is provided",
1155 Blueprint: `
1156cc_library_shared {
1157 name: "foo",
1158 sanitize: {
1159 misc_undefined: ["undefined", "nullability"],
1160 },
1161}
1162`,
1163 ExpectedBazelTargets: []string{
1164 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1165 "features": `[
1166 "ubsan_undefined",
1167 "ubsan_nullability",
1168 ]`,
1169 "local_includes": `["."]`,
1170 }),
1171 },
1172 })
1173}
1174
1175func TestCcLibrarySharedWithUBSanPropertiesArchSpecific(t *testing.T) {
1176 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1177 Description: "cc_library_shared has correct feature select when UBSan props are specified in arch specific blocks",
1178 Blueprint: `
1179cc_library_shared {
1180 name: "foo",
1181 sanitize: {
1182 misc_undefined: ["undefined", "nullability"],
1183 },
1184 target: {
1185 android: {
1186 sanitize: {
1187 misc_undefined: ["alignment"],
1188 },
1189 },
1190 linux_glibc: {
1191 sanitize: {
1192 integer_overflow: true,
1193 },
1194 },
1195 },
1196}
1197`,
1198 ExpectedBazelTargets: []string{
1199 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1200 "features": `[
1201 "ubsan_undefined",
1202 "ubsan_nullability",
1203 ] + select({
1204 "//build/bazel/platforms/os:android": ["ubsan_alignment"],
1205 "//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"],
1206 "//conditions:default": [],
1207 })`,
1208 "local_includes": `["."]`,
1209 }),
1210 },
1211 })
1212}
Trevor Radcliffe56b1a2b2023-02-06 21:58:30 +00001213
Trevor Radcliffeded095c2023-06-12 19:18:28 +00001214func TestCcLibrarySharedWithSanitizerBlocklist(t *testing.T) {
1215 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1216 Description: "cc_library_shared has correct features when sanitize.blocklist is provided",
1217 Blueprint: `
1218cc_library_shared {
1219 name: "foo",
1220 sanitize: {
1221 blocklist: "foo_blocklist.txt",
1222 },
1223}
1224`,
1225 ExpectedBazelTargets: []string{
1226 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Trevor Radcliffed9b7f172023-08-09 22:21:38 +00001227 "copts": `select({
1228 "//build/bazel/rules/cc:sanitizers_enabled": ["-fsanitize-ignorelist=$(location foo_blocklist.txt)"],
1229 "//conditions:default": [],
1230 })`,
1231 "additional_compiler_inputs": `select({
1232 "//build/bazel/rules/cc:sanitizers_enabled": [":foo_blocklist.txt"],
1233 "//conditions:default": [],
1234 })`,
Trevor Radcliffeded095c2023-06-12 19:18:28 +00001235 "local_includes": `["."]`,
1236 }),
1237 },
1238 })
1239}
1240
Trevor Radcliffe56b1a2b2023-02-06 21:58:30 +00001241func TestCcLibrarySharedWithThinLto(t *testing.T) {
1242 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1243 Description: "cc_library_shared has correct features when thin lto is enabled",
1244 Blueprint: `
1245cc_library_shared {
1246 name: "foo",
1247 lto: {
1248 thin: true,
1249 },
1250}
1251`,
1252 ExpectedBazelTargets: []string{
1253 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1254 "features": `["android_thin_lto"]`,
1255 "local_includes": `["."]`,
1256 }),
1257 },
1258 })
1259}
1260
1261func TestCcLibrarySharedWithLtoNever(t *testing.T) {
1262 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1263 Description: "cc_library_shared has correct features when thin lto is enabled",
1264 Blueprint: `
1265cc_library_shared {
1266 name: "foo",
1267 lto: {
1268 never: true,
1269 },
1270}
1271`,
1272 ExpectedBazelTargets: []string{
1273 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1274 "features": `["-android_thin_lto"]`,
1275 "local_includes": `["."]`,
1276 }),
1277 },
1278 })
1279}
1280
1281func TestCcLibrarySharedWithThinLtoArchSpecific(t *testing.T) {
1282 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1283 Description: "cc_library_shared has correct features when LTO differs across arch and os variants",
1284 Blueprint: `
1285cc_library_shared {
1286 name: "foo",
1287 target: {
1288 android: {
1289 lto: {
1290 thin: true,
1291 },
1292 },
1293 },
1294 arch: {
1295 riscv64: {
1296 lto: {
1297 thin: false,
1298 },
1299 },
1300 },
1301}`,
1302 ExpectedBazelTargets: []string{
1303 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1304 "local_includes": `["."]`,
1305 "features": `select({
1306 "//build/bazel/platforms/os_arch:android_arm": ["android_thin_lto"],
1307 "//build/bazel/platforms/os_arch:android_arm64": ["android_thin_lto"],
1308 "//build/bazel/platforms/os_arch:android_riscv64": ["-android_thin_lto"],
1309 "//build/bazel/platforms/os_arch:android_x86": ["android_thin_lto"],
1310 "//build/bazel/platforms/os_arch:android_x86_64": ["android_thin_lto"],
1311 "//conditions:default": [],
1312 })`}),
1313 },
1314 })
1315}
1316
1317func TestCcLibrarySharedWithThinLtoDisabledDefaultEnabledVariant(t *testing.T) {
1318 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1319 Description: "cc_library_shared with thin lto disabled by default but enabled on a particular variant",
1320 Blueprint: `
1321cc_library_shared {
1322 name: "foo",
1323 lto: {
1324 never: true,
1325 },
1326 target: {
1327 android: {
1328 lto: {
1329 thin: true,
1330 never: false,
1331 },
1332 },
1333 },
1334}`,
1335 ExpectedBazelTargets: []string{
1336 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1337 "local_includes": `["."]`,
1338 "features": `select({
1339 "//build/bazel/platforms/os:android": ["android_thin_lto"],
1340 "//conditions:default": ["-android_thin_lto"],
1341 })`,
1342 }),
1343 },
1344 })
1345}
1346
1347func TestCcLibrarySharedWithThinLtoAndWholeProgramVtables(t *testing.T) {
1348 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1349 Description: "cc_library_shared has correct features when thin LTO is enabled with whole_program_vtables",
1350 Blueprint: `
1351cc_library_shared {
1352 name: "foo",
1353 lto: {
1354 thin: true,
1355 },
1356 whole_program_vtables: true,
1357}
1358`,
1359 ExpectedBazelTargets: []string{
1360 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1361 "features": `[
1362 "android_thin_lto",
1363 "android_thin_lto_whole_program_vtables",
1364 ]`,
1365 "local_includes": `["."]`,
1366 }),
1367 },
1368 })
1369}
Trevor Radcliffea8b44162023-04-14 18:25:24 +00001370
1371func TestCcLibrarySharedHiddenVisibilityConvertedToFeature(t *testing.T) {
1372 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1373 Description: "cc_library_shared changes hidden visibility flag to feature",
1374 Blueprint: `
1375cc_library_shared{
1376 name: "foo",
1377 cflags: ["-fvisibility=hidden"],
1378}`,
1379 ExpectedBazelTargets: []string{
1380 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1381 "features": `["visibility_hidden"]`,
1382 "local_includes": `["."]`,
1383 }),
1384 },
1385 })
1386}
1387
1388func TestCcLibrarySharedHiddenVisibilityConvertedToFeatureOsSpecific(t *testing.T) {
1389 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1390 Description: "cc_library_shared changes hidden visibility flag to feature for specific os",
1391 Blueprint: `
1392cc_library_shared{
1393 name: "foo",
1394 target: {
1395 android: {
1396 cflags: ["-fvisibility=hidden"],
1397 },
1398 },
1399}`,
1400 ExpectedBazelTargets: []string{
1401 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1402 "features": `select({
1403 "//build/bazel/platforms/os:android": ["visibility_hidden"],
1404 "//conditions:default": [],
1405 })`,
1406 "local_includes": `["."]`,
1407 }),
1408 },
1409 })
1410}
Sam Delmerico75dbca22023-04-20 13:13:25 +00001411
1412func TestCcLibrarySharedStubsDessertVersionConversion(t *testing.T) {
1413 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1414 Description: "cc_library_shared converts dessert codename versions to numerical versions",
1415 Blueprint: `
1416cc_library_shared {
1417 name: "a",
1418 include_build_directory: false,
1419 stubs: {
1420 symbol_file: "a.map.txt",
1421 versions: [
1422 "Q",
1423 "R",
1424 "31",
1425 ],
1426 },
1427}
1428cc_library_shared {
1429 name: "b",
1430 include_build_directory: false,
1431 stubs: {
1432 symbol_file: "b.map.txt",
1433 versions: [
1434 "Q",
1435 "R",
1436 "31",
1437 "current",
1438 ],
1439 },
1440}
1441`,
1442 ExpectedBazelTargets: []string{
1443 makeCcStubSuiteTargets("a", AttrNameToString{
Spandan Das04f9f4c2023-09-13 23:59:05 +00001444 "api_surface": `"module-libapi"`,
Sam Delmerico75dbca22023-04-20 13:13:25 +00001445 "soname": `"a.so"`,
1446 "source_library_label": `"//:a"`,
1447 "stubs_symbol_file": `"a.map.txt"`,
1448 "stubs_versions": `[
1449 "29",
1450 "30",
1451 "31",
1452 "current",
1453 ]`,
1454 }),
1455 MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
1456 "stubs_symbol_file": `"a.map.txt"`,
1457 }),
1458 makeCcStubSuiteTargets("b", AttrNameToString{
Spandan Das04f9f4c2023-09-13 23:59:05 +00001459 "api_surface": `"module-libapi"`,
Sam Delmerico75dbca22023-04-20 13:13:25 +00001460 "soname": `"b.so"`,
1461 "source_library_label": `"//:b"`,
1462 "stubs_symbol_file": `"b.map.txt"`,
1463 "stubs_versions": `[
1464 "29",
1465 "30",
1466 "31",
1467 "current",
1468 ]`,
1469 }),
1470 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
1471 "stubs_symbol_file": `"b.map.txt"`,
1472 }),
1473 },
1474 })
1475}
Trevor Radcliffe27669c02023-03-28 20:47:10 +00001476
1477func TestCcLibrarySharedWithCfi(t *testing.T) {
1478 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1479 Description: "cc_library_shared has correct features when cfi is enabled for specific variants",
1480 Blueprint: `
1481cc_library_shared {
1482 name: "foo",
1483 sanitize: {
1484 cfi: true,
1485 },
1486}`,
1487 ExpectedBazelTargets: []string{
1488 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1489 "features": `["android_cfi"]`,
1490 "local_includes": `["."]`,
1491 }),
1492 },
1493 })
1494}
1495
1496func TestCcLibrarySharedWithCfiOsSpecific(t *testing.T) {
1497 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1498 Description: "cc_library_shared has correct features when cfi is enabled",
1499 Blueprint: `
1500cc_library_shared {
1501 name: "foo",
1502 target: {
1503 android: {
1504 sanitize: {
1505 cfi: true,
1506 },
1507 },
1508 },
1509}`,
1510 ExpectedBazelTargets: []string{
1511 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1512 "features": `select({
1513 "//build/bazel/platforms/os:android": ["android_cfi"],
1514 "//conditions:default": [],
1515 })`,
1516 "local_includes": `["."]`,
1517 }),
1518 },
1519 })
1520}
1521
1522func TestCcLibrarySharedWithCfiAndCfiAssemblySupport(t *testing.T) {
1523 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1524 Description: "cc_library_shared has correct features when cfi is enabled with cfi assembly support",
1525 Blueprint: `
Trevor Radcliffe85d55c22023-09-21 17:04:43 +00001526cc_library_static {
Trevor Radcliffe27669c02023-03-28 20:47:10 +00001527 name: "foo",
1528 sanitize: {
1529 cfi: true,
1530 config: {
1531 cfi_assembly_support: true,
1532 },
1533 },
1534}`,
1535 ExpectedBazelTargets: []string{
Trevor Radcliffe85d55c22023-09-21 17:04:43 +00001536 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
Trevor Radcliffe27669c02023-03-28 20:47:10 +00001537 "features": `[
1538 "android_cfi",
1539 "android_cfi_assembly_support",
1540 ]`,
1541 "local_includes": `["."]`,
1542 }),
1543 },
1544 })
1545}
Trevor Radcliffe523c5c62023-06-16 20:15:45 +00001546
1547func TestCcLibrarySharedExplicitlyDisablesCfiWhenFalse(t *testing.T) {
1548 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1549 Description: "cc_library_shared disables cfi when explciitly set to false in the bp",
1550 Blueprint: `
1551cc_library_shared {
1552 name: "foo",
1553 sanitize: {
1554 cfi: false,
1555 },
1556}
1557`,
1558 ExpectedBazelTargets: []string{
1559 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1560 "features": `["-android_cfi"]`,
1561 "local_includes": `["."]`,
1562 }),
1563 },
1564 })
1565}
Alixe2667872023-04-24 14:57:32 +00001566
1567func TestCCLibrarySharedRscriptSrc(t *testing.T) {
1568 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1569 Description: ``,
1570 Blueprint: `
1571cc_library_shared{
1572 name : "foo",
1573 srcs : [
1574 "ccSrc.cc",
1575 "rsSrc.rscript",
1576 ],
1577 include_build_directory: false,
1578}
1579`,
1580 ExpectedBazelTargets: []string{
1581 MakeBazelTarget("rscript_to_cpp", "foo_renderscript", AttrNameToString{
1582 "srcs": `["rsSrc.rscript"]`,
1583 }),
1584 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1585 "absolute_includes": `[
1586 "frameworks/rs",
1587 "frameworks/rs/cpp",
1588 ]`,
1589 "local_includes": `["."]`,
1590 "srcs": `[
1591 "ccSrc.cc",
1592 "foo_renderscript",
1593 ]`,
1594 })}})
1595}
Spandan Das1f65f9e2023-09-15 01:08:23 +00001596
1597func TestCcLibrarySdkVariantUsesStubs(t *testing.T) {
1598 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1599 Description: "cc_library_shared stubs",
1600 ModuleTypeUnderTest: "cc_library_shared",
1601 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
Chris Parsons0c4de1f2023-09-21 20:36:35 +00001602 StubbedBuildDefinitions: []string{"libNoStubs", "libHasApexStubs", "libHasApexAndNdkStubs", "libHasApexAndNdkStubs.ndk_stub_libs"},
Spandan Das1f65f9e2023-09-15 01:08:23 +00001603 Blueprint: soongCcLibrarySharedPreamble + `
1604cc_library_shared {
1605 name: "libUsesSdk",
1606 sdk_version: "current",
1607 shared_libs: [
1608 "libNoStubs",
1609 "libHasApexStubs",
1610 "libHasApexAndNdkStubs",
1611 ]
1612}
1613cc_library_shared {
1614 name: "libNoStubs",
Spandan Das1f65f9e2023-09-15 01:08:23 +00001615}
1616cc_library_shared {
1617 name: "libHasApexStubs",
1618 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
Spandan Das1f65f9e2023-09-15 01:08:23 +00001619 apex_available: ["apex_a"],
1620}
1621cc_library_shared {
1622 name: "libHasApexAndNdkStubs",
1623 stubs: { symbol_file: "b.map.txt", versions: ["28", "29", "current"] },
Spandan Das1f65f9e2023-09-15 01:08:23 +00001624 apex_available: ["apex_b"],
1625}
1626ndk_library {
1627 name: "libHasApexAndNdkStubs",
Chris Parsons0c4de1f2023-09-21 20:36:35 +00001628 first_version: "28",
Spandan Das1f65f9e2023-09-15 01:08:23 +00001629}
1630`,
1631 ExpectedBazelTargets: []string{
1632 MakeBazelTarget("cc_library_shared", "libUsesSdk", AttrNameToString{
1633 "implementation_dynamic_deps": `[":libNoStubs"] + select({
1634 "//build/bazel/rules/apex:system": [
1635 "@api_surfaces//module-libapi/current:libHasApexStubs",
1636 "@api_surfaces//module-libapi/current:libHasApexAndNdkStubs",
1637 ],
1638 "//build/bazel/rules/apex:unbundled_app": [
1639 ":libHasApexStubs",
Spandan Das9d47a822023-09-19 18:23:26 +00001640 "//.:libHasApexAndNdkStubs.ndk_stub_libs-current",
Spandan Das1f65f9e2023-09-15 01:08:23 +00001641 ],
1642 "//conditions:default": [
1643 ":libHasApexStubs",
1644 ":libHasApexAndNdkStubs",
1645 ],
1646 })`,
1647 "local_includes": `["."]`,
1648 "sdk_version": `"current"`,
Spandan Dasaf725832023-09-19 19:51:52 +00001649 "deps": `select({
1650 "//build/bazel/rules/apex:unbundled_app": ["//build/bazel/rules/cc:ndk_sysroot"],
1651 "//conditions:default": [],
1652 })`,
Spandan Das1f65f9e2023-09-15 01:08:23 +00001653 }),
1654 },
1655 })
1656}