From 50ab2c69d9702fb1e708d841238749fde068bc77 Mon Sep 17 00:00:00 2001 From: Jesse Schalken Date: Wed, 27 Jul 2022 23:28:55 +1000 Subject: [PATCH 1/2] Fix download of Windows Python toolchain on Linux --- python/repositories.bzl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/repositories.bzl b/python/repositories.bzl index 8bb8a9ced9..d4d929de35 100644 --- a/python/repositories.bzl +++ b/python/repositories.bzl @@ -110,7 +110,8 @@ 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: - exec_result = rctx.execute(["chmod", "-R", "ugo-w", "lib"]) + lib_dir = "lib" if "windows" not in platform else "Lib" + exec_result = rctx.execute(["chmod", "-R", "ugo-w", lib_dir]) if exec_result.return_code != 0: fail_msg = "Failed to make interpreter installation read-only. 'chmod' error msg: {}".format( exec_result.stderr, @@ -148,6 +149,7 @@ filegroup( "DLLs/**", "extensions/**", "include/**", + "Lib/**", "lib/**", "libs/**", "Scripts/**", From 077fedf71c9e39ff8231ae7354d32422337d6ed7 Mon Sep 17 00:00:00 2001 From: Jesse Schalken Date: Wed, 3 Aug 2022 02:58:25 +1000 Subject: [PATCH 2/2] Use a more specific glob based on the target platform to avoid picking up lib twice (as Lib) on macOS --- python/repositories.bzl | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/python/repositories.bzl b/python/repositories.bzl index d4d929de35..30c284191a 100644 --- a/python/repositories.bzl +++ b/python/repositories.bzl @@ -132,17 +132,8 @@ def _python_repository_impl(rctx): python_bin = "python.exe" if ("windows" in platform) else "bin/python3" - build_content = """\ -# Generated by python/repositories.bzl - -load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair") - -package(default_visibility = ["//visibility:public"]) - -filegroup( - name = "files", - srcs = glob( - include = [ + if "windows" in platform: + glob_include = [ "*.exe", "*.dll", "bin/**", @@ -150,11 +141,31 @@ filegroup( "extensions/**", "include/**", "Lib/**", - "lib/**", "libs/**", "Scripts/**", "share/**", - ], + ] + else: + glob_include = [ + "bin/**", + "extensions/**", + "include/**", + "lib/**", + "libs/**", + "share/**", + ] + + build_content = """\ +# Generated by python/repositories.bzl + +load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "files", + srcs = glob( + include = {glob_include}, # Platform-agnostic filegroup can't match on all patterns. allow_empty = True, exclude = [ @@ -208,6 +219,7 @@ py_runtime_pair( py3_runtime = ":py3_runtime", ) """.format( + glob_include = repr(glob_include), python_path = python_bin, python_version = python_short_version, )