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

Method analyze

client/tool/clang.py:37–113  ·  view source on GitHub ↗

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

(self, params)

Source from the content-addressed store, hash-verified

35 pass
36
37 def analyze(self, params):
38 """执行clang扫描任务
39
40 :param params: 需包含下面键值:
41 'rules': lint扫描的规则列表
42 'incr_scan' : 是否增量扫描
43
44 :return: return a :py:class:`IssueResponse`
45 """
46 # 根据项目环境变量选择合适的xcode版本
47 XcodeSwitch.set_xcodebuild_version()
48
49 source_dir = params['source_dir']
50 rules = params['rules']
51 pre_cmd = params.get('pre_cmd')
52 build_cmd = params.get('build_cmd')
53 build_args = shlex.split(build_cmd)
54 work_dir = os.getcwd()
55
56 # 如果编译命令为空,会导致shlex.split(None)操作卡顿
57 if not build_cmd:
58 raise TaskError(code=E_NODE_TASK_CONFIG, msg=u'编译命令为空,请先填写xcodebuild命令!')
59
60 if build_args and 'xcodebuild' not in build_args:
61 raise TaskError(code=E_NODE_TASK_CONFIG, msg=u'编译命令填写错误,请填写xcodebuild命令!')
62 if not build_args:
63 build_args = ['xcodebuild']
64
65 # get compild cwd from env var
66 build_cwd = os.environ.get('BUILD_CWD', None)
67 compile_cwd = os.path.join(source_dir, build_cwd) if build_cwd else source_dir
68
69 # 执行前置命令
70 if pre_cmd:
71 LogPrinter.info('run pre command ...')
72 pre_cmd = BasicCompile.generate_shell_file(pre_cmd, shell_name="tca_pre_cmd")
73 LogPrinter.info('run pre cmd shell file: %s' % pre_cmd)
74 sp = SubProcController(
75 shlex.split(pre_cmd),
76 cwd=compile_cwd,
77 stdout_line_callback=subprocc_log,
78 stderr_line_callback=subprocc_log,
79 stdout_filepath=None,
80 stderr_filepath=None
81 )
82 sp.wait()
83 if sp.returncode != 0:
84 LogPrinter.info("Pre command run error!")
85 raise CompileTaskError(msg=f"前置命令执行失败,请确认命令能否在代码根目录下成功执行: {pre_cmd}")
86
87 # 执行xcodebuild analyze
88 LogPrinter.info('analyze project ...')
89 build_cmd = build_args + ['CLANG_STATIC_ANALYZER_MODE_ON_ANALYZE_ACTION=shallow', 'analyze']
90 build_log = os.path.join(work_dir, 'clang_analyze.log')
91
92 LogPrinter.info('run cmd: %s' % ' '.join(build_cmd))
93 sp = SubProcController(
94 build_cmd,

Callers

nothing calls this directly

Calls 8

format_resultMethod · 0.95
TaskErrorClass · 0.90
CompileTaskErrorClass · 0.90
generate_shell_fileMethod · 0.80
debugMethod · 0.80
getMethod · 0.45
infoMethod · 0.45

Tested by

no test coverage detected