Skip to content
Snippets Groups Projects
Commit d28bb5f8 authored by Adrien Crovato's avatar Adrien Crovato
Browse files

Use format_code from amfe scripts

parent 6b1fbe32
No related branches found
No related tags found
No related merge requests found
Pipeline #49636 passed with warnings
...@@ -24,8 +24,8 @@ format: ...@@ -24,8 +24,8 @@ format:
<<: *global_tag_def <<: *global_tag_def
stage: build stage: build
script: script:
- clang-format --version # we use clang-format-10 exclusively - clang-format --version
- ./scripts/format_code.py - ./ext/amfe/scripts/format_code.py
- mkdir -p patches - mkdir -p patches
- if git diff --patch --exit-code > patches/clang-format.patch; then echo "Clang format changed nothing"; else echo "Clang format found changes to make!"; false; fi - if git diff --patch --exit-code > patches/clang-format.patch; then echo "Clang format changed nothing"; else echo "Clang format found changes to make!"; false; fi
artifacts: artifacts:
......
#!/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):
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(os.path.relpath(fullname, start=root), 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'):
# print(f)
cmd = ['clang-format-10', "-style=file", "-i", f]
retcode = subprocess.call(cmd)
if retcode != 0:
print(f'ERROR: retcode = {retcode}')
break
if __name__ == "__main__":
# print('running format_code.py...')
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