Skip to content

Commit df55823

Browse files
authored
fix(toolchain): delete 'share/terminfo' for recent linux python toolchains (#1898)
This affects Linux toolchains that have the `terminfo` databases bundled with the toolchain. Our solution to this is to remove the `share/terminfo` altogether if we are downloading an affected `linux` toolchain. Tested with (on a Mac): ```console bazel build --platforms=//tests/support:linux_x86_64 @python_3_11//:files bazel build --platforms=//tests/support:windows_x86_64 @python_3_11//:files ``` Workaround astral-sh/python-build-standalone#231 Fixes #1800
1 parent 4320d7a commit df55823

File tree

4 files changed

+73
-5
lines changed

4 files changed

+73
-5
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,27 @@ A brief description of the categories of changes:
1717
* Particular sub-systems are identified using parentheses, e.g. `(bzlmod)` or
1818
`(docs)`.
1919

20+
## Unreleased
21+
22+
[x.x.x]: https://github.com/bazelbuild/rules_python/releases/tag/x.x.x
23+
24+
### Changed
25+
26+
### Fixed
27+
28+
### Added
29+
30+
## [0.32.2] - 2024-05-14
31+
32+
[0.32.2]: https://github.com/bazelbuild/rules_python/releases/tag/0.32.2
33+
34+
### Fixed
35+
36+
* Workaround existence of infinite symlink loops on case insensitive filesystems when targeting linux platforms with recent Python toolchains. Works around an upstream [issue][indygreg-231]. Fixes [#1800][rules_python_1800].
37+
38+
[indygreg-231]: https://github.com/indygreg/python-build-standalone/issues/231
39+
[rules_python_1800]: https://github.com/bazelbuild/rules_python/issues/1800
40+
2041
## [0.32.0] - 2024-05-12
2142

2243
[0.32.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.32.0

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ python.toolchain(
4949
is_default = True,
5050
python_version = "3.11",
5151
)
52-
use_repo(python, "python_versions", "pythons_hub")
52+
use_repo(python, "python_3_11", "python_versions", "pythons_hub")
5353

5454
# This call registers the Python toolchains.
5555
register_toolchains("@pythons_hub//:all")

python/repositories.bzl

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def _python_repository_impl(rctx):
176176
rctx.patch(patch, strip = 1)
177177

178178
# Write distutils.cfg to the Python installation.
179-
if "windows" in rctx.os.name:
179+
if "windows" in platform:
180180
distutils_path = "Lib/distutils/distutils.cfg"
181181
else:
182182
distutils_path = "lib/python{}/distutils/distutils.cfg".format(python_short_version)
@@ -187,7 +187,7 @@ def _python_repository_impl(rctx):
187187

188188
# Make the Python installation read-only.
189189
if not rctx.attr.ignore_root_user_error:
190-
if "windows" not in rctx.os.name:
190+
if "windows" not in platform:
191191
lib_dir = "lib" if "windows" not in platform else "Lib"
192192

193193
repo_utils.execute_checked(
@@ -228,7 +228,28 @@ def _python_repository_impl(rctx):
228228
"**/__pycache__/*.pyc.*", # During pyc creation, temp files named *.pyc.NNN are created
229229
]
230230

231-
if rctx.attr.ignore_root_user_error or "windows" in rctx.os.name:
231+
if "linux" in platform:
232+
# Workaround around https://github.com/indygreg/python-build-standalone/issues/231
233+
for url in urls:
234+
head_and_release, _, _ = url.rpartition("/")
235+
_, _, release = head_and_release.rpartition("/")
236+
if not release.isdigit():
237+
# Maybe this is some custom toolchain, so skip this
238+
break
239+
240+
if int(release) >= 20240224:
241+
# Starting with this release the Linux toolchains have infinite symlink loop
242+
# on host platforms that are not Linux. Delete the files no
243+
# matter the host platform so that the cross-built artifacts
244+
# are the same irrespective of the host platform we are
245+
# building on.
246+
#
247+
# Link to the first affected release:
248+
# https://github.com/indygreg/python-build-standalone/releases/tag/20240224
249+
rctx.delete("share/terminfo")
250+
break
251+
252+
if rctx.attr.ignore_root_user_error or "windows" in platform:
232253
glob_exclude += [
233254
# These pycache files are created on first use of the associated python files.
234255
# Exclude them from the glob because otherwise between the first time and second time a python toolchain is used,"
@@ -263,7 +284,7 @@ def _python_repository_impl(rctx):
263284
]
264285

265286
if rctx.attr.coverage_tool:
266-
if "windows" in rctx.os.name:
287+
if "windows" in platform:
267288
coverage_tool = None
268289
else:
269290
coverage_tool = '"{}"'.format(rctx.attr.coverage_tool)

tests/support/BUILD.bazel

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,29 @@ platform(
3737
"@platforms//os:windows",
3838
],
3939
)
40+
41+
# Used when testing downloading of toolchains for a different platform
42+
43+
platform(
44+
name = "linux_x86_64",
45+
constraint_values = [
46+
"@platforms//cpu:x86_64",
47+
"@platforms//os:linux",
48+
],
49+
)
50+
51+
platform(
52+
name = "mac_x86_64",
53+
constraint_values = [
54+
"@platforms//cpu:x86_64",
55+
"@platforms//os:macos",
56+
],
57+
)
58+
59+
platform(
60+
name = "windows_x86_64",
61+
constraint_values = [
62+
"@platforms//cpu:x86_64",
63+
"@platforms//os:windows",
64+
],
65+
)

0 commit comments

Comments
 (0)