]> git.ipfire.org Git - thirdparty/pdns.git/blob - build-scripts/test-sources-sorted.py
Merge pull request #8970 from kpfleming/clarify-tsigkey-purpose
[thirdparty/pdns.git] / build-scripts / test-sources-sorted.py
1 #!/usr/bin/env python3
2
3 import re
4 import sys
5
6 REGEX = re.compile(r'(?s)[a-z0-9][a-z0-9_]+_SOURCES ?= ?\\.*?^$', re.MULTILINE)
7
8
9 def test_sources(fname) -> int:
10 text = ""
11 with open(fname, mode="r") as f:
12 text = f.read()
13
14 matches = re.findall(REGEX, text)
15 ret = 0
16 for match in matches:
17 lines = match.split(" \\\n\t")
18 elem = lines[0].rstrip(' =')
19 lines = lines[1:]
20 sorted_lines = sorted(lines)
21
22 if sorted_lines != lines:
23 ret = 1
24 print(f'Source files for {elem} in {fname} is not sorted properly'
25 .format(elem=elem, fname=fname))
26 return ret
27
28
29 if __name__ == "__main__":
30 sys.exit(test_sources(sys.argv[1]))