• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# coding=utf-8
3# The build entrance of UniProton.
4
5#
6# Copyright (c) 2021-2023 Huawei Device Co., Ltd.
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11#     http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
19
20import xml.dom.minidom
21import sys
22import logging
23import globle
24from logs import BuilderNolog, log_msg
25
26
27logging.basicConfig(level=logging.NOTSET)
28logging.info(globle.config_dir)
29config_tree = xml.dom.minidom.parse(globle.config_dir)
30EXCEPTION_LIST = (AssertionError, AttributeError, IOError,
31                  ImportError, IndentationError,
32                  IndexError, KeyError, NameError,
33                  SyntaxError, TypeError, ValueError)
34
35def getNodeValue(node, index = 0):
36    return node.childNodes[index].nodeValue
37
38def getXmlNode(node, name):
39    return node.getElementsByTagName(name)
40
41def getNodeAtrrValue(node, attrname):
42    return node.getAttribute(attrname)
43
44def getChildNodeValueByNodeName(farthe_node, nodename, index = 0):
45    return farthe_node.getElementsByTagName(nodename)[0].childNodes[index].nodeValue
46
47def getChildNodeByNodeAtrr(farthe_node, node_name, atrr_name, strr_vlue):
48    for node in farthe_node.getElementsByTagName(node_name):
49        if node.getAttribute(atrr_name).startswith(strr_vlue):
50            return node
51    return False
52
53# 根据cputype获取hcc_path, kconf_dir, plam_type
54def get_cpu_info(cpu_type, cpu_plat, os_plat):
55    nameNode = "project"
56    cpu_list = config_tree.documentElement.getElementsByTagName(nameNode)
57    hcc_path, kconf_dir, plam_type, lib_type = "", "", "", ""
58    try:
59        for cpu in cpu_list:
60            if getNodeAtrrValue(cpu, "cpu_type") == cpu_type:
61                lib_type = getChildNodeValueByNodeName(cpu, "lib_type")
62                plam_type = getChildNodeValueByNodeName(getChildNodeByNodeAtrr(cpu, "platform", "plat_name", cpu_plat), "name")
63                hcc_path = getChildNodeValueByNodeName(getChildNodeByNodeAtrr(cpu, "platform", "plat_name", cpu_plat), "compile_path_{}".format(os_plat))
64                kconf_dir = getChildNodeValueByNodeName(getChildNodeByNodeAtrr(cpu, "platform", "plat_name", cpu_plat), "kconf_dir")
65    except EXCEPTION_LIST:
66        log_msg('error', "get cpu {} config info error:{} {}".format(cpu_type, cpu_plat, os_plat))
67        sys.exit(0)
68
69    system, core = "None", "None"
70    try:
71        for cpu in cpu_list:
72            if getNodeAtrrValue(cpu, "cpu_type") == cpu_type:
73                core = getChildNodeValueByNodeName(getChildNodeByNodeAtrr(cpu, "platform", "plat_name", cpu_plat), "core")
74                system = getChildNodeValueByNodeName(cpu, "system")
75    except EXCEPTION_LIST:
76        system = "None"
77    return lib_type, plam_type, hcc_path, kconf_dir, system, core
78
79def get_tool_info(tool_name, node_name):
80    tool_list = config_tree.documentElement.getElementsByTagName("tool")
81    try:
82        for tool in tool_list:
83            if getNodeAtrrValue(tool, "tool_name") == tool_name:
84                return getChildNodeValueByNodeName(tool, node_name)
85    except EXCEPTION_LIST:
86        log_msg("error", "get tool config info error:{} {}".format(tool_name, node_name))
87        sys.exit(0)
88    return False
89
90
91def get_compile_mode():
92    nameNode = "UniProton_compile_mode"
93    cpu_list = config_tree.documentElement.getElementsByTagName(nameNode)
94    compile_mode = getNodeValue(cpu_list[0])
95    return compile_mode
96