File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -124,6 +124,8 @@ Unreleased changes template.
124124* (toolchains) Local Python installs can be used to create a toolchain
125125 equivalent to the standard toolchains. See [ Local toolchains] docs for how to
126126 configure them.
127+ * (toolchains) Expose ` $(PYTHON2_ROOTPATH) ` and ` $(PYTHON3_ROOTPATH) ` which are runfiles
128+ locations equivalents of ` $(PYTHON2) ` and `$(PYTHON3) respectively.
127129
128130
129131{#v0-0-0-removed}
Original file line number Diff line number Diff line change @@ -215,7 +215,11 @@ attribute. You can obtain the path to the Python interpreter using the
215215` $(PYTHON2) ` and ` $(PYTHON3) ` [ "Make"
216216Variables] ( https://bazel.build/reference/be/make-variables ) . See the
217217{gh-path}` test_current_py_toolchain <tests/load_from_macro/BUILD.bazel> ` target
218- for an example.
218+ for an example. We also make available ` $(PYTHON2_ROOTPATH) ` and ` $(PYTHON3_ROOTPATH) `
219+ which are Make Variable equivalents of ` $(PYTHON2) ` and ` $(PYTHON3) ` but for runfiles
220+ locations. These will be helpful if you need to set env vars of binary/test rules
221+ while using [ ` --nolegacy_external_runfiles ` ] ( https://bazel.build/reference/command-line-reference#flag--legacy_external_runfiles ) .
222+ The original make variables still work in exec contexts such as genrules.
219223
220224### Overriding toolchain defaults and adding more versions
221225
Original file line number Diff line number Diff line change @@ -27,11 +27,13 @@ def _current_py_toolchain_impl(ctx):
2727 direct .append (toolchain .py3_runtime .interpreter )
2828 transitive .append (toolchain .py3_runtime .files )
2929 vars ["PYTHON3" ] = toolchain .py3_runtime .interpreter .path
30+ vars ["PYTHON3_ROOTPATH" ] = toolchain .py3_runtime .interpreter .short_path
3031
3132 if toolchain .py2_runtime and toolchain .py2_runtime .interpreter :
3233 direct .append (toolchain .py2_runtime .interpreter )
3334 transitive .append (toolchain .py2_runtime .files )
3435 vars ["PYTHON2" ] = toolchain .py2_runtime .interpreter .path
36+ vars ["PYTHON2_ROOTPATH" ] = toolchain .py2_runtime .interpreter .short_path
3537
3638 files = depset (direct , transitive = transitive )
3739 return [
@@ -49,6 +51,11 @@ current_py_toolchain = rule(
4951 other rules, such as genrule. It allows exposing a python toolchain after toolchain resolution has
5052 happened, to a rule which expects a concrete implementation of a toolchain, rather than a
5153 toolchain_type which could be resolved to that toolchain.
54+
55+ :::{versionchanged} VERSION_NEXT_FEATURE
56+ From now on, we also expose `$(PYTHON2_ROOTPATH)` and `$(PYTHON3_ROOTPATH)` which are runfiles
57+ locations equivalents of `$(PYTHON2)` and `$(PYTHON3) respectively.
58+ :::
5259 """ ,
5360 implementation = _current_py_toolchain_impl ,
5461 attrs = {
You can’t perform that action at this time.
0 commit comments