Meta: Make check-style.py complain if a non-AK complex header is used

LibC's complex.h should not be used in C++ code, and libc++'s version
implementation does not follow the Serenity C++ style.
This commit is contained in:
implicitfield 2023-06-07 16:35:35 +04:00 committed by Andreas Kling
parent cccb6c7287
commit ec636a404b
Notes: sideshowbarker 2024-07-18 00:34:07 +09:00

View file

@ -47,6 +47,9 @@ GOOD_PRAGMA_ONCE_PATTERN = re.compile('(^|\\S\n\n)#pragma once(\n\n\\S.|$)')
# LibC is supposed to be a system library; don't mention the directory.
BAD_INCLUDE_LIBC = re.compile("# *include <LibC/")
# Serenity C++ code must not use LibC's or libc++'s complex number implementation.
BAD_INCLUDE_COMPLEX = re.compile("# *include <c[c]?omplex")
# Make sure that all includes are either system includes or immediately resolvable local includes
ANY_INCLUDE_PATTERN = re.compile('^ *# *include\\b.*[>"](?!\\)).*$', re.M)
SYSTEM_INCLUDE_PATTERN = re.compile("^ *# *include *<([^>]+)>(?: /[*/].*)?$")
@ -98,6 +101,7 @@ def run():
errors_include_libc = []
errors_include_weird_format = []
errors_include_missing_local = []
errors_include_bad_complex = []
for filename in find_files_here_or_argv():
with open(filename, "r") as f:
@ -121,6 +125,8 @@ def run():
if not is_in_prefix_list(filename, LIBC_CHECK_EXCLUDES):
if BAD_INCLUDE_LIBC.search(file_content):
errors_include_libc.append(filename)
if BAD_INCLUDE_COMPLEX.search(file_content):
errors_include_bad_complex.append(filename)
if not is_in_prefix_list(filename, INCLUDE_CHECK_EXCLUDES):
file_directory = pathlib.Path(filename).parent
for include_line in ANY_INCLUDE_PATTERN.findall(file_content):
@ -173,6 +179,12 @@ def run():
" ".join(errors_include_missing_local),
)
have_errors = True
if errors_include_bad_complex:
print(
"Files that include a non-AK complex header:",
" ".join(errors_include_bad_complex),
)
have_errors = True
if have_errors:
sys.exit(1)