|
22 | 22 | import sys |
23 | 23 | import tempfile |
24 | 24 | import traceback |
25 | | -from typing import Dict, List, Optional |
| 25 | +from typing import Dict, List, Optional, Any |
26 | 26 |
|
27 | 27 | from codechecker_analyzer.analyzers.clangsa.analyzer import ClangSA |
28 | 28 |
|
|
49 | 49 | # The compilation flags of which the prefix is any of these regular expressions |
50 | 50 | # will not be included in the output Clang command. |
51 | 51 | # These flags should be ignored only in case the original compiler is clang. |
52 | | -IGNORED_OPTIONS_CLANG = [ |
| 52 | +IGNORED_OPTIONS_LIST_CLANG = [ |
53 | 53 | # Clang gives different warnings than GCC. Thus if these flags are kept, |
54 | 54 | # '-Werror', '-pedantic-errors' the analysis with Clang can fail even |
55 | 55 | # if the compilation passes with GCC. |
|
66 | 66 | # The compilation flags of which the prefix is any of these regular expressions |
67 | 67 | # will not be included in the output Clang command. |
68 | 68 | # These flags should be ignored only in case the original compiler is gcc. |
69 | | -IGNORED_OPTIONS_GCC = [ |
| 69 | +IGNORED_OPTIONS_LIST_GCC = [ |
70 | 70 | # --- UNKNOWN BY CLANG --- # |
71 | 71 | '-fallow-fetchr-insn', |
72 | 72 | '-fcall-saved-', |
|
191 | 191 | '-mabi' |
192 | 192 | ] |
193 | 193 |
|
194 | | -IGNORED_OPTIONS_GCC = re.compile('|'.join(IGNORED_OPTIONS_GCC)) |
195 | | -IGNORED_OPTIONS_CLANG = re.compile('|'.join(IGNORED_OPTIONS_CLANG)) |
| 194 | +IGNORED_OPTIONS_GCC = re.compile('|'.join(IGNORED_OPTIONS_LIST_GCC)) |
| 195 | +IGNORED_OPTIONS_CLANG = re.compile('|'.join(IGNORED_OPTIONS_LIST_CLANG)) |
196 | 196 |
|
197 | 197 | # The compilation flags of which the prefix is any of these regular expressions |
198 | 198 | # will not be included in the output Clang command. These flags have further |
|
218 | 218 | } |
219 | 219 |
|
220 | 220 |
|
221 | | -COMPILE_OPTIONS = [ |
| 221 | +COMPILE_OPTIONS_LIST = [ |
222 | 222 | '-nostdinc', |
223 | 223 | r'-nostdinc\+\+', |
224 | 224 | '-pedantic', |
|
235 | 235 | '-pthread' |
236 | 236 | ] |
237 | 237 |
|
238 | | -COMPILE_OPTIONS = re.compile('|'.join(COMPILE_OPTIONS)) |
| 238 | +COMPILE_OPTIONS = re.compile('|'.join(COMPILE_OPTIONS_LIST)) |
239 | 239 |
|
240 | | -COMPILE_OPTIONS_MERGED = [ |
| 240 | +COMPILE_OPTIONS_LIST_MERGED = [ |
241 | 241 | '--sysroot', |
242 | 242 | '-sdkroot', |
243 | 243 | '--include', |
|
253 | 253 | '-iwithprefixbefore' |
254 | 254 | ] |
255 | 255 |
|
256 | | -INCLUDE_OPTIONS_MERGED = [ |
| 256 | +INCLUDE_OPTIONS_LIST_MERGED = [ |
257 | 257 | '-iquote', |
258 | 258 | '-[IF]', |
259 | 259 | '-isystem', |
|
271 | 271 | '-rewrite-objc'] |
272 | 272 |
|
273 | 273 | COMPILE_OPTIONS_MERGED = \ |
274 | | - re.compile('(' + '|'.join(COMPILE_OPTIONS_MERGED) + ')') |
| 274 | + re.compile('(' + '|'.join(COMPILE_OPTIONS_LIST_MERGED) + ')') |
275 | 275 |
|
276 | 276 | INCLUDE_OPTIONS_MERGED = \ |
277 | | - re.compile('(' + '|'.join(INCLUDE_OPTIONS_MERGED) + ')') |
| 277 | + re.compile('(' + '|'.join(INCLUDE_OPTIONS_LIST_MERGED) + ')') |
278 | 278 |
|
279 | 279 |
|
280 | 280 | PRECOMPILATION_OPTION = re.compile('-(E|M[G|T|Q|F|J|P|V|M]*)$') |
@@ -344,14 +344,14 @@ def __hash__(self): |
344 | 344 | (self.compiler, self.language, tuple(self.compiler_flags))) |
345 | 345 |
|
346 | 346 | compiler_info: Dict[ImplicitInfoSpecifierKey, dict] = {} |
347 | | - compiler_isexecutable = {} |
| 347 | + compiler_isexecutable: Dict[str, bool] = {} |
348 | 348 | # Store the already detected compiler version information. |
349 | 349 | # If the value is False the compiler is not clang otherwise the value |
350 | 350 | # should be a clang version information object. |
351 | | - compiler_versions = {} |
| 351 | + compiler_versions: Dict[str, Any] = {} |
352 | 352 |
|
353 | 353 | @staticmethod |
354 | | - def is_executable_compiler(compiler): |
| 354 | + def is_executable_compiler(compiler: str): |
355 | 355 | if compiler not in ImplicitCompilerInfo.compiler_isexecutable: |
356 | 356 | ImplicitCompilerInfo.compiler_isexecutable[compiler] = \ |
357 | 357 | which(compiler) is not None |
@@ -405,7 +405,7 @@ def __parse_compiler_includes(compile_cmd: List[str]): |
405 | 405 | start_mark = "#include <...> search starts here:" |
406 | 406 | end_mark = "End of search list." |
407 | 407 |
|
408 | | - include_paths = [] |
| 408 | + include_paths: List[str] = [] |
409 | 409 | lines = ImplicitCompilerInfo.__get_compiler_err(compile_cmd) |
410 | 410 |
|
411 | 411 | if not lines: |
@@ -571,7 +571,7 @@ def load_compiler_info(file_path: str): |
571 | 571 | for k, v in contents.items(): |
572 | 572 | k = json.loads(k) |
573 | 573 | ICI.compiler_info[ |
574 | | - ICI.ImplicitInfoSpecifierKey(k[0], k[1], tuple(k[2]))] = v |
| 574 | + ICI.ImplicitInfoSpecifierKey(k[0], k[1], list(k[2]))] = v |
575 | 575 |
|
576 | 576 | @staticmethod |
577 | 577 | def set(details, compiler_info_file=None): |
@@ -739,7 +739,7 @@ def __get_installed_dir(clang_binary) -> Optional[str]: |
739 | 739 | if 'clang' not in clang_path.name: |
740 | 740 | return None |
741 | 741 |
|
742 | | - return clang_path.parent |
| 742 | + return str(clang_path.parent) if clang_path.parent else None |
743 | 743 |
|
744 | 744 |
|
745 | 745 | def __collect_clang_compile_opts(flag_iterator, details): |
|
0 commit comments