Skip to content

Commit

Permalink
[libc++] [test] Check the presence of "pragma include_instead" in new…
Browse files Browse the repository at this point in the history
…ly added headers.

Unless/until we revert D106124, we should make sure that every newly added
detail header includes this line.
  • Loading branch information
Arthur O'Dwyer committed Feb 27, 2022
1 parent b486a9d commit b6d7568
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions libcxx/test/libcxx/lint/lint_headers.sh.py
Expand Up @@ -15,11 +15,38 @@ def exclude_from_consideration(path):
os.path.basename(path) == '__config' or
os.path.basename(path) == '__config_site.in' or
os.path.basename(path) == '__libcpp_version' or
os.path.basename(path) == '__locale' or
not os.path.isfile(path)
)


def check_for_pragma_GCC_system_header(pretty_fname, lines):
if pretty_fname not in ['__undef_macros']:
if '# pragma GCC system_header\n' not in lines:
print('FAILED TO FIND # pragma GCC system_header in libcxx/include/%s!' % pretty_fname)
return False
return True

def check_for_pragma_clang_include_instead(pretty_fname, lines):
expect_include_instead = pretty_fname.startswith('__') and pretty_fname not in [
'__assert',
'__bsd_locale_fallbacks.h',
'__bsd_locale_defaults.h',
'__availability',
'__debug',
'__errc',
'__mbstate_t.h',
'__undef_macros',
]
found_include_instead = any(line.startswith('# pragma clang include_instead') for line in lines)
if expect_include_instead and not found_include_instead:
print('FAILED TO FIND # pragma clang include_instead in libcxx/include/%s!' % pretty_fname)
return False
elif found_include_instead and not expect_include_instead:
print('UNEXPECTEDLY FOUND # pragma clang include_instead in libcxx/include/%s!' % pretty_fname)
return False
return True


if __name__ == '__main__':
libcxx_test_libcxx_lint = os.path.dirname(os.path.abspath(__file__))
libcxx_include = os.path.abspath(os.path.join(libcxx_test_libcxx_lint, '../../../include'))
Expand All @@ -37,11 +64,11 @@ def pretty(path):

okay = True
for fname in all_headers:
pretty_fname = pretty(fname)
with open(fname, 'r') as f:
lines = f.readlines()

if '# pragma GCC system_header\n' not in lines:
if pretty(fname) not in ['__undef_macros']:
okay = False
print('FAILED TO FIND # pragma GCC system_header in libcxx/include/%s!' % pretty(fname))
okay = check_for_pragma_GCC_system_header(pretty_fname, lines) and okay
okay = check_for_pragma_clang_include_instead(pretty_fname, lines) and okay

assert okay

0 comments on commit b6d7568

Please sign in to comment.