[libc-commits] [PATCH] D116126: [libc] add test formatting rules

Michael Jones via Phabricator via libc-commits libc-commits at lists.llvm.org
Tue Dec 21 13:11:48 PST 2021


michaelrj created this revision.
michaelrj added reviewers: sivachandra, lntue.
Herald added subscribers: libc-commits, ecnelises, tschuett, mgorny.
Herald added a project: libc-project.
michaelrj requested review of this revision.
Herald added a subscriber: aheejin.

Add an invocation of clang tidy that applies to the tests for LLVM-libc.
The next patch will include the actual changes made by applying the new
formatting rules.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116126

Files:
  libc/cmake/modules/LLVMLibCTestRules.cmake
  libc/test/src/string/memory_utils/.clang-tidy
  libc/utils/MPFRWrapper/.clang-tidy
  libc/utils/UnitTest/.clang-tidy


Index: libc/utils/UnitTest/.clang-tidy
===================================================================
--- /dev/null
+++ 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'
Index: libc/utils/MPFRWrapper/.clang-tidy
===================================================================
--- /dev/null
+++ 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'
Index: libc/test/src/string/memory_utils/.clang-tidy
===================================================================
--- /dev/null
+++ 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'
Index: libc/cmake/modules/LLVMLibCTestRules.cmake
===================================================================
--- libc/cmake/modules/LLVMLibCTestRules.cmake
+++ 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 $<TARGET_FILE:clang-tidy>
+              "--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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116126.395743.patch
Type: text/x-patch
Size: 3721 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20211221/32239441/attachment.bin>


More information about the libc-commits mailing list