Files
systemd/tools/check-includes.py
Zbigniew Jędrzejewski-Szmek 495658d43c 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.
2023-05-09 08:11:10 +02:00

32 lines
933 B
Python
Executable File

#!/usr/bin/env python3
# SPDX-License-Identifier: LGPL-2.1-or-later
# 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
for n, line in enumerate(open(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)
return good
if __name__ == '__main__':
good = all(check_file(name) for name in sys.argv[1:])
sys.exit(0 if good else 1)