Skip to content

Commit 60241d2

Browse files
jylinv0JiaYan Lin
andauthored
Add toolchains argument to unittests.make (#483)
* Add toolchains argument to unittests.make Make unittests.make bypass toolchains arguments to target rule's constructor. * update doc --------- Co-authored-by: JiaYan Lin <[email protected]>
1 parent 1a1ee6c commit 60241d2

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

docs/unittest_doc.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ Registers the toolchains for unittest users.
426426
## unittest.make
427427

428428
<pre>
429-
unittest.make(<a href="#unittest.make-impl">impl</a>, <a href="#unittest.make-attrs">attrs</a>, <a href="#unittest.make-doc">doc</a>)
429+
unittest.make(<a href="#unittest.make-impl">impl</a>, <a href="#unittest.make-attrs">attrs</a>, <a href="#unittest.make-doc">doc</a>, <a href="#unittest.make-toolchains">toolchains</a>)
430430
</pre>
431431

432432
Creates a unit test rule from its implementation function.
@@ -439,6 +439,9 @@ implementation function's name so that it can be printed in test feedback.
439439
The optional `attrs` argument can be used to define dependencies for this
440440
test, in order to form unit tests of rules.
441441

442+
The optional `toolchains` argument can be used to define toolchain
443+
dependencies for this test.
444+
442445
An example of a unit test:
443446

444447
```
@@ -463,6 +466,7 @@ Recall that names of test rules must end in `_test`.
463466
| <a id="unittest.make-impl"></a>impl | The implementation function of the unit test. | none |
464467
| <a id="unittest.make-attrs"></a>attrs | An optional dictionary to supplement the attrs passed to the unit test's <code>rule()</code> constructor. | <code>{}</code> |
465468
| <a id="unittest.make-doc"></a>doc | A description of the rule that can be extracted by documentation generating tools. | <code>""</code> |
469+
| <a id="unittest.make-toolchains"></a>toolchains | An optional list to supplement the toolchains passed to the unit test's <code>rule()</code> constructor. | <code>[]</code> |
466470

467471
**RETURNS**
468472

lib/unittest.bzl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def _impl_function_name(impl):
148148
impl_name = impl_name.partition("<function ")[-1]
149149
return impl_name.rpartition(">")[0]
150150

151-
def _make(impl, attrs = {}, doc = ""):
151+
def _make(impl, attrs = {}, doc = "", toolchains = []):
152152
"""Creates a unit test rule from its implementation function.
153153
154154
Each unit test is defined in an implementation function that must then be
@@ -159,6 +159,9 @@ def _make(impl, attrs = {}, doc = ""):
159159
The optional `attrs` argument can be used to define dependencies for this
160160
test, in order to form unit tests of rules.
161161
162+
The optional `toolchains` argument can be used to define toolchain
163+
dependencies for this test.
164+
162165
An example of a unit test:
163166
164167
```
@@ -179,6 +182,8 @@ def _make(impl, attrs = {}, doc = ""):
179182
attrs: An optional dictionary to supplement the attrs passed to the
180183
unit test's `rule()` constructor.
181184
doc: A description of the rule that can be extracted by documentation generating tools.
185+
toolchains: An optional list to supplement the toolchains passed to
186+
the unit test's `rule()` constructor.
182187
183188
Returns:
184189
A rule definition that should be stored in a global whose name ends in
@@ -193,7 +198,7 @@ def _make(impl, attrs = {}, doc = ""):
193198
attrs = attrs,
194199
_skylark_testable = True,
195200
test = True,
196-
toolchains = [TOOLCHAIN_TYPE],
201+
toolchains = toolchains + [TOOLCHAIN_TYPE],
197202
)
198203

199204
_ActionInfo = provider(

0 commit comments

Comments
 (0)