diff --git a/libcxx/utils/libcxx/test/features.py b/libcxx/utils/libcxx/test/features.py index 094608c2a16eee..ad2089bdde4dd2 100644 --- a/libcxx/utils/libcxx/test/features.py +++ b/libcxx/utils/libcxx/test/features.py @@ -18,6 +18,22 @@ _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 @@ 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')]),