From d0dba4cb501a2a5ee897761121855e8ac4717ba2 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Fri, 31 Mar 2023 10:54:14 +0200 Subject: [PATCH] Include `symlinks` and `root_symlinks` in Python ZIPs --- .../common/python/py_executable_bazel.bzl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/starlark/builtins_bzl/common/python/py_executable_bazel.bzl b/src/main/starlark/builtins_bzl/common/python/py_executable_bazel.bzl index 6969cbdb227d68..4caaba5b0e270c 100644 --- a/src/main/starlark/builtins_bzl/common/python/py_executable_bazel.bzl +++ b/src/main/starlark/builtins_bzl/common/python/py_executable_bazel.bzl @@ -342,6 +342,12 @@ def _create_windows_exe_launcher( use_default_shell_env = True, ) +def _map_zip_runfiles_symlink(prefix, symlink): + return "{}/{}={}".format(prefix, symlink.path, symlink.target_file.path) + +def _map_zip_runfiles_root_symlink(symlink): + return _map_zip_runfiles_symlink(_ZIP_RUNFILES_DIRECTORY_NAME, symlink) + def _create_zip_file(ctx, *, output, original_nonzip_executable, executable_for_zip_file, runfiles): workspace_name = ctx.workspace_name legacy_external_runfiles = _py_builtins.get_legacy_external_runfiles(ctx) @@ -370,6 +376,16 @@ def _create_zip_file(ctx, *, output, original_nonzip_executable, executable_for_ return None manifest.add_all(runfiles.files, map_each = map_zip_runfiles, allow_closure = True) + manifest.add_all( + runfiles.symlinks, + map_each = lambda symlink: _map_zip_runfiles_symlink( + _ZIP_RUNFILES_DIRECTORY_NAME + "/" + workspace_name, + symlink, + ), + allow_closure = True, + ) + manifest.add_all(runfiles.root_symlinks, map_each = _map_zip_runfiles_root_symlink) + inputs = [executable_for_zip_file] for artifact in runfiles.files.to_list(): # Don't include the original executable because it isn't used by the