Skip to content

Commit 5fd9cc4

Browse files
mordantecopybara-github
authored andcommitted
[libc++][CMake] Removes LIBCXX_ENABLE_CLANG_TIDY. (#85794)
The clang-tidy selection in CMake was refactored in llvm/llvm-project#81362. During review it was suggested to remove this CMake option. NOKEYCHECK=True GitOrigin-RevId: 6775285e7695f2d45cf455f5d31b2c9fa9362d3d
1 parent 1f6372d commit 5fd9cc4

File tree

6 files changed

+48
-37
lines changed

6 files changed

+48
-37
lines changed

CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ option(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS
123123
to provide compile-time errors when using features unavailable on some version of
124124
the shared library they shipped should turn this on and see `include/__availability`
125125
for more details." OFF)
126-
option(LIBCXX_ENABLE_CLANG_TIDY "Whether to compile and run clang-tidy checks" OFF)
127126

128127
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
129128
set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-gcc.cfg.in")
@@ -863,10 +862,6 @@ add_subdirectory(modules)
863862

864863
set(LIBCXX_TEST_DEPS "cxx_experimental")
865864

866-
if (LIBCXX_ENABLE_CLANG_TIDY)
867-
list(APPEND LIBCXX_TEST_DEPS cxx-tidy)
868-
endif()
869-
870865
list(APPEND LIBCXX_TEST_DEPS generate-cxx-modules)
871866

872867
if (LIBCXX_INCLUDE_BENCHMARKS)

docs/ReleaseNotes/19.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,6 @@ Build System Changes
132132

133133
- The ``LIBCXX_EXECUTOR`` and ``LIBCXXABI_EXECUTOR`` CMake variables have been removed. Please
134134
set ``LIBCXX_TEST_PARAMS`` to ``executor=<...>`` instead.
135+
136+
- The Cmake variable ``LIBCXX_ENABLE_CLANG_TIDY`` has been removed. The build system has been changed
137+
to automatically detect the presence of ``clang-tidy`` and the required ``Clang`` libraries.

test/tools/CMakeLists.txt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11

22
set(LIBCXX_TEST_TOOLS_PATH ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
33

4-
# TODO: Remove LIBCXX_ENABLE_CLANG_TIDY
5-
if(LIBCXX_ENABLE_CLANG_TIDY)
6-
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
7-
message(STATUS "Clang-tidy can only be used when building libc++ with "
8-
"a clang compiler.")
9-
return()
10-
endif()
11-
add_subdirectory(clang_tidy_checks)
4+
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
5+
message(STATUS "Clang-tidy tests are disabled due to non-clang based compiler.")
6+
return()
127
endif()
8+
add_subdirectory(clang_tidy_checks)

test/tools/clang_tidy_checks/CMakeLists.txt

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,14 @@ set(Clang_DIR_SAVE ${Clang_DIR})
99
# versions must match. Otherwise there likely will be ODR-violations. This had
1010
# led to crashes and incorrect output of the clang-tidy based checks.
1111
find_package(Clang ${CMAKE_CXX_COMPILER_VERSION})
12-
13-
set(SOURCES
14-
abi_tag_on_virtual.cpp
15-
header_exportable_declarations.cpp
16-
hide_from_abi.cpp
17-
proper_version_checks.cpp
18-
qualify_declval.cpp
19-
robust_against_adl.cpp
20-
uglify_attributes.cpp
21-
22-
libcpp_module.cpp
23-
)
24-
2512
if(NOT Clang_FOUND)
26-
message(STATUS "Could not find a suitable version of the Clang development package;
27-
custom libc++ clang-tidy checks will not be available.")
13+
message(STATUS "Clang-tidy tests are disabled since the "
14+
"Clang development package is unavailable.")
15+
return()
16+
endif()
17+
if(NOT TARGET clangTidy)
18+
message(STATUS "Clang-tidy tests are disabled since the "
19+
"Clang development package has no clangTidy target.")
2820
return()
2921
endif()
3022

@@ -54,6 +46,38 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
5446
)
5547
endif()
5648

49+
# In some cases even with the clangTidy target present the headers appear not to
50+
# be on the system. Run a short test to see whether the header is present.
51+
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test.cpp" "
52+
#if !__has_include(\"clang-tidy/ClangTidyCheck.h\")
53+
# error No clang-tidy headers
54+
#endif
55+
int main(){}
56+
")
57+
try_compile(HAS_CLANG_TIDY_HEADERS
58+
"${CMAKE_CURRENT_BINARY_DIR}"
59+
"${CMAKE_CURRENT_BINARY_DIR}/test.cpp"
60+
LINK_LIBRARIES clangTidy)
61+
62+
if(NOT HAS_CLANG_TIDY_HEADERS)
63+
message(STATUS "Clang-tidy tests are disabled since the "
64+
"clang-tidy headers are not present.")
65+
return()
66+
endif()
67+
message(STATUS "Clang-tidy tests are enabled.")
68+
69+
set(SOURCES
70+
abi_tag_on_virtual.cpp
71+
header_exportable_declarations.cpp
72+
hide_from_abi.cpp
73+
proper_version_checks.cpp
74+
qualify_declval.cpp
75+
robust_against_adl.cpp
76+
uglify_attributes.cpp
77+
78+
libcpp_module.cpp
79+
)
80+
5781
add_library(cxx-tidy MODULE ${SOURCES})
5882
target_link_libraries(cxx-tidy clangTidy)
5983

@@ -64,3 +88,5 @@ set_target_properties(cxx-tidy PROPERTIES
6488

6589
set_target_properties(cxx-tidy PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
6690
set(CMAKE_SHARED_MODULE_SUFFIX_CXX .plugin) # Use a portable suffix to simplify how we can find it from Lit
91+
92+
list(APPEND LIBCXX_TEST_DEPS cxx-tidy)

utils/ci/buildkite-pipeline.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ definitions:
4343

4444
environment_definitions:
4545
_common_env: &common_env
46-
ENABLE_CLANG_TIDY: "On"
4746
LLVM_SYMBOLIZER_PATH: "/usr/bin/llvm-symbolizer-${LLVM_HEAD_VERSION}"
4847
CLANG_CRASH_DIAGNOSTICS_DIR: "crash_diagnostics"
4948
CC: clang-${LLVM_HEAD_VERSION}

utils/ci/run-buildbot

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ CMAKE The CMake binary to use. This variable is optional.
4444
CLANG_FORMAT The clang-format binary to use when generating the format
4545
ignore list.
4646
47-
ENABLE_CLANG_TIDY Whether to compile and run clang-tidy checks. This variable
48-
is optional.
49-
5047
EOF
5148
}
5249

@@ -111,10 +108,6 @@ function clean() {
111108
rm -rf "${BUILD_DIR}"
112109
}
113110

114-
if [ -z "${ENABLE_CLANG_TIDY}" ]; then
115-
ENABLE_CLANG_TIDY=Off
116-
fi
117-
118111
function generate-cmake-base() {
119112
echo "--- Generating CMake"
120113
${CMAKE} \
@@ -126,7 +119,6 @@ function generate-cmake-base() {
126119
-DLIBCXX_ENABLE_WERROR=YES \
127120
-DLIBCXXABI_ENABLE_WERROR=YES \
128121
-DLIBUNWIND_ENABLE_WERROR=YES \
129-
-DLIBCXX_ENABLE_CLANG_TIDY=${ENABLE_CLANG_TIDY} \
130122
-DLLVM_LIT_ARGS="-sv --xunit-xml-output test-results.xml --timeout=1500 --time-tests" \
131123
"${@}"
132124
}

0 commit comments

Comments
 (0)