blob: 72034faaa260931c5758c5c924120aa8de2f4c78 [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 (
18 "android/soong/android"
19 "android/soong/cc"
Chris Parsons484e50a2021-05-13 15:13:04 -040020 "android/soong/genrule"
21
Rupert Shuttleworth095081c2021-03-25 09:06:03 +000022 "testing"
23)
24
25const (
26 // See cc/testing.go for more context
27 soongCcLibraryStaticPreamble = `
28cc_defaults {
Liz Kammer8337ea42021-09-10 10:06:32 -040029 name: "linux_bionic_supported",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +000030}
31
32toolchain_library {
Liz Kammer8337ea42021-09-10 10:06:32 -040033 name: "libclang_rt.builtins-x86_64-android",
34 defaults: ["linux_bionic_supported"],
35 vendor_available: true,
36 vendor_ramdisk_available: true,
37 product_available: true,
38 recovery_available: true,
39 native_bridge_supported: true,
40 src: "",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +000041}`
42)
43
44func TestCcLibraryStaticLoadStatement(t *testing.T) {
45 testCases := []struct {
46 bazelTargets BazelTargets
47 expectedLoadStatements string
48 }{
49 {
50 bazelTargets: BazelTargets{
51 BazelTarget{
52 name: "cc_library_static_target",
53 ruleClass: "cc_library_static",
54 // NOTE: No bzlLoadLocation for native rules
55 },
56 },
57 expectedLoadStatements: ``,
58 },
59 }
60
61 for _, testCase := range testCases {
62 actual := testCase.bazelTargets.LoadStatements()
63 expected := testCase.expectedLoadStatements
64 if actual != expected {
65 t.Fatalf("Expected load statements to be %s, got %s", expected, actual)
66 }
67 }
68
69}
70
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +020071func registerCcLibraryStaticModuleTypes(ctx android.RegistrationContext) {
72 cc.RegisterCCBuildComponents(ctx)
73 ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory)
74 ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
75 ctx.RegisterModuleType("genrule", genrule.GenRuleFactory)
Chris Parsons51f8c392021-08-03 21:01:05 -040076 // Required for system_shared_libs dependencies.
77 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +020078}
79
80func runCcLibraryStaticTestCase(t *testing.T, tc bp2buildTestCase) {
Liz Kammere4982e82021-05-25 10:39:35 -040081 t.Helper()
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +020082 runBp2BuildTestCase(t, registerCcLibraryStaticModuleTypes, tc)
83}
84
85func TestCcLibraryStaticSimple(t *testing.T) {
86 runCcLibraryStaticTestCase(t, bp2buildTestCase{
87 description: "cc_library_static test",
88 moduleTypeUnderTest: "cc_library_static",
89 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
90 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
91 filesystem: map[string]string{
92 // NOTE: include_dir headers *should not* appear in Bazel hdrs later (?)
93 "include_dir_1/include_dir_1_a.h": "",
94 "include_dir_1/include_dir_1_b.h": "",
95 "include_dir_2/include_dir_2_a.h": "",
96 "include_dir_2/include_dir_2_b.h": "",
97 // NOTE: local_include_dir headers *should not* appear in Bazel hdrs later (?)
98 "local_include_dir_1/local_include_dir_1_a.h": "",
99 "local_include_dir_1/local_include_dir_1_b.h": "",
100 "local_include_dir_2/local_include_dir_2_a.h": "",
101 "local_include_dir_2/local_include_dir_2_b.h": "",
102 // NOTE: export_include_dir headers *should* appear in Bazel hdrs later
103 "export_include_dir_1/export_include_dir_1_a.h": "",
104 "export_include_dir_1/export_include_dir_1_b.h": "",
105 "export_include_dir_2/export_include_dir_2_a.h": "",
106 "export_include_dir_2/export_include_dir_2_b.h": "",
107 // NOTE: Soong implicitly includes headers in the current directory
108 "implicit_include_1.h": "",
109 "implicit_include_2.h": "",
110 },
111 blueprint: soongCcLibraryStaticPreamble + `
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000112cc_library_headers {
113 name: "header_lib_1",
114 export_include_dirs: ["header_lib_1"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400115 bazel_module: { bp2build_available: false },
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000116}
117
118cc_library_headers {
119 name: "header_lib_2",
120 export_include_dirs: ["header_lib_2"],
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: "static_lib_1",
126 srcs: ["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: "static_lib_2",
132 srcs: ["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: "whole_static_lib_1",
138 srcs: ["whole_static_lib_1.cc"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400139 bazel_module: { bp2build_available: false },
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000140}
141
142cc_library_static {
143 name: "whole_static_lib_2",
144 srcs: ["whole_static_lib_2.cc"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400145 bazel_module: { bp2build_available: false },
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000146}
147
148cc_library_static {
149 name: "foo_static",
150 srcs: [
151 "foo_static1.cc",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000152 "foo_static2.cc",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000153 ],
154 cflags: [
155 "-Dflag1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000156 "-Dflag2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000157 ],
158 static_libs: [
159 "static_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000160 "static_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000161 ],
162 whole_static_libs: [
163 "whole_static_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000164 "whole_static_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000165 ],
166 include_dirs: [
Jingwen Chened9c17d2021-04-13 07:14:55 +0000167 "include_dir_1",
168 "include_dir_2",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000169 ],
170 local_include_dirs: [
171 "local_include_dir_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000172 "local_include_dir_2",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000173 ],
174 export_include_dirs: [
Chris Parsonsd6358772021-05-18 18:35:24 -0400175 "export_include_dir_1",
176 "export_include_dir_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000177 ],
178 header_libs: [
179 "header_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000180 "header_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000181 ],
182
183 // TODO: Also support export_header_lib_headers
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000184}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200185 expectedBazelTargets: []string{`cc_library_static(
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000186 name = "foo_static",
Liz Kammer35687bc2021-09-10 10:07:07 -0400187 absolute_includes = [
188 "include_dir_1",
189 "include_dir_2",
190 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000191 copts = [
192 "-Dflag1",
193 "-Dflag2",
194 ],
Liz Kammer5fad5012021-09-09 14:08:21 -0400195 export_includes = [
196 "export_include_dir_1",
197 "export_include_dir_2",
198 ],
Chris Parsonsd6358772021-05-18 18:35:24 -0400199 implementation_deps = [
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000200 ":header_lib_1",
201 ":header_lib_2",
202 ":static_lib_1",
203 ":static_lib_2",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000204 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000205 linkstatic = True,
Liz Kammer35687bc2021-09-10 10:07:07 -0400206 local_includes = [
207 "local_include_dir_1",
208 "local_include_dir_2",
209 ".",
210 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000211 srcs = [
212 "foo_static1.cc",
213 "foo_static2.cc",
214 ],
Chris Parsons08648312021-05-06 16:23:19 -0400215 whole_archive_deps = [
216 ":whole_static_lib_1",
217 ":whole_static_lib_2",
218 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000219)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200220 })
221}
222
223func TestCcLibraryStaticSubpackage(t *testing.T) {
224 runCcLibraryStaticTestCase(t, bp2buildTestCase{
225 description: "cc_library_static subpackage test",
226 moduleTypeUnderTest: "cc_library_static",
227 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
228 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
229 filesystem: map[string]string{
230 // subpackage with subdirectory
231 "subpackage/Android.bp": "",
232 "subpackage/subpackage_header.h": "",
233 "subpackage/subdirectory/subdirectory_header.h": "",
234 // subsubpackage with subdirectory
235 "subpackage/subsubpackage/Android.bp": "",
236 "subpackage/subsubpackage/subsubpackage_header.h": "",
237 "subpackage/subsubpackage/subdirectory/subdirectory_header.h": "",
238 // subsubsubpackage with subdirectory
239 "subpackage/subsubpackage/subsubsubpackage/Android.bp": "",
240 "subpackage/subsubpackage/subsubsubpackage/subsubsubpackage_header.h": "",
241 "subpackage/subsubpackage/subsubsubpackage/subdirectory/subdirectory_header.h": "",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000242 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200243 blueprint: soongCcLibraryStaticPreamble + `
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400244cc_library_static {
245 name: "foo_static",
Liz Kammer35687bc2021-09-10 10:07:07 -0400246 srcs: [],
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400247 include_dirs: [
Liz Kammer35687bc2021-09-10 10:07:07 -0400248 "subpackage",
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400249 ],
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400250}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200251 expectedBazelTargets: []string{`cc_library_static(
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400252 name = "foo_static",
Liz Kammer35687bc2021-09-10 10:07:07 -0400253 absolute_includes = ["subpackage"],
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400254 linkstatic = True,
Liz Kammer35687bc2021-09-10 10:07:07 -0400255 local_includes = ["."],
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400256)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200257 })
258}
259
260func TestCcLibraryStaticExportIncludeDir(t *testing.T) {
261 runCcLibraryStaticTestCase(t, bp2buildTestCase{
262 description: "cc_library_static export include dir",
263 moduleTypeUnderTest: "cc_library_static",
264 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
265 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
266 filesystem: map[string]string{
267 // subpackage with subdirectory
268 "subpackage/Android.bp": "",
269 "subpackage/subpackage_header.h": "",
270 "subpackage/subdirectory/subdirectory_header.h": "",
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400271 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200272 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000273cc_library_static {
274 name: "foo_static",
275 export_include_dirs: ["subpackage"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400276 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000277}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200278 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000279 name = "foo_static",
Liz Kammer5fad5012021-09-09 14:08:21 -0400280 export_includes = ["subpackage"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000281 linkstatic = True,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000282)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200283 })
284}
285
286func TestCcLibraryStaticExportSystemIncludeDir(t *testing.T) {
287 runCcLibraryStaticTestCase(t, bp2buildTestCase{
288 description: "cc_library_static export system include dir",
289 moduleTypeUnderTest: "cc_library_static",
290 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
291 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
292 filesystem: map[string]string{
293 // subpackage with subdirectory
294 "subpackage/Android.bp": "",
295 "subpackage/subpackage_header.h": "",
296 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000297 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200298 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000299cc_library_static {
300 name: "foo_static",
301 export_system_include_dirs: ["subpackage"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400302 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000303}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200304 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000305 name = "foo_static",
Liz Kammer5fad5012021-09-09 14:08:21 -0400306 export_system_includes = ["subpackage"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000307 linkstatic = True,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000308)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200309 })
310}
311
312func TestCcLibraryStaticManyIncludeDirs(t *testing.T) {
313 runCcLibraryStaticTestCase(t, bp2buildTestCase{
314 description: "cc_library_static include_dirs, local_include_dirs, export_include_dirs (b/183742505)",
315 moduleTypeUnderTest: "cc_library_static",
316 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
317 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
318 dir: "subpackage",
319 filesystem: map[string]string{
320 // subpackage with subdirectory
321 "subpackage/Android.bp": `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000322cc_library_static {
323 name: "foo_static",
324 // include_dirs are workspace/root relative
325 include_dirs: [
326 "subpackage/subsubpackage",
327 "subpackage2",
328 "subpackage3/subsubpackage"
329 ],
330 local_include_dirs: ["subsubpackage2"], // module dir relative
331 export_include_dirs: ["./exported_subsubpackage"], // module dir relative
332 include_build_directory: true,
333 bazel_module: { bp2build_available: true },
334}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200335 "subpackage/subsubpackage/header.h": "",
336 "subpackage/subsubpackage2/header.h": "",
337 "subpackage/exported_subsubpackage/header.h": "",
338 "subpackage2/header.h": "",
339 "subpackage3/subsubpackage/header.h": "",
340 },
341 blueprint: soongCcLibraryStaticPreamble,
342 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000343 name = "foo_static",
Liz Kammer35687bc2021-09-10 10:07:07 -0400344 absolute_includes = [
345 "subpackage/subsubpackage",
346 "subpackage2",
347 "subpackage3/subsubpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000348 ],
Liz Kammer5fad5012021-09-09 14:08:21 -0400349 export_includes = ["./exported_subsubpackage"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000350 linkstatic = True,
Liz Kammer35687bc2021-09-10 10:07:07 -0400351 local_includes = [
352 "subsubpackage2",
353 ".",
354 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000355)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200356 })
357}
358
359func TestCcLibraryStaticIncludeBuildDirectoryDisabled(t *testing.T) {
360 runCcLibraryStaticTestCase(t, bp2buildTestCase{
361 description: "cc_library_static include_build_directory disabled",
362 moduleTypeUnderTest: "cc_library_static",
363 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
364 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
365 filesystem: map[string]string{
366 // subpackage with subdirectory
367 "subpackage/Android.bp": "",
368 "subpackage/subpackage_header.h": "",
369 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000370 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200371 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000372cc_library_static {
373 name: "foo_static",
374 include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended
375 local_include_dirs: ["subpackage2"],
376 include_build_directory: false,
377}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200378 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000379 name = "foo_static",
Liz Kammer35687bc2021-09-10 10:07:07 -0400380 absolute_includes = ["subpackage"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000381 linkstatic = True,
Liz Kammer35687bc2021-09-10 10:07:07 -0400382 local_includes = ["subpackage2"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000383)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200384 })
385}
386
387func TestCcLibraryStaticIncludeBuildDirectoryEnabled(t *testing.T) {
388 runCcLibraryStaticTestCase(t, bp2buildTestCase{
389 description: "cc_library_static include_build_directory enabled",
390 moduleTypeUnderTest: "cc_library_static",
391 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
392 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
393 filesystem: map[string]string{
394 // subpackage with subdirectory
395 "subpackage/Android.bp": "",
396 "subpackage/subpackage_header.h": "",
397 "subpackage2/Android.bp": "",
398 "subpackage2/subpackage2_header.h": "",
399 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000400 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200401 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000402cc_library_static {
403 name: "foo_static",
404 include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended
405 local_include_dirs: ["subpackage2"],
406 include_build_directory: true,
407}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200408 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000409 name = "foo_static",
Liz Kammer35687bc2021-09-10 10:07:07 -0400410 absolute_includes = ["subpackage"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000411 linkstatic = True,
Liz Kammer35687bc2021-09-10 10:07:07 -0400412 local_includes = [
413 "subpackage2",
414 ".",
415 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000416)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200417 })
418}
419
420func TestCcLibraryStaticArchSpecificStaticLib(t *testing.T) {
421 runCcLibraryStaticTestCase(t, bp2buildTestCase{
422 description: "cc_library_static arch-specific static_libs",
423 moduleTypeUnderTest: "cc_library_static",
424 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
425 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200426 filesystem: map[string]string{},
427 blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -0400428cc_library_static {
429 name: "static_dep",
430 bazel_module: { bp2build_available: false },
431}
432cc_library_static {
433 name: "static_dep2",
434 bazel_module: { bp2build_available: false },
435}
Jingwen Chened9c17d2021-04-13 07:14:55 +0000436cc_library_static {
437 name: "foo_static",
438 arch: { arm64: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } },
Liz Kammer8337ea42021-09-10 10:06:32 -0400439 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000440}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200441 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000442 name = "foo_static",
Chris Parsonsd6358772021-05-18 18:35:24 -0400443 implementation_deps = select({
Chris Parsons08648312021-05-06 16:23:19 -0400444 "//build/bazel/platforms/arch:arm64": [":static_dep"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000445 "//conditions:default": [],
446 }),
447 linkstatic = True,
Chris Parsons08648312021-05-06 16:23:19 -0400448 whole_archive_deps = select({
449 "//build/bazel/platforms/arch:arm64": [":static_dep2"],
450 "//conditions:default": [],
451 }),
Jingwen Chened9c17d2021-04-13 07:14:55 +0000452)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200453 })
454}
455
456func TestCcLibraryStaticOsSpecificStaticLib(t *testing.T) {
457 runCcLibraryStaticTestCase(t, bp2buildTestCase{
458 description: "cc_library_static os-specific static_libs",
459 moduleTypeUnderTest: "cc_library_static",
460 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
461 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200462 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}
Jingwen Chened9c17d2021-04-13 07:14:55 +0000472cc_library_static {
473 name: "foo_static",
474 target: { android: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } },
Liz Kammer8337ea42021-09-10 10:06:32 -0400475 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000476}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200477 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000478 name = "foo_static",
Chris Parsonsd6358772021-05-18 18:35:24 -0400479 implementation_deps = select({
Chris Parsons08648312021-05-06 16:23:19 -0400480 "//build/bazel/platforms/os:android": [":static_dep"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000481 "//conditions:default": [],
482 }),
483 linkstatic = True,
Chris Parsons08648312021-05-06 16:23:19 -0400484 whole_archive_deps = select({
485 "//build/bazel/platforms/os:android": [":static_dep2"],
486 "//conditions:default": [],
487 }),
Jingwen Chened9c17d2021-04-13 07:14:55 +0000488)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200489 })
490}
491
492func TestCcLibraryStaticBaseArchOsSpecificStaticLib(t *testing.T) {
493 runCcLibraryStaticTestCase(t, bp2buildTestCase{
494 description: "cc_library_static base, arch and os-specific static_libs",
495 moduleTypeUnderTest: "cc_library_static",
496 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
497 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200498 filesystem: map[string]string{},
499 blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -0400500cc_library_static {
501 name: "static_dep",
502 bazel_module: { bp2build_available: false },
503}
504cc_library_static {
505 name: "static_dep2",
506 bazel_module: { bp2build_available: false },
507}
508cc_library_static {
509 name: "static_dep3",
510 bazel_module: { bp2build_available: false },
511}
512cc_library_static {
513 name: "static_dep4",
514 bazel_module: { bp2build_available: false },
515}
Jingwen Chened9c17d2021-04-13 07:14:55 +0000516cc_library_static {
517 name: "foo_static",
518 static_libs: ["static_dep"],
519 whole_static_libs: ["static_dep2"],
520 target: { android: { static_libs: ["static_dep3"] } },
521 arch: { arm64: { static_libs: ["static_dep4"] } },
Liz Kammer8337ea42021-09-10 10:06:32 -0400522 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000523}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200524 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000525 name = "foo_static",
Chris Parsonsd6358772021-05-18 18:35:24 -0400526 implementation_deps = [":static_dep"] + select({
Jingwen Chened9c17d2021-04-13 07:14:55 +0000527 "//build/bazel/platforms/arch:arm64": [":static_dep4"],
528 "//conditions:default": [],
529 }) + select({
530 "//build/bazel/platforms/os:android": [":static_dep3"],
531 "//conditions:default": [],
532 }),
533 linkstatic = True,
Chris Parsons08648312021-05-06 16:23:19 -0400534 whole_archive_deps = [":static_dep2"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000535)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200536 })
537}
538
539func TestCcLibraryStaticSimpleExcludeSrcs(t *testing.T) {
540 runCcLibraryStaticTestCase(t, bp2buildTestCase{
541 description: "cc_library_static simple exclude_srcs",
542 moduleTypeUnderTest: "cc_library_static",
543 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
544 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200545 filesystem: map[string]string{
546 "common.c": "",
547 "foo-a.c": "",
548 "foo-excluded.c": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000549 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200550 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000551cc_library_static {
552 name: "foo_static",
553 srcs: ["common.c", "foo-*.c"],
554 exclude_srcs: ["foo-excluded.c"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400555 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000556}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200557 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000558 name = "foo_static",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000559 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400560 srcs_c = [
Jingwen Chene32e9e02021-04-23 09:17:24 +0000561 "common.c",
562 "foo-a.c",
563 ],
564)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200565 })
566}
567
568func TestCcLibraryStaticOneArchSrcs(t *testing.T) {
569 runCcLibraryStaticTestCase(t, bp2buildTestCase{
570 description: "cc_library_static one arch specific srcs",
571 moduleTypeUnderTest: "cc_library_static",
572 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
573 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200574 filesystem: map[string]string{
575 "common.c": "",
576 "foo-arm.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000577 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200578 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000579cc_library_static {
580 name: "foo_static",
581 srcs: ["common.c"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400582 arch: { arm: { srcs: ["foo-arm.c"] } },
583 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000584}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200585 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000586 name = "foo_static",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000587 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400588 srcs_c = ["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000589 "//build/bazel/platforms/arch:arm": ["foo-arm.c"],
590 "//conditions:default": [],
591 }),
592)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200593 })
594}
595
596func TestCcLibraryStaticOneArchSrcsExcludeSrcs(t *testing.T) {
597 runCcLibraryStaticTestCase(t, bp2buildTestCase{
598 description: "cc_library_static one arch specific srcs and exclude_srcs",
599 moduleTypeUnderTest: "cc_library_static",
600 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
601 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200602 filesystem: map[string]string{
603 "common.c": "",
604 "for-arm.c": "",
605 "not-for-arm.c": "",
606 "not-for-anything.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000607 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200608 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000609cc_library_static {
610 name: "foo_static",
611 srcs: ["common.c", "not-for-*.c"],
612 exclude_srcs: ["not-for-anything.c"],
613 arch: {
614 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
615 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400616 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000617}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200618 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000619 name = "foo_static",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000620 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400621 srcs_c = ["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000622 "//build/bazel/platforms/arch:arm": ["for-arm.c"],
623 "//conditions:default": ["not-for-arm.c"],
624 }),
625)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200626 })
627}
628
629func TestCcLibraryStaticTwoArchExcludeSrcs(t *testing.T) {
630 runCcLibraryStaticTestCase(t, bp2buildTestCase{
631 description: "cc_library_static arch specific exclude_srcs for 2 architectures",
632 moduleTypeUnderTest: "cc_library_static",
633 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
634 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200635 filesystem: map[string]string{
636 "common.c": "",
637 "for-arm.c": "",
638 "for-x86.c": "",
639 "not-for-arm.c": "",
640 "not-for-x86.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000641 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200642 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000643cc_library_static {
644 name: "foo_static",
645 srcs: ["common.c", "not-for-*.c"],
646 exclude_srcs: ["not-for-everything.c"],
647 arch: {
648 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
649 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
650 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400651 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000652} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200653 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000654 name = "foo_static",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000655 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400656 srcs_c = ["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000657 "//build/bazel/platforms/arch:arm": [
658 "for-arm.c",
659 "not-for-x86.c",
660 ],
661 "//build/bazel/platforms/arch:x86": [
662 "for-x86.c",
663 "not-for-arm.c",
664 ],
665 "//conditions:default": [
666 "not-for-arm.c",
667 "not-for-x86.c",
668 ],
669 }),
670)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200671 })
672}
673func TestCcLibraryStaticFourArchExcludeSrcs(t *testing.T) {
674 runCcLibraryStaticTestCase(t, bp2buildTestCase{
675 description: "cc_library_static arch specific exclude_srcs for 4 architectures",
676 moduleTypeUnderTest: "cc_library_static",
677 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
678 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200679 filesystem: map[string]string{
680 "common.c": "",
681 "for-arm.c": "",
682 "for-arm64.c": "",
683 "for-x86.c": "",
684 "for-x86_64.c": "",
685 "not-for-arm.c": "",
686 "not-for-arm64.c": "",
687 "not-for-x86.c": "",
688 "not-for-x86_64.c": "",
689 "not-for-everything.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000690 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200691 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000692cc_library_static {
693 name: "foo_static",
694 srcs: ["common.c", "not-for-*.c"],
695 exclude_srcs: ["not-for-everything.c"],
696 arch: {
697 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
698 arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] },
699 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
700 x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] },
Liz Kammer8337ea42021-09-10 10:06:32 -0400701 },
702 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000703} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200704 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000705 name = "foo_static",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000706 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400707 srcs_c = ["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000708 "//build/bazel/platforms/arch:arm": [
709 "for-arm.c",
710 "not-for-arm64.c",
711 "not-for-x86.c",
712 "not-for-x86_64.c",
713 ],
714 "//build/bazel/platforms/arch:arm64": [
715 "for-arm64.c",
716 "not-for-arm.c",
717 "not-for-x86.c",
718 "not-for-x86_64.c",
719 ],
720 "//build/bazel/platforms/arch:x86": [
721 "for-x86.c",
722 "not-for-arm.c",
723 "not-for-arm64.c",
724 "not-for-x86_64.c",
725 ],
726 "//build/bazel/platforms/arch:x86_64": [
727 "for-x86_64.c",
728 "not-for-arm.c",
729 "not-for-arm64.c",
730 "not-for-x86.c",
731 ],
732 "//conditions:default": [
733 "not-for-arm.c",
734 "not-for-arm64.c",
735 "not-for-x86.c",
736 "not-for-x86_64.c",
737 ],
738 }),
739)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200740 })
741}
742
Liz Kammer2b07ec72021-05-26 15:08:27 -0400743func TestCcLibraryStaticOneArchEmpty(t *testing.T) {
744 runCcLibraryStaticTestCase(t, bp2buildTestCase{
745 description: "cc_library_static one arch empty",
746 moduleTypeUnderTest: "cc_library_static",
747 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
748 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammer2b07ec72021-05-26 15:08:27 -0400749 filesystem: map[string]string{
750 "common.cc": "",
751 "foo-no-arm.cc": "",
752 "foo-excluded.cc": "",
753 },
754 blueprint: soongCcLibraryStaticPreamble + `
755cc_library_static {
756 name: "foo_static",
757 srcs: ["common.cc", "foo-*.cc"],
758 exclude_srcs: ["foo-excluded.cc"],
759 arch: {
760 arm: { exclude_srcs: ["foo-no-arm.cc"] },
761 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400762 include_build_directory: false,
Liz Kammer2b07ec72021-05-26 15:08:27 -0400763}`,
764 expectedBazelTargets: []string{`cc_library_static(
765 name = "foo_static",
Liz Kammer2b07ec72021-05-26 15:08:27 -0400766 linkstatic = True,
767 srcs = ["common.cc"] + select({
768 "//build/bazel/platforms/arch:arm": [],
769 "//conditions:default": ["foo-no-arm.cc"],
770 }),
771)`},
772 })
773}
774
775func TestCcLibraryStaticOneArchEmptyOtherSet(t *testing.T) {
776 runCcLibraryStaticTestCase(t, bp2buildTestCase{
777 description: "cc_library_static one arch empty other set",
778 moduleTypeUnderTest: "cc_library_static",
779 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
780 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammer2b07ec72021-05-26 15:08:27 -0400781 filesystem: map[string]string{
782 "common.cc": "",
783 "foo-no-arm.cc": "",
784 "x86-only.cc": "",
785 "foo-excluded.cc": "",
786 },
787 blueprint: soongCcLibraryStaticPreamble + `
788cc_library_static {
789 name: "foo_static",
790 srcs: ["common.cc", "foo-*.cc"],
791 exclude_srcs: ["foo-excluded.cc"],
792 arch: {
793 arm: { exclude_srcs: ["foo-no-arm.cc"] },
794 x86: { srcs: ["x86-only.cc"] },
795 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400796 include_build_directory: false,
Liz Kammer2b07ec72021-05-26 15:08:27 -0400797}`,
798 expectedBazelTargets: []string{`cc_library_static(
799 name = "foo_static",
Liz Kammer2b07ec72021-05-26 15:08:27 -0400800 linkstatic = True,
801 srcs = ["common.cc"] + select({
802 "//build/bazel/platforms/arch:arm": [],
803 "//build/bazel/platforms/arch:x86": [
804 "foo-no-arm.cc",
805 "x86-only.cc",
806 ],
807 "//conditions:default": ["foo-no-arm.cc"],
808 }),
809)`},
810 })
811}
812
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200813func TestCcLibraryStaticMultipleDepSameName(t *testing.T) {
814 runCcLibraryStaticTestCase(t, bp2buildTestCase{
815 description: "cc_library_static multiple dep same name panic",
816 moduleTypeUnderTest: "cc_library_static",
817 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
818 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200819 filesystem: map[string]string{},
820 blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -0400821cc_library_static {
822 name: "static_dep",
823 bazel_module: { bp2build_available: false },
824}
Liz Kammer2b50ce62021-04-26 15:47:28 -0400825cc_library_static {
826 name: "foo_static",
Chris Parsons08648312021-05-06 16:23:19 -0400827 static_libs: ["static_dep", "static_dep"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400828 include_build_directory: false,
Liz Kammer2b50ce62021-04-26 15:47:28 -0400829}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200830 expectedBazelTargets: []string{`cc_library_static(
Liz Kammer2b50ce62021-04-26 15:47:28 -0400831 name = "foo_static",
Chris Parsonsd6358772021-05-18 18:35:24 -0400832 implementation_deps = [":static_dep"],
Liz Kammer2b50ce62021-04-26 15:47:28 -0400833 linkstatic = True,
Liz Kammer2b50ce62021-04-26 15:47:28 -0400834)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200835 })
836}
837
838func TestCcLibraryStaticOneMultilibSrcsExcludeSrcs(t *testing.T) {
839 runCcLibraryStaticTestCase(t, bp2buildTestCase{
840 description: "cc_library_static 1 multilib srcs and exclude_srcs",
841 moduleTypeUnderTest: "cc_library_static",
842 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
843 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200844 filesystem: map[string]string{
845 "common.c": "",
846 "for-lib32.c": "",
847 "not-for-lib32.c": "",
Liz Kammer2b50ce62021-04-26 15:47:28 -0400848 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200849 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -0400850cc_library_static {
851 name: "foo_static",
852 srcs: ["common.c", "not-for-*.c"],
853 multilib: {
854 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
855 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400856 include_build_directory: false,
Chris Parsonsc424b762021-04-29 18:06:50 -0400857} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200858 expectedBazelTargets: []string{`cc_library_static(
Chris Parsonsc424b762021-04-29 18:06:50 -0400859 name = "foo_static",
Chris Parsonsc424b762021-04-29 18:06:50 -0400860 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400861 srcs_c = ["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -0400862 "//build/bazel/platforms/arch:arm": ["for-lib32.c"],
863 "//build/bazel/platforms/arch:x86": ["for-lib32.c"],
864 "//conditions:default": ["not-for-lib32.c"],
865 }),
866)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200867 })
868}
869
870func TestCcLibraryStaticTwoMultilibSrcsExcludeSrcs(t *testing.T) {
871 runCcLibraryStaticTestCase(t, bp2buildTestCase{
872 description: "cc_library_static 2 multilib srcs and exclude_srcs",
873 moduleTypeUnderTest: "cc_library_static",
874 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
875 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200876 filesystem: map[string]string{
877 "common.c": "",
878 "for-lib32.c": "",
879 "for-lib64.c": "",
880 "not-for-lib32.c": "",
881 "not-for-lib64.c": "",
Chris Parsonsc424b762021-04-29 18:06:50 -0400882 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200883 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -0400884cc_library_static {
885 name: "foo_static2",
886 srcs: ["common.c", "not-for-*.c"],
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} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200893 expectedBazelTargets: []string{`cc_library_static(
Chris Parsonsc424b762021-04-29 18:06:50 -0400894 name = "foo_static2",
Chris Parsonsc424b762021-04-29 18:06:50 -0400895 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400896 srcs_c = ["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -0400897 "//build/bazel/platforms/arch:arm": [
898 "for-lib32.c",
899 "not-for-lib64.c",
900 ],
901 "//build/bazel/platforms/arch:arm64": [
902 "for-lib64.c",
903 "not-for-lib32.c",
904 ],
905 "//build/bazel/platforms/arch:x86": [
906 "for-lib32.c",
907 "not-for-lib64.c",
908 ],
909 "//build/bazel/platforms/arch:x86_64": [
910 "for-lib64.c",
911 "not-for-lib32.c",
912 ],
913 "//conditions:default": [
914 "not-for-lib32.c",
915 "not-for-lib64.c",
916 ],
917 }),
918)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200919 })
920}
921
922func TestCcLibrarySTaticArchMultilibSrcsExcludeSrcs(t *testing.T) {
923 runCcLibraryStaticTestCase(t, bp2buildTestCase{
924 description: "cc_library_static arch and multilib srcs and exclude_srcs",
925 moduleTypeUnderTest: "cc_library_static",
926 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
927 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200928 filesystem: map[string]string{
929 "common.c": "",
930 "for-arm.c": "",
931 "for-arm64.c": "",
932 "for-x86.c": "",
933 "for-x86_64.c": "",
934 "for-lib32.c": "",
935 "for-lib64.c": "",
936 "not-for-arm.c": "",
937 "not-for-arm64.c": "",
938 "not-for-x86.c": "",
939 "not-for-x86_64.c": "",
940 "not-for-lib32.c": "",
941 "not-for-lib64.c": "",
942 "not-for-everything.c": "",
Chris Parsonsc424b762021-04-29 18:06:50 -0400943 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200944 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -0400945cc_library_static {
946 name: "foo_static3",
947 srcs: ["common.c", "not-for-*.c"],
948 exclude_srcs: ["not-for-everything.c"],
949 arch: {
950 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
951 arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] },
952 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
953 x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] },
954 },
955 multilib: {
956 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
957 lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] },
958 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400959 include_build_directory: false,
Chris Parsonsc424b762021-04-29 18:06:50 -0400960}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200961 expectedBazelTargets: []string{`cc_library_static(
Chris Parsonsc424b762021-04-29 18:06:50 -0400962 name = "foo_static3",
Chris Parsonsc424b762021-04-29 18:06:50 -0400963 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400964 srcs_c = ["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -0400965 "//build/bazel/platforms/arch:arm": [
966 "for-arm.c",
967 "for-lib32.c",
968 "not-for-arm64.c",
969 "not-for-lib64.c",
970 "not-for-x86.c",
971 "not-for-x86_64.c",
972 ],
973 "//build/bazel/platforms/arch:arm64": [
974 "for-arm64.c",
975 "for-lib64.c",
976 "not-for-arm.c",
977 "not-for-lib32.c",
978 "not-for-x86.c",
979 "not-for-x86_64.c",
980 ],
981 "//build/bazel/platforms/arch:x86": [
982 "for-lib32.c",
983 "for-x86.c",
984 "not-for-arm.c",
985 "not-for-arm64.c",
986 "not-for-lib64.c",
987 "not-for-x86_64.c",
988 ],
989 "//build/bazel/platforms/arch:x86_64": [
990 "for-lib64.c",
991 "for-x86_64.c",
992 "not-for-arm.c",
993 "not-for-arm64.c",
994 "not-for-lib32.c",
995 "not-for-x86.c",
996 ],
997 "//conditions:default": [
998 "not-for-arm.c",
999 "not-for-arm64.c",
1000 "not-for-lib32.c",
1001 "not-for-lib64.c",
1002 "not-for-x86.c",
1003 "not-for-x86_64.c",
1004 ],
1005 }),
1006)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001007 })
1008}
1009
1010func TestCcLibraryStaticArchSrcsExcludeSrcsGeneratedFiles(t *testing.T) {
1011 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1012 description: "cc_library_static arch srcs/exclude_srcs with generated files",
1013 moduleTypeUnderTest: "cc_library_static",
1014 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1015 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001016 filesystem: map[string]string{
Chris Parsons990c4f42021-05-25 12:10:58 -04001017 "common.cpp": "",
1018 "for-x86.cpp": "",
1019 "not-for-x86.cpp": "",
1020 "not-for-everything.cpp": "",
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001021 "dep/Android.bp": `
Chris Parsons484e50a2021-05-13 15:13:04 -04001022genrule {
Liz Kammer8337ea42021-09-10 10:06:32 -04001023 name: "generated_src_other_pkg",
1024 out: ["generated_src_other_pkg.cpp"],
1025 cmd: "nothing to see here",
Chris Parsons484e50a2021-05-13 15:13:04 -04001026}
1027
1028genrule {
Liz Kammer8337ea42021-09-10 10:06:32 -04001029 name: "generated_hdr_other_pkg",
1030 out: ["generated_hdr_other_pkg.cpp"],
1031 cmd: "nothing to see here",
Chris Parsons484e50a2021-05-13 15:13:04 -04001032}
1033
1034genrule {
Liz Kammer8337ea42021-09-10 10:06:32 -04001035 name: "generated_hdr_other_pkg_x86",
1036 out: ["generated_hdr_other_pkg_x86.cpp"],
1037 cmd: "nothing to see here",
Chris Parsons484e50a2021-05-13 15:13:04 -04001038}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001039 },
1040 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsons484e50a2021-05-13 15:13:04 -04001041genrule {
1042 name: "generated_src",
1043 out: ["generated_src.cpp"],
1044 cmd: "nothing to see here",
1045}
1046
1047genrule {
1048 name: "generated_src_x86",
1049 out: ["generated_src_x86.cpp"],
1050 cmd: "nothing to see here",
1051}
1052
1053genrule {
1054 name: "generated_hdr",
1055 out: ["generated_hdr.h"],
1056 cmd: "nothing to see here",
1057}
1058
1059cc_library_static {
1060 name: "foo_static3",
Chris Parsons990c4f42021-05-25 12:10:58 -04001061 srcs: ["common.cpp", "not-for-*.cpp"],
1062 exclude_srcs: ["not-for-everything.cpp"],
Chris Parsons484e50a2021-05-13 15:13:04 -04001063 generated_sources: ["generated_src", "generated_src_other_pkg"],
1064 generated_headers: ["generated_hdr", "generated_hdr_other_pkg"],
1065 arch: {
1066 x86: {
Chris Parsons990c4f42021-05-25 12:10:58 -04001067 srcs: ["for-x86.cpp"],
1068 exclude_srcs: ["not-for-x86.cpp"],
Chris Parsons484e50a2021-05-13 15:13:04 -04001069 generated_sources: ["generated_src_x86"],
1070 generated_headers: ["generated_hdr_other_pkg_x86"],
1071 },
1072 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001073 include_build_directory: false,
Chris Parsons484e50a2021-05-13 15:13:04 -04001074}
1075`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001076 expectedBazelTargets: []string{`cc_library_static(
Chris Parsons484e50a2021-05-13 15:13:04 -04001077 name = "foo_static3",
Chris Parsons484e50a2021-05-13 15:13:04 -04001078 linkstatic = True,
1079 srcs = [
1080 "//dep:generated_hdr_other_pkg",
1081 "//dep:generated_src_other_pkg",
1082 ":generated_hdr",
1083 ":generated_src",
Chris Parsons990c4f42021-05-25 12:10:58 -04001084 "common.cpp",
Chris Parsons484e50a2021-05-13 15:13:04 -04001085 ] + select({
1086 "//build/bazel/platforms/arch:x86": [
1087 "//dep:generated_hdr_other_pkg_x86",
1088 ":generated_src_x86",
Chris Parsons990c4f42021-05-25 12:10:58 -04001089 "for-x86.cpp",
Chris Parsons484e50a2021-05-13 15:13:04 -04001090 ],
Chris Parsons990c4f42021-05-25 12:10:58 -04001091 "//conditions:default": ["not-for-x86.cpp"],
Chris Parsons484e50a2021-05-13 15:13:04 -04001092 }),
1093)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001094 })
Rupert Shuttleworth095081c2021-03-25 09:06:03 +00001095}
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001096
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001097func TestCcLibraryStaticGetTargetProperties(t *testing.T) {
1098 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1099
1100 description: "cc_library_static complex GetTargetProperties",
1101 moduleTypeUnderTest: "cc_library_static",
1102 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1103 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001104 blueprint: soongCcLibraryStaticPreamble + `
1105cc_library_static {
1106 name: "foo_static",
1107 target: {
1108 android: {
1109 srcs: ["android_src.c"],
1110 },
1111 android_arm: {
1112 srcs: ["android_arm_src.c"],
1113 },
1114 android_arm64: {
1115 srcs: ["android_arm64_src.c"],
1116 },
1117 android_x86: {
1118 srcs: ["android_x86_src.c"],
1119 },
1120 android_x86_64: {
1121 srcs: ["android_x86_64_src.c"],
1122 },
1123 linux_bionic_arm64: {
1124 srcs: ["linux_bionic_arm64_src.c"],
1125 },
1126 linux_bionic_x86_64: {
1127 srcs: ["linux_bionic_x86_64_src.c"],
1128 },
1129 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001130 include_build_directory: false,
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001131}`,
1132 expectedBazelTargets: []string{`cc_library_static(
1133 name = "foo_static",
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001134 linkstatic = True,
1135 srcs_c = select({
1136 "//build/bazel/platforms/os:android": ["android_src.c"],
1137 "//conditions:default": [],
1138 }) + select({
Rupert Shuttleworthffd45822021-05-14 03:02:34 -04001139 "//build/bazel/platforms/os_arch:android_arm": ["android_arm_src.c"],
1140 "//build/bazel/platforms/os_arch:android_arm64": ["android_arm64_src.c"],
1141 "//build/bazel/platforms/os_arch:android_x86": ["android_x86_src.c"],
1142 "//build/bazel/platforms/os_arch:android_x86_64": ["android_x86_64_src.c"],
Rupert Shuttleworthffd45822021-05-14 03:02:34 -04001143 "//build/bazel/platforms/os_arch:linux_bionic_arm64": ["linux_bionic_arm64_src.c"],
1144 "//build/bazel/platforms/os_arch:linux_bionic_x86_64": ["linux_bionic_x86_64_src.c"],
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001145 "//conditions:default": [],
1146 }),
1147)`},
1148 })
1149}
1150
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001151func TestCcLibraryStaticProductVariableSelects(t *testing.T) {
1152 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1153 description: "cc_library_static product variable selects",
1154 moduleTypeUnderTest: "cc_library_static",
1155 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1156 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001157 blueprint: soongCcLibraryStaticPreamble + `
1158cc_library_static {
1159 name: "foo_static",
1160 srcs: ["common.c"],
1161 product_variables: {
1162 malloc_not_svelte: {
1163 cflags: ["-Wmalloc_not_svelte"],
1164 },
1165 malloc_zero_contents: {
1166 cflags: ["-Wmalloc_zero_contents"],
1167 },
1168 binder32bit: {
1169 cflags: ["-Wbinder32bit"],
1170 },
1171 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001172 include_build_directory: false,
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001173} `,
1174 expectedBazelTargets: []string{`cc_library_static(
1175 name = "foo_static",
Liz Kammer8337ea42021-09-10 10:06:32 -04001176 copts = select({
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001177 "//build/bazel/product_variables:binder32bit": ["-Wbinder32bit"],
1178 "//conditions:default": [],
1179 }) + select({
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001180 "//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"],
1181 "//conditions:default": [],
1182 }) + select({
1183 "//build/bazel/product_variables:malloc_zero_contents": ["-Wmalloc_zero_contents"],
1184 "//conditions:default": [],
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001185 }),
1186 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -04001187 srcs_c = ["common.c"],
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001188)`},
1189 })
1190}
1191
1192func TestCcLibraryStaticProductVariableArchSpecificSelects(t *testing.T) {
1193 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1194 description: "cc_library_static arch-specific product variable selects",
1195 moduleTypeUnderTest: "cc_library_static",
1196 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1197 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001198 filesystem: map[string]string{},
1199 blueprint: soongCcLibraryStaticPreamble + `
1200cc_library_static {
1201 name: "foo_static",
1202 srcs: ["common.c"],
1203 product_variables: {
1204 malloc_not_svelte: {
1205 cflags: ["-Wmalloc_not_svelte"],
1206 },
1207 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001208 arch: {
1209 arm64: {
1210 product_variables: {
1211 malloc_not_svelte: {
1212 cflags: ["-Warm64_malloc_not_svelte"],
1213 },
1214 },
1215 },
1216 },
1217 multilib: {
1218 lib32: {
1219 product_variables: {
1220 malloc_not_svelte: {
1221 cflags: ["-Wlib32_malloc_not_svelte"],
1222 },
1223 },
1224 },
1225 },
1226 target: {
1227 android: {
1228 product_variables: {
1229 malloc_not_svelte: {
1230 cflags: ["-Wandroid_malloc_not_svelte"],
1231 },
1232 },
1233 }
1234 },
1235 include_build_directory: false,
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001236} `,
1237 expectedBazelTargets: []string{`cc_library_static(
1238 name = "foo_static",
Liz Kammer8337ea42021-09-10 10:06:32 -04001239 copts = select({
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001240 "//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"],
1241 "//conditions:default": [],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001242 }) + select({
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001243 "//build/bazel/product_variables:malloc_not_svelte-android": ["-Wandroid_malloc_not_svelte"],
1244 "//conditions:default": [],
1245 }) + select({
1246 "//build/bazel/product_variables:malloc_not_svelte-arm": ["-Wlib32_malloc_not_svelte"],
1247 "//conditions:default": [],
1248 }) + select({
1249 "//build/bazel/product_variables:malloc_not_svelte-arm64": ["-Warm64_malloc_not_svelte"],
1250 "//conditions:default": [],
1251 }) + select({
1252 "//build/bazel/product_variables:malloc_not_svelte-x86": ["-Wlib32_malloc_not_svelte"],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001253 "//conditions:default": [],
1254 }),
1255 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -04001256 srcs_c = ["common.c"],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001257)`},
1258 })
1259}
Liz Kammerba7a9c52021-05-26 08:45:30 -04001260
1261func TestCcLibraryStaticProductVariableStringReplacement(t *testing.T) {
1262 runCcLibraryStaticTestCase(t, bp2buildTestCase{
Chris Parsons69fa9f92021-07-13 11:47:44 -04001263 description: "cc_library_static product variable string replacement",
Liz Kammerba7a9c52021-05-26 08:45:30 -04001264 moduleTypeUnderTest: "cc_library_static",
1265 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1266 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammerba7a9c52021-05-26 08:45:30 -04001267 filesystem: map[string]string{},
1268 blueprint: soongCcLibraryStaticPreamble + `
1269cc_library_static {
1270 name: "foo_static",
Chris Parsons69fa9f92021-07-13 11:47:44 -04001271 srcs: ["common.S"],
Liz Kammerba7a9c52021-05-26 08:45:30 -04001272 product_variables: {
1273 platform_sdk_version: {
1274 asflags: ["-DPLATFORM_SDK_VERSION=%d"],
1275 },
1276 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001277 include_build_directory: false,
Liz Kammerba7a9c52021-05-26 08:45:30 -04001278} `,
1279 expectedBazelTargets: []string{`cc_library_static(
1280 name = "foo_static",
Liz Kammer8337ea42021-09-10 10:06:32 -04001281 asflags = select({
Liz Kammerba7a9c52021-05-26 08:45:30 -04001282 "//build/bazel/product_variables:platform_sdk_version": ["-DPLATFORM_SDK_VERSION=$(Platform_sdk_version)"],
1283 "//conditions:default": [],
1284 }),
Liz Kammerba7a9c52021-05-26 08:45:30 -04001285 linkstatic = True,
Chris Parsons69fa9f92021-07-13 11:47:44 -04001286 srcs_as = ["common.S"],
Liz Kammerba7a9c52021-05-26 08:45:30 -04001287)`},
1288 })
1289}
Chris Parsons51f8c392021-08-03 21:01:05 -04001290
1291func TestStaticLibrary_SystemSharedLibsRootEmpty(t *testing.T) {
1292 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1293 description: "cc_library_static system_shared_lib empty root",
1294 moduleTypeUnderTest: "cc_library_static",
1295 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1296 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1297 blueprint: soongCcLibraryStaticPreamble + `
1298cc_library_static {
1299 name: "root_empty",
Liz Kammer8337ea42021-09-10 10:06:32 -04001300 system_shared_libs: [],
1301 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001302}
1303`,
1304 expectedBazelTargets: []string{`cc_library_static(
1305 name = "root_empty",
Chris Parsons51f8c392021-08-03 21:01:05 -04001306 linkstatic = True,
1307 system_dynamic_deps = [],
1308)`},
1309 })
1310}
1311
1312func TestStaticLibrary_SystemSharedLibsStaticEmpty(t *testing.T) {
1313 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1314 description: "cc_library_static system_shared_lib empty static default",
1315 moduleTypeUnderTest: "cc_library_static",
1316 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1317 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1318 blueprint: soongCcLibraryStaticPreamble + `
1319cc_defaults {
1320 name: "static_empty_defaults",
1321 static: {
Liz Kammer8337ea42021-09-10 10:06:32 -04001322 system_shared_libs: [],
1323 },
1324 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001325}
1326cc_library_static {
1327 name: "static_empty",
Liz Kammer8337ea42021-09-10 10:06:32 -04001328 defaults: ["static_empty_defaults"],
Chris Parsons51f8c392021-08-03 21:01:05 -04001329}
1330`,
1331 expectedBazelTargets: []string{`cc_library_static(
1332 name = "static_empty",
Chris Parsons51f8c392021-08-03 21:01:05 -04001333 linkstatic = True,
1334 system_dynamic_deps = [],
1335)`},
1336 })
1337}
1338
1339func TestStaticLibrary_SystemSharedLibsBionicEmpty(t *testing.T) {
1340 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1341 description: "cc_library_static system_shared_lib empty for bionic variant",
1342 moduleTypeUnderTest: "cc_library_static",
1343 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1344 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1345 blueprint: soongCcLibraryStaticPreamble + `
1346cc_library_static {
1347 name: "target_bionic_empty",
1348 target: {
1349 bionic: {
1350 system_shared_libs: [],
1351 },
1352 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001353 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001354}
1355`,
1356 expectedBazelTargets: []string{`cc_library_static(
1357 name = "target_bionic_empty",
Chris Parsons51f8c392021-08-03 21:01:05 -04001358 linkstatic = True,
1359 system_dynamic_deps = [],
1360)`},
1361 })
1362}
1363
1364func TestStaticLibrary_SystemSharedLibsLinuxBionicEmpty(t *testing.T) {
1365 // Note that this behavior is technically incorrect (it's a simplification).
1366 // The correct behavior would be if bp2build wrote `system_dynamic_deps = []`
1367 // only for linux_bionic, but `android` had `["libc", "libdl", "libm"].
1368 // b/195791252 tracks the fix.
1369 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1370 description: "cc_library_static system_shared_lib empty for linux_bionic variant",
1371 moduleTypeUnderTest: "cc_library_static",
1372 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1373 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1374 blueprint: soongCcLibraryStaticPreamble + `
1375cc_library_static {
1376 name: "target_linux_bionic_empty",
1377 target: {
1378 linux_bionic: {
1379 system_shared_libs: [],
1380 },
1381 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001382 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001383}
1384`,
1385 expectedBazelTargets: []string{`cc_library_static(
1386 name = "target_linux_bionic_empty",
Chris Parsons51f8c392021-08-03 21:01:05 -04001387 linkstatic = True,
1388 system_dynamic_deps = [],
1389)`},
1390 })
1391}
1392
1393func TestStaticLibrary_SystemSharedLibsBionic(t *testing.T) {
1394 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1395 description: "cc_library_static system_shared_libs set for bionic variant",
1396 moduleTypeUnderTest: "cc_library_static",
1397 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1398 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1399 blueprint: soongCcLibraryStaticPreamble + `
1400cc_library{name: "libc"}
1401
1402cc_library_static {
1403 name: "target_bionic",
1404 target: {
1405 bionic: {
1406 system_shared_libs: ["libc"],
1407 },
1408 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001409 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001410}
1411`,
1412 expectedBazelTargets: []string{`cc_library_static(
1413 name = "target_bionic",
Chris Parsons51f8c392021-08-03 21:01:05 -04001414 linkstatic = True,
1415 system_dynamic_deps = select({
1416 "//build/bazel/platforms/os:bionic": [":libc"],
1417 "//conditions:default": [],
1418 }),
1419)`},
1420 })
1421}
1422
1423func TestStaticLibrary_SystemSharedLibsLinuxRootAndLinuxBionic(t *testing.T) {
1424 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1425 description: "cc_library_static system_shared_libs set for root and linux_bionic variant",
1426 moduleTypeUnderTest: "cc_library_static",
1427 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1428 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1429 blueprint: soongCcLibraryStaticPreamble + `
1430cc_library{name: "libc"}
1431cc_library{name: "libm"}
1432
1433cc_library_static {
1434 name: "target_linux_bionic",
Liz Kammer8337ea42021-09-10 10:06:32 -04001435 system_shared_libs: ["libc"],
Chris Parsons51f8c392021-08-03 21:01:05 -04001436 target: {
1437 linux_bionic: {
1438 system_shared_libs: ["libm"],
1439 },
1440 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001441 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001442}
1443`,
1444 expectedBazelTargets: []string{`cc_library_static(
1445 name = "target_linux_bionic",
Chris Parsons51f8c392021-08-03 21:01:05 -04001446 linkstatic = True,
1447 system_dynamic_deps = [":libc"] + select({
1448 "//build/bazel/platforms/os:linux_bionic": [":libm"],
1449 "//conditions:default": [],
1450 }),
1451)`},
1452 })
1453}