blob: 6f600da5cdb7b7b9a6f91b8d1e73359d5225d284 [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"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500178 }),
179 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000180 })
181}
182
183func TestCcLibrarySharedArchSpecificSharedLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000184 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +0000185 Description: "cc_library_shared arch-specific shared_libs with whole_static_libs",
186 Filesystem: map[string]string{},
187 StubbedBuildDefinitions: []string{"static_dep", "shared_dep"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000188 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000189cc_library_static {
190 name: "static_dep",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000191}
192cc_library_shared {
193 name: "shared_dep",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000194}
195cc_library_shared {
196 name: "foo_shared",
197 arch: { arm64: { shared_libs: ["shared_dep"], whole_static_libs: ["static_dep"] } },
198 include_build_directory: false,
199}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000200 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000201 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500202 "implementation_dynamic_deps": `select({
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000203 "//build/bazel/platforms/arch:arm64": [":shared_dep"],
204 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500205 })`,
206 "whole_archive_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": [":static_dep"],
208 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500209 })`,
210 }),
211 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000212 })
213}
214
215func TestCcLibrarySharedOsSpecificSharedLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000216 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Chris Parsons5011e612023-09-13 23:33:20 +0000217 StubbedBuildDefinitions: []string{"shared_dep"},
218 Description: "cc_library_shared os-specific shared_libs",
219 Filesystem: map[string]string{},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000220 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000221cc_library_shared {
222 name: "shared_dep",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000223}
224cc_library_shared {
225 name: "foo_shared",
226 target: { android: { shared_libs: ["shared_dep"], } },
227 include_build_directory: false,
228}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000229 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000230 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500231 "implementation_dynamic_deps": `select({
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000232 "//build/bazel/platforms/os:android": [":shared_dep"],
233 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500234 })`,
235 }),
236 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000237 })
238}
239
240func TestCcLibrarySharedBaseArchOsSpecificSharedLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000241 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Chris Parsons5011e612023-09-13 23:33:20 +0000242 StubbedBuildDefinitions: []string{"shared_dep", "shared_dep2", "shared_dep3"},
243 Description: "cc_library_shared base, arch, and os-specific shared_libs",
244 Filesystem: map[string]string{},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000245 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000246cc_library_shared {
247 name: "shared_dep",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000248}
249cc_library_shared {
250 name: "shared_dep2",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000251}
252cc_library_shared {
253 name: "shared_dep3",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000254}
255cc_library_shared {
256 name: "foo_shared",
257 shared_libs: ["shared_dep"],
258 target: { android: { shared_libs: ["shared_dep2"] } },
259 arch: { arm64: { shared_libs: ["shared_dep3"] } },
260 include_build_directory: false,
261}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000262 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000263 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500264 "implementation_dynamic_deps": `[":shared_dep"] + select({
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000265 "//build/bazel/platforms/arch:arm64": [":shared_dep3"],
266 "//conditions:default": [],
267 }) + select({
268 "//build/bazel/platforms/os:android": [":shared_dep2"],
269 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500270 })`,
271 }),
272 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000273 })
274}
275
276func TestCcLibrarySharedSimpleExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000277 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
278 Description: "cc_library_shared simple exclude_srcs",
279 Filesystem: map[string]string{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000280 "common.c": "",
281 "foo-a.c": "",
282 "foo-excluded.c": "",
283 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000284 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000285cc_library_shared {
286 name: "foo_shared",
287 srcs: ["common.c", "foo-*.c"],
288 exclude_srcs: ["foo-excluded.c"],
289 include_build_directory: false,
290}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000291 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000292 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500293 "srcs_c": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000294 "common.c",
295 "foo-a.c",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500296 ]`,
297 }),
298 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000299 })
300}
301
302func TestCcLibrarySharedStrip(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000303 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
304 Description: "cc_library_shared stripping",
305 Filesystem: map[string]string{},
306 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000307cc_library_shared {
308 name: "foo_shared",
309 strip: {
310 keep_symbols: false,
311 keep_symbols_and_debug_frame: true,
312 keep_symbols_list: ["sym", "sym2"],
313 all: true,
314 none: false,
315 },
316 include_build_directory: false,
317}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000318 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000319 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500320 "strip": `{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000321 "all": True,
322 "keep_symbols": False,
323 "keep_symbols_and_debug_frame": True,
324 "keep_symbols_list": [
325 "sym",
326 "sym2",
327 ],
328 "none": False,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500329 }`,
330 }),
331 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000332 })
333}
334
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +0000335func TestCcLibrarySharedVersionScriptAndDynamicList(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000336 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +0000337 Description: "cc_library_shared version script and dynamic list",
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000338 Filesystem: map[string]string{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000339 "version_script": "",
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +0000340 "dynamic.list": "",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000341 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000342 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000343cc_library_shared {
344 name: "foo_shared",
345 version_script: "version_script",
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +0000346 dynamic_list: "dynamic.list",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000347 include_build_directory: false,
348}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000349 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000350 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +0000351 "additional_linker_inputs": `[
352 "version_script",
353 "dynamic.list",
354 ]`,
355 "linkopts": `[
356 "-Wl,--version-script,$(location version_script)",
357 "-Wl,--dynamic-list,$(location dynamic.list)",
358 ]`,
Trevor Radcliffef06dd912023-05-19 14:51:41 +0000359 "features": `["android_cfi_exports_map"]`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500360 }),
361 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000362 })
363}
Jingwen Chen6ada5892021-09-17 11:38:09 +0000364
Trevor Radcliffeea6a45d2022-09-20 18:58:01 +0000365func TestCcLibraryLdflagsSplitBySpaceSoongAdded(t *testing.T) {
366 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
367 Description: "ldflags are split by spaces except for the ones added by soong (version script and dynamic list)",
368 Filesystem: map[string]string{
369 "version_script": "",
370 "dynamic.list": "",
371 },
372 Blueprint: `
373cc_library_shared {
374 name: "foo",
375 ldflags: [
376 "--nospace_flag",
377 "-z spaceflag",
378 ],
379 version_script: "version_script",
380 dynamic_list: "dynamic.list",
381 include_build_directory: false,
382}`,
383 ExpectedBazelTargets: []string{
384 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
385 "additional_linker_inputs": `[
386 "version_script",
387 "dynamic.list",
388 ]`,
389 "linkopts": `[
390 "--nospace_flag",
391 "-z",
392 "spaceflag",
393 "-Wl,--version-script,$(location version_script)",
394 "-Wl,--dynamic-list,$(location dynamic.list)",
395 ]`,
Trevor Radcliffef06dd912023-05-19 14:51:41 +0000396 "features": `["android_cfi_exports_map"]`,
Trevor Radcliffeea6a45d2022-09-20 18:58:01 +0000397 }),
398 },
399 })
400}
401
Jingwen Chen6ada5892021-09-17 11:38:09 +0000402func TestCcLibrarySharedNoCrtTrue(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000403 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux01ec55e2023-01-30 22:53:04 +0000404 Description: "cc_library_shared - nocrt: true disables feature",
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000405 Filesystem: map[string]string{
Jingwen Chen6ada5892021-09-17 11:38:09 +0000406 "impl.cpp": "",
407 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000408 Blueprint: soongCcLibraryPreamble + `
Jingwen Chen6ada5892021-09-17 11:38:09 +0000409cc_library_shared {
410 name: "foo_shared",
411 srcs: ["impl.cpp"],
412 nocrt: true,
413 include_build_directory: false,
414}
415`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000416 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000417 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux01ec55e2023-01-30 22:53:04 +0000418 "features": `["-link_crt"]`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500419 "srcs": `["impl.cpp"]`,
420 }),
421 },
422 })
Jingwen Chen6ada5892021-09-17 11:38:09 +0000423}
424
425func TestCcLibrarySharedNoCrtFalse(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000426 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux01ec55e2023-01-30 22:53:04 +0000427 Description: "cc_library_shared - nocrt: false doesn't disable feature",
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000428 Filesystem: map[string]string{
Jingwen Chen6ada5892021-09-17 11:38:09 +0000429 "impl.cpp": "",
430 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000431 Blueprint: soongCcLibraryPreamble + `
Jingwen Chen6ada5892021-09-17 11:38:09 +0000432cc_library_shared {
433 name: "foo_shared",
434 srcs: ["impl.cpp"],
435 nocrt: false,
436 include_build_directory: false,
437}
438`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000439 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000440 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500441 "srcs": `["impl.cpp"]`,
442 }),
443 },
444 })
Jingwen Chen6ada5892021-09-17 11:38:09 +0000445}
446
447func TestCcLibrarySharedNoCrtArchVariant(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000448 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
449 Description: "cc_library_shared - nocrt in select",
450 Filesystem: map[string]string{
Jingwen Chen6ada5892021-09-17 11:38:09 +0000451 "impl.cpp": "",
452 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000453 Blueprint: soongCcLibraryPreamble + `
Jingwen Chen6ada5892021-09-17 11:38:09 +0000454cc_library_shared {
455 name: "foo_shared",
456 srcs: ["impl.cpp"],
457 arch: {
458 arm: {
459 nocrt: true,
460 },
461 x86: {
462 nocrt: false,
463 },
464 },
465 include_build_directory: false,
466}
467`,
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux01ec55e2023-01-30 22:53:04 +0000468 ExpectedBazelTargets: []string{
469 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
470 "features": `select({
471 "//build/bazel/platforms/arch:arm": ["-link_crt"],
472 "//conditions:default": [],
473 })`,
474 "srcs": `["impl.cpp"]`,
475 }),
476 },
Jingwen Chen6ada5892021-09-17 11:38:09 +0000477 })
478}
Liz Kammer12615db2021-09-28 09:19:17 -0400479
480func TestCcLibrarySharedProto(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000481 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
482 Blueprint: soongCcProtoPreamble + `cc_library_shared {
Liz Kammer12615db2021-09-28 09:19:17 -0400483 name: "foo",
484 srcs: ["foo.proto"],
485 proto: {
Liz Kammer12615db2021-09-28 09:19:17 -0400486 export_proto_headers: true,
487 },
488 include_build_directory: false,
489}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000490 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000491 MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -0400492 "srcs": `["foo.proto"]`,
Alixe06d75b2022-08-31 18:28:19 +0000493 }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -0400494 "deps": `[":foo_proto"]`,
Alixe06d75b2022-08-31 18:28:19 +0000495 }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -0400496 "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
497 "whole_archive_deps": `[":foo_cc_proto_lite"]`,
498 }),
499 },
500 })
501}
Rupert Shuttleworth484aa252021-12-10 07:22:53 -0500502
503func TestCcLibrarySharedUseVersionLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000504 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Liz Kammerbaced712022-09-16 09:01:29 -0400505 Filesystem: map[string]string{
506 soongCcVersionLibBpPath: soongCcVersionLibBp,
507 },
Chris Parsonscd209032023-09-19 01:12:48 +0000508 StubbedBuildDefinitions: []string{"//build/soong/cc/libbuildversion:libbuildversion"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000509 Blueprint: soongCcProtoPreamble + `cc_library_shared {
Rupert Shuttleworth484aa252021-12-10 07:22:53 -0500510 name: "foo",
511 use_version_lib: true,
512 include_build_directory: false,
513}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000514 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000515 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Yu Liufe978fd2023-04-24 16:37:18 -0700516 "use_version_lib": "True",
517 "whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
Rupert Shuttleworth484aa252021-12-10 07:22:53 -0500518 }),
519 },
520 })
521}
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000522
523func TestCcLibrarySharedStubs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000524 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
525 Description: "cc_library_shared stubs",
526 ModuleTypeUnderTest: "cc_library_shared",
527 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
528 Dir: "foo/bar",
529 Filesystem: map[string]string{
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000530 "foo/bar/Android.bp": `
531cc_library_shared {
532 name: "a",
533 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
534 bazel_module: { bp2build_available: true },
535 include_build_directory: false,
536}
537`,
538 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000539 Blueprint: soongCcLibraryPreamble,
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000540 ExpectedBazelTargets: []string{makeCcStubSuiteTargets("a", AttrNameToString{
Spandan Das04f9f4c2023-09-13 23:59:05 +0000541 "api_surface": `"module-libapi"`,
Sam Delmerico5f906492023-03-15 18:06:18 -0400542 "soname": `"a.so"`,
543 "source_library_label": `"//foo/bar:a"`,
544 "stubs_symbol_file": `"a.map.txt"`,
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000545 "stubs_versions": `[
Trevor Radcliffe087af542022-09-16 15:36:10 +0000546 "28",
547 "29",
548 "current",
549 ]`,
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000550 }),
551 MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
Yu Liu56ccb1a2022-11-12 10:47:07 -0800552 "stubs_symbol_file": `"a.map.txt"`,
Trevor Radcliffe087af542022-09-16 15:36:10 +0000553 }),
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000554 },
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000555 })
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000556}
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000557
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400558func TestCcLibrarySharedStubs_UseImplementationInSameApex(t *testing.T) {
559 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
560 Description: "cc_library_shared stubs",
561 ModuleTypeUnderTest: "cc_library_shared",
562 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000563 StubbedBuildDefinitions: []string{"a"},
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400564 Blueprint: soongCcLibrarySharedPreamble + `
565cc_library_shared {
566 name: "a",
567 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400568 include_build_directory: false,
569 apex_available: ["made_up_apex"],
570}
571cc_library_shared {
572 name: "b",
573 shared_libs: [":a"],
574 include_build_directory: false,
575 apex_available: ["made_up_apex"],
576}
577`,
578 ExpectedBazelTargets: []string{
579 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
580 "implementation_dynamic_deps": `[":a"]`,
581 "tags": `["apex_available=made_up_apex"]`,
582 }),
583 },
584 })
585}
586
587func TestCcLibrarySharedStubs_UseStubsInDifferentApex(t *testing.T) {
588 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
589 Description: "cc_library_shared stubs",
590 ModuleTypeUnderTest: "cc_library_shared",
591 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000592 StubbedBuildDefinitions: []string{"a"},
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400593 Blueprint: soongCcLibrarySharedPreamble + `
594cc_library_shared {
595 name: "a",
596 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400597 include_build_directory: false,
598 apex_available: ["apex_a"],
599}
600cc_library_shared {
601 name: "b",
602 shared_libs: [":a"],
603 include_build_directory: false,
604 apex_available: ["apex_b"],
605}
606`,
607 ExpectedBazelTargets: []string{
608 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
609 "implementation_dynamic_deps": `select({
Spandan Das6d4d9da2023-04-18 06:20:40 +0000610 "//build/bazel/rules/apex:apex_b": ["@api_surfaces//module-libapi/current:a"],
611 "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400612 "//conditions:default": [":a"],
613 })`,
614 "tags": `["apex_available=apex_b"]`,
615 }),
616 },
617 })
618}
619
Spandan Das6d4d9da2023-04-18 06:20:40 +0000620// Tests that library in apexfoo links against stubs of platform_lib and otherapex_lib
621func TestCcLibrarySharedStubs_UseStubsFromMultipleApiDomains(t *testing.T) {
622 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
623 Description: "cc_library_shared stubs",
624 ModuleTypeUnderTest: "cc_library_shared",
625 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000626 StubbedBuildDefinitions: []string{"libplatform_stable", "libapexfoo_stable"},
Spandan Das6d4d9da2023-04-18 06:20:40 +0000627 Blueprint: soongCcLibrarySharedPreamble + `
628cc_library_shared {
629 name: "libplatform_stable",
630 stubs: { symbol_file: "libplatform_stable.map.txt", versions: ["28", "29", "current"] },
631 apex_available: ["//apex_available:platform"],
Spandan Das6d4d9da2023-04-18 06:20:40 +0000632 include_build_directory: false,
633}
634cc_library_shared {
635 name: "libapexfoo_stable",
636 stubs: { symbol_file: "libapexfoo_stable.map.txt", versions: ["28", "29", "current"] },
637 apex_available: ["apexfoo"],
Spandan Das6d4d9da2023-04-18 06:20:40 +0000638 include_build_directory: false,
639}
640cc_library_shared {
641 name: "libutils",
642 shared_libs: ["libplatform_stable", "libapexfoo_stable",],
643 apex_available: ["//apex_available:platform", "apexfoo", "apexbar"],
644 include_build_directory: false,
645}
646`,
647 ExpectedBazelTargets: []string{
648 MakeBazelTarget("cc_library_shared", "libutils", AttrNameToString{
649 "implementation_dynamic_deps": `select({
650 "//build/bazel/rules/apex:apexbar": [
651 "@api_surfaces//module-libapi/current:libplatform_stable",
652 "@api_surfaces//module-libapi/current:libapexfoo_stable",
653 ],
654 "//build/bazel/rules/apex:apexfoo": [
655 "@api_surfaces//module-libapi/current:libplatform_stable",
656 ":libapexfoo_stable",
657 ],
658 "//build/bazel/rules/apex:system": [
Spandan Dasf7bae9a2023-09-06 22:07:15 +0000659 ":libplatform_stable",
Spandan Das6d4d9da2023-04-18 06:20:40 +0000660 "@api_surfaces//module-libapi/current:libapexfoo_stable",
661 ],
662 "//conditions:default": [
663 ":libplatform_stable",
664 ":libapexfoo_stable",
665 ],
666 })`,
667 "tags": `[
668 "apex_available=//apex_available:platform",
669 "apex_available=apexfoo",
670 "apex_available=apexbar",
671 ]`,
672 }),
673 },
674 })
675}
676
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400677func TestCcLibrarySharedStubs_IgnorePlatformAvailable(t *testing.T) {
678 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
679 Description: "cc_library_shared stubs",
680 ModuleTypeUnderTest: "cc_library_shared",
681 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000682 StubbedBuildDefinitions: []string{"a"},
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400683 Blueprint: soongCcLibrarySharedPreamble + `
684cc_library_shared {
685 name: "a",
686 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400687 include_build_directory: false,
688 apex_available: ["//apex_available:platform", "apex_a"],
689}
690cc_library_shared {
691 name: "b",
692 shared_libs: [":a"],
693 include_build_directory: false,
694 apex_available: ["//apex_available:platform", "apex_b"],
695}
696`,
697 ExpectedBazelTargets: []string{
698 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
699 "implementation_dynamic_deps": `select({
Spandan Das6d4d9da2023-04-18 06:20:40 +0000700 "//build/bazel/rules/apex:apex_b": ["@api_surfaces//module-libapi/current:a"],
701 "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400702 "//conditions:default": [":a"],
703 })`,
704 "tags": `[
705 "apex_available=//apex_available:platform",
706 "apex_available=apex_b",
707 ]`,
708 }),
709 },
710 })
711}
712
Spandan Das6d4d9da2023-04-18 06:20:40 +0000713func TestCcLibraryDoesNotDropStubDepIfNoVariationAcrossAxis(t *testing.T) {
714 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
715 Description: "cc_library depeends on impl for all configurations",
716 ModuleTypeUnderTest: "cc_library_shared",
717 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000718 StubbedBuildDefinitions: []string{"a"},
Spandan Das6d4d9da2023-04-18 06:20:40 +0000719 Blueprint: soongCcLibrarySharedPreamble + `
720cc_library_shared {
721 name: "a",
722 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
Spandan Das6d4d9da2023-04-18 06:20:40 +0000723 apex_available: ["//apex_available:platform"],
724}
725cc_library_shared {
726 name: "b",
727 shared_libs: [":a"],
728 include_build_directory: false,
729 apex_available: ["//apex_available:platform"],
730}
731`,
732 ExpectedBazelTargets: []string{
733 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
734 "implementation_dynamic_deps": `[":a"]`,
735 "tags": `["apex_available=//apex_available:platform"]`,
736 }),
737 },
738 })
739}
740
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400741func TestCcLibrarySharedStubs_MultipleApexAvailable(t *testing.T) {
742 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
743 ModuleTypeUnderTest: "cc_library_shared",
744 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000745 StubbedBuildDefinitions: []string{"a"},
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400746 Blueprint: soongCcLibrarySharedPreamble + `
747cc_library_shared {
748 name: "a",
749 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400750 include_build_directory: false,
751 apex_available: ["//apex_available:platform", "apex_a", "apex_b"],
752}
753cc_library_shared {
754 name: "b",
755 shared_libs: [":a"],
756 include_build_directory: false,
757 apex_available: ["//apex_available:platform", "apex_b"],
758}
759
760cc_library_shared {
761 name: "c",
762 shared_libs: [":a"],
763 include_build_directory: false,
764 apex_available: ["//apex_available:platform", "apex_a", "apex_b"],
765}
766`,
767 ExpectedBazelTargets: []string{
768 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
769 "implementation_dynamic_deps": `select({
Spandan Das6d4d9da2023-04-18 06:20:40 +0000770 "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400771 "//conditions:default": [":a"],
772 })`,
773 "tags": `[
774 "apex_available=//apex_available:platform",
775 "apex_available=apex_b",
776 ]`,
777 }),
778 MakeBazelTarget("cc_library_shared", "c", AttrNameToString{
779 "implementation_dynamic_deps": `[":a"]`,
780 "tags": `[
781 "apex_available=//apex_available:platform",
782 "apex_available=apex_a",
783 "apex_available=apex_b",
784 ]`,
785 }),
786 },
787 })
788}
789
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000790func TestCcLibrarySharedSystemSharedLibsSharedEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000791 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
792 Description: "cc_library_shared system_shared_libs empty shared default",
793 ModuleTypeUnderTest: "cc_library_shared",
794 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
795 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000796cc_defaults {
797 name: "empty_defaults",
798 shared: {
799 system_shared_libs: [],
800 },
801 include_build_directory: false,
802}
803cc_library_shared {
804 name: "empty",
805 defaults: ["empty_defaults"],
806}
807`,
Alixe06d75b2022-08-31 18:28:19 +0000808 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 +0000809 "system_dynamic_deps": "[]",
810 })},
811 })
812}
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000813
814func TestCcLibrarySharedConvertLex(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000815 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
816 Description: "cc_library_shared with lex files",
817 ModuleTypeUnderTest: "cc_library_shared",
818 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
819 Filesystem: map[string]string{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000820 "foo.c": "",
821 "bar.cc": "",
822 "foo1.l": "",
823 "bar1.ll": "",
824 "foo2.l": "",
825 "bar2.ll": "",
826 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000827 Blueprint: `cc_library_shared {
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000828 name: "foo_lib",
829 srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"],
830 lex: { flags: ["--foo_flags"] },
831 include_build_directory: false,
832 bazel_module: { bp2build_available: true },
833}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000834 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000835 MakeBazelTarget("genlex", "foo_lib_genlex_l", AttrNameToString{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000836 "srcs": `[
837 "foo1.l",
838 "foo2.l",
839 ]`,
840 "lexopts": `["--foo_flags"]`,
841 }),
Alixe06d75b2022-08-31 18:28:19 +0000842 MakeBazelTarget("genlex", "foo_lib_genlex_ll", AttrNameToString{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000843 "srcs": `[
844 "bar1.ll",
845 "bar2.ll",
846 ]`,
847 "lexopts": `["--foo_flags"]`,
848 }),
Alixe06d75b2022-08-31 18:28:19 +0000849 MakeBazelTarget("cc_library_shared", "foo_lib", AttrNameToString{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000850 "srcs": `[
851 "bar.cc",
852 ":foo_lib_genlex_ll",
853 ]`,
854 "srcs_c": `[
855 "foo.c",
856 ":foo_lib_genlex_l",
857 ]`,
858 }),
859 },
860 })
861}
Alix1be00d42022-05-16 22:56:04 +0000862
863func TestCcLibrarySharedClangUnknownFlags(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000864 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
865 Blueprint: soongCcProtoPreamble + `cc_library_shared {
Alix1be00d42022-05-16 22:56:04 +0000866 name: "foo",
867 conlyflags: ["-a", "-finline-functions"],
868 cflags: ["-b","-finline-functions"],
869 cppflags: ["-c", "-finline-functions"],
870 ldflags: ["-d","-finline-functions", "-e"],
871 include_build_directory: false,
872}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000873 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000874 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Alix1be00d42022-05-16 22:56:04 +0000875 "conlyflags": `["-a"]`,
876 "copts": `["-b"]`,
877 "cppflags": `["-c"]`,
878 "linkopts": `[
879 "-d",
880 "-e",
881 ]`,
882 }),
883 },
884 })
885}
886
887func TestCCLibraryFlagSpaceSplitting(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000888 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
889 Blueprint: soongCcProtoPreamble + `cc_library_shared {
Alix1be00d42022-05-16 22:56:04 +0000890 name: "foo",
891 conlyflags: [ "-include header.h"],
892 cflags: ["-include header.h"],
893 cppflags: ["-include header.h"],
894 version_script: "version_script",
895 include_build_directory: false,
896}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000897 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000898 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Alix1be00d42022-05-16 22:56:04 +0000899 "additional_linker_inputs": `["version_script"]`,
900 "conlyflags": `[
901 "-include",
902 "header.h",
903 ]`,
904 "copts": `[
905 "-include",
906 "header.h",
907 ]`,
908 "cppflags": `[
909 "-include",
910 "header.h",
911 ]`,
912 "linkopts": `["-Wl,--version-script,$(location version_script)"]`,
Trevor Radcliffef06dd912023-05-19 14:51:41 +0000913 "features": `["android_cfi_exports_map"]`,
Alix1be00d42022-05-16 22:56:04 +0000914 }),
915 },
916 })
917}
Cole Faust6b29f592022-08-09 09:50:56 -0700918
919func TestCCLibrarySharedRuntimeDeps(t *testing.T) {
920 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
921 Blueprint: `cc_library_shared {
922 name: "bar",
923}
924
925cc_library_shared {
926 name: "foo",
Chris Parsonscd209032023-09-19 01:12:48 +0000927 runtime_libs: ["bar"],
Cole Faust6b29f592022-08-09 09:50:56 -0700928}`,
929 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000930 MakeBazelTarget("cc_library_shared", "bar", AttrNameToString{
Cole Faust6b29f592022-08-09 09:50:56 -0700931 "local_includes": `["."]`,
932 }),
Alixe06d75b2022-08-31 18:28:19 +0000933 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Chris Parsonscd209032023-09-19 01:12:48 +0000934 "runtime_deps": `[":bar"]`,
Cole Faust6b29f592022-08-09 09:50:56 -0700935 "local_includes": `["."]`,
936 }),
937 },
938 })
939}
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -0500940
941func TestCcLibrarySharedEmptySuffix(t *testing.T) {
942 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
943 Description: "cc_library_shared with empty suffix",
944 Filesystem: map[string]string{
945 "foo.c": "",
946 },
947 Blueprint: soongCcLibrarySharedPreamble + `
948cc_library_shared {
949 name: "foo_shared",
950 suffix: "",
951 srcs: ["foo.c"],
952 include_build_directory: false,
953}`,
954 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000955 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -0500956 "srcs_c": `["foo.c"]`,
957 "suffix": `""`,
958 }),
959 },
960 })
961}
962
963func TestCcLibrarySharedSuffix(t *testing.T) {
964 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
965 Description: "cc_library_shared with suffix",
966 Filesystem: map[string]string{
967 "foo.c": "",
968 },
969 Blueprint: soongCcLibrarySharedPreamble + `
970cc_library_shared {
971 name: "foo_shared",
972 suffix: "-suf",
973 srcs: ["foo.c"],
974 include_build_directory: false,
975}`,
976 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000977 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -0500978 "srcs_c": `["foo.c"]`,
979 "suffix": `"-suf"`,
980 }),
981 },
982 })
983}
984
985func TestCcLibrarySharedArchVariantSuffix(t *testing.T) {
986 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
987 Description: "cc_library_shared with arch-variant suffix",
988 Filesystem: map[string]string{
989 "foo.c": "",
990 },
991 Blueprint: soongCcLibrarySharedPreamble + `
992cc_library_shared {
993 name: "foo_shared",
994 arch: {
995 arm64: { suffix: "-64" },
996 arm: { suffix: "-32" },
997 },
998 srcs: ["foo.c"],
999 include_build_directory: false,
1000}`,
1001 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001002 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -05001003 "srcs_c": `["foo.c"]`,
1004 "suffix": `select({
1005 "//build/bazel/platforms/arch:arm": "-32",
1006 "//build/bazel/platforms/arch:arm64": "-64",
1007 "//conditions:default": None,
1008 })`,
1009 }),
1010 },
1011 })
1012}
Trevor Radcliffecee4e052022-09-06 19:31:25 +00001013
1014func TestCcLibrarySharedWithSyspropSrcs(t *testing.T) {
1015 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1016 Description: "cc_library_shared with sysprop sources",
1017 Blueprint: `
1018cc_library_shared {
1019 name: "foo",
1020 srcs: [
1021 "bar.sysprop",
1022 "baz.sysprop",
1023 "blah.cpp",
1024 ],
1025 min_sdk_version: "5",
1026}`,
1027 ExpectedBazelTargets: []string{
1028 MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
1029 "srcs": `[
1030 "bar.sysprop",
1031 "baz.sysprop",
1032 ]`,
1033 }),
1034 MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
1035 "dep": `":foo_sysprop_library"`,
1036 "min_sdk_version": `"5"`,
1037 }),
1038 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1039 "srcs": `["blah.cpp"]`,
1040 "local_includes": `["."]`,
1041 "min_sdk_version": `"5"`,
1042 "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`,
1043 }),
1044 },
1045 })
1046}
1047
1048func TestCcLibrarySharedWithSyspropSrcsSomeConfigs(t *testing.T) {
1049 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1050 Description: "cc_library_shared with sysprop sources in some configs but not others",
1051 Blueprint: `
1052cc_library_shared {
1053 name: "foo",
1054 srcs: [
1055 "blah.cpp",
1056 ],
1057 target: {
1058 android: {
1059 srcs: ["bar.sysprop"],
1060 },
1061 },
1062 min_sdk_version: "5",
1063}`,
1064 ExpectedBazelTargets: []string{
1065 MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
1066 "srcs": `select({
1067 "//build/bazel/platforms/os:android": ["bar.sysprop"],
1068 "//conditions:default": [],
1069 })`,
1070 }),
1071 MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
1072 "dep": `":foo_sysprop_library"`,
1073 "min_sdk_version": `"5"`,
1074 }),
1075 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1076 "srcs": `["blah.cpp"]`,
1077 "local_includes": `["."]`,
1078 "min_sdk_version": `"5"`,
1079 "whole_archive_deps": `select({
1080 "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"],
1081 "//conditions:default": [],
1082 })`,
1083 }),
1084 },
1085 })
1086}
Yu Liu56ccb1a2022-11-12 10:47:07 -08001087
1088func TestCcLibrarySharedHeaderAbiChecker(t *testing.T) {
1089 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1090 Description: "cc_library_shared with header abi checker",
1091 Blueprint: `cc_library_shared {
1092 name: "foo",
1093 header_abi_checker: {
1094 enabled: true,
1095 symbol_file: "a.map.txt",
1096 exclude_symbol_versions: [
1097 "29",
1098 "30",
1099 ],
1100 exclude_symbol_tags: [
1101 "tag1",
1102 "tag2",
1103 ],
1104 check_all_apis: true,
1105 diff_flags: ["-allow-adding-removing-weak-symbols"],
1106 },
1107 include_build_directory: false,
1108}`,
1109 ExpectedBazelTargets: []string{
1110 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1111 "abi_checker_enabled": `True`,
1112 "abi_checker_symbol_file": `"a.map.txt"`,
1113 "abi_checker_exclude_symbol_versions": `[
1114 "29",
1115 "30",
1116 ]`,
1117 "abi_checker_exclude_symbol_tags": `[
1118 "tag1",
1119 "tag2",
1120 ]`,
1121 "abi_checker_check_all_apis": `True`,
1122 "abi_checker_diff_flags": `["-allow-adding-removing-weak-symbols"]`,
1123 }),
1124 },
1125 })
1126}
Trevor Radcliffedb7e0262022-10-28 16:48:18 +00001127
1128func TestCcLibrarySharedWithIntegerOverflowProperty(t *testing.T) {
1129 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1130 Description: "cc_library_shared has correct features when integer_overflow property is provided",
1131 Blueprint: `
1132cc_library_shared {
1133 name: "foo",
1134 sanitize: {
1135 integer_overflow: true,
1136 },
1137}
1138`,
1139 ExpectedBazelTargets: []string{
1140 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1141 "features": `["ubsan_integer_overflow"]`,
1142 "local_includes": `["."]`,
1143 }),
1144 },
1145 })
1146}
1147
1148func TestCcLibrarySharedWithMiscUndefinedProperty(t *testing.T) {
1149 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1150 Description: "cc_library_shared has correct features when misc_undefined property is provided",
1151 Blueprint: `
1152cc_library_shared {
1153 name: "foo",
1154 sanitize: {
1155 misc_undefined: ["undefined", "nullability"],
1156 },
1157}
1158`,
1159 ExpectedBazelTargets: []string{
1160 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1161 "features": `[
1162 "ubsan_undefined",
1163 "ubsan_nullability",
1164 ]`,
1165 "local_includes": `["."]`,
1166 }),
1167 },
1168 })
1169}
1170
1171func TestCcLibrarySharedWithUBSanPropertiesArchSpecific(t *testing.T) {
1172 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1173 Description: "cc_library_shared has correct feature select when UBSan props are specified in arch specific blocks",
1174 Blueprint: `
1175cc_library_shared {
1176 name: "foo",
1177 sanitize: {
1178 misc_undefined: ["undefined", "nullability"],
1179 },
1180 target: {
1181 android: {
1182 sanitize: {
1183 misc_undefined: ["alignment"],
1184 },
1185 },
1186 linux_glibc: {
1187 sanitize: {
1188 integer_overflow: true,
1189 },
1190 },
1191 },
1192}
1193`,
1194 ExpectedBazelTargets: []string{
1195 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1196 "features": `[
1197 "ubsan_undefined",
1198 "ubsan_nullability",
1199 ] + select({
1200 "//build/bazel/platforms/os:android": ["ubsan_alignment"],
1201 "//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"],
1202 "//conditions:default": [],
1203 })`,
1204 "local_includes": `["."]`,
1205 }),
1206 },
1207 })
1208}
Trevor Radcliffe56b1a2b2023-02-06 21:58:30 +00001209
Trevor Radcliffeded095c2023-06-12 19:18:28 +00001210func TestCcLibrarySharedWithSanitizerBlocklist(t *testing.T) {
1211 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1212 Description: "cc_library_shared has correct features when sanitize.blocklist is provided",
1213 Blueprint: `
1214cc_library_shared {
1215 name: "foo",
1216 sanitize: {
1217 blocklist: "foo_blocklist.txt",
1218 },
1219}
1220`,
1221 ExpectedBazelTargets: []string{
1222 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Trevor Radcliffed9b7f172023-08-09 22:21:38 +00001223 "copts": `select({
1224 "//build/bazel/rules/cc:sanitizers_enabled": ["-fsanitize-ignorelist=$(location foo_blocklist.txt)"],
1225 "//conditions:default": [],
1226 })`,
1227 "additional_compiler_inputs": `select({
1228 "//build/bazel/rules/cc:sanitizers_enabled": [":foo_blocklist.txt"],
1229 "//conditions:default": [],
1230 })`,
Trevor Radcliffeded095c2023-06-12 19:18:28 +00001231 "local_includes": `["."]`,
1232 }),
1233 },
1234 })
1235}
1236
Trevor Radcliffe56b1a2b2023-02-06 21:58:30 +00001237func TestCcLibrarySharedWithThinLto(t *testing.T) {
1238 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1239 Description: "cc_library_shared has correct features when thin lto is enabled",
1240 Blueprint: `
1241cc_library_shared {
1242 name: "foo",
1243 lto: {
1244 thin: true,
1245 },
1246}
1247`,
1248 ExpectedBazelTargets: []string{
1249 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1250 "features": `["android_thin_lto"]`,
1251 "local_includes": `["."]`,
1252 }),
1253 },
1254 })
1255}
1256
1257func TestCcLibrarySharedWithLtoNever(t *testing.T) {
1258 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1259 Description: "cc_library_shared has correct features when thin lto is enabled",
1260 Blueprint: `
1261cc_library_shared {
1262 name: "foo",
1263 lto: {
1264 never: true,
1265 },
1266}
1267`,
1268 ExpectedBazelTargets: []string{
1269 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1270 "features": `["-android_thin_lto"]`,
1271 "local_includes": `["."]`,
1272 }),
1273 },
1274 })
1275}
1276
1277func TestCcLibrarySharedWithThinLtoArchSpecific(t *testing.T) {
1278 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1279 Description: "cc_library_shared has correct features when LTO differs across arch and os variants",
1280 Blueprint: `
1281cc_library_shared {
1282 name: "foo",
1283 target: {
1284 android: {
1285 lto: {
1286 thin: true,
1287 },
1288 },
1289 },
1290 arch: {
1291 riscv64: {
1292 lto: {
1293 thin: false,
1294 },
1295 },
1296 },
1297}`,
1298 ExpectedBazelTargets: []string{
1299 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1300 "local_includes": `["."]`,
1301 "features": `select({
1302 "//build/bazel/platforms/os_arch:android_arm": ["android_thin_lto"],
1303 "//build/bazel/platforms/os_arch:android_arm64": ["android_thin_lto"],
1304 "//build/bazel/platforms/os_arch:android_riscv64": ["-android_thin_lto"],
1305 "//build/bazel/platforms/os_arch:android_x86": ["android_thin_lto"],
1306 "//build/bazel/platforms/os_arch:android_x86_64": ["android_thin_lto"],
1307 "//conditions:default": [],
1308 })`}),
1309 },
1310 })
1311}
1312
1313func TestCcLibrarySharedWithThinLtoDisabledDefaultEnabledVariant(t *testing.T) {
1314 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1315 Description: "cc_library_shared with thin lto disabled by default but enabled on a particular variant",
1316 Blueprint: `
1317cc_library_shared {
1318 name: "foo",
1319 lto: {
1320 never: true,
1321 },
1322 target: {
1323 android: {
1324 lto: {
1325 thin: true,
1326 never: false,
1327 },
1328 },
1329 },
1330}`,
1331 ExpectedBazelTargets: []string{
1332 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1333 "local_includes": `["."]`,
1334 "features": `select({
1335 "//build/bazel/platforms/os:android": ["android_thin_lto"],
1336 "//conditions:default": ["-android_thin_lto"],
1337 })`,
1338 }),
1339 },
1340 })
1341}
1342
1343func TestCcLibrarySharedWithThinLtoAndWholeProgramVtables(t *testing.T) {
1344 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1345 Description: "cc_library_shared has correct features when thin LTO is enabled with whole_program_vtables",
1346 Blueprint: `
1347cc_library_shared {
1348 name: "foo",
1349 lto: {
1350 thin: true,
1351 },
1352 whole_program_vtables: true,
1353}
1354`,
1355 ExpectedBazelTargets: []string{
1356 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1357 "features": `[
1358 "android_thin_lto",
1359 "android_thin_lto_whole_program_vtables",
1360 ]`,
1361 "local_includes": `["."]`,
1362 }),
1363 },
1364 })
1365}
Trevor Radcliffea8b44162023-04-14 18:25:24 +00001366
1367func TestCcLibrarySharedHiddenVisibilityConvertedToFeature(t *testing.T) {
1368 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1369 Description: "cc_library_shared changes hidden visibility flag to feature",
1370 Blueprint: `
1371cc_library_shared{
1372 name: "foo",
1373 cflags: ["-fvisibility=hidden"],
1374}`,
1375 ExpectedBazelTargets: []string{
1376 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1377 "features": `["visibility_hidden"]`,
1378 "local_includes": `["."]`,
1379 }),
1380 },
1381 })
1382}
1383
1384func TestCcLibrarySharedHiddenVisibilityConvertedToFeatureOsSpecific(t *testing.T) {
1385 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1386 Description: "cc_library_shared changes hidden visibility flag to feature for specific os",
1387 Blueprint: `
1388cc_library_shared{
1389 name: "foo",
1390 target: {
1391 android: {
1392 cflags: ["-fvisibility=hidden"],
1393 },
1394 },
1395}`,
1396 ExpectedBazelTargets: []string{
1397 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1398 "features": `select({
1399 "//build/bazel/platforms/os:android": ["visibility_hidden"],
1400 "//conditions:default": [],
1401 })`,
1402 "local_includes": `["."]`,
1403 }),
1404 },
1405 })
1406}
Sam Delmerico75dbca22023-04-20 13:13:25 +00001407
1408func TestCcLibrarySharedStubsDessertVersionConversion(t *testing.T) {
1409 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1410 Description: "cc_library_shared converts dessert codename versions to numerical versions",
1411 Blueprint: `
1412cc_library_shared {
1413 name: "a",
1414 include_build_directory: false,
1415 stubs: {
1416 symbol_file: "a.map.txt",
1417 versions: [
1418 "Q",
1419 "R",
1420 "31",
1421 ],
1422 },
1423}
1424cc_library_shared {
1425 name: "b",
1426 include_build_directory: false,
1427 stubs: {
1428 symbol_file: "b.map.txt",
1429 versions: [
1430 "Q",
1431 "R",
1432 "31",
1433 "current",
1434 ],
1435 },
1436}
1437`,
1438 ExpectedBazelTargets: []string{
1439 makeCcStubSuiteTargets("a", AttrNameToString{
Spandan Das04f9f4c2023-09-13 23:59:05 +00001440 "api_surface": `"module-libapi"`,
Sam Delmerico75dbca22023-04-20 13:13:25 +00001441 "soname": `"a.so"`,
1442 "source_library_label": `"//:a"`,
1443 "stubs_symbol_file": `"a.map.txt"`,
1444 "stubs_versions": `[
1445 "29",
1446 "30",
1447 "31",
1448 "current",
1449 ]`,
1450 }),
1451 MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
1452 "stubs_symbol_file": `"a.map.txt"`,
1453 }),
1454 makeCcStubSuiteTargets("b", AttrNameToString{
Spandan Das04f9f4c2023-09-13 23:59:05 +00001455 "api_surface": `"module-libapi"`,
Sam Delmerico75dbca22023-04-20 13:13:25 +00001456 "soname": `"b.so"`,
1457 "source_library_label": `"//:b"`,
1458 "stubs_symbol_file": `"b.map.txt"`,
1459 "stubs_versions": `[
1460 "29",
1461 "30",
1462 "31",
1463 "current",
1464 ]`,
1465 }),
1466 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
1467 "stubs_symbol_file": `"b.map.txt"`,
1468 }),
1469 },
1470 })
1471}
Trevor Radcliffe27669c02023-03-28 20:47:10 +00001472
1473func TestCcLibrarySharedWithCfi(t *testing.T) {
1474 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1475 Description: "cc_library_shared has correct features when cfi is enabled for specific variants",
1476 Blueprint: `
1477cc_library_shared {
1478 name: "foo",
1479 sanitize: {
1480 cfi: true,
1481 },
1482}`,
1483 ExpectedBazelTargets: []string{
1484 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1485 "features": `["android_cfi"]`,
1486 "local_includes": `["."]`,
1487 }),
1488 },
1489 })
1490}
1491
1492func TestCcLibrarySharedWithCfiOsSpecific(t *testing.T) {
1493 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1494 Description: "cc_library_shared has correct features when cfi is enabled",
1495 Blueprint: `
1496cc_library_shared {
1497 name: "foo",
1498 target: {
1499 android: {
1500 sanitize: {
1501 cfi: true,
1502 },
1503 },
1504 },
1505}`,
1506 ExpectedBazelTargets: []string{
1507 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1508 "features": `select({
1509 "//build/bazel/platforms/os:android": ["android_cfi"],
1510 "//conditions:default": [],
1511 })`,
1512 "local_includes": `["."]`,
1513 }),
1514 },
1515 })
1516}
1517
1518func TestCcLibrarySharedWithCfiAndCfiAssemblySupport(t *testing.T) {
1519 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1520 Description: "cc_library_shared has correct features when cfi is enabled with cfi assembly support",
1521 Blueprint: `
1522cc_library_static {
1523 name: "foo",
1524 sanitize: {
1525 cfi: true,
1526 config: {
1527 cfi_assembly_support: true,
1528 },
1529 },
1530}`,
1531 ExpectedBazelTargets: []string{
1532 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1533 "features": `[
1534 "android_cfi",
1535 "android_cfi_assembly_support",
1536 ]`,
1537 "local_includes": `["."]`,
1538 }),
1539 },
1540 })
1541}
Trevor Radcliffe523c5c62023-06-16 20:15:45 +00001542
1543func TestCcLibrarySharedExplicitlyDisablesCfiWhenFalse(t *testing.T) {
1544 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1545 Description: "cc_library_shared disables cfi when explciitly set to false in the bp",
1546 Blueprint: `
1547cc_library_shared {
1548 name: "foo",
1549 sanitize: {
1550 cfi: false,
1551 },
1552}
1553`,
1554 ExpectedBazelTargets: []string{
1555 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1556 "features": `["-android_cfi"]`,
1557 "local_includes": `["."]`,
1558 }),
1559 },
1560 })
1561}
Alixe2667872023-04-24 14:57:32 +00001562
1563func TestCCLibrarySharedRscriptSrc(t *testing.T) {
1564 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1565 Description: ``,
1566 Blueprint: `
1567cc_library_shared{
1568 name : "foo",
1569 srcs : [
1570 "ccSrc.cc",
1571 "rsSrc.rscript",
1572 ],
1573 include_build_directory: false,
1574}
1575`,
1576 ExpectedBazelTargets: []string{
1577 MakeBazelTarget("rscript_to_cpp", "foo_renderscript", AttrNameToString{
1578 "srcs": `["rsSrc.rscript"]`,
1579 }),
1580 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1581 "absolute_includes": `[
1582 "frameworks/rs",
1583 "frameworks/rs/cpp",
1584 ]`,
1585 "local_includes": `["."]`,
1586 "srcs": `[
1587 "ccSrc.cc",
1588 "foo_renderscript",
1589 ]`,
1590 })}})
1591}
Spandan Das1f65f9e2023-09-15 01:08:23 +00001592
1593func TestCcLibrarySdkVariantUsesStubs(t *testing.T) {
1594 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1595 Description: "cc_library_shared stubs",
1596 ModuleTypeUnderTest: "cc_library_shared",
1597 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
1598 Blueprint: soongCcLibrarySharedPreamble + `
1599cc_library_shared {
1600 name: "libUsesSdk",
1601 sdk_version: "current",
1602 shared_libs: [
1603 "libNoStubs",
1604 "libHasApexStubs",
1605 "libHasApexAndNdkStubs",
1606 ]
1607}
1608cc_library_shared {
1609 name: "libNoStubs",
1610 bazel_module: { bp2build_available: false },
1611}
1612cc_library_shared {
1613 name: "libHasApexStubs",
1614 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
1615 bazel_module: { bp2build_available: false },
1616 apex_available: ["apex_a"],
1617}
1618cc_library_shared {
1619 name: "libHasApexAndNdkStubs",
1620 stubs: { symbol_file: "b.map.txt", versions: ["28", "29", "current"] },
1621 bazel_module: { bp2build_available: false },
1622 apex_available: ["apex_b"],
1623}
1624ndk_library {
1625 name: "libHasApexAndNdkStubs",
1626 bazel_module: { bp2build_available: false },
1627}
1628`,
1629 ExpectedBazelTargets: []string{
1630 MakeBazelTarget("cc_library_shared", "libUsesSdk", AttrNameToString{
1631 "implementation_dynamic_deps": `[":libNoStubs"] + select({
1632 "//build/bazel/rules/apex:system": [
1633 "@api_surfaces//module-libapi/current:libHasApexStubs",
1634 "@api_surfaces//module-libapi/current:libHasApexAndNdkStubs",
1635 ],
1636 "//build/bazel/rules/apex:unbundled_app": [
1637 ":libHasApexStubs",
1638 "//.:libHasApexAndNdkStubs.ndk_stub_libs",
1639 ],
1640 "//conditions:default": [
1641 ":libHasApexStubs",
1642 ":libHasApexAndNdkStubs",
1643 ],
1644 })`,
1645 "local_includes": `["."]`,
1646 "sdk_version": `"current"`,
1647 }),
1648 },
1649 })
1650}