Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaula Toth <paulatoth@google.com>2020-05-22 03:39:03 +0300
committerPaula Toth <paulatoth@google.com>2020-05-22 04:40:59 +0300
commit2a4c30985ded329d64357f5535d2ff2a3f955c81 (patch)
tree1afcbfe473f0503a25024f09b7af44c0f73d1ff9 /libc/cmake/modules/LLVMLibCObjectRules.cmake
parent54c2c2add7ad42ce1910a276cd1cd2912af4cddd (diff)
[libc] Make clang-tidy use host compiler's resource dir.
Summary: When building llvm-libc with linting enabled, clang-tidy would use the resource dir of the monorepo rather then the host compiler's resource dir. This presented issues when including headers from the host compiler e.g. for sanitizers. Therefore this patch explicitly tells clang-tidy to use the host compiler's resource dir. Reviewers: sivachandra Reviewed By: sivachandra Subscribers: mgorny, tschuett, ecnelises, libc-commits Tags: #libc-project Differential Revision: https://reviews.llvm.org/D80265
Diffstat (limited to 'libc/cmake/modules/LLVMLibCObjectRules.cmake')
-rw-r--r--libc/cmake/modules/LLVMLibCObjectRules.cmake34
1 files changed, 26 insertions, 8 deletions
diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake
index 2b7b53778de1..898831ca6818 100644
--- a/libc/cmake/modules/LLVMLibCObjectRules.cmake
+++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake
@@ -206,8 +206,30 @@ function(add_entrypoint_object target_name)
)
if(LLVM_LIBC_ENABLE_LINTING)
- set(lint_timestamp "${CMAKE_CURRENT_BINARY_DIR}/.${target_name}.__lint_timestamp__")
+ # We only want a second invocation of clang-tidy to run
+ # restrict-system-libc-headers if the compiler-resource-dir was set in
+ # order to prevent false-positives due to a mismatch between the host
+ # compiler and the compiled clang-tidy.
+ if(COMPILER_RESOURCE_DIR)
+ # We run restrict-system-libc-headers with --system-headers to prevent
+ # transitive inclusion through compler provided headers.
+ set(restrict_system_headers_check_invocation
+ COMMAND $<TARGET_FILE:clang-tidy> --system-headers
+ --checks="-*,llvmlibc-restrict-system-libc-headers"
+ # We explicitly set the resource dir here to match the
+ # resource dir of the host compiler.
+ "--extra-arg=-resource-dir=${COMPILER_RESOURCE_DIR}"
+ --quiet
+ -p ${PROJECT_BINARY_DIR}
+ ${ADD_ENTRYPOINT_OBJ_SRCS}
+ )
+ else()
+ set(restrict_system_headers_check_invocation
+ COMMAND ${CMAKE_COMMAND} -E echo "Header file check skipped")
+ endif()
+
+ 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:
@@ -222,13 +244,9 @@ function(add_entrypoint_object target_name)
# Path to directory containing compile_commands.json
-p ${PROJECT_BINARY_DIR}
${ADD_ENTRYPOINT_OBJ_SRCS}
- # We run restrict-system-libc-headers with --system-headers to prevent
- # transitive inclusion through compler provided headers.
- COMMAND $<TARGET_FILE:clang-tidy> --system-headers
- --checks="-*,llvmlibc-restrict-system-libc-headers"
- --quiet
- -p ${PROJECT_BINARY_DIR}
- ${ADD_ENTRYPOINT_OBJ_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