Skip to content

Commit d814250

Browse files
committed
fix(toolchain): delete 'share/terminfo' for recent linux python toolchains
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. Workaround astral-sh/python-build-standalone#231 Fixes bazel-contrib#1800
1 parent 4320d7a commit d814250

File tree

3 files changed

+65
-4
lines changed

3 files changed

+65
-4
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

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/BUILD.bazel

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,22 @@ build_test(
2525
"//python/entry_points:py_console_script_binary_bzl",
2626
],
2727
)
28+
29+
# Used for manual tests when downloading a toolchain for a particular platform
30+
platform(
31+
name = "linux_x86_64",
32+
constraint_values = [
33+
"@platforms//cpu:x86_64",
34+
"@platforms//os:linux",
35+
],
36+
visibility = ["//:__subpackages__"],
37+
)
38+
39+
platform(
40+
name = "windows_x86_64",
41+
constraint_values = [
42+
"@platforms//cpu:x86_64",
43+
"@platforms//os:windows",
44+
],
45+
visibility = ["//:__subpackages__"],
46+
)

0 commit comments

Comments
 (0)