]> git.ipfire.org Git - thirdparty/pdns.git/blame - build-scripts/test-sources-sorted.py
Merge pull request #12955 from rgacogne/ddist-fix-doc-codeblocks
[thirdparty/pdns.git] / build-scripts / test-sources-sorted.py
CommitLineData
8b7a0c7d
PL
1#!/usr/bin/env python3
2
3import re
4import sys
5
6REGEX = re.compile(r'(?s)[a-z0-9][a-z0-9_]+_SOURCES ?= ?\\.*?^$', re.MULTILINE)
7
8
9def 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
29if __name__ == "__main__":
30 sys.exit(test_sources(sys.argv[1]))