Skip to content

Commit c7b7fc1

Browse files
committed
clang-tidy: run tool only on source files participating in targets
clang-tidy can't be ran as is on every source file and header
1 parent 98f5802 commit c7b7fc1

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

mesonbuild/scripts/clangtidy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import shutil
1212
import sys
1313

14-
from .run_tool import run_clang_tool, run_with_buffered_output
14+
from .run_tool import run_with_buffered_output, run_clang_tool_on_sources
1515
from ..environment import detect_clangtidy, detect_clangapply
1616
import typing as T
1717

@@ -56,7 +56,7 @@ def run(args: T.List[str]) -> int:
5656
fixesdir.unlink()
5757
fixesdir.mkdir(parents=True)
5858

59-
tidyret = run_clang_tool('clang-tidy', srcdir, builddir, run_clang_tidy, tidyexe, builddir, fixesdir)
59+
tidyret = run_clang_tool_on_sources('clang-tidy', srcdir, builddir, run_clang_tidy, tidyexe, builddir, fixesdir)
6060
if fixesdir is not None:
6161
print('Applying fix-its...')
6262
applyret = subprocess.run(applyexe + ['-format', '-style=file', '-ignore-insert-conflict', fixesdir]).returncode

mesonbuild/scripts/run_tool.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import json
1010
import signal
1111
import sys
12-
from pathlib import Path
12+
from pathlib import Path, PosixPath
1313

1414
from .. import mlog
1515
from ..compilers import lang_suffixes
@@ -128,6 +128,26 @@ def wrapper(path: Path) -> T.Iterable[T.Coroutine[None, None, int]]:
128128
yield fn(path, *args)
129129
return asyncio.run(_run_workers(all_clike_files(name, srcdir, builddir), wrapper))
130130

131+
def run_clang_tool_on_sources(name: str, srcdir: Path, builddir: Path, fn: T.Callable[..., T.Coroutine[None, None, int]], *args: T.Any) -> int:
132+
if sys.platform == 'win32':
133+
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
134+
135+
source_files = set()
136+
with open('meson-info/intro-targets.json', encoding='utf-8') as fp:
137+
targets = json.load(fp)
138+
139+
for target in targets:
140+
for target_source in target.get('target_sources') or []:
141+
for source in target_source.get('sources') or []:
142+
source_files.add(PosixPath(source))
143+
144+
clike_files = set(all_clike_files(name, srcdir, builddir))
145+
source_files = source_files.intersection(clike_files)
146+
147+
def wrapper(path: Path) -> T.Iterable[T.Coroutine[None, None, int]]:
148+
yield fn(path, *args)
149+
return asyncio.run(_run_workers(source_files, wrapper))
150+
131151
def run_tool_on_targets(fn: T.Callable[[T.Dict[str, T.Any]],
132152
T.Iterable[T.Coroutine[None, None, int]]]) -> int:
133153
if sys.platform == 'win32':

0 commit comments

Comments
 (0)