[libc-commits] [PATCH] D77861: [libc] Add cmake target for linting libc.

Paula Toth via Phabricator via libc-commits libc-commits at lists.llvm.org
Fri Apr 10 01:03:28 PDT 2020


PaulkaToast created this revision.
Herald added subscribers: libc-commits, tschuett, mgorny.
Herald added a project: libc-project.
PaulkaToast edited the summary of this revision.

Draft


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77861

Files:
  libc/CMakeLists.txt
  libc/cmake/modules/LLVMLibCRules.cmake


Index: libc/cmake/modules/LLVMLibCRules.cmake
===================================================================
--- libc/cmake/modules/LLVMLibCRules.cmake
+++ 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 $<TARGET_FILE:clang-tidy> "--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
Index: libc/CMakeLists.txt
===================================================================
--- libc/CMakeLists.txt
+++ 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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77861.256520.patch
Type: text/x-patch
Size: 2300 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20200410/3c06e810/attachment-0001.bin>


More information about the libc-commits mailing list