From d6d3a9201302c5c728d2bdd1c50678e18645e7eb Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 8 Feb 2023 18:16:48 +0100 Subject: [PATCH] build: replace check-single-includes with clang-tidy (#22061) Clang-tidy already does what check-single-includes does automatically on top of its regular linting. It is also generator independent, so it doesn't take an eternity to run on slower generators such as Visual Studio. --- .github/workflows/ci.yml | 3 +-- CMakeLists.txt | 4 ++-- Makefile | 2 +- src/nvim/CMakeLists.txt | 37 ++++++++++++++----------------------- 4 files changed, 18 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aa2708332c..d3974e8c85 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -171,8 +171,7 @@ jobs: run: cmake --build build --target lintc-clint - if: success() || failure() && steps.abort_job.outputs.status == 'success' - name: check-single-includes - run: make check-single-includes + run: cmake --build build --target clang-tidy - name: Cache dependencies run: ./ci/before_cache.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 6cfcc61213..36210bb007 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -244,9 +244,9 @@ endif() # Lint # find_program(LUACHECK_PRG luacheck) +find_program(SHELLCHECK_PRG shellcheck) find_program(STYLUA_PRG stylua) find_program(UNCRUSTIFY_PRG uncrustify) -find_program(SHELLCHECK_PRG shellcheck) add_glob_target( REQUIRED @@ -287,7 +287,7 @@ add_custom_target(lintcommit add_dependencies(lintcommit nvim) add_custom_target(lint) -add_dependencies(lint check-single-includes lintc lintlua lintsh lintcommit) +add_dependencies(lint clang-tidy lintc lintlua lintsh lintcommit) # # Format diff --git a/Makefile b/Makefile index be1eef92de..2f7624d707 100644 --- a/Makefile +++ b/Makefile @@ -130,7 +130,7 @@ functionaltest-lua: | nvim $(BUILD_TOOL) -C build $@ FORMAT=formatc formatlua format -LINT=lintlua lintsh lintc check-single-includes lintcommit lint +LINT=lintlua lintsh lintc clang-tidy lintcommit lint TEST=functionaltest unittest generated-sources benchmark uninstall $(FORMAT) $(LINT) $(TEST): | build/.ran-cmake $(CMAKE_PRG) --build build --target $@ diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index 90b17492bf..5fda718dbb 100755 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -878,44 +878,35 @@ function(get_test_target prefix sfile relative_path_var target_var) endif() endfunction() +find_program(CLANG_TIDY_PRG clang-tidy) +set(EXCLUDE_CLANG_TIDY typval_encode.c.h ui_events.in.h) if(WIN32) - set(NO_SINGLE_CHECK_HEADERS + list(APPEND EXCLUDE_CLANG_TIDY os/pty_process_unix.h os/unix_defs.h) else() - set(NO_SINGLE_CHECK_HEADERS + list(APPEND EXCLUDE_CLANG_TIDY os/win_defs.h os/pty_process_win.h os/pty_conpty_win.h os/os_win_console.h) endif() -foreach(hfile ${NVIM_HEADERS}) - get_test_target(test-includes "${hfile}" relative_path texe) - - if(NOT ${hfile} MATCHES "[.](c|in)[.]h$") - set(tsource "${GENERATED_DIR}/${relative_path}.test-include.c") - write_file("${tsource}" "#include \"${hfile}\"\nint main(int argc, char **argv) { return 0; }") - add_executable( - ${texe} - EXCLUDE_FROM_ALL - ${tsource} ${NVIM_HEADERS} ${NVIM_GENERATED_FOR_HEADERS}) - target_link_libraries(${texe} PRIVATE main_lib) - set_target_properties(${texe} PROPERTIES FOLDER test) - - list(FIND NO_SINGLE_CHECK_HEADERS "${relative_path}" hfile_exclude_idx) - if(${hfile_exclude_idx} EQUAL -1) - list(APPEND HEADER_CHECK_TARGETS ${texe}) - endif() - endif() -endforeach() -add_custom_target(check-single-includes DEPENDS ${HEADER_CHECK_TARGETS}) +add_glob_target( + TARGET clang-tidy + COMMAND ${CLANG_TIDY_PRG} + FILES ${NVIM_SOURCES} ${NVIM_HEADERS} + FLAGS --quiet + EXCLUDE ${EXCLUDE_CLANG_TIDY}) +add_custom_target(copy_compile_commands + COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/compile_commands.json ${PROJECT_SOURCE_DIR}/compile_commands.json) +add_dependencies(copy_compile_commands nvim) +add_dependencies(clang-tidy copy_compile_commands) if(CI_BUILD) set(LINT_OUTPUT_FORMAT gh_action) else() set(LINT_OUTPUT_FORMAT vs7) endif() - add_glob_target( TARGET lintc-clint COMMAND ${PROJECT_SOURCE_DIR}/src/clint.py