编译执行函数 :param params: :return:
(self, params)
| 25 | self.sensitive_word_maps = {"infer": "Tool", "Infer": "Tool"} |
| 26 | |
| 27 | def compile(self, params): |
| 28 | """ |
| 29 | 编译执行函数 |
| 30 | :param params: |
| 31 | :return: |
| 32 | """ |
| 33 | source_dir = params.source_dir |
| 34 | work_dir = os.getcwd() |
| 35 | pre_cmd = params.get("pre_cmd", None) |
| 36 | build_cmd = shlex.split(params.get("build_cmd", None)) |
| 37 | incr_scan = params.get("incr_scan", True) |
| 38 | envs = params.get("envs", {}) |
| 39 | |
| 40 | # get compild cwd from env var |
| 41 | build_cwd = os.environ.get("BUILD_CWD", None) |
| 42 | compile_cwd = os.path.join(source_dir, build_cwd) if build_cwd else source_dir |
| 43 | |
| 44 | infer_result_dir = os.path.join(work_dir, "infer_result") |
| 45 | error_output = os.path.join(infer_result_dir, "report.json") |
| 46 | |
| 47 | # pre-process step |
| 48 | # 可能会需要要前置命令做为clean project, 可以做全量,需要clean一下项目 |
| 49 | # 或者infer compile -- cmake . |
| 50 | # infer compile -- ./configure |
| 51 | if pre_cmd: |
| 52 | SubProcController(shlex.split(pre_cmd), cwd=compile_cwd, shell=False).wait() |
| 53 | |
| 54 | # capture |
| 55 | scan_capture_cmd = ["infer", "capture", "--continue", "--jobs", "8"] |
| 56 | # 增量--reactive |
| 57 | if incr_scan: |
| 58 | scan_capture_cmd.append("--reactive") |
| 59 | # 针对iOS项目,如果默认与xcpretty结合使用,但是无法扫出问题,可以尝试无需使用xcpretty,这样会以infer自带的clang来编译项目 |
| 60 | if envs.get("INFER_NO_XCPRETTY", False): |
| 61 | scan_capture_cmd.append("--no-xcpretty") |
| 62 | # 编译捕获依赖,无须源码,jar包中class文件也能做到分析转换成中间文件。--dependencies |
| 63 | if envs.get("INFER_DEPENDENCES", False): |
| 64 | scan_capture_cmd.append("--dependencies") |
| 65 | # 指定java的bootclasspath |
| 66 | if envs.get("INFER_BOOTCLASSPATH", False): |
| 67 | scan_capture_cmd.append("--bootclasspath") |
| 68 | scan_capture_cmd.append(envs.get("INFER_BOOTCLASSPATH")) |
| 69 | # 指定buck-out的根目录 |
| 70 | if envs.get("INFER_BUCK_OUT", False): |
| 71 | scan_capture_cmd.append("--buck-out") |
| 72 | scan_capture_cmd.append(envs.get("INFER_BUCK_OUT")) |
| 73 | # 编译时候指定c++头文件model,可能会导致编译失败 |
| 74 | if envs.get("INFER_CXX_HEADER", False): |
| 75 | scan_capture_cmd.append("--cxx-infer-headers") |
| 76 | scan_capture_cmd.append(envs.get("INFER_CXX_HEADER")) |
| 77 | |
| 78 | # 设置特殊的option,比如--siof-safe-methods string, --no-default-linters, "--compute-analytics" |
| 79 | # "--headers" --header会扫描头文件使耗时家长 |
| 80 | if "INFER_CAPTURE_PARAMS" in envs: |
| 81 | scan_capture_cmd += shlex.split(envs["INFER_CAPTURE_PARAMS"]) |
| 82 | |
| 83 | scan_capture_cmd.extend(["-o", infer_result_dir, "--"]) |
| 84 | scan_capture_cmd.extend(build_cmd) |
no test coverage detected