summaryrefslogtreecommitdiff
path: root/mesonbuild/scripts/clangformat.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2018-12-23 16:19:45 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2018-12-24 00:46:16 +0200
commit33f8d6d4c653b1894c29388d6a51f1815209900c (patch)
tree8368d3f7669bc8392eb01e517618bf62765ea6bf /mesonbuild/scripts/clangformat.py
parent4df9006ca43338fea07b9d542f94da34369e43d3 (diff)
downloadmeson-clangformat.tar.gz
Add a clang-format target.clangformat
Diffstat (limited to 'mesonbuild/scripts/clangformat.py')
-rw-r--r--mesonbuild/scripts/clangformat.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/mesonbuild/scripts/clangformat.py b/mesonbuild/scripts/clangformat.py
new file mode 100644
index 000000000..fcdf5af74
--- /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)