blob: 9b533f3970ca8d1284d5261797a64bf3e4c025fe [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{
Sam Delmerico5f906492023-03-15 18:06:18 -0400544 "soname": `"a.so"`,
545 "source_library_label": `"//foo/bar:a"`,
546 "stubs_symbol_file": `"a.map.txt"`,
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000547 "stubs_versions": `[
Trevor Radcliffe087af542022-09-16 15:36:10 +0000548 "28",
549 "29",
550 "current",
551 ]`,
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000552 }),
553 MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
Yu Liu56ccb1a2022-11-12 10:47:07 -0800554 "stubs_symbol_file": `"a.map.txt"`,
Trevor Radcliffe087af542022-09-16 15:36:10 +0000555 }),
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000556 },
Trevor Radcliffef19d8a72022-09-20 23:04:39 +0000557 })
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000558}
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000559
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400560func TestCcLibrarySharedStubs_UseImplementationInSameApex(t *testing.T) {
561 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
562 Description: "cc_library_shared stubs",
563 ModuleTypeUnderTest: "cc_library_shared",
564 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
565 Blueprint: soongCcLibrarySharedPreamble + `
566cc_library_shared {
567 name: "a",
568 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
569 bazel_module: { bp2build_available: false },
570 include_build_directory: false,
571 apex_available: ["made_up_apex"],
572}
573cc_library_shared {
574 name: "b",
575 shared_libs: [":a"],
576 include_build_directory: false,
577 apex_available: ["made_up_apex"],
578}
579`,
580 ExpectedBazelTargets: []string{
581 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
582 "implementation_dynamic_deps": `[":a"]`,
583 "tags": `["apex_available=made_up_apex"]`,
584 }),
585 },
586 })
587}
588
589func TestCcLibrarySharedStubs_UseStubsInDifferentApex(t *testing.T) {
590 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
591 Description: "cc_library_shared stubs",
592 ModuleTypeUnderTest: "cc_library_shared",
593 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
594 Blueprint: soongCcLibrarySharedPreamble + `
595cc_library_shared {
596 name: "a",
597 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
598 bazel_module: { bp2build_available: false },
599 include_build_directory: false,
600 apex_available: ["apex_a"],
601}
602cc_library_shared {
603 name: "b",
604 shared_libs: [":a"],
605 include_build_directory: false,
606 apex_available: ["apex_b"],
607}
608`,
609 ExpectedBazelTargets: []string{
610 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
611 "implementation_dynamic_deps": `select({
Spandan Das6d4d9da2023-04-18 06:20:40 +0000612 "//build/bazel/rules/apex:apex_b": ["@api_surfaces//module-libapi/current:a"],
613 "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400614 "//conditions:default": [":a"],
615 })`,
616 "tags": `["apex_available=apex_b"]`,
617 }),
618 },
619 })
620}
621
Spandan Das6d4d9da2023-04-18 06:20:40 +0000622// Tests that library in apexfoo links against stubs of platform_lib and otherapex_lib
623func TestCcLibrarySharedStubs_UseStubsFromMultipleApiDomains(t *testing.T) {
624 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
625 Description: "cc_library_shared stubs",
626 ModuleTypeUnderTest: "cc_library_shared",
627 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
628 Blueprint: soongCcLibrarySharedPreamble + `
629cc_library_shared {
630 name: "libplatform_stable",
631 stubs: { symbol_file: "libplatform_stable.map.txt", versions: ["28", "29", "current"] },
632 apex_available: ["//apex_available:platform"],
633 bazel_module: { bp2build_available: false },
634 include_build_directory: false,
635}
636cc_library_shared {
637 name: "libapexfoo_stable",
638 stubs: { symbol_file: "libapexfoo_stable.map.txt", versions: ["28", "29", "current"] },
639 apex_available: ["apexfoo"],
640 bazel_module: { bp2build_available: false },
641 include_build_directory: false,
642}
643cc_library_shared {
644 name: "libutils",
645 shared_libs: ["libplatform_stable", "libapexfoo_stable",],
646 apex_available: ["//apex_available:platform", "apexfoo", "apexbar"],
647 include_build_directory: false,
648}
649`,
650 ExpectedBazelTargets: []string{
651 MakeBazelTarget("cc_library_shared", "libutils", AttrNameToString{
652 "implementation_dynamic_deps": `select({
653 "//build/bazel/rules/apex:apexbar": [
654 "@api_surfaces//module-libapi/current:libplatform_stable",
655 "@api_surfaces//module-libapi/current:libapexfoo_stable",
656 ],
657 "//build/bazel/rules/apex:apexfoo": [
658 "@api_surfaces//module-libapi/current:libplatform_stable",
659 ":libapexfoo_stable",
660 ],
661 "//build/bazel/rules/apex:system": [
Spandan Dasf7bae9a2023-09-06 22:07:15 +0000662 ":libplatform_stable",
Spandan Das6d4d9da2023-04-18 06:20:40 +0000663 "@api_surfaces//module-libapi/current:libapexfoo_stable",
664 ],
665 "//conditions:default": [
666 ":libplatform_stable",
667 ":libapexfoo_stable",
668 ],
669 })`,
670 "tags": `[
671 "apex_available=//apex_available:platform",
672 "apex_available=apexfoo",
673 "apex_available=apexbar",
674 ]`,
675 }),
676 },
677 })
678}
679
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400680func TestCcLibrarySharedStubs_IgnorePlatformAvailable(t *testing.T) {
681 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
682 Description: "cc_library_shared stubs",
683 ModuleTypeUnderTest: "cc_library_shared",
684 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
685 Blueprint: soongCcLibrarySharedPreamble + `
686cc_library_shared {
687 name: "a",
688 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
689 bazel_module: { bp2build_available: false },
690 include_build_directory: false,
691 apex_available: ["//apex_available:platform", "apex_a"],
692}
693cc_library_shared {
694 name: "b",
695 shared_libs: [":a"],
696 include_build_directory: false,
697 apex_available: ["//apex_available:platform", "apex_b"],
698}
699`,
700 ExpectedBazelTargets: []string{
701 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
702 "implementation_dynamic_deps": `select({
Spandan Das6d4d9da2023-04-18 06:20:40 +0000703 "//build/bazel/rules/apex:apex_b": ["@api_surfaces//module-libapi/current:a"],
704 "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400705 "//conditions:default": [":a"],
706 })`,
707 "tags": `[
708 "apex_available=//apex_available:platform",
709 "apex_available=apex_b",
710 ]`,
711 }),
712 },
713 })
714}
715
Spandan Das6d4d9da2023-04-18 06:20:40 +0000716func TestCcLibraryDoesNotDropStubDepIfNoVariationAcrossAxis(t *testing.T) {
717 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
718 Description: "cc_library depeends on impl for all configurations",
719 ModuleTypeUnderTest: "cc_library_shared",
720 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
721 Blueprint: soongCcLibrarySharedPreamble + `
722cc_library_shared {
723 name: "a",
724 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
725 bazel_module: { bp2build_available: false },
726 apex_available: ["//apex_available:platform"],
727}
728cc_library_shared {
729 name: "b",
730 shared_libs: [":a"],
731 include_build_directory: false,
732 apex_available: ["//apex_available:platform"],
733}
734`,
735 ExpectedBazelTargets: []string{
736 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
737 "implementation_dynamic_deps": `[":a"]`,
738 "tags": `["apex_available=//apex_available:platform"]`,
739 }),
740 },
741 })
742}
743
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400744func TestCcLibrarySharedStubs_MultipleApexAvailable(t *testing.T) {
745 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
746 ModuleTypeUnderTest: "cc_library_shared",
747 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
748 Blueprint: soongCcLibrarySharedPreamble + `
749cc_library_shared {
750 name: "a",
751 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
752 bazel_module: { bp2build_available: false },
753 include_build_directory: false,
754 apex_available: ["//apex_available:platform", "apex_a", "apex_b"],
755}
756cc_library_shared {
757 name: "b",
758 shared_libs: [":a"],
759 include_build_directory: false,
760 apex_available: ["//apex_available:platform", "apex_b"],
761}
762
763cc_library_shared {
764 name: "c",
765 shared_libs: [":a"],
766 include_build_directory: false,
767 apex_available: ["//apex_available:platform", "apex_a", "apex_b"],
768}
769`,
770 ExpectedBazelTargets: []string{
771 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
772 "implementation_dynamic_deps": `select({
Spandan Das6d4d9da2023-04-18 06:20:40 +0000773 "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
Liz Kammer48cdbeb2023-03-17 10:17:50 -0400774 "//conditions:default": [":a"],
775 })`,
776 "tags": `[
777 "apex_available=//apex_available:platform",
778 "apex_available=apex_b",
779 ]`,
780 }),
781 MakeBazelTarget("cc_library_shared", "c", AttrNameToString{
782 "implementation_dynamic_deps": `[":a"]`,
783 "tags": `[
784 "apex_available=//apex_available:platform",
785 "apex_available=apex_a",
786 "apex_available=apex_b",
787 ]`,
788 }),
789 },
790 })
791}
792
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000793func TestCcLibrarySharedSystemSharedLibsSharedEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000794 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
795 Description: "cc_library_shared system_shared_libs empty shared default",
796 ModuleTypeUnderTest: "cc_library_shared",
797 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
798 Blueprint: soongCcLibrarySharedPreamble + `
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000799cc_defaults {
800 name: "empty_defaults",
801 shared: {
802 system_shared_libs: [],
803 },
804 include_build_directory: false,
805}
806cc_library_shared {
807 name: "empty",
808 defaults: ["empty_defaults"],
809}
810`,
Alixe06d75b2022-08-31 18:28:19 +0000811 ExpectedBazelTargets: []string{MakeBazelTarget("cc_library_shared", "empty", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux126bd582022-04-21 15:19:27 +0000812 "system_dynamic_deps": "[]",
813 })},
814 })
815}
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000816
817func TestCcLibrarySharedConvertLex(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000818 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
819 Description: "cc_library_shared with lex files",
820 ModuleTypeUnderTest: "cc_library_shared",
821 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
822 Filesystem: map[string]string{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000823 "foo.c": "",
824 "bar.cc": "",
825 "foo1.l": "",
826 "bar1.ll": "",
827 "foo2.l": "",
828 "bar2.ll": "",
829 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000830 Blueprint: `cc_library_shared {
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000831 name: "foo_lib",
832 srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"],
833 lex: { flags: ["--foo_flags"] },
834 include_build_directory: false,
835 bazel_module: { bp2build_available: true },
836}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000837 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000838 MakeBazelTarget("genlex", "foo_lib_genlex_l", AttrNameToString{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000839 "srcs": `[
840 "foo1.l",
841 "foo2.l",
842 ]`,
843 "lexopts": `["--foo_flags"]`,
844 }),
Alixe06d75b2022-08-31 18:28:19 +0000845 MakeBazelTarget("genlex", "foo_lib_genlex_ll", AttrNameToString{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000846 "srcs": `[
847 "bar1.ll",
848 "bar2.ll",
849 ]`,
850 "lexopts": `["--foo_flags"]`,
851 }),
Alixe06d75b2022-08-31 18:28:19 +0000852 MakeBazelTarget("cc_library_shared", "foo_lib", AttrNameToString{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000853 "srcs": `[
854 "bar.cc",
855 ":foo_lib_genlex_ll",
856 ]`,
857 "srcs_c": `[
858 "foo.c",
859 ":foo_lib_genlex_l",
860 ]`,
861 }),
862 },
863 })
864}
Alix1be00d42022-05-16 22:56:04 +0000865
866func TestCcLibrarySharedClangUnknownFlags(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000867 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
868 Blueprint: soongCcProtoPreamble + `cc_library_shared {
Alix1be00d42022-05-16 22:56:04 +0000869 name: "foo",
870 conlyflags: ["-a", "-finline-functions"],
871 cflags: ["-b","-finline-functions"],
872 cppflags: ["-c", "-finline-functions"],
873 ldflags: ["-d","-finline-functions", "-e"],
874 include_build_directory: false,
875}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000876 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000877 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Alix1be00d42022-05-16 22:56:04 +0000878 "conlyflags": `["-a"]`,
879 "copts": `["-b"]`,
880 "cppflags": `["-c"]`,
881 "linkopts": `[
882 "-d",
883 "-e",
884 ]`,
885 }),
886 },
887 })
888}
889
890func TestCCLibraryFlagSpaceSplitting(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000891 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
892 Blueprint: soongCcProtoPreamble + `cc_library_shared {
Alix1be00d42022-05-16 22:56:04 +0000893 name: "foo",
894 conlyflags: [ "-include header.h"],
895 cflags: ["-include header.h"],
896 cppflags: ["-include header.h"],
897 version_script: "version_script",
898 include_build_directory: false,
899}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000900 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000901 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Alix1be00d42022-05-16 22:56:04 +0000902 "additional_linker_inputs": `["version_script"]`,
903 "conlyflags": `[
904 "-include",
905 "header.h",
906 ]`,
907 "copts": `[
908 "-include",
909 "header.h",
910 ]`,
911 "cppflags": `[
912 "-include",
913 "header.h",
914 ]`,
915 "linkopts": `["-Wl,--version-script,$(location version_script)"]`,
Trevor Radcliffef06dd912023-05-19 14:51:41 +0000916 "features": `["android_cfi_exports_map"]`,
Alix1be00d42022-05-16 22:56:04 +0000917 }),
918 },
919 })
920}
Cole Faust6b29f592022-08-09 09:50:56 -0700921
922func TestCCLibrarySharedRuntimeDeps(t *testing.T) {
923 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
924 Blueprint: `cc_library_shared {
925 name: "bar",
926}
927
928cc_library_shared {
929 name: "foo",
930 runtime_libs: ["foo"],
931}`,
932 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000933 MakeBazelTarget("cc_library_shared", "bar", AttrNameToString{
Cole Faust6b29f592022-08-09 09:50:56 -0700934 "local_includes": `["."]`,
935 }),
Alixe06d75b2022-08-31 18:28:19 +0000936 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Cole Faust6b29f592022-08-09 09:50:56 -0700937 "runtime_deps": `[":foo"]`,
938 "local_includes": `["."]`,
939 }),
940 },
941 })
942}
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -0500943
944func TestCcLibrarySharedEmptySuffix(t *testing.T) {
945 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
946 Description: "cc_library_shared with empty suffix",
947 Filesystem: map[string]string{
948 "foo.c": "",
949 },
950 Blueprint: soongCcLibrarySharedPreamble + `
951cc_library_shared {
952 name: "foo_shared",
953 suffix: "",
954 srcs: ["foo.c"],
955 include_build_directory: false,
956}`,
957 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000958 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -0500959 "srcs_c": `["foo.c"]`,
960 "suffix": `""`,
961 }),
962 },
963 })
964}
965
966func TestCcLibrarySharedSuffix(t *testing.T) {
967 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
968 Description: "cc_library_shared with suffix",
969 Filesystem: map[string]string{
970 "foo.c": "",
971 },
972 Blueprint: soongCcLibrarySharedPreamble + `
973cc_library_shared {
974 name: "foo_shared",
975 suffix: "-suf",
976 srcs: ["foo.c"],
977 include_build_directory: false,
978}`,
979 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000980 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -0500981 "srcs_c": `["foo.c"]`,
982 "suffix": `"-suf"`,
983 }),
984 },
985 })
986}
987
988func TestCcLibrarySharedArchVariantSuffix(t *testing.T) {
989 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
990 Description: "cc_library_shared with arch-variant suffix",
991 Filesystem: map[string]string{
992 "foo.c": "",
993 },
994 Blueprint: soongCcLibrarySharedPreamble + `
995cc_library_shared {
996 name: "foo_shared",
997 arch: {
998 arm64: { suffix: "-64" },
999 arm: { suffix: "-32" },
1000 },
1001 srcs: ["foo.c"],
1002 include_build_directory: false,
1003}`,
1004 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001005 MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -05001006 "srcs_c": `["foo.c"]`,
1007 "suffix": `select({
1008 "//build/bazel/platforms/arch:arm": "-32",
1009 "//build/bazel/platforms/arch:arm64": "-64",
1010 "//conditions:default": None,
1011 })`,
1012 }),
1013 },
1014 })
1015}
Trevor Radcliffecee4e052022-09-06 19:31:25 +00001016
1017func TestCcLibrarySharedWithSyspropSrcs(t *testing.T) {
1018 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1019 Description: "cc_library_shared with sysprop sources",
1020 Blueprint: `
1021cc_library_shared {
1022 name: "foo",
1023 srcs: [
1024 "bar.sysprop",
1025 "baz.sysprop",
1026 "blah.cpp",
1027 ],
1028 min_sdk_version: "5",
1029}`,
1030 ExpectedBazelTargets: []string{
1031 MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
1032 "srcs": `[
1033 "bar.sysprop",
1034 "baz.sysprop",
1035 ]`,
1036 }),
1037 MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
1038 "dep": `":foo_sysprop_library"`,
1039 "min_sdk_version": `"5"`,
1040 }),
1041 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1042 "srcs": `["blah.cpp"]`,
1043 "local_includes": `["."]`,
1044 "min_sdk_version": `"5"`,
1045 "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`,
1046 }),
1047 },
1048 })
1049}
1050
1051func TestCcLibrarySharedWithSyspropSrcsSomeConfigs(t *testing.T) {
1052 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1053 Description: "cc_library_shared with sysprop sources in some configs but not others",
1054 Blueprint: `
1055cc_library_shared {
1056 name: "foo",
1057 srcs: [
1058 "blah.cpp",
1059 ],
1060 target: {
1061 android: {
1062 srcs: ["bar.sysprop"],
1063 },
1064 },
1065 min_sdk_version: "5",
1066}`,
1067 ExpectedBazelTargets: []string{
1068 MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
1069 "srcs": `select({
1070 "//build/bazel/platforms/os:android": ["bar.sysprop"],
1071 "//conditions:default": [],
1072 })`,
1073 }),
1074 MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
1075 "dep": `":foo_sysprop_library"`,
1076 "min_sdk_version": `"5"`,
1077 }),
1078 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1079 "srcs": `["blah.cpp"]`,
1080 "local_includes": `["."]`,
1081 "min_sdk_version": `"5"`,
1082 "whole_archive_deps": `select({
1083 "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"],
1084 "//conditions:default": [],
1085 })`,
1086 }),
1087 },
1088 })
1089}
Yu Liu56ccb1a2022-11-12 10:47:07 -08001090
1091func TestCcLibrarySharedHeaderAbiChecker(t *testing.T) {
1092 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1093 Description: "cc_library_shared with header abi checker",
1094 Blueprint: `cc_library_shared {
1095 name: "foo",
1096 header_abi_checker: {
1097 enabled: true,
1098 symbol_file: "a.map.txt",
1099 exclude_symbol_versions: [
1100 "29",
1101 "30",
1102 ],
1103 exclude_symbol_tags: [
1104 "tag1",
1105 "tag2",
1106 ],
1107 check_all_apis: true,
1108 diff_flags: ["-allow-adding-removing-weak-symbols"],
1109 },
1110 include_build_directory: false,
1111}`,
1112 ExpectedBazelTargets: []string{
1113 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1114 "abi_checker_enabled": `True`,
1115 "abi_checker_symbol_file": `"a.map.txt"`,
1116 "abi_checker_exclude_symbol_versions": `[
1117 "29",
1118 "30",
1119 ]`,
1120 "abi_checker_exclude_symbol_tags": `[
1121 "tag1",
1122 "tag2",
1123 ]`,
1124 "abi_checker_check_all_apis": `True`,
1125 "abi_checker_diff_flags": `["-allow-adding-removing-weak-symbols"]`,
1126 }),
1127 },
1128 })
1129}
Trevor Radcliffedb7e0262022-10-28 16:48:18 +00001130
1131func TestCcLibrarySharedWithIntegerOverflowProperty(t *testing.T) {
1132 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1133 Description: "cc_library_shared has correct features when integer_overflow property is provided",
1134 Blueprint: `
1135cc_library_shared {
1136 name: "foo",
1137 sanitize: {
1138 integer_overflow: true,
1139 },
1140}
1141`,
1142 ExpectedBazelTargets: []string{
1143 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1144 "features": `["ubsan_integer_overflow"]`,
1145 "local_includes": `["."]`,
1146 }),
1147 },
1148 })
1149}
1150
1151func TestCcLibrarySharedWithMiscUndefinedProperty(t *testing.T) {
1152 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1153 Description: "cc_library_shared has correct features when misc_undefined property is provided",
1154 Blueprint: `
1155cc_library_shared {
1156 name: "foo",
1157 sanitize: {
1158 misc_undefined: ["undefined", "nullability"],
1159 },
1160}
1161`,
1162 ExpectedBazelTargets: []string{
1163 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1164 "features": `[
1165 "ubsan_undefined",
1166 "ubsan_nullability",
1167 ]`,
1168 "local_includes": `["."]`,
1169 }),
1170 },
1171 })
1172}
1173
1174func TestCcLibrarySharedWithUBSanPropertiesArchSpecific(t *testing.T) {
1175 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1176 Description: "cc_library_shared has correct feature select when UBSan props are specified in arch specific blocks",
1177 Blueprint: `
1178cc_library_shared {
1179 name: "foo",
1180 sanitize: {
1181 misc_undefined: ["undefined", "nullability"],
1182 },
1183 target: {
1184 android: {
1185 sanitize: {
1186 misc_undefined: ["alignment"],
1187 },
1188 },
1189 linux_glibc: {
1190 sanitize: {
1191 integer_overflow: true,
1192 },
1193 },
1194 },
1195}
1196`,
1197 ExpectedBazelTargets: []string{
1198 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1199 "features": `[
1200 "ubsan_undefined",
1201 "ubsan_nullability",
1202 ] + select({
1203 "//build/bazel/platforms/os:android": ["ubsan_alignment"],
1204 "//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"],
1205 "//conditions:default": [],
1206 })`,
1207 "local_includes": `["."]`,
1208 }),
1209 },
1210 })
1211}
Trevor Radcliffe56b1a2b2023-02-06 21:58:30 +00001212
Trevor Radcliffeded095c2023-06-12 19:18:28 +00001213func TestCcLibrarySharedWithSanitizerBlocklist(t *testing.T) {
1214 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1215 Description: "cc_library_shared has correct features when sanitize.blocklist is provided",
1216 Blueprint: `
1217cc_library_shared {
1218 name: "foo",
1219 sanitize: {
1220 blocklist: "foo_blocklist.txt",
1221 },
1222}
1223`,
1224 ExpectedBazelTargets: []string{
1225 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Trevor Radcliffed9b7f172023-08-09 22:21:38 +00001226 "copts": `select({
1227 "//build/bazel/rules/cc:sanitizers_enabled": ["-fsanitize-ignorelist=$(location foo_blocklist.txt)"],
1228 "//conditions:default": [],
1229 })`,
1230 "additional_compiler_inputs": `select({
1231 "//build/bazel/rules/cc:sanitizers_enabled": [":foo_blocklist.txt"],
1232 "//conditions:default": [],
1233 })`,
Trevor Radcliffeded095c2023-06-12 19:18:28 +00001234 "local_includes": `["."]`,
1235 }),
1236 },
1237 })
1238}
1239
Trevor Radcliffe56b1a2b2023-02-06 21:58:30 +00001240func TestCcLibrarySharedWithThinLto(t *testing.T) {
1241 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1242 Description: "cc_library_shared has correct features when thin lto is enabled",
1243 Blueprint: `
1244cc_library_shared {
1245 name: "foo",
1246 lto: {
1247 thin: true,
1248 },
1249}
1250`,
1251 ExpectedBazelTargets: []string{
1252 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1253 "features": `["android_thin_lto"]`,
1254 "local_includes": `["."]`,
1255 }),
1256 },
1257 })
1258}
1259
1260func TestCcLibrarySharedWithLtoNever(t *testing.T) {
1261 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1262 Description: "cc_library_shared has correct features when thin lto is enabled",
1263 Blueprint: `
1264cc_library_shared {
1265 name: "foo",
1266 lto: {
1267 never: true,
1268 },
1269}
1270`,
1271 ExpectedBazelTargets: []string{
1272 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1273 "features": `["-android_thin_lto"]`,
1274 "local_includes": `["."]`,
1275 }),
1276 },
1277 })
1278}
1279
1280func TestCcLibrarySharedWithThinLtoArchSpecific(t *testing.T) {
1281 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1282 Description: "cc_library_shared has correct features when LTO differs across arch and os variants",
1283 Blueprint: `
1284cc_library_shared {
1285 name: "foo",
1286 target: {
1287 android: {
1288 lto: {
1289 thin: true,
1290 },
1291 },
1292 },
1293 arch: {
1294 riscv64: {
1295 lto: {
1296 thin: false,
1297 },
1298 },
1299 },
1300}`,
1301 ExpectedBazelTargets: []string{
1302 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1303 "local_includes": `["."]`,
1304 "features": `select({
1305 "//build/bazel/platforms/os_arch:android_arm": ["android_thin_lto"],
1306 "//build/bazel/platforms/os_arch:android_arm64": ["android_thin_lto"],
1307 "//build/bazel/platforms/os_arch:android_riscv64": ["-android_thin_lto"],
1308 "//build/bazel/platforms/os_arch:android_x86": ["android_thin_lto"],
1309 "//build/bazel/platforms/os_arch:android_x86_64": ["android_thin_lto"],
1310 "//conditions:default": [],
1311 })`}),
1312 },
1313 })
1314}
1315
1316func TestCcLibrarySharedWithThinLtoDisabledDefaultEnabledVariant(t *testing.T) {
1317 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1318 Description: "cc_library_shared with thin lto disabled by default but enabled on a particular variant",
1319 Blueprint: `
1320cc_library_shared {
1321 name: "foo",
1322 lto: {
1323 never: true,
1324 },
1325 target: {
1326 android: {
1327 lto: {
1328 thin: true,
1329 never: false,
1330 },
1331 },
1332 },
1333}`,
1334 ExpectedBazelTargets: []string{
1335 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1336 "local_includes": `["."]`,
1337 "features": `select({
1338 "//build/bazel/platforms/os:android": ["android_thin_lto"],
1339 "//conditions:default": ["-android_thin_lto"],
1340 })`,
1341 }),
1342 },
1343 })
1344}
1345
1346func TestCcLibrarySharedWithThinLtoAndWholeProgramVtables(t *testing.T) {
1347 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1348 Description: "cc_library_shared has correct features when thin LTO is enabled with whole_program_vtables",
1349 Blueprint: `
1350cc_library_shared {
1351 name: "foo",
1352 lto: {
1353 thin: true,
1354 },
1355 whole_program_vtables: true,
1356}
1357`,
1358 ExpectedBazelTargets: []string{
1359 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1360 "features": `[
1361 "android_thin_lto",
1362 "android_thin_lto_whole_program_vtables",
1363 ]`,
1364 "local_includes": `["."]`,
1365 }),
1366 },
1367 })
1368}
Trevor Radcliffea8b44162023-04-14 18:25:24 +00001369
1370func TestCcLibrarySharedHiddenVisibilityConvertedToFeature(t *testing.T) {
1371 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1372 Description: "cc_library_shared changes hidden visibility flag to feature",
1373 Blueprint: `
1374cc_library_shared{
1375 name: "foo",
1376 cflags: ["-fvisibility=hidden"],
1377}`,
1378 ExpectedBazelTargets: []string{
1379 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1380 "features": `["visibility_hidden"]`,
1381 "local_includes": `["."]`,
1382 }),
1383 },
1384 })
1385}
1386
1387func TestCcLibrarySharedHiddenVisibilityConvertedToFeatureOsSpecific(t *testing.T) {
1388 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1389 Description: "cc_library_shared changes hidden visibility flag to feature for specific os",
1390 Blueprint: `
1391cc_library_shared{
1392 name: "foo",
1393 target: {
1394 android: {
1395 cflags: ["-fvisibility=hidden"],
1396 },
1397 },
1398}`,
1399 ExpectedBazelTargets: []string{
1400 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1401 "features": `select({
1402 "//build/bazel/platforms/os:android": ["visibility_hidden"],
1403 "//conditions:default": [],
1404 })`,
1405 "local_includes": `["."]`,
1406 }),
1407 },
1408 })
1409}
Sam Delmerico75dbca22023-04-20 13:13:25 +00001410
1411func TestCcLibrarySharedStubsDessertVersionConversion(t *testing.T) {
1412 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1413 Description: "cc_library_shared converts dessert codename versions to numerical versions",
1414 Blueprint: `
1415cc_library_shared {
1416 name: "a",
1417 include_build_directory: false,
1418 stubs: {
1419 symbol_file: "a.map.txt",
1420 versions: [
1421 "Q",
1422 "R",
1423 "31",
1424 ],
1425 },
1426}
1427cc_library_shared {
1428 name: "b",
1429 include_build_directory: false,
1430 stubs: {
1431 symbol_file: "b.map.txt",
1432 versions: [
1433 "Q",
1434 "R",
1435 "31",
1436 "current",
1437 ],
1438 },
1439}
1440`,
1441 ExpectedBazelTargets: []string{
1442 makeCcStubSuiteTargets("a", AttrNameToString{
1443 "soname": `"a.so"`,
1444 "source_library_label": `"//:a"`,
1445 "stubs_symbol_file": `"a.map.txt"`,
1446 "stubs_versions": `[
1447 "29",
1448 "30",
1449 "31",
1450 "current",
1451 ]`,
1452 }),
1453 MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
1454 "stubs_symbol_file": `"a.map.txt"`,
1455 }),
1456 makeCcStubSuiteTargets("b", AttrNameToString{
1457 "soname": `"b.so"`,
1458 "source_library_label": `"//:b"`,
1459 "stubs_symbol_file": `"b.map.txt"`,
1460 "stubs_versions": `[
1461 "29",
1462 "30",
1463 "31",
1464 "current",
1465 ]`,
1466 }),
1467 MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
1468 "stubs_symbol_file": `"b.map.txt"`,
1469 }),
1470 },
1471 })
1472}
Trevor Radcliffe27669c02023-03-28 20:47:10 +00001473
1474func TestCcLibrarySharedWithCfi(t *testing.T) {
1475 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1476 Description: "cc_library_shared has correct features when cfi is enabled for specific variants",
1477 Blueprint: `
1478cc_library_shared {
1479 name: "foo",
1480 sanitize: {
1481 cfi: true,
1482 },
1483}`,
1484 ExpectedBazelTargets: []string{
1485 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1486 "features": `["android_cfi"]`,
1487 "local_includes": `["."]`,
1488 }),
1489 },
1490 })
1491}
1492
1493func TestCcLibrarySharedWithCfiOsSpecific(t *testing.T) {
1494 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1495 Description: "cc_library_shared has correct features when cfi is enabled",
1496 Blueprint: `
1497cc_library_shared {
1498 name: "foo",
1499 target: {
1500 android: {
1501 sanitize: {
1502 cfi: true,
1503 },
1504 },
1505 },
1506}`,
1507 ExpectedBazelTargets: []string{
1508 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1509 "features": `select({
1510 "//build/bazel/platforms/os:android": ["android_cfi"],
1511 "//conditions:default": [],
1512 })`,
1513 "local_includes": `["."]`,
1514 }),
1515 },
1516 })
1517}
1518
1519func TestCcLibrarySharedWithCfiAndCfiAssemblySupport(t *testing.T) {
1520 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1521 Description: "cc_library_shared has correct features when cfi is enabled with cfi assembly support",
1522 Blueprint: `
1523cc_library_static {
1524 name: "foo",
1525 sanitize: {
1526 cfi: true,
1527 config: {
1528 cfi_assembly_support: true,
1529 },
1530 },
1531}`,
1532 ExpectedBazelTargets: []string{
1533 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1534 "features": `[
1535 "android_cfi",
1536 "android_cfi_assembly_support",
1537 ]`,
1538 "local_includes": `["."]`,
1539 }),
1540 },
1541 })
1542}
Trevor Radcliffe523c5c62023-06-16 20:15:45 +00001543
1544func TestCcLibrarySharedExplicitlyDisablesCfiWhenFalse(t *testing.T) {
1545 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1546 Description: "cc_library_shared disables cfi when explciitly set to false in the bp",
1547 Blueprint: `
1548cc_library_shared {
1549 name: "foo",
1550 sanitize: {
1551 cfi: false,
1552 },
1553}
1554`,
1555 ExpectedBazelTargets: []string{
1556 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1557 "features": `["-android_cfi"]`,
1558 "local_includes": `["."]`,
1559 }),
1560 },
1561 })
1562}
Alixe2667872023-04-24 14:57:32 +00001563
1564func TestCCLibrarySharedRscriptSrc(t *testing.T) {
1565 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1566 Description: ``,
1567 Blueprint: `
1568cc_library_shared{
1569 name : "foo",
1570 srcs : [
1571 "ccSrc.cc",
1572 "rsSrc.rscript",
1573 ],
1574 include_build_directory: false,
1575}
1576`,
1577 ExpectedBazelTargets: []string{
1578 MakeBazelTarget("rscript_to_cpp", "foo_renderscript", AttrNameToString{
1579 "srcs": `["rsSrc.rscript"]`,
1580 }),
1581 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1582 "absolute_includes": `[
1583 "frameworks/rs",
1584 "frameworks/rs/cpp",
1585 ]`,
1586 "local_includes": `["."]`,
1587 "srcs": `[
1588 "ccSrc.cc",
1589 "foo_renderscript",
1590 ]`,
1591 })}})
1592}