Skip to content

Commit ff30935

Browse files
authored
fix(repo setup): Skip aliases for unloaded toolchains (#1473)
Some platforms don't contain every version, e.g. s390x doesn't have 3.8, which is indicated by a missing sha256 value. When this happens, no repository for the runtime is created (`python_repository` rule). Similar logic needs to be in the toolchains setup logic because otherwise a reference to an undefined repository exists in the select() expression of the aliases. Because those references are lazily evaluated, they don't always cause a problem, but do mean that query operations (e.g., `rdeps()`) can't work and the order of entries is important (which is surprising). Closes #1472
1 parent cbac8dd commit ff30935

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ A brief description of the categories of changes:
1919

2020
## Unreleased
2121

22+
### Fixed
23+
24+
* Skip aliases for unloaded toolchains. Some Python versions that don't have full
25+
platform support, and referencing their undefined repositories can break operations
26+
like `bazel query rdeps(...)`.
27+
2228
## [0.26.0] - 2023-10-06
2329

2430
### Changed

python/private/toolchains_repo.bzl

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,22 +155,27 @@ def _toolchain_aliases_impl(rctx):
155155
build_contents = """\
156156
# Generated by python/private/toolchains_repo.bzl
157157
package(default_visibility = ["//visibility:public"])
158-
load("@rules_python//python:versions.bzl", "PLATFORMS", "gen_python_config_settings")
158+
load("@rules_python//python:versions.bzl", "gen_python_config_settings")
159159
gen_python_config_settings()
160160
exports_files(["defs.bzl"])
161-
alias(name = "files", actual = select({{":" + item: "@{py_repository}_" + item + "//:files" for item in PLATFORMS.keys()}}))
162-
alias(name = "includes", actual = select({{":" + item: "@{py_repository}_" + item + "//:includes" for item in PLATFORMS.keys()}}))
163-
alias(name = "libpython", actual = select({{":" + item: "@{py_repository}_" + item + "//:libpython" for item in PLATFORMS.keys()}}))
164-
alias(name = "py3_runtime", actual = select({{":" + item: "@{py_repository}_" + item + "//:py3_runtime" for item in PLATFORMS.keys()}}))
165-
alias(name = "python_headers", actual = select({{":" + item: "@{py_repository}_" + item + "//:python_headers" for item in PLATFORMS.keys()}}))
166-
alias(name = "python_runtimes", actual = select({{":" + item: "@{py_repository}_" + item + "//:python_runtimes" for item in PLATFORMS.keys()}}))
167-
alias(name = "python3", actual = select({{":" + item: "@{py_repository}_" + item + "//:" + ("python.exe" if "windows" in item else "bin/python3") for item in PLATFORMS.keys()}}))
161+
162+
PLATFORMS = [
163+
{loaded_platforms}
164+
]
165+
alias(name = "files", actual = select({{":" + item: "@{py_repository}_" + item + "//:files" for item in PLATFORMS}}))
166+
alias(name = "includes", actual = select({{":" + item: "@{py_repository}_" + item + "//:includes" for item in PLATFORMS}}))
167+
alias(name = "libpython", actual = select({{":" + item: "@{py_repository}_" + item + "//:libpython" for item in PLATFORMS}}))
168+
alias(name = "py3_runtime", actual = select({{":" + item: "@{py_repository}_" + item + "//:py3_runtime" for item in PLATFORMS}}))
169+
alias(name = "python_headers", actual = select({{":" + item: "@{py_repository}_" + item + "//:python_headers" for item in PLATFORMS}}))
170+
alias(name = "python_runtimes", actual = select({{":" + item: "@{py_repository}_" + item + "//:python_runtimes" for item in PLATFORMS}}))
171+
alias(name = "python3", actual = select({{":" + item: "@{py_repository}_" + item + "//:" + ("python.exe" if "windows" in item else "bin/python3") for item in PLATFORMS}}))
168172
""".format(
169173
py_repository = rctx.attr.user_repository_name,
174+
loaded_platforms = "\n".join([" \"{}\",".format(p) for p in rctx.attr.platforms]),
170175
)
171176
if not is_windows:
172177
build_contents += """\
173-
alias(name = "pip", actual = select({{":" + item: "@{py_repository}_" + item + "//:python_runtimes" for item in PLATFORMS.keys() if "windows" not in item}}))
178+
alias(name = "pip", actual = select({{":" + item: "@{py_repository}_" + item + "//:python_runtimes" for item in PLATFORMS if "windows" not in item}}))
174179
""".format(
175180
py_repository = rctx.attr.user_repository_name,
176181
host_platform = host_platform,
@@ -239,6 +244,9 @@ toolchain_aliases = repository_rule(
239244
a BUILD.bazel file declaring aliases to the host platform's targets.
240245
""",
241246
attrs = {
247+
"platforms": attr.string_list(
248+
doc = "List of platforms for which aliases shall be created",
249+
),
242250
"python_version": attr.string(doc = "The Python version."),
243251
"user_repository_name": attr.string(
244252
mandatory = True,

python/repositories.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,11 +553,13 @@ def python_register_toolchains(
553553
))
554554
register_coverage_tool = False
555555

556+
loaded_platforms = []
556557
for platform in PLATFORMS.keys():
557558
sha256 = tool_versions[python_version]["sha256"].get(platform, None)
558559
if not sha256:
559560
continue
560561

562+
loaded_platforms.append(platform)
561563
(release_filename, urls, strip_prefix, patches) = get_release_info(platform, python_version, base_url, tool_versions)
562564

563565
# allow passing in a tool version
@@ -604,6 +606,7 @@ def python_register_toolchains(
604606
name = name,
605607
python_version = python_version,
606608
user_repository_name = name,
609+
platforms = loaded_platforms,
607610
)
608611

609612
# in bzlmod we write out our own toolchain repos

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy