blob: 229b1c25ef37673a20a1dd55dedc4d50cb2f8ffa [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)
76}
77
78func runCcLibraryStaticTestCase(t *testing.T, tc bp2buildTestCase) {
79 runBp2BuildTestCase(t, registerCcLibraryStaticModuleTypes, tc)
80}
81
82func TestCcLibraryStaticSimple(t *testing.T) {
83 runCcLibraryStaticTestCase(t, bp2buildTestCase{
84 description: "cc_library_static test",
85 moduleTypeUnderTest: "cc_library_static",
86 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
87 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
88 filesystem: map[string]string{
89 // NOTE: include_dir headers *should not* appear in Bazel hdrs later (?)
90 "include_dir_1/include_dir_1_a.h": "",
91 "include_dir_1/include_dir_1_b.h": "",
92 "include_dir_2/include_dir_2_a.h": "",
93 "include_dir_2/include_dir_2_b.h": "",
94 // NOTE: local_include_dir headers *should not* appear in Bazel hdrs later (?)
95 "local_include_dir_1/local_include_dir_1_a.h": "",
96 "local_include_dir_1/local_include_dir_1_b.h": "",
97 "local_include_dir_2/local_include_dir_2_a.h": "",
98 "local_include_dir_2/local_include_dir_2_b.h": "",
99 // NOTE: export_include_dir headers *should* appear in Bazel hdrs later
100 "export_include_dir_1/export_include_dir_1_a.h": "",
101 "export_include_dir_1/export_include_dir_1_b.h": "",
102 "export_include_dir_2/export_include_dir_2_a.h": "",
103 "export_include_dir_2/export_include_dir_2_b.h": "",
104 // NOTE: Soong implicitly includes headers in the current directory
105 "implicit_include_1.h": "",
106 "implicit_include_2.h": "",
107 },
108 blueprint: soongCcLibraryStaticPreamble + `
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000109cc_library_headers {
110 name: "header_lib_1",
111 export_include_dirs: ["header_lib_1"],
112}
113
114cc_library_headers {
115 name: "header_lib_2",
116 export_include_dirs: ["header_lib_2"],
117}
118
119cc_library_static {
120 name: "static_lib_1",
121 srcs: ["static_lib_1.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000122}
123
124cc_library_static {
125 name: "static_lib_2",
126 srcs: ["static_lib_2.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000127}
128
129cc_library_static {
130 name: "whole_static_lib_1",
131 srcs: ["whole_static_lib_1.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000132}
133
134cc_library_static {
135 name: "whole_static_lib_2",
136 srcs: ["whole_static_lib_2.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000137}
138
139cc_library_static {
140 name: "foo_static",
141 srcs: [
142 "foo_static1.cc",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000143 "foo_static2.cc",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000144 ],
145 cflags: [
146 "-Dflag1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000147 "-Dflag2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000148 ],
149 static_libs: [
150 "static_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000151 "static_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000152 ],
153 whole_static_libs: [
154 "whole_static_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000155 "whole_static_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000156 ],
157 include_dirs: [
Jingwen Chened9c17d2021-04-13 07:14:55 +0000158 "include_dir_1",
159 "include_dir_2",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000160 ],
161 local_include_dirs: [
162 "local_include_dir_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000163 "local_include_dir_2",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000164 ],
165 export_include_dirs: [
Chris Parsonsd6358772021-05-18 18:35:24 -0400166 "export_include_dir_1",
167 "export_include_dir_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000168 ],
169 header_libs: [
170 "header_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000171 "header_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000172 ],
173
174 // TODO: Also support export_header_lib_headers
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000175}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200176 expectedBazelTargets: []string{`cc_library_static(
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000177 name = "foo_static",
178 copts = [
179 "-Dflag1",
180 "-Dflag2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000181 "-Iinclude_dir_1",
Chris Parsons484e50a2021-05-13 15:13:04 -0400182 "-I$(BINDIR)/include_dir_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000183 "-Iinclude_dir_2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400184 "-I$(BINDIR)/include_dir_2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000185 "-Ilocal_include_dir_1",
Chris Parsons484e50a2021-05-13 15:13:04 -0400186 "-I$(BINDIR)/local_include_dir_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000187 "-Ilocal_include_dir_2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400188 "-I$(BINDIR)/local_include_dir_2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000189 "-I.",
Chris Parsons484e50a2021-05-13 15:13:04 -0400190 "-I$(BINDIR)/.",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000191 ],
Chris Parsonsd6358772021-05-18 18:35:24 -0400192 implementation_deps = [
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000193 ":header_lib_1",
194 ":header_lib_2",
195 ":static_lib_1",
196 ":static_lib_2",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000197 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000198 includes = [
199 "export_include_dir_1",
200 "export_include_dir_2",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000201 ],
202 linkstatic = True,
203 srcs = [
204 "foo_static1.cc",
205 "foo_static2.cc",
206 ],
Chris Parsons08648312021-05-06 16:23:19 -0400207 whole_archive_deps = [
208 ":whole_static_lib_1",
209 ":whole_static_lib_2",
210 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000211)`, `cc_library_static(
212 name = "static_lib_1",
Chris Parsons484e50a2021-05-13 15:13:04 -0400213 copts = [
214 "-I.",
215 "-I$(BINDIR)/.",
216 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000217 linkstatic = True,
Jingwen Chen882bcc12021-04-27 05:54:20 +0000218 srcs = ["static_lib_1.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000219)`, `cc_library_static(
220 name = "static_lib_2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400221 copts = [
222 "-I.",
223 "-I$(BINDIR)/.",
224 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000225 linkstatic = True,
Jingwen Chen882bcc12021-04-27 05:54:20 +0000226 srcs = ["static_lib_2.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000227)`, `cc_library_static(
228 name = "whole_static_lib_1",
Chris Parsons484e50a2021-05-13 15:13:04 -0400229 copts = [
230 "-I.",
231 "-I$(BINDIR)/.",
232 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000233 linkstatic = True,
Jingwen Chen882bcc12021-04-27 05:54:20 +0000234 srcs = ["whole_static_lib_1.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000235)`, `cc_library_static(
236 name = "whole_static_lib_2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400237 copts = [
238 "-I.",
239 "-I$(BINDIR)/.",
240 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000241 linkstatic = True,
Jingwen Chen882bcc12021-04-27 05:54:20 +0000242 srcs = ["whole_static_lib_2.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000243)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200244 })
245}
246
247func TestCcLibraryStaticSubpackage(t *testing.T) {
248 runCcLibraryStaticTestCase(t, bp2buildTestCase{
249 description: "cc_library_static subpackage test",
250 moduleTypeUnderTest: "cc_library_static",
251 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
252 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
253 filesystem: map[string]string{
254 // subpackage with subdirectory
255 "subpackage/Android.bp": "",
256 "subpackage/subpackage_header.h": "",
257 "subpackage/subdirectory/subdirectory_header.h": "",
258 // subsubpackage with subdirectory
259 "subpackage/subsubpackage/Android.bp": "",
260 "subpackage/subsubpackage/subsubpackage_header.h": "",
261 "subpackage/subsubpackage/subdirectory/subdirectory_header.h": "",
262 // subsubsubpackage with subdirectory
263 "subpackage/subsubpackage/subsubsubpackage/Android.bp": "",
264 "subpackage/subsubpackage/subsubsubpackage/subsubsubpackage_header.h": "",
265 "subpackage/subsubpackage/subsubsubpackage/subdirectory/subdirectory_header.h": "",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000266 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200267 blueprint: soongCcLibraryStaticPreamble + `
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400268cc_library_static {
269 name: "foo_static",
270 srcs: [
271 ],
272 include_dirs: [
273 "subpackage",
274 ],
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400275}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200276 expectedBazelTargets: []string{`cc_library_static(
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400277 name = "foo_static",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000278 copts = [
279 "-Isubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400280 "-I$(BINDIR)/subpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000281 "-I.",
Chris Parsons484e50a2021-05-13 15:13:04 -0400282 "-I$(BINDIR)/.",
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400283 ],
284 linkstatic = True,
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400285)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200286 })
287}
288
289func TestCcLibraryStaticExportIncludeDir(t *testing.T) {
290 runCcLibraryStaticTestCase(t, bp2buildTestCase{
291 description: "cc_library_static export include dir",
292 moduleTypeUnderTest: "cc_library_static",
293 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
294 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
295 filesystem: map[string]string{
296 // subpackage with subdirectory
297 "subpackage/Android.bp": "",
298 "subpackage/subpackage_header.h": "",
299 "subpackage/subdirectory/subdirectory_header.h": "",
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400300 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200301 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000302cc_library_static {
303 name: "foo_static",
304 export_include_dirs: ["subpackage"],
305}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200306 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000307 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400308 copts = [
309 "-I.",
310 "-I$(BINDIR)/.",
311 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000312 includes = ["subpackage"],
313 linkstatic = True,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000314)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200315 })
316}
317
318func TestCcLibraryStaticExportSystemIncludeDir(t *testing.T) {
319 runCcLibraryStaticTestCase(t, bp2buildTestCase{
320 description: "cc_library_static export system include dir",
321 moduleTypeUnderTest: "cc_library_static",
322 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
323 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
324 filesystem: map[string]string{
325 // subpackage with subdirectory
326 "subpackage/Android.bp": "",
327 "subpackage/subpackage_header.h": "",
328 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000329 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200330 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000331cc_library_static {
332 name: "foo_static",
333 export_system_include_dirs: ["subpackage"],
334}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200335 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000336 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400337 copts = [
338 "-I.",
339 "-I$(BINDIR)/.",
340 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000341 includes = ["subpackage"],
342 linkstatic = True,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000343)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200344 })
345}
346
347func TestCcLibraryStaticManyIncludeDirs(t *testing.T) {
348 runCcLibraryStaticTestCase(t, bp2buildTestCase{
349 description: "cc_library_static include_dirs, local_include_dirs, export_include_dirs (b/183742505)",
350 moduleTypeUnderTest: "cc_library_static",
351 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
352 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
353 dir: "subpackage",
354 filesystem: map[string]string{
355 // subpackage with subdirectory
356 "subpackage/Android.bp": `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000357cc_library_static {
358 name: "foo_static",
359 // include_dirs are workspace/root relative
360 include_dirs: [
361 "subpackage/subsubpackage",
362 "subpackage2",
363 "subpackage3/subsubpackage"
364 ],
365 local_include_dirs: ["subsubpackage2"], // module dir relative
366 export_include_dirs: ["./exported_subsubpackage"], // module dir relative
367 include_build_directory: true,
368 bazel_module: { bp2build_available: true },
369}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200370 "subpackage/subsubpackage/header.h": "",
371 "subpackage/subsubpackage2/header.h": "",
372 "subpackage/exported_subsubpackage/header.h": "",
373 "subpackage2/header.h": "",
374 "subpackage3/subsubpackage/header.h": "",
375 },
376 blueprint: soongCcLibraryStaticPreamble,
377 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000378 name = "foo_static",
379 copts = [
380 "-Isubpackage/subsubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400381 "-I$(BINDIR)/subpackage/subsubpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000382 "-Isubpackage2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400383 "-I$(BINDIR)/subpackage2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000384 "-Isubpackage3/subsubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400385 "-I$(BINDIR)/subpackage3/subsubpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000386 "-Isubpackage/subsubpackage2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400387 "-I$(BINDIR)/subpackage/subsubpackage2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000388 "-Isubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400389 "-I$(BINDIR)/subpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000390 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000391 includes = ["./exported_subsubpackage"],
392 linkstatic = True,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000393)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200394 })
395}
396
397func TestCcLibraryStaticIncludeBuildDirectoryDisabled(t *testing.T) {
398 runCcLibraryStaticTestCase(t, bp2buildTestCase{
399 description: "cc_library_static include_build_directory disabled",
400 moduleTypeUnderTest: "cc_library_static",
401 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
402 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
403 filesystem: map[string]string{
404 // subpackage with subdirectory
405 "subpackage/Android.bp": "",
406 "subpackage/subpackage_header.h": "",
407 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000408 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200409 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000410cc_library_static {
411 name: "foo_static",
412 include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended
413 local_include_dirs: ["subpackage2"],
414 include_build_directory: false,
415}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200416 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000417 name = "foo_static",
418 copts = [
419 "-Isubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400420 "-I$(BINDIR)/subpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000421 "-Isubpackage2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400422 "-I$(BINDIR)/subpackage2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000423 ],
424 linkstatic = True,
425)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200426 })
427}
428
429func TestCcLibraryStaticIncludeBuildDirectoryEnabled(t *testing.T) {
430 runCcLibraryStaticTestCase(t, bp2buildTestCase{
431 description: "cc_library_static include_build_directory enabled",
432 moduleTypeUnderTest: "cc_library_static",
433 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
434 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
435 filesystem: map[string]string{
436 // subpackage with subdirectory
437 "subpackage/Android.bp": "",
438 "subpackage/subpackage_header.h": "",
439 "subpackage2/Android.bp": "",
440 "subpackage2/subpackage2_header.h": "",
441 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000442 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200443 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000444cc_library_static {
445 name: "foo_static",
446 include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended
447 local_include_dirs: ["subpackage2"],
448 include_build_directory: true,
449}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200450 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000451 name = "foo_static",
452 copts = [
453 "-Isubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400454 "-I$(BINDIR)/subpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000455 "-Isubpackage2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400456 "-I$(BINDIR)/subpackage2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000457 "-I.",
Chris Parsons484e50a2021-05-13 15:13:04 -0400458 "-I$(BINDIR)/.",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000459 ],
460 linkstatic = True,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000461)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200462 })
463}
464
465func TestCcLibraryStaticArchSpecificStaticLib(t *testing.T) {
466 runCcLibraryStaticTestCase(t, bp2buildTestCase{
467 description: "cc_library_static arch-specific static_libs",
468 moduleTypeUnderTest: "cc_library_static",
469 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
470 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
471 depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
472 filesystem: map[string]string{},
473 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000474cc_library_static { name: "static_dep" }
475cc_library_static { name: "static_dep2" }
476cc_library_static {
477 name: "foo_static",
478 arch: { arm64: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } },
479}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200480 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000481 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400482 copts = [
483 "-I.",
484 "-I$(BINDIR)/.",
485 ],
Chris Parsonsd6358772021-05-18 18:35:24 -0400486 implementation_deps = select({
Chris Parsons08648312021-05-06 16:23:19 -0400487 "//build/bazel/platforms/arch:arm64": [":static_dep"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000488 "//conditions:default": [],
489 }),
490 linkstatic = True,
Chris Parsons08648312021-05-06 16:23:19 -0400491 whole_archive_deps = select({
492 "//build/bazel/platforms/arch:arm64": [":static_dep2"],
493 "//conditions:default": [],
494 }),
Jingwen Chened9c17d2021-04-13 07:14:55 +0000495)`, `cc_library_static(
496 name = "static_dep",
Chris Parsons484e50a2021-05-13 15:13:04 -0400497 copts = [
498 "-I.",
499 "-I$(BINDIR)/.",
500 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000501 linkstatic = True,
502)`, `cc_library_static(
503 name = "static_dep2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400504 copts = [
505 "-I.",
506 "-I$(BINDIR)/.",
507 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000508 linkstatic = True,
509)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200510 })
511}
512
513func TestCcLibraryStaticOsSpecificStaticLib(t *testing.T) {
514 runCcLibraryStaticTestCase(t, bp2buildTestCase{
515 description: "cc_library_static os-specific static_libs",
516 moduleTypeUnderTest: "cc_library_static",
517 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
518 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
519 depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
520 filesystem: map[string]string{},
521 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000522cc_library_static { name: "static_dep" }
523cc_library_static { name: "static_dep2" }
524cc_library_static {
525 name: "foo_static",
526 target: { android: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } },
527}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200528 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000529 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400530 copts = [
531 "-I.",
532 "-I$(BINDIR)/.",
533 ],
Chris Parsonsd6358772021-05-18 18:35:24 -0400534 implementation_deps = select({
Chris Parsons08648312021-05-06 16:23:19 -0400535 "//build/bazel/platforms/os:android": [":static_dep"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000536 "//conditions:default": [],
537 }),
538 linkstatic = True,
Chris Parsons08648312021-05-06 16:23:19 -0400539 whole_archive_deps = select({
540 "//build/bazel/platforms/os:android": [":static_dep2"],
541 "//conditions:default": [],
542 }),
Jingwen Chened9c17d2021-04-13 07:14:55 +0000543)`, `cc_library_static(
544 name = "static_dep",
Chris Parsons484e50a2021-05-13 15:13:04 -0400545 copts = [
546 "-I.",
547 "-I$(BINDIR)/.",
548 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000549 linkstatic = True,
550)`, `cc_library_static(
551 name = "static_dep2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400552 copts = [
553 "-I.",
554 "-I$(BINDIR)/.",
555 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000556 linkstatic = True,
557)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200558 })
559}
560
561func TestCcLibraryStaticBaseArchOsSpecificStaticLib(t *testing.T) {
562 runCcLibraryStaticTestCase(t, bp2buildTestCase{
563 description: "cc_library_static base, arch and os-specific static_libs",
564 moduleTypeUnderTest: "cc_library_static",
565 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
566 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
567 depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
568 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,
634 depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
635 filesystem: map[string]string{
636 "common.c": "",
637 "foo-a.c": "",
638 "foo-excluded.c": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000639 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200640 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000641cc_library_static {
642 name: "foo_static",
643 srcs: ["common.c", "foo-*.c"],
644 exclude_srcs: ["foo-excluded.c"],
645}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200646 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000647 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400648 copts = [
649 "-I.",
650 "-I$(BINDIR)/.",
651 ],
Jingwen Chene32e9e02021-04-23 09:17:24 +0000652 linkstatic = True,
653 srcs = [
654 "common.c",
655 "foo-a.c",
656 ],
657)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200658 })
659}
660
661func TestCcLibraryStaticOneArchSrcs(t *testing.T) {
662 runCcLibraryStaticTestCase(t, bp2buildTestCase{
663 description: "cc_library_static one arch specific srcs",
664 moduleTypeUnderTest: "cc_library_static",
665 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
666 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
667 depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
668 filesystem: map[string]string{
669 "common.c": "",
670 "foo-arm.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000671 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200672 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000673cc_library_static {
674 name: "foo_static",
675 srcs: ["common.c"],
676 arch: { arm: { srcs: ["foo-arm.c"] } }
677}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200678 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000679 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400680 copts = [
681 "-I.",
682 "-I$(BINDIR)/.",
683 ],
Jingwen Chene32e9e02021-04-23 09:17:24 +0000684 linkstatic = True,
685 srcs = ["common.c"] + select({
686 "//build/bazel/platforms/arch:arm": ["foo-arm.c"],
687 "//conditions:default": [],
688 }),
689)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200690 })
691}
692
693func TestCcLibraryStaticOneArchSrcsExcludeSrcs(t *testing.T) {
694 runCcLibraryStaticTestCase(t, bp2buildTestCase{
695 description: "cc_library_static one arch specific srcs and exclude_srcs",
696 moduleTypeUnderTest: "cc_library_static",
697 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
698 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
699 depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
700 filesystem: map[string]string{
701 "common.c": "",
702 "for-arm.c": "",
703 "not-for-arm.c": "",
704 "not-for-anything.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000705 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200706 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000707cc_library_static {
708 name: "foo_static",
709 srcs: ["common.c", "not-for-*.c"],
710 exclude_srcs: ["not-for-anything.c"],
711 arch: {
712 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
713 },
714}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200715 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000716 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400717 copts = [
718 "-I.",
719 "-I$(BINDIR)/.",
720 ],
Jingwen Chene32e9e02021-04-23 09:17:24 +0000721 linkstatic = True,
722 srcs = ["common.c"] + select({
723 "//build/bazel/platforms/arch:arm": ["for-arm.c"],
724 "//conditions:default": ["not-for-arm.c"],
725 }),
726)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200727 })
728}
729
730func TestCcLibraryStaticTwoArchExcludeSrcs(t *testing.T) {
731 runCcLibraryStaticTestCase(t, bp2buildTestCase{
732 description: "cc_library_static arch specific exclude_srcs for 2 architectures",
733 moduleTypeUnderTest: "cc_library_static",
734 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
735 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
736 depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
737 filesystem: map[string]string{
738 "common.c": "",
739 "for-arm.c": "",
740 "for-x86.c": "",
741 "not-for-arm.c": "",
742 "not-for-x86.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000743 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200744 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000745cc_library_static {
746 name: "foo_static",
747 srcs: ["common.c", "not-for-*.c"],
748 exclude_srcs: ["not-for-everything.c"],
749 arch: {
750 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
751 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
752 },
753} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200754 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000755 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400756 copts = [
757 "-I.",
758 "-I$(BINDIR)/.",
759 ],
Jingwen Chene32e9e02021-04-23 09:17:24 +0000760 linkstatic = True,
761 srcs = ["common.c"] + select({
762 "//build/bazel/platforms/arch:arm": [
763 "for-arm.c",
764 "not-for-x86.c",
765 ],
766 "//build/bazel/platforms/arch:x86": [
767 "for-x86.c",
768 "not-for-arm.c",
769 ],
770 "//conditions:default": [
771 "not-for-arm.c",
772 "not-for-x86.c",
773 ],
774 }),
775)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200776 })
777}
778func TestCcLibraryStaticFourArchExcludeSrcs(t *testing.T) {
779 runCcLibraryStaticTestCase(t, bp2buildTestCase{
780 description: "cc_library_static arch specific exclude_srcs for 4 architectures",
781 moduleTypeUnderTest: "cc_library_static",
782 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
783 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
784 depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
785 filesystem: map[string]string{
786 "common.c": "",
787 "for-arm.c": "",
788 "for-arm64.c": "",
789 "for-x86.c": "",
790 "for-x86_64.c": "",
791 "not-for-arm.c": "",
792 "not-for-arm64.c": "",
793 "not-for-x86.c": "",
794 "not-for-x86_64.c": "",
795 "not-for-everything.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000796 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200797 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000798cc_library_static {
799 name: "foo_static",
800 srcs: ["common.c", "not-for-*.c"],
801 exclude_srcs: ["not-for-everything.c"],
802 arch: {
803 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
804 arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] },
805 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
806 x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] },
807 },
808} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200809 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000810 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400811 copts = [
812 "-I.",
813 "-I$(BINDIR)/.",
814 ],
Jingwen Chene32e9e02021-04-23 09:17:24 +0000815 linkstatic = True,
816 srcs = ["common.c"] + select({
817 "//build/bazel/platforms/arch:arm": [
818 "for-arm.c",
819 "not-for-arm64.c",
820 "not-for-x86.c",
821 "not-for-x86_64.c",
822 ],
823 "//build/bazel/platforms/arch:arm64": [
824 "for-arm64.c",
825 "not-for-arm.c",
826 "not-for-x86.c",
827 "not-for-x86_64.c",
828 ],
829 "//build/bazel/platforms/arch:x86": [
830 "for-x86.c",
831 "not-for-arm.c",
832 "not-for-arm64.c",
833 "not-for-x86_64.c",
834 ],
835 "//build/bazel/platforms/arch:x86_64": [
836 "for-x86_64.c",
837 "not-for-arm.c",
838 "not-for-arm64.c",
839 "not-for-x86.c",
840 ],
841 "//conditions:default": [
842 "not-for-arm.c",
843 "not-for-arm64.c",
844 "not-for-x86.c",
845 "not-for-x86_64.c",
846 ],
847 }),
848)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200849 })
850}
851
852func TestCcLibraryStaticMultipleDepSameName(t *testing.T) {
853 runCcLibraryStaticTestCase(t, bp2buildTestCase{
854 description: "cc_library_static multiple dep same name panic",
855 moduleTypeUnderTest: "cc_library_static",
856 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
857 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
858 depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
859 filesystem: map[string]string{},
860 blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer2b50ce62021-04-26 15:47:28 -0400861cc_library_static { name: "static_dep" }
862cc_library_static {
863 name: "foo_static",
Chris Parsons08648312021-05-06 16:23:19 -0400864 static_libs: ["static_dep", "static_dep"],
Liz Kammer2b50ce62021-04-26 15:47:28 -0400865}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200866 expectedBazelTargets: []string{`cc_library_static(
Liz Kammer2b50ce62021-04-26 15:47:28 -0400867 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400868 copts = [
869 "-I.",
870 "-I$(BINDIR)/.",
871 ],
Chris Parsonsd6358772021-05-18 18:35:24 -0400872 implementation_deps = [":static_dep"],
Liz Kammer2b50ce62021-04-26 15:47:28 -0400873 linkstatic = True,
874)`, `cc_library_static(
875 name = "static_dep",
Chris Parsons484e50a2021-05-13 15:13:04 -0400876 copts = [
877 "-I.",
878 "-I$(BINDIR)/.",
879 ],
Liz Kammer2b50ce62021-04-26 15:47:28 -0400880 linkstatic = True,
881)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200882 })
883}
884
885func TestCcLibraryStaticOneMultilibSrcsExcludeSrcs(t *testing.T) {
886 runCcLibraryStaticTestCase(t, bp2buildTestCase{
887 description: "cc_library_static 1 multilib srcs and exclude_srcs",
888 moduleTypeUnderTest: "cc_library_static",
889 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
890 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
891 depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
892 filesystem: map[string]string{
893 "common.c": "",
894 "for-lib32.c": "",
895 "not-for-lib32.c": "",
Liz Kammer2b50ce62021-04-26 15:47:28 -0400896 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200897 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -0400898cc_library_static {
899 name: "foo_static",
900 srcs: ["common.c", "not-for-*.c"],
901 multilib: {
902 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
903 },
904} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200905 expectedBazelTargets: []string{`cc_library_static(
Chris Parsonsc424b762021-04-29 18:06:50 -0400906 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400907 copts = [
908 "-I.",
909 "-I$(BINDIR)/.",
910 ],
Chris Parsonsc424b762021-04-29 18:06:50 -0400911 linkstatic = True,
912 srcs = ["common.c"] + select({
913 "//build/bazel/platforms/arch:arm": ["for-lib32.c"],
914 "//build/bazel/platforms/arch:x86": ["for-lib32.c"],
915 "//conditions:default": ["not-for-lib32.c"],
916 }),
917)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200918 })
919}
920
921func TestCcLibraryStaticTwoMultilibSrcsExcludeSrcs(t *testing.T) {
922 runCcLibraryStaticTestCase(t, bp2buildTestCase{
923 description: "cc_library_static 2 multilib srcs and exclude_srcs",
924 moduleTypeUnderTest: "cc_library_static",
925 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
926 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
927 depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
928 filesystem: map[string]string{
929 "common.c": "",
930 "for-lib32.c": "",
931 "for-lib64.c": "",
932 "not-for-lib32.c": "",
933 "not-for-lib64.c": "",
Chris Parsonsc424b762021-04-29 18:06:50 -0400934 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200935 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -0400936cc_library_static {
937 name: "foo_static2",
938 srcs: ["common.c", "not-for-*.c"],
939 multilib: {
940 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
941 lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] },
942 },
943} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200944 expectedBazelTargets: []string{`cc_library_static(
Chris Parsonsc424b762021-04-29 18:06:50 -0400945 name = "foo_static2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400946 copts = [
947 "-I.",
948 "-I$(BINDIR)/.",
949 ],
Chris Parsonsc424b762021-04-29 18:06:50 -0400950 linkstatic = True,
951 srcs = ["common.c"] + select({
952 "//build/bazel/platforms/arch:arm": [
953 "for-lib32.c",
954 "not-for-lib64.c",
955 ],
956 "//build/bazel/platforms/arch:arm64": [
957 "for-lib64.c",
958 "not-for-lib32.c",
959 ],
960 "//build/bazel/platforms/arch:x86": [
961 "for-lib32.c",
962 "not-for-lib64.c",
963 ],
964 "//build/bazel/platforms/arch:x86_64": [
965 "for-lib64.c",
966 "not-for-lib32.c",
967 ],
968 "//conditions:default": [
969 "not-for-lib32.c",
970 "not-for-lib64.c",
971 ],
972 }),
973)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200974 })
975}
976
977func TestCcLibrarySTaticArchMultilibSrcsExcludeSrcs(t *testing.T) {
978 runCcLibraryStaticTestCase(t, bp2buildTestCase{
979 description: "cc_library_static arch and multilib srcs and exclude_srcs",
980 moduleTypeUnderTest: "cc_library_static",
981 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
982 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
983 depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
984 filesystem: map[string]string{
985 "common.c": "",
986 "for-arm.c": "",
987 "for-arm64.c": "",
988 "for-x86.c": "",
989 "for-x86_64.c": "",
990 "for-lib32.c": "",
991 "for-lib64.c": "",
992 "not-for-arm.c": "",
993 "not-for-arm64.c": "",
994 "not-for-x86.c": "",
995 "not-for-x86_64.c": "",
996 "not-for-lib32.c": "",
997 "not-for-lib64.c": "",
998 "not-for-everything.c": "",
Chris Parsonsc424b762021-04-29 18:06:50 -0400999 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001000 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -04001001cc_library_static {
1002 name: "foo_static3",
1003 srcs: ["common.c", "not-for-*.c"],
1004 exclude_srcs: ["not-for-everything.c"],
1005 arch: {
1006 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
1007 arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] },
1008 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
1009 x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] },
1010 },
1011 multilib: {
1012 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
1013 lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] },
1014 },
1015}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001016 expectedBazelTargets: []string{`cc_library_static(
Chris Parsonsc424b762021-04-29 18:06:50 -04001017 name = "foo_static3",
Chris Parsons484e50a2021-05-13 15:13:04 -04001018 copts = [
1019 "-I.",
1020 "-I$(BINDIR)/.",
1021 ],
Chris Parsonsc424b762021-04-29 18:06:50 -04001022 linkstatic = True,
1023 srcs = ["common.c"] + select({
1024 "//build/bazel/platforms/arch:arm": [
1025 "for-arm.c",
1026 "for-lib32.c",
1027 "not-for-arm64.c",
1028 "not-for-lib64.c",
1029 "not-for-x86.c",
1030 "not-for-x86_64.c",
1031 ],
1032 "//build/bazel/platforms/arch:arm64": [
1033 "for-arm64.c",
1034 "for-lib64.c",
1035 "not-for-arm.c",
1036 "not-for-lib32.c",
1037 "not-for-x86.c",
1038 "not-for-x86_64.c",
1039 ],
1040 "//build/bazel/platforms/arch:x86": [
1041 "for-lib32.c",
1042 "for-x86.c",
1043 "not-for-arm.c",
1044 "not-for-arm64.c",
1045 "not-for-lib64.c",
1046 "not-for-x86_64.c",
1047 ],
1048 "//build/bazel/platforms/arch:x86_64": [
1049 "for-lib64.c",
1050 "for-x86_64.c",
1051 "not-for-arm.c",
1052 "not-for-arm64.c",
1053 "not-for-lib32.c",
1054 "not-for-x86.c",
1055 ],
1056 "//conditions:default": [
1057 "not-for-arm.c",
1058 "not-for-arm64.c",
1059 "not-for-lib32.c",
1060 "not-for-lib64.c",
1061 "not-for-x86.c",
1062 "not-for-x86_64.c",
1063 ],
1064 }),
1065)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001066 })
1067}
1068
1069func TestCcLibraryStaticArchSrcsExcludeSrcsGeneratedFiles(t *testing.T) {
1070 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1071 description: "cc_library_static arch srcs/exclude_srcs with generated files",
1072 moduleTypeUnderTest: "cc_library_static",
1073 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1074 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1075 depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
1076 filesystem: map[string]string{
1077 "common.c": "",
1078 "for-x86.c": "",
1079 "not-for-x86.c": "",
1080 "not-for-everything.c": "",
1081 "dep/Android.bp": `
Chris Parsons484e50a2021-05-13 15:13:04 -04001082genrule {
1083 name: "generated_src_other_pkg",
1084 out: ["generated_src_other_pkg.cpp"],
1085 cmd: "nothing to see here",
1086}
1087
1088genrule {
1089 name: "generated_hdr_other_pkg",
1090 out: ["generated_hdr_other_pkg.cpp"],
1091 cmd: "nothing to see here",
1092}
1093
1094genrule {
1095 name: "generated_hdr_other_pkg_x86",
1096 out: ["generated_hdr_other_pkg_x86.cpp"],
1097 cmd: "nothing to see here",
1098}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001099 },
1100 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsons484e50a2021-05-13 15:13:04 -04001101genrule {
1102 name: "generated_src",
1103 out: ["generated_src.cpp"],
1104 cmd: "nothing to see here",
1105}
1106
1107genrule {
1108 name: "generated_src_x86",
1109 out: ["generated_src_x86.cpp"],
1110 cmd: "nothing to see here",
1111}
1112
1113genrule {
1114 name: "generated_hdr",
1115 out: ["generated_hdr.h"],
1116 cmd: "nothing to see here",
1117}
1118
1119cc_library_static {
1120 name: "foo_static3",
1121 srcs: ["common.c", "not-for-*.c"],
1122 exclude_srcs: ["not-for-everything.c"],
1123 generated_sources: ["generated_src", "generated_src_other_pkg"],
1124 generated_headers: ["generated_hdr", "generated_hdr_other_pkg"],
1125 arch: {
1126 x86: {
1127 srcs: ["for-x86.c"],
1128 exclude_srcs: ["not-for-x86.c"],
1129 generated_sources: ["generated_src_x86"],
1130 generated_headers: ["generated_hdr_other_pkg_x86"],
1131 },
1132 },
1133}
1134`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001135 expectedBazelTargets: []string{`cc_library_static(
Chris Parsons484e50a2021-05-13 15:13:04 -04001136 name = "foo_static3",
1137 copts = [
1138 "-I.",
1139 "-I$(BINDIR)/.",
1140 ],
1141 linkstatic = True,
1142 srcs = [
1143 "//dep:generated_hdr_other_pkg",
1144 "//dep:generated_src_other_pkg",
1145 ":generated_hdr",
1146 ":generated_src",
1147 "common.c",
1148 ] + select({
1149 "//build/bazel/platforms/arch:x86": [
1150 "//dep:generated_hdr_other_pkg_x86",
1151 ":generated_src_x86",
1152 "for-x86.c",
1153 ],
1154 "//conditions:default": ["not-for-x86.c"],
1155 }),
1156)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001157 })
Rupert Shuttleworth095081c2021-03-25 09:06:03 +00001158}
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001159
1160func TestCcLibraryStaticProductVariableSelects(t *testing.T) {
1161 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1162 description: "cc_library_static product variable selects",
1163 moduleTypeUnderTest: "cc_library_static",
1164 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1165 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1166 depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
1167 filesystem: map[string]string{},
1168 blueprint: soongCcLibraryStaticPreamble + `
1169cc_library_static {
1170 name: "foo_static",
1171 srcs: ["common.c"],
1172 product_variables: {
1173 malloc_not_svelte: {
1174 cflags: ["-Wmalloc_not_svelte"],
1175 },
1176 malloc_zero_contents: {
1177 cflags: ["-Wmalloc_zero_contents"],
1178 },
1179 binder32bit: {
1180 cflags: ["-Wbinder32bit"],
1181 },
1182 },
1183} `,
1184 expectedBazelTargets: []string{`cc_library_static(
1185 name = "foo_static",
1186 copts = [
1187 "-I.",
1188 "-I$(BINDIR)/.",
1189 ] + select({
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001190 "//build/bazel/product_variables:binder32bit": ["-Wbinder32bit"],
1191 "//conditions:default": [],
1192 }) + select({
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001193 "//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"],
1194 "//conditions:default": [],
1195 }) + select({
1196 "//build/bazel/product_variables:malloc_zero_contents": ["-Wmalloc_zero_contents"],
1197 "//conditions:default": [],
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001198 }),
1199 linkstatic = True,
1200 srcs = ["common.c"],
1201)`},
1202 })
1203}
1204
1205func TestCcLibraryStaticProductVariableArchSpecificSelects(t *testing.T) {
1206 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1207 description: "cc_library_static arch-specific product variable selects",
1208 moduleTypeUnderTest: "cc_library_static",
1209 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1210 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1211 depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
1212 filesystem: map[string]string{},
1213 blueprint: soongCcLibraryStaticPreamble + `
1214cc_library_static {
1215 name: "foo_static",
1216 srcs: ["common.c"],
1217 product_variables: {
1218 malloc_not_svelte: {
1219 cflags: ["-Wmalloc_not_svelte"],
1220 },
1221 },
1222 arch: {
1223 arm64: {
1224 product_variables: {
1225 malloc_not_svelte: {
1226 cflags: ["-Warm64_malloc_not_svelte"],
1227 },
1228 },
1229 },
1230 },
1231 multilib: {
1232 lib32: {
1233 product_variables: {
1234 malloc_not_svelte: {
1235 cflags: ["-Wlib32_malloc_not_svelte"],
1236 },
1237 },
1238 },
1239 },
1240 target: {
1241 android: {
1242 product_variables: {
1243 malloc_not_svelte: {
1244 cflags: ["-Wandroid_malloc_not_svelte"],
1245 },
1246 },
1247 }
1248 },
1249} `,
1250 expectedBazelTargets: []string{`cc_library_static(
1251 name = "foo_static",
1252 copts = [
1253 "-I.",
1254 "-I$(BINDIR)/.",
1255 ] + select({
1256 "//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"],
1257 "//conditions:default": [],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001258 }) + select({
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001259 "//build/bazel/product_variables:malloc_not_svelte-android": ["-Wandroid_malloc_not_svelte"],
1260 "//conditions:default": [],
1261 }) + select({
1262 "//build/bazel/product_variables:malloc_not_svelte-arm": ["-Wlib32_malloc_not_svelte"],
1263 "//conditions:default": [],
1264 }) + select({
1265 "//build/bazel/product_variables:malloc_not_svelte-arm64": ["-Warm64_malloc_not_svelte"],
1266 "//conditions:default": [],
1267 }) + select({
1268 "//build/bazel/product_variables:malloc_not_svelte-x86": ["-Wlib32_malloc_not_svelte"],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001269 "//conditions:default": [],
1270 }),
1271 linkstatic = True,
1272 srcs = ["common.c"],
1273)`},
1274 })
1275}