blob: 921e6e30b67ff14db6b96b7d72531d2b13772b90 [file] [log] [blame]
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +00001// Copyright 2021 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package bp2build
16
17import (
18 "testing"
19
20 "android/soong/android"
21 "android/soong/cc"
22)
23
24const (
25 // See cc/testing.go for more context
26 // TODO(alexmarquez): Split out the preamble into common code?
27 soongCcLibrarySharedPreamble = soongCcLibraryStaticPreamble
28)
29
30func registerCcLibrarySharedModuleTypes(ctx android.RegistrationContext) {
31 cc.RegisterCCBuildComponents(ctx)
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000032 ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
33 ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory)
Liz Kammer12615db2021-09-28 09:19:17 -040034 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000035}
36
Sam Delmerico3177a6e2022-06-21 19:28:33 +000037func runCcLibrarySharedTestCase(t *testing.T, tc Bp2buildTestCase) {
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000038 t.Helper()
Alex Márquez Pérez Muñíz Díaz Puras Thaureauxc641cc42023-03-16 17:03:43 +000039 t.Parallel()
Sam Delmerico3177a6e2022-06-21 19:28:33 +000040 (&tc).ModuleTypeUnderTest = "cc_library_shared"
41 (&tc).ModuleTypeUnderTestFactory = cc.LibrarySharedFactory
42 RunBp2BuildTestCase(t, registerCcLibrarySharedModuleTypes, tc)
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000043}
44
45func TestCcLibrarySharedSimple(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000046 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
47 Description: "cc_library_shared simple overall test",
48 Filesystem: map[string]string{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000049 // NOTE: include_dir headers *should not* appear in Bazel hdrs later (?)
50 "include_dir_1/include_dir_1_a.h": "",
51 "include_dir_1/include_dir_1_b.h": "",
52 "include_dir_2/include_dir_2_a.h": "",
53 "include_dir_2/include_dir_2_b.h": "",
54 // NOTE: local_include_dir headers *should not* appear in Bazel hdrs later (?)
55 "local_include_dir_1/local_include_dir_1_a.h": "",
56 "local_include_dir_1/local_include_dir_1_b.h": "",
57 "local_include_dir_2/local_include_dir_2_a.h": "",
58 "local_include_dir_2/local_include_dir_2_b.h": "",
59 // NOTE: export_include_dir headers *should* appear in Bazel hdrs later
60 "export_include_dir_1/export_include_dir_1_a.h": "",
61 "export_include_dir_1/export_include_dir_1_b.h": "",
62 "export_include_dir_2/export_include_dir_2_a.h": "",
63 "export_include_dir_2/export_include_dir_2_b.h": "",
64 // NOTE: Soong implicitly includes headers in the current directory
65 "implicit_include_1.h": "",
66 "implicit_include_2.h": "",
67 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +000068 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000069cc_library_headers {
70 name: "header_lib_1",
71 export_include_dirs: ["header_lib_1"],
72 bazel_module: { bp2build_available: false },
73}
74
75cc_library_headers {
76 name: "header_lib_2",
77 export_include_dirs: ["header_lib_2"],
78 bazel_module: { bp2build_available: false },
79}
80
81cc_library_shared {
82 name: "shared_lib_1",
83 srcs: ["shared_lib_1.cc"],
84 bazel_module: { bp2build_available: false },
85}
86
87cc_library_shared {
88 name: "shared_lib_2",
89 srcs: ["shared_lib_2.cc"],
90 bazel_module: { bp2build_available: false },
91}
92
93cc_library_static {
94 name: "whole_static_lib_1",
95 srcs: ["whole_static_lib_1.cc"],
96 bazel_module: { bp2build_available: false },
97}
98
99cc_library_static {
100 name: "whole_static_lib_2",
101 srcs: ["whole_static_lib_2.cc"],
102 bazel_module: { bp2build_available: false },
103}
104
105cc_library_shared {
106 name: "foo_shared",
107 srcs: [
108 "foo_shared1.cc",
109 "foo_shared2.cc",
110 ],
111 cflags: [
112 "-Dflag1",
113 "-Dflag2"
114 ],
115 shared_libs: [
116 "shared_lib_1",
117 "shared_lib_2"
118 ],
119 whole_static_libs: [
120 "whole_static_lib_1",
121 "whole_static_lib_2"
122 ],
123 include_dirs: [
124 "include_dir_1",
125 "include_dir_2",
126 ],
127 local_include_dirs: [
128 "local_include_dir_1",
129 "local_include_dir_2",
130 ],
131 export_include_dirs: [
132 "export_include_dir_1",
133 "export_include_dir_2"
134 ],
135 header_libs: [
136 "header_lib_1",
137 "header_lib_2"
138 ],
Yu Liufc603162022-03-01 15:44:08 -0800139 sdk_version: "current",
140 min_sdk_version: "29",
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000141
142 // TODO: Also support export_header_lib_headers
143}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000144 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000145 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500146 "absolute_includes": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000147 "include_dir_1",
148 "include_dir_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500149 ]`,
150 "copts": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000151 "-Dflag1",
152 "-Dflag2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500153 ]`,
154 "export_includes": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000155 "export_include_dir_1",
156 "export_include_dir_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500157 ]`,
158 "implementation_deps": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000159 ":header_lib_1",
160 ":header_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500161 ]`,
162 "implementation_dynamic_deps": `[
Liz Kammer7a210ac2021-09-22 15:52:58 -0400163 ":shared_lib_1",
164 ":shared_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500165 ]`,
166 "local_includes": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000167 "local_include_dir_1",
168 "local_include_dir_2",
169 ".",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500170 ]`,
171 "srcs": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000172 "foo_shared1.cc",
173 "foo_shared2.cc",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500174 ]`,
175 "whole_archive_deps": `[
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000176 ":whole_static_lib_1",
177 ":whole_static_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500178 ]`,
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000179 "sdk_version": `"current"`,
180 "min_sdk_version": `"29"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500181 }),
182 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000183 })
184}
185
186func TestCcLibrarySharedArchSpecificSharedLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000187 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
188 Description: "cc_library_shared arch-specific shared_libs with whole_static_libs",
189 Filesystem: map[string]string{},
190 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000191cc_library_static {
192 name: "static_dep",
193 bazel_module: { bp2build_available: false },
194}
195cc_library_shared {
196 name: "shared_dep",
197 bazel_module: { bp2build_available: false },
198}
199cc_library_shared {
200 name: "foo_shared",
201 arch: { arm64: { shared_libs: ["shared_dep"], whole_static_libs: ["static_dep"] } },
202 include_build_directory: false,
203}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000204 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000205 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500206 "implementation_dynamic_deps": `select({
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000207 "//build/bazel/platforms/arch:arm64": [":shared_dep"],
208 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500209 })`,
210 "whole_archive_deps": `select({
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000211 "//build/bazel/platforms/arch:arm64": [":static_dep"],
212 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500213 })`,
214 }),
215 },
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000216 })
217}
218
219func TestCcLibrarySharedOsSpecificSharedLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000220 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
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 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000512 Blueprint: soongCcProtoPreamble + `cc_library_shared {
Rupert Shuttleworth484aa252021-12-10 07:22:53 -0500513 name: "foo",
514 use_version_lib: true,
515 include_build_directory: false,
516}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000517 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000518 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Yu Liufe978fd2023-04-24 16:37:18 -0700519 "use_version_lib": "True",
520 "whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
Rupert Shuttleworth484aa252021-12-10 07:22:53 -0500521 }),
522 },
523 })
524}
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000525
526func TestCcLibrarySharedStubs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000527 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
528 Description: "cc_library_shared stubs",
529 ModuleTypeUnderTest: "cc_library_shared",
530 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
531 Dir: "foo/bar",
532 Filesystem: map[string]string{
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000533 "foo/bar/Android.bp": `
534cc_library_shared {
535 name: "a",
536 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
537 bazel_module: { bp2build_available: true },
538 include_build_directory: false,
539}
540`,
541 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000542 Blueprint: soongCcLibraryPreamble,
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000543 ExpectedBazelTargets: []string{makeCcStubSuiteTargets("a", AttrNameToString{
Spandan Das04f9f4c2023-09-13 23:59:05 +0000544 "api_surface": `"module-libapi"`,
Sam Delmerico5f906492023-03-15 18:06:18 -0400545 "soname": `"a.so"`,
546 "source_library_label": `"//foo/bar:a"`,
547 "stubs_symbol_file": `"a.map.txt"`,
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000548 "stubs_versions": `[
Trevor Radcliffe087af542022-09-16 15:36:10 +0000549 "28",
550 "29",
551 "current",
552 ]`,
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000553 }),
554 MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
Yu Liu56ccb1a2022-11-12 10:47:07 -0800555 "stubs_symbol_file": `"a.map.txt"`,
Trevor Radcliffe087af542022-09-16 15:36:10 +0000556 }),
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000557 },
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000558 })
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000559}
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000560
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400561func TestCcLibrarySharedStubs_UseImplementationInSameApex(t *testing.T) {
562 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
563 Description: "cc_library_shared stubs",
564 ModuleTypeUnderTest: "cc_library_shared",
565 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
566 Blueprint: soongCcLibrarySharedPreamble + `
567cc_library_shared {
568 name: "a",
569 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
570 bazel_module: { bp2build_available: false },
571 include_build_directory: false,
572 apex_available: ["made_up_apex"],
573}
574cc_library_shared {
575 name: "b",
576 shared_libs: [":a"],
577 include_build_directory: false,
578 apex_available: ["made_up_apex"],
579}
580`,
581 ExpectedBazelTargets: []string{
582 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
583 "implementation_dynamic_deps": `[":a"]`,
584 "tags": `["apex_available=made_up_apex"]`,
585 }),
586 },
587 })
588}
589
590func TestCcLibrarySharedStubs_UseStubsInDifferentApex(t *testing.T) {
591 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
592 Description: "cc_library_shared stubs",
593 ModuleTypeUnderTest: "cc_library_shared",
594 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
595 Blueprint: soongCcLibrarySharedPreamble + `
596cc_library_shared {
597 name: "a",
598 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
599 bazel_module: { bp2build_available: false },
600 include_build_directory: false,
601 apex_available: ["apex_a"],
602}
603cc_library_shared {
604 name: "b",
605 shared_libs: [":a"],
606 include_build_directory: false,
607 apex_available: ["apex_b"],
608}
609`,
610 ExpectedBazelTargets: []string{
611 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
612 "implementation_dynamic_deps": `select({
Spandan Das6d4d9da2023-04-18 06:20:40 +0000613 "//build/bazel/rules/apex:apex_b": ["@api_surfaces//module-libapi/current:a"],
614 "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400615 "//conditions:default": [":a"],
616 })`,
617 "tags": `["apex_available=apex_b"]`,
618 }),
619 },
620 })
621}
622
Spandan Das6d4d9da2023-04-18 06:20:40 +0000623// Tests that library in apexfoo links against stubs of platform_lib and otherapex_lib
624func TestCcLibrarySharedStubs_UseStubsFromMultipleApiDomains(t *testing.T) {
625 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
626 Description: "cc_library_shared stubs",
627 ModuleTypeUnderTest: "cc_library_shared",
628 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
629 Blueprint: soongCcLibrarySharedPreamble + `
630cc_library_shared {
631 name: "libplatform_stable",
632 stubs: { symbol_file: "libplatform_stable.map.txt", versions: ["28", "29", "current"] },
633 apex_available: ["//apex_available:platform"],
634 bazel_module: { bp2build_available: false },
635 include_build_directory: false,
636}
637cc_library_shared {
638 name: "libapexfoo_stable",
639 stubs: { symbol_file: "libapexfoo_stable.map.txt", versions: ["28", "29", "current"] },
640 apex_available: ["apexfoo"],
641 bazel_module: { bp2build_available: false },
642 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,
686 Blueprint: soongCcLibrarySharedPreamble + `
687cc_library_shared {
688 name: "a",
689 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
690 bazel_module: { bp2build_available: false },
691 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,
722 Blueprint: soongCcLibrarySharedPreamble + `
723cc_library_shared {
724 name: "a",
725 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
726 bazel_module: { bp2build_available: false },
727 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,
749 Blueprint: soongCcLibrarySharedPreamble + `
750cc_library_shared {
751 name: "a",
752 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
753 bazel_module: { bp2build_available: false },
754 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",
931 runtime_libs: ["foo"],
932}`,
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{
Cole Faust6b29f592022-08-09 09:50:56 -0700938 "runtime_deps": `[":foo"]`,
939 "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: `
1526cc_library_static {
1527 name: "foo",
1528 sanitize: {
1529 cfi: true,
1530 config: {
1531 cfi_assembly_support: true,
1532 },
1533 },
1534}`,
1535 ExpectedBazelTargets: []string{
1536 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1537 "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}