diff --git a/docs/native_binary_doc.md b/docs/native_binary_doc.md index a23b2420..ecc9b569 100755 --- a/docs/native_binary_doc.md +++ b/docs/native_binary_doc.md @@ -41,7 +41,7 @@ in genrule.tools for example. You can also augment the binary with runfiles.
load("@bazel_skylib//rules:native_binary.bzl", "native_test")
-native_test(name, src, data, out, env)
+native_test(name, src, data, out, env, env_inherit)
Wraps a pre-built binary or script with a test rule.
@@ -59,5 +59,6 @@ the binary with runfiles.
| data | data dependencies. See https://bazel.build/reference/be/common-definitions#typical.data | List of labels | optional | `[]` |
| out | An output name for the copy of the binary. Defaults to name.exe. (We add .exe to the name by default because it's required on Windows and tolerated on other platforms.) | String | optional | `""` |
| env | Environment variables to set when running the binary. | Dictionary: String -> String | optional | `{}` |
+| env_inherit | List of environment variable names to be inherited from the external environment when the test is executed by bazel test. | List of strings | optional | `[]` |
diff --git a/rules/native_binary.bzl b/rules/native_binary.bzl
index 25b3021a..33b027b6 100644
--- a/rules/native_binary.bzl
+++ b/rules/native_binary.bzl
@@ -42,6 +42,7 @@ def _impl_rule(ctx):
),
RunEnvironmentInfo(
environment = ctx.attr.env,
+ inherited_environment = getattr(ctx.attr, "env_inherit", []),
),
]
@@ -73,6 +74,13 @@ _ATTRS = {
),
}
+_TEST_ATTRS = _ATTRS | {
+ "env_inherit": attr.string_list(
+ doc = "List of environment variable names to be inherited from the " +
+ "external environment when the test is executed by bazel test.",
+ ),
+}
+
native_binary = rule(
implementation = _impl_rule,
attrs = _ATTRS,
@@ -87,7 +95,7 @@ in genrule.tools for example. You can also augment the binary with runfiles.
native_test = rule(
implementation = _impl_rule,
- attrs = _ATTRS,
+ attrs = _TEST_ATTRS,
test = True,
doc = """
Wraps a pre-built binary or script with a test rule.