blob: 207a080e872defddddb4ae888cc6d080d9a95929 [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"
20 "strings"
21 "testing"
22)
23
24const (
25 // See cc/testing.go for more context
26 soongCcLibraryStaticPreamble = `
27cc_defaults {
28 name: "linux_bionic_supported",
29}
30
31toolchain_library {
32 name: "libclang_rt.builtins-x86_64-android",
33 defaults: ["linux_bionic_supported"],
34 vendor_available: true,
35 vendor_ramdisk_available: true,
36 product_available: true,
37 recovery_available: true,
38 native_bridge_supported: true,
39 src: "",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +000040}`
41)
42
43func TestCcLibraryStaticLoadStatement(t *testing.T) {
44 testCases := []struct {
45 bazelTargets BazelTargets
46 expectedLoadStatements string
47 }{
48 {
49 bazelTargets: BazelTargets{
50 BazelTarget{
51 name: "cc_library_static_target",
52 ruleClass: "cc_library_static",
53 // NOTE: No bzlLoadLocation for native rules
54 },
55 },
56 expectedLoadStatements: ``,
57 },
58 }
59
60 for _, testCase := range testCases {
61 actual := testCase.bazelTargets.LoadStatements()
62 expected := testCase.expectedLoadStatements
63 if actual != expected {
64 t.Fatalf("Expected load statements to be %s, got %s", expected, actual)
65 }
66 }
67
68}
69
70func TestCcLibraryStaticBp2Build(t *testing.T) {
71 testCases := []struct {
72 description string
73 moduleTypeUnderTest string
74 moduleTypeUnderTestFactory android.ModuleFactory
75 moduleTypeUnderTestBp2BuildMutator func(android.TopDownMutatorContext)
76 preArchMutators []android.RegisterMutatorFunc
77 depsMutators []android.RegisterMutatorFunc
78 bp string
79 expectedBazelTargets []string
80 filesystem map[string]string
81 dir string
82 }{
83 {
84 description: "cc_library_static test",
85 moduleTypeUnderTest: "cc_library_static",
86 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
87 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
88 filesystem: map[string]string{
89 // NOTE: include_dir headers *should not* appear in Bazel hdrs later (?)
90 "include_dir_1/include_dir_1_a.h": "",
91 "include_dir_1/include_dir_1_b.h": "",
92 "include_dir_2/include_dir_2_a.h": "",
93 "include_dir_2/include_dir_2_b.h": "",
94 // NOTE: local_include_dir headers *should not* appear in Bazel hdrs later (?)
95 "local_include_dir_1/local_include_dir_1_a.h": "",
96 "local_include_dir_1/local_include_dir_1_b.h": "",
97 "local_include_dir_2/local_include_dir_2_a.h": "",
98 "local_include_dir_2/local_include_dir_2_b.h": "",
99 // NOTE: export_include_dir headers *should* appear in Bazel hdrs later
100 "export_include_dir_1/export_include_dir_1_a.h": "",
101 "export_include_dir_1/export_include_dir_1_b.h": "",
102 "export_include_dir_2/export_include_dir_2_a.h": "",
103 "export_include_dir_2/export_include_dir_2_b.h": "",
Rupert Shuttleworthc58d3d22021-04-06 16:37:15 +0000104 // NOTE: Soong implicitly includes headers in the current directory
105 "implicit_include_1.h": "",
106 "implicit_include_2.h": "",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000107 },
108 bp: soongCcLibraryStaticPreamble + `
109cc_library_headers {
110 name: "header_lib_1",
111 export_include_dirs: ["header_lib_1"],
112}
113
114cc_library_headers {
115 name: "header_lib_2",
116 export_include_dirs: ["header_lib_2"],
117}
118
119cc_library_static {
120 name: "static_lib_1",
121 srcs: ["static_lib_1.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000122}
123
124cc_library_static {
125 name: "static_lib_2",
126 srcs: ["static_lib_2.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000127}
128
129cc_library_static {
130 name: "whole_static_lib_1",
131 srcs: ["whole_static_lib_1.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000132}
133
134cc_library_static {
135 name: "whole_static_lib_2",
136 srcs: ["whole_static_lib_2.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000137}
138
139cc_library_static {
140 name: "foo_static",
141 srcs: [
142 "foo_static1.cc",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000143 "foo_static2.cc",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000144 ],
145 cflags: [
146 "-Dflag1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000147 "-Dflag2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000148 ],
149 static_libs: [
150 "static_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000151 "static_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000152 ],
153 whole_static_libs: [
154 "whole_static_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000155 "whole_static_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000156 ],
157 include_dirs: [
Jingwen Chened9c17d2021-04-13 07:14:55 +0000158 "include_dir_1",
159 "include_dir_2",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000160 ],
161 local_include_dirs: [
162 "local_include_dir_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000163 "local_include_dir_2",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000164 ],
165 export_include_dirs: [
Jingwen Chened9c17d2021-04-13 07:14:55 +0000166 "export_include_dir_1",
167 "export_include_dir_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000168 ],
169 header_libs: [
170 "header_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000171 "header_lib_2"
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000172 ],
173
174 // TODO: Also support export_header_lib_headers
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000175}`,
176 expectedBazelTargets: []string{`cc_library_static(
177 name = "foo_static",
178 copts = [
179 "-Dflag1",
180 "-Dflag2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000181 "-Iinclude_dir_1",
182 "-Iinclude_dir_2",
183 "-Ilocal_include_dir_1",
184 "-Ilocal_include_dir_2",
185 "-I.",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000186 ],
187 deps = [
188 ":header_lib_1",
189 ":header_lib_2",
190 ":static_lib_1",
191 ":static_lib_2",
192 ":whole_static_lib_1",
193 ":whole_static_lib_2",
194 ],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000195 includes = [
196 "export_include_dir_1",
197 "export_include_dir_2",
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000198 ],
199 linkstatic = True,
200 srcs = [
201 "foo_static1.cc",
202 "foo_static2.cc",
203 ],
204)`, `cc_library_static(
205 name = "static_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000206 copts = ["-I."],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000207 linkstatic = True,
Jingwen Chen882bcc12021-04-27 05:54:20 +0000208 srcs = ["static_lib_1.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000209)`, `cc_library_static(
210 name = "static_lib_2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000211 copts = ["-I."],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000212 linkstatic = True,
Jingwen Chen882bcc12021-04-27 05:54:20 +0000213 srcs = ["static_lib_2.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000214)`, `cc_library_static(
215 name = "whole_static_lib_1",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000216 copts = ["-I."],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000217 linkstatic = True,
Jingwen Chen882bcc12021-04-27 05:54:20 +0000218 srcs = ["whole_static_lib_1.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000219)`, `cc_library_static(
220 name = "whole_static_lib_2",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000221 copts = ["-I."],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000222 linkstatic = True,
Jingwen Chen882bcc12021-04-27 05:54:20 +0000223 srcs = ["whole_static_lib_2.cc"],
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000224)`},
225 },
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400226 {
227 description: "cc_library_static subpackage test",
228 moduleTypeUnderTest: "cc_library_static",
229 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
230 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
231 filesystem: map[string]string{
232 // subpackage with subdirectory
233 "subpackage/Android.bp": "",
234 "subpackage/subpackage_header.h": "",
235 "subpackage/subdirectory/subdirectory_header.h": "",
236 // subsubpackage with subdirectory
237 "subpackage/subsubpackage/Android.bp": "",
238 "subpackage/subsubpackage/subsubpackage_header.h": "",
239 "subpackage/subsubpackage/subdirectory/subdirectory_header.h": "",
240 // subsubsubpackage with subdirectory
241 "subpackage/subsubpackage/subsubsubpackage/Android.bp": "",
242 "subpackage/subsubpackage/subsubsubpackage/subsubsubpackage_header.h": "",
243 "subpackage/subsubpackage/subsubsubpackage/subdirectory/subdirectory_header.h": "",
244 },
245 bp: soongCcLibraryStaticPreamble + `
246cc_library_static {
247 name: "foo_static",
248 srcs: [
249 ],
250 include_dirs: [
251 "subpackage",
252 ],
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400253}`,
254 expectedBazelTargets: []string{`cc_library_static(
255 name = "foo_static",
Jingwen Chened9c17d2021-04-13 07:14:55 +0000256 copts = [
257 "-Isubpackage",
258 "-I.",
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400259 ],
260 linkstatic = True,
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400261)`},
262 },
Jingwen Chened9c17d2021-04-13 07:14:55 +0000263 {
264 description: "cc_library_static export include dir",
265 moduleTypeUnderTest: "cc_library_static",
266 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
267 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
268 filesystem: map[string]string{
269 // subpackage with subdirectory
270 "subpackage/Android.bp": "",
271 "subpackage/subpackage_header.h": "",
272 "subpackage/subdirectory/subdirectory_header.h": "",
273 },
274 bp: soongCcLibraryStaticPreamble + `
275cc_library_static {
276 name: "foo_static",
277 export_include_dirs: ["subpackage"],
278}`,
279 expectedBazelTargets: []string{`cc_library_static(
280 name = "foo_static",
281 copts = ["-I."],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000282 includes = ["subpackage"],
283 linkstatic = True,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000284)`},
285 },
286 {
287 description: "cc_library_static export system include dir",
288 moduleTypeUnderTest: "cc_library_static",
289 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
290 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
291 filesystem: map[string]string{
292 // subpackage with subdirectory
293 "subpackage/Android.bp": "",
294 "subpackage/subpackage_header.h": "",
295 "subpackage/subdirectory/subdirectory_header.h": "",
296 },
297 bp: soongCcLibraryStaticPreamble + `
298cc_library_static {
299 name: "foo_static",
300 export_system_include_dirs: ["subpackage"],
301}`,
302 expectedBazelTargets: []string{`cc_library_static(
303 name = "foo_static",
304 copts = ["-I."],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000305 includes = ["subpackage"],
306 linkstatic = True,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000307)`},
308 },
309 {
310 description: "cc_library_static include_dirs, local_include_dirs, export_include_dirs (b/183742505)",
311 moduleTypeUnderTest: "cc_library_static",
312 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
313 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
314 dir: "subpackage",
315 filesystem: map[string]string{
316 // subpackage with subdirectory
317 "subpackage/Android.bp": `
318cc_library_static {
319 name: "foo_static",
320 // include_dirs are workspace/root relative
321 include_dirs: [
322 "subpackage/subsubpackage",
323 "subpackage2",
324 "subpackage3/subsubpackage"
325 ],
326 local_include_dirs: ["subsubpackage2"], // module dir relative
327 export_include_dirs: ["./exported_subsubpackage"], // module dir relative
328 include_build_directory: true,
329 bazel_module: { bp2build_available: true },
330}`,
331 "subpackage/subsubpackage/header.h": "",
332 "subpackage/subsubpackage2/header.h": "",
333 "subpackage/exported_subsubpackage/header.h": "",
334 "subpackage2/header.h": "",
335 "subpackage3/subsubpackage/header.h": "",
336 },
337 bp: soongCcLibraryStaticPreamble,
338 expectedBazelTargets: []string{`cc_library_static(
339 name = "foo_static",
340 copts = [
341 "-Isubpackage/subsubpackage",
342 "-Isubpackage2",
343 "-Isubpackage3/subsubpackage",
344 "-Isubpackage/subsubpackage2",
345 "-Isubpackage",
346 ],
Jingwen Chened9c17d2021-04-13 07:14:55 +0000347 includes = ["./exported_subsubpackage"],
348 linkstatic = True,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000349)`},
350 },
351 {
352 description: "cc_library_static include_build_directory disabled",
353 moduleTypeUnderTest: "cc_library_static",
354 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
355 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
356 filesystem: map[string]string{
357 // subpackage with subdirectory
358 "subpackage/Android.bp": "",
359 "subpackage/subpackage_header.h": "",
360 "subpackage/subdirectory/subdirectory_header.h": "",
361 },
362 bp: soongCcLibraryStaticPreamble + `
363cc_library_static {
364 name: "foo_static",
365 include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended
366 local_include_dirs: ["subpackage2"],
367 include_build_directory: false,
368}`,
369 expectedBazelTargets: []string{`cc_library_static(
370 name = "foo_static",
371 copts = [
372 "-Isubpackage",
373 "-Isubpackage2",
374 ],
375 linkstatic = True,
376)`},
377 },
378 {
379 description: "cc_library_static include_build_directory enabled",
380 moduleTypeUnderTest: "cc_library_static",
381 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
382 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
383 filesystem: map[string]string{
384 // subpackage with subdirectory
385 "subpackage/Android.bp": "",
386 "subpackage/subpackage_header.h": "",
387 "subpackage2/Android.bp": "",
388 "subpackage2/subpackage2_header.h": "",
389 "subpackage/subdirectory/subdirectory_header.h": "",
390 },
391 bp: soongCcLibraryStaticPreamble + `
392cc_library_static {
393 name: "foo_static",
394 include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended
395 local_include_dirs: ["subpackage2"],
396 include_build_directory: true,
397}`,
398 expectedBazelTargets: []string{`cc_library_static(
399 name = "foo_static",
400 copts = [
401 "-Isubpackage",
402 "-Isubpackage2",
403 "-I.",
404 ],
405 linkstatic = True,
Jingwen Chened9c17d2021-04-13 07:14:55 +0000406)`},
407 },
408 {
409 description: "cc_library_static arch-specific static_libs",
410 moduleTypeUnderTest: "cc_library_static",
411 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
412 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
413 depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
414 filesystem: map[string]string{},
415 bp: soongCcLibraryStaticPreamble + `
416cc_library_static { name: "static_dep" }
417cc_library_static { name: "static_dep2" }
418cc_library_static {
419 name: "foo_static",
420 arch: { arm64: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } },
421}`,
422 expectedBazelTargets: []string{`cc_library_static(
423 name = "foo_static",
424 copts = ["-I."],
425 deps = select({
426 "//build/bazel/platforms/arch:arm64": [
427 ":static_dep",
428 ":static_dep2",
429 ],
430 "//conditions:default": [],
431 }),
432 linkstatic = True,
433)`, `cc_library_static(
434 name = "static_dep",
435 copts = ["-I."],
436 linkstatic = True,
437)`, `cc_library_static(
438 name = "static_dep2",
439 copts = ["-I."],
440 linkstatic = True,
441)`},
442 },
443 {
444 description: "cc_library_static os-specific static_libs",
445 moduleTypeUnderTest: "cc_library_static",
446 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
447 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
448 depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
449 filesystem: map[string]string{},
450 bp: soongCcLibraryStaticPreamble + `
451cc_library_static { name: "static_dep" }
452cc_library_static { name: "static_dep2" }
453cc_library_static {
454 name: "foo_static",
455 target: { android: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } },
456}`,
457 expectedBazelTargets: []string{`cc_library_static(
458 name = "foo_static",
459 copts = ["-I."],
460 deps = select({
461 "//build/bazel/platforms/os:android": [
462 ":static_dep",
463 ":static_dep2",
464 ],
465 "//conditions:default": [],
466 }),
467 linkstatic = True,
468)`, `cc_library_static(
469 name = "static_dep",
470 copts = ["-I."],
471 linkstatic = True,
472)`, `cc_library_static(
473 name = "static_dep2",
474 copts = ["-I."],
475 linkstatic = True,
476)`},
477 },
478 {
479 description: "cc_library_static base, arch and os-specific static_libs",
480 moduleTypeUnderTest: "cc_library_static",
481 moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
482 moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
483 depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
484 filesystem: map[string]string{},
485 bp: soongCcLibraryStaticPreamble + `
486cc_library_static { name: "static_dep" }
487cc_library_static { name: "static_dep2" }
488cc_library_static { name: "static_dep3" }
489cc_library_static { name: "static_dep4" }
490cc_library_static {
491 name: "foo_static",
492 static_libs: ["static_dep"],
493 whole_static_libs: ["static_dep2"],
494 target: { android: { static_libs: ["static_dep3"] } },
495 arch: { arm64: { static_libs: ["static_dep4"] } },
496}`,
497 expectedBazelTargets: []string{`cc_library_static(
498 name = "foo_static",
499 copts = ["-I."],
500 deps = [
501 ":static_dep",
502 ":static_dep2",
503 ] + select({
504 "//build/bazel/platforms/arch:arm64": [":static_dep4"],
505 "//conditions:default": [],
506 }) + select({
507 "//build/bazel/platforms/os:android": [":static_dep3"],
508 "//conditions:default": [],
509 }),
510 linkstatic = True,
511)`, `cc_library_static(
512 name = "static_dep",
513 copts = ["-I."],
514 linkstatic = True,
515)`, `cc_library_static(
516 name = "static_dep2",
517 copts = ["-I."],
518 linkstatic = True,
519)`, `cc_library_static(
520 name = "static_dep3",
521 copts = ["-I."],
522 linkstatic = True,
523)`, `cc_library_static(
524 name = "static_dep4",
525 copts = ["-I."],
526 linkstatic = True,
527)`},
528 },
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000529 }
530
531 dir := "."
532 for _, testCase := range testCases {
533 filesystem := make(map[string][]byte)
534 toParse := []string{
535 "Android.bp",
536 }
537 for f, content := range testCase.filesystem {
538 if strings.HasSuffix(f, "Android.bp") {
539 toParse = append(toParse, f)
540 }
541 filesystem[f] = []byte(content)
542 }
543 config := android.TestConfig(buildDir, nil, testCase.bp, filesystem)
544 ctx := android.NewTestContext(config)
545
546 cc.RegisterCCBuildComponents(ctx)
547 ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory)
548 ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
549
550 ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory)
551 for _, m := range testCase.depsMutators {
552 ctx.DepsBp2BuildMutators(m)
553 }
554 ctx.RegisterBp2BuildMutator(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestBp2BuildMutator)
Jingwen Chened9c17d2021-04-13 07:14:55 +0000555 ctx.RegisterBp2BuildConfig(bp2buildConfig)
Rupert Shuttleworth095081c2021-03-25 09:06:03 +0000556 ctx.RegisterForBazelConversion()
557
558 _, errs := ctx.ParseFileList(dir, toParse)
559 if Errored(t, testCase.description, errs) {
560 continue
561 }
562 _, errs = ctx.ResolveDependencies(config)
563 if Errored(t, testCase.description, errs) {
564 continue
565 }
566
567 checkDir := dir
568 if testCase.dir != "" {
569 checkDir = testCase.dir
570 }
571 codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
572 bazelTargets := generateBazelTargetsForDir(codegenCtx, checkDir)
573 if actualCount, expectedCount := len(bazelTargets), len(testCase.expectedBazelTargets); actualCount != expectedCount {
574 t.Errorf("%s: Expected %d bazel target, got %d", testCase.description, expectedCount, actualCount)
575 } else {
576 for i, target := range bazelTargets {
577 if w, g := testCase.expectedBazelTargets[i], target.content; w != g {
578 t.Errorf(
579 "%s: Expected generated Bazel target to be '%s', got '%s'",
580 testCase.description,
581 w,
582 g,
583 )
584 }
585 }
586 }
587 }
588}