]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add script to check sort order for SOURCES 9570/head
authorPieter Lexis <pieter.lexis@powerdns.com>
Thu, 1 Oct 2020 14:03:34 +0000 (16:03 +0200)
committerPieter Lexis <pieter.lexis@powerdns.com>
Thu, 1 Oct 2020 14:19:14 +0000 (16:19 +0200)
.circleci/config.yml
build-scripts/test-sources-sorted.py [new file with mode: 0755]

index 4a83b9093cdb33adf7bebd53bf06e4660d129e86..edf1a4d9f0a97903e261a89143297bf4398626ba 100644 (file)
@@ -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 (executable)
index 0000000..8476dfb
--- /dev/null
@@ -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]))