1313import os
1414import platform
1515import shutil
16+ import subprocess
1617from pathlib import Path
1718from string import Template
1819from typing import Union
@@ -140,6 +141,14 @@ def get_cli_archive_path(output_path: Path, is_onedir: bool) -> str:
140141 return os .path .join (output_path , get_cli_archive_filename (is_onedir ))
141142
142143
144+ def archive_directory (input_path : Path , output_path : str ) -> None :
145+ if get_os_name () == 'darwin' :
146+ # use ditto on macOS to preserve code signature metadata
147+ subprocess .run (['ditto' , '-c' , '-k' , str (input_path ), output_path ], check = True )
148+ else :
149+ shutil .make_archive (output_path .removesuffix (f'.{ _ARCHIVE_FORMAT } ' ), _ARCHIVE_FORMAT , input_path )
150+
151+
143152def process_executable_file (input_path : Path , is_onedir : bool ) -> str :
144153 output_path = input_path .parent
145154 hash_file_path = get_cli_hash_path (output_path , is_onedir )
@@ -150,7 +159,7 @@ def process_executable_file(input_path: Path, is_onedir: bool) -> str:
150159 write_hashes_db_to_file (normalized_hashes , hash_file_path )
151160
152161 archived_file_path = get_cli_archive_path (output_path , is_onedir )
153- shutil . make_archive ( archived_file_path , _ARCHIVE_FORMAT , input_path )
162+ archive_directory ( input_path , f' { archived_file_path } . { _ARCHIVE_FORMAT } ' )
154163 shutil .rmtree (input_path )
155164 else :
156165 file_hash = get_hash_of_file (input_path )
0 commit comments