blob: 1dc6713de6bf1b8865d1e6e775f7b3b842f823e3 [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) {
Liz Kammere4982e82021-05-25 10:39:35 -040079 t.Helper()
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +020080 runBp2BuildTestCase(t, registerCcLibraryStaticModuleTypes, tc)
81}
82
83func TestCcLibraryStaticSimple(t *testing.T) {
84 runCcLibraryStaticTestCase(t, bp2buildTestCase{
85 description: "cc_library_static test",
86 moduleTypeUnderTest: "cc_library_static",
87 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
88 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
89 filesystem: map[string]string{
90 // NOTE: include_dir headers *should not* appear in Bazel hdrs later (?)
91 "include_dir_1/include_dir_1_a.h": "",
92 "include_dir_1/include_dir_1_b.h": "",
93 "include_dir_2/include_dir_2_a.h": "",
94 "include_dir_2/include_dir_2_b.h": "",
95 // NOTE: local_include_dir headers *should not* appear in Bazel hdrs later (?)
96 "local_include_dir_1/local_include_dir_1_a.h": "",
97 "local_include_dir_1/local_include_dir_1_b.h": "",
98 "local_include_dir_2/local_include_dir_2_a.h": "",
99 "local_include_dir_2/local_include_dir_2_b.h": "",
100 // NOTE: export_include_dir headers *should* appear in Bazel hdrs later
101 "export_include_dir_1/export_include_dir_1_a.h": "",
102 "export_include_dir_1/export_include_dir_1_b.h": "",
103 "export_include_dir_2/export_include_dir_2_a.h": "",
104 "export_include_dir_2/export_include_dir_2_b.h": "",
105 // NOTE: Soong implicitly includes headers in the current directory
106 "implicit_include_1.h": "",
107 "implicit_include_2.h": "",
108 },
109 blueprint: soongCcLibraryStaticPreamble + `
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000110cc_library_headers {
111 name: "header_lib_1",
112 export_include_dirs: ["header_lib_1"],
113}
114
115cc_library_headers {
116 name: "header_lib_2",
117 export_include_dirs: ["header_lib_2"],
118}
119
120cc_library_static {
121 name: "static_lib_1",
122 srcs: ["static_lib_1.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000123}
124
125cc_library_static {
126 name: "static_lib_2",
127 srcs: ["static_lib_2.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000128}
129
130cc_library_static {
131 name: "whole_static_lib_1",
132 srcs: ["whole_static_lib_1.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000133}
134
135cc_library_static {
136 name: "whole_static_lib_2",
137 srcs: ["whole_static_lib_2.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000138}
139
140cc_library_static {
141 name: "foo_static",
142 srcs: [
143 "foo_static1.cc",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000144 "foo_static2.cc",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000145 ],
146 cflags: [
147 "-Dflag1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000148 "-Dflag2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000149 ],
150 static_libs: [
151 "static_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000152 "static_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000153 ],
154 whole_static_libs: [
155 "whole_static_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000156 "whole_static_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000157 ],
158 include_dirs: [
Jingwen Chened9c17d2021-04-13 07:14:55 +0000159 "include_dir_1",
160 "include_dir_2",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000161 ],
162 local_include_dirs: [
163 "local_include_dir_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000164 "local_include_dir_2",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000165 ],
166 export_include_dirs: [
Chris Parsonsd6358772021-05-18 18:35:24 -0400167 "export_include_dir_1",
168 "export_include_dir_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000169 ],
170 header_libs: [
171 "header_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000172 "header_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000173 ],
174
175 // TODO: Also support export_header_lib_headers
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000176}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200177 expectedBazelTargets: []string{`cc_library_static(
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000178 name = "foo_static",
179 copts = [
180 "-Dflag1",
181 "-Dflag2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000182 "-Iinclude_dir_1",
Chris Parsons484e50a2021-05-13 15:13:04 -0400183 "-I$(BINDIR)/include_dir_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000184 "-Iinclude_dir_2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400185 "-I$(BINDIR)/include_dir_2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000186 "-Ilocal_include_dir_1",
Chris Parsons484e50a2021-05-13 15:13:04 -0400187 "-I$(BINDIR)/local_include_dir_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000188 "-Ilocal_include_dir_2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400189 "-I$(BINDIR)/local_include_dir_2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000190 "-I.",
Chris Parsons484e50a2021-05-13 15:13:04 -0400191 "-I$(BINDIR)/.",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000192 ],
Chris Parsonsd6358772021-05-18 18:35:24 -0400193 implementation_deps = [
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000194 ":header_lib_1",
195 ":header_lib_2",
196 ":static_lib_1",
197 ":static_lib_2",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000198 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000199 includes = [
200 "export_include_dir_1",
201 "export_include_dir_2",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000202 ],
203 linkstatic = True,
204 srcs = [
205 "foo_static1.cc",
206 "foo_static2.cc",
207 ],
Chris Parsons08648312021-05-06 16:23:19 -0400208 whole_archive_deps = [
209 ":whole_static_lib_1",
210 ":whole_static_lib_2",
211 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000212)`, `cc_library_static(
213 name = "static_lib_1",
Chris Parsons484e50a2021-05-13 15:13:04 -0400214 copts = [
215 "-I.",
216 "-I$(BINDIR)/.",
217 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000218 linkstatic = True,
Jingwen Chen882bcc12021-04-27 05:54:20 +0000219 srcs = ["static_lib_1.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000220)`, `cc_library_static(
221 name = "static_lib_2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400222 copts = [
223 "-I.",
224 "-I$(BINDIR)/.",
225 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000226 linkstatic = True,
Jingwen Chen882bcc12021-04-27 05:54:20 +0000227 srcs = ["static_lib_2.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000228)`, `cc_library_static(
229 name = "whole_static_lib_1",
Chris Parsons484e50a2021-05-13 15:13:04 -0400230 copts = [
231 "-I.",
232 "-I$(BINDIR)/.",
233 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000234 linkstatic = True,
Jingwen Chen882bcc12021-04-27 05:54:20 +0000235 srcs = ["whole_static_lib_1.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000236)`, `cc_library_static(
237 name = "whole_static_lib_2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400238 copts = [
239 "-I.",
240 "-I$(BINDIR)/.",
241 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000242 linkstatic = True,
Jingwen Chen882bcc12021-04-27 05:54:20 +0000243 srcs = ["whole_static_lib_2.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000244)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200245 })
246}
247
248func TestCcLibraryStaticSubpackage(t *testing.T) {
249 runCcLibraryStaticTestCase(t, bp2buildTestCase{
250 description: "cc_library_static subpackage test",
251 moduleTypeUnderTest: "cc_library_static",
252 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
253 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
254 filesystem: map[string]string{
255 // subpackage with subdirectory
256 "subpackage/Android.bp": "",
257 "subpackage/subpackage_header.h": "",
258 "subpackage/subdirectory/subdirectory_header.h": "",
259 // subsubpackage with subdirectory
260 "subpackage/subsubpackage/Android.bp": "",
261 "subpackage/subsubpackage/subsubpackage_header.h": "",
262 "subpackage/subsubpackage/subdirectory/subdirectory_header.h": "",
263 // subsubsubpackage with subdirectory
264 "subpackage/subsubpackage/subsubsubpackage/Android.bp": "",
265 "subpackage/subsubpackage/subsubsubpackage/subsubsubpackage_header.h": "",
266 "subpackage/subsubpackage/subsubsubpackage/subdirectory/subdirectory_header.h": "",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000267 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200268 blueprint: soongCcLibraryStaticPreamble + `
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400269cc_library_static {
270 name: "foo_static",
271 srcs: [
272 ],
273 include_dirs: [
274 "subpackage",
275 ],
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400276}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200277 expectedBazelTargets: []string{`cc_library_static(
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400278 name = "foo_static",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000279 copts = [
280 "-Isubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400281 "-I$(BINDIR)/subpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000282 "-I.",
Chris Parsons484e50a2021-05-13 15:13:04 -0400283 "-I$(BINDIR)/.",
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400284 ],
285 linkstatic = True,
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400286)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200287 })
288}
289
290func TestCcLibraryStaticExportIncludeDir(t *testing.T) {
291 runCcLibraryStaticTestCase(t, bp2buildTestCase{
292 description: "cc_library_static export include dir",
293 moduleTypeUnderTest: "cc_library_static",
294 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
295 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
296 filesystem: map[string]string{
297 // subpackage with subdirectory
298 "subpackage/Android.bp": "",
299 "subpackage/subpackage_header.h": "",
300 "subpackage/subdirectory/subdirectory_header.h": "",
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400301 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200302 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000303cc_library_static {
304 name: "foo_static",
305 export_include_dirs: ["subpackage"],
306}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200307 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000308 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400309 copts = [
310 "-I.",
311 "-I$(BINDIR)/.",
312 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000313 includes = ["subpackage"],
314 linkstatic = True,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000315)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200316 })
317}
318
319func TestCcLibraryStaticExportSystemIncludeDir(t *testing.T) {
320 runCcLibraryStaticTestCase(t, bp2buildTestCase{
321 description: "cc_library_static export system include dir",
322 moduleTypeUnderTest: "cc_library_static",
323 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
324 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
325 filesystem: map[string]string{
326 // subpackage with subdirectory
327 "subpackage/Android.bp": "",
328 "subpackage/subpackage_header.h": "",
329 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000330 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200331 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000332cc_library_static {
333 name: "foo_static",
334 export_system_include_dirs: ["subpackage"],
335}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200336 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000337 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400338 copts = [
339 "-I.",
340 "-I$(BINDIR)/.",
341 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000342 includes = ["subpackage"],
343 linkstatic = True,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000344)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200345 })
346}
347
348func TestCcLibraryStaticManyIncludeDirs(t *testing.T) {
349 runCcLibraryStaticTestCase(t, bp2buildTestCase{
350 description: "cc_library_static include_dirs, local_include_dirs, export_include_dirs (b/183742505)",
351 moduleTypeUnderTest: "cc_library_static",
352 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
353 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
354 dir: "subpackage",
355 filesystem: map[string]string{
356 // subpackage with subdirectory
357 "subpackage/Android.bp": `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000358cc_library_static {
359 name: "foo_static",
360 // include_dirs are workspace/root relative
361 include_dirs: [
362 "subpackage/subsubpackage",
363 "subpackage2",
364 "subpackage3/subsubpackage"
365 ],
366 local_include_dirs: ["subsubpackage2"], // module dir relative
367 export_include_dirs: ["./exported_subsubpackage"], // module dir relative
368 include_build_directory: true,
369 bazel_module: { bp2build_available: true },
370}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200371 "subpackage/subsubpackage/header.h": "",
372 "subpackage/subsubpackage2/header.h": "",
373 "subpackage/exported_subsubpackage/header.h": "",
374 "subpackage2/header.h": "",
375 "subpackage3/subsubpackage/header.h": "",
376 },
377 blueprint: soongCcLibraryStaticPreamble,
378 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000379 name = "foo_static",
380 copts = [
381 "-Isubpackage/subsubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400382 "-I$(BINDIR)/subpackage/subsubpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000383 "-Isubpackage2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400384 "-I$(BINDIR)/subpackage2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000385 "-Isubpackage3/subsubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400386 "-I$(BINDIR)/subpackage3/subsubpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000387 "-Isubpackage/subsubpackage2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400388 "-I$(BINDIR)/subpackage/subsubpackage2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000389 "-Isubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400390 "-I$(BINDIR)/subpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000391 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000392 includes = ["./exported_subsubpackage"],
393 linkstatic = True,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000394)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200395 })
396}
397
398func TestCcLibraryStaticIncludeBuildDirectoryDisabled(t *testing.T) {
399 runCcLibraryStaticTestCase(t, bp2buildTestCase{
400 description: "cc_library_static include_build_directory disabled",
401 moduleTypeUnderTest: "cc_library_static",
402 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
403 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
404 filesystem: map[string]string{
405 // subpackage with subdirectory
406 "subpackage/Android.bp": "",
407 "subpackage/subpackage_header.h": "",
408 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000409 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200410 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000411cc_library_static {
412 name: "foo_static",
413 include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended
414 local_include_dirs: ["subpackage2"],
415 include_build_directory: false,
416}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200417 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000418 name = "foo_static",
419 copts = [
420 "-Isubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400421 "-I$(BINDIR)/subpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000422 "-Isubpackage2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400423 "-I$(BINDIR)/subpackage2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000424 ],
425 linkstatic = True,
426)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200427 })
428}
429
430func TestCcLibraryStaticIncludeBuildDirectoryEnabled(t *testing.T) {
431 runCcLibraryStaticTestCase(t, bp2buildTestCase{
432 description: "cc_library_static include_build_directory enabled",
433 moduleTypeUnderTest: "cc_library_static",
434 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
435 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
436 filesystem: map[string]string{
437 // subpackage with subdirectory
438 "subpackage/Android.bp": "",
439 "subpackage/subpackage_header.h": "",
440 "subpackage2/Android.bp": "",
441 "subpackage2/subpackage2_header.h": "",
442 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000443 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200444 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000445cc_library_static {
446 name: "foo_static",
447 include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended
448 local_include_dirs: ["subpackage2"],
449 include_build_directory: true,
450}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200451 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000452 name = "foo_static",
453 copts = [
454 "-Isubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400455 "-I$(BINDIR)/subpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000456 "-Isubpackage2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400457 "-I$(BINDIR)/subpackage2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000458 "-I.",
Chris Parsons484e50a2021-05-13 15:13:04 -0400459 "-I$(BINDIR)/.",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000460 ],
461 linkstatic = True,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000462)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200463 })
464}
465
466func TestCcLibraryStaticArchSpecificStaticLib(t *testing.T) {
467 runCcLibraryStaticTestCase(t, bp2buildTestCase{
468 description: "cc_library_static arch-specific static_libs",
469 moduleTypeUnderTest: "cc_library_static",
470 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
471 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200472 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,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200519 filesystem: map[string]string{},
520 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000521cc_library_static { name: "static_dep" }
522cc_library_static { name: "static_dep2" }
523cc_library_static {
524 name: "foo_static",
525 target: { android: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } },
526}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200527 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000528 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400529 copts = [
530 "-I.",
531 "-I$(BINDIR)/.",
532 ],
Chris Parsonsd6358772021-05-18 18:35:24 -0400533 implementation_deps = select({
Chris Parsons08648312021-05-06 16:23:19 -0400534 "//build/bazel/platforms/os:android": [":static_dep"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000535 "//conditions:default": [],
536 }),
537 linkstatic = True,
Chris Parsons08648312021-05-06 16:23:19 -0400538 whole_archive_deps = select({
539 "//build/bazel/platforms/os:android": [":static_dep2"],
540 "//conditions:default": [],
541 }),
Jingwen Chened9c17d2021-04-13 07:14:55 +0000542)`, `cc_library_static(
543 name = "static_dep",
Chris Parsons484e50a2021-05-13 15:13:04 -0400544 copts = [
545 "-I.",
546 "-I$(BINDIR)/.",
547 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000548 linkstatic = True,
549)`, `cc_library_static(
550 name = "static_dep2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400551 copts = [
552 "-I.",
553 "-I$(BINDIR)/.",
554 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000555 linkstatic = True,
556)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200557 })
558}
559
560func TestCcLibraryStaticBaseArchOsSpecificStaticLib(t *testing.T) {
561 runCcLibraryStaticTestCase(t, bp2buildTestCase{
562 description: "cc_library_static base, arch and os-specific static_libs",
563 moduleTypeUnderTest: "cc_library_static",
564 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
565 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200566 filesystem: map[string]string{},
567 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000568cc_library_static { name: "static_dep" }
569cc_library_static { name: "static_dep2" }
570cc_library_static { name: "static_dep3" }
571cc_library_static { name: "static_dep4" }
572cc_library_static {
573 name: "foo_static",
574 static_libs: ["static_dep"],
575 whole_static_libs: ["static_dep2"],
576 target: { android: { static_libs: ["static_dep3"] } },
577 arch: { arm64: { static_libs: ["static_dep4"] } },
578}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200579 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000580 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400581 copts = [
582 "-I.",
583 "-I$(BINDIR)/.",
584 ],
Chris Parsonsd6358772021-05-18 18:35:24 -0400585 implementation_deps = [":static_dep"] + select({
Jingwen Chened9c17d2021-04-13 07:14:55 +0000586 "//build/bazel/platforms/arch:arm64": [":static_dep4"],
587 "//conditions:default": [],
588 }) + select({
589 "//build/bazel/platforms/os:android": [":static_dep3"],
590 "//conditions:default": [],
591 }),
592 linkstatic = True,
Chris Parsons08648312021-05-06 16:23:19 -0400593 whole_archive_deps = [":static_dep2"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000594)`, `cc_library_static(
595 name = "static_dep",
Chris Parsons484e50a2021-05-13 15:13:04 -0400596 copts = [
597 "-I.",
598 "-I$(BINDIR)/.",
599 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000600 linkstatic = True,
601)`, `cc_library_static(
602 name = "static_dep2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400603 copts = [
604 "-I.",
605 "-I$(BINDIR)/.",
606 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000607 linkstatic = True,
608)`, `cc_library_static(
609 name = "static_dep3",
Chris Parsons484e50a2021-05-13 15:13:04 -0400610 copts = [
611 "-I.",
612 "-I$(BINDIR)/.",
613 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000614 linkstatic = True,
615)`, `cc_library_static(
616 name = "static_dep4",
Chris Parsons484e50a2021-05-13 15:13:04 -0400617 copts = [
618 "-I.",
619 "-I$(BINDIR)/.",
620 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000621 linkstatic = True,
622)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200623 })
624}
625
626func TestCcLibraryStaticSimpleExcludeSrcs(t *testing.T) {
627 runCcLibraryStaticTestCase(t, bp2buildTestCase{
628 description: "cc_library_static simple exclude_srcs",
629 moduleTypeUnderTest: "cc_library_static",
630 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
631 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200632 filesystem: map[string]string{
633 "common.c": "",
634 "foo-a.c": "",
635 "foo-excluded.c": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000636 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200637 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000638cc_library_static {
639 name: "foo_static",
640 srcs: ["common.c", "foo-*.c"],
641 exclude_srcs: ["foo-excluded.c"],
642}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200643 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000644 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400645 copts = [
646 "-I.",
647 "-I$(BINDIR)/.",
648 ],
Jingwen Chene32e9e02021-04-23 09:17:24 +0000649 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400650 srcs_c = [
Jingwen Chene32e9e02021-04-23 09:17:24 +0000651 "common.c",
652 "foo-a.c",
653 ],
654)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200655 })
656}
657
658func TestCcLibraryStaticOneArchSrcs(t *testing.T) {
659 runCcLibraryStaticTestCase(t, bp2buildTestCase{
660 description: "cc_library_static one arch specific srcs",
661 moduleTypeUnderTest: "cc_library_static",
662 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
663 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200664 filesystem: map[string]string{
665 "common.c": "",
666 "foo-arm.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000667 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200668 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000669cc_library_static {
670 name: "foo_static",
671 srcs: ["common.c"],
672 arch: { arm: { srcs: ["foo-arm.c"] } }
673}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200674 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000675 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400676 copts = [
677 "-I.",
678 "-I$(BINDIR)/.",
679 ],
Jingwen Chene32e9e02021-04-23 09:17:24 +0000680 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400681 srcs_c = ["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000682 "//build/bazel/platforms/arch:arm": ["foo-arm.c"],
683 "//conditions:default": [],
684 }),
685)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200686 })
687}
688
689func TestCcLibraryStaticOneArchSrcsExcludeSrcs(t *testing.T) {
690 runCcLibraryStaticTestCase(t, bp2buildTestCase{
691 description: "cc_library_static one arch specific srcs and exclude_srcs",
692 moduleTypeUnderTest: "cc_library_static",
693 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
694 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200695 filesystem: map[string]string{
696 "common.c": "",
697 "for-arm.c": "",
698 "not-for-arm.c": "",
699 "not-for-anything.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000700 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200701 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000702cc_library_static {
703 name: "foo_static",
704 srcs: ["common.c", "not-for-*.c"],
705 exclude_srcs: ["not-for-anything.c"],
706 arch: {
707 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
708 },
709}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200710 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000711 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400712 copts = [
713 "-I.",
714 "-I$(BINDIR)/.",
715 ],
Jingwen Chene32e9e02021-04-23 09:17:24 +0000716 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400717 srcs_c = ["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000718 "//build/bazel/platforms/arch:arm": ["for-arm.c"],
719 "//conditions:default": ["not-for-arm.c"],
720 }),
721)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200722 })
723}
724
725func TestCcLibraryStaticTwoArchExcludeSrcs(t *testing.T) {
726 runCcLibraryStaticTestCase(t, bp2buildTestCase{
727 description: "cc_library_static arch specific exclude_srcs for 2 architectures",
728 moduleTypeUnderTest: "cc_library_static",
729 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
730 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200731 filesystem: map[string]string{
732 "common.c": "",
733 "for-arm.c": "",
734 "for-x86.c": "",
735 "not-for-arm.c": "",
736 "not-for-x86.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000737 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200738 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000739cc_library_static {
740 name: "foo_static",
741 srcs: ["common.c", "not-for-*.c"],
742 exclude_srcs: ["not-for-everything.c"],
743 arch: {
744 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
745 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
746 },
747} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200748 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000749 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400750 copts = [
751 "-I.",
752 "-I$(BINDIR)/.",
753 ],
Jingwen Chene32e9e02021-04-23 09:17:24 +0000754 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400755 srcs_c = ["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000756 "//build/bazel/platforms/arch:arm": [
757 "for-arm.c",
758 "not-for-x86.c",
759 ],
760 "//build/bazel/platforms/arch:x86": [
761 "for-x86.c",
762 "not-for-arm.c",
763 ],
764 "//conditions:default": [
765 "not-for-arm.c",
766 "not-for-x86.c",
767 ],
768 }),
769)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200770 })
771}
772func TestCcLibraryStaticFourArchExcludeSrcs(t *testing.T) {
773 runCcLibraryStaticTestCase(t, bp2buildTestCase{
774 description: "cc_library_static arch specific exclude_srcs for 4 architectures",
775 moduleTypeUnderTest: "cc_library_static",
776 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
777 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200778 filesystem: map[string]string{
779 "common.c": "",
780 "for-arm.c": "",
781 "for-arm64.c": "",
782 "for-x86.c": "",
783 "for-x86_64.c": "",
784 "not-for-arm.c": "",
785 "not-for-arm64.c": "",
786 "not-for-x86.c": "",
787 "not-for-x86_64.c": "",
788 "not-for-everything.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000789 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200790 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000791cc_library_static {
792 name: "foo_static",
793 srcs: ["common.c", "not-for-*.c"],
794 exclude_srcs: ["not-for-everything.c"],
795 arch: {
796 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
797 arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] },
798 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
799 x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] },
800 },
801} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200802 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000803 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400804 copts = [
805 "-I.",
806 "-I$(BINDIR)/.",
807 ],
Jingwen Chene32e9e02021-04-23 09:17:24 +0000808 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400809 srcs_c = ["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000810 "//build/bazel/platforms/arch:arm": [
811 "for-arm.c",
812 "not-for-arm64.c",
813 "not-for-x86.c",
814 "not-for-x86_64.c",
815 ],
816 "//build/bazel/platforms/arch:arm64": [
817 "for-arm64.c",
818 "not-for-arm.c",
819 "not-for-x86.c",
820 "not-for-x86_64.c",
821 ],
822 "//build/bazel/platforms/arch:x86": [
823 "for-x86.c",
824 "not-for-arm.c",
825 "not-for-arm64.c",
826 "not-for-x86_64.c",
827 ],
828 "//build/bazel/platforms/arch:x86_64": [
829 "for-x86_64.c",
830 "not-for-arm.c",
831 "not-for-arm64.c",
832 "not-for-x86.c",
833 ],
834 "//conditions:default": [
835 "not-for-arm.c",
836 "not-for-arm64.c",
837 "not-for-x86.c",
838 "not-for-x86_64.c",
839 ],
840 }),
841)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200842 })
843}
844
Liz Kammer2b07ec72021-05-26 15:08:27 -0400845func TestCcLibraryStaticOneArchEmpty(t *testing.T) {
846 runCcLibraryStaticTestCase(t, bp2buildTestCase{
847 description: "cc_library_static one arch empty",
848 moduleTypeUnderTest: "cc_library_static",
849 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
850 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammer2b07ec72021-05-26 15:08:27 -0400851 filesystem: map[string]string{
852 "common.cc": "",
853 "foo-no-arm.cc": "",
854 "foo-excluded.cc": "",
855 },
856 blueprint: soongCcLibraryStaticPreamble + `
857cc_library_static {
858 name: "foo_static",
859 srcs: ["common.cc", "foo-*.cc"],
860 exclude_srcs: ["foo-excluded.cc"],
861 arch: {
862 arm: { exclude_srcs: ["foo-no-arm.cc"] },
863 },
864}`,
865 expectedBazelTargets: []string{`cc_library_static(
866 name = "foo_static",
867 copts = [
868 "-I.",
869 "-I$(BINDIR)/.",
870 ],
871 linkstatic = True,
872 srcs = ["common.cc"] + select({
873 "//build/bazel/platforms/arch:arm": [],
874 "//conditions:default": ["foo-no-arm.cc"],
875 }),
876)`},
877 })
878}
879
880func TestCcLibraryStaticOneArchEmptyOtherSet(t *testing.T) {
881 runCcLibraryStaticTestCase(t, bp2buildTestCase{
882 description: "cc_library_static one arch empty other set",
883 moduleTypeUnderTest: "cc_library_static",
884 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
885 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammer2b07ec72021-05-26 15:08:27 -0400886 filesystem: map[string]string{
887 "common.cc": "",
888 "foo-no-arm.cc": "",
889 "x86-only.cc": "",
890 "foo-excluded.cc": "",
891 },
892 blueprint: soongCcLibraryStaticPreamble + `
893cc_library_static {
894 name: "foo_static",
895 srcs: ["common.cc", "foo-*.cc"],
896 exclude_srcs: ["foo-excluded.cc"],
897 arch: {
898 arm: { exclude_srcs: ["foo-no-arm.cc"] },
899 x86: { srcs: ["x86-only.cc"] },
900 },
901}`,
902 expectedBazelTargets: []string{`cc_library_static(
903 name = "foo_static",
904 copts = [
905 "-I.",
906 "-I$(BINDIR)/.",
907 ],
908 linkstatic = True,
909 srcs = ["common.cc"] + select({
910 "//build/bazel/platforms/arch:arm": [],
911 "//build/bazel/platforms/arch:x86": [
912 "foo-no-arm.cc",
913 "x86-only.cc",
914 ],
915 "//conditions:default": ["foo-no-arm.cc"],
916 }),
917)`},
918 })
919}
920
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200921func TestCcLibraryStaticMultipleDepSameName(t *testing.T) {
922 runCcLibraryStaticTestCase(t, bp2buildTestCase{
923 description: "cc_library_static multiple dep same name panic",
924 moduleTypeUnderTest: "cc_library_static",
925 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
926 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200927 filesystem: map[string]string{},
928 blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer2b50ce62021-04-26 15:47:28 -0400929cc_library_static { name: "static_dep" }
930cc_library_static {
931 name: "foo_static",
Chris Parsons08648312021-05-06 16:23:19 -0400932 static_libs: ["static_dep", "static_dep"],
Liz Kammer2b50ce62021-04-26 15:47:28 -0400933}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200934 expectedBazelTargets: []string{`cc_library_static(
Liz Kammer2b50ce62021-04-26 15:47:28 -0400935 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400936 copts = [
937 "-I.",
938 "-I$(BINDIR)/.",
939 ],
Chris Parsonsd6358772021-05-18 18:35:24 -0400940 implementation_deps = [":static_dep"],
Liz Kammer2b50ce62021-04-26 15:47:28 -0400941 linkstatic = True,
942)`, `cc_library_static(
943 name = "static_dep",
Chris Parsons484e50a2021-05-13 15:13:04 -0400944 copts = [
945 "-I.",
946 "-I$(BINDIR)/.",
947 ],
Liz Kammer2b50ce62021-04-26 15:47:28 -0400948 linkstatic = True,
949)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200950 })
951}
952
953func TestCcLibraryStaticOneMultilibSrcsExcludeSrcs(t *testing.T) {
954 runCcLibraryStaticTestCase(t, bp2buildTestCase{
955 description: "cc_library_static 1 multilib srcs and exclude_srcs",
956 moduleTypeUnderTest: "cc_library_static",
957 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
958 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200959 filesystem: map[string]string{
960 "common.c": "",
961 "for-lib32.c": "",
962 "not-for-lib32.c": "",
Liz Kammer2b50ce62021-04-26 15:47:28 -0400963 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200964 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -0400965cc_library_static {
966 name: "foo_static",
967 srcs: ["common.c", "not-for-*.c"],
968 multilib: {
969 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
970 },
971} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200972 expectedBazelTargets: []string{`cc_library_static(
Chris Parsonsc424b762021-04-29 18:06:50 -0400973 name = "foo_static",
Chris Parsons484e50a2021-05-13 15:13:04 -0400974 copts = [
975 "-I.",
976 "-I$(BINDIR)/.",
977 ],
Chris Parsonsc424b762021-04-29 18:06:50 -0400978 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400979 srcs_c = ["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -0400980 "//build/bazel/platforms/arch:arm": ["for-lib32.c"],
981 "//build/bazel/platforms/arch:x86": ["for-lib32.c"],
982 "//conditions:default": ["not-for-lib32.c"],
983 }),
984)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200985 })
986}
987
988func TestCcLibraryStaticTwoMultilibSrcsExcludeSrcs(t *testing.T) {
989 runCcLibraryStaticTestCase(t, bp2buildTestCase{
990 description: "cc_library_static 2 multilib srcs and exclude_srcs",
991 moduleTypeUnderTest: "cc_library_static",
992 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
993 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200994 filesystem: map[string]string{
995 "common.c": "",
996 "for-lib32.c": "",
997 "for-lib64.c": "",
998 "not-for-lib32.c": "",
999 "not-for-lib64.c": "",
Chris Parsonsc424b762021-04-29 18:06:50 -04001000 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001001 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -04001002cc_library_static {
1003 name: "foo_static2",
1004 srcs: ["common.c", "not-for-*.c"],
1005 multilib: {
1006 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
1007 lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] },
1008 },
1009} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001010 expectedBazelTargets: []string{`cc_library_static(
Chris Parsonsc424b762021-04-29 18:06:50 -04001011 name = "foo_static2",
Chris Parsons484e50a2021-05-13 15:13:04 -04001012 copts = [
1013 "-I.",
1014 "-I$(BINDIR)/.",
1015 ],
Chris Parsonsc424b762021-04-29 18:06:50 -04001016 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -04001017 srcs_c = ["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -04001018 "//build/bazel/platforms/arch:arm": [
1019 "for-lib32.c",
1020 "not-for-lib64.c",
1021 ],
1022 "//build/bazel/platforms/arch:arm64": [
1023 "for-lib64.c",
1024 "not-for-lib32.c",
1025 ],
1026 "//build/bazel/platforms/arch:x86": [
1027 "for-lib32.c",
1028 "not-for-lib64.c",
1029 ],
1030 "//build/bazel/platforms/arch:x86_64": [
1031 "for-lib64.c",
1032 "not-for-lib32.c",
1033 ],
1034 "//conditions:default": [
1035 "not-for-lib32.c",
1036 "not-for-lib64.c",
1037 ],
1038 }),
1039)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001040 })
1041}
1042
1043func TestCcLibrarySTaticArchMultilibSrcsExcludeSrcs(t *testing.T) {
1044 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1045 description: "cc_library_static arch and multilib srcs and exclude_srcs",
1046 moduleTypeUnderTest: "cc_library_static",
1047 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1048 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001049 filesystem: map[string]string{
1050 "common.c": "",
1051 "for-arm.c": "",
1052 "for-arm64.c": "",
1053 "for-x86.c": "",
1054 "for-x86_64.c": "",
1055 "for-lib32.c": "",
1056 "for-lib64.c": "",
1057 "not-for-arm.c": "",
1058 "not-for-arm64.c": "",
1059 "not-for-x86.c": "",
1060 "not-for-x86_64.c": "",
1061 "not-for-lib32.c": "",
1062 "not-for-lib64.c": "",
1063 "not-for-everything.c": "",
Chris Parsonsc424b762021-04-29 18:06:50 -04001064 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001065 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -04001066cc_library_static {
1067 name: "foo_static3",
1068 srcs: ["common.c", "not-for-*.c"],
1069 exclude_srcs: ["not-for-everything.c"],
1070 arch: {
1071 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
1072 arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] },
1073 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
1074 x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] },
1075 },
1076 multilib: {
1077 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
1078 lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] },
1079 },
1080}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001081 expectedBazelTargets: []string{`cc_library_static(
Chris Parsonsc424b762021-04-29 18:06:50 -04001082 name = "foo_static3",
Chris Parsons484e50a2021-05-13 15:13:04 -04001083 copts = [
1084 "-I.",
1085 "-I$(BINDIR)/.",
1086 ],
Chris Parsonsc424b762021-04-29 18:06:50 -04001087 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -04001088 srcs_c = ["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -04001089 "//build/bazel/platforms/arch:arm": [
1090 "for-arm.c",
1091 "for-lib32.c",
1092 "not-for-arm64.c",
1093 "not-for-lib64.c",
1094 "not-for-x86.c",
1095 "not-for-x86_64.c",
1096 ],
1097 "//build/bazel/platforms/arch:arm64": [
1098 "for-arm64.c",
1099 "for-lib64.c",
1100 "not-for-arm.c",
1101 "not-for-lib32.c",
1102 "not-for-x86.c",
1103 "not-for-x86_64.c",
1104 ],
1105 "//build/bazel/platforms/arch:x86": [
1106 "for-lib32.c",
1107 "for-x86.c",
1108 "not-for-arm.c",
1109 "not-for-arm64.c",
1110 "not-for-lib64.c",
1111 "not-for-x86_64.c",
1112 ],
1113 "//build/bazel/platforms/arch:x86_64": [
1114 "for-lib64.c",
1115 "for-x86_64.c",
1116 "not-for-arm.c",
1117 "not-for-arm64.c",
1118 "not-for-lib32.c",
1119 "not-for-x86.c",
1120 ],
1121 "//conditions:default": [
1122 "not-for-arm.c",
1123 "not-for-arm64.c",
1124 "not-for-lib32.c",
1125 "not-for-lib64.c",
1126 "not-for-x86.c",
1127 "not-for-x86_64.c",
1128 ],
1129 }),
1130)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001131 })
1132}
1133
1134func TestCcLibraryStaticArchSrcsExcludeSrcsGeneratedFiles(t *testing.T) {
1135 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1136 description: "cc_library_static arch srcs/exclude_srcs with generated files",
1137 moduleTypeUnderTest: "cc_library_static",
1138 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1139 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001140 filesystem: map[string]string{
Chris Parsons990c4f42021-05-25 12:10:58 -04001141 "common.cpp": "",
1142 "for-x86.cpp": "",
1143 "not-for-x86.cpp": "",
1144 "not-for-everything.cpp": "",
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001145 "dep/Android.bp": `
Chris Parsons484e50a2021-05-13 15:13:04 -04001146genrule {
1147 name: "generated_src_other_pkg",
1148 out: ["generated_src_other_pkg.cpp"],
1149 cmd: "nothing to see here",
1150}
1151
1152genrule {
1153 name: "generated_hdr_other_pkg",
1154 out: ["generated_hdr_other_pkg.cpp"],
1155 cmd: "nothing to see here",
1156}
1157
1158genrule {
1159 name: "generated_hdr_other_pkg_x86",
1160 out: ["generated_hdr_other_pkg_x86.cpp"],
1161 cmd: "nothing to see here",
1162}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001163 },
1164 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsons484e50a2021-05-13 15:13:04 -04001165genrule {
1166 name: "generated_src",
1167 out: ["generated_src.cpp"],
1168 cmd: "nothing to see here",
1169}
1170
1171genrule {
1172 name: "generated_src_x86",
1173 out: ["generated_src_x86.cpp"],
1174 cmd: "nothing to see here",
1175}
1176
1177genrule {
1178 name: "generated_hdr",
1179 out: ["generated_hdr.h"],
1180 cmd: "nothing to see here",
1181}
1182
1183cc_library_static {
1184 name: "foo_static3",
Chris Parsons990c4f42021-05-25 12:10:58 -04001185 srcs: ["common.cpp", "not-for-*.cpp"],
1186 exclude_srcs: ["not-for-everything.cpp"],
Chris Parsons484e50a2021-05-13 15:13:04 -04001187 generated_sources: ["generated_src", "generated_src_other_pkg"],
1188 generated_headers: ["generated_hdr", "generated_hdr_other_pkg"],
1189 arch: {
1190 x86: {
Chris Parsons990c4f42021-05-25 12:10:58 -04001191 srcs: ["for-x86.cpp"],
1192 exclude_srcs: ["not-for-x86.cpp"],
Chris Parsons484e50a2021-05-13 15:13:04 -04001193 generated_sources: ["generated_src_x86"],
1194 generated_headers: ["generated_hdr_other_pkg_x86"],
1195 },
1196 },
1197}
1198`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001199 expectedBazelTargets: []string{`cc_library_static(
Chris Parsons484e50a2021-05-13 15:13:04 -04001200 name = "foo_static3",
1201 copts = [
1202 "-I.",
1203 "-I$(BINDIR)/.",
1204 ],
1205 linkstatic = True,
1206 srcs = [
1207 "//dep:generated_hdr_other_pkg",
1208 "//dep:generated_src_other_pkg",
1209 ":generated_hdr",
1210 ":generated_src",
Chris Parsons990c4f42021-05-25 12:10:58 -04001211 "common.cpp",
Chris Parsons484e50a2021-05-13 15:13:04 -04001212 ] + select({
1213 "//build/bazel/platforms/arch:x86": [
1214 "//dep:generated_hdr_other_pkg_x86",
1215 ":generated_src_x86",
Chris Parsons990c4f42021-05-25 12:10:58 -04001216 "for-x86.cpp",
Chris Parsons484e50a2021-05-13 15:13:04 -04001217 ],
Chris Parsons990c4f42021-05-25 12:10:58 -04001218 "//conditions:default": ["not-for-x86.cpp"],
Chris Parsons484e50a2021-05-13 15:13:04 -04001219 }),
1220)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001221 })
Rupert Shuttleworth095081c2021-03-25 09:06:03 +00001222}
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001223
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001224func TestCcLibraryStaticGetTargetProperties(t *testing.T) {
1225 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1226
1227 description: "cc_library_static complex GetTargetProperties",
1228 moduleTypeUnderTest: "cc_library_static",
1229 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1230 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001231 blueprint: soongCcLibraryStaticPreamble + `
1232cc_library_static {
1233 name: "foo_static",
1234 target: {
1235 android: {
1236 srcs: ["android_src.c"],
1237 },
1238 android_arm: {
1239 srcs: ["android_arm_src.c"],
1240 },
1241 android_arm64: {
1242 srcs: ["android_arm64_src.c"],
1243 },
1244 android_x86: {
1245 srcs: ["android_x86_src.c"],
1246 },
1247 android_x86_64: {
1248 srcs: ["android_x86_64_src.c"],
1249 },
1250 linux_bionic_arm64: {
1251 srcs: ["linux_bionic_arm64_src.c"],
1252 },
1253 linux_bionic_x86_64: {
1254 srcs: ["linux_bionic_x86_64_src.c"],
1255 },
1256 },
1257}`,
1258 expectedBazelTargets: []string{`cc_library_static(
1259 name = "foo_static",
1260 copts = [
1261 "-I.",
1262 "-I$(BINDIR)/.",
1263 ],
1264 linkstatic = True,
1265 srcs_c = select({
1266 "//build/bazel/platforms/os:android": ["android_src.c"],
1267 "//conditions:default": [],
1268 }) + select({
Rupert Shuttleworthffd45822021-05-14 03:02:34 -04001269 "//build/bazel/platforms/os_arch:android_arm": ["android_arm_src.c"],
1270 "//build/bazel/platforms/os_arch:android_arm64": ["android_arm64_src.c"],
1271 "//build/bazel/platforms/os_arch:android_x86": ["android_x86_src.c"],
1272 "//build/bazel/platforms/os_arch:android_x86_64": ["android_x86_64_src.c"],
Rupert Shuttleworthffd45822021-05-14 03:02:34 -04001273 "//build/bazel/platforms/os_arch:linux_bionic_arm64": ["linux_bionic_arm64_src.c"],
1274 "//build/bazel/platforms/os_arch:linux_bionic_x86_64": ["linux_bionic_x86_64_src.c"],
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001275 "//conditions:default": [],
1276 }),
1277)`},
1278 })
1279}
1280
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001281func TestCcLibraryStaticProductVariableSelects(t *testing.T) {
1282 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1283 description: "cc_library_static product variable selects",
1284 moduleTypeUnderTest: "cc_library_static",
1285 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1286 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001287 blueprint: soongCcLibraryStaticPreamble + `
1288cc_library_static {
1289 name: "foo_static",
1290 srcs: ["common.c"],
1291 product_variables: {
1292 malloc_not_svelte: {
1293 cflags: ["-Wmalloc_not_svelte"],
1294 },
1295 malloc_zero_contents: {
1296 cflags: ["-Wmalloc_zero_contents"],
1297 },
1298 binder32bit: {
1299 cflags: ["-Wbinder32bit"],
1300 },
1301 },
1302} `,
1303 expectedBazelTargets: []string{`cc_library_static(
1304 name = "foo_static",
1305 copts = [
1306 "-I.",
1307 "-I$(BINDIR)/.",
1308 ] + select({
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001309 "//build/bazel/product_variables:binder32bit": ["-Wbinder32bit"],
1310 "//conditions:default": [],
1311 }) + select({
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001312 "//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"],
1313 "//conditions:default": [],
1314 }) + select({
1315 "//build/bazel/product_variables:malloc_zero_contents": ["-Wmalloc_zero_contents"],
1316 "//conditions:default": [],
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001317 }),
1318 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -04001319 srcs_c = ["common.c"],
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001320)`},
1321 })
1322}
1323
1324func TestCcLibraryStaticProductVariableArchSpecificSelects(t *testing.T) {
1325 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1326 description: "cc_library_static arch-specific product variable selects",
1327 moduleTypeUnderTest: "cc_library_static",
1328 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1329 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001330 filesystem: map[string]string{},
1331 blueprint: soongCcLibraryStaticPreamble + `
1332cc_library_static {
1333 name: "foo_static",
1334 srcs: ["common.c"],
1335 product_variables: {
1336 malloc_not_svelte: {
1337 cflags: ["-Wmalloc_not_svelte"],
1338 },
1339 },
1340 arch: {
1341 arm64: {
1342 product_variables: {
1343 malloc_not_svelte: {
1344 cflags: ["-Warm64_malloc_not_svelte"],
1345 },
1346 },
1347 },
1348 },
1349 multilib: {
1350 lib32: {
1351 product_variables: {
1352 malloc_not_svelte: {
1353 cflags: ["-Wlib32_malloc_not_svelte"],
1354 },
1355 },
1356 },
1357 },
1358 target: {
1359 android: {
1360 product_variables: {
1361 malloc_not_svelte: {
1362 cflags: ["-Wandroid_malloc_not_svelte"],
1363 },
1364 },
1365 }
1366 },
1367} `,
1368 expectedBazelTargets: []string{`cc_library_static(
1369 name = "foo_static",
1370 copts = [
1371 "-I.",
1372 "-I$(BINDIR)/.",
1373 ] + select({
1374 "//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"],
1375 "//conditions:default": [],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001376 }) + select({
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001377 "//build/bazel/product_variables:malloc_not_svelte-android": ["-Wandroid_malloc_not_svelte"],
1378 "//conditions:default": [],
1379 }) + select({
1380 "//build/bazel/product_variables:malloc_not_svelte-arm": ["-Wlib32_malloc_not_svelte"],
1381 "//conditions:default": [],
1382 }) + select({
1383 "//build/bazel/product_variables:malloc_not_svelte-arm64": ["-Warm64_malloc_not_svelte"],
1384 "//conditions:default": [],
1385 }) + select({
1386 "//build/bazel/product_variables:malloc_not_svelte-x86": ["-Wlib32_malloc_not_svelte"],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001387 "//conditions:default": [],
1388 }),
1389 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -04001390 srcs_c = ["common.c"],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001391)`},
1392 })
1393}
Liz Kammerba7a9c52021-05-26 08:45:30 -04001394
1395func TestCcLibraryStaticProductVariableStringReplacement(t *testing.T) {
1396 runCcLibraryStaticTestCase(t, bp2buildTestCase{
Chris Parsons69fa9f92021-07-13 11:47:44 -04001397 description: "cc_library_static product variable string replacement",
Liz Kammerba7a9c52021-05-26 08:45:30 -04001398 moduleTypeUnderTest: "cc_library_static",
1399 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1400 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammerba7a9c52021-05-26 08:45:30 -04001401 filesystem: map[string]string{},
1402 blueprint: soongCcLibraryStaticPreamble + `
1403cc_library_static {
1404 name: "foo_static",
Chris Parsons69fa9f92021-07-13 11:47:44 -04001405 srcs: ["common.S"],
Liz Kammerba7a9c52021-05-26 08:45:30 -04001406 product_variables: {
1407 platform_sdk_version: {
1408 asflags: ["-DPLATFORM_SDK_VERSION=%d"],
1409 },
1410 },
1411} `,
1412 expectedBazelTargets: []string{`cc_library_static(
1413 name = "foo_static",
Chris Parsons69fa9f92021-07-13 11:47:44 -04001414 asflags = [
1415 "-I.",
1416 "-I$(BINDIR)/.",
1417 ] + select({
Liz Kammerba7a9c52021-05-26 08:45:30 -04001418 "//build/bazel/product_variables:platform_sdk_version": ["-DPLATFORM_SDK_VERSION=$(Platform_sdk_version)"],
1419 "//conditions:default": [],
1420 }),
1421 copts = [
1422 "-I.",
1423 "-I$(BINDIR)/.",
1424 ],
1425 linkstatic = True,
Chris Parsons69fa9f92021-07-13 11:47:44 -04001426 srcs_as = ["common.S"],
Liz Kammerba7a9c52021-05-26 08:45:30 -04001427)`},
1428 })
1429}