From d7dfbce2882c935fa16d09b261a7db4762b3278d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 14 Feb 2024 13:40:33 +1100 Subject: [PATCH] code_clean: exclude BLI_strict_flags.h from removal As this is only added to set strict warnings, cleaning logic would remove as the compilers output is unchanged. Support excluding headers from removal, others can be added if needed. --- tools/utils_maintenance/code_clean.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tools/utils_maintenance/code_clean.py b/tools/utils_maintenance/code_clean.py index bbbd095103e..7d926c2b92f 100755 --- a/tools/utils_maintenance/code_clean.py +++ b/tools/utils_maintenance/code_clean.py @@ -1465,6 +1465,14 @@ class edit_generators: # Before committing these changes all supported platforms should be tested to compile without problems. is_default = False + @staticmethod + def _header_exclude(f_basename: str) -> str: + # This header only exists to add additional warnings, removing it doesn't impact generated output. + # Skip this file. + if f_basename == "BLI_strict_flags.h": + return True + return False + @staticmethod def _header_guard_from_filename(f: str) -> str: return '__%s__' % os.path.basename(f).replace('.', '_').upper() @@ -1481,6 +1489,10 @@ class edit_generators: os.path.join(SOURCE_DIR, 'source'), ('.h', '.hh', '.inl', '.hpp', '.hxx'), ): + f_basename = os.path.basename(f) + if cls._header_exclude(f_basename): + continue + with open(f, 'r', encoding='utf-8') as fh: data = fh.read() @@ -1521,7 +1533,12 @@ class edit_generators: # Remove include. for match in re.finditer(r"^(([ \t]*#\s*include\s+\")([^\"]+)(\"[^\n]*\n))", data, flags=re.MULTILINE): header_name = match.group(3) - header_guard = cls._header_guard_from_filename(header_name) + # Use in case the include has a leading path. + header_basename = os.path.basename(header_name) + if cls._header_exclude(header_basename): + continue + + header_guard = cls._header_guard_from_filename(header_basename) edits.append(Edit( span=match.span(), content='', # Remove the header.