build: add check to clint to prevent non-defs header includes

Also enable iwyu on headers, but add an ignore for each file separately.

Work on https://github.com/neovim/neovim/issues/6371.
This commit is contained in:
dundargoc
2023-11-26 13:24:38 +01:00
committed by dundargoc
parent 17d81ac2ab
commit ce6075f82a
2 changed files with 392 additions and 1 deletions

View File

@@ -151,6 +151,7 @@ Syntax: clint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
_ERROR_CATEGORIES = [
'build/endif_comment',
'build/header_guard',
'build/include_defs',
'build/printf_format',
'build/storage_class',
'readability/bool',
@@ -879,6 +880,196 @@ def CheckForHeaderGuard(filename, lines, error):
error(filename, 0, 'build/header_guard', 5,
'No "#pragma once" found in header')
def CheckIncludes(filename, lines, error):
"""Checks that headers only include _defs headers
Args:
filename: The name of the C++ header file.
lines: An array of strings, each representing a line of the file.
error: The function to call with any errors found.
"""
if filename.endswith('.c.h') or filename.endswith('.in.h') or FileInfo(filename).RelativePath() in {
'func_attr.h',
}:
return
check_includes_ignore = [
"api/command.h",
"api/deprecated.h",
"api/extmark.h",
"api/keysets.h",
"api/options.h",
"api/private/converter.h",
"api/private/defs.h",
"api/private/dispatch.h",
"api/private/helpers.h",
"api/private/validate.h",
"api/tabpage.h",
"api/ui.h",
"api/vim.h",
"api/vimscript.h",
"api/win_config.h",
"arglist.h",
"arglist_defs.h",
"ascii.h",
"assert.h",
"autocmd.h",
"buffer.h",
"buffer_defs.h",
"buffer_updates.h",
"change.h",
"channel.h",
"charset.h",
"cmdexpand.h",
"cmdexpand_defs.h",
"cmdhist.h",
"context.h",
"cursor.h",
"cursor_shape.h",
"decoration.h",
"decoration_defs.h",
"decoration_provider.h",
"diff.h",
"digraph.h",
"drawline.h",
"drawscreen.h",
"edit.h",
"eval.h",
"eval/decode.h",
"eval/encode.h",
"eval/funcs.h",
"eval/typval.h",
"eval/typval_defs.h",
"eval/typval_encode.h",
"eval/userfunc.h",
"event/libuv_process.h",
"event/loop.h",
"event/multiqueue.h",
"event/process.h",
"event/rstream.h",
"event/signal.h",
"event/socket.h",
"event/stream.h",
"event/time.h",
"event/wstream.h",
"ex_cmds.h",
"ex_cmds_defs.h",
"ex_docmd.h",
"ex_eval_defs.h",
"ex_getln.h",
"extmark_defs.h",
"file_search.h",
"fileio.h",
"fold.h",
"fold_defs.h",
"garray.h",
"getchar.h",
"getchar_defs.h",
"globals.h",
"grid.h",
"grid_defs.h",
"hashtab.h",
"highlight.h",
"highlight_defs.h",
"highlight_group.h",
"iconv.h",
"indent.h",
"indent_c.h",
"input.h",
"insexpand.h",
"keycodes.h",
"linematch.h",
"log.h",
"lua/converter.h",
"lua/executor.h",
"lua/treesitter.h",
"macros.h",
"main.h",
"map.h",
"mapping.h",
"mapping_defs.h",
"mark.h",
"mark_defs.h",
"marktree.h",
"mbyte.h",
"mbyte_defs.h",
"memfile_defs.h",
"memline.h",
"memory.h",
"menu.h",
"message.h",
"mouse.h",
"move.h",
"msgpack_rpc/channel_defs.h",
"msgpack_rpc/helpers.h",
"msgpack_rpc/unpacker.h",
"normal.h",
"nvim/extmark.h",
"ops.h",
"option.h",
"option_defs.h",
"option_vars.h",
"os/fileio.h",
"os/fs.h",
"os/input.h",
"os/lang.h",
"os/os.h",
"os/process.h",
"os/pty_conpty_win.h",
"os/pty_process_unix.h",
"os/pty_process_win.h",
"os/shell.h",
"path.h",
"plines.h",
"popupmenu.h",
"profile.h",
"quickfix.h",
"regexp.h",
"regexp_defs.h",
"runtime.h",
"search.h",
"sha256.h",
"sign_defs.h",
"spell.h",
"spell_defs.h",
"spellfile.h",
"spellsuggest.h",
"statusline.h",
"statusline_defs.h",
"strings.h",
"syntax.h",
"tag.h",
"textformat.h",
"textobject.h",
"tui/input.h",
"tui/terminfo.h",
"tui/tui.h",
"ugrid.h",
"ui.h",
"ui_client.h",
"ui_compositor.h",
"undo_defs.h",
"usercmd.h",
"version.h",
"vim.h",
"viml/parser/expressions.h",
"viml/parser/parser.h",
"window.h",
"winfloat.h",
]
for i in check_includes_ignore:
if filename.endswith(i):
return
for i, line in enumerate(lines):
if("#include" in line):
if("#include <" in line):
continue
if "_defs" not in line:
error(filename, i, 'build/include_defs', 5,
'Headers should not include non-"_defs" headers')
def CheckForBadCharacters(filename, lines, error):
"""Logs an error for each line containing bad characters.
@@ -2166,6 +2357,7 @@ def ProcessFileData(filename, file_extension, lines, error,
if file_extension == 'h':
CheckForHeaderGuard(filename, lines, error)
CheckIncludes(filename, lines, error)
RemoveMultiLineComments(filename, lines, error)
clean_lines = CleansedLines(lines, init_lines)