diff --git a/.github/workflows/test_scripts.yml b/.github/workflows/test_scripts.yml index b26699e8b7..1f73fa0567 100644 --- a/.github/workflows/test_scripts.yml +++ b/.github/workflows/test_scripts.yml @@ -17,6 +17,7 @@ jobs: check_autotest_options, param_parse, python-cleanliness, + astyle-cleanliness, validate_board_list, ] steps: @@ -29,4 +30,6 @@ jobs: CI_BUILD_TARGET: ${{matrix.config}} shell: bash run: | + sudo apt update + sudo apt-get install -y astyle Tools/scripts/build_ci.sh diff --git a/Tools/scripts/build_ci.sh b/Tools/scripts/build_ci.sh index 357df28cb3..bc48d06d86 100755 --- a/Tools/scripts/build_ci.sh +++ b/Tools/scripts/build_ci.sh @@ -401,6 +401,12 @@ for t in $CI_BUILD_TARGET; do continue fi + if [ "$t" == "astyle-cleanliness" ]; then + echo "Checking AStyle code cleanliness" + ./Tools/scripts/run_astyle.py + continue + fi + if [ "$t" == "configure-all" ]; then echo "Checking configure of all boards" ./Tools/scripts/configure_all.py diff --git a/Tools/scripts/run_astyle.py b/Tools/scripts/run_astyle.py new file mode 100755 index 0000000000..2a9ac336b7 --- /dev/null +++ b/Tools/scripts/run_astyle.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 + +""" +Runs astyle over directory sub-trees known to be "astyle-clean" + + AP_FLAKE8_CLEAN +""" + +import os +import pathlib +import subprocess +import sys + +import argparse + +os.environ['PYTHONUNBUFFERED'] = '1' + + +class AStyleChecker(object): + def __init__(self): + self.retcode = 0 + self.directories_to_check = [ + 'libraries/AP_DDS', + ] + self.files_to_check = [] + + def progress(self, string): + print("****** %s" % (string,)) + + def check(self): + '''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.extend(self.files_to_check) + ret = subprocess.run( + astyle_command, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + text=True + ) + if ret.returncode != 0: + self.progress("astyle check failed: (%s)" % (ret.stdout)) + self.retcode = 1 + if "Formatted" in ret.stdout: + self.progress("Files needing formatting found") + print(ret.stdout) + self.retcode = 1 + + def run(self): + for d in self.directories_to_check: + self.files_to_check.extend(list(pathlib.Path(d).glob("*"))) + self.files_to_check = list(filter(lambda x : x.suffix in [".c", ".h", ".cpp"], self.files_to_check)) + self.check() + return self.retcode + + +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') + args = parser.parse_args() + + checker = AStyleChecker() + sys.exit(checker.run())