blob: e3ea9a07ce1e13966489db718b1cc21a6a84f5fe [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 ],
839 "//build/bazel/platforms/arch:x86": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400840 "not-for-lib64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400841 "for-lib32.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400842 ],
843 "//build/bazel/platforms/arch:x86_64": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400844 "not-for-lib32.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400845 "for-lib64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400846 ],
847 "//conditions:default": [
848 "not-for-lib32.c",
849 "not-for-lib64.c",
850 ],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500851 })`,
852 }),
853 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200854 })
855}
856
857func TestCcLibrarySTaticArchMultilibSrcsExcludeSrcs(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000858 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
859 Description: "cc_library_static arch and multilib srcs and exclude_srcs",
860 Filesystem: map[string]string{
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200861 "common.c": "",
862 "for-arm.c": "",
863 "for-arm64.c": "",
864 "for-x86.c": "",
865 "for-x86_64.c": "",
866 "for-lib32.c": "",
867 "for-lib64.c": "",
868 "not-for-arm.c": "",
869 "not-for-arm64.c": "",
870 "not-for-x86.c": "",
871 "not-for-x86_64.c": "",
872 "not-for-lib32.c": "",
873 "not-for-lib64.c": "",
874 "not-for-everything.c": "",
Chris Parsonsc424b762021-04-29 18:06:50 -0400875 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000876 Blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -0400877cc_library_static {
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500878 name: "foo_static",
Chris Parsonsc424b762021-04-29 18:06:50 -0400879 srcs: ["common.c", "not-for-*.c"],
880 exclude_srcs: ["not-for-everything.c"],
881 arch: {
882 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
883 arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] },
884 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
885 x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] },
886 },
887 multilib: {
888 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
889 lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] },
890 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400891 include_build_directory: false,
Chris Parsonsc424b762021-04-29 18:06:50 -0400892}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000893 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000894 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500895 "srcs_c": `["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -0400896 "//build/bazel/platforms/arch:arm": [
Liz Kammer9bad9d62021-10-11 15:40:35 -0400897 "not-for-arm64.c",
898 "not-for-lib64.c",
899 "not-for-x86.c",
900 "not-for-x86_64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400901 "for-arm.c",
902 "for-lib32.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400903 ],
904 "//build/bazel/platforms/arch:arm64": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400905 "not-for-arm.c",
906 "not-for-lib32.c",
907 "not-for-x86.c",
908 "not-for-x86_64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400909 "for-arm64.c",
910 "for-lib64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400911 ],
912 "//build/bazel/platforms/arch:x86": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400913 "not-for-arm.c",
914 "not-for-arm64.c",
915 "not-for-lib64.c",
916 "not-for-x86_64.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400917 "for-x86.c",
918 "for-lib32.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400919 ],
920 "//build/bazel/platforms/arch:x86_64": [
Chris Parsonsc424b762021-04-29 18:06:50 -0400921 "not-for-arm.c",
922 "not-for-arm64.c",
923 "not-for-lib32.c",
924 "not-for-x86.c",
Liz Kammer9bad9d62021-10-11 15:40:35 -0400925 "for-x86_64.c",
926 "for-lib64.c",
Chris Parsonsc424b762021-04-29 18:06:50 -0400927 ],
928 "//conditions:default": [
929 "not-for-arm.c",
930 "not-for-arm64.c",
931 "not-for-lib32.c",
932 "not-for-lib64.c",
933 "not-for-x86.c",
934 "not-for-x86_64.c",
935 ],
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500936 })`,
937 }),
938 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200939 })
940}
941
Liz Kammerae3994e2021-10-19 09:45:48 -0400942func TestCcLibraryStaticGeneratedHeadersAllPartitions(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000943 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
944 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammerae3994e2021-10-19 09:45:48 -0400945genrule {
946 name: "generated_hdr",
947 cmd: "nothing to see here",
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400948 bazel_module: { bp2build_available: false },
Liz Kammerae3994e2021-10-19 09:45:48 -0400949}
950
Liz Kammere6583482021-10-19 13:56:10 -0400951genrule {
952 name: "export_generated_hdr",
953 cmd: "nothing to see here",
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400954 bazel_module: { bp2build_available: false },
Liz Kammere6583482021-10-19 13:56:10 -0400955}
956
Liz Kammerae3994e2021-10-19 09:45:48 -0400957cc_library_static {
958 name: "foo_static",
959 srcs: ["cpp_src.cpp", "as_src.S", "c_src.c"],
Liz Kammere6583482021-10-19 13:56:10 -0400960 generated_headers: ["generated_hdr", "export_generated_hdr"],
961 export_generated_headers: ["export_generated_hdr"],
Liz Kammerae3994e2021-10-19 09:45:48 -0400962 include_build_directory: false,
963}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000964 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000965 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer1263d9b2021-12-10 14:28:20 -0500966 "export_includes": `["."]`,
967 "local_includes": `["."]`,
968 "hdrs": `[":export_generated_hdr"]`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500969 "srcs": `[
Liz Kammerae3994e2021-10-19 09:45:48 -0400970 "cpp_src.cpp",
971 ":generated_hdr",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500972 ]`,
973 "srcs_as": `[
Liz Kammerae3994e2021-10-19 09:45:48 -0400974 "as_src.S",
975 ":generated_hdr",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500976 ]`,
977 "srcs_c": `[
Liz Kammerae3994e2021-10-19 09:45:48 -0400978 "c_src.c",
979 ":generated_hdr",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500980 ]`,
981 }),
982 },
Liz Kammerae3994e2021-10-19 09:45:48 -0400983 })
984}
985
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200986func TestCcLibraryStaticArchSrcsExcludeSrcsGeneratedFiles(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000987 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
988 Description: "cc_library_static arch srcs/exclude_srcs with generated files",
989 Filesystem: map[string]string{
Chris Parsons990c4f42021-05-25 12:10:58 -0400990 "common.cpp": "",
991 "for-x86.cpp": "",
992 "not-for-x86.cpp": "",
993 "not-for-everything.cpp": "",
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400994 "dep/Android.bp": simpleModuleDoNotConvertBp2build("genrule", "generated_src_other_pkg") +
995 simpleModuleDoNotConvertBp2build("genrule", "generated_hdr_other_pkg") +
996 simpleModuleDoNotConvertBp2build("genrule", "generated_src_other_pkg_x86") +
997 simpleModuleDoNotConvertBp2build("genrule", "generated_hdr_other_pkg_x86") +
998 simpleModuleDoNotConvertBp2build("genrule", "generated_hdr_other_pkg_android"),
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200999 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001000 Blueprint: soongCcLibraryStaticPreamble +
Liz Kammerbe46fcc2021-11-01 15:32:43 -04001001 simpleModuleDoNotConvertBp2build("genrule", "generated_src") +
1002 simpleModuleDoNotConvertBp2build("genrule", "generated_src_not_x86") +
1003 simpleModuleDoNotConvertBp2build("genrule", "generated_src_android") +
1004 simpleModuleDoNotConvertBp2build("genrule", "generated_hdr") + `
Chris Parsons484e50a2021-05-13 15:13:04 -04001005cc_library_static {
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001006 name: "foo_static",
Liz Kammer222bdcf2021-10-11 14:15:51 -04001007 srcs: ["common.cpp", "not-for-*.cpp"],
1008 exclude_srcs: ["not-for-everything.cpp"],
1009 generated_sources: ["generated_src", "generated_src_other_pkg", "generated_src_not_x86"],
1010 generated_headers: ["generated_hdr", "generated_hdr_other_pkg"],
Liz Kammer1263d9b2021-12-10 14:28:20 -05001011 export_generated_headers: ["generated_hdr_other_pkg"],
Liz Kammer222bdcf2021-10-11 14:15:51 -04001012 arch: {
1013 x86: {
1014 srcs: ["for-x86.cpp"],
1015 exclude_srcs: ["not-for-x86.cpp"],
1016 generated_headers: ["generated_hdr_other_pkg_x86"],
1017 exclude_generated_sources: ["generated_src_not_x86"],
Liz Kammer1263d9b2021-12-10 14:28:20 -05001018 export_generated_headers: ["generated_hdr_other_pkg_x86"],
Liz Kammer222bdcf2021-10-11 14:15:51 -04001019 },
1020 },
1021 target: {
1022 android: {
1023 generated_sources: ["generated_src_android"],
1024 generated_headers: ["generated_hdr_other_pkg_android"],
Liz Kammer1263d9b2021-12-10 14:28:20 -05001025 export_generated_headers: ["generated_hdr_other_pkg_android"],
Liz Kammer222bdcf2021-10-11 14:15:51 -04001026 },
1027 },
1028
Liz Kammer8337ea42021-09-10 10:06:32 -04001029 include_build_directory: false,
Chris Parsons484e50a2021-05-13 15:13:04 -04001030}
1031`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001032 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001033 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001034 "srcs": `[
Chris Parsons990c4f42021-05-25 12:10:58 -04001035 "common.cpp",
Liz Kammer9bad9d62021-10-11 15:40:35 -04001036 ":generated_src",
1037 "//dep:generated_src_other_pkg",
Liz Kammerae3994e2021-10-19 09:45:48 -04001038 ":generated_hdr",
Chris Parsons484e50a2021-05-13 15:13:04 -04001039 ] + select({
Liz Kammer1263d9b2021-12-10 14:28:20 -05001040 "//build/bazel/platforms/arch:x86": ["for-x86.cpp"],
Liz Kammer222bdcf2021-10-11 14:15:51 -04001041 "//conditions:default": [
Liz Kammer222bdcf2021-10-11 14:15:51 -04001042 "not-for-x86.cpp",
Liz Kammer9bad9d62021-10-11 15:40:35 -04001043 ":generated_src_not_x86",
Liz Kammer222bdcf2021-10-11 14:15:51 -04001044 ],
1045 }) + select({
Liz Kammer1263d9b2021-12-10 14:28:20 -05001046 "//build/bazel/platforms/os:android": [":generated_src_android"],
Liz Kammer222bdcf2021-10-11 14:15:51 -04001047 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001048 })`,
Liz Kammer1263d9b2021-12-10 14:28:20 -05001049 "hdrs": `["//dep:generated_hdr_other_pkg"] + select({
1050 "//build/bazel/platforms/arch:x86": ["//dep:generated_hdr_other_pkg_x86"],
1051 "//conditions:default": [],
1052 }) + select({
1053 "//build/bazel/platforms/os:android": ["//dep:generated_hdr_other_pkg_android"],
1054 "//conditions:default": [],
1055 })`,
1056 "local_includes": `["."]`,
1057 "export_absolute_includes": `["dep"]`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001058 }),
1059 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001060 })
Rupert Shuttleworth095081c2021-03-25 09:06:03 +00001061}
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001062
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001063func TestCcLibraryStaticGetTargetProperties(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001064 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001065
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001066 Description: "cc_library_static complex GetTargetProperties",
1067 Blueprint: soongCcLibraryStaticPreamble + `
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001068cc_library_static {
1069 name: "foo_static",
1070 target: {
1071 android: {
1072 srcs: ["android_src.c"],
1073 },
1074 android_arm: {
1075 srcs: ["android_arm_src.c"],
1076 },
1077 android_arm64: {
1078 srcs: ["android_arm64_src.c"],
1079 },
1080 android_x86: {
1081 srcs: ["android_x86_src.c"],
1082 },
1083 android_x86_64: {
1084 srcs: ["android_x86_64_src.c"],
1085 },
1086 linux_bionic_arm64: {
1087 srcs: ["linux_bionic_arm64_src.c"],
1088 },
1089 linux_bionic_x86_64: {
1090 srcs: ["linux_bionic_x86_64_src.c"],
1091 },
1092 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001093 include_build_directory: false,
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001094}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001095 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001096 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001097 "srcs_c": `select({
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001098 "//build/bazel/platforms/os:android": ["android_src.c"],
1099 "//conditions:default": [],
1100 }) + select({
Rupert Shuttleworthffd45822021-05-14 03:02:34 -04001101 "//build/bazel/platforms/os_arch:android_arm": ["android_arm_src.c"],
1102 "//build/bazel/platforms/os_arch:android_arm64": ["android_arm64_src.c"],
1103 "//build/bazel/platforms/os_arch:android_x86": ["android_x86_src.c"],
1104 "//build/bazel/platforms/os_arch:android_x86_64": ["android_x86_64_src.c"],
Rupert Shuttleworthffd45822021-05-14 03:02:34 -04001105 "//build/bazel/platforms/os_arch:linux_bionic_arm64": ["linux_bionic_arm64_src.c"],
1106 "//build/bazel/platforms/os_arch:linux_bionic_x86_64": ["linux_bionic_x86_64_src.c"],
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001107 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001108 })`,
1109 }),
1110 },
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001111 })
1112}
1113
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001114func TestCcLibraryStaticProductVariableSelects(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001115 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1116 Description: "cc_library_static product variable selects",
1117 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001118cc_library_static {
1119 name: "foo_static",
1120 srcs: ["common.c"],
1121 product_variables: {
1122 malloc_not_svelte: {
1123 cflags: ["-Wmalloc_not_svelte"],
1124 },
1125 malloc_zero_contents: {
1126 cflags: ["-Wmalloc_zero_contents"],
1127 },
1128 binder32bit: {
1129 cflags: ["-Wbinder32bit"],
1130 },
1131 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001132 include_build_directory: false,
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001133} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001134 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001135 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001136 "copts": `select({
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001137 "//build/bazel/product_variables:binder32bit": ["-Wbinder32bit"],
1138 "//conditions:default": [],
1139 }) + select({
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001140 "//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"],
1141 "//conditions:default": [],
1142 }) + select({
1143 "//build/bazel/product_variables:malloc_zero_contents": ["-Wmalloc_zero_contents"],
1144 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001145 })`,
1146 "srcs_c": `["common.c"]`,
1147 }),
1148 },
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001149 })
1150}
1151
1152func TestCcLibraryStaticProductVariableArchSpecificSelects(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001153 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1154 Description: "cc_library_static arch-specific product variable selects",
1155 Filesystem: map[string]string{},
1156 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001157cc_library_static {
1158 name: "foo_static",
1159 srcs: ["common.c"],
1160 product_variables: {
1161 malloc_not_svelte: {
1162 cflags: ["-Wmalloc_not_svelte"],
1163 },
1164 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001165 arch: {
1166 arm64: {
1167 product_variables: {
1168 malloc_not_svelte: {
1169 cflags: ["-Warm64_malloc_not_svelte"],
1170 },
1171 },
1172 },
1173 },
1174 multilib: {
1175 lib32: {
1176 product_variables: {
1177 malloc_not_svelte: {
1178 cflags: ["-Wlib32_malloc_not_svelte"],
1179 },
1180 },
1181 },
1182 },
1183 target: {
1184 android: {
1185 product_variables: {
1186 malloc_not_svelte: {
1187 cflags: ["-Wandroid_malloc_not_svelte"],
1188 },
1189 },
1190 }
1191 },
1192 include_build_directory: false,
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001193} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001194 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001195 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001196 "copts": `select({
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001197 "//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"],
1198 "//conditions:default": [],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001199 }) + select({
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001200 "//build/bazel/product_variables:malloc_not_svelte-android": ["-Wandroid_malloc_not_svelte"],
1201 "//conditions:default": [],
1202 }) + select({
1203 "//build/bazel/product_variables:malloc_not_svelte-arm": ["-Wlib32_malloc_not_svelte"],
1204 "//conditions:default": [],
1205 }) + select({
1206 "//build/bazel/product_variables:malloc_not_svelte-arm64": ["-Warm64_malloc_not_svelte"],
1207 "//conditions:default": [],
1208 }) + select({
1209 "//build/bazel/product_variables:malloc_not_svelte-x86": ["-Wlib32_malloc_not_svelte"],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001210 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001211 })`,
1212 "srcs_c": `["common.c"]`,
1213 }),
1214 },
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001215 })
1216}
Liz Kammerba7a9c52021-05-26 08:45:30 -04001217
1218func TestCcLibraryStaticProductVariableStringReplacement(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001219 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1220 Description: "cc_library_static product variable string replacement",
1221 Filesystem: map[string]string{},
1222 Blueprint: soongCcLibraryStaticPreamble + `
Liz Kammerba7a9c52021-05-26 08:45:30 -04001223cc_library_static {
1224 name: "foo_static",
Chris Parsons69fa9f92021-07-13 11:47:44 -04001225 srcs: ["common.S"],
Liz Kammerba7a9c52021-05-26 08:45:30 -04001226 product_variables: {
1227 platform_sdk_version: {
1228 asflags: ["-DPLATFORM_SDK_VERSION=%d"],
1229 },
1230 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001231 include_build_directory: false,
Liz Kammerba7a9c52021-05-26 08:45:30 -04001232} `,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001233 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001234 MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001235 "asflags": `select({
Liz Kammerba7a9c52021-05-26 08:45:30 -04001236 "//build/bazel/product_variables:platform_sdk_version": ["-DPLATFORM_SDK_VERSION=$(Platform_sdk_version)"],
1237 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001238 })`,
1239 "srcs_as": `["common.S"]`,
1240 }),
1241 },
Liz Kammerba7a9c52021-05-26 08:45:30 -04001242 })
1243}
Chris Parsons51f8c392021-08-03 21:01:05 -04001244
1245func TestStaticLibrary_SystemSharedLibsRootEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001246 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1247 Description: "cc_library_static system_shared_lib empty root",
1248 Blueprint: soongCcLibraryStaticPreamble + `
Chris Parsons51f8c392021-08-03 21:01:05 -04001249cc_library_static {
1250 name: "root_empty",
Liz Kammer8337ea42021-09-10 10:06:32 -04001251 system_shared_libs: [],
1252 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001253}
1254`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001255 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001256 MakeBazelTarget("cc_library_static", "root_empty", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001257 "system_dynamic_deps": `[]`,
1258 }),
1259 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001260 })
1261}
1262
1263func TestStaticLibrary_SystemSharedLibsStaticEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001264 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1265 Description: "cc_library_static system_shared_lib empty static default",
1266 Blueprint: soongCcLibraryStaticPreamble + `
Chris Parsons51f8c392021-08-03 21:01:05 -04001267cc_defaults {
1268 name: "static_empty_defaults",
1269 static: {
Liz Kammer8337ea42021-09-10 10:06:32 -04001270 system_shared_libs: [],
1271 },
1272 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001273}
1274cc_library_static {
1275 name: "static_empty",
Liz Kammer8337ea42021-09-10 10:06:32 -04001276 defaults: ["static_empty_defaults"],
Chris Parsons51f8c392021-08-03 21:01:05 -04001277}
1278`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001279 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001280 MakeBazelTarget("cc_library_static", "static_empty", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001281 "system_dynamic_deps": `[]`,
1282 }),
1283 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001284 })
1285}
1286
1287func TestStaticLibrary_SystemSharedLibsBionicEmpty(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001288 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1289 Description: "cc_library_static system_shared_lib empty for bionic variant",
1290 Blueprint: soongCcLibraryStaticPreamble + `
Chris Parsons51f8c392021-08-03 21:01:05 -04001291cc_library_static {
1292 name: "target_bionic_empty",
1293 target: {
1294 bionic: {
1295 system_shared_libs: [],
1296 },
1297 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001298 include_build_directory: false,
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", "target_bionic_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_SystemSharedLibsLinuxBionicEmpty(t *testing.T) {
1310 // Note that this behavior is technically incorrect (it's a simplification).
1311 // The correct behavior would be if bp2build wrote `system_dynamic_deps = []`
1312 // only for linux_bionic, but `android` had `["libc", "libdl", "libm"].
1313 // b/195791252 tracks the fix.
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001314 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1315 Description: "cc_library_static system_shared_lib empty for linux_bionic variant",
1316 Blueprint: soongCcLibraryStaticPreamble + `
Chris Parsons51f8c392021-08-03 21:01:05 -04001317cc_library_static {
1318 name: "target_linux_bionic_empty",
1319 target: {
1320 linux_bionic: {
1321 system_shared_libs: [],
1322 },
1323 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001324 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001325}
1326`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001327 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001328 MakeBazelTarget("cc_library_static", "target_linux_bionic_empty", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001329 "system_dynamic_deps": `[]`,
1330 }),
1331 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001332 })
1333}
1334
1335func TestStaticLibrary_SystemSharedLibsBionic(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001336 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1337 Description: "cc_library_static system_shared_libs set for bionic variant",
1338 Blueprint: soongCcLibraryStaticPreamble +
Liz Kammerbe46fcc2021-11-01 15:32:43 -04001339 simpleModuleDoNotConvertBp2build("cc_library", "libc") + `
Chris Parsons51f8c392021-08-03 21:01:05 -04001340cc_library_static {
1341 name: "target_bionic",
1342 target: {
1343 bionic: {
1344 system_shared_libs: ["libc"],
1345 },
1346 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001347 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001348}
1349`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001350 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001351 MakeBazelTarget("cc_library_static", "target_bionic", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001352 "system_dynamic_deps": `select({
Chris Parsons2dde0cb2021-10-01 14:45:30 -04001353 "//build/bazel/platforms/os:android": [":libc"],
1354 "//build/bazel/platforms/os:linux_bionic": [":libc"],
Chris Parsons51f8c392021-08-03 21:01:05 -04001355 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001356 })`,
1357 }),
1358 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001359 })
1360}
1361
1362func TestStaticLibrary_SystemSharedLibsLinuxRootAndLinuxBionic(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001363 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1364 Description: "cc_library_static system_shared_libs set for root and linux_bionic variant",
1365 Blueprint: soongCcLibraryStaticPreamble +
Liz Kammerbe46fcc2021-11-01 15:32:43 -04001366 simpleModuleDoNotConvertBp2build("cc_library", "libc") +
1367 simpleModuleDoNotConvertBp2build("cc_library", "libm") + `
Chris Parsons51f8c392021-08-03 21:01:05 -04001368cc_library_static {
1369 name: "target_linux_bionic",
Liz Kammer8337ea42021-09-10 10:06:32 -04001370 system_shared_libs: ["libc"],
Chris Parsons51f8c392021-08-03 21:01:05 -04001371 target: {
1372 linux_bionic: {
1373 system_shared_libs: ["libm"],
1374 },
1375 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001376 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001377}
1378`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001379 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001380 MakeBazelTarget("cc_library_static", "target_linux_bionic", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001381 "system_dynamic_deps": `[":libc"] + select({
Chris Parsons51f8c392021-08-03 21:01:05 -04001382 "//build/bazel/platforms/os:linux_bionic": [":libm"],
1383 "//conditions:default": [],
Liz Kammer78cfdaa2021-11-08 12:56:31 -05001384 })`,
1385 }),
1386 },
Chris Parsons51f8c392021-08-03 21:01:05 -04001387 })
1388}
Liz Kammer12615db2021-09-28 09:19:17 -04001389
Liz Kammer54309532021-12-14 12:21:22 -05001390func TestCcLibrarystatic_SystemSharedLibUsedAsDep(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001391 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1392 Description: "cc_library_static system_shared_lib empty for linux_bionic variant",
1393 Blueprint: soongCcLibraryStaticPreamble +
Liz Kammer54309532021-12-14 12:21:22 -05001394 simpleModuleDoNotConvertBp2build("cc_library", "libc") + `
Liz Kammer91487d42022-09-13 11:27:11 -04001395
1396cc_library {
1397 name: "libm",
1398 stubs: {
1399 symbol_file: "libm.map.txt",
1400 versions: ["current"],
1401 },
1402 bazel_module: { bp2build_available: false },
1403}
1404
Liz Kammer54309532021-12-14 12:21:22 -05001405cc_library_static {
1406 name: "used_in_bionic_oses",
1407 target: {
1408 android: {
1409 shared_libs: ["libc"],
1410 },
1411 linux_bionic: {
1412 shared_libs: ["libc"],
1413 },
1414 },
1415 include_build_directory: false,
1416}
1417
1418cc_library_static {
1419 name: "all",
1420 shared_libs: ["libc"],
1421 include_build_directory: false,
1422}
1423
1424cc_library_static {
1425 name: "keep_for_empty_system_shared_libs",
1426 shared_libs: ["libc"],
Liz Kammer91487d42022-09-13 11:27:11 -04001427 system_shared_libs: [],
1428 include_build_directory: false,
1429}
1430
1431cc_library_static {
1432 name: "used_with_stubs",
1433 shared_libs: ["libm"],
1434 include_build_directory: false,
1435}
1436
1437cc_library_static {
1438 name: "keep_with_stubs",
1439 shared_libs: ["libm"],
1440 system_shared_libs: [],
Liz Kammer54309532021-12-14 12:21:22 -05001441 include_build_directory: false,
1442}
1443`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001444 ExpectedBazelTargets: []string{
Liz Kammer43345e22022-08-04 13:57:35 -04001445 MakeBazelTarget("cc_library_static", "all", AttrNameToString{}),
Alixe06d75b2022-08-31 18:28:19 +00001446 MakeBazelTarget("cc_library_static", "keep_for_empty_system_shared_libs", AttrNameToString{
Liz Kammer54309532021-12-14 12:21:22 -05001447 "implementation_dynamic_deps": `[":libc"]`,
1448 "system_dynamic_deps": `[]`,
1449 }),
Liz Kammer91487d42022-09-13 11:27:11 -04001450 MakeBazelTarget("cc_library_static", "keep_with_stubs", AttrNameToString{
1451 "implementation_dynamic_deps": `select({
1452 "//build/bazel/rules/apex:android-in_apex": [":libm_stub_libs_current"],
1453 "//conditions:default": [":libm"],
1454 })`,
1455 "system_dynamic_deps": `[]`,
1456 }),
Alixe06d75b2022-08-31 18:28:19 +00001457 MakeBazelTarget("cc_library_static", "used_in_bionic_oses", AttrNameToString{}),
Liz Kammer91487d42022-09-13 11:27:11 -04001458 MakeBazelTarget("cc_library_static", "used_with_stubs", AttrNameToString{}),
Liz Kammer54309532021-12-14 12:21:22 -05001459 },
1460 })
1461}
1462
Liz Kammer12615db2021-09-28 09:19:17 -04001463func TestCcLibraryStaticProto(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001464 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1465 Blueprint: soongCcProtoPreamble + `cc_library_static {
Liz Kammer12615db2021-09-28 09:19:17 -04001466 name: "foo",
1467 srcs: ["foo.proto"],
1468 proto: {
Liz Kammer12615db2021-09-28 09:19:17 -04001469 export_proto_headers: true,
1470 },
1471 include_build_directory: false,
1472}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001473 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001474 MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04001475 "srcs": `["foo.proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00001476 }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04001477 "deps": `[":foo_proto"]`,
Alixe06d75b2022-08-31 18:28:19 +00001478 }), MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
Liz Kammer12615db2021-09-28 09:19:17 -04001479 "deps": `[":libprotobuf-cpp-lite"]`,
1480 "whole_archive_deps": `[":foo_cc_proto_lite"]`,
1481 }),
1482 },
1483 })
1484}
Rupert Shuttleworth484aa252021-12-10 07:22:53 -05001485
1486func TestCcLibraryStaticUseVersionLib(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001487 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Liz Kammerbaced712022-09-16 09:01:29 -04001488 Filesystem: map[string]string{
1489 soongCcVersionLibBpPath: soongCcVersionLibBp,
1490 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001491 Blueprint: soongCcProtoPreamble + `cc_library_static {
Rupert Shuttleworth484aa252021-12-10 07:22:53 -05001492 name: "foo",
1493 use_version_lib: true,
Liz Kammerbaced712022-09-16 09:01:29 -04001494 static_libs: ["libbuildversion"],
Rupert Shuttleworth484aa252021-12-10 07:22:53 -05001495 include_build_directory: false,
1496}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001497 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001498 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
Liz Kammerbaced712022-09-16 09:01:29 -04001499 "implementation_whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
1500 }),
1501 },
1502 })
1503}
1504
1505func TestCcLibraryStaticUseVersionLibHasDep(t *testing.T) {
1506 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1507 Filesystem: map[string]string{
1508 soongCcVersionLibBpPath: soongCcVersionLibBp,
1509 },
1510 Blueprint: soongCcProtoPreamble + `cc_library_static {
1511 name: "foo",
1512 use_version_lib: true,
1513 whole_static_libs: ["libbuildversion"],
1514 include_build_directory: false,
1515}`,
1516 ExpectedBazelTargets: []string{
1517 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1518 "whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
Rupert Shuttleworth484aa252021-12-10 07:22:53 -05001519 }),
1520 },
1521 })
1522}
Liz Kammercac7f692021-12-16 14:19:32 -05001523
1524func TestCcLibraryStaticStdInFlags(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001525 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1526 Blueprint: soongCcProtoPreamble + `cc_library_static {
Liz Kammercac7f692021-12-16 14:19:32 -05001527 name: "foo",
1528 cflags: ["-std=candcpp"],
1529 conlyflags: ["-std=conly"],
1530 cppflags: ["-std=cpp"],
1531 include_build_directory: false,
1532}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001533 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001534 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
Liz Kammercac7f692021-12-16 14:19:32 -05001535 "conlyflags": `["-std=conly"]`,
1536 "cppflags": `["-std=cpp"]`,
1537 }),
1538 },
1539 })
1540}
Liz Kammer7128d382022-05-12 11:42:33 -04001541
1542func TestCcLibraryStaticStl(t *testing.T) {
1543 testCases := []struct {
1544 desc string
1545 prop string
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001546 attr AttrNameToString
Liz Kammer7128d382022-05-12 11:42:33 -04001547 }{
1548 {
1549 desc: "c++_shared deduped to libc++",
1550 prop: `stl: "c++_shared",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001551 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001552 "stl": `"libc++"`,
1553 },
1554 },
1555 {
1556 desc: "libc++ to libc++",
1557 prop: `stl: "libc++",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001558 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001559 "stl": `"libc++"`,
1560 },
1561 },
1562 {
1563 desc: "c++_static to libc++_static",
1564 prop: `stl: "c++_static",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001565 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001566 "stl": `"libc++_static"`,
1567 },
1568 },
1569 {
1570 desc: "libc++_static to libc++_static",
1571 prop: `stl: "libc++_static",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001572 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001573 "stl": `"libc++_static"`,
1574 },
1575 },
1576 {
1577 desc: "system to system",
1578 prop: `stl: "system",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001579 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001580 "stl": `"system"`,
1581 },
1582 },
1583 {
1584 desc: "none to none",
1585 prop: `stl: "none",`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001586 attr: AttrNameToString{
Liz Kammer7128d382022-05-12 11:42:33 -04001587 "stl": `"none"`,
1588 },
1589 },
1590 {
1591 desc: "empty to empty",
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001592 attr: AttrNameToString{},
Liz Kammer7128d382022-05-12 11:42:33 -04001593 },
1594 }
1595 for _, tc := range testCases {
1596 t.Run(tc.desc, func(*testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001597 runCcLibraryStaticTestCase(t, Bp2buildTestCase{
1598 Blueprint: fmt.Sprintf(`cc_library_static {
Liz Kammer7128d382022-05-12 11:42:33 -04001599 name: "foo",
1600 include_build_directory: false,
1601 %s
1602}`, tc.prop),
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001603 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001604 MakeBazelTarget("cc_library_static", "foo", tc.attr),
Liz Kammer7128d382022-05-12 11:42:33 -04001605 },
1606 })
1607 })
1608 }
1609}
Cole Faust6b29f592022-08-09 09:50:56 -07001610
1611func TestCCLibraryStaticRuntimeDeps(t *testing.T) {
1612 runCcLibrarySharedTestCase(t, Bp2buildTestCase{
1613 Blueprint: `cc_library_shared {
1614 name: "bar",
1615}
1616
1617cc_library_static {
1618 name: "foo",
1619 runtime_libs: ["foo"],
1620}`,
1621 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001622 MakeBazelTarget("cc_library_shared", "bar", AttrNameToString{
Cole Faust6b29f592022-08-09 09:50:56 -07001623 "local_includes": `["."]`,
1624 }),
Alixe06d75b2022-08-31 18:28:19 +00001625 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
Cole Faust6b29f592022-08-09 09:50:56 -07001626 "runtime_deps": `[":foo"]`,
1627 "local_includes": `["."]`,
1628 }),
1629 },
1630 })
1631}
Trevor Radcliffecee4e052022-09-06 19:31:25 +00001632
1633func TestCcLibraryStaticWithSyspropSrcs(t *testing.T) {
1634 runCcLibraryTestCase(t, Bp2buildTestCase{
1635 Description: "cc_library_static with sysprop sources",
1636 Blueprint: `
1637cc_library_static {
1638 name: "foo",
1639 srcs: [
1640 "bar.sysprop",
1641 "baz.sysprop",
1642 "blah.cpp",
1643 ],
1644 min_sdk_version: "5",
1645}`,
1646 ExpectedBazelTargets: []string{
1647 MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
1648 "srcs": `[
1649 "bar.sysprop",
1650 "baz.sysprop",
1651 ]`,
1652 }),
1653 MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
1654 "dep": `":foo_sysprop_library"`,
1655 "min_sdk_version": `"5"`,
1656 }),
1657 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1658 "srcs": `["blah.cpp"]`,
1659 "local_includes": `["."]`,
1660 "min_sdk_version": `"5"`,
1661 "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`,
1662 }),
1663 },
1664 })
1665}
1666
1667func TestCcLibraryStaticWithSyspropSrcsSomeConfigs(t *testing.T) {
1668 runCcLibraryTestCase(t, Bp2buildTestCase{
1669 Description: "cc_library_static with sysprop sources in some configs but not others",
1670 Blueprint: `
1671cc_library_static {
1672 name: "foo",
1673 srcs: [
1674 "blah.cpp",
1675 ],
1676 target: {
1677 android: {
1678 srcs: ["bar.sysprop"],
1679 },
1680 },
1681 min_sdk_version: "5",
1682}`,
1683 ExpectedBazelTargets: []string{
1684 MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
1685 "srcs": `select({
1686 "//build/bazel/platforms/os:android": ["bar.sysprop"],
1687 "//conditions:default": [],
1688 })`,
1689 }),
1690 MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
1691 "dep": `":foo_sysprop_library"`,
1692 "min_sdk_version": `"5"`,
1693 }),
1694 MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
1695 "srcs": `["blah.cpp"]`,
1696 "local_includes": `["."]`,
1697 "min_sdk_version": `"5"`,
1698 "whole_archive_deps": `select({
1699 "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"],
1700 "//conditions:default": [],
1701 })`,
1702 }),
1703 },
1704 })
1705}