From 1f15d552a6d6c39e7e689f6c928623135cc2ff86 Mon Sep 17 00:00:00 2001 From: angelosa Date: Mon, 1 Sep 2025 15:47:16 +0200 Subject: scripts/build: add a python script for checking EoF markers across source tree --- scripts/build/check_eof.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 scripts/build/check_eof.py diff --git a/scripts/build/check_eof.py b/scripts/build/check_eof.py new file mode 100644 index 00000000000..d681ca8edcd --- /dev/null +++ b/scripts/build/check_eof.py @@ -0,0 +1,27 @@ +#!/usr/bin/python3 +## +## license:BSD-3-Clause +## copyright-holders:Angelo Salese +"""Checks that all files in source code ends with a newline at end of file +""" + +import os +import sys + +if __name__ == '__main__': + CHAR_DEPTH = 2 if sys.platform in ["win32", "cygwin"] else 1 + for r, _, f in os.walk("src"): + FILEPATHS = [os.path.join(r, file) for file in f] + for item in FILEPATHS: + if not item.endswith((".cpp", ".h", ".mm", ".lua", ".py")): + continue + with open(item, mode="r", encoding="utf-8") as fh: + try: + fh.seek(0, os.SEEK_END) + fh.seek(fh.tell() - CHAR_DEPTH, os.SEEK_SET) + value = fh.read(CHAR_DEPTH) + if value != os.linesep: + raise ValueError(value, item) + except UnicodeDecodeError: + print(item, file=sys.stderr) + raise -- cgit v1.2.3