From f23e8d5e1128c900b5a4eda2038491800fdc6dff Mon Sep 17 00:00:00 2001 From: Aetias Date: Sun, 18 Feb 2024 11:34:42 +0100 Subject: [PATCH] Exclude duplicate macros in `m2ctx` --- tools/m2ctx.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/m2ctx.py b/tools/m2ctx.py index 17811919..4cf897ec 100755 --- a/tools/m2ctx.py +++ b/tools/m2ctx.py @@ -66,7 +66,7 @@ while i < len(sys.argv): try: - ctx = subprocess.check_output(['gcc', '-E', '-P', '-undef', '-dD', *CXX_FLAGS, in_file], cwd=root_dir, encoding=encoding) + ctx: str = subprocess.check_output(['gcc', '-E', '-P', '-undef', '-dD', *CXX_FLAGS, in_file], cwd=root_dir, encoding=encoding) except subprocess.CalledProcessError as e: eprint(f"Failed to preprocess '{in_file}'") if verbose: eprint(e) @@ -74,6 +74,13 @@ except subprocess.CalledProcessError as e: exit(1) +lines = ctx.splitlines(True) +for i in reversed(range(len(lines))): + if lines[i].startswith('#define __cplusplus'): lines.pop(i) + elif lines[i].startswith('#define __STDC_HOSTED__'): lines.pop(i) + +ctx = ''.join(lines) + if out_file: try: with open(out_file, "w") as file: