diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2018-12-23 16:19:45 +0200 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2018-12-30 00:50:00 +0200 |
commit | 1fca654055d3502d2db9c5aad66a522beaa1df19 (patch) | |
tree | baf97e14e15d57482ed73adba96ab98180ca13d6 /mesonbuild/scripts | |
parent | 3b495c397ec1baffe99d63031f2b03301b7f6ba5 (diff) | |
download | meson-1fca654055d3502d2db9c5aad66a522beaa1df19.zip meson-1fca654055d3502d2db9c5aad66a522beaa1df19.tar.gz meson-1fca654055d3502d2db9c5aad66a522beaa1df19.tar.bz2 |
Add a clang-format target.
Diffstat (limited to 'mesonbuild/scripts')
-rw-r--r-- | mesonbuild/scripts/clangformat.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/mesonbuild/scripts/clangformat.py b/mesonbuild/scripts/clangformat.py new file mode 100644 index 0000000..fcdf5af --- /dev/null +++ b/mesonbuild/scripts/clangformat.py @@ -0,0 +1,37 @@ +# Copyright 2018 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'])) + 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-format', '-style=file', '-i', 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) |