Skip to content

Commit 66e0331

Browse files
committed
Address review comments
1 parent 10a15df commit 66e0331

File tree

8 files changed

+48
-105
lines changed

8 files changed

+48
-105
lines changed

libcxx/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,6 @@ option(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS
124124
the shared library they shipped should turn this on and see `include/__availability`
125125
for more details." OFF)
126126
option(LIBCXX_ENABLE_CLANG_TIDY "Whether to compile and run clang-tidy checks" OFF)
127-
set(LIBCXX_CLANG_TIDY_EXECUTABLE "" CACHE FILEPATH
128-
"The clang-tidy executable to use to run the clang-tidy checks.
129-
When the variable is not set cmake will search for clang-tidy.
130-
This is only used when LIBCXX_ENABLE_CLANG_TIDY is ON.")
131127

132128
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
133129
set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-gcc.cfg.in")

libcxx/test/configs/cmake-bridge.cfg.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ config.test_exec_root = os.path.join('@CMAKE_BINARY_DIR@', 'test')
2525
# Add substitutions for bootstrapping the test suite configuration
2626
import shlex
2727
config.substitutions.append(('%{cxx}', shlex.quote('@CMAKE_CXX_COMPILER@')))
28-
config.substitutions.append(('%{clang-tidy}', shlex.quote('@LIBCXX_CLANG_TIDY@')))
2928
config.substitutions.append(('%{libcxx-dir}', '@LIBCXX_SOURCE_DIR@'))
3029
config.substitutions.append(('%{include-dir}', '@LIBCXX_GENERATED_INCLUDE_DIR@'))
3130
config.substitutions.append(('%{target-include-dir}', '@LIBCXX_GENERATED_INCLUDE_TARGET_DIR@'))

libcxx/test/tools/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,10 @@ set(LIBCXX_TEST_TOOLS_PATH ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
33

44
# TODO: Remove LIBCXX_ENABLE_CLANG_TIDY
55
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()
611
add_subdirectory(clang_tidy_checks)
712
endif()

libcxx/test/tools/clang_tidy_checks/CMakeLists.txt

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -5,81 +5,10 @@
55
set(LLVM_DIR_SAVE ${LLVM_DIR})
66
set(Clang_DIR_SAVE ${Clang_DIR})
77

8-
# libc++ only supports the latest two released versions of clang-tidy. During
9-
# the release period there the new unreleased version is also supported. To keep
10-
# this code simple, always accept the last 3 versions.
11-
set(HEAD ${LLVM_VERSION_MAJOR})
12-
math(EXPR MINUS_1 "${HEAD} - 1")
13-
math(EXPR MINUS_2 "${MINUS_1} - 1")
14-
math(EXPR MINUS_3 "${MINUS_2} - 1")
15-
16-
if("${LIBCXX_CLANG_TIDY_EXECUTABLE}" STREQUAL "")
17-
set(NAMES "clang-tidy-${HEAD}"
18-
"clang-tidy-${MINUS_1}"
19-
"clang-tidy-${MINUS_2}"
20-
"clang-tidy-${MINUS_3}"
21-
"clang-tidy")
22-
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
23-
string(REGEX MATCH
24-
"[0-9]+"
25-
LIBCXX_CLANG_MAJOR
26-
"${CMAKE_CXX_COMPILER_VERSION}")
27-
set(NAMES "clang-tidy-${LIBCXX_CLANG_MAJOR}"
28-
"clang-tidy")
29-
endif()
30-
find_program(LIBCXX_CLANG_TIDY NAMES ${NAMES})
31-
else()
32-
set(LIBCXX_CLANG_TIDY "${LIBCXX_CLANG_TIDY_EXECUTABLE}" CACHE INTERNAL "")
33-
endif()
34-
35-
if("${LIBCXX_CLANG_TIDY}" STREQUAL "")
36-
set(LIBCXX_CLANG_TIDY "" CACHE INTERNAL "")
37-
message(STATUS "Could not find a clang-tidy executable;
38-
custom libc++ clang-tidy checks will not be available.")
39-
return()
40-
endif()
41-
42-
execute_process(COMMAND
43-
"${LIBCXX_CLANG_TIDY}" "--version"
44-
OUTPUT_VARIABLE CLANG_TIDY_VERSION_OUTPUT
45-
COMMAND_ERROR_IS_FATAL ANY)
46-
string(REGEX MATCH
47-
"[0-9]+\.[0-9]+\.[0-9]+"
48-
LIBCXX_CLANG_TIDY_VERSION
49-
"${CLANG_TIDY_VERSION_OUTPUT}")
50-
51-
if("${LIBCXX_CLANG_TIDY_VERSION}" VERSION_LESS "${MINUS_3}")
52-
set(LIBCXX_CLANG_TIDY "" CACHE INTERNAL "")
53-
message(STATUS "The clang-tidy version found ${LIBCXX_CLANG_TIDY_VERSION} is
54-
too old, version ${MINUS_3}.0.0 is required;
55-
custom libc++ clang-tidy checks will not be available.")
56-
return()
57-
endif()
58-
59-
# For modules clang-tidy 17 or newer is required. This is due to the state of
60-
# implementation in clang/clang-tidy. This additional restriction should be
61-
# temporary.
62-
# TODO(LLVM-19) Remove this check
63-
if("${LIBCXX_CLANG_TIDY_VERSION}" VERSION_LESS "17.0.0")
64-
message(STATUS "The clang-tidy version found ${LIBCXX_CLANG_TIDY_VERSION} is
65-
too old, version 17.0.0 is required;
66-
custom libc++ clang-tidy checks will not be available.")
67-
endif()
68-
69-
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
70-
NOT CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "${LIBCXX_CLANG_TIDY_VERSION}")
71-
72-
set(LIBCXX_CLANG_TIDY "" CACHE INTERNAL "")
73-
message(STATUS "The version of clang ${CMAKE_CXX_COMPILER_VERSION} differs
74-
from the version of clang-tidy ${LIBCXX_CLANG_TIDY_VERSION};
75-
custom libc++ clang-tidy checks will not be available.")
76-
return()
77-
endif()
78-
798
# Since the Clang C++ ABI is not stable the Clang libraries and clang-tidy
809
# version must match. Otherwise there likely will be ODR-violations. This had
8110
# led to crashes and incorrect output of the clang-tidy based checks.
82-
find_package(Clang "${LIBCXX_CLANG_TIDY_VERSION}")
11+
find_package(Clang ${CMAKE_CXX_COMPILER_VERSION})
8312

8413
set(SOURCES
8514
abi_tag_on_virtual.cpp
@@ -94,7 +23,6 @@ set(SOURCES
9423
)
9524

9625
if(NOT Clang_FOUND)
97-
set(LIBCXX_CLANG_TIDY "" CACHE INTERNAL "")
9826
message(STATUS "Could not find a suitable version of the Clang development package;
9927
custom libc++ clang-tidy checks will not be available.")
10028
return()

libcxx/utils/ci/run-buildbot

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ CLANG_FORMAT The clang-format binary to use when generating the format
4747
ENABLE_CLANG_TIDY Whether to compile and run clang-tidy checks. This variable
4848
is optional.
4949
50-
CLANG_TIDY_EXECUTABLE
51-
The clang-tidy executable to use. Its version should match
52-
the clang version used. This variable is optional.
53-
5450
EOF
5551
}
5652

@@ -119,10 +115,6 @@ if [ -z "${ENABLE_CLANG_TIDY}" ]; then
119115
ENABLE_CLANG_TIDY=Off
120116
fi
121117

122-
if [ -z "${CLANG_TIDY_EXECUTABLE}" ]; then
123-
CLANG_TIDY_EXECUTABLE=''
124-
fi
125-
126118
function generate-cmake-base() {
127119
echo "--- Generating CMake"
128120
${CMAKE} \
@@ -135,7 +127,6 @@ function generate-cmake-base() {
135127
-DLIBCXXABI_ENABLE_WERROR=YES \
136128
-DLIBUNWIND_ENABLE_WERROR=YES \
137129
-DLIBCXX_ENABLE_CLANG_TIDY=${ENABLE_CLANG_TIDY} \
138-
-DLIBCXX_CLANG_TIDY_EXECUTABLE=${CLANG_TIDY_EXECUTABLE} \
139130
-DLLVM_LIT_ARGS="-sv --xunit-xml-output test-results.xml --timeout=1500 --time-tests" \
140131
"${@}"
141132
}

libcxx/utils/libcxx/test/config.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@
99
import os
1010

1111

12-
def _hasSubstitution(substitution, config):
13-
for k, v in config.substitutions:
14-
if k == substitution:
15-
return True
16-
return False
17-
18-
1912
def _getSubstitution(substitution, config):
2013
for (orig, replacement) in config.substitutions:
2114
if orig == substitution:

libcxx/utils/libcxx/test/features.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# ===----------------------------------------------------------------------===##
88

99
from libcxx.test.dsl import *
10-
import libcxx.test.config as config
1110
from lit.BooleanExpression import BooleanExpression
1211
import re
1312
import shutil
@@ -24,7 +23,6 @@
2423
_isMSVC = lambda cfg: "_MSC_VER" in compilerMacros(cfg)
2524
_msvcVersion = lambda cfg: (int(compilerMacros(cfg)["_MSC_VER"]) // 100, int(compilerMacros(cfg)["_MSC_VER"]) % 100)
2625

27-
2826
def _getAndroidDeviceApi(cfg):
2927
return int(
3028
programOutput(
@@ -275,11 +273,6 @@ def _getAndroidDeviceApi(cfg):
275273
name="executor-has-no-bash",
276274
when=lambda cfg: runScriptExitCode(cfg, ["%{exec} bash -c 'bash --version'"]) != 0,
277275
),
278-
Feature(
279-
name="has-clang-tidy",
280-
when=lambda cfg: config._hasSubstitution("%{clang-tidy}", cfg)
281-
and config._getSubstitution("%{clang-tidy}", cfg) != "",
282-
),
283276
# Whether module support for the platform is available.
284277
Feature(
285278
name="has-no-cxx-module-support",

libcxx/utils/libcxx/test/params.py

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,14 @@
5353
"-Wunused-parameter",
5454
"-Wunreachable-code",
5555
"-Wno-unused-local-typedef",
56-
5756
# Disable warnings for extensions used in C++03
5857
"-Wno-local-type-template-args",
5958
"-Wno-c++11-extensions",
60-
6159
# TODO(philnik) This fails with the PSTL.
6260
"-Wno-unknown-pragmas",
6361
# Don't fail compilation in case the compiler fails to perform the requested
6462
# loop vectorization.
6563
"-Wno-pass-failed",
66-
6764
# TODO: Find out why GCC warns in lots of places (is this a problem with always_inline?)
6865
"-Wno-dangling-reference",
6966
"-Wno-mismatched-new-delete",
@@ -110,6 +107,37 @@ def getSizeOptimizationFlag(cfg):
110107
)
111108

112109

110+
def testClangTidy(cfg, version, executable):
111+
try:
112+
if version in commandOutput(cfg, [f"{executable} --version"]):
113+
return executable
114+
except ConfigurationRuntimeError:
115+
return None
116+
117+
118+
def getSuitableClangTidy(cfg):
119+
# If we didn't build the libcxx-tidy plugin via CMake, we can't run the clang-tidy tests.
120+
if (
121+
runScriptExitCode(
122+
cfg, ["stat %{test-tools-dir}/clang_tidy_checks/libcxx-tidy.plugin"]
123+
)
124+
!= 0
125+
):
126+
return None
127+
128+
version = "{__clang_major__}.{__clang_minor__}.{__clang_patchlevel__}".format(
129+
**compilerMacros(cfg)
130+
)
131+
exe = testClangTidy(
132+
cfg, version, "clang-tidy-{__clang_major__}".format(**compilerMacros(cfg))
133+
)
134+
135+
if not exe:
136+
exe = testClangTidy(cfg, version, "clang-tidy")
137+
138+
return exe
139+
140+
113141
# fmt: off
114142
DEFAULT_PARAMETERS = [
115143
Parameter(
@@ -366,6 +394,16 @@ def getSizeOptimizationFlag(cfg):
366394
default=f"{shlex.quote(sys.executable)} {shlex.quote(str(Path(__file__).resolve().parent.parent.parent / 'run.py'))}",
367395
help="Custom executor to use instead of the configured default.",
368396
actions=lambda executor: [AddSubstitution("%{executor}", executor)],
369-
)
397+
),
398+
Parameter(
399+
name='clang-tidy-executable',
400+
type=str,
401+
default=lambda cfg: getSuitableClangTidy(cfg),
402+
help="TODO",
403+
actions=lambda exe: [] if exe is None else [
404+
AddFeature('has-clang-tidy'),
405+
AddSubstitution('%{clang-tidy}', exe),
406+
]
407+
),
370408
]
371409
# fmt: on

0 commit comments

Comments
 (0)