]>
Commit | Line | Data |
---|---|---|
c4a090d6 ZJS |
1 | #!/usr/bin/env python3 |
2 | # SPDX-License-Identifier: LGPL-2.1-or-later | |
3 | ||
f56accb6 | 4 | # pylint: disable=consider-using-with |
c4a090d6 | 5 | |
495658d4 ZJS |
6 | import os |
7 | import pathlib | |
c4a090d6 ZJS |
8 | import re |
9 | import sys | |
10 | ||
495658d4 ZJS |
11 | PROJECT_ROOT = pathlib.Path(os.getenv('PROJECT_SOURCE_ROOT', '.')) |
12 | ||
c4a090d6 ZJS |
13 | def check_file(filename): |
14 | seen = set() | |
15 | good = True | |
16 | for n, line in enumerate(open(filename)): | |
e76ff432 ZJS |
17 | m = re.match(r'^\s*#\s*include\s*[<"](\S*)[>"]', line) |
18 | if m: | |
c4a090d6 ZJS |
19 | include = m.group(1) |
20 | if include in seen: | |
495658d4 ZJS |
21 | try: |
22 | filename = pathlib.Path(filename).resolve().relative_to(PROJECT_ROOT) | |
23 | except ValueError: | |
24 | pass | |
c4a090d6 ZJS |
25 | print(f'{filename}:{n}: {line.strip()}') |
26 | good = False | |
27 | seen.add(include) | |
28 | return good | |
29 | ||
30 | if __name__ == '__main__': | |
f56accb6 FS |
31 | all_good = all(check_file(name) for name in sys.argv[1:]) |
32 | sys.exit(0 if all_good else 1) |