blob: 4c86374b5fd66ade7ec350d4574346a7a674c557 [file] [log] [blame]
Jingwen Chen63930982021-03-24 10:04:33 -04001// 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 (
Jingwen Chen6ada5892021-09-17 11:38:09 +000018 "fmt"
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux1c92aef2021-08-23 16:10:00 +000019 "testing"
20
Jingwen Chen63930982021-03-24 10:04:33 -040021 "android/soong/android"
22 "android/soong/cc"
Jingwen Chen63930982021-03-24 10:04:33 -040023)
24
25const (
26 // See cc/testing.go for more context
27 soongCcLibraryPreamble = `
28cc_defaults {
Liz Kammer8337ea42021-09-10 10:06:32 -040029 name: "linux_bionic_supported",
Liz Kammerbaced712022-09-16 09:01:29 -040030}
31`
32
33 soongCcVersionLibBpPath = "build/soong/cc/libbuildversion/Android.bp"
34 soongCcVersionLibBp = `
35cc_library_static {
36 name: "libbuildversion",
37 bazel_module: { bp2build_available: false },
38}
39`
Liz Kammer12615db2021-09-28 09:19:17 -040040
41 soongCcProtoLibraries = `
42cc_library {
43 name: "libprotobuf-cpp-lite",
44 bazel_module: { bp2build_available: false },
45}
46
47cc_library {
48 name: "libprotobuf-cpp-full",
49 bazel_module: { bp2build_available: false },
50}`
51
52 soongCcProtoPreamble = soongCcLibraryPreamble + soongCcProtoLibraries
Jingwen Chen63930982021-03-24 10:04:33 -040053)
54
Sam Delmerico3177a6e2022-06-21 19:28:33 +000055func runCcLibraryTestCase(t *testing.T, tc Bp2buildTestCase) {
Liz Kammere4982e82021-05-25 10:39:35 -040056 t.Helper()
Sam Delmerico3177a6e2022-06-21 19:28:33 +000057 RunBp2BuildTestCase(t, registerCcLibraryModuleTypes, tc)
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +020058}
59
60func registerCcLibraryModuleTypes(ctx android.RegistrationContext) {
61 cc.RegisterCCBuildComponents(ctx)
Jingwen Chen14a8bda2021-06-02 11:10:02 +000062 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +020063 ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory)
Liz Kammer2d7bbe32021-06-10 18:20:06 -040064 ctx.RegisterModuleType("cc_prebuilt_library_static", cc.PrebuiltStaticLibraryFactory)
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +020065 ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
66}
67
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +020068func TestCcLibrarySimple(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000069 runCcLibraryTestCase(t, Bp2buildTestCase{
70 Description: "cc_library - simple example",
71 ModuleTypeUnderTest: "cc_library",
72 ModuleTypeUnderTestFactory: cc.LibraryFactory,
73 Filesystem: map[string]string{
Liz Kammerbaced712022-09-16 09:01:29 -040074 soongCcVersionLibBpPath: soongCcVersionLibBp,
75 "android.cpp": "",
76 "bionic.cpp": "",
77 "darwin.cpp": "",
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +020078 // Refer to cc.headerExts for the supported header extensions in Soong.
79 "header.h": "",
80 "header.hh": "",
81 "header.hpp": "",
82 "header.hxx": "",
83 "header.h++": "",
84 "header.inl": "",
85 "header.inc": "",
86 "header.ipp": "",
87 "header.h.generic": "",
88 "impl.cpp": "",
89 "linux.cpp": "",
90 "x86.cpp": "",
91 "x86_64.cpp": "",
92 "foo-dir/a.h": "",
93 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +000094 Blueprint: soongCcLibraryPreamble +
Liz Kammer78cfdaa2021-11-08 12:56:31 -050095 simpleModuleDoNotConvertBp2build("cc_library_headers", "some-headers") + `
Jingwen Chen63930982021-03-24 10:04:33 -040096cc_library {
97 name: "foo-lib",
98 srcs: ["impl.cpp"],
99 cflags: ["-Wall"],
100 header_libs: ["some-headers"],
101 export_include_dirs: ["foo-dir"],
102 ldflags: ["-Wl,--exclude-libs=bar.a"],
103 arch: {
104 x86: {
105 ldflags: ["-Wl,--exclude-libs=baz.a"],
106 srcs: ["x86.cpp"],
107 },
108 x86_64: {
109 ldflags: ["-Wl,--exclude-libs=qux.a"],
110 srcs: ["x86_64.cpp"],
111 },
112 },
113 target: {
114 android: {
115 srcs: ["android.cpp"],
116 },
117 linux_glibc: {
118 srcs: ["linux.cpp"],
119 },
120 darwin: {
121 srcs: ["darwin.cpp"],
122 },
Liz Kammer01a16e82021-07-16 16:33:47 -0400123 bionic: {
124 srcs: ["bionic.cpp"]
125 },
Jingwen Chen63930982021-03-24 10:04:33 -0400126 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400127 include_build_directory: false,
Yu Liufc603162022-03-01 15:44:08 -0800128 sdk_version: "current",
129 min_sdk_version: "29",
Yu Liua79c9462022-03-22 16:35:22 -0700130 use_version_lib: true,
Jingwen Chen63930982021-03-24 10:04:33 -0400131}
132`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000133 ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -0500134 "copts": `["-Wall"]`,
135 "export_includes": `["foo-dir"]`,
136 "implementation_deps": `[":some-headers"]`,
137 "linkopts": `["-Wl,--exclude-libs=bar.a"] + select({
Jingwen Chened9c17d2021-04-13 07:14:55 +0000138 "//build/bazel/platforms/arch:x86": ["-Wl,--exclude-libs=baz.a"],
139 "//build/bazel/platforms/arch:x86_64": ["-Wl,--exclude-libs=qux.a"],
140 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500141 })`,
Chris Parsons77acf2e2021-12-03 17:27:16 -0500142 "srcs": `["impl.cpp"] + select({
Jingwen Chenb4628eb2021-04-08 14:40:57 +0000143 "//build/bazel/platforms/arch:x86": ["x86.cpp"],
144 "//build/bazel/platforms/arch:x86_64": ["x86_64.cpp"],
Jingwen Chen63930982021-03-24 10:04:33 -0400145 "//conditions:default": [],
146 }) + select({
Chris Parsons2dde0cb2021-10-01 14:45:30 -0400147 "//build/bazel/platforms/os:android": [
Chris Parsons2dde0cb2021-10-01 14:45:30 -0400148 "bionic.cpp",
Liz Kammerfdd72e62021-10-11 15:41:03 -0400149 "android.cpp",
Chris Parsons2dde0cb2021-10-01 14:45:30 -0400150 ],
Jingwen Chenb4628eb2021-04-08 14:40:57 +0000151 "//build/bazel/platforms/os:darwin": ["darwin.cpp"],
152 "//build/bazel/platforms/os:linux": ["linux.cpp"],
Chris Parsons2dde0cb2021-10-01 14:45:30 -0400153 "//build/bazel/platforms/os:linux_bionic": ["bionic.cpp"],
Liz Kammer01a16e82021-07-16 16:33:47 -0400154 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500155 })`,
Liz Kammerbaced712022-09-16 09:01:29 -0400156 "sdk_version": `"current"`,
157 "min_sdk_version": `"29"`,
158 "use_version_lib": `True`,
159 "implementation_whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
Chris Parsons77acf2e2021-12-03 17:27:16 -0500160 }),
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500161 })
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200162}
163
164func TestCcLibraryTrimmedLdAndroid(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000165 runCcLibraryTestCase(t, Bp2buildTestCase{
166 Description: "cc_library - trimmed example of //bionic/linker:ld-android",
167 ModuleTypeUnderTest: "cc_library",
168 ModuleTypeUnderTestFactory: cc.LibraryFactory,
169 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200170 "ld-android.cpp": "",
171 "linked_list.h": "",
172 "linker.h": "",
173 "linker_block_allocator.h": "",
174 "linker_cfi.h": "",
Jingwen Chen63930982021-03-24 10:04:33 -0400175 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000176 Blueprint: soongCcLibraryPreamble +
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400177 simpleModuleDoNotConvertBp2build("cc_library_headers", "libc_headers") + `
Jingwen Chen63930982021-03-24 10:04:33 -0400178cc_library {
179 name: "fake-ld-android",
180 srcs: ["ld_android.cpp"],
181 cflags: [
182 "-Wall",
183 "-Wextra",
184 "-Wunused",
185 "-Werror",
186 ],
187 header_libs: ["libc_headers"],
188 ldflags: [
189 "-Wl,--exclude-libs=libgcc.a",
190 "-Wl,--exclude-libs=libgcc_stripped.a",
191 "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a",
192 "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a",
193 "-Wl,--exclude-libs=libclang_rt.builtins-i686-android.a",
194 "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a",
195 ],
196 arch: {
197 x86: {
198 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
199 },
200 x86_64: {
201 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
202 },
203 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400204 include_build_directory: false,
Jingwen Chen63930982021-03-24 10:04:33 -0400205}
206`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000207 ExpectedBazelTargets: makeCcLibraryTargets("fake-ld-android", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -0500208 "srcs": `["ld_android.cpp"]`,
209 "copts": `[
Jingwen Chen63930982021-03-24 10:04:33 -0400210 "-Wall",
211 "-Wextra",
212 "-Wunused",
213 "-Werror",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500214 ]`,
Chris Parsons77acf2e2021-12-03 17:27:16 -0500215 "implementation_deps": `[":libc_headers"]`,
216 "linkopts": `[
Jingwen Chen63930982021-03-24 10:04:33 -0400217 "-Wl,--exclude-libs=libgcc.a",
218 "-Wl,--exclude-libs=libgcc_stripped.a",
219 "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a",
220 "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a",
221 "-Wl,--exclude-libs=libclang_rt.builtins-i686-android.a",
222 "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a",
223 ] + select({
Jingwen Chenb4628eb2021-04-08 14:40:57 +0000224 "//build/bazel/platforms/arch:x86": ["-Wl,--exclude-libs=libgcc_eh.a"],
225 "//build/bazel/platforms/arch:x86_64": ["-Wl,--exclude-libs=libgcc_eh.a"],
Jingwen Chen63930982021-03-24 10:04:33 -0400226 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500227 })`,
Chris Parsons77acf2e2021-12-03 17:27:16 -0500228 }),
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200229 })
230}
231
232func TestCcLibraryExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000233 runCcLibraryTestCase(t, Bp2buildTestCase{
234 Description: "cc_library exclude_srcs - trimmed example of //external/arm-optimized-routines:libarm-optimized-routines-math",
235 ModuleTypeUnderTest: "cc_library",
236 ModuleTypeUnderTestFactory: cc.LibraryFactory,
237 Dir: "external",
238 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200239 "external/math/cosf.c": "",
240 "external/math/erf.c": "",
241 "external/math/erf_data.c": "",
242 "external/math/erff.c": "",
243 "external/math/erff_data.c": "",
244 "external/Android.bp": `
Jingwen Chen4ecc67d2021-04-27 09:47:02 +0000245cc_library {
246 name: "fake-libarm-optimized-routines-math",
247 exclude_srcs: [
248 // Provided by:
249 // bionic/libm/upstream-freebsd/lib/msun/src/s_erf.c
250 // bionic/libm/upstream-freebsd/lib/msun/src/s_erff.c
251 "math/erf.c",
252 "math/erf_data.c",
253 "math/erff.c",
254 "math/erff_data.c",
255 ],
256 srcs: [
257 "math/*.c",
258 ],
259 // arch-specific settings
260 arch: {
261 arm64: {
262 cflags: [
263 "-DHAVE_FAST_FMA=1",
264 ],
265 },
266 },
267 bazel_module: { bp2build_available: true },
268}
269`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200270 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000271 Blueprint: soongCcLibraryPreamble,
272 ExpectedBazelTargets: makeCcLibraryTargets("fake-libarm-optimized-routines-math", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -0500273 "copts": `select({
Jingwen Chen4ecc67d2021-04-27 09:47:02 +0000274 "//build/bazel/platforms/arch:arm64": ["-DHAVE_FAST_FMA=1"],
275 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500276 })`,
Chris Parsons77acf2e2021-12-03 17:27:16 -0500277 "local_includes": `["."]`,
278 "srcs_c": `["math/cosf.c"]`,
279 }),
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200280 })
281}
282
283func TestCcLibrarySharedStaticProps(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000284 runCcLibraryTestCase(t, Bp2buildTestCase{
285 Description: "cc_library shared/static props",
286 ModuleTypeUnderTest: "cc_library",
287 ModuleTypeUnderTestFactory: cc.LibraryFactory,
288 Filesystem: map[string]string{
Liz Kammer8337ea42021-09-10 10:06:32 -0400289 "both.cpp": "",
290 "sharedonly.cpp": "",
291 "staticonly.cpp": "",
292 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000293 Blueprint: soongCcLibraryPreamble + `
Jingwen Chen53681ef2021-04-29 08:15:13 +0000294cc_library {
295 name: "a",
Chris Parsons08648312021-05-06 16:23:19 -0400296 srcs: ["both.cpp"],
297 cflags: ["bothflag"],
298 shared_libs: ["shared_dep_for_both"],
Liz Kammercc2c1ef2022-03-21 09:03:29 -0400299 static_libs: ["static_dep_for_both", "whole_and_static_lib_for_both"],
300 whole_static_libs: ["whole_static_lib_for_both", "whole_and_static_lib_for_both"],
Chris Parsons08648312021-05-06 16:23:19 -0400301 static: {
302 srcs: ["staticonly.cpp"],
303 cflags: ["staticflag"],
304 shared_libs: ["shared_dep_for_static"],
305 static_libs: ["static_dep_for_static"],
306 whole_static_libs: ["whole_static_lib_for_static"],
307 },
308 shared: {
309 srcs: ["sharedonly.cpp"],
310 cflags: ["sharedflag"],
311 shared_libs: ["shared_dep_for_shared"],
312 static_libs: ["static_dep_for_shared"],
313 whole_static_libs: ["whole_static_lib_for_shared"],
314 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400315 include_build_directory: false,
Jingwen Chen53681ef2021-04-29 08:15:13 +0000316}
317
Liz Kammer8337ea42021-09-10 10:06:32 -0400318cc_library_static {
319 name: "static_dep_for_shared",
320 bazel_module: { bp2build_available: false },
321}
Chris Parsons08648312021-05-06 16:23:19 -0400322
Liz Kammer8337ea42021-09-10 10:06:32 -0400323cc_library_static {
324 name: "static_dep_for_static",
325 bazel_module: { bp2build_available: false },
326}
Chris Parsons08648312021-05-06 16:23:19 -0400327
Liz Kammer8337ea42021-09-10 10:06:32 -0400328cc_library_static {
329 name: "static_dep_for_both",
330 bazel_module: { bp2build_available: false },
331}
Chris Parsons08648312021-05-06 16:23:19 -0400332
Liz Kammer8337ea42021-09-10 10:06:32 -0400333cc_library_static {
334 name: "whole_static_lib_for_shared",
335 bazel_module: { bp2build_available: false },
336}
Chris Parsons08648312021-05-06 16:23:19 -0400337
Liz Kammer8337ea42021-09-10 10:06:32 -0400338cc_library_static {
339 name: "whole_static_lib_for_static",
340 bazel_module: { bp2build_available: false },
341}
Chris Parsons08648312021-05-06 16:23:19 -0400342
Liz Kammer8337ea42021-09-10 10:06:32 -0400343cc_library_static {
344 name: "whole_static_lib_for_both",
345 bazel_module: { bp2build_available: false },
346}
Chris Parsons08648312021-05-06 16:23:19 -0400347
Liz Kammercc2c1ef2022-03-21 09:03:29 -0400348cc_library_static {
349 name: "whole_and_static_lib_for_both",
350 bazel_module: { bp2build_available: false },
351}
352
Liz Kammer8337ea42021-09-10 10:06:32 -0400353cc_library {
354 name: "shared_dep_for_shared",
355 bazel_module: { bp2build_available: false },
356}
Chris Parsons08648312021-05-06 16:23:19 -0400357
Liz Kammer8337ea42021-09-10 10:06:32 -0400358cc_library {
359 name: "shared_dep_for_static",
360 bazel_module: { bp2build_available: false },
361}
Chris Parsons08648312021-05-06 16:23:19 -0400362
Liz Kammer8337ea42021-09-10 10:06:32 -0400363cc_library {
364 name: "shared_dep_for_both",
365 bazel_module: { bp2build_available: false },
366}
Jingwen Chen53681ef2021-04-29 08:15:13 +0000367`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000368 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000369 MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -0500370 "copts": `[
371 "bothflag",
372 "staticflag",
373 ]`,
374 "implementation_deps": `[
375 ":static_dep_for_both",
376 ":static_dep_for_static",
377 ]`,
378 "implementation_dynamic_deps": `[
379 ":shared_dep_for_both",
380 ":shared_dep_for_static",
381 ]`,
382 "srcs": `[
383 "both.cpp",
384 "staticonly.cpp",
385 ]`,
386 "whole_archive_deps": `[
387 ":whole_static_lib_for_both",
Liz Kammercc2c1ef2022-03-21 09:03:29 -0400388 ":whole_and_static_lib_for_both",
Chris Parsons77acf2e2021-12-03 17:27:16 -0500389 ":whole_static_lib_for_static",
390 ]`}),
Alixe06d75b2022-08-31 18:28:19 +0000391 MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -0500392 "copts": `[
393 "bothflag",
394 "sharedflag",
395 ]`,
396 "implementation_deps": `[
397 ":static_dep_for_both",
398 ":static_dep_for_shared",
399 ]`,
400 "implementation_dynamic_deps": `[
401 ":shared_dep_for_both",
402 ":shared_dep_for_shared",
403 ]`,
404 "srcs": `[
405 "both.cpp",
406 "sharedonly.cpp",
407 ]`,
408 "whole_archive_deps": `[
409 ":whole_static_lib_for_both",
Liz Kammercc2c1ef2022-03-21 09:03:29 -0400410 ":whole_and_static_lib_for_both",
Chris Parsons77acf2e2021-12-03 17:27:16 -0500411 ":whole_static_lib_for_shared",
412 ]`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500413 }),
414 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200415 })
416}
417
Liz Kammer7a210ac2021-09-22 15:52:58 -0400418func TestCcLibraryDeps(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000419 runCcLibraryTestCase(t, Bp2buildTestCase{
420 Description: "cc_library shared/static props",
421 ModuleTypeUnderTest: "cc_library",
422 ModuleTypeUnderTestFactory: cc.LibraryFactory,
423 Filesystem: map[string]string{
Liz Kammer7a210ac2021-09-22 15:52:58 -0400424 "both.cpp": "",
425 "sharedonly.cpp": "",
426 "staticonly.cpp": "",
427 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000428 Blueprint: soongCcLibraryPreamble + `
Liz Kammer7a210ac2021-09-22 15:52:58 -0400429cc_library {
430 name: "a",
431 srcs: ["both.cpp"],
432 cflags: ["bothflag"],
433 shared_libs: ["implementation_shared_dep_for_both", "shared_dep_for_both"],
434 export_shared_lib_headers: ["shared_dep_for_both"],
435 static_libs: ["implementation_static_dep_for_both", "static_dep_for_both"],
436 export_static_lib_headers: ["static_dep_for_both", "whole_static_dep_for_both"],
437 whole_static_libs: ["not_explicitly_exported_whole_static_dep_for_both", "whole_static_dep_for_both"],
438 static: {
439 srcs: ["staticonly.cpp"],
440 cflags: ["staticflag"],
441 shared_libs: ["implementation_shared_dep_for_static", "shared_dep_for_static"],
442 export_shared_lib_headers: ["shared_dep_for_static"],
443 static_libs: ["implementation_static_dep_for_static", "static_dep_for_static"],
444 export_static_lib_headers: ["static_dep_for_static", "whole_static_dep_for_static"],
445 whole_static_libs: ["not_explicitly_exported_whole_static_dep_for_static", "whole_static_dep_for_static"],
446 },
447 shared: {
448 srcs: ["sharedonly.cpp"],
449 cflags: ["sharedflag"],
450 shared_libs: ["implementation_shared_dep_for_shared", "shared_dep_for_shared"],
451 export_shared_lib_headers: ["shared_dep_for_shared"],
452 static_libs: ["implementation_static_dep_for_shared", "static_dep_for_shared"],
453 export_static_lib_headers: ["static_dep_for_shared", "whole_static_dep_for_shared"],
454 whole_static_libs: ["not_explicitly_exported_whole_static_dep_for_shared", "whole_static_dep_for_shared"],
455 },
456 include_build_directory: false,
457}
458` + simpleModuleDoNotConvertBp2build("cc_library_static", "static_dep_for_shared") +
459 simpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep_for_shared") +
460 simpleModuleDoNotConvertBp2build("cc_library_static", "static_dep_for_static") +
461 simpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep_for_static") +
462 simpleModuleDoNotConvertBp2build("cc_library_static", "static_dep_for_both") +
463 simpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep_for_both") +
464 simpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep_for_shared") +
465 simpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep_for_shared") +
466 simpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep_for_static") +
467 simpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep_for_static") +
468 simpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep_for_both") +
469 simpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep_for_both") +
470 simpleModuleDoNotConvertBp2build("cc_library", "shared_dep_for_shared") +
471 simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep_for_shared") +
472 simpleModuleDoNotConvertBp2build("cc_library", "shared_dep_for_static") +
473 simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep_for_static") +
474 simpleModuleDoNotConvertBp2build("cc_library", "shared_dep_for_both") +
475 simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep_for_both"),
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000476 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000477 MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -0500478 "copts": `[
479 "bothflag",
480 "staticflag",
481 ]`,
482 "deps": `[
483 ":static_dep_for_both",
484 ":static_dep_for_static",
485 ]`,
486 "dynamic_deps": `[
487 ":shared_dep_for_both",
488 ":shared_dep_for_static",
489 ]`,
490 "implementation_deps": `[
491 ":implementation_static_dep_for_both",
492 ":implementation_static_dep_for_static",
493 ]`,
494 "implementation_dynamic_deps": `[
495 ":implementation_shared_dep_for_both",
496 ":implementation_shared_dep_for_static",
497 ]`,
498 "srcs": `[
499 "both.cpp",
500 "staticonly.cpp",
501 ]`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500502 "whole_archive_deps": `[
Liz Kammer7a210ac2021-09-22 15:52:58 -0400503 ":not_explicitly_exported_whole_static_dep_for_both",
504 ":whole_static_dep_for_both",
Chris Parsons77acf2e2021-12-03 17:27:16 -0500505 ":not_explicitly_exported_whole_static_dep_for_static",
506 ":whole_static_dep_for_static",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500507 ]`,
508 }),
Alixe06d75b2022-08-31 18:28:19 +0000509 MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -0500510 "copts": `[
511 "bothflag",
512 "sharedflag",
513 ]`,
514 "deps": `[
515 ":static_dep_for_both",
516 ":static_dep_for_shared",
517 ]`,
518 "dynamic_deps": `[
519 ":shared_dep_for_both",
520 ":shared_dep_for_shared",
521 ]`,
522 "implementation_deps": `[
523 ":implementation_static_dep_for_both",
524 ":implementation_static_dep_for_shared",
525 ]`,
526 "implementation_dynamic_deps": `[
527 ":implementation_shared_dep_for_both",
528 ":implementation_shared_dep_for_shared",
529 ]`,
530 "srcs": `[
531 "both.cpp",
532 "sharedonly.cpp",
533 ]`,
534 "whole_archive_deps": `[
535 ":not_explicitly_exported_whole_static_dep_for_both",
536 ":whole_static_dep_for_both",
537 ":not_explicitly_exported_whole_static_dep_for_shared",
538 ":whole_static_dep_for_shared",
539 ]`,
540 })},
541 },
542 )
Liz Kammer7a210ac2021-09-22 15:52:58 -0400543}
544
Liz Kammer2d7bbe32021-06-10 18:20:06 -0400545func TestCcLibraryWholeStaticLibsAlwaysLink(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000546 runCcLibraryTestCase(t, Bp2buildTestCase{
547 ModuleTypeUnderTest: "cc_library",
548 ModuleTypeUnderTestFactory: cc.LibraryFactory,
549 Dir: "foo/bar",
550 Filesystem: map[string]string{
Liz Kammer2d7bbe32021-06-10 18:20:06 -0400551 "foo/bar/Android.bp": `
552cc_library {
553 name: "a",
554 whole_static_libs: ["whole_static_lib_for_both"],
555 static: {
556 whole_static_libs: ["whole_static_lib_for_static"],
557 },
558 shared: {
559 whole_static_libs: ["whole_static_lib_for_shared"],
560 },
561 bazel_module: { bp2build_available: true },
Liz Kammer8337ea42021-09-10 10:06:32 -0400562 include_build_directory: false,
Liz Kammer2d7bbe32021-06-10 18:20:06 -0400563}
564
565cc_prebuilt_library_static { name: "whole_static_lib_for_shared" }
566
567cc_prebuilt_library_static { name: "whole_static_lib_for_static" }
568
569cc_prebuilt_library_static { name: "whole_static_lib_for_both" }
570`,
571 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000572 Blueprint: soongCcLibraryPreamble,
573 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000574 MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -0500575 "whole_archive_deps": `[
576 ":whole_static_lib_for_both_alwayslink",
577 ":whole_static_lib_for_static_alwayslink",
578 ]`,
579 }),
Alixe06d75b2022-08-31 18:28:19 +0000580 MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -0500581 "whole_archive_deps": `[
582 ":whole_static_lib_for_both_alwayslink",
583 ":whole_static_lib_for_shared_alwayslink",
584 ]`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500585 }),
586 },
Chris Parsons77acf2e2021-12-03 17:27:16 -0500587 },
588 )
Liz Kammer2d7bbe32021-06-10 18:20:06 -0400589}
590
Jingwen Chenbcf53042021-05-26 04:42:42 +0000591func TestCcLibrarySharedStaticPropsInArch(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000592 runCcLibraryTestCase(t, Bp2buildTestCase{
593 Description: "cc_library shared/static props in arch",
594 ModuleTypeUnderTest: "cc_library",
595 ModuleTypeUnderTestFactory: cc.LibraryFactory,
596 Dir: "foo/bar",
597 Filesystem: map[string]string{
Jingwen Chenbcf53042021-05-26 04:42:42 +0000598 "foo/bar/arm.cpp": "",
599 "foo/bar/x86.cpp": "",
600 "foo/bar/sharedonly.cpp": "",
601 "foo/bar/staticonly.cpp": "",
602 "foo/bar/Android.bp": `
603cc_library {
604 name: "a",
605 arch: {
606 arm: {
607 shared: {
608 srcs: ["arm_shared.cpp"],
609 cflags: ["-DARM_SHARED"],
610 static_libs: ["arm_static_dep_for_shared"],
611 whole_static_libs: ["arm_whole_static_dep_for_shared"],
612 shared_libs: ["arm_shared_dep_for_shared"],
613 },
614 },
615 x86: {
616 static: {
617 srcs: ["x86_static.cpp"],
618 cflags: ["-DX86_STATIC"],
619 static_libs: ["x86_dep_for_static"],
620 },
621 },
622 },
623 target: {
624 android: {
625 shared: {
626 srcs: ["android_shared.cpp"],
627 cflags: ["-DANDROID_SHARED"],
628 static_libs: ["android_dep_for_shared"],
629 },
630 },
631 android_arm: {
632 shared: {
633 cflags: ["-DANDROID_ARM_SHARED"],
634 },
635 },
636 },
637 srcs: ["both.cpp"],
638 cflags: ["bothflag"],
639 static_libs: ["static_dep_for_both"],
640 static: {
641 srcs: ["staticonly.cpp"],
642 cflags: ["staticflag"],
643 static_libs: ["static_dep_for_static"],
644 },
645 shared: {
646 srcs: ["sharedonly.cpp"],
647 cflags: ["sharedflag"],
648 static_libs: ["static_dep_for_shared"],
649 },
650 bazel_module: { bp2build_available: true },
651}
652
653cc_library_static { name: "static_dep_for_shared" }
654cc_library_static { name: "static_dep_for_static" }
655cc_library_static { name: "static_dep_for_both" }
656
657cc_library_static { name: "arm_static_dep_for_shared" }
658cc_library_static { name: "arm_whole_static_dep_for_shared" }
659cc_library_static { name: "arm_shared_dep_for_shared" }
660
661cc_library_static { name: "x86_dep_for_static" }
662
663cc_library_static { name: "android_dep_for_shared" }
664`,
665 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000666 Blueprint: soongCcLibraryPreamble,
667 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000668 MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -0500669 "copts": `[
670 "bothflag",
671 "staticflag",
672 ] + select({
673 "//build/bazel/platforms/arch:x86": ["-DX86_STATIC"],
674 "//conditions:default": [],
675 })`,
676 "implementation_deps": `[
677 ":static_dep_for_both",
678 ":static_dep_for_static",
679 ] + select({
680 "//build/bazel/platforms/arch:x86": [":x86_dep_for_static"],
681 "//conditions:default": [],
682 })`,
683 "local_includes": `["."]`,
684 "srcs": `[
685 "both.cpp",
686 "staticonly.cpp",
687 ] + select({
688 "//build/bazel/platforms/arch:x86": ["x86_static.cpp"],
689 "//conditions:default": [],
690 })`,
691 }),
Alixe06d75b2022-08-31 18:28:19 +0000692 MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -0500693 "copts": `[
694 "bothflag",
695 "sharedflag",
696 ] + select({
697 "//build/bazel/platforms/arch:arm": ["-DARM_SHARED"],
698 "//conditions:default": [],
699 }) + select({
700 "//build/bazel/platforms/os:android": ["-DANDROID_SHARED"],
701 "//conditions:default": [],
702 }) + select({
703 "//build/bazel/platforms/os_arch:android_arm": ["-DANDROID_ARM_SHARED"],
704 "//conditions:default": [],
705 })`,
706 "implementation_deps": `[
707 ":static_dep_for_both",
708 ":static_dep_for_shared",
709 ] + select({
710 "//build/bazel/platforms/arch:arm": [":arm_static_dep_for_shared"],
711 "//conditions:default": [],
712 }) + select({
713 "//build/bazel/platforms/os:android": [":android_dep_for_shared"],
714 "//conditions:default": [],
715 })`,
716 "implementation_dynamic_deps": `select({
717 "//build/bazel/platforms/arch:arm": [":arm_shared_dep_for_shared"],
718 "//conditions:default": [],
719 })`,
720 "local_includes": `["."]`,
721 "srcs": `[
722 "both.cpp",
723 "sharedonly.cpp",
724 ] + select({
725 "//build/bazel/platforms/arch:arm": ["arm_shared.cpp"],
726 "//conditions:default": [],
727 }) + select({
728 "//build/bazel/platforms/os:android": ["android_shared.cpp"],
729 "//conditions:default": [],
730 })`,
731 "whole_archive_deps": `select({
732 "//build/bazel/platforms/arch:arm": [":arm_whole_static_dep_for_shared"],
733 "//conditions:default": [],
734 })`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500735 }),
736 },
Chris Parsons77acf2e2021-12-03 17:27:16 -0500737 },
738 )
Jingwen Chenbcf53042021-05-26 04:42:42 +0000739}
740
Jingwen Chen14a8bda2021-06-02 11:10:02 +0000741func TestCcLibrarySharedStaticPropsWithMixedSources(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000742 runCcLibraryTestCase(t, Bp2buildTestCase{
743 Description: "cc_library shared/static props with c/cpp/s mixed sources",
744 ModuleTypeUnderTest: "cc_library",
745 ModuleTypeUnderTestFactory: cc.LibraryFactory,
746 Dir: "foo/bar",
747 Filesystem: map[string]string{
Jingwen Chen14a8bda2021-06-02 11:10:02 +0000748 "foo/bar/both_source.cpp": "",
749 "foo/bar/both_source.cc": "",
750 "foo/bar/both_source.c": "",
751 "foo/bar/both_source.s": "",
752 "foo/bar/both_source.S": "",
753 "foo/bar/shared_source.cpp": "",
754 "foo/bar/shared_source.cc": "",
755 "foo/bar/shared_source.c": "",
756 "foo/bar/shared_source.s": "",
757 "foo/bar/shared_source.S": "",
758 "foo/bar/static_source.cpp": "",
759 "foo/bar/static_source.cc": "",
760 "foo/bar/static_source.c": "",
761 "foo/bar/static_source.s": "",
762 "foo/bar/static_source.S": "",
763 "foo/bar/Android.bp": `
764cc_library {
765 name: "a",
766 srcs: [
Liz Kammerd366c902021-06-03 13:43:01 -0400767 "both_source.cpp",
768 "both_source.cc",
769 "both_source.c",
770 "both_source.s",
771 "both_source.S",
Liz Kammer57e2e7a2021-09-20 12:55:02 -0400772 ":both_filegroup",
Liz Kammerd366c902021-06-03 13:43:01 -0400773 ],
Jingwen Chen14a8bda2021-06-02 11:10:02 +0000774 static: {
Liz Kammer8337ea42021-09-10 10:06:32 -0400775 srcs: [
776 "static_source.cpp",
777 "static_source.cc",
778 "static_source.c",
779 "static_source.s",
780 "static_source.S",
781 ":static_filegroup",
782 ],
Jingwen Chen14a8bda2021-06-02 11:10:02 +0000783 },
784 shared: {
Liz Kammer8337ea42021-09-10 10:06:32 -0400785 srcs: [
786 "shared_source.cpp",
787 "shared_source.cc",
788 "shared_source.c",
789 "shared_source.s",
790 "shared_source.S",
791 ":shared_filegroup",
792 ],
Jingwen Chen14a8bda2021-06-02 11:10:02 +0000793 },
794 bazel_module: { bp2build_available: true },
795}
796
797filegroup {
798 name: "both_filegroup",
799 srcs: [
800 // Not relevant, handled by filegroup macro
Liz Kammerd366c902021-06-03 13:43:01 -0400801 ],
Jingwen Chen14a8bda2021-06-02 11:10:02 +0000802}
803
804filegroup {
805 name: "shared_filegroup",
806 srcs: [
807 // Not relevant, handled by filegroup macro
Liz Kammerd366c902021-06-03 13:43:01 -0400808 ],
Jingwen Chen14a8bda2021-06-02 11:10:02 +0000809}
810
811filegroup {
812 name: "static_filegroup",
813 srcs: [
814 // Not relevant, handled by filegroup macro
Liz Kammerd366c902021-06-03 13:43:01 -0400815 ],
Jingwen Chen14a8bda2021-06-02 11:10:02 +0000816}
817`,
818 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000819 Blueprint: soongCcLibraryPreamble,
820 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000821 MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500822 "local_includes": `["."]`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500823 "srcs": `[
Jingwen Chen14a8bda2021-06-02 11:10:02 +0000824 "both_source.cpp",
Liz Kammer57e2e7a2021-09-20 12:55:02 -0400825 "both_source.cc",
826 ":both_filegroup_cpp_srcs",
Chris Parsons77acf2e2021-12-03 17:27:16 -0500827 "static_source.cpp",
828 "static_source.cc",
829 ":static_filegroup_cpp_srcs",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500830 ]`,
831 "srcs_as": `[
Jingwen Chen14a8bda2021-06-02 11:10:02 +0000832 "both_source.s",
833 "both_source.S",
834 ":both_filegroup_as_srcs",
Chris Parsons77acf2e2021-12-03 17:27:16 -0500835 "static_source.s",
836 "static_source.S",
837 ":static_filegroup_as_srcs",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500838 ]`,
839 "srcs_c": `[
Jingwen Chen14a8bda2021-06-02 11:10:02 +0000840 "both_source.c",
841 ":both_filegroup_c_srcs",
Chris Parsons77acf2e2021-12-03 17:27:16 -0500842 "static_source.c",
843 ":static_filegroup_c_srcs",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500844 ]`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500845 }),
Alixe06d75b2022-08-31 18:28:19 +0000846 MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -0500847 "local_includes": `["."]`,
848 "srcs": `[
849 "both_source.cpp",
850 "both_source.cc",
851 ":both_filegroup_cpp_srcs",
852 "shared_source.cpp",
853 "shared_source.cc",
854 ":shared_filegroup_cpp_srcs",
855 ]`,
856 "srcs_as": `[
857 "both_source.s",
858 "both_source.S",
859 ":both_filegroup_as_srcs",
860 "shared_source.s",
861 "shared_source.S",
862 ":shared_filegroup_as_srcs",
863 ]`,
864 "srcs_c": `[
865 "both_source.c",
866 ":both_filegroup_c_srcs",
867 "shared_source.c",
868 ":shared_filegroup_c_srcs",
869 ]`,
870 })}})
Jingwen Chen14a8bda2021-06-02 11:10:02 +0000871}
872
Trevor Radcliffe82dd8552022-10-03 20:27:27 +0000873func TestCcLibraryNonConfiguredVersionScriptAndDynamicList(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000874 runCcLibraryTestCase(t, Bp2buildTestCase{
Trevor Radcliffe82dd8552022-10-03 20:27:27 +0000875 Description: "cc_library non-configured version script and dynamic list",
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000876 ModuleTypeUnderTest: "cc_library",
877 ModuleTypeUnderTestFactory: cc.LibraryFactory,
878 Dir: "foo/bar",
879 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200880 "foo/bar/Android.bp": `
Lukacs T. Berki1353e592021-04-30 15:35:09 +0200881cc_library {
882 name: "a",
883 srcs: ["a.cpp"],
884 version_script: "v.map",
Trevor Radcliffe82dd8552022-10-03 20:27:27 +0000885 dynamic_list: "dynamic.list",
Lukacs T. Berki1353e592021-04-30 15:35:09 +0200886 bazel_module: { bp2build_available: true },
Liz Kammer8337ea42021-09-10 10:06:32 -0400887 include_build_directory: false,
Lukacs T. Berki1353e592021-04-30 15:35:09 +0200888}
889`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200890 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000891 Blueprint: soongCcLibraryPreamble,
892 ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{
Trevor Radcliffe82dd8552022-10-03 20:27:27 +0000893 "additional_linker_inputs": `[
894 "v.map",
895 "dynamic.list",
896 ]`,
897 "linkopts": `[
898 "-Wl,--version-script,$(location v.map)",
899 "-Wl,--dynamic-list,$(location dynamic.list)",
900 ]`,
901 "srcs": `["a.cpp"]`,
Chris Parsons77acf2e2021-12-03 17:27:16 -0500902 }),
903 },
904 )
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200905}
906
Trevor Radcliffe82dd8552022-10-03 20:27:27 +0000907func TestCcLibraryConfiguredVersionScriptAndDynamicList(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000908 runCcLibraryTestCase(t, Bp2buildTestCase{
Trevor Radcliffe82dd8552022-10-03 20:27:27 +0000909 Description: "cc_library configured version script and dynamic list",
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000910 ModuleTypeUnderTest: "cc_library",
911 ModuleTypeUnderTestFactory: cc.LibraryFactory,
912 Dir: "foo/bar",
913 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200914 "foo/bar/Android.bp": `
Liz Kammer8337ea42021-09-10 10:06:32 -0400915cc_library {
916 name: "a",
917 srcs: ["a.cpp"],
918 arch: {
919 arm: {
920 version_script: "arm.map",
Trevor Radcliffe82dd8552022-10-03 20:27:27 +0000921 dynamic_list: "dynamic_arm.list",
Liz Kammer8337ea42021-09-10 10:06:32 -0400922 },
923 arm64: {
924 version_script: "arm64.map",
Trevor Radcliffe82dd8552022-10-03 20:27:27 +0000925 dynamic_list: "dynamic_arm64.list",
Liz Kammer8337ea42021-09-10 10:06:32 -0400926 },
927 },
Lukacs T. Berki56bb0832021-05-12 12:36:45 +0200928
Liz Kammer8337ea42021-09-10 10:06:32 -0400929 bazel_module: { bp2build_available: true },
930 include_build_directory: false,
931}
Liz Kammerd366c902021-06-03 13:43:01 -0400932 `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200933 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000934 Blueprint: soongCcLibraryPreamble,
935 ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -0500936 "additional_linker_inputs": `select({
Trevor Radcliffe82dd8552022-10-03 20:27:27 +0000937 "//build/bazel/platforms/arch:arm": [
938 "arm.map",
939 "dynamic_arm.list",
940 ],
941 "//build/bazel/platforms/arch:arm64": [
942 "arm64.map",
943 "dynamic_arm64.list",
944 ],
Liz Kammerd2871182021-10-04 13:54:37 -0400945 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500946 })`,
Chris Parsons77acf2e2021-12-03 17:27:16 -0500947 "linkopts": `select({
Trevor Radcliffe82dd8552022-10-03 20:27:27 +0000948 "//build/bazel/platforms/arch:arm": [
949 "-Wl,--version-script,$(location arm.map)",
950 "-Wl,--dynamic-list,$(location dynamic_arm.list)",
951 ],
952 "//build/bazel/platforms/arch:arm64": [
953 "-Wl,--version-script,$(location arm64.map)",
954 "-Wl,--dynamic-list,$(location dynamic_arm64.list)",
955 ],
Liz Kammerd2871182021-10-04 13:54:37 -0400956 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500957 })`,
Chris Parsons77acf2e2021-12-03 17:27:16 -0500958 "srcs": `["a.cpp"]`,
959 }),
960 },
961 )
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200962}
963
Trevor Radcliffeea6a45d2022-09-20 18:58:01 +0000964func TestCcLibraryLdflagsSplitBySpaceExceptSoongAdded(t *testing.T) {
965 runCcLibraryTestCase(t, Bp2buildTestCase{
966 Description: "ldflags are split by spaces except for the ones added by soong (version script and dynamic list)",
967 ModuleTypeUnderTest: "cc_library",
968 ModuleTypeUnderTestFactory: cc.LibraryFactory,
969 Filesystem: map[string]string{
970 "version_script": "",
971 "dynamic.list": "",
972 },
973 Blueprint: `
974cc_library {
975 name: "foo",
976 ldflags: [
977 "--nospace_flag",
978 "-z spaceflag",
979 ],
980 version_script: "version_script",
981 dynamic_list: "dynamic.list",
982 include_build_directory: false,
983}
984`,
985 ExpectedBazelTargets: []string{
986 MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}),
987 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
988 "additional_linker_inputs": `[
989 "version_script",
990 "dynamic.list",
991 ]`,
992 "linkopts": `[
993 "--nospace_flag",
994 "-z",
995 "spaceflag",
996 "-Wl,--version-script,$(location version_script)",
997 "-Wl,--dynamic-list,$(location dynamic.list)",
998 ]`,
999 }),
1000 },
1001 })
1002}
1003
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001004func TestCcLibrarySharedLibs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001005 runCcLibraryTestCase(t, Bp2buildTestCase{
1006 Description: "cc_library shared_libs",
1007 ModuleTypeUnderTest: "cc_library",
1008 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1009 Blueprint: soongCcLibraryPreamble + `
Rupert Shuttleworthc50fa8d2021-05-06 02:40:33 -04001010cc_library {
1011 name: "mylib",
Liz Kammer8337ea42021-09-10 10:06:32 -04001012 bazel_module: { bp2build_available: false },
Rupert Shuttleworthc50fa8d2021-05-06 02:40:33 -04001013}
1014
1015cc_library {
1016 name: "a",
1017 shared_libs: ["mylib",],
Liz Kammer8337ea42021-09-10 10:06:32 -04001018 include_build_directory: false,
Rupert Shuttleworthc50fa8d2021-05-06 02:40:33 -04001019}
1020`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001021 ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001022 "implementation_dynamic_deps": `[":mylib"]`,
1023 }),
1024 },
1025 )
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001026}
1027
Liz Kammer0eae52e2021-10-06 10:32:26 -04001028func TestCcLibraryFeatures(t *testing.T) {
Chris Parsons77acf2e2021-12-03 17:27:16 -05001029 expected_targets := []string{}
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001030 expected_targets = append(expected_targets, makeCcLibraryTargets("a", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001031 "features": `[
1032 "disable_pack_relocations",
1033 "-no_undefined_symbols",
Yu Liu8d82ac52022-05-17 15:13:28 -07001034 "-coverage",
Chris Parsons77acf2e2021-12-03 17:27:16 -05001035 ]`,
1036 "srcs": `["a.cpp"]`,
1037 })...)
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001038 expected_targets = append(expected_targets, makeCcLibraryTargets("b", AttrNameToString{
Yu Liu8d82ac52022-05-17 15:13:28 -07001039 "features": `["-coverage"] + select({
Chris Parsons77acf2e2021-12-03 17:27:16 -05001040 "//build/bazel/platforms/arch:x86_64": [
1041 "disable_pack_relocations",
1042 "-no_undefined_symbols",
1043 ],
1044 "//conditions:default": [],
1045 })`,
1046 "srcs": `["b.cpp"]`,
1047 })...)
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001048 expected_targets = append(expected_targets, makeCcLibraryTargets("c", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001049 "features": `select({
1050 "//build/bazel/platforms/os:darwin": [
1051 "disable_pack_relocations",
1052 "-no_undefined_symbols",
1053 ],
1054 "//conditions:default": [],
1055 })`,
1056 "srcs": `["c.cpp"]`,
1057 })...)
1058
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001059 runCcLibraryTestCase(t, Bp2buildTestCase{
1060 Description: "cc_library pack_relocations test",
1061 ModuleTypeUnderTest: "cc_library",
1062 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1063 Blueprint: soongCcLibraryPreamble + `
Rupert Shuttleworth143be942021-05-09 23:55:51 -04001064cc_library {
1065 name: "a",
1066 srcs: ["a.cpp"],
1067 pack_relocations: false,
Liz Kammer0eae52e2021-10-06 10:32:26 -04001068 allow_undefined_symbols: true,
Liz Kammer8337ea42021-09-10 10:06:32 -04001069 include_build_directory: false,
Yu Liu8d82ac52022-05-17 15:13:28 -07001070 native_coverage: false,
Rupert Shuttleworth143be942021-05-09 23:55:51 -04001071}
1072
1073cc_library {
1074 name: "b",
1075 srcs: ["b.cpp"],
1076 arch: {
1077 x86_64: {
Liz Kammer8337ea42021-09-10 10:06:32 -04001078 pack_relocations: false,
Liz Kammer0eae52e2021-10-06 10:32:26 -04001079 allow_undefined_symbols: true,
Liz Kammer8337ea42021-09-10 10:06:32 -04001080 },
Rupert Shuttleworth143be942021-05-09 23:55:51 -04001081 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001082 include_build_directory: false,
Yu Liu8d82ac52022-05-17 15:13:28 -07001083 native_coverage: false,
Rupert Shuttleworth143be942021-05-09 23:55:51 -04001084}
1085
1086cc_library {
1087 name: "c",
1088 srcs: ["c.cpp"],
1089 target: {
1090 darwin: {
Liz Kammer8337ea42021-09-10 10:06:32 -04001091 pack_relocations: false,
Liz Kammer0eae52e2021-10-06 10:32:26 -04001092 allow_undefined_symbols: true,
Liz Kammer8337ea42021-09-10 10:06:32 -04001093 },
Rupert Shuttleworth143be942021-05-09 23:55:51 -04001094 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001095 include_build_directory: false,
Rupert Shuttleworth143be942021-05-09 23:55:51 -04001096}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001097 ExpectedBazelTargets: expected_targets,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001098 })
1099}
1100
1101func TestCcLibrarySpacesInCopts(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001102 runCcLibraryTestCase(t, Bp2buildTestCase{
1103 Description: "cc_library spaces in copts",
1104 ModuleTypeUnderTest: "cc_library",
1105 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1106 Blueprint: soongCcLibraryPreamble + `
Jingwen Chen3950cd62021-05-12 04:33:00 +00001107cc_library {
1108 name: "a",
1109 cflags: ["-include header.h",],
Liz Kammer8337ea42021-09-10 10:06:32 -04001110 include_build_directory: false,
Jingwen Chen3950cd62021-05-12 04:33:00 +00001111}
1112`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001113 ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001114 "copts": `[
Jingwen Chen3950cd62021-05-12 04:33:00 +00001115 "-include",
1116 "header.h",
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001117 ]`,
Chris Parsons77acf2e2021-12-03 17:27:16 -05001118 }),
1119 },
1120 )
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001121}
1122
1123func TestCcLibraryCppFlagsGoesIntoCopts(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001124 runCcLibraryTestCase(t, Bp2buildTestCase{
1125 Description: "cc_library cppflags usage",
1126 ModuleTypeUnderTest: "cc_library",
1127 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1128 Blueprint: soongCcLibraryPreamble + `cc_library {
Jingwen Chen75be1ca2021-05-12 05:04:58 +00001129 name: "a",
1130 srcs: ["a.cpp"],
Liz Kammer8337ea42021-09-10 10:06:32 -04001131 cflags: ["-Wall"],
Jingwen Chen75be1ca2021-05-12 05:04:58 +00001132 cppflags: [
1133 "-fsigned-char",
1134 "-pedantic",
Liz Kammer8337ea42021-09-10 10:06:32 -04001135 ],
Jingwen Chen75be1ca2021-05-12 05:04:58 +00001136 arch: {
1137 arm64: {
1138 cppflags: ["-DARM64=1"],
Liz Kammer8337ea42021-09-10 10:06:32 -04001139 },
Liz Kammerd366c902021-06-03 13:43:01 -04001140 },
Jingwen Chen75be1ca2021-05-12 05:04:58 +00001141 target: {
1142 android: {
1143 cppflags: ["-DANDROID=1"],
Liz Kammer8337ea42021-09-10 10:06:32 -04001144 },
Liz Kammerd366c902021-06-03 13:43:01 -04001145 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001146 include_build_directory: false,
Jingwen Chen75be1ca2021-05-12 05:04:58 +00001147}
1148`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001149 ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001150 "copts": `["-Wall"]`,
1151 "cppflags": `[
Chris Parsons990c4f42021-05-25 12:10:58 -04001152 "-fsigned-char",
1153 "-pedantic",
Jingwen Chen75be1ca2021-05-12 05:04:58 +00001154 ] + select({
1155 "//build/bazel/platforms/arch:arm64": ["-DARM64=1"],
1156 "//conditions:default": [],
1157 }) + select({
1158 "//build/bazel/platforms/os:android": ["-DANDROID=1"],
1159 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001160 })`,
Chris Parsons77acf2e2021-12-03 17:27:16 -05001161 "srcs": `["a.cpp"]`,
1162 }),
1163 },
1164 )
Jingwen Chen63930982021-03-24 10:04:33 -04001165}
Rupert Shuttleworth22cd2eb2021-05-27 02:15:54 -04001166
Liz Kammer47535c52021-06-02 16:02:22 -04001167func TestCcLibraryExcludeLibs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001168 runCcLibraryTestCase(t, Bp2buildTestCase{
1169 ModuleTypeUnderTest: "cc_library",
1170 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1171 Filesystem: map[string]string{},
1172 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer47535c52021-06-02 16:02:22 -04001173cc_library {
1174 name: "foo_static",
1175 srcs: ["common.c"],
1176 whole_static_libs: [
1177 "arm_whole_static_lib_excludes",
1178 "malloc_not_svelte_whole_static_lib_excludes"
1179 ],
1180 static_libs: [
1181 "arm_static_lib_excludes",
1182 "malloc_not_svelte_static_lib_excludes"
1183 ],
1184 shared_libs: [
1185 "arm_shared_lib_excludes",
1186 ],
1187 arch: {
1188 arm: {
1189 exclude_shared_libs: [
1190 "arm_shared_lib_excludes",
1191 ],
1192 exclude_static_libs: [
1193 "arm_static_lib_excludes",
1194 "arm_whole_static_lib_excludes",
1195 ],
1196 },
1197 },
1198 product_variables: {
1199 malloc_not_svelte: {
1200 shared_libs: ["malloc_not_svelte_shared_lib"],
1201 whole_static_libs: ["malloc_not_svelte_whole_static_lib"],
1202 exclude_static_libs: [
1203 "malloc_not_svelte_static_lib_excludes",
1204 "malloc_not_svelte_whole_static_lib_excludes",
1205 ],
1206 },
1207 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001208 include_build_directory: false,
Liz Kammer47535c52021-06-02 16:02:22 -04001209}
1210
1211cc_library {
1212 name: "arm_whole_static_lib_excludes",
1213 bazel_module: { bp2build_available: false },
1214}
1215
1216cc_library {
1217 name: "malloc_not_svelte_whole_static_lib",
1218 bazel_module: { bp2build_available: false },
1219}
1220
1221cc_library {
1222 name: "malloc_not_svelte_whole_static_lib_excludes",
1223 bazel_module: { bp2build_available: false },
1224}
1225
1226cc_library {
1227 name: "arm_static_lib_excludes",
1228 bazel_module: { bp2build_available: false },
1229}
1230
1231cc_library {
1232 name: "malloc_not_svelte_static_lib_excludes",
1233 bazel_module: { bp2build_available: false },
1234}
1235
1236cc_library {
1237 name: "arm_shared_lib_excludes",
1238 bazel_module: { bp2build_available: false },
1239}
1240
1241cc_library {
1242 name: "malloc_not_svelte_shared_lib",
1243 bazel_module: { bp2build_available: false },
1244}
1245`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001246 ExpectedBazelTargets: makeCcLibraryTargets("foo_static", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001247 "implementation_deps": `select({
Liz Kammer47535c52021-06-02 16:02:22 -04001248 "//build/bazel/platforms/arch:arm": [],
Chris Parsons953b3562021-09-20 15:14:39 -04001249 "//conditions:default": [":arm_static_lib_excludes_bp2build_cc_library_static"],
Liz Kammer47535c52021-06-02 16:02:22 -04001250 }) + select({
1251 "//build/bazel/product_variables:malloc_not_svelte": [],
Chris Parsons953b3562021-09-20 15:14:39 -04001252 "//conditions:default": [":malloc_not_svelte_static_lib_excludes_bp2build_cc_library_static"],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001253 })`,
Chris Parsons77acf2e2021-12-03 17:27:16 -05001254 "implementation_dynamic_deps": `select({
Liz Kammer7a210ac2021-09-22 15:52:58 -04001255 "//build/bazel/platforms/arch:arm": [],
1256 "//conditions:default": [":arm_shared_lib_excludes"],
1257 }) + select({
1258 "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_shared_lib"],
1259 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001260 })`,
Chris Parsons77acf2e2021-12-03 17:27:16 -05001261 "srcs_c": `["common.c"]`,
1262 "whole_archive_deps": `select({
Liz Kammer47535c52021-06-02 16:02:22 -04001263 "//build/bazel/platforms/arch:arm": [],
Chris Parsons953b3562021-09-20 15:14:39 -04001264 "//conditions:default": [":arm_whole_static_lib_excludes_bp2build_cc_library_static"],
Liz Kammer47535c52021-06-02 16:02:22 -04001265 }) + select({
Chris Parsons953b3562021-09-20 15:14:39 -04001266 "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_whole_static_lib_bp2build_cc_library_static"],
1267 "//conditions:default": [":malloc_not_svelte_whole_static_lib_excludes_bp2build_cc_library_static"],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001268 })`,
Chris Parsons77acf2e2021-12-03 17:27:16 -05001269 }),
1270 },
1271 )
Liz Kammer47535c52021-06-02 16:02:22 -04001272}
Liz Kammerd366c902021-06-03 13:43:01 -04001273
Zi Wang0a8a1292022-08-30 06:27:01 +00001274func TestCcLibraryProductVariablesHeaderLibs(t *testing.T) {
1275 runCcLibraryTestCase(t, Bp2buildTestCase{
1276 ModuleTypeUnderTest: "cc_library",
1277 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1278 Filesystem: map[string]string{},
1279 Blueprint: soongCcLibraryStaticPreamble + `
1280cc_library {
1281 name: "foo_static",
1282 srcs: ["common.c"],
1283 product_variables: {
1284 malloc_not_svelte: {
1285 header_libs: ["malloc_not_svelte_header_lib"],
1286 },
1287 },
1288 include_build_directory: false,
1289}
1290
1291cc_library {
1292 name: "malloc_not_svelte_header_lib",
1293 bazel_module: { bp2build_available: false },
1294}
1295`,
1296 ExpectedBazelTargets: makeCcLibraryTargets("foo_static", AttrNameToString{
1297 "implementation_deps": `select({
1298 "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_header_lib"],
1299 "//conditions:default": [],
1300 })`,
1301 "srcs_c": `["common.c"]`,
1302 "target_compatible_with": `["//build/bazel/platforms/os:android"]`,
1303 }),
1304 },
1305 )
1306}
1307
Liz Kammerd366c902021-06-03 13:43:01 -04001308func TestCCLibraryNoCrtTrue(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001309 runCcLibraryTestCase(t, Bp2buildTestCase{
1310 Description: "cc_library - nocrt: true emits attribute",
1311 ModuleTypeUnderTest: "cc_library",
1312 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1313 Filesystem: map[string]string{
Jingwen Chen6ada5892021-09-17 11:38:09 +00001314 "impl.cpp": "",
1315 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001316 Blueprint: soongCcLibraryPreamble + `
Jingwen Chen6ada5892021-09-17 11:38:09 +00001317cc_library {
1318 name: "foo-lib",
1319 srcs: ["impl.cpp"],
1320 nocrt: true,
1321 include_build_directory: false,
1322}
1323`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001324 ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001325 "link_crt": `False`,
1326 "srcs": `["impl.cpp"]`,
1327 }),
1328 },
1329 )
Jingwen Chen6ada5892021-09-17 11:38:09 +00001330}
1331
1332func TestCCLibraryNoCrtFalse(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001333 runCcLibraryTestCase(t, Bp2buildTestCase{
1334 Description: "cc_library - nocrt: false - does not emit attribute",
1335 ModuleTypeUnderTest: "cc_library",
1336 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1337 Filesystem: map[string]string{
Jingwen Chen6ada5892021-09-17 11:38:09 +00001338 "impl.cpp": "",
1339 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001340 Blueprint: soongCcLibraryPreamble + `
Jingwen Chen6ada5892021-09-17 11:38:09 +00001341cc_library {
1342 name: "foo-lib",
1343 srcs: ["impl.cpp"],
1344 nocrt: false,
1345 include_build_directory: false,
1346}
1347`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001348 ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001349 "srcs": `["impl.cpp"]`,
1350 }),
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001351 })
Jingwen Chen6ada5892021-09-17 11:38:09 +00001352}
1353
1354func TestCCLibraryNoCrtArchVariant(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001355 runCcLibraryTestCase(t, Bp2buildTestCase{
1356 Description: "cc_library - nocrt in select",
1357 ModuleTypeUnderTest: "cc_library",
1358 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1359 Filesystem: map[string]string{
Jingwen Chen6ada5892021-09-17 11:38:09 +00001360 "impl.cpp": "",
1361 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001362 Blueprint: soongCcLibraryPreamble + `
Jingwen Chen6ada5892021-09-17 11:38:09 +00001363cc_library {
1364 name: "foo-lib",
1365 srcs: ["impl.cpp"],
1366 arch: {
1367 arm: {
1368 nocrt: true,
1369 },
1370 x86: {
1371 nocrt: false,
1372 },
1373 },
1374 include_build_directory: false,
1375}
1376`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001377 ExpectedErr: fmt.Errorf("module \"foo-lib\": nocrt is not supported for arch variants"),
Jingwen Chen6ada5892021-09-17 11:38:09 +00001378 })
1379}
1380
1381func TestCCLibraryNoLibCrtTrue(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001382 runCcLibraryTestCase(t, Bp2buildTestCase{
1383 ModuleTypeUnderTest: "cc_library",
1384 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1385 Filesystem: map[string]string{
Liz Kammerd366c902021-06-03 13:43:01 -04001386 "impl.cpp": "",
1387 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001388 Blueprint: soongCcLibraryPreamble + `
Liz Kammerd366c902021-06-03 13:43:01 -04001389cc_library {
1390 name: "foo-lib",
1391 srcs: ["impl.cpp"],
1392 no_libcrt: true,
Liz Kammer8337ea42021-09-10 10:06:32 -04001393 include_build_directory: false,
Liz Kammerd366c902021-06-03 13:43:01 -04001394}
1395`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001396 ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001397 "srcs": `["impl.cpp"]`,
1398 "use_libcrt": `False`,
1399 }),
1400 })
1401}
1402
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001403func makeCcLibraryTargets(name string, attrs AttrNameToString) []string {
Chris Parsons77acf2e2021-12-03 17:27:16 -05001404 STATIC_ONLY_ATTRS := map[string]bool{}
1405 SHARED_ONLY_ATTRS := map[string]bool{
1406 "link_crt": true,
1407 "additional_linker_inputs": true,
1408 "linkopts": true,
1409 "strip": true,
Yu Liu75be7b92022-02-01 09:54:09 -08001410 "inject_bssl_hash": true,
Wei Li81852ca2022-07-27 00:22:06 -07001411 "has_stubs": true,
Liz Kammerbaced712022-09-16 09:01:29 -04001412 "use_version_lib": true,
Chris Parsons77acf2e2021-12-03 17:27:16 -05001413 }
Wei Li81852ca2022-07-27 00:22:06 -07001414
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001415 sharedAttrs := AttrNameToString{}
1416 staticAttrs := AttrNameToString{}
Chris Parsons77acf2e2021-12-03 17:27:16 -05001417 for key, val := range attrs {
1418 if _, staticOnly := STATIC_ONLY_ATTRS[key]; !staticOnly {
1419 sharedAttrs[key] = val
1420 }
1421 if _, sharedOnly := SHARED_ONLY_ATTRS[key]; !sharedOnly {
1422 staticAttrs[key] = val
1423 }
1424 }
Alixe06d75b2022-08-31 18:28:19 +00001425 sharedTarget := MakeBazelTarget("cc_library_shared", name, sharedAttrs)
1426 staticTarget := MakeBazelTarget("cc_library_static", name+"_bp2build_cc_library_static", staticAttrs)
Chris Parsons77acf2e2021-12-03 17:27:16 -05001427
1428 return []string{staticTarget, sharedTarget}
Liz Kammerd366c902021-06-03 13:43:01 -04001429}
1430
Jingwen Chen6ada5892021-09-17 11:38:09 +00001431func TestCCLibraryNoLibCrtFalse(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001432 runCcLibraryTestCase(t, Bp2buildTestCase{
1433 ModuleTypeUnderTest: "cc_library",
1434 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1435 Filesystem: map[string]string{
Liz Kammerd366c902021-06-03 13:43:01 -04001436 "impl.cpp": "",
1437 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001438 Blueprint: soongCcLibraryPreamble + `
Liz Kammerd366c902021-06-03 13:43:01 -04001439cc_library {
1440 name: "foo-lib",
1441 srcs: ["impl.cpp"],
1442 no_libcrt: false,
Liz Kammer8337ea42021-09-10 10:06:32 -04001443 include_build_directory: false,
Liz Kammerd366c902021-06-03 13:43:01 -04001444}
1445`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001446 ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001447 "srcs": `["impl.cpp"]`,
1448 "use_libcrt": `True`,
1449 }),
1450 })
Liz Kammerd366c902021-06-03 13:43:01 -04001451}
1452
Jingwen Chen6ada5892021-09-17 11:38:09 +00001453func TestCCLibraryNoLibCrtArchVariant(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001454 runCcLibraryTestCase(t, Bp2buildTestCase{
1455 ModuleTypeUnderTest: "cc_library",
1456 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1457 Filesystem: map[string]string{
Liz Kammerd366c902021-06-03 13:43:01 -04001458 "impl.cpp": "",
1459 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001460 Blueprint: soongCcLibraryPreamble + `
Liz Kammerd366c902021-06-03 13:43:01 -04001461cc_library {
1462 name: "foo-lib",
1463 srcs: ["impl.cpp"],
1464 arch: {
1465 arm: {
1466 no_libcrt: true,
1467 },
1468 x86: {
1469 no_libcrt: true,
1470 },
1471 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001472 include_build_directory: false,
Liz Kammerd366c902021-06-03 13:43:01 -04001473}
1474`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001475 ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001476 "srcs": `["impl.cpp"]`,
1477 "use_libcrt": `select({
Liz Kammerd366c902021-06-03 13:43:01 -04001478 "//build/bazel/platforms/arch:arm": False,
1479 "//build/bazel/platforms/arch:x86": False,
1480 "//conditions:default": None,
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001481 })`,
Chris Parsons77acf2e2021-12-03 17:27:16 -05001482 }),
1483 })
Liz Kammerd366c902021-06-03 13:43:01 -04001484}
1485
Chris Parsons58852a02021-12-09 18:10:18 -05001486func TestCCLibraryNoLibCrtArchAndTargetVariant(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001487 runCcLibraryTestCase(t, Bp2buildTestCase{
1488 ModuleTypeUnderTest: "cc_library",
1489 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1490 Filesystem: map[string]string{
Chris Parsons58852a02021-12-09 18:10:18 -05001491 "impl.cpp": "",
1492 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001493 Blueprint: soongCcLibraryPreamble + `
Chris Parsons58852a02021-12-09 18:10:18 -05001494cc_library {
1495 name: "foo-lib",
1496 srcs: ["impl.cpp"],
1497 arch: {
1498 arm: {
1499 no_libcrt: true,
1500 },
1501 x86: {
1502 no_libcrt: true,
1503 },
1504 },
1505 target: {
1506 darwin: {
1507 no_libcrt: true,
1508 }
1509 },
1510 include_build_directory: false,
1511}
1512`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001513 ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{
Chris Parsons58852a02021-12-09 18:10:18 -05001514 "srcs": `["impl.cpp"]`,
1515 "use_libcrt": `select({
1516 "//build/bazel/platforms/os_arch:android_arm": False,
1517 "//build/bazel/platforms/os_arch:android_x86": False,
1518 "//build/bazel/platforms/os_arch:darwin_arm64": False,
1519 "//build/bazel/platforms/os_arch:darwin_x86_64": False,
1520 "//build/bazel/platforms/os_arch:linux_glibc_x86": False,
1521 "//build/bazel/platforms/os_arch:linux_musl_x86": False,
1522 "//build/bazel/platforms/os_arch:windows_x86": False,
1523 "//conditions:default": None,
1524 })`,
1525 }),
1526 })
1527}
1528
1529func TestCCLibraryNoLibCrtArchAndTargetVariantConflict(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001530 runCcLibraryTestCase(t, Bp2buildTestCase{
1531 ModuleTypeUnderTest: "cc_library",
1532 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1533 Filesystem: map[string]string{
Chris Parsons58852a02021-12-09 18:10:18 -05001534 "impl.cpp": "",
1535 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001536 Blueprint: soongCcLibraryPreamble + `
Chris Parsons58852a02021-12-09 18:10:18 -05001537cc_library {
1538 name: "foo-lib",
1539 srcs: ["impl.cpp"],
1540 arch: {
1541 arm: {
1542 no_libcrt: true,
1543 },
1544 // This is expected to override the value for darwin_x86_64.
1545 x86_64: {
1546 no_libcrt: true,
1547 },
1548 },
1549 target: {
1550 darwin: {
1551 no_libcrt: false,
1552 }
1553 },
1554 include_build_directory: false,
1555}
1556`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001557 ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{
Chris Parsons58852a02021-12-09 18:10:18 -05001558 "srcs": `["impl.cpp"]`,
1559 "use_libcrt": `select({
1560 "//build/bazel/platforms/os_arch:android_arm": False,
1561 "//build/bazel/platforms/os_arch:android_x86_64": False,
1562 "//build/bazel/platforms/os_arch:darwin_arm64": True,
1563 "//build/bazel/platforms/os_arch:darwin_x86_64": False,
1564 "//build/bazel/platforms/os_arch:linux_bionic_x86_64": False,
1565 "//build/bazel/platforms/os_arch:linux_glibc_x86_64": False,
1566 "//build/bazel/platforms/os_arch:linux_musl_x86_64": False,
1567 "//build/bazel/platforms/os_arch:windows_x86_64": False,
1568 "//conditions:default": None,
1569 })`,
1570 }),
1571 })
1572}
1573
Jingwen Chen3d383bb2021-06-09 07:18:37 +00001574func TestCcLibraryStrip(t *testing.T) {
Chris Parsons77acf2e2021-12-03 17:27:16 -05001575 expectedTargets := []string{}
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001576 expectedTargets = append(expectedTargets, makeCcLibraryTargets("all", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001577 "strip": `{
1578 "all": True,
1579 }`,
1580 })...)
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001581 expectedTargets = append(expectedTargets, makeCcLibraryTargets("keep_symbols", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001582 "strip": `{
1583 "keep_symbols": True,
1584 }`,
1585 })...)
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001586 expectedTargets = append(expectedTargets, makeCcLibraryTargets("keep_symbols_and_debug_frame", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001587 "strip": `{
1588 "keep_symbols_and_debug_frame": True,
1589 }`,
1590 })...)
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001591 expectedTargets = append(expectedTargets, makeCcLibraryTargets("keep_symbols_list", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001592 "strip": `{
1593 "keep_symbols_list": ["symbol"],
1594 }`,
1595 })...)
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001596 expectedTargets = append(expectedTargets, makeCcLibraryTargets("none", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001597 "strip": `{
1598 "none": True,
1599 }`,
1600 })...)
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001601 expectedTargets = append(expectedTargets, makeCcLibraryTargets("nothing", AttrNameToString{})...)
Chris Parsons77acf2e2021-12-03 17:27:16 -05001602
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001603 runCcLibraryTestCase(t, Bp2buildTestCase{
1604 Description: "cc_library strip args",
1605 ModuleTypeUnderTest: "cc_library",
1606 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1607 Blueprint: soongCcLibraryPreamble + `
Jingwen Chen3d383bb2021-06-09 07:18:37 +00001608cc_library {
1609 name: "nothing",
Liz Kammer8337ea42021-09-10 10:06:32 -04001610 include_build_directory: false,
Jingwen Chen3d383bb2021-06-09 07:18:37 +00001611}
1612cc_library {
1613 name: "keep_symbols",
Jingwen Chen3d383bb2021-06-09 07:18:37 +00001614 strip: {
Liz Kammer8337ea42021-09-10 10:06:32 -04001615 keep_symbols: true,
1616 },
1617 include_build_directory: false,
Jingwen Chen3d383bb2021-06-09 07:18:37 +00001618}
1619cc_library {
1620 name: "keep_symbols_and_debug_frame",
Jingwen Chen3d383bb2021-06-09 07:18:37 +00001621 strip: {
Liz Kammer8337ea42021-09-10 10:06:32 -04001622 keep_symbols_and_debug_frame: true,
1623 },
1624 include_build_directory: false,
Jingwen Chen3d383bb2021-06-09 07:18:37 +00001625}
1626cc_library {
1627 name: "none",
Jingwen Chen3d383bb2021-06-09 07:18:37 +00001628 strip: {
Liz Kammer8337ea42021-09-10 10:06:32 -04001629 none: true,
1630 },
1631 include_build_directory: false,
Jingwen Chen3d383bb2021-06-09 07:18:37 +00001632}
1633cc_library {
1634 name: "keep_symbols_list",
Jingwen Chen3d383bb2021-06-09 07:18:37 +00001635 strip: {
Liz Kammer8337ea42021-09-10 10:06:32 -04001636 keep_symbols_list: ["symbol"],
1637 },
1638 include_build_directory: false,
Jingwen Chen3d383bb2021-06-09 07:18:37 +00001639}
1640cc_library {
1641 name: "all",
Jingwen Chen3d383bb2021-06-09 07:18:37 +00001642 strip: {
Liz Kammer8337ea42021-09-10 10:06:32 -04001643 all: true,
1644 },
1645 include_build_directory: false,
Jingwen Chen3d383bb2021-06-09 07:18:37 +00001646}
1647`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001648 ExpectedBazelTargets: expectedTargets,
Jingwen Chen3d383bb2021-06-09 07:18:37 +00001649 })
1650}
1651
1652func TestCcLibraryStripWithArch(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001653 runCcLibraryTestCase(t, Bp2buildTestCase{
1654 Description: "cc_library strip args",
1655 ModuleTypeUnderTest: "cc_library",
1656 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1657 Blueprint: soongCcLibraryPreamble + `
Jingwen Chen3d383bb2021-06-09 07:18:37 +00001658cc_library {
1659 name: "multi-arch",
Jingwen Chen3d383bb2021-06-09 07:18:37 +00001660 target: {
1661 darwin: {
1662 strip: {
1663 keep_symbols_list: ["foo", "bar"]
1664 }
1665 },
1666 },
1667 arch: {
1668 arm: {
1669 strip: {
1670 keep_symbols_and_debug_frame: true,
1671 },
1672 },
1673 arm64: {
1674 strip: {
1675 keep_symbols: true,
1676 },
1677 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001678 },
1679 include_build_directory: false,
Jingwen Chen3d383bb2021-06-09 07:18:37 +00001680}
1681`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001682 ExpectedBazelTargets: makeCcLibraryTargets("multi-arch", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001683 "strip": `{
Jingwen Chen3d383bb2021-06-09 07:18:37 +00001684 "keep_symbols": select({
1685 "//build/bazel/platforms/arch:arm64": True,
1686 "//conditions:default": None,
1687 }),
1688 "keep_symbols_and_debug_frame": select({
1689 "//build/bazel/platforms/arch:arm": True,
1690 "//conditions:default": None,
1691 }),
1692 "keep_symbols_list": select({
1693 "//build/bazel/platforms/os:darwin": [
1694 "foo",
1695 "bar",
1696 ],
1697 "//conditions:default": [],
1698 }),
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001699 }`,
Chris Parsons77acf2e2021-12-03 17:27:16 -05001700 }),
1701 },
1702 )
Jingwen Chen3d383bb2021-06-09 07:18:37 +00001703}
Chris Parsons51f8c392021-08-03 21:01:05 -04001704
1705func TestCcLibrary_SystemSharedLibsRootEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001706 runCcLibraryTestCase(t, Bp2buildTestCase{
1707 Description: "cc_library system_shared_libs empty at root",
1708 ModuleTypeUnderTest: "cc_library",
1709 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1710 Blueprint: soongCcLibraryPreamble + `
Chris Parsons51f8c392021-08-03 21:01:05 -04001711cc_library {
1712 name: "root_empty",
Liz Kammer8337ea42021-09-10 10:06:32 -04001713 system_shared_libs: [],
1714 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001715}
1716`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001717 ExpectedBazelTargets: makeCcLibraryTargets("root_empty", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001718 "system_dynamic_deps": `[]`,
1719 }),
1720 },
1721 )
Chris Parsons51f8c392021-08-03 21:01:05 -04001722}
1723
1724func TestCcLibrary_SystemSharedLibsStaticEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001725 runCcLibraryTestCase(t, Bp2buildTestCase{
1726 Description: "cc_library system_shared_libs empty for static variant",
1727 ModuleTypeUnderTest: "cc_library",
1728 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1729 Blueprint: soongCcLibraryPreamble + `
Chris Parsons51f8c392021-08-03 21:01:05 -04001730cc_library {
1731 name: "static_empty",
1732 static: {
Liz Kammer8337ea42021-09-10 10:06:32 -04001733 system_shared_libs: [],
1734 },
1735 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001736}
1737`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001738 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001739 MakeBazelTarget("cc_library_static", "static_empty_bp2build_cc_library_static", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001740 "system_dynamic_deps": "[]",
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001741 }),
Alixe06d75b2022-08-31 18:28:19 +00001742 MakeBazelTarget("cc_library_shared", "static_empty", AttrNameToString{}),
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001743 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001744 })
1745}
1746
1747func TestCcLibrary_SystemSharedLibsSharedEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001748 runCcLibraryTestCase(t, Bp2buildTestCase{
1749 Description: "cc_library system_shared_libs empty for shared variant",
1750 ModuleTypeUnderTest: "cc_library",
1751 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1752 Blueprint: soongCcLibraryPreamble + `
Chris Parsons51f8c392021-08-03 21:01:05 -04001753cc_library {
1754 name: "shared_empty",
1755 shared: {
Liz Kammer8337ea42021-09-10 10:06:32 -04001756 system_shared_libs: [],
1757 },
1758 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001759}
1760`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001761 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001762 MakeBazelTarget("cc_library_static", "shared_empty_bp2build_cc_library_static", AttrNameToString{}),
1763 MakeBazelTarget("cc_library_shared", "shared_empty", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001764 "system_dynamic_deps": "[]",
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001765 }),
1766 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001767 })
1768}
1769
1770func TestCcLibrary_SystemSharedLibsSharedBionicEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001771 runCcLibraryTestCase(t, Bp2buildTestCase{
1772 Description: "cc_library system_shared_libs empty for shared, bionic variant",
1773 ModuleTypeUnderTest: "cc_library",
1774 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1775 Blueprint: soongCcLibraryPreamble + `
Chris Parsons51f8c392021-08-03 21:01:05 -04001776cc_library {
1777 name: "shared_empty",
1778 target: {
1779 bionic: {
1780 shared: {
1781 system_shared_libs: [],
1782 }
1783 }
Liz Kammer8337ea42021-09-10 10:06:32 -04001784 },
1785 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001786}
1787`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001788 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001789 MakeBazelTarget("cc_library_static", "shared_empty_bp2build_cc_library_static", AttrNameToString{}),
1790 MakeBazelTarget("cc_library_shared", "shared_empty", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001791 "system_dynamic_deps": "[]",
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001792 }),
1793 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001794 })
1795}
1796
1797func TestCcLibrary_SystemSharedLibsLinuxBionicEmpty(t *testing.T) {
1798 // Note that this behavior is technically incorrect (it's a simplification).
1799 // The correct behavior would be if bp2build wrote `system_dynamic_deps = []`
1800 // only for linux_bionic, but `android` had `["libc", "libdl", "libm"].
1801 // b/195791252 tracks the fix.
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001802 runCcLibraryTestCase(t, Bp2buildTestCase{
1803 Description: "cc_library system_shared_libs empty for linux_bionic variant",
1804 ModuleTypeUnderTest: "cc_library",
1805 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1806 Blueprint: soongCcLibraryPreamble + `
Chris Parsons51f8c392021-08-03 21:01:05 -04001807cc_library {
1808 name: "target_linux_bionic_empty",
1809 target: {
1810 linux_bionic: {
1811 system_shared_libs: [],
1812 },
1813 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001814 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001815}
1816`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001817 ExpectedBazelTargets: makeCcLibraryTargets("target_linux_bionic_empty", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001818 "system_dynamic_deps": `[]`,
1819 }),
1820 },
1821 )
Chris Parsons51f8c392021-08-03 21:01:05 -04001822}
1823
1824func TestCcLibrary_SystemSharedLibsBionicEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001825 runCcLibraryTestCase(t, Bp2buildTestCase{
1826 Description: "cc_library system_shared_libs empty for bionic variant",
1827 ModuleTypeUnderTest: "cc_library",
1828 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1829 Blueprint: soongCcLibraryPreamble + `
Chris Parsons51f8c392021-08-03 21:01:05 -04001830cc_library {
1831 name: "target_bionic_empty",
1832 target: {
1833 bionic: {
1834 system_shared_libs: [],
1835 },
1836 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001837 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001838}
1839`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001840 ExpectedBazelTargets: makeCcLibraryTargets("target_bionic_empty", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001841 "system_dynamic_deps": `[]`,
1842 }),
1843 },
1844 )
Chris Parsons51f8c392021-08-03 21:01:05 -04001845}
1846
1847func TestCcLibrary_SystemSharedLibsSharedAndRoot(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001848 runCcLibraryTestCase(t, Bp2buildTestCase{
1849 Description: "cc_library system_shared_libs set for shared and root",
1850 ModuleTypeUnderTest: "cc_library",
1851 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1852 Blueprint: soongCcLibraryPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -04001853cc_library {
1854 name: "libc",
1855 bazel_module: { bp2build_available: false },
1856}
1857cc_library {
1858 name: "libm",
1859 bazel_module: { bp2build_available: false },
1860}
Chris Parsons51f8c392021-08-03 21:01:05 -04001861
1862cc_library {
1863 name: "foo",
1864 system_shared_libs: ["libc"],
1865 shared: {
Liz Kammer8337ea42021-09-10 10:06:32 -04001866 system_shared_libs: ["libm"],
Chris Parsons51f8c392021-08-03 21:01:05 -04001867 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001868 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001869}
1870`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001871 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001872 MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001873 "system_dynamic_deps": `[":libc"]`,
1874 }),
Alixe06d75b2022-08-31 18:28:19 +00001875 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001876 "system_dynamic_deps": `[
1877 ":libc",
1878 ":libm",
1879 ]`,
1880 }),
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001881 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001882 })
1883}
Chris Parsons2dde0cb2021-10-01 14:45:30 -04001884
1885func TestCcLibraryOsSelects(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001886 runCcLibraryTestCase(t, Bp2buildTestCase{
1887 Description: "cc_library - selects for all os targets",
1888 ModuleTypeUnderTest: "cc_library",
1889 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1890 Filesystem: map[string]string{},
1891 Blueprint: soongCcLibraryPreamble + `
Chris Parsons2dde0cb2021-10-01 14:45:30 -04001892cc_library {
1893 name: "foo-lib",
1894 srcs: ["base.cpp"],
1895 target: {
1896 android: {
1897 srcs: ["android.cpp"],
1898 },
1899 linux: {
1900 srcs: ["linux.cpp"],
1901 },
1902 linux_glibc: {
1903 srcs: ["linux_glibc.cpp"],
1904 },
1905 darwin: {
1906 srcs: ["darwin.cpp"],
1907 },
1908 bionic: {
1909 srcs: ["bionic.cpp"],
1910 },
1911 linux_musl: {
1912 srcs: ["linux_musl.cpp"],
1913 },
1914 windows: {
1915 srcs: ["windows.cpp"],
1916 },
1917 },
1918 include_build_directory: false,
1919}
1920`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001921 ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05001922 "srcs": `["base.cpp"] + select({
Chris Parsons2dde0cb2021-10-01 14:45:30 -04001923 "//build/bazel/platforms/os:android": [
Chris Parsons2dde0cb2021-10-01 14:45:30 -04001924 "linux.cpp",
Liz Kammer9bad9d62021-10-11 15:40:35 -04001925 "bionic.cpp",
Liz Kammerfdd72e62021-10-11 15:41:03 -04001926 "android.cpp",
Chris Parsons2dde0cb2021-10-01 14:45:30 -04001927 ],
1928 "//build/bazel/platforms/os:darwin": ["darwin.cpp"],
1929 "//build/bazel/platforms/os:linux": [
Liz Kammer9bad9d62021-10-11 15:40:35 -04001930 "linux.cpp",
Liz Kammerfdd72e62021-10-11 15:41:03 -04001931 "linux_glibc.cpp",
Chris Parsons2dde0cb2021-10-01 14:45:30 -04001932 ],
1933 "//build/bazel/platforms/os:linux_bionic": [
Chris Parsons2dde0cb2021-10-01 14:45:30 -04001934 "linux.cpp",
Liz Kammer9bad9d62021-10-11 15:40:35 -04001935 "bionic.cpp",
Chris Parsons2dde0cb2021-10-01 14:45:30 -04001936 ],
1937 "//build/bazel/platforms/os:linux_musl": [
Liz Kammer9bad9d62021-10-11 15:40:35 -04001938 "linux.cpp",
Liz Kammerfdd72e62021-10-11 15:41:03 -04001939 "linux_musl.cpp",
Chris Parsons2dde0cb2021-10-01 14:45:30 -04001940 ],
1941 "//build/bazel/platforms/os:windows": ["windows.cpp"],
1942 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001943 })`,
Chris Parsons77acf2e2021-12-03 17:27:16 -05001944 }),
1945 },
1946 )
Jingwen Chen97b85312021-10-08 10:41:31 +00001947}
1948
Yu Liu75be7b92022-02-01 09:54:09 -08001949func TestLibcryptoHashInjection(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001950 runCcLibraryTestCase(t, Bp2buildTestCase{
1951 Description: "cc_library - libcrypto hash injection",
1952 ModuleTypeUnderTest: "cc_library",
1953 ModuleTypeUnderTestFactory: cc.LibraryFactory,
1954 Filesystem: map[string]string{},
1955 Blueprint: soongCcLibraryPreamble + `
Yu Liu75be7b92022-02-01 09:54:09 -08001956cc_library {
1957 name: "libcrypto",
1958 target: {
1959 android: {
1960 inject_bssl_hash: true,
1961 },
1962 },
1963 include_build_directory: false,
1964}
1965`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001966 ExpectedBazelTargets: makeCcLibraryTargets("libcrypto", AttrNameToString{
Yu Liu75be7b92022-02-01 09:54:09 -08001967 "inject_bssl_hash": `select({
1968 "//build/bazel/platforms/os:android": True,
1969 "//conditions:default": None,
1970 })`,
1971 }),
1972 },
1973 )
1974}
1975
Jingwen Chen5b11ab12021-10-11 17:44:33 +00001976func TestCcLibraryCppStdWithGnuExtensions_ConvertsToFeatureAttr(t *testing.T) {
Jingwen Chen97b85312021-10-08 10:41:31 +00001977 type testCase struct {
1978 cpp_std string
Chris Parsons79bd2b72021-11-29 17:52:41 -05001979 c_std string
Jingwen Chen97b85312021-10-08 10:41:31 +00001980 gnu_extensions string
1981 bazel_cpp_std string
Chris Parsons79bd2b72021-11-29 17:52:41 -05001982 bazel_c_std string
Jingwen Chen97b85312021-10-08 10:41:31 +00001983 }
1984
1985 testCases := []testCase{
1986 // Existing usages of cpp_std in AOSP are:
1987 // experimental, c++11, c++17, c++2a, c++98, gnu++11, gnu++17
1988 //
1989 // not set, only emit if gnu_extensions is disabled. the default (gnu+17
1990 // is set in the toolchain.)
1991 {cpp_std: "", gnu_extensions: "", bazel_cpp_std: ""},
Liz Kammera5a29de2022-05-25 23:19:37 -04001992 {cpp_std: "", gnu_extensions: "false", bazel_cpp_std: "cpp_std_default_no_gnu", bazel_c_std: "c_std_default_no_gnu"},
Jingwen Chen97b85312021-10-08 10:41:31 +00001993 {cpp_std: "", gnu_extensions: "true", bazel_cpp_std: ""},
1994 // experimental defaults to gnu++2a
Liz Kammera5a29de2022-05-25 23:19:37 -04001995 {cpp_std: "experimental", gnu_extensions: "", bazel_cpp_std: "cpp_std_experimental"},
1996 {cpp_std: "experimental", gnu_extensions: "false", bazel_cpp_std: "cpp_std_experimental_no_gnu", bazel_c_std: "c_std_default_no_gnu"},
1997 {cpp_std: "experimental", gnu_extensions: "true", bazel_cpp_std: "cpp_std_experimental"},
Jingwen Chen97b85312021-10-08 10:41:31 +00001998 // Explicitly setting a c++ std does not use replace gnu++ std even if
1999 // gnu_extensions is true.
2000 // "c++11",
2001 {cpp_std: "c++11", gnu_extensions: "", bazel_cpp_std: "c++11"},
Liz Kammera5a29de2022-05-25 23:19:37 -04002002 {cpp_std: "c++11", gnu_extensions: "false", bazel_cpp_std: "c++11", bazel_c_std: "c_std_default_no_gnu"},
Jingwen Chen97b85312021-10-08 10:41:31 +00002003 {cpp_std: "c++11", gnu_extensions: "true", bazel_cpp_std: "c++11"},
2004 // "c++17",
2005 {cpp_std: "c++17", gnu_extensions: "", bazel_cpp_std: "c++17"},
Liz Kammera5a29de2022-05-25 23:19:37 -04002006 {cpp_std: "c++17", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c_std_default_no_gnu"},
Jingwen Chen97b85312021-10-08 10:41:31 +00002007 {cpp_std: "c++17", gnu_extensions: "true", bazel_cpp_std: "c++17"},
2008 // "c++2a",
2009 {cpp_std: "c++2a", gnu_extensions: "", bazel_cpp_std: "c++2a"},
Liz Kammera5a29de2022-05-25 23:19:37 -04002010 {cpp_std: "c++2a", gnu_extensions: "false", bazel_cpp_std: "c++2a", bazel_c_std: "c_std_default_no_gnu"},
Jingwen Chen97b85312021-10-08 10:41:31 +00002011 {cpp_std: "c++2a", gnu_extensions: "true", bazel_cpp_std: "c++2a"},
2012 // "c++98",
2013 {cpp_std: "c++98", gnu_extensions: "", bazel_cpp_std: "c++98"},
Liz Kammera5a29de2022-05-25 23:19:37 -04002014 {cpp_std: "c++98", gnu_extensions: "false", bazel_cpp_std: "c++98", bazel_c_std: "c_std_default_no_gnu"},
Jingwen Chen97b85312021-10-08 10:41:31 +00002015 {cpp_std: "c++98", gnu_extensions: "true", bazel_cpp_std: "c++98"},
2016 // gnu++ is replaced with c++ if gnu_extensions is explicitly false.
2017 // "gnu++11",
2018 {cpp_std: "gnu++11", gnu_extensions: "", bazel_cpp_std: "gnu++11"},
Liz Kammera5a29de2022-05-25 23:19:37 -04002019 {cpp_std: "gnu++11", gnu_extensions: "false", bazel_cpp_std: "c++11", bazel_c_std: "c_std_default_no_gnu"},
Jingwen Chen97b85312021-10-08 10:41:31 +00002020 {cpp_std: "gnu++11", gnu_extensions: "true", bazel_cpp_std: "gnu++11"},
2021 // "gnu++17",
2022 {cpp_std: "gnu++17", gnu_extensions: "", bazel_cpp_std: "gnu++17"},
Liz Kammera5a29de2022-05-25 23:19:37 -04002023 {cpp_std: "gnu++17", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c_std_default_no_gnu"},
Jingwen Chen97b85312021-10-08 10:41:31 +00002024 {cpp_std: "gnu++17", gnu_extensions: "true", bazel_cpp_std: "gnu++17"},
Chris Parsons79bd2b72021-11-29 17:52:41 -05002025
2026 // some c_std test cases
Liz Kammera5a29de2022-05-25 23:19:37 -04002027 {c_std: "experimental", gnu_extensions: "", bazel_c_std: "c_std_experimental"},
2028 {c_std: "experimental", gnu_extensions: "false", bazel_cpp_std: "cpp_std_default_no_gnu", bazel_c_std: "c_std_experimental_no_gnu"},
2029 {c_std: "experimental", gnu_extensions: "true", bazel_c_std: "c_std_experimental"},
Chris Parsons79bd2b72021-11-29 17:52:41 -05002030 {c_std: "gnu11", cpp_std: "gnu++17", gnu_extensions: "", bazel_cpp_std: "gnu++17", bazel_c_std: "gnu11"},
2031 {c_std: "gnu11", cpp_std: "gnu++17", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c11"},
2032 {c_std: "gnu11", cpp_std: "gnu++17", gnu_extensions: "true", bazel_cpp_std: "gnu++17", bazel_c_std: "gnu11"},
Jingwen Chen97b85312021-10-08 10:41:31 +00002033 }
Chris Parsons79bd2b72021-11-29 17:52:41 -05002034 for i, tc := range testCases {
Liz Kammera5a29de2022-05-25 23:19:37 -04002035 name := fmt.Sprintf("cpp std: %q, c std: %q, gnu_extensions: %q", tc.cpp_std, tc.c_std, tc.gnu_extensions)
2036 t.Run(name, func(t *testing.T) {
2037 name_prefix := fmt.Sprintf("a_%v", i)
2038 cppStdProp := ""
2039 if tc.cpp_std != "" {
2040 cppStdProp = fmt.Sprintf(" cpp_std: \"%s\",", tc.cpp_std)
2041 }
2042 cStdProp := ""
2043 if tc.c_std != "" {
2044 cStdProp = fmt.Sprintf(" c_std: \"%s\",", tc.c_std)
2045 }
2046 gnuExtensionsProp := ""
2047 if tc.gnu_extensions != "" {
2048 gnuExtensionsProp = fmt.Sprintf(" gnu_extensions: %s,", tc.gnu_extensions)
2049 }
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002050 attrs := AttrNameToString{}
Liz Kammera5a29de2022-05-25 23:19:37 -04002051 if tc.bazel_cpp_std != "" {
2052 attrs["cpp_std"] = fmt.Sprintf(`"%s"`, tc.bazel_cpp_std)
2053 }
2054 if tc.bazel_c_std != "" {
2055 attrs["c_std"] = fmt.Sprintf(`"%s"`, tc.bazel_c_std)
2056 }
Jingwen Chen97b85312021-10-08 10:41:31 +00002057
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002058 runCcLibraryTestCase(t, Bp2buildTestCase{
2059 Description: fmt.Sprintf(
Liz Kammera5a29de2022-05-25 23:19:37 -04002060 "cc_library with cpp_std: %s and gnu_extensions: %s", tc.cpp_std, tc.gnu_extensions),
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002061 ModuleTypeUnderTest: "cc_library",
2062 ModuleTypeUnderTestFactory: cc.LibraryFactory,
2063 Blueprint: soongCcLibraryPreamble + fmt.Sprintf(`
Jingwen Chen97b85312021-10-08 10:41:31 +00002064cc_library {
Chris Parsons79bd2b72021-11-29 17:52:41 -05002065 name: "%s_full",
Jingwen Chen97b85312021-10-08 10:41:31 +00002066%s // cpp_std: *string
Chris Parsons79bd2b72021-11-29 17:52:41 -05002067%s // c_std: *string
Jingwen Chen97b85312021-10-08 10:41:31 +00002068%s // gnu_extensions: *bool
2069 include_build_directory: false,
2070}
Chris Parsons79bd2b72021-11-29 17:52:41 -05002071`, name_prefix, cppStdProp, cStdProp, gnuExtensionsProp),
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002072 ExpectedBazelTargets: makeCcLibraryTargets(name_prefix+"_full", attrs),
Liz Kammera5a29de2022-05-25 23:19:37 -04002073 })
Jingwen Chen5b11ab12021-10-11 17:44:33 +00002074
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002075 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2076 Description: fmt.Sprintf(
Liz Kammera5a29de2022-05-25 23:19:37 -04002077 "cc_library_static with cpp_std: %s and gnu_extensions: %s", tc.cpp_std, tc.gnu_extensions),
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002078 ModuleTypeUnderTest: "cc_library_static",
2079 ModuleTypeUnderTestFactory: cc.LibraryStaticFactory,
2080 Blueprint: soongCcLibraryPreamble + fmt.Sprintf(`
Jingwen Chen5b11ab12021-10-11 17:44:33 +00002081cc_library_static {
Chris Parsons79bd2b72021-11-29 17:52:41 -05002082 name: "%s_static",
Jingwen Chen5b11ab12021-10-11 17:44:33 +00002083%s // cpp_std: *string
Chris Parsons79bd2b72021-11-29 17:52:41 -05002084%s // c_std: *string
Jingwen Chen5b11ab12021-10-11 17:44:33 +00002085%s // gnu_extensions: *bool
2086 include_build_directory: false,
2087}
Chris Parsons79bd2b72021-11-29 17:52:41 -05002088`, name_prefix, cppStdProp, cStdProp, gnuExtensionsProp),
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002089 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00002090 MakeBazelTarget("cc_library_static", name_prefix+"_static", attrs),
Liz Kammera5a29de2022-05-25 23:19:37 -04002091 },
2092 })
Jingwen Chen5b11ab12021-10-11 17:44:33 +00002093
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002094 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
2095 Description: fmt.Sprintf(
Liz Kammera5a29de2022-05-25 23:19:37 -04002096 "cc_library_shared with cpp_std: %s and gnu_extensions: %s", tc.cpp_std, tc.gnu_extensions),
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002097 ModuleTypeUnderTest: "cc_library_shared",
2098 ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
2099 Blueprint: soongCcLibraryPreamble + fmt.Sprintf(`
Jingwen Chen5b11ab12021-10-11 17:44:33 +00002100cc_library_shared {
Chris Parsons79bd2b72021-11-29 17:52:41 -05002101 name: "%s_shared",
Jingwen Chen5b11ab12021-10-11 17:44:33 +00002102%s // cpp_std: *string
Chris Parsons79bd2b72021-11-29 17:52:41 -05002103%s // c_std: *string
Jingwen Chen5b11ab12021-10-11 17:44:33 +00002104%s // gnu_extensions: *bool
2105 include_build_directory: false,
2106}
Chris Parsons79bd2b72021-11-29 17:52:41 -05002107`, name_prefix, cppStdProp, cStdProp, gnuExtensionsProp),
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002108 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00002109 MakeBazelTarget("cc_library_shared", name_prefix+"_shared", attrs),
Liz Kammera5a29de2022-05-25 23:19:37 -04002110 },
2111 })
Jingwen Chen5b11ab12021-10-11 17:44:33 +00002112 })
Jingwen Chen97b85312021-10-08 10:41:31 +00002113 }
Chris Parsons2dde0cb2021-10-01 14:45:30 -04002114}
Liz Kammer12615db2021-09-28 09:19:17 -04002115
2116func TestCcLibraryProtoSimple(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002117 runCcLibraryTestCase(t, Bp2buildTestCase{
2118 ModuleTypeUnderTest: "cc_library",
2119 ModuleTypeUnderTestFactory: cc.LibraryFactory,
2120 Blueprint: soongCcProtoPreamble + `cc_library {
Liz Kammer12615db2021-09-28 09:19:17 -04002121 name: "foo",
2122 srcs: ["foo.proto"],
2123 include_build_directory: false,
2124}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002125 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00002126 MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
Liz Kammer7756c8f2022-02-14 20:49:15 -05002127 "srcs": `["foo.proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00002128 }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04002129 "deps": `[":foo_proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00002130 }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04002131 "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`,
Chris Parsons77acf2e2021-12-03 17:27:16 -05002132 "deps": `[":libprotobuf-cpp-lite"]`,
Alixe06d75b2022-08-31 18:28:19 +00002133 }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Liz Kammer84b0ecb2022-09-14 10:49:13 -04002134 "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
2135 "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`,
Liz Kammer12615db2021-09-28 09:19:17 -04002136 }),
2137 },
2138 })
2139}
2140
2141func TestCcLibraryProtoNoCanonicalPathFromRoot(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002142 runCcLibraryTestCase(t, Bp2buildTestCase{
2143 ModuleTypeUnderTest: "cc_library",
2144 ModuleTypeUnderTestFactory: cc.LibraryFactory,
2145 Blueprint: soongCcProtoPreamble + `cc_library {
Liz Kammer12615db2021-09-28 09:19:17 -04002146 name: "foo",
2147 srcs: ["foo.proto"],
2148 proto: { canonical_path_from_root: false},
2149 include_build_directory: false,
2150}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002151 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00002152 MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
Liz Kammer7756c8f2022-02-14 20:49:15 -05002153 "srcs": `["foo.proto"]`,
2154 "strip_import_prefix": `""`,
Alixe06d75b2022-08-31 18:28:19 +00002155 }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04002156 "deps": `[":foo_proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00002157 }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04002158 "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`,
Chris Parsons77acf2e2021-12-03 17:27:16 -05002159 "deps": `[":libprotobuf-cpp-lite"]`,
Alixe06d75b2022-08-31 18:28:19 +00002160 }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Liz Kammer84b0ecb2022-09-14 10:49:13 -04002161 "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
2162 "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`,
Liz Kammer12615db2021-09-28 09:19:17 -04002163 }),
2164 },
2165 })
2166}
2167
2168func TestCcLibraryProtoExplicitCanonicalPathFromRoot(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002169 runCcLibraryTestCase(t, Bp2buildTestCase{
2170 ModuleTypeUnderTest: "cc_library",
2171 ModuleTypeUnderTestFactory: cc.LibraryFactory,
2172 Blueprint: soongCcProtoPreamble + `cc_library {
Liz Kammer12615db2021-09-28 09:19:17 -04002173 name: "foo",
2174 srcs: ["foo.proto"],
2175 proto: { canonical_path_from_root: true},
2176 include_build_directory: false,
2177}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002178 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00002179 MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
Liz Kammer7756c8f2022-02-14 20:49:15 -05002180 "srcs": `["foo.proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00002181 }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04002182 "deps": `[":foo_proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00002183 }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04002184 "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`,
Chris Parsons77acf2e2021-12-03 17:27:16 -05002185 "deps": `[":libprotobuf-cpp-lite"]`,
Alixe06d75b2022-08-31 18:28:19 +00002186 }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Liz Kammer84b0ecb2022-09-14 10:49:13 -04002187 "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
2188 "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`,
Liz Kammer12615db2021-09-28 09:19:17 -04002189 }),
2190 },
2191 })
2192}
2193
2194func TestCcLibraryProtoFull(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002195 runCcLibraryTestCase(t, Bp2buildTestCase{
2196 ModuleTypeUnderTest: "cc_library",
2197 ModuleTypeUnderTestFactory: cc.LibraryFactory,
2198 Blueprint: soongCcProtoPreamble + `cc_library {
Liz Kammer12615db2021-09-28 09:19:17 -04002199 name: "foo",
2200 srcs: ["foo.proto"],
2201 proto: {
Liz Kammer12615db2021-09-28 09:19:17 -04002202 type: "full",
2203 },
2204 include_build_directory: false,
2205}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002206 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00002207 MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04002208 "srcs": `["foo.proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00002209 }), MakeBazelTarget("cc_proto_library", "foo_cc_proto", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04002210 "deps": `[":foo_proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00002211 }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04002212 "implementation_whole_archive_deps": `[":foo_cc_proto"]`,
Chris Parsons77acf2e2021-12-03 17:27:16 -05002213 "deps": `[":libprotobuf-cpp-full"]`,
Alixe06d75b2022-08-31 18:28:19 +00002214 }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Liz Kammer84b0ecb2022-09-14 10:49:13 -04002215 "dynamic_deps": `[":libprotobuf-cpp-full"]`,
2216 "implementation_whole_archive_deps": `[":foo_cc_proto"]`,
Liz Kammer12615db2021-09-28 09:19:17 -04002217 }),
2218 },
2219 })
2220}
2221
2222func TestCcLibraryProtoLite(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002223 runCcLibraryTestCase(t, Bp2buildTestCase{
2224 ModuleTypeUnderTest: "cc_library",
2225 ModuleTypeUnderTestFactory: cc.LibraryFactory,
2226 Blueprint: soongCcProtoPreamble + `cc_library {
Liz Kammer12615db2021-09-28 09:19:17 -04002227 name: "foo",
2228 srcs: ["foo.proto"],
2229 proto: {
Liz Kammer12615db2021-09-28 09:19:17 -04002230 type: "lite",
2231 },
2232 include_build_directory: false,
2233}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002234 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00002235 MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04002236 "srcs": `["foo.proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00002237 }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04002238 "deps": `[":foo_proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00002239 }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04002240 "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`,
Chris Parsons77acf2e2021-12-03 17:27:16 -05002241 "deps": `[":libprotobuf-cpp-lite"]`,
Alixe06d75b2022-08-31 18:28:19 +00002242 }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Liz Kammer84b0ecb2022-09-14 10:49:13 -04002243 "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
2244 "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`,
Liz Kammer12615db2021-09-28 09:19:17 -04002245 }),
2246 },
2247 })
2248}
2249
2250func TestCcLibraryProtoExportHeaders(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002251 runCcLibraryTestCase(t, Bp2buildTestCase{
2252 ModuleTypeUnderTest: "cc_library",
2253 ModuleTypeUnderTestFactory: cc.LibraryFactory,
2254 Blueprint: soongCcProtoPreamble + `cc_library {
Liz Kammer12615db2021-09-28 09:19:17 -04002255 name: "foo",
2256 srcs: ["foo.proto"],
2257 proto: {
Liz Kammer12615db2021-09-28 09:19:17 -04002258 export_proto_headers: true,
2259 },
2260 include_build_directory: false,
2261}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002262 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00002263 MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04002264 "srcs": `["foo.proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00002265 }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04002266 "deps": `[":foo_proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00002267 }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05002268 "deps": `[":libprotobuf-cpp-lite"]`,
Liz Kammer12615db2021-09-28 09:19:17 -04002269 "whole_archive_deps": `[":foo_cc_proto_lite"]`,
Alixe06d75b2022-08-31 18:28:19 +00002270 }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Chris Parsons77acf2e2021-12-03 17:27:16 -05002271 "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
2272 "whole_archive_deps": `[":foo_cc_proto_lite"]`,
Liz Kammer12615db2021-09-28 09:19:17 -04002273 }),
2274 },
2275 })
2276}
Liz Kammeraabfb5d2021-12-08 15:25:06 -05002277
Yu Liu2d136142022-08-18 14:46:13 -07002278func TestCcLibraryProtoIncludeDirs(t *testing.T) {
2279 runCcLibraryTestCase(t, Bp2buildTestCase{
2280 ModuleTypeUnderTest: "cc_library",
2281 ModuleTypeUnderTestFactory: cc.LibraryFactory,
2282 Blueprint: soongCcProtoPreamble + `cc_library {
2283 name: "foo",
2284 srcs: ["foo.proto"],
2285 proto: {
2286 include_dirs: ["external/protobuf/src"],
2287 },
2288 include_build_directory: false,
2289}`,
2290 ExpectedBazelTargets: []string{
2291 MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
2292 "srcs": `["foo.proto"]`,
2293 "deps": `["//external/protobuf:libprotobuf-proto"]`,
2294 }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{
2295 "deps": `[":foo_proto"]`,
2296 }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
2297 "deps": `[":libprotobuf-cpp-lite"]`,
2298 "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`,
2299 }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Liz Kammer84b0ecb2022-09-14 10:49:13 -04002300 "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
2301 "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`,
Yu Liu2d136142022-08-18 14:46:13 -07002302 }),
2303 },
2304 })
2305}
2306
2307func TestCcLibraryProtoIncludeDirsUnknown(t *testing.T) {
2308 runCcLibraryTestCase(t, Bp2buildTestCase{
2309 ModuleTypeUnderTest: "cc_library",
2310 ModuleTypeUnderTestFactory: cc.LibraryFactory,
2311 Blueprint: soongCcProtoPreamble + `cc_library {
2312 name: "foo",
2313 srcs: ["foo.proto"],
2314 proto: {
2315 include_dirs: ["external/protobuf/abc"],
2316 },
2317 include_build_directory: false,
2318}`,
2319 ExpectedErr: fmt.Errorf("module \"foo\": Could not find the proto_library target for include dir: external/protobuf/abc"),
2320 })
2321}
2322
Yu Liu2aa806b2022-09-01 11:54:47 -07002323func TestCcLibraryConvertedProtoFilegroups(t *testing.T) {
2324 runCcLibraryTestCase(t, Bp2buildTestCase{
2325 ModuleTypeUnderTest: "cc_library",
2326 ModuleTypeUnderTestFactory: cc.LibraryFactory,
2327 Blueprint: soongCcProtoPreamble + `
2328filegroup {
2329 name: "a_fg_proto",
2330 srcs: ["a_fg.proto"],
2331}
2332
2333cc_library {
2334 name: "a",
2335 srcs: [
2336 ":a_fg_proto",
2337 "a.proto",
2338 ],
2339 proto: {
2340 export_proto_headers: true,
2341 },
2342 include_build_directory: false,
2343}`,
2344 ExpectedBazelTargets: []string{
2345 MakeBazelTarget("proto_library", "a_proto", AttrNameToString{
Yu Liu2a85fb12022-09-15 22:18:48 -07002346 "deps": `[":a_fg_proto_bp2build_converted"]`,
Yu Liu2aa806b2022-09-01 11:54:47 -07002347 "srcs": `["a.proto"]`,
2348 }), MakeBazelTarget("cc_lite_proto_library", "a_cc_proto_lite", AttrNameToString{
2349 "deps": `[
2350 ":a_fg_proto_bp2build_converted",
2351 ":a_proto",
2352 ]`,
2353 }), MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{
2354 "deps": `[":libprotobuf-cpp-lite"]`,
2355 "whole_archive_deps": `[":a_cc_proto_lite"]`,
2356 }), MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
2357 "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
2358 "whole_archive_deps": `[":a_cc_proto_lite"]`,
2359 }), MakeBazelTargetNoRestrictions("proto_library", "a_fg_proto_bp2build_converted", AttrNameToString{
2360 "srcs": `["a_fg.proto"]`,
Yu Liu2a85fb12022-09-15 22:18:48 -07002361 "tags": `["manual"]`,
Yu Liu2aa806b2022-09-01 11:54:47 -07002362 }), MakeBazelTargetNoRestrictions("filegroup", "a_fg_proto", AttrNameToString{
2363 "srcs": `["a_fg.proto"]`,
2364 }),
2365 },
2366 })
2367}
2368
2369func TestCcLibraryConvertedProtoFilegroupsNoProtoFiles(t *testing.T) {
2370 runCcLibraryTestCase(t, Bp2buildTestCase{
2371 ModuleTypeUnderTest: "cc_library",
2372 ModuleTypeUnderTestFactory: cc.LibraryFactory,
2373 Blueprint: soongCcProtoPreamble + `
2374filegroup {
2375 name: "a_fg_proto",
2376 srcs: ["a_fg.proto"],
2377}
2378
2379cc_library {
2380 name: "a",
2381 srcs: [
2382 ":a_fg_proto",
2383 ],
2384 proto: {
2385 export_proto_headers: true,
2386 },
2387 include_build_directory: false,
2388}`,
2389 ExpectedBazelTargets: []string{
2390 MakeBazelTarget("cc_lite_proto_library", "a_cc_proto_lite", AttrNameToString{
2391 "deps": `[":a_fg_proto_bp2build_converted"]`,
2392 }), MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{
2393 "deps": `[":libprotobuf-cpp-lite"]`,
2394 "whole_archive_deps": `[":a_cc_proto_lite"]`,
2395 }), MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
2396 "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
2397 "whole_archive_deps": `[":a_cc_proto_lite"]`,
2398 }), MakeBazelTargetNoRestrictions("proto_library", "a_fg_proto_bp2build_converted", AttrNameToString{
2399 "srcs": `["a_fg.proto"]`,
Yu Liu2a85fb12022-09-15 22:18:48 -07002400 "tags": `["manual"]`,
Yu Liu2aa806b2022-09-01 11:54:47 -07002401 }), MakeBazelTargetNoRestrictions("filegroup", "a_fg_proto", AttrNameToString{
2402 "srcs": `["a_fg.proto"]`,
2403 }),
2404 },
2405 })
2406}
2407
2408func TestCcLibraryExternalConvertedProtoFilegroups(t *testing.T) {
2409 runCcLibraryTestCase(t, Bp2buildTestCase{
2410 ModuleTypeUnderTest: "cc_library",
2411 ModuleTypeUnderTestFactory: cc.LibraryFactory,
2412 Filesystem: map[string]string{
2413 "path/to/A/Android.bp": `
2414filegroup {
2415 name: "a_fg_proto",
2416 srcs: ["a_fg.proto"],
2417}`,
2418 },
2419 Blueprint: soongCcProtoPreamble + `
2420cc_library {
2421 name: "a",
2422 srcs: [
2423 ":a_fg_proto",
2424 "a.proto",
2425 ],
2426 proto: {
2427 export_proto_headers: true,
2428 },
2429 include_build_directory: false,
2430}`,
2431 ExpectedBazelTargets: []string{
2432 MakeBazelTarget("proto_library", "a_proto", AttrNameToString{
Yu Liu2a85fb12022-09-15 22:18:48 -07002433 "deps": `["//path/to/A:a_fg_proto_bp2build_converted"]`,
Yu Liu2aa806b2022-09-01 11:54:47 -07002434 "srcs": `["a.proto"]`,
2435 }), MakeBazelTarget("cc_lite_proto_library", "a_cc_proto_lite", AttrNameToString{
2436 "deps": `[
2437 "//path/to/A:a_fg_proto_bp2build_converted",
2438 ":a_proto",
2439 ]`,
2440 }), MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{
2441 "deps": `[":libprotobuf-cpp-lite"]`,
2442 "whole_archive_deps": `[":a_cc_proto_lite"]`,
2443 }), MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
2444 "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
2445 "whole_archive_deps": `[":a_cc_proto_lite"]`,
2446 }),
2447 },
2448 })
2449}
2450
Liz Kammeraabfb5d2021-12-08 15:25:06 -05002451func TestCcLibraryProtoFilegroups(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002452 runCcLibraryTestCase(t, Bp2buildTestCase{
2453 ModuleTypeUnderTest: "cc_library",
2454 ModuleTypeUnderTestFactory: cc.LibraryFactory,
2455 Blueprint: soongCcProtoPreamble +
Liz Kammeraabfb5d2021-12-08 15:25:06 -05002456 simpleModuleDoNotConvertBp2build("filegroup", "a_fg_proto") +
2457 simpleModuleDoNotConvertBp2build("filegroup", "b_protos") +
2458 simpleModuleDoNotConvertBp2build("filegroup", "c-proto-srcs") +
2459 simpleModuleDoNotConvertBp2build("filegroup", "proto-srcs-d") + `
2460cc_library {
2461 name: "a",
2462 srcs: [":a_fg_proto"],
2463 proto: {
Liz Kammeraabfb5d2021-12-08 15:25:06 -05002464 export_proto_headers: true,
2465 },
2466 include_build_directory: false,
2467}
2468
2469cc_library {
2470 name: "b",
2471 srcs: [":b_protos"],
2472 proto: {
Liz Kammeraabfb5d2021-12-08 15:25:06 -05002473 export_proto_headers: true,
2474 },
2475 include_build_directory: false,
2476}
2477
2478cc_library {
2479 name: "c",
2480 srcs: [":c-proto-srcs"],
2481 proto: {
Liz Kammeraabfb5d2021-12-08 15:25:06 -05002482 export_proto_headers: true,
2483 },
2484 include_build_directory: false,
2485}
2486
2487cc_library {
2488 name: "d",
2489 srcs: [":proto-srcs-d"],
2490 proto: {
Liz Kammeraabfb5d2021-12-08 15:25:06 -05002491 export_proto_headers: true,
2492 },
2493 include_build_directory: false,
2494}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002495 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00002496 MakeBazelTarget("proto_library", "a_proto", AttrNameToString{
Liz Kammeraabfb5d2021-12-08 15:25:06 -05002497 "srcs": `[":a_fg_proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00002498 }), MakeBazelTarget("cc_lite_proto_library", "a_cc_proto_lite", AttrNameToString{
Liz Kammeraabfb5d2021-12-08 15:25:06 -05002499 "deps": `[":a_proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00002500 }), MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{
Liz Kammeraabfb5d2021-12-08 15:25:06 -05002501 "deps": `[":libprotobuf-cpp-lite"]`,
2502 "whole_archive_deps": `[":a_cc_proto_lite"]`,
2503 "srcs": `[":a_fg_proto_cpp_srcs"]`,
2504 "srcs_as": `[":a_fg_proto_as_srcs"]`,
2505 "srcs_c": `[":a_fg_proto_c_srcs"]`,
Alixe06d75b2022-08-31 18:28:19 +00002506 }), MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
Liz Kammeraabfb5d2021-12-08 15:25:06 -05002507 "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
2508 "whole_archive_deps": `[":a_cc_proto_lite"]`,
2509 "srcs": `[":a_fg_proto_cpp_srcs"]`,
2510 "srcs_as": `[":a_fg_proto_as_srcs"]`,
2511 "srcs_c": `[":a_fg_proto_c_srcs"]`,
Alixe06d75b2022-08-31 18:28:19 +00002512 }), MakeBazelTarget("proto_library", "b_proto", AttrNameToString{
Liz Kammeraabfb5d2021-12-08 15:25:06 -05002513 "srcs": `[":b_protos"]`,
Alixe06d75b2022-08-31 18:28:19 +00002514 }), MakeBazelTarget("cc_lite_proto_library", "b_cc_proto_lite", AttrNameToString{
Liz Kammeraabfb5d2021-12-08 15:25:06 -05002515 "deps": `[":b_proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00002516 }), MakeBazelTarget("cc_library_static", "b_bp2build_cc_library_static", AttrNameToString{
Liz Kammeraabfb5d2021-12-08 15:25:06 -05002517 "deps": `[":libprotobuf-cpp-lite"]`,
2518 "whole_archive_deps": `[":b_cc_proto_lite"]`,
2519 "srcs": `[":b_protos_cpp_srcs"]`,
2520 "srcs_as": `[":b_protos_as_srcs"]`,
2521 "srcs_c": `[":b_protos_c_srcs"]`,
Alixe06d75b2022-08-31 18:28:19 +00002522 }), MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
Liz Kammeraabfb5d2021-12-08 15:25:06 -05002523 "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
2524 "whole_archive_deps": `[":b_cc_proto_lite"]`,
2525 "srcs": `[":b_protos_cpp_srcs"]`,
2526 "srcs_as": `[":b_protos_as_srcs"]`,
2527 "srcs_c": `[":b_protos_c_srcs"]`,
Alixe06d75b2022-08-31 18:28:19 +00002528 }), MakeBazelTarget("proto_library", "c_proto", AttrNameToString{
Liz Kammeraabfb5d2021-12-08 15:25:06 -05002529 "srcs": `[":c-proto-srcs"]`,
Alixe06d75b2022-08-31 18:28:19 +00002530 }), MakeBazelTarget("cc_lite_proto_library", "c_cc_proto_lite", AttrNameToString{
Liz Kammeraabfb5d2021-12-08 15:25:06 -05002531 "deps": `[":c_proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00002532 }), MakeBazelTarget("cc_library_static", "c_bp2build_cc_library_static", AttrNameToString{
Liz Kammeraabfb5d2021-12-08 15:25:06 -05002533 "deps": `[":libprotobuf-cpp-lite"]`,
2534 "whole_archive_deps": `[":c_cc_proto_lite"]`,
2535 "srcs": `[":c-proto-srcs_cpp_srcs"]`,
2536 "srcs_as": `[":c-proto-srcs_as_srcs"]`,
2537 "srcs_c": `[":c-proto-srcs_c_srcs"]`,
Alixe06d75b2022-08-31 18:28:19 +00002538 }), MakeBazelTarget("cc_library_shared", "c", AttrNameToString{
Liz Kammeraabfb5d2021-12-08 15:25:06 -05002539 "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
2540 "whole_archive_deps": `[":c_cc_proto_lite"]`,
2541 "srcs": `[":c-proto-srcs_cpp_srcs"]`,
2542 "srcs_as": `[":c-proto-srcs_as_srcs"]`,
2543 "srcs_c": `[":c-proto-srcs_c_srcs"]`,
Alixe06d75b2022-08-31 18:28:19 +00002544 }), MakeBazelTarget("proto_library", "d_proto", AttrNameToString{
Liz Kammeraabfb5d2021-12-08 15:25:06 -05002545 "srcs": `[":proto-srcs-d"]`,
Alixe06d75b2022-08-31 18:28:19 +00002546 }), MakeBazelTarget("cc_lite_proto_library", "d_cc_proto_lite", AttrNameToString{
Liz Kammeraabfb5d2021-12-08 15:25:06 -05002547 "deps": `[":d_proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00002548 }), MakeBazelTarget("cc_library_static", "d_bp2build_cc_library_static", AttrNameToString{
Liz Kammeraabfb5d2021-12-08 15:25:06 -05002549 "deps": `[":libprotobuf-cpp-lite"]`,
2550 "whole_archive_deps": `[":d_cc_proto_lite"]`,
2551 "srcs": `[":proto-srcs-d_cpp_srcs"]`,
2552 "srcs_as": `[":proto-srcs-d_as_srcs"]`,
2553 "srcs_c": `[":proto-srcs-d_c_srcs"]`,
Alixe06d75b2022-08-31 18:28:19 +00002554 }), MakeBazelTarget("cc_library_shared", "d", AttrNameToString{
Liz Kammeraabfb5d2021-12-08 15:25:06 -05002555 "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
2556 "whole_archive_deps": `[":d_cc_proto_lite"]`,
2557 "srcs": `[":proto-srcs-d_cpp_srcs"]`,
2558 "srcs_as": `[":proto-srcs-d_as_srcs"]`,
2559 "srcs_c": `[":proto-srcs-d_c_srcs"]`,
2560 }),
2561 },
2562 })
2563}
Chris Parsons58852a02021-12-09 18:10:18 -05002564
2565func TestCcLibraryDisabledArchAndTarget(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002566 runCcLibraryTestCase(t, Bp2buildTestCase{
2567 ModuleTypeUnderTest: "cc_library",
2568 ModuleTypeUnderTestFactory: cc.LibraryFactory,
2569 Blueprint: soongCcProtoPreamble + `cc_library {
Chris Parsons58852a02021-12-09 18:10:18 -05002570 name: "foo",
2571 srcs: ["foo.cpp"],
Liz Kammerdfeb1202022-05-13 17:20:20 -04002572 host_supported: true,
Chris Parsons58852a02021-12-09 18:10:18 -05002573 target: {
2574 darwin: {
2575 enabled: false,
2576 },
2577 windows: {
2578 enabled: false,
2579 },
2580 linux_glibc_x86: {
2581 enabled: false,
2582 },
2583 },
2584 include_build_directory: false,
2585}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002586 ExpectedBazelTargets: makeCcLibraryTargets("foo", AttrNameToString{
Chris Parsons58852a02021-12-09 18:10:18 -05002587 "srcs": `["foo.cpp"]`,
2588 "target_compatible_with": `select({
2589 "//build/bazel/platforms/os_arch:darwin_arm64": ["@platforms//:incompatible"],
2590 "//build/bazel/platforms/os_arch:darwin_x86_64": ["@platforms//:incompatible"],
2591 "//build/bazel/platforms/os_arch:linux_glibc_x86": ["@platforms//:incompatible"],
2592 "//build/bazel/platforms/os_arch:windows_x86": ["@platforms//:incompatible"],
2593 "//build/bazel/platforms/os_arch:windows_x86_64": ["@platforms//:incompatible"],
2594 "//conditions:default": [],
2595 })`,
2596 }),
2597 })
2598}
2599
2600func TestCcLibraryDisabledArchAndTargetWithDefault(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002601 runCcLibraryTestCase(t, Bp2buildTestCase{
2602 ModuleTypeUnderTest: "cc_library",
2603 ModuleTypeUnderTestFactory: cc.LibraryFactory,
2604 Blueprint: soongCcProtoPreamble + `cc_library {
Chris Parsons58852a02021-12-09 18:10:18 -05002605 name: "foo",
2606 srcs: ["foo.cpp"],
2607 enabled: false,
Liz Kammerdfeb1202022-05-13 17:20:20 -04002608 host_supported: true,
Chris Parsons58852a02021-12-09 18:10:18 -05002609 target: {
2610 darwin: {
2611 enabled: true,
2612 },
2613 windows: {
2614 enabled: false,
2615 },
2616 linux_glibc_x86: {
2617 enabled: false,
2618 },
2619 },
2620 include_build_directory: false,
2621}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002622 ExpectedBazelTargets: makeCcLibraryTargets("foo", AttrNameToString{
Chris Parsons58852a02021-12-09 18:10:18 -05002623 "srcs": `["foo.cpp"]`,
2624 "target_compatible_with": `select({
2625 "//build/bazel/platforms/os_arch:darwin_arm64": [],
2626 "//build/bazel/platforms/os_arch:darwin_x86_64": [],
2627 "//conditions:default": ["@platforms//:incompatible"],
2628 })`,
2629 }),
2630 })
2631}
2632
2633func TestCcLibrarySharedDisabled(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002634 runCcLibraryTestCase(t, Bp2buildTestCase{
2635 ModuleTypeUnderTest: "cc_library",
2636 ModuleTypeUnderTestFactory: cc.LibraryFactory,
2637 Blueprint: soongCcProtoPreamble + `cc_library {
Chris Parsons58852a02021-12-09 18:10:18 -05002638 name: "foo",
2639 srcs: ["foo.cpp"],
2640 enabled: false,
2641 shared: {
2642 enabled: true,
2643 },
2644 target: {
2645 android: {
2646 shared: {
2647 enabled: false,
2648 },
2649 }
2650 },
2651 include_build_directory: false,
2652}`,
Alixe06d75b2022-08-31 18:28:19 +00002653 ExpectedBazelTargets: []string{MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
Chris Parsons58852a02021-12-09 18:10:18 -05002654 "srcs": `["foo.cpp"]`,
2655 "target_compatible_with": `["@platforms//:incompatible"]`,
Alixe06d75b2022-08-31 18:28:19 +00002656 }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Chris Parsons58852a02021-12-09 18:10:18 -05002657 "srcs": `["foo.cpp"]`,
2658 "target_compatible_with": `select({
2659 "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
2660 "//conditions:default": [],
2661 })`,
2662 }),
2663 },
2664 })
2665}
2666
2667func TestCcLibraryStaticDisabledForSomeArch(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002668 runCcLibraryTestCase(t, Bp2buildTestCase{
2669 ModuleTypeUnderTest: "cc_library",
2670 ModuleTypeUnderTestFactory: cc.LibraryFactory,
2671 Blueprint: soongCcProtoPreamble + `cc_library {
Chris Parsons58852a02021-12-09 18:10:18 -05002672 name: "foo",
Liz Kammerdfeb1202022-05-13 17:20:20 -04002673 host_supported: true,
Chris Parsons58852a02021-12-09 18:10:18 -05002674 srcs: ["foo.cpp"],
2675 shared: {
2676 enabled: false
2677 },
2678 target: {
2679 darwin: {
2680 enabled: true,
2681 },
2682 windows: {
2683 enabled: false,
2684 },
2685 linux_glibc_x86: {
2686 shared: {
2687 enabled: true,
2688 },
2689 },
2690 },
2691 include_build_directory: false,
2692}`,
Alixe06d75b2022-08-31 18:28:19 +00002693 ExpectedBazelTargets: []string{MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
Chris Parsons58852a02021-12-09 18:10:18 -05002694 "srcs": `["foo.cpp"]`,
2695 "target_compatible_with": `select({
2696 "//build/bazel/platforms/os:windows": ["@platforms//:incompatible"],
2697 "//conditions:default": [],
2698 })`,
Alixe06d75b2022-08-31 18:28:19 +00002699 }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Chris Parsons58852a02021-12-09 18:10:18 -05002700 "srcs": `["foo.cpp"]`,
2701 "target_compatible_with": `select({
2702 "//build/bazel/platforms/os_arch:darwin_arm64": [],
2703 "//build/bazel/platforms/os_arch:darwin_x86_64": [],
2704 "//build/bazel/platforms/os_arch:linux_glibc_x86": [],
2705 "//conditions:default": ["@platforms//:incompatible"],
2706 })`,
2707 }),
2708 }})
2709}
Jingwen Chen0ee88a62022-01-07 14:55:29 +00002710
2711func TestCcLibraryStubs(t *testing.T) {
Wei Li81852ca2022-07-27 00:22:06 -07002712 expectedBazelTargets := makeCcLibraryTargets("a", AttrNameToString{
2713 "has_stubs": `True`,
2714 })
2715 expectedBazelTargets = append(expectedBazelTargets, makeCcStubSuiteTargets("a", AttrNameToString{
2716 "soname": `"a.so"`,
2717 "source_library": `":a"`,
2718 "stubs_symbol_file": `"a.map.txt"`,
2719 "stubs_versions": `[
2720 "28",
2721 "29",
2722 "current",
2723 ]`,
2724 }))
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002725 runCcLibraryTestCase(t, Bp2buildTestCase{
2726 Description: "cc_library stubs",
2727 ModuleTypeUnderTest: "cc_library",
2728 ModuleTypeUnderTestFactory: cc.LibraryFactory,
2729 Dir: "foo/bar",
2730 Filesystem: map[string]string{
Jingwen Chen0ee88a62022-01-07 14:55:29 +00002731 "foo/bar/Android.bp": `
2732cc_library {
2733 name: "a",
2734 stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
2735 bazel_module: { bp2build_available: true },
2736 include_build_directory: false,
2737}
2738`,
2739 },
Wei Li81852ca2022-07-27 00:22:06 -07002740 Blueprint: soongCcLibraryPreamble,
2741 ExpectedBazelTargets: expectedBazelTargets,
Jingwen Chen0ee88a62022-01-07 14:55:29 +00002742 },
2743 )
2744}
Liz Kammerf38a8372022-02-04 15:39:00 -05002745
Spandan Das4238c652022-09-09 01:38:47 +00002746func TestCcApiContributionsWithHdrs(t *testing.T) {
2747 bp := `
2748 cc_library {
2749 name: "libfoo",
2750 stubs: { symbol_file: "libfoo.map.txt", versions: ["28", "29", "current"] },
2751 llndk: { symbol_file: "libfoo.map.txt", override_export_include_dirs: ["dir2"]},
2752 export_include_dirs: ["dir1"],
2753 }
2754 `
2755 expectedBazelTargets := []string{
2756 MakeBazelTarget(
2757 "cc_api_library_headers",
2758 "libfoo.systemapi.headers",
2759 AttrNameToString{
2760 "export_includes": `["dir1"]`,
2761 }),
2762 MakeBazelTarget(
2763 "cc_api_library_headers",
2764 "libfoo.vendorapi.headers",
2765 AttrNameToString{
2766 "export_includes": `["dir2"]`,
2767 }),
2768 MakeBazelTarget(
2769 "cc_api_contribution",
2770 "libfoo.contribution",
2771 AttrNameToString{
2772 "api": `"libfoo.map.txt"`,
2773 "library_name": `"libfoo"`,
2774 "api_surfaces": `[
2775 "systemapi",
2776 "vendorapi",
2777 ]`,
2778 "hdrs": `[
2779 ":libfoo.systemapi.headers",
2780 ":libfoo.vendorapi.headers",
2781 ]`,
2782 }),
2783 }
2784 RunApiBp2BuildTestCase(t, cc.RegisterLibraryBuildComponents, Bp2buildTestCase{
2785 Blueprint: bp,
2786 Description: "cc API contributions to systemapi and vendorapi",
2787 ExpectedBazelTargets: expectedBazelTargets,
2788 })
2789}
2790
2791func TestCcApiSurfaceCombinations(t *testing.T) {
2792 testCases := []struct {
2793 bp string
2794 expectedApi string
2795 expectedApiSurfaces string
2796 description string
2797 }{
2798 {
2799 bp: `
2800 cc_library {
2801 name: "a",
2802 stubs: {symbol_file: "a.map.txt"},
2803 }`,
2804 expectedApi: `"a.map.txt"`,
2805 expectedApiSurfaces: `["systemapi"]`,
2806 description: "Library that contributes to systemapi",
2807 },
2808 {
2809 bp: `
2810 cc_library {
2811 name: "a",
2812 llndk: {symbol_file: "a.map.txt"},
2813 }`,
2814 expectedApi: `"a.map.txt"`,
2815 expectedApiSurfaces: `["vendorapi"]`,
2816 description: "Library that contributes to vendorapi",
2817 },
2818 {
2819 bp: `
2820 cc_library {
2821 name: "a",
2822 llndk: {symbol_file: "a.map.txt"},
2823 stubs: {symbol_file: "a.map.txt"},
2824 }`,
2825 expectedApi: `"a.map.txt"`,
2826 expectedApiSurfaces: `[
2827 "systemapi",
2828 "vendorapi",
2829 ]`,
2830 description: "Library that contributes to systemapi and vendorapi",
2831 },
2832 }
2833 for _, testCase := range testCases {
2834 expectedBazelTargets := []string{
2835 MakeBazelTarget(
2836 "cc_api_contribution",
2837 "a.contribution",
2838 AttrNameToString{
2839 "library_name": `"a"`,
2840 "hdrs": `[]`,
2841 "api": testCase.expectedApi,
2842 "api_surfaces": testCase.expectedApiSurfaces,
2843 },
2844 ),
2845 }
2846 RunApiBp2BuildTestCase(t, cc.RegisterLibraryBuildComponents, Bp2buildTestCase{
2847 Blueprint: testCase.bp,
2848 Description: testCase.description,
2849 ExpectedBazelTargets: expectedBazelTargets,
2850 })
2851 }
2852}
2853
2854// llndk struct property in Soong provides users with several options to configure the exported include dirs
2855// Test the generated bazel targets for the different configurations
2856func TestCcVendorApiHeaders(t *testing.T) {
2857 testCases := []struct {
2858 bp string
2859 expectedIncludes string
2860 expectedSystemIncludes string
2861 description string
2862 }{
2863 {
2864 bp: `
2865 cc_library {
2866 name: "a",
2867 export_include_dirs: ["include"],
2868 export_system_include_dirs: ["base_system_include"],
2869 llndk: {
2870 symbol_file: "a.map.txt",
2871 export_headers_as_system: true,
2872 },
2873 }
2874 `,
2875 expectedIncludes: "",
2876 expectedSystemIncludes: `[
2877 "base_system_include",
2878 "include",
2879 ]`,
2880 description: "Headers are exported as system to API surface",
2881 },
2882 {
2883 bp: `
2884 cc_library {
2885 name: "a",
2886 export_include_dirs: ["include"],
2887 export_system_include_dirs: ["base_system_include"],
2888 llndk: {
2889 symbol_file: "a.map.txt",
2890 override_export_include_dirs: ["llndk_include"],
2891 },
2892 }
2893 `,
2894 expectedIncludes: `["llndk_include"]`,
2895 expectedSystemIncludes: `["base_system_include"]`,
2896 description: "Non-system Headers are ovverriden before export to API surface",
2897 },
2898 {
2899 bp: `
2900 cc_library {
2901 name: "a",
2902 export_include_dirs: ["include"],
2903 export_system_include_dirs: ["base_system_include"],
2904 llndk: {
2905 symbol_file: "a.map.txt",
2906 override_export_include_dirs: ["llndk_include"],
2907 export_headers_as_system: true,
2908 },
2909 }
2910 `,
2911 expectedIncludes: "", // includes are set to nil
2912 expectedSystemIncludes: `[
2913 "base_system_include",
2914 "llndk_include",
2915 ]`,
2916 description: "System Headers are extended before export to API surface",
2917 },
2918 }
2919 for _, testCase := range testCases {
2920 attrs := AttrNameToString{}
2921 if testCase.expectedIncludes != "" {
2922 attrs["export_includes"] = testCase.expectedIncludes
2923 }
2924 if testCase.expectedSystemIncludes != "" {
2925 attrs["export_system_includes"] = testCase.expectedSystemIncludes
2926 }
2927
2928 expectedBazelTargets := []string{
2929 MakeBazelTarget("cc_api_library_headers", "a.vendorapi.headers", attrs),
2930 // Create a target for cc_api_contribution target
2931 MakeBazelTarget("cc_api_contribution", "a.contribution", AttrNameToString{
2932 "api": `"a.map.txt"`,
2933 "api_surfaces": `["vendorapi"]`,
2934 "hdrs": `[":a.vendorapi.headers"]`,
2935 "library_name": `"a"`,
2936 }),
2937 }
2938 RunApiBp2BuildTestCase(t, cc.RegisterLibraryBuildComponents, Bp2buildTestCase{
2939 Blueprint: testCase.bp,
2940 ExpectedBazelTargets: expectedBazelTargets,
2941 })
2942 }
2943}
2944
Trevor Radcliffe0ed6b7d2022-09-12 20:19:26 +00002945func TestCcLibraryStubsAcrossConfigsDuplicatesRemoved(t *testing.T) {
2946 runCcLibraryTestCase(t, Bp2buildTestCase{
2947 Description: "stub target generation of the same lib across configs should not result in duplicates",
2948 ModuleTypeUnderTest: "cc_library",
2949 ModuleTypeUnderTestFactory: cc.LibraryFactory,
2950 Filesystem: map[string]string{
2951 "bar.map.txt": "",
2952 },
2953 Blueprint: `
2954cc_library {
2955 name: "barlib",
2956 stubs: { symbol_file: "bar.map.txt", versions: ["28", "29", "current"] },
2957 bazel_module: { bp2build_available: false },
2958}
2959cc_library {
2960 name: "foolib",
2961 shared_libs: ["barlib"],
2962 target: {
2963 android: {
2964 shared_libs: ["barlib"],
2965 },
2966 },
2967 bazel_module: { bp2build_available: true },
2968}`,
2969 ExpectedBazelTargets: makeCcLibraryTargets("foolib", AttrNameToString{
2970 "implementation_dynamic_deps": `select({
2971 "//build/bazel/rules/apex:android-in_apex": [":barlib_stub_libs_current"],
2972 "//conditions:default": [":barlib"],
2973 })`,
2974 "local_includes": `["."]`,
2975 }),
2976 })
2977}
2978
Liz Kammerf38a8372022-02-04 15:39:00 -05002979func TestCcLibraryEscapeLdflags(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002980 runCcLibraryTestCase(t, Bp2buildTestCase{
2981 ModuleTypeUnderTest: "cc_library",
2982 ModuleTypeUnderTestFactory: cc.LibraryFactory,
2983 Blueprint: soongCcProtoPreamble + `cc_library {
Liz Kammerf38a8372022-02-04 15:39:00 -05002984 name: "foo",
2985 ldflags: ["-Wl,--rpath,${ORIGIN}"],
2986 include_build_directory: false,
2987}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002988 ExpectedBazelTargets: makeCcLibraryTargets("foo", AttrNameToString{
Liz Kammerf38a8372022-02-04 15:39:00 -05002989 "linkopts": `["-Wl,--rpath,$${ORIGIN}"]`,
2990 }),
2991 })
2992}
Trevor Radcliffeef9c9002022-05-13 20:55:35 +00002993
2994func TestCcLibraryConvertLex(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00002995 runCcLibraryTestCase(t, Bp2buildTestCase{
2996 ModuleTypeUnderTest: "cc_library",
2997 ModuleTypeUnderTestFactory: cc.LibraryFactory,
2998 Filesystem: map[string]string{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +00002999 "foo.c": "",
3000 "bar.cc": "",
3001 "foo1.l": "",
3002 "bar1.ll": "",
3003 "foo2.l": "",
3004 "bar2.ll": "",
3005 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00003006 Blueprint: `cc_library {
Trevor Radcliffeef9c9002022-05-13 20:55:35 +00003007 name: "foo_lib",
3008 srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"],
3009 lex: { flags: ["--foo_flags"] },
3010 include_build_directory: false,
3011 bazel_module: { bp2build_available: true },
3012}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00003013 ExpectedBazelTargets: append([]string{
Alixe06d75b2022-08-31 18:28:19 +00003014 MakeBazelTarget("genlex", "foo_lib_genlex_l", AttrNameToString{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +00003015 "srcs": `[
3016 "foo1.l",
3017 "foo2.l",
3018 ]`,
3019 "lexopts": `["--foo_flags"]`,
3020 }),
Alixe06d75b2022-08-31 18:28:19 +00003021 MakeBazelTarget("genlex", "foo_lib_genlex_ll", AttrNameToString{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +00003022 "srcs": `[
3023 "bar1.ll",
3024 "bar2.ll",
3025 ]`,
3026 "lexopts": `["--foo_flags"]`,
3027 }),
3028 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00003029 makeCcLibraryTargets("foo_lib", AttrNameToString{
Trevor Radcliffeef9c9002022-05-13 20:55:35 +00003030 "srcs": `[
3031 "bar.cc",
3032 ":foo_lib_genlex_ll",
3033 ]`,
3034 "srcs_c": `[
3035 "foo.c",
3036 ":foo_lib_genlex_l",
3037 ]`,
3038 })...),
3039 })
3040}
Cole Faust6b29f592022-08-09 09:50:56 -07003041
3042func TestCCLibraryRuntimeDeps(t *testing.T) {
3043 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
3044 Blueprint: `cc_library_shared {
3045 name: "bar",
3046}
3047
3048cc_library {
3049 name: "foo",
3050 runtime_libs: ["foo"],
3051}`,
3052 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00003053 MakeBazelTarget("cc_library_shared", "bar", AttrNameToString{
Cole Faust6b29f592022-08-09 09:50:56 -07003054 "local_includes": `["."]`,
3055 }),
Alixe06d75b2022-08-31 18:28:19 +00003056 MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
Cole Faust6b29f592022-08-09 09:50:56 -07003057 "runtime_deps": `[":foo"]`,
3058 "local_includes": `["."]`,
3059 }),
Alixe06d75b2022-08-31 18:28:19 +00003060 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Cole Faust6b29f592022-08-09 09:50:56 -07003061 "runtime_deps": `[":foo"]`,
3062 "local_includes": `["."]`,
3063 }),
3064 },
3065 })
3066}
Cole Faust5fa4e962022-08-22 14:31:04 -07003067
3068func TestCcLibraryWithInstructionSet(t *testing.T) {
3069 runCcLibraryTestCase(t, Bp2buildTestCase{
3070 ModuleTypeUnderTest: "cc_library",
3071 ModuleTypeUnderTestFactory: cc.LibraryFactory,
3072 Blueprint: `cc_library {
3073 name: "foo",
3074 arch: {
3075 arm: {
3076 instruction_set: "arm",
3077 }
3078 }
3079}
3080`,
3081 ExpectedBazelTargets: makeCcLibraryTargets("foo", AttrNameToString{
3082 "features": `select({
3083 "//build/bazel/platforms/arch:arm": [
3084 "arm_isa_arm",
3085 "-arm_isa_thumb",
3086 ],
3087 "//conditions:default": [],
3088 })`,
3089 "local_includes": `["."]`,
3090 }),
3091 })
3092}
Vinh Tran9f6796a2022-08-16 13:10:31 -04003093
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -05003094func TestCcLibraryEmptySuffix(t *testing.T) {
3095 runCcLibraryTestCase(t, Bp2buildTestCase{
3096 Description: "cc_library with empty suffix",
3097 ModuleTypeUnderTest: "cc_library",
3098 ModuleTypeUnderTestFactory: cc.LibraryFactory,
3099 Filesystem: map[string]string{
3100 "foo.c": "",
3101 },
3102 Blueprint: `cc_library {
3103 name: "foo",
3104 suffix: "",
3105 srcs: ["foo.c"],
3106 include_build_directory: false,
3107}`,
3108 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00003109 MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -05003110 "srcs_c": `["foo.c"]`,
3111 }),
Alixe06d75b2022-08-31 18:28:19 +00003112 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -05003113 "srcs_c": `["foo.c"]`,
3114 "suffix": `""`,
3115 }),
3116 },
3117 })
3118}
3119
3120func TestCcLibrarySuffix(t *testing.T) {
3121 runCcLibraryTestCase(t, Bp2buildTestCase{
3122 Description: "cc_library with suffix",
3123 ModuleTypeUnderTest: "cc_library",
3124 ModuleTypeUnderTestFactory: cc.LibraryFactory,
3125 Filesystem: map[string]string{
3126 "foo.c": "",
3127 },
3128 Blueprint: `cc_library {
3129 name: "foo",
3130 suffix: "-suf",
3131 srcs: ["foo.c"],
3132 include_build_directory: false,
3133}`,
3134 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00003135 MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -05003136 "srcs_c": `["foo.c"]`,
3137 }),
Alixe06d75b2022-08-31 18:28:19 +00003138 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -05003139 "srcs_c": `["foo.c"]`,
3140 "suffix": `"-suf"`,
3141 }),
3142 },
3143 })
3144}
3145
3146func TestCcLibraryArchVariantSuffix(t *testing.T) {
3147 runCcLibraryTestCase(t, Bp2buildTestCase{
3148 Description: "cc_library with arch-variant suffix",
3149 ModuleTypeUnderTest: "cc_library",
3150 ModuleTypeUnderTestFactory: cc.LibraryFactory,
3151 Filesystem: map[string]string{
3152 "foo.c": "",
3153 },
3154 Blueprint: `cc_library {
3155 name: "foo",
3156 arch: {
3157 arm64: { suffix: "-64" },
3158 arm: { suffix: "-32" },
3159 },
3160 srcs: ["foo.c"],
3161 include_build_directory: false,
3162}`,
3163 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00003164 MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -05003165 "srcs_c": `["foo.c"]`,
3166 }),
Alixe06d75b2022-08-31 18:28:19 +00003167 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -05003168 "srcs_c": `["foo.c"]`,
3169 "suffix": `select({
3170 "//build/bazel/platforms/arch:arm": "-32",
3171 "//build/bazel/platforms/arch:arm64": "-64",
3172 "//conditions:default": None,
3173 })`,
3174 }),
3175 },
3176 })
3177}
3178
Vinh Tran9f6796a2022-08-16 13:10:31 -04003179func TestCcLibraryWithAidlSrcs(t *testing.T) {
3180 runCcLibraryTestCase(t, Bp2buildTestCase{
3181 Description: "cc_library with aidl srcs",
3182 ModuleTypeUnderTest: "cc_library",
3183 ModuleTypeUnderTestFactory: cc.LibraryFactory,
3184 Blueprint: `
3185filegroup {
3186 name: "A_aidl",
3187 srcs: ["aidl/A.aidl"],
3188 path: "aidl",
3189}
3190cc_library {
3191 name: "foo",
3192 srcs: [
3193 ":A_aidl",
3194 "B.aidl",
3195 ],
3196}`,
3197 ExpectedBazelTargets: []string{
3198 MakeBazelTargetNoRestrictions("aidl_library", "A_aidl", AttrNameToString{
3199 "srcs": `["aidl/A.aidl"]`,
3200 "strip_import_prefix": `"aidl"`,
3201 }),
Alixe06d75b2022-08-31 18:28:19 +00003202 MakeBazelTarget("aidl_library", "foo_aidl_library", AttrNameToString{
Vinh Tran9f6796a2022-08-16 13:10:31 -04003203 "srcs": `["B.aidl"]`,
3204 }),
Alixe06d75b2022-08-31 18:28:19 +00003205 MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{
Vinh Tran9f6796a2022-08-16 13:10:31 -04003206 "deps": `[
3207 ":A_aidl",
3208 ":foo_aidl_library",
3209 ]`,
3210 }),
Alixe06d75b2022-08-31 18:28:19 +00003211 MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
Vinh Tranfde57eb2022-08-29 17:46:58 -04003212 "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`,
3213 "local_includes": `["."]`,
Vinh Tran9f6796a2022-08-16 13:10:31 -04003214 }),
Alixe06d75b2022-08-31 18:28:19 +00003215 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Liz Kammer84b0ecb2022-09-14 10:49:13 -04003216 "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`,
3217 "local_includes": `["."]`,
Vinh Tran9f6796a2022-08-16 13:10:31 -04003218 }),
3219 },
3220 })
3221}
3222
3223func TestCcLibraryWithNonAdjacentAidlFilegroup(t *testing.T) {
3224 runCcLibraryTestCase(t, Bp2buildTestCase{
3225 Description: "cc_library with non aidl filegroup",
3226 ModuleTypeUnderTest: "cc_library",
3227 ModuleTypeUnderTestFactory: cc.LibraryFactory,
3228 Filesystem: map[string]string{
3229 "path/to/A/Android.bp": `
3230filegroup {
Vinh Tranfde57eb2022-08-29 17:46:58 -04003231 name: "A_aidl",
3232 srcs: ["aidl/A.aidl"],
3233 path: "aidl",
Vinh Tran9f6796a2022-08-16 13:10:31 -04003234}`,
3235 },
3236 Blueprint: `
3237cc_library {
Vinh Tranfde57eb2022-08-29 17:46:58 -04003238 name: "foo",
3239 srcs: [
3240 ":A_aidl",
3241 ],
Vinh Tran9f6796a2022-08-16 13:10:31 -04003242}`,
3243 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00003244 MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{
Vinh Tran9f6796a2022-08-16 13:10:31 -04003245 "deps": `["//path/to/A:A_aidl"]`,
3246 }),
Alixe06d75b2022-08-31 18:28:19 +00003247 MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
Vinh Tranfde57eb2022-08-29 17:46:58 -04003248 "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`,
3249 "local_includes": `["."]`,
3250 }),
Vinh Tranfde57eb2022-08-29 17:46:58 -04003251 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Liz Kammer84b0ecb2022-09-14 10:49:13 -04003252 "local_includes": `["."]`,
3253 "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`,
Vinh Tranfde57eb2022-08-29 17:46:58 -04003254 }),
3255 },
3256 })
3257}
3258
3259func TestCcLibraryWithExportAidlHeaders(t *testing.T) {
3260 runCcLibraryTestCase(t, Bp2buildTestCase{
3261 Description: "cc_library with export aidl headers",
3262 ModuleTypeUnderTest: "cc_library",
3263 ModuleTypeUnderTestFactory: cc.LibraryFactory,
3264 Blueprint: `
3265cc_library {
3266 name: "foo",
3267 srcs: [
3268 "Foo.aidl",
3269 ],
3270 aidl: {
3271 export_aidl_headers: true,
3272 }
3273}`,
3274 ExpectedBazelTargets: []string{
3275 MakeBazelTarget("aidl_library", "foo_aidl_library", AttrNameToString{
3276 "srcs": `["Foo.aidl"]`,
3277 }),
3278 MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{
3279 "deps": `[":foo_aidl_library"]`,
3280 }),
3281 MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
Vinh Tran9f6796a2022-08-16 13:10:31 -04003282 "whole_archive_deps": `[":foo_cc_aidl_library"]`,
3283 "local_includes": `["."]`,
3284 }),
Alixe06d75b2022-08-31 18:28:19 +00003285 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
Vinh Tran9f6796a2022-08-16 13:10:31 -04003286 "whole_archive_deps": `[":foo_cc_aidl_library"]`,
3287 "local_includes": `["."]`,
3288 }),
3289 },
3290 })
3291}
Vinh Tran85fb07c2022-09-16 16:17:48 -04003292
3293func TestCcLibraryWithTargetApex(t *testing.T) {
3294 runCcLibraryTestCase(t, Bp2buildTestCase{
3295 Description: "cc_library with target.apex",
3296 ModuleTypeUnderTest: "cc_library",
3297 ModuleTypeUnderTestFactory: cc.LibraryFactory,
3298 Blueprint: `
3299cc_library {
3300 name: "foo",
3301 shared_libs: ["bar", "baz"],
3302 static_libs: ["baz", "buh"],
3303 target: {
3304 apex: {
3305 exclude_shared_libs: ["bar"],
3306 exclude_static_libs: ["buh"],
3307 }
3308 }
3309}`,
3310 ExpectedBazelTargets: []string{
3311 MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
3312 "implementation_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({
3313 "//build/bazel/rules/apex:non_apex": [":buh__BP2BUILD__MISSING__DEP"],
3314 "//conditions:default": [],
3315 })`,
3316 "implementation_dynamic_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({
3317 "//build/bazel/rules/apex:non_apex": [":bar__BP2BUILD__MISSING__DEP"],
3318 "//conditions:default": [],
3319 })`,
3320 "local_includes": `["."]`,
3321 }),
3322 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
3323 "implementation_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({
3324 "//build/bazel/rules/apex:non_apex": [":buh__BP2BUILD__MISSING__DEP"],
3325 "//conditions:default": [],
3326 })`,
3327 "implementation_dynamic_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({
3328 "//build/bazel/rules/apex:non_apex": [":bar__BP2BUILD__MISSING__DEP"],
3329 "//conditions:default": [],
3330 })`,
3331 "local_includes": `["."]`,
3332 }),
3333 },
3334 })
3335}
3336
3337func TestCcLibraryWithTargetApexAndExportLibHeaders(t *testing.T) {
3338 runCcLibraryTestCase(t, Bp2buildTestCase{
3339 Description: "cc_library with target.apex and export_shared|static_lib_headers",
3340 ModuleTypeUnderTest: "cc_library",
3341 ModuleTypeUnderTestFactory: cc.LibraryFactory,
3342 Blueprint: `
3343cc_library_static {
3344 name: "foo",
3345 shared_libs: ["bar", "baz"],
3346 static_libs: ["abc"],
3347 export_shared_lib_headers: ["baz"],
3348 export_static_lib_headers: ["abc"],
3349 target: {
3350 apex: {
3351 exclude_shared_libs: ["baz", "bar"],
3352 exclude_static_libs: ["abc"],
3353 }
3354 }
3355}`,
3356 ExpectedBazelTargets: []string{
3357 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
3358 "implementation_dynamic_deps": `select({
3359 "//build/bazel/rules/apex:non_apex": [":bar__BP2BUILD__MISSING__DEP"],
3360 "//conditions:default": [],
3361 })`,
3362 "dynamic_deps": `select({
3363 "//build/bazel/rules/apex:non_apex": [":baz__BP2BUILD__MISSING__DEP"],
3364 "//conditions:default": [],
3365 })`,
3366 "deps": `select({
3367 "//build/bazel/rules/apex:non_apex": [":abc__BP2BUILD__MISSING__DEP"],
3368 "//conditions:default": [],
3369 })`,
3370 "local_includes": `["."]`,
3371 }),
3372 },
3373 })
3374}
Trevor Radcliffecee4e052022-09-06 19:31:25 +00003375
3376func TestCcLibraryWithSyspropSrcs(t *testing.T) {
3377 runCcLibraryTestCase(t, Bp2buildTestCase{
3378 Description: "cc_library with sysprop sources",
3379 ModuleTypeUnderTest: "cc_library",
3380 ModuleTypeUnderTestFactory: cc.LibraryFactory,
3381 Blueprint: `
3382cc_library {
3383 name: "foo",
3384 srcs: [
3385 "bar.sysprop",
3386 "baz.sysprop",
3387 "blah.cpp",
3388 ],
3389 min_sdk_version: "5",
3390}`,
3391 ExpectedBazelTargets: []string{
3392 MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
3393 "srcs": `[
3394 "bar.sysprop",
3395 "baz.sysprop",
3396 ]`,
3397 }),
3398 MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
3399 "dep": `":foo_sysprop_library"`,
3400 "min_sdk_version": `"5"`,
3401 }),
3402 MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
3403 "srcs": `["blah.cpp"]`,
3404 "local_includes": `["."]`,
3405 "min_sdk_version": `"5"`,
3406 "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`,
3407 }),
3408 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
3409 "srcs": `["blah.cpp"]`,
3410 "local_includes": `["."]`,
3411 "min_sdk_version": `"5"`,
3412 "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`,
3413 }),
3414 },
3415 })
3416}
3417
3418func TestCcLibraryWithSyspropSrcsSomeConfigs(t *testing.T) {
3419 runCcLibraryTestCase(t, Bp2buildTestCase{
3420 Description: "cc_library with sysprop sources in some configs but not others",
3421 ModuleTypeUnderTest: "cc_library",
3422 ModuleTypeUnderTestFactory: cc.LibraryFactory,
3423 Blueprint: `
3424cc_library {
3425 name: "foo",
3426 host_supported: true,
3427 srcs: [
3428 "blah.cpp",
3429 ],
3430 target: {
3431 android: {
3432 srcs: ["bar.sysprop"],
3433 },
3434 },
3435 min_sdk_version: "5",
3436}`,
3437 ExpectedBazelTargets: []string{
3438 MakeBazelTargetNoRestrictions("sysprop_library", "foo_sysprop_library", AttrNameToString{
3439 "srcs": `select({
3440 "//build/bazel/platforms/os:android": ["bar.sysprop"],
3441 "//conditions:default": [],
3442 })`,
3443 }),
3444 MakeBazelTargetNoRestrictions("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
3445 "dep": `":foo_sysprop_library"`,
3446 "min_sdk_version": `"5"`,
3447 }),
3448 MakeBazelTargetNoRestrictions("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
3449 "srcs": `["blah.cpp"]`,
3450 "local_includes": `["."]`,
3451 "min_sdk_version": `"5"`,
3452 "whole_archive_deps": `select({
3453 "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"],
3454 "//conditions:default": [],
3455 })`,
3456 }),
3457 MakeBazelTargetNoRestrictions("cc_library_shared", "foo", AttrNameToString{
3458 "srcs": `["blah.cpp"]`,
3459 "local_includes": `["."]`,
3460 "min_sdk_version": `"5"`,
3461 "whole_archive_deps": `select({
3462 "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"],
3463 "//conditions:default": [],
3464 })`,
3465 }),
3466 },
3467 })
3468}
Vinh Tran395a1e92022-09-16 18:27:29 -04003469
3470func TestCcLibraryWithAidlAndSharedLibs(t *testing.T) {
3471 runCcLibraryTestCase(t, Bp2buildTestCase{
3472 Description: "cc_aidl_library depends on shared libs from parent cc_library_static",
3473 ModuleTypeUnderTest: "cc_library",
3474 ModuleTypeUnderTestFactory: cc.LibraryFactory,
3475 Blueprint: `
3476cc_library_static {
3477 name: "foo",
3478 srcs: [
3479 "Foo.aidl",
3480 ],
3481 shared_libs: [
3482 "bar",
3483 "baz",
3484 ],
3485 export_shared_lib_headers: [
3486 "baz",
3487 ],
3488}` +
3489 simpleModuleDoNotConvertBp2build("cc_library", "bar") +
3490 simpleModuleDoNotConvertBp2build("cc_library", "baz"),
3491 ExpectedBazelTargets: []string{
3492 MakeBazelTarget("aidl_library", "foo_aidl_library", AttrNameToString{
3493 "srcs": `["Foo.aidl"]`,
3494 }),
3495 MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{
3496 "deps": `[":foo_aidl_library"]`,
3497 "implementation_dynamic_deps": `[
3498 ":baz",
3499 ":bar",
3500 ]`,
3501 }),
3502 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
3503 "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`,
3504 "dynamic_deps": `[":baz"]`,
3505 "implementation_dynamic_deps": `[":bar"]`,
3506 "local_includes": `["."]`,
3507 }),
3508 },
3509 })
3510}
Sam Delmericoc9b8fbd2022-10-25 15:47:17 -04003511
3512func TestCcLibraryWithTidy(t *testing.T) {
3513 runCcLibraryTestCase(t, Bp2buildTestCase{
3514 Description: "cc_library uses tidy properties",
3515 ModuleTypeUnderTest: "cc_library",
3516 ModuleTypeUnderTestFactory: cc.LibraryFactory,
3517 Blueprint: `
3518cc_library_static {
3519 name: "foo",
3520 srcs: ["foo.cpp"],
3521 tidy: true,
3522 tidy_checks: ["check1", "check2"],
3523 tidy_checks_as_errors: ["check1error", "check2error"],
3524 tidy_disabled_srcs: ["bar.cpp"],
Sam Delmerico4c902d62022-11-02 14:17:15 -04003525 tidy_timeout_srcs: ["baz.cpp"],
Sam Delmericoc9b8fbd2022-10-25 15:47:17 -04003526}`,
3527 ExpectedBazelTargets: []string{
3528 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
3529 "local_includes": `["."]`,
3530 "srcs": `["foo.cpp"]`,
3531 "tidy": `True`,
3532 "tidy_checks": `[
3533 "check1",
3534 "check2",
3535 ]`,
3536 "tidy_checks_as_errors": `[
3537 "check1error",
3538 "check2error",
3539 ]`,
3540 "tidy_disabled_srcs": `["bar.cpp"]`,
Sam Delmerico4c902d62022-11-02 14:17:15 -04003541 "tidy_timeout_srcs": `["baz.cpp"]`,
Sam Delmericoc9b8fbd2022-10-25 15:47:17 -04003542 }),
3543 },
3544 })
3545}