blob: d9499a500ce1ee8ba8a663e5ba8e889ba2142639 [file] [log] [blame]
Cole Faust5a231bd2024-02-07 09:43:59 -08001// Copyright 2024 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 android
16
17import (
18 "fmt"
19 "reflect"
20 "testing"
21
22 "github.com/google/blueprint"
23 "github.com/google/blueprint/proptools"
24)
25
26func TestSelects(t *testing.T) {
27 testCases := []struct {
28 name string
29 bp string
30 provider selectsTestProvider
Cole Faust69349462024-04-25 16:02:15 -070031 providers map[string]selectsTestProvider
Cole Faust5a231bd2024-02-07 09:43:59 -080032 vendorVars map[string]map[string]string
33 expectedError string
34 }{
35 {
36 name: "basic string list",
37 bp: `
38 my_module_type {
39 name: "foo",
40 my_string_list: select(soong_config_variable("my_namespace", "my_variable"), {
41 "a": ["a.cpp"],
42 "b": ["b.cpp"],
Cole Faust683316a2024-04-02 16:45:54 -070043 default: ["c.cpp"],
Cole Faust5a231bd2024-02-07 09:43:59 -080044 }),
45 }
46 `,
47 provider: selectsTestProvider{
48 my_string_list: &[]string{"c.cpp"},
49 },
50 },
51 {
52 name: "basic string",
53 bp: `
54 my_module_type {
55 name: "foo",
56 my_string: select(soong_config_variable("my_namespace", "my_variable"), {
57 "a": "a.cpp",
58 "b": "b.cpp",
Cole Faust683316a2024-04-02 16:45:54 -070059 default: "c.cpp",
Cole Faust5a231bd2024-02-07 09:43:59 -080060 }),
61 }
62 `,
63 provider: selectsTestProvider{
64 my_string: proptools.StringPtr("c.cpp"),
65 },
66 },
67 {
68 name: "basic bool",
69 bp: `
70 my_module_type {
71 name: "foo",
72 my_bool: select(soong_config_variable("my_namespace", "my_variable"), {
73 "a": true,
74 "b": false,
Cole Faust683316a2024-04-02 16:45:54 -070075 default: true,
Cole Faust5a231bd2024-02-07 09:43:59 -080076 }),
77 }
78 `,
79 provider: selectsTestProvider{
80 my_bool: proptools.BoolPtr(true),
81 },
82 },
83 {
Cole Faustbdd8aee2024-03-14 14:33:02 -070084 name: "basic paths",
85 bp: `
86 my_module_type {
87 name: "foo",
88 my_paths: select(soong_config_variable("my_namespace", "my_variable"), {
89 "a": ["foo.txt"],
90 "b": ["bar.txt"],
Cole Faust683316a2024-04-02 16:45:54 -070091 default: ["baz.txt"],
Cole Faustbdd8aee2024-03-14 14:33:02 -070092 }),
93 }
94 `,
95 provider: selectsTestProvider{
96 my_paths: &[]string{"baz.txt"},
97 },
98 },
99 {
100 name: "paths with module references",
101 bp: `
102 my_module_type {
103 name: "foo",
104 my_paths: select(soong_config_variable("my_namespace", "my_variable"), {
105 "a": [":a"],
106 "b": [":b"],
Cole Faust683316a2024-04-02 16:45:54 -0700107 default: [":c"],
Cole Faustbdd8aee2024-03-14 14:33:02 -0700108 }),
109 }
110 `,
111 expectedError: `"foo" depends on undefined module "c"`,
112 },
113 {
Cole Faust5a231bd2024-02-07 09:43:59 -0800114 name: "Differing types",
115 bp: `
116 my_module_type {
117 name: "foo",
118 my_string: select(soong_config_variable("my_namespace", "my_variable"), {
119 "a": "a.cpp",
120 "b": true,
Cole Faust683316a2024-04-02 16:45:54 -0700121 default: "c.cpp",
Cole Faust5a231bd2024-02-07 09:43:59 -0800122 }),
123 }
124 `,
Cole Faust12c8ed42024-03-28 16:26:59 -0700125 expectedError: `Android.bp:8:5: Found select statement with differing types "string" and "bool" in its cases`,
126 },
127 {
128 name: "Select type doesn't match property type",
129 bp: `
130 my_module_type {
131 name: "foo",
132 my_string: select(soong_config_variable("my_namespace", "my_variable"), {
133 "a": false,
134 "b": true,
Cole Faust683316a2024-04-02 16:45:54 -0700135 default: true,
Cole Faust12c8ed42024-03-28 16:26:59 -0700136 }),
137 }
138 `,
139 expectedError: `can't assign bool value to string property "my_string\[0\]"`,
Cole Faust5a231bd2024-02-07 09:43:59 -0800140 },
141 {
142 name: "String list non-default",
143 bp: `
144 my_module_type {
145 name: "foo",
146 my_string_list: select(soong_config_variable("my_namespace", "my_variable"), {
147 "a": ["a.cpp"],
148 "b": ["b.cpp"],
Cole Faust683316a2024-04-02 16:45:54 -0700149 default: ["c.cpp"],
Cole Faust5a231bd2024-02-07 09:43:59 -0800150 }),
151 }
152 `,
153 provider: selectsTestProvider{
154 my_string_list: &[]string{"a.cpp"},
155 },
156 vendorVars: map[string]map[string]string{
157 "my_namespace": {
158 "my_variable": "a",
159 },
160 },
161 },
162 {
163 name: "String list append",
164 bp: `
165 my_module_type {
166 name: "foo",
167 my_string_list: select(soong_config_variable("my_namespace", "my_variable"), {
168 "a": ["a.cpp"],
169 "b": ["b.cpp"],
Cole Faust683316a2024-04-02 16:45:54 -0700170 default: ["c.cpp"],
Cole Faust5a231bd2024-02-07 09:43:59 -0800171 }) + select(soong_config_variable("my_namespace", "my_variable_2"), {
172 "a2": ["a2.cpp"],
173 "b2": ["b2.cpp"],
Cole Faust683316a2024-04-02 16:45:54 -0700174 default: ["c2.cpp"],
Cole Faust5a231bd2024-02-07 09:43:59 -0800175 }),
176 }
177 `,
178 provider: selectsTestProvider{
179 my_string_list: &[]string{"a.cpp", "c2.cpp"},
180 },
181 vendorVars: map[string]map[string]string{
182 "my_namespace": {
183 "my_variable": "a",
184 },
185 },
186 },
187 {
188 name: "String list prepend literal",
189 bp: `
190 my_module_type {
191 name: "foo",
192 my_string_list: ["literal.cpp"] + select(soong_config_variable("my_namespace", "my_variable"), {
193 "a2": ["a2.cpp"],
194 "b2": ["b2.cpp"],
Cole Faust683316a2024-04-02 16:45:54 -0700195 default: ["c2.cpp"],
Cole Faust5a231bd2024-02-07 09:43:59 -0800196 }),
197 }
198 `,
199 provider: selectsTestProvider{
200 my_string_list: &[]string{"literal.cpp", "c2.cpp"},
201 },
202 },
203 {
204 name: "String list append literal",
205 bp: `
206 my_module_type {
207 name: "foo",
208 my_string_list: select(soong_config_variable("my_namespace", "my_variable"), {
209 "a2": ["a2.cpp"],
210 "b2": ["b2.cpp"],
Cole Faust683316a2024-04-02 16:45:54 -0700211 default: ["c2.cpp"],
Cole Faust5a231bd2024-02-07 09:43:59 -0800212 }) + ["literal.cpp"],
213 }
214 `,
215 provider: selectsTestProvider{
216 my_string_list: &[]string{"c2.cpp", "literal.cpp"},
217 },
218 },
219 {
Cole Faust74ef4652024-03-27 16:45:41 -0700220 name: "true + false = true",
Cole Faust5a231bd2024-02-07 09:43:59 -0800221 bp: `
222 my_module_type {
223 name: "foo",
224 my_bool: select(soong_config_variable("my_namespace", "my_variable"), {
225 "a": true,
226 "b": false,
Cole Faust683316a2024-04-02 16:45:54 -0700227 default: true,
Cole Faust5a231bd2024-02-07 09:43:59 -0800228 }) + false,
229 }
230 `,
Cole Faust74ef4652024-03-27 16:45:41 -0700231 provider: selectsTestProvider{
232 my_bool: proptools.BoolPtr(true),
233 },
234 },
235 {
236 name: "false + false = false",
237 bp: `
238 my_module_type {
239 name: "foo",
240 my_bool: select(soong_config_variable("my_namespace", "my_variable"), {
241 "a": true,
242 "b": false,
Cole Faust683316a2024-04-02 16:45:54 -0700243 default: true,
Cole Faust74ef4652024-03-27 16:45:41 -0700244 }) + false,
245 }
246 `,
247 vendorVars: map[string]map[string]string{
248 "my_namespace": {
249 "my_variable": "b",
250 },
251 },
252 provider: selectsTestProvider{
253 my_bool: proptools.BoolPtr(false),
254 },
Cole Faust5a231bd2024-02-07 09:43:59 -0800255 },
256 {
257 name: "Append string",
258 bp: `
259 my_module_type {
260 name: "foo",
261 my_string: select(soong_config_variable("my_namespace", "my_variable"), {
262 "a": "a",
263 "b": "b",
Cole Faust683316a2024-04-02 16:45:54 -0700264 default: "c",
Cole Faust5a231bd2024-02-07 09:43:59 -0800265 }) + ".cpp",
266 }
267 `,
268 provider: selectsTestProvider{
269 my_string: proptools.StringPtr("c.cpp"),
270 },
271 },
Cole Faust0aa21cc2024-03-20 12:28:03 -0700272 {
Cole Faustfc57d402024-04-11 12:09:44 -0700273 name: "Select on arch",
Cole Faust0aa21cc2024-03-20 12:28:03 -0700274 bp: `
275 my_module_type {
276 name: "foo",
Cole Faustfc57d402024-04-11 12:09:44 -0700277 my_string: select(arch(), {
Cole Faust0aa21cc2024-03-20 12:28:03 -0700278 "x86": "my_x86",
279 "x86_64": "my_x86_64",
280 "arm": "my_arm",
281 "arm64": "my_arm64",
Cole Faust683316a2024-04-02 16:45:54 -0700282 default: "my_default",
Cole Faust0aa21cc2024-03-20 12:28:03 -0700283 }),
284 }
285 `,
286 provider: selectsTestProvider{
287 my_string: proptools.StringPtr("my_arm64"),
288 },
289 },
Cole Faust12c8ed42024-03-28 16:26:59 -0700290 {
Cole Faustfc57d402024-04-11 12:09:44 -0700291 name: "Select on os",
292 bp: `
293 my_module_type {
294 name: "foo",
295 my_string: select(os(), {
296 "android": "my_android",
297 "linux": "my_linux",
298 default: "my_default",
299 }),
300 }
301 `,
302 provider: selectsTestProvider{
303 my_string: proptools.StringPtr("my_android"),
304 },
305 },
306 {
Cole Faust12c8ed42024-03-28 16:26:59 -0700307 name: "Unset value",
308 bp: `
309 my_module_type {
310 name: "foo",
311 my_string: select(soong_config_variable("my_namespace", "my_variable"), {
312 "a": unset,
313 "b": "b",
Cole Faust683316a2024-04-02 16:45:54 -0700314 default: "c",
Cole Faust12c8ed42024-03-28 16:26:59 -0700315 })
316 }
317 `,
318 vendorVars: map[string]map[string]string{
319 "my_namespace": {
320 "my_variable": "a",
321 },
322 },
323 provider: selectsTestProvider{},
324 },
325 {
326 name: "Unset value on different branch",
327 bp: `
328 my_module_type {
329 name: "foo",
330 my_string: select(soong_config_variable("my_namespace", "my_variable"), {
331 "a": unset,
332 "b": "b",
Cole Faust683316a2024-04-02 16:45:54 -0700333 default: "c",
Cole Faust12c8ed42024-03-28 16:26:59 -0700334 })
335 }
336 `,
337 provider: selectsTestProvider{
338 my_string: proptools.StringPtr("c"),
339 },
340 },
341 {
342 name: "unset + unset = unset",
343 bp: `
344 my_module_type {
345 name: "foo",
346 my_string: select(soong_config_variable("my_namespace", "my_variable"), {
Cole Faustfdbf5d42024-04-10 15:01:23 -0700347 "foo": "bar",
Cole Faust683316a2024-04-02 16:45:54 -0700348 default: unset,
Cole Faust12c8ed42024-03-28 16:26:59 -0700349 }) + select(soong_config_variable("my_namespace", "my_variable2"), {
Cole Faustfdbf5d42024-04-10 15:01:23 -0700350 "baz": "qux",
Cole Faust683316a2024-04-02 16:45:54 -0700351 default: unset,
Cole Faust12c8ed42024-03-28 16:26:59 -0700352 })
353 }
354 `,
355 provider: selectsTestProvider{},
356 },
357 {
358 name: "unset + string = string",
359 bp: `
360 my_module_type {
361 name: "foo",
362 my_string: select(soong_config_variable("my_namespace", "my_variable"), {
Cole Faustfdbf5d42024-04-10 15:01:23 -0700363 "foo": "bar",
Cole Faust683316a2024-04-02 16:45:54 -0700364 default: unset,
Cole Faust12c8ed42024-03-28 16:26:59 -0700365 }) + select(soong_config_variable("my_namespace", "my_variable2"), {
Cole Faust683316a2024-04-02 16:45:54 -0700366 default: "a",
Cole Faust12c8ed42024-03-28 16:26:59 -0700367 })
368 }
369 `,
370 provider: selectsTestProvider{
371 my_string: proptools.StringPtr("a"),
372 },
373 },
374 {
375 name: "unset + bool = bool",
376 bp: `
377 my_module_type {
378 name: "foo",
379 my_bool: select(soong_config_variable("my_namespace", "my_variable"), {
380 "a": true,
Cole Faust683316a2024-04-02 16:45:54 -0700381 default: unset,
Cole Faust12c8ed42024-03-28 16:26:59 -0700382 }) + select(soong_config_variable("my_namespace", "my_variable2"), {
Cole Faust683316a2024-04-02 16:45:54 -0700383 default: true,
Cole Faust12c8ed42024-03-28 16:26:59 -0700384 })
385 }
386 `,
387 provider: selectsTestProvider{
388 my_bool: proptools.BoolPtr(true),
389 },
390 },
Cole Faust02dd6e52024-04-03 17:04:57 -0700391 {
392 name: "defaults with lists are appended",
393 bp: `
394 my_module_type {
395 name: "foo",
396 defaults: ["bar"],
397 my_string_list: select(soong_config_variable("my_namespace", "my_variable"), {
398 "a": ["a1"],
399 default: ["b1"],
400 }),
401 }
402 my_defaults {
403 name: "bar",
404 my_string_list: select(soong_config_variable("my_namespace", "my_variable2"), {
405 "a": ["a2"],
406 default: ["b2"],
407 }),
408 }
409 `,
410 provider: selectsTestProvider{
411 my_string_list: &[]string{"b2", "b1"},
412 },
413 },
414 {
Cole Faust69349462024-04-25 16:02:15 -0700415 name: "defaults applied to multiple modules",
416 bp: `
417 my_module_type {
418 name: "foo2",
419 defaults: ["bar"],
420 my_string_list: select(soong_config_variable("my_namespace", "my_variable"), {
421 "a": ["a1"],
422 default: ["b1"],
423 }),
424 }
425 my_module_type {
426 name: "foo",
427 defaults: ["bar"],
428 my_string_list: select(soong_config_variable("my_namespace", "my_variable"), {
429 "a": ["a1"],
430 default: ["b1"],
431 }),
432 }
433 my_defaults {
434 name: "bar",
435 my_string_list: select(soong_config_variable("my_namespace", "my_variable2"), {
436 "a": ["a2"],
437 default: ["b2"],
438 }),
439 }
440 `,
441 providers: map[string]selectsTestProvider{
442 "foo": {
443 my_string_list: &[]string{"b2", "b1"},
444 },
445 "foo2": {
446 my_string_list: &[]string{"b2", "b1"},
447 },
448 },
449 },
450 {
Cole Faust02dd6e52024-04-03 17:04:57 -0700451 name: "Replacing string list",
452 bp: `
453 my_module_type {
454 name: "foo",
455 defaults: ["bar"],
456 replacing_string_list: select(soong_config_variable("my_namespace", "my_variable"), {
457 "a": ["a1"],
458 default: ["b1"],
459 }),
460 }
461 my_defaults {
462 name: "bar",
463 replacing_string_list: select(soong_config_variable("my_namespace", "my_variable2"), {
464 "a": ["a2"],
465 default: ["b2"],
466 }),
467 }
468 `,
469 provider: selectsTestProvider{
470 replacing_string_list: &[]string{"b1"},
471 },
472 },
Cole Faustfdbf5d42024-04-10 15:01:23 -0700473 {
474 name: "Multi-condition string 1",
475 bp: `
476 my_module_type {
477 name: "foo",
478 my_string: select((
479 soong_config_variable("my_namespace", "my_variable"),
480 soong_config_variable("my_namespace", "my_variable2"),
481 ), {
482 ("a", "b"): "a+b",
483 ("a", default): "a+default",
484 (default, default): "default",
485 }),
486 }
487 `,
488 vendorVars: map[string]map[string]string{
489 "my_namespace": {
490 "my_variable": "a",
491 "my_variable2": "b",
492 },
493 },
494 provider: selectsTestProvider{
495 my_string: proptools.StringPtr("a+b"),
496 },
497 },
498 {
499 name: "Multi-condition string 2",
500 bp: `
501 my_module_type {
502 name: "foo",
503 my_string: select((
504 soong_config_variable("my_namespace", "my_variable"),
505 soong_config_variable("my_namespace", "my_variable2"),
506 ), {
507 ("a", "b"): "a+b",
508 ("a", default): "a+default",
509 (default, default): "default",
510 }),
511 }
512 `,
513 vendorVars: map[string]map[string]string{
514 "my_namespace": {
515 "my_variable": "a",
516 "my_variable2": "c",
517 },
518 },
519 provider: selectsTestProvider{
520 my_string: proptools.StringPtr("a+default"),
521 },
522 },
523 {
524 name: "Multi-condition string 3",
525 bp: `
526 my_module_type {
527 name: "foo",
528 my_string: select((
529 soong_config_variable("my_namespace", "my_variable"),
530 soong_config_variable("my_namespace", "my_variable2"),
531 ), {
532 ("a", "b"): "a+b",
533 ("a", default): "a+default",
534 (default, default): "default",
535 }),
536 }
537 `,
538 vendorVars: map[string]map[string]string{
539 "my_namespace": {
540 "my_variable": "c",
541 "my_variable2": "b",
542 },
543 },
544 provider: selectsTestProvider{
545 my_string: proptools.StringPtr("default"),
546 },
547 },
548 {
549 name: "Select on boolean",
550 bp: `
551 my_module_type {
552 name: "foo",
553 my_string: select(boolean_var_for_testing(), {
554 true: "t",
555 false: "f",
556 }),
557 }
558 `,
559 vendorVars: map[string]map[string]string{
560 "boolean_var": {
561 "for_testing": "true",
562 },
563 },
564 provider: selectsTestProvider{
565 my_string: proptools.StringPtr("t"),
566 },
567 },
568 {
569 name: "Select on boolean false",
570 bp: `
571 my_module_type {
572 name: "foo",
573 my_string: select(boolean_var_for_testing(), {
574 true: "t",
575 false: "f",
576 }),
577 }
578 `,
579 vendorVars: map[string]map[string]string{
580 "boolean_var": {
581 "for_testing": "false",
582 },
583 },
584 provider: selectsTestProvider{
585 my_string: proptools.StringPtr("f"),
586 },
587 },
588 {
589 name: "Select on boolean undefined",
590 bp: `
591 my_module_type {
592 name: "foo",
593 my_string: select(boolean_var_for_testing(), {
594 true: "t",
595 false: "f",
596 }),
597 }
598 `,
599 expectedError: "foo",
600 },
601 {
602 name: "Select on boolean undefined with default",
603 bp: `
604 my_module_type {
605 name: "foo",
606 my_string: select(boolean_var_for_testing(), {
607 true: "t",
608 false: "f",
609 default: "default",
610 }),
611 }
612 `,
613 provider: selectsTestProvider{
614 my_string: proptools.StringPtr("default"),
615 },
616 },
617 {
618 name: "Mismatched condition types",
619 bp: `
620 my_module_type {
621 name: "foo",
622 my_string: select(boolean_var_for_testing(), {
623 "true": "t",
624 "false": "f",
625 default: "default",
626 }),
627 }
628 `,
629 vendorVars: map[string]map[string]string{
630 "boolean_var": {
631 "for_testing": "false",
632 },
633 },
634 expectedError: "Expected all branches of a select on condition boolean_var_for_testing\\(\\) to have type bool, found string",
635 },
Cole Faust60f6bb22024-04-30 13:58:55 -0700636 {
637 name: "Assigning select to nonconfigurable bool",
638 bp: `
639 my_module_type {
640 name: "foo",
641 my_nonconfigurable_bool: select(arch(), {
642 "x86_64": true,
643 default: false,
644 }),
645 }
646 `,
647 expectedError: `can't assign select statement to non-configurable property "my_nonconfigurable_bool"`,
648 },
649 {
650 name: "Assigning select to nonconfigurable string",
651 bp: `
652 my_module_type {
653 name: "foo",
654 my_nonconfigurable_string: select(arch(), {
655 "x86_64": "x86!",
656 default: "unknown!",
657 }),
658 }
659 `,
660 expectedError: `can't assign select statement to non-configurable property "my_nonconfigurable_string"`,
661 },
662 {
663 name: "Assigning appended selects to nonconfigurable string",
664 bp: `
665 my_module_type {
666 name: "foo",
667 my_nonconfigurable_string: select(arch(), {
668 "x86_64": "x86!",
669 default: "unknown!",
670 }) + select(os(), {
671 "darwin": "_darwin!",
672 default: "unknown!",
673 }),
674 }
675 `,
676 expectedError: `can't assign select statement to non-configurable property "my_nonconfigurable_string"`,
677 },
678 {
679 name: "Assigning select to nonconfigurable string list",
680 bp: `
681 my_module_type {
682 name: "foo",
683 my_nonconfigurable_string_list: select(arch(), {
684 "x86_64": ["foo", "bar"],
685 default: ["baz", "qux"],
686 }),
687 }
688 `,
689 expectedError: `can't assign select statement to non-configurable property "my_nonconfigurable_string_list"`,
690 },
Cole Faust5a231bd2024-02-07 09:43:59 -0800691 }
692
693 for _, tc := range testCases {
694 t.Run(tc.name, func(t *testing.T) {
695 fixtures := GroupFixturePreparers(
Cole Faust02dd6e52024-04-03 17:04:57 -0700696 PrepareForTestWithDefaults,
Cole Faust0aa21cc2024-03-20 12:28:03 -0700697 PrepareForTestWithArchMutator,
Cole Faust5a231bd2024-02-07 09:43:59 -0800698 FixtureRegisterWithContext(func(ctx RegistrationContext) {
699 ctx.RegisterModuleType("my_module_type", newSelectsMockModule)
Cole Faust02dd6e52024-04-03 17:04:57 -0700700 ctx.RegisterModuleType("my_defaults", newSelectsMockModuleDefaults)
Cole Faust5a231bd2024-02-07 09:43:59 -0800701 }),
702 FixtureModifyProductVariables(func(variables FixtureProductVariables) {
703 variables.VendorVars = tc.vendorVars
704 }),
705 )
706 if tc.expectedError != "" {
707 fixtures = fixtures.ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(tc.expectedError))
708 }
709 result := fixtures.RunTestWithBp(t, tc.bp)
710
711 if tc.expectedError == "" {
Cole Faust69349462024-04-25 16:02:15 -0700712 if len(tc.providers) == 0 {
713 tc.providers = map[string]selectsTestProvider{
714 "foo": tc.provider,
715 }
716 }
717
718 for moduleName := range tc.providers {
719 expected := tc.providers[moduleName]
720 m := result.ModuleForTests(moduleName, "android_arm64_armv8-a")
721 p, _ := OtherModuleProvider(result.testContext.OtherModuleProviderAdaptor(), m.Module(), selectsTestProviderKey)
722 if !reflect.DeepEqual(p, expected) {
723 t.Errorf("Expected:\n %q\ngot:\n %q", expected.String(), p.String())
724 }
Cole Faust5a231bd2024-02-07 09:43:59 -0800725 }
726 }
727 })
728 }
729}
730
731type selectsTestProvider struct {
Cole Faust60f6bb22024-04-30 13:58:55 -0700732 my_bool *bool
733 my_string *string
734 my_string_list *[]string
735 my_paths *[]string
736 replacing_string_list *[]string
737 my_nonconfigurable_bool *bool
738 my_nonconfigurable_string *string
739 my_nonconfigurable_string_list []string
Cole Faust5a231bd2024-02-07 09:43:59 -0800740}
741
742func (p *selectsTestProvider) String() string {
743 myBoolStr := "nil"
744 if p.my_bool != nil {
745 myBoolStr = fmt.Sprintf("%t", *p.my_bool)
746 }
747 myStringStr := "nil"
748 if p.my_string != nil {
749 myStringStr = *p.my_string
750 }
Cole Faust60f6bb22024-04-30 13:58:55 -0700751 myNonconfigurableStringStr := "nil"
752 if p.my_string != nil {
753 myNonconfigurableStringStr = *p.my_nonconfigurable_string
754 }
Cole Faust5a231bd2024-02-07 09:43:59 -0800755 return fmt.Sprintf(`selectsTestProvider {
756 my_bool: %v,
757 my_string: %s,
758 my_string_list: %s,
Cole Faustbdd8aee2024-03-14 14:33:02 -0700759 my_paths: %s,
Cole Faust02dd6e52024-04-03 17:04:57 -0700760 replacing_string_list %s,
Cole Faust60f6bb22024-04-30 13:58:55 -0700761 my_nonconfigurable_bool: %v,
762 my_nonconfigurable_string: %s,
763 my_nonconfigurable_string_list: %s,
764}`,
765 myBoolStr,
766 myStringStr,
767 p.my_string_list,
768 p.my_paths,
769 p.replacing_string_list,
770 p.my_nonconfigurable_bool,
771 myNonconfigurableStringStr,
772 p.my_nonconfigurable_string_list,
773 )
Cole Faust5a231bd2024-02-07 09:43:59 -0800774}
775
776var selectsTestProviderKey = blueprint.NewProvider[selectsTestProvider]()
777
778type selectsMockModuleProperties struct {
Cole Faust60f6bb22024-04-30 13:58:55 -0700779 My_bool proptools.Configurable[bool]
780 My_string proptools.Configurable[string]
781 My_string_list proptools.Configurable[[]string]
782 My_paths proptools.Configurable[[]string] `android:"path"`
783 Replacing_string_list proptools.Configurable[[]string] `android:"replace_instead_of_append,arch_variant"`
784 My_nonconfigurable_bool *bool
785 My_nonconfigurable_string *string
786 My_nonconfigurable_string_list []string
Cole Faust5a231bd2024-02-07 09:43:59 -0800787}
788
789type selectsMockModule struct {
790 ModuleBase
791 DefaultableModuleBase
792 properties selectsMockModuleProperties
793}
794
795func (p *selectsMockModule) GenerateAndroidBuildActions(ctx ModuleContext) {
Cole Faustbdd8aee2024-03-14 14:33:02 -0700796 SetProvider(ctx, selectsTestProviderKey, selectsTestProvider{
Cole Faust60f6bb22024-04-30 13:58:55 -0700797 my_bool: p.properties.My_bool.Get(ctx),
798 my_string: p.properties.My_string.Get(ctx),
799 my_string_list: p.properties.My_string_list.Get(ctx),
800 my_paths: p.properties.My_paths.Get(ctx),
801 replacing_string_list: p.properties.Replacing_string_list.Get(ctx),
802 my_nonconfigurable_bool: p.properties.My_nonconfigurable_bool,
803 my_nonconfigurable_string: p.properties.My_nonconfigurable_string,
804 my_nonconfigurable_string_list: p.properties.My_nonconfigurable_string_list,
Cole Faust5a231bd2024-02-07 09:43:59 -0800805 })
806}
807
808func newSelectsMockModule() Module {
809 m := &selectsMockModule{}
810 m.AddProperties(&m.properties)
Cole Faust0aa21cc2024-03-20 12:28:03 -0700811 InitAndroidArchModule(m, HostAndDeviceSupported, MultilibFirst)
Cole Faust5a231bd2024-02-07 09:43:59 -0800812 InitDefaultableModule(m)
813 return m
814}
Cole Faust02dd6e52024-04-03 17:04:57 -0700815
816type selectsMockModuleDefaults struct {
817 ModuleBase
818 DefaultsModuleBase
819}
820
821func (d *selectsMockModuleDefaults) GenerateAndroidBuildActions(ctx ModuleContext) {
822}
823
824func newSelectsMockModuleDefaults() Module {
825 module := &selectsMockModuleDefaults{}
826
827 module.AddProperties(
828 &selectsMockModuleProperties{},
829 )
830
831 InitDefaultsModule(module)
832
833 return module
834}