diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2019-09-29 23:17:02 +0300 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2019-10-01 22:02:51 +0300 |
commit | d3b389f349edf9fac12c3d40361ea0cd394926c0 (patch) | |
tree | d3f5b8947ae0795cbf48128a23cad47961514fb8 /mesonbuild | |
parent | 5a52983f16309b86d7be1a327e2f240be2bcaaea (diff) | |
download | meson-d3b389f349edf9fac12c3d40361ea0cd394926c0.zip meson-d3b389f349edf9fac12c3d40361ea0cd394926c0.tar.gz meson-d3b389f349edf9fac12c3d40361ea0cd394926c0.tar.bz2 |
Add clang-tidy target. Closes #2383.
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 8 | ||||
-rw-r--r-- | mesonbuild/scripts/clangtidy.py | 38 |
2 files changed, 45 insertions, 1 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 1f3fb77..fe1eee6 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -2657,7 +2657,6 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485''')) self.create_target_alias('meson-scan-build') def generate_clangtool(self, name): - import shutil target_name = 'clang-' + name if not os.path.exists(os.path.join(self.environment.source_dir, '.clang-' + name)) and \ not os.path.exists(os.path.join(self.environment.source_dir, '_clang-' + name)): @@ -2677,10 +2676,17 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485''')) return self.generate_clangtool('format') + def generate_clangtidy(self): + import shutil + if not shutil.which('clang-tidy'): + return + self.generate_clangtool('tidy') + # For things like scan-build and other helper tools we might have. def generate_utils(self): self.generate_scanbuild() self.generate_clangformat() + self.generate_clangtidy() cmd = self.environment.get_build_command() + ['--internal', 'uninstall'] elem = NinjaBuildElement(self.all_outputs, 'meson-uninstall', 'CUSTOM_COMMAND', 'PHONY') elem.add_item('COMMAND', cmd) diff --git a/mesonbuild/scripts/clangtidy.py b/mesonbuild/scripts/clangtidy.py new file mode 100644 index 0000000..11c737f --- /dev/null +++ b/mesonbuild/scripts/clangtidy.py @@ -0,0 +1,38 @@ +# Copyright 2019 The Meson development team + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import pathlib +import subprocess +from concurrent.futures import ThreadPoolExecutor + +from ..compilers import lang_suffixes + +def clangformat(srcdir_name, builddir_name): + srcdir = pathlib.Path(srcdir_name) + suffixes = set(lang_suffixes['c']).union(set(lang_suffixes['cpp'])) + suffixes.add('h') + futures = [] + with ThreadPoolExecutor() as e: + for f in (x for suff in suffixes for x in srcdir.glob('**/*.' + suff)): + strf = str(f) + if strf.startswith(builddir_name): + continue + futures.append(e.submit(subprocess.check_call, ['clang-tidy', '-p', builddir_name, strf])) + [x.result() for x in futures] + return 0 + +def run(args): + srcdir_name = args[0] + builddir_name = args[1] + return clangformat(srcdir_name, builddir_name) |