diff options
Diffstat (limited to 'build_files/cmake/cmake_consistency_check.py')
-rwxr-xr-x | build_files/cmake/cmake_consistency_check.py | 186 |
1 files changed, 131 insertions, 55 deletions
diff --git a/build_files/cmake/cmake_consistency_check.py b/build_files/cmake/cmake_consistency_check.py index f55b2e95d5e..4b35e34a5cd 100755 --- a/build_files/cmake/cmake_consistency_check.py +++ b/build_files/cmake/cmake_consistency_check.py @@ -23,27 +23,31 @@ # <pep8 compliant> -IGNORE = \ - "/test/",\ - "/decimate_glut_test/",\ - "/BSP_GhostTest/",\ - "/release/",\ - "/xembed/",\ - "/decimation/intern/future/",\ - "/TerraplayNetwork/",\ - "/ik_glut_test/" +from cmake_consistency_check_config import IGNORE, UTF8_CHECK, SOURCE_DIR import os -from os.path import join, dirname, normpath, abspath, splitext +from os.path import join, dirname, normpath, splitext -base = join(os.path.dirname(__file__), "..", "..") -base = normpath(base) -base = abspath(base) - -print("Scanning:", base) +print("Scanning:", SOURCE_DIR) global_h = set() global_c = set() +global_refs = {} + + +def replace_line(f, i, text, keep_indent=True): + file_handle = open(f, 'r') + data = file_handle.readlines() + file_handle.close() + + l = data[i] + ws = l[:len(l) - len(l.lstrip())] + + data[i] = "%s%s\n" % (ws, text) + + file_handle = open(f, 'w') + file_handle.writelines(data) + file_handle.close() def source_list(path, filename_check=None): @@ -88,7 +92,20 @@ def cmake_get_src(f): found = False i = 0 # print(f) + + def is_definition(l, f, i, name): + 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)) + return True + + if ("list(APPEND %s" % name) in l or ('list(APPEND ' in l and l.endswith(name)): + if l.endswith(")"): + raise Exception("strict formatting not kept 'list(APPEND %s...)' on 1 line %s:%d" % (name, f, i)) + return True + while it is not None: + context_name = "" while it is not None: i += 1 try: @@ -98,16 +115,13 @@ def cmake_get_src(f): break l = l.strip() if not l.startswith("#"): - if 'set(SRC' in l or ('set(' in l and l.endswith("SRC")): - if len(l.split()) > 1: - raise Exception("strict formatting not kept 'set(SRC*' %s:%d" % (f, i)) - found = True + found = is_definition(l, f, i, "SRC") + if found: + context_name = "SRC" break - - if "list(APPEND SRC" in l: - if l.endswith(")"): - raise Exception("strict formatting not kept 'list(APPEND SRC...)' on 1 line %s:%d" % (f, i)) - found = True + found = is_definition(l, f, i, "INC") + if found: + context_name = "INC" break if found: @@ -136,22 +150,45 @@ def cmake_get_src(f): if not l: pass elif l.startswith("$"): - print("Cant use var '%s' %s:%d" % (l, f, i)) + if context_name == "SRC": + # assume if it ends with context_name we know about it + if not l.split("}")[0].endswith(context_name): + print("Can't use var '%s' %s:%d" % (l, f, i)) elif len(l.split()) > 1: raise Exception("Multi-line define '%s' %s:%d" % (l, f, i)) else: new_file = normpath(join(cmake_base, l)) - if is_c_header(new_file): - sources_h.append(new_file) - elif is_c(new_file): - sources_c.append(new_file) - elif l in ("PARENT_SCOPE", ): - # cmake var, ignore - pass - else: - raise Exception("unknown file type - not c or h %s -> %s" % (f, new_file)) - + if context_name == "SRC": + if is_c_header(new_file): + sources_h.append(new_file) + global_refs.setdefault(new_file, []).append((f, i)) + elif is_c(new_file): + sources_c.append(new_file) + global_refs.setdefault(new_file, []).append((f, i)) + elif l in ("PARENT_SCOPE", ): + # cmake var, ignore + pass + elif new_file.endswith(".list"): + pass + elif new_file.endswith(".def"): + pass + else: + raise Exception("unknown file type - not c or h %s -> %s" % (f, new_file)) + + elif context_name == "INC": + if os.path.isdir(new_file): + new_path_rel = os.path.relpath(new_file, cmake_base) + + 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 + # replace_line(f, i - 1, new_path_rel) + + else: + raise Exception("non existant include %s:%d -> %s" % (f, i, new_file)) + # print(new_file) global_h.update(set(sources_h)) @@ -169,11 +206,15 @@ def cmake_get_src(f): if ff not in sources_c: print(" missing: " + ff) ''' + + # reset + sources_h[:] = [] + sources_c[:] = [] filen.close() -for cmake in source_list(base, is_cmake): +for cmake in source_list(SOURCE_DIR, is_cmake): cmake_get_src(cmake) @@ -183,39 +224,74 @@ def is_ignore(f): 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): - raise Exception("CMake referenced file missing: " + 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(base, is_c)): +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(base, is_c_header)): +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) -# 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() +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() |