@@ -83,7 +83,18 @@ def _impl(ctx):
83
83
providers .extend (test_providers )
84
84
return _handle_legacy_return (ctx , cc_info , providers )
85
85
86
- def _make_cc_test (with_linkstatic = False , with_aspects = False ):
86
+ def make_cc_test (with_linkstatic = False , with_aspects = False ):
87
+ """Makes one of the cc_test rule variants.
88
+
89
+ This function shall only be used internally in CC ruleset.
90
+
91
+ Args:
92
+ with_linkstatic: sets value _linkstatic_explicitly_set attribute
93
+ with_aspects: Attaches graph_structure_aspect to `deps` attribute and
94
+ implicit deps.
95
+ Returns:
96
+ A cc_test rule class.
97
+ """
87
98
_cc_test_attrs = None
88
99
if with_aspects :
89
100
_cc_test_attrs = dict (cc_binary_attrs_with_aspects )
@@ -119,7 +130,6 @@ def _make_cc_test(with_linkstatic = False, with_aspects = False):
119
130
_linkstatic_explicitly_set = attr .bool (default = with_linkstatic ),
120
131
)
121
132
return rule (
122
- name = "cc_test" ,
123
133
implementation = _impl ,
124
134
attrs = _cc_test_attrs ,
125
135
outputs = {
@@ -135,39 +145,3 @@ def _make_cc_test(with_linkstatic = False, with_aspects = False):
135
145
incompatible_use_toolchain_transition = True ,
136
146
test = True ,
137
147
)
138
-
139
- _cc_test_variants = struct (
140
- with_aspects = struct (
141
- explicit_linkstatic = _make_cc_test (with_linkstatic = True , with_aspects = True ),
142
- default_linkstatic = _make_cc_test (with_aspects = True ),
143
- ),
144
- without_aspects = struct (
145
- explicit_linkstatic = _make_cc_test (with_linkstatic = True ),
146
- default_linkstatic = _make_cc_test (),
147
- ),
148
- )
149
-
150
- def cc_test_wrapper (** kwargs ):
151
- """Entry point for cc_test rules.
152
-
153
- This avoids propagating aspects on certain attributes if dynamic_deps attribute is unset.
154
-
155
- It also serves to detect if the `linkstatic` attribute was explicitly set or not.
156
- This is to workaround a deficiency in Starlark attributes.
157
- (See: https://github.com/bazelbuild/bazel/issues/14434)
158
-
159
- Args:
160
- **kwargs: Arguments suitable for cc_test.
161
- """
162
- cc_test_aspects = None
163
-
164
- # Propagate an aspect if dynamic_deps attribute is specified.
165
- if "dynamic_deps" in kwargs and cc_helper .is_non_empty_list_or_select (kwargs ["dynamic_deps" ], "dynamic_deps" ):
166
- cc_test_aspects = _cc_test_variants .with_aspects
167
- else :
168
- cc_test_aspects = _cc_test_variants .without_aspects
169
-
170
- if "linkstatic" in kwargs :
171
- cc_test_aspects .explicit_linkstatic (** kwargs )
172
- else :
173
- cc_test_aspects .default_linkstatic (** kwargs )
0 commit comments