blob: f0225b16879fcd398cb362bdd3f1870b9d396429 [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 {
29 name: "linux_bionic_supported",
30}
31
32toolchain_library {
33 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"],
115}
116
117cc_library_headers {
118 name: "header_lib_2",
119 export_include_dirs: ["header_lib_2"],
120}
121
122cc_library_static {
123 name: "static_lib_1",
124 srcs: ["static_lib_1.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000125}
126
127cc_library_static {
128 name: "static_lib_2",
129 srcs: ["static_lib_2.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000130}
131
132cc_library_static {
133 name: "whole_static_lib_1",
134 srcs: ["whole_static_lib_1.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000135}
136
137cc_library_static {
138 name: "whole_static_lib_2",
139 srcs: ["whole_static_lib_2.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000140}
141
142cc_library_static {
143 name: "foo_static",
144 srcs: [
145 "foo_static1.cc",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000146 "foo_static2.cc",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000147 ],
148 cflags: [
149 "-Dflag1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000150 "-Dflag2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000151 ],
152 static_libs: [
153 "static_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000154 "static_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000155 ],
156 whole_static_libs: [
157 "whole_static_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000158 "whole_static_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000159 ],
160 include_dirs: [
Jingwen Chened9c17d2021-04-13 07:14:55 +0000161 "include_dir_1",
162 "include_dir_2",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000163 ],
164 local_include_dirs: [
165 "local_include_dir_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000166 "local_include_dir_2",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000167 ],
168 export_include_dirs: [
Chris Parsonsd6358772021-05-18 18:35:24 -0400169 "export_include_dir_1",
170 "export_include_dir_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000171 ],
172 header_libs: [
173 "header_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000174 "header_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000175 ],
176
177 // TODO: Also support export_header_lib_headers
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000178}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200179 expectedBazelTargets: []string{`cc_library_static(
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000180 name = "foo_static",
181 copts = [
182 "-Dflag1",
183 "-Dflag2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000184 "-Iinclude_dir_1",
Chris Parsons484e50a2021-05-13 15:13:04 -0400185 "-I$(BINDIR)/include_dir_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000186 "-Iinclude_dir_2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400187 "-I$(BINDIR)/include_dir_2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000188 "-Ilocal_include_dir_1",
Chris Parsons484e50a2021-05-13 15:13:04 -0400189 "-I$(BINDIR)/local_include_dir_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000190 "-Ilocal_include_dir_2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400191 "-I$(BINDIR)/local_include_dir_2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000192 "-I.",
Chris Parsons484e50a2021-05-13 15:13:04 -0400193 "-I$(BINDIR)/.",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000194 ],
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,
206 srcs = [
207 "foo_static1.cc",
208 "foo_static2.cc",
209 ],
Chris Parsons08648312021-05-06 16:23:19 -0400210 whole_archive_deps = [
211 ":whole_static_lib_1",
212 ":whole_static_lib_2",
213 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000214)`, `cc_library_static(
215 name = "static_lib_1",
Chris Parsons484e50a2021-05-13 15:13:04 -0400216 copts = [
217 "-I.",
218 "-I$(BINDIR)/.",
219 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000220 linkstatic = True,
Jingwen Chen882bcc12021-04-27 05:54:20 +0000221 srcs = ["static_lib_1.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000222)`, `cc_library_static(
223 name = "static_lib_2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400224 copts = [
225 "-I.",
226 "-I$(BINDIR)/.",
227 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000228 linkstatic = True,
Jingwen Chen882bcc12021-04-27 05:54:20 +0000229 srcs = ["static_lib_2.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000230)`, `cc_library_static(
231 name = "whole_static_lib_1",
Chris Parsons484e50a2021-05-13 15:13:04 -0400232 copts = [
233 "-I.",
234 "-I$(BINDIR)/.",
235 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000236 linkstatic = True,
Jingwen Chen882bcc12021-04-27 05:54:20 +0000237 srcs = ["whole_static_lib_1.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000238)`, `cc_library_static(
239 name = "whole_static_lib_2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400240 copts = [
241 "-I.",
242 "-I$(BINDIR)/.",
243 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000244 linkstatic = True,
Jingwen Chen882bcc12021-04-27 05:54:20 +0000245 srcs = ["whole_static_lib_2.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000246)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200247 })
248}
249
250func TestCcLibraryStaticSubpackage(t *testing.T) {
251 runCcLibraryStaticTestCase(t, bp2buildTestCase{
252 description: "cc_library_static subpackage test",
253 moduleTypeUnderTest: "cc_library_static",
254 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
255 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
256 filesystem: map[string]string{
257 // subpackage with subdirectory
258 "subpackage/Android.bp": "",
259 "subpackage/subpackage_header.h": "",
260 "subpackage/subdirectory/subdirectory_header.h": "",
261 // subsubpackage with subdirectory
262 "subpackage/subsubpackage/Android.bp": "",
263 "subpackage/subsubpackage/subsubpackage_header.h": "",
264 "subpackage/subsubpackage/subdirectory/subdirectory_header.h": "",
265 // subsubsubpackage with subdirectory
266 "subpackage/subsubpackage/subsubsubpackage/Android.bp": "",
267 "subpackage/subsubpackage/subsubsubpackage/subsubsubpackage_header.h": "",
268 "subpackage/subsubpackage/subsubsubpackage/subdirectory/subdirectory_header.h": "",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000269 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200270 blueprint: soongCcLibraryStaticPreamble + `
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400271cc_library_static {
272 name: "foo_static",
273 srcs: [
274 ],
275 include_dirs: [
276 "subpackage",
277 ],
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400278}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200279 expectedBazelTargets: []string{`cc_library_static(
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400280 name = "foo_static",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000281 copts = [
282 "-Isubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400283 "-I$(BINDIR)/subpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000284 "-I.",
Chris Parsons484e50a2021-05-13 15:13:04 -0400285 "-I$(BINDIR)/.",
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400286 ],
287 linkstatic = True,
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400288)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200289 })
290}
291
292func TestCcLibraryStaticExportIncludeDir(t *testing.T) {
293 runCcLibraryStaticTestCase(t, bp2buildTestCase{
294 description: "cc_library_static export include dir",
295 moduleTypeUnderTest: "cc_library_static",
296 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
297 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
298 filesystem: map[string]string{
299 // subpackage with subdirectory
300 "subpackage/Android.bp": "",
301 "subpackage/subpackage_header.h": "",
302 "subpackage/subdirectory/subdirectory_header.h": "",
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400303 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200304 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000305cc_library_static {
306 name: "foo_static",
307 export_include_dirs: ["subpackage"],
308}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200309 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000310 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400311 copts = [
312 "-I.",
313 "-I$(BINDIR)/.",
314 ],
Liz Kammer5fad5012021-09-09 14:08:21 -0400315 export_includes = ["subpackage"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000316 linkstatic = True,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000317)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200318 })
319}
320
321func TestCcLibraryStaticExportSystemIncludeDir(t *testing.T) {
322 runCcLibraryStaticTestCase(t, bp2buildTestCase{
323 description: "cc_library_static export system include dir",
324 moduleTypeUnderTest: "cc_library_static",
325 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
326 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
327 filesystem: map[string]string{
328 // subpackage with subdirectory
329 "subpackage/Android.bp": "",
330 "subpackage/subpackage_header.h": "",
331 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000332 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200333 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000334cc_library_static {
335 name: "foo_static",
336 export_system_include_dirs: ["subpackage"],
337}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200338 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000339 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400340 copts = [
341 "-I.",
342 "-I$(BINDIR)/.",
343 ],
Liz Kammer5fad5012021-09-09 14:08:21 -0400344 export_system_includes = ["subpackage"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000345 linkstatic = True,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000346)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200347 })
348}
349
350func TestCcLibraryStaticManyIncludeDirs(t *testing.T) {
351 runCcLibraryStaticTestCase(t, bp2buildTestCase{
352 description: "cc_library_static include_dirs, local_include_dirs, export_include_dirs (b/183742505)",
353 moduleTypeUnderTest: "cc_library_static",
354 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
355 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
356 dir: "subpackage",
357 filesystem: map[string]string{
358 // subpackage with subdirectory
359 "subpackage/Android.bp": `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000360cc_library_static {
361 name: "foo_static",
362 // include_dirs are workspace/root relative
363 include_dirs: [
364 "subpackage/subsubpackage",
365 "subpackage2",
366 "subpackage3/subsubpackage"
367 ],
368 local_include_dirs: ["subsubpackage2"], // module dir relative
369 export_include_dirs: ["./exported_subsubpackage"], // module dir relative
370 include_build_directory: true,
371 bazel_module: { bp2build_available: true },
372}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200373 "subpackage/subsubpackage/header.h": "",
374 "subpackage/subsubpackage2/header.h": "",
375 "subpackage/exported_subsubpackage/header.h": "",
376 "subpackage2/header.h": "",
377 "subpackage3/subsubpackage/header.h": "",
378 },
379 blueprint: soongCcLibraryStaticPreamble,
380 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000381 name = "foo_static",
382 copts = [
383 "-Isubpackage/subsubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400384 "-I$(BINDIR)/subpackage/subsubpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000385 "-Isubpackage2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400386 "-I$(BINDIR)/subpackage2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000387 "-Isubpackage3/subsubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400388 "-I$(BINDIR)/subpackage3/subsubpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000389 "-Isubpackage/subsubpackage2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400390 "-I$(BINDIR)/subpackage/subsubpackage2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000391 "-Isubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400392 "-I$(BINDIR)/subpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000393 ],
Liz Kammer5fad5012021-09-09 14:08:21 -0400394 export_includes = ["./exported_subsubpackage"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000395 linkstatic = True,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000396)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200397 })
398}
399
400func TestCcLibraryStaticIncludeBuildDirectoryDisabled(t *testing.T) {
401 runCcLibraryStaticTestCase(t, bp2buildTestCase{
402 description: "cc_library_static include_build_directory disabled",
403 moduleTypeUnderTest: "cc_library_static",
404 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
405 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
406 filesystem: map[string]string{
407 // subpackage with subdirectory
408 "subpackage/Android.bp": "",
409 "subpackage/subpackage_header.h": "",
410 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000411 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200412 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000413cc_library_static {
414 name: "foo_static",
415 include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended
416 local_include_dirs: ["subpackage2"],
417 include_build_directory: false,
418}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200419 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000420 name = "foo_static",
421 copts = [
422 "-Isubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400423 "-I$(BINDIR)/subpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000424 "-Isubpackage2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400425 "-I$(BINDIR)/subpackage2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000426 ],
427 linkstatic = True,
428)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200429 })
430}
431
432func TestCcLibraryStaticIncludeBuildDirectoryEnabled(t *testing.T) {
433 runCcLibraryStaticTestCase(t, bp2buildTestCase{
434 description: "cc_library_static include_build_directory enabled",
435 moduleTypeUnderTest: "cc_library_static",
436 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
437 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
438 filesystem: map[string]string{
439 // subpackage with subdirectory
440 "subpackage/Android.bp": "",
441 "subpackage/subpackage_header.h": "",
442 "subpackage2/Android.bp": "",
443 "subpackage2/subpackage2_header.h": "",
444 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000445 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200446 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000447cc_library_static {
448 name: "foo_static",
449 include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended
450 local_include_dirs: ["subpackage2"],
451 include_build_directory: true,
452}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200453 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000454 name = "foo_static",
455 copts = [
456 "-Isubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400457 "-I$(BINDIR)/subpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000458 "-Isubpackage2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400459 "-I$(BINDIR)/subpackage2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000460 "-I.",
Chris Parsons484e50a2021-05-13 15:13:04 -0400461 "-I$(BINDIR)/.",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000462 ],
463 linkstatic = True,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000464)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200465 })
466}
467
468func TestCcLibraryStaticArchSpecificStaticLib(t *testing.T) {
469 runCcLibraryStaticTestCase(t, bp2buildTestCase{
470 description: "cc_library_static arch-specific static_libs",
471 moduleTypeUnderTest: "cc_library_static",
472 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
473 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200474 filesystem: map[string]string{},
475 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000476cc_library_static { name: "static_dep" }
477cc_library_static { name: "static_dep2" }
478cc_library_static {
479 name: "foo_static",
480 arch: { arm64: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } },
481}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200482 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000483 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400484 copts = [
485 "-I.",
486 "-I$(BINDIR)/.",
487 ],
Chris Parsonsd6358772021-05-18 18:35:24 -0400488 implementation_deps = select({
Chris Parsons08648312021-05-06 16:23:19 -0400489 "//build/bazel/platforms/arch:arm64": [":static_dep"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000490 "//conditions:default": [],
491 }),
492 linkstatic = True,
Chris Parsons08648312021-05-06 16:23:19 -0400493 whole_archive_deps = select({
494 "//build/bazel/platforms/arch:arm64": [":static_dep2"],
495 "//conditions:default": [],
496 }),
Jingwen Chened9c17d2021-04-13 07:14:55 +0000497)`, `cc_library_static(
498 name = "static_dep",
Chris Parsons484e50a2021-05-13 15:13:04 -0400499 copts = [
500 "-I.",
501 "-I$(BINDIR)/.",
502 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000503 linkstatic = True,
504)`, `cc_library_static(
505 name = "static_dep2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400506 copts = [
507 "-I.",
508 "-I$(BINDIR)/.",
509 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000510 linkstatic = True,
511)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200512 })
513}
514
515func TestCcLibraryStaticOsSpecificStaticLib(t *testing.T) {
516 runCcLibraryStaticTestCase(t, bp2buildTestCase{
517 description: "cc_library_static os-specific static_libs",
518 moduleTypeUnderTest: "cc_library_static",
519 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
520 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200521 filesystem: map[string]string{},
522 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000523cc_library_static { name: "static_dep" }
524cc_library_static { name: "static_dep2" }
525cc_library_static {
526 name: "foo_static",
527 target: { android: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } },
528}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200529 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000530 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400531 copts = [
532 "-I.",
533 "-I$(BINDIR)/.",
534 ],
Chris Parsonsd6358772021-05-18 18:35:24 -0400535 implementation_deps = select({
Chris Parsons08648312021-05-06 16:23:19 -0400536 "//build/bazel/platforms/os:android": [":static_dep"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000537 "//conditions:default": [],
538 }),
539 linkstatic = True,
Chris Parsons08648312021-05-06 16:23:19 -0400540 whole_archive_deps = select({
541 "//build/bazel/platforms/os:android": [":static_dep2"],
542 "//conditions:default": [],
543 }),
Jingwen Chened9c17d2021-04-13 07:14:55 +0000544)`, `cc_library_static(
545 name = "static_dep",
Chris Parsons484e50a2021-05-13 15:13:04 -0400546 copts = [
547 "-I.",
548 "-I$(BINDIR)/.",
549 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000550 linkstatic = True,
551)`, `cc_library_static(
552 name = "static_dep2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400553 copts = [
554 "-I.",
555 "-I$(BINDIR)/.",
556 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000557 linkstatic = True,
558)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200559 })
560}
561
562func TestCcLibraryStaticBaseArchOsSpecificStaticLib(t *testing.T) {
563 runCcLibraryStaticTestCase(t, bp2buildTestCase{
564 description: "cc_library_static base, arch and os-specific static_libs",
565 moduleTypeUnderTest: "cc_library_static",
566 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
567 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200568 filesystem: map[string]string{},
569 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000570cc_library_static { name: "static_dep" }
571cc_library_static { name: "static_dep2" }
572cc_library_static { name: "static_dep3" }
573cc_library_static { name: "static_dep4" }
574cc_library_static {
575 name: "foo_static",
576 static_libs: ["static_dep"],
577 whole_static_libs: ["static_dep2"],
578 target: { android: { static_libs: ["static_dep3"] } },
579 arch: { arm64: { static_libs: ["static_dep4"] } },
580}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200581 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000582 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400583 copts = [
584 "-I.",
585 "-I$(BINDIR)/.",
586 ],
Chris Parsonsd6358772021-05-18 18:35:24 -0400587 implementation_deps = [":static_dep"] + select({
Jingwen Chened9c17d2021-04-13 07:14:55 +0000588 "//build/bazel/platforms/arch:arm64": [":static_dep4"],
589 "//conditions:default": [],
590 }) + select({
591 "//build/bazel/platforms/os:android": [":static_dep3"],
592 "//conditions:default": [],
593 }),
594 linkstatic = True,
Chris Parsons08648312021-05-06 16:23:19 -0400595 whole_archive_deps = [":static_dep2"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000596)`, `cc_library_static(
597 name = "static_dep",
Chris Parsons484e50a2021-05-13 15:13:04 -0400598 copts = [
599 "-I.",
600 "-I$(BINDIR)/.",
601 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000602 linkstatic = True,
603)`, `cc_library_static(
604 name = "static_dep2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400605 copts = [
606 "-I.",
607 "-I$(BINDIR)/.",
608 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000609 linkstatic = True,
610)`, `cc_library_static(
611 name = "static_dep3",
Chris Parsons484e50a2021-05-13 15:13:04 -0400612 copts = [
613 "-I.",
614 "-I$(BINDIR)/.",
615 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000616 linkstatic = True,
617)`, `cc_library_static(
618 name = "static_dep4",
Chris Parsons484e50a2021-05-13 15:13:04 -0400619 copts = [
620 "-I.",
621 "-I$(BINDIR)/.",
622 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000623 linkstatic = True,
624)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200625 })
626}
627
628func TestCcLibraryStaticSimpleExcludeSrcs(t *testing.T) {
629 runCcLibraryStaticTestCase(t, bp2buildTestCase{
630 description: "cc_library_static simple exclude_srcs",
631 moduleTypeUnderTest: "cc_library_static",
632 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
633 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200634 filesystem: map[string]string{
635 "common.c": "",
636 "foo-a.c": "",
637 "foo-excluded.c": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000638 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200639 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000640cc_library_static {
641 name: "foo_static",
642 srcs: ["common.c", "foo-*.c"],
643 exclude_srcs: ["foo-excluded.c"],
644}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200645 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000646 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400647 copts = [
648 "-I.",
649 "-I$(BINDIR)/.",
650 ],
Jingwen Chene32e9e02021-04-23 09:17:24 +0000651 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400652 srcs_c = [
Jingwen Chene32e9e02021-04-23 09:17:24 +0000653 "common.c",
654 "foo-a.c",
655 ],
656)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200657 })
658}
659
660func TestCcLibraryStaticOneArchSrcs(t *testing.T) {
661 runCcLibraryStaticTestCase(t, bp2buildTestCase{
662 description: "cc_library_static one arch specific srcs",
663 moduleTypeUnderTest: "cc_library_static",
664 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
665 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200666 filesystem: map[string]string{
667 "common.c": "",
668 "foo-arm.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000669 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200670 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000671cc_library_static {
672 name: "foo_static",
673 srcs: ["common.c"],
674 arch: { arm: { srcs: ["foo-arm.c"] } }
675}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200676 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000677 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400678 copts = [
679 "-I.",
680 "-I$(BINDIR)/.",
681 ],
Jingwen Chene32e9e02021-04-23 09:17:24 +0000682 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400683 srcs_c = ["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000684 "//build/bazel/platforms/arch:arm": ["foo-arm.c"],
685 "//conditions:default": [],
686 }),
687)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200688 })
689}
690
691func TestCcLibraryStaticOneArchSrcsExcludeSrcs(t *testing.T) {
692 runCcLibraryStaticTestCase(t, bp2buildTestCase{
693 description: "cc_library_static one arch specific srcs and exclude_srcs",
694 moduleTypeUnderTest: "cc_library_static",
695 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
696 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200697 filesystem: map[string]string{
698 "common.c": "",
699 "for-arm.c": "",
700 "not-for-arm.c": "",
701 "not-for-anything.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000702 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200703 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000704cc_library_static {
705 name: "foo_static",
706 srcs: ["common.c", "not-for-*.c"],
707 exclude_srcs: ["not-for-anything.c"],
708 arch: {
709 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
710 },
711}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200712 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000713 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400714 copts = [
715 "-I.",
716 "-I$(BINDIR)/.",
717 ],
Jingwen Chene32e9e02021-04-23 09:17:24 +0000718 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400719 srcs_c = ["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000720 "//build/bazel/platforms/arch:arm": ["for-arm.c"],
721 "//conditions:default": ["not-for-arm.c"],
722 }),
723)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200724 })
725}
726
727func TestCcLibraryStaticTwoArchExcludeSrcs(t *testing.T) {
728 runCcLibraryStaticTestCase(t, bp2buildTestCase{
729 description: "cc_library_static arch specific exclude_srcs for 2 architectures",
730 moduleTypeUnderTest: "cc_library_static",
731 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
732 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200733 filesystem: map[string]string{
734 "common.c": "",
735 "for-arm.c": "",
736 "for-x86.c": "",
737 "not-for-arm.c": "",
738 "not-for-x86.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000739 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200740 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000741cc_library_static {
742 name: "foo_static",
743 srcs: ["common.c", "not-for-*.c"],
744 exclude_srcs: ["not-for-everything.c"],
745 arch: {
746 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
747 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
748 },
749} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200750 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000751 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400752 copts = [
753 "-I.",
754 "-I$(BINDIR)/.",
755 ],
Jingwen Chene32e9e02021-04-23 09:17:24 +0000756 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400757 srcs_c = ["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000758 "//build/bazel/platforms/arch:arm": [
759 "for-arm.c",
760 "not-for-x86.c",
761 ],
762 "//build/bazel/platforms/arch:x86": [
763 "for-x86.c",
764 "not-for-arm.c",
765 ],
766 "//conditions:default": [
767 "not-for-arm.c",
768 "not-for-x86.c",
769 ],
770 }),
771)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200772 })
773}
774func TestCcLibraryStaticFourArchExcludeSrcs(t *testing.T) {
775 runCcLibraryStaticTestCase(t, bp2buildTestCase{
776 description: "cc_library_static arch specific exclude_srcs for 4 architectures",
777 moduleTypeUnderTest: "cc_library_static",
778 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
779 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200780 filesystem: map[string]string{
781 "common.c": "",
782 "for-arm.c": "",
783 "for-arm64.c": "",
784 "for-x86.c": "",
785 "for-x86_64.c": "",
786 "not-for-arm.c": "",
787 "not-for-arm64.c": "",
788 "not-for-x86.c": "",
789 "not-for-x86_64.c": "",
790 "not-for-everything.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000791 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200792 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000793cc_library_static {
794 name: "foo_static",
795 srcs: ["common.c", "not-for-*.c"],
796 exclude_srcs: ["not-for-everything.c"],
797 arch: {
798 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
799 arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] },
800 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
801 x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] },
802 },
803} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200804 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000805 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400806 copts = [
807 "-I.",
808 "-I$(BINDIR)/.",
809 ],
Jingwen Chene32e9e02021-04-23 09:17:24 +0000810 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400811 srcs_c = ["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000812 "//build/bazel/platforms/arch:arm": [
813 "for-arm.c",
814 "not-for-arm64.c",
815 "not-for-x86.c",
816 "not-for-x86_64.c",
817 ],
818 "//build/bazel/platforms/arch:arm64": [
819 "for-arm64.c",
820 "not-for-arm.c",
821 "not-for-x86.c",
822 "not-for-x86_64.c",
823 ],
824 "//build/bazel/platforms/arch:x86": [
825 "for-x86.c",
826 "not-for-arm.c",
827 "not-for-arm64.c",
828 "not-for-x86_64.c",
829 ],
830 "//build/bazel/platforms/arch:x86_64": [
831 "for-x86_64.c",
832 "not-for-arm.c",
833 "not-for-arm64.c",
834 "not-for-x86.c",
835 ],
836 "//conditions:default": [
837 "not-for-arm.c",
838 "not-for-arm64.c",
839 "not-for-x86.c",
840 "not-for-x86_64.c",
841 ],
842 }),
843)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200844 })
845}
846
Liz Kammer2b07ec72021-05-26 15:08:27 -0400847func TestCcLibraryStaticOneArchEmpty(t *testing.T) {
848 runCcLibraryStaticTestCase(t, bp2buildTestCase{
849 description: "cc_library_static one arch empty",
850 moduleTypeUnderTest: "cc_library_static",
851 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
852 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammer2b07ec72021-05-26 15:08:27 -0400853 filesystem: map[string]string{
854 "common.cc": "",
855 "foo-no-arm.cc": "",
856 "foo-excluded.cc": "",
857 },
858 blueprint: soongCcLibraryStaticPreamble + `
859cc_library_static {
860 name: "foo_static",
861 srcs: ["common.cc", "foo-*.cc"],
862 exclude_srcs: ["foo-excluded.cc"],
863 arch: {
864 arm: { exclude_srcs: ["foo-no-arm.cc"] },
865 },
866}`,
867 expectedBazelTargets: []string{`cc_library_static(
868 name = "foo_static",
869 copts = [
870 "-I.",
871 "-I$(BINDIR)/.",
872 ],
873 linkstatic = True,
874 srcs = ["common.cc"] + select({
875 "//build/bazel/platforms/arch:arm": [],
876 "//conditions:default": ["foo-no-arm.cc"],
877 }),
878)`},
879 })
880}
881
882func TestCcLibraryStaticOneArchEmptyOtherSet(t *testing.T) {
883 runCcLibraryStaticTestCase(t, bp2buildTestCase{
884 description: "cc_library_static one arch empty other set",
885 moduleTypeUnderTest: "cc_library_static",
886 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
887 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammer2b07ec72021-05-26 15:08:27 -0400888 filesystem: map[string]string{
889 "common.cc": "",
890 "foo-no-arm.cc": "",
891 "x86-only.cc": "",
892 "foo-excluded.cc": "",
893 },
894 blueprint: soongCcLibraryStaticPreamble + `
895cc_library_static {
896 name: "foo_static",
897 srcs: ["common.cc", "foo-*.cc"],
898 exclude_srcs: ["foo-excluded.cc"],
899 arch: {
900 arm: { exclude_srcs: ["foo-no-arm.cc"] },
901 x86: { srcs: ["x86-only.cc"] },
902 },
903}`,
904 expectedBazelTargets: []string{`cc_library_static(
905 name = "foo_static",
906 copts = [
907 "-I.",
908 "-I$(BINDIR)/.",
909 ],
910 linkstatic = True,
911 srcs = ["common.cc"] + select({
912 "//build/bazel/platforms/arch:arm": [],
913 "//build/bazel/platforms/arch:x86": [
914 "foo-no-arm.cc",
915 "x86-only.cc",
916 ],
917 "//conditions:default": ["foo-no-arm.cc"],
918 }),
919)`},
920 })
921}
922
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200923func TestCcLibraryStaticMultipleDepSameName(t *testing.T) {
924 runCcLibraryStaticTestCase(t, bp2buildTestCase{
925 description: "cc_library_static multiple dep same name panic",
926 moduleTypeUnderTest: "cc_library_static",
927 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
928 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200929 filesystem: map[string]string{},
930 blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer2b50ce62021-04-26 15:47:28 -0400931cc_library_static { name: "static_dep" }
932cc_library_static {
933 name: "foo_static",
Chris Parsons08648312021-05-06 16:23:19 -0400934 static_libs: ["static_dep", "static_dep"],
Liz Kammer2b50ce62021-04-26 15:47:28 -0400935}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200936 expectedBazelTargets: []string{`cc_library_static(
Liz Kammer2b50ce62021-04-26 15:47:28 -0400937 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400938 copts = [
939 "-I.",
940 "-I$(BINDIR)/.",
941 ],
Chris Parsonsd6358772021-05-18 18:35:24 -0400942 implementation_deps = [":static_dep"],
Liz Kammer2b50ce62021-04-26 15:47:28 -0400943 linkstatic = True,
944)`, `cc_library_static(
945 name = "static_dep",
Chris Parsons484e50a2021-05-13 15:13:04 -0400946 copts = [
947 "-I.",
948 "-I$(BINDIR)/.",
949 ],
Liz Kammer2b50ce62021-04-26 15:47:28 -0400950 linkstatic = True,
951)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200952 })
953}
954
955func TestCcLibraryStaticOneMultilibSrcsExcludeSrcs(t *testing.T) {
956 runCcLibraryStaticTestCase(t, bp2buildTestCase{
957 description: "cc_library_static 1 multilib srcs and exclude_srcs",
958 moduleTypeUnderTest: "cc_library_static",
959 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
960 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200961 filesystem: map[string]string{
962 "common.c": "",
963 "for-lib32.c": "",
964 "not-for-lib32.c": "",
Liz Kammer2b50ce62021-04-26 15:47:28 -0400965 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200966 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -0400967cc_library_static {
968 name: "foo_static",
969 srcs: ["common.c", "not-for-*.c"],
970 multilib: {
971 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
972 },
973} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200974 expectedBazelTargets: []string{`cc_library_static(
Chris Parsonsc424b762021-04-29 18:06:50 -0400975 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400976 copts = [
977 "-I.",
978 "-I$(BINDIR)/.",
979 ],
Chris Parsonsc424b762021-04-29 18:06:50 -0400980 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400981 srcs_c = ["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -0400982 "//build/bazel/platforms/arch:arm": ["for-lib32.c"],
983 "//build/bazel/platforms/arch:x86": ["for-lib32.c"],
984 "//conditions:default": ["not-for-lib32.c"],
985 }),
986)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200987 })
988}
989
990func TestCcLibraryStaticTwoMultilibSrcsExcludeSrcs(t *testing.T) {
991 runCcLibraryStaticTestCase(t, bp2buildTestCase{
992 description: "cc_library_static 2 multilib srcs and exclude_srcs",
993 moduleTypeUnderTest: "cc_library_static",
994 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
995 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200996 filesystem: map[string]string{
997 "common.c": "",
998 "for-lib32.c": "",
999 "for-lib64.c": "",
1000 "not-for-lib32.c": "",
1001 "not-for-lib64.c": "",
Chris Parsonsc424b762021-04-29 18:06:50 -04001002 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001003 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -04001004cc_library_static {
1005 name: "foo_static2",
1006 srcs: ["common.c", "not-for-*.c"],
1007 multilib: {
1008 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
1009 lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] },
1010 },
1011} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001012 expectedBazelTargets: []string{`cc_library_static(
Chris Parsonsc424b762021-04-29 18:06:50 -04001013 name = "foo_static2",
Chris Parsons484e50a2021-05-13 15:13:04 -04001014 copts = [
1015 "-I.",
1016 "-I$(BINDIR)/.",
1017 ],
Chris Parsonsc424b762021-04-29 18:06:50 -04001018 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -04001019 srcs_c = ["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -04001020 "//build/bazel/platforms/arch:arm": [
1021 "for-lib32.c",
1022 "not-for-lib64.c",
1023 ],
1024 "//build/bazel/platforms/arch:arm64": [
1025 "for-lib64.c",
1026 "not-for-lib32.c",
1027 ],
1028 "//build/bazel/platforms/arch:x86": [
1029 "for-lib32.c",
1030 "not-for-lib64.c",
1031 ],
1032 "//build/bazel/platforms/arch:x86_64": [
1033 "for-lib64.c",
1034 "not-for-lib32.c",
1035 ],
1036 "//conditions:default": [
1037 "not-for-lib32.c",
1038 "not-for-lib64.c",
1039 ],
1040 }),
1041)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001042 })
1043}
1044
1045func TestCcLibrarySTaticArchMultilibSrcsExcludeSrcs(t *testing.T) {
1046 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1047 description: "cc_library_static arch and multilib srcs and exclude_srcs",
1048 moduleTypeUnderTest: "cc_library_static",
1049 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1050 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001051 filesystem: map[string]string{
1052 "common.c": "",
1053 "for-arm.c": "",
1054 "for-arm64.c": "",
1055 "for-x86.c": "",
1056 "for-x86_64.c": "",
1057 "for-lib32.c": "",
1058 "for-lib64.c": "",
1059 "not-for-arm.c": "",
1060 "not-for-arm64.c": "",
1061 "not-for-x86.c": "",
1062 "not-for-x86_64.c": "",
1063 "not-for-lib32.c": "",
1064 "not-for-lib64.c": "",
1065 "not-for-everything.c": "",
Chris Parsonsc424b762021-04-29 18:06:50 -04001066 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001067 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -04001068cc_library_static {
1069 name: "foo_static3",
1070 srcs: ["common.c", "not-for-*.c"],
1071 exclude_srcs: ["not-for-everything.c"],
1072 arch: {
1073 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
1074 arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] },
1075 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
1076 x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] },
1077 },
1078 multilib: {
1079 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
1080 lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] },
1081 },
1082}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001083 expectedBazelTargets: []string{`cc_library_static(
Chris Parsonsc424b762021-04-29 18:06:50 -04001084 name = "foo_static3",
Chris Parsons484e50a2021-05-13 15:13:04 -04001085 copts = [
1086 "-I.",
1087 "-I$(BINDIR)/.",
1088 ],
Chris Parsonsc424b762021-04-29 18:06:50 -04001089 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -04001090 srcs_c = ["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -04001091 "//build/bazel/platforms/arch:arm": [
1092 "for-arm.c",
1093 "for-lib32.c",
1094 "not-for-arm64.c",
1095 "not-for-lib64.c",
1096 "not-for-x86.c",
1097 "not-for-x86_64.c",
1098 ],
1099 "//build/bazel/platforms/arch:arm64": [
1100 "for-arm64.c",
1101 "for-lib64.c",
1102 "not-for-arm.c",
1103 "not-for-lib32.c",
1104 "not-for-x86.c",
1105 "not-for-x86_64.c",
1106 ],
1107 "//build/bazel/platforms/arch:x86": [
1108 "for-lib32.c",
1109 "for-x86.c",
1110 "not-for-arm.c",
1111 "not-for-arm64.c",
1112 "not-for-lib64.c",
1113 "not-for-x86_64.c",
1114 ],
1115 "//build/bazel/platforms/arch:x86_64": [
1116 "for-lib64.c",
1117 "for-x86_64.c",
1118 "not-for-arm.c",
1119 "not-for-arm64.c",
1120 "not-for-lib32.c",
1121 "not-for-x86.c",
1122 ],
1123 "//conditions:default": [
1124 "not-for-arm.c",
1125 "not-for-arm64.c",
1126 "not-for-lib32.c",
1127 "not-for-lib64.c",
1128 "not-for-x86.c",
1129 "not-for-x86_64.c",
1130 ],
1131 }),
1132)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001133 })
1134}
1135
1136func TestCcLibraryStaticArchSrcsExcludeSrcsGeneratedFiles(t *testing.T) {
1137 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1138 description: "cc_library_static arch srcs/exclude_srcs with generated files",
1139 moduleTypeUnderTest: "cc_library_static",
1140 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1141 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001142 filesystem: map[string]string{
Chris Parsons990c4f42021-05-25 12:10:58 -04001143 "common.cpp": "",
1144 "for-x86.cpp": "",
1145 "not-for-x86.cpp": "",
1146 "not-for-everything.cpp": "",
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001147 "dep/Android.bp": `
Chris Parsons484e50a2021-05-13 15:13:04 -04001148genrule {
1149 name: "generated_src_other_pkg",
1150 out: ["generated_src_other_pkg.cpp"],
1151 cmd: "nothing to see here",
1152}
1153
1154genrule {
1155 name: "generated_hdr_other_pkg",
1156 out: ["generated_hdr_other_pkg.cpp"],
1157 cmd: "nothing to see here",
1158}
1159
1160genrule {
1161 name: "generated_hdr_other_pkg_x86",
1162 out: ["generated_hdr_other_pkg_x86.cpp"],
1163 cmd: "nothing to see here",
1164}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001165 },
1166 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsons484e50a2021-05-13 15:13:04 -04001167genrule {
1168 name: "generated_src",
1169 out: ["generated_src.cpp"],
1170 cmd: "nothing to see here",
1171}
1172
1173genrule {
1174 name: "generated_src_x86",
1175 out: ["generated_src_x86.cpp"],
1176 cmd: "nothing to see here",
1177}
1178
1179genrule {
1180 name: "generated_hdr",
1181 out: ["generated_hdr.h"],
1182 cmd: "nothing to see here",
1183}
1184
1185cc_library_static {
1186 name: "foo_static3",
Chris Parsons990c4f42021-05-25 12:10:58 -04001187 srcs: ["common.cpp", "not-for-*.cpp"],
1188 exclude_srcs: ["not-for-everything.cpp"],
Chris Parsons484e50a2021-05-13 15:13:04 -04001189 generated_sources: ["generated_src", "generated_src_other_pkg"],
1190 generated_headers: ["generated_hdr", "generated_hdr_other_pkg"],
1191 arch: {
1192 x86: {
Chris Parsons990c4f42021-05-25 12:10:58 -04001193 srcs: ["for-x86.cpp"],
1194 exclude_srcs: ["not-for-x86.cpp"],
Chris Parsons484e50a2021-05-13 15:13:04 -04001195 generated_sources: ["generated_src_x86"],
1196 generated_headers: ["generated_hdr_other_pkg_x86"],
1197 },
1198 },
1199}
1200`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001201 expectedBazelTargets: []string{`cc_library_static(
Chris Parsons484e50a2021-05-13 15:13:04 -04001202 name = "foo_static3",
1203 copts = [
1204 "-I.",
1205 "-I$(BINDIR)/.",
1206 ],
1207 linkstatic = True,
1208 srcs = [
1209 "//dep:generated_hdr_other_pkg",
1210 "//dep:generated_src_other_pkg",
1211 ":generated_hdr",
1212 ":generated_src",
Chris Parsons990c4f42021-05-25 12:10:58 -04001213 "common.cpp",
Chris Parsons484e50a2021-05-13 15:13:04 -04001214 ] + select({
1215 "//build/bazel/platforms/arch:x86": [
1216 "//dep:generated_hdr_other_pkg_x86",
1217 ":generated_src_x86",
Chris Parsons990c4f42021-05-25 12:10:58 -04001218 "for-x86.cpp",
Chris Parsons484e50a2021-05-13 15:13:04 -04001219 ],
Chris Parsons990c4f42021-05-25 12:10:58 -04001220 "//conditions:default": ["not-for-x86.cpp"],
Chris Parsons484e50a2021-05-13 15:13:04 -04001221 }),
1222)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001223 })
Rupert Shuttleworth095081c2021-03-25 09:06:03 +00001224}
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001225
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001226func TestCcLibraryStaticGetTargetProperties(t *testing.T) {
1227 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1228
1229 description: "cc_library_static complex GetTargetProperties",
1230 moduleTypeUnderTest: "cc_library_static",
1231 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1232 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001233 blueprint: soongCcLibraryStaticPreamble + `
1234cc_library_static {
1235 name: "foo_static",
1236 target: {
1237 android: {
1238 srcs: ["android_src.c"],
1239 },
1240 android_arm: {
1241 srcs: ["android_arm_src.c"],
1242 },
1243 android_arm64: {
1244 srcs: ["android_arm64_src.c"],
1245 },
1246 android_x86: {
1247 srcs: ["android_x86_src.c"],
1248 },
1249 android_x86_64: {
1250 srcs: ["android_x86_64_src.c"],
1251 },
1252 linux_bionic_arm64: {
1253 srcs: ["linux_bionic_arm64_src.c"],
1254 },
1255 linux_bionic_x86_64: {
1256 srcs: ["linux_bionic_x86_64_src.c"],
1257 },
1258 },
1259}`,
1260 expectedBazelTargets: []string{`cc_library_static(
1261 name = "foo_static",
1262 copts = [
1263 "-I.",
1264 "-I$(BINDIR)/.",
1265 ],
1266 linkstatic = True,
1267 srcs_c = select({
1268 "//build/bazel/platforms/os:android": ["android_src.c"],
1269 "//conditions:default": [],
1270 }) + select({
Rupert Shuttleworthffd45822021-05-14 03:02:34 -04001271 "//build/bazel/platforms/os_arch:android_arm": ["android_arm_src.c"],
1272 "//build/bazel/platforms/os_arch:android_arm64": ["android_arm64_src.c"],
1273 "//build/bazel/platforms/os_arch:android_x86": ["android_x86_src.c"],
1274 "//build/bazel/platforms/os_arch:android_x86_64": ["android_x86_64_src.c"],
Rupert Shuttleworthffd45822021-05-14 03:02:34 -04001275 "//build/bazel/platforms/os_arch:linux_bionic_arm64": ["linux_bionic_arm64_src.c"],
1276 "//build/bazel/platforms/os_arch:linux_bionic_x86_64": ["linux_bionic_x86_64_src.c"],
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001277 "//conditions:default": [],
1278 }),
1279)`},
1280 })
1281}
1282
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001283func TestCcLibraryStaticProductVariableSelects(t *testing.T) {
1284 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1285 description: "cc_library_static product variable selects",
1286 moduleTypeUnderTest: "cc_library_static",
1287 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1288 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001289 blueprint: soongCcLibraryStaticPreamble + `
1290cc_library_static {
1291 name: "foo_static",
1292 srcs: ["common.c"],
1293 product_variables: {
1294 malloc_not_svelte: {
1295 cflags: ["-Wmalloc_not_svelte"],
1296 },
1297 malloc_zero_contents: {
1298 cflags: ["-Wmalloc_zero_contents"],
1299 },
1300 binder32bit: {
1301 cflags: ["-Wbinder32bit"],
1302 },
1303 },
1304} `,
1305 expectedBazelTargets: []string{`cc_library_static(
1306 name = "foo_static",
1307 copts = [
1308 "-I.",
1309 "-I$(BINDIR)/.",
1310 ] + select({
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001311 "//build/bazel/product_variables:binder32bit": ["-Wbinder32bit"],
1312 "//conditions:default": [],
1313 }) + select({
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001314 "//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"],
1315 "//conditions:default": [],
1316 }) + select({
1317 "//build/bazel/product_variables:malloc_zero_contents": ["-Wmalloc_zero_contents"],
1318 "//conditions:default": [],
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001319 }),
1320 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -04001321 srcs_c = ["common.c"],
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001322)`},
1323 })
1324}
1325
1326func TestCcLibraryStaticProductVariableArchSpecificSelects(t *testing.T) {
1327 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1328 description: "cc_library_static arch-specific product variable selects",
1329 moduleTypeUnderTest: "cc_library_static",
1330 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1331 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001332 filesystem: map[string]string{},
1333 blueprint: soongCcLibraryStaticPreamble + `
1334cc_library_static {
1335 name: "foo_static",
1336 srcs: ["common.c"],
1337 product_variables: {
1338 malloc_not_svelte: {
1339 cflags: ["-Wmalloc_not_svelte"],
1340 },
1341 },
1342 arch: {
1343 arm64: {
1344 product_variables: {
1345 malloc_not_svelte: {
1346 cflags: ["-Warm64_malloc_not_svelte"],
1347 },
1348 },
1349 },
1350 },
1351 multilib: {
1352 lib32: {
1353 product_variables: {
1354 malloc_not_svelte: {
1355 cflags: ["-Wlib32_malloc_not_svelte"],
1356 },
1357 },
1358 },
1359 },
1360 target: {
1361 android: {
1362 product_variables: {
1363 malloc_not_svelte: {
1364 cflags: ["-Wandroid_malloc_not_svelte"],
1365 },
1366 },
1367 }
1368 },
1369} `,
1370 expectedBazelTargets: []string{`cc_library_static(
1371 name = "foo_static",
1372 copts = [
1373 "-I.",
1374 "-I$(BINDIR)/.",
1375 ] + select({
1376 "//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"],
1377 "//conditions:default": [],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001378 }) + select({
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001379 "//build/bazel/product_variables:malloc_not_svelte-android": ["-Wandroid_malloc_not_svelte"],
1380 "//conditions:default": [],
1381 }) + select({
1382 "//build/bazel/product_variables:malloc_not_svelte-arm": ["-Wlib32_malloc_not_svelte"],
1383 "//conditions:default": [],
1384 }) + select({
1385 "//build/bazel/product_variables:malloc_not_svelte-arm64": ["-Warm64_malloc_not_svelte"],
1386 "//conditions:default": [],
1387 }) + select({
1388 "//build/bazel/product_variables:malloc_not_svelte-x86": ["-Wlib32_malloc_not_svelte"],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001389 "//conditions:default": [],
1390 }),
1391 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -04001392 srcs_c = ["common.c"],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001393)`},
1394 })
1395}
Liz Kammerba7a9c52021-05-26 08:45:30 -04001396
1397func TestCcLibraryStaticProductVariableStringReplacement(t *testing.T) {
1398 runCcLibraryStaticTestCase(t, bp2buildTestCase{
Chris Parsons69fa9f92021-07-13 11:47:44 -04001399 description: "cc_library_static product variable string replacement",
Liz Kammerba7a9c52021-05-26 08:45:30 -04001400 moduleTypeUnderTest: "cc_library_static",
1401 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1402 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammerba7a9c52021-05-26 08:45:30 -04001403 filesystem: map[string]string{},
1404 blueprint: soongCcLibraryStaticPreamble + `
1405cc_library_static {
1406 name: "foo_static",
Chris Parsons69fa9f92021-07-13 11:47:44 -04001407 srcs: ["common.S"],
Liz Kammerba7a9c52021-05-26 08:45:30 -04001408 product_variables: {
1409 platform_sdk_version: {
1410 asflags: ["-DPLATFORM_SDK_VERSION=%d"],
1411 },
1412 },
1413} `,
1414 expectedBazelTargets: []string{`cc_library_static(
1415 name = "foo_static",
Chris Parsons69fa9f92021-07-13 11:47:44 -04001416 asflags = [
1417 "-I.",
1418 "-I$(BINDIR)/.",
1419 ] + select({
Liz Kammerba7a9c52021-05-26 08:45:30 -04001420 "//build/bazel/product_variables:platform_sdk_version": ["-DPLATFORM_SDK_VERSION=$(Platform_sdk_version)"],
1421 "//conditions:default": [],
1422 }),
1423 copts = [
1424 "-I.",
1425 "-I$(BINDIR)/.",
1426 ],
1427 linkstatic = True,
Chris Parsons69fa9f92021-07-13 11:47:44 -04001428 srcs_as = ["common.S"],
Liz Kammerba7a9c52021-05-26 08:45:30 -04001429)`},
1430 })
1431}
Chris Parsons51f8c392021-08-03 21:01:05 -04001432
1433func TestStaticLibrary_SystemSharedLibsRootEmpty(t *testing.T) {
1434 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1435 description: "cc_library_static system_shared_lib empty root",
1436 moduleTypeUnderTest: "cc_library_static",
1437 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1438 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1439 blueprint: soongCcLibraryStaticPreamble + `
1440cc_library_static {
1441 name: "root_empty",
1442 system_shared_libs: [],
1443}
1444`,
1445 expectedBazelTargets: []string{`cc_library_static(
1446 name = "root_empty",
1447 copts = [
1448 "-I.",
1449 "-I$(BINDIR)/.",
1450 ],
1451 linkstatic = True,
1452 system_dynamic_deps = [],
1453)`},
1454 })
1455}
1456
1457func TestStaticLibrary_SystemSharedLibsStaticEmpty(t *testing.T) {
1458 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1459 description: "cc_library_static system_shared_lib empty static default",
1460 moduleTypeUnderTest: "cc_library_static",
1461 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1462 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1463 blueprint: soongCcLibraryStaticPreamble + `
1464cc_defaults {
1465 name: "static_empty_defaults",
1466 static: {
1467 system_shared_libs: [],
1468 },
1469}
1470cc_library_static {
1471 name: "static_empty",
1472 defaults: ["static_empty_defaults"],
1473}
1474`,
1475 expectedBazelTargets: []string{`cc_library_static(
1476 name = "static_empty",
1477 copts = [
1478 "-I.",
1479 "-I$(BINDIR)/.",
1480 ],
1481 linkstatic = True,
1482 system_dynamic_deps = [],
1483)`},
1484 })
1485}
1486
1487func TestStaticLibrary_SystemSharedLibsBionicEmpty(t *testing.T) {
1488 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1489 description: "cc_library_static system_shared_lib empty for bionic variant",
1490 moduleTypeUnderTest: "cc_library_static",
1491 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1492 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1493 blueprint: soongCcLibraryStaticPreamble + `
1494cc_library_static {
1495 name: "target_bionic_empty",
1496 target: {
1497 bionic: {
1498 system_shared_libs: [],
1499 },
1500 },
1501}
1502`,
1503 expectedBazelTargets: []string{`cc_library_static(
1504 name = "target_bionic_empty",
1505 copts = [
1506 "-I.",
1507 "-I$(BINDIR)/.",
1508 ],
1509 linkstatic = True,
1510 system_dynamic_deps = [],
1511)`},
1512 })
1513}
1514
1515func TestStaticLibrary_SystemSharedLibsLinuxBionicEmpty(t *testing.T) {
1516 // Note that this behavior is technically incorrect (it's a simplification).
1517 // The correct behavior would be if bp2build wrote `system_dynamic_deps = []`
1518 // only for linux_bionic, but `android` had `["libc", "libdl", "libm"].
1519 // b/195791252 tracks the fix.
1520 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1521 description: "cc_library_static system_shared_lib empty for linux_bionic variant",
1522 moduleTypeUnderTest: "cc_library_static",
1523 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1524 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1525 blueprint: soongCcLibraryStaticPreamble + `
1526cc_library_static {
1527 name: "target_linux_bionic_empty",
1528 target: {
1529 linux_bionic: {
1530 system_shared_libs: [],
1531 },
1532 },
1533}
1534`,
1535 expectedBazelTargets: []string{`cc_library_static(
1536 name = "target_linux_bionic_empty",
1537 copts = [
1538 "-I.",
1539 "-I$(BINDIR)/.",
1540 ],
1541 linkstatic = True,
1542 system_dynamic_deps = [],
1543)`},
1544 })
1545}
1546
1547func TestStaticLibrary_SystemSharedLibsBionic(t *testing.T) {
1548 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1549 description: "cc_library_static system_shared_libs set for bionic variant",
1550 moduleTypeUnderTest: "cc_library_static",
1551 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1552 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1553 blueprint: soongCcLibraryStaticPreamble + `
1554cc_library{name: "libc"}
1555
1556cc_library_static {
1557 name: "target_bionic",
1558 target: {
1559 bionic: {
1560 system_shared_libs: ["libc"],
1561 },
1562 },
1563}
1564`,
1565 expectedBazelTargets: []string{`cc_library_static(
1566 name = "target_bionic",
1567 copts = [
1568 "-I.",
1569 "-I$(BINDIR)/.",
1570 ],
1571 linkstatic = True,
1572 system_dynamic_deps = select({
1573 "//build/bazel/platforms/os:bionic": [":libc"],
1574 "//conditions:default": [],
1575 }),
1576)`},
1577 })
1578}
1579
1580func TestStaticLibrary_SystemSharedLibsLinuxRootAndLinuxBionic(t *testing.T) {
1581 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1582 description: "cc_library_static system_shared_libs set for root and linux_bionic variant",
1583 moduleTypeUnderTest: "cc_library_static",
1584 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1585 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1586 blueprint: soongCcLibraryStaticPreamble + `
1587cc_library{name: "libc"}
1588cc_library{name: "libm"}
1589
1590cc_library_static {
1591 name: "target_linux_bionic",
1592 system_shared_libs: ["libc"],
1593 target: {
1594 linux_bionic: {
1595 system_shared_libs: ["libm"],
1596 },
1597 },
1598}
1599`,
1600 expectedBazelTargets: []string{`cc_library_static(
1601 name = "target_linux_bionic",
1602 copts = [
1603 "-I.",
1604 "-I$(BINDIR)/.",
1605 ],
1606 linkstatic = True,
1607 system_dynamic_deps = [":libc"] + select({
1608 "//build/bazel/platforms/os:linux_bionic": [":libm"],
1609 "//conditions:default": [],
1610 }),
1611)`},
1612 })
1613}