Tools: Allow enforcing astyle in CLI automatically

Signed-off-by: Ryan Friedman <ryanfriedman5410+github@gmail.com>
This commit is contained in:
Ryan Friedman 2023-08-17 16:17:54 -06:00 committed by Peter Barker
parent 7d264f1700
commit a56782546d
2 changed files with 13 additions and 5 deletions

View File

@ -415,7 +415,7 @@ for t in $CI_BUILD_TARGET; do
if [ "$t" == "astyle-cleanliness" ]; then if [ "$t" == "astyle-cleanliness" ]; then
echo "Checking AStyle code cleanliness" echo "Checking AStyle code cleanliness"
./Tools/scripts/run_astyle.py ./Tools/scripts/run_astyle.py --dry-run
continue continue
fi fi

View File

@ -14,15 +14,17 @@ import sys
import argparse import argparse
os.environ['PYTHONUNBUFFERED'] = '1' os.environ['PYTHONUNBUFFERED'] = '1'
DRY_RUN_DEFAULT = False
class AStyleChecker(object): class AStyleChecker(object):
def __init__(self): def __init__(self, *, dry_run=DRY_RUN_DEFAULT):
self.retcode = 0 self.retcode = 0
self.directories_to_check = [ self.directories_to_check = [
'libraries/AP_DDS', 'libraries/AP_DDS',
] ]
self.files_to_check = [] self.files_to_check = []
self.dry_run = dry_run
def progress(self, string): def progress(self, string):
print("****** %s" % (string,)) print("****** %s" % (string,))
@ -31,7 +33,10 @@ class AStyleChecker(object):
'''run astyle on all files in self.files_to_check''' '''run astyle on all files in self.files_to_check'''
# for path in self.files_to_check: # for path in self.files_to_check:
# self.progress("Checking (%s)" % path) # self.progress("Checking (%s)" % path)
astyle_command = ["astyle", "--dry-run"] astyle_command = ["astyle"]
if self.dry_run:
astyle_command.append("--dry-run")
astyle_command.append("--options=Tools/CodeStyle/astylerc") astyle_command.append("--options=Tools/CodeStyle/astylerc")
astyle_command.extend(self.files_to_check) astyle_command.extend(self.files_to_check)
ret = subprocess.run( ret = subprocess.run(
@ -58,8 +63,11 @@ class AStyleChecker(object):
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Check all Python files for astyle cleanliness') parser = argparse.ArgumentParser(description='Check all Python files for astyle cleanliness')
# parser.add_argument('--build', action='store_true', default=False, help='build as well as configure') parser.add_argument('--dry-run',
action='store_true',
default=DRY_RUN_DEFAULT,
help='Perform a trial run with no changes made to check for formatting')
args = parser.parse_args() args = parser.parse_args()
checker = AStyleChecker() checker = AStyleChecker(dry_run=args.dry_run)
sys.exit(checker.run()) sys.exit(checker.run())