summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2023-05-05 09:38:15 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2023-05-09 08:11:10 +0200
commit495658d43c72d3a1496c8181bb1fcec84a76d66c (patch)
tree6092e25a56a6190c4ec17b03c4589e11bbabfa8a /tools
parentb0bd2ae8b3311f1cc811f0986072c09b293e8c07 (diff)
downloadsystemd-495658d43c72d3a1496c8181bb1fcec84a76d66c.tar.gz
check-includes: print path relative to project root
Instead of /home/zbyszek/src/systemd-work/build/../src/xdg-autostart-generator/xdg-autostart-service.h:11, print just src/xdg-autostart-generator/xdg-autostart-service.h:11. This is a bit annoying that this requires so much verbosity, but the output with the full names was too annoying.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/check-includes.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/tools/check-includes.py b/tools/check-includes.py
index 27d11b9d0a..abca2882f0 100755
--- a/tools/check-includes.py
+++ b/tools/check-includes.py
@@ -3,9 +3,13 @@
# pylint: disable=missing-docstring,invalid-name,unspecified-encoding,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
@@ -13,6 +17,10 @@ def check_file(filename):
if m := re.match(r'^\s*#\s*include\s*[<"](\S*)[>"]', line):
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)