diff options
author | Chris Love <335402+chrislovecnm@users.noreply.github.com> | 2023-06-13 13:13:15 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-13 19:13:15 +0000 |
commit | 3903d1a5b94cf5908cdd571d5c09bb27a5310ce2 (patch) | |
tree | 8eab0ccaf8db0dce72e8f892617c11a20beb8d39 | |
parent | 68db9553946b6ad83e820e1297dddb9502601f8f (diff) | |
download | bazelbuild-rules_python-3903d1a5b94cf5908cdd571d5c09bb27a5310ce2.tar.gz |
fix(bzlmod): Fixing Windows Python Interpreter symlink issues (#1265)
When using Windows you cannot run the symlink directly.
Because of how symlinks work in Windows we need to path realpath resolve
the link.
Unlike Linux and OSX we cannot execute the Python symlink directly.
Windows throws an error "-1073741515", when we execute the symlink
directory. This error means that the Python binary cannot find dlls.
This is because the symlink that we create is not in the same folder as
the dlls.
---------
Co-authored-by: Richard Levasseur <richardlev@gmail.com>
-rw-r--r-- | python/pip_install/pip_repository.bzl | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/python/pip_install/pip_repository.bzl b/python/pip_install/pip_repository.bzl index 5239fd5..915b470 100644 --- a/python/pip_install/pip_repository.bzl +++ b/python/pip_install/pip_repository.bzl @@ -15,9 +15,11 @@ "" load("//python:repositories.bzl", "get_interpreter_dirname", "is_standalone_interpreter") +load("//python:versions.bzl", "WINDOWS_NAME") load("//python/pip_install:repositories.bzl", "all_requirements") load("//python/pip_install:requirements_parser.bzl", parse_requirements = "parse") load("//python/pip_install/private:srcs.bzl", "PIP_INSTALL_PY_SRCS") +load("//python/private:toolchains_repo.bzl", "get_host_os_arch") CPPFLAGS = "CPPFLAGS" @@ -72,8 +74,16 @@ def _resolve_python_interpreter(rctx): python_interpreter = _get_python_interpreter_attr(rctx) if rctx.attr.python_interpreter_target != None: - target = rctx.attr.python_interpreter_target - python_interpreter = rctx.path(target) + python_interpreter = rctx.path(rctx.attr.python_interpreter_target) + + # If we have @@ we have bzlmod so we need to hand Windows differently. + if str(Label("//:unused")).startswith("@@"): + (os, _) = get_host_os_arch(rctx) + + # On Windows, the symlink doesn't work because Windows attempts to find + # Python DLLs where the symlink is, not where the symlink points. + if os == WINDOWS_NAME: + python_interpreter = python_interpreter.realpath elif "/" not in python_interpreter: found_python_interpreter = rctx.which(python_interpreter) if not found_python_interpreter: @@ -670,7 +680,6 @@ py_binary( def _whl_library_impl(rctx): python_interpreter = _resolve_python_interpreter(rctx) - args = [ python_interpreter, "-m", @@ -699,7 +708,7 @@ def _whl_library_impl(rctx): ) if result.return_code: - fail("whl_library %s failed: %s (%s)" % (rctx.attr.name, result.stdout, result.stderr)) + fail("whl_library %s failed: %s (%s) error code: '%s'" % (rctx.attr.name, result.stdout, result.stderr, result.return_code)) return |