summaryrefslogtreecommitdiffstats
path: root/tools/check-includes.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
commit55944e5e40b1be2afc4855d8d2baf4b73d1876b5 (patch)
tree33f869f55a1b149e9b7c2b7e201867ca5dd52992 /tools/check-includes.py
parentInitial commit. (diff)
downloadsystemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.tar.xz
systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.zip
Adding upstream version 255.4.upstream/255.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/check-includes.py')
-rwxr-xr-xtools/check-includes.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tools/check-includes.py b/tools/check-includes.py
new file mode 100755
index 0000000..5d5b39f
--- /dev/null
+++ b/tools/check-includes.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+# pylint: disable=consider-using-with
+
+import os
+import pathlib
+import re
+import sys
+
+PROJECT_ROOT = pathlib.Path(os.getenv('PROJECT_SOURCE_ROOT', '.'))
+
+def check_file(filename):
+ seen = set()
+ good = True
+ for n, line in enumerate(open(filename)):
+ m = re.match(r'^\s*#\s*include\s*[<"](\S*)[>"]', line)
+ if m:
+ include = m.group(1)
+ if include in seen:
+ try:
+ filename = pathlib.Path(filename).resolve().relative_to(PROJECT_ROOT)
+ except ValueError:
+ pass
+ print(f'{filename}:{n}: {line.strip()}')
+ good = False
+ seen.add(include)
+ return good
+
+if __name__ == '__main__':
+ all_good = all(check_file(name) for name in sys.argv[1:])
+ sys.exit(0 if all_good else 1)