| 91 | |
| 92 | |
| 93 | class XcodeLogParser(object): |
| 94 | swiftc_exec = "bin/swiftc " |
| 95 | clang_exec = re.compile(r"^\s*\S*clang\S*") |
| 96 | |
| 97 | def __init__(self, _input: Iterator[str], _logFunc, skip_validate_bin, verbosity): |
| 98 | self._input = _input |
| 99 | self._log = _logFunc |
| 100 | self.skip_validate_bin = skip_validate_bin |
| 101 | self.verbosity = verbosity |
| 102 | self._pch_info = {} # {condition => pch_file_path} |
| 103 | |
| 104 | def parse_compile_swift_module(self, line: str): |
| 105 | if not line.startswith("CompileSwiftSources "): |
| 106 | return |
| 107 | |
| 108 | li = read_until_empty_line(self._input) |
| 109 | if not li: |
| 110 | return |
| 111 | |
| 112 | command = li[-1] # type: str |
| 113 | if not self.skip_validate_bin and self.swiftc_exec not in command: |
| 114 | echo(f"Error: ================= Can't found {self.swiftc_exec}\n" + command) |
| 115 | return |
| 116 | |
| 117 | module = {} |
| 118 | directory = next((cmd_split(i)[1] for i in li if i.startswith("cd ")), None) |
| 119 | if directory: |
| 120 | module["directory"] = directory |
| 121 | module["command"] = command |
| 122 | files = extract_swift_files_from_swiftc(command) |
| 123 | module["module_name"] = files[2] |
| 124 | module["files"] = files[0] |
| 125 | module["fileLists"] = files[1] |
| 126 | if files[3]: |
| 127 | self.index_store_path.add(files[3]) |
| 128 | echo(f"CompileSwiftModule {module['module_name']}") |
| 129 | return module |
| 130 | |
| 131 | def parse_swift_error(self, line: str): |
| 132 | regexp_str: Optional[str] = None |
| 133 | if not line.startswith('/'): return |
| 134 | if self.verbosity == 1: regexp_str = r'\:\s+(error)\:' |
| 135 | if self.verbosity == 2: regexp_str = r'\:\s+(error|warning)\:' |
| 136 | if self.verbosity == 3: regexp_str = r'\:\s+(error|warning|note)\:' |
| 137 | if not (regexp_str and re.search(regexp_str, line)): return |
| 138 | echo(line) |
| 139 | |
| 140 | def parse_swift_driver_module(self, line: str): |
| 141 | # match cases 1: |
| 142 | # SwiftDriver XXXDevEEUnitTest normal x86_64 com.apple.xcode.tools.swift.compiler (in target 'XXXDevEEUnitTest' from project 'XXXDev') |
| 143 | # cd ... |
| 144 | # builtin-SwiftDriver -- /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -module-name XXXDevEEUnitTest |
| 145 | |
| 146 | # match cases 2: |
| 147 | # SwiftDriver\ Compilation XXX normal x86_64 com.apple.xcode.tools.swift.compiler (in target 'XXX' from project 'XXX') |
| 148 | # cd ... |
| 149 | # builtin-Swift-Compilation -- /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -module-name XXX |
| 150 | |