From d8142504c7de92cb2f8e2dc687d7424b8c7bd907 Mon Sep 17 00:00:00 2001 From: aignas <240938+aignas@users.noreply.github.com> Date: Tue, 14 May 2024 10:41:36 +0900 Subject: [PATCH] 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 https://github.com/indygreg/python-build-standalone/issues/231 Fixes #1800 --- CHANGELOG.md | 21 +++++++++++++++++++++ python/repositories.bzl | 29 +++++++++++++++++++++++++---- tests/BUILD.bazel | 19 +++++++++++++++++++ 3 files changed, 65 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index daccaaa37a..0a3031c2a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,27 @@ A brief description of the categories of changes: * Particular sub-systems are identified using parentheses, e.g. `(bzlmod)` or `(docs)`. +## Unreleased + +[x.x.x]: https://github.com/bazelbuild/rules_python/releases/tag/x.x.x + +### Changed + +### Fixed + +### Added + +## [0.32.2] - 2024-05-14 + +[0.32.2]: https://github.com/bazelbuild/rules_python/releases/tag/0.32.2 + +### Fixed + +* 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]. + +[indygreg-231]: https://github.com/indygreg/python-build-standalone/issues/231 +[rules_python_1800]: https://github.com/bazelbuild/rules_python/issues/1800 + ## [0.32.0] - 2024-05-12 [0.32.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.32.0 diff --git a/python/repositories.bzl b/python/repositories.bzl index f77d302ca6..eb122b6e7b 100644 --- a/python/repositories.bzl +++ b/python/repositories.bzl @@ -176,7 +176,7 @@ def _python_repository_impl(rctx): rctx.patch(patch, strip = 1) # Write distutils.cfg to the Python installation. - if "windows" in rctx.os.name: + if "windows" in platform: distutils_path = "Lib/distutils/distutils.cfg" else: distutils_path = "lib/python{}/distutils/distutils.cfg".format(python_short_version) @@ -187,7 +187,7 @@ def _python_repository_impl(rctx): # Make the Python installation read-only. if not rctx.attr.ignore_root_user_error: - if "windows" not in rctx.os.name: + if "windows" not in platform: lib_dir = "lib" if "windows" not in platform else "Lib" repo_utils.execute_checked( @@ -228,7 +228,28 @@ def _python_repository_impl(rctx): "**/__pycache__/*.pyc.*", # During pyc creation, temp files named *.pyc.NNN are created ] - if rctx.attr.ignore_root_user_error or "windows" in rctx.os.name: + if "linux" in platform: + # Workaround around https://github.com/indygreg/python-build-standalone/issues/231 + for url in urls: + head_and_release, _, _ = url.rpartition("/") + _, _, release = head_and_release.rpartition("/") + if not release.isdigit(): + # Maybe this is some custom toolchain, so skip this + break + + if int(release) >= 20240224: + # Starting with this release the Linux toolchains have infinite symlink loop + # on host platforms that are not Linux. Delete the files no + # matter the host platform so that the cross-built artifacts + # are the same irrespective of the host platform we are + # building on. + # + # Link to the first affected release: + # https://github.com/indygreg/python-build-standalone/releases/tag/20240224 + rctx.delete("share/terminfo") + break + + if rctx.attr.ignore_root_user_error or "windows" in platform: glob_exclude += [ # These pycache files are created on first use of the associated python files. # 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): ] if rctx.attr.coverage_tool: - if "windows" in rctx.os.name: + if "windows" in platform: coverage_tool = None else: coverage_tool = '"{}"'.format(rctx.attr.coverage_tool) diff --git a/tests/BUILD.bazel b/tests/BUILD.bazel index e7dbef65d8..5c2dce435d 100644 --- a/tests/BUILD.bazel +++ b/tests/BUILD.bazel @@ -25,3 +25,22 @@ build_test( "//python/entry_points:py_console_script_binary_bzl", ], ) + +# Used for manual tests when downloading a toolchain for a particular platform +platform( + name = "linux_x86_64", + constraint_values = [ + "@platforms//cpu:x86_64", + "@platforms//os:linux", + ], + visibility = ["//:__subpackages__"], +) + +platform( + name = "windows_x86_64", + constraint_values = [ + "@platforms//cpu:x86_64", + "@platforms//os:windows", + ], + visibility = ["//:__subpackages__"], +)