[Bf-blender-cvs] [c6df7266c71] master: CMake: move cmake_consistency_check.py into source/tools/ repo

Campbell Barton noreply at git.blender.org
Wed Feb 23 02:33:08 CET 2022


Commit: c6df7266c718555cde5a729dae1c6023ef2b3530
Author: Campbell Barton
Date:   Wed Feb 23 12:30:59 2022 +1100
Branches: master
https://developer.blender.org/rBc6df7266c718555cde5a729dae1c6023ef2b3530

CMake: move cmake_consistency_check.py into source/tools/ repo

This isn't needed for building Blender so move this along side
other source checking scripts.

===================================================================

M	GNUmakefile
D	build_files/cmake/cmake_consistency_check.py
D	build_files/cmake/cmake_consistency_check_config.py

===================================================================

diff --git a/GNUmakefile b/GNUmakefile
index a410662647e..575f3e904df 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -489,7 +489,7 @@ check_pep8: .FORCE
 
 check_cmake: .FORCE
 	@PYTHONIOENCODING=utf_8 $(PYTHON) \
-	    build_files/cmake/cmake_consistency_check.py
+	    source/tools/check_source/check_cmake_consistency.py
 
 
 # -----------------------------------------------------------------------------
diff --git a/build_files/cmake/cmake_consistency_check.py b/build_files/cmake/cmake_consistency_check.py
deleted file mode 100755
index ec31b4cdfe3..00000000000
--- a/build_files/cmake/cmake_consistency_check.py
+++ /dev/null
@@ -1,387 +0,0 @@
-#!/usr/bin/env python3
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-# <pep8 compliant>
-
-# Note: this code should be cleaned up / refactored.
-
-import sys
-if sys.version_info.major < 3:
-    print("\nPython3.x needed, found %s.\nAborting!\n" %
-          sys.version.partition(" ")[0])
-    sys.exit(1)
-
-import os
-from os.path import (
-    dirname,
-    join,
-    normpath,
-    splitext,
-)
-
-from cmake_consistency_check_config import (
-    IGNORE_SOURCE,
-    IGNORE_SOURCE_MISSING,
-    IGNORE_CMAKE,
-    UTF8_CHECK,
-    SOURCE_DIR,
-    BUILD_DIR,
-)
-
-from typing import (
-    Callable,
-    Dict,
-    Generator,
-    Iterator,
-    List,
-    Optional,
-    Tuple,
-)
-
-
-global_h = set()
-global_c = set()
-global_refs: Dict[str, List[Tuple[str, int]]] = {}
-
-# Flatten `IGNORE_SOURCE_MISSING` to avoid nested looping.
-IGNORE_SOURCE_MISSING_FLAT = [
-    (k, ignore_path) for k, ig_list in IGNORE_SOURCE_MISSING
-    for ignore_path in ig_list
-]
-
-# Ignore cmake file, path pairs.
-global_ignore_source_missing: Dict[str, List[str]] = {}
-for k, v in IGNORE_SOURCE_MISSING_FLAT:
-    global_ignore_source_missing.setdefault(k, []).append(v)
-del IGNORE_SOURCE_MISSING_FLAT
-
-
-def replace_line(f: str, i: int, text: str, keep_indent: bool = True) -> None:
-    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: str,
-        filename_check: Optional[Callable[[str], bool]] = None,
-) -> Generator[str, None, None]:
-    for dirpath, dirnames, filenames in os.walk(path):
-        # skip '.git'
-        dirnames[:] = [d for d in dirnames if not d.startswith(".")]
-
-        for filename in filenames:
-            if filename_check is None or filename_check(filename):
-                yield os.path.join(dirpath, filename)
-
-
-# extension checking
-def is_cmake(filename: str) -> bool:
-    ext = splitext(filename)[1]
-    return (ext == ".cmake") or (filename == "CMakeLists.txt")
-
-
-def is_c_header(filename: str) -> bool:
-    ext = splitext(filename)[1]
-    return (ext in {".h", ".hpp", ".hxx", ".hh"})
-
-
-def is_c(filename: str) -> bool:
-    ext = splitext(filename)[1]
-    return (ext in {".c", ".cpp", ".cxx", ".m", ".mm", ".rc", ".cc", ".inl", ".metal"})
-
-
-def is_c_any(filename: str) -> bool:
-    return is_c(filename) or is_c_header(filename)
-
-
-def cmake_get_src(f: str) -> None:
-
-    sources_h = []
-    sources_c = []
-
-    filen = open(f, "r", encoding="utf8")
-    it: Optional[Iterator[str]] = iter(filen)
-    found = False
-    i = 0
-    # print(f)
-
-    def is_definition(l: str, f: str, i: int, name: str) -> bool:
-        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))
-            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
-        return False
-
-    while it is not None:
-        context_name = ""
-        while it is not None:
-            i += 1
-            try:
-                l = next(it)
-            except StopIteration:
-                it = None
-                break
-            l = l.strip()
-            if not l.startswith("#"):
-                found = is_definition(l, f, i, "SRC")
-                if found:
-                    context_name = "SRC"
-                    break
-                found = is_definition(l, f, i, "INC")
-                if found:
-                    context_name = "INC"
-                    break
-
-        if found:
-            cmake_base = dirname(f)
-            cmake_base_bin = os.path.join(BUILD_DIR, os.path.relpath(cmake_base, SOURCE_DIR))
-
-            # Find known missing sources list (if we have one).
-            f_rel = os.path.relpath(f, SOURCE_DIR)
-            f_rel_key = f_rel
-            if os.sep != "/":
-                f_rel_key = f_rel_key.replace(os.sep, "/")
-            local_ignore_source_missing = global_ignore_source_missing.get(f_rel_key, [])
-
-            while it is not None:
-                i += 1
-                try:
-                    l = next(it)
-                except StopIteration:
-                    it = None
-                    break
-
-                l = l.strip()
-
-                if not l.startswith("#"):
-
-                    # Remove in-line comments.
-                    l = l.split(" # ")[0].rstrip()
-
-                    if ")" in l:
-                        if l.strip() != ")":
-                            raise Exception("strict formatting not kept '*)' %s:%d" % (f, i))
-                        break
-
-                    # replace dirs
-                    l = l.replace("${CMAKE_SOURCE_DIR}", SOURCE_DIR)
-                    l = l.replace("${CMAKE_CURRENT_SOURCE_DIR}", cmake_base)
-                    l = l.replace("${CMAKE_CURRENT_BINARY_DIR}", cmake_base_bin)
-                    l = l.strip('"')
-
-                    if not l:
-                        pass
-                    elif l in local_ignore_source_missing:
-                        local_ignore_source_missing.remove(l)
-                    elif l.startswith("$"):
-                        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 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
-                            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))
-
-                        elif context_name == "INC":
-                            if new_file.startswith(BUILD_DIR):
-                                # assume generated path
-                                pass
-                            elif 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 existent include %s:%d -> %s" % (f, i, new_file))
-
-                        # print(new_file)
-
-            global_h.update(set(sources_h))
-            global_c.update(set(sources_c))
-            '''
-            if not sources_h and not sources_c:
-                raise Exception("No sources %s" % f)
-
-            sources_h_fs = list(source_list(cmake_base, is_c_header))
-            sources_c_fs = list(source_list(cmake_base, is_c))
-            '''
-            # find missing C files:
-            '''
-            for ff in sources_c_fs:
-                if ff not in sources_c:
-                    print("  missing: " + ff)
-            '''
-
-            # reset
-            del sources_h[:]
-            del sources_c[:]
-
-    filen.close()
-
-
-def is_ignore_source(f: str, ignore_used: List[bool]) -> bool:
-    for index, ignore_path in enumerate(IGNORE_SOURCE):
-        if ignore_path in f:
-            ignore_used[index] = True
-            return True
-    return False
-
-
-def is_ignore_cmake(f: str, ignore_used: List[bool]) -> bool:
-    for index, ignore_path in enumerate(IGNORE_CMAKE):
-        if ignore_path in f:
-            ignore_used[index] = True
-            return True
-    return False
-
-
-def main() -> No

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list