@@ -34,12 +34,13 @@ def parse_modules(*, module_ctx, _fail = fail):
34
34
35
35
Returns:
36
36
A struct with the following attributes:
37
- * `toolchains`: The list of toolchains to register. The last
38
- element is special and is treated as the default toolchain.
39
- * `defaults`: The default `kwargs` passed to
40
- {bzl:obj}`python_register_toolchains`.
41
- * `debug_info`: {type}`None | dict` extra information to be passed
42
- to the debug repo.
37
+ * `toolchains`: The list of toolchains to register. The last
38
+ element is special and is treated as the default toolchain.
39
+ * `config`: Various toolchain config, see `_get_toolchain_config`.
40
+ * `debug_info`: {type}`None | dict` extra information to be passed
41
+ to the debug repo.
42
+ * `platforms`: {type}`dict[str, platform_info]` of the base set of
43
+ platforms toolchains should be created for, if possible.
43
44
"""
44
45
if module_ctx .os .environ .get ("RULES_PYTHON_BZLMOD_DEBUG" , "0" ) == "1" :
45
46
debug_info = {
@@ -285,11 +286,12 @@ def _python_impl(module_ctx):
285
286
kwargs .update (py .config .kwargs .get (toolchain_info .python_version , {}))
286
287
kwargs .update (py .config .kwargs .get (full_python_version , {}))
287
288
kwargs .update (py .config .default )
288
- loaded_platforms [ full_python_version ] = python_register_toolchains (
289
+ toolchain_registered_platforms = python_register_toolchains (
289
290
name = toolchain_info .name ,
290
291
_internal_bzlmod_toolchain_call = True ,
291
292
** kwargs
292
293
)
294
+ loaded_platforms [full_python_version ] = toolchain_registered_platforms
293
295
294
296
# List of the base names ("python_3_10") for the toolchain repos
295
297
base_toolchain_repo_names = []
@@ -332,20 +334,19 @@ def _python_impl(module_ctx):
332
334
base_name = t .name
333
335
base_toolchain_repo_names .append (base_name )
334
336
fv = full_version (version = t .python_version , minor_mapping = py .config .minor_mapping )
335
- for platform in loaded_platforms [fv ]:
336
- if platform not in PLATFORMS :
337
- continue
337
+ platforms = loaded_platforms [fv ]
338
+ for platform_name , platform_info in platforms .items ():
338
339
key = str (len (toolchain_names ))
339
340
340
- full_name = "{}_{}" .format (base_name , platform )
341
+ full_name = "{}_{}" .format (base_name , platform_name )
341
342
toolchain_names .append (full_name )
342
343
toolchain_repo_names [key ] = full_name
343
- toolchain_tcw_map [key ] = PLATFORMS [ platform ] .compatible_with
344
+ toolchain_tcw_map [key ] = platform_info .compatible_with
344
345
345
346
# The target_settings attribute may not be present for users
346
347
# patching python/versions.bzl.
347
- toolchain_ts_map [key ] = getattr (PLATFORMS [ platform ] , "target_settings" , [])
348
- toolchain_platform_keys [key ] = platform
348
+ toolchain_ts_map [key ] = getattr (platform_info , "target_settings" , [])
349
+ toolchain_platform_keys [key ] = platform_name
349
350
toolchain_python_versions [key ] = fv
350
351
351
352
# The last toolchain is the default; it can't have version constraints
@@ -483,9 +484,9 @@ def _process_single_version_overrides(*, tag, _fail = fail, default):
483
484
return
484
485
485
486
for platform in (tag .sha256 or []):
486
- if platform not in PLATFORMS :
487
+ if platform not in default [ "platforms" ] :
487
488
_fail ("The platform must be one of {allowed} but got '{got}'" .format (
488
- allowed = sorted (PLATFORMS ),
489
+ allowed = sorted (default [ "platforms" ] ),
489
490
got = platform ,
490
491
))
491
492
return
@@ -602,6 +603,26 @@ def _override_defaults(*overrides, modules, _fail = fail, default):
602
603
override .fn (tag = tag , _fail = _fail , default = default )
603
604
604
605
def _get_toolchain_config (* , modules , _fail = fail ):
606
+ """Computes the configs for toolchains.
607
+
608
+ Args:
609
+ modules: The modules from module_ctx
610
+ _fail: Function to call for failing; only used for testing.
611
+
612
+ Returns:
613
+ A struct with the following:
614
+ * `kwargs`: {type}`dict[str, dict[str, object]` custom kwargs to pass to
615
+ `python_register_toolchains`, keyed by python version.
616
+ The first key is either a Major.Minor or Major.Minor.Patch
617
+ string.
618
+ * `minor_mapping`: {type}`dict[str, str]` the mapping of Major.Minor
619
+ to Major.Minor.Patch.
620
+ * `default`: {type}`dict[str, object]` of kwargs passed along to
621
+ `python_register_toolchains`. These keys take final precedence.
622
+ * `register_all_versions`: {type}`bool` whether all known versions
623
+ should be registered.
624
+ """
625
+
605
626
# Items that can be overridden
606
627
available_versions = {
607
628
version : {
@@ -621,6 +642,7 @@ def _get_toolchain_config(*, modules, _fail = fail):
621
642
}
622
643
default = {
623
644
"base_url" : DEFAULT_RELEASE_BASE_URL ,
645
+ "platforms" : dict (PLATFORMS ), # Copy so it's mutable.
624
646
"tool_versions" : available_versions ,
625
647
}
626
648
0 commit comments