blob: 5c9afbf7f5f2b5c8a184b2d11ef9850231a85a83 [file] [log] [blame]
Rupert Shuttleworth095081c2021-03-25 09:06:03 +00001// Copyright 2021 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package bp2build
16
17import (
18 "android/soong/android"
19 "android/soong/cc"
Chris Parsons484e50a2021-05-13 15:13:04 -040020 "android/soong/genrule"
21
Rupert Shuttleworth095081c2021-03-25 09:06:03 +000022 "testing"
23)
24
25const (
26 // See cc/testing.go for more context
27 soongCcLibraryStaticPreamble = `
28cc_defaults {
Liz Kammer8337ea42021-09-10 10:06:32 -040029 name: "linux_bionic_supported",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +000030}
31
32toolchain_library {
Liz Kammer8337ea42021-09-10 10:06:32 -040033 name: "libclang_rt.builtins-x86_64-android",
34 defaults: ["linux_bionic_supported"],
35 vendor_available: true,
36 vendor_ramdisk_available: true,
37 product_available: true,
38 recovery_available: true,
39 native_bridge_supported: true,
40 src: "",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +000041}`
42)
43
44func TestCcLibraryStaticLoadStatement(t *testing.T) {
45 testCases := []struct {
46 bazelTargets BazelTargets
47 expectedLoadStatements string
48 }{
49 {
50 bazelTargets: BazelTargets{
51 BazelTarget{
52 name: "cc_library_static_target",
53 ruleClass: "cc_library_static",
54 // NOTE: No bzlLoadLocation for native rules
55 },
56 },
57 expectedLoadStatements: ``,
58 },
59 }
60
61 for _, testCase := range testCases {
62 actual := testCase.bazelTargets.LoadStatements()
63 expected := testCase.expectedLoadStatements
64 if actual != expected {
65 t.Fatalf("Expected load statements to be %s, got %s", expected, actual)
66 }
67 }
68
69}
70
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +020071func registerCcLibraryStaticModuleTypes(ctx android.RegistrationContext) {
72 cc.RegisterCCBuildComponents(ctx)
73 ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory)
74 ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
75 ctx.RegisterModuleType("genrule", genrule.GenRuleFactory)
Chris Parsons51f8c392021-08-03 21:01:05 -040076 // Required for system_shared_libs dependencies.
77 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +020078}
79
80func runCcLibraryStaticTestCase(t *testing.T, tc bp2buildTestCase) {
Liz Kammere4982e82021-05-25 10:39:35 -040081 t.Helper()
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +020082 runBp2BuildTestCase(t, registerCcLibraryStaticModuleTypes, tc)
83}
84
85func TestCcLibraryStaticSimple(t *testing.T) {
86 runCcLibraryStaticTestCase(t, bp2buildTestCase{
87 description: "cc_library_static test",
88 moduleTypeUnderTest: "cc_library_static",
89 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
90 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
91 filesystem: map[string]string{
92 // NOTE: include_dir headers *should not* appear in Bazel hdrs later (?)
93 "include_dir_1/include_dir_1_a.h": "",
94 "include_dir_1/include_dir_1_b.h": "",
95 "include_dir_2/include_dir_2_a.h": "",
96 "include_dir_2/include_dir_2_b.h": "",
97 // NOTE: local_include_dir headers *should not* appear in Bazel hdrs later (?)
98 "local_include_dir_1/local_include_dir_1_a.h": "",
99 "local_include_dir_1/local_include_dir_1_b.h": "",
100 "local_include_dir_2/local_include_dir_2_a.h": "",
101 "local_include_dir_2/local_include_dir_2_b.h": "",
102 // NOTE: export_include_dir headers *should* appear in Bazel hdrs later
103 "export_include_dir_1/export_include_dir_1_a.h": "",
104 "export_include_dir_1/export_include_dir_1_b.h": "",
105 "export_include_dir_2/export_include_dir_2_a.h": "",
106 "export_include_dir_2/export_include_dir_2_b.h": "",
107 // NOTE: Soong implicitly includes headers in the current directory
108 "implicit_include_1.h": "",
109 "implicit_include_2.h": "",
110 },
111 blueprint: soongCcLibraryStaticPreamble + `
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000112cc_library_headers {
113 name: "header_lib_1",
114 export_include_dirs: ["header_lib_1"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400115 bazel_module: { bp2build_available: false },
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000116}
117
118cc_library_headers {
119 name: "header_lib_2",
120 export_include_dirs: ["header_lib_2"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400121 bazel_module: { bp2build_available: false },
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000122}
123
124cc_library_static {
125 name: "static_lib_1",
126 srcs: ["static_lib_1.cc"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400127 bazel_module: { bp2build_available: false },
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000128}
129
130cc_library_static {
131 name: "static_lib_2",
132 srcs: ["static_lib_2.cc"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400133 bazel_module: { bp2build_available: false },
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000134}
135
136cc_library_static {
137 name: "whole_static_lib_1",
138 srcs: ["whole_static_lib_1.cc"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400139 bazel_module: { bp2build_available: false },
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000140}
141
142cc_library_static {
143 name: "whole_static_lib_2",
144 srcs: ["whole_static_lib_2.cc"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400145 bazel_module: { bp2build_available: false },
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000146}
147
148cc_library_static {
149 name: "foo_static",
150 srcs: [
151 "foo_static1.cc",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000152 "foo_static2.cc",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000153 ],
154 cflags: [
155 "-Dflag1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000156 "-Dflag2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000157 ],
158 static_libs: [
159 "static_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000160 "static_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000161 ],
162 whole_static_libs: [
163 "whole_static_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000164 "whole_static_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000165 ],
166 include_dirs: [
Jingwen Chened9c17d2021-04-13 07:14:55 +0000167 "include_dir_1",
168 "include_dir_2",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000169 ],
170 local_include_dirs: [
171 "local_include_dir_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000172 "local_include_dir_2",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000173 ],
174 export_include_dirs: [
Chris Parsonsd6358772021-05-18 18:35:24 -0400175 "export_include_dir_1",
176 "export_include_dir_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000177 ],
178 header_libs: [
179 "header_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000180 "header_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000181 ],
182
183 // TODO: Also support export_header_lib_headers
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000184}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200185 expectedBazelTargets: []string{`cc_library_static(
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000186 name = "foo_static",
187 copts = [
188 "-Dflag1",
189 "-Dflag2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000190 "-Iinclude_dir_1",
Chris Parsons484e50a2021-05-13 15:13:04 -0400191 "-I$(BINDIR)/include_dir_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000192 "-Iinclude_dir_2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400193 "-I$(BINDIR)/include_dir_2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000194 "-Ilocal_include_dir_1",
Chris Parsons484e50a2021-05-13 15:13:04 -0400195 "-I$(BINDIR)/local_include_dir_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000196 "-Ilocal_include_dir_2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400197 "-I$(BINDIR)/local_include_dir_2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000198 "-I.",
Chris Parsons484e50a2021-05-13 15:13:04 -0400199 "-I$(BINDIR)/.",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000200 ],
Liz Kammer5fad5012021-09-09 14:08:21 -0400201 export_includes = [
202 "export_include_dir_1",
203 "export_include_dir_2",
204 ],
Chris Parsonsd6358772021-05-18 18:35:24 -0400205 implementation_deps = [
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000206 ":header_lib_1",
207 ":header_lib_2",
208 ":static_lib_1",
209 ":static_lib_2",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000210 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000211 linkstatic = True,
212 srcs = [
213 "foo_static1.cc",
214 "foo_static2.cc",
215 ],
Chris Parsons08648312021-05-06 16:23:19 -0400216 whole_archive_deps = [
217 ":whole_static_lib_1",
218 ":whole_static_lib_2",
219 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000220)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200221 })
222}
223
224func TestCcLibraryStaticSubpackage(t *testing.T) {
225 runCcLibraryStaticTestCase(t, bp2buildTestCase{
226 description: "cc_library_static subpackage test",
227 moduleTypeUnderTest: "cc_library_static",
228 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
229 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
230 filesystem: map[string]string{
231 // subpackage with subdirectory
232 "subpackage/Android.bp": "",
233 "subpackage/subpackage_header.h": "",
234 "subpackage/subdirectory/subdirectory_header.h": "",
235 // subsubpackage with subdirectory
236 "subpackage/subsubpackage/Android.bp": "",
237 "subpackage/subsubpackage/subsubpackage_header.h": "",
238 "subpackage/subsubpackage/subdirectory/subdirectory_header.h": "",
239 // subsubsubpackage with subdirectory
240 "subpackage/subsubpackage/subsubsubpackage/Android.bp": "",
241 "subpackage/subsubpackage/subsubsubpackage/subsubsubpackage_header.h": "",
242 "subpackage/subsubpackage/subsubsubpackage/subdirectory/subdirectory_header.h": "",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000243 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200244 blueprint: soongCcLibraryStaticPreamble + `
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400245cc_library_static {
246 name: "foo_static",
247 srcs: [
248 ],
249 include_dirs: [
Liz Kammer8337ea42021-09-10 10:06:32 -0400250 "subpackage",
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400251 ],
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400252}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200253 expectedBazelTargets: []string{`cc_library_static(
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400254 name = "foo_static",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000255 copts = [
256 "-Isubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400257 "-I$(BINDIR)/subpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000258 "-I.",
Chris Parsons484e50a2021-05-13 15:13:04 -0400259 "-I$(BINDIR)/.",
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400260 ],
261 linkstatic = True,
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400262)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200263 })
264}
265
266func TestCcLibraryStaticExportIncludeDir(t *testing.T) {
267 runCcLibraryStaticTestCase(t, bp2buildTestCase{
268 description: "cc_library_static export include dir",
269 moduleTypeUnderTest: "cc_library_static",
270 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
271 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
272 filesystem: map[string]string{
273 // subpackage with subdirectory
274 "subpackage/Android.bp": "",
275 "subpackage/subpackage_header.h": "",
276 "subpackage/subdirectory/subdirectory_header.h": "",
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400277 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200278 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000279cc_library_static {
280 name: "foo_static",
281 export_include_dirs: ["subpackage"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400282 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000283}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200284 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000285 name = "foo_static",
Liz Kammer5fad5012021-09-09 14:08:21 -0400286 export_includes = ["subpackage"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000287 linkstatic = True,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000288)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200289 })
290}
291
292func TestCcLibraryStaticExportSystemIncludeDir(t *testing.T) {
293 runCcLibraryStaticTestCase(t, bp2buildTestCase{
294 description: "cc_library_static export system include dir",
295 moduleTypeUnderTest: "cc_library_static",
296 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
297 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
298 filesystem: map[string]string{
299 // subpackage with subdirectory
300 "subpackage/Android.bp": "",
301 "subpackage/subpackage_header.h": "",
302 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000303 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200304 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000305cc_library_static {
306 name: "foo_static",
307 export_system_include_dirs: ["subpackage"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400308 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000309}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200310 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000311 name = "foo_static",
Liz Kammer5fad5012021-09-09 14:08:21 -0400312 export_system_includes = ["subpackage"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000313 linkstatic = True,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000314)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200315 })
316}
317
318func TestCcLibraryStaticManyIncludeDirs(t *testing.T) {
319 runCcLibraryStaticTestCase(t, bp2buildTestCase{
320 description: "cc_library_static include_dirs, local_include_dirs, export_include_dirs (b/183742505)",
321 moduleTypeUnderTest: "cc_library_static",
322 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
323 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
324 dir: "subpackage",
325 filesystem: map[string]string{
326 // subpackage with subdirectory
327 "subpackage/Android.bp": `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000328cc_library_static {
329 name: "foo_static",
330 // include_dirs are workspace/root relative
331 include_dirs: [
332 "subpackage/subsubpackage",
333 "subpackage2",
334 "subpackage3/subsubpackage"
335 ],
336 local_include_dirs: ["subsubpackage2"], // module dir relative
337 export_include_dirs: ["./exported_subsubpackage"], // module dir relative
338 include_build_directory: true,
339 bazel_module: { bp2build_available: true },
340}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200341 "subpackage/subsubpackage/header.h": "",
342 "subpackage/subsubpackage2/header.h": "",
343 "subpackage/exported_subsubpackage/header.h": "",
344 "subpackage2/header.h": "",
345 "subpackage3/subsubpackage/header.h": "",
346 },
347 blueprint: soongCcLibraryStaticPreamble,
348 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000349 name = "foo_static",
350 copts = [
351 "-Isubpackage/subsubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400352 "-I$(BINDIR)/subpackage/subsubpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000353 "-Isubpackage2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400354 "-I$(BINDIR)/subpackage2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000355 "-Isubpackage3/subsubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400356 "-I$(BINDIR)/subpackage3/subsubpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000357 "-Isubpackage/subsubpackage2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400358 "-I$(BINDIR)/subpackage/subsubpackage2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000359 "-Isubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400360 "-I$(BINDIR)/subpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000361 ],
Liz Kammer5fad5012021-09-09 14:08:21 -0400362 export_includes = ["./exported_subsubpackage"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000363 linkstatic = True,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000364)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200365 })
366}
367
368func TestCcLibraryStaticIncludeBuildDirectoryDisabled(t *testing.T) {
369 runCcLibraryStaticTestCase(t, bp2buildTestCase{
370 description: "cc_library_static include_build_directory disabled",
371 moduleTypeUnderTest: "cc_library_static",
372 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
373 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
374 filesystem: map[string]string{
375 // subpackage with subdirectory
376 "subpackage/Android.bp": "",
377 "subpackage/subpackage_header.h": "",
378 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000379 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200380 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000381cc_library_static {
382 name: "foo_static",
383 include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended
384 local_include_dirs: ["subpackage2"],
385 include_build_directory: false,
386}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200387 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000388 name = "foo_static",
389 copts = [
390 "-Isubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400391 "-I$(BINDIR)/subpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000392 "-Isubpackage2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400393 "-I$(BINDIR)/subpackage2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000394 ],
395 linkstatic = True,
396)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200397 })
398}
399
400func TestCcLibraryStaticIncludeBuildDirectoryEnabled(t *testing.T) {
401 runCcLibraryStaticTestCase(t, bp2buildTestCase{
402 description: "cc_library_static include_build_directory enabled",
403 moduleTypeUnderTest: "cc_library_static",
404 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
405 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
406 filesystem: map[string]string{
407 // subpackage with subdirectory
408 "subpackage/Android.bp": "",
409 "subpackage/subpackage_header.h": "",
410 "subpackage2/Android.bp": "",
411 "subpackage2/subpackage2_header.h": "",
412 "subpackage/subdirectory/subdirectory_header.h": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000413 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200414 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chened9c17d2021-04-13 07:14:55 +0000415cc_library_static {
416 name: "foo_static",
417 include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended
418 local_include_dirs: ["subpackage2"],
419 include_build_directory: true,
420}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200421 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000422 name = "foo_static",
423 copts = [
424 "-Isubpackage",
Chris Parsons484e50a2021-05-13 15:13:04 -0400425 "-I$(BINDIR)/subpackage",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000426 "-Isubpackage2",
Chris Parsons484e50a2021-05-13 15:13:04 -0400427 "-I$(BINDIR)/subpackage2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000428 "-I.",
Chris Parsons484e50a2021-05-13 15:13:04 -0400429 "-I$(BINDIR)/.",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000430 ],
431 linkstatic = True,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000432)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200433 })
434}
435
436func TestCcLibraryStaticArchSpecificStaticLib(t *testing.T) {
437 runCcLibraryStaticTestCase(t, bp2buildTestCase{
438 description: "cc_library_static arch-specific static_libs",
439 moduleTypeUnderTest: "cc_library_static",
440 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
441 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200442 filesystem: map[string]string{},
443 blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -0400444cc_library_static {
445 name: "static_dep",
446 bazel_module: { bp2build_available: false },
447}
448cc_library_static {
449 name: "static_dep2",
450 bazel_module: { bp2build_available: false },
451}
Jingwen Chened9c17d2021-04-13 07:14:55 +0000452cc_library_static {
453 name: "foo_static",
454 arch: { arm64: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } },
Liz Kammer8337ea42021-09-10 10:06:32 -0400455 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000456}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200457 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000458 name = "foo_static",
Chris Parsonsd6358772021-05-18 18:35:24 -0400459 implementation_deps = select({
Chris Parsons08648312021-05-06 16:23:19 -0400460 "//build/bazel/platforms/arch:arm64": [":static_dep"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000461 "//conditions:default": [],
462 }),
463 linkstatic = True,
Chris Parsons08648312021-05-06 16:23:19 -0400464 whole_archive_deps = select({
465 "//build/bazel/platforms/arch:arm64": [":static_dep2"],
466 "//conditions:default": [],
467 }),
Jingwen Chened9c17d2021-04-13 07:14:55 +0000468)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200469 })
470}
471
472func TestCcLibraryStaticOsSpecificStaticLib(t *testing.T) {
473 runCcLibraryStaticTestCase(t, bp2buildTestCase{
474 description: "cc_library_static os-specific static_libs",
475 moduleTypeUnderTest: "cc_library_static",
476 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
477 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200478 filesystem: map[string]string{},
479 blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -0400480cc_library_static {
481 name: "static_dep",
482 bazel_module: { bp2build_available: false },
483}
484cc_library_static {
485 name: "static_dep2",
486 bazel_module: { bp2build_available: false },
487}
Jingwen Chened9c17d2021-04-13 07:14:55 +0000488cc_library_static {
489 name: "foo_static",
490 target: { android: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } },
Liz Kammer8337ea42021-09-10 10:06:32 -0400491 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000492}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200493 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000494 name = "foo_static",
Chris Parsonsd6358772021-05-18 18:35:24 -0400495 implementation_deps = select({
Chris Parsons08648312021-05-06 16:23:19 -0400496 "//build/bazel/platforms/os:android": [":static_dep"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000497 "//conditions:default": [],
498 }),
499 linkstatic = True,
Chris Parsons08648312021-05-06 16:23:19 -0400500 whole_archive_deps = select({
501 "//build/bazel/platforms/os:android": [":static_dep2"],
502 "//conditions:default": [],
503 }),
Jingwen Chened9c17d2021-04-13 07:14:55 +0000504)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200505 })
506}
507
508func TestCcLibraryStaticBaseArchOsSpecificStaticLib(t *testing.T) {
509 runCcLibraryStaticTestCase(t, bp2buildTestCase{
510 description: "cc_library_static base, arch and os-specific static_libs",
511 moduleTypeUnderTest: "cc_library_static",
512 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
513 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200514 filesystem: map[string]string{},
515 blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -0400516cc_library_static {
517 name: "static_dep",
518 bazel_module: { bp2build_available: false },
519}
520cc_library_static {
521 name: "static_dep2",
522 bazel_module: { bp2build_available: false },
523}
524cc_library_static {
525 name: "static_dep3",
526 bazel_module: { bp2build_available: false },
527}
528cc_library_static {
529 name: "static_dep4",
530 bazel_module: { bp2build_available: false },
531}
Jingwen Chened9c17d2021-04-13 07:14:55 +0000532cc_library_static {
533 name: "foo_static",
534 static_libs: ["static_dep"],
535 whole_static_libs: ["static_dep2"],
536 target: { android: { static_libs: ["static_dep3"] } },
537 arch: { arm64: { static_libs: ["static_dep4"] } },
Liz Kammer8337ea42021-09-10 10:06:32 -0400538 include_build_directory: false,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000539}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200540 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chened9c17d2021-04-13 07:14:55 +0000541 name = "foo_static",
Chris Parsonsd6358772021-05-18 18:35:24 -0400542 implementation_deps = [":static_dep"] + select({
Jingwen Chened9c17d2021-04-13 07:14:55 +0000543 "//build/bazel/platforms/arch:arm64": [":static_dep4"],
544 "//conditions:default": [],
545 }) + select({
546 "//build/bazel/platforms/os:android": [":static_dep3"],
547 "//conditions:default": [],
548 }),
549 linkstatic = True,
Chris Parsons08648312021-05-06 16:23:19 -0400550 whole_archive_deps = [":static_dep2"],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000551)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200552 })
553}
554
555func TestCcLibraryStaticSimpleExcludeSrcs(t *testing.T) {
556 runCcLibraryStaticTestCase(t, bp2buildTestCase{
557 description: "cc_library_static simple exclude_srcs",
558 moduleTypeUnderTest: "cc_library_static",
559 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
560 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200561 filesystem: map[string]string{
562 "common.c": "",
563 "foo-a.c": "",
564 "foo-excluded.c": "",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000565 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200566 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000567cc_library_static {
568 name: "foo_static",
569 srcs: ["common.c", "foo-*.c"],
570 exclude_srcs: ["foo-excluded.c"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400571 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000572}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200573 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000574 name = "foo_static",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000575 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400576 srcs_c = [
Jingwen Chene32e9e02021-04-23 09:17:24 +0000577 "common.c",
578 "foo-a.c",
579 ],
580)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200581 })
582}
583
584func TestCcLibraryStaticOneArchSrcs(t *testing.T) {
585 runCcLibraryStaticTestCase(t, bp2buildTestCase{
586 description: "cc_library_static one arch specific srcs",
587 moduleTypeUnderTest: "cc_library_static",
588 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
589 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200590 filesystem: map[string]string{
591 "common.c": "",
592 "foo-arm.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000593 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200594 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000595cc_library_static {
596 name: "foo_static",
597 srcs: ["common.c"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400598 arch: { arm: { srcs: ["foo-arm.c"] } },
599 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000600}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200601 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000602 name = "foo_static",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000603 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400604 srcs_c = ["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000605 "//build/bazel/platforms/arch:arm": ["foo-arm.c"],
606 "//conditions:default": [],
607 }),
608)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200609 })
610}
611
612func TestCcLibraryStaticOneArchSrcsExcludeSrcs(t *testing.T) {
613 runCcLibraryStaticTestCase(t, bp2buildTestCase{
614 description: "cc_library_static one arch specific srcs and exclude_srcs",
615 moduleTypeUnderTest: "cc_library_static",
616 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
617 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200618 filesystem: map[string]string{
619 "common.c": "",
620 "for-arm.c": "",
621 "not-for-arm.c": "",
622 "not-for-anything.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000623 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200624 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000625cc_library_static {
626 name: "foo_static",
627 srcs: ["common.c", "not-for-*.c"],
628 exclude_srcs: ["not-for-anything.c"],
629 arch: {
630 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
631 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400632 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000633}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200634 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000635 name = "foo_static",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000636 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400637 srcs_c = ["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000638 "//build/bazel/platforms/arch:arm": ["for-arm.c"],
639 "//conditions:default": ["not-for-arm.c"],
640 }),
641)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200642 })
643}
644
645func TestCcLibraryStaticTwoArchExcludeSrcs(t *testing.T) {
646 runCcLibraryStaticTestCase(t, bp2buildTestCase{
647 description: "cc_library_static arch specific exclude_srcs for 2 architectures",
648 moduleTypeUnderTest: "cc_library_static",
649 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
650 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200651 filesystem: map[string]string{
652 "common.c": "",
653 "for-arm.c": "",
654 "for-x86.c": "",
655 "not-for-arm.c": "",
656 "not-for-x86.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000657 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200658 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000659cc_library_static {
660 name: "foo_static",
661 srcs: ["common.c", "not-for-*.c"],
662 exclude_srcs: ["not-for-everything.c"],
663 arch: {
664 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
665 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
666 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400667 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000668} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200669 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000670 name = "foo_static",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000671 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400672 srcs_c = ["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000673 "//build/bazel/platforms/arch:arm": [
674 "for-arm.c",
675 "not-for-x86.c",
676 ],
677 "//build/bazel/platforms/arch:x86": [
678 "for-x86.c",
679 "not-for-arm.c",
680 ],
681 "//conditions:default": [
682 "not-for-arm.c",
683 "not-for-x86.c",
684 ],
685 }),
686)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200687 })
688}
689func TestCcLibraryStaticFourArchExcludeSrcs(t *testing.T) {
690 runCcLibraryStaticTestCase(t, bp2buildTestCase{
691 description: "cc_library_static arch specific exclude_srcs for 4 architectures",
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 "for-arm64.c": "",
699 "for-x86.c": "",
700 "for-x86_64.c": "",
701 "not-for-arm.c": "",
702 "not-for-arm64.c": "",
703 "not-for-x86.c": "",
704 "not-for-x86_64.c": "",
705 "not-for-everything.c": "",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000706 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200707 blueprint: soongCcLibraryStaticPreamble + `
Jingwen Chene32e9e02021-04-23 09:17:24 +0000708cc_library_static {
709 name: "foo_static",
710 srcs: ["common.c", "not-for-*.c"],
711 exclude_srcs: ["not-for-everything.c"],
712 arch: {
713 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
714 arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] },
715 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
716 x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] },
Liz Kammer8337ea42021-09-10 10:06:32 -0400717 },
718 include_build_directory: false,
Jingwen Chene32e9e02021-04-23 09:17:24 +0000719} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200720 expectedBazelTargets: []string{`cc_library_static(
Jingwen Chene32e9e02021-04-23 09:17:24 +0000721 name = "foo_static",
Jingwen Chene32e9e02021-04-23 09:17:24 +0000722 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400723 srcs_c = ["common.c"] + select({
Jingwen Chene32e9e02021-04-23 09:17:24 +0000724 "//build/bazel/platforms/arch:arm": [
725 "for-arm.c",
726 "not-for-arm64.c",
727 "not-for-x86.c",
728 "not-for-x86_64.c",
729 ],
730 "//build/bazel/platforms/arch:arm64": [
731 "for-arm64.c",
732 "not-for-arm.c",
733 "not-for-x86.c",
734 "not-for-x86_64.c",
735 ],
736 "//build/bazel/platforms/arch:x86": [
737 "for-x86.c",
738 "not-for-arm.c",
739 "not-for-arm64.c",
740 "not-for-x86_64.c",
741 ],
742 "//build/bazel/platforms/arch:x86_64": [
743 "for-x86_64.c",
744 "not-for-arm.c",
745 "not-for-arm64.c",
746 "not-for-x86.c",
747 ],
748 "//conditions:default": [
749 "not-for-arm.c",
750 "not-for-arm64.c",
751 "not-for-x86.c",
752 "not-for-x86_64.c",
753 ],
754 }),
755)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200756 })
757}
758
Liz Kammer2b07ec72021-05-26 15:08:27 -0400759func TestCcLibraryStaticOneArchEmpty(t *testing.T) {
760 runCcLibraryStaticTestCase(t, bp2buildTestCase{
761 description: "cc_library_static one arch empty",
762 moduleTypeUnderTest: "cc_library_static",
763 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
764 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammer2b07ec72021-05-26 15:08:27 -0400765 filesystem: map[string]string{
766 "common.cc": "",
767 "foo-no-arm.cc": "",
768 "foo-excluded.cc": "",
769 },
770 blueprint: soongCcLibraryStaticPreamble + `
771cc_library_static {
772 name: "foo_static",
773 srcs: ["common.cc", "foo-*.cc"],
774 exclude_srcs: ["foo-excluded.cc"],
775 arch: {
776 arm: { exclude_srcs: ["foo-no-arm.cc"] },
777 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400778 include_build_directory: false,
Liz Kammer2b07ec72021-05-26 15:08:27 -0400779}`,
780 expectedBazelTargets: []string{`cc_library_static(
781 name = "foo_static",
Liz Kammer2b07ec72021-05-26 15:08:27 -0400782 linkstatic = True,
783 srcs = ["common.cc"] + select({
784 "//build/bazel/platforms/arch:arm": [],
785 "//conditions:default": ["foo-no-arm.cc"],
786 }),
787)`},
788 })
789}
790
791func TestCcLibraryStaticOneArchEmptyOtherSet(t *testing.T) {
792 runCcLibraryStaticTestCase(t, bp2buildTestCase{
793 description: "cc_library_static one arch empty other set",
794 moduleTypeUnderTest: "cc_library_static",
795 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
796 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammer2b07ec72021-05-26 15:08:27 -0400797 filesystem: map[string]string{
798 "common.cc": "",
799 "foo-no-arm.cc": "",
800 "x86-only.cc": "",
801 "foo-excluded.cc": "",
802 },
803 blueprint: soongCcLibraryStaticPreamble + `
804cc_library_static {
805 name: "foo_static",
806 srcs: ["common.cc", "foo-*.cc"],
807 exclude_srcs: ["foo-excluded.cc"],
808 arch: {
809 arm: { exclude_srcs: ["foo-no-arm.cc"] },
810 x86: { srcs: ["x86-only.cc"] },
811 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400812 include_build_directory: false,
Liz Kammer2b07ec72021-05-26 15:08:27 -0400813}`,
814 expectedBazelTargets: []string{`cc_library_static(
815 name = "foo_static",
Liz Kammer2b07ec72021-05-26 15:08:27 -0400816 linkstatic = True,
817 srcs = ["common.cc"] + select({
818 "//build/bazel/platforms/arch:arm": [],
819 "//build/bazel/platforms/arch:x86": [
820 "foo-no-arm.cc",
821 "x86-only.cc",
822 ],
823 "//conditions:default": ["foo-no-arm.cc"],
824 }),
825)`},
826 })
827}
828
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200829func TestCcLibraryStaticMultipleDepSameName(t *testing.T) {
830 runCcLibraryStaticTestCase(t, bp2buildTestCase{
831 description: "cc_library_static multiple dep same name panic",
832 moduleTypeUnderTest: "cc_library_static",
833 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
834 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200835 filesystem: map[string]string{},
836 blueprint: soongCcLibraryStaticPreamble + `
Liz Kammer8337ea42021-09-10 10:06:32 -0400837cc_library_static {
838 name: "static_dep",
839 bazel_module: { bp2build_available: false },
840}
Liz Kammer2b50ce62021-04-26 15:47:28 -0400841cc_library_static {
842 name: "foo_static",
Chris Parsons08648312021-05-06 16:23:19 -0400843 static_libs: ["static_dep", "static_dep"],
Liz Kammer8337ea42021-09-10 10:06:32 -0400844 include_build_directory: false,
Liz Kammer2b50ce62021-04-26 15:47:28 -0400845}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200846 expectedBazelTargets: []string{`cc_library_static(
Liz Kammer2b50ce62021-04-26 15:47:28 -0400847 name = "foo_static",
Chris Parsonsd6358772021-05-18 18:35:24 -0400848 implementation_deps = [":static_dep"],
Liz Kammer2b50ce62021-04-26 15:47:28 -0400849 linkstatic = True,
Liz Kammer2b50ce62021-04-26 15:47:28 -0400850)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200851 })
852}
853
854func TestCcLibraryStaticOneMultilibSrcsExcludeSrcs(t *testing.T) {
855 runCcLibraryStaticTestCase(t, bp2buildTestCase{
856 description: "cc_library_static 1 multilib srcs and exclude_srcs",
857 moduleTypeUnderTest: "cc_library_static",
858 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
859 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200860 filesystem: map[string]string{
861 "common.c": "",
862 "for-lib32.c": "",
863 "not-for-lib32.c": "",
Liz Kammer2b50ce62021-04-26 15:47:28 -0400864 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200865 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -0400866cc_library_static {
867 name: "foo_static",
868 srcs: ["common.c", "not-for-*.c"],
869 multilib: {
870 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
871 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400872 include_build_directory: false,
Chris Parsonsc424b762021-04-29 18:06:50 -0400873} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200874 expectedBazelTargets: []string{`cc_library_static(
Chris Parsonsc424b762021-04-29 18:06:50 -0400875 name = "foo_static",
Chris Parsonsc424b762021-04-29 18:06:50 -0400876 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400877 srcs_c = ["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -0400878 "//build/bazel/platforms/arch:arm": ["for-lib32.c"],
879 "//build/bazel/platforms/arch:x86": ["for-lib32.c"],
880 "//conditions:default": ["not-for-lib32.c"],
881 }),
882)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200883 })
884}
885
886func TestCcLibraryStaticTwoMultilibSrcsExcludeSrcs(t *testing.T) {
887 runCcLibraryStaticTestCase(t, bp2buildTestCase{
888 description: "cc_library_static 2 multilib srcs and exclude_srcs",
889 moduleTypeUnderTest: "cc_library_static",
890 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
891 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200892 filesystem: map[string]string{
893 "common.c": "",
894 "for-lib32.c": "",
895 "for-lib64.c": "",
896 "not-for-lib32.c": "",
897 "not-for-lib64.c": "",
Chris Parsonsc424b762021-04-29 18:06:50 -0400898 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200899 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -0400900cc_library_static {
901 name: "foo_static2",
902 srcs: ["common.c", "not-for-*.c"],
903 multilib: {
904 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
905 lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] },
906 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400907 include_build_directory: false,
Chris Parsonsc424b762021-04-29 18:06:50 -0400908} `,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200909 expectedBazelTargets: []string{`cc_library_static(
Chris Parsonsc424b762021-04-29 18:06:50 -0400910 name = "foo_static2",
Chris Parsonsc424b762021-04-29 18:06:50 -0400911 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400912 srcs_c = ["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -0400913 "//build/bazel/platforms/arch:arm": [
914 "for-lib32.c",
915 "not-for-lib64.c",
916 ],
917 "//build/bazel/platforms/arch:arm64": [
918 "for-lib64.c",
919 "not-for-lib32.c",
920 ],
921 "//build/bazel/platforms/arch:x86": [
922 "for-lib32.c",
923 "not-for-lib64.c",
924 ],
925 "//build/bazel/platforms/arch:x86_64": [
926 "for-lib64.c",
927 "not-for-lib32.c",
928 ],
929 "//conditions:default": [
930 "not-for-lib32.c",
931 "not-for-lib64.c",
932 ],
933 }),
934)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200935 })
936}
937
938func TestCcLibrarySTaticArchMultilibSrcsExcludeSrcs(t *testing.T) {
939 runCcLibraryStaticTestCase(t, bp2buildTestCase{
940 description: "cc_library_static arch and multilib srcs and exclude_srcs",
941 moduleTypeUnderTest: "cc_library_static",
942 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
943 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200944 filesystem: map[string]string{
945 "common.c": "",
946 "for-arm.c": "",
947 "for-arm64.c": "",
948 "for-x86.c": "",
949 "for-x86_64.c": "",
950 "for-lib32.c": "",
951 "for-lib64.c": "",
952 "not-for-arm.c": "",
953 "not-for-arm64.c": "",
954 "not-for-x86.c": "",
955 "not-for-x86_64.c": "",
956 "not-for-lib32.c": "",
957 "not-for-lib64.c": "",
958 "not-for-everything.c": "",
Chris Parsonsc424b762021-04-29 18:06:50 -0400959 },
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200960 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsonsc424b762021-04-29 18:06:50 -0400961cc_library_static {
962 name: "foo_static3",
963 srcs: ["common.c", "not-for-*.c"],
964 exclude_srcs: ["not-for-everything.c"],
965 arch: {
966 arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
967 arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] },
968 x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
969 x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] },
970 },
971 multilib: {
972 lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
973 lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] },
974 },
Liz Kammer8337ea42021-09-10 10:06:32 -0400975 include_build_directory: false,
Chris Parsonsc424b762021-04-29 18:06:50 -0400976}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +0200977 expectedBazelTargets: []string{`cc_library_static(
Chris Parsonsc424b762021-04-29 18:06:50 -0400978 name = "foo_static3",
Chris Parsonsc424b762021-04-29 18:06:50 -0400979 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -0400980 srcs_c = ["common.c"] + select({
Chris Parsonsc424b762021-04-29 18:06:50 -0400981 "//build/bazel/platforms/arch:arm": [
982 "for-arm.c",
983 "for-lib32.c",
984 "not-for-arm64.c",
985 "not-for-lib64.c",
986 "not-for-x86.c",
987 "not-for-x86_64.c",
988 ],
989 "//build/bazel/platforms/arch:arm64": [
990 "for-arm64.c",
991 "for-lib64.c",
992 "not-for-arm.c",
993 "not-for-lib32.c",
994 "not-for-x86.c",
995 "not-for-x86_64.c",
996 ],
997 "//build/bazel/platforms/arch:x86": [
998 "for-lib32.c",
999 "for-x86.c",
1000 "not-for-arm.c",
1001 "not-for-arm64.c",
1002 "not-for-lib64.c",
1003 "not-for-x86_64.c",
1004 ],
1005 "//build/bazel/platforms/arch:x86_64": [
1006 "for-lib64.c",
1007 "for-x86_64.c",
1008 "not-for-arm.c",
1009 "not-for-arm64.c",
1010 "not-for-lib32.c",
1011 "not-for-x86.c",
1012 ],
1013 "//conditions:default": [
1014 "not-for-arm.c",
1015 "not-for-arm64.c",
1016 "not-for-lib32.c",
1017 "not-for-lib64.c",
1018 "not-for-x86.c",
1019 "not-for-x86_64.c",
1020 ],
1021 }),
1022)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001023 })
1024}
1025
1026func TestCcLibraryStaticArchSrcsExcludeSrcsGeneratedFiles(t *testing.T) {
1027 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1028 description: "cc_library_static arch srcs/exclude_srcs with generated files",
1029 moduleTypeUnderTest: "cc_library_static",
1030 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1031 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001032 filesystem: map[string]string{
Chris Parsons990c4f42021-05-25 12:10:58 -04001033 "common.cpp": "",
1034 "for-x86.cpp": "",
1035 "not-for-x86.cpp": "",
1036 "not-for-everything.cpp": "",
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001037 "dep/Android.bp": `
Chris Parsons484e50a2021-05-13 15:13:04 -04001038genrule {
Liz Kammer8337ea42021-09-10 10:06:32 -04001039 name: "generated_src_other_pkg",
1040 out: ["generated_src_other_pkg.cpp"],
1041 cmd: "nothing to see here",
Chris Parsons484e50a2021-05-13 15:13:04 -04001042}
1043
1044genrule {
Liz Kammer8337ea42021-09-10 10:06:32 -04001045 name: "generated_hdr_other_pkg",
1046 out: ["generated_hdr_other_pkg.cpp"],
1047 cmd: "nothing to see here",
Chris Parsons484e50a2021-05-13 15:13:04 -04001048}
1049
1050genrule {
Liz Kammer8337ea42021-09-10 10:06:32 -04001051 name: "generated_hdr_other_pkg_x86",
1052 out: ["generated_hdr_other_pkg_x86.cpp"],
1053 cmd: "nothing to see here",
Chris Parsons484e50a2021-05-13 15:13:04 -04001054}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001055 },
1056 blueprint: soongCcLibraryStaticPreamble + `
Chris Parsons484e50a2021-05-13 15:13:04 -04001057genrule {
1058 name: "generated_src",
1059 out: ["generated_src.cpp"],
1060 cmd: "nothing to see here",
1061}
1062
1063genrule {
1064 name: "generated_src_x86",
1065 out: ["generated_src_x86.cpp"],
1066 cmd: "nothing to see here",
1067}
1068
1069genrule {
1070 name: "generated_hdr",
1071 out: ["generated_hdr.h"],
1072 cmd: "nothing to see here",
1073}
1074
1075cc_library_static {
1076 name: "foo_static3",
Chris Parsons990c4f42021-05-25 12:10:58 -04001077 srcs: ["common.cpp", "not-for-*.cpp"],
1078 exclude_srcs: ["not-for-everything.cpp"],
Chris Parsons484e50a2021-05-13 15:13:04 -04001079 generated_sources: ["generated_src", "generated_src_other_pkg"],
1080 generated_headers: ["generated_hdr", "generated_hdr_other_pkg"],
1081 arch: {
1082 x86: {
Chris Parsons990c4f42021-05-25 12:10:58 -04001083 srcs: ["for-x86.cpp"],
1084 exclude_srcs: ["not-for-x86.cpp"],
Chris Parsons484e50a2021-05-13 15:13:04 -04001085 generated_sources: ["generated_src_x86"],
1086 generated_headers: ["generated_hdr_other_pkg_x86"],
1087 },
1088 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001089 include_build_directory: false,
Chris Parsons484e50a2021-05-13 15:13:04 -04001090}
1091`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001092 expectedBazelTargets: []string{`cc_library_static(
Chris Parsons484e50a2021-05-13 15:13:04 -04001093 name = "foo_static3",
Chris Parsons484e50a2021-05-13 15:13:04 -04001094 linkstatic = True,
1095 srcs = [
1096 "//dep:generated_hdr_other_pkg",
1097 "//dep:generated_src_other_pkg",
1098 ":generated_hdr",
1099 ":generated_src",
Chris Parsons990c4f42021-05-25 12:10:58 -04001100 "common.cpp",
Chris Parsons484e50a2021-05-13 15:13:04 -04001101 ] + select({
1102 "//build/bazel/platforms/arch:x86": [
1103 "//dep:generated_hdr_other_pkg_x86",
1104 ":generated_src_x86",
Chris Parsons990c4f42021-05-25 12:10:58 -04001105 "for-x86.cpp",
Chris Parsons484e50a2021-05-13 15:13:04 -04001106 ],
Chris Parsons990c4f42021-05-25 12:10:58 -04001107 "//conditions:default": ["not-for-x86.cpp"],
Chris Parsons484e50a2021-05-13 15:13:04 -04001108 }),
1109)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +02001110 })
Rupert Shuttleworth095081c2021-03-25 09:06:03 +00001111}
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001112
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001113func TestCcLibraryStaticGetTargetProperties(t *testing.T) {
1114 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1115
1116 description: "cc_library_static complex GetTargetProperties",
1117 moduleTypeUnderTest: "cc_library_static",
1118 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1119 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001120 blueprint: soongCcLibraryStaticPreamble + `
1121cc_library_static {
1122 name: "foo_static",
1123 target: {
1124 android: {
1125 srcs: ["android_src.c"],
1126 },
1127 android_arm: {
1128 srcs: ["android_arm_src.c"],
1129 },
1130 android_arm64: {
1131 srcs: ["android_arm64_src.c"],
1132 },
1133 android_x86: {
1134 srcs: ["android_x86_src.c"],
1135 },
1136 android_x86_64: {
1137 srcs: ["android_x86_64_src.c"],
1138 },
1139 linux_bionic_arm64: {
1140 srcs: ["linux_bionic_arm64_src.c"],
1141 },
1142 linux_bionic_x86_64: {
1143 srcs: ["linux_bionic_x86_64_src.c"],
1144 },
1145 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001146 include_build_directory: false,
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001147}`,
1148 expectedBazelTargets: []string{`cc_library_static(
1149 name = "foo_static",
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001150 linkstatic = True,
1151 srcs_c = select({
1152 "//build/bazel/platforms/os:android": ["android_src.c"],
1153 "//conditions:default": [],
1154 }) + select({
Rupert Shuttleworthffd45822021-05-14 03:02:34 -04001155 "//build/bazel/platforms/os_arch:android_arm": ["android_arm_src.c"],
1156 "//build/bazel/platforms/os_arch:android_arm64": ["android_arm64_src.c"],
1157 "//build/bazel/platforms/os_arch:android_x86": ["android_x86_src.c"],
1158 "//build/bazel/platforms/os_arch:android_x86_64": ["android_x86_64_src.c"],
Rupert Shuttleworthffd45822021-05-14 03:02:34 -04001159 "//build/bazel/platforms/os_arch:linux_bionic_arm64": ["linux_bionic_arm64_src.c"],
1160 "//build/bazel/platforms/os_arch:linux_bionic_x86_64": ["linux_bionic_x86_64_src.c"],
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -04001161 "//conditions:default": [],
1162 }),
1163)`},
1164 })
1165}
1166
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001167func TestCcLibraryStaticProductVariableSelects(t *testing.T) {
1168 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1169 description: "cc_library_static product variable selects",
1170 moduleTypeUnderTest: "cc_library_static",
1171 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1172 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001173 blueprint: soongCcLibraryStaticPreamble + `
1174cc_library_static {
1175 name: "foo_static",
1176 srcs: ["common.c"],
1177 product_variables: {
1178 malloc_not_svelte: {
1179 cflags: ["-Wmalloc_not_svelte"],
1180 },
1181 malloc_zero_contents: {
1182 cflags: ["-Wmalloc_zero_contents"],
1183 },
1184 binder32bit: {
1185 cflags: ["-Wbinder32bit"],
1186 },
1187 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001188 include_build_directory: false,
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001189} `,
1190 expectedBazelTargets: []string{`cc_library_static(
1191 name = "foo_static",
Liz Kammer8337ea42021-09-10 10:06:32 -04001192 copts = select({
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001193 "//build/bazel/product_variables:binder32bit": ["-Wbinder32bit"],
1194 "//conditions:default": [],
1195 }) + select({
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001196 "//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"],
1197 "//conditions:default": [],
1198 }) + select({
1199 "//build/bazel/product_variables:malloc_zero_contents": ["-Wmalloc_zero_contents"],
1200 "//conditions:default": [],
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001201 }),
1202 linkstatic = True,
Chris Parsons990c4f42021-05-25 12:10:58 -04001203 srcs_c = ["common.c"],
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001204)`},
1205 })
1206}
1207
1208func TestCcLibraryStaticProductVariableArchSpecificSelects(t *testing.T) {
1209 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1210 description: "cc_library_static arch-specific product variable selects",
1211 moduleTypeUnderTest: "cc_library_static",
1212 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1213 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001214 filesystem: map[string]string{},
1215 blueprint: soongCcLibraryStaticPreamble + `
1216cc_library_static {
1217 name: "foo_static",
1218 srcs: ["common.c"],
1219 product_variables: {
1220 malloc_not_svelte: {
1221 cflags: ["-Wmalloc_not_svelte"],
1222 },
1223 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001224 arch: {
1225 arm64: {
1226 product_variables: {
1227 malloc_not_svelte: {
1228 cflags: ["-Warm64_malloc_not_svelte"],
1229 },
1230 },
1231 },
1232 },
1233 multilib: {
1234 lib32: {
1235 product_variables: {
1236 malloc_not_svelte: {
1237 cflags: ["-Wlib32_malloc_not_svelte"],
1238 },
1239 },
1240 },
1241 },
1242 target: {
1243 android: {
1244 product_variables: {
1245 malloc_not_svelte: {
1246 cflags: ["-Wandroid_malloc_not_svelte"],
1247 },
1248 },
1249 }
1250 },
1251 include_build_directory: false,
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001252} `,
1253 expectedBazelTargets: []string{`cc_library_static(
1254 name = "foo_static",
Liz Kammer8337ea42021-09-10 10:06:32 -04001255 copts = select({
Liz Kammere3e4a5f2021-05-10 11:39:53 -04001256 "//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,
Chris Parsons990c4f42021-05-25 12:10:58 -04001272 srcs_c = ["common.c"],
Liz Kammer6fd7b3f2021-05-06 13:54:29 -04001273)`},
1274 })
1275}
Liz Kammerba7a9c52021-05-26 08:45:30 -04001276
1277func TestCcLibraryStaticProductVariableStringReplacement(t *testing.T) {
1278 runCcLibraryStaticTestCase(t, bp2buildTestCase{
Chris Parsons69fa9f92021-07-13 11:47:44 -04001279 description: "cc_library_static product variable string replacement",
Liz Kammerba7a9c52021-05-26 08:45:30 -04001280 moduleTypeUnderTest: "cc_library_static",
1281 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1282 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
Liz Kammerba7a9c52021-05-26 08:45:30 -04001283 filesystem: map[string]string{},
1284 blueprint: soongCcLibraryStaticPreamble + `
1285cc_library_static {
1286 name: "foo_static",
Chris Parsons69fa9f92021-07-13 11:47:44 -04001287 srcs: ["common.S"],
Liz Kammerba7a9c52021-05-26 08:45:30 -04001288 product_variables: {
1289 platform_sdk_version: {
1290 asflags: ["-DPLATFORM_SDK_VERSION=%d"],
1291 },
1292 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001293 include_build_directory: false,
Liz Kammerba7a9c52021-05-26 08:45:30 -04001294} `,
1295 expectedBazelTargets: []string{`cc_library_static(
1296 name = "foo_static",
Liz Kammer8337ea42021-09-10 10:06:32 -04001297 asflags = select({
Liz Kammerba7a9c52021-05-26 08:45:30 -04001298 "//build/bazel/product_variables:platform_sdk_version": ["-DPLATFORM_SDK_VERSION=$(Platform_sdk_version)"],
1299 "//conditions:default": [],
1300 }),
Liz Kammerba7a9c52021-05-26 08:45:30 -04001301 linkstatic = True,
Chris Parsons69fa9f92021-07-13 11:47:44 -04001302 srcs_as = ["common.S"],
Liz Kammerba7a9c52021-05-26 08:45:30 -04001303)`},
1304 })
1305}
Chris Parsons51f8c392021-08-03 21:01:05 -04001306
1307func TestStaticLibrary_SystemSharedLibsRootEmpty(t *testing.T) {
1308 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1309 description: "cc_library_static system_shared_lib empty root",
1310 moduleTypeUnderTest: "cc_library_static",
1311 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1312 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1313 blueprint: soongCcLibraryStaticPreamble + `
1314cc_library_static {
1315 name: "root_empty",
Liz Kammer8337ea42021-09-10 10:06:32 -04001316 system_shared_libs: [],
1317 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001318}
1319`,
1320 expectedBazelTargets: []string{`cc_library_static(
1321 name = "root_empty",
Chris Parsons51f8c392021-08-03 21:01:05 -04001322 linkstatic = True,
1323 system_dynamic_deps = [],
1324)`},
1325 })
1326}
1327
1328func TestStaticLibrary_SystemSharedLibsStaticEmpty(t *testing.T) {
1329 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1330 description: "cc_library_static system_shared_lib empty static default",
1331 moduleTypeUnderTest: "cc_library_static",
1332 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1333 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1334 blueprint: soongCcLibraryStaticPreamble + `
1335cc_defaults {
1336 name: "static_empty_defaults",
1337 static: {
Liz Kammer8337ea42021-09-10 10:06:32 -04001338 system_shared_libs: [],
1339 },
1340 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001341}
1342cc_library_static {
1343 name: "static_empty",
Liz Kammer8337ea42021-09-10 10:06:32 -04001344 defaults: ["static_empty_defaults"],
Chris Parsons51f8c392021-08-03 21:01:05 -04001345}
1346`,
1347 expectedBazelTargets: []string{`cc_library_static(
1348 name = "static_empty",
Chris Parsons51f8c392021-08-03 21:01:05 -04001349 linkstatic = True,
1350 system_dynamic_deps = [],
1351)`},
1352 })
1353}
1354
1355func TestStaticLibrary_SystemSharedLibsBionicEmpty(t *testing.T) {
1356 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1357 description: "cc_library_static system_shared_lib empty for bionic variant",
1358 moduleTypeUnderTest: "cc_library_static",
1359 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1360 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1361 blueprint: soongCcLibraryStaticPreamble + `
1362cc_library_static {
1363 name: "target_bionic_empty",
1364 target: {
1365 bionic: {
1366 system_shared_libs: [],
1367 },
1368 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001369 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001370}
1371`,
1372 expectedBazelTargets: []string{`cc_library_static(
1373 name = "target_bionic_empty",
Chris Parsons51f8c392021-08-03 21:01:05 -04001374 linkstatic = True,
1375 system_dynamic_deps = [],
1376)`},
1377 })
1378}
1379
1380func TestStaticLibrary_SystemSharedLibsLinuxBionicEmpty(t *testing.T) {
1381 // Note that this behavior is technically incorrect (it's a simplification).
1382 // The correct behavior would be if bp2build wrote `system_dynamic_deps = []`
1383 // only for linux_bionic, but `android` had `["libc", "libdl", "libm"].
1384 // b/195791252 tracks the fix.
1385 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1386 description: "cc_library_static system_shared_lib empty for linux_bionic variant",
1387 moduleTypeUnderTest: "cc_library_static",
1388 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1389 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1390 blueprint: soongCcLibraryStaticPreamble + `
1391cc_library_static {
1392 name: "target_linux_bionic_empty",
1393 target: {
1394 linux_bionic: {
1395 system_shared_libs: [],
1396 },
1397 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001398 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001399}
1400`,
1401 expectedBazelTargets: []string{`cc_library_static(
1402 name = "target_linux_bionic_empty",
Chris Parsons51f8c392021-08-03 21:01:05 -04001403 linkstatic = True,
1404 system_dynamic_deps = [],
1405)`},
1406 })
1407}
1408
1409func TestStaticLibrary_SystemSharedLibsBionic(t *testing.T) {
1410 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1411 description: "cc_library_static system_shared_libs set for bionic variant",
1412 moduleTypeUnderTest: "cc_library_static",
1413 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1414 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1415 blueprint: soongCcLibraryStaticPreamble + `
1416cc_library{name: "libc"}
1417
1418cc_library_static {
1419 name: "target_bionic",
1420 target: {
1421 bionic: {
1422 system_shared_libs: ["libc"],
1423 },
1424 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001425 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001426}
1427`,
1428 expectedBazelTargets: []string{`cc_library_static(
1429 name = "target_bionic",
Chris Parsons51f8c392021-08-03 21:01:05 -04001430 linkstatic = True,
1431 system_dynamic_deps = select({
1432 "//build/bazel/platforms/os:bionic": [":libc"],
1433 "//conditions:default": [],
1434 }),
1435)`},
1436 })
1437}
1438
1439func TestStaticLibrary_SystemSharedLibsLinuxRootAndLinuxBionic(t *testing.T) {
1440 runCcLibraryStaticTestCase(t, bp2buildTestCase{
1441 description: "cc_library_static system_shared_libs set for root and linux_bionic variant",
1442 moduleTypeUnderTest: "cc_library_static",
1443 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
1444 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
1445 blueprint: soongCcLibraryStaticPreamble + `
1446cc_library{name: "libc"}
1447cc_library{name: "libm"}
1448
1449cc_library_static {
1450 name: "target_linux_bionic",
Liz Kammer8337ea42021-09-10 10:06:32 -04001451 system_shared_libs: ["libc"],
Chris Parsons51f8c392021-08-03 21:01:05 -04001452 target: {
1453 linux_bionic: {
1454 system_shared_libs: ["libm"],
1455 },
1456 },
Liz Kammer8337ea42021-09-10 10:06:32 -04001457 include_build_directory: false,
Chris Parsons51f8c392021-08-03 21:01:05 -04001458}
1459`,
1460 expectedBazelTargets: []string{`cc_library_static(
1461 name = "target_linux_bionic",
Chris Parsons51f8c392021-08-03 21:01:05 -04001462 linkstatic = True,
1463 system_dynamic_deps = [":libc"] + select({
1464 "//build/bazel/platforms/os:linux_bionic": [":libm"],
1465 "//conditions:default": [],
1466 }),
1467)`},
1468 })
1469}