clangformat.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright 2018 The Meson development team
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. # Unless required by applicable law or agreed to in writing, software
  7. # distributed under the License is distributed on an "AS IS" BASIS,
  8. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. # See the License for the specific language governing permissions and
  10. # limitations under the License.
  11. import pathlib
  12. import subprocess
  13. from concurrent.futures import ThreadPoolExecutor
  14. from ..compilers import lang_suffixes
  15. def clangformat(srcdir_name, builddir_name):
  16. srcdir = pathlib.Path(srcdir_name)
  17. suffixes = set(lang_suffixes['c']).union(set(lang_suffixes['cpp']))
  18. futures = []
  19. with ThreadPoolExecutor() as e:
  20. for f in (x for suff in suffixes for x in srcdir.glob('**/*.' + suff)):
  21. strf = str(f)
  22. if strf.startswith(builddir_name):
  23. continue
  24. futures.append(e.submit(subprocess.check_call, ['clang-format', '-style=file', '-i', strf]))
  25. [x.result() for x in futures]
  26. return 0
  27. def run(args):
  28. srcdir_name = args[0]
  29. builddir_name = args[1]
  30. return clangformat(srcdir_name, builddir_name)