Rupert Shuttleworth | 54e7841 | 2021-02-15 11:04:32 +0000 | [diff] [blame] | 1 | // 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 | |
| 15 | package bp2build |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/cc" |
| 20 | "strings" |
| 21 | "testing" |
| 22 | ) |
| 23 | |
| 24 | const ( |
| 25 | // See cc/testing.go for more context |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 26 | soongCcLibraryHeadersPreamble = ` |
Rupert Shuttleworth | 54e7841 | 2021-02-15 11:04:32 +0000 | [diff] [blame] | 27 | cc_defaults { |
| 28 | name: "linux_bionic_supported", |
| 29 | } |
| 30 | |
| 31 | toolchain_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 Shuttleworth | 54e7841 | 2021-02-15 11:04:32 +0000 | [diff] [blame] | 40 | }` |
| 41 | ) |
| 42 | |
| 43 | func TestCcLibraryHeadersLoadStatement(t *testing.T) { |
| 44 | testCases := []struct { |
| 45 | bazelTargets BazelTargets |
| 46 | expectedLoadStatements string |
| 47 | }{ |
| 48 | { |
| 49 | bazelTargets: BazelTargets{ |
| 50 | BazelTarget{ |
| 51 | name: "cc_library_headers_target", |
| 52 | ruleClass: "cc_library_headers", |
| 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 | |
| 70 | func TestCcLibraryHeadersBp2Build(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_headers test", |
| 85 | moduleTypeUnderTest: "cc_library_headers", |
| 86 | moduleTypeUnderTestFactory: cc.LibraryHeaderFactory, |
| 87 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryHeadersBp2Build, |
| 88 | filesystem: map[string]string{ |
Rupert Shuttleworth | b815168 | 2021-04-06 20:06:21 +0000 | [diff] [blame] | 89 | "lib-1/lib1a.h": "", |
| 90 | "lib-1/lib1b.h": "", |
| 91 | "lib-2/lib2a.h": "", |
| 92 | "lib-2/lib2b.h": "", |
| 93 | "dir-1/dir1a.h": "", |
| 94 | "dir-1/dir1b.h": "", |
| 95 | "dir-2/dir2a.h": "", |
| 96 | "dir-2/dir2b.h": "", |
| 97 | "arch_arm64_exported_include_dir/a.h": "", |
| 98 | "arch_x86_exported_include_dir/b.h": "", |
| 99 | "arch_x86_64_exported_include_dir/c.h": "", |
Rupert Shuttleworth | 54e7841 | 2021-02-15 11:04:32 +0000 | [diff] [blame] | 100 | }, |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 101 | bp: soongCcLibraryHeadersPreamble + ` |
Rupert Shuttleworth | 54e7841 | 2021-02-15 11:04:32 +0000 | [diff] [blame] | 102 | cc_library_headers { |
| 103 | name: "lib-1", |
| 104 | export_include_dirs: ["lib-1"], |
Rupert Shuttleworth | 54e7841 | 2021-02-15 11:04:32 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | cc_library_headers { |
| 108 | name: "lib-2", |
| 109 | export_include_dirs: ["lib-2"], |
Rupert Shuttleworth | 54e7841 | 2021-02-15 11:04:32 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | cc_library_headers { |
| 113 | name: "foo_headers", |
| 114 | export_include_dirs: ["dir-1", "dir-2"], |
| 115 | header_libs: ["lib-1", "lib-2"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 116 | |
Rupert Shuttleworth | b815168 | 2021-04-06 20:06:21 +0000 | [diff] [blame] | 117 | arch: { |
| 118 | arm64: { |
| 119 | // We expect dir-1 headers to be dropped, because dir-1 is already in export_include_dirs |
| 120 | export_include_dirs: ["arch_arm64_exported_include_dir", "dir-1"], |
| 121 | }, |
| 122 | x86: { |
| 123 | export_include_dirs: ["arch_x86_exported_include_dir"], |
| 124 | }, |
| 125 | x86_64: { |
| 126 | export_include_dirs: ["arch_x86_64_exported_include_dir"], |
| 127 | }, |
| 128 | }, |
| 129 | |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 130 | // TODO: Also support export_header_lib_headers |
Rupert Shuttleworth | 54e7841 | 2021-02-15 11:04:32 +0000 | [diff] [blame] | 131 | }`, |
| 132 | expectedBazelTargets: []string{`cc_library_headers( |
| 133 | name = "foo_headers", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 134 | copts = [ |
| 135 | "-I.", |
| 136 | "-I$(BINDIR)/.", |
| 137 | ], |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame^] | 138 | implementation_deps = [ |
Rupert Shuttleworth | 54e7841 | 2021-02-15 11:04:32 +0000 | [diff] [blame] | 139 | ":lib-1", |
| 140 | ":lib-2", |
| 141 | ], |
Rupert Shuttleworth | 54e7841 | 2021-02-15 11:04:32 +0000 | [diff] [blame] | 142 | includes = [ |
| 143 | "dir-1", |
| 144 | "dir-2", |
Rupert Shuttleworth | b815168 | 2021-04-06 20:06:21 +0000 | [diff] [blame] | 145 | ] + select({ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 146 | "//build/bazel/platforms/arch:arm64": ["arch_arm64_exported_include_dir"], |
| 147 | "//build/bazel/platforms/arch:x86": ["arch_x86_exported_include_dir"], |
| 148 | "//build/bazel/platforms/arch:x86_64": ["arch_x86_64_exported_include_dir"], |
Rupert Shuttleworth | b815168 | 2021-04-06 20:06:21 +0000 | [diff] [blame] | 149 | "//conditions:default": [], |
| 150 | }), |
Rupert Shuttleworth | 54e7841 | 2021-02-15 11:04:32 +0000 | [diff] [blame] | 151 | )`, `cc_library_headers( |
| 152 | name = "lib-1", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 153 | copts = [ |
| 154 | "-I.", |
| 155 | "-I$(BINDIR)/.", |
| 156 | ], |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 157 | includes = ["lib-1"], |
Rupert Shuttleworth | 54e7841 | 2021-02-15 11:04:32 +0000 | [diff] [blame] | 158 | )`, `cc_library_headers( |
| 159 | name = "lib-2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 160 | copts = [ |
| 161 | "-I.", |
| 162 | "-I$(BINDIR)/.", |
| 163 | ], |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 164 | includes = ["lib-2"], |
Rupert Shuttleworth | 54e7841 | 2021-02-15 11:04:32 +0000 | [diff] [blame] | 165 | )`}, |
| 166 | }, |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 167 | { |
| 168 | description: "cc_library_headers test with os-specific header_libs props", |
| 169 | moduleTypeUnderTest: "cc_library_headers", |
| 170 | moduleTypeUnderTestFactory: cc.LibraryHeaderFactory, |
| 171 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryHeadersBp2Build, |
| 172 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 173 | filesystem: map[string]string{}, |
| 174 | bp: soongCcLibraryPreamble + ` |
| 175 | cc_library_headers { name: "android-lib" } |
| 176 | cc_library_headers { name: "base-lib" } |
| 177 | cc_library_headers { name: "darwin-lib" } |
| 178 | cc_library_headers { name: "fuchsia-lib" } |
| 179 | cc_library_headers { name: "linux-lib" } |
| 180 | cc_library_headers { name: "linux_bionic-lib" } |
| 181 | cc_library_headers { name: "windows-lib" } |
| 182 | cc_library_headers { |
| 183 | name: "foo_headers", |
| 184 | header_libs: ["base-lib"], |
| 185 | target: { |
| 186 | android: { header_libs: ["android-lib"] }, |
| 187 | darwin: { header_libs: ["darwin-lib"] }, |
| 188 | fuchsia: { header_libs: ["fuchsia-lib"] }, |
| 189 | linux_bionic: { header_libs: ["linux_bionic-lib"] }, |
| 190 | linux_glibc: { header_libs: ["linux-lib"] }, |
| 191 | windows: { header_libs: ["windows-lib"] }, |
| 192 | }, |
| 193 | bazel_module: { bp2build_available: true }, |
| 194 | }`, |
| 195 | expectedBazelTargets: []string{`cc_library_headers( |
| 196 | name = "android-lib", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 197 | copts = [ |
| 198 | "-I.", |
| 199 | "-I$(BINDIR)/.", |
| 200 | ], |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 201 | )`, `cc_library_headers( |
| 202 | name = "base-lib", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 203 | copts = [ |
| 204 | "-I.", |
| 205 | "-I$(BINDIR)/.", |
| 206 | ], |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 207 | )`, `cc_library_headers( |
| 208 | name = "darwin-lib", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 209 | copts = [ |
| 210 | "-I.", |
| 211 | "-I$(BINDIR)/.", |
| 212 | ], |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 213 | )`, `cc_library_headers( |
| 214 | name = "foo_headers", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 215 | copts = [ |
| 216 | "-I.", |
| 217 | "-I$(BINDIR)/.", |
| 218 | ], |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame^] | 219 | implementation_deps = [":base-lib"] + select({ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 220 | "//build/bazel/platforms/os:android": [":android-lib"], |
| 221 | "//build/bazel/platforms/os:darwin": [":darwin-lib"], |
| 222 | "//build/bazel/platforms/os:fuchsia": [":fuchsia-lib"], |
| 223 | "//build/bazel/platforms/os:linux": [":linux-lib"], |
| 224 | "//build/bazel/platforms/os:linux_bionic": [":linux_bionic-lib"], |
| 225 | "//build/bazel/platforms/os:windows": [":windows-lib"], |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 226 | "//conditions:default": [], |
| 227 | }), |
| 228 | )`, `cc_library_headers( |
| 229 | name = "fuchsia-lib", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 230 | copts = [ |
| 231 | "-I.", |
| 232 | "-I$(BINDIR)/.", |
| 233 | ], |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 234 | )`, `cc_library_headers( |
| 235 | name = "linux-lib", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 236 | copts = [ |
| 237 | "-I.", |
| 238 | "-I$(BINDIR)/.", |
| 239 | ], |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 240 | )`, `cc_library_headers( |
| 241 | name = "linux_bionic-lib", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 242 | copts = [ |
| 243 | "-I.", |
| 244 | "-I$(BINDIR)/.", |
| 245 | ], |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 246 | )`, `cc_library_headers( |
| 247 | name = "windows-lib", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 248 | copts = [ |
| 249 | "-I.", |
| 250 | "-I$(BINDIR)/.", |
| 251 | ], |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 252 | )`}, |
| 253 | }, |
| 254 | { |
| 255 | description: "cc_library_headers test with os-specific header_libs and export_header_lib_headers props", |
| 256 | moduleTypeUnderTest: "cc_library_headers", |
| 257 | moduleTypeUnderTestFactory: cc.LibraryHeaderFactory, |
| 258 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryHeadersBp2Build, |
| 259 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 260 | filesystem: map[string]string{}, |
| 261 | bp: soongCcLibraryPreamble + ` |
| 262 | cc_library_headers { name: "android-lib" } |
| 263 | cc_library_headers { name: "exported-lib" } |
| 264 | cc_library_headers { |
| 265 | name: "foo_headers", |
| 266 | target: { |
| 267 | android: { header_libs: ["android-lib"], export_header_lib_headers: ["exported-lib"] }, |
| 268 | }, |
| 269 | }`, |
| 270 | expectedBazelTargets: []string{`cc_library_headers( |
| 271 | name = "android-lib", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 272 | copts = [ |
| 273 | "-I.", |
| 274 | "-I$(BINDIR)/.", |
| 275 | ], |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 276 | )`, `cc_library_headers( |
| 277 | name = "exported-lib", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 278 | copts = [ |
| 279 | "-I.", |
| 280 | "-I$(BINDIR)/.", |
| 281 | ], |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 282 | )`, `cc_library_headers( |
| 283 | name = "foo_headers", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 284 | copts = [ |
| 285 | "-I.", |
| 286 | "-I$(BINDIR)/.", |
| 287 | ], |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 288 | deps = select({ |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame^] | 289 | "//build/bazel/platforms/os:android": [":exported-lib"], |
| 290 | "//conditions:default": [], |
| 291 | }), |
| 292 | implementation_deps = select({ |
| 293 | "//build/bazel/platforms/os:android": [":android-lib"], |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 294 | "//conditions:default": [], |
| 295 | }), |
| 296 | )`}, |
| 297 | }, |
Rupert Shuttleworth | 375451e | 2021-04-26 07:49:08 -0400 | [diff] [blame] | 298 | { |
| 299 | description: "cc_library_headers test with arch-specific and target-specific export_system_include_dirs props", |
| 300 | moduleTypeUnderTest: "cc_library_headers", |
| 301 | moduleTypeUnderTestFactory: cc.LibraryHeaderFactory, |
| 302 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryHeadersBp2Build, |
| 303 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 304 | filesystem: map[string]string{}, |
| 305 | bp: soongCcLibraryPreamble + `cc_library_headers { |
| 306 | name: "foo_headers", |
| 307 | export_system_include_dirs: [ |
| 308 | "shared_include_dir", |
| 309 | ], |
| 310 | target: { |
| 311 | android: { |
| 312 | export_system_include_dirs: [ |
| 313 | "android_include_dir", |
| 314 | ], |
| 315 | }, |
| 316 | linux_glibc: { |
| 317 | export_system_include_dirs: [ |
| 318 | "linux_include_dir", |
| 319 | ], |
| 320 | }, |
| 321 | darwin: { |
| 322 | export_system_include_dirs: [ |
| 323 | "darwin_include_dir", |
| 324 | ], |
| 325 | }, |
| 326 | }, |
| 327 | arch: { |
| 328 | arm: { |
| 329 | export_system_include_dirs: [ |
| 330 | "arm_include_dir", |
| 331 | ], |
| 332 | }, |
| 333 | x86_64: { |
| 334 | export_system_include_dirs: [ |
| 335 | "x86_64_include_dir", |
| 336 | ], |
| 337 | }, |
| 338 | }, |
| 339 | }`, |
| 340 | expectedBazelTargets: []string{`cc_library_headers( |
| 341 | name = "foo_headers", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 342 | copts = [ |
| 343 | "-I.", |
| 344 | "-I$(BINDIR)/.", |
| 345 | ], |
Rupert Shuttleworth | 375451e | 2021-04-26 07:49:08 -0400 | [diff] [blame] | 346 | includes = ["shared_include_dir"] + select({ |
| 347 | "//build/bazel/platforms/arch:arm": ["arm_include_dir"], |
| 348 | "//build/bazel/platforms/arch:x86_64": ["x86_64_include_dir"], |
| 349 | "//conditions:default": [], |
| 350 | }) + select({ |
| 351 | "//build/bazel/platforms/os:android": ["android_include_dir"], |
| 352 | "//build/bazel/platforms/os:darwin": ["darwin_include_dir"], |
| 353 | "//build/bazel/platforms/os:linux": ["linux_include_dir"], |
| 354 | "//conditions:default": [], |
| 355 | }), |
| 356 | )`}, |
| 357 | }, |
Rupert Shuttleworth | 54e7841 | 2021-02-15 11:04:32 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | dir := "." |
| 361 | for _, testCase := range testCases { |
| 362 | filesystem := make(map[string][]byte) |
| 363 | toParse := []string{ |
| 364 | "Android.bp", |
| 365 | } |
| 366 | for f, content := range testCase.filesystem { |
| 367 | if strings.HasSuffix(f, "Android.bp") { |
| 368 | toParse = append(toParse, f) |
| 369 | } |
| 370 | filesystem[f] = []byte(content) |
| 371 | } |
| 372 | config := android.TestConfig(buildDir, nil, testCase.bp, filesystem) |
| 373 | ctx := android.NewTestContext(config) |
| 374 | |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 375 | // TODO(jingwen): make this default for all bp2build tests |
| 376 | ctx.RegisterBp2BuildConfig(bp2buildConfig) |
| 377 | |
Rupert Shuttleworth | 54e7841 | 2021-02-15 11:04:32 +0000 | [diff] [blame] | 378 | cc.RegisterCCBuildComponents(ctx) |
| 379 | ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory) |
| 380 | |
| 381 | ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory) |
| 382 | for _, m := range testCase.depsMutators { |
| 383 | ctx.DepsBp2BuildMutators(m) |
| 384 | } |
| 385 | ctx.RegisterBp2BuildMutator(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestBp2BuildMutator) |
| 386 | ctx.RegisterForBazelConversion() |
| 387 | |
| 388 | _, errs := ctx.ParseFileList(dir, toParse) |
Rupert Shuttleworth | 06559d0 | 2021-05-19 09:14:26 -0400 | [diff] [blame] | 389 | if errored(t, testCase.description, errs) { |
Rupert Shuttleworth | 54e7841 | 2021-02-15 11:04:32 +0000 | [diff] [blame] | 390 | continue |
| 391 | } |
| 392 | _, errs = ctx.ResolveDependencies(config) |
Rupert Shuttleworth | 06559d0 | 2021-05-19 09:14:26 -0400 | [diff] [blame] | 393 | if errored(t, testCase.description, errs) { |
Rupert Shuttleworth | 54e7841 | 2021-02-15 11:04:32 +0000 | [diff] [blame] | 394 | continue |
| 395 | } |
| 396 | |
| 397 | checkDir := dir |
| 398 | if testCase.dir != "" { |
| 399 | checkDir = testCase.dir |
| 400 | } |
Jingwen Chen | 164e086 | 2021-02-19 00:48:40 -0500 | [diff] [blame] | 401 | codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build) |
Jingwen Chen | ba369ad | 2021-02-22 10:19:34 -0500 | [diff] [blame] | 402 | bazelTargets := generateBazelTargetsForDir(codegenCtx, checkDir) |
Rupert Shuttleworth | 54e7841 | 2021-02-15 11:04:32 +0000 | [diff] [blame] | 403 | if actualCount, expectedCount := len(bazelTargets), len(testCase.expectedBazelTargets); actualCount != expectedCount { |
| 404 | t.Errorf("%s: Expected %d bazel target, got %d", testCase.description, expectedCount, actualCount) |
| 405 | } else { |
| 406 | for i, target := range bazelTargets { |
| 407 | if w, g := testCase.expectedBazelTargets[i], target.content; w != g { |
| 408 | t.Errorf( |
| 409 | "%s: Expected generated Bazel target to be '%s', got '%s'", |
| 410 | testCase.description, |
| 411 | w, |
| 412 | g, |
| 413 | ) |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | } |