From a56782546d931652c4f37a9bb4f404d5469b8dd1 Mon Sep 17 00:00:00 2001 From: Ryan Friedman Date: Thu, 17 Aug 2023 16:17:54 -0600 Subject: [PATCH] Tools: Allow enforcing astyle in CLI automatically Signed-off-by: Ryan Friedman --- Tools/scripts/build_ci.sh | 2 +- Tools/scripts/run_astyle.py | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Tools/scripts/build_ci.sh b/Tools/scripts/build_ci.sh index a5a9c1c27b..1f86af9475 100755 --- a/Tools/scripts/build_ci.sh +++ b/Tools/scripts/build_ci.sh @@ -415,7 +415,7 @@ for t in $CI_BUILD_TARGET; do if [ "$t" == "astyle-cleanliness" ]; then echo "Checking AStyle code cleanliness" - ./Tools/scripts/run_astyle.py + ./Tools/scripts/run_astyle.py --dry-run continue fi diff --git a/Tools/scripts/run_astyle.py b/Tools/scripts/run_astyle.py index ecf78a19e1..4fa18aeb6d 100755 --- a/Tools/scripts/run_astyle.py +++ b/Tools/scripts/run_astyle.py @@ -14,15 +14,17 @@ import sys import argparse os.environ['PYTHONUNBUFFERED'] = '1' +DRY_RUN_DEFAULT = False class AStyleChecker(object): - def __init__(self): + def __init__(self, *, dry_run=DRY_RUN_DEFAULT): self.retcode = 0 self.directories_to_check = [ 'libraries/AP_DDS', ] self.files_to_check = [] + self.dry_run = dry_run def progress(self, string): print("****** %s" % (string,)) @@ -31,7 +33,10 @@ class AStyleChecker(object): '''run astyle on all files in self.files_to_check''' # for path in self.files_to_check: # 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.extend(self.files_to_check) ret = subprocess.run( @@ -58,8 +63,11 @@ class AStyleChecker(object): if __name__ == '__main__': 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() - checker = AStyleChecker() + checker = AStyleChecker(dry_run=args.dry_run) sys.exit(checker.run())