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