2023-05-05 15:03:12 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
|
2023-07-18 00:37:17 +08:00
|
|
|
# pylint: disable=consider-using-with
|
2023-05-05 15:03:12 +08:00
|
|
|
|
2023-05-05 15:38:15 +08:00
|
|
|
import os
|
|
|
|
import pathlib
|
2023-05-05 15:03:12 +08:00
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
2023-05-05 15:38:15 +08:00
|
|
|
PROJECT_ROOT = pathlib.Path(os.getenv('PROJECT_SOURCE_ROOT', '.'))
|
|
|
|
|
2023-05-05 15:03:12 +08:00
|
|
|
def check_file(filename):
|
|
|
|
seen = set()
|
|
|
|
good = True
|
|
|
|
for n, line in enumerate(open(filename)):
|
2023-05-07 17:01:33 +08:00
|
|
|
m = re.match(r'^\s*#\s*include\s*[<"](\S*)[>"]', line)
|
|
|
|
if m:
|
2023-05-05 15:03:12 +08:00
|
|
|
include = m.group(1)
|
|
|
|
if include in seen:
|
2023-05-05 15:38:15 +08:00
|
|
|
try:
|
|
|
|
filename = pathlib.Path(filename).resolve().relative_to(PROJECT_ROOT)
|
|
|
|
except ValueError:
|
|
|
|
pass
|
2023-05-05 15:03:12 +08:00
|
|
|
print(f'{filename}:{n}: {line.strip()}')
|
|
|
|
good = False
|
|
|
|
seen.add(include)
|
|
|
|
return good
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2023-07-18 00:37:17 +08:00
|
|
|
all_good = all(check_file(name) for name in sys.argv[1:])
|
|
|
|
sys.exit(0 if all_good else 1)
|