| 
									
										
										
										
											2012-11-26 13:58:06 +00:00
										 |  |  | #!/usr/bin/env python3 | 
					
						
							| 
									
										
										
										
											2010-12-16 21:32:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  | # ***** BEGIN GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  | # modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  | # as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  | # of the License, or (at your option) any later version. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | # GNU General Public License for more details. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | # along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # ***** END GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-04 09:27:25 +00:00
										 |  |  | # <pep8 compliant> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-20 15:58:07 +11:00
										 |  |  | # Note: this code should be cleaned up / refactored. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-19 00:01:10 +00:00
										 |  |  | import sys | 
					
						
							| 
									
										
										
										
											2020-09-07 22:58:16 +10:00
										 |  |  | if sys.version_info.major < 3: | 
					
						
							| 
									
										
										
										
											2011-11-19 00:01:10 +00:00
										 |  |  |     print("\nPython3.x needed, found %s.\nAborting!\n" % | 
					
						
							|  |  |  |           sys.version.partition(" ")[0]) | 
					
						
							|  |  |  |     sys.exit(1) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-12 12:19:27 +10:00
										 |  |  | import os | 
					
						
							|  |  |  | from os.path import ( | 
					
						
							|  |  |  |     dirname, | 
					
						
							|  |  |  |     join, | 
					
						
							|  |  |  |     normpath, | 
					
						
							|  |  |  |     splitext, | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-17 16:05:38 +10:00
										 |  |  | from cmake_consistency_check_config import ( | 
					
						
							| 
									
										
										
										
											2018-11-29 08:49:50 +11:00
										 |  |  |     IGNORE_SOURCE, | 
					
						
							| 
									
										
										
										
											2019-10-29 03:41:34 +11:00
										 |  |  |     IGNORE_SOURCE_MISSING, | 
					
						
							| 
									
										
										
										
											2018-11-29 08:49:50 +11:00
										 |  |  |     IGNORE_CMAKE, | 
					
						
							| 
									
										
										
										
											2016-07-30 18:15:16 +10:00
										 |  |  |     UTF8_CHECK, | 
					
						
							|  |  |  |     SOURCE_DIR, | 
					
						
							|  |  |  |     BUILD_DIR, | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2015-05-17 16:05:38 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-12 12:19:27 +10:00
										 |  |  | from typing import ( | 
					
						
							|  |  |  |     Callable, | 
					
						
							|  |  |  |     Dict, | 
					
						
							|  |  |  |     Generator, | 
					
						
							| 
									
										
										
										
											2021-04-13 21:12:17 +10:00
										 |  |  |     Iterator, | 
					
						
							| 
									
										
										
										
											2021-04-12 12:19:27 +10:00
										 |  |  |     List, | 
					
						
							|  |  |  |     Optional, | 
					
						
							|  |  |  |     Tuple, | 
					
						
							| 
									
										
										
										
											2021-01-20 15:58:07 +11:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-12 12:19:27 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  | global_h = set() | 
					
						
							|  |  |  | global_c = set() | 
					
						
							| 
									
										
										
										
											2021-04-12 12:19:27 +10:00
										 |  |  | global_refs: Dict[str, List[Tuple[str, int]]] = {} | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-20 15:53:51 +11:00
										 |  |  | # Flatten `IGNORE_SOURCE_MISSING` to avoid nested looping. | 
					
						
							| 
									
										
										
										
											2021-04-12 12:19:27 +10:00
										 |  |  | IGNORE_SOURCE_MISSING_FLAT = [ | 
					
						
							| 
									
										
										
										
											2021-01-20 15:58:07 +11:00
										 |  |  |     (k, ignore_path) for k, ig_list in IGNORE_SOURCE_MISSING | 
					
						
							|  |  |  |     for ignore_path in ig_list | 
					
						
							| 
									
										
										
										
											2021-01-20 15:53:51 +11:00
										 |  |  | ] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-29 03:41:34 +11:00
										 |  |  | # Ignore cmake file, path pairs. | 
					
						
							| 
									
										
										
										
											2021-04-12 12:19:27 +10:00
										 |  |  | global_ignore_source_missing: Dict[str, List[str]] = {} | 
					
						
							|  |  |  | for k, v in IGNORE_SOURCE_MISSING_FLAT: | 
					
						
							| 
									
										
										
										
											2019-10-29 03:41:34 +11:00
										 |  |  |     global_ignore_source_missing.setdefault(k, []).append(v) | 
					
						
							| 
									
										
										
										
											2021-04-12 12:19:27 +10:00
										 |  |  | del IGNORE_SOURCE_MISSING_FLAT | 
					
						
							| 
									
										
										
										
											2019-10-29 03:41:34 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-04 09:27:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-12 12:19:27 +10:00
										 |  |  | def replace_line(f: str, i: int, text: str, keep_indent: bool = True) -> None: | 
					
						
							| 
									
										
										
										
											2011-07-17 12:42:03 +00:00
										 |  |  |     file_handle = open(f, 'r') | 
					
						
							|  |  |  |     data = file_handle.readlines() | 
					
						
							|  |  |  |     file_handle.close() | 
					
						
							| 
									
										
										
										
											2011-07-31 03:15:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-17 12:42:03 +00:00
										 |  |  |     l = data[i] | 
					
						
							|  |  |  |     ws = l[:len(l) - len(l.lstrip())] | 
					
						
							| 
									
										
										
										
											2011-07-29 01:24:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-17 12:42:03 +00:00
										 |  |  |     data[i] = "%s%s\n" % (ws, text) | 
					
						
							| 
									
										
										
										
											2011-07-29 01:24:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-17 12:42:03 +00:00
										 |  |  |     file_handle = open(f, 'w') | 
					
						
							|  |  |  |     file_handle.writelines(data) | 
					
						
							|  |  |  |     file_handle.close() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-12 12:19:27 +10:00
										 |  |  | def source_list( | 
					
						
							|  |  |  |         path: str, | 
					
						
							|  |  |  |         filename_check: Optional[Callable[[str], bool]] = None, | 
					
						
							|  |  |  | ) -> Generator[str, None, None]: | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  |     for dirpath, dirnames, filenames in os.walk(path): | 
					
						
							| 
									
										
										
										
											2014-01-28 23:00:28 +11:00
										 |  |  |         # skip '.git' | 
					
						
							| 
									
										
										
										
											2017-08-23 15:36:39 +10:00
										 |  |  |         dirnames[:] = [d for d in dirnames if not d.startswith(".")] | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for filename in filenames: | 
					
						
							|  |  |  |             if filename_check is None or filename_check(filename): | 
					
						
							|  |  |  |                 yield os.path.join(dirpath, filename) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-04 09:27:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  | # extension checking | 
					
						
							| 
									
										
										
										
											2021-04-12 12:19:27 +10:00
										 |  |  | def is_cmake(filename: str) -> bool: | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  |     ext = splitext(filename)[1] | 
					
						
							|  |  |  |     return (ext == ".cmake") or (filename == "CMakeLists.txt") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-04 09:27:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-12 12:19:27 +10:00
										 |  |  | def is_c_header(filename: str) -> bool: | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  |     ext = splitext(filename)[1] | 
					
						
							| 
									
										
										
										
											2012-12-31 07:06:51 +00:00
										 |  |  |     return (ext in {".h", ".hpp", ".hxx", ".hh"}) | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-04 09:27:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-12 12:19:27 +10:00
										 |  |  | def is_c(filename: str) -> bool: | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  |     ext = splitext(filename)[1] | 
					
						
							| 
									
										
										
										
											2012-12-31 07:06:51 +00:00
										 |  |  |     return (ext in {".c", ".cpp", ".cxx", ".m", ".mm", ".rc", ".cc", ".inl"}) | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-04 09:27:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-12 12:19:27 +10:00
										 |  |  | def is_c_any(filename: str) -> bool: | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  |     return is_c(filename) or is_c_header(filename) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-04 09:27:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-12 12:19:27 +10:00
										 |  |  | def cmake_get_src(f: str) -> None: | 
					
						
							| 
									
										
										
										
											2011-02-04 09:27:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  |     sources_h = [] | 
					
						
							|  |  |  |     sources_c = [] | 
					
						
							| 
									
										
										
										
											2011-02-04 09:27:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-14 08:35:56 +00:00
										 |  |  |     filen = open(f, "r", encoding="utf8") | 
					
						
							| 
									
										
										
										
											2021-04-12 12:19:27 +10:00
										 |  |  |     it: Optional[Iterator[str]] = iter(filen) | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  |     found = False | 
					
						
							|  |  |  |     i = 0 | 
					
						
							|  |  |  |     # print(f) | 
					
						
							| 
									
										
										
										
											2011-07-17 12:42:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-12 12:19:27 +10:00
										 |  |  |     def is_definition(l: str, f: str, i: int, name: str) -> bool: | 
					
						
							| 
									
										
										
										
											2011-11-10 06:05:22 +00:00
										 |  |  |         if l.startswith("unset("): | 
					
						
							|  |  |  |             return False | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-17 12:42:03 +00:00
										 |  |  |         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 | 
					
						
							| 
									
										
										
										
											2021-04-12 12:19:27 +10:00
										 |  |  |         return False | 
					
						
							| 
									
										
										
										
											2011-07-17 12:42:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  |     while it is not None: | 
					
						
							| 
									
										
										
										
											2011-07-17 12:42:03 +00:00
										 |  |  |         context_name = "" | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  |         while it is not None: | 
					
						
							|  |  |  |             i += 1 | 
					
						
							|  |  |  |             try: | 
					
						
							|  |  |  |                 l = next(it) | 
					
						
							|  |  |  |             except StopIteration: | 
					
						
							|  |  |  |                 it = None | 
					
						
							|  |  |  |                 break | 
					
						
							|  |  |  |             l = l.strip() | 
					
						
							|  |  |  |             if not l.startswith("#"): | 
					
						
							| 
									
										
										
										
											2011-07-17 12:42:03 +00:00
										 |  |  |                 found = is_definition(l, f, i, "SRC") | 
					
						
							|  |  |  |                 if found: | 
					
						
							|  |  |  |                     context_name = "SRC" | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  |                     break | 
					
						
							| 
									
										
										
										
											2011-07-17 12:42:03 +00:00
										 |  |  |                 found = is_definition(l, f, i, "INC") | 
					
						
							|  |  |  |                 if found: | 
					
						
							|  |  |  |                     context_name = "INC" | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  |                     break | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if found: | 
					
						
							|  |  |  |             cmake_base = dirname(f) | 
					
						
							| 
									
										
										
										
											2015-05-17 16:05:38 +10:00
										 |  |  |             cmake_base_bin = os.path.join(BUILD_DIR, os.path.relpath(cmake_base, SOURCE_DIR)) | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-29 03:41:34 +11:00
										 |  |  |             # 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, []) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  |             while it is not None: | 
					
						
							|  |  |  |                 i += 1 | 
					
						
							|  |  |  |                 try: | 
					
						
							|  |  |  |                     l = next(it) | 
					
						
							|  |  |  |                 except StopIteration: | 
					
						
							|  |  |  |                     it = None | 
					
						
							|  |  |  |                     break | 
					
						
							| 
									
										
										
										
											2011-02-04 09:27:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  |                 l = l.strip() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if not l.startswith("#"): | 
					
						
							| 
									
										
										
										
											2011-02-04 09:27:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-29 01:32:33 +11:00
										 |  |  |                     # Remove in-line comments. | 
					
						
							|  |  |  |                     l = l.split(" # ")[0].rstrip() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  |                     if ")" in l: | 
					
						
							|  |  |  |                         if l.strip() != ")": | 
					
						
							|  |  |  |                             raise Exception("strict formatting not kept '*)' %s:%d" % (f, i)) | 
					
						
							|  |  |  |                         break | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-25 08:35:10 +00:00
										 |  |  |                     # replace dirs | 
					
						
							| 
									
										
										
										
											2018-11-29 08:49:50 +11:00
										 |  |  |                     l = l.replace("${CMAKE_SOURCE_DIR}", SOURCE_DIR) | 
					
						
							| 
									
										
										
										
											2011-01-25 08:35:10 +00:00
										 |  |  |                     l = l.replace("${CMAKE_CURRENT_SOURCE_DIR}", cmake_base) | 
					
						
							| 
									
										
										
										
											2015-05-17 16:05:38 +10:00
										 |  |  |                     l = l.replace("${CMAKE_CURRENT_BINARY_DIR}", cmake_base_bin) | 
					
						
							|  |  |  |                     l = l.strip('"') | 
					
						
							| 
									
										
										
										
											2011-01-25 08:35:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  |                     if not l: | 
					
						
							|  |  |  |                         pass | 
					
						
							| 
									
										
										
										
											2021-01-20 15:53:51 +11:00
										 |  |  |                     elif l in local_ignore_source_missing: | 
					
						
							|  |  |  |                         local_ignore_source_missing.remove(l) | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  |                     elif l.startswith("$"): | 
					
						
							| 
									
										
										
										
											2011-07-17 12:42:03 +00:00
										 |  |  |                         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)) | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  |                     elif len(l.split()) > 1: | 
					
						
							|  |  |  |                         raise Exception("Multi-line define '%s' %s:%d" % (l, f, i)) | 
					
						
							|  |  |  |                     else: | 
					
						
							|  |  |  |                         new_file = normpath(join(cmake_base, l)) | 
					
						
							| 
									
										
										
										
											2011-02-04 09:27:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-17 12:42:03 +00:00
										 |  |  |                         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)) | 
					
						
							| 
									
										
										
										
											2014-09-18 17:45:31 +10:00
										 |  |  |                             elif l in {"PARENT_SCOPE", }: | 
					
						
							| 
									
										
										
										
											2011-07-17 12:42:03 +00:00
										 |  |  |                                 # cmake var, ignore | 
					
						
							|  |  |  |                                 pass | 
					
						
							|  |  |  |                             elif new_file.endswith(".list"): | 
					
						
							|  |  |  |                                 pass | 
					
						
							|  |  |  |                             elif new_file.endswith(".def"): | 
					
						
							|  |  |  |                                 pass | 
					
						
							| 
									
										
										
										
											2011-11-08 20:27:37 +00:00
										 |  |  |                             elif new_file.endswith(".cl"):  # opencl | 
					
						
							|  |  |  |                                 pass | 
					
						
							|  |  |  |                             elif new_file.endswith(".cu"):  # cuda | 
					
						
							|  |  |  |                                 pass | 
					
						
							|  |  |  |                             elif new_file.endswith(".osl"):  # open shading language | 
					
						
							|  |  |  |                                 pass | 
					
						
							| 
									
										
										
										
											2015-02-13 16:09:24 +11:00
										 |  |  |                             elif new_file.endswith(".glsl"): | 
					
						
							|  |  |  |                                 pass | 
					
						
							| 
									
										
										
										
											2011-07-17 12:42:03 +00:00
										 |  |  |                             else: | 
					
						
							|  |  |  |                                 raise Exception("unknown file type - not c or h %s -> %s" % (f, new_file)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                         elif context_name == "INC": | 
					
						
							| 
									
										
										
										
											2015-05-17 16:05:38 +10:00
										 |  |  |                             if new_file.startswith(BUILD_DIR): | 
					
						
							|  |  |  |                                 # assume generated path | 
					
						
							|  |  |  |                                 pass | 
					
						
							|  |  |  |                             elif os.path.isdir(new_file): | 
					
						
							| 
									
										
										
										
											2011-07-17 12:42:03 +00:00
										 |  |  |                                 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)) | 
					
						
							| 
									
										
										
										
											2011-07-29 01:24:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-07 13:54:13 +10:00
										 |  |  |                                     # # Save time. just replace the line | 
					
						
							| 
									
										
										
										
											2011-07-17 12:42:03 +00:00
										 |  |  |                                     # replace_line(f, i - 1, new_path_rel) | 
					
						
							| 
									
										
										
										
											2011-07-29 01:24:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-17 12:42:03 +00:00
										 |  |  |                             else: | 
					
						
							| 
									
										
										
										
											2021-01-20 15:53:51 +11:00
										 |  |  |                                 raise Exception("non existent include %s:%d -> %s" % (f, i, new_file)) | 
					
						
							| 
									
										
										
										
											2011-07-29 01:24:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  |                         # 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) | 
					
						
							|  |  |  |             '''
 | 
					
						
							| 
									
										
										
										
											2011-07-29 01:24:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-17 12:42:03 +00:00
										 |  |  |             # reset | 
					
						
							| 
									
										
										
										
											2012-11-14 09:45:15 +00:00
										 |  |  |             del sources_h[:] | 
					
						
							|  |  |  |             del sources_c[:] | 
					
						
							| 
									
										
										
										
											2011-02-04 09:27:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  |     filen.close() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-12 12:19:27 +10:00
										 |  |  | def is_ignore_source(f: str, ignore_used: List[bool]) -> bool: | 
					
						
							| 
									
										
										
										
											2021-01-20 15:58:07 +11:00
										 |  |  |     for index, ignore_path in enumerate(IGNORE_SOURCE): | 
					
						
							|  |  |  |         if ignore_path in f: | 
					
						
							| 
									
										
										
										
											2018-11-29 08:49:50 +11:00
										 |  |  |             ignore_used[index] = True | 
					
						
							|  |  |  |             return True | 
					
						
							|  |  |  |     return False | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-12 12:19:27 +10:00
										 |  |  | def is_ignore_cmake(f: str, ignore_used: List[bool]) -> bool: | 
					
						
							| 
									
										
										
										
											2021-01-20 15:58:07 +11:00
										 |  |  |     for index, ignore_path in enumerate(IGNORE_CMAKE): | 
					
						
							|  |  |  |         if ignore_path in f: | 
					
						
							| 
									
										
										
										
											2016-04-12 20:08:25 +10:00
										 |  |  |             ignore_used[index] = True | 
					
						
							| 
									
										
										
										
											2010-11-29 04:35:56 +00:00
										 |  |  |             return True | 
					
						
							|  |  |  |     return False | 
					
						
							| 
									
										
										
										
											2011-02-04 09:27:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-22 05:30:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-12 12:19:27 +10:00
										 |  |  | def main() -> None: | 
					
						
							| 
									
										
										
										
											2015-06-07 13:54:13 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |     print("Scanning:", SOURCE_DIR) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-29 08:49:50 +11:00
										 |  |  |     ignore_used_source = [False] * len(IGNORE_SOURCE) | 
					
						
							|  |  |  |     ignore_used_cmake = [False] * len(IGNORE_CMAKE) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-07 13:54:13 +10:00
										 |  |  |     for cmake in source_list(SOURCE_DIR, is_cmake): | 
					
						
							| 
									
										
										
										
											2018-11-29 08:49:50 +11:00
										 |  |  |         if not is_ignore_cmake(cmake, ignore_used_cmake): | 
					
						
							|  |  |  |             cmake_get_src(cmake) | 
					
						
							| 
									
										
										
										
											2015-06-07 13:54:13 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # 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.startswith(BUILD_DIR): | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if not os.path.exists(f): | 
					
						
							|  |  |  |             refs = global_refs[f] | 
					
						
							|  |  |  |             if refs: | 
					
						
							|  |  |  |                 for cf, i in refs: | 
					
						
							|  |  |  |                     errs.append((cf, i)) | 
					
						
							|  |  |  |             else: | 
					
						
							| 
									
										
										
										
											2021-01-20 15:58:07 +11:00
										 |  |  |                 raise Exception("CMake references missing, internal error, aborting!") | 
					
						
							| 
									
										
										
										
											2015-06-07 13:54:13 +10:00
										 |  |  |             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: | 
					
						
							| 
									
										
										
										
											2021-01-20 15:58:07 +11:00
										 |  |  |         raise Exception("CMake references missing files, aborting!") | 
					
						
							| 
									
										
										
										
											2015-06-07 13:54:13 +10:00
										 |  |  |     del is_err | 
					
						
							|  |  |  |     del errs | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # now check on files not accounted for. | 
					
						
							| 
									
										
										
										
											2018-09-19 17:48:11 +02:00
										 |  |  |     print("\nC/C++ Files CMake does not know about...") | 
					
						
							| 
									
										
										
										
											2015-06-07 13:54:13 +10:00
										 |  |  |     for cf in sorted(source_list(SOURCE_DIR, is_c)): | 
					
						
							| 
									
										
										
										
											2018-11-29 08:49:50 +11:00
										 |  |  |         if not is_ignore_source(cf, ignore_used_source): | 
					
						
							| 
									
										
										
										
											2015-06-07 13:54:13 +10:00
										 |  |  |             if cf not in global_c: | 
					
						
							|  |  |  |                 print("missing_c: ", cf) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-20 15:58:07 +11:00
										 |  |  |             # Check if automake builds a corresponding .o file. | 
					
						
							| 
									
										
										
										
											2015-06-07 13:54:13 +10:00
										 |  |  |             '''
 | 
					
						
							|  |  |  |             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) | 
					
						
							|  |  |  |             '''
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 17:48:11 +02:00
										 |  |  |     print("\nC/C++ Headers CMake does not know about...") | 
					
						
							| 
									
										
										
										
											2015-06-07 13:54:13 +10:00
										 |  |  |     for hf in sorted(source_list(SOURCE_DIR, is_c_header)): | 
					
						
							| 
									
										
										
										
											2018-11-29 08:49:50 +11:00
										 |  |  |         if not is_ignore_source(hf, ignore_used_source): | 
					
						
							| 
									
										
										
										
											2015-06-07 13:54:13 +10:00
										 |  |  |             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: | 
					
						
							| 
									
										
										
										
											2021-04-12 12:19:27 +10:00
										 |  |  |                             for _ in open(f, "r", encoding="utf8"): | 
					
						
							| 
									
										
										
										
											2015-06-07 13:54:13 +10:00
										 |  |  |                                 i += 1 | 
					
						
							|  |  |  |                         except UnicodeDecodeError: | 
					
						
							|  |  |  |                             print("Non utf8: %s:%d" % (f, i)) | 
					
						
							|  |  |  |                             if i > 1: | 
					
						
							|  |  |  |                                 traceback.print_exc() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-12 20:08:25 +10:00
										 |  |  |     # Check ignores aren't stale | 
					
						
							| 
									
										
										
										
											2018-11-29 08:49:50 +11:00
										 |  |  |     print("\nCheck for unused 'IGNORE_SOURCE' paths...") | 
					
						
							| 
									
										
										
										
											2021-01-20 15:58:07 +11:00
										 |  |  |     for index, ignore_path in enumerate(IGNORE_SOURCE): | 
					
						
							| 
									
										
										
										
											2018-11-29 08:49:50 +11:00
										 |  |  |         if not ignore_used_source[index]: | 
					
						
							| 
									
										
										
										
											2021-01-20 15:58:07 +11:00
										 |  |  |             print("unused ignore: %r" % ignore_path) | 
					
						
							| 
									
										
										
										
											2018-11-29 08:49:50 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-29 03:41:34 +11:00
										 |  |  |     # Check ignores aren't stale | 
					
						
							|  |  |  |     print("\nCheck for unused 'IGNORE_SOURCE_MISSING' paths...") | 
					
						
							|  |  |  |     for k, v in sorted(global_ignore_source_missing.items()): | 
					
						
							| 
									
										
										
										
											2021-01-20 15:58:07 +11:00
										 |  |  |         for ignore_path in v: | 
					
						
							|  |  |  |             print("unused ignore: %r -> %r" % (ignore_path, k)) | 
					
						
							| 
									
										
										
										
											2019-10-29 03:41:34 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-29 08:49:50 +11:00
										 |  |  |     # Check ignores aren't stale | 
					
						
							|  |  |  |     print("\nCheck for unused 'IGNORE_CMAKE' paths...") | 
					
						
							| 
									
										
										
										
											2021-01-20 15:58:07 +11:00
										 |  |  |     for index, ignore_path in enumerate(IGNORE_CMAKE): | 
					
						
							| 
									
										
										
										
											2018-11-29 08:49:50 +11:00
										 |  |  |         if not ignore_used_cmake[index]: | 
					
						
							| 
									
										
										
										
											2021-01-20 15:58:07 +11:00
										 |  |  |             print("unused ignore: %r" % ignore_path) | 
					
						
							| 
									
										
										
										
											2016-04-12 20:08:25 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-07 13:54:13 +10:00
										 |  |  | if __name__ == "__main__": | 
					
						
							|  |  |  |     main() |