This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Check project-owned C and header files with clang-format."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--root", type=Path, required=True)
|
||||
parser.add_argument("--clang-format", required=True)
|
||||
args = parser.parse_args()
|
||||
|
||||
root = args.root.resolve()
|
||||
files: list[Path] = []
|
||||
for directory in ("include", "src", "adapters", "samples", "tests"):
|
||||
files.extend(sorted((root / directory).rglob("*.c")))
|
||||
files.extend(sorted((root / directory).rglob("*.h")))
|
||||
|
||||
result = subprocess.run(
|
||||
[args.clang_format, "--dry-run", "--Werror", *map(str, files)],
|
||||
cwd=root,
|
||||
check=False,
|
||||
)
|
||||
if result.returncode != 0:
|
||||
return result.returncode
|
||||
print(f"format check passed across {len(files)} C/header files")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user