Skip to content

Commit 6fc07d7

Browse files
committed
fix/handle missing interpreter in bin
1 parent 5344aa0 commit 6fc07d7

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

python/private/py_executable.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,6 @@ def _create_venv_unixy(ctx, *, venv_root, runtime, interpreter_actual_path):
662662
# needed or used at runtime. However, the zip code uses the interpreter
663663
# File object to figure out some paths.
664664
interpreter = ctx.actions.declare_file("{}/{}".format(bin_dir, py_exe_basename))
665-
666665
ctx.actions.write(interpreter, "actual:{}".format(interpreter_actual_path))
667666

668667
elif runtime.interpreter:
@@ -671,6 +670,7 @@ def _create_venv_unixy(ctx, *, venv_root, runtime, interpreter_actual_path):
671670
# in runfiles is always a symlink. An RBE implementation, for example,
672671
# may choose to write what symlink() points to instead.
673672
interpreter = ctx.actions.declare_symlink("{}/{}".format(bin_dir, py_exe_basename))
673+
interpreter_runfiles.add(interpreter)
674674

675675
rel_path = relative_path(
676676
# dirname is necessary because a relative symlink is relative to
@@ -681,6 +681,7 @@ def _create_venv_unixy(ctx, *, venv_root, runtime, interpreter_actual_path):
681681
ctx.actions.symlink(output = interpreter, target_path = rel_path)
682682
else:
683683
interpreter = ctx.actions.declare_symlink("{}/{}".format(bin_dir, py_exe_basename))
684+
interpreter_runfiles.add(interpreter)
684685
ctx.actions.symlink(output = interpreter, target_path = runtime.interpreter_path)
685686
else:
686687
interpreter = None

python/private/python_bootstrap_template.txt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,9 @@ def search_path(name):
144144
def find_python_binary(runfiles_root):
145145
"""Finds the real Python binary if it's not a normal absolute path."""
146146
if PYTHON_BINARY:
147-
bin_path = find_binary(runfiles_root, PYTHON_BINARY)
147+
return find_binary(runfiles_root, PYTHON_BINARY)
148148
else:
149-
bin_path = find_binary(runfiles_root, PYTHON_BINARY_ACTUAL)
150-
return bin_path
149+
return find_binary(runfiles_root, PYTHON_BINARY_ACTUAL)
151150

152151

153152
def print_verbose(*args, mapping=None, values=None):
@@ -353,13 +352,16 @@ print(site.getsitepackages(["{venv_src}"])[-1])
353352
target = join(python_home, f)
354353
_symlink_exist_ok(from_=venv_path, to=target)
355354

356-
# Re-add all the entries under bin/, which includes supporting
357-
# .dll files when under windows.
358355
runfiles_venv_bin = join(runfiles_venv, BIN_DIR_NAME)
359-
for f_basename in os.listdir(runfiles_venv_bin):
360-
venv_path = join(venv, BIN_DIR_NAME, f_basename)
361-
target = join(runfiles_venv_bin, f_basename)
362-
_symlink_exist_ok(from_=venv_path, to=target)
356+
# The runfiles bin directory may not exist if
357+
# supports_build_time_venv=False and the interpreter is resolved at runtime.
358+
if os.path.exists(runfiles_venv_bin):
359+
# Re-add all the entries under bin/, which includes supporting
360+
# .dll files when under windows.
361+
for f_basename in os.listdir(runfiles_venv_bin):
362+
venv_path = join(venv, BIN_DIR_NAME, f_basename)
363+
target = join(runfiles_venv_bin, f_basename)
364+
_symlink_exist_ok(from_=venv_path, to=target)
363365

364366
_symlink_exist_ok(from_=join(venv, "lib"), to=join(runfiles_venv, "lib"))
365367
_symlink_exist_ok(from_=venv_site_packages, to=runfiles_venv_site_packages)

0 commit comments

Comments
 (0)