1
0

bytebeat_compiler.py: remove generated files

This commit is contained in:
Intel A80486DX2-66 2024-08-26 21:40:33 +03:00
parent 12d3353208
commit df6863a3f5
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B

View File

@ -4,7 +4,8 @@ if __name__ == "__main__":
print(":: C bytebeat generator: compiler unit")
from argparse import ArgumentParser
from os import environ, makedirs, name as os_name
from os import environ, listdir, makedirs, name as os_name, \
remove as delete_file, rmdir
from os.path import exists, join as path_join
from shlex import join as command_line_join, split as command_line_split
from shutil import which
@ -94,6 +95,10 @@ def run_command(*command: list[str]) -> None:
if subprocess.run(command).returncode != EXIT_SUCCESS:
raise SystemExit(EXIT_FAILURE)
def delete_empty_dir(path: str) -> None:
if exists(path) and len(listdir(path)) == 0:
rmdir(path)
preprocessor_bool = lambda value: "1" if value else "0"
C_str_repr = lambda s: '"' + s.replace("\\", "\\\\").replace(r'"', r'\"') + '"'
@ -200,6 +205,9 @@ if __name__ == "__main__":
parser.add_argument("--color", default="auto", type=str,
help="ANSI escape codes. Set to 'always' to enable them, 'none' to "
"disable. Default: 'auto'.")
parser.add_argument("--keep-files", default=False, action="store_true",
help="keep generated files: substituted source code of runtime unit "
"and the executable it will be compiled to.")
args = parser.parse_args()
bytebeat_contents = read_from_file_or_stdin(args.file).strip()
@ -387,3 +395,8 @@ if __name__ == "__main__":
"-I" + PATHS["include_directory"]
)
run_command(OUTPUT_FILE)
if not args.keep_files:
delete_file(PATHS["substitute"])
delete_file(OUTPUT_FILE)
delete_empty_dir(PATHS["bin_dir"])