diff --git a/wpiformat/pyproject.toml b/wpiformat/pyproject.toml index 3337de4..30fb863 100644 --- a/wpiformat/pyproject.toml +++ b/wpiformat/pyproject.toml @@ -7,7 +7,8 @@ dependencies = [ "regex==2023.10.3", "black==23.9.1", "clang-format==17.0.5", - "clang-tidy==17.0.1" + "clang-tidy==17.0.1", + "gersemi==0.9.3" ] classifiers = [ "Development Status :: 5 - Production/Stable", diff --git a/wpiformat/wpiformat/__init__.py b/wpiformat/wpiformat/__init__.py index f84b6fe..7cd8d05 100644 --- a/wpiformat/wpiformat/__init__.py +++ b/wpiformat/wpiformat/__init__.py @@ -11,6 +11,7 @@ from wpiformat.cidentlist import CIdentList from wpiformat.clangformat import ClangFormat from wpiformat.clangtidy import ClangTidy +from wpiformat.cmakeformat import CMakeFormat from wpiformat.config import Config from wpiformat.eofnewline import EofNewline from wpiformat.gtestname import GTestName @@ -483,6 +484,7 @@ def main(): task_pipeline = [ BraceComment(), CIdentList(), + CMakeFormat(), EofNewline(), GTestName(), IncludeGuard(), diff --git a/wpiformat/wpiformat/cmakeformat.py b/wpiformat/wpiformat/cmakeformat.py new file mode 100644 index 0000000..b490c70 --- /dev/null +++ b/wpiformat/wpiformat/cmakeformat.py @@ -0,0 +1,22 @@ +"""This task runs gersemi on CMake files.""" + +import subprocess +import sys + +from wpiformat.task import Task + + +class CMakeFormat(Task): + @staticmethod + def should_process_file(config_file, name): + return name.endswith("CMakeLists.txt") or name.endswith(".cmake") + + @staticmethod + def run_batch(config_file, names): + try: + args = [sys.executable, "-m", "gersemi", "-i"] + returncode = subprocess.run(args + names).returncode + except FileNotFoundError: + print("Error: gersemi not found in PATH. Is it installed?", file=sys.stderr) + return False + return True