[libcxx-commits] [PATCH] D141241: [libc++] Add clang-tidy to the list of possible substitutions for %{clang-tidy}

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jan 8 16:41:01 PST 2023


philnik created this revision.
philnik added reviewers: ldionne, Mordante.
Herald added a subscriber: arichardson.
Herald added a reviewer: njames93.
Herald added a project: All.
philnik requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141241

Files:
  libcxx/utils/libcxx/test/features.py


Index: libcxx/utils/libcxx/test/features.py
===================================================================
--- libcxx/utils/libcxx/test/features.py
+++ libcxx/utils/libcxx/test/features.py
@@ -18,6 +18,20 @@
 _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 runScriptExitCode(cfg, ['stat %{test-tools}/clang_tidy_checks/libcxx-tidy.plugin']) != 0:
+      return ''
+
+    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 ''
+
 DEFAULT_FEATURES = [
   Feature(name='fcoroutines-ts',
           when=lambda cfg: hasCompileFlag(cfg, '-fcoroutines-ts') and
@@ -142,9 +156,8 @@
           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) != '',
+          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')]),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141241.487246.patch
Type: text/x-patch
Size: 1802 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230109/d05cdf2e/attachment.bin>


More information about the libcxx-commits mailing list