Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'build_files/cmake/cmake_consistency_check.py')
-rwxr-xr-xbuild_files/cmake/cmake_consistency_check.py63
1 files changed, 39 insertions, 24 deletions
diff --git a/build_files/cmake/cmake_consistency_check.py b/build_files/cmake/cmake_consistency_check.py
index c613d4d799b..c62e5fc0b59 100755
--- a/build_files/cmake/cmake_consistency_check.py
+++ b/build_files/cmake/cmake_consistency_check.py
@@ -28,6 +28,14 @@ if sys.version_info.major < 3:
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,
@@ -37,32 +45,35 @@ from cmake_consistency_check_config import (
BUILD_DIR,
)
-
-import os
-from os.path import (
- dirname,
- join,
- normpath,
- splitext,
+from typing import (
+ Callable,
+ Dict,
+ Generator,
+ Iterator,
+ List,
+ Optional,
+ Tuple,
)
+
global_h = set()
global_c = set()
-global_refs = {}
+global_refs: Dict[str, List[Tuple[str, int]]] = {}
# Flatten `IGNORE_SOURCE_MISSING` to avoid nested looping.
-IGNORE_SOURCE_MISSING = [
+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 = {}
-for k, v in IGNORE_SOURCE_MISSING:
+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, i, text, keep_indent=True):
+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()
@@ -77,7 +88,10 @@ def replace_line(f, i, text, keep_indent=True):
file_handle.close()
-def source_list(path, filename_check=None):
+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(".")]
@@ -88,37 +102,37 @@ def source_list(path, filename_check=None):
# extension checking
-def is_cmake(filename):
+def is_cmake(filename: str) -> bool:
ext = splitext(filename)[1]
return (ext == ".cmake") or (filename == "CMakeLists.txt")
-def is_c_header(filename):
+def is_c_header(filename: str) -> bool:
ext = splitext(filename)[1]
return (ext in {".h", ".hpp", ".hxx", ".hh"})
-def is_c(filename):
+def is_c(filename: str) -> bool:
ext = splitext(filename)[1]
return (ext in {".c", ".cpp", ".cxx", ".m", ".mm", ".rc", ".cc", ".inl"})
-def is_c_any(filename):
+def is_c_any(filename: str) -> bool:
return is_c(filename) or is_c_header(filename)
-def cmake_get_src(f):
+def cmake_get_src(f: str) -> None:
sources_h = []
sources_c = []
filen = open(f, "r", encoding="utf8")
- it = iter(filen)
+ it: Optional[Iterator[str]] = iter(filen)
found = False
i = 0
# print(f)
- def is_definition(l, f, i, name):
+ def is_definition(l: str, f: str, i: int, name: str) -> bool:
if l.startswith("unset("):
return False
@@ -131,6 +145,7 @@ def cmake_get_src(f):
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 = ""
@@ -269,7 +284,7 @@ def cmake_get_src(f):
filen.close()
-def is_ignore_source(f, ignore_used):
+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
@@ -277,7 +292,7 @@ def is_ignore_source(f, ignore_used):
return False
-def is_ignore_cmake(f, ignore_used):
+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
@@ -285,7 +300,7 @@ def is_ignore_cmake(f, ignore_used):
return False
-def main():
+def main() -> None:
print("Scanning:", SOURCE_DIR)
@@ -359,7 +374,7 @@ def main():
if "extern" not in f:
i = 1
try:
- for l in open(f, "r", encoding="utf8"):
+ for _ in open(f, "r", encoding="utf8"):
i += 1
except UnicodeDecodeError:
print("Non utf8: %s:%d" % (f, i))