From: Pieter Lexis Date: Thu, 1 Oct 2020 14:03:34 +0000 (+0200) Subject: Add script to check sort order for SOURCES X-Git-Tag: auth-4.4.0-alpha2~33^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F9570%2Fhead;p=thirdparty%2Fpdns.git Add script to check sort order for SOURCES --- diff --git a/.circleci/config.yml b/.circleci/config.yml index 4a83b9093c..edf1a4d9f0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -520,6 +520,17 @@ jobs: git --no-pager diff exit $(git diff | wc -l) working_directory: ~/project + - run: + name: Check Makefile.am SOURCES sort order + command: | + exitcode=0 + for f in $(find . -type f -name 'Makefile.am'); do + ./build-scripts/test-sources-sorted.py ${f} + if [ $? -ne 0 ]; then + exitcode=1 + fi + done + exit ${exitcode} build-auth: docker: diff --git a/build-scripts/test-sources-sorted.py b/build-scripts/test-sources-sorted.py new file mode 100755 index 0000000000..8476dfb894 --- /dev/null +++ b/build-scripts/test-sources-sorted.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +import re +import sys + +REGEX = re.compile(r'(?s)[a-z0-9][a-z0-9_]+_SOURCES ?= ?\\.*?^$', re.MULTILINE) + + +def test_sources(fname) -> int: + text = "" + with open(fname, mode="r") as f: + text = f.read() + + matches = re.findall(REGEX, text) + ret = 0 + for match in matches: + lines = match.split(" \\\n\t") + elem = lines[0].rstrip(' =') + lines = lines[1:] + sorted_lines = sorted(lines) + + if sorted_lines != lines: + ret = 1 + print(f'Source files for {elem} in {fname} is not sorted properly' + .format(elem=elem, fname=fname)) + return ret + + +if __name__ == "__main__": + sys.exit(test_sources(sys.argv[1]))