blob: 8084a5d8ee05574f3d4651d39b4cbebe889d538c [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 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +000099 Blueprint: soongCcLibraryStaticPreamble + `
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000100cc_library_headers {
101 name: "header_lib_1",
102 export_include_dirs: ["header_lib_1"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400103 bazel_module: { bp2build_available: false },
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000104}
105
106cc_library_headers {
107 name: "header_lib_2",
108 export_include_dirs: ["header_lib_2"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400109 bazel_module: { bp2build_available: false },
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000110}
111
112cc_library_static {
113 name: "static_lib_1",
114 srcs: ["static_lib_1.cc"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400115 bazel_module: { bp2build_available: false },
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000116}
117
118cc_library_static {
119 name: "static_lib_2",
120 srcs: ["static_lib_2.cc"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400121 bazel_module: { bp2build_available: false },
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000122}
123
124cc_library_static {
125 name: "whole_static_lib_1",
126 srcs: ["whole_static_lib_1.cc"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400127 bazel_module: { bp2build_available: false },
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000128}
129
130cc_library_static {
131 name: "whole_static_lib_2",
132 srcs: ["whole_static_lib_2.cc"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400133 bazel_module: { bp2build_available: false },
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000134}
135
136cc_library_static {
137 name: "foo_static",
138 srcs: [
139 "foo_static1.cc",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000140 "foo_static2.cc",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000141 ],
142 cflags: [
143 "-Dflag1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000144 "-Dflag2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000145 ],
146 static_libs: [
147 "static_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000148 "static_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000149 ],
150 whole_static_libs: [
151 "whole_static_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000152 "whole_static_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000153 ],
154 include_dirs: [
Jingwen Chened9c17d2021-04-13 07:14:55 +0000155 "include_dir_1",
156 "include_dir_2",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000157 ],
158 local_include_dirs: [
159 "local_include_dir_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000160 "local_include_dir_2",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000161 ],
162 export_include_dirs: [
Chris Parsonsd6358772021-05-18 18:35:24 -0400163 "export_include_dir_1",
164 "export_include_dir_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000165 ],
166 header_libs: [
167 "header_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000168 "header_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000169 ],
Yu Liufc603162022-03-01 15:44:08 -0800170 sdk_version: "current",
171 min_sdk_version: "29",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000172
173 // TODO: Also support export_header_lib_headers
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000174}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000175 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000176 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500177 "absolute_includes": `[
Liz Kammer35687bc2021-09-10 10:07:07 -0400178 "include_dir_1",
179 "include_dir_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500180 ]`,
181 "copts": `[
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000182 "-Dflag1",
183 "-Dflag2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500184 ]`,
185 "export_includes": `[
Liz Kammer5fad5012021-09-09 14:08:21 -0400186 "export_include_dir_1",
187 "export_include_dir_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500188 ]`,
189 "implementation_deps": `[
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000190 ":header_lib_1",
191 ":header_lib_2",
192 ":static_lib_1",
193 ":static_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500194 ]`,
195 "local_includes": `[
Liz Kammer35687bc2021-09-10 10:07:07 -0400196 "local_include_dir_1",
197 "local_include_dir_2",
198 ".",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500199 ]`,
200 "srcs": `[
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000201 "foo_static1.cc",
202 "foo_static2.cc",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500203 ]`,
204 "whole_archive_deps": `[
Chris Parsons08648312021-05-06 16:23:19 -0400205 ":whole_static_lib_1",
206 ":whole_static_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500207 ]`,
Liz Kammer7128d382022-05-12 11:42:33 -0400208 "sdk_version": `"current"`,
209 "min_sdk_version": `"29"`,
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{
395 Description: "cc_library_static arch-specific static_libs",
396 Filesystem: map[string]string{},
397 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -0400398cc_library_static {
399 name: "static_dep",
400 bazel_module: { bp2build_available: false },
401}
402cc_library_static {
403 name: "static_dep2",
404 bazel_module: { bp2build_available: false },
405}
Jingwen Chened9c17d2021-04-13 07:14:55 +0000406cc_library_static {
407 name: "foo_static",
408 arch: { arm64: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } },
Liz Kammer8337ea42021-09-10 10:06:32 -0400409 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000410}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000411 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000412 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500413 "implementation_deps": `select({
Chris Parsons08648312021-05-06 16:23:19 -0400414 "//build/bazel/platforms/arch:arm64": [":static_dep"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000415 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500416 })`,
417 "whole_archive_deps": `select({
Chris Parsons08648312021-05-06 16:23:19 -0400418 "//build/bazel/platforms/arch:arm64": [":static_dep2"],
419 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500420 })`,
421 }),
422 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200423 })
424}
425
426func TestCcLibraryStaticOsSpecificStaticLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000427 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
428 Description: "cc_library_static os-specific static_libs",
429 Filesystem: map[string]string{},
430 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -0400431cc_library_static {
432 name: "static_dep",
433 bazel_module: { bp2build_available: false },
434}
435cc_library_static {
436 name: "static_dep2",
437 bazel_module: { bp2build_available: false },
438}
Jingwen Chened9c17d2021-04-13 07:14:55 +0000439cc_library_static {
440 name: "foo_static",
441 target: { android: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } },
Liz Kammer8337ea42021-09-10 10:06:32 -0400442 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000443}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000444 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000445 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500446 "implementation_deps": `select({
Chris Parsons08648312021-05-06 16:23:19 -0400447 "//build/bazel/platforms/os:android": [":static_dep"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000448 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500449 })`,
450 "whole_archive_deps": `select({
Chris Parsons08648312021-05-06 16:23:19 -0400451 "//build/bazel/platforms/os:android": [":static_dep2"],
452 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500453 })`,
454 }),
455 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200456 })
457}
458
459func TestCcLibraryStaticBaseArchOsSpecificStaticLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000460 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
461 Description: "cc_library_static base, arch and os-specific static_libs",
462 Filesystem: map[string]string{},
463 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -0400464cc_library_static {
465 name: "static_dep",
466 bazel_module: { bp2build_available: false },
467}
468cc_library_static {
469 name: "static_dep2",
470 bazel_module: { bp2build_available: false },
471}
472cc_library_static {
473 name: "static_dep3",
474 bazel_module: { bp2build_available: false },
475}
476cc_library_static {
477 name: "static_dep4",
478 bazel_module: { bp2build_available: false },
479}
Jingwen Chened9c17d2021-04-13 07:14:55 +0000480cc_library_static {
481 name: "foo_static",
482 static_libs: ["static_dep"],
483 whole_static_libs: ["static_dep2"],
484 target: { android: { static_libs: ["static_dep3"] } },
485 arch: { arm64: { static_libs: ["static_dep4"] } },
Liz Kammer8337ea42021-09-10 10:06:32 -0400486 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000487}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000488 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000489 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500490 "implementation_deps": `[":static_dep"] + select({
Jingwen Chened9c17d2021-04-13 07:14:55 +0000491 "//build/bazel/platforms/arch:arm64": [":static_dep4"],
492 "//conditions:default": [],
493 }) + select({
494 "//build/bazel/platforms/os:android": [":static_dep3"],
495 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500496 })`,
497 "whole_archive_deps": `[":static_dep2"]`,
498 }),
499 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200500 })
501}
502
503func TestCcLibraryStaticSimpleExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000504 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
505 Description: "cc_library_static simple exclude_srcs",
506 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200507 "common.c": "",
508 "foo-a.c": "",
509 "foo-excluded.c": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000510 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000511 Blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000512cc_library_static {
513 name: "foo_static",
514 srcs: ["common.c", "foo-*.c"],
515 exclude_srcs: ["foo-excluded.c"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400516 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000517}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000518 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000519 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500520 "srcs_c": `[
Jingwen Chene32e9e02021-04-23 09:17:24 +0000521 "common.c",
522 "foo-a.c",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500523 ]`,
524 }),
525 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200526 })
527}
528
529func TestCcLibraryStaticOneArchSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000530 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
531 Description: "cc_library_static one arch specific srcs",
532 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200533 "common.c": "",
534 "foo-arm.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000535 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000536 Blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000537cc_library_static {
538 name: "foo_static",
539 srcs: ["common.c"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400540 arch: { arm: { srcs: ["foo-arm.c"] } },
541 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000542}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000543 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000544 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500545 "srcs_c": `["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000546 "//build/bazel/platforms/arch:arm": ["foo-arm.c"],
547 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500548 })`,
549 }),
550 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200551 })
552}
553
554func TestCcLibraryStaticOneArchSrcsExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000555 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
556 Description: "cc_library_static one arch specific srcs and exclude_srcs",
557 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200558 "common.c": "",
559 "for-arm.c": "",
560 "not-for-arm.c": "",
561 "not-for-anything.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000562 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000563 Blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000564cc_library_static {
565 name: "foo_static",
566 srcs: ["common.c", "not-for-*.c"],
567 exclude_srcs: ["not-for-anything.c"],
568 arch: {
569 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
570 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400571 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000572}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000573 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000574 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500575 "srcs_c": `["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000576 "//build/bazel/platforms/arch:arm": ["for-arm.c"],
577 "//conditions:default": ["not-for-arm.c"],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500578 })`,
579 }),
580 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200581 })
582}
583
584func TestCcLibraryStaticTwoArchExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000585 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
586 Description: "cc_library_static arch specific exclude_srcs for 2 architectures",
587 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200588 "common.c": "",
589 "for-arm.c": "",
590 "for-x86.c": "",
591 "not-for-arm.c": "",
592 "not-for-x86.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000593 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000594 Blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000595cc_library_static {
596 name: "foo_static",
597 srcs: ["common.c", "not-for-*.c"],
598 exclude_srcs: ["not-for-everything.c"],
599 arch: {
600 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
601 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
602 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400603 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000604} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000605 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000606 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500607 "srcs_c": `["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000608 "//build/bazel/platforms/arch:arm": [
Jingwen Chene32e9e02021-04-23 09:17:24 +0000609 "not-for-x86.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400610 "for-arm.c",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000611 ],
612 "//build/bazel/platforms/arch:x86": [
Jingwen Chene32e9e02021-04-23 09:17:24 +0000613 "not-for-arm.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400614 "for-x86.c",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000615 ],
616 "//conditions:default": [
617 "not-for-arm.c",
618 "not-for-x86.c",
619 ],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500620 })`,
621 }),
622 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200623 })
624}
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500625
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200626func TestCcLibraryStaticFourArchExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000627 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
628 Description: "cc_library_static arch specific exclude_srcs for 4 architectures",
629 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200630 "common.c": "",
631 "for-arm.c": "",
632 "for-arm64.c": "",
633 "for-x86.c": "",
634 "for-x86_64.c": "",
635 "not-for-arm.c": "",
636 "not-for-arm64.c": "",
637 "not-for-x86.c": "",
638 "not-for-x86_64.c": "",
639 "not-for-everything.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000640 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000641 Blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000642cc_library_static {
643 name: "foo_static",
644 srcs: ["common.c", "not-for-*.c"],
645 exclude_srcs: ["not-for-everything.c"],
646 arch: {
647 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
648 arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] },
649 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
650 x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] },
Liz Kammer8337ea42021-09-10 10:06:32 -0400651 },
652 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000653} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000654 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000655 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500656 "srcs_c": `["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000657 "//build/bazel/platforms/arch:arm": [
Jingwen Chene32e9e02021-04-23 09:17:24 +0000658 "not-for-arm64.c",
659 "not-for-x86.c",
660 "not-for-x86_64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400661 "for-arm.c",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000662 ],
663 "//build/bazel/platforms/arch:arm64": [
Jingwen Chene32e9e02021-04-23 09:17:24 +0000664 "not-for-arm.c",
665 "not-for-x86.c",
666 "not-for-x86_64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400667 "for-arm64.c",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000668 ],
669 "//build/bazel/platforms/arch:x86": [
Jingwen Chene32e9e02021-04-23 09:17:24 +0000670 "not-for-arm.c",
671 "not-for-arm64.c",
672 "not-for-x86_64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400673 "for-x86.c",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000674 ],
675 "//build/bazel/platforms/arch:x86_64": [
Jingwen Chene32e9e02021-04-23 09:17:24 +0000676 "not-for-arm.c",
677 "not-for-arm64.c",
678 "not-for-x86.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400679 "for-x86_64.c",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000680 ],
681 "//conditions:default": [
682 "not-for-arm.c",
683 "not-for-arm64.c",
684 "not-for-x86.c",
685 "not-for-x86_64.c",
686 ],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500687 })`,
688 }),
689 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200690 })
691}
692
Liz Kammer2b07ec72021-05-26 15:08:27 -0400693func TestCcLibraryStaticOneArchEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000694 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
695 Description: "cc_library_static one arch empty",
696 Filesystem: map[string]string{
Liz Kammer2b07ec72021-05-26 15:08:27 -0400697 "common.cc": "",
698 "foo-no-arm.cc": "",
699 "foo-excluded.cc": "",
700 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000701 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer2b07ec72021-05-26 15:08:27 -0400702cc_library_static {
703 name: "foo_static",
704 srcs: ["common.cc", "foo-*.cc"],
705 exclude_srcs: ["foo-excluded.cc"],
706 arch: {
707 arm: { exclude_srcs: ["foo-no-arm.cc"] },
708 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400709 include_build_directory: false,
Liz Kammer2b07ec72021-05-26 15:08:27 -0400710}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000711 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000712 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500713 "srcs": `["common.cc"] + select({
Liz Kammer2b07ec72021-05-26 15:08:27 -0400714 "//build/bazel/platforms/arch:arm": [],
715 "//conditions:default": ["foo-no-arm.cc"],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500716 })`,
717 }),
718 },
Liz Kammer2b07ec72021-05-26 15:08:27 -0400719 })
720}
721
722func TestCcLibraryStaticOneArchEmptyOtherSet(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000723 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
724 Description: "cc_library_static one arch empty other set",
725 Filesystem: map[string]string{
Liz Kammer2b07ec72021-05-26 15:08:27 -0400726 "common.cc": "",
727 "foo-no-arm.cc": "",
728 "x86-only.cc": "",
729 "foo-excluded.cc": "",
730 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000731 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer2b07ec72021-05-26 15:08:27 -0400732cc_library_static {
733 name: "foo_static",
734 srcs: ["common.cc", "foo-*.cc"],
735 exclude_srcs: ["foo-excluded.cc"],
736 arch: {
737 arm: { exclude_srcs: ["foo-no-arm.cc"] },
738 x86: { srcs: ["x86-only.cc"] },
739 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400740 include_build_directory: false,
Liz Kammer2b07ec72021-05-26 15:08:27 -0400741}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000742 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000743 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500744 "srcs": `["common.cc"] + select({
Liz Kammer2b07ec72021-05-26 15:08:27 -0400745 "//build/bazel/platforms/arch:arm": [],
746 "//build/bazel/platforms/arch:x86": [
747 "foo-no-arm.cc",
748 "x86-only.cc",
749 ],
750 "//conditions:default": ["foo-no-arm.cc"],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500751 })`,
752 }),
753 },
Liz Kammer2b07ec72021-05-26 15:08:27 -0400754 })
755}
756
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200757func TestCcLibraryStaticMultipleDepSameName(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000758 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
759 Description: "cc_library_static multiple dep same name panic",
760 Filesystem: map[string]string{},
761 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -0400762cc_library_static {
763 name: "static_dep",
764 bazel_module: { bp2build_available: false },
765}
Liz Kammer2b50ce62021-04-26 15:47:28 -0400766cc_library_static {
767 name: "foo_static",
Chris Parsons08648312021-05-06 16:23:19 -0400768 static_libs: ["static_dep", "static_dep"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400769 include_build_directory: false,
Liz Kammer2b50ce62021-04-26 15:47:28 -0400770}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000771 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000772 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500773 "implementation_deps": `[":static_dep"]`,
774 }),
775 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200776 })
777}
778
779func TestCcLibraryStaticOneMultilibSrcsExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000780 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
781 Description: "cc_library_static 1 multilib srcs and exclude_srcs",
782 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200783 "common.c": "",
784 "for-lib32.c": "",
785 "not-for-lib32.c": "",
Liz Kammer2b50ce62021-04-26 15:47:28 -0400786 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000787 Blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -0400788cc_library_static {
789 name: "foo_static",
790 srcs: ["common.c", "not-for-*.c"],
791 multilib: {
792 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
793 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400794 include_build_directory: false,
Chris Parsonsc424b762021-04-29 18:06:50 -0400795} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000796 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000797 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500798 "srcs_c": `["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -0400799 "//build/bazel/platforms/arch:arm": ["for-lib32.c"],
800 "//build/bazel/platforms/arch:x86": ["for-lib32.c"],
801 "//conditions:default": ["not-for-lib32.c"],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500802 })`,
803 }),
804 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200805 })
806}
807
808func TestCcLibraryStaticTwoMultilibSrcsExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000809 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
810 Description: "cc_library_static 2 multilib srcs and exclude_srcs",
811 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200812 "common.c": "",
813 "for-lib32.c": "",
814 "for-lib64.c": "",
815 "not-for-lib32.c": "",
816 "not-for-lib64.c": "",
Chris Parsonsc424b762021-04-29 18:06:50 -0400817 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000818 Blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -0400819cc_library_static {
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500820 name: "foo_static",
Chris Parsonsc424b762021-04-29 18:06:50 -0400821 srcs: ["common.c", "not-for-*.c"],
822 multilib: {
823 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
824 lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] },
825 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400826 include_build_directory: false,
Chris Parsonsc424b762021-04-29 18:06:50 -0400827} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000828 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000829 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500830 "srcs_c": `["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -0400831 "//build/bazel/platforms/arch:arm": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400832 "not-for-lib64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400833 "for-lib32.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400834 ],
835 "//build/bazel/platforms/arch:arm64": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400836 "not-for-lib32.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400837 "for-lib64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400838 ],
Colin Crossf05b0d32022-07-14 18:10:34 -0700839 "//build/bazel/platforms/arch:riscv64": [
840 "not-for-lib32.c",
841 "for-lib64.c",
842 ],
Chris Parsonsc424b762021-04-29 18:06:50 -0400843 "//build/bazel/platforms/arch:x86": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400844 "not-for-lib64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400845 "for-lib32.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400846 ],
847 "//build/bazel/platforms/arch:x86_64": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400848 "not-for-lib32.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400849 "for-lib64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400850 ],
851 "//conditions:default": [
852 "not-for-lib32.c",
853 "not-for-lib64.c",
854 ],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500855 })`,
856 }),
857 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200858 })
859}
860
861func TestCcLibrarySTaticArchMultilibSrcsExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000862 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
863 Description: "cc_library_static arch and multilib srcs and exclude_srcs",
864 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200865 "common.c": "",
866 "for-arm.c": "",
867 "for-arm64.c": "",
868 "for-x86.c": "",
869 "for-x86_64.c": "",
870 "for-lib32.c": "",
871 "for-lib64.c": "",
872 "not-for-arm.c": "",
873 "not-for-arm64.c": "",
Colin Crossf05b0d32022-07-14 18:10:34 -0700874 "not-for-riscv64.c": "",
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200875 "not-for-x86.c": "",
876 "not-for-x86_64.c": "",
877 "not-for-lib32.c": "",
878 "not-for-lib64.c": "",
879 "not-for-everything.c": "",
Chris Parsonsc424b762021-04-29 18:06:50 -0400880 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000881 Blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -0400882cc_library_static {
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500883 name: "foo_static",
Chris Parsonsc424b762021-04-29 18:06:50 -0400884 srcs: ["common.c", "not-for-*.c"],
885 exclude_srcs: ["not-for-everything.c"],
886 arch: {
887 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
888 arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] },
Colin Crossf05b0d32022-07-14 18:10:34 -0700889 riscv64: { srcs: ["for-riscv64.c"], exclude_srcs: ["not-for-riscv64.c"] },
Chris Parsonsc424b762021-04-29 18:06:50 -0400890 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
891 x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] },
892 },
893 multilib: {
894 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
895 lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] },
896 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400897 include_build_directory: false,
Chris Parsonsc424b762021-04-29 18:06:50 -0400898}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000899 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000900 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500901 "srcs_c": `["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -0400902 "//build/bazel/platforms/arch:arm": [
Liz Kammer9bad9d62021-10-11 15:40:35 -0400903 "not-for-arm64.c",
904 "not-for-lib64.c",
Colin Crossf05b0d32022-07-14 18:10:34 -0700905 "not-for-riscv64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400906 "not-for-x86.c",
907 "not-for-x86_64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400908 "for-arm.c",
909 "for-lib32.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400910 ],
911 "//build/bazel/platforms/arch:arm64": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400912 "not-for-arm.c",
913 "not-for-lib32.c",
Colin Crossf05b0d32022-07-14 18:10:34 -0700914 "not-for-riscv64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400915 "not-for-x86.c",
916 "not-for-x86_64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400917 "for-arm64.c",
918 "for-lib64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400919 ],
Colin Crossf05b0d32022-07-14 18:10:34 -0700920 "//build/bazel/platforms/arch:riscv64": [
921 "not-for-arm.c",
922 "not-for-arm64.c",
923 "not-for-lib32.c",
924 "not-for-x86.c",
925 "not-for-x86_64.c",
926 "for-riscv64.c",
927 "for-lib64.c",
928 ],
Chris Parsonsc424b762021-04-29 18:06:50 -0400929 "//build/bazel/platforms/arch:x86": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400930 "not-for-arm.c",
931 "not-for-arm64.c",
932 "not-for-lib64.c",
Colin Crossf05b0d32022-07-14 18:10:34 -0700933 "not-for-riscv64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400934 "not-for-x86_64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400935 "for-x86.c",
936 "for-lib32.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400937 ],
938 "//build/bazel/platforms/arch:x86_64": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400939 "not-for-arm.c",
940 "not-for-arm64.c",
941 "not-for-lib32.c",
Colin Crossf05b0d32022-07-14 18:10:34 -0700942 "not-for-riscv64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400943 "not-for-x86.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400944 "for-x86_64.c",
945 "for-lib64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400946 ],
947 "//conditions:default": [
948 "not-for-arm.c",
949 "not-for-arm64.c",
950 "not-for-lib32.c",
951 "not-for-lib64.c",
Colin Crossf05b0d32022-07-14 18:10:34 -0700952 "not-for-riscv64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400953 "not-for-x86.c",
954 "not-for-x86_64.c",
955 ],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500956 })`,
957 }),
958 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200959 })
960}
961
Liz Kammerae3994e2021-10-19 09:45:48 -0400962func TestCcLibraryStaticGeneratedHeadersAllPartitions(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000963 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
964 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammerae3994e2021-10-19 09:45:48 -0400965genrule {
966 name: "generated_hdr",
967 cmd: "nothing to see here",
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400968 bazel_module: { bp2build_available: false },
Liz Kammerae3994e2021-10-19 09:45:48 -0400969}
970
Liz Kammere6583482021-10-19 13:56:10 -0400971genrule {
972 name: "export_generated_hdr",
973 cmd: "nothing to see here",
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400974 bazel_module: { bp2build_available: false },
Liz Kammere6583482021-10-19 13:56:10 -0400975}
976
Liz Kammerae3994e2021-10-19 09:45:48 -0400977cc_library_static {
978 name: "foo_static",
979 srcs: ["cpp_src.cpp", "as_src.S", "c_src.c"],
Liz Kammere6583482021-10-19 13:56:10 -0400980 generated_headers: ["generated_hdr", "export_generated_hdr"],
981 export_generated_headers: ["export_generated_hdr"],
Liz Kammerae3994e2021-10-19 09:45:48 -0400982 include_build_directory: false,
983}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000984 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000985 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer1263d9b2021-12-10 14:28:20 -0500986 "export_includes": `["."]`,
987 "local_includes": `["."]`,
988 "hdrs": `[":export_generated_hdr"]`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500989 "srcs": `[
Liz Kammerae3994e2021-10-19 09:45:48 -0400990 "cpp_src.cpp",
991 ":generated_hdr",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500992 ]`,
993 "srcs_as": `[
Liz Kammerae3994e2021-10-19 09:45:48 -0400994 "as_src.S",
995 ":generated_hdr",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500996 ]`,
997 "srcs_c": `[
Liz Kammerae3994e2021-10-19 09:45:48 -0400998 "c_src.c",
999 ":generated_hdr",
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001000 ]`,
1001 }),
1002 },
Liz Kammerae3994e2021-10-19 09:45:48 -04001003 })
1004}
1005
Zi Wang9f609db2023-01-04 11:06:54 -08001006// generated_headers has "variant_prepend" tag. In bp2build output,
1007// variant info(select) should go before general info.
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001008func TestCcLibraryStaticArchSrcsExcludeSrcsGeneratedFiles(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001009 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1010 Description: "cc_library_static arch srcs/exclude_srcs with generated files",
1011 Filesystem: map[string]string{
Chris Parsons990c4f42021-05-25 12:10:58 -04001012 "common.cpp": "",
1013 "for-x86.cpp": "",
1014 "not-for-x86.cpp": "",
1015 "not-for-everything.cpp": "",
Liz Kammerbe46fcc2021-11-01 15:32:43 -04001016 "dep/Android.bp": simpleModuleDoNotConvertBp2build("genrule", "generated_src_other_pkg") +
1017 simpleModuleDoNotConvertBp2build("genrule", "generated_hdr_other_pkg") +
1018 simpleModuleDoNotConvertBp2build("genrule", "generated_src_other_pkg_x86") +
1019 simpleModuleDoNotConvertBp2build("genrule", "generated_hdr_other_pkg_x86") +
1020 simpleModuleDoNotConvertBp2build("genrule", "generated_hdr_other_pkg_android"),
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001021 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001022 Blueprint: soongCcLibraryStaticPreamble +
Liz Kammerbe46fcc2021-11-01 15:32:43 -04001023 simpleModuleDoNotConvertBp2build("genrule", "generated_src") +
1024 simpleModuleDoNotConvertBp2build("genrule", "generated_src_not_x86") +
1025 simpleModuleDoNotConvertBp2build("genrule", "generated_src_android") +
1026 simpleModuleDoNotConvertBp2build("genrule", "generated_hdr") + `
Chris Parsons484e50a2021-05-13 15:13:04 -04001027cc_library_static {
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001028 name: "foo_static",
Liz Kammer222bdcf2021-10-11 14:15:51 -04001029 srcs: ["common.cpp", "not-for-*.cpp"],
1030 exclude_srcs: ["not-for-everything.cpp"],
1031 generated_sources: ["generated_src", "generated_src_other_pkg", "generated_src_not_x86"],
1032 generated_headers: ["generated_hdr", "generated_hdr_other_pkg"],
Liz Kammer1263d9b2021-12-10 14:28:20 -05001033 export_generated_headers: ["generated_hdr_other_pkg"],
Liz Kammer222bdcf2021-10-11 14:15:51 -04001034 arch: {
1035 x86: {
1036 srcs: ["for-x86.cpp"],
1037 exclude_srcs: ["not-for-x86.cpp"],
1038 generated_headers: ["generated_hdr_other_pkg_x86"],
1039 exclude_generated_sources: ["generated_src_not_x86"],
Liz Kammer1263d9b2021-12-10 14:28:20 -05001040 export_generated_headers: ["generated_hdr_other_pkg_x86"],
Liz Kammer222bdcf2021-10-11 14:15:51 -04001041 },
1042 },
1043 target: {
1044 android: {
1045 generated_sources: ["generated_src_android"],
1046 generated_headers: ["generated_hdr_other_pkg_android"],
Liz Kammer1263d9b2021-12-10 14:28:20 -05001047 export_generated_headers: ["generated_hdr_other_pkg_android"],
Liz Kammer222bdcf2021-10-11 14:15:51 -04001048 },
1049 },
1050
Liz Kammer8337ea42021-09-10 10:06:32 -04001051 include_build_directory: false,
Chris Parsons484e50a2021-05-13 15:13:04 -04001052}
1053`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001054 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001055 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001056 "srcs": `[
Chris Parsons990c4f42021-05-25 12:10:58 -04001057 "common.cpp",
Liz Kammer9bad9d62021-10-11 15:40:35 -04001058 ":generated_src",
1059 "//dep:generated_src_other_pkg",
Liz Kammerae3994e2021-10-19 09:45:48 -04001060 ":generated_hdr",
Chris Parsons484e50a2021-05-13 15:13:04 -04001061 ] + select({
Liz Kammer1263d9b2021-12-10 14:28:20 -05001062 "//build/bazel/platforms/arch:x86": ["for-x86.cpp"],
Liz Kammer222bdcf2021-10-11 14:15:51 -04001063 "//conditions:default": [
Liz Kammer222bdcf2021-10-11 14:15:51 -04001064 "not-for-x86.cpp",
Liz Kammer9bad9d62021-10-11 15:40:35 -04001065 ":generated_src_not_x86",
Liz Kammer222bdcf2021-10-11 14:15:51 -04001066 ],
1067 }) + select({
Liz Kammer1263d9b2021-12-10 14:28:20 -05001068 "//build/bazel/platforms/os:android": [":generated_src_android"],
Liz Kammer222bdcf2021-10-11 14:15:51 -04001069 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001070 })`,
Zi Wang9f609db2023-01-04 11:06:54 -08001071 "hdrs": `select({
Liz Kammer1263d9b2021-12-10 14:28:20 -05001072 "//build/bazel/platforms/os:android": ["//dep:generated_hdr_other_pkg_android"],
1073 "//conditions:default": [],
Zi Wang9f609db2023-01-04 11:06:54 -08001074 }) + select({
1075 "//build/bazel/platforms/arch:x86": ["//dep:generated_hdr_other_pkg_x86"],
1076 "//conditions:default": [],
1077 }) + ["//dep:generated_hdr_other_pkg"]`,
Liz Kammer1263d9b2021-12-10 14:28:20 -05001078 "local_includes": `["."]`,
1079 "export_absolute_includes": `["dep"]`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001080 }),
1081 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001082 })
Rupert Shuttleworth095081c2021-03-25 09:06:03 +00001083}
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001084
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001085func TestCcLibraryStaticGetTargetProperties(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001086 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001087
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001088 Description: "cc_library_static complex GetTargetProperties",
1089 Blueprint: soongCcLibraryStaticPreamble + `
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001090cc_library_static {
1091 name: "foo_static",
1092 target: {
1093 android: {
1094 srcs: ["android_src.c"],
1095 },
1096 android_arm: {
1097 srcs: ["android_arm_src.c"],
1098 },
1099 android_arm64: {
1100 srcs: ["android_arm64_src.c"],
1101 },
1102 android_x86: {
1103 srcs: ["android_x86_src.c"],
1104 },
1105 android_x86_64: {
1106 srcs: ["android_x86_64_src.c"],
1107 },
1108 linux_bionic_arm64: {
1109 srcs: ["linux_bionic_arm64_src.c"],
1110 },
1111 linux_bionic_x86_64: {
1112 srcs: ["linux_bionic_x86_64_src.c"],
1113 },
1114 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001115 include_build_directory: false,
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001116}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001117 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001118 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001119 "srcs_c": `select({
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001120 "//build/bazel/platforms/os:android": ["android_src.c"],
1121 "//conditions:default": [],
1122 }) + select({
Rupert Shuttleworthffd45822021-05-14 03:02:34 -04001123 "//build/bazel/platforms/os_arch:android_arm": ["android_arm_src.c"],
1124 "//build/bazel/platforms/os_arch:android_arm64": ["android_arm64_src.c"],
1125 "//build/bazel/platforms/os_arch:android_x86": ["android_x86_src.c"],
1126 "//build/bazel/platforms/os_arch:android_x86_64": ["android_x86_64_src.c"],
Rupert Shuttleworthffd45822021-05-14 03:02:34 -04001127 "//build/bazel/platforms/os_arch:linux_bionic_arm64": ["linux_bionic_arm64_src.c"],
1128 "//build/bazel/platforms/os_arch:linux_bionic_x86_64": ["linux_bionic_x86_64_src.c"],
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001129 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001130 })`,
1131 }),
1132 },
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001133 })
1134}
1135
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001136func TestCcLibraryStaticProductVariableSelects(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001137 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1138 Description: "cc_library_static product variable selects",
1139 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001140cc_library_static {
1141 name: "foo_static",
1142 srcs: ["common.c"],
1143 product_variables: {
1144 malloc_not_svelte: {
1145 cflags: ["-Wmalloc_not_svelte"],
1146 },
1147 malloc_zero_contents: {
1148 cflags: ["-Wmalloc_zero_contents"],
1149 },
1150 binder32bit: {
1151 cflags: ["-Wbinder32bit"],
1152 },
1153 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001154 include_build_directory: false,
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001155} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001156 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001157 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001158 "copts": `select({
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001159 "//build/bazel/product_variables:binder32bit": ["-Wbinder32bit"],
1160 "//conditions:default": [],
1161 }) + select({
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001162 "//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"],
1163 "//conditions:default": [],
1164 }) + select({
1165 "//build/bazel/product_variables:malloc_zero_contents": ["-Wmalloc_zero_contents"],
1166 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001167 })`,
1168 "srcs_c": `["common.c"]`,
1169 }),
1170 },
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001171 })
1172}
1173
1174func TestCcLibraryStaticProductVariableArchSpecificSelects(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001175 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1176 Description: "cc_library_static arch-specific product variable selects",
1177 Filesystem: map[string]string{},
1178 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001179cc_library_static {
1180 name: "foo_static",
1181 srcs: ["common.c"],
1182 product_variables: {
1183 malloc_not_svelte: {
1184 cflags: ["-Wmalloc_not_svelte"],
1185 },
1186 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001187 arch: {
1188 arm64: {
1189 product_variables: {
1190 malloc_not_svelte: {
1191 cflags: ["-Warm64_malloc_not_svelte"],
1192 },
1193 },
1194 },
1195 },
1196 multilib: {
1197 lib32: {
1198 product_variables: {
1199 malloc_not_svelte: {
1200 cflags: ["-Wlib32_malloc_not_svelte"],
1201 },
1202 },
1203 },
1204 },
1205 target: {
1206 android: {
1207 product_variables: {
1208 malloc_not_svelte: {
1209 cflags: ["-Wandroid_malloc_not_svelte"],
1210 },
1211 },
1212 }
1213 },
1214 include_build_directory: false,
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001215} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001216 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001217 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001218 "copts": `select({
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001219 "//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"],
1220 "//conditions:default": [],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001221 }) + select({
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001222 "//build/bazel/product_variables:malloc_not_svelte-android": ["-Wandroid_malloc_not_svelte"],
1223 "//conditions:default": [],
1224 }) + select({
1225 "//build/bazel/product_variables:malloc_not_svelte-arm": ["-Wlib32_malloc_not_svelte"],
1226 "//conditions:default": [],
1227 }) + select({
1228 "//build/bazel/product_variables:malloc_not_svelte-arm64": ["-Warm64_malloc_not_svelte"],
1229 "//conditions:default": [],
1230 }) + select({
1231 "//build/bazel/product_variables:malloc_not_svelte-x86": ["-Wlib32_malloc_not_svelte"],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001232 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001233 })`,
1234 "srcs_c": `["common.c"]`,
1235 }),
1236 },
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001237 })
1238}
Liz Kammerba7a9c52021-05-26 08:45:30 -04001239
1240func TestCcLibraryStaticProductVariableStringReplacement(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001241 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1242 Description: "cc_library_static product variable string replacement",
1243 Filesystem: map[string]string{},
1244 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammerba7a9c52021-05-26 08:45:30 -04001245cc_library_static {
1246 name: "foo_static",
Chris Parsons69fa9f92021-07-13 11:47:44 -04001247 srcs: ["common.S"],
Liz Kammerba7a9c52021-05-26 08:45:30 -04001248 product_variables: {
1249 platform_sdk_version: {
1250 asflags: ["-DPLATFORM_SDK_VERSION=%d"],
1251 },
1252 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001253 include_build_directory: false,
Liz Kammerba7a9c52021-05-26 08:45:30 -04001254} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001255 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001256 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001257 "asflags": `select({
Liz Kammerba7a9c52021-05-26 08:45:30 -04001258 "//build/bazel/product_variables:platform_sdk_version": ["-DPLATFORM_SDK_VERSION=$(Platform_sdk_version)"],
1259 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001260 })`,
1261 "srcs_as": `["common.S"]`,
1262 }),
1263 },
Liz Kammerba7a9c52021-05-26 08:45:30 -04001264 })
1265}
Chris Parsons51f8c392021-08-03 21:01:05 -04001266
1267func TestStaticLibrary_SystemSharedLibsRootEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001268 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1269 Description: "cc_library_static system_shared_lib empty root",
1270 Blueprint: soongCcLibraryStaticPreamble + `
Chris Parsons51f8c392021-08-03 21:01:05 -04001271cc_library_static {
1272 name: "root_empty",
Liz Kammer8337ea42021-09-10 10:06:32 -04001273 system_shared_libs: [],
1274 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001275}
1276`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001277 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001278 MakeBazelTarget("cc_library_static", "root_empty", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001279 "system_dynamic_deps": `[]`,
1280 }),
1281 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001282 })
1283}
1284
1285func TestStaticLibrary_SystemSharedLibsStaticEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001286 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1287 Description: "cc_library_static system_shared_lib empty static default",
1288 Blueprint: soongCcLibraryStaticPreamble + `
Chris Parsons51f8c392021-08-03 21:01:05 -04001289cc_defaults {
1290 name: "static_empty_defaults",
1291 static: {
Liz Kammer8337ea42021-09-10 10:06:32 -04001292 system_shared_libs: [],
1293 },
1294 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001295}
1296cc_library_static {
1297 name: "static_empty",
Liz Kammer8337ea42021-09-10 10:06:32 -04001298 defaults: ["static_empty_defaults"],
Chris Parsons51f8c392021-08-03 21:01:05 -04001299}
1300`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001301 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001302 MakeBazelTarget("cc_library_static", "static_empty", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001303 "system_dynamic_deps": `[]`,
1304 }),
1305 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001306 })
1307}
1308
1309func TestStaticLibrary_SystemSharedLibsBionicEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001310 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1311 Description: "cc_library_static system_shared_lib empty for bionic variant",
1312 Blueprint: soongCcLibraryStaticPreamble + `
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001313cc_library {
1314 name: "libc_musl",
1315 bazel_module: { bp2build_available: false },
1316}
1317
Chris Parsons51f8c392021-08-03 21:01:05 -04001318cc_library_static {
1319 name: "target_bionic_empty",
1320 target: {
1321 bionic: {
1322 system_shared_libs: [],
1323 },
1324 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001325 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001326}
1327`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001328 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001329 MakeBazelTarget("cc_library_static", "target_bionic_empty", AttrNameToString{
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001330 "system_dynamic_deps": `select({
1331 "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
1332 "//conditions:default": [],
1333 })`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001334 }),
1335 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001336 })
1337}
1338
1339func TestStaticLibrary_SystemSharedLibsLinuxBionicEmpty(t *testing.T) {
1340 // Note that this behavior is technically incorrect (it's a simplification).
1341 // The correct behavior would be if bp2build wrote `system_dynamic_deps = []`
1342 // only for linux_bionic, but `android` had `["libc", "libdl", "libm"].
1343 // b/195791252 tracks the fix.
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001344 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1345 Description: "cc_library_static system_shared_lib empty for linux_bionic variant",
1346 Blueprint: soongCcLibraryStaticPreamble + `
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001347cc_library {
1348 name: "libc_musl",
1349 bazel_module: { bp2build_available: false },
1350}
1351
Chris Parsons51f8c392021-08-03 21:01:05 -04001352cc_library_static {
1353 name: "target_linux_bionic_empty",
1354 target: {
1355 linux_bionic: {
1356 system_shared_libs: [],
1357 },
1358 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001359 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001360}
1361`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001362 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001363 MakeBazelTarget("cc_library_static", "target_linux_bionic_empty", AttrNameToString{
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001364 "system_dynamic_deps": `select({
1365 "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
1366 "//conditions:default": [],
1367 })`,
1368 }),
1369 },
1370 })
1371}
1372
1373func TestStaticLibrary_SystemSharedLibsMuslEmpty(t *testing.T) {
1374 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1375 Description: "cc_library_static system_shared_lib empty for musl variant",
1376 Blueprint: soongCcLibraryStaticPreamble + `
1377cc_library {
1378 name: "libc_musl",
1379 bazel_module: { bp2build_available: false },
1380}
1381
1382cc_library_static {
1383 name: "target_musl_empty",
1384 target: {
1385 musl: {
1386 system_shared_libs: [],
1387 },
1388 },
1389 include_build_directory: false,
1390}
1391`,
1392 ExpectedBazelTargets: []string{
1393 MakeBazelTarget("cc_library_static", "target_musl_empty", AttrNameToString{
1394 "system_dynamic_deps": `[]`,
1395 }),
1396 },
1397 })
1398}
1399
1400func TestStaticLibrary_SystemSharedLibsLinuxMuslEmpty(t *testing.T) {
1401 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1402 Description: "cc_library_static system_shared_lib empty for linux_musl variant",
1403 Blueprint: soongCcLibraryStaticPreamble + `
1404cc_library {
1405 name: "libc_musl",
1406 bazel_module: { bp2build_available: false },
1407}
1408
1409cc_library_static {
1410 name: "target_linux_musl_empty",
1411 target: {
1412 linux_musl: {
1413 system_shared_libs: [],
1414 },
1415 },
1416 include_build_directory: false,
1417}
1418`,
1419 ExpectedBazelTargets: []string{
1420 MakeBazelTarget("cc_library_static", "target_linux_musl_empty", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001421 "system_dynamic_deps": `[]`,
1422 }),
1423 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001424 })
1425}
1426
1427func TestStaticLibrary_SystemSharedLibsBionic(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001428 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1429 Description: "cc_library_static system_shared_libs set for bionic variant",
1430 Blueprint: soongCcLibraryStaticPreamble +
Liz Kammerbe46fcc2021-11-01 15:32:43 -04001431 simpleModuleDoNotConvertBp2build("cc_library", "libc") + `
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001432cc_library {
1433 name: "libc_musl",
1434 bazel_module: { bp2build_available: false },
1435}
1436
Chris Parsons51f8c392021-08-03 21:01:05 -04001437cc_library_static {
1438 name: "target_bionic",
1439 target: {
1440 bionic: {
1441 system_shared_libs: ["libc"],
1442 },
1443 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001444 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001445}
1446`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001447 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001448 MakeBazelTarget("cc_library_static", "target_bionic", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001449 "system_dynamic_deps": `select({
Chris Parsons2dde0cb2021-10-01 14:45:30 -04001450 "//build/bazel/platforms/os:android": [":libc"],
1451 "//build/bazel/platforms/os:linux_bionic": [":libc"],
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001452 "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
Chris Parsons51f8c392021-08-03 21:01:05 -04001453 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001454 })`,
1455 }),
1456 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001457 })
1458}
1459
1460func TestStaticLibrary_SystemSharedLibsLinuxRootAndLinuxBionic(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001461 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1462 Description: "cc_library_static system_shared_libs set for root and linux_bionic variant",
1463 Blueprint: soongCcLibraryStaticPreamble +
Liz Kammerbe46fcc2021-11-01 15:32:43 -04001464 simpleModuleDoNotConvertBp2build("cc_library", "libc") +
1465 simpleModuleDoNotConvertBp2build("cc_library", "libm") + `
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001466cc_library {
1467 name: "libc_musl",
1468 bazel_module: { bp2build_available: false },
1469}
1470
Chris Parsons51f8c392021-08-03 21:01:05 -04001471cc_library_static {
1472 name: "target_linux_bionic",
Liz Kammer8337ea42021-09-10 10:06:32 -04001473 system_shared_libs: ["libc"],
Chris Parsons51f8c392021-08-03 21:01:05 -04001474 target: {
1475 linux_bionic: {
1476 system_shared_libs: ["libm"],
1477 },
1478 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001479 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001480}
1481`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001482 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001483 MakeBazelTarget("cc_library_static", "target_linux_bionic", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001484 "system_dynamic_deps": `[":libc"] + select({
Chris Parsons51f8c392021-08-03 21:01:05 -04001485 "//build/bazel/platforms/os:linux_bionic": [":libm"],
Trevor Radcliffe0d1b4022022-12-12 22:26:34 +00001486 "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
Chris Parsons51f8c392021-08-03 21:01:05 -04001487 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001488 })`,
1489 }),
1490 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001491 })
1492}
Liz Kammer12615db2021-09-28 09:19:17 -04001493
Liz Kammer54309532021-12-14 12:21:22 -05001494func TestCcLibrarystatic_SystemSharedLibUsedAsDep(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001495 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1496 Description: "cc_library_static system_shared_lib empty for linux_bionic variant",
1497 Blueprint: soongCcLibraryStaticPreamble +
Liz Kammer54309532021-12-14 12:21:22 -05001498 simpleModuleDoNotConvertBp2build("cc_library", "libc") + `
Liz Kammer91487d42022-09-13 11:27:11 -04001499
1500cc_library {
1501 name: "libm",
1502 stubs: {
1503 symbol_file: "libm.map.txt",
1504 versions: ["current"],
1505 },
1506 bazel_module: { bp2build_available: false },
Spandan Das6d4d9da2023-04-18 06:20:40 +00001507 apex_available: ["com.android.runtime"],
Liz Kammer91487d42022-09-13 11:27:11 -04001508}
1509
Liz Kammer54309532021-12-14 12:21:22 -05001510cc_library_static {
1511 name: "used_in_bionic_oses",
1512 target: {
1513 android: {
1514 shared_libs: ["libc"],
1515 },
1516 linux_bionic: {
1517 shared_libs: ["libc"],
1518 },
1519 },
1520 include_build_directory: false,
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001521 apex_available: ["foo"],
Liz Kammer54309532021-12-14 12:21:22 -05001522}
1523
1524cc_library_static {
1525 name: "all",
1526 shared_libs: ["libc"],
1527 include_build_directory: false,
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001528 apex_available: ["foo"],
Liz Kammer54309532021-12-14 12:21:22 -05001529}
1530
1531cc_library_static {
1532 name: "keep_for_empty_system_shared_libs",
1533 shared_libs: ["libc"],
Liz Kammer91487d42022-09-13 11:27:11 -04001534 system_shared_libs: [],
1535 include_build_directory: false,
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001536 apex_available: ["foo"],
Liz Kammer91487d42022-09-13 11:27:11 -04001537}
1538
1539cc_library_static {
1540 name: "used_with_stubs",
1541 shared_libs: ["libm"],
1542 include_build_directory: false,
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001543 apex_available: ["foo"],
Liz Kammer91487d42022-09-13 11:27:11 -04001544}
1545
1546cc_library_static {
1547 name: "keep_with_stubs",
1548 shared_libs: ["libm"],
1549 system_shared_libs: [],
Liz Kammer54309532021-12-14 12:21:22 -05001550 include_build_directory: false,
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001551 apex_available: ["foo"],
Liz Kammer54309532021-12-14 12:21:22 -05001552}
1553`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001554 ExpectedBazelTargets: []string{
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001555 MakeBazelTarget("cc_library_static", "all", AttrNameToString{
1556 "tags": `["apex_available=foo"]`,
1557 }),
Alixe06d75b2022-08-31 18:28:19 +00001558 MakeBazelTarget("cc_library_static", "keep_for_empty_system_shared_libs", AttrNameToString{
Liz Kammer54309532021-12-14 12:21:22 -05001559 "implementation_dynamic_deps": `[":libc"]`,
1560 "system_dynamic_deps": `[]`,
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001561 "tags": `["apex_available=foo"]`,
Liz Kammer54309532021-12-14 12:21:22 -05001562 }),
Liz Kammer91487d42022-09-13 11:27:11 -04001563 MakeBazelTarget("cc_library_static", "keep_with_stubs", AttrNameToString{
1564 "implementation_dynamic_deps": `select({
Spandan Das6d4d9da2023-04-18 06:20:40 +00001565 "//build/bazel/rules/apex:foo": ["@api_surfaces//module-libapi/current:libm"],
1566 "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:libm"],
Liz Kammer91487d42022-09-13 11:27:11 -04001567 "//conditions:default": [":libm"],
1568 })`,
1569 "system_dynamic_deps": `[]`,
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001570 "tags": `["apex_available=foo"]`,
Liz Kammer91487d42022-09-13 11:27:11 -04001571 }),
Liz Kammer48cdbeb2023-03-17 10:17:50 -04001572 MakeBazelTarget("cc_library_static", "used_in_bionic_oses", AttrNameToString{
1573 "tags": `["apex_available=foo"]`,
1574 }),
1575 MakeBazelTarget("cc_library_static", "used_with_stubs", AttrNameToString{
1576 "tags": `["apex_available=foo"]`,
1577 }),
Liz Kammer54309532021-12-14 12:21:22 -05001578 },
1579 })
1580}
1581
Liz Kammer12615db2021-09-28 09:19:17 -04001582func TestCcLibraryStaticProto(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001583 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1584 Blueprint: soongCcProtoPreamble + `cc_library_static {
Liz Kammer12615db2021-09-28 09:19:17 -04001585 name: "foo",
1586 srcs: ["foo.proto"],
1587 proto: {
Liz Kammer12615db2021-09-28 09:19:17 -04001588 export_proto_headers: true,
1589 },
1590 include_build_directory: false,
1591}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001592 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001593 MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04001594 "srcs": `["foo.proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00001595 }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04001596 "deps": `[":foo_proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00001597 }), MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04001598 "deps": `[":libprotobuf-cpp-lite"]`,
1599 "whole_archive_deps": `[":foo_cc_proto_lite"]`,
1600 }),
1601 },
1602 })
1603}
Rupert Shuttleworth484aa252021-12-10 07:22:53 -05001604
1605func TestCcLibraryStaticUseVersionLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001606 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Liz Kammerbaced712022-09-16 09:01:29 -04001607 Filesystem: map[string]string{
1608 soongCcVersionLibBpPath: soongCcVersionLibBp,
1609 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001610 Blueprint: soongCcProtoPreamble + `cc_library_static {
Rupert Shuttleworth484aa252021-12-10 07:22:53 -05001611 name: "foo",
1612 use_version_lib: true,
Liz Kammerbaced712022-09-16 09:01:29 -04001613 static_libs: ["libbuildversion"],
Rupert Shuttleworth484aa252021-12-10 07:22:53 -05001614 include_build_directory: false,
1615}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001616 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001617 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
Yu Liufe978fd2023-04-24 16:37:18 -07001618 "whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
Liz Kammerbaced712022-09-16 09:01:29 -04001619 }),
1620 },
1621 })
1622}
1623
1624func TestCcLibraryStaticUseVersionLibHasDep(t *testing.T) {
1625 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1626 Filesystem: map[string]string{
1627 soongCcVersionLibBpPath: soongCcVersionLibBp,
1628 },
1629 Blueprint: soongCcProtoPreamble + `cc_library_static {
1630 name: "foo",
1631 use_version_lib: true,
1632 whole_static_libs: ["libbuildversion"],
1633 include_build_directory: false,
1634}`,
1635 ExpectedBazelTargets: []string{
1636 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1637 "whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
Rupert Shuttleworth484aa252021-12-10 07:22:53 -05001638 }),
1639 },
1640 })
1641}
Liz Kammercac7f692021-12-16 14:19:32 -05001642
1643func TestCcLibraryStaticStdInFlags(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001644 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1645 Blueprint: soongCcProtoPreamble + `cc_library_static {
Liz Kammercac7f692021-12-16 14:19:32 -05001646 name: "foo",
1647 cflags: ["-std=candcpp"],
1648 conlyflags: ["-std=conly"],
1649 cppflags: ["-std=cpp"],
1650 include_build_directory: false,
1651}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001652 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001653 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
Liz Kammercac7f692021-12-16 14:19:32 -05001654 "conlyflags": `["-std=conly"]`,
1655 "cppflags": `["-std=cpp"]`,
1656 }),
1657 },
1658 })
1659}
Liz Kammer7128d382022-05-12 11:42:33 -04001660
1661func TestCcLibraryStaticStl(t *testing.T) {
1662 testCases := []struct {
1663 desc string
1664 prop string
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001665 attr AttrNameToString
Liz Kammer7128d382022-05-12 11:42:33 -04001666 }{
1667 {
1668 desc: "c++_shared deduped to libc++",
1669 prop: `stl: "c++_shared",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001670 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001671 "stl": `"libc++"`,
1672 },
1673 },
1674 {
1675 desc: "libc++ to libc++",
1676 prop: `stl: "libc++",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001677 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001678 "stl": `"libc++"`,
1679 },
1680 },
1681 {
1682 desc: "c++_static to libc++_static",
1683 prop: `stl: "c++_static",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001684 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001685 "stl": `"libc++_static"`,
1686 },
1687 },
1688 {
1689 desc: "libc++_static to libc++_static",
1690 prop: `stl: "libc++_static",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001691 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001692 "stl": `"libc++_static"`,
1693 },
1694 },
1695 {
1696 desc: "system to system",
1697 prop: `stl: "system",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001698 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001699 "stl": `"system"`,
1700 },
1701 },
1702 {
1703 desc: "none to none",
1704 prop: `stl: "none",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001705 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001706 "stl": `"none"`,
1707 },
1708 },
1709 {
1710 desc: "empty to empty",
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001711 attr: AttrNameToString{},
Liz Kammer7128d382022-05-12 11:42:33 -04001712 },
1713 }
1714 for _, tc := range testCases {
1715 t.Run(tc.desc, func(*testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001716 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1717 Blueprint: fmt.Sprintf(`cc_library_static {
Liz Kammer7128d382022-05-12 11:42:33 -04001718 name: "foo",
1719 include_build_directory: false,
1720 %s
1721}`, tc.prop),
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001722 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001723 MakeBazelTarget("cc_library_static", "foo", tc.attr),
Liz Kammer7128d382022-05-12 11:42:33 -04001724 },
1725 })
1726 })
1727 }
1728}
Cole Faust6b29f592022-08-09 09:50:56 -07001729
1730func TestCCLibraryStaticRuntimeDeps(t *testing.T) {
1731 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1732 Blueprint: `cc_library_shared {
1733 name: "bar",
1734}
1735
1736cc_library_static {
1737 name: "foo",
1738 runtime_libs: ["foo"],
1739}`,
1740 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001741 MakeBazelTarget("cc_library_shared", "bar", AttrNameToString{
Cole Faust6b29f592022-08-09 09:50:56 -07001742 "local_includes": `["."]`,
1743 }),
Alixe06d75b2022-08-31 18:28:19 +00001744 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
Cole Faust6b29f592022-08-09 09:50:56 -07001745 "runtime_deps": `[":foo"]`,
1746 "local_includes": `["."]`,
1747 }),
1748 },
1749 })
1750}
Trevor Radcliffecee4e052022-09-06 19:31:25 +00001751
1752func TestCcLibraryStaticWithSyspropSrcs(t *testing.T) {
1753 runCcLibraryTestCase(t, Bp2buildTestCase{
1754 Description: "cc_library_static with sysprop sources",
1755 Blueprint: `
1756cc_library_static {
1757 name: "foo",
1758 srcs: [
1759 "bar.sysprop",
1760 "baz.sysprop",
1761 "blah.cpp",
1762 ],
1763 min_sdk_version: "5",
1764}`,
1765 ExpectedBazelTargets: []string{
1766 MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
1767 "srcs": `[
1768 "bar.sysprop",
1769 "baz.sysprop",
1770 ]`,
1771 }),
1772 MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
1773 "dep": `":foo_sysprop_library"`,
1774 "min_sdk_version": `"5"`,
1775 }),
1776 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1777 "srcs": `["blah.cpp"]`,
1778 "local_includes": `["."]`,
1779 "min_sdk_version": `"5"`,
1780 "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`,
1781 }),
1782 },
1783 })
1784}
1785
1786func TestCcLibraryStaticWithSyspropSrcsSomeConfigs(t *testing.T) {
1787 runCcLibraryTestCase(t, Bp2buildTestCase{
1788 Description: "cc_library_static with sysprop sources in some configs but not others",
1789 Blueprint: `
1790cc_library_static {
1791 name: "foo",
1792 srcs: [
1793 "blah.cpp",
1794 ],
1795 target: {
1796 android: {
1797 srcs: ["bar.sysprop"],
1798 },
1799 },
1800 min_sdk_version: "5",
1801}`,
1802 ExpectedBazelTargets: []string{
1803 MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
1804 "srcs": `select({
1805 "//build/bazel/platforms/os:android": ["bar.sysprop"],
1806 "//conditions:default": [],
1807 })`,
1808 }),
1809 MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
1810 "dep": `":foo_sysprop_library"`,
1811 "min_sdk_version": `"5"`,
1812 }),
1813 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1814 "srcs": `["blah.cpp"]`,
1815 "local_includes": `["."]`,
1816 "min_sdk_version": `"5"`,
1817 "whole_archive_deps": `select({
1818 "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"],
1819 "//conditions:default": [],
1820 })`,
1821 }),
1822 },
1823 })
1824}
Trevor Radcliffedb7e0262022-10-28 16:48:18 +00001825
1826func TestCcLibraryStaticWithIntegerOverflowProperty(t *testing.T) {
1827 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1828 Description: "cc_library_static has correct features when integer_overflow property is provided",
1829 Blueprint: `
1830cc_library_static {
1831 name: "foo",
1832 sanitize: {
1833 integer_overflow: true,
1834 },
1835}
1836`,
1837 ExpectedBazelTargets: []string{
1838 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1839 "features": `["ubsan_integer_overflow"]`,
1840 "local_includes": `["."]`,
1841 }),
1842 },
1843 })
1844}
1845
1846func TestCcLibraryStaticWithMiscUndefinedProperty(t *testing.T) {
1847 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1848 Description: "cc_library_static has correct features when misc_undefined property is provided",
1849 Blueprint: `
1850cc_library_static {
1851 name: "foo",
1852 sanitize: {
1853 misc_undefined: ["undefined", "nullability"],
1854 },
1855}
1856`,
1857 ExpectedBazelTargets: []string{
1858 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1859 "features": `[
1860 "ubsan_undefined",
1861 "ubsan_nullability",
1862 ]`,
1863 "local_includes": `["."]`,
1864 }),
1865 },
1866 })
1867}
1868
1869func TestCcLibraryStaticWithUBSanPropertiesArchSpecific(t *testing.T) {
1870 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1871 Description: "cc_library_static has correct feature select when UBSan props are specified in arch specific blocks",
1872 Blueprint: `
1873cc_library_static {
1874 name: "foo",
1875 sanitize: {
1876 misc_undefined: ["undefined", "nullability"],
1877 },
1878 target: {
1879 android: {
1880 sanitize: {
1881 misc_undefined: ["alignment"],
1882 },
1883 },
1884 linux_glibc: {
1885 sanitize: {
1886 integer_overflow: true,
1887 },
1888 },
1889 },
1890}
1891`,
1892 ExpectedBazelTargets: []string{
1893 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1894 "features": `[
1895 "ubsan_undefined",
1896 "ubsan_nullability",
1897 ] + select({
1898 "//build/bazel/platforms/os:android": ["ubsan_alignment"],
1899 "//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"],
1900 "//conditions:default": [],
1901 })`,
1902 "local_includes": `["."]`,
1903 }),
1904 },
1905 })
1906}
Trevor Radcliffe56b1a2b2023-02-06 21:58:30 +00001907
Trevor Radcliffeded095c2023-06-12 19:18:28 +00001908func TestCcLibraryStaticWithSanitizerBlocklist(t *testing.T) {
1909 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1910 Description: "cc_library_static has correct features when sanitize.blocklist is provided",
1911 Blueprint: `
1912cc_library_static {
1913 name: "foo",
1914 sanitize: {
1915 blocklist: "foo_blocklist.txt",
1916 },
1917}
1918`,
1919 ExpectedBazelTargets: []string{
1920 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
Trevor Radcliffed7148712023-07-10 18:50:47 +00001921 "features": `["sanitizer_blocklist_foo_blocklist_txt"]`,
Trevor Radcliffeded095c2023-06-12 19:18:28 +00001922 "local_includes": `["."]`,
1923 }),
1924 },
1925 })
1926}
1927
Trevor Radcliffe56b1a2b2023-02-06 21:58:30 +00001928func TestCcLibraryStaticWithThinLto(t *testing.T) {
1929 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1930 Description: "cc_library_static has correct features when thin lto is enabled",
1931 Blueprint: `
1932cc_library_static {
1933 name: "foo",
1934 lto: {
1935 thin: true,
1936 },
1937}
1938`,
1939 ExpectedBazelTargets: []string{
1940 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1941 "features": `["android_thin_lto"]`,
1942 "local_includes": `["."]`,
1943 }),
1944 },
1945 })
1946}
1947
1948func TestCcLibraryStaticWithLtoNever(t *testing.T) {
1949 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1950 Description: "cc_library_static has correct features when thin lto is enabled",
1951 Blueprint: `
1952cc_library_static {
1953 name: "foo",
1954 lto: {
1955 never: true,
1956 },
1957}
1958`,
1959 ExpectedBazelTargets: []string{
1960 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1961 "features": `["-android_thin_lto"]`,
1962 "local_includes": `["."]`,
1963 }),
1964 },
1965 })
1966}
1967
1968func TestCcLibraryStaticWithThinLtoArchSpecific(t *testing.T) {
1969 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1970 Description: "cc_library_static has correct features when LTO differs across arch and os variants",
1971 Blueprint: `
1972cc_library_static {
1973 name: "foo",
1974 target: {
1975 android: {
1976 lto: {
1977 thin: true,
1978 },
1979 },
1980 },
1981 arch: {
1982 riscv64: {
1983 lto: {
1984 thin: false,
1985 },
1986 },
1987 },
1988}`,
1989 ExpectedBazelTargets: []string{
1990 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1991 "local_includes": `["."]`,
1992 "features": `select({
1993 "//build/bazel/platforms/os_arch:android_arm": ["android_thin_lto"],
1994 "//build/bazel/platforms/os_arch:android_arm64": ["android_thin_lto"],
1995 "//build/bazel/platforms/os_arch:android_riscv64": ["-android_thin_lto"],
1996 "//build/bazel/platforms/os_arch:android_x86": ["android_thin_lto"],
1997 "//build/bazel/platforms/os_arch:android_x86_64": ["android_thin_lto"],
1998 "//conditions:default": [],
1999 })`}),
2000 },
2001 })
2002}
2003
2004func TestCcLibraryStaticWithThinLtoDisabledDefaultEnabledVariant(t *testing.T) {
2005 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2006 Description: "cc_library_static has correct features when LTO disabled by default but enabled on a particular variant",
2007 Blueprint: `
2008cc_library_static {
2009 name: "foo",
2010 lto: {
2011 never: true,
2012 },
2013 target: {
2014 android: {
2015 lto: {
2016 thin: true,
2017 never: false,
2018 },
2019 },
2020 },
2021}`,
2022 ExpectedBazelTargets: []string{
2023 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2024 "local_includes": `["."]`,
2025 "features": `select({
2026 "//build/bazel/platforms/os:android": ["android_thin_lto"],
2027 "//conditions:default": ["-android_thin_lto"],
2028 })`,
2029 }),
2030 },
2031 })
2032}
2033
2034func TestCcLibraryStaticWithThinLtoAndWholeProgramVtables(t *testing.T) {
2035 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2036 Description: "cc_library_static has correct features when thin lto is enabled with whole_program_vtables",
2037 Blueprint: `
2038cc_library_static {
2039 name: "foo",
2040 lto: {
2041 thin: true,
2042 },
2043 whole_program_vtables: true,
2044}
2045`,
2046 ExpectedBazelTargets: []string{
2047 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2048 "features": `[
2049 "android_thin_lto",
2050 "android_thin_lto_whole_program_vtables",
2051 ]`,
2052 "local_includes": `["."]`,
2053 }),
2054 },
2055 })
2056}
Trevor Radcliffea8b44162023-04-14 18:25:24 +00002057
2058func TestCcLibraryStaticHiddenVisibilityConvertedToFeature(t *testing.T) {
2059 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2060 Description: "cc_library_static changes hidden visibility flag to feature",
2061 Blueprint: `
2062cc_library_static {
2063 name: "foo",
2064 cflags: ["-fvisibility=hidden"],
2065}`,
2066 ExpectedBazelTargets: []string{
2067 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2068 "features": `["visibility_hidden"]`,
2069 "local_includes": `["."]`,
2070 }),
2071 },
2072 })
2073}
2074
2075func TestCcLibraryStaticHiddenVisibilityConvertedToFeatureOsSpecific(t *testing.T) {
2076 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2077 Description: "cc_library_static changes hidden visibility flag to feature for specific os",
2078 Blueprint: `
2079cc_library_static {
2080 name: "foo",
2081 target: {
2082 android: {
2083 cflags: ["-fvisibility=hidden"],
2084 },
2085 },
2086}`,
2087 ExpectedBazelTargets: []string{
2088 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2089 "features": `select({
2090 "//build/bazel/platforms/os:android": ["visibility_hidden"],
2091 "//conditions:default": [],
2092 })`,
2093 "local_includes": `["."]`,
2094 }),
2095 },
2096 })
2097}
Trevor Radcliffe27669c02023-03-28 20:47:10 +00002098
2099func TestCcLibraryStaticWithCfi(t *testing.T) {
2100 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2101 Description: "cc_library_static has correct features when cfi is enabled",
2102 Blueprint: `
2103cc_library_static {
2104 name: "foo",
2105 sanitize: {
2106 cfi: true,
2107 },
2108}`,
2109 ExpectedBazelTargets: []string{
2110 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2111 "features": `["android_cfi"]`,
2112 "local_includes": `["."]`,
2113 }),
2114 },
2115 })
2116}
2117
2118func TestCcLibraryStaticWithCfiOsSpecific(t *testing.T) {
2119 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2120 Description: "cc_library_static has correct features when cfi is enabled for specific variants",
2121 Blueprint: `
2122cc_library_static {
2123 name: "foo",
2124 target: {
2125 android: {
2126 sanitize: {
2127 cfi: true,
2128 },
2129 },
2130 },
2131}`,
2132 ExpectedBazelTargets: []string{
2133 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2134 "features": `select({
2135 "//build/bazel/platforms/os:android": ["android_cfi"],
2136 "//conditions:default": [],
2137 })`,
2138 "local_includes": `["."]`,
2139 }),
2140 },
2141 })
2142}
2143
2144func TestCcLibraryStaticWithCfiAndCfiAssemblySupport(t *testing.T) {
2145 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2146 Description: "cc_library_static has correct features when cfi is enabled with cfi_assembly_support",
2147 Blueprint: `
2148cc_library_static {
2149 name: "foo",
2150 sanitize: {
2151 cfi: true,
2152 config: {
2153 cfi_assembly_support: true,
2154 },
2155 },
2156}`,
2157 ExpectedBazelTargets: []string{
2158 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2159 "features": `[
2160 "android_cfi",
2161 "android_cfi_assembly_support",
2162 ]`,
2163 "local_includes": `["."]`,
2164 }),
2165 },
2166 })
2167}
Trevor Radcliffe523c5c62023-06-16 20:15:45 +00002168
2169func TestCcLibraryStaticExplicitlyDisablesCfiWhenFalse(t *testing.T) {
2170 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2171 Description: "cc_library_static disables cfi when explciitly set to false in the bp",
2172 Blueprint: `
2173cc_library_static {
2174 name: "foo",
2175 sanitize: {
2176 cfi: false,
2177 },
2178}
2179`,
2180 ExpectedBazelTargets: []string{
2181 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2182 "features": `["-android_cfi"]`,
2183 "local_includes": `["."]`,
2184 }),
2185 },
2186 })
2187}
Alixe2667872023-04-24 14:57:32 +00002188
2189func TestCCLibraryStaticRscriptSrc(t *testing.T) {
2190 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
2191 Description: `cc_library_static with rscript files in sources`,
2192 Blueprint: `
2193cc_library_static{
2194 name : "foo",
2195 srcs : [
2196 "ccSrc.cc",
2197 "rsSrc.rscript",
2198 ],
2199 include_build_directory: false,
2200}
2201`,
2202 ExpectedBazelTargets: []string{
2203 MakeBazelTarget("rscript_to_cpp", "foo_renderscript", AttrNameToString{
2204 "srcs": `["rsSrc.rscript"]`,
2205 }),
2206 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
2207 "absolute_includes": `[
2208 "frameworks/rs",
2209 "frameworks/rs/cpp",
2210 ]`,
2211 "local_includes": `["."]`,
2212 "srcs": `[
2213 "ccSrc.cc",
2214 "foo_renderscript",
2215 ]`,
2216 })}})
2217}