openubmc-bingo 0.5.240__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of openubmc-bingo might be problematic. Click here for more details.
- bmcgo/__init__.py +12 -0
- bmcgo/bmcgo.py +22 -0
- bmcgo/bmcgo_config.py +176 -0
- bmcgo/cli/__init__.py +10 -0
- bmcgo/cli/cli.py +584 -0
- bmcgo/codegen/__init__.py +14 -0
- bmcgo/codegen/c/__init__.py +9 -0
- bmcgo/codegen/c/annotation.py +52 -0
- bmcgo/codegen/c/argument.py +42 -0
- bmcgo/codegen/c/codegen.py +153 -0
- bmcgo/codegen/c/comment.py +22 -0
- bmcgo/codegen/c/ctype_defination.py +353 -0
- bmcgo/codegen/c/helper.py +87 -0
- bmcgo/codegen/c/interface.py +63 -0
- bmcgo/codegen/c/method.py +82 -0
- bmcgo/codegen/c/property.py +180 -0
- bmcgo/codegen/c/renderer.py +21 -0
- bmcgo/codegen/c/signal.py +64 -0
- bmcgo/codegen/c/template/client.c.mako +145 -0
- bmcgo/codegen/c/template/client.h.mako +36 -0
- bmcgo/codegen/c/template/interface.c.mako +0 -0
- bmcgo/codegen/c/template/interface.introspect.xml.mako +99 -0
- bmcgo/codegen/c/template/micro_component.c.mako +32 -0
- bmcgo/codegen/c/template/public.c.mako +228 -0
- bmcgo/codegen/c/template/public.h.mako +128 -0
- bmcgo/codegen/c/template/server.c.mako +104 -0
- bmcgo/codegen/c/template/server.h.mako +36 -0
- bmcgo/codegen/lua/.lua-format +7 -0
- bmcgo/codegen/lua/Makefile +101 -0
- bmcgo/codegen/lua/__init__.py +9 -0
- bmcgo/codegen/lua/codegen.py +171 -0
- bmcgo/codegen/lua/proto/Makefile +87 -0
- bmcgo/codegen/lua/proto/ipmi_types.proto +17 -0
- bmcgo/codegen/lua/proto/types.proto +52 -0
- bmcgo/codegen/lua/script/check_intfs.py +161 -0
- bmcgo/codegen/lua/script/dto/__init__.py +11 -0
- bmcgo/codegen/lua/script/dto/exception.py +53 -0
- bmcgo/codegen/lua/script/dto/kepler_abstract.py +47 -0
- bmcgo/codegen/lua/script/dto/options.py +33 -0
- bmcgo/codegen/lua/script/dto/print_simple.py +19 -0
- bmcgo/codegen/lua/script/dto/redfish_api.py +241 -0
- bmcgo/codegen/lua/script/dto/url_route.py +195 -0
- bmcgo/codegen/lua/script/gen_db_json.py +444 -0
- bmcgo/codegen/lua/script/gen_depends.py +89 -0
- bmcgo/codegen/lua/script/gen_entry.py +263 -0
- bmcgo/codegen/lua/script/gen_feature_json.py +156 -0
- bmcgo/codegen/lua/script/gen_historical_local_db_json.py +88 -0
- bmcgo/codegen/lua/script/gen_intf_json.py +261 -0
- bmcgo/codegen/lua/script/gen_intf_rpc_json.py +575 -0
- bmcgo/codegen/lua/script/gen_ipmi_json.py +485 -0
- bmcgo/codegen/lua/script/gen_mdb_json.py +117 -0
- bmcgo/codegen/lua/script/gen_rpc_msg_json.py +487 -0
- bmcgo/codegen/lua/script/gen_schema.py +302 -0
- bmcgo/codegen/lua/script/ipmi_types_pb2.py +135 -0
- bmcgo/codegen/lua/script/loader/__init__.py +11 -0
- bmcgo/codegen/lua/script/loader/file_utils.py +33 -0
- bmcgo/codegen/lua/script/loader/kepler_abstract_collect.py +79 -0
- bmcgo/codegen/lua/script/loader/kepler_abstract_loader.py +47 -0
- bmcgo/codegen/lua/script/loader/redfish_loader.py +127 -0
- bmcgo/codegen/lua/script/lua_format.py +62 -0
- bmcgo/codegen/lua/script/mds_util.py +385 -0
- bmcgo/codegen/lua/script/merge_model.py +330 -0
- bmcgo/codegen/lua/script/merge_proto_algo.py +85 -0
- bmcgo/codegen/lua/script/proto_loader.py +47 -0
- bmcgo/codegen/lua/script/proto_plugin.py +140 -0
- bmcgo/codegen/lua/script/redfish_source_tree.py +118 -0
- bmcgo/codegen/lua/script/render_utils/__init__.py +38 -0
- bmcgo/codegen/lua/script/render_utils/base.py +25 -0
- bmcgo/codegen/lua/script/render_utils/client_lua.py +98 -0
- bmcgo/codegen/lua/script/render_utils/controller_lua.py +71 -0
- bmcgo/codegen/lua/script/render_utils/db_lua.py +224 -0
- bmcgo/codegen/lua/script/render_utils/error_lua.py +185 -0
- bmcgo/codegen/lua/script/render_utils/factory.py +52 -0
- bmcgo/codegen/lua/script/render_utils/ipmi_lua.py +159 -0
- bmcgo/codegen/lua/script/render_utils/ipmi_message_lua.py +24 -0
- bmcgo/codegen/lua/script/render_utils/mdb_lua.py +177 -0
- bmcgo/codegen/lua/script/render_utils/mdb_register.py +215 -0
- bmcgo/codegen/lua/script/render_utils/message_lua.py +26 -0
- bmcgo/codegen/lua/script/render_utils/messages_lua.py +156 -0
- bmcgo/codegen/lua/script/render_utils/model_lua.py +485 -0
- bmcgo/codegen/lua/script/render_utils/old_model_lua.py +429 -0
- bmcgo/codegen/lua/script/render_utils/plugin_lua.py +38 -0
- bmcgo/codegen/lua/script/render_utils/redfish_proto.py +86 -0
- bmcgo/codegen/lua/script/render_utils/request_lua.py +76 -0
- bmcgo/codegen/lua/script/render_utils/service_lua.py +130 -0
- bmcgo/codegen/lua/script/render_utils/utils_message_lua.py +125 -0
- bmcgo/codegen/lua/script/render_utils/validate_lua.py +221 -0
- bmcgo/codegen/lua/script/sep_ipmi_message_cmds.py +217 -0
- bmcgo/codegen/lua/script/template.py +166 -0
- bmcgo/codegen/lua/script/types_pb2.py +516 -0
- bmcgo/codegen/lua/script/utils.py +663 -0
- bmcgo/codegen/lua/script/validate.py +80 -0
- bmcgo/codegen/lua/script/yaml_to_json.py +73 -0
- bmcgo/codegen/lua/templates/Makefile +114 -0
- bmcgo/codegen/lua/templates/apps/Makefile +261 -0
- bmcgo/codegen/lua/templates/apps/Makefile.mdb.mk +64 -0
- bmcgo/codegen/lua/templates/apps/app.lua.mako +19 -0
- bmcgo/codegen/lua/templates/apps/class.lua.mako +35 -0
- bmcgo/codegen/lua/templates/apps/client.lua.mako +429 -0
- bmcgo/codegen/lua/templates/apps/controller.lua.mako +276 -0
- bmcgo/codegen/lua/templates/apps/datas.lua.mako +8 -0
- bmcgo/codegen/lua/templates/apps/db.lua.mako +89 -0
- bmcgo/codegen/lua/templates/apps/entry.lua.mako +128 -0
- bmcgo/codegen/lua/templates/apps/feature.lua.mako +37 -0
- bmcgo/codegen/lua/templates/apps/generate_route.mako +25 -0
- bmcgo/codegen/lua/templates/apps/impl_feature.lua.mako +72 -0
- bmcgo/codegen/lua/templates/apps/ipmi.lua.mako +97 -0
- bmcgo/codegen/lua/templates/apps/ipmi_cmd.lua.mako +18 -0
- bmcgo/codegen/lua/templates/apps/ipmi_message.lua.mako +36 -0
- bmcgo/codegen/lua/templates/apps/local_db.lua.mako +263 -0
- bmcgo/codegen/lua/templates/apps/main.lua.mako +25 -0
- bmcgo/codegen/lua/templates/apps/mc.lua.mako +77 -0
- bmcgo/codegen/lua/templates/apps/mdb.lua.mako +45 -0
- bmcgo/codegen/lua/templates/apps/mdb_interface.lua.mako +73 -0
- bmcgo/codegen/lua/templates/apps/message.lua.mako +38 -0
- bmcgo/codegen/lua/templates/apps/model.lua.mako +239 -0
- bmcgo/codegen/lua/templates/apps/orm_classes.lua.mako +16 -0
- bmcgo/codegen/lua/templates/apps/plugin.lua.mako +8 -0
- bmcgo/codegen/lua/templates/apps/redfish.proto.mako +47 -0
- bmcgo/codegen/lua/templates/apps/service.lua.mako +440 -0
- bmcgo/codegen/lua/templates/apps/signal_listen.lua.mako +19 -0
- bmcgo/codegen/lua/templates/apps/utils/default_intf.lua.mako +41 -0
- bmcgo/codegen/lua/templates/apps/utils/enum.mako +10 -0
- bmcgo/codegen/lua/templates/apps/utils/imports.mako +13 -0
- bmcgo/codegen/lua/templates/apps/utils/mdb_intf.lua.mako +25 -0
- bmcgo/codegen/lua/templates/apps/utils/mdb_obj.lua.mako +23 -0
- bmcgo/codegen/lua/templates/apps/utils/message.mako +160 -0
- bmcgo/codegen/lua/templates/apps/utils/request.lua.mako +59 -0
- bmcgo/codegen/lua/templates/apps/utils/validate.mako +83 -0
- bmcgo/codegen/lua/templates/errors.lua.mako +36 -0
- bmcgo/codegen/lua/templates/messages.lua.mako +32 -0
- bmcgo/codegen/lua/templates/new_app/.clang-format.mako +170 -0
- bmcgo/codegen/lua/templates/new_app/.gitignore.mako +26 -0
- bmcgo/codegen/lua/templates/new_app/CHANGELOG.md.mako +0 -0
- bmcgo/codegen/lua/templates/new_app/CMakeLists.txt.mako +29 -0
- bmcgo/codegen/lua/templates/new_app/Makefile.mako +25 -0
- bmcgo/codegen/lua/templates/new_app/README.md.mako +0 -0
- bmcgo/codegen/lua/templates/new_app/conanfile.py.mako +7 -0
- bmcgo/codegen/lua/templates/new_app/config.cfg.mako +6 -0
- bmcgo/codegen/lua/templates/new_app/mds/model.json.mako +3 -0
- bmcgo/codegen/lua/templates/new_app/mds/service.json.mako +21 -0
- bmcgo/codegen/lua/templates/new_app/permissions.ini.mako +16 -0
- bmcgo/codegen/lua/templates/new_app/src/lualib/${project_name}_app.lua.mako +16 -0
- bmcgo/codegen/lua/templates/new_app/src/service/main.lua.mako +25 -0
- bmcgo/codegen/lua/templates/new_app/test/integration/test_${project_name}.conf.mako +9 -0
- bmcgo/codegen/lua/templates/new_app/test/integration/test_${project_name}.lua.mako +47 -0
- bmcgo/codegen/lua/templates/new_app/test/unit/test.lua.mako +23 -0
- bmcgo/codegen/lua/templates/new_app/user_conf/rootfs/etc/systemd/system/${project_name}.service.mako +18 -0
- bmcgo/codegen/lua/templates/new_app/user_conf/rootfs/etc/systemd/system/multi-user.target.wants/${project_name}.service.link +1 -0
- bmcgo/component/__init__.py +10 -0
- bmcgo/component/analysis/analysis.py +183 -0
- bmcgo/component/analysis/build_deps.py +165 -0
- bmcgo/component/analysis/data_deps.py +333 -0
- bmcgo/component/analysis/dep-rules.json +912 -0
- bmcgo/component/analysis/dep_node.py +110 -0
- bmcgo/component/analysis/intf_deps.py +163 -0
- bmcgo/component/analysis/intf_validation.py +254 -0
- bmcgo/component/analysis/rule.py +211 -0
- bmcgo/component/analysis/smc_dfx_whitelist.json +11 -0
- bmcgo/component/analysis/sr_validation.py +391 -0
- bmcgo/component/build.py +222 -0
- bmcgo/component/component_dt_version_parse.py +348 -0
- bmcgo/component/component_helper.py +114 -0
- bmcgo/component/coverage/__init__.py +11 -0
- bmcgo/component/coverage/c_incremental_cov_report.template +53 -0
- bmcgo/component/coverage/incremental_cov.py +464 -0
- bmcgo/component/deploy.py +110 -0
- bmcgo/component/gen.py +169 -0
- bmcgo/component/package_info.py +236 -0
- bmcgo/component/template/conanbase.py.mako +278 -0
- bmcgo/component/template/conanfile.deploy.py.mako +40 -0
- bmcgo/component/test.py +947 -0
- bmcgo/errors.py +119 -0
- bmcgo/frame.py +217 -0
- bmcgo/functional/__init__.py +10 -0
- bmcgo/functional/analysis.py +96 -0
- bmcgo/functional/bmc_studio_action.py +98 -0
- bmcgo/functional/check.py +185 -0
- bmcgo/functional/conan_index_build.py +251 -0
- bmcgo/functional/config.py +332 -0
- bmcgo/functional/csr_build.py +724 -0
- bmcgo/functional/deploy.py +263 -0
- bmcgo/functional/diff.py +235 -0
- bmcgo/functional/fetch.py +235 -0
- bmcgo/functional/full_component.py +391 -0
- bmcgo/functional/maintain.py +381 -0
- bmcgo/functional/new.py +166 -0
- bmcgo/functional/schema_valid.py +111 -0
- bmcgo/functional/simple_sign.py +104 -0
- bmcgo/functional/upgrade.py +78 -0
- bmcgo/ipmigen/__init__.py +13 -0
- bmcgo/ipmigen/ctype_defination.py +82 -0
- bmcgo/ipmigen/ipmigen.py +309 -0
- bmcgo/ipmigen/template/cmd.c.mako +366 -0
- bmcgo/ipmigen/template/ipmi.c.mako +25 -0
- bmcgo/ipmigen/template/ipmi.h.mako +51 -0
- bmcgo/logger.py +176 -0
- bmcgo/misc.py +117 -0
- bmcgo/target/app.yml +17 -0
- bmcgo/target/install_sdk.yml +15 -0
- bmcgo/target/personal.yml +53 -0
- bmcgo/target/publish.yml +45 -0
- bmcgo/tasks/__init__.py +11 -0
- bmcgo/tasks/download_buildtools_hm.py +124 -0
- bmcgo/tasks/misc.py +15 -0
- bmcgo/tasks/task.py +354 -0
- bmcgo/tasks/task_build_conan.py +714 -0
- bmcgo/tasks/task_build_rootfs_img.py +595 -0
- bmcgo/tasks/task_buildgppbin.py +88 -0
- bmcgo/tasks/task_buildhpm_ext4.py +82 -0
- bmcgo/tasks/task_create_interface_config.py +122 -0
- bmcgo/tasks/task_download_buildtools.py +99 -0
- bmcgo/tasks/task_download_dependency.py +72 -0
- bmcgo/tasks/task_hpm_envir_prepare.py +112 -0
- bmcgo/tasks/task_packet_to_supporte.py +87 -0
- bmcgo/tasks/task_prepare.py +105 -0
- bmcgo/tasks/task_sign_and_pack_hpm.py +42 -0
- bmcgo/utils/__init__.py +10 -0
- bmcgo/utils/buffer.py +128 -0
- bmcgo/utils/combine_json_schemas.py +170 -0
- bmcgo/utils/component_post.py +54 -0
- bmcgo/utils/component_version_check.py +86 -0
- bmcgo/utils/config.py +1067 -0
- bmcgo/utils/fetch_component_code.py +232 -0
- bmcgo/utils/install_manager.py +61 -0
- bmcgo/utils/installations/__init__.py +10 -0
- bmcgo/utils/installations/base_installer.py +70 -0
- bmcgo/utils/installations/install_consts.py +30 -0
- bmcgo/utils/installations/install_plans/bingo.yml +11 -0
- bmcgo/utils/installations/install_workflow.py +50 -0
- bmcgo/utils/installations/installers/apt_installer.py +177 -0
- bmcgo/utils/installations/installers/pip_installer.py +46 -0
- bmcgo/utils/installations/version_util.py +100 -0
- bmcgo/utils/mapping_config_patch.py +443 -0
- bmcgo/utils/perf_analysis.py +114 -0
- bmcgo/utils/tools.py +704 -0
- bmcgo/worker.py +417 -0
- openubmc_bingo-0.5.240.dist-info/METADATA +30 -0
- openubmc_bingo-0.5.240.dist-info/RECORD +242 -0
- openubmc_bingo-0.5.240.dist-info/WHEEL +5 -0
- openubmc_bingo-0.5.240.dist-info/entry_points.txt +2 -0
- openubmc_bingo-0.5.240.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/python3
|
|
2
|
+
# coding: utf-8
|
|
3
|
+
# Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
# openUBMC is licensed under Mulan PSL v2.
|
|
5
|
+
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
6
|
+
# You may obtain a copy of Mulan PSL v2 at:
|
|
7
|
+
# http://license.coscl.org.cn/MulanPSL2
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
9
|
+
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
10
|
+
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
11
|
+
# See the Mulan PSL v2 for more details.
|
|
12
|
+
from xml.dom import Node
|
|
13
|
+
from bmcgo.codegen.c.comment import Comment
|
|
14
|
+
from bmcgo.codegen.c.ctype_defination import CTypes
|
|
15
|
+
from bmcgo.codegen.c.helper import Helper
|
|
16
|
+
from bmcgo.logger import Logger
|
|
17
|
+
|
|
18
|
+
log = Logger("c_argument")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Argument():
|
|
23
|
+
def __init__(self, node: Node, comment: Comment, prefix: str = ""):
|
|
24
|
+
self.node = node
|
|
25
|
+
prefix = prefix + " "
|
|
26
|
+
self.comment = comment or Comment()
|
|
27
|
+
self.name = Helper.get_node_value(node, "name", "")
|
|
28
|
+
self.direction = Helper.get_node_value(node, "direction", "in")
|
|
29
|
+
self.signature = Helper.get_node_value(node, "type")
|
|
30
|
+
if self.signature is None:
|
|
31
|
+
log.error("参数缺少 'type' 属性")
|
|
32
|
+
self.ctype = CTypes.types.get(self.signature, CTypes.types.get("*"))
|
|
33
|
+
if self.ctype is None:
|
|
34
|
+
log.error("未知的 C 类型: %s", self.signature)
|
|
35
|
+
if self.direction != "in" and self.direction != "out":
|
|
36
|
+
log.error("无效的方向参数: '%s', 其值必须为 [in out], 获取到 %s" % {self.name, self.direction})
|
|
37
|
+
log.debug("%s 参数, 名称: %33s 签名: %4s 方向: %s" % (
|
|
38
|
+
prefix, self.name + ",", self.signature + ",", self.direction))
|
|
39
|
+
|
|
40
|
+
def set_arg_id(self, arg_id: int):
|
|
41
|
+
if not self.name:
|
|
42
|
+
self.name = "arg_" + str(arg_id)
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
#!/usr/bin/python3
|
|
2
|
+
# coding: utf-8
|
|
3
|
+
# Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
# openUBMC is licensed under Mulan PSL v2.
|
|
5
|
+
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
6
|
+
# You may obtain a copy of Mulan PSL v2 at:
|
|
7
|
+
# http://license.coscl.org.cn/MulanPSL2
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
9
|
+
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
10
|
+
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
11
|
+
# See the Mulan PSL v2 for more details.
|
|
12
|
+
import hashlib
|
|
13
|
+
import json
|
|
14
|
+
import os
|
|
15
|
+
import subprocess
|
|
16
|
+
import stat
|
|
17
|
+
from xml.dom import minidom, Node
|
|
18
|
+
import yaml
|
|
19
|
+
import semver
|
|
20
|
+
from mako.lookup import TemplateLookup
|
|
21
|
+
from bmcgo.codegen.c.interface import Interface
|
|
22
|
+
from bmcgo.codegen.c.comment import Comment
|
|
23
|
+
from bmcgo.codegen.c.renderer import Renderer
|
|
24
|
+
from bmcgo.logger import Logger
|
|
25
|
+
cwd = os.path.split(os.path.realpath(__file__))[0]
|
|
26
|
+
|
|
27
|
+
global log
|
|
28
|
+
log = Logger()
|
|
29
|
+
|
|
30
|
+
PKG_PUBLIC = "public"
|
|
31
|
+
PKG_SERVER = "server"
|
|
32
|
+
PKG_CLIENT = "client"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class XmlInterfaces(Renderer):
|
|
36
|
+
def __init__(self, lookup, xml_file, base_version):
|
|
37
|
+
super(Renderer, self).__init__()
|
|
38
|
+
self.base_version = base_version
|
|
39
|
+
self.version = "0.0.1"
|
|
40
|
+
self.name = os.path.basename(xml_file)[:-4]
|
|
41
|
+
self.lookup = lookup
|
|
42
|
+
self.introspect_xml_sha256 = None # 自举文件的sha256值
|
|
43
|
+
file_handler = open(xml_file)
|
|
44
|
+
self.dom = minidom.parse(file_handler)
|
|
45
|
+
file_handler.close()
|
|
46
|
+
self.interfaces: list[Interface] = []
|
|
47
|
+
for subnode in self.dom.childNodes:
|
|
48
|
+
if subnode.nodeType == Node.DOCUMENT_TYPE_NODE:
|
|
49
|
+
continue
|
|
50
|
+
if subnode.nodeType == Node.ELEMENT_NODE:
|
|
51
|
+
self._parse_subnode(subnode)
|
|
52
|
+
|
|
53
|
+
def render_xml(self, template, out_file):
|
|
54
|
+
file_handler = os.fdopen(os.open(out_file, os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
|
|
55
|
+
stat.S_IWUSR | stat.S_IRUSR), 'w')
|
|
56
|
+
out = self.render(self.lookup, template, interfaces=self.interfaces, version=self.base_version)
|
|
57
|
+
hash_val = hashlib.sha256()
|
|
58
|
+
hash_val.update(out.encode('utf-8'))
|
|
59
|
+
self.introspect_xml_sha256 = hash_val.hexdigest()
|
|
60
|
+
log.info("The sha256sum of interface %s is %s", out_file, self.introspect_xml_sha256)
|
|
61
|
+
file_handler.write(out)
|
|
62
|
+
file_handler.close()
|
|
63
|
+
|
|
64
|
+
def render_c_language(self, template, out_file):
|
|
65
|
+
file_handler = os.fdopen(os.open(out_file, os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
|
|
66
|
+
stat.S_IWUSR | stat.S_IRUSR), 'w')
|
|
67
|
+
out = self.render(self.lookup, template, xml=self, version=self.base_version)
|
|
68
|
+
file_handler.write(out)
|
|
69
|
+
file_handler.close()
|
|
70
|
+
|
|
71
|
+
def _parse_subnode(self, subnode):
|
|
72
|
+
remove_node = []
|
|
73
|
+
comment = Comment()
|
|
74
|
+
for child in subnode.childNodes:
|
|
75
|
+
if child.nodeType == Node.COMMENT_NODE:
|
|
76
|
+
comment.append(child)
|
|
77
|
+
elif child.nodeType != Node.ELEMENT_NODE:
|
|
78
|
+
continue
|
|
79
|
+
if child.nodeName == "version":
|
|
80
|
+
self.version = str(child.firstChild.nodeValue)
|
|
81
|
+
ver = semver.parse(self.version, False)
|
|
82
|
+
if ver is None:
|
|
83
|
+
raise Exception("Interface has version error, abort")
|
|
84
|
+
for com in comment.nodes:
|
|
85
|
+
subnode.removeChild(com)
|
|
86
|
+
remove_node.append(child)
|
|
87
|
+
elif child.nodeName == "interface":
|
|
88
|
+
intf = Interface(child, comment, self.version)
|
|
89
|
+
self.interfaces.append(intf)
|
|
90
|
+
comment = Comment()
|
|
91
|
+
for node in remove_node:
|
|
92
|
+
subnode.removeChild(node)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class CodeGen(object):
|
|
96
|
+
def __init__(self, base_version):
|
|
97
|
+
self.base_version = base_version
|
|
98
|
+
|
|
99
|
+
def format(self, out_file):
|
|
100
|
+
try:
|
|
101
|
+
subprocess.run(["/usr/bin/clang-format", "--version"], stderr=subprocess.DEVNULL,
|
|
102
|
+
stdout=subprocess.DEVNULL)
|
|
103
|
+
except Exception:
|
|
104
|
+
log.error("Command clang-format not found, skip format %s/%s", os.getcwd(), out_file)
|
|
105
|
+
return
|
|
106
|
+
if not os.path.isfile(".clang-format"):
|
|
107
|
+
log.error("the style file .clang-format is missing, skip format %s/%s", os.getcwd(), out_file)
|
|
108
|
+
return
|
|
109
|
+
subprocess.run(["/usr/bin/clang-format", "--style=file", "-i", out_file])
|
|
110
|
+
|
|
111
|
+
def gen(self, xml_file, directory="."):
|
|
112
|
+
os.makedirs(os.path.join(directory, PKG_PUBLIC), exist_ok=True)
|
|
113
|
+
os.makedirs(os.path.join(directory, PKG_SERVER), exist_ok=True)
|
|
114
|
+
os.makedirs(os.path.join(directory, PKG_CLIENT), exist_ok=True)
|
|
115
|
+
lookup = TemplateLookup(directories=os.path.join(cwd, "template"))
|
|
116
|
+
interfaces = XmlInterfaces(lookup, xml_file, self.base_version)
|
|
117
|
+
out_file = os.path.join(directory, PKG_PUBLIC, os.path.basename(xml_file))
|
|
118
|
+
interfaces.render_xml("interface.introspect.xml.mako", out_file)
|
|
119
|
+
for code_type in [PKG_SERVER, PKG_CLIENT, PKG_PUBLIC]:
|
|
120
|
+
out_file = os.path.join(directory, code_type, interfaces.name + ".h")
|
|
121
|
+
interfaces.render_c_language(code_type + ".h.mako", out_file)
|
|
122
|
+
self.format(out_file)
|
|
123
|
+
out_file = os.path.join(directory, code_type, interfaces.name + ".c")
|
|
124
|
+
interfaces.render_c_language(code_type + ".c.mako", out_file)
|
|
125
|
+
self.format(out_file)
|
|
126
|
+
json_file = os.path.join(directory, "package.yml")
|
|
127
|
+
data = {
|
|
128
|
+
"version": interfaces.version,
|
|
129
|
+
"name": interfaces.name
|
|
130
|
+
}
|
|
131
|
+
with os.fdopen(os.open(json_file, os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
|
|
132
|
+
stat.S_IWUSR | stat.S_IRUSR), 'w') as file_handler:
|
|
133
|
+
yaml.dump(data, file_handler, encoding='utf-8', allow_unicode=True)
|
|
134
|
+
log.success("Generate code successfully, interface: %s", xml_file)
|
|
135
|
+
|
|
136
|
+
def gen_mds(self, mds):
|
|
137
|
+
file_handler = open(mds, "r")
|
|
138
|
+
mds = json.load(file_handler)
|
|
139
|
+
service_type = mds.get("type", [])
|
|
140
|
+
if "application" not in service_type:
|
|
141
|
+
return
|
|
142
|
+
file_handler.close()
|
|
143
|
+
service_name = mds.get("name", "")
|
|
144
|
+
if service_name in ["ssdp", "libproto-mc4c", "file_transfer"]:
|
|
145
|
+
return
|
|
146
|
+
lookup = TemplateLookup(directories=os.path.join(cwd, "template"))
|
|
147
|
+
template = lookup.get_template("micro_component.c.mako")
|
|
148
|
+
out = template.render(lookup=lookup, mds=mds, version=self.base_version)
|
|
149
|
+
os.makedirs("service", exist_ok=True)
|
|
150
|
+
file_handler = os.fdopen(os.open("service/micro_component.c", os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
|
|
151
|
+
stat.S_IWUSR | stat.S_IRUSR), 'w')
|
|
152
|
+
file_handler.write(out)
|
|
153
|
+
file_handler.close()
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/python3
|
|
2
|
+
# coding: utf-8
|
|
3
|
+
# Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
# openUBMC is licensed under Mulan PSL v2.
|
|
5
|
+
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
6
|
+
# You may obtain a copy of Mulan PSL v2 at:
|
|
7
|
+
# http://license.coscl.org.cn/MulanPSL2
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
9
|
+
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
10
|
+
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
11
|
+
# See the Mulan PSL v2 for more details.
|
|
12
|
+
from xml.dom import Node
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Comment():
|
|
16
|
+
def __init__(self):
|
|
17
|
+
self.texts: list[str] = []
|
|
18
|
+
self.nodes: list[Node] = []
|
|
19
|
+
|
|
20
|
+
def append(self, node: Node):
|
|
21
|
+
self.texts.append(node.nodeValue.strip())
|
|
22
|
+
self.nodes.append(node)
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
#!/usr/bin/python3
|
|
2
|
+
# coding: utf-8
|
|
3
|
+
# Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
# openUBMC is licensed under Mulan PSL v2.
|
|
5
|
+
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
6
|
+
# You may obtain a copy of Mulan PSL v2 at:
|
|
7
|
+
# http://license.coscl.org.cn/MulanPSL2
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
9
|
+
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
10
|
+
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
11
|
+
# See the Mulan PSL v2 for more details.
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class CTypeBase(object):
|
|
15
|
+
arg_in: str # 做为函数的入参参数
|
|
16
|
+
arg_out: str # 做为函数的出差参数
|
|
17
|
+
write_type: str # 属性写函数关键字,前加mdb_set_xxx得到真实函数名
|
|
18
|
+
variant_type: str # 属性的gvariant type(signature)字符串
|
|
19
|
+
|
|
20
|
+
def __init__(self, variant_type, write_type, arg_in, arg_out, arg_decode,
|
|
21
|
+
arg_encode,
|
|
22
|
+
args_write_remote_declear, arg_free):
|
|
23
|
+
self.variant_type = variant_type
|
|
24
|
+
self.write_type = write_type
|
|
25
|
+
self.arg_in = arg_in
|
|
26
|
+
self.arg_out = arg_out
|
|
27
|
+
self.arg_decode = arg_decode
|
|
28
|
+
self.arg_encode = arg_encode
|
|
29
|
+
self.arg_free = arg_free
|
|
30
|
+
self.args_write_remote_declear = args_write_remote_declear
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
def render_in_args(self, prop_name: str, is_const: bool):
|
|
34
|
+
return self._replace(self.arg_in, prop_name, is_const)
|
|
35
|
+
|
|
36
|
+
def render_out_args(self, prop_name, is_const: bool):
|
|
37
|
+
return self._replace(self.arg_out, prop_name, is_const)
|
|
38
|
+
|
|
39
|
+
def render_in_encode(self, prop_name):
|
|
40
|
+
pass
|
|
41
|
+
|
|
42
|
+
def render_out_decode(self, prop_name):
|
|
43
|
+
pass
|
|
44
|
+
|
|
45
|
+
def is_array(self):
|
|
46
|
+
glib_type = ["b", "y", "n", "q", "i", "u", "x", "t", "d", "h", "s", "o", "g"]
|
|
47
|
+
if self.variant_type.startswith("a") and self.variant_type[1:] in glib_type:
|
|
48
|
+
return True
|
|
49
|
+
else:
|
|
50
|
+
return False
|
|
51
|
+
|
|
52
|
+
def _replace(self, template: str, prop_name: str, is_const: bool):
|
|
53
|
+
out = template.replace("<arg_name>", prop_name)
|
|
54
|
+
const_str = ""
|
|
55
|
+
if is_const:
|
|
56
|
+
const_str = "const "
|
|
57
|
+
return out.replace("<const>", const_str)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class CTypes():
|
|
61
|
+
types = {
|
|
62
|
+
"b": CTypeBase(variant_type="b",
|
|
63
|
+
write_type="boolean",
|
|
64
|
+
arg_in="gboolean <arg_name>",
|
|
65
|
+
arg_out="gboolean *<arg_name>",
|
|
66
|
+
args_write_remote_declear="g_variant_new_boolean(<arg_name>)",
|
|
67
|
+
arg_decode=[
|
|
68
|
+
"<req><arg_name> = parameter_get_boolean(parameters, arg_id);"],
|
|
69
|
+
arg_free=[],
|
|
70
|
+
arg_encode=[
|
|
71
|
+
"g_variant_builder_add_value(&builder, g_variant_new_boolean(<req><arg_name>));"],),
|
|
72
|
+
"ab": CTypeBase(variant_type="ab",
|
|
73
|
+
write_type="array_boolean",
|
|
74
|
+
arg_in="gsize n_<arg_name>, <const>gboolean *<arg_name>",
|
|
75
|
+
arg_out="gsize *n_<arg_name>, gboolean **<arg_name>",
|
|
76
|
+
args_write_remote_declear="BUILD_BASIC_TYPE_ARRAY(\"b\", n_<arg_name>, <arg_name>)",
|
|
77
|
+
arg_decode=["ITER_BASIC_TYPE_ARRAY(parameters, arg_id, <req>n_<arg_name>, " +
|
|
78
|
+
"<req><arg_name>, boolean, \"b\");"],
|
|
79
|
+
arg_free=["g_free(<req><arg_name>);"],
|
|
80
|
+
arg_encode=[
|
|
81
|
+
"tmp_v = BUILD_BASIC_TYPE_ARRAY(\"b\", <req>n_<arg_name>, <req><arg_name>);",
|
|
82
|
+
"g_variant_builder_add_value(&builder, tmp_v);"],
|
|
83
|
+
),
|
|
84
|
+
"y": CTypeBase(variant_type="y",
|
|
85
|
+
write_type="uint8",
|
|
86
|
+
arg_in="guint8 <arg_name>",
|
|
87
|
+
arg_out="guint8 *<arg_name>",
|
|
88
|
+
args_write_remote_declear="g_variant_new_byte(<arg_name>)",
|
|
89
|
+
arg_decode=["<req><arg_name> = parameter_get_uint8(parameters, arg_id);"],
|
|
90
|
+
arg_free=[],
|
|
91
|
+
arg_encode=[
|
|
92
|
+
"g_variant_builder_add_value(&builder, g_variant_new_byte(<req><arg_name>));"]),
|
|
93
|
+
"ay": CTypeBase(variant_type="ay",
|
|
94
|
+
write_type="array_uint8",
|
|
95
|
+
arg_in="gsize n_<arg_name>, <const>guint8 *<arg_name>",
|
|
96
|
+
arg_out="gsize *n_<arg_name>, guint8 **<arg_name>",
|
|
97
|
+
args_write_remote_declear="BUILD_BASIC_TYPE_ARRAY(\"y\", n_<arg_name>, <arg_name>)",
|
|
98
|
+
arg_decode=["ITER_BASIC_TYPE_ARRAY(parameters, arg_id, <req>n_<arg_name>, <req><arg_name>," +
|
|
99
|
+
" uint8, \"y\");"],
|
|
100
|
+
arg_free=["g_free(<req><arg_name>);"],
|
|
101
|
+
arg_encode=[
|
|
102
|
+
"tmp_v = BUILD_BASIC_TYPE_ARRAY(\"y\", <req>n_<arg_name>, <req><arg_name>);",
|
|
103
|
+
"g_variant_builder_add_value(&builder, tmp_v);"],
|
|
104
|
+
),
|
|
105
|
+
"n": CTypeBase(variant_type="n",
|
|
106
|
+
write_type="int16",
|
|
107
|
+
arg_in="gint16 <arg_name>",
|
|
108
|
+
arg_out="gint16 *<arg_name>",
|
|
109
|
+
args_write_remote_declear="g_variant_new_int16(<arg_name>)",
|
|
110
|
+
arg_decode=["<req><arg_name> = parameter_get_int16(parameters, arg_id);"],
|
|
111
|
+
arg_free=[],
|
|
112
|
+
arg_encode=[
|
|
113
|
+
"g_variant_builder_add_value(&builder, g_variant_new_int16(<req><arg_name>));"]),
|
|
114
|
+
"an": CTypeBase(variant_type="an",
|
|
115
|
+
write_type="array_int16",
|
|
116
|
+
arg_in="gsize n_<arg_name>, <const>gint16 *<arg_name>",
|
|
117
|
+
arg_out="gsize *n_<arg_name>, gint16 **<arg_name>",
|
|
118
|
+
args_write_remote_declear="BUILD_BASIC_TYPE_ARRAY(\"n\", n_<arg_name>, <arg_name>)",
|
|
119
|
+
arg_decode=["ITER_BASIC_TYPE_ARRAY(parameters, arg_id, <req>n_<arg_name>, <req><arg_name>," +
|
|
120
|
+
" int16, \"n\");"],
|
|
121
|
+
arg_free=["g_free(<req><arg_name>);"],
|
|
122
|
+
arg_encode=[
|
|
123
|
+
"tmp_v = BUILD_BASIC_TYPE_ARRAY(\"n\", <req>n_<arg_name>, <req><arg_name>);",
|
|
124
|
+
"g_variant_builder_add_value(&builder, tmp_v);"],
|
|
125
|
+
),
|
|
126
|
+
"q": CTypeBase(variant_type="q",
|
|
127
|
+
write_type="uint16",
|
|
128
|
+
arg_in="guint16 <arg_name>",
|
|
129
|
+
arg_out="guint16 *<arg_name>",
|
|
130
|
+
args_write_remote_declear="g_variant_new_uint16(<arg_name>)",
|
|
131
|
+
arg_decode=["<req><arg_name> = parameter_get_uint16(parameters, arg_id);"],
|
|
132
|
+
arg_free=[],
|
|
133
|
+
arg_encode=[
|
|
134
|
+
"g_variant_builder_add_value(&builder, g_variant_new_uint16(<req><arg_name>));"]),
|
|
135
|
+
"aq": CTypeBase(variant_type="aq",
|
|
136
|
+
write_type="array_uint16",
|
|
137
|
+
arg_in="gsize n_<arg_name>, <const>guint16 *<arg_name>",
|
|
138
|
+
arg_out="gsize *n_<arg_name>, guint16 **<arg_name>",
|
|
139
|
+
args_write_remote_declear="BUILD_BASIC_TYPE_ARRAY(\"q\", n_<arg_name>, <arg_name>)",
|
|
140
|
+
arg_decode=["ITER_BASIC_TYPE_ARRAY(parameters, arg_id, <req>n_<arg_name>, <req><arg_name>," +
|
|
141
|
+
" uint16, \"q\");"],
|
|
142
|
+
arg_free=["g_free(<req><arg_name>);"],
|
|
143
|
+
arg_encode=[
|
|
144
|
+
"tmp_v = BUILD_BASIC_TYPE_ARRAY(\"q\", <req>n_<arg_name>, <req><arg_name>);",
|
|
145
|
+
"g_variant_builder_add_value(&builder, tmp_v);"],
|
|
146
|
+
),
|
|
147
|
+
"i": CTypeBase(variant_type="i",
|
|
148
|
+
write_type="int32",
|
|
149
|
+
arg_in="gint32 <arg_name>",
|
|
150
|
+
arg_out="gint32 *<arg_name>",
|
|
151
|
+
args_write_remote_declear="g_variant_new_int32(<arg_name>)",
|
|
152
|
+
arg_decode=[
|
|
153
|
+
"<req><arg_name> = parameter_get_int32(parameters, arg_id);"],
|
|
154
|
+
arg_free=[],
|
|
155
|
+
arg_encode=[
|
|
156
|
+
"g_variant_builder_add_value(&builder, g_variant_new_int32(<req><arg_name>));"]),
|
|
157
|
+
"ai": CTypeBase(variant_type="ai",
|
|
158
|
+
write_type="array_int32",
|
|
159
|
+
arg_in="gsize n_<arg_name>, <const>gint32 *<arg_name>",
|
|
160
|
+
arg_out="gsize *n_<arg_name>, gint32 **<arg_name>",
|
|
161
|
+
args_write_remote_declear="BUILD_BASIC_TYPE_ARRAY(\"i\", n_<arg_name>, <arg_name>)",
|
|
162
|
+
arg_decode=["ITER_BASIC_TYPE_ARRAY(parameters, arg_id, <req>n_<arg_name>, <req><arg_name>," +
|
|
163
|
+
" int32, \"i\");"],
|
|
164
|
+
arg_free=["g_free(<req><arg_name>);"],
|
|
165
|
+
arg_encode=[
|
|
166
|
+
"tmp_v = BUILD_BASIC_TYPE_ARRAY(\"i\", <req>n_<arg_name>, <req><arg_name>);",
|
|
167
|
+
"g_variant_builder_add_value(&builder, tmp_v);"],
|
|
168
|
+
),
|
|
169
|
+
"u": CTypeBase(variant_type="u",
|
|
170
|
+
write_type="uint32",
|
|
171
|
+
arg_in="guint32 <arg_name>",
|
|
172
|
+
arg_out="guint32 *<arg_name>",
|
|
173
|
+
args_write_remote_declear="g_variant_new_uint32(<arg_name>)",
|
|
174
|
+
arg_decode=["<req><arg_name> = parameter_get_uint32(parameters, arg_id);"],
|
|
175
|
+
arg_free=[],
|
|
176
|
+
arg_encode=[
|
|
177
|
+
"g_variant_builder_add_value(&builder, g_variant_new_uint32(<req><arg_name>));"]),
|
|
178
|
+
"au": CTypeBase(variant_type="au",
|
|
179
|
+
write_type="array_uint32",
|
|
180
|
+
arg_in="gsize n_<arg_name>, <const>guint32 *<arg_name>",
|
|
181
|
+
arg_out="gsize *n_<arg_name>, guint32 **<arg_name>",
|
|
182
|
+
args_write_remote_declear="BUILD_BASIC_TYPE_ARRAY(\"u\", n_<arg_name>, <arg_name>)",
|
|
183
|
+
arg_decode=["ITER_BASIC_TYPE_ARRAY(parameters, arg_id, <req>n_<arg_name>, <req><arg_name>," +
|
|
184
|
+
" uint32, \"u\");"],
|
|
185
|
+
arg_free=["g_free(<req><arg_name>);"],
|
|
186
|
+
arg_encode=[
|
|
187
|
+
"tmp_v = BUILD_BASIC_TYPE_ARRAY(\"u\", <req>n_<arg_name>, <req><arg_name>);",
|
|
188
|
+
"g_variant_builder_add_value(&builder, tmp_v);"],
|
|
189
|
+
),
|
|
190
|
+
"x": CTypeBase(variant_type="x",
|
|
191
|
+
write_type="int64",
|
|
192
|
+
arg_in="gint64 <arg_name>",
|
|
193
|
+
arg_out="gint64 *<arg_name>",
|
|
194
|
+
args_write_remote_declear="g_variant_new_int64(<arg_name>)",
|
|
195
|
+
arg_decode=["<req><arg_name> = parameter_get_int64(parameters, arg_id);"],
|
|
196
|
+
arg_free=[],
|
|
197
|
+
arg_encode=[
|
|
198
|
+
"g_variant_builder_add_value(&builder, g_variant_new_int64(<req><arg_name>));"]),
|
|
199
|
+
"ax": CTypeBase(variant_type="ax",
|
|
200
|
+
write_type="array_int64",
|
|
201
|
+
arg_in="gsize n_<arg_name>, <const>gint64 *<arg_name>",
|
|
202
|
+
arg_out="gsize *n_<arg_name>, gint64 **<arg_name>",
|
|
203
|
+
args_write_remote_declear="BUILD_BASIC_TYPE_ARRAY(\"x\", n_<arg_name>, <arg_name>)",
|
|
204
|
+
arg_decode=["ITER_BASIC_TYPE_ARRAY(parameters, arg_id, <req>n_<arg_name>, <req><arg_name>," +
|
|
205
|
+
" int64, \"x\");"],
|
|
206
|
+
arg_free=["g_free(<req><arg_name>);"],
|
|
207
|
+
arg_encode=[
|
|
208
|
+
"tmp_v = BUILD_BASIC_TYPE_ARRAY(\"x\", <req>n_<arg_name>, <req><arg_name>);",
|
|
209
|
+
"g_variant_builder_add_value(&builder, tmp_v);"],
|
|
210
|
+
),
|
|
211
|
+
"t": CTypeBase(variant_type="t",
|
|
212
|
+
write_type="uint64",
|
|
213
|
+
arg_in="guint64 <arg_name>",
|
|
214
|
+
arg_out="guint64 *<arg_name>",
|
|
215
|
+
args_write_remote_declear="g_variant_new_uint64(<arg_name>)",
|
|
216
|
+
arg_decode=[
|
|
217
|
+
"<req><arg_name> = parameter_get_uint64(parameters, arg_id);"],
|
|
218
|
+
arg_free=[],
|
|
219
|
+
arg_encode=[
|
|
220
|
+
"g_variant_builder_add_value(&builder, g_variant_new_uint64(<req><arg_name>));"]),
|
|
221
|
+
"at": CTypeBase(variant_type="at",
|
|
222
|
+
write_type="array_uint64",
|
|
223
|
+
arg_in="gsize n_<arg_name>, <const>guint64 *<arg_name>",
|
|
224
|
+
arg_out="gsize *n_<arg_name>, guint64 **<arg_name>",
|
|
225
|
+
args_write_remote_declear="BUILD_BASIC_TYPE_ARRAY(\"t\", n_<arg_name>, <arg_name>)",
|
|
226
|
+
arg_decode=["ITER_BASIC_TYPE_ARRAY(parameters, arg_id, <req>n_<arg_name>, <req><arg_name>," +
|
|
227
|
+
" uint64, \"t\");"],
|
|
228
|
+
arg_free=["g_free(<req><arg_name>);"],
|
|
229
|
+
arg_encode=[
|
|
230
|
+
"tmp_v = BUILD_BASIC_TYPE_ARRAY(\"t\", <req>n_<arg_name>, <req><arg_name>);",
|
|
231
|
+
"g_variant_builder_add_value(&builder, tmp_v);"],
|
|
232
|
+
),
|
|
233
|
+
"d": CTypeBase(variant_type="d",
|
|
234
|
+
write_type="double",
|
|
235
|
+
arg_in="gdouble <arg_name>",
|
|
236
|
+
arg_out="gdouble *<arg_name>",
|
|
237
|
+
args_write_remote_declear="g_variant_new_double(<arg_name>)",
|
|
238
|
+
arg_decode=[
|
|
239
|
+
"<req><arg_name> = parameter_get_double(parameters, arg_id);"],
|
|
240
|
+
arg_free=[],
|
|
241
|
+
arg_encode=[
|
|
242
|
+
"g_variant_builder_add_value(&builder, g_variant_new_double(<req><arg_name>));"]),
|
|
243
|
+
"ad": CTypeBase(variant_type="ad",
|
|
244
|
+
write_type="array_double",
|
|
245
|
+
arg_in="gsize n_<arg_name>, <const>gdouble *<arg_name>",
|
|
246
|
+
arg_out="gsize *n_<arg_name>, gdouble **<arg_name>",
|
|
247
|
+
args_write_remote_declear="BUILD_BASIC_TYPE_ARRAY(\"d\", n_<arg_name>, <arg_name>)",
|
|
248
|
+
arg_decode=["ITER_BASIC_TYPE_ARRAY(parameters, arg_id, <req>n_<arg_name>, <req><arg_name>," +
|
|
249
|
+
" double, \"d\");"],
|
|
250
|
+
arg_free=["g_free(<req><arg_name>);"],
|
|
251
|
+
arg_encode=[
|
|
252
|
+
"tmp_v = BUILD_BASIC_TYPE_ARRAY(\"d\", <req>n_<arg_name>, <req><arg_name>);",
|
|
253
|
+
"g_variant_builder_add_value(&builder, tmp_v);"],
|
|
254
|
+
),
|
|
255
|
+
"h": CTypeBase(variant_type="h",
|
|
256
|
+
write_type="handle",
|
|
257
|
+
arg_in="gint32 <arg_name>",
|
|
258
|
+
arg_out="gint32 *<arg_name>",
|
|
259
|
+
args_write_remote_declear="g_variant_new_handle(<arg_name>)",
|
|
260
|
+
arg_decode=[
|
|
261
|
+
"<req><arg_name> = parameter_get_handle(parameters, arg_id);"],
|
|
262
|
+
arg_free=[],
|
|
263
|
+
arg_encode=[
|
|
264
|
+
"g_variant_builder_add_value(&builder, g_variant_new_handle(<req><arg_name>));"]),
|
|
265
|
+
"ah": CTypeBase(variant_type="ah",
|
|
266
|
+
write_type="array_handle",
|
|
267
|
+
arg_in="gsize n_<arg_name>, <const>gint32 *<arg_name>",
|
|
268
|
+
arg_out="gsize *n_<arg_name>, gint32 **<arg_name>",
|
|
269
|
+
args_write_remote_declear="BUILD_BASIC_TYPE_ARRAY(\"h\", n_<arg_name>, <arg_name>)",
|
|
270
|
+
arg_decode=["ITER_BASIC_TYPE_ARRAY(parameters, arg_id, <req>n_<arg_name>, <req><arg_name>," +
|
|
271
|
+
" int32, \"h\");"],
|
|
272
|
+
arg_free=["g_free(<req><arg_name>);"],
|
|
273
|
+
arg_encode=[
|
|
274
|
+
"tmp_v = BUILD_BASIC_TYPE_ARRAY(\"h\", <req>n_<arg_name>, <req><arg_name>);",
|
|
275
|
+
"g_variant_builder_add_value(&builder, tmp_v);"],
|
|
276
|
+
),
|
|
277
|
+
"s": CTypeBase(variant_type="s",
|
|
278
|
+
write_type="string",
|
|
279
|
+
arg_in="<const>gchar *<arg_name>",
|
|
280
|
+
arg_out="gchar **<arg_name>",
|
|
281
|
+
args_write_remote_declear="g_variant_new_string(<arg_name> ? <arg_name> : \"\")",
|
|
282
|
+
arg_decode=[
|
|
283
|
+
"<req><arg_name> = parameter_get_string(parameters, arg_id);"],
|
|
284
|
+
arg_free=["g_free(<req><arg_name>);"],
|
|
285
|
+
arg_encode=[
|
|
286
|
+
"g_variant_builder_add_value(&builder, g_variant_new_string(<req><arg_name>));"]),
|
|
287
|
+
"as": CTypeBase(variant_type="as",
|
|
288
|
+
write_type="array_string",
|
|
289
|
+
arg_in="<const>gchar *<const>*<arg_name>",
|
|
290
|
+
arg_out="gchar ***<arg_name>",
|
|
291
|
+
args_write_remote_declear="BUILD_STRING_TYPE_ARRAY(\"s\", <arg_name>)",
|
|
292
|
+
arg_decode=["ITER_STRING_TYPE_ARRAY(parameters, arg_id, <req><arg_name>, char *, \"s\");"],
|
|
293
|
+
arg_free=["g_strfreev(<req><arg_name>);"],
|
|
294
|
+
arg_encode=[
|
|
295
|
+
"tmp_v = BUILD_STRING_TYPE_ARRAY(\"s\", <req><arg_name>);",
|
|
296
|
+
"g_variant_builder_add_value(&builder, tmp_v);"],
|
|
297
|
+
),
|
|
298
|
+
"g": CTypeBase(variant_type="g",
|
|
299
|
+
write_type="signature",
|
|
300
|
+
arg_in="<const>gchar *<arg_name>",
|
|
301
|
+
arg_out="gchar **<arg_name>",
|
|
302
|
+
args_write_remote_declear="g_variant_new_signature(<arg_name> ? <arg_name> : \"\")",
|
|
303
|
+
arg_decode=[
|
|
304
|
+
"<req><arg_name> = parameter_get_signature(parameters, arg_id);"],
|
|
305
|
+
arg_free=["g_free(<req><arg_name>);"],
|
|
306
|
+
arg_encode=[
|
|
307
|
+
"g_variant_builder_add_value(&builder, g_variant_new_signature(<req><arg_name>));"]),
|
|
308
|
+
"ag": CTypeBase(variant_type="ag",
|
|
309
|
+
write_type="array_signature",
|
|
310
|
+
arg_in="<const>gchar *<const>*<arg_name>",
|
|
311
|
+
arg_out="gchar ***<arg_name>",
|
|
312
|
+
args_write_remote_declear="BUILD_STRING_TYPE_ARRAY(\"g\", <arg_name>)",
|
|
313
|
+
arg_decode=["ITER_STRING_TYPE_ARRAY(parameters, arg_id, <req><arg_name>, char *, \"g\");"],
|
|
314
|
+
arg_free=["g_strfreev(<req><arg_name>);"],
|
|
315
|
+
arg_encode=[
|
|
316
|
+
"tmp_v = BUILD_STRING_TYPE_ARRAY(\"g\", <req><arg_name>);",
|
|
317
|
+
"g_variant_builder_add_value(&builder, tmp_v);"],
|
|
318
|
+
),
|
|
319
|
+
"o": CTypeBase(variant_type="o",
|
|
320
|
+
write_type="object_path",
|
|
321
|
+
arg_in="<const>gchar *<arg_name>",
|
|
322
|
+
arg_out="gchar **<arg_name>",
|
|
323
|
+
args_write_remote_declear="g_variant_new_object_path(<arg_name> ? <arg_name> : \"\")",
|
|
324
|
+
arg_decode=[
|
|
325
|
+
"<req><arg_name> = parameter_get_object_path(parameters, arg_id);"],
|
|
326
|
+
arg_free=["g_free(<req><arg_name>);"],
|
|
327
|
+
arg_encode=[
|
|
328
|
+
"g_variant_builder_add_value(&builder, g_variant_new_object_path(<req><arg_name>));"]),
|
|
329
|
+
"ao": CTypeBase(variant_type="ao",
|
|
330
|
+
write_type="array_object_path",
|
|
331
|
+
arg_in="<const>gchar *<const>*<arg_name>",
|
|
332
|
+
arg_out="gchar ***<arg_name>",
|
|
333
|
+
args_write_remote_declear="BUILD_STRING_TYPE_ARRAY(\"o\", <arg_name>)",
|
|
334
|
+
arg_decode=[
|
|
335
|
+
"ITER_STRING_TYPE_ARRAY(parameters, arg_id, <req><arg_name>, char *, \"o\");"],
|
|
336
|
+
arg_free=["g_strfreev(<req><arg_name>);"],
|
|
337
|
+
arg_encode=[
|
|
338
|
+
"tmp_v = BUILD_STRING_TYPE_ARRAY(\"o\", <req><arg_name>);",
|
|
339
|
+
"g_variant_builder_add_value(&builder, tmp_v);"],
|
|
340
|
+
),
|
|
341
|
+
"*": CTypeBase(variant_type="v",
|
|
342
|
+
write_type="variant",
|
|
343
|
+
arg_in="GVariant *<arg_name>",
|
|
344
|
+
arg_out="GVariant **<arg_name>",
|
|
345
|
+
args_write_remote_declear="g_variant_ref(<arg_name>)",
|
|
346
|
+
arg_decode=[
|
|
347
|
+
"<req><arg_name> = g_variant_get_child_value(parameters, arg_id);"],
|
|
348
|
+
arg_free=["if (<req><arg_name>) {",
|
|
349
|
+
" g_variant_unref(<req><arg_name>);", "}"],
|
|
350
|
+
arg_encode=[
|
|
351
|
+
"g_variant_take_ref(<req><arg_name>);",
|
|
352
|
+
"g_variant_builder_add_value(&builder, <req><arg_name>);"])
|
|
353
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/usr/bin/python3
|
|
2
|
+
# coding: utf-8
|
|
3
|
+
# Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
# openUBMC is licensed under Mulan PSL v2.
|
|
5
|
+
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
6
|
+
# You may obtain a copy of Mulan PSL v2 at:
|
|
7
|
+
# http://license.coscl.org.cn/MulanPSL2
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
9
|
+
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
10
|
+
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
11
|
+
# See the Mulan PSL v2 for more details.
|
|
12
|
+
import subprocess
|
|
13
|
+
import sys
|
|
14
|
+
import os
|
|
15
|
+
from xml.dom import minidom, Node
|
|
16
|
+
from colorama import Fore, Style
|
|
17
|
+
from bmcgo.logger import Logger
|
|
18
|
+
|
|
19
|
+
global log
|
|
20
|
+
log = Logger()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Helper():
|
|
24
|
+
@staticmethod
|
|
25
|
+
def get_node_value(dom: Node, name, default=None):
|
|
26
|
+
node: minidom.Attr = dom.attributes.get(name)
|
|
27
|
+
if node is None:
|
|
28
|
+
if default is None:
|
|
29
|
+
raise Exception("节点分析失败, 终止构建")
|
|
30
|
+
return default
|
|
31
|
+
return node.childNodes[0].nodeValue.strip()
|
|
32
|
+
|
|
33
|
+
@staticmethod
|
|
34
|
+
def get_git_path():
|
|
35
|
+
if os.path.isfile("/usr/bin/git"):
|
|
36
|
+
return "/usr/bin/git"
|
|
37
|
+
elif os.path.isfile("/usr/local/bin/git"):
|
|
38
|
+
return "/usr/local/bin/git"
|
|
39
|
+
elif os.path.isfile("/usr/sbin/git"):
|
|
40
|
+
return "/usr/sbin/git"
|
|
41
|
+
else:
|
|
42
|
+
raise OSError("git 命令未找到, 请检查 git 是否安装或是否安装到系统路径")
|
|
43
|
+
|
|
44
|
+
@staticmethod
|
|
45
|
+
def get_privilege(value):
|
|
46
|
+
splits = value.split(",", -1)
|
|
47
|
+
privilege = []
|
|
48
|
+
for split in splits:
|
|
49
|
+
split = split.strip()
|
|
50
|
+
if split == "UserMgmt":
|
|
51
|
+
privilege.append("PRI_USER_MGMT")
|
|
52
|
+
elif split == "BasicSetting":
|
|
53
|
+
privilege.append("PRI_BASIC_SETTING")
|
|
54
|
+
elif split == "KVMMgmt":
|
|
55
|
+
privilege.append("PRI_KVM_MGMT")
|
|
56
|
+
elif split == "VMMMgmt":
|
|
57
|
+
privilege.append("PRI_VMM_MGMT")
|
|
58
|
+
elif split == "SecurityMgmt":
|
|
59
|
+
privilege.append("PRI_SECURITY_MGMT")
|
|
60
|
+
elif split == "PowerMgmt":
|
|
61
|
+
privilege.append("PRI_POWER_MGMT")
|
|
62
|
+
elif split == "DiagnoseMgmt":
|
|
63
|
+
privilege.append("PRI_DIAGNOSE_MGMT")
|
|
64
|
+
elif split == "ReadOnly":
|
|
65
|
+
privilege.append("PRI_READ_ONLY")
|
|
66
|
+
elif split == "ConfigureSelf":
|
|
67
|
+
privilege.append("PRI_CONFIG_SELF")
|
|
68
|
+
if len(privilege) == 0:
|
|
69
|
+
return "0"
|
|
70
|
+
return " | ".join(privilege)
|
|
71
|
+
|
|
72
|
+
@staticmethod
|
|
73
|
+
def run(cmd, check=True, stderr=sys.stderr, stdout=sys.stdout):
|
|
74
|
+
log.info("开始运行命令: %s %s %s", Fore.GREEN,
|
|
75
|
+
" ".join(cmd), Style.RESET_ALL)
|
|
76
|
+
ret = subprocess.run(cmd, check=check, stderr=stderr, stdout=stdout)
|
|
77
|
+
return ret.returncode
|
|
78
|
+
|
|
79
|
+
@staticmethod
|
|
80
|
+
def string_to_bool(str_value):
|
|
81
|
+
if str_value.lower() == "false":
|
|
82
|
+
return False
|
|
83
|
+
if str_value == "":
|
|
84
|
+
return False
|
|
85
|
+
if str_value == "0":
|
|
86
|
+
return False
|
|
87
|
+
return True
|