Skip to content

Commit 80aab4a

Browse files
authored
fix: Enable location expansion for sh_py_run_test (#2583)
I noticed that my `$(location //path/to:target)` wasn't getting expanded when writing a test. This patch fixes the issue by forwarding the already-expanded environment from the inner target to the outer target.
1 parent 4de99ab commit 80aab4a

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

tests/support/sh_py_run_test.bzl

+3-6
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,14 @@ def _py_reconfig_impl(ctx):
8686
default_info.default_runfiles,
8787
),
8888
),
89-
testing.TestEnvironment(
90-
environment = ctx.attr.env,
91-
),
89+
# Inherit the expanded environment from the inner target.
90+
ctx.attr.target[RunEnvironmentInfo],
9291
]
9392

9493
def _make_reconfig_rule(**kwargs):
9594
attrs = {
9695
"bootstrap_impl": attr.string(),
9796
"build_python_zip": attr.string(default = "auto"),
98-
"env": attr.string_dict(),
9997
"extra_toolchains": attr.string_list(
10098
doc = """
10199
Value for the --extra_toolchains flag.
@@ -133,7 +131,6 @@ def py_reconfig_test(*, name, **kwargs):
133131
reconfig_kwargs["bootstrap_impl"] = kwargs.pop("bootstrap_impl", None)
134132
reconfig_kwargs["extra_toolchains"] = kwargs.pop("extra_toolchains", None)
135133
reconfig_kwargs["python_version"] = kwargs.pop("python_version", None)
136-
reconfig_kwargs["env"] = kwargs.get("env")
137134
reconfig_kwargs["target_compatible_with"] = kwargs.get("target_compatible_with")
138135

139136
inner_name = "_{}_inner".format(name)
@@ -172,7 +169,7 @@ def sh_py_run_test(*, name, sh_src, py_src, **kwargs):
172169

173170
py_binary_kwargs = {
174171
key: kwargs.pop(key)
175-
for key in ("imports", "deps")
172+
for key in ("imports", "deps", "env")
176173
if key in kwargs
177174
}
178175

0 commit comments

Comments
 (0)