blob: 7b97b3906939a06a504dc2fc45d9b10e2f9e68cd [file] [log] [blame]
Rupert Shuttleworth095081c2021-03-25 09:06:03 +00001// Copyright 2021 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package bp2build
16
17import (
Cole Faust6b29f592022-08-09 09:50:56 -070018 "fmt"
19 "testing"
20
Rupert Shuttleworth095081c2021-03-25 09:06:03 +000021 "android/soong/android"
22 "android/soong/cc"
Chris Parsons484e50a2021-05-13 15:13:04 -040023 "android/soong/genrule"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +000024)
25
26const (
27 // See cc/testing.go for more context
28 soongCcLibraryStaticPreamble = `
29cc_defaults {
Liz Kammer8337ea42021-09-10 10:06:32 -040030 name: "linux_bionic_supported",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +000031}`
32)
33
34func TestCcLibraryStaticLoadStatement(t *testing.T) {
35 testCases := []struct {
36 bazelTargets BazelTargets
37 expectedLoadStatements string
38 }{
39 {
40 bazelTargets: BazelTargets{
41 BazelTarget{
42 name: "cc_library_static_target",
43 ruleClass: "cc_library_static",
44 // NOTE: No bzlLoadLocation for native rules
45 },
46 },
47 expectedLoadStatements: ``,
48 },
49 }
50
51 for _, testCase := range testCases {
52 actual := testCase.bazelTargets.LoadStatements()
53 expected := testCase.expectedLoadStatements
54 if actual != expected {
55 t.Fatalf("Expected load statements to be %s, got %s", expected, actual)
56 }
57 }
Rupert Shuttleworth095081c2021-03-25 09:06:03 +000058}
59
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +020060func registerCcLibraryStaticModuleTypes(ctx android.RegistrationContext) {
61 cc.RegisterCCBuildComponents(ctx)
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +020062 ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
63 ctx.RegisterModuleType("genrule", genrule.GenRuleFactory)
Chris Parsons51f8c392021-08-03 21:01:05 -040064 // Required for system_shared_libs dependencies.
65 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +020066}
67
Sam Delmerico3177a6e2022-06-21 19:28:33 +000068func runCcLibraryStaticTestCase(t *testing.T, tc Bp2buildTestCase) {
Liz Kammere4982e82021-05-25 10:39:35 -040069 t.Helper()
Liz Kammer78cfdaa2021-11-08 12:56:31 -050070
Sam Delmerico3177a6e2022-06-21 19:28:33 +000071 (&tc).ModuleTypeUnderTest = "cc_library_static"
72 (&tc).ModuleTypeUnderTestFactory = cc.LibraryStaticFactory
73 RunBp2BuildTestCase(t, registerCcLibraryStaticModuleTypes, tc)
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +020074}
75
76func TestCcLibraryStaticSimple(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000077 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
78 Description: "cc_library_static test",
79 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +020080 // NOTE: include_dir headers *should not* appear in Bazel hdrs later (?)
81 "include_dir_1/include_dir_1_a.h": "",
82 "include_dir_1/include_dir_1_b.h": "",
83 "include_dir_2/include_dir_2_a.h": "",
84 "include_dir_2/include_dir_2_b.h": "",
85 // NOTE: local_include_dir headers *should not* appear in Bazel hdrs later (?)
86 "local_include_dir_1/local_include_dir_1_a.h": "",
87 "local_include_dir_1/local_include_dir_1_b.h": "",
88 "local_include_dir_2/local_include_dir_2_a.h": "",
89 "local_include_dir_2/local_include_dir_2_b.h": "",
90 // NOTE: export_include_dir headers *should* appear in Bazel hdrs later
91 "export_include_dir_1/export_include_dir_1_a.h": "",
92 "export_include_dir_1/export_include_dir_1_b.h": "",
93 "export_include_dir_2/export_include_dir_2_a.h": "",
94 "export_include_dir_2/export_include_dir_2_b.h": "",
95 // NOTE: Soong implicitly includes headers in the current directory
96 "implicit_include_1.h": "",
97 "implicit_include_2.h": "",
98 },
Chris Parsonscd209032023-09-19 01:12:48 +000099 StubbedBuildDefinitions: []string{"header_lib_1", "header_lib_2",
100 "static_lib_1", "static_lib_2", "whole_static_lib_1", "whole_static_lib_2"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000101 Blueprint: soongCcLibraryStaticPreamble + `
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000102cc_library_headers {
103 name: "header_lib_1",
104 export_include_dirs: ["header_lib_1"],
105}
106
107cc_library_headers {
108 name: "header_lib_2",
109 export_include_dirs: ["header_lib_2"],
110}
111
112cc_library_static {
113 name: "static_lib_1",
114 srcs: ["static_lib_1.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000115}
116
117cc_library_static {
118 name: "static_lib_2",
119 srcs: ["static_lib_2.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000120}
121
122cc_library_static {
123 name: "whole_static_lib_1",
124 srcs: ["whole_static_lib_1.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000125}
126
127cc_library_static {
128 name: "whole_static_lib_2",
129 srcs: ["whole_static_lib_2.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000130}
131
132cc_library_static {
133 name: "foo_static",
134 srcs: [
135 "foo_static1.cc",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000136 "foo_static2.cc",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000137 ],
138 cflags: [
139 "-Dflag1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000140 "-Dflag2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000141 ],
142 static_libs: [
143 "static_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000144 "static_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000145 ],
146 whole_static_libs: [
147 "whole_static_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000148 "whole_static_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000149 ],
150 include_dirs: [
Jingwen Chened9c17d2021-04-13 07:14:55 +0000151 "include_dir_1",
152 "include_dir_2",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000153 ],
154 local_include_dirs: [
155 "local_include_dir_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000156 "local_include_dir_2",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000157 ],
158 export_include_dirs: [
Chris Parsonsd6358772021-05-18 18:35:24 -0400159 "export_include_dir_1",
160 "export_include_dir_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000161 ],
162 header_libs: [
163 "header_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000164 "header_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000165 ],
Yu Liufc603162022-03-01 15:44:08 -0800166 sdk_version: "current",
167 min_sdk_version: "29",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000168
169 // TODO: Also support export_header_lib_headers
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000170}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000171 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000172 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500173 "absolute_includes": `[
Liz Kammer35687bc2021-09-10 10:07:07 -0400174 "include_dir_1",
175 "include_dir_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500176 ]`,
177 "copts": `[
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000178 "-Dflag1",
179 "-Dflag2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500180 ]`,
181 "export_includes": `[
Liz Kammer5fad5012021-09-09 14:08:21 -0400182 "export_include_dir_1",
183 "export_include_dir_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500184 ]`,
185 "implementation_deps": `[
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000186 ":header_lib_1",
187 ":header_lib_2",
188 ":static_lib_1",
189 ":static_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500190 ]`,
191 "local_includes": `[
Liz Kammer35687bc2021-09-10 10:07:07 -0400192 "local_include_dir_1",
193 "local_include_dir_2",
194 ".",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500195 ]`,
196 "srcs": `[
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000197 "foo_static1.cc",
198 "foo_static2.cc",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500199 ]`,
200 "whole_archive_deps": `[
Chris Parsons08648312021-05-06 16:23:19 -0400201 ":whole_static_lib_1",
202 ":whole_static_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500203 ]`,
Liz Kammer7128d382022-05-12 11:42:33 -0400204 "sdk_version": `"current"`,
205 "min_sdk_version": `"29"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500206 }),
207 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200208 })
209}
210
211func TestCcLibraryStaticSubpackage(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000212 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
213 Description: "cc_library_static subpackage test",
214 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200215 // subpackage with subdirectory
216 "subpackage/Android.bp": "",
217 "subpackage/subpackage_header.h": "",
218 "subpackage/subdirectory/subdirectory_header.h": "",
219 // subsubpackage with subdirectory
220 "subpackage/subsubpackage/Android.bp": "",
221 "subpackage/subsubpackage/subsubpackage_header.h": "",
222 "subpackage/subsubpackage/subdirectory/subdirectory_header.h": "",
223 // subsubsubpackage with subdirectory
224 "subpackage/subsubpackage/subsubsubpackage/Android.bp": "",
225 "subpackage/subsubpackage/subsubsubpackage/subsubsubpackage_header.h": "",
226 "subpackage/subsubpackage/subsubsubpackage/subdirectory/subdirectory_header.h": "",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000227 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000228 Blueprint: soongCcLibraryStaticPreamble + `
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400229cc_library_static {
230 name: "foo_static",
Liz Kammer35687bc2021-09-10 10:07:07 -0400231 srcs: [],
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400232 include_dirs: [
Liz Kammer35687bc2021-09-10 10:07:07 -0400233 "subpackage",
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400234 ],
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400235}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000236 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000237 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500238 "absolute_includes": `["subpackage"]`,
239 "local_includes": `["."]`,
240 }),
241 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200242 })
243}
244
245func TestCcLibraryStaticExportIncludeDir(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000246 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
247 Description: "cc_library_static export include dir",
248 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200249 // subpackage with subdirectory
250 "subpackage/Android.bp": "",
251 "subpackage/subpackage_header.h": "",
252 "subpackage/subdirectory/subdirectory_header.h": "",
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400253 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000254 Blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000255cc_library_static {
256 name: "foo_static",
257 export_include_dirs: ["subpackage"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400258 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000259}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000260 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000261 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500262 "export_includes": `["subpackage"]`,
263 }),
264 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200265 })
266}
267
268func TestCcLibraryStaticExportSystemIncludeDir(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000269 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
270 Description: "cc_library_static export system include dir",
271 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200272 // subpackage with subdirectory
273 "subpackage/Android.bp": "",
274 "subpackage/subpackage_header.h": "",
275 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000276 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000277 Blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000278cc_library_static {
279 name: "foo_static",
280 export_system_include_dirs: ["subpackage"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400281 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000282}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000283 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000284 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500285 "export_system_includes": `["subpackage"]`,
286 }),
287 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200288 })
289}
290
291func TestCcLibraryStaticManyIncludeDirs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000292 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
293 Description: "cc_library_static include_dirs, local_include_dirs, export_include_dirs (b/183742505)",
294 Dir: "subpackage",
295 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200296 // subpackage with subdirectory
297 "subpackage/Android.bp": `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000298cc_library_static {
299 name: "foo_static",
300 // include_dirs are workspace/root relative
301 include_dirs: [
302 "subpackage/subsubpackage",
303 "subpackage2",
304 "subpackage3/subsubpackage"
305 ],
306 local_include_dirs: ["subsubpackage2"], // module dir relative
307 export_include_dirs: ["./exported_subsubpackage"], // module dir relative
308 include_build_directory: true,
309 bazel_module: { bp2build_available: true },
310}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200311 "subpackage/subsubpackage/header.h": "",
312 "subpackage/subsubpackage2/header.h": "",
313 "subpackage/exported_subsubpackage/header.h": "",
314 "subpackage2/header.h": "",
315 "subpackage3/subsubpackage/header.h": "",
316 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000317 Blueprint: soongCcLibraryStaticPreamble,
318 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000319 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500320 "absolute_includes": `[
Liz Kammer35687bc2021-09-10 10:07:07 -0400321 "subpackage/subsubpackage",
322 "subpackage2",
323 "subpackage3/subsubpackage",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500324 ]`,
325 "export_includes": `["./exported_subsubpackage"]`,
326 "local_includes": `[
Liz Kammer35687bc2021-09-10 10:07:07 -0400327 "subsubpackage2",
328 ".",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500329 ]`,
330 })},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200331 })
332}
333
334func TestCcLibraryStaticIncludeBuildDirectoryDisabled(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000335 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
336 Description: "cc_library_static include_build_directory disabled",
337 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200338 // subpackage with subdirectory
339 "subpackage/Android.bp": "",
340 "subpackage/subpackage_header.h": "",
341 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000342 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000343 Blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000344cc_library_static {
345 name: "foo_static",
346 include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended
347 local_include_dirs: ["subpackage2"],
348 include_build_directory: false,
349}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000350 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000351 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500352 "absolute_includes": `["subpackage"]`,
353 "local_includes": `["subpackage2"]`,
354 }),
355 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200356 })
357}
358
359func TestCcLibraryStaticIncludeBuildDirectoryEnabled(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000360 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
361 Description: "cc_library_static include_build_directory enabled",
362 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200363 // subpackage with subdirectory
364 "subpackage/Android.bp": "",
365 "subpackage/subpackage_header.h": "",
366 "subpackage2/Android.bp": "",
367 "subpackage2/subpackage2_header.h": "",
368 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000369 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000370 Blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000371cc_library_static {
372 name: "foo_static",
373 include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended
374 local_include_dirs: ["subpackage2"],
375 include_build_directory: true,
376}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000377 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000378 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500379 "absolute_includes": `["subpackage"]`,
380 "local_includes": `[
Liz Kammer35687bc2021-09-10 10:07:07 -0400381 "subpackage2",
382 ".",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500383 ]`,
384 }),
385 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200386 })
387}
388
389func TestCcLibraryStaticArchSpecificStaticLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000390 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +0000391 Description: "cc_library_static arch-specific static_libs",
392 Filesystem: map[string]string{},
393 StubbedBuildDefinitions: []string{"static_dep", "static_dep2"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000394 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -0400395cc_library_static {
396 name: "static_dep",
Liz Kammer8337ea42021-09-10 10:06:32 -0400397}
398cc_library_static {
399 name: "static_dep2",
Liz Kammer8337ea42021-09-10 10:06:32 -0400400}
Jingwen Chened9c17d2021-04-13 07:14:55 +0000401cc_library_static {
402 name: "foo_static",
403 arch: { arm64: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } },
Liz Kammer8337ea42021-09-10 10:06:32 -0400404 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000405}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000406 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000407 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500408 "implementation_deps": `select({
Chris Parsons08648312021-05-06 16:23:19 -0400409 "//build/bazel/platforms/arch:arm64": [":static_dep"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000410 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500411 })`,
412 "whole_archive_deps": `select({
Chris Parsons08648312021-05-06 16:23:19 -0400413 "//build/bazel/platforms/arch:arm64": [":static_dep2"],
414 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500415 })`,
416 }),
417 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200418 })
419}
420
421func TestCcLibraryStaticOsSpecificStaticLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000422 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +0000423 Description: "cc_library_static os-specific static_libs",
424 Filesystem: map[string]string{},
425 StubbedBuildDefinitions: []string{"static_dep", "static_dep2"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000426 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -0400427cc_library_static {
428 name: "static_dep",
Liz Kammer8337ea42021-09-10 10:06:32 -0400429}
430cc_library_static {
431 name: "static_dep2",
Liz Kammer8337ea42021-09-10 10:06:32 -0400432}
Jingwen Chened9c17d2021-04-13 07:14:55 +0000433cc_library_static {
434 name: "foo_static",
435 target: { android: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } },
Liz Kammer8337ea42021-09-10 10:06:32 -0400436 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000437}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000438 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000439 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500440 "implementation_deps": `select({
Chris Parsons08648312021-05-06 16:23:19 -0400441 "//build/bazel/platforms/os:android": [":static_dep"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000442 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500443 })`,
444 "whole_archive_deps": `select({
Chris Parsons08648312021-05-06 16:23:19 -0400445 "//build/bazel/platforms/os:android": [":static_dep2"],
446 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500447 })`,
448 }),
449 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200450 })
451}
452
453func TestCcLibraryStaticBaseArchOsSpecificStaticLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000454 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
455 Description: "cc_library_static base, arch and os-specific static_libs",
456 Filesystem: map[string]string{},
Chris Parsonscd209032023-09-19 01:12:48 +0000457 StubbedBuildDefinitions: []string{"static_dep", "static_dep2", "static_dep3",
458 "static_dep4"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000459 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -0400460cc_library_static {
461 name: "static_dep",
Liz Kammer8337ea42021-09-10 10:06:32 -0400462}
463cc_library_static {
464 name: "static_dep2",
Liz Kammer8337ea42021-09-10 10:06:32 -0400465}
466cc_library_static {
467 name: "static_dep3",
Liz Kammer8337ea42021-09-10 10:06:32 -0400468}
469cc_library_static {
470 name: "static_dep4",
Liz Kammer8337ea42021-09-10 10:06:32 -0400471}
Jingwen Chened9c17d2021-04-13 07:14:55 +0000472cc_library_static {
473 name: "foo_static",
474 static_libs: ["static_dep"],
475 whole_static_libs: ["static_dep2"],
476 target: { android: { static_libs: ["static_dep3"] } },
477 arch: { arm64: { static_libs: ["static_dep4"] } },
Liz Kammer8337ea42021-09-10 10:06:32 -0400478 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000479}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000480 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000481 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500482 "implementation_deps": `[":static_dep"] + select({
Jingwen Chened9c17d2021-04-13 07:14:55 +0000483 "//build/bazel/platforms/arch:arm64": [":static_dep4"],
484 "//conditions:default": [],
485 }) + select({
486 "//build/bazel/platforms/os:android": [":static_dep3"],
487 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500488 })`,
489 "whole_archive_deps": `[":static_dep2"]`,
490 }),
491 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200492 })
493}
494
495func TestCcLibraryStaticSimpleExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000496 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
497 Description: "cc_library_static simple exclude_srcs",
498 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200499 "common.c": "",
500 "foo-a.c": "",
501 "foo-excluded.c": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000502 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000503 Blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000504cc_library_static {
505 name: "foo_static",
506 srcs: ["common.c", "foo-*.c"],
507 exclude_srcs: ["foo-excluded.c"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400508 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000509}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000510 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000511 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500512 "srcs_c": `[
Jingwen Chene32e9e02021-04-23 09:17:24 +0000513 "common.c",
514 "foo-a.c",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500515 ]`,
516 }),
517 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200518 })
519}
520
521func TestCcLibraryStaticOneArchSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000522 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
523 Description: "cc_library_static one arch specific srcs",
524 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200525 "common.c": "",
526 "foo-arm.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000527 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000528 Blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000529cc_library_static {
530 name: "foo_static",
531 srcs: ["common.c"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400532 arch: { arm: { srcs: ["foo-arm.c"] } },
533 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000534}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000535 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000536 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500537 "srcs_c": `["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000538 "//build/bazel/platforms/arch:arm": ["foo-arm.c"],
539 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500540 })`,
541 }),
542 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200543 })
544}
545
546func TestCcLibraryStaticOneArchSrcsExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000547 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
548 Description: "cc_library_static one arch specific srcs and exclude_srcs",
549 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200550 "common.c": "",
551 "for-arm.c": "",
552 "not-for-arm.c": "",
553 "not-for-anything.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000554 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000555 Blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000556cc_library_static {
557 name: "foo_static",
558 srcs: ["common.c", "not-for-*.c"],
559 exclude_srcs: ["not-for-anything.c"],
560 arch: {
561 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
562 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400563 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000564}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000565 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000566 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500567 "srcs_c": `["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000568 "//build/bazel/platforms/arch:arm": ["for-arm.c"],
569 "//conditions:default": ["not-for-arm.c"],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500570 })`,
571 }),
572 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200573 })
574}
575
576func TestCcLibraryStaticTwoArchExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000577 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
578 Description: "cc_library_static arch specific exclude_srcs for 2 architectures",
579 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200580 "common.c": "",
581 "for-arm.c": "",
582 "for-x86.c": "",
583 "not-for-arm.c": "",
584 "not-for-x86.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000585 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000586 Blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000587cc_library_static {
588 name: "foo_static",
589 srcs: ["common.c", "not-for-*.c"],
590 exclude_srcs: ["not-for-everything.c"],
591 arch: {
592 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
593 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
594 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400595 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000596} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000597 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000598 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500599 "srcs_c": `["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000600 "//build/bazel/platforms/arch:arm": [
Jingwen Chene32e9e02021-04-23 09:17:24 +0000601 "not-for-x86.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400602 "for-arm.c",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000603 ],
604 "//build/bazel/platforms/arch:x86": [
Jingwen Chene32e9e02021-04-23 09:17:24 +0000605 "not-for-arm.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400606 "for-x86.c",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000607 ],
608 "//conditions:default": [
609 "not-for-arm.c",
610 "not-for-x86.c",
611 ],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500612 })`,
613 }),
614 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200615 })
616}
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500617
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200618func TestCcLibraryStaticFourArchExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000619 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
620 Description: "cc_library_static arch specific exclude_srcs for 4 architectures",
621 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200622 "common.c": "",
623 "for-arm.c": "",
624 "for-arm64.c": "",
625 "for-x86.c": "",
626 "for-x86_64.c": "",
627 "not-for-arm.c": "",
628 "not-for-arm64.c": "",
629 "not-for-x86.c": "",
630 "not-for-x86_64.c": "",
631 "not-for-everything.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000632 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000633 Blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000634cc_library_static {
635 name: "foo_static",
636 srcs: ["common.c", "not-for-*.c"],
637 exclude_srcs: ["not-for-everything.c"],
638 arch: {
639 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
640 arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] },
641 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
642 x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] },
Liz Kammer8337ea42021-09-10 10:06:32 -0400643 },
644 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000645} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000646 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000647 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500648 "srcs_c": `["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000649 "//build/bazel/platforms/arch:arm": [
Jingwen Chene32e9e02021-04-23 09:17:24 +0000650 "not-for-arm64.c",
651 "not-for-x86.c",
652 "not-for-x86_64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400653 "for-arm.c",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000654 ],
655 "//build/bazel/platforms/arch:arm64": [
Jingwen Chene32e9e02021-04-23 09:17:24 +0000656 "not-for-arm.c",
657 "not-for-x86.c",
658 "not-for-x86_64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400659 "for-arm64.c",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000660 ],
661 "//build/bazel/platforms/arch:x86": [
Jingwen Chene32e9e02021-04-23 09:17:24 +0000662 "not-for-arm.c",
663 "not-for-arm64.c",
664 "not-for-x86_64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400665 "for-x86.c",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000666 ],
667 "//build/bazel/platforms/arch:x86_64": [
Jingwen Chene32e9e02021-04-23 09:17:24 +0000668 "not-for-arm.c",
669 "not-for-arm64.c",
670 "not-for-x86.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400671 "for-x86_64.c",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000672 ],
673 "//conditions:default": [
674 "not-for-arm.c",
675 "not-for-arm64.c",
676 "not-for-x86.c",
677 "not-for-x86_64.c",
678 ],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500679 })`,
680 }),
681 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200682 })
683}
684
Liz Kammer2b07ec72021-05-26 15:08:27 -0400685func TestCcLibraryStaticOneArchEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000686 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
687 Description: "cc_library_static one arch empty",
688 Filesystem: map[string]string{
Liz Kammer2b07ec72021-05-26 15:08:27 -0400689 "common.cc": "",
690 "foo-no-arm.cc": "",
691 "foo-excluded.cc": "",
692 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000693 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer2b07ec72021-05-26 15:08:27 -0400694cc_library_static {
695 name: "foo_static",
696 srcs: ["common.cc", "foo-*.cc"],
697 exclude_srcs: ["foo-excluded.cc"],
698 arch: {
699 arm: { exclude_srcs: ["foo-no-arm.cc"] },
700 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400701 include_build_directory: false,
Liz Kammer2b07ec72021-05-26 15:08:27 -0400702}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000703 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000704 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500705 "srcs": `["common.cc"] + select({
Liz Kammer2b07ec72021-05-26 15:08:27 -0400706 "//build/bazel/platforms/arch:arm": [],
707 "//conditions:default": ["foo-no-arm.cc"],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500708 })`,
709 }),
710 },
Liz Kammer2b07ec72021-05-26 15:08:27 -0400711 })
712}
713
714func TestCcLibraryStaticOneArchEmptyOtherSet(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000715 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
716 Description: "cc_library_static one arch empty other set",
717 Filesystem: map[string]string{
Liz Kammer2b07ec72021-05-26 15:08:27 -0400718 "common.cc": "",
719 "foo-no-arm.cc": "",
720 "x86-only.cc": "",
721 "foo-excluded.cc": "",
722 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000723 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer2b07ec72021-05-26 15:08:27 -0400724cc_library_static {
725 name: "foo_static",
726 srcs: ["common.cc", "foo-*.cc"],
727 exclude_srcs: ["foo-excluded.cc"],
728 arch: {
729 arm: { exclude_srcs: ["foo-no-arm.cc"] },
730 x86: { srcs: ["x86-only.cc"] },
731 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400732 include_build_directory: false,
Liz Kammer2b07ec72021-05-26 15:08:27 -0400733}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000734 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000735 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500736 "srcs": `["common.cc"] + select({
Liz Kammer2b07ec72021-05-26 15:08:27 -0400737 "//build/bazel/platforms/arch:arm": [],
738 "//build/bazel/platforms/arch:x86": [
739 "foo-no-arm.cc",
740 "x86-only.cc",
741 ],
742 "//conditions:default": ["foo-no-arm.cc"],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500743 })`,
744 }),
745 },
Liz Kammer2b07ec72021-05-26 15:08:27 -0400746 })
747}
748
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200749func TestCcLibraryStaticMultipleDepSameName(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000750 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +0000751 Description: "cc_library_static multiple dep same name panic",
752 Filesystem: map[string]string{},
753 StubbedBuildDefinitions: []string{"static_dep"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000754 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -0400755cc_library_static {
756 name: "static_dep",
Liz Kammer8337ea42021-09-10 10:06:32 -0400757}
Liz Kammer2b50ce62021-04-26 15:47:28 -0400758cc_library_static {
759 name: "foo_static",
Chris Parsons08648312021-05-06 16:23:19 -0400760 static_libs: ["static_dep", "static_dep"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400761 include_build_directory: false,
Liz Kammer2b50ce62021-04-26 15:47:28 -0400762}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000763 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000764 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500765 "implementation_deps": `[":static_dep"]`,
766 }),
767 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200768 })
769}
770
771func TestCcLibraryStaticOneMultilibSrcsExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000772 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
773 Description: "cc_library_static 1 multilib srcs and exclude_srcs",
774 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200775 "common.c": "",
776 "for-lib32.c": "",
777 "not-for-lib32.c": "",
Liz Kammer2b50ce62021-04-26 15:47:28 -0400778 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000779 Blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -0400780cc_library_static {
781 name: "foo_static",
782 srcs: ["common.c", "not-for-*.c"],
783 multilib: {
784 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
785 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400786 include_build_directory: false,
Chris Parsonsc424b762021-04-29 18:06:50 -0400787} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000788 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000789 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500790 "srcs_c": `["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -0400791 "//build/bazel/platforms/arch:arm": ["for-lib32.c"],
792 "//build/bazel/platforms/arch:x86": ["for-lib32.c"],
793 "//conditions:default": ["not-for-lib32.c"],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500794 })`,
795 }),
796 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200797 })
798}
799
800func TestCcLibraryStaticTwoMultilibSrcsExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000801 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
802 Description: "cc_library_static 2 multilib srcs and exclude_srcs",
803 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200804 "common.c": "",
805 "for-lib32.c": "",
806 "for-lib64.c": "",
807 "not-for-lib32.c": "",
808 "not-for-lib64.c": "",
Chris Parsonsc424b762021-04-29 18:06:50 -0400809 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000810 Blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -0400811cc_library_static {
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500812 name: "foo_static",
Chris Parsonsc424b762021-04-29 18:06:50 -0400813 srcs: ["common.c", "not-for-*.c"],
814 multilib: {
815 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
816 lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] },
817 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400818 include_build_directory: false,
Chris Parsonsc424b762021-04-29 18:06:50 -0400819} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000820 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000821 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500822 "srcs_c": `["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -0400823 "//build/bazel/platforms/arch:arm": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400824 "not-for-lib64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400825 "for-lib32.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400826 ],
827 "//build/bazel/platforms/arch:arm64": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400828 "not-for-lib32.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400829 "for-lib64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400830 ],
Colin Crossf05b0d32022-07-14 18:10:34 -0700831 "//build/bazel/platforms/arch:riscv64": [
832 "not-for-lib32.c",
833 "for-lib64.c",
834 ],
Chris Parsonsc424b762021-04-29 18:06:50 -0400835 "//build/bazel/platforms/arch:x86": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400836 "not-for-lib64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400837 "for-lib32.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400838 ],
839 "//build/bazel/platforms/arch:x86_64": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400840 "not-for-lib32.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400841 "for-lib64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400842 ],
843 "//conditions:default": [
844 "not-for-lib32.c",
845 "not-for-lib64.c",
846 ],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500847 })`,
848 }),
849 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200850 })
851}
852
853func TestCcLibrarySTaticArchMultilibSrcsExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000854 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
855 Description: "cc_library_static arch and multilib srcs and exclude_srcs",
856 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200857 "common.c": "",
858 "for-arm.c": "",
859 "for-arm64.c": "",
860 "for-x86.c": "",
861 "for-x86_64.c": "",
862 "for-lib32.c": "",
863 "for-lib64.c": "",
864 "not-for-arm.c": "",
865 "not-for-arm64.c": "",
Colin Crossf05b0d32022-07-14 18:10:34 -0700866 "not-for-riscv64.c": "",
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200867 "not-for-x86.c": "",
868 "not-for-x86_64.c": "",
869 "not-for-lib32.c": "",
870 "not-for-lib64.c": "",
871 "not-for-everything.c": "",
Chris Parsonsc424b762021-04-29 18:06:50 -0400872 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000873 Blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -0400874cc_library_static {
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500875 name: "foo_static",
Chris Parsonsc424b762021-04-29 18:06:50 -0400876 srcs: ["common.c", "not-for-*.c"],
877 exclude_srcs: ["not-for-everything.c"],
878 arch: {
879 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
880 arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] },
Colin Crossf05b0d32022-07-14 18:10:34 -0700881 riscv64: { srcs: ["for-riscv64.c"], exclude_srcs: ["not-for-riscv64.c"] },
Chris Parsonsc424b762021-04-29 18:06:50 -0400882 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
883 x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] },
884 },
885 multilib: {
886 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
887 lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] },
888 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400889 include_build_directory: false,
Chris Parsonsc424b762021-04-29 18:06:50 -0400890}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000891 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000892 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500893 "srcs_c": `["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -0400894 "//build/bazel/platforms/arch:arm": [
Liz Kammer9bad9d62021-10-11 15:40:35 -0400895 "not-for-arm64.c",
896 "not-for-lib64.c",
Colin Crossf05b0d32022-07-14 18:10:34 -0700897 "not-for-riscv64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400898 "not-for-x86.c",
899 "not-for-x86_64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400900 "for-arm.c",
901 "for-lib32.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400902 ],
903 "//build/bazel/platforms/arch:arm64": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400904 "not-for-arm.c",
905 "not-for-lib32.c",
Colin Crossf05b0d32022-07-14 18:10:34 -0700906 "not-for-riscv64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400907 "not-for-x86.c",
908 "not-for-x86_64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400909 "for-arm64.c",
910 "for-lib64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400911 ],
Colin Crossf05b0d32022-07-14 18:10:34 -0700912 "//build/bazel/platforms/arch:riscv64": [
913 "not-for-arm.c",
914 "not-for-arm64.c",
915 "not-for-lib32.c",
916 "not-for-x86.c",
917 "not-for-x86_64.c",
918 "for-riscv64.c",
919 "for-lib64.c",
920 ],
Chris Parsonsc424b762021-04-29 18:06:50 -0400921 "//build/bazel/platforms/arch:x86": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400922 "not-for-arm.c",
923 "not-for-arm64.c",
924 "not-for-lib64.c",
Colin Crossf05b0d32022-07-14 18:10:34 -0700925 "not-for-riscv64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400926 "not-for-x86_64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400927 "for-x86.c",
928 "for-lib32.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400929 ],
930 "//build/bazel/platforms/arch:x86_64": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400931 "not-for-arm.c",
932 "not-for-arm64.c",
933 "not-for-lib32.c",
Colin Crossf05b0d32022-07-14 18:10:34 -0700934 "not-for-riscv64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400935 "not-for-x86.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400936 "for-x86_64.c",
937 "for-lib64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400938 ],
939 "//conditions:default": [
940 "not-for-arm.c",
941 "not-for-arm64.c",
942 "not-for-lib32.c",
943 "not-for-lib64.c",
Colin Crossf05b0d32022-07-14 18:10:34 -0700944 "not-for-riscv64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400945 "not-for-x86.c",
946 "not-for-x86_64.c",
947 ],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500948 })`,
949 }),
950 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200951 })
952}
953
Liz Kammerae3994e2021-10-19 09:45:48 -0400954func TestCcLibraryStaticGeneratedHeadersAllPartitions(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000955 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +0000956 StubbedBuildDefinitions: []string{"generated_hdr", "export_generated_hdr"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000957 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammerae3994e2021-10-19 09:45:48 -0400958genrule {
959 name: "generated_hdr",
960 cmd: "nothing to see here",
961}
962
Liz Kammere6583482021-10-19 13:56:10 -0400963genrule {
964 name: "export_generated_hdr",
965 cmd: "nothing to see here",
966}
967
Liz Kammerae3994e2021-10-19 09:45:48 -0400968cc_library_static {
969 name: "foo_static",
970 srcs: ["cpp_src.cpp", "as_src.S", "c_src.c"],
Liz Kammere6583482021-10-19 13:56:10 -0400971 generated_headers: ["generated_hdr", "export_generated_hdr"],
972 export_generated_headers: ["export_generated_hdr"],
Liz Kammerae3994e2021-10-19 09:45:48 -0400973 include_build_directory: false,
974}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000975 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000976 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer1263d9b2021-12-10 14:28:20 -0500977 "export_includes": `["."]`,
978 "local_includes": `["."]`,
979 "hdrs": `[":export_generated_hdr"]`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500980 "srcs": `[
Liz Kammerae3994e2021-10-19 09:45:48 -0400981 "cpp_src.cpp",
982 ":generated_hdr",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500983 ]`,
984 "srcs_as": `[
Liz Kammerae3994e2021-10-19 09:45:48 -0400985 "as_src.S",
986 ":generated_hdr",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500987 ]`,
988 "srcs_c": `[
Liz Kammerae3994e2021-10-19 09:45:48 -0400989 "c_src.c",
990 ":generated_hdr",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500991 ]`,
992 }),
993 },
Liz Kammerae3994e2021-10-19 09:45:48 -0400994 })
995}
996
Liz Kammer0db0e342023-07-18 11:39:30 -0400997func TestCcLibraryStaticGeneratedHeadersMultipleExports(t *testing.T) {
998 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +0000999 StubbedBuildDefinitions: []string{"generated_hdr", "export_generated_hdr"},
Liz Kammer0db0e342023-07-18 11:39:30 -04001000 Blueprint: soongCcLibraryStaticPreamble + `
1001genrule {
1002 name: "generated_hdr",
1003 cmd: "nothing to see here",
1004 export_include_dirs: ["foo", "bar"],
Liz Kammer0db0e342023-07-18 11:39:30 -04001005}
1006
1007genrule {
1008 name: "export_generated_hdr",
1009 cmd: "nothing to see here",
1010 export_include_dirs: ["a", "b"],
Liz Kammer0db0e342023-07-18 11:39:30 -04001011}
1012
1013cc_library_static {
1014 name: "foo_static",
1015 generated_headers: ["generated_hdr", "export_generated_hdr"],
1016 export_generated_headers: ["export_generated_hdr"],
1017 include_build_directory: false,
1018}`,
1019 ExpectedBazelTargets: []string{
1020 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
1021 "deps": `[":export_generated_hdr__header_library"]`,
1022 "implementation_deps": `[":generated_hdr__header_library"]`,
1023 }),
1024 },
1025 })
1026}
1027
Zi Wang9f609db2023-01-04 11:06:54 -08001028// generated_headers has "variant_prepend" tag. In bp2build output,
1029// variant info(select) should go before general info.
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001030func TestCcLibraryStaticArchSrcsExcludeSrcsGeneratedFiles(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001031 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1032 Description: "cc_library_static arch srcs/exclude_srcs with generated files",
Chris Parsonscd209032023-09-19 01:12:48 +00001033 StubbedBuildDefinitions: []string{"//dep:generated_src_other_pkg", "//dep:generated_hdr_other_pkg",
1034 "//dep:generated_src_other_pkg_x86", "//dep:generated_hdr_other_pkg_x86", "//dep:generated_hdr_other_pkg_android",
1035 "generated_src", "generated_src_not_x86", "generated_src_android", "generated_hdr",
1036 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001037 Filesystem: map[string]string{
Chris Parsons990c4f42021-05-25 12:10:58 -04001038 "common.cpp": "",
1039 "for-x86.cpp": "",
1040 "not-for-x86.cpp": "",
1041 "not-for-everything.cpp": "",
Chris Parsonscd209032023-09-19 01:12:48 +00001042 "dep/Android.bp": simpleModule("genrule", "generated_src_other_pkg") +
1043 simpleModule("genrule", "generated_hdr_other_pkg") +
1044 simpleModule("genrule", "generated_src_other_pkg_x86") +
1045 simpleModule("genrule", "generated_hdr_other_pkg_x86") +
1046 simpleModule("genrule", "generated_hdr_other_pkg_android"),
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001047 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001048 Blueprint: soongCcLibraryStaticPreamble +
Chris Parsonscd209032023-09-19 01:12:48 +00001049 simpleModule("genrule", "generated_src") +
1050 simpleModule("genrule", "generated_src_not_x86") +
1051 simpleModule("genrule", "generated_src_android") +
1052 simpleModule("genrule", "generated_hdr") + `
Chris Parsons484e50a2021-05-13 15:13:04 -04001053cc_library_static {
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001054 name: "foo_static",
Liz Kammer222bdcf2021-10-11 14:15:51 -04001055 srcs: ["common.cpp", "not-for-*.cpp"],
1056 exclude_srcs: ["not-for-everything.cpp"],
1057 generated_sources: ["generated_src", "generated_src_other_pkg", "generated_src_not_x86"],
1058 generated_headers: ["generated_hdr", "generated_hdr_other_pkg"],
Liz Kammer1263d9b2021-12-10 14:28:20 -05001059 export_generated_headers: ["generated_hdr_other_pkg"],
Liz Kammer222bdcf2021-10-11 14:15:51 -04001060 arch: {
1061 x86: {
1062 srcs: ["for-x86.cpp"],
1063 exclude_srcs: ["not-for-x86.cpp"],
1064 generated_headers: ["generated_hdr_other_pkg_x86"],
1065 exclude_generated_sources: ["generated_src_not_x86"],
Liz Kammer1263d9b2021-12-10 14:28:20 -05001066 export_generated_headers: ["generated_hdr_other_pkg_x86"],
Liz Kammer222bdcf2021-10-11 14:15:51 -04001067 },
1068 },
1069 target: {
1070 android: {
1071 generated_sources: ["generated_src_android"],
1072 generated_headers: ["generated_hdr_other_pkg_android"],
Liz Kammer1263d9b2021-12-10 14:28:20 -05001073 export_generated_headers: ["generated_hdr_other_pkg_android"],
Liz Kammer222bdcf2021-10-11 14:15:51 -04001074 },
1075 },
1076
Liz Kammer8337ea42021-09-10 10:06:32 -04001077 include_build_directory: false,
Chris Parsons484e50a2021-05-13 15:13:04 -04001078}
1079`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001080 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001081 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001082 "srcs": `[
Chris Parsons990c4f42021-05-25 12:10:58 -04001083 "common.cpp",
Liz Kammer9bad9d62021-10-11 15:40:35 -04001084 ":generated_src",
1085 "//dep:generated_src_other_pkg",
Liz Kammerae3994e2021-10-19 09:45:48 -04001086 ":generated_hdr",
Chris Parsons484e50a2021-05-13 15:13:04 -04001087 ] + select({
Liz Kammer1263d9b2021-12-10 14:28:20 -05001088 "//build/bazel/platforms/arch:x86": ["for-x86.cpp"],
Liz Kammer222bdcf2021-10-11 14:15:51 -04001089 "//conditions:default": [
Liz Kammer222bdcf2021-10-11 14:15:51 -04001090 "not-for-x86.cpp",
Liz Kammer9bad9d62021-10-11 15:40:35 -04001091 ":generated_src_not_x86",
Liz Kammer222bdcf2021-10-11 14:15:51 -04001092 ],
1093 }) + select({
Liz Kammer1263d9b2021-12-10 14:28:20 -05001094 "//build/bazel/platforms/os:android": [":generated_src_android"],
Liz Kammer222bdcf2021-10-11 14:15:51 -04001095 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001096 })`,
Zi Wang9f609db2023-01-04 11:06:54 -08001097 "hdrs": `select({
Liz Kammer1263d9b2021-12-10 14:28:20 -05001098 "//build/bazel/platforms/os:android": ["//dep:generated_hdr_other_pkg_android"],
1099 "//conditions:default": [],
Zi Wang9f609db2023-01-04 11:06:54 -08001100 }) + select({
1101 "//build/bazel/platforms/arch:x86": ["//dep:generated_hdr_other_pkg_x86"],
1102 "//conditions:default": [],
1103 }) + ["//dep:generated_hdr_other_pkg"]`,
Liz Kammer1263d9b2021-12-10 14:28:20 -05001104 "local_includes": `["."]`,
1105 "export_absolute_includes": `["dep"]`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001106 }),
1107 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001108 })
Rupert Shuttleworth095081c2021-03-25 09:06:03 +00001109}
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001110
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001111func TestCcLibraryStaticGetTargetProperties(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001112 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001113
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001114 Description: "cc_library_static complex GetTargetProperties",
1115 Blueprint: soongCcLibraryStaticPreamble + `
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001116cc_library_static {
1117 name: "foo_static",
1118 target: {
1119 android: {
1120 srcs: ["android_src.c"],
1121 },
1122 android_arm: {
1123 srcs: ["android_arm_src.c"],
1124 },
1125 android_arm64: {
1126 srcs: ["android_arm64_src.c"],
1127 },
1128 android_x86: {
1129 srcs: ["android_x86_src.c"],
1130 },
1131 android_x86_64: {
1132 srcs: ["android_x86_64_src.c"],
1133 },
1134 linux_bionic_arm64: {
1135 srcs: ["linux_bionic_arm64_src.c"],
1136 },
1137 linux_bionic_x86_64: {
1138 srcs: ["linux_bionic_x86_64_src.c"],
1139 },
1140 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001141 include_build_directory: false,
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001142}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001143 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001144 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001145 "srcs_c": `select({
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001146 "//build/bazel/platforms/os:android": ["android_src.c"],
1147 "//conditions:default": [],
1148 }) + select({
Rupert Shuttleworthffd45822021-05-14 03:02:34 -04001149 "//build/bazel/platforms/os_arch:android_arm": ["android_arm_src.c"],
1150 "//build/bazel/platforms/os_arch:android_arm64": ["android_arm64_src.c"],
1151 "//build/bazel/platforms/os_arch:android_x86": ["android_x86_src.c"],
1152 "//build/bazel/platforms/os_arch:android_x86_64": ["android_x86_64_src.c"],
Rupert Shuttleworthffd45822021-05-14 03:02:34 -04001153 "//build/bazel/platforms/os_arch:linux_bionic_arm64": ["linux_bionic_arm64_src.c"],
1154 "//build/bazel/platforms/os_arch:linux_bionic_x86_64": ["linux_bionic_x86_64_src.c"],
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001155 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001156 })`,
1157 }),
1158 },
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001159 })
1160}
1161
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001162func TestCcLibraryStaticProductVariableSelects(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001163 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1164 Description: "cc_library_static product variable selects",
1165 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001166cc_library_static {
1167 name: "foo_static",
1168 srcs: ["common.c"],
1169 product_variables: {
1170 malloc_not_svelte: {
1171 cflags: ["-Wmalloc_not_svelte"],
1172 },
1173 malloc_zero_contents: {
1174 cflags: ["-Wmalloc_zero_contents"],
1175 },
1176 binder32bit: {
1177 cflags: ["-Wbinder32bit"],
1178 },
1179 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001180 include_build_directory: false,
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001181} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001182 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001183 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001184 "copts": `select({
Cole Faust87c0c332023-07-31 12:10:12 -07001185 "//build/bazel/product_config/config_settings:binder32bit": ["-Wbinder32bit"],
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001186 "//conditions:default": [],
1187 }) + select({
Cole Faust87c0c332023-07-31 12:10:12 -07001188 "//build/bazel/product_config/config_settings:malloc_not_svelte": ["-Wmalloc_not_svelte"],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001189 "//conditions:default": [],
1190 }) + select({
Cole Faust87c0c332023-07-31 12:10:12 -07001191 "//build/bazel/product_config/config_settings:malloc_zero_contents": ["-Wmalloc_zero_contents"],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001192 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001193 })`,
1194 "srcs_c": `["common.c"]`,
1195 }),
1196 },
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001197 })
1198}
1199
1200func TestCcLibraryStaticProductVariableArchSpecificSelects(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001201 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1202 Description: "cc_library_static arch-specific product variable selects",
1203 Filesystem: map[string]string{},
1204 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001205cc_library_static {
1206 name: "foo_static",
1207 srcs: ["common.c"],
1208 product_variables: {
1209 malloc_not_svelte: {
1210 cflags: ["-Wmalloc_not_svelte"],
1211 },
1212 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001213 arch: {
1214 arm64: {
1215 product_variables: {
1216 malloc_not_svelte: {
1217 cflags: ["-Warm64_malloc_not_svelte"],
1218 },
1219 },
1220 },
1221 },
1222 multilib: {
1223 lib32: {
1224 product_variables: {
1225 malloc_not_svelte: {
1226 cflags: ["-Wlib32_malloc_not_svelte"],
1227 },
1228 },
1229 },
1230 },
1231 target: {
1232 android: {
1233 product_variables: {
1234 malloc_not_svelte: {
1235 cflags: ["-Wandroid_malloc_not_svelte"],
1236 },
1237 },
1238 }
1239 },
1240 include_build_directory: false,
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001241} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001242 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001243 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001244 "copts": `select({
Cole Faust87c0c332023-07-31 12:10:12 -07001245 "//build/bazel/product_config/config_settings:malloc_not_svelte": ["-Wmalloc_not_svelte"],
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001246 "//conditions:default": [],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001247 }) + select({
Cole Faust87c0c332023-07-31 12:10:12 -07001248 "//build/bazel/product_config/config_settings:malloc_not_svelte-android": ["-Wandroid_malloc_not_svelte"],
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001249 "//conditions:default": [],
1250 }) + select({
Cole Faust87c0c332023-07-31 12:10:12 -07001251 "//build/bazel/product_config/config_settings:malloc_not_svelte-arm": ["-Wlib32_malloc_not_svelte"],
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001252 "//conditions:default": [],
1253 }) + select({
Cole Faust87c0c332023-07-31 12:10:12 -07001254 "//build/bazel/product_config/config_settings:malloc_not_svelte-arm64": ["-Warm64_malloc_not_svelte"],
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001255 "//conditions:default": [],
1256 }) + select({
Cole Faust87c0c332023-07-31 12:10:12 -07001257 "//build/bazel/product_config/config_settings:malloc_not_svelte-x86": ["-Wlib32_malloc_not_svelte"],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001258 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001259 })`,
1260 "srcs_c": `["common.c"]`,
1261 }),
1262 },
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001263 })
1264}
Liz Kammerba7a9c52021-05-26 08:45:30 -04001265
1266func TestCcLibraryStaticProductVariableStringReplacement(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001267 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1268 Description: "cc_library_static product variable string replacement",
1269 Filesystem: map[string]string{},
1270 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammerba7a9c52021-05-26 08:45:30 -04001271cc_library_static {
1272 name: "foo_static",
Chris Parsons69fa9f92021-07-13 11:47:44 -04001273 srcs: ["common.S"],
Liz Kammerba7a9c52021-05-26 08:45:30 -04001274 product_variables: {
1275 platform_sdk_version: {
1276 asflags: ["-DPLATFORM_SDK_VERSION=%d"],
1277 },
1278 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001279 include_build_directory: false,
Liz Kammerba7a9c52021-05-26 08:45:30 -04001280} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001281 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001282 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001283 "asflags": `select({
Cole Faust87c0c332023-07-31 12:10:12 -07001284 "//build/bazel/product_config/config_settings:platform_sdk_version": ["-DPLATFORM_SDK_VERSION=$(Platform_sdk_version)"],
Liz Kammerba7a9c52021-05-26 08:45:30 -04001285 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001286 })`,
1287 "srcs_as": `["common.S"]`,
1288 }),
1289 },
Liz Kammerba7a9c52021-05-26 08:45:30 -04001290 })
1291}
Chris Parsons51f8c392021-08-03 21:01:05 -04001292
1293func TestStaticLibrary_SystemSharedLibsRootEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001294 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1295 Description: "cc_library_static system_shared_lib empty root",
1296 Blueprint: soongCcLibraryStaticPreamble + `
Chris Parsons51f8c392021-08-03 21:01:05 -04001297cc_library_static {
1298 name: "root_empty",
Liz Kammer8337ea42021-09-10 10:06:32 -04001299 system_shared_libs: [],
1300 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001301}
1302`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001303 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001304 MakeBazelTarget("cc_library_static", "root_empty", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001305 "system_dynamic_deps": `[]`,
1306 }),
1307 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001308 })
1309}
1310
1311func TestStaticLibrary_SystemSharedLibsStaticEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001312 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1313 Description: "cc_library_static system_shared_lib empty static default",
1314 Blueprint: soongCcLibraryStaticPreamble + `
Chris Parsons51f8c392021-08-03 21:01:05 -04001315cc_defaults {
1316 name: "static_empty_defaults",
1317 static: {
Liz Kammer8337ea42021-09-10 10:06:32 -04001318 system_shared_libs: [],
1319 },
1320 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001321}
1322cc_library_static {
1323 name: "static_empty",
Liz Kammer8337ea42021-09-10 10:06:32 -04001324 defaults: ["static_empty_defaults"],
Chris Parsons51f8c392021-08-03 21:01:05 -04001325}
1326`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001327 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001328 MakeBazelTarget("cc_library_static", "static_empty", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001329 "system_dynamic_deps": `[]`,
1330 }),
1331 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001332 })
1333}
1334
1335func TestStaticLibrary_SystemSharedLibsBionicEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001336 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +00001337 Description: "cc_library_static system_shared_lib empty for bionic variant",
1338 StubbedBuildDefinitions: []string{"libc_musl"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001339 Blueprint: soongCcLibraryStaticPreamble + `
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001340cc_library {
1341 name: "libc_musl",
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001342}
1343
Chris Parsons51f8c392021-08-03 21:01:05 -04001344cc_library_static {
1345 name: "target_bionic_empty",
1346 target: {
1347 bionic: {
1348 system_shared_libs: [],
1349 },
1350 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001351 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001352}
1353`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001354 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001355 MakeBazelTarget("cc_library_static", "target_bionic_empty", AttrNameToString{
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001356 "system_dynamic_deps": `select({
1357 "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
1358 "//conditions:default": [],
1359 })`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001360 }),
1361 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001362 })
1363}
1364
1365func TestStaticLibrary_SystemSharedLibsLinuxBionicEmpty(t *testing.T) {
1366 // Note that this behavior is technically incorrect (it's a simplification).
1367 // The correct behavior would be if bp2build wrote `system_dynamic_deps = []`
1368 // only for linux_bionic, but `android` had `["libc", "libdl", "libm"].
1369 // b/195791252 tracks the fix.
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001370 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +00001371 Description: "cc_library_static system_shared_lib empty for linux_bionic variant",
1372 StubbedBuildDefinitions: []string{"libc_musl"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001373 Blueprint: soongCcLibraryStaticPreamble + `
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001374cc_library {
1375 name: "libc_musl",
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001376}
1377
Chris Parsons51f8c392021-08-03 21:01:05 -04001378cc_library_static {
1379 name: "target_linux_bionic_empty",
1380 target: {
1381 linux_bionic: {
1382 system_shared_libs: [],
1383 },
1384 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001385 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001386}
1387`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001388 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001389 MakeBazelTarget("cc_library_static", "target_linux_bionic_empty", AttrNameToString{
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001390 "system_dynamic_deps": `select({
1391 "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
1392 "//conditions:default": [],
1393 })`,
1394 }),
1395 },
1396 })
1397}
1398
1399func TestStaticLibrary_SystemSharedLibsMuslEmpty(t *testing.T) {
1400 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsons4c81ce02023-09-21 15:30:27 +00001401 Description: "cc_library_static system_shared_lib empty for musl variant",
1402 StubbedBuildDefinitions: []string{"libc_musl"},
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001403 Blueprint: soongCcLibraryStaticPreamble + `
1404cc_library {
1405 name: "libc_musl",
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001406}
1407
1408cc_library_static {
1409 name: "target_musl_empty",
1410 target: {
1411 musl: {
1412 system_shared_libs: [],
1413 },
1414 },
1415 include_build_directory: false,
1416}
1417`,
1418 ExpectedBazelTargets: []string{
1419 MakeBazelTarget("cc_library_static", "target_musl_empty", AttrNameToString{
1420 "system_dynamic_deps": `[]`,
1421 }),
1422 },
1423 })
1424}
1425
1426func TestStaticLibrary_SystemSharedLibsLinuxMuslEmpty(t *testing.T) {
1427 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsons4c81ce02023-09-21 15:30:27 +00001428 Description: "cc_library_static system_shared_lib empty for linux_musl variant",
1429 StubbedBuildDefinitions: []string{"libc_musl"},
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001430 Blueprint: soongCcLibraryStaticPreamble + `
1431cc_library {
1432 name: "libc_musl",
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001433}
1434
1435cc_library_static {
1436 name: "target_linux_musl_empty",
1437 target: {
1438 linux_musl: {
1439 system_shared_libs: [],
1440 },
1441 },
1442 include_build_directory: false,
1443}
1444`,
1445 ExpectedBazelTargets: []string{
1446 MakeBazelTarget("cc_library_static", "target_linux_musl_empty", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001447 "system_dynamic_deps": `[]`,
1448 }),
1449 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001450 })
1451}
1452
1453func TestStaticLibrary_SystemSharedLibsBionic(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001454 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +00001455 Description: "cc_library_static system_shared_libs set for bionic variant",
1456 StubbedBuildDefinitions: []string{"libc", "libc_musl"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001457 Blueprint: soongCcLibraryStaticPreamble +
Chris Parsonscd209032023-09-19 01:12:48 +00001458 simpleModule("cc_library", "libc") + `
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001459cc_library {
1460 name: "libc_musl",
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001461}
1462
Chris Parsons51f8c392021-08-03 21:01:05 -04001463cc_library_static {
1464 name: "target_bionic",
1465 target: {
1466 bionic: {
1467 system_shared_libs: ["libc"],
1468 },
1469 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001470 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001471}
1472`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001473 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001474 MakeBazelTarget("cc_library_static", "target_bionic", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001475 "system_dynamic_deps": `select({
Chris Parsons2dde0cb2021-10-01 14:45:30 -04001476 "//build/bazel/platforms/os:android": [":libc"],
1477 "//build/bazel/platforms/os:linux_bionic": [":libc"],
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001478 "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
Chris Parsons51f8c392021-08-03 21:01:05 -04001479 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001480 })`,
1481 }),
1482 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001483 })
1484}
1485
1486func TestStaticLibrary_SystemSharedLibsLinuxRootAndLinuxBionic(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001487 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +00001488 Description: "cc_library_static system_shared_libs set for root and linux_bionic variant",
1489 StubbedBuildDefinitions: []string{"libc", "libm", "libc_musl"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001490 Blueprint: soongCcLibraryStaticPreamble +
Chris Parsonscd209032023-09-19 01:12:48 +00001491 simpleModule("cc_library", "libc") +
1492 simpleModule("cc_library", "libm") + `
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001493cc_library {
1494 name: "libc_musl",
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001495}
1496
Chris Parsons51f8c392021-08-03 21:01:05 -04001497cc_library_static {
1498 name: "target_linux_bionic",
Liz Kammer8337ea42021-09-10 10:06:32 -04001499 system_shared_libs: ["libc"],
Chris Parsons51f8c392021-08-03 21:01:05 -04001500 target: {
1501 linux_bionic: {
1502 system_shared_libs: ["libm"],
1503 },
1504 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001505 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001506}
1507`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001508 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001509 MakeBazelTarget("cc_library_static", "target_linux_bionic", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001510 "system_dynamic_deps": `[":libc"] + select({
Chris Parsons51f8c392021-08-03 21:01:05 -04001511 "//build/bazel/platforms/os:linux_bionic": [":libm"],
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001512 "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
Chris Parsons51f8c392021-08-03 21:01:05 -04001513 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001514 })`,
1515 }),
1516 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001517 })
1518}
Liz Kammer12615db2021-09-28 09:19:17 -04001519
Liz Kammer54309532021-12-14 12:21:22 -05001520func TestCcLibrarystatic_SystemSharedLibUsedAsDep(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001521 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +00001522 Description: "cc_library_static system_shared_lib empty for linux_bionic variant",
1523 StubbedBuildDefinitions: []string{"libc", "libm"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001524 Blueprint: soongCcLibraryStaticPreamble +
Chris Parsonscd209032023-09-19 01:12:48 +00001525 simpleModule("cc_library", "libc") + `
Liz Kammer91487d42022-09-13 11:27:11 -04001526
1527cc_library {
1528 name: "libm",
1529 stubs: {
1530 symbol_file: "libm.map.txt",
1531 versions: ["current"],
1532 },
Spandan Das6d4d9da2023-04-18 06:20:40 +00001533 apex_available: ["com.android.runtime"],
Liz Kammer91487d42022-09-13 11:27:11 -04001534}
1535
Liz Kammer54309532021-12-14 12:21:22 -05001536cc_library_static {
1537 name: "used_in_bionic_oses",
1538 target: {
1539 android: {
1540 shared_libs: ["libc"],
1541 },
1542 linux_bionic: {
1543 shared_libs: ["libc"],
1544 },
1545 },
1546 include_build_directory: false,
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001547 apex_available: ["foo"],
Liz Kammer54309532021-12-14 12:21:22 -05001548}
1549
1550cc_library_static {
1551 name: "all",
1552 shared_libs: ["libc"],
1553 include_build_directory: false,
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001554 apex_available: ["foo"],
Liz Kammer54309532021-12-14 12:21:22 -05001555}
1556
1557cc_library_static {
1558 name: "keep_for_empty_system_shared_libs",
1559 shared_libs: ["libc"],
Liz Kammer91487d42022-09-13 11:27:11 -04001560 system_shared_libs: [],
1561 include_build_directory: false,
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001562 apex_available: ["foo"],
Liz Kammer91487d42022-09-13 11:27:11 -04001563}
1564
1565cc_library_static {
1566 name: "used_with_stubs",
1567 shared_libs: ["libm"],
1568 include_build_directory: false,
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001569 apex_available: ["foo"],
Liz Kammer91487d42022-09-13 11:27:11 -04001570}
1571
1572cc_library_static {
1573 name: "keep_with_stubs",
1574 shared_libs: ["libm"],
1575 system_shared_libs: [],
Liz Kammer54309532021-12-14 12:21:22 -05001576 include_build_directory: false,
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001577 apex_available: ["foo"],
Liz Kammer54309532021-12-14 12:21:22 -05001578}
1579`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001580 ExpectedBazelTargets: []string{
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001581 MakeBazelTarget("cc_library_static", "all", AttrNameToString{
1582 "tags": `["apex_available=foo"]`,
1583 }),
Alixe06d75b2022-08-31 18:28:19 +00001584 MakeBazelTarget("cc_library_static", "keep_for_empty_system_shared_libs", AttrNameToString{
Liz Kammer54309532021-12-14 12:21:22 -05001585 "implementation_dynamic_deps": `[":libc"]`,
1586 "system_dynamic_deps": `[]`,
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001587 "tags": `["apex_available=foo"]`,
Liz Kammer54309532021-12-14 12:21:22 -05001588 }),
Liz Kammer91487d42022-09-13 11:27:11 -04001589 MakeBazelTarget("cc_library_static", "keep_with_stubs", AttrNameToString{
1590 "implementation_dynamic_deps": `select({
Spandan Das6d4d9da2023-04-18 06:20:40 +00001591 "//build/bazel/rules/apex:foo": ["@api_surfaces//module-libapi/current:libm"],
1592 "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:libm"],
Liz Kammer91487d42022-09-13 11:27:11 -04001593 "//conditions:default": [":libm"],
1594 })`,
1595 "system_dynamic_deps": `[]`,
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001596 "tags": `["apex_available=foo"]`,
Liz Kammer91487d42022-09-13 11:27:11 -04001597 }),
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001598 MakeBazelTarget("cc_library_static", "used_in_bionic_oses", AttrNameToString{
1599 "tags": `["apex_available=foo"]`,
1600 }),
1601 MakeBazelTarget("cc_library_static", "used_with_stubs", AttrNameToString{
1602 "tags": `["apex_available=foo"]`,
1603 }),
Liz Kammer54309532021-12-14 12:21:22 -05001604 },
1605 })
1606}
1607
Liz Kammer12615db2021-09-28 09:19:17 -04001608func TestCcLibraryStaticProto(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001609 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +00001610 StubbedBuildDefinitions: []string{"libprotobuf-cpp-full", "libprotobuf-cpp-lite"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001611 Blueprint: soongCcProtoPreamble + `cc_library_static {
Liz Kammer12615db2021-09-28 09:19:17 -04001612 name: "foo",
1613 srcs: ["foo.proto"],
1614 proto: {
Liz Kammer12615db2021-09-28 09:19:17 -04001615 export_proto_headers: true,
1616 },
1617 include_build_directory: false,
1618}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001619 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001620 MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04001621 "srcs": `["foo.proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00001622 }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04001623 "deps": `[":foo_proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00001624 }), MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04001625 "deps": `[":libprotobuf-cpp-lite"]`,
1626 "whole_archive_deps": `[":foo_cc_proto_lite"]`,
1627 }),
1628 },
1629 })
1630}
Rupert Shuttleworth484aa252021-12-10 07:22:53 -05001631
1632func TestCcLibraryStaticUseVersionLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001633 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Liz Kammerbaced712022-09-16 09:01:29 -04001634 Filesystem: map[string]string{
1635 soongCcVersionLibBpPath: soongCcVersionLibBp,
1636 },
Chris Parsonscd209032023-09-19 01:12:48 +00001637 StubbedBuildDefinitions: []string{"//build/soong/cc/libbuildversion:libbuildversion", "libprotobuf-cpp-full", "libprotobuf-cpp-lite"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001638 Blueprint: soongCcProtoPreamble + `cc_library_static {
Rupert Shuttleworth484aa252021-12-10 07:22:53 -05001639 name: "foo",
1640 use_version_lib: true,
Liz Kammerbaced712022-09-16 09:01:29 -04001641 static_libs: ["libbuildversion"],
Rupert Shuttleworth484aa252021-12-10 07:22:53 -05001642 include_build_directory: false,
1643}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001644 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001645 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
Yu Liufe978fd2023-04-24 16:37:18 -07001646 "whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
Liz Kammerbaced712022-09-16 09:01:29 -04001647 }),
1648 },
1649 })
1650}
1651
1652func TestCcLibraryStaticUseVersionLibHasDep(t *testing.T) {
1653 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1654 Filesystem: map[string]string{
1655 soongCcVersionLibBpPath: soongCcVersionLibBp,
1656 },
Chris Parsonscd209032023-09-19 01:12:48 +00001657 StubbedBuildDefinitions: []string{"//build/soong/cc/libbuildversion:libbuildversion", "libprotobuf-cpp-full", "libprotobuf-cpp-lite"},
1658
Liz Kammerbaced712022-09-16 09:01:29 -04001659 Blueprint: soongCcProtoPreamble + `cc_library_static {
1660 name: "foo",
1661 use_version_lib: true,
1662 whole_static_libs: ["libbuildversion"],
1663 include_build_directory: false,
1664}`,
1665 ExpectedBazelTargets: []string{
1666 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1667 "whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
Rupert Shuttleworth484aa252021-12-10 07:22:53 -05001668 }),
1669 },
1670 })
1671}
Liz Kammercac7f692021-12-16 14:19:32 -05001672
1673func TestCcLibraryStaticStdInFlags(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001674 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +00001675 StubbedBuildDefinitions: []string{"libprotobuf-cpp-full", "libprotobuf-cpp-lite"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001676 Blueprint: soongCcProtoPreamble + `cc_library_static {
Liz Kammercac7f692021-12-16 14:19:32 -05001677 name: "foo",
1678 cflags: ["-std=candcpp"],
1679 conlyflags: ["-std=conly"],
1680 cppflags: ["-std=cpp"],
1681 include_build_directory: false,
1682}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001683 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001684 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
Liz Kammercac7f692021-12-16 14:19:32 -05001685 "conlyflags": `["-std=conly"]`,
1686 "cppflags": `["-std=cpp"]`,
1687 }),
1688 },
1689 })
1690}
Liz Kammer7128d382022-05-12 11:42:33 -04001691
1692func TestCcLibraryStaticStl(t *testing.T) {
1693 testCases := []struct {
1694 desc string
1695 prop string
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001696 attr AttrNameToString
Liz Kammer7128d382022-05-12 11:42:33 -04001697 }{
1698 {
1699 desc: "c++_shared deduped to libc++",
1700 prop: `stl: "c++_shared",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001701 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001702 "stl": `"libc++"`,
1703 },
1704 },
1705 {
1706 desc: "libc++ to libc++",
1707 prop: `stl: "libc++",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001708 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001709 "stl": `"libc++"`,
1710 },
1711 },
1712 {
1713 desc: "c++_static to libc++_static",
1714 prop: `stl: "c++_static",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001715 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001716 "stl": `"libc++_static"`,
1717 },
1718 },
1719 {
1720 desc: "libc++_static to libc++_static",
1721 prop: `stl: "libc++_static",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001722 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001723 "stl": `"libc++_static"`,
1724 },
1725 },
1726 {
1727 desc: "system to system",
1728 prop: `stl: "system",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001729 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001730 "stl": `"system"`,
1731 },
1732 },
1733 {
1734 desc: "none to none",
1735 prop: `stl: "none",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001736 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001737 "stl": `"none"`,
1738 },
1739 },
1740 {
1741 desc: "empty to empty",
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001742 attr: AttrNameToString{},
Liz Kammer7128d382022-05-12 11:42:33 -04001743 },
1744 }
1745 for _, tc := range testCases {
1746 t.Run(tc.desc, func(*testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001747 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1748 Blueprint: fmt.Sprintf(`cc_library_static {
Liz Kammer7128d382022-05-12 11:42:33 -04001749 name: "foo",
1750 include_build_directory: false,
1751 %s
1752}`, tc.prop),
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001753 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001754 MakeBazelTarget("cc_library_static", "foo", tc.attr),
Liz Kammer7128d382022-05-12 11:42:33 -04001755 },
1756 })
1757 })
1758 }
1759}
Cole Faust6b29f592022-08-09 09:50:56 -07001760
1761func TestCCLibraryStaticRuntimeDeps(t *testing.T) {
1762 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1763 Blueprint: `cc_library_shared {
1764 name: "bar",
1765}
1766
1767cc_library_static {
1768 name: "foo",
Chris Parsonscd209032023-09-19 01:12:48 +00001769 runtime_libs: ["bar"],
Cole Faust6b29f592022-08-09 09:50:56 -07001770}`,
1771 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001772 MakeBazelTarget("cc_library_shared", "bar", AttrNameToString{
Cole Faust6b29f592022-08-09 09:50:56 -07001773 "local_includes": `["."]`,
1774 }),
Alixe06d75b2022-08-31 18:28:19 +00001775 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
Chris Parsonscd209032023-09-19 01:12:48 +00001776 "runtime_deps": `[":bar"]`,
Cole Faust6b29f592022-08-09 09:50:56 -07001777 "local_includes": `["."]`,
1778 }),
1779 },
1780 })
1781}
Trevor Radcliffecee4e052022-09-06 19:31:25 +00001782
1783func TestCcLibraryStaticWithSyspropSrcs(t *testing.T) {
1784 runCcLibraryTestCase(t, Bp2buildTestCase{
1785 Description: "cc_library_static with sysprop sources",
1786 Blueprint: `
1787cc_library_static {
1788 name: "foo",
1789 srcs: [
1790 "bar.sysprop",
1791 "baz.sysprop",
1792 "blah.cpp",
1793 ],
1794 min_sdk_version: "5",
1795}`,
1796 ExpectedBazelTargets: []string{
1797 MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
1798 "srcs": `[
1799 "bar.sysprop",
1800 "baz.sysprop",
1801 ]`,
1802 }),
1803 MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
1804 "dep": `":foo_sysprop_library"`,
1805 "min_sdk_version": `"5"`,
1806 }),
1807 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1808 "srcs": `["blah.cpp"]`,
1809 "local_includes": `["."]`,
1810 "min_sdk_version": `"5"`,
1811 "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`,
1812 }),
1813 },
1814 })
1815}
1816
1817func TestCcLibraryStaticWithSyspropSrcsSomeConfigs(t *testing.T) {
1818 runCcLibraryTestCase(t, Bp2buildTestCase{
1819 Description: "cc_library_static with sysprop sources in some configs but not others",
1820 Blueprint: `
1821cc_library_static {
1822 name: "foo",
1823 srcs: [
1824 "blah.cpp",
1825 ],
1826 target: {
1827 android: {
1828 srcs: ["bar.sysprop"],
1829 },
1830 },
1831 min_sdk_version: "5",
1832}`,
1833 ExpectedBazelTargets: []string{
1834 MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
1835 "srcs": `select({
1836 "//build/bazel/platforms/os:android": ["bar.sysprop"],
1837 "//conditions:default": [],
1838 })`,
1839 }),
1840 MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
1841 "dep": `":foo_sysprop_library"`,
1842 "min_sdk_version": `"5"`,
1843 }),
1844 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1845 "srcs": `["blah.cpp"]`,
1846 "local_includes": `["."]`,
1847 "min_sdk_version": `"5"`,
1848 "whole_archive_deps": `select({
1849 "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"],
1850 "//conditions:default": [],
1851 })`,
1852 }),
1853 },
1854 })
1855}
Trevor Radcliffedb7e0262022-10-28 16:48:18 +00001856
1857func TestCcLibraryStaticWithIntegerOverflowProperty(t *testing.T) {
1858 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1859 Description: "cc_library_static has correct features when integer_overflow property is provided",
1860 Blueprint: `
1861cc_library_static {
1862 name: "foo",
1863 sanitize: {
1864 integer_overflow: true,
1865 },
1866}
1867`,
1868 ExpectedBazelTargets: []string{
1869 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1870 "features": `["ubsan_integer_overflow"]`,
1871 "local_includes": `["."]`,
1872 }),
1873 },
1874 })
1875}
1876
1877func TestCcLibraryStaticWithMiscUndefinedProperty(t *testing.T) {
1878 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1879 Description: "cc_library_static has correct features when misc_undefined property is provided",
1880 Blueprint: `
1881cc_library_static {
1882 name: "foo",
1883 sanitize: {
1884 misc_undefined: ["undefined", "nullability"],
1885 },
1886}
1887`,
1888 ExpectedBazelTargets: []string{
1889 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1890 "features": `[
1891 "ubsan_undefined",
1892 "ubsan_nullability",
1893 ]`,
1894 "local_includes": `["."]`,
1895 }),
1896 },
1897 })
1898}
1899
1900func TestCcLibraryStaticWithUBSanPropertiesArchSpecific(t *testing.T) {
1901 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1902 Description: "cc_library_static has correct feature select when UBSan props are specified in arch specific blocks",
1903 Blueprint: `
1904cc_library_static {
1905 name: "foo",
1906 sanitize: {
1907 misc_undefined: ["undefined", "nullability"],
1908 },
1909 target: {
1910 android: {
1911 sanitize: {
1912 misc_undefined: ["alignment"],
1913 },
1914 },
1915 linux_glibc: {
1916 sanitize: {
1917 integer_overflow: true,
1918 },
1919 },
1920 },
1921}
1922`,
1923 ExpectedBazelTargets: []string{
1924 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1925 "features": `[
1926 "ubsan_undefined",
1927 "ubsan_nullability",
1928 ] + select({
1929 "//build/bazel/platforms/os:android": ["ubsan_alignment"],
1930 "//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"],
1931 "//conditions:default": [],
1932 })`,
1933 "local_includes": `["."]`,
1934 }),
1935 },
1936 })
1937}
Trevor Radcliffe56b1a2b2023-02-06 21:58:30 +00001938
Trevor Radcliffeded095c2023-06-12 19:18:28 +00001939func TestCcLibraryStaticWithSanitizerBlocklist(t *testing.T) {
1940 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1941 Description: "cc_library_static has correct features when sanitize.blocklist is provided",
1942 Blueprint: `
1943cc_library_static {
1944 name: "foo",
1945 sanitize: {
1946 blocklist: "foo_blocklist.txt",
1947 },
1948}
1949`,
1950 ExpectedBazelTargets: []string{
1951 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
Trevor Radcliffed9b7f172023-08-09 22:21:38 +00001952 "copts": `select({
1953 "//build/bazel/rules/cc:sanitizers_enabled": ["-fsanitize-ignorelist=$(location foo_blocklist.txt)"],
1954 "//conditions:default": [],
1955 })`,
1956 "additional_compiler_inputs": `select({
1957 "//build/bazel/rules/cc:sanitizers_enabled": [":foo_blocklist.txt"],
1958 "//conditions:default": [],
1959 })`,
Trevor Radcliffeded095c2023-06-12 19:18:28 +00001960 "local_includes": `["."]`,
1961 }),
1962 },
1963 })
1964}
1965
Trevor Radcliffe56b1a2b2023-02-06 21:58:30 +00001966func TestCcLibraryStaticWithThinLto(t *testing.T) {
1967 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1968 Description: "cc_library_static has correct features when thin lto is enabled",
1969 Blueprint: `
1970cc_library_static {
1971 name: "foo",
1972 lto: {
1973 thin: true,
1974 },
1975}
1976`,
1977 ExpectedBazelTargets: []string{
1978 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1979 "features": `["android_thin_lto"]`,
1980 "local_includes": `["."]`,
1981 }),
1982 },
1983 })
1984}
1985
1986func TestCcLibraryStaticWithLtoNever(t *testing.T) {
1987 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1988 Description: "cc_library_static has correct features when thin lto is enabled",
1989 Blueprint: `
1990cc_library_static {
1991 name: "foo",
1992 lto: {
1993 never: true,
1994 },
1995}
1996`,
1997 ExpectedBazelTargets: []string{
1998 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1999 "features": `["-android_thin_lto"]`,
2000 "local_includes": `["."]`,
2001 }),
2002 },
2003 })
2004}
2005
2006func TestCcLibraryStaticWithThinLtoArchSpecific(t *testing.T) {
2007 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2008 Description: "cc_library_static has correct features when LTO differs across arch and os variants",
2009 Blueprint: `
2010cc_library_static {
2011 name: "foo",
2012 target: {
2013 android: {
2014 lto: {
2015 thin: true,
2016 },
2017 },
2018 },
2019 arch: {
2020 riscv64: {
2021 lto: {
2022 thin: false,
2023 },
2024 },
2025 },
2026}`,
2027 ExpectedBazelTargets: []string{
2028 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2029 "local_includes": `["."]`,
2030 "features": `select({
2031 "//build/bazel/platforms/os_arch:android_arm": ["android_thin_lto"],
2032 "//build/bazel/platforms/os_arch:android_arm64": ["android_thin_lto"],
2033 "//build/bazel/platforms/os_arch:android_riscv64": ["-android_thin_lto"],
2034 "//build/bazel/platforms/os_arch:android_x86": ["android_thin_lto"],
2035 "//build/bazel/platforms/os_arch:android_x86_64": ["android_thin_lto"],
2036 "//conditions:default": [],
2037 })`}),
2038 },
2039 })
2040}
2041
2042func TestCcLibraryStaticWithThinLtoDisabledDefaultEnabledVariant(t *testing.T) {
2043 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2044 Description: "cc_library_static has correct features when LTO disabled by default but enabled on a particular variant",
2045 Blueprint: `
2046cc_library_static {
2047 name: "foo",
2048 lto: {
2049 never: true,
2050 },
2051 target: {
2052 android: {
2053 lto: {
2054 thin: true,
2055 never: false,
2056 },
2057 },
2058 },
2059}`,
2060 ExpectedBazelTargets: []string{
2061 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2062 "local_includes": `["."]`,
2063 "features": `select({
2064 "//build/bazel/platforms/os:android": ["android_thin_lto"],
2065 "//conditions:default": ["-android_thin_lto"],
2066 })`,
2067 }),
2068 },
2069 })
2070}
2071
2072func TestCcLibraryStaticWithThinLtoAndWholeProgramVtables(t *testing.T) {
2073 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2074 Description: "cc_library_static has correct features when thin lto is enabled with whole_program_vtables",
2075 Blueprint: `
2076cc_library_static {
2077 name: "foo",
2078 lto: {
2079 thin: true,
2080 },
2081 whole_program_vtables: true,
2082}
2083`,
2084 ExpectedBazelTargets: []string{
2085 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2086 "features": `[
2087 "android_thin_lto",
2088 "android_thin_lto_whole_program_vtables",
2089 ]`,
2090 "local_includes": `["."]`,
2091 }),
2092 },
2093 })
2094}
Trevor Radcliffea8b44162023-04-14 18:25:24 +00002095
2096func TestCcLibraryStaticHiddenVisibilityConvertedToFeature(t *testing.T) {
2097 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2098 Description: "cc_library_static changes hidden visibility flag to feature",
2099 Blueprint: `
2100cc_library_static {
2101 name: "foo",
2102 cflags: ["-fvisibility=hidden"],
2103}`,
2104 ExpectedBazelTargets: []string{
2105 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2106 "features": `["visibility_hidden"]`,
2107 "local_includes": `["."]`,
2108 }),
2109 },
2110 })
2111}
2112
2113func TestCcLibraryStaticHiddenVisibilityConvertedToFeatureOsSpecific(t *testing.T) {
2114 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2115 Description: "cc_library_static changes hidden visibility flag to feature for specific os",
2116 Blueprint: `
2117cc_library_static {
2118 name: "foo",
2119 target: {
2120 android: {
2121 cflags: ["-fvisibility=hidden"],
2122 },
2123 },
2124}`,
2125 ExpectedBazelTargets: []string{
2126 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2127 "features": `select({
2128 "//build/bazel/platforms/os:android": ["visibility_hidden"],
2129 "//conditions:default": [],
2130 })`,
2131 "local_includes": `["."]`,
2132 }),
2133 },
2134 })
2135}
Trevor Radcliffe27669c02023-03-28 20:47:10 +00002136
2137func TestCcLibraryStaticWithCfi(t *testing.T) {
2138 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2139 Description: "cc_library_static has correct features when cfi is enabled",
2140 Blueprint: `
2141cc_library_static {
2142 name: "foo",
2143 sanitize: {
2144 cfi: true,
2145 },
2146}`,
2147 ExpectedBazelTargets: []string{
2148 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2149 "features": `["android_cfi"]`,
2150 "local_includes": `["."]`,
2151 }),
2152 },
2153 })
2154}
2155
2156func TestCcLibraryStaticWithCfiOsSpecific(t *testing.T) {
2157 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2158 Description: "cc_library_static has correct features when cfi is enabled for specific variants",
2159 Blueprint: `
2160cc_library_static {
2161 name: "foo",
2162 target: {
2163 android: {
2164 sanitize: {
2165 cfi: true,
2166 },
2167 },
2168 },
2169}`,
2170 ExpectedBazelTargets: []string{
2171 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2172 "features": `select({
2173 "//build/bazel/platforms/os:android": ["android_cfi"],
2174 "//conditions:default": [],
2175 })`,
2176 "local_includes": `["."]`,
2177 }),
2178 },
2179 })
2180}
2181
2182func TestCcLibraryStaticWithCfiAndCfiAssemblySupport(t *testing.T) {
2183 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2184 Description: "cc_library_static has correct features when cfi is enabled with cfi_assembly_support",
2185 Blueprint: `
2186cc_library_static {
2187 name: "foo",
2188 sanitize: {
2189 cfi: true,
2190 config: {
2191 cfi_assembly_support: true,
2192 },
2193 },
2194}`,
2195 ExpectedBazelTargets: []string{
2196 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2197 "features": `[
2198 "android_cfi",
2199 "android_cfi_assembly_support",
2200 ]`,
2201 "local_includes": `["."]`,
2202 }),
2203 },
2204 })
2205}
Trevor Radcliffe523c5c62023-06-16 20:15:45 +00002206
2207func TestCcLibraryStaticExplicitlyDisablesCfiWhenFalse(t *testing.T) {
2208 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2209 Description: "cc_library_static disables cfi when explciitly set to false in the bp",
2210 Blueprint: `
2211cc_library_static {
2212 name: "foo",
2213 sanitize: {
2214 cfi: false,
2215 },
2216}
2217`,
2218 ExpectedBazelTargets: []string{
2219 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2220 "features": `["-android_cfi"]`,
2221 "local_includes": `["."]`,
2222 }),
2223 },
2224 })
2225}
Alixe2667872023-04-24 14:57:32 +00002226
2227func TestCCLibraryStaticRscriptSrc(t *testing.T) {
2228 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2229 Description: `cc_library_static with rscript files in sources`,
2230 Blueprint: `
2231cc_library_static{
2232 name : "foo",
2233 srcs : [
2234 "ccSrc.cc",
2235 "rsSrc.rscript",
2236 ],
2237 include_build_directory: false,
2238}
2239`,
2240 ExpectedBazelTargets: []string{
2241 MakeBazelTarget("rscript_to_cpp", "foo_renderscript", AttrNameToString{
2242 "srcs": `["rsSrc.rscript"]`,
2243 }),
2244 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2245 "absolute_includes": `[
2246 "frameworks/rs",
2247 "frameworks/rs/cpp",
2248 ]`,
2249 "local_includes": `["."]`,
2250 "srcs": `[
2251 "ccSrc.cc",
2252 "foo_renderscript",
2253 ]`,
2254 })}})
2255}
Spandan Dasa99348d2023-08-01 23:10:05 +00002256
2257func TestCcLibraryWithProtoInGeneratedSrcs(t *testing.T) {
2258 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2259 Description: "cc_library with a .proto file generated from a genrule",
2260 ModuleTypeUnderTest: "cc_library_static",
2261 ModuleTypeUnderTestFactory: cc.LibraryStaticFactory,
Chris Parsonscd209032023-09-19 01:12:48 +00002262 StubbedBuildDefinitions: []string{"libprotobuf-cpp-lite"},
Spandan Dasa99348d2023-08-01 23:10:05 +00002263 Blueprint: soongCcLibraryPreamble + `
2264cc_library_static {
2265 name: "mylib",
2266 generated_sources: ["myprotogen"],
2267}
2268genrule {
2269 name: "myprotogen",
2270 out: ["myproto.proto"],
2271}
Chris Parsonscd209032023-09-19 01:12:48 +00002272` + simpleModule("cc_library", "libprotobuf-cpp-lite"),
Spandan Dasa99348d2023-08-01 23:10:05 +00002273 ExpectedBazelTargets: []string{
2274 MakeBazelTarget("cc_library_static", "mylib", AttrNameToString{
2275 "local_includes": `["."]`,
2276 "deps": `[":libprotobuf-cpp-lite"]`,
2277 "implementation_whole_archive_deps": `[":mylib_cc_proto_lite"]`,
2278 }),
2279 MakeBazelTarget("cc_lite_proto_library", "mylib_cc_proto_lite", AttrNameToString{
2280 "deps": `[":mylib_proto"]`,
2281 }),
2282 MakeBazelTarget("proto_library", "mylib_proto", AttrNameToString{
2283 "srcs": `[":myprotogen"]`,
2284 }),
2285 MakeBazelTargetNoRestrictions("genrule", "myprotogen", AttrNameToString{
2286 "cmd": `""`,
2287 "outs": `["myproto.proto"]`,
2288 }),
2289 },
2290 })
2291}