blob: 09e40edab0382bce3c24c9aff31455a6fdae5bc0 [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"`,
Spandan Dasaf725832023-09-19 19:51:52 +0000206 "deps": `select({
207 "//build/bazel/rules/apex:unbundled_app": ["//build/bazel/rules/cc:ndk_sysroot"],
208 "//conditions:default": [],
209 })`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500210 }),
211 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200212 })
213}
214
215func TestCcLibraryStaticSubpackage(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000216 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
217 Description: "cc_library_static subpackage test",
218 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200219 // subpackage with subdirectory
220 "subpackage/Android.bp": "",
221 "subpackage/subpackage_header.h": "",
222 "subpackage/subdirectory/subdirectory_header.h": "",
223 // subsubpackage with subdirectory
224 "subpackage/subsubpackage/Android.bp": "",
225 "subpackage/subsubpackage/subsubpackage_header.h": "",
226 "subpackage/subsubpackage/subdirectory/subdirectory_header.h": "",
227 // subsubsubpackage with subdirectory
228 "subpackage/subsubpackage/subsubsubpackage/Android.bp": "",
229 "subpackage/subsubpackage/subsubsubpackage/subsubsubpackage_header.h": "",
230 "subpackage/subsubpackage/subsubsubpackage/subdirectory/subdirectory_header.h": "",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000231 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000232 Blueprint: soongCcLibraryStaticPreamble + `
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400233cc_library_static {
234 name: "foo_static",
Liz Kammer35687bc2021-09-10 10:07:07 -0400235 srcs: [],
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400236 include_dirs: [
Liz Kammer35687bc2021-09-10 10:07:07 -0400237 "subpackage",
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400238 ],
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400239}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000240 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000241 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500242 "absolute_includes": `["subpackage"]`,
243 "local_includes": `["."]`,
244 }),
245 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200246 })
247}
248
249func TestCcLibraryStaticExportIncludeDir(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000250 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
251 Description: "cc_library_static export include dir",
252 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200253 // subpackage with subdirectory
254 "subpackage/Android.bp": "",
255 "subpackage/subpackage_header.h": "",
256 "subpackage/subdirectory/subdirectory_header.h": "",
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400257 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000258 Blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000259cc_library_static {
260 name: "foo_static",
261 export_include_dirs: ["subpackage"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400262 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000263}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000264 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000265 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500266 "export_includes": `["subpackage"]`,
267 }),
268 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200269 })
270}
271
272func TestCcLibraryStaticExportSystemIncludeDir(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000273 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
274 Description: "cc_library_static export system include dir",
275 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200276 // subpackage with subdirectory
277 "subpackage/Android.bp": "",
278 "subpackage/subpackage_header.h": "",
279 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000280 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000281 Blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000282cc_library_static {
283 name: "foo_static",
284 export_system_include_dirs: ["subpackage"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400285 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000286}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000287 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000288 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500289 "export_system_includes": `["subpackage"]`,
290 }),
291 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200292 })
293}
294
295func TestCcLibraryStaticManyIncludeDirs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000296 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
297 Description: "cc_library_static include_dirs, local_include_dirs, export_include_dirs (b/183742505)",
298 Dir: "subpackage",
299 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200300 // subpackage with subdirectory
301 "subpackage/Android.bp": `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000302cc_library_static {
303 name: "foo_static",
304 // include_dirs are workspace/root relative
305 include_dirs: [
306 "subpackage/subsubpackage",
307 "subpackage2",
308 "subpackage3/subsubpackage"
309 ],
310 local_include_dirs: ["subsubpackage2"], // module dir relative
311 export_include_dirs: ["./exported_subsubpackage"], // module dir relative
312 include_build_directory: true,
313 bazel_module: { bp2build_available: true },
314}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200315 "subpackage/subsubpackage/header.h": "",
316 "subpackage/subsubpackage2/header.h": "",
317 "subpackage/exported_subsubpackage/header.h": "",
318 "subpackage2/header.h": "",
319 "subpackage3/subsubpackage/header.h": "",
320 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000321 Blueprint: soongCcLibraryStaticPreamble,
322 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000323 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500324 "absolute_includes": `[
Liz Kammer35687bc2021-09-10 10:07:07 -0400325 "subpackage/subsubpackage",
326 "subpackage2",
327 "subpackage3/subsubpackage",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500328 ]`,
329 "export_includes": `["./exported_subsubpackage"]`,
330 "local_includes": `[
Liz Kammer35687bc2021-09-10 10:07:07 -0400331 "subsubpackage2",
332 ".",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500333 ]`,
334 })},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200335 })
336}
337
338func TestCcLibraryStaticIncludeBuildDirectoryDisabled(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000339 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
340 Description: "cc_library_static include_build_directory disabled",
341 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200342 // subpackage with subdirectory
343 "subpackage/Android.bp": "",
344 "subpackage/subpackage_header.h": "",
345 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000346 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000347 Blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000348cc_library_static {
349 name: "foo_static",
350 include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended
351 local_include_dirs: ["subpackage2"],
352 include_build_directory: false,
353}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000354 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000355 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500356 "absolute_includes": `["subpackage"]`,
357 "local_includes": `["subpackage2"]`,
358 }),
359 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200360 })
361}
362
363func TestCcLibraryStaticIncludeBuildDirectoryEnabled(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000364 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
365 Description: "cc_library_static include_build_directory enabled",
366 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200367 // subpackage with subdirectory
368 "subpackage/Android.bp": "",
369 "subpackage/subpackage_header.h": "",
370 "subpackage2/Android.bp": "",
371 "subpackage2/subpackage2_header.h": "",
372 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000373 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000374 Blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000375cc_library_static {
376 name: "foo_static",
377 include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended
378 local_include_dirs: ["subpackage2"],
379 include_build_directory: true,
380}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000381 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000382 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500383 "absolute_includes": `["subpackage"]`,
384 "local_includes": `[
Liz Kammer35687bc2021-09-10 10:07:07 -0400385 "subpackage2",
386 ".",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500387 ]`,
388 }),
389 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200390 })
391}
392
393func TestCcLibraryStaticArchSpecificStaticLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000394 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +0000395 Description: "cc_library_static arch-specific static_libs",
396 Filesystem: map[string]string{},
397 StubbedBuildDefinitions: []string{"static_dep", "static_dep2"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000398 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -0400399cc_library_static {
400 name: "static_dep",
Liz Kammer8337ea42021-09-10 10:06:32 -0400401}
402cc_library_static {
403 name: "static_dep2",
Liz Kammer8337ea42021-09-10 10:06:32 -0400404}
Jingwen Chened9c17d2021-04-13 07:14:55 +0000405cc_library_static {
406 name: "foo_static",
407 arch: { arm64: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } },
Liz Kammer8337ea42021-09-10 10:06:32 -0400408 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000409}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000410 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000411 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500412 "implementation_deps": `select({
Chris Parsons08648312021-05-06 16:23:19 -0400413 "//build/bazel/platforms/arch:arm64": [":static_dep"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000414 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500415 })`,
416 "whole_archive_deps": `select({
Chris Parsons08648312021-05-06 16:23:19 -0400417 "//build/bazel/platforms/arch:arm64": [":static_dep2"],
418 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500419 })`,
420 }),
421 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200422 })
423}
424
425func TestCcLibraryStaticOsSpecificStaticLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000426 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +0000427 Description: "cc_library_static os-specific static_libs",
428 Filesystem: map[string]string{},
429 StubbedBuildDefinitions: []string{"static_dep", "static_dep2"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000430 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -0400431cc_library_static {
432 name: "static_dep",
Liz Kammer8337ea42021-09-10 10:06:32 -0400433}
434cc_library_static {
435 name: "static_dep2",
Liz Kammer8337ea42021-09-10 10:06:32 -0400436}
Jingwen Chened9c17d2021-04-13 07:14:55 +0000437cc_library_static {
438 name: "foo_static",
439 target: { android: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } },
Liz Kammer8337ea42021-09-10 10:06:32 -0400440 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000441}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000442 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000443 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500444 "implementation_deps": `select({
Chris Parsons08648312021-05-06 16:23:19 -0400445 "//build/bazel/platforms/os:android": [":static_dep"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000446 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500447 })`,
448 "whole_archive_deps": `select({
Chris Parsons08648312021-05-06 16:23:19 -0400449 "//build/bazel/platforms/os:android": [":static_dep2"],
450 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500451 })`,
452 }),
453 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200454 })
455}
456
457func TestCcLibraryStaticBaseArchOsSpecificStaticLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000458 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
459 Description: "cc_library_static base, arch and os-specific static_libs",
460 Filesystem: map[string]string{},
Chris Parsonscd209032023-09-19 01:12:48 +0000461 StubbedBuildDefinitions: []string{"static_dep", "static_dep2", "static_dep3",
462 "static_dep4"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000463 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -0400464cc_library_static {
465 name: "static_dep",
Liz Kammer8337ea42021-09-10 10:06:32 -0400466}
467cc_library_static {
468 name: "static_dep2",
Liz Kammer8337ea42021-09-10 10:06:32 -0400469}
470cc_library_static {
471 name: "static_dep3",
Liz Kammer8337ea42021-09-10 10:06:32 -0400472}
473cc_library_static {
474 name: "static_dep4",
Liz Kammer8337ea42021-09-10 10:06:32 -0400475}
Jingwen Chened9c17d2021-04-13 07:14:55 +0000476cc_library_static {
477 name: "foo_static",
478 static_libs: ["static_dep"],
479 whole_static_libs: ["static_dep2"],
480 target: { android: { static_libs: ["static_dep3"] } },
481 arch: { arm64: { static_libs: ["static_dep4"] } },
Liz Kammer8337ea42021-09-10 10:06:32 -0400482 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000483}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000484 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000485 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500486 "implementation_deps": `[":static_dep"] + select({
Jingwen Chened9c17d2021-04-13 07:14:55 +0000487 "//build/bazel/platforms/arch:arm64": [":static_dep4"],
488 "//conditions:default": [],
489 }) + select({
490 "//build/bazel/platforms/os:android": [":static_dep3"],
491 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500492 })`,
493 "whole_archive_deps": `[":static_dep2"]`,
494 }),
495 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200496 })
497}
498
499func TestCcLibraryStaticSimpleExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000500 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
501 Description: "cc_library_static simple exclude_srcs",
502 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200503 "common.c": "",
504 "foo-a.c": "",
505 "foo-excluded.c": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000506 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000507 Blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000508cc_library_static {
509 name: "foo_static",
510 srcs: ["common.c", "foo-*.c"],
511 exclude_srcs: ["foo-excluded.c"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400512 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000513}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000514 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000515 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500516 "srcs_c": `[
Jingwen Chene32e9e02021-04-23 09:17:24 +0000517 "common.c",
518 "foo-a.c",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500519 ]`,
520 }),
521 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200522 })
523}
524
525func TestCcLibraryStaticOneArchSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000526 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
527 Description: "cc_library_static one arch specific srcs",
528 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200529 "common.c": "",
530 "foo-arm.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000531 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000532 Blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000533cc_library_static {
534 name: "foo_static",
535 srcs: ["common.c"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400536 arch: { arm: { srcs: ["foo-arm.c"] } },
537 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000538}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000539 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000540 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500541 "srcs_c": `["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000542 "//build/bazel/platforms/arch:arm": ["foo-arm.c"],
543 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500544 })`,
545 }),
546 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200547 })
548}
549
550func TestCcLibraryStaticOneArchSrcsExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000551 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
552 Description: "cc_library_static one arch specific srcs and exclude_srcs",
553 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200554 "common.c": "",
555 "for-arm.c": "",
556 "not-for-arm.c": "",
557 "not-for-anything.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000558 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000559 Blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000560cc_library_static {
561 name: "foo_static",
562 srcs: ["common.c", "not-for-*.c"],
563 exclude_srcs: ["not-for-anything.c"],
564 arch: {
565 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
566 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400567 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000568}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000569 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000570 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500571 "srcs_c": `["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000572 "//build/bazel/platforms/arch:arm": ["for-arm.c"],
573 "//conditions:default": ["not-for-arm.c"],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500574 })`,
575 }),
576 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200577 })
578}
579
580func TestCcLibraryStaticTwoArchExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000581 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
582 Description: "cc_library_static arch specific exclude_srcs for 2 architectures",
583 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200584 "common.c": "",
585 "for-arm.c": "",
586 "for-x86.c": "",
587 "not-for-arm.c": "",
588 "not-for-x86.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000589 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000590 Blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000591cc_library_static {
592 name: "foo_static",
593 srcs: ["common.c", "not-for-*.c"],
594 exclude_srcs: ["not-for-everything.c"],
595 arch: {
596 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
597 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
598 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400599 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000600} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000601 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000602 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500603 "srcs_c": `["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000604 "//build/bazel/platforms/arch:arm": [
Jingwen Chene32e9e02021-04-23 09:17:24 +0000605 "not-for-x86.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400606 "for-arm.c",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000607 ],
608 "//build/bazel/platforms/arch:x86": [
Jingwen Chene32e9e02021-04-23 09:17:24 +0000609 "not-for-arm.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400610 "for-x86.c",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000611 ],
612 "//conditions:default": [
613 "not-for-arm.c",
614 "not-for-x86.c",
615 ],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500616 })`,
617 }),
618 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200619 })
620}
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500621
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200622func TestCcLibraryStaticFourArchExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000623 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
624 Description: "cc_library_static arch specific exclude_srcs for 4 architectures",
625 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200626 "common.c": "",
627 "for-arm.c": "",
628 "for-arm64.c": "",
629 "for-x86.c": "",
630 "for-x86_64.c": "",
631 "not-for-arm.c": "",
632 "not-for-arm64.c": "",
633 "not-for-x86.c": "",
634 "not-for-x86_64.c": "",
635 "not-for-everything.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000636 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000637 Blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000638cc_library_static {
639 name: "foo_static",
640 srcs: ["common.c", "not-for-*.c"],
641 exclude_srcs: ["not-for-everything.c"],
642 arch: {
643 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
644 arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] },
645 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
646 x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] },
Liz Kammer8337ea42021-09-10 10:06:32 -0400647 },
648 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000649} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000650 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000651 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500652 "srcs_c": `["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000653 "//build/bazel/platforms/arch:arm": [
Jingwen Chene32e9e02021-04-23 09:17:24 +0000654 "not-for-arm64.c",
655 "not-for-x86.c",
656 "not-for-x86_64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400657 "for-arm.c",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000658 ],
659 "//build/bazel/platforms/arch:arm64": [
Jingwen Chene32e9e02021-04-23 09:17:24 +0000660 "not-for-arm.c",
661 "not-for-x86.c",
662 "not-for-x86_64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400663 "for-arm64.c",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000664 ],
665 "//build/bazel/platforms/arch:x86": [
Jingwen Chene32e9e02021-04-23 09:17:24 +0000666 "not-for-arm.c",
667 "not-for-arm64.c",
668 "not-for-x86_64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400669 "for-x86.c",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000670 ],
671 "//build/bazel/platforms/arch:x86_64": [
Jingwen Chene32e9e02021-04-23 09:17:24 +0000672 "not-for-arm.c",
673 "not-for-arm64.c",
674 "not-for-x86.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400675 "for-x86_64.c",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000676 ],
677 "//conditions:default": [
678 "not-for-arm.c",
679 "not-for-arm64.c",
680 "not-for-x86.c",
681 "not-for-x86_64.c",
682 ],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500683 })`,
684 }),
685 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200686 })
687}
688
Liz Kammer2b07ec72021-05-26 15:08:27 -0400689func TestCcLibraryStaticOneArchEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000690 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
691 Description: "cc_library_static one arch empty",
692 Filesystem: map[string]string{
Liz Kammer2b07ec72021-05-26 15:08:27 -0400693 "common.cc": "",
694 "foo-no-arm.cc": "",
695 "foo-excluded.cc": "",
696 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000697 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer2b07ec72021-05-26 15:08:27 -0400698cc_library_static {
699 name: "foo_static",
700 srcs: ["common.cc", "foo-*.cc"],
701 exclude_srcs: ["foo-excluded.cc"],
702 arch: {
703 arm: { exclude_srcs: ["foo-no-arm.cc"] },
704 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400705 include_build_directory: false,
Liz Kammer2b07ec72021-05-26 15:08:27 -0400706}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000707 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000708 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500709 "srcs": `["common.cc"] + select({
Liz Kammer2b07ec72021-05-26 15:08:27 -0400710 "//build/bazel/platforms/arch:arm": [],
711 "//conditions:default": ["foo-no-arm.cc"],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500712 })`,
713 }),
714 },
Liz Kammer2b07ec72021-05-26 15:08:27 -0400715 })
716}
717
718func TestCcLibraryStaticOneArchEmptyOtherSet(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000719 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
720 Description: "cc_library_static one arch empty other set",
721 Filesystem: map[string]string{
Liz Kammer2b07ec72021-05-26 15:08:27 -0400722 "common.cc": "",
723 "foo-no-arm.cc": "",
724 "x86-only.cc": "",
725 "foo-excluded.cc": "",
726 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000727 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer2b07ec72021-05-26 15:08:27 -0400728cc_library_static {
729 name: "foo_static",
730 srcs: ["common.cc", "foo-*.cc"],
731 exclude_srcs: ["foo-excluded.cc"],
732 arch: {
733 arm: { exclude_srcs: ["foo-no-arm.cc"] },
734 x86: { srcs: ["x86-only.cc"] },
735 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400736 include_build_directory: false,
Liz Kammer2b07ec72021-05-26 15:08:27 -0400737}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000738 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000739 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500740 "srcs": `["common.cc"] + select({
Liz Kammer2b07ec72021-05-26 15:08:27 -0400741 "//build/bazel/platforms/arch:arm": [],
742 "//build/bazel/platforms/arch:x86": [
743 "foo-no-arm.cc",
744 "x86-only.cc",
745 ],
746 "//conditions:default": ["foo-no-arm.cc"],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500747 })`,
748 }),
749 },
Liz Kammer2b07ec72021-05-26 15:08:27 -0400750 })
751}
752
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200753func TestCcLibraryStaticMultipleDepSameName(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000754 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +0000755 Description: "cc_library_static multiple dep same name panic",
756 Filesystem: map[string]string{},
757 StubbedBuildDefinitions: []string{"static_dep"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000758 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -0400759cc_library_static {
760 name: "static_dep",
Liz Kammer8337ea42021-09-10 10:06:32 -0400761}
Liz Kammer2b50ce62021-04-26 15:47:28 -0400762cc_library_static {
763 name: "foo_static",
Chris Parsons08648312021-05-06 16:23:19 -0400764 static_libs: ["static_dep", "static_dep"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400765 include_build_directory: false,
Liz Kammer2b50ce62021-04-26 15:47:28 -0400766}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000767 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000768 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500769 "implementation_deps": `[":static_dep"]`,
770 }),
771 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200772 })
773}
774
775func TestCcLibraryStaticOneMultilibSrcsExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000776 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
777 Description: "cc_library_static 1 multilib srcs and exclude_srcs",
778 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200779 "common.c": "",
780 "for-lib32.c": "",
781 "not-for-lib32.c": "",
Liz Kammer2b50ce62021-04-26 15:47:28 -0400782 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000783 Blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -0400784cc_library_static {
785 name: "foo_static",
786 srcs: ["common.c", "not-for-*.c"],
787 multilib: {
788 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
789 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400790 include_build_directory: false,
Chris Parsonsc424b762021-04-29 18:06:50 -0400791} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000792 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000793 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500794 "srcs_c": `["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -0400795 "//build/bazel/platforms/arch:arm": ["for-lib32.c"],
796 "//build/bazel/platforms/arch:x86": ["for-lib32.c"],
797 "//conditions:default": ["not-for-lib32.c"],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500798 })`,
799 }),
800 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200801 })
802}
803
804func TestCcLibraryStaticTwoMultilibSrcsExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000805 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
806 Description: "cc_library_static 2 multilib srcs and exclude_srcs",
807 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200808 "common.c": "",
809 "for-lib32.c": "",
810 "for-lib64.c": "",
811 "not-for-lib32.c": "",
812 "not-for-lib64.c": "",
Chris Parsonsc424b762021-04-29 18:06:50 -0400813 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000814 Blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -0400815cc_library_static {
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500816 name: "foo_static",
Chris Parsonsc424b762021-04-29 18:06:50 -0400817 srcs: ["common.c", "not-for-*.c"],
818 multilib: {
819 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
820 lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] },
821 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400822 include_build_directory: false,
Chris Parsonsc424b762021-04-29 18:06:50 -0400823} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000824 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000825 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500826 "srcs_c": `["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -0400827 "//build/bazel/platforms/arch:arm": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400828 "not-for-lib64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400829 "for-lib32.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400830 ],
831 "//build/bazel/platforms/arch:arm64": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400832 "not-for-lib32.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400833 "for-lib64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400834 ],
Colin Crossf05b0d32022-07-14 18:10:34 -0700835 "//build/bazel/platforms/arch:riscv64": [
836 "not-for-lib32.c",
837 "for-lib64.c",
838 ],
Chris Parsonsc424b762021-04-29 18:06:50 -0400839 "//build/bazel/platforms/arch:x86": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400840 "not-for-lib64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400841 "for-lib32.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400842 ],
843 "//build/bazel/platforms/arch:x86_64": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400844 "not-for-lib32.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400845 "for-lib64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400846 ],
847 "//conditions:default": [
848 "not-for-lib32.c",
849 "not-for-lib64.c",
850 ],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500851 })`,
852 }),
853 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200854 })
855}
856
857func TestCcLibrarySTaticArchMultilibSrcsExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000858 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
859 Description: "cc_library_static arch and multilib srcs and exclude_srcs",
860 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200861 "common.c": "",
862 "for-arm.c": "",
863 "for-arm64.c": "",
864 "for-x86.c": "",
865 "for-x86_64.c": "",
866 "for-lib32.c": "",
867 "for-lib64.c": "",
868 "not-for-arm.c": "",
869 "not-for-arm64.c": "",
Colin Crossf05b0d32022-07-14 18:10:34 -0700870 "not-for-riscv64.c": "",
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200871 "not-for-x86.c": "",
872 "not-for-x86_64.c": "",
873 "not-for-lib32.c": "",
874 "not-for-lib64.c": "",
875 "not-for-everything.c": "",
Chris Parsonsc424b762021-04-29 18:06:50 -0400876 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000877 Blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -0400878cc_library_static {
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500879 name: "foo_static",
Chris Parsonsc424b762021-04-29 18:06:50 -0400880 srcs: ["common.c", "not-for-*.c"],
881 exclude_srcs: ["not-for-everything.c"],
882 arch: {
883 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
884 arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] },
Colin Crossf05b0d32022-07-14 18:10:34 -0700885 riscv64: { srcs: ["for-riscv64.c"], exclude_srcs: ["not-for-riscv64.c"] },
Chris Parsonsc424b762021-04-29 18:06:50 -0400886 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
887 x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] },
888 },
889 multilib: {
890 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
891 lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] },
892 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400893 include_build_directory: false,
Chris Parsonsc424b762021-04-29 18:06:50 -0400894}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000895 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000896 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500897 "srcs_c": `["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -0400898 "//build/bazel/platforms/arch:arm": [
Liz Kammer9bad9d62021-10-11 15:40:35 -0400899 "not-for-arm64.c",
900 "not-for-lib64.c",
Colin Crossf05b0d32022-07-14 18:10:34 -0700901 "not-for-riscv64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400902 "not-for-x86.c",
903 "not-for-x86_64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400904 "for-arm.c",
905 "for-lib32.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400906 ],
907 "//build/bazel/platforms/arch:arm64": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400908 "not-for-arm.c",
909 "not-for-lib32.c",
Colin Crossf05b0d32022-07-14 18:10:34 -0700910 "not-for-riscv64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400911 "not-for-x86.c",
912 "not-for-x86_64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400913 "for-arm64.c",
914 "for-lib64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400915 ],
Colin Crossf05b0d32022-07-14 18:10:34 -0700916 "//build/bazel/platforms/arch:riscv64": [
917 "not-for-arm.c",
918 "not-for-arm64.c",
919 "not-for-lib32.c",
920 "not-for-x86.c",
921 "not-for-x86_64.c",
922 "for-riscv64.c",
923 "for-lib64.c",
924 ],
Chris Parsonsc424b762021-04-29 18:06:50 -0400925 "//build/bazel/platforms/arch:x86": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400926 "not-for-arm.c",
927 "not-for-arm64.c",
928 "not-for-lib64.c",
Colin Crossf05b0d32022-07-14 18:10:34 -0700929 "not-for-riscv64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400930 "not-for-x86_64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400931 "for-x86.c",
932 "for-lib32.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400933 ],
934 "//build/bazel/platforms/arch:x86_64": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400935 "not-for-arm.c",
936 "not-for-arm64.c",
937 "not-for-lib32.c",
Colin Crossf05b0d32022-07-14 18:10:34 -0700938 "not-for-riscv64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400939 "not-for-x86.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400940 "for-x86_64.c",
941 "for-lib64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400942 ],
943 "//conditions:default": [
944 "not-for-arm.c",
945 "not-for-arm64.c",
946 "not-for-lib32.c",
947 "not-for-lib64.c",
Colin Crossf05b0d32022-07-14 18:10:34 -0700948 "not-for-riscv64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400949 "not-for-x86.c",
950 "not-for-x86_64.c",
951 ],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500952 })`,
953 }),
954 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200955 })
956}
957
Liz Kammerae3994e2021-10-19 09:45:48 -0400958func TestCcLibraryStaticGeneratedHeadersAllPartitions(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000959 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +0000960 StubbedBuildDefinitions: []string{"generated_hdr", "export_generated_hdr"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000961 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammerae3994e2021-10-19 09:45:48 -0400962genrule {
963 name: "generated_hdr",
964 cmd: "nothing to see here",
965}
966
Liz Kammere6583482021-10-19 13:56:10 -0400967genrule {
968 name: "export_generated_hdr",
969 cmd: "nothing to see here",
970}
971
Liz Kammerae3994e2021-10-19 09:45:48 -0400972cc_library_static {
973 name: "foo_static",
974 srcs: ["cpp_src.cpp", "as_src.S", "c_src.c"],
Liz Kammere6583482021-10-19 13:56:10 -0400975 generated_headers: ["generated_hdr", "export_generated_hdr"],
976 export_generated_headers: ["export_generated_hdr"],
Liz Kammerae3994e2021-10-19 09:45:48 -0400977 include_build_directory: false,
978}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000979 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000980 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer1263d9b2021-12-10 14:28:20 -0500981 "export_includes": `["."]`,
982 "local_includes": `["."]`,
983 "hdrs": `[":export_generated_hdr"]`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500984 "srcs": `[
Liz Kammerae3994e2021-10-19 09:45:48 -0400985 "cpp_src.cpp",
986 ":generated_hdr",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500987 ]`,
988 "srcs_as": `[
Liz Kammerae3994e2021-10-19 09:45:48 -0400989 "as_src.S",
990 ":generated_hdr",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500991 ]`,
992 "srcs_c": `[
Liz Kammerae3994e2021-10-19 09:45:48 -0400993 "c_src.c",
994 ":generated_hdr",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500995 ]`,
996 }),
997 },
Liz Kammerae3994e2021-10-19 09:45:48 -0400998 })
999}
1000
Liz Kammer0db0e342023-07-18 11:39:30 -04001001func TestCcLibraryStaticGeneratedHeadersMultipleExports(t *testing.T) {
1002 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +00001003 StubbedBuildDefinitions: []string{"generated_hdr", "export_generated_hdr"},
Liz Kammer0db0e342023-07-18 11:39:30 -04001004 Blueprint: soongCcLibraryStaticPreamble + `
1005genrule {
1006 name: "generated_hdr",
1007 cmd: "nothing to see here",
1008 export_include_dirs: ["foo", "bar"],
Liz Kammer0db0e342023-07-18 11:39:30 -04001009}
1010
1011genrule {
1012 name: "export_generated_hdr",
1013 cmd: "nothing to see here",
1014 export_include_dirs: ["a", "b"],
Liz Kammer0db0e342023-07-18 11:39:30 -04001015}
1016
1017cc_library_static {
1018 name: "foo_static",
1019 generated_headers: ["generated_hdr", "export_generated_hdr"],
1020 export_generated_headers: ["export_generated_hdr"],
1021 include_build_directory: false,
1022}`,
1023 ExpectedBazelTargets: []string{
1024 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
1025 "deps": `[":export_generated_hdr__header_library"]`,
1026 "implementation_deps": `[":generated_hdr__header_library"]`,
1027 }),
1028 },
1029 })
1030}
1031
Zi Wang9f609db2023-01-04 11:06:54 -08001032// generated_headers has "variant_prepend" tag. In bp2build output,
1033// variant info(select) should go before general info.
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001034func TestCcLibraryStaticArchSrcsExcludeSrcsGeneratedFiles(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001035 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1036 Description: "cc_library_static arch srcs/exclude_srcs with generated files",
Chris Parsonscd209032023-09-19 01:12:48 +00001037 StubbedBuildDefinitions: []string{"//dep:generated_src_other_pkg", "//dep:generated_hdr_other_pkg",
1038 "//dep:generated_src_other_pkg_x86", "//dep:generated_hdr_other_pkg_x86", "//dep:generated_hdr_other_pkg_android",
1039 "generated_src", "generated_src_not_x86", "generated_src_android", "generated_hdr",
1040 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001041 Filesystem: map[string]string{
Chris Parsons990c4f42021-05-25 12:10:58 -04001042 "common.cpp": "",
1043 "for-x86.cpp": "",
1044 "not-for-x86.cpp": "",
1045 "not-for-everything.cpp": "",
Chris Parsonscd209032023-09-19 01:12:48 +00001046 "dep/Android.bp": simpleModule("genrule", "generated_src_other_pkg") +
1047 simpleModule("genrule", "generated_hdr_other_pkg") +
1048 simpleModule("genrule", "generated_src_other_pkg_x86") +
1049 simpleModule("genrule", "generated_hdr_other_pkg_x86") +
1050 simpleModule("genrule", "generated_hdr_other_pkg_android"),
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001051 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001052 Blueprint: soongCcLibraryStaticPreamble +
Chris Parsonscd209032023-09-19 01:12:48 +00001053 simpleModule("genrule", "generated_src") +
1054 simpleModule("genrule", "generated_src_not_x86") +
1055 simpleModule("genrule", "generated_src_android") +
1056 simpleModule("genrule", "generated_hdr") + `
Chris Parsons484e50a2021-05-13 15:13:04 -04001057cc_library_static {
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001058 name: "foo_static",
Liz Kammer222bdcf2021-10-11 14:15:51 -04001059 srcs: ["common.cpp", "not-for-*.cpp"],
1060 exclude_srcs: ["not-for-everything.cpp"],
1061 generated_sources: ["generated_src", "generated_src_other_pkg", "generated_src_not_x86"],
1062 generated_headers: ["generated_hdr", "generated_hdr_other_pkg"],
Liz Kammer1263d9b2021-12-10 14:28:20 -05001063 export_generated_headers: ["generated_hdr_other_pkg"],
Liz Kammer222bdcf2021-10-11 14:15:51 -04001064 arch: {
1065 x86: {
1066 srcs: ["for-x86.cpp"],
1067 exclude_srcs: ["not-for-x86.cpp"],
1068 generated_headers: ["generated_hdr_other_pkg_x86"],
1069 exclude_generated_sources: ["generated_src_not_x86"],
Liz Kammer1263d9b2021-12-10 14:28:20 -05001070 export_generated_headers: ["generated_hdr_other_pkg_x86"],
Liz Kammer222bdcf2021-10-11 14:15:51 -04001071 },
1072 },
1073 target: {
1074 android: {
1075 generated_sources: ["generated_src_android"],
1076 generated_headers: ["generated_hdr_other_pkg_android"],
Liz Kammer1263d9b2021-12-10 14:28:20 -05001077 export_generated_headers: ["generated_hdr_other_pkg_android"],
Liz Kammer222bdcf2021-10-11 14:15:51 -04001078 },
1079 },
1080
Liz Kammer8337ea42021-09-10 10:06:32 -04001081 include_build_directory: false,
Chris Parsons484e50a2021-05-13 15:13:04 -04001082}
1083`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001084 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001085 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001086 "srcs": `[
Chris Parsons990c4f42021-05-25 12:10:58 -04001087 "common.cpp",
Liz Kammer9bad9d62021-10-11 15:40:35 -04001088 ":generated_src",
1089 "//dep:generated_src_other_pkg",
Liz Kammerae3994e2021-10-19 09:45:48 -04001090 ":generated_hdr",
Chris Parsons484e50a2021-05-13 15:13:04 -04001091 ] + select({
Liz Kammer1263d9b2021-12-10 14:28:20 -05001092 "//build/bazel/platforms/arch:x86": ["for-x86.cpp"],
Liz Kammer222bdcf2021-10-11 14:15:51 -04001093 "//conditions:default": [
Liz Kammer222bdcf2021-10-11 14:15:51 -04001094 "not-for-x86.cpp",
Liz Kammer9bad9d62021-10-11 15:40:35 -04001095 ":generated_src_not_x86",
Liz Kammer222bdcf2021-10-11 14:15:51 -04001096 ],
1097 }) + select({
Liz Kammer1263d9b2021-12-10 14:28:20 -05001098 "//build/bazel/platforms/os:android": [":generated_src_android"],
Liz Kammer222bdcf2021-10-11 14:15:51 -04001099 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001100 })`,
Zi Wang9f609db2023-01-04 11:06:54 -08001101 "hdrs": `select({
Liz Kammer1263d9b2021-12-10 14:28:20 -05001102 "//build/bazel/platforms/os:android": ["//dep:generated_hdr_other_pkg_android"],
1103 "//conditions:default": [],
Zi Wang9f609db2023-01-04 11:06:54 -08001104 }) + select({
1105 "//build/bazel/platforms/arch:x86": ["//dep:generated_hdr_other_pkg_x86"],
1106 "//conditions:default": [],
1107 }) + ["//dep:generated_hdr_other_pkg"]`,
Liz Kammer1263d9b2021-12-10 14:28:20 -05001108 "local_includes": `["."]`,
1109 "export_absolute_includes": `["dep"]`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001110 }),
1111 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001112 })
Rupert Shuttleworth095081c2021-03-25 09:06:03 +00001113}
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001114
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001115func TestCcLibraryStaticGetTargetProperties(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001116 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001117
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001118 Description: "cc_library_static complex GetTargetProperties",
1119 Blueprint: soongCcLibraryStaticPreamble + `
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001120cc_library_static {
1121 name: "foo_static",
1122 target: {
1123 android: {
1124 srcs: ["android_src.c"],
1125 },
1126 android_arm: {
1127 srcs: ["android_arm_src.c"],
1128 },
1129 android_arm64: {
1130 srcs: ["android_arm64_src.c"],
1131 },
1132 android_x86: {
1133 srcs: ["android_x86_src.c"],
1134 },
1135 android_x86_64: {
1136 srcs: ["android_x86_64_src.c"],
1137 },
1138 linux_bionic_arm64: {
1139 srcs: ["linux_bionic_arm64_src.c"],
1140 },
1141 linux_bionic_x86_64: {
1142 srcs: ["linux_bionic_x86_64_src.c"],
1143 },
1144 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001145 include_build_directory: false,
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001146}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001147 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001148 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001149 "srcs_c": `select({
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001150 "//build/bazel/platforms/os:android": ["android_src.c"],
1151 "//conditions:default": [],
1152 }) + select({
Rupert Shuttleworthffd45822021-05-14 03:02:34 -04001153 "//build/bazel/platforms/os_arch:android_arm": ["android_arm_src.c"],
1154 "//build/bazel/platforms/os_arch:android_arm64": ["android_arm64_src.c"],
1155 "//build/bazel/platforms/os_arch:android_x86": ["android_x86_src.c"],
1156 "//build/bazel/platforms/os_arch:android_x86_64": ["android_x86_64_src.c"],
Rupert Shuttleworthffd45822021-05-14 03:02:34 -04001157 "//build/bazel/platforms/os_arch:linux_bionic_arm64": ["linux_bionic_arm64_src.c"],
1158 "//build/bazel/platforms/os_arch:linux_bionic_x86_64": ["linux_bionic_x86_64_src.c"],
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001159 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001160 })`,
1161 }),
1162 },
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001163 })
1164}
1165
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001166func TestCcLibraryStaticProductVariableSelects(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001167 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1168 Description: "cc_library_static product variable selects",
1169 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001170cc_library_static {
1171 name: "foo_static",
1172 srcs: ["common.c"],
1173 product_variables: {
1174 malloc_not_svelte: {
1175 cflags: ["-Wmalloc_not_svelte"],
1176 },
1177 malloc_zero_contents: {
1178 cflags: ["-Wmalloc_zero_contents"],
1179 },
1180 binder32bit: {
1181 cflags: ["-Wbinder32bit"],
1182 },
1183 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001184 include_build_directory: false,
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001185} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001186 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001187 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001188 "copts": `select({
Cole Faust87c0c332023-07-31 12:10:12 -07001189 "//build/bazel/product_config/config_settings:binder32bit": ["-Wbinder32bit"],
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001190 "//conditions:default": [],
1191 }) + select({
Cole Faust87c0c332023-07-31 12:10:12 -07001192 "//build/bazel/product_config/config_settings:malloc_not_svelte": ["-Wmalloc_not_svelte"],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001193 "//conditions:default": [],
1194 }) + select({
Cole Faust87c0c332023-07-31 12:10:12 -07001195 "//build/bazel/product_config/config_settings:malloc_zero_contents": ["-Wmalloc_zero_contents"],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001196 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001197 })`,
1198 "srcs_c": `["common.c"]`,
1199 }),
1200 },
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001201 })
1202}
1203
1204func TestCcLibraryStaticProductVariableArchSpecificSelects(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001205 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1206 Description: "cc_library_static arch-specific product variable selects",
1207 Filesystem: map[string]string{},
1208 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001209cc_library_static {
1210 name: "foo_static",
1211 srcs: ["common.c"],
1212 product_variables: {
1213 malloc_not_svelte: {
1214 cflags: ["-Wmalloc_not_svelte"],
1215 },
1216 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001217 arch: {
1218 arm64: {
1219 product_variables: {
1220 malloc_not_svelte: {
1221 cflags: ["-Warm64_malloc_not_svelte"],
1222 },
1223 },
1224 },
1225 },
1226 multilib: {
1227 lib32: {
1228 product_variables: {
1229 malloc_not_svelte: {
1230 cflags: ["-Wlib32_malloc_not_svelte"],
1231 },
1232 },
1233 },
1234 },
1235 target: {
1236 android: {
1237 product_variables: {
1238 malloc_not_svelte: {
1239 cflags: ["-Wandroid_malloc_not_svelte"],
1240 },
1241 },
1242 }
1243 },
1244 include_build_directory: false,
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001245} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001246 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001247 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001248 "copts": `select({
Cole Faust87c0c332023-07-31 12:10:12 -07001249 "//build/bazel/product_config/config_settings:malloc_not_svelte": ["-Wmalloc_not_svelte"],
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001250 "//conditions:default": [],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001251 }) + select({
Cole Faust87c0c332023-07-31 12:10:12 -07001252 "//build/bazel/product_config/config_settings:malloc_not_svelte-android": ["-Wandroid_malloc_not_svelte"],
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001253 "//conditions:default": [],
1254 }) + select({
Cole Faust87c0c332023-07-31 12:10:12 -07001255 "//build/bazel/product_config/config_settings:malloc_not_svelte-arm": ["-Wlib32_malloc_not_svelte"],
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001256 "//conditions:default": [],
1257 }) + select({
Cole Faust87c0c332023-07-31 12:10:12 -07001258 "//build/bazel/product_config/config_settings:malloc_not_svelte-arm64": ["-Warm64_malloc_not_svelte"],
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001259 "//conditions:default": [],
1260 }) + select({
Cole Faust87c0c332023-07-31 12:10:12 -07001261 "//build/bazel/product_config/config_settings:malloc_not_svelte-x86": ["-Wlib32_malloc_not_svelte"],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001262 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001263 })`,
1264 "srcs_c": `["common.c"]`,
1265 }),
1266 },
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001267 })
1268}
Liz Kammerba7a9c52021-05-26 08:45:30 -04001269
1270func TestCcLibraryStaticProductVariableStringReplacement(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001271 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1272 Description: "cc_library_static product variable string replacement",
1273 Filesystem: map[string]string{},
1274 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammerba7a9c52021-05-26 08:45:30 -04001275cc_library_static {
1276 name: "foo_static",
Chris Parsons69fa9f92021-07-13 11:47:44 -04001277 srcs: ["common.S"],
Liz Kammerba7a9c52021-05-26 08:45:30 -04001278 product_variables: {
1279 platform_sdk_version: {
1280 asflags: ["-DPLATFORM_SDK_VERSION=%d"],
1281 },
1282 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001283 include_build_directory: false,
Liz Kammerba7a9c52021-05-26 08:45:30 -04001284} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001285 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001286 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001287 "asflags": `select({
Cole Faust87c0c332023-07-31 12:10:12 -07001288 "//build/bazel/product_config/config_settings:platform_sdk_version": ["-DPLATFORM_SDK_VERSION=$(Platform_sdk_version)"],
Liz Kammerba7a9c52021-05-26 08:45:30 -04001289 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001290 })`,
1291 "srcs_as": `["common.S"]`,
1292 }),
1293 },
Liz Kammerba7a9c52021-05-26 08:45:30 -04001294 })
1295}
Chris Parsons51f8c392021-08-03 21:01:05 -04001296
1297func TestStaticLibrary_SystemSharedLibsRootEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001298 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1299 Description: "cc_library_static system_shared_lib empty root",
1300 Blueprint: soongCcLibraryStaticPreamble + `
Chris Parsons51f8c392021-08-03 21:01:05 -04001301cc_library_static {
1302 name: "root_empty",
Liz Kammer8337ea42021-09-10 10:06:32 -04001303 system_shared_libs: [],
1304 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001305}
1306`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001307 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001308 MakeBazelTarget("cc_library_static", "root_empty", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001309 "system_dynamic_deps": `[]`,
1310 }),
1311 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001312 })
1313}
1314
1315func TestStaticLibrary_SystemSharedLibsStaticEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001316 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1317 Description: "cc_library_static system_shared_lib empty static default",
1318 Blueprint: soongCcLibraryStaticPreamble + `
Chris Parsons51f8c392021-08-03 21:01:05 -04001319cc_defaults {
1320 name: "static_empty_defaults",
1321 static: {
Liz Kammer8337ea42021-09-10 10:06:32 -04001322 system_shared_libs: [],
1323 },
1324 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001325}
1326cc_library_static {
1327 name: "static_empty",
Liz Kammer8337ea42021-09-10 10:06:32 -04001328 defaults: ["static_empty_defaults"],
Chris Parsons51f8c392021-08-03 21:01:05 -04001329}
1330`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001331 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001332 MakeBazelTarget("cc_library_static", "static_empty", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001333 "system_dynamic_deps": `[]`,
1334 }),
1335 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001336 })
1337}
1338
1339func TestStaticLibrary_SystemSharedLibsBionicEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001340 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +00001341 Description: "cc_library_static system_shared_lib empty for bionic variant",
1342 StubbedBuildDefinitions: []string{"libc_musl"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001343 Blueprint: soongCcLibraryStaticPreamble + `
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001344cc_library {
1345 name: "libc_musl",
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001346}
1347
Chris Parsons51f8c392021-08-03 21:01:05 -04001348cc_library_static {
1349 name: "target_bionic_empty",
1350 target: {
1351 bionic: {
1352 system_shared_libs: [],
1353 },
1354 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001355 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001356}
1357`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001358 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001359 MakeBazelTarget("cc_library_static", "target_bionic_empty", AttrNameToString{
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001360 "system_dynamic_deps": `select({
1361 "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
1362 "//conditions:default": [],
1363 })`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001364 }),
1365 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001366 })
1367}
1368
1369func TestStaticLibrary_SystemSharedLibsLinuxBionicEmpty(t *testing.T) {
1370 // Note that this behavior is technically incorrect (it's a simplification).
1371 // The correct behavior would be if bp2build wrote `system_dynamic_deps = []`
1372 // only for linux_bionic, but `android` had `["libc", "libdl", "libm"].
1373 // b/195791252 tracks the fix.
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001374 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +00001375 Description: "cc_library_static system_shared_lib empty for linux_bionic variant",
1376 StubbedBuildDefinitions: []string{"libc_musl"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001377 Blueprint: soongCcLibraryStaticPreamble + `
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001378cc_library {
1379 name: "libc_musl",
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001380}
1381
Chris Parsons51f8c392021-08-03 21:01:05 -04001382cc_library_static {
1383 name: "target_linux_bionic_empty",
1384 target: {
1385 linux_bionic: {
1386 system_shared_libs: [],
1387 },
1388 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001389 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001390}
1391`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001392 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001393 MakeBazelTarget("cc_library_static", "target_linux_bionic_empty", AttrNameToString{
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001394 "system_dynamic_deps": `select({
1395 "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
1396 "//conditions:default": [],
1397 })`,
1398 }),
1399 },
1400 })
1401}
1402
1403func TestStaticLibrary_SystemSharedLibsMuslEmpty(t *testing.T) {
1404 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsons4c81ce02023-09-21 15:30:27 +00001405 Description: "cc_library_static system_shared_lib empty for musl variant",
1406 StubbedBuildDefinitions: []string{"libc_musl"},
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001407 Blueprint: soongCcLibraryStaticPreamble + `
1408cc_library {
1409 name: "libc_musl",
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001410}
1411
1412cc_library_static {
1413 name: "target_musl_empty",
1414 target: {
1415 musl: {
1416 system_shared_libs: [],
1417 },
1418 },
1419 include_build_directory: false,
1420}
1421`,
1422 ExpectedBazelTargets: []string{
1423 MakeBazelTarget("cc_library_static", "target_musl_empty", AttrNameToString{
1424 "system_dynamic_deps": `[]`,
1425 }),
1426 },
1427 })
1428}
1429
1430func TestStaticLibrary_SystemSharedLibsLinuxMuslEmpty(t *testing.T) {
1431 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsons4c81ce02023-09-21 15:30:27 +00001432 Description: "cc_library_static system_shared_lib empty for linux_musl variant",
1433 StubbedBuildDefinitions: []string{"libc_musl"},
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001434 Blueprint: soongCcLibraryStaticPreamble + `
1435cc_library {
1436 name: "libc_musl",
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001437}
1438
1439cc_library_static {
1440 name: "target_linux_musl_empty",
1441 target: {
1442 linux_musl: {
1443 system_shared_libs: [],
1444 },
1445 },
1446 include_build_directory: false,
1447}
1448`,
1449 ExpectedBazelTargets: []string{
1450 MakeBazelTarget("cc_library_static", "target_linux_musl_empty", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001451 "system_dynamic_deps": `[]`,
1452 }),
1453 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001454 })
1455}
1456
1457func TestStaticLibrary_SystemSharedLibsBionic(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001458 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +00001459 Description: "cc_library_static system_shared_libs set for bionic variant",
1460 StubbedBuildDefinitions: []string{"libc", "libc_musl"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001461 Blueprint: soongCcLibraryStaticPreamble +
Chris Parsonscd209032023-09-19 01:12:48 +00001462 simpleModule("cc_library", "libc") + `
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001463cc_library {
1464 name: "libc_musl",
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001465}
1466
Chris Parsons51f8c392021-08-03 21:01:05 -04001467cc_library_static {
1468 name: "target_bionic",
1469 target: {
1470 bionic: {
1471 system_shared_libs: ["libc"],
1472 },
1473 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001474 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001475}
1476`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001477 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001478 MakeBazelTarget("cc_library_static", "target_bionic", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001479 "system_dynamic_deps": `select({
Chris Parsons2dde0cb2021-10-01 14:45:30 -04001480 "//build/bazel/platforms/os:android": [":libc"],
1481 "//build/bazel/platforms/os:linux_bionic": [":libc"],
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001482 "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
Chris Parsons51f8c392021-08-03 21:01:05 -04001483 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001484 })`,
1485 }),
1486 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001487 })
1488}
1489
1490func TestStaticLibrary_SystemSharedLibsLinuxRootAndLinuxBionic(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001491 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +00001492 Description: "cc_library_static system_shared_libs set for root and linux_bionic variant",
1493 StubbedBuildDefinitions: []string{"libc", "libm", "libc_musl"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001494 Blueprint: soongCcLibraryStaticPreamble +
Chris Parsonscd209032023-09-19 01:12:48 +00001495 simpleModule("cc_library", "libc") +
1496 simpleModule("cc_library", "libm") + `
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001497cc_library {
1498 name: "libc_musl",
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001499}
1500
Chris Parsons51f8c392021-08-03 21:01:05 -04001501cc_library_static {
1502 name: "target_linux_bionic",
Liz Kammer8337ea42021-09-10 10:06:32 -04001503 system_shared_libs: ["libc"],
Chris Parsons51f8c392021-08-03 21:01:05 -04001504 target: {
1505 linux_bionic: {
1506 system_shared_libs: ["libm"],
1507 },
1508 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001509 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001510}
1511`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001512 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001513 MakeBazelTarget("cc_library_static", "target_linux_bionic", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001514 "system_dynamic_deps": `[":libc"] + select({
Chris Parsons51f8c392021-08-03 21:01:05 -04001515 "//build/bazel/platforms/os:linux_bionic": [":libm"],
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001516 "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
Chris Parsons51f8c392021-08-03 21:01:05 -04001517 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001518 })`,
1519 }),
1520 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001521 })
1522}
Liz Kammer12615db2021-09-28 09:19:17 -04001523
Liz Kammer54309532021-12-14 12:21:22 -05001524func TestCcLibrarystatic_SystemSharedLibUsedAsDep(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001525 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +00001526 Description: "cc_library_static system_shared_lib empty for linux_bionic variant",
1527 StubbedBuildDefinitions: []string{"libc", "libm"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001528 Blueprint: soongCcLibraryStaticPreamble +
Chris Parsonscd209032023-09-19 01:12:48 +00001529 simpleModule("cc_library", "libc") + `
Liz Kammer91487d42022-09-13 11:27:11 -04001530
1531cc_library {
1532 name: "libm",
1533 stubs: {
1534 symbol_file: "libm.map.txt",
1535 versions: ["current"],
1536 },
Spandan Das6d4d9da2023-04-18 06:20:40 +00001537 apex_available: ["com.android.runtime"],
Liz Kammer91487d42022-09-13 11:27:11 -04001538}
1539
Liz Kammer54309532021-12-14 12:21:22 -05001540cc_library_static {
1541 name: "used_in_bionic_oses",
1542 target: {
1543 android: {
1544 shared_libs: ["libc"],
1545 },
1546 linux_bionic: {
1547 shared_libs: ["libc"],
1548 },
1549 },
1550 include_build_directory: false,
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001551 apex_available: ["foo"],
Liz Kammer54309532021-12-14 12:21:22 -05001552}
1553
1554cc_library_static {
1555 name: "all",
1556 shared_libs: ["libc"],
1557 include_build_directory: false,
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001558 apex_available: ["foo"],
Liz Kammer54309532021-12-14 12:21:22 -05001559}
1560
1561cc_library_static {
1562 name: "keep_for_empty_system_shared_libs",
1563 shared_libs: ["libc"],
Liz Kammer91487d42022-09-13 11:27:11 -04001564 system_shared_libs: [],
1565 include_build_directory: false,
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001566 apex_available: ["foo"],
Liz Kammer91487d42022-09-13 11:27:11 -04001567}
1568
1569cc_library_static {
1570 name: "used_with_stubs",
1571 shared_libs: ["libm"],
1572 include_build_directory: false,
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001573 apex_available: ["foo"],
Liz Kammer91487d42022-09-13 11:27:11 -04001574}
1575
1576cc_library_static {
1577 name: "keep_with_stubs",
1578 shared_libs: ["libm"],
1579 system_shared_libs: [],
Liz Kammer54309532021-12-14 12:21:22 -05001580 include_build_directory: false,
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001581 apex_available: ["foo"],
Liz Kammer54309532021-12-14 12:21:22 -05001582}
1583`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001584 ExpectedBazelTargets: []string{
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001585 MakeBazelTarget("cc_library_static", "all", AttrNameToString{
1586 "tags": `["apex_available=foo"]`,
1587 }),
Alixe06d75b2022-08-31 18:28:19 +00001588 MakeBazelTarget("cc_library_static", "keep_for_empty_system_shared_libs", AttrNameToString{
Liz Kammer54309532021-12-14 12:21:22 -05001589 "implementation_dynamic_deps": `[":libc"]`,
1590 "system_dynamic_deps": `[]`,
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001591 "tags": `["apex_available=foo"]`,
Liz Kammer54309532021-12-14 12:21:22 -05001592 }),
Liz Kammer91487d42022-09-13 11:27:11 -04001593 MakeBazelTarget("cc_library_static", "keep_with_stubs", AttrNameToString{
1594 "implementation_dynamic_deps": `select({
Spandan Das6d4d9da2023-04-18 06:20:40 +00001595 "//build/bazel/rules/apex:foo": ["@api_surfaces//module-libapi/current:libm"],
1596 "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:libm"],
Liz Kammer91487d42022-09-13 11:27:11 -04001597 "//conditions:default": [":libm"],
1598 })`,
1599 "system_dynamic_deps": `[]`,
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001600 "tags": `["apex_available=foo"]`,
Liz Kammer91487d42022-09-13 11:27:11 -04001601 }),
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001602 MakeBazelTarget("cc_library_static", "used_in_bionic_oses", AttrNameToString{
1603 "tags": `["apex_available=foo"]`,
1604 }),
1605 MakeBazelTarget("cc_library_static", "used_with_stubs", AttrNameToString{
1606 "tags": `["apex_available=foo"]`,
1607 }),
Liz Kammer54309532021-12-14 12:21:22 -05001608 },
1609 })
1610}
1611
Liz Kammer12615db2021-09-28 09:19:17 -04001612func TestCcLibraryStaticProto(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001613 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +00001614 StubbedBuildDefinitions: []string{"libprotobuf-cpp-full", "libprotobuf-cpp-lite"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001615 Blueprint: soongCcProtoPreamble + `cc_library_static {
Liz Kammer12615db2021-09-28 09:19:17 -04001616 name: "foo",
1617 srcs: ["foo.proto"],
1618 proto: {
Liz Kammer12615db2021-09-28 09:19:17 -04001619 export_proto_headers: true,
1620 },
1621 include_build_directory: false,
1622}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001623 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001624 MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04001625 "srcs": `["foo.proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00001626 }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04001627 "deps": `[":foo_proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00001628 }), MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04001629 "deps": `[":libprotobuf-cpp-lite"]`,
1630 "whole_archive_deps": `[":foo_cc_proto_lite"]`,
1631 }),
1632 },
1633 })
1634}
Rupert Shuttleworth484aa252021-12-10 07:22:53 -05001635
1636func TestCcLibraryStaticUseVersionLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001637 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Liz Kammerbaced712022-09-16 09:01:29 -04001638 Filesystem: map[string]string{
1639 soongCcVersionLibBpPath: soongCcVersionLibBp,
1640 },
Chris Parsonscd209032023-09-19 01:12:48 +00001641 StubbedBuildDefinitions: []string{"//build/soong/cc/libbuildversion:libbuildversion", "libprotobuf-cpp-full", "libprotobuf-cpp-lite"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001642 Blueprint: soongCcProtoPreamble + `cc_library_static {
Rupert Shuttleworth484aa252021-12-10 07:22:53 -05001643 name: "foo",
1644 use_version_lib: true,
Liz Kammerbaced712022-09-16 09:01:29 -04001645 static_libs: ["libbuildversion"],
Rupert Shuttleworth484aa252021-12-10 07:22:53 -05001646 include_build_directory: false,
1647}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001648 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001649 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
Yu Liufe978fd2023-04-24 16:37:18 -07001650 "whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
Liz Kammerbaced712022-09-16 09:01:29 -04001651 }),
1652 },
1653 })
1654}
1655
1656func TestCcLibraryStaticUseVersionLibHasDep(t *testing.T) {
1657 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1658 Filesystem: map[string]string{
1659 soongCcVersionLibBpPath: soongCcVersionLibBp,
1660 },
Chris Parsonscd209032023-09-19 01:12:48 +00001661 StubbedBuildDefinitions: []string{"//build/soong/cc/libbuildversion:libbuildversion", "libprotobuf-cpp-full", "libprotobuf-cpp-lite"},
1662
Liz Kammerbaced712022-09-16 09:01:29 -04001663 Blueprint: soongCcProtoPreamble + `cc_library_static {
1664 name: "foo",
1665 use_version_lib: true,
1666 whole_static_libs: ["libbuildversion"],
1667 include_build_directory: false,
1668}`,
1669 ExpectedBazelTargets: []string{
1670 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1671 "whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
Rupert Shuttleworth484aa252021-12-10 07:22:53 -05001672 }),
1673 },
1674 })
1675}
Liz Kammercac7f692021-12-16 14:19:32 -05001676
1677func TestCcLibraryStaticStdInFlags(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001678 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Chris Parsonscd209032023-09-19 01:12:48 +00001679 StubbedBuildDefinitions: []string{"libprotobuf-cpp-full", "libprotobuf-cpp-lite"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001680 Blueprint: soongCcProtoPreamble + `cc_library_static {
Liz Kammercac7f692021-12-16 14:19:32 -05001681 name: "foo",
1682 cflags: ["-std=candcpp"],
1683 conlyflags: ["-std=conly"],
1684 cppflags: ["-std=cpp"],
1685 include_build_directory: false,
1686}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001687 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001688 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
Liz Kammercac7f692021-12-16 14:19:32 -05001689 "conlyflags": `["-std=conly"]`,
1690 "cppflags": `["-std=cpp"]`,
1691 }),
1692 },
1693 })
1694}
Liz Kammer7128d382022-05-12 11:42:33 -04001695
1696func TestCcLibraryStaticStl(t *testing.T) {
1697 testCases := []struct {
1698 desc string
1699 prop string
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001700 attr AttrNameToString
Liz Kammer7128d382022-05-12 11:42:33 -04001701 }{
1702 {
1703 desc: "c++_shared deduped to libc++",
1704 prop: `stl: "c++_shared",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001705 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001706 "stl": `"libc++"`,
1707 },
1708 },
1709 {
1710 desc: "libc++ to libc++",
1711 prop: `stl: "libc++",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001712 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001713 "stl": `"libc++"`,
1714 },
1715 },
1716 {
1717 desc: "c++_static to libc++_static",
1718 prop: `stl: "c++_static",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001719 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001720 "stl": `"libc++_static"`,
1721 },
1722 },
1723 {
1724 desc: "libc++_static to libc++_static",
1725 prop: `stl: "libc++_static",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001726 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001727 "stl": `"libc++_static"`,
1728 },
1729 },
1730 {
1731 desc: "system to system",
1732 prop: `stl: "system",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001733 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001734 "stl": `"system"`,
1735 },
1736 },
1737 {
1738 desc: "none to none",
1739 prop: `stl: "none",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001740 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001741 "stl": `"none"`,
1742 },
1743 },
1744 {
1745 desc: "empty to empty",
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001746 attr: AttrNameToString{},
Liz Kammer7128d382022-05-12 11:42:33 -04001747 },
1748 }
1749 for _, tc := range testCases {
1750 t.Run(tc.desc, func(*testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001751 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1752 Blueprint: fmt.Sprintf(`cc_library_static {
Liz Kammer7128d382022-05-12 11:42:33 -04001753 name: "foo",
1754 include_build_directory: false,
1755 %s
1756}`, tc.prop),
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001757 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001758 MakeBazelTarget("cc_library_static", "foo", tc.attr),
Liz Kammer7128d382022-05-12 11:42:33 -04001759 },
1760 })
1761 })
1762 }
1763}
Cole Faust6b29f592022-08-09 09:50:56 -07001764
1765func TestCCLibraryStaticRuntimeDeps(t *testing.T) {
1766 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1767 Blueprint: `cc_library_shared {
1768 name: "bar",
1769}
1770
1771cc_library_static {
1772 name: "foo",
Chris Parsonscd209032023-09-19 01:12:48 +00001773 runtime_libs: ["bar"],
Cole Faust6b29f592022-08-09 09:50:56 -07001774}`,
1775 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001776 MakeBazelTarget("cc_library_shared", "bar", AttrNameToString{
Cole Faust6b29f592022-08-09 09:50:56 -07001777 "local_includes": `["."]`,
1778 }),
Alixe06d75b2022-08-31 18:28:19 +00001779 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
Chris Parsonscd209032023-09-19 01:12:48 +00001780 "runtime_deps": `[":bar"]`,
Cole Faust6b29f592022-08-09 09:50:56 -07001781 "local_includes": `["."]`,
1782 }),
1783 },
1784 })
1785}
Trevor Radcliffecee4e052022-09-06 19:31:25 +00001786
1787func TestCcLibraryStaticWithSyspropSrcs(t *testing.T) {
1788 runCcLibraryTestCase(t, Bp2buildTestCase{
1789 Description: "cc_library_static with sysprop sources",
1790 Blueprint: `
1791cc_library_static {
1792 name: "foo",
1793 srcs: [
1794 "bar.sysprop",
1795 "baz.sysprop",
1796 "blah.cpp",
1797 ],
1798 min_sdk_version: "5",
1799}`,
1800 ExpectedBazelTargets: []string{
1801 MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
1802 "srcs": `[
1803 "bar.sysprop",
1804 "baz.sysprop",
1805 ]`,
1806 }),
1807 MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
1808 "dep": `":foo_sysprop_library"`,
1809 "min_sdk_version": `"5"`,
1810 }),
1811 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1812 "srcs": `["blah.cpp"]`,
1813 "local_includes": `["."]`,
1814 "min_sdk_version": `"5"`,
1815 "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`,
1816 }),
1817 },
1818 })
1819}
1820
1821func TestCcLibraryStaticWithSyspropSrcsSomeConfigs(t *testing.T) {
1822 runCcLibraryTestCase(t, Bp2buildTestCase{
1823 Description: "cc_library_static with sysprop sources in some configs but not others",
1824 Blueprint: `
1825cc_library_static {
1826 name: "foo",
1827 srcs: [
1828 "blah.cpp",
1829 ],
1830 target: {
1831 android: {
1832 srcs: ["bar.sysprop"],
1833 },
1834 },
1835 min_sdk_version: "5",
1836}`,
1837 ExpectedBazelTargets: []string{
1838 MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
1839 "srcs": `select({
1840 "//build/bazel/platforms/os:android": ["bar.sysprop"],
1841 "//conditions:default": [],
1842 })`,
1843 }),
1844 MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
1845 "dep": `":foo_sysprop_library"`,
1846 "min_sdk_version": `"5"`,
1847 }),
1848 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1849 "srcs": `["blah.cpp"]`,
1850 "local_includes": `["."]`,
1851 "min_sdk_version": `"5"`,
1852 "whole_archive_deps": `select({
1853 "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"],
1854 "//conditions:default": [],
1855 })`,
1856 }),
1857 },
1858 })
1859}
Trevor Radcliffedb7e0262022-10-28 16:48:18 +00001860
1861func TestCcLibraryStaticWithIntegerOverflowProperty(t *testing.T) {
1862 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1863 Description: "cc_library_static has correct features when integer_overflow property is provided",
1864 Blueprint: `
1865cc_library_static {
1866 name: "foo",
1867 sanitize: {
1868 integer_overflow: true,
1869 },
1870}
1871`,
1872 ExpectedBazelTargets: []string{
1873 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1874 "features": `["ubsan_integer_overflow"]`,
1875 "local_includes": `["."]`,
1876 }),
1877 },
1878 })
1879}
1880
1881func TestCcLibraryStaticWithMiscUndefinedProperty(t *testing.T) {
1882 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1883 Description: "cc_library_static has correct features when misc_undefined property is provided",
1884 Blueprint: `
1885cc_library_static {
1886 name: "foo",
1887 sanitize: {
1888 misc_undefined: ["undefined", "nullability"],
1889 },
1890}
1891`,
1892 ExpectedBazelTargets: []string{
1893 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1894 "features": `[
1895 "ubsan_undefined",
1896 "ubsan_nullability",
1897 ]`,
1898 "local_includes": `["."]`,
1899 }),
1900 },
1901 })
1902}
1903
1904func TestCcLibraryStaticWithUBSanPropertiesArchSpecific(t *testing.T) {
1905 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1906 Description: "cc_library_static has correct feature select when UBSan props are specified in arch specific blocks",
1907 Blueprint: `
1908cc_library_static {
1909 name: "foo",
1910 sanitize: {
1911 misc_undefined: ["undefined", "nullability"],
1912 },
1913 target: {
1914 android: {
1915 sanitize: {
1916 misc_undefined: ["alignment"],
1917 },
1918 },
1919 linux_glibc: {
1920 sanitize: {
1921 integer_overflow: true,
1922 },
1923 },
1924 },
1925}
1926`,
1927 ExpectedBazelTargets: []string{
1928 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1929 "features": `[
1930 "ubsan_undefined",
1931 "ubsan_nullability",
1932 ] + select({
1933 "//build/bazel/platforms/os:android": ["ubsan_alignment"],
1934 "//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"],
1935 "//conditions:default": [],
1936 })`,
1937 "local_includes": `["."]`,
1938 }),
1939 },
1940 })
1941}
Trevor Radcliffe56b1a2b2023-02-06 21:58:30 +00001942
Trevor Radcliffeded095c2023-06-12 19:18:28 +00001943func TestCcLibraryStaticWithSanitizerBlocklist(t *testing.T) {
1944 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1945 Description: "cc_library_static has correct features when sanitize.blocklist is provided",
1946 Blueprint: `
1947cc_library_static {
1948 name: "foo",
1949 sanitize: {
1950 blocklist: "foo_blocklist.txt",
1951 },
1952}
1953`,
1954 ExpectedBazelTargets: []string{
1955 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
Trevor Radcliffed9b7f172023-08-09 22:21:38 +00001956 "copts": `select({
1957 "//build/bazel/rules/cc:sanitizers_enabled": ["-fsanitize-ignorelist=$(location foo_blocklist.txt)"],
1958 "//conditions:default": [],
1959 })`,
1960 "additional_compiler_inputs": `select({
1961 "//build/bazel/rules/cc:sanitizers_enabled": [":foo_blocklist.txt"],
1962 "//conditions:default": [],
1963 })`,
Trevor Radcliffeded095c2023-06-12 19:18:28 +00001964 "local_includes": `["."]`,
1965 }),
1966 },
1967 })
1968}
1969
Trevor Radcliffe56b1a2b2023-02-06 21:58:30 +00001970func TestCcLibraryStaticWithThinLto(t *testing.T) {
1971 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1972 Description: "cc_library_static has correct features when thin lto is enabled",
1973 Blueprint: `
1974cc_library_static {
1975 name: "foo",
1976 lto: {
1977 thin: true,
1978 },
1979}
1980`,
1981 ExpectedBazelTargets: []string{
1982 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1983 "features": `["android_thin_lto"]`,
1984 "local_includes": `["."]`,
1985 }),
1986 },
1987 })
1988}
1989
1990func TestCcLibraryStaticWithLtoNever(t *testing.T) {
1991 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1992 Description: "cc_library_static has correct features when thin lto is enabled",
1993 Blueprint: `
1994cc_library_static {
1995 name: "foo",
1996 lto: {
1997 never: true,
1998 },
1999}
2000`,
2001 ExpectedBazelTargets: []string{
2002 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2003 "features": `["-android_thin_lto"]`,
2004 "local_includes": `["."]`,
2005 }),
2006 },
2007 })
2008}
2009
2010func TestCcLibraryStaticWithThinLtoArchSpecific(t *testing.T) {
2011 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2012 Description: "cc_library_static has correct features when LTO differs across arch and os variants",
2013 Blueprint: `
2014cc_library_static {
2015 name: "foo",
2016 target: {
2017 android: {
2018 lto: {
2019 thin: true,
2020 },
2021 },
2022 },
2023 arch: {
2024 riscv64: {
2025 lto: {
2026 thin: false,
2027 },
2028 },
2029 },
2030}`,
2031 ExpectedBazelTargets: []string{
2032 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2033 "local_includes": `["."]`,
2034 "features": `select({
2035 "//build/bazel/platforms/os_arch:android_arm": ["android_thin_lto"],
2036 "//build/bazel/platforms/os_arch:android_arm64": ["android_thin_lto"],
2037 "//build/bazel/platforms/os_arch:android_riscv64": ["-android_thin_lto"],
2038 "//build/bazel/platforms/os_arch:android_x86": ["android_thin_lto"],
2039 "//build/bazel/platforms/os_arch:android_x86_64": ["android_thin_lto"],
2040 "//conditions:default": [],
2041 })`}),
2042 },
2043 })
2044}
2045
2046func TestCcLibraryStaticWithThinLtoDisabledDefaultEnabledVariant(t *testing.T) {
2047 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2048 Description: "cc_library_static has correct features when LTO disabled by default but enabled on a particular variant",
2049 Blueprint: `
2050cc_library_static {
2051 name: "foo",
2052 lto: {
2053 never: true,
2054 },
2055 target: {
2056 android: {
2057 lto: {
2058 thin: true,
2059 never: false,
2060 },
2061 },
2062 },
2063}`,
2064 ExpectedBazelTargets: []string{
2065 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2066 "local_includes": `["."]`,
2067 "features": `select({
2068 "//build/bazel/platforms/os:android": ["android_thin_lto"],
2069 "//conditions:default": ["-android_thin_lto"],
2070 })`,
2071 }),
2072 },
2073 })
2074}
2075
2076func TestCcLibraryStaticWithThinLtoAndWholeProgramVtables(t *testing.T) {
2077 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2078 Description: "cc_library_static has correct features when thin lto is enabled with whole_program_vtables",
2079 Blueprint: `
2080cc_library_static {
2081 name: "foo",
2082 lto: {
2083 thin: true,
2084 },
2085 whole_program_vtables: true,
2086}
2087`,
2088 ExpectedBazelTargets: []string{
2089 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2090 "features": `[
2091 "android_thin_lto",
2092 "android_thin_lto_whole_program_vtables",
2093 ]`,
2094 "local_includes": `["."]`,
2095 }),
2096 },
2097 })
2098}
Trevor Radcliffea8b44162023-04-14 18:25:24 +00002099
2100func TestCcLibraryStaticHiddenVisibilityConvertedToFeature(t *testing.T) {
2101 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2102 Description: "cc_library_static changes hidden visibility flag to feature",
2103 Blueprint: `
2104cc_library_static {
2105 name: "foo",
2106 cflags: ["-fvisibility=hidden"],
2107}`,
2108 ExpectedBazelTargets: []string{
2109 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2110 "features": `["visibility_hidden"]`,
2111 "local_includes": `["."]`,
2112 }),
2113 },
2114 })
2115}
2116
2117func TestCcLibraryStaticHiddenVisibilityConvertedToFeatureOsSpecific(t *testing.T) {
2118 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2119 Description: "cc_library_static changes hidden visibility flag to feature for specific os",
2120 Blueprint: `
2121cc_library_static {
2122 name: "foo",
2123 target: {
2124 android: {
2125 cflags: ["-fvisibility=hidden"],
2126 },
2127 },
2128}`,
2129 ExpectedBazelTargets: []string{
2130 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2131 "features": `select({
2132 "//build/bazel/platforms/os:android": ["visibility_hidden"],
2133 "//conditions:default": [],
2134 })`,
2135 "local_includes": `["."]`,
2136 }),
2137 },
2138 })
2139}
Trevor Radcliffe27669c02023-03-28 20:47:10 +00002140
2141func TestCcLibraryStaticWithCfi(t *testing.T) {
2142 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2143 Description: "cc_library_static has correct features when cfi is enabled",
2144 Blueprint: `
2145cc_library_static {
2146 name: "foo",
2147 sanitize: {
2148 cfi: true,
2149 },
2150}`,
2151 ExpectedBazelTargets: []string{
2152 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2153 "features": `["android_cfi"]`,
2154 "local_includes": `["."]`,
2155 }),
2156 },
2157 })
2158}
2159
2160func TestCcLibraryStaticWithCfiOsSpecific(t *testing.T) {
2161 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2162 Description: "cc_library_static has correct features when cfi is enabled for specific variants",
2163 Blueprint: `
2164cc_library_static {
2165 name: "foo",
2166 target: {
2167 android: {
2168 sanitize: {
2169 cfi: true,
2170 },
2171 },
2172 },
2173}`,
2174 ExpectedBazelTargets: []string{
2175 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2176 "features": `select({
2177 "//build/bazel/platforms/os:android": ["android_cfi"],
2178 "//conditions:default": [],
2179 })`,
2180 "local_includes": `["."]`,
2181 }),
2182 },
2183 })
2184}
2185
2186func TestCcLibraryStaticWithCfiAndCfiAssemblySupport(t *testing.T) {
2187 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2188 Description: "cc_library_static has correct features when cfi is enabled with cfi_assembly_support",
2189 Blueprint: `
2190cc_library_static {
2191 name: "foo",
2192 sanitize: {
2193 cfi: true,
2194 config: {
2195 cfi_assembly_support: true,
2196 },
2197 },
2198}`,
2199 ExpectedBazelTargets: []string{
2200 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2201 "features": `[
2202 "android_cfi",
2203 "android_cfi_assembly_support",
2204 ]`,
2205 "local_includes": `["."]`,
2206 }),
2207 },
2208 })
2209}
Trevor Radcliffe523c5c62023-06-16 20:15:45 +00002210
2211func TestCcLibraryStaticExplicitlyDisablesCfiWhenFalse(t *testing.T) {
2212 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2213 Description: "cc_library_static disables cfi when explciitly set to false in the bp",
2214 Blueprint: `
2215cc_library_static {
2216 name: "foo",
2217 sanitize: {
2218 cfi: false,
2219 },
2220}
2221`,
2222 ExpectedBazelTargets: []string{
2223 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2224 "features": `["-android_cfi"]`,
2225 "local_includes": `["."]`,
2226 }),
2227 },
2228 })
2229}
Alixe2667872023-04-24 14:57:32 +00002230
2231func TestCCLibraryStaticRscriptSrc(t *testing.T) {
2232 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2233 Description: `cc_library_static with rscript files in sources`,
2234 Blueprint: `
2235cc_library_static{
2236 name : "foo",
2237 srcs : [
2238 "ccSrc.cc",
2239 "rsSrc.rscript",
2240 ],
2241 include_build_directory: false,
2242}
2243`,
2244 ExpectedBazelTargets: []string{
2245 MakeBazelTarget("rscript_to_cpp", "foo_renderscript", AttrNameToString{
2246 "srcs": `["rsSrc.rscript"]`,
2247 }),
2248 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2249 "absolute_includes": `[
2250 "frameworks/rs",
2251 "frameworks/rs/cpp",
2252 ]`,
2253 "local_includes": `["."]`,
2254 "srcs": `[
2255 "ccSrc.cc",
2256 "foo_renderscript",
2257 ]`,
2258 })}})
2259}
Spandan Dasa99348d2023-08-01 23:10:05 +00002260
2261func TestCcLibraryWithProtoInGeneratedSrcs(t *testing.T) {
2262 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2263 Description: "cc_library with a .proto file generated from a genrule",
2264 ModuleTypeUnderTest: "cc_library_static",
2265 ModuleTypeUnderTestFactory: cc.LibraryStaticFactory,
Chris Parsonscd209032023-09-19 01:12:48 +00002266 StubbedBuildDefinitions: []string{"libprotobuf-cpp-lite"},
Spandan Dasa99348d2023-08-01 23:10:05 +00002267 Blueprint: soongCcLibraryPreamble + `
2268cc_library_static {
2269 name: "mylib",
2270 generated_sources: ["myprotogen"],
2271}
2272genrule {
2273 name: "myprotogen",
2274 out: ["myproto.proto"],
2275}
Chris Parsonscd209032023-09-19 01:12:48 +00002276` + simpleModule("cc_library", "libprotobuf-cpp-lite"),
Spandan Dasa99348d2023-08-01 23:10:05 +00002277 ExpectedBazelTargets: []string{
2278 MakeBazelTarget("cc_library_static", "mylib", AttrNameToString{
2279 "local_includes": `["."]`,
2280 "deps": `[":libprotobuf-cpp-lite"]`,
2281 "implementation_whole_archive_deps": `[":mylib_cc_proto_lite"]`,
2282 }),
2283 MakeBazelTarget("cc_lite_proto_library", "mylib_cc_proto_lite", AttrNameToString{
2284 "deps": `[":mylib_proto"]`,
2285 }),
2286 MakeBazelTarget("proto_library", "mylib_proto", AttrNameToString{
2287 "srcs": `[":myprotogen"]`,
2288 }),
2289 MakeBazelTargetNoRestrictions("genrule", "myprotogen", AttrNameToString{
2290 "cmd": `""`,
2291 "outs": `["myproto.proto"]`,
2292 }),
2293 },
2294 })
2295}