@@ -819,15 +819,25 @@ def _create_zip_file(ctx, *, output, zip_main, runfiles):
819819 ),
820820 )
821821
822- def map_empty_filenames (path ):
823- return "{}=" .format (_get_zip_runfiles_path (path , workspace_name , legacy_external_runfiles ))
824-
825- manifest .add_all (runfiles .empty_filenames , map_each = map_empty_filenames , allow_closure = True )
822+ def map_zip_empty_filenames (list_paths_cb ):
823+ return [
824+ _get_zip_runfiles_path (path , workspace_name , legacy_external_runfiles ) + "="
825+ for path in list_paths_cb ().to_list ()
826+ ]
827+
828+ manifest .add_all (
829+ # NOTE: Accessing runfiles.empty_filenames implicitly flattens the runfiles.
830+ # Smuggle a lambda in via a list to defer that flattening.
831+ [lambda : runfiles .empty_filenames ],
832+ map_each = map_zip_empty_filenames ,
833+ allow_closure = True
834+ )
826835
827836 def map_zip_runfiles (file ):
828- return "{}={}" .format (
829- _get_zip_runfiles_path (file .short_path , workspace_name , legacy_external_runfiles ),
830- file .path ,
837+ return (
838+ # NOTE: Use "+" for performance
839+ _get_zip_runfiles_path (file .short_path , workspace_name , legacy_external_runfiles )
840+ + "=" + file .path
831841 )
832842
833843 manifest .add_all (runfiles .files , map_each = map_zip_runfiles , allow_closure = True )
@@ -864,15 +874,21 @@ def _create_zip_file(ctx, *, output, zip_main, runfiles):
864874 )
865875
866876def _get_zip_runfiles_path (path , workspace_name , legacy_external_runfiles ):
877+ maybe_workspace = ""
867878 if legacy_external_runfiles and path .startswith (_EXTERNAL_PATH_PREFIX ):
868879 zip_runfiles_path = path .removeprefix (_EXTERNAL_PATH_PREFIX )
869880 else :
870881 # NOTE: External runfiles (artifacts in other repos) will have a leading
871882 # path component of "../" so that they refer outside the main workspace
872883 # directory and into the runfiles root. So we simplify it, e.g.
873884 # "workspace/../foo/bar" to simply "foo/bar".
874- zip_runfiles_path = "{}/{}" .format (workspace_name , path ) if not path .startswith ("../" ) else path [3 :]
875- return "{}/{}" .format (_ZIP_RUNFILES_DIRECTORY_NAME , zip_runfiles_path )
885+ if path .startswith ("../" ):
886+ zip_runfiles_path = path [3 :]
887+ else :
888+ zip_runfiles_path = path
889+ maybe_workspace = workspace_name + "/"
890+ # NOTE: Use "+" for performance
891+ return _ZIP_RUNFILES_DIRECTORY_NAME + "/" + maybe_workspace + zip_runfiles_path
876892
877893def _create_executable_zip_file (
878894 ctx ,
0 commit comments