xref: /aosp_15_r20/external/bazelbuild-rules_cc/tests/rule_based_toolchain/variables/BUILD (revision eed53cd41c5909d05eedc7ad9720bb158fd93452)
1load("//cc/toolchains:format.bzl", "format_arg")
2load("//cc/toolchains:nested_args.bzl", "cc_nested_args")
3load("//cc/toolchains/impl:variables.bzl", "cc_builtin_variables", "cc_variable", "types")
4load("//tests/rule_based_toolchain:analysis_test_suite.bzl", "analysis_test_suite")
5load(":variables_test.bzl", "TARGETS", "TESTS")
6
7cc_variable(
8    name = "str",
9    type = types.string,
10)
11
12cc_variable(
13    name = "optional_list",
14    type = types.option(types.list(types.string)),
15)
16
17cc_variable(
18    name = "str_list",
19    type = types.list(types.string),
20)
21
22cc_variable(
23    name = "str_option",
24    type = types.option(types.string),
25)
26
27cc_variable(
28    name = "struct",
29    actions = ["//tests/rule_based_toolchain/actions:c_compile"],
30    type = types.struct(
31        nested_str = types.string,
32        nested_str_list = types.list(types.string),
33    ),
34)
35
36cc_variable(
37    name = "struct_list",
38    actions = ["//tests/rule_based_toolchain/actions:c_compile"],
39    type = types.list(types.struct(
40        nested_str = types.string,
41        nested_str_list = types.list(types.string),
42    )),
43)
44
45cc_variable(
46    name = "struct_list.nested_str_list",
47    type = types.unknown,
48)
49
50# Dots in the name confuse the test rules.
51# It would end up generating targets.struct_list.nested_str_list.
52alias(
53    name = "nested_str_list",
54    actual = ":struct_list.nested_str_list",
55)
56
57cc_nested_args(
58    name = "simple_str",
59    args = [format_arg("%s", ":str")],
60)
61
62cc_nested_args(
63    name = "list_not_allowed",
64    args = [format_arg("%s", ":str_list")],
65)
66
67cc_nested_args(
68    name = "iterate_over_list",
69    args = [format_arg("%s")],
70    iterate_over = ":str_list",
71)
72
73cc_nested_args(
74    name = "iterate_over_non_list",
75    args = ["--foo"],
76    iterate_over = ":str",
77)
78
79cc_nested_args(
80    name = "str_not_a_bool",
81    args = ["--foo"],
82    requires_true = ":str",
83)
84
85cc_nested_args(
86    name = "str_equal",
87    args = ["--foo"],
88    requires_equal = ":str",
89    requires_equal_value = "bar",
90)
91
92cc_nested_args(
93    name = "inner_iter",
94    args = [format_arg("%s")],
95    iterate_over = ":struct_list.nested_str_list",
96)
97
98cc_nested_args(
99    name = "outer_iter",
100    iterate_over = ":struct_list",
101    nested = [":inner_iter"],
102)
103
104cc_nested_args(
105    name = "bad_inner_iter",
106    args = [format_arg("%s", ":struct_list.nested_str_list")],
107)
108
109cc_nested_args(
110    name = "bad_outer_iter",
111    iterate_over = ":struct_list",
112    nested = [":bad_inner_iter"],
113)
114
115cc_nested_args(
116    name = "bad_nested_optional",
117    args = [format_arg("%s", ":str_option")],
118)
119
120cc_nested_args(
121    name = "good_nested_optional",
122    args = [format_arg("%s", ":str_option")],
123    requires_not_none = ":str_option",
124)
125
126cc_nested_args(
127    name = "optional_list_iter",
128    args = ["--foo"],
129    iterate_over = ":optional_list",
130)
131
132cc_builtin_variables(
133    name = "variables",
134    srcs = [
135        ":optional_list",
136        ":str",
137        ":str_list",
138        ":str_option",
139        ":struct",
140        ":struct_list",
141    ],
142)
143
144analysis_test_suite(
145    name = "test_suite",
146    targets = TARGETS,
147    tests = TESTS,
148)
149