aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorLei YU <yulei.sh@bytedance.com>2023-08-30 06:47:14 +0000
committerJussi Pakkanen <jpakkane@gmail.com>2023-09-25 16:25:01 +0300
commit8d6b474bf67bb8a75e8f60196f7eaf7528a85c62 (patch)
tree1a5d56603a4e64c6878577ba45fb3af15ebf2fd8 /mesonbuild
parentf20f33149495b5b43bba5f06aa5b9ff4ee59a474 (diff)
downloadmeson-8d6b474bf67bb8a75e8f60196f7eaf7528a85c62.zip
meson-8d6b474bf67bb8a75e8f60196f7eaf7528a85c62.tar.gz
meson-8d6b474bf67bb8a75e8f60196f7eaf7528a85c62.tar.bz2
Add clang-tidy-fix target
Add the `clang-tidy-fix` target to apply clang-tidy fixes to the source code. This is done by calling `run-clang-tidy` with `-fix` argument. Add a test case to run `clang-tidy-fix` and verify the file is changed. Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/backend/ninjabackend.py1
-rw-r--r--mesonbuild/scripts/clangtidy.py7
2 files changed, 7 insertions, 1 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index a57b249..925941a 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -3659,6 +3659,7 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
if not shutil.which('clang-tidy'):
return
self.generate_clangtool('tidy')
+ self.generate_clangtool('tidy', 'fix')
def generate_tags(self, tool: str, target_name: str) -> None:
import shutil
diff --git a/mesonbuild/scripts/clangtidy.py b/mesonbuild/scripts/clangtidy.py
index 324a26e..943bde5 100644
--- a/mesonbuild/scripts/clangtidy.py
+++ b/mesonbuild/scripts/clangtidy.py
@@ -23,8 +23,12 @@ import typing as T
def run_clang_tidy(fname: Path, builddir: Path) -> subprocess.CompletedProcess:
return subprocess.run(['clang-tidy', '-p', str(builddir), str(fname)])
+def run_clang_tidy_fix(fname: Path, builddir: Path) -> subprocess.CompletedProcess:
+ return subprocess.run(['run-clang-tidy', '-fix', '-format', '-quiet', '-p', str(builddir), str(fname)])
+
def run(args: T.List[str]) -> int:
parser = argparse.ArgumentParser()
+ parser.add_argument('--fix', action='store_true')
parser.add_argument('sourcedir')
parser.add_argument('builddir')
options = parser.parse_args(args)
@@ -32,4 +36,5 @@ def run(args: T.List[str]) -> int:
srcdir = Path(options.sourcedir)
builddir = Path(options.builddir)
- return run_tool('clang-tidy', srcdir, builddir, run_clang_tidy, builddir)
+ run_func = run_clang_tidy_fix if options.fix else run_clang_tidy
+ return run_tool('clang-tidy', srcdir, builddir, run_func, builddir)