MCPcopy Create free account
hub / github.com/Tencent/CodeAnalysis / handle_log

Method handle_log

client/tool/util/compile.py:167–228  ·  view source on GitHub ↗

处理编译log,判断是否编译成功

(self, returncode)

Source from the content-addressed store, hash-verified

165 logger.info("basic compile done.")
166
167 def handle_log(self, returncode):
168 """
169 处理编译log,判断是否编译成功
170 """
171 exist_error_flag = False
172 exist_success_flag = False
173 exist_100_flag = False
174 cov_no_file_emitted = False
175 # 遍历编译日志队列
176 while not self.build_log_end.empty():
177 build_log_line = self.build_log_end.get()
178 # 增加编译脚本找不到命令的情况
179 if (
180 build_log_line.lower().find("error") != -1
181 or build_log_line.lower().find("build failed") != -1
182 or build_log_line.lower().find(": command not found") != -1
183 or build_log_line.lower().find(": 未找到命令") != -1
184 ):
185 exist_error_flag = True
186 if build_log_line.lower().find("build successful") != -1:
187 exist_success_flag = True
188 if build_log_line.lower().find("units (100%)") != -1:
189 exist_100_flag = True
190 if build_log_line.lower().find("no files were emitted") != -1:
191 cov_no_file_emitted = True
192
193 logger.info("exist_error_flag : %s" % exist_error_flag)
194 logger.info("exist_success_flag : %s" % exist_success_flag)
195 logger.info("exist_100_flag : %s" % exist_100_flag)
196 logger.info("cov_no_file_emitted : %s" % cov_no_file_emitted)
197
198 success_returncode = [0, -9]
199 if exist_100_flag:
200 logger.info("编译成功!")
201 elif returncode not in success_returncode and exist_error_flag:
202 logger.info("编译结束,rc为:%d" % returncode)
203 raise CompileTaskError(msg="项目编译失败,请确认当前版本是否能在本地进行编译!")
204 elif returncode in success_returncode and exist_error_flag:
205 logger.error("编译结束,可能存在异常,请注意,rc为%d" % returncode)
206 elif exist_success_flag:
207 logger.info("编译成功!")
208 if cov_no_file_emitted:
209 # 输出idir/build-log.txt内容,方便调试
210 build_log = os.path.join(self.params["work_dir"], "idir", "build-log.txt")
211 if os.path.exists(build_log):
212 logger.info("idir/build-log.txt内容:")
213 f = open(build_log)
214 # 逐行读取,遇到无法解码的行,捕获异常并跳过(一次性读取,如果有无法解码的行,会异常)
215 while True:
216 try:
217 line = f.readline()
218 if not line: # 读到文件末尾,退出
219 break
220 else:
221 self.print_log(line)
222 except Exception as err:
223 logger.warning("readline error(%s), skip this line." % str(err))
224 f.close()

Callers 1

compileMethod · 0.95

Calls 6

print_logMethod · 0.95
CompileTaskErrorClass · 0.90
errorMethod · 0.80
warningMethod · 0.80
getMethod · 0.45
infoMethod · 0.45

Tested by

no test coverage detected