From f70a81cced3a45594c40affd7fd94792bdf2d5d2 Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Mon, 9 Jan 2023 01:39:58 +0100 Subject: [PATCH] [libc++] Add clang-tidy to the list of possible substitutions for %{clang-tidy} Most people don't have a versioned clang-tidy locally. This allows them to still run the clang-tidy test if they have a suitable version. Reviewed By: ldionne, #libc Spies: libcxx-commits, arichardson Differential Revision: https://reviews.llvm.org/D141241 --- libcxx/utils/libcxx/test/features.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/libcxx/utils/libcxx/test/features.py b/libcxx/utils/libcxx/test/features.py index 094608c..ad2089b 100644 --- a/libcxx/utils/libcxx/test/features.py +++ b/libcxx/utils/libcxx/test/features.py @@ -18,6 +18,22 @@ _isGCC = lambda cfg: '__GNUC__' in compilerMacros(cfg) and '__clang__' no _isMSVC = lambda cfg: '_MSC_VER' in compilerMacros(cfg) _msvcVersion = lambda cfg: (int(compilerMacros(cfg)['_MSC_VER']) // 100, int(compilerMacros(cfg)['_MSC_VER']) % 100) +def _getSuitableClangTidy(cfg): + try: + # If we didn't build the libcxx-tidy plugin via CMake, we can't run the clang-tidy tests. + if runScriptExitCode(cfg, ['stat %{test-tools}/clang_tidy_checks/libcxx-tidy.plugin']) != 0: + return None + + # TODO This should be the last stable release. + if runScriptExitCode(cfg, ['clang-tidy-16 --version']) == 0: + return 'clang-tidy-16' + + if int(re.search('[0-9]+', commandOutput(cfg, ['clang-tidy --version'])).group()) >= 16: + return 'clang-tidy' + + except ConfigurationRuntimeError: + return None + DEFAULT_FEATURES = [ Feature(name='fcoroutines-ts', when=lambda cfg: hasCompileFlag(cfg, '-fcoroutines-ts') and @@ -141,10 +157,8 @@ DEFAULT_FEATURES = [ Feature(name='executor-has-no-bash', when=lambda cfg: runScriptExitCode(cfg, ['%{exec} bash -c \'bash --version\'']) != 0), Feature(name='has-clang-tidy', - # TODO This should be the last stable release. - when=lambda cfg: runScriptExitCode(cfg, ['clang-tidy-16 --version']) == 0 and - runScriptExitCode(cfg, ['stat %{test-tools}/clang_tidy_checks/libcxx-tidy.plugin']) == 0, - actions=[AddSubstitution('%{clang-tidy}', 'clang-tidy-16')]), + when=lambda cfg: _getSuitableClangTidy(cfg) is not None, + actions=[AddSubstitution('%{clang-tidy}', lambda cfg: _getSuitableClangTidy(cfg))]), Feature(name='has-clang-query', when=lambda cfg: runScriptExitCode(cfg, ['clang-query-15 --version']) == 0, actions=[AddSubstitution('%{clang-query}', 'clang-query-15')]), -- 2.7.4