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 <jiayanl@google.com>
diff --git a/docs/unittest_doc.md b/docs/unittest_doc.md
index 353d05b..99000e4 100755
--- a/docs/unittest_doc.md
+++ b/docs/unittest_doc.md
@@ -426,7 +426,7 @@
## unittest.make
<pre>
-unittest.make(<a href="#unittest.make-impl">impl</a>, <a href="#unittest.make-attrs">attrs</a>, <a href="#unittest.make-doc">doc</a>)
+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>)
</pre>
Creates a unit test rule from its implementation function.
@@ -439,6 +439,9 @@
The optional `attrs` argument can be used to define dependencies for this
test, in order to form unit tests of rules.
+The optional `toolchains` argument can be used to define toolchain
+dependencies for this test.
+
An example of a unit test:
```
@@ -463,6 +466,7 @@
| <a id="unittest.make-impl"></a>impl | The implementation function of the unit test. | none |
| <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> |
| <a id="unittest.make-doc"></a>doc | A description of the rule that can be extracted by documentation generating tools. | <code>""</code> |
+| <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> |
**RETURNS**
diff --git a/lib/unittest.bzl b/lib/unittest.bzl
index 02e374c..3860ad1 100644
--- a/lib/unittest.bzl
+++ b/lib/unittest.bzl
@@ -148,7 +148,7 @@
impl_name = impl_name.partition("<function ")[-1]
return impl_name.rpartition(">")[0]
-def _make(impl, attrs = {}, doc = ""):
+def _make(impl, attrs = {}, doc = "", toolchains = []):
"""Creates a unit test rule from its implementation function.
Each unit test is defined in an implementation function that must then be
@@ -159,6 +159,9 @@
The optional `attrs` argument can be used to define dependencies for this
test, in order to form unit tests of rules.
+ The optional `toolchains` argument can be used to define toolchain
+ dependencies for this test.
+
An example of a unit test:
```
@@ -179,6 +182,8 @@
attrs: An optional dictionary to supplement the attrs passed to the
unit test's `rule()` constructor.
doc: A description of the rule that can be extracted by documentation generating tools.
+ toolchains: An optional list to supplement the toolchains passed to
+ the unit test's `rule()` constructor.
Returns:
A rule definition that should be stored in a global whose name ends in
@@ -193,7 +198,7 @@
attrs = attrs,
_skylark_testable = True,
test = True,
- toolchains = [TOOLCHAIN_TYPE],
+ toolchains = toolchains + [TOOLCHAIN_TYPE],
)
_ActionInfo = provider(