Skip to content
Snippets Groups Projects
Commit 9d7c4feb authored by Boman Romain's avatar Boman Romain
Browse files

add basic clang-format script

parent 60cc4701
No related branches found
No related tags found
1 merge request!58Improve Continuous Integration
Pipeline #1567 passed
---
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html#
# the "Visual Studio" style is similar to:
BasedOnStyle: LLVM
UseTab: Never
IndentWidth: 4
BreakBeforeBraces: Allman
AccessModifierOffset: -4
SortIncludes: false
ColumnLimit: 0
...
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
#
# This script runs "clang-format" recursively on all C/C++ files
import sys
import os
import fnmatch
import re
import subprocess
def all_files(root,
patterns='*',
skips='*.git*;*build*',
single_level=False,
yield_folders=False):
# self.checkPath(root)
patterns = patterns.split(';')
skips = skips.split(';')
for path, subdirs, files in os.walk(root):
# print('processing folder', path)
if yield_folders:
files.extend(subdirs)
files.sort()
for name in files:
for pattern in patterns:
if fnmatch.fnmatch(name, pattern):
fullname = os.path.join(path, name)
ok = True
for skip in skips:
if fnmatch.fnmatch(fullname, skip):
ok = False
if ok:
yield fullname
break
if single_level:
break
def main():
# loop over all files and format them
encs = {}
for f in all_files(os.getcwd(), patterns='*.cpp;*.c;*.h;*.hpp',
skips='*.git*;*build*'):
print(f)
cmd = ['clang-format', "-style=file", "-i", f]
retcode = subprocess.call(cmd)
if retcode != 0:
print(f'ERROR: retcode = {retcode}')
break
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment