blob: 194a6b3598da9127317deea5f40befd45babffcc [file] [log] [blame]
Jingwen Chen12b4c272021-03-10 02:05:59 -05001// 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//
Colin Crossd079e0b2022-08-16 10:27:33 -07007// http://www.apache.org/licenses/LICENSE-2.0
Jingwen Chen12b4c272021-03-10 02:05:59 -05008//
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.
14package android
15
Sam Delmerico24c56032022-03-28 19:53:03 +000016import (
Sam Delmericocc518432022-03-30 15:50:34 +000017 "fmt"
Sam Delmerico24c56032022-03-28 19:53:03 +000018 "testing"
Sam Delmericocc518432022-03-30 15:50:34 +000019
Wei Lid7736ec2022-05-12 23:37:53 -070020 "android/soong/android/allowlists"
21 "android/soong/bazel"
22
Sam Delmericocc518432022-03-30 15:50:34 +000023 "github.com/google/blueprint"
24 "github.com/google/blueprint/proptools"
Sam Delmerico24c56032022-03-28 19:53:03 +000025)
Jingwen Chen12b4c272021-03-10 02:05:59 -050026
27func TestConvertAllModulesInPackage(t *testing.T) {
28 testCases := []struct {
Sam Delmerico24c56032022-03-28 19:53:03 +000029 prefixes allowlists.Bp2BuildConfig
Jingwen Chen12b4c272021-03-10 02:05:59 -050030 packageDir string
31 }{
32 {
Sam Delmerico24c56032022-03-28 19:53:03 +000033 prefixes: allowlists.Bp2BuildConfig{
34 "a": allowlists.Bp2BuildDefaultTrueRecursively,
Jingwen Chen12b4c272021-03-10 02:05:59 -050035 },
36 packageDir: "a",
37 },
38 {
Sam Delmerico24c56032022-03-28 19:53:03 +000039 prefixes: allowlists.Bp2BuildConfig{
40 "a/b": allowlists.Bp2BuildDefaultTrueRecursively,
Jingwen Chen12b4c272021-03-10 02:05:59 -050041 },
42 packageDir: "a/b",
43 },
44 {
Sam Delmerico24c56032022-03-28 19:53:03 +000045 prefixes: allowlists.Bp2BuildConfig{
46 "a/b": allowlists.Bp2BuildDefaultTrueRecursively,
47 "a/b/c": allowlists.Bp2BuildDefaultTrueRecursively,
Jingwen Chen12b4c272021-03-10 02:05:59 -050048 },
49 packageDir: "a/b",
50 },
51 {
Sam Delmerico24c56032022-03-28 19:53:03 +000052 prefixes: allowlists.Bp2BuildConfig{
53 "a": allowlists.Bp2BuildDefaultTrueRecursively,
54 "d/e/f": allowlists.Bp2BuildDefaultTrueRecursively,
Jingwen Chen12b4c272021-03-10 02:05:59 -050055 },
56 packageDir: "a/b",
57 },
58 {
Sam Delmerico24c56032022-03-28 19:53:03 +000059 prefixes: allowlists.Bp2BuildConfig{
60 "a": allowlists.Bp2BuildDefaultFalse,
61 "a/b": allowlists.Bp2BuildDefaultTrueRecursively,
62 "a/b/c": allowlists.Bp2BuildDefaultFalse,
Jingwen Chen12b4c272021-03-10 02:05:59 -050063 },
64 packageDir: "a/b",
65 },
66 {
Sam Delmerico24c56032022-03-28 19:53:03 +000067 prefixes: allowlists.Bp2BuildConfig{
68 "a": allowlists.Bp2BuildDefaultTrueRecursively,
69 "a/b": allowlists.Bp2BuildDefaultFalse,
70 "a/b/c": allowlists.Bp2BuildDefaultTrueRecursively,
Jingwen Chen12b4c272021-03-10 02:05:59 -050071 },
72 packageDir: "a",
73 },
MarkDacek756b2962022-10-13 17:50:17 +000074 {
75 prefixes: allowlists.Bp2BuildConfig{
76 "a": allowlists.Bp2BuildDefaultFalseRecursively,
77 "a/b": allowlists.Bp2BuildDefaultTrue,
78 },
79 packageDir: "a/b",
80 },
81 {
82 prefixes: allowlists.Bp2BuildConfig{
83 "a": allowlists.Bp2BuildDefaultFalseRecursively,
84 "a/b": allowlists.Bp2BuildDefaultTrueRecursively,
85 },
86 packageDir: "a/b/c",
87 },
Jingwen Chen12b4c272021-03-10 02:05:59 -050088 }
89
90 for _, test := range testCases {
Sam Delmerico24c56032022-03-28 19:53:03 +000091 if ok, _ := bp2buildDefaultTrueRecursively(test.packageDir, test.prefixes); !ok {
Jingwen Chen12b4c272021-03-10 02:05:59 -050092 t.Errorf("Expected to convert all modules in %s based on %v, but failed.", test.packageDir, test.prefixes)
93 }
94 }
95}
96
97func TestModuleOptIn(t *testing.T) {
98 testCases := []struct {
Sam Delmerico24c56032022-03-28 19:53:03 +000099 prefixes allowlists.Bp2BuildConfig
Jingwen Chen12b4c272021-03-10 02:05:59 -0500100 packageDir string
101 }{
102 {
Sam Delmerico24c56032022-03-28 19:53:03 +0000103 prefixes: allowlists.Bp2BuildConfig{
104 "a/b": allowlists.Bp2BuildDefaultFalse,
Jingwen Chen12b4c272021-03-10 02:05:59 -0500105 },
106 packageDir: "a/b",
107 },
108 {
Sam Delmerico24c56032022-03-28 19:53:03 +0000109 prefixes: allowlists.Bp2BuildConfig{
110 "a": allowlists.Bp2BuildDefaultFalse,
111 "a/b": allowlists.Bp2BuildDefaultTrueRecursively,
Jingwen Chen12b4c272021-03-10 02:05:59 -0500112 },
113 packageDir: "a",
114 },
115 {
Sam Delmerico24c56032022-03-28 19:53:03 +0000116 prefixes: allowlists.Bp2BuildConfig{
117 "a/b": allowlists.Bp2BuildDefaultTrueRecursively,
Jingwen Chen12b4c272021-03-10 02:05:59 -0500118 },
119 packageDir: "a", // opt-in by default
120 },
121 {
Sam Delmerico24c56032022-03-28 19:53:03 +0000122 prefixes: allowlists.Bp2BuildConfig{
123 "a/b/c": allowlists.Bp2BuildDefaultTrueRecursively,
Jingwen Chen12b4c272021-03-10 02:05:59 -0500124 },
125 packageDir: "a/b",
126 },
127 {
Sam Delmerico24c56032022-03-28 19:53:03 +0000128 prefixes: allowlists.Bp2BuildConfig{
129 "a": allowlists.Bp2BuildDefaultTrueRecursively,
130 "d/e/f": allowlists.Bp2BuildDefaultTrueRecursively,
Jingwen Chen12b4c272021-03-10 02:05:59 -0500131 },
132 packageDir: "foo/bar",
133 },
134 {
Sam Delmerico24c56032022-03-28 19:53:03 +0000135 prefixes: allowlists.Bp2BuildConfig{
136 "a": allowlists.Bp2BuildDefaultTrueRecursively,
137 "a/b": allowlists.Bp2BuildDefaultFalse,
138 "a/b/c": allowlists.Bp2BuildDefaultTrueRecursively,
Jingwen Chen12b4c272021-03-10 02:05:59 -0500139 },
140 packageDir: "a/b",
141 },
142 {
Sam Delmerico24c56032022-03-28 19:53:03 +0000143 prefixes: allowlists.Bp2BuildConfig{
144 "a": allowlists.Bp2BuildDefaultFalse,
145 "a/b": allowlists.Bp2BuildDefaultTrueRecursively,
146 "a/b/c": allowlists.Bp2BuildDefaultFalse,
Jingwen Chen12b4c272021-03-10 02:05:59 -0500147 },
148 packageDir: "a",
149 },
MarkDacek756b2962022-10-13 17:50:17 +0000150 {
151 prefixes: allowlists.Bp2BuildConfig{
152 "a": allowlists.Bp2BuildDefaultFalseRecursively,
153 "a/b": allowlists.Bp2BuildDefaultTrue,
154 },
155 packageDir: "a/b/c",
156 },
157 {
158 prefixes: allowlists.Bp2BuildConfig{
159 "a": allowlists.Bp2BuildDefaultTrueRecursively,
160 "a/b": allowlists.Bp2BuildDefaultFalseRecursively,
161 },
162 packageDir: "a/b/c",
163 },
Jingwen Chen12b4c272021-03-10 02:05:59 -0500164 }
165
166 for _, test := range testCases {
Sam Delmerico24c56032022-03-28 19:53:03 +0000167 if ok, _ := bp2buildDefaultTrueRecursively(test.packageDir, test.prefixes); ok {
Jingwen Chen12b4c272021-03-10 02:05:59 -0500168 t.Errorf("Expected to allow module opt-in in %s based on %v, but failed.", test.packageDir, test.prefixes)
169 }
170 }
171}
Sam Delmericocc518432022-03-30 15:50:34 +0000172
173type TestBazelModule struct {
174 bazel.TestModuleInfo
175 BazelModuleBase
176}
177
178var _ blueprint.Module = TestBazelModule{}
179
180func (m TestBazelModule) Name() string {
181 return m.TestModuleInfo.ModuleName
182}
183
184func (m TestBazelModule) GenerateBuildActions(blueprint.ModuleContext) {
185}
186
187type TestBazelConversionContext struct {
188 omc bazel.OtherModuleTestContext
Cole Faust324a92e2022-08-23 15:29:05 -0700189 allowlist Bp2BuildConversionAllowlist
Sam Delmericocc518432022-03-30 15:50:34 +0000190 errors []string
191}
192
193var _ bazelOtherModuleContext = &TestBazelConversionContext{}
194
195func (bcc *TestBazelConversionContext) OtherModuleType(m blueprint.Module) string {
196 return bcc.omc.OtherModuleType(m)
197}
198
199func (bcc *TestBazelConversionContext) OtherModuleName(m blueprint.Module) string {
200 return bcc.omc.OtherModuleName(m)
201}
202
203func (bcc *TestBazelConversionContext) OtherModuleDir(m blueprint.Module) string {
204 return bcc.omc.OtherModuleDir(m)
205}
206
207func (bcc *TestBazelConversionContext) ModuleErrorf(format string, args ...interface{}) {
208 bcc.errors = append(bcc.errors, fmt.Sprintf(format, args...))
209}
210
211func (bcc *TestBazelConversionContext) Config() Config {
212 return Config{
213 &config{
Cole Faust324a92e2022-08-23 15:29:05 -0700214 Bp2buildPackageConfig: bcc.allowlist,
Sam Delmericocc518432022-03-30 15:50:34 +0000215 },
216 }
217}
218
219var bazelableBazelModuleBase = BazelModuleBase{
220 bazelProperties: properties{
Romain Jobredeaux8242b432023-05-04 10:16:26 -0400221 Bazel_module: BazelModuleProperties{
Sam Delmericocc518432022-03-30 15:50:34 +0000222 CanConvertToBazel: true,
223 },
224 },
225}
226
227func TestBp2BuildAllowlist(t *testing.T) {
228 testCases := []struct {
229 description string
230 shouldConvert bool
231 expectedErrors []string
232 module TestBazelModule
Cole Faust324a92e2022-08-23 15:29:05 -0700233 allowlist Bp2BuildConversionAllowlist
Sam Delmericocc518432022-03-30 15:50:34 +0000234 }{
235 {
236 description: "allowlist enables module",
237 shouldConvert: true,
238 module: TestBazelModule{
239 TestModuleInfo: bazel.TestModuleInfo{
240 ModuleName: "foo",
241 Typ: "rule1",
242 Dir: "dir1",
243 },
244 BazelModuleBase: bazelableBazelModuleBase,
245 },
Cole Faust324a92e2022-08-23 15:29:05 -0700246 allowlist: Bp2BuildConversionAllowlist{
Sam Delmericocc518432022-03-30 15:50:34 +0000247 moduleAlwaysConvert: map[string]bool{
248 "foo": true,
249 },
250 },
251 },
252 {
253 description: "module in name allowlist and type allowlist fails",
254 shouldConvert: false,
255 expectedErrors: []string{"A module cannot be in moduleAlwaysConvert and also be in moduleTypeAlwaysConvert"},
256 module: TestBazelModule{
257 TestModuleInfo: bazel.TestModuleInfo{
258 ModuleName: "foo",
259 Typ: "rule1",
260 Dir: "dir1",
261 },
262 BazelModuleBase: bazelableBazelModuleBase,
263 },
Cole Faust324a92e2022-08-23 15:29:05 -0700264 allowlist: Bp2BuildConversionAllowlist{
Sam Delmericocc518432022-03-30 15:50:34 +0000265 moduleAlwaysConvert: map[string]bool{
266 "foo": true,
267 },
268 moduleTypeAlwaysConvert: map[string]bool{
269 "rule1": true,
270 },
271 },
272 },
273 {
274 description: "module in allowlist and denylist fails",
275 shouldConvert: false,
276 expectedErrors: []string{"a module cannot be in moduleDoNotConvert and also be in moduleAlwaysConvert"},
277 module: TestBazelModule{
278 TestModuleInfo: bazel.TestModuleInfo{
279 ModuleName: "foo",
280 Typ: "rule1",
281 Dir: "dir1",
282 },
283 BazelModuleBase: bazelableBazelModuleBase,
284 },
Cole Faust324a92e2022-08-23 15:29:05 -0700285 allowlist: Bp2BuildConversionAllowlist{
Sam Delmericocc518432022-03-30 15:50:34 +0000286 moduleAlwaysConvert: map[string]bool{
287 "foo": true,
288 },
289 moduleDoNotConvert: map[string]bool{
290 "foo": true,
291 },
292 },
293 },
294 {
Sam Delmericocc518432022-03-30 15:50:34 +0000295 description: "module allowlist and enabled directory",
296 shouldConvert: false,
Yu Liu10853f92022-09-14 16:05:22 -0700297 expectedErrors: []string{"A module cannot be in a directory marked Bp2BuildDefaultTrue or Bp2BuildDefaultTrueRecursively and also be in moduleAlwaysConvert. Directory: 'existing/build/dir' Module: 'foo'"},
Sam Delmericocc518432022-03-30 15:50:34 +0000298 module: TestBazelModule{
299 TestModuleInfo: bazel.TestModuleInfo{
300 ModuleName: "foo",
301 Typ: "rule1",
302 Dir: "existing/build/dir",
303 },
304 BazelModuleBase: bazelableBazelModuleBase,
305 },
Cole Faust324a92e2022-08-23 15:29:05 -0700306 allowlist: Bp2BuildConversionAllowlist{
Sam Delmericocc518432022-03-30 15:50:34 +0000307 moduleAlwaysConvert: map[string]bool{
308 "foo": true,
309 },
310 defaultConfig: allowlists.Bp2BuildConfig{
311 "existing/build/dir": allowlists.Bp2BuildDefaultTrue,
312 },
313 },
314 },
315 {
316 description: "module allowlist and enabled subdirectory",
317 shouldConvert: false,
Yu Liu10853f92022-09-14 16:05:22 -0700318 expectedErrors: []string{"A module cannot be in a directory marked Bp2BuildDefaultTrue or Bp2BuildDefaultTrueRecursively and also be in moduleAlwaysConvert. Directory: 'existing/build/dir' Module: 'foo'"},
Sam Delmericocc518432022-03-30 15:50:34 +0000319 module: TestBazelModule{
320 TestModuleInfo: bazel.TestModuleInfo{
321 ModuleName: "foo",
322 Typ: "rule1",
323 Dir: "existing/build/dir/subdir",
324 },
325 BazelModuleBase: bazelableBazelModuleBase,
326 },
Cole Faust324a92e2022-08-23 15:29:05 -0700327 allowlist: Bp2BuildConversionAllowlist{
Sam Delmericocc518432022-03-30 15:50:34 +0000328 moduleAlwaysConvert: map[string]bool{
329 "foo": true,
330 },
331 defaultConfig: allowlists.Bp2BuildConfig{
332 "existing/build/dir": allowlists.Bp2BuildDefaultTrueRecursively,
333 },
334 },
335 },
336 {
337 description: "module enabled in unit test short-circuits other allowlists",
338 shouldConvert: true,
339 module: TestBazelModule{
340 TestModuleInfo: bazel.TestModuleInfo{
341 ModuleName: "foo",
342 Typ: "rule1",
343 Dir: ".",
344 },
345 BazelModuleBase: BazelModuleBase{
346 bazelProperties: properties{
Romain Jobredeaux8242b432023-05-04 10:16:26 -0400347 Bazel_module: BazelModuleProperties{
Sam Delmericocc518432022-03-30 15:50:34 +0000348 CanConvertToBazel: true,
349 Bp2build_available: proptools.BoolPtr(true),
350 },
351 },
352 },
353 },
Cole Faust324a92e2022-08-23 15:29:05 -0700354 allowlist: Bp2BuildConversionAllowlist{
Sam Delmericocc518432022-03-30 15:50:34 +0000355 moduleAlwaysConvert: map[string]bool{
356 "foo": true,
357 },
358 moduleDoNotConvert: map[string]bool{
359 "foo": true,
360 },
361 },
362 },
363 }
364
365 for _, test := range testCases {
366 t.Run(test.description, func(t *testing.T) {
367 bcc := &TestBazelConversionContext{
368 omc: bazel.OtherModuleTestContext{
369 Modules: []bazel.TestModuleInfo{
370 test.module.TestModuleInfo,
371 },
372 },
373 allowlist: test.allowlist,
374 }
375
Liz Kammerc86e0942023-08-11 16:15:12 -0400376 shouldConvert := test.module.shouldConvertWithBp2build(bcc,
377 shouldConvertParams{
378 module: test.module.TestModuleInfo,
379 moduleDir: test.module.TestModuleInfo.Dir,
380 moduleType: test.module.TestModuleInfo.Typ,
381 moduleName: test.module.TestModuleInfo.ModuleName,
382 },
383 )
Sam Delmericocc518432022-03-30 15:50:34 +0000384 if test.shouldConvert != shouldConvert {
385 t.Errorf("Module shouldConvert expected to be: %v, but was: %v", test.shouldConvert, shouldConvert)
386 }
387
388 errorsMatch := true
389 if len(test.expectedErrors) != len(bcc.errors) {
390 errorsMatch = false
391 } else {
392 for i, err := range test.expectedErrors {
393 if err != bcc.errors[i] {
394 errorsMatch = false
395 }
396 }
397 }
398 if !errorsMatch {
399 t.Errorf("Expected errors to be: %v, but were: %v", test.expectedErrors, bcc.errors)
400 }
401 })
402 }
403}
Wei Lid7736ec2022-05-12 23:37:53 -0700404
405func TestBp2buildAllowList(t *testing.T) {
Chris Parsonsad876012022-08-20 14:48:32 -0400406 allowlist := GetBp2BuildAllowList()
Wei Lid7736ec2022-05-12 23:37:53 -0700407 for k, v := range allowlists.Bp2buildDefaultConfig {
408 if allowlist.defaultConfig[k] != v {
409 t.Errorf("bp2build default config of %s: expected: %v, got: %v", k, v, allowlist.defaultConfig[k])
410 }
411 }
412 for k, v := range allowlists.Bp2buildKeepExistingBuildFile {
413 if allowlist.keepExistingBuildFile[k] != v {
414 t.Errorf("bp2build keep existing build file of %s: expected: %v, got: %v", k, v, allowlist.keepExistingBuildFile[k])
415 }
416 }
417 for _, k := range allowlists.Bp2buildModuleTypeAlwaysConvertList {
418 if !allowlist.moduleTypeAlwaysConvert[k] {
419 t.Errorf("bp2build module type always convert of %s: expected: true, got: %v", k, allowlist.moduleTypeAlwaysConvert[k])
420 }
421 }
422 for _, k := range allowlists.Bp2buildModuleDoNotConvertList {
423 if !allowlist.moduleDoNotConvert[k] {
424 t.Errorf("bp2build module do not convert of %s: expected: true, got: %v", k, allowlist.moduleDoNotConvert[k])
425 }
426 }
Wei Lid7736ec2022-05-12 23:37:53 -0700427}
Usta Shrestha342f28f2022-11-02 00:59:16 -0400428
429func TestShouldKeepExistingBuildFileForDir(t *testing.T) {
430 allowlist := NewBp2BuildAllowlist()
431 // entry "a/b2/c2" is moot because of its parent "a/b2"
432 allowlist.SetKeepExistingBuildFile(map[string]bool{"a": false, "a/b1": false, "a/b2": true, "a/b1/c1": true, "a/b2/c2": false})
433 truths := []string{"a", "a/b1", "a/b2", "a/b1/c1", "a/b2/c", "a/b2/c2", "a/b2/c2/d"}
434 falsities := []string{"a1", "a/b", "a/b1/c"}
435 for _, dir := range truths {
436 if !allowlist.ShouldKeepExistingBuildFileForDir(dir) {
437 t.Errorf("%s expected TRUE but was FALSE", dir)
438 }
439 }
440 for _, dir := range falsities {
441 if allowlist.ShouldKeepExistingBuildFileForDir(dir) {
442 t.Errorf("%s expected FALSE but was TRUE", dir)
443 }
444 }
445}
Liz Kammerc13f7852023-05-17 13:01:48 -0400446
447type mixedBuildModule struct {
448 ModuleBase
449 BazelModuleBase
450 props struct {
451 Deps []string
452 Mixed_build_incompatible *bool
453 QueuedBazelCall bool `blueprint:"mutated"`
454 }
455}
456
457type mixedBuildModuleInfo struct {
458 QueuedBazelCall bool
459}
460
461var mixedBuildModuleProvider = blueprint.NewProvider(mixedBuildModuleInfo{})
462
463func mixedBuildModuleFactory() Module {
464 m := &mixedBuildModule{}
465 m.AddProperties(&m.props)
466 InitAndroidArchModule(m, HostAndDeviceDefault, MultilibBoth)
467 InitBazelModule(m)
468
469 return m
470}
471
472func (m *mixedBuildModule) ConvertWithBp2build(ctx TopDownMutatorContext) {
473}
474
475func (m *mixedBuildModule) DepsMutator(ctx BottomUpMutatorContext) {
476 ctx.AddDependency(ctx.Module(), installDepTag{}, m.props.Deps...)
477}
478
479func (m *mixedBuildModule) GenerateAndroidBuildActions(ctx ModuleContext) {
480}
481
482func (m *mixedBuildModule) IsMixedBuildSupported(ctx BaseModuleContext) bool {
483 return !proptools.Bool(m.props.Mixed_build_incompatible)
484}
485
486func (m *mixedBuildModule) QueueBazelCall(ctx BaseModuleContext) {
487 m.props.QueuedBazelCall = true
488}
489
490func (m *mixedBuildModule) ProcessBazelQueryResponse(ctx ModuleContext) {
491 ctx.SetProvider(mixedBuildModuleProvider, mixedBuildModuleInfo{
492 QueuedBazelCall: m.props.QueuedBazelCall,
493 })
494}
495
496var prepareForMixedBuildTests = FixtureRegisterWithContext(func(ctx RegistrationContext) {
497 ctx.RegisterModuleType("deps", mixedBuildModuleFactory)
498 RegisterMixedBuildsMutator(ctx)
499})
500
501func TestMixedBuildsEnabledForType(t *testing.T) {
502 baseBp := `
503 deps {
504 name: "foo",
505 deps: ["bar"],
506 target: { windows: { enabled: true } },
507 %s
508 }
509`
510 depBp := `
511 deps {
512 name: "bar",
513 target: {
514 windows: {
515 enabled: true,
516 },
517 },
518 }
519`
520 testCases := []struct {
521 desc string
522 variant *string
523 missingDeps bool
524 extraBpInfo string
525 mixedBuildsEnabled bool
526 }{
527 {
528 desc: "mixed builds works",
529 mixedBuildsEnabled: true,
530 extraBpInfo: `bazel_module: { bp2build_available: true },`,
531 },
532 {
533 desc: "missing deps",
534 missingDeps: true,
535 mixedBuildsEnabled: false,
536 extraBpInfo: `bazel_module: { bp2build_available: true },`,
537 },
538 {
539 desc: "windows no mixed builds",
540 mixedBuildsEnabled: false,
541 variant: proptools.StringPtr("windows_x86"),
542 extraBpInfo: `bazel_module: { bp2build_available: true },`,
543 },
544 {
545 desc: "mixed builds disabled by type",
546 mixedBuildsEnabled: false,
547 extraBpInfo: `mixed_build_incompatible: true,
548 bazel_module: { bp2build_available: true },`,
549 },
550 {
551 desc: "mixed builds not bp2build available",
552 mixedBuildsEnabled: false,
553 extraBpInfo: `bazel_module: { bp2build_available: false },`,
554 },
555 }
556
557 for _, tc := range testCases {
558 t.Run(tc.desc, func(t *testing.T) {
559 handlers := GroupFixturePreparers(
560 prepareForMixedBuildTests,
561 PrepareForTestWithArchMutator,
562 FixtureModifyConfig(func(config Config) {
563 config.BazelContext = MockBazelContext{
564 OutputBaseDir: "base",
565 }
566 config.Targets[Windows] = []Target{
567 {Windows, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", "", true},
568 {Windows, Arch{ArchType: X86}, NativeBridgeDisabled, "", "", true},
569 }
570 }),
571 )
572 bp := fmt.Sprintf(baseBp, tc.extraBpInfo)
573 if tc.missingDeps {
574 handlers = GroupFixturePreparers(
575 handlers,
576 PrepareForTestWithAllowMissingDependencies,
577 )
578 } else {
579 bp += depBp
580 }
581 result := handlers.RunTestWithBp(t, bp)
582
583 variant := proptools.StringDefault(tc.variant, "android_arm64_armv8-a")
584
585 m := result.ModuleForTests("foo", variant)
586 mixedBuildModuleInfo := result.TestContext.ModuleProvider(m.Module(), mixedBuildModuleProvider).(mixedBuildModuleInfo)
587 if w, g := tc.mixedBuildsEnabled, mixedBuildModuleInfo.QueuedBazelCall; w != g {
588 t.Errorf("Expected mixed builds enabled %t, got mixed builds enabled %t", w, g)
589 }
590 })
591 }
592}