bytebeat_compiler.py: remove generated files
This commit is contained in:
parent
12d3353208
commit
df6863a3f5
@ -4,7 +4,8 @@ if __name__ == "__main__":
|
|||||||
print(":: C bytebeat generator: compiler unit")
|
print(":: C bytebeat generator: compiler unit")
|
||||||
|
|
||||||
from argparse import ArgumentParser
|
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 os.path import exists, join as path_join
|
||||||
from shlex import join as command_line_join, split as command_line_split
|
from shlex import join as command_line_join, split as command_line_split
|
||||||
from shutil import which
|
from shutil import which
|
||||||
@ -94,6 +95,10 @@ def run_command(*command: list[str]) -> None:
|
|||||||
if subprocess.run(command).returncode != EXIT_SUCCESS:
|
if subprocess.run(command).returncode != EXIT_SUCCESS:
|
||||||
raise SystemExit(EXIT_FAILURE)
|
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"
|
preprocessor_bool = lambda value: "1" if value else "0"
|
||||||
C_str_repr = lambda s: '"' + s.replace("\\", "\\\\").replace(r'"', r'\"') + '"'
|
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,
|
parser.add_argument("--color", default="auto", type=str,
|
||||||
help="ANSI escape codes. Set to 'always' to enable them, 'none' to "
|
help="ANSI escape codes. Set to 'always' to enable them, 'none' to "
|
||||||
"disable. Default: 'auto'.")
|
"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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
bytebeat_contents = read_from_file_or_stdin(args.file).strip()
|
bytebeat_contents = read_from_file_or_stdin(args.file).strip()
|
||||||
@ -387,3 +395,8 @@ if __name__ == "__main__":
|
|||||||
"-I" + PATHS["include_directory"]
|
"-I" + PATHS["include_directory"]
|
||||||
)
|
)
|
||||||
run_command(OUTPUT_FILE)
|
run_command(OUTPUT_FILE)
|
||||||
|
|
||||||
|
if not args.keep_files:
|
||||||
|
delete_file(PATHS["substitute"])
|
||||||
|
delete_file(OUTPUT_FILE)
|
||||||
|
delete_empty_dir(PATHS["bin_dir"])
|
||||||
|
Loading…
Reference in New Issue
Block a user