-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathrun_clang_format.py
47 lines (39 loc) · 1.34 KB
/
run_clang_format.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#! /usr/bin/python
# Copyright 2016-2019 NXP
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
# To use this script run
# $./run_clang_format.py
from __future__ import print_function
import subprocess
import sys,os
#Folders to scan
folders = []
folders.append("lib");
#Files which will be not formatted
exceptions = []
#For windows use "\\" instead of "/" path separators.
if os.environ.get('OS','') == 'Windows_NT':
for i, folder in enumerate(folders):
folders[i] = os.path.normpath(folder)
for i, ext in enumerate(exceptions):
exceptions[i] = os.path.normpath(ext)
#Files with this extensions will be formatted/
extensions = []
extensions.append(".h")
extensions.append(".c")
#processing formatting
for folder in folders:
print('*****************************************************************************')
print(folder);
for path, subdirs, files in os.walk(folder):
for name in files:
if any(ext in name for ext in extensions):
file = os.path.join(path, name)
if file in exceptions:
print("Ignored: ", file)
else:
print("Formatting: ", file)
subprocess.call(["clang-format", "-i", file])
print('*****************************************************************************\n')