From 023a0db04ca92a825704f3f1a8382554996efb53 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Thu, 23 Feb 2023 01:28:03 -0500 Subject: [PATCH] clangformat: don't noisily print status messages for every checked file The version lookup should be silent. While we're at it, the version lookup should not be happening more than once, which printing multiple messages indicated we were doing. Pass the version into the per-file function rather than looking it up fresh each time. Fixes https://github.com/mesonbuild/meson/pull/11054#issuecomment-1430169280 --- mesonbuild/scripts/clangformat.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mesonbuild/scripts/clangformat.py b/mesonbuild/scripts/clangformat.py index a706b76d6..c66df1600 100644 --- a/mesonbuild/scripts/clangformat.py +++ b/mesonbuild/scripts/clangformat.py @@ -23,10 +23,9 @@ from ..mesonlib import version_compare from ..programs import ExternalProgram import typing as T -def run_clang_format(fname: Path, exelist: T.List[str], check: bool) -> subprocess.CompletedProcess: +def run_clang_format(fname: Path, exelist: T.List[str], check: bool, cformat_ver: T.Optional[str]) -> subprocess.CompletedProcess: clangformat_10 = False - if check: - cformat_ver = ExternalProgram('clang-format', exelist).get_version() + if check and cformat_ver: if version_compare(cformat_ver, '>=10'): clangformat_10 = True exelist = exelist + ['--dry-run', '--Werror'] @@ -58,4 +57,9 @@ def run(args: T.List[str]) -> int: print('Could not execute clang-format "%s"' % ' '.join(exelist)) return 1 - return run_tool('clang-format', srcdir, builddir, run_clang_format, exelist, options.check) + if options.check: + cformat_ver = ExternalProgram('clang-format', exelist, silent=True).get_version() + else: + cformat_ver = None + + return run_tool('clang-format', srcdir, builddir, run_clang_format, exelist, options.check, cformat_ver)