@@ -19,21 +19,28 @@ without the overhead of a bazel-in-bazel integration test.
1919
2020load ("//python:py_binary.bzl" , "py_binary" )
2121load ("//python:py_test.bzl" , "py_test" )
22+ load ("//python/private:toolchain_types.bzl" , "TARGET_TOOLCHAIN_TYPE" ) # buildifier: disable=bzl-visibility
2223
2324def _perform_transition_impl (input_settings , attr ):
2425 settings = dict (input_settings )
2526 settings ["//command_line_option:build_python_zip" ] = attr .build_python_zip
2627 if attr .bootstrap_impl :
2728 settings ["//python/config_settings:bootstrap_impl" ] = attr .bootstrap_impl
29+ if attr .extra_toolchains :
30+ settings ["//command_line_option:extra_toolchains" ] = attr .extra_toolchains
31+ else :
32+ settings ["//command_line_option:extra_toolchains" ] = input_settings ["//command_line_option:extra_toolchains" ]
2833 return settings
2934
3035_perform_transition = transition (
3136 implementation = _perform_transition_impl ,
3237 inputs = [
3338 "//python/config_settings:bootstrap_impl" ,
39+ "//command_line_option:extra_toolchains" ,
3440 ],
3541 outputs = [
3642 "//command_line_option:build_python_zip" ,
43+ "//command_line_option:extra_toolchains" ,
3744 "//python/config_settings:bootstrap_impl" ,
3845 ],
3946)
@@ -79,17 +86,27 @@ def _py_reconfig_impl(ctx):
7986 ]
8087
8188def _make_reconfig_rule (** kwargs ):
89+ attrs = {
90+ "bootstrap_impl" : attr .string (),
91+ "build_python_zip" : attr .string (default = "auto" ),
92+ "env" : attr .string_dict (),
93+ "extra_toolchains" : attr .string_list (
94+ doc = """
95+ Value for the --extra_toolchains flag.
96+
97+ NOTE: You'll likely have to also specify //tests/cc:all (or some CC toolchain)
98+ to make the RBE presubmits happy, which disable auto-detection of a CC
99+ toolchain.
100+ """ ,
101+ ),
102+ "target" : attr .label (executable = True , cfg = "target" ),
103+ "_allowlist_function_transition" : attr .label (
104+ default = "@bazel_tools//tools/allowlists/function_transition_allowlist" ,
105+ ),
106+ }
82107 return rule (
83108 implementation = _py_reconfig_impl ,
84- attrs = {
85- "bootstrap_impl" : attr .string (),
86- "build_python_zip" : attr .string (default = "auto" ),
87- "env" : attr .string_dict (),
88- "target" : attr .label (executable = True , cfg = "target" ),
89- "_allowlist_function_transition" : attr .label (
90- default = "@bazel_tools//tools/allowlists/function_transition_allowlist" ,
91- ),
92- },
109+ attrs = attrs ,
93110 cfg = _perform_transition ,
94111 ** kwargs
95112 )
@@ -106,7 +123,8 @@ def py_reconfig_test(*, name, **kwargs):
106123 **kwargs: kwargs to pass along to _py_reconfig_test and py_test.
107124 """
108125 reconfig_kwargs = {}
109- reconfig_kwargs ["bootstrap_impl" ] = kwargs .pop ("bootstrap_impl" )
126+ reconfig_kwargs ["bootstrap_impl" ] = kwargs .pop ("bootstrap_impl" , None )
127+ reconfig_kwargs ["extra_toolchains" ] = kwargs .pop ("extra_toolchains" , None )
110128 reconfig_kwargs ["env" ] = kwargs .get ("env" )
111129 inner_name = "_{}_inner" + name
112130 _py_reconfig_test (
@@ -147,3 +165,33 @@ def sh_py_run_test(*, name, sh_src, py_src, **kwargs):
147165 main = py_src ,
148166 tags = ["manual" ],
149167 )
168+
169+ def _current_build_settings_impl (ctx ):
170+ info = ctx .actions .declare_file (ctx .label .name + ".json" )
171+ toolchain = ctx .toolchains [TARGET_TOOLCHAIN_TYPE ]
172+ runtime = toolchain .py3_runtime
173+ files = [info ]
174+ ctx .actions .write (
175+ output = info ,
176+ content = json .encode ({
177+ "interpreter" : {
178+ "short_path" : runtime .interpreter .short_path if runtime .interpreter else None ,
179+ },
180+ "interpreter_path" : runtime .interpreter_path ,
181+ }),
182+ )
183+ return [DefaultInfo (
184+ files = depset (files ),
185+ )]
186+
187+ current_build_settings = rule (
188+ doc = """
189+ Writes information about the current build config to JSON for testing.
190+
191+ This is so tests can verify information about the build config used for them.
192+ """ ,
193+ implementation = _current_build_settings_impl ,
194+ toolchains = [
195+ TARGET_TOOLCHAIN_TYPE ,
196+ ],
197+ )
0 commit comments