@@ -161,7 +161,8 @@ def __update_tool_names(self, tool_names, task_list):
161161 tool_names .remove (c_name )
162162 return tool_names
163163
164- def read_tool_config_from_ini_file (self , tool_names = None , custom_tools = None , task_list = None , config_all_tools = False , include_common = True ):
164+ def read_tool_config_from_ini_file (self , tool_names = None , custom_tools = None , task_list = None , config_all_tools = False ,
165+ include_common = True ):
165166 """
166167 从ini文件中读取工具配置
167168 """
@@ -194,6 +195,7 @@ def read_tool_config_from_ini_file(self, tool_names=None, custom_tools=None, tas
194195 "env_path" : env_path_section , # env_path_section中现在已经没有key为"PATH"的元素,可以作为编译工具的env_path
195196 "env_value" : env_value_section
196197 }
198+ self .__format_to_fullpath (compile_config )
197199 config_dict ["compile_config" ] = compile_config
198200 return config_dict
199201 else :
@@ -236,6 +238,25 @@ def __format_config(self, tool_cfg, env_path_section, env_value_section):
236238 tool_cfg ["env_value" ] = self .__str_to_dict (tool_cfg ["env_value" ], env_value_section )
237239 tool_cfg ["tool_url" ] = self .__str_to_list (tool_cfg ["tool_url" ])
238240 tool_cfg ["path" ] = self .__str_to_list (tool_cfg ["path" ], uniq = False )
241+ self .__format_to_fullpath (tool_cfg )
242+
243+ def __format_to_fullpath (self , tool_cfg ):
244+ # 将路径类型的环境变量(env_path)中的相对路径转换成绝对路径
245+ for env_name , rel_path in tool_cfg ["env_path" ].items ():
246+ if "PATH" == env_name : # PATH应该单独放在path字段中,如果放在env_path中,忽略,避免影响和覆盖原有PATH变量
247+ continue
248+ full_path = os .path .join (settings .TOOL_BASE_DIR , rel_path )
249+ tool_cfg ["env_path" ][env_name ] = full_path
250+
251+ # 将PATH环境变量的相对路径转换成绝对路径
252+ path_env = []
253+ for rel_path in tool_cfg ["path" ]:
254+ if "$" in rel_path or "%" in rel_path : # 带变量的环境变量,已经是全路径
255+ full_path = rel_path
256+ else :
257+ full_path = os .path .join (settings .TOOL_BASE_DIR , rel_path )
258+ path_env .append (full_path )
259+ tool_cfg ["path" ] = path_env
239260
240261 def read_config_from_tool_schemes (self , tool_names = None , task_list = None ):
241262 """
@@ -266,7 +287,7 @@ def read_config_from_tool_schemes(self, tool_names=None, task_list=None):
266287 config_dict = {}
267288 already_config_tools = [] # 记录已经读取到配置的工具
268289 for task_config in task_list :
269- task_name = task_config [ "task_name" ]
290+ task_name = task_config . get ( "task_name" )
270291 if tool_names and task_name not in tool_names :
271292 continue
272293 task_params = task_config .get ("task_params" , {})
@@ -282,29 +303,41 @@ def read_config_from_tool_schemes(self, tool_names=None, task_list=None):
282303 for tool_lib in tool_libs :
283304 lib_support_os = tool_lib .get ("os" , [])
284305 if self ._os_type in lib_support_os :
306+ # 使用新的结构存储环境变量,避免修改原有的任务参数
307+ new_lib_envs = {}
285308 lib_envs = tool_lib .get ("envs" , {})
286309 if not lib_envs : # 可能会传空list,这里判空,避免后面格式出错
287- lib_envs = {}
310+ new_lib_envs = {}
311+
288312 scm_url = tool_lib .get ("scm_url" )
289- lib_dir_name = scm_url .split ('/' )[- 1 ].strip ().replace (".git" , "" )
290- # 环境变量中的$ROOT_DIR替换为目录名,后续加载环境变量时会拼接为全路径
313+ # 支持git仓库地址和zip包地址两种格式
314+ lib_dir_name = BaseScmUrlMgr .get_last_dir_name_from_url (scm_url )
315+ lib_dir_path = os .path .join (settings .TOOL_BASE_DIR , lib_dir_name )
316+
317+ # 将环境变量中的$ROOT_DIR替换为实际路径,重新保存到new_lib_envs
291318 for key , value in lib_envs .items ():
292319 if "$ROOT_DIR" in value :
293- lib_envs [key ] = value .replace ("$ROOT_DIR" , lib_dir_name )
320+ new_lib_envs [key ] = value .replace ("$ROOT_DIR" , lib_dir_path )
321+ else :
322+ new_lib_envs [key ] = value
323+
294324 # PATH和其他环境变量分开处理
295325 path_envs = []
296326 other_envs = {}
297- for env_name , env_value in lib_envs .items ():
327+ for env_name , env_value in new_lib_envs .items ():
298328 if env_name == "PATH" :
299329 path_envs = self .__str_to_list (env_value )
300330 else :
301- other_envs [env_name ] = env_value
331+ # 根据英文分号拆分后,再环境变量分隔符拼接到一起
332+ value_list = self .__str_to_list (env_value )
333+ value_format = os .pathsep .join (value_list )
334+ other_envs [env_name ] = value_format
302335 lib_config = {
303336 "tool_url" : scm_url ,
304337 "scm_type" : tool_lib .get ("scm_type" ),
305338 "auth_info" : tool_lib .get ("auth_info" ),
306339 "path" : path_envs ,
307- "env_path" : lib_envs ,
340+ "env_path" : other_envs ,
308341 "env_value" : {}
309342 }
310343 lib_name = tool_lib .get ("name" )
0 commit comments