blob: f02ce4d3fc143f68ae6c40a9a705965522d7ce8c [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 ],
Liz Kammer35687bc2021-09-10 10:07:07 -0400205 local_includes = [
206 "local_include_dir_1",
207 "local_include_dir_2",
208 ".",
209 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000210 srcs = [
211 "foo_static1.cc",
212 "foo_static2.cc",
213 ],
Chris Parsons08648312021-05-06 16:23:19 -0400214 whole_archive_deps = [
215 ":whole_static_lib_1",
216 ":whole_static_lib_2",
217 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000218)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200219 })
220}
221
222func TestCcLibraryStaticSubpackage(t *testing.T) {
223 runCcLibraryStaticTestCase(t, bp2buildTestCase{
224 description: "cc_library_static subpackage test",
225 moduleTypeUnderTest: "cc_library_static",
226 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
227 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
228 filesystem: map[string]string{
229 // subpackage with subdirectory
230 "subpackage/Android.bp": "",
231 "subpackage/subpackage_header.h": "",
232 "subpackage/subdirectory/subdirectory_header.h": "",
233 // subsubpackage with subdirectory
234 "subpackage/subsubpackage/Android.bp": "",
235 "subpackage/subsubpackage/subsubpackage_header.h": "",
236 "subpackage/subsubpackage/subdirectory/subdirectory_header.h": "",
237 // subsubsubpackage with subdirectory
238 "subpackage/subsubpackage/subsubsubpackage/Android.bp": "",
239 "subpackage/subsubpackage/subsubsubpackage/subsubsubpackage_header.h": "",
240 "subpackage/subsubpackage/subsubsubpackage/subdirectory/subdirectory_header.h": "",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000241 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200242 blueprint: soongCcLibraryStaticPreamble + `
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400243cc_library_static {
244 name: "foo_static",
Liz Kammer35687bc2021-09-10 10:07:07 -0400245 srcs: [],
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400246 include_dirs: [
Liz Kammer35687bc2021-09-10 10:07:07 -0400247 "subpackage",
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400248 ],
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400249}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200250 expectedBazelTargets: []string{`cc_library_static(
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400251 name = "foo_static",
Liz Kammer35687bc2021-09-10 10:07:07 -0400252 absolute_includes = ["subpackage"],
Liz Kammer35687bc2021-09-10 10:07:07 -0400253 local_includes = ["."],
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400254)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200255 })
256}
257
258func TestCcLibraryStaticExportIncludeDir(t *testing.T) {
259 runCcLibraryStaticTestCase(t, bp2buildTestCase{
260 description: "cc_library_static export include dir",
261 moduleTypeUnderTest: "cc_library_static",
262 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
263 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
264 filesystem: map[string]string{
265 // subpackage with subdirectory
266 "subpackage/Android.bp": "",
267 "subpackage/subpackage_header.h": "",
268 "subpackage/subdirectory/subdirectory_header.h": "",
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400269 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200270 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000271cc_library_static {
272 name: "foo_static",
273 export_include_dirs: ["subpackage"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400274 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000275}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200276 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000277 name = "foo_static",
Liz Kammer5fad5012021-09-09 14:08:21 -0400278 export_includes = ["subpackage"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000279)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200280 })
281}
282
283func TestCcLibraryStaticExportSystemIncludeDir(t *testing.T) {
284 runCcLibraryStaticTestCase(t, bp2buildTestCase{
285 description: "cc_library_static export system include dir",
286 moduleTypeUnderTest: "cc_library_static",
287 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
288 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
289 filesystem: map[string]string{
290 // subpackage with subdirectory
291 "subpackage/Android.bp": "",
292 "subpackage/subpackage_header.h": "",
293 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000294 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200295 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000296cc_library_static {
297 name: "foo_static",
298 export_system_include_dirs: ["subpackage"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400299 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000300}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200301 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000302 name = "foo_static",
Liz Kammer5fad5012021-09-09 14:08:21 -0400303 export_system_includes = ["subpackage"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000304)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200305 })
306}
307
308func TestCcLibraryStaticManyIncludeDirs(t *testing.T) {
309 runCcLibraryStaticTestCase(t, bp2buildTestCase{
310 description: "cc_library_static include_dirs, local_include_dirs, export_include_dirs (b/183742505)",
311 moduleTypeUnderTest: "cc_library_static",
312 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
313 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
314 dir: "subpackage",
315 filesystem: map[string]string{
316 // subpackage with subdirectory
317 "subpackage/Android.bp": `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000318cc_library_static {
319 name: "foo_static",
320 // include_dirs are workspace/root relative
321 include_dirs: [
322 "subpackage/subsubpackage",
323 "subpackage2",
324 "subpackage3/subsubpackage"
325 ],
326 local_include_dirs: ["subsubpackage2"], // module dir relative
327 export_include_dirs: ["./exported_subsubpackage"], // module dir relative
328 include_build_directory: true,
329 bazel_module: { bp2build_available: true },
330}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200331 "subpackage/subsubpackage/header.h": "",
332 "subpackage/subsubpackage2/header.h": "",
333 "subpackage/exported_subsubpackage/header.h": "",
334 "subpackage2/header.h": "",
335 "subpackage3/subsubpackage/header.h": "",
336 },
337 blueprint: soongCcLibraryStaticPreamble,
338 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000339 name = "foo_static",
Liz Kammer35687bc2021-09-10 10:07:07 -0400340 absolute_includes = [
341 "subpackage/subsubpackage",
342 "subpackage2",
343 "subpackage3/subsubpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000344 ],
Liz Kammer5fad5012021-09-09 14:08:21 -0400345 export_includes = ["./exported_subsubpackage"],
Liz Kammer35687bc2021-09-10 10:07:07 -0400346 local_includes = [
347 "subsubpackage2",
348 ".",
349 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000350)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200351 })
352}
353
354func TestCcLibraryStaticIncludeBuildDirectoryDisabled(t *testing.T) {
355 runCcLibraryStaticTestCase(t, bp2buildTestCase{
356 description: "cc_library_static include_build_directory disabled",
357 moduleTypeUnderTest: "cc_library_static",
358 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
359 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
360 filesystem: map[string]string{
361 // subpackage with subdirectory
362 "subpackage/Android.bp": "",
363 "subpackage/subpackage_header.h": "",
364 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000365 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200366 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000367cc_library_static {
368 name: "foo_static",
369 include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended
370 local_include_dirs: ["subpackage2"],
371 include_build_directory: false,
372}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200373 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000374 name = "foo_static",
Liz Kammer35687bc2021-09-10 10:07:07 -0400375 absolute_includes = ["subpackage"],
Liz Kammer35687bc2021-09-10 10:07:07 -0400376 local_includes = ["subpackage2"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000377)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200378 })
379}
380
381func TestCcLibraryStaticIncludeBuildDirectoryEnabled(t *testing.T) {
382 runCcLibraryStaticTestCase(t, bp2buildTestCase{
383 description: "cc_library_static include_build_directory enabled",
384 moduleTypeUnderTest: "cc_library_static",
385 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
386 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
387 filesystem: map[string]string{
388 // subpackage with subdirectory
389 "subpackage/Android.bp": "",
390 "subpackage/subpackage_header.h": "",
391 "subpackage2/Android.bp": "",
392 "subpackage2/subpackage2_header.h": "",
393 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000394 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200395 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000396cc_library_static {
397 name: "foo_static",
398 include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended
399 local_include_dirs: ["subpackage2"],
400 include_build_directory: true,
401}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200402 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000403 name = "foo_static",
Liz Kammer35687bc2021-09-10 10:07:07 -0400404 absolute_includes = ["subpackage"],
Liz Kammer35687bc2021-09-10 10:07:07 -0400405 local_includes = [
406 "subpackage2",
407 ".",
408 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000409)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200410 })
411}
412
413func TestCcLibraryStaticArchSpecificStaticLib(t *testing.T) {
414 runCcLibraryStaticTestCase(t, bp2buildTestCase{
415 description: "cc_library_static arch-specific static_libs",
416 moduleTypeUnderTest: "cc_library_static",
417 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
418 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200419 filesystem: map[string]string{},
420 blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -0400421cc_library_static {
422 name: "static_dep",
423 bazel_module: { bp2build_available: false },
424}
425cc_library_static {
426 name: "static_dep2",
427 bazel_module: { bp2build_available: false },
428}
Jingwen Chened9c17d2021-04-13 07:14:55 +0000429cc_library_static {
430 name: "foo_static",
431 arch: { arm64: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } },
Liz Kammer8337ea42021-09-10 10:06:32 -0400432 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000433}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200434 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000435 name = "foo_static",
Chris Parsonsd6358772021-05-18 18:35:24 -0400436 implementation_deps = select({
Chris Parsons08648312021-05-06 16:23:19 -0400437 "//build/bazel/platforms/arch:arm64": [":static_dep"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000438 "//conditions:default": [],
439 }),
Chris Parsons08648312021-05-06 16:23:19 -0400440 whole_archive_deps = select({
441 "//build/bazel/platforms/arch:arm64": [":static_dep2"],
442 "//conditions:default": [],
443 }),
Jingwen Chened9c17d2021-04-13 07:14:55 +0000444)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200445 })
446}
447
448func TestCcLibraryStaticOsSpecificStaticLib(t *testing.T) {
449 runCcLibraryStaticTestCase(t, bp2buildTestCase{
450 description: "cc_library_static os-specific static_libs",
451 moduleTypeUnderTest: "cc_library_static",
452 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
453 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200454 filesystem: map[string]string{},
455 blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -0400456cc_library_static {
457 name: "static_dep",
458 bazel_module: { bp2build_available: false },
459}
460cc_library_static {
461 name: "static_dep2",
462 bazel_module: { bp2build_available: false },
463}
Jingwen Chened9c17d2021-04-13 07:14:55 +0000464cc_library_static {
465 name: "foo_static",
466 target: { android: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } },
Liz Kammer8337ea42021-09-10 10:06:32 -0400467 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000468}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200469 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000470 name = "foo_static",
Chris Parsonsd6358772021-05-18 18:35:24 -0400471 implementation_deps = select({
Chris Parsons08648312021-05-06 16:23:19 -0400472 "//build/bazel/platforms/os:android": [":static_dep"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000473 "//conditions:default": [],
474 }),
Chris Parsons08648312021-05-06 16:23:19 -0400475 whole_archive_deps = select({
476 "//build/bazel/platforms/os:android": [":static_dep2"],
477 "//conditions:default": [],
478 }),
Jingwen Chened9c17d2021-04-13 07:14:55 +0000479)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200480 })
481}
482
483func TestCcLibraryStaticBaseArchOsSpecificStaticLib(t *testing.T) {
484 runCcLibraryStaticTestCase(t, bp2buildTestCase{
485 description: "cc_library_static base, arch and os-specific static_libs",
486 moduleTypeUnderTest: "cc_library_static",
487 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
488 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200489 filesystem: map[string]string{},
490 blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -0400491cc_library_static {
492 name: "static_dep",
493 bazel_module: { bp2build_available: false },
494}
495cc_library_static {
496 name: "static_dep2",
497 bazel_module: { bp2build_available: false },
498}
499cc_library_static {
500 name: "static_dep3",
501 bazel_module: { bp2build_available: false },
502}
503cc_library_static {
504 name: "static_dep4",
505 bazel_module: { bp2build_available: false },
506}
Jingwen Chened9c17d2021-04-13 07:14:55 +0000507cc_library_static {
508 name: "foo_static",
509 static_libs: ["static_dep"],
510 whole_static_libs: ["static_dep2"],
511 target: { android: { static_libs: ["static_dep3"] } },
512 arch: { arm64: { static_libs: ["static_dep4"] } },
Liz Kammer8337ea42021-09-10 10:06:32 -0400513 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000514}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200515 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000516 name = "foo_static",
Chris Parsonsd6358772021-05-18 18:35:24 -0400517 implementation_deps = [":static_dep"] + select({
Jingwen Chened9c17d2021-04-13 07:14:55 +0000518 "//build/bazel/platforms/arch:arm64": [":static_dep4"],
519 "//conditions:default": [],
520 }) + select({
521 "//build/bazel/platforms/os:android": [":static_dep3"],
522 "//conditions:default": [],
523 }),
Chris Parsons08648312021-05-06 16:23:19 -0400524 whole_archive_deps = [":static_dep2"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000525)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200526 })
527}
528
529func TestCcLibraryStaticSimpleExcludeSrcs(t *testing.T) {
530 runCcLibraryStaticTestCase(t, bp2buildTestCase{
531 description: "cc_library_static simple exclude_srcs",
532 moduleTypeUnderTest: "cc_library_static",
533 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
534 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200535 filesystem: map[string]string{
536 "common.c": "",
537 "foo-a.c": "",
538 "foo-excluded.c": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000539 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200540 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000541cc_library_static {
542 name: "foo_static",
543 srcs: ["common.c", "foo-*.c"],
544 exclude_srcs: ["foo-excluded.c"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400545 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000546}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200547 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000548 name = "foo_static",
Chris Parsons990c4f42021-05-25 12:10:58 -0400549 srcs_c = [
Jingwen Chene32e9e02021-04-23 09:17:24 +0000550 "common.c",
551 "foo-a.c",
552 ],
553)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200554 })
555}
556
557func TestCcLibraryStaticOneArchSrcs(t *testing.T) {
558 runCcLibraryStaticTestCase(t, bp2buildTestCase{
559 description: "cc_library_static one arch specific srcs",
560 moduleTypeUnderTest: "cc_library_static",
561 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
562 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200563 filesystem: map[string]string{
564 "common.c": "",
565 "foo-arm.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000566 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200567 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000568cc_library_static {
569 name: "foo_static",
570 srcs: ["common.c"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400571 arch: { arm: { srcs: ["foo-arm.c"] } },
572 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000573}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200574 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000575 name = "foo_static",
Chris Parsons990c4f42021-05-25 12:10:58 -0400576 srcs_c = ["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000577 "//build/bazel/platforms/arch:arm": ["foo-arm.c"],
578 "//conditions:default": [],
579 }),
580)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200581 })
582}
583
584func TestCcLibraryStaticOneArchSrcsExcludeSrcs(t *testing.T) {
585 runCcLibraryStaticTestCase(t, bp2buildTestCase{
586 description: "cc_library_static one arch specific srcs and exclude_srcs",
587 moduleTypeUnderTest: "cc_library_static",
588 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
589 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200590 filesystem: map[string]string{
591 "common.c": "",
592 "for-arm.c": "",
593 "not-for-arm.c": "",
594 "not-for-anything.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000595 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200596 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000597cc_library_static {
598 name: "foo_static",
599 srcs: ["common.c", "not-for-*.c"],
600 exclude_srcs: ["not-for-anything.c"],
601 arch: {
602 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
603 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400604 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000605}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200606 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000607 name = "foo_static",
Chris Parsons990c4f42021-05-25 12:10:58 -0400608 srcs_c = ["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000609 "//build/bazel/platforms/arch:arm": ["for-arm.c"],
610 "//conditions:default": ["not-for-arm.c"],
611 }),
612)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200613 })
614}
615
616func TestCcLibraryStaticTwoArchExcludeSrcs(t *testing.T) {
617 runCcLibraryStaticTestCase(t, bp2buildTestCase{
618 description: "cc_library_static arch specific exclude_srcs for 2 architectures",
619 moduleTypeUnderTest: "cc_library_static",
620 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
621 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200622 filesystem: map[string]string{
623 "common.c": "",
624 "for-arm.c": "",
625 "for-x86.c": "",
626 "not-for-arm.c": "",
627 "not-for-x86.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000628 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200629 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000630cc_library_static {
631 name: "foo_static",
632 srcs: ["common.c", "not-for-*.c"],
633 exclude_srcs: ["not-for-everything.c"],
634 arch: {
635 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
636 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
637 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400638 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000639} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200640 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000641 name = "foo_static",
Chris Parsons990c4f42021-05-25 12:10:58 -0400642 srcs_c = ["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000643 "//build/bazel/platforms/arch:arm": [
644 "for-arm.c",
645 "not-for-x86.c",
646 ],
647 "//build/bazel/platforms/arch:x86": [
648 "for-x86.c",
649 "not-for-arm.c",
650 ],
651 "//conditions:default": [
652 "not-for-arm.c",
653 "not-for-x86.c",
654 ],
655 }),
656)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200657 })
658}
659func TestCcLibraryStaticFourArchExcludeSrcs(t *testing.T) {
660 runCcLibraryStaticTestCase(t, bp2buildTestCase{
661 description: "cc_library_static arch specific exclude_srcs for 4 architectures",
662 moduleTypeUnderTest: "cc_library_static",
663 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
664 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200665 filesystem: map[string]string{
666 "common.c": "",
667 "for-arm.c": "",
668 "for-arm64.c": "",
669 "for-x86.c": "",
670 "for-x86_64.c": "",
671 "not-for-arm.c": "",
672 "not-for-arm64.c": "",
673 "not-for-x86.c": "",
674 "not-for-x86_64.c": "",
675 "not-for-everything.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000676 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200677 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000678cc_library_static {
679 name: "foo_static",
680 srcs: ["common.c", "not-for-*.c"],
681 exclude_srcs: ["not-for-everything.c"],
682 arch: {
683 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
684 arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] },
685 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
686 x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] },
Liz Kammer8337ea42021-09-10 10:06:32 -0400687 },
688 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000689} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200690 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000691 name = "foo_static",
Chris Parsons990c4f42021-05-25 12:10:58 -0400692 srcs_c = ["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000693 "//build/bazel/platforms/arch:arm": [
694 "for-arm.c",
695 "not-for-arm64.c",
696 "not-for-x86.c",
697 "not-for-x86_64.c",
698 ],
699 "//build/bazel/platforms/arch:arm64": [
700 "for-arm64.c",
701 "not-for-arm.c",
702 "not-for-x86.c",
703 "not-for-x86_64.c",
704 ],
705 "//build/bazel/platforms/arch:x86": [
706 "for-x86.c",
707 "not-for-arm.c",
708 "not-for-arm64.c",
709 "not-for-x86_64.c",
710 ],
711 "//build/bazel/platforms/arch:x86_64": [
712 "for-x86_64.c",
713 "not-for-arm.c",
714 "not-for-arm64.c",
715 "not-for-x86.c",
716 ],
717 "//conditions:default": [
718 "not-for-arm.c",
719 "not-for-arm64.c",
720 "not-for-x86.c",
721 "not-for-x86_64.c",
722 ],
723 }),
724)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200725 })
726}
727
Liz Kammer2b07ec72021-05-26 15:08:27 -0400728func TestCcLibraryStaticOneArchEmpty(t *testing.T) {
729 runCcLibraryStaticTestCase(t, bp2buildTestCase{
730 description: "cc_library_static one arch empty",
731 moduleTypeUnderTest: "cc_library_static",
732 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
733 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammer2b07ec72021-05-26 15:08:27 -0400734 filesystem: map[string]string{
735 "common.cc": "",
736 "foo-no-arm.cc": "",
737 "foo-excluded.cc": "",
738 },
739 blueprint: soongCcLibraryStaticPreamble + `
740cc_library_static {
741 name: "foo_static",
742 srcs: ["common.cc", "foo-*.cc"],
743 exclude_srcs: ["foo-excluded.cc"],
744 arch: {
745 arm: { exclude_srcs: ["foo-no-arm.cc"] },
746 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400747 include_build_directory: false,
Liz Kammer2b07ec72021-05-26 15:08:27 -0400748}`,
749 expectedBazelTargets: []string{`cc_library_static(
750 name = "foo_static",
Liz Kammer2b07ec72021-05-26 15:08:27 -0400751 srcs = ["common.cc"] + select({
752 "//build/bazel/platforms/arch:arm": [],
753 "//conditions:default": ["foo-no-arm.cc"],
754 }),
755)`},
756 })
757}
758
759func TestCcLibraryStaticOneArchEmptyOtherSet(t *testing.T) {
760 runCcLibraryStaticTestCase(t, bp2buildTestCase{
761 description: "cc_library_static one arch empty other set",
762 moduleTypeUnderTest: "cc_library_static",
763 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
764 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammer2b07ec72021-05-26 15:08:27 -0400765 filesystem: map[string]string{
766 "common.cc": "",
767 "foo-no-arm.cc": "",
768 "x86-only.cc": "",
769 "foo-excluded.cc": "",
770 },
771 blueprint: soongCcLibraryStaticPreamble + `
772cc_library_static {
773 name: "foo_static",
774 srcs: ["common.cc", "foo-*.cc"],
775 exclude_srcs: ["foo-excluded.cc"],
776 arch: {
777 arm: { exclude_srcs: ["foo-no-arm.cc"] },
778 x86: { srcs: ["x86-only.cc"] },
779 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400780 include_build_directory: false,
Liz Kammer2b07ec72021-05-26 15:08:27 -0400781}`,
782 expectedBazelTargets: []string{`cc_library_static(
783 name = "foo_static",
Liz Kammer2b07ec72021-05-26 15:08:27 -0400784 srcs = ["common.cc"] + select({
785 "//build/bazel/platforms/arch:arm": [],
786 "//build/bazel/platforms/arch:x86": [
787 "foo-no-arm.cc",
788 "x86-only.cc",
789 ],
790 "//conditions:default": ["foo-no-arm.cc"],
791 }),
792)`},
793 })
794}
795
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200796func TestCcLibraryStaticMultipleDepSameName(t *testing.T) {
797 runCcLibraryStaticTestCase(t, bp2buildTestCase{
798 description: "cc_library_static multiple dep same name panic",
799 moduleTypeUnderTest: "cc_library_static",
800 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
801 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200802 filesystem: map[string]string{},
803 blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -0400804cc_library_static {
805 name: "static_dep",
806 bazel_module: { bp2build_available: false },
807}
Liz Kammer2b50ce62021-04-26 15:47:28 -0400808cc_library_static {
809 name: "foo_static",
Chris Parsons08648312021-05-06 16:23:19 -0400810 static_libs: ["static_dep", "static_dep"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400811 include_build_directory: false,
Liz Kammer2b50ce62021-04-26 15:47:28 -0400812}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200813 expectedBazelTargets: []string{`cc_library_static(
Liz Kammer2b50ce62021-04-26 15:47:28 -0400814 name = "foo_static",
Chris Parsonsd6358772021-05-18 18:35:24 -0400815 implementation_deps = [":static_dep"],
Liz Kammer2b50ce62021-04-26 15:47:28 -0400816)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200817 })
818}
819
820func TestCcLibraryStaticOneMultilibSrcsExcludeSrcs(t *testing.T) {
821 runCcLibraryStaticTestCase(t, bp2buildTestCase{
822 description: "cc_library_static 1 multilib srcs and exclude_srcs",
823 moduleTypeUnderTest: "cc_library_static",
824 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
825 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200826 filesystem: map[string]string{
827 "common.c": "",
828 "for-lib32.c": "",
829 "not-for-lib32.c": "",
Liz Kammer2b50ce62021-04-26 15:47:28 -0400830 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200831 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -0400832cc_library_static {
833 name: "foo_static",
834 srcs: ["common.c", "not-for-*.c"],
835 multilib: {
836 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
837 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400838 include_build_directory: false,
Chris Parsonsc424b762021-04-29 18:06:50 -0400839} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200840 expectedBazelTargets: []string{`cc_library_static(
Chris Parsonsc424b762021-04-29 18:06:50 -0400841 name = "foo_static",
Chris Parsons990c4f42021-05-25 12:10:58 -0400842 srcs_c = ["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -0400843 "//build/bazel/platforms/arch:arm": ["for-lib32.c"],
844 "//build/bazel/platforms/arch:x86": ["for-lib32.c"],
845 "//conditions:default": ["not-for-lib32.c"],
846 }),
847)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200848 })
849}
850
851func TestCcLibraryStaticTwoMultilibSrcsExcludeSrcs(t *testing.T) {
852 runCcLibraryStaticTestCase(t, bp2buildTestCase{
853 description: "cc_library_static 2 multilib srcs and exclude_srcs",
854 moduleTypeUnderTest: "cc_library_static",
855 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
856 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200857 filesystem: map[string]string{
858 "common.c": "",
859 "for-lib32.c": "",
860 "for-lib64.c": "",
861 "not-for-lib32.c": "",
862 "not-for-lib64.c": "",
Chris Parsonsc424b762021-04-29 18:06:50 -0400863 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200864 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -0400865cc_library_static {
866 name: "foo_static2",
867 srcs: ["common.c", "not-for-*.c"],
868 multilib: {
869 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
870 lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] },
871 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400872 include_build_directory: false,
Chris Parsonsc424b762021-04-29 18:06:50 -0400873} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200874 expectedBazelTargets: []string{`cc_library_static(
Chris Parsonsc424b762021-04-29 18:06:50 -0400875 name = "foo_static2",
Chris Parsons990c4f42021-05-25 12:10:58 -0400876 srcs_c = ["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -0400877 "//build/bazel/platforms/arch:arm": [
878 "for-lib32.c",
879 "not-for-lib64.c",
880 ],
881 "//build/bazel/platforms/arch:arm64": [
882 "for-lib64.c",
883 "not-for-lib32.c",
884 ],
885 "//build/bazel/platforms/arch:x86": [
886 "for-lib32.c",
887 "not-for-lib64.c",
888 ],
889 "//build/bazel/platforms/arch:x86_64": [
890 "for-lib64.c",
891 "not-for-lib32.c",
892 ],
893 "//conditions:default": [
894 "not-for-lib32.c",
895 "not-for-lib64.c",
896 ],
897 }),
898)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200899 })
900}
901
902func TestCcLibrarySTaticArchMultilibSrcsExcludeSrcs(t *testing.T) {
903 runCcLibraryStaticTestCase(t, bp2buildTestCase{
904 description: "cc_library_static arch and multilib srcs and exclude_srcs",
905 moduleTypeUnderTest: "cc_library_static",
906 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
907 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200908 filesystem: map[string]string{
909 "common.c": "",
910 "for-arm.c": "",
911 "for-arm64.c": "",
912 "for-x86.c": "",
913 "for-x86_64.c": "",
914 "for-lib32.c": "",
915 "for-lib64.c": "",
916 "not-for-arm.c": "",
917 "not-for-arm64.c": "",
918 "not-for-x86.c": "",
919 "not-for-x86_64.c": "",
920 "not-for-lib32.c": "",
921 "not-for-lib64.c": "",
922 "not-for-everything.c": "",
Chris Parsonsc424b762021-04-29 18:06:50 -0400923 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200924 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -0400925cc_library_static {
926 name: "foo_static3",
927 srcs: ["common.c", "not-for-*.c"],
928 exclude_srcs: ["not-for-everything.c"],
929 arch: {
930 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
931 arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] },
932 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
933 x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] },
934 },
935 multilib: {
936 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
937 lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] },
938 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400939 include_build_directory: false,
Chris Parsonsc424b762021-04-29 18:06:50 -0400940}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200941 expectedBazelTargets: []string{`cc_library_static(
Chris Parsonsc424b762021-04-29 18:06:50 -0400942 name = "foo_static3",
Chris Parsons990c4f42021-05-25 12:10:58 -0400943 srcs_c = ["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -0400944 "//build/bazel/platforms/arch:arm": [
945 "for-arm.c",
946 "for-lib32.c",
947 "not-for-arm64.c",
948 "not-for-lib64.c",
949 "not-for-x86.c",
950 "not-for-x86_64.c",
951 ],
952 "//build/bazel/platforms/arch:arm64": [
953 "for-arm64.c",
954 "for-lib64.c",
955 "not-for-arm.c",
956 "not-for-lib32.c",
957 "not-for-x86.c",
958 "not-for-x86_64.c",
959 ],
960 "//build/bazel/platforms/arch:x86": [
961 "for-lib32.c",
962 "for-x86.c",
963 "not-for-arm.c",
964 "not-for-arm64.c",
965 "not-for-lib64.c",
966 "not-for-x86_64.c",
967 ],
968 "//build/bazel/platforms/arch:x86_64": [
969 "for-lib64.c",
970 "for-x86_64.c",
971 "not-for-arm.c",
972 "not-for-arm64.c",
973 "not-for-lib32.c",
974 "not-for-x86.c",
975 ],
976 "//conditions:default": [
977 "not-for-arm.c",
978 "not-for-arm64.c",
979 "not-for-lib32.c",
980 "not-for-lib64.c",
981 "not-for-x86.c",
982 "not-for-x86_64.c",
983 ],
984 }),
985)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200986 })
987}
988
989func TestCcLibraryStaticArchSrcsExcludeSrcsGeneratedFiles(t *testing.T) {
990 runCcLibraryStaticTestCase(t, bp2buildTestCase{
991 description: "cc_library_static arch srcs/exclude_srcs with generated files",
992 moduleTypeUnderTest: "cc_library_static",
993 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
994 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200995 filesystem: map[string]string{
Chris Parsons990c4f42021-05-25 12:10:58 -0400996 "common.cpp": "",
997 "for-x86.cpp": "",
998 "not-for-x86.cpp": "",
999 "not-for-everything.cpp": "",
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001000 "dep/Android.bp": `
Chris Parsons484e50a2021-05-13 15:13:04 -04001001genrule {
Liz Kammer8337ea42021-09-10 10:06:32 -04001002 name: "generated_src_other_pkg",
1003 out: ["generated_src_other_pkg.cpp"],
1004 cmd: "nothing to see here",
Chris Parsons484e50a2021-05-13 15:13:04 -04001005}
1006
1007genrule {
Liz Kammer8337ea42021-09-10 10:06:32 -04001008 name: "generated_hdr_other_pkg",
1009 out: ["generated_hdr_other_pkg.cpp"],
1010 cmd: "nothing to see here",
Chris Parsons484e50a2021-05-13 15:13:04 -04001011}
1012
1013genrule {
Liz Kammer8337ea42021-09-10 10:06:32 -04001014 name: "generated_hdr_other_pkg_x86",
1015 out: ["generated_hdr_other_pkg_x86.cpp"],
1016 cmd: "nothing to see here",
Chris Parsons484e50a2021-05-13 15:13:04 -04001017}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001018 },
1019 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsons484e50a2021-05-13 15:13:04 -04001020genrule {
1021 name: "generated_src",
1022 out: ["generated_src.cpp"],
1023 cmd: "nothing to see here",
1024}
1025
1026genrule {
1027 name: "generated_src_x86",
1028 out: ["generated_src_x86.cpp"],
1029 cmd: "nothing to see here",
1030}
1031
1032genrule {
1033 name: "generated_hdr",
1034 out: ["generated_hdr.h"],
1035 cmd: "nothing to see here",
1036}
1037
1038cc_library_static {
1039 name: "foo_static3",
Chris Parsons990c4f42021-05-25 12:10:58 -04001040 srcs: ["common.cpp", "not-for-*.cpp"],
1041 exclude_srcs: ["not-for-everything.cpp"],
Chris Parsons484e50a2021-05-13 15:13:04 -04001042 generated_sources: ["generated_src", "generated_src_other_pkg"],
1043 generated_headers: ["generated_hdr", "generated_hdr_other_pkg"],
1044 arch: {
1045 x86: {
Chris Parsons990c4f42021-05-25 12:10:58 -04001046 srcs: ["for-x86.cpp"],
1047 exclude_srcs: ["not-for-x86.cpp"],
Chris Parsons484e50a2021-05-13 15:13:04 -04001048 generated_sources: ["generated_src_x86"],
1049 generated_headers: ["generated_hdr_other_pkg_x86"],
1050 },
1051 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001052 include_build_directory: false,
Chris Parsons484e50a2021-05-13 15:13:04 -04001053}
1054`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001055 expectedBazelTargets: []string{`cc_library_static(
Chris Parsons484e50a2021-05-13 15:13:04 -04001056 name = "foo_static3",
Chris Parsons484e50a2021-05-13 15:13:04 -04001057 srcs = [
1058 "//dep:generated_hdr_other_pkg",
1059 "//dep:generated_src_other_pkg",
1060 ":generated_hdr",
1061 ":generated_src",
Chris Parsons990c4f42021-05-25 12:10:58 -04001062 "common.cpp",
Chris Parsons484e50a2021-05-13 15:13:04 -04001063 ] + select({
1064 "//build/bazel/platforms/arch:x86": [
1065 "//dep:generated_hdr_other_pkg_x86",
1066 ":generated_src_x86",
Chris Parsons990c4f42021-05-25 12:10:58 -04001067 "for-x86.cpp",
Chris Parsons484e50a2021-05-13 15:13:04 -04001068 ],
Chris Parsons990c4f42021-05-25 12:10:58 -04001069 "//conditions:default": ["not-for-x86.cpp"],
Chris Parsons484e50a2021-05-13 15:13:04 -04001070 }),
1071)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001072 })
Rupert Shuttleworth095081c2021-03-25 09:06:03 +00001073}
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001074
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001075func TestCcLibraryStaticGetTargetProperties(t *testing.T) {
1076 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1077
1078 description: "cc_library_static complex GetTargetProperties",
1079 moduleTypeUnderTest: "cc_library_static",
1080 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1081 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001082 blueprint: soongCcLibraryStaticPreamble + `
1083cc_library_static {
1084 name: "foo_static",
1085 target: {
1086 android: {
1087 srcs: ["android_src.c"],
1088 },
1089 android_arm: {
1090 srcs: ["android_arm_src.c"],
1091 },
1092 android_arm64: {
1093 srcs: ["android_arm64_src.c"],
1094 },
1095 android_x86: {
1096 srcs: ["android_x86_src.c"],
1097 },
1098 android_x86_64: {
1099 srcs: ["android_x86_64_src.c"],
1100 },
1101 linux_bionic_arm64: {
1102 srcs: ["linux_bionic_arm64_src.c"],
1103 },
1104 linux_bionic_x86_64: {
1105 srcs: ["linux_bionic_x86_64_src.c"],
1106 },
1107 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001108 include_build_directory: false,
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001109}`,
1110 expectedBazelTargets: []string{`cc_library_static(
1111 name = "foo_static",
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001112 srcs_c = select({
1113 "//build/bazel/platforms/os:android": ["android_src.c"],
1114 "//conditions:default": [],
1115 }) + select({
Rupert Shuttleworthffd45822021-05-14 03:02:34 -04001116 "//build/bazel/platforms/os_arch:android_arm": ["android_arm_src.c"],
1117 "//build/bazel/platforms/os_arch:android_arm64": ["android_arm64_src.c"],
1118 "//build/bazel/platforms/os_arch:android_x86": ["android_x86_src.c"],
1119 "//build/bazel/platforms/os_arch:android_x86_64": ["android_x86_64_src.c"],
Rupert Shuttleworthffd45822021-05-14 03:02:34 -04001120 "//build/bazel/platforms/os_arch:linux_bionic_arm64": ["linux_bionic_arm64_src.c"],
1121 "//build/bazel/platforms/os_arch:linux_bionic_x86_64": ["linux_bionic_x86_64_src.c"],
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001122 "//conditions:default": [],
1123 }),
1124)`},
1125 })
1126}
1127
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001128func TestCcLibraryStaticProductVariableSelects(t *testing.T) {
1129 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1130 description: "cc_library_static product variable selects",
1131 moduleTypeUnderTest: "cc_library_static",
1132 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1133 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001134 blueprint: soongCcLibraryStaticPreamble + `
1135cc_library_static {
1136 name: "foo_static",
1137 srcs: ["common.c"],
1138 product_variables: {
1139 malloc_not_svelte: {
1140 cflags: ["-Wmalloc_not_svelte"],
1141 },
1142 malloc_zero_contents: {
1143 cflags: ["-Wmalloc_zero_contents"],
1144 },
1145 binder32bit: {
1146 cflags: ["-Wbinder32bit"],
1147 },
1148 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001149 include_build_directory: false,
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001150} `,
1151 expectedBazelTargets: []string{`cc_library_static(
1152 name = "foo_static",
Liz Kammer8337ea42021-09-10 10:06:32 -04001153 copts = select({
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001154 "//build/bazel/product_variables:binder32bit": ["-Wbinder32bit"],
1155 "//conditions:default": [],
1156 }) + select({
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001157 "//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"],
1158 "//conditions:default": [],
1159 }) + select({
1160 "//build/bazel/product_variables:malloc_zero_contents": ["-Wmalloc_zero_contents"],
1161 "//conditions:default": [],
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001162 }),
Chris Parsons990c4f42021-05-25 12:10:58 -04001163 srcs_c = ["common.c"],
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001164)`},
1165 })
1166}
1167
1168func TestCcLibraryStaticProductVariableArchSpecificSelects(t *testing.T) {
1169 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1170 description: "cc_library_static arch-specific product variable selects",
1171 moduleTypeUnderTest: "cc_library_static",
1172 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1173 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001174 filesystem: map[string]string{},
1175 blueprint: soongCcLibraryStaticPreamble + `
1176cc_library_static {
1177 name: "foo_static",
1178 srcs: ["common.c"],
1179 product_variables: {
1180 malloc_not_svelte: {
1181 cflags: ["-Wmalloc_not_svelte"],
1182 },
1183 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001184 arch: {
1185 arm64: {
1186 product_variables: {
1187 malloc_not_svelte: {
1188 cflags: ["-Warm64_malloc_not_svelte"],
1189 },
1190 },
1191 },
1192 },
1193 multilib: {
1194 lib32: {
1195 product_variables: {
1196 malloc_not_svelte: {
1197 cflags: ["-Wlib32_malloc_not_svelte"],
1198 },
1199 },
1200 },
1201 },
1202 target: {
1203 android: {
1204 product_variables: {
1205 malloc_not_svelte: {
1206 cflags: ["-Wandroid_malloc_not_svelte"],
1207 },
1208 },
1209 }
1210 },
1211 include_build_directory: false,
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001212} `,
1213 expectedBazelTargets: []string{`cc_library_static(
1214 name = "foo_static",
Liz Kammer8337ea42021-09-10 10:06:32 -04001215 copts = select({
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001216 "//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"],
1217 "//conditions:default": [],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001218 }) + select({
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001219 "//build/bazel/product_variables:malloc_not_svelte-android": ["-Wandroid_malloc_not_svelte"],
1220 "//conditions:default": [],
1221 }) + select({
1222 "//build/bazel/product_variables:malloc_not_svelte-arm": ["-Wlib32_malloc_not_svelte"],
1223 "//conditions:default": [],
1224 }) + select({
1225 "//build/bazel/product_variables:malloc_not_svelte-arm64": ["-Warm64_malloc_not_svelte"],
1226 "//conditions:default": [],
1227 }) + select({
1228 "//build/bazel/product_variables:malloc_not_svelte-x86": ["-Wlib32_malloc_not_svelte"],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001229 "//conditions:default": [],
1230 }),
Chris Parsons990c4f42021-05-25 12:10:58 -04001231 srcs_c = ["common.c"],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001232)`},
1233 })
1234}
Liz Kammerba7a9c52021-05-26 08:45:30 -04001235
1236func TestCcLibraryStaticProductVariableStringReplacement(t *testing.T) {
1237 runCcLibraryStaticTestCase(t, bp2buildTestCase{
Chris Parsons69fa9f92021-07-13 11:47:44 -04001238 description: "cc_library_static product variable string replacement",
Liz Kammerba7a9c52021-05-26 08:45:30 -04001239 moduleTypeUnderTest: "cc_library_static",
1240 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1241 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammerba7a9c52021-05-26 08:45:30 -04001242 filesystem: map[string]string{},
1243 blueprint: soongCcLibraryStaticPreamble + `
1244cc_library_static {
1245 name: "foo_static",
Chris Parsons69fa9f92021-07-13 11:47:44 -04001246 srcs: ["common.S"],
Liz Kammerba7a9c52021-05-26 08:45:30 -04001247 product_variables: {
1248 platform_sdk_version: {
1249 asflags: ["-DPLATFORM_SDK_VERSION=%d"],
1250 },
1251 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001252 include_build_directory: false,
Liz Kammerba7a9c52021-05-26 08:45:30 -04001253} `,
1254 expectedBazelTargets: []string{`cc_library_static(
1255 name = "foo_static",
Liz Kammer8337ea42021-09-10 10:06:32 -04001256 asflags = select({
Liz Kammerba7a9c52021-05-26 08:45:30 -04001257 "//build/bazel/product_variables:platform_sdk_version": ["-DPLATFORM_SDK_VERSION=$(Platform_sdk_version)"],
1258 "//conditions:default": [],
1259 }),
Chris Parsons69fa9f92021-07-13 11:47:44 -04001260 srcs_as = ["common.S"],
Liz Kammerba7a9c52021-05-26 08:45:30 -04001261)`},
1262 })
1263}
Chris Parsons51f8c392021-08-03 21:01:05 -04001264
1265func TestStaticLibrary_SystemSharedLibsRootEmpty(t *testing.T) {
1266 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1267 description: "cc_library_static system_shared_lib empty root",
1268 moduleTypeUnderTest: "cc_library_static",
1269 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1270 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1271 blueprint: soongCcLibraryStaticPreamble + `
1272cc_library_static {
1273 name: "root_empty",
Liz Kammer8337ea42021-09-10 10:06:32 -04001274 system_shared_libs: [],
1275 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001276}
1277`,
1278 expectedBazelTargets: []string{`cc_library_static(
1279 name = "root_empty",
Chris Parsons51f8c392021-08-03 21:01:05 -04001280 system_dynamic_deps = [],
1281)`},
1282 })
1283}
1284
1285func TestStaticLibrary_SystemSharedLibsStaticEmpty(t *testing.T) {
1286 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1287 description: "cc_library_static system_shared_lib empty static default",
1288 moduleTypeUnderTest: "cc_library_static",
1289 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1290 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1291 blueprint: soongCcLibraryStaticPreamble + `
1292cc_defaults {
1293 name: "static_empty_defaults",
1294 static: {
Liz Kammer8337ea42021-09-10 10:06:32 -04001295 system_shared_libs: [],
1296 },
1297 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001298}
1299cc_library_static {
1300 name: "static_empty",
Liz Kammer8337ea42021-09-10 10:06:32 -04001301 defaults: ["static_empty_defaults"],
Chris Parsons51f8c392021-08-03 21:01:05 -04001302}
1303`,
1304 expectedBazelTargets: []string{`cc_library_static(
1305 name = "static_empty",
Chris Parsons51f8c392021-08-03 21:01:05 -04001306 system_dynamic_deps = [],
1307)`},
1308 })
1309}
1310
1311func TestStaticLibrary_SystemSharedLibsBionicEmpty(t *testing.T) {
1312 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1313 description: "cc_library_static system_shared_lib empty for bionic variant",
1314 moduleTypeUnderTest: "cc_library_static",
1315 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1316 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1317 blueprint: soongCcLibraryStaticPreamble + `
1318cc_library_static {
1319 name: "target_bionic_empty",
1320 target: {
1321 bionic: {
1322 system_shared_libs: [],
1323 },
1324 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001325 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001326}
1327`,
1328 expectedBazelTargets: []string{`cc_library_static(
1329 name = "target_bionic_empty",
Chris Parsons51f8c392021-08-03 21:01:05 -04001330 system_dynamic_deps = [],
1331)`},
1332 })
1333}
1334
1335func TestStaticLibrary_SystemSharedLibsLinuxBionicEmpty(t *testing.T) {
1336 // Note that this behavior is technically incorrect (it's a simplification).
1337 // The correct behavior would be if bp2build wrote `system_dynamic_deps = []`
1338 // only for linux_bionic, but `android` had `["libc", "libdl", "libm"].
1339 // b/195791252 tracks the fix.
1340 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1341 description: "cc_library_static system_shared_lib empty for linux_bionic variant",
1342 moduleTypeUnderTest: "cc_library_static",
1343 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1344 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1345 blueprint: soongCcLibraryStaticPreamble + `
1346cc_library_static {
1347 name: "target_linux_bionic_empty",
1348 target: {
1349 linux_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_linux_bionic_empty",
Chris Parsons51f8c392021-08-03 21:01:05 -04001358 system_dynamic_deps = [],
1359)`},
1360 })
1361}
1362
1363func TestStaticLibrary_SystemSharedLibsBionic(t *testing.T) {
1364 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1365 description: "cc_library_static system_shared_libs set for bionic variant",
1366 moduleTypeUnderTest: "cc_library_static",
1367 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1368 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1369 blueprint: soongCcLibraryStaticPreamble + `
1370cc_library{name: "libc"}
1371
1372cc_library_static {
1373 name: "target_bionic",
1374 target: {
1375 bionic: {
1376 system_shared_libs: ["libc"],
1377 },
1378 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001379 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001380}
1381`,
1382 expectedBazelTargets: []string{`cc_library_static(
1383 name = "target_bionic",
Chris Parsons51f8c392021-08-03 21:01:05 -04001384 system_dynamic_deps = select({
Chris Parsons2dde0cb2021-10-01 14:45:30 -04001385 "//build/bazel/platforms/os:android": [":libc"],
1386 "//build/bazel/platforms/os:linux_bionic": [":libc"],
Chris Parsons51f8c392021-08-03 21:01:05 -04001387 "//conditions:default": [],
1388 }),
1389)`},
1390 })
1391}
1392
1393func TestStaticLibrary_SystemSharedLibsLinuxRootAndLinuxBionic(t *testing.T) {
1394 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1395 description: "cc_library_static system_shared_libs set for root and linux_bionic variant",
1396 moduleTypeUnderTest: "cc_library_static",
1397 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1398 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1399 blueprint: soongCcLibraryStaticPreamble + `
1400cc_library{name: "libc"}
1401cc_library{name: "libm"}
1402
1403cc_library_static {
1404 name: "target_linux_bionic",
Liz Kammer8337ea42021-09-10 10:06:32 -04001405 system_shared_libs: ["libc"],
Chris Parsons51f8c392021-08-03 21:01:05 -04001406 target: {
1407 linux_bionic: {
1408 system_shared_libs: ["libm"],
1409 },
1410 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001411 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001412}
1413`,
1414 expectedBazelTargets: []string{`cc_library_static(
1415 name = "target_linux_bionic",
Chris Parsons51f8c392021-08-03 21:01:05 -04001416 system_dynamic_deps = [":libc"] + select({
1417 "//build/bazel/platforms/os:linux_bionic": [":libm"],
1418 "//conditions:default": [],
1419 }),
1420)`},
1421 })
1422}