summaryrefslogtreecommitdiffstats
path: root/CMakeScripts
diff options
context:
space:
mode:
Diffstat (limited to 'CMakeScripts')
-rwxr-xr-xCMakeScripts/cmake_consistency_check.py212
1 files changed, 123 insertions, 89 deletions
diff --git a/CMakeScripts/cmake_consistency_check.py b/CMakeScripts/cmake_consistency_check.py
index 53026910e..64419936b 100755
--- a/CMakeScripts/cmake_consistency_check.py
+++ b/CMakeScripts/cmake_consistency_check.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# $Id: cmake_consistency_check.py 38869 2011-07-31 03:15:37Z campbellbarton $
# ***** BEGIN GPL LICENSE BLOCK *****
@@ -23,13 +23,22 @@
# <pep8 compliant>
-from cmake_consistency_check_config import IGNORE, UTF8_CHECK, SOURCE_DIR
+import sys
+if not sys.version.startswith("3"):
+ print("\nPython3.x needed, found %s.\nAborting!\n" %
+ sys.version.partition(" ")[0])
+ sys.exit(1)
+
+from cmake_consistency_check_config import (
+ IGNORE,
+ UTF8_CHECK,
+ SOURCE_DIR,
+)
+
import os
from os.path import join, dirname, normpath, splitext
-print("Scanning:", SOURCE_DIR)
-
global_h = set()
global_c = set()
global_refs = {}
@@ -53,7 +62,7 @@ def replace_line(f, i, text, keep_indent=True):
def source_list(path, filename_check=None):
for dirpath, dirnames, filenames in os.walk(path):
- # skip '.svn'
+ # skip '.bzr'
if dirpath.startswith("."):
continue
@@ -70,12 +79,12 @@ def is_cmake(filename):
def is_c_header(filename):
ext = splitext(filename)[1]
- return (ext in (".h", ".hpp", ".hxx"))
+ return (ext in {".h", ".hpp", ".hxx", ".hh"})
def is_c(filename):
ext = splitext(filename)[1]
- return (ext in (".c", ".cpp", ".cxx", ".m", ".mm", ".rc"))
+ return (ext in {".c", ".cpp", ".cxx", ".m", ".mm", ".rc", ".cc", ".inl"})
def is_c_any(filename):
@@ -87,13 +96,16 @@ def cmake_get_src(f):
sources_h = []
sources_c = []
- filen = open(f, "r")
+ filen = open(f, "r", encoding="utf8")
it = iter(filen)
found = False
i = 0
# print(f)
def is_definition(l, f, i, name):
+ if l.startswith("unset("):
+ return False
+
if ('set(%s' % name) in l or ('set(' in l and l.endswith(name)):
if len(l.split()) > 1:
raise Exception("strict formatting not kept 'set(%s*' %s:%d" % (name, f, i))
@@ -146,6 +158,7 @@ def cmake_get_src(f):
# replace dirs
l = l.replace("${CMAKE_CURRENT_SOURCE_DIR}", cmake_base)
+ l = l.strip('"')
if not l:
pass
@@ -166,13 +179,21 @@ def cmake_get_src(f):
elif is_c(new_file):
sources_c.append(new_file)
global_refs.setdefault(new_file, []).append((f, i))
- elif l in ("PARENT_SCOPE", ):
+ elif l in {"PARENT_SCOPE", }:
# cmake var, ignore
pass
elif new_file.endswith(".list"):
pass
elif new_file.endswith(".def"):
pass
+ elif new_file.endswith(".cl"): # opencl
+ pass
+ elif new_file.endswith(".cu"): # cuda
+ pass
+ elif new_file.endswith(".osl"): # open shading language
+ pass
+ elif new_file.endswith(".glsl"):
+ pass
else:
raise Exception("unknown file type - not c or h %s -> %s" % (f, new_file))
@@ -183,11 +204,11 @@ def cmake_get_src(f):
if new_path_rel != l:
print("overly relative path:\n %s:%d\n %s\n %s" % (f, i, l, new_path_rel))
- ## Save time. just replace the line
+ # # Save time. just replace the line
# replace_line(f, i - 1, new_path_rel)
else:
- raise Exception("non existant include %s:%d -> %s" % (f, i, new_file))
+ raise Exception("non existent include %s:%d -> %s" % (f, i, new_file))
# print(new_file)
@@ -208,90 +229,103 @@ def cmake_get_src(f):
'''
# reset
- sources_h[:] = []
- sources_c[:] = []
+ del sources_h[:]
+ del sources_c[:]
filen.close()
-for cmake in source_list(SOURCE_DIR, is_cmake):
- cmake_get_src(cmake)
-
-
-def is_ignore(f):
- for ig in IGNORE:
+def is_ignore(f, ignore_used):
+ for index, ig in enumerate(IGNORE):
if ig in f:
+ ignore_used[index] = True
return True
return False
-# First do stupid check, do these files exist?
-print("\nChecking for missing references:")
-is_err = False
-errs = []
-for f in (global_h | global_c):
- if f.endswith("dna.c"):
- continue
-
- if not os.path.exists(f):
- refs = global_refs[f]
- if refs:
- for cf, i in refs:
- errs.append((cf, i))
- else:
- raise Exception("CMake referenecs missing, internal error, aborting!")
- is_err = True
-
-errs.sort()
-errs.reverse()
-for cf, i in errs:
- print("%s:%d" % (cf, i))
- # Write a 'sed' script, useful if we get a lot of these
- # print("sed '%dd' '%s' > '%s.tmp' ; mv '%s.tmp' '%s'" % (i, cf, cf, cf, cf))
-
-
-if is_err:
- raise Exception("CMake referenecs missing files, aborting!")
-del is_err
-del errs
-
-# now check on files not accounted for.
-print("\nC/C++ Files CMake doesnt know about...")
-for cf in sorted(source_list(SOURCE_DIR, is_c)):
- if not is_ignore(cf):
- if cf not in global_c:
- print("missing_c: ", cf)
-
- # check if automake builds a corrasponding .o file.
- '''
- if cf in global_c:
- out1 = os.path.splitext(cf)[0] + ".o"
- out2 = os.path.splitext(cf)[0] + ".Po"
- out2_dir, out2_file = out2 = os.path.split(out2)
- out2 = os.path.join(out2_dir, ".deps", out2_file)
- if not os.path.exists(out1) and not os.path.exists(out2):
- print("bad_c: ", cf)
- '''
-
-print("\nC/C++ Headers CMake doesnt know about...")
-for hf in sorted(source_list(SOURCE_DIR, is_c_header)):
- if not is_ignore(hf):
- if hf not in global_h:
- print("missing_h: ", hf)
-
-if UTF8_CHECK:
- # test encoding
- import traceback
- for files in (global_c, global_h):
- for f in sorted(files):
- if os.path.exists(f):
- # ignore outside of our source tree
- if "extern" not in f:
- i = 1
- try:
- for l in open(f, "r", encoding="utf8"):
- i += 1
- except:
- print("Non utf8: %s:%d" % (f, i))
- if i > 1:
- traceback.print_exc()
+def main():
+
+ print("Scanning:", SOURCE_DIR)
+
+ for cmake in source_list(SOURCE_DIR, is_cmake):
+ cmake_get_src(cmake)
+
+ # First do stupid check, do these files exist?
+ print("\nChecking for missing references:")
+ is_err = False
+ errs = []
+ for f in (global_h | global_c):
+
+ if not os.path.exists(f):
+ refs = global_refs[f]
+ if refs:
+ for cf, i in refs:
+ errs.append((cf, i))
+ else:
+ raise Exception("CMake referenecs missing, internal error, aborting!")
+ is_err = True
+
+ errs.sort()
+ errs.reverse()
+ for cf, i in errs:
+ print("%s:%d" % (cf, i))
+ # Write a 'sed' script, useful if we get a lot of these
+ # print("sed '%dd' '%s' > '%s.tmp' ; mv '%s.tmp' '%s'" % (i, cf, cf, cf, cf))
+
+ if is_err:
+ raise Exception("CMake referenecs missing files, aborting!")
+ del is_err
+ del errs
+
+ ignore_used = [False] * len(IGNORE)
+
+ # now check on files not accounted for.
+ print("\nC/C++ Files CMake doesnt know about...")
+ for cf in sorted(source_list(SOURCE_DIR, is_c)):
+ if not is_ignore(cf, ignore_used):
+ if cf not in global_c:
+ print("missing_c: ", cf)
+
+ # check if automake builds a corrasponding .o file.
+ '''
+ if cf in global_c:
+ out1 = os.path.splitext(cf)[0] + ".o"
+ out2 = os.path.splitext(cf)[0] + ".Po"
+ out2_dir, out2_file = out2 = os.path.split(out2)
+ out2 = os.path.join(out2_dir, ".deps", out2_file)
+ if not os.path.exists(out1) and not os.path.exists(out2):
+ print("bad_c: ", cf)
+ '''
+
+ print("\nC/C++ Headers CMake doesnt know about...")
+ for hf in sorted(source_list(SOURCE_DIR, is_c_header)):
+ if not is_ignore(hf, ignore_used):
+ if hf not in global_h:
+ print("missing_h: ", hf)
+
+ if UTF8_CHECK:
+ # test encoding
+ import traceback
+ for files in (global_c, global_h):
+ for f in sorted(files):
+ if os.path.exists(f):
+ # ignore outside of our source tree
+ if "extern" not in f:
+ i = 1
+ try:
+ for l in open(f, "r", encoding="utf8"):
+ i += 1
+ except UnicodeDecodeError:
+ print("Non utf8: %s:%d" % (f, i))
+ if i > 1:
+ traceback.print_exc()
+
+ # Check ignores aren't stale
+ print("\nCheck for unused 'IGNORE' paths...")
+ for index, ig in enumerate(IGNORE):
+ if not ignore_used[index]:
+ print("unused ignore: %r" % ig)
+
+
+if __name__ == "__main__":
+ main()