widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #08939
[Merge] lp:~widelands-dev/widelands/automate_clang-format into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/automate_clang-format into lp:widelands.
Commit message:
Added script to utils for running clang-format over the code base.
Requested reviews:
SirVer (sirver)
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/automate_clang-format/+merge/312287
I think it would be a good idea to automate clang-format - it is starting to cost me real time when I work on a branch and trunk hasn't been formatted properly.
Can this be added to the bunnybot merge command once we have this in trunk? I'm thinking bzr merge, clang-format, bzr commit here.
--
Your team Widelands Developers is subscribed to branch lp:~widelands-dev/widelands/automate_clang-format.
=== added file 'utils/run_clang_format.py'
--- utils/run_clang_format.py 1970-01-01 00:00:00 +0000
+++ utils/run_clang_format.py 2016-12-01 18:04:25 +0000
@@ -0,0 +1,43 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+
+"""This script runs clang-format over src and all its subdirectories."""
+
+import argparse
+import os
+import sys
+from subprocess import call
+
+
+def parse_args():
+ p = argparse.ArgumentParser(description='Run clang-format over the code base.'
+ )
+ return p.parse_args()
+
+
+def find_cplusplus_files():
+ for (dirpath, _, filenames) in os.walk('./src'):
+ for filename in filenames:
+ if os.path.splitext(filename)[-1].lower() == '.cc' or os.path.splitext(filename)[-1].lower() == '.h':
+ yield os.path.join(dirpath, filename)
+
+
+def main():
+ parse_args()
+
+ if not os.path.isdir('src') or not os.path.isdir('utils'):
+ print('CWD is not the root of the repository.')
+ return 1
+
+ sys.stdout.write('Running clang-format ')
+ for filename in find_cplusplus_files():
+ # print "Formatting %r" % filename
+ sys.stdout.write('.')
+ sys.stdout.flush()
+ call(['clang-format-3.8', '-i', filename])
+ print '\nFormatting finished.'
+ return 0
+
+if __name__ == '__main__':
+ sys.exit(main())
Follow ups