]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
check-includes: print path relative to project root
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 5 May 2023 07:38:15 +0000 (09:38 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 9 May 2023 06:11:10 +0000 (08:11 +0200)
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.

tools/check-includes.py

index 27d11b9d0a9d86d8c7762282504871f833578cb5..abca2882f0b5894d6672dd19ad77e9c374ae9839 100755 (executable)
@@ -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)