@@ -101,18 +101,27 @@ def read_manifest(
101101 return entries
102102
103103
104- def path_norm (path , pathsep ):
105- if pathsep == "/" :
106- return path .replace ("\\ " , pathsep )
104+ def convert_symlink_target (path , platform_pathsep ):
105+ """Converts the path a symlink points to the target-platform format.
106+
107+ On Windows, relative symlinks must use backslashes.
108+ """
109+ if platform_pathsep == "/" :
110+ # Convert Windows to Unix
111+ return path .replace ("\\ " , platform_pathsep )
107112 else :
113+ # Convert Unix to Windows
108114 return path .replace ("/" , "\\ " )
109115
116+ # Zip files use forward slash for the entries, even on Windows
117+ def normalize_zip_path (path ):
118+ return path .replace ("\\ " , "/" )
110119
111- def _write_entry (zf , entry , compress_type , seen , pathsep ):
120+ def _write_entry (zf , entry , compress_type , seen , platform_pathsep ):
112121 type_ , is_symlink_str , zip_path , content_path = entry
113122 # Normalize slashes, otherwise the `seen` logic doesn't
114123 # work correctly.
115- zip_path = path_norm (zip_path , pathsep )
124+ zip_path = normalize_zip_path (zip_path )
116125 if zip_path in seen :
117126 # This can occur because symlink entries have precedence
118127 # over non-symlink entries.
@@ -133,8 +142,7 @@ def _write_entry(zf, entry, compress_type, seen, pathsep):
133142 zi .date_time = (1980 , 1 , 1 , 0 , 0 , 0 )
134143 zi .create_system = 3 # Unix
135144 zi .compress_type = compress_type
136- # Windows doesn't like symlinks with forward slashes
137- target = path_norm (content_path , pathsep )
145+ target = convert_symlink_target (content_path , platform_pathsep )
138146 # Set permissions to 777 for symlink (standard)
139147 zi .external_attr = (S_IFLNK | 0o777 ) << 16
140148 zf .writestr (zi , target )
@@ -153,14 +161,14 @@ def _write_entry(zf, entry, compress_type, seen, pathsep):
153161 zi .date_time = (1980 , 1 , 1 , 0 , 0 , 0 )
154162 zi .create_system = 3 # Unix
155163 zi .compress_type = compress_type
156- # Windows doesn't like symlinks with forward slashes
157- target = path_norm (os .readlink (content_path ), pathsep )
164+ target = convert_symlink_target (os .readlink (content_path ), platform_pathsep )
158165 # Set permissions to 777 for symlink (standard)
159166 zi .external_attr = (S_IFLNK | 0o777 ) << 16
160167 zf .writestr (zi , target )
161168 else :
162169 st = os .stat (content_path )
163170 zi = zipfile .ZipInfo (zip_path )
171+ print ("store:" , zip_path )
164172 zi .date_time = (1980 , 1 , 1 , 0 , 0 , 0 )
165173 zi .create_system = 3 # Unix
166174 zi .compress_type = compress_type
@@ -255,8 +263,8 @@ def main():
255263 "--runfiles-dir" , default = "runfiles" , help = "Name of the runfiles directory"
256264 )
257265 parser .add_argument (
258- "--pathsep" ,
259- default = "/" ,
266+ "--target-platform- pathsep" ,
267+ help = "The path separator for the target platform"
260268 )
261269 args = parser .parse_args ()
262270
@@ -268,7 +276,7 @@ def main():
268276 workspace_name = args .workspace_name ,
269277 legacy_external_runfiles = args .legacy_external_runfiles == "1" ,
270278 runfiles_dir = args .runfiles_dir ,
271- pathsep = args .pathsep ,
279+ platform_pathsep = args .target_platform_pathsep ,
272280 )
273281 except Exception as e :
274282 e .add_note (f"Error creating zip { args .output } " )
0 commit comments