diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -19,6 +19,19 @@ set(LIBC_TARGET_MACHINE ${CMAKE_SYSTEM_PROCESSOR}) +if("clang-tools-extra" IN_LIST LLVM_ENABLE_PROJECTS + AND "clang" IN_LIST LLVM_ENABLE_PROJECTS) + add_custom_target(lint-libc) + set(LIBC_LINT_ENABLED TRUE) +else() + add_custom_target( + lint-libc + COMMAND exit 1 + COMMENT "Add 'clang' and 'clang-tools-extra' to LLVM_ENABLE_PROJECTS to use lint-libc." + ) + set(LIBC_LINT_ENABLED FALSE) +endif() + include(CMakeParseArguments) include(LLVMLibCRules) include(LLVMLibCCheckCpuFeatures) diff --git a/libc/cmake/modules/LLVMLibCRules.cmake b/libc/cmake/modules/LLVMLibCRules.cmake --- a/libc/cmake/modules/LLVMLibCRules.cmake +++ b/libc/cmake/modules/LLVMLibCRules.cmake @@ -298,6 +298,30 @@ "OBJECT_FILES" "${all_objects}" "OBJECT_FILES_RAW" "${all_objects_raw}" ) + + if(LIBC_LINT_ENABLED) + add_custom_target( + ${target_name}-lint + # --quiet is used to surpress warning statistics from clang-tidy like: + # Suppressed X warnings (X in non-user code). + # There seems to be a bug in clang-tidy where by even with --quiet some + # messages from clang's own diagnostics engine leak through: + # X warnings generated. + # Until this is fixed upstream, we use -fno-caret-diagnostics to surpress + # these. + COMMAND $ "--extra-arg=-fno-caret-diagnostics" --quiet + # Path to directory containing compile_commands.json + -p ${PROJECT_BINARY_DIR} + ${ADD_ENTRYPOINT_OBJ_SRCS} + COMMENT "Linting... ${target_name}" + DEPENDS ${clang-tidy} ${target_name} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + # Allows clang-tidy to show colored output messages until D41720 is landed. + USES_TERMINAL + ) + add_dependencies(lint-libc ${target_name}-lint) + endif() + endfunction(add_entrypoint_object) # A rule to build a library from a collection of entrypoint objects. @@ -416,7 +440,7 @@ if(NOT LLVM_INCLUDE_TESTS) return() endif() - + cmake_parse_arguments( "LIBC_UNITTEST" "" # No optional arguments