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

Class BasicCompile

client/tool/util/compile.py:30–236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28
29
30class BasicCompile(object):
31
32 build_log_end = queue.Queue(20)
33 stop_on_output_flag = False
34
35 def __init__(self, params, sensitive, sensitive_word_maps, build_cmd=None, shell=True):
36 """
37 编译模块构造函数
38 :param params:
39 """
40 self.params = params
41 self.sensitive = sensitive
42 self.sensitive_word_maps = sensitive_word_maps
43 self.shell = shell
44 # 编译条件1: 编译命令
45 if build_cmd:
46 self.build_cmd = build_cmd
47 else:
48 self.build_cmd = params["build_cmd"]
49 if not self.build_cmd:
50 raise CompileTaskError("编译语言项目执行静态分析需要输入编译命令,请填入编译命令后重试!")
51 # 编译条件2: 编译项目路径
52 self.build_cwd = params["source_dir"]
53 build_cwd = os.environ.get("BUILD_CWD", None)
54 self.build_cwd = os.path.join(self.build_cwd, build_cwd) if build_cwd else self.build_cwd
55 # 编译条件3: 编译中断设置
56 self.stop_on_output = os.environ.get("STOP_ON_OUTPUT")
57 # 编译条件4: 执行前置命令
58 self.pre_cmd()
59
60 @staticmethod
61 def generate_shell_file(cmd, log_flag=True, shell_name="tca_build"):
62 """
63 将编译命令保存到bash/bat的脚本文件中,并赋予可执行权限,返回执行该脚本文件的命令
64 :param cmd: 编译命令字符串
65 :param log_flag: 是否输出命令,默认输出
66 :param shell_name: 生成的shell文件名
67 :return: 执行该脚本文件的命令
68 """
69 work_dir = os.getcwd()
70 if platform.system() == "Windows":
71 file_name = f"{shell_name}.bat"
72 else:
73 file_name = f"{shell_name}.sh"
74 shell_filepath = os.path.join(work_dir, file_name)
75 # 格式化文件路径
76 shell_filepath = PathMgr().format_path(shell_filepath)
77 with open(shell_filepath, "w") as wf:
78 wf.write(cmd)
79 # 给文件授权可执行权限
80 os.chmod(shell_filepath, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
81
82 if log_flag:
83 logger.info("Cmd:\n%s" % cmd)
84 logger.info("Generated shell file: %s" % shell_filepath)
85
86 if platform.system() == "Windows":
87 return shell_filepath

Callers 9

compileMethod · 0.90
compileMethod · 0.90
compileMethod · 0.90
compileMethod · 0.90
compileMethod · 0.90
compileMethod · 0.90
compileMethod · 0.90
compileMethod · 0.90
compileMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected