1#!/usr/bin/env python3 2# coding=utf-8 3# The build entrance of UniProton. 4# Copyright © Huawei Technologies Co., Ltd. 2010-2020. All rights reserved. 5import xml.dom.minidom 6import sys 7import logging 8import globle 9from logs import BuilderNolog, log_msg 10 11 12logging.basicConfig(level=logging.NOTSET) 13logging.info(globle.config_dir) 14config_tree = xml.dom.minidom.parse(globle.config_dir) 15EXCEPTION_LIST = (AssertionError, AttributeError, IOError, 16 ImportError, IndentationError, 17 IndexError, KeyError, NameError, 18 SyntaxError, TypeError, ValueError) 19 20def getNodeValue(node, index = 0): 21 return node.childNodes[index].nodeValue 22 23def getXmlNode(node, name): 24 return node.getElementsByTagName(name) 25 26def getNodeAtrrValue(node, attrname): 27 return node.getAttribute(attrname) 28 29def getChildNodeValueByNodeName(farthe_node, nodename, index = 0): 30 return farthe_node.getElementsByTagName(nodename)[0].childNodes[index].nodeValue 31 32def getChildNodeByNodeAtrr(farthe_node, node_name, atrr_name, strr_vlue): 33 for node in farthe_node.getElementsByTagName(node_name): 34 if node.getAttribute(atrr_name).startswith(strr_vlue): 35 return node 36 return False 37 38# 根据cputype获取hcc_path, kconf_dir, plam_type 39def get_cpu_info(cpu_type, cpu_plat, os_plat): 40 nameNode = "project" 41 cpu_list = config_tree.documentElement.getElementsByTagName(nameNode) 42 hcc_path, kconf_dir, plam_type, lib_type = "", "", "", "" 43 try: 44 for cpu in cpu_list: 45 if getNodeAtrrValue(cpu, "cpu_type") == cpu_type: 46 lib_type = getChildNodeValueByNodeName(cpu, "lib_type") 47 plam_type = getChildNodeValueByNodeName(getChildNodeByNodeAtrr(cpu, "platform", "plat_name", cpu_plat), "name") 48 hcc_path = getChildNodeValueByNodeName(getChildNodeByNodeAtrr(cpu, "platform", "plat_name", cpu_plat), "compile_path_{}".format(os_plat)) 49 kconf_dir = getChildNodeValueByNodeName(getChildNodeByNodeAtrr(cpu, "platform", "plat_name", cpu_plat), "kconf_dir") 50 except EXCEPTION_LIST: 51 log_msg('error', "get cpu {} config info error:{} {}".format(cpu_type, cpu_plat, os_plat)) 52 sys.exit(0) 53 54 system, core = "None", "None" 55 try: 56 for cpu in cpu_list: 57 if getNodeAtrrValue(cpu, "cpu_type") == cpu_type: 58 core = getChildNodeValueByNodeName(getChildNodeByNodeAtrr(cpu, "platform", "plat_name", cpu_plat), "core") 59 system = getChildNodeValueByNodeName(cpu, "system") 60 except EXCEPTION_LIST: 61 system = "None" 62 return lib_type, plam_type, hcc_path, kconf_dir, system, core 63 64def get_tool_info(tool_name, node_name): 65 tool_list = config_tree.documentElement.getElementsByTagName("tool") 66 try: 67 for tool in tool_list: 68 if getNodeAtrrValue(tool, "tool_name") == tool_name: 69 return getChildNodeValueByNodeName(tool, node_name) 70 except EXCEPTION_LIST: 71 log_msg("error", "get tool config info error:{} {}".format(tool_name, node_name)) 72 sys.exit(0) 73 return False 74 75 76def get_compile_mode(): 77 nameNode = "UniProton_compile_mode" 78 cpu_list = config_tree.documentElement.getElementsByTagName(nameNode) 79 compile_mode = getNodeValue(cpu_list[0]) 80 return compile_mode 81