Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/scripts/apply_clang_format_on_all_sources.py
1693 views
1
#!/usr/bin/env python
2
3
# Copyright 2019 The ANGLE Project Authors. All rights reserved.
4
# Use of this source code is governed by a BSD-style license that can be
5
# found in the LICENSE file.
6
7
# apply_clang_format_on_all_sources.py:
8
# Script to apply clang-format recursively on directory,
9
# example usage:
10
# ./scripts/apply_clang_format_on_all_sources.py src
11
12
from __future__ import print_function
13
14
import os
15
import sys
16
import platform
17
import subprocess
18
19
# inplace change and use style from .clang-format
20
CLANG_FORMAT_ARGS = ['-i', '-style=file']
21
22
23
def main(directory):
24
system = platform.system()
25
26
clang_format_exe = 'clang-format'
27
if system == 'Windows':
28
clang_format_exe += '.bat'
29
30
partial_cmd = [clang_format_exe] + CLANG_FORMAT_ARGS
31
32
for subdir, _, files in os.walk(directory):
33
if 'third_party' in subdir:
34
continue
35
36
for f in files:
37
if f.endswith(('.c', '.h', '.cpp', '.hpp')):
38
f_abspath = os.path.join(subdir, f)
39
print("Applying clang-format on ", f_abspath)
40
subprocess.check_call(partial_cmd + [f_abspath])
41
42
43
if __name__ == '__main__':
44
if len(sys.argv) > 2:
45
print('Too mang args', file=sys.stderr)
46
47
elif len(sys.argv) == 2:
48
main(os.path.join(os.getcwd(), sys.argv[1]))
49
50
else:
51
main(os.getcwd())
52
53