MCPcopy Index your code
hub / github.com/Tencent/CodeAnalysis / analyze

Method analyze

client/tool/cpplint.py:255–318  ·  view source on GitHub ↗

执行cpplint扫描任务 :param params: 需包含下面键值: 'rules': lint扫描的规则列表 'incr_scan' : 是否增量扫描 :return: return a :py:class:`IssueResponse`

(self, params)

Source from the content-addressed store, hash-verified

253 return "100"
254
255 def analyze(self, params):
256 """执行cpplint扫描任务
257 :param params: 需包含下面键值:
258 'rules': lint扫描的规则列表
259 'incr_scan' : 是否增量扫描
260 :return: return a :py:class:`IssueResponse`
261 """
262 source_dir = params.source_dir
263 rules = params["rules"]
264 incr_scan = params["incr_scan"]
265
266 path_mgr = PathMgr()
267
268 if incr_scan:
269 diffs = SCMMgr(params).get_scm_diff()
270 toscans = [
271 os.path.join(source_dir, diff.path)
272 for diff in diffs
273 if diff.path.endswith(self.want_suffix) and diff.state != "del"
274 ]
275 else:
276 toscans = path_mgr.get_dir_files(source_dir, self.want_suffix)
277
278 # filter include and exclude path
279 relpos = len(source_dir) + 1
280 toscans = FilterPathUtil(params).get_include_files(toscans, relpos)
281
282 if not toscans:
283 logger.info("To-be-scanned files is empty ")
284 return []
285 else:
286 logger.info("toscans: %s" % len(toscans))
287
288 # 执行cpplint工具
289 start_time = time.time()
290 reg_client = re.compile(r"^(.+?):(\d+):\s+(.+?)\s+\[([\S]+)\]\s+\[(\d+)\]$")
291 max_linelength = self.__get_linelength_param(params)
292 # 获取项目名称
293 project_name = None
294 scm_type = params.get("scm_type")
295 if "git" == scm_type: # git仓库
296 project_name = params.get("scm_url")
297 if project_name.find("#") != -1:
298 project_name = project_name.split("#")[0]
299 project_name = project_name.split("/")[-1]
300 project_name = project_name.replace(".git", "")
301 elif "svn" == scm_type: # svn项目
302 project_name = params.get("scm_url").split("/")[-1].split("_proj")[0]
303 cmd_args = self.__prepare_cpplint_args(source_dir, rules, max_linelength, project_name)
304
305 self.print_log("run cmd on every file: %s" % " ".join(cmd_args))
306
307 # 多线程执行cpplint
308 issues = ThreadRunner(cmd_args, reg_client, source_dir, rules).run(toscans)
309
310 # 单线程执行cpplint
311 # issues = CpplintRunner().run_cpplint_on_files(toscans, cmd_args, reg_client, source_dir, rules)
312

Callers

nothing calls this directly

Calls 9

get_dir_filesMethod · 0.80
ThreadRunnerClass · 0.70
infoMethod · 0.45
compileMethod · 0.45
getMethod · 0.45
print_logMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected