diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake --- a/libc/cmake/modules/LLVMLibCTestRules.cmake +++ b/libc/cmake/modules/LLVMLibCTestRules.cmake @@ -166,6 +166,45 @@ ${fq_target_name} ) endif() + + if(LLVM_LIBC_ENABLE_LINTING) + set(lint_timestamp "${CMAKE_CURRENT_BINARY_DIR}/.${target_name}.__lint_timestamp__") + add_custom_command( + OUTPUT ${lint_timestamp} + # --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 + "--export-fixes=${CMAKE_CURRENT_BINARY_DIR}/${target_name}.yaml" + # Path to directory containing compile_commands.json + -p ${PROJECT_BINARY_DIR} + ${LIBC_UNITTEST_SRCS} + # See above: this might be a second invocation of clang-tidy depending on + # the conditions above. + ${restrict_system_headers_check_invocation} + # We have two options for running commands, add_custom_command and + # add_custom_target. We don't want to run the linter unless source files + # have changed. add_custom_target explicitly runs everytime therefore we + # use add_custom_command. This function requires an output file and since + # linting doesn't produce a file, we create a dummy file using a + # crossplatform touch. + COMMAND "${CMAKE_COMMAND}" -E touch ${lint_timestamp} + COMMENT "Linting... ${target_name}" + DEPENDS clang-tidy ${internal_target_name} ${LIBC_UNITTEST_SRCS} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + + add_custom_target(${fq_target_name}.__lint__ + DEPENDS ${lint_timestamp}) + add_dependencies(lint-libc ${fq_target_name}.__lint__) + add_dependencies(${fq_target_name} ${fq_target_name}.__lint__) + endif() + endfunction(add_libc_unittest) function(add_libc_testsuite suite_name) diff --git a/libc/test/src/string/memory_utils/.clang-tidy b/libc/test/src/string/memory_utils/.clang-tidy new file mode 100644 --- /dev/null +++ b/libc/test/src/string/memory_utils/.clang-tidy @@ -0,0 +1,8 @@ +# temporary, this folder was crashing clang-tidy. I'm working on reporting the bug. +InheritParentConfig: false +Checks: '-*,llvmlibc-*' +HeaderFilterRegex: '.*' +WarningsAsErrors: 'llvmlibc-*' +CheckOptions: + - key: llvmlibc-restrict-system-libc-headers.Includes + value: '-*, linux/*, asm/*.h, asm-generic/*.h' diff --git a/libc/utils/MPFRWrapper/.clang-tidy b/libc/utils/MPFRWrapper/.clang-tidy new file mode 100644 --- /dev/null +++ b/libc/utils/MPFRWrapper/.clang-tidy @@ -0,0 +1,7 @@ +InheritParentConfig: false +Checks: '-*,llvmlibc-*' +HeaderFilterRegex: '.*' +WarningsAsErrors: 'llvmlibc-*' +CheckOptions: + - key: llvmlibc-restrict-system-libc-headers.Includes + value: '-*, linux/*, asm/*.h, asm-generic/*.h' diff --git a/libc/utils/UnitTest/.clang-tidy b/libc/utils/UnitTest/.clang-tidy new file mode 100644 --- /dev/null +++ b/libc/utils/UnitTest/.clang-tidy @@ -0,0 +1,7 @@ +InheritParentConfig: false +Checks: '-*,llvmlibc-*' +HeaderFilterRegex: '.*' +WarningsAsErrors: 'llvmlibc-*' +CheckOptions: + - key: llvmlibc-restrict-system-libc-headers.Includes + value: '-*, linux/*, asm/*.h, asm-generic/*.h'