From 875e097fe65eac923eb67412d3e5b2c33f4a3910 Mon Sep 17 00:00:00 2001 From: Neil Date: Wed, 11 Mar 2020 15:34:44 +1100 Subject: Modernize and simplify script. Now requires Python 3. --- scripts/HeaderCheck.py | 74 +++++++++++++++++++------------------------------- 1 file changed, 28 insertions(+), 46 deletions(-) (limited to 'scripts/HeaderCheck.py') diff --git a/scripts/HeaderCheck.py b/scripts/HeaderCheck.py index 42de0ba9c..f8a7f582e 100644 --- a/scripts/HeaderCheck.py +++ b/scripts/HeaderCheck.py @@ -3,69 +3,51 @@ # Canonical header order is defined in scripts/HeaderOrder.txt # Requires Python 3.6 or later -from __future__ import print_function -import codecs, glob, os, platform, sys, unicodedata +import codecs, glob, os -def ciCompare(a,b): - return cmp(a.lower(), b.lower()) - -def ciKey(a): - return a.lower() - -def SortListInsensitive(l): - try: # Try key function - l.sort(key=ciKey) - except TypeError: # Earlier version of Python, so use comparison function - l.sort(ciCompare) +patterns = [ + "include/*.h", + "src/*.cxx", + "lexlib/*.cxx", + "lexers/*.cxx", + "win32/*.cxx", + "gtk/*.cxx", + "cocoa/*.mm", + "cocoa/*.h", + "test/unit/*.cxx", + "lexilla/src/*.cxx", + "lexilla/test/*.cxx", +] def IsHeader(x): return x.strip().startswith("#") and ("include" in x or "import" in x) +def HeaderFromIncludeLine(s): + #\s*#\s*(include|import)\s+\S+\s* + return s.strip()[1:].strip()[7:].strip() + def ExtractHeaders(filename): - with codecs.open(filename, "r", "UTF-8") as infile: - includeLines = [x.strip()[1:].strip()[7:].strip() for x in infile.readlines() if \ - IsHeader(x)] - if '.' not in filename: - print(filename) - for n in includeLines: - print(n) - print() - return includeLines + with codecs.open(filename, "r", "windows-1252") as infile: + return [HeaderFromIncludeLine(l) for l in infile if IsHeader(l)] def CheckFiles(root): # Find all the lexer source code files - filePaths = glob.glob(root + "/include/*.h") - filePaths += glob.glob(root + "/src/*.cxx") - SortListInsensitive(filePaths) - filePaths += glob.glob(root + "/lexlib/*.cxx") - filePaths += glob.glob(root + "/lexers/*.cxx") - filePaths += glob.glob(root + "/win32/*.cxx") - filePaths += glob.glob(root + "/gtk/*.cxx") - filePaths += glob.glob(root + "/cocoa/*.mm") - filePaths += glob.glob(root + "/cocoa/*.h") - filePaths += glob.glob(root + "/test/unit/*.cxx") - filePaths += glob.glob(root + "/lexilla/src/*.cxx") - filePaths += glob.glob(root + "/lexilla/test/*.cxx") + filePaths = [] + for p in patterns: + filePaths += glob.glob(os.path.join(root, p)) # The Qt platform code interleaves system and Scintilla headers #~ filePaths += glob.glob(root + "/qt/ScintillaEditBase/*.cpp") #~ filePaths += glob.glob(root + "/qt/ScintillaEdit/*.cpp") #~ print(filePaths) - masterHeaderList = ExtractHeaders(root + "/scripts/HeaderOrder.txt") - for f in filePaths: - if "LexCaml" in f: + masterHeaderList = ExtractHeaders(os.path.join(root, "scripts/HeaderOrder.txt")) + orderedPaths = sorted(filePaths, key=str.casefold) + for f in orderedPaths: + if "LexCaml" in f: # LexCaml adds system headers in #if to be an external lexer continue print(" File ", f) - try: - incs = ExtractHeaders(f) - except UnicodeDecodeError: - #~ print("UnicodeDecodeError\n") - continue + incs = ExtractHeaders(f) #~ print("\n".join(incs)) news = set(incs) - set(masterHeaderList) - #~ print("") - #~ print("\n".join(incs)) - #~ print("") - ended = False m = 0 i = 0 while i < len(incs): -- cgit v1.2.3