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

Method analyze

client/tool/util/tscan.py:30–65  ·  view source on GitHub ↗

分析执行函数 :param params: 分析所需要的资源 1.项目地址 2.工作地址 3.分析参数 :param tc_home: tscan所在目录 :param bin_name: 二进制文件名称如tscancode, tsclua :param want_syffix: 扫描的文件后缀 :return:

(self, params, tc_home, bin_name, want_suffix)

Source from the content-addressed store, hash-verified

28
29class Tscan(CodeLintModel):
30 def analyze(self, params, tc_home, bin_name, want_suffix):
31 """
32 分析执行函数
33 :param params: 分析所需要的资源 1.项目地址 2.工作地址 3.分析参数
34 :param tc_home: tscan所在目录
35 :param bin_name: 二进制文件名称如tscancode, tsclua
36 :param want_syffix: 扫描的文件后缀
37 :return:
38 """
39 source_dir = params["source_dir"]
40 self.relpos = len(source_dir) + 1
41 self.work_dir = os.getcwd()
42 output_file = os.path.join(self.work_dir, "result.xml")
43 self.rules = params["rules"]
44 toscans = [source_dir]
45 inc = params["incr_scan"]
46 if inc:
47 diffs = SCMMgr(params).get_scm_diff()
48 toscans = [diff.path.replace(os.sep, "/") for diff in diffs if diff.path.endswith(tuple(want_suffix))]
49 toscans = PathMgr().format_cmd_arg_list(toscans)
50 os.chmod(os.path.join(tc_home, bin_name), stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
51 cmd_args = [bin_name, "--xml", f"2>{output_file}"]
52 CMD_ARG_MAX = PathMgr().get_cmd_arg_max()
53 cmd_args_list = PathMgr().get_cmd_args_list(cmd_args, toscans, CMD_ARG_MAX)
54 issues = []
55 for cmd in cmd_args_list:
56 LogPrinter.info(f"cmd: {cmd}")
57 sp = SubProcController(
58 command=cmd,
59 cwd=tc_home,
60 stdout_line_callback=subprocc_log,
61 )
62 sp.wait()
63 if os.path.exists(output_file) and os.stat(output_file).st_size != 0:
64 issues.extend(self._format_issue(output_file))
65 return issues
66
67 def _format_issue(self, output_file):
68 issues = []

Callers

nothing calls this directly

Calls 2

_format_issueMethod · 0.95
infoMethod · 0.45

Tested by

no test coverage detected