Skip to content

Commit 8076029

Browse files
committed
fix: group venv symlink creation into runfiles symlinks
1 parent e132012 commit 8076029

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

python/private/py_executable.bzl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def _create_executable(
356356
[stage2_bootstrap] + (
357357
venv.files_without_interpreter if venv else []
358358
),
359-
)
359+
).merge(venv.runfiles)
360360
zip_main = _create_zip_main(
361361
ctx,
362362
stage2_bootstrap = stage2_bootstrap,
@@ -606,7 +606,7 @@ def _create_venv(ctx, output_prefix, imports, runtime_details):
606606
}
607607
venv_app_files = create_venv_app_files(ctx, ctx.attr.deps, venv_dir_map)
608608

609-
files_without_interpreter = [pth, site_init] + venv_app_files
609+
files_without_interpreter = [pth, site_init] + venv_app_files.venv_files
610610
if pyvenv_cfg:
611611
files_without_interpreter.append(pyvenv_cfg)
612612

@@ -629,6 +629,11 @@ def _create_venv(ctx, output_prefix, imports, runtime_details):
629629
venv,
630630
),
631631
),
632+
# runtime, exe, and libs
633+
# Runfiles necessary for
634+
_runfiles = ctx.runfiles(
635+
symlinks = venv_app_files.runfiles_symlinks,
636+
),
632637
)
633638

634639
def _map_each_identity(v):

python/private/venv_runfiles.bzl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ load(
1414
"VenvSymlinkEntry",
1515
"VenvSymlinkKind",
1616
)
17+
load(":py_internal.bzl", "py_internal")
1718

1819
def create_venv_app_files(ctx, deps, venv_dir_map):
1920
"""Creates the tree of app-specific files for a venv for a binary.
@@ -44,16 +45,16 @@ def create_venv_app_files(ctx, deps, venv_dir_map):
4445

4546
link_map = build_link_map(ctx, entries)
4647
venv_files = []
48+
runfiles_symlinks = {}
49+
4750
for kind, kind_map in link_map.items():
4851
base = venv_dir_map[kind]
4952
for venv_path, link_to in kind_map.items():
5053
bin_venv_path = paths.join(base, venv_path)
5154
if is_file(link_to):
52-
if link_to.is_directory:
53-
venv_link = ctx.actions.declare_directory(bin_venv_path)
54-
else:
55-
venv_link = ctx.actions.declare_file(bin_venv_path)
56-
ctx.actions.symlink(output = venv_link, target_file = link_to)
55+
symlink_from = "{}/{}".format(ctx.label.package, bin_venv_path)
56+
runfiles_symlinks[symlink_from] = link_to
57+
5758
else:
5859
venv_link = ctx.actions.declare_symlink(bin_venv_path)
5960
venv_link_rf_path = runfiles_root_path(ctx, venv_link.short_path)
@@ -64,9 +65,12 @@ def create_venv_app_files(ctx, deps, venv_dir_map):
6465
to = link_to,
6566
)
6667
ctx.actions.symlink(output = venv_link, target_path = rel_path)
67-
venv_files.append(venv_link)
68+
venv_files.append(venv_link)
6869

69-
return venv_files
70+
return struct(
71+
venv_files = venv_files,
72+
runfiles_symlinks = runfiles_symlinks,
73+
)
7074

7175
# Visible for testing
7276
def build_link_map(ctx, entries):

0 commit comments

Comments
 (0)