-
Notifications
You must be signed in to change notification settings - Fork 2
/
clang_format.py
31 lines (26 loc) · 1.09 KB
/
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
import os
import sys
def clangFormat():
if os.name == "nt":
osPathName = "windows-x86_64"
exeName = "clang-format.exe"
elif os.name == "posix":
osPathName = "linux-x86_64"
exeName = "clang-format"
if os.environ.get("ANDROID_NDK_HOME") != None:
ndkHome = str(os.environ.get("ANDROID_NDK_HOME"))
elif os.environ.get("ANDROID_NDK_ROOT") != None:
ndkHome = str(os.environ.get("ANDROID_NDK_ROOT"))
else:
print("ANDROID_NDK_HOME environment variable needs to be set")
sys.exit(1)
scriptPath = os.path.dirname(os.path.realpath(__file__))
srcDir = os.path.join(scriptPath, "app", "src", "main", "cpp")
clangFormatExe = os.path.join(ndkHome, "toolchains", "llvm", "prebuilt", osPathName, "bin", exeName)
for file in os.listdir(srcDir):
if file.endswith(".c") or file.endswith(".cpp") or file.endswith(".h") or file.endswith(".hpp"):
exe = clangFormatExe + " -i -style=file " + str(os.path.join(srcDir, file))
print(exe)
os.system(exe)
if __name__ == '__main__':
clangFormat()