aboutsummaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli/cformat.py
diff options
context:
space:
mode:
authorskullY <skullydazed@gmail.com>2019-11-12 17:17:12 -0800
committerskullydazed <skullydazed@users.noreply.github.com>2019-11-12 18:39:42 -0800
commit5421ba11dedd9912967b1fa5ed1f664687221143 (patch)
tree1c6d133798e7c87aa11fb811f0cc8e3e846741a6 /lib/python/qmk/cli/cformat.py
parentb252cce18fd474562510be5fc1e401287d747cd3 (diff)
downloadqmk_firmware-5421ba11dedd9912967b1fa5ed1f664687221143.tar.gz
qmk_firmware-5421ba11dedd9912967b1fa5ed1f664687221143.zip
Add support for newer versions of clang-format, if installed
Diffstat (limited to 'lib/python/qmk/cli/cformat.py')
-rw-r--r--lib/python/qmk/cli/cformat.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/python/qmk/cli/cformat.py b/lib/python/qmk/cli/cformat.py
index d2382bdbd..17ca91b3b 100644
--- a/lib/python/qmk/cli/cformat.py
+++ b/lib/python/qmk/cli/cformat.py
@@ -2,6 +2,7 @@
2""" 2"""
3import os 3import os
4import subprocess 4import subprocess
5from shutil import which
5 6
6from milc import cli 7from milc import cli
7 8
@@ -11,10 +12,18 @@ from milc import cli
11def cformat(cli): 12def cformat(cli):
12 """Format C code according to QMK's style. 13 """Format C code according to QMK's style.
13 """ 14 """
15 # Determine which version of clang-format to use
14 clang_format = ['clang-format', '-i'] 16 clang_format = ['clang-format', '-i']
17 for clang_version in [10, 9, 8, 7]:
18 binary = 'clang-format-%d' % clang_version
19 if which(binary):
20 clang_format[0] = binary
21 break
15 22
16 # Find the list of files to format 23 # Find the list of files to format
17 if not cli.args.files: 24 if cli.args.files:
25 cli.args.files = [os.path.join(os.environ['ORIG_CWD'], file) for file in cli.args.files]
26 else:
18 for dir in ['drivers', 'quantum', 'tests', 'tmk_core']: 27 for dir in ['drivers', 'quantum', 'tests', 'tmk_core']:
19 for dirpath, dirnames, filenames in os.walk(dir): 28 for dirpath, dirnames, filenames in os.walk(dir):
20 if 'tmk_core/protocol/usb_hid' in dirpath: 29 if 'tmk_core/protocol/usb_hid' in dirpath: