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.

Files changed (242) hide show
  1. bmcgo/__init__.py +12 -0
  2. bmcgo/bmcgo.py +22 -0
  3. bmcgo/bmcgo_config.py +176 -0
  4. bmcgo/cli/__init__.py +10 -0
  5. bmcgo/cli/cli.py +584 -0
  6. bmcgo/codegen/__init__.py +14 -0
  7. bmcgo/codegen/c/__init__.py +9 -0
  8. bmcgo/codegen/c/annotation.py +52 -0
  9. bmcgo/codegen/c/argument.py +42 -0
  10. bmcgo/codegen/c/codegen.py +153 -0
  11. bmcgo/codegen/c/comment.py +22 -0
  12. bmcgo/codegen/c/ctype_defination.py +353 -0
  13. bmcgo/codegen/c/helper.py +87 -0
  14. bmcgo/codegen/c/interface.py +63 -0
  15. bmcgo/codegen/c/method.py +82 -0
  16. bmcgo/codegen/c/property.py +180 -0
  17. bmcgo/codegen/c/renderer.py +21 -0
  18. bmcgo/codegen/c/signal.py +64 -0
  19. bmcgo/codegen/c/template/client.c.mako +145 -0
  20. bmcgo/codegen/c/template/client.h.mako +36 -0
  21. bmcgo/codegen/c/template/interface.c.mako +0 -0
  22. bmcgo/codegen/c/template/interface.introspect.xml.mako +99 -0
  23. bmcgo/codegen/c/template/micro_component.c.mako +32 -0
  24. bmcgo/codegen/c/template/public.c.mako +228 -0
  25. bmcgo/codegen/c/template/public.h.mako +128 -0
  26. bmcgo/codegen/c/template/server.c.mako +104 -0
  27. bmcgo/codegen/c/template/server.h.mako +36 -0
  28. bmcgo/codegen/lua/.lua-format +7 -0
  29. bmcgo/codegen/lua/Makefile +101 -0
  30. bmcgo/codegen/lua/__init__.py +9 -0
  31. bmcgo/codegen/lua/codegen.py +171 -0
  32. bmcgo/codegen/lua/proto/Makefile +87 -0
  33. bmcgo/codegen/lua/proto/ipmi_types.proto +17 -0
  34. bmcgo/codegen/lua/proto/types.proto +52 -0
  35. bmcgo/codegen/lua/script/check_intfs.py +161 -0
  36. bmcgo/codegen/lua/script/dto/__init__.py +11 -0
  37. bmcgo/codegen/lua/script/dto/exception.py +53 -0
  38. bmcgo/codegen/lua/script/dto/kepler_abstract.py +47 -0
  39. bmcgo/codegen/lua/script/dto/options.py +33 -0
  40. bmcgo/codegen/lua/script/dto/print_simple.py +19 -0
  41. bmcgo/codegen/lua/script/dto/redfish_api.py +241 -0
  42. bmcgo/codegen/lua/script/dto/url_route.py +195 -0
  43. bmcgo/codegen/lua/script/gen_db_json.py +444 -0
  44. bmcgo/codegen/lua/script/gen_depends.py +89 -0
  45. bmcgo/codegen/lua/script/gen_entry.py +263 -0
  46. bmcgo/codegen/lua/script/gen_feature_json.py +156 -0
  47. bmcgo/codegen/lua/script/gen_historical_local_db_json.py +88 -0
  48. bmcgo/codegen/lua/script/gen_intf_json.py +261 -0
  49. bmcgo/codegen/lua/script/gen_intf_rpc_json.py +575 -0
  50. bmcgo/codegen/lua/script/gen_ipmi_json.py +485 -0
  51. bmcgo/codegen/lua/script/gen_mdb_json.py +117 -0
  52. bmcgo/codegen/lua/script/gen_rpc_msg_json.py +487 -0
  53. bmcgo/codegen/lua/script/gen_schema.py +302 -0
  54. bmcgo/codegen/lua/script/ipmi_types_pb2.py +135 -0
  55. bmcgo/codegen/lua/script/loader/__init__.py +11 -0
  56. bmcgo/codegen/lua/script/loader/file_utils.py +33 -0
  57. bmcgo/codegen/lua/script/loader/kepler_abstract_collect.py +79 -0
  58. bmcgo/codegen/lua/script/loader/kepler_abstract_loader.py +47 -0
  59. bmcgo/codegen/lua/script/loader/redfish_loader.py +127 -0
  60. bmcgo/codegen/lua/script/lua_format.py +62 -0
  61. bmcgo/codegen/lua/script/mds_util.py +385 -0
  62. bmcgo/codegen/lua/script/merge_model.py +330 -0
  63. bmcgo/codegen/lua/script/merge_proto_algo.py +85 -0
  64. bmcgo/codegen/lua/script/proto_loader.py +47 -0
  65. bmcgo/codegen/lua/script/proto_plugin.py +140 -0
  66. bmcgo/codegen/lua/script/redfish_source_tree.py +118 -0
  67. bmcgo/codegen/lua/script/render_utils/__init__.py +38 -0
  68. bmcgo/codegen/lua/script/render_utils/base.py +25 -0
  69. bmcgo/codegen/lua/script/render_utils/client_lua.py +98 -0
  70. bmcgo/codegen/lua/script/render_utils/controller_lua.py +71 -0
  71. bmcgo/codegen/lua/script/render_utils/db_lua.py +224 -0
  72. bmcgo/codegen/lua/script/render_utils/error_lua.py +185 -0
  73. bmcgo/codegen/lua/script/render_utils/factory.py +52 -0
  74. bmcgo/codegen/lua/script/render_utils/ipmi_lua.py +159 -0
  75. bmcgo/codegen/lua/script/render_utils/ipmi_message_lua.py +24 -0
  76. bmcgo/codegen/lua/script/render_utils/mdb_lua.py +177 -0
  77. bmcgo/codegen/lua/script/render_utils/mdb_register.py +215 -0
  78. bmcgo/codegen/lua/script/render_utils/message_lua.py +26 -0
  79. bmcgo/codegen/lua/script/render_utils/messages_lua.py +156 -0
  80. bmcgo/codegen/lua/script/render_utils/model_lua.py +485 -0
  81. bmcgo/codegen/lua/script/render_utils/old_model_lua.py +429 -0
  82. bmcgo/codegen/lua/script/render_utils/plugin_lua.py +38 -0
  83. bmcgo/codegen/lua/script/render_utils/redfish_proto.py +86 -0
  84. bmcgo/codegen/lua/script/render_utils/request_lua.py +76 -0
  85. bmcgo/codegen/lua/script/render_utils/service_lua.py +130 -0
  86. bmcgo/codegen/lua/script/render_utils/utils_message_lua.py +125 -0
  87. bmcgo/codegen/lua/script/render_utils/validate_lua.py +221 -0
  88. bmcgo/codegen/lua/script/sep_ipmi_message_cmds.py +217 -0
  89. bmcgo/codegen/lua/script/template.py +166 -0
  90. bmcgo/codegen/lua/script/types_pb2.py +516 -0
  91. bmcgo/codegen/lua/script/utils.py +663 -0
  92. bmcgo/codegen/lua/script/validate.py +80 -0
  93. bmcgo/codegen/lua/script/yaml_to_json.py +73 -0
  94. bmcgo/codegen/lua/templates/Makefile +114 -0
  95. bmcgo/codegen/lua/templates/apps/Makefile +261 -0
  96. bmcgo/codegen/lua/templates/apps/Makefile.mdb.mk +64 -0
  97. bmcgo/codegen/lua/templates/apps/app.lua.mako +19 -0
  98. bmcgo/codegen/lua/templates/apps/class.lua.mako +35 -0
  99. bmcgo/codegen/lua/templates/apps/client.lua.mako +429 -0
  100. bmcgo/codegen/lua/templates/apps/controller.lua.mako +276 -0
  101. bmcgo/codegen/lua/templates/apps/datas.lua.mako +8 -0
  102. bmcgo/codegen/lua/templates/apps/db.lua.mako +89 -0
  103. bmcgo/codegen/lua/templates/apps/entry.lua.mako +128 -0
  104. bmcgo/codegen/lua/templates/apps/feature.lua.mako +37 -0
  105. bmcgo/codegen/lua/templates/apps/generate_route.mako +25 -0
  106. bmcgo/codegen/lua/templates/apps/impl_feature.lua.mako +72 -0
  107. bmcgo/codegen/lua/templates/apps/ipmi.lua.mako +97 -0
  108. bmcgo/codegen/lua/templates/apps/ipmi_cmd.lua.mako +18 -0
  109. bmcgo/codegen/lua/templates/apps/ipmi_message.lua.mako +36 -0
  110. bmcgo/codegen/lua/templates/apps/local_db.lua.mako +263 -0
  111. bmcgo/codegen/lua/templates/apps/main.lua.mako +25 -0
  112. bmcgo/codegen/lua/templates/apps/mc.lua.mako +77 -0
  113. bmcgo/codegen/lua/templates/apps/mdb.lua.mako +45 -0
  114. bmcgo/codegen/lua/templates/apps/mdb_interface.lua.mako +73 -0
  115. bmcgo/codegen/lua/templates/apps/message.lua.mako +38 -0
  116. bmcgo/codegen/lua/templates/apps/model.lua.mako +239 -0
  117. bmcgo/codegen/lua/templates/apps/orm_classes.lua.mako +16 -0
  118. bmcgo/codegen/lua/templates/apps/plugin.lua.mako +8 -0
  119. bmcgo/codegen/lua/templates/apps/redfish.proto.mako +47 -0
  120. bmcgo/codegen/lua/templates/apps/service.lua.mako +440 -0
  121. bmcgo/codegen/lua/templates/apps/signal_listen.lua.mako +19 -0
  122. bmcgo/codegen/lua/templates/apps/utils/default_intf.lua.mako +41 -0
  123. bmcgo/codegen/lua/templates/apps/utils/enum.mako +10 -0
  124. bmcgo/codegen/lua/templates/apps/utils/imports.mako +13 -0
  125. bmcgo/codegen/lua/templates/apps/utils/mdb_intf.lua.mako +25 -0
  126. bmcgo/codegen/lua/templates/apps/utils/mdb_obj.lua.mako +23 -0
  127. bmcgo/codegen/lua/templates/apps/utils/message.mako +160 -0
  128. bmcgo/codegen/lua/templates/apps/utils/request.lua.mako +59 -0
  129. bmcgo/codegen/lua/templates/apps/utils/validate.mako +83 -0
  130. bmcgo/codegen/lua/templates/errors.lua.mako +36 -0
  131. bmcgo/codegen/lua/templates/messages.lua.mako +32 -0
  132. bmcgo/codegen/lua/templates/new_app/.clang-format.mako +170 -0
  133. bmcgo/codegen/lua/templates/new_app/.gitignore.mako +26 -0
  134. bmcgo/codegen/lua/templates/new_app/CHANGELOG.md.mako +0 -0
  135. bmcgo/codegen/lua/templates/new_app/CMakeLists.txt.mako +29 -0
  136. bmcgo/codegen/lua/templates/new_app/Makefile.mako +25 -0
  137. bmcgo/codegen/lua/templates/new_app/README.md.mako +0 -0
  138. bmcgo/codegen/lua/templates/new_app/conanfile.py.mako +7 -0
  139. bmcgo/codegen/lua/templates/new_app/config.cfg.mako +6 -0
  140. bmcgo/codegen/lua/templates/new_app/mds/model.json.mako +3 -0
  141. bmcgo/codegen/lua/templates/new_app/mds/service.json.mako +21 -0
  142. bmcgo/codegen/lua/templates/new_app/permissions.ini.mako +16 -0
  143. bmcgo/codegen/lua/templates/new_app/src/lualib/${project_name}_app.lua.mako +16 -0
  144. bmcgo/codegen/lua/templates/new_app/src/service/main.lua.mako +25 -0
  145. bmcgo/codegen/lua/templates/new_app/test/integration/test_${project_name}.conf.mako +9 -0
  146. bmcgo/codegen/lua/templates/new_app/test/integration/test_${project_name}.lua.mako +47 -0
  147. bmcgo/codegen/lua/templates/new_app/test/unit/test.lua.mako +23 -0
  148. bmcgo/codegen/lua/templates/new_app/user_conf/rootfs/etc/systemd/system/${project_name}.service.mako +18 -0
  149. bmcgo/codegen/lua/templates/new_app/user_conf/rootfs/etc/systemd/system/multi-user.target.wants/${project_name}.service.link +1 -0
  150. bmcgo/component/__init__.py +10 -0
  151. bmcgo/component/analysis/analysis.py +183 -0
  152. bmcgo/component/analysis/build_deps.py +165 -0
  153. bmcgo/component/analysis/data_deps.py +333 -0
  154. bmcgo/component/analysis/dep-rules.json +912 -0
  155. bmcgo/component/analysis/dep_node.py +110 -0
  156. bmcgo/component/analysis/intf_deps.py +163 -0
  157. bmcgo/component/analysis/intf_validation.py +254 -0
  158. bmcgo/component/analysis/rule.py +211 -0
  159. bmcgo/component/analysis/smc_dfx_whitelist.json +11 -0
  160. bmcgo/component/analysis/sr_validation.py +391 -0
  161. bmcgo/component/build.py +222 -0
  162. bmcgo/component/component_dt_version_parse.py +348 -0
  163. bmcgo/component/component_helper.py +114 -0
  164. bmcgo/component/coverage/__init__.py +11 -0
  165. bmcgo/component/coverage/c_incremental_cov_report.template +53 -0
  166. bmcgo/component/coverage/incremental_cov.py +464 -0
  167. bmcgo/component/deploy.py +110 -0
  168. bmcgo/component/gen.py +169 -0
  169. bmcgo/component/package_info.py +236 -0
  170. bmcgo/component/template/conanbase.py.mako +278 -0
  171. bmcgo/component/template/conanfile.deploy.py.mako +40 -0
  172. bmcgo/component/test.py +947 -0
  173. bmcgo/errors.py +119 -0
  174. bmcgo/frame.py +217 -0
  175. bmcgo/functional/__init__.py +10 -0
  176. bmcgo/functional/analysis.py +96 -0
  177. bmcgo/functional/bmc_studio_action.py +98 -0
  178. bmcgo/functional/check.py +185 -0
  179. bmcgo/functional/conan_index_build.py +251 -0
  180. bmcgo/functional/config.py +332 -0
  181. bmcgo/functional/csr_build.py +724 -0
  182. bmcgo/functional/deploy.py +263 -0
  183. bmcgo/functional/diff.py +235 -0
  184. bmcgo/functional/fetch.py +235 -0
  185. bmcgo/functional/full_component.py +391 -0
  186. bmcgo/functional/maintain.py +381 -0
  187. bmcgo/functional/new.py +166 -0
  188. bmcgo/functional/schema_valid.py +111 -0
  189. bmcgo/functional/simple_sign.py +104 -0
  190. bmcgo/functional/upgrade.py +78 -0
  191. bmcgo/ipmigen/__init__.py +13 -0
  192. bmcgo/ipmigen/ctype_defination.py +82 -0
  193. bmcgo/ipmigen/ipmigen.py +309 -0
  194. bmcgo/ipmigen/template/cmd.c.mako +366 -0
  195. bmcgo/ipmigen/template/ipmi.c.mako +25 -0
  196. bmcgo/ipmigen/template/ipmi.h.mako +51 -0
  197. bmcgo/logger.py +176 -0
  198. bmcgo/misc.py +117 -0
  199. bmcgo/target/app.yml +17 -0
  200. bmcgo/target/install_sdk.yml +15 -0
  201. bmcgo/target/personal.yml +53 -0
  202. bmcgo/target/publish.yml +45 -0
  203. bmcgo/tasks/__init__.py +11 -0
  204. bmcgo/tasks/download_buildtools_hm.py +124 -0
  205. bmcgo/tasks/misc.py +15 -0
  206. bmcgo/tasks/task.py +354 -0
  207. bmcgo/tasks/task_build_conan.py +714 -0
  208. bmcgo/tasks/task_build_rootfs_img.py +595 -0
  209. bmcgo/tasks/task_buildgppbin.py +88 -0
  210. bmcgo/tasks/task_buildhpm_ext4.py +82 -0
  211. bmcgo/tasks/task_create_interface_config.py +122 -0
  212. bmcgo/tasks/task_download_buildtools.py +99 -0
  213. bmcgo/tasks/task_download_dependency.py +72 -0
  214. bmcgo/tasks/task_hpm_envir_prepare.py +112 -0
  215. bmcgo/tasks/task_packet_to_supporte.py +87 -0
  216. bmcgo/tasks/task_prepare.py +105 -0
  217. bmcgo/tasks/task_sign_and_pack_hpm.py +42 -0
  218. bmcgo/utils/__init__.py +10 -0
  219. bmcgo/utils/buffer.py +128 -0
  220. bmcgo/utils/combine_json_schemas.py +170 -0
  221. bmcgo/utils/component_post.py +54 -0
  222. bmcgo/utils/component_version_check.py +86 -0
  223. bmcgo/utils/config.py +1067 -0
  224. bmcgo/utils/fetch_component_code.py +232 -0
  225. bmcgo/utils/install_manager.py +61 -0
  226. bmcgo/utils/installations/__init__.py +10 -0
  227. bmcgo/utils/installations/base_installer.py +70 -0
  228. bmcgo/utils/installations/install_consts.py +30 -0
  229. bmcgo/utils/installations/install_plans/bingo.yml +11 -0
  230. bmcgo/utils/installations/install_workflow.py +50 -0
  231. bmcgo/utils/installations/installers/apt_installer.py +177 -0
  232. bmcgo/utils/installations/installers/pip_installer.py +46 -0
  233. bmcgo/utils/installations/version_util.py +100 -0
  234. bmcgo/utils/mapping_config_patch.py +443 -0
  235. bmcgo/utils/perf_analysis.py +114 -0
  236. bmcgo/utils/tools.py +704 -0
  237. bmcgo/worker.py +417 -0
  238. openubmc_bingo-0.5.240.dist-info/METADATA +30 -0
  239. openubmc_bingo-0.5.240.dist-info/RECORD +242 -0
  240. openubmc_bingo-0.5.240.dist-info/WHEEL +5 -0
  241. openubmc_bingo-0.5.240.dist-info/entry_points.txt +2 -0
  242. openubmc_bingo-0.5.240.dist-info/top_level.txt +1 -0
bmcgo/cli/cli.py ADDED
@@ -0,0 +1,584 @@
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 argparse
13
+ import inspect
14
+ import os
15
+ import signal
16
+ import sys
17
+ import textwrap
18
+ import importlib
19
+ import stat
20
+ import json
21
+ import re
22
+ import traceback
23
+ from importlib.util import spec_from_file_location, module_from_spec
24
+
25
+ import yaml
26
+ from colorama import Fore, Style
27
+
28
+ from bmcgo import __version__ as client_version
29
+ from bmcgo.component.build import BuildComp
30
+ from bmcgo.component.test import TestComp
31
+ from bmcgo.component.deploy import DeployComp
32
+ from bmcgo.component.gen import GenComp
33
+ from bmcgo import errors
34
+ from bmcgo import misc
35
+ from bmcgo.logger import Logger
36
+ from bmcgo.frame import Frame
37
+ from bmcgo.bmcgo_config import BmcgoConfig
38
+ from bmcgo.utils.tools import Tools
39
+ from bmcgo.utils.config import Config
40
+
41
+ cwd = os.getcwd()
42
+ tools = Tools()
43
+ log = tools.log
44
+
45
+ SKIP_CONFIG_COMMANDS = ("config")
46
+
47
+
48
+ class Command(object):
49
+ """A single command of the bmcgo application, with all the first level commands. Manages the
50
+ parsing of parameters and delegates functionality in collaborators. It can also show the
51
+ help of the tool.
52
+ """
53
+ def __init__(self):
54
+ self.bconfig = BmcgoConfig()
55
+ # 请使用_get_command_group获取命令组
56
+ self._command_group = None
57
+ self.comp_cmds = {
58
+ misc.BUILD: misc.BUILD,
59
+ misc.DEPLOY: misc.DEPLOY,
60
+ misc.TEST: misc.TEST,
61
+ misc.GEN: misc.GEN
62
+ }
63
+
64
+ self.inte_cmds = {
65
+ misc.BUILD: misc.BUILD,
66
+ "publish": "inte_publish",
67
+ }
68
+ self.misc_cmds = {
69
+ misc.HELP: misc.HELP
70
+ }
71
+
72
+ self.studio_cmds = {
73
+ }
74
+
75
+ self.conan_idx_cmds = {
76
+ }
77
+
78
+ self.ibmc_sdk_cmds = {
79
+ }
80
+
81
+ self.cmd_info_dict = {
82
+ misc.GRP_MISC: self.misc_cmds,
83
+ misc.GRP_COMP: self.comp_cmds,
84
+ misc.GRP_INTE: self.inte_cmds,
85
+ misc.GRP_STUDIO: self.studio_cmds,
86
+ misc.GRP_CONAN_IDX: self.conan_idx_cmds,
87
+ misc.GRP_IBMC_SDK: self.ibmc_sdk_cmds
88
+ }
89
+
90
+ @property
91
+ def __is_valid_component(self):
92
+ return self.bconfig.component is not None
93
+
94
+ @staticmethod
95
+ def _match_command(comm_key: str, command, is_full_match: bool):
96
+ if is_full_match and comm_key == command:
97
+ return True
98
+ elif not is_full_match and comm_key.startswith(command):
99
+ return True
100
+ return False
101
+
102
+ @staticmethod
103
+ def _import_from_path(module_name, file_path):
104
+ """"从指定路径动态导入模块"""
105
+ # 创建模块规范
106
+ spec = spec_from_file_location(module_name, file_path)
107
+ if not spec:
108
+ raise ImportError(f"无法从路径{file_path}导入模块{module_name}")
109
+ # 创建新模块
110
+ module = module_from_spec(spec)
111
+ # 添加到sys.modules缓存
112
+ sys.modules[module_name] = module
113
+ # 执行模块代码
114
+ spec.loader.exec_module(module)
115
+ return module
116
+
117
+ def frame_build(self, args=None):
118
+ _, work_dir = self._is_integrated_project()
119
+ os.chdir(work_dir)
120
+ config = Config(self.bconfig)
121
+ frame = Frame(self.bconfig, config)
122
+ frame.parse(args)
123
+ return frame.run()
124
+
125
+ def help(self, *args):
126
+ """
127
+ 获取命令帮助
128
+ """
129
+
130
+ parser = argparse.ArgumentParser(description=self.help.__doc__,
131
+ prog="bingo help")
132
+ parser.add_argument("command", help='command', nargs="?")
133
+ args = parser.parse_args(*args)
134
+ if not args.command:
135
+ self._show_help()
136
+ return
137
+ try:
138
+ commands = self._commands(False)
139
+ method = commands[args.command]
140
+ self._warn_python_version()
141
+ method(["--help"])
142
+ except KeyError as exp:
143
+ log.debug("Exception: %s", str(exp))
144
+ raise errors.BmcGoException("未知命令 '%s'" % args.command) from exp
145
+
146
+ def gen(self, *args):
147
+ """
148
+ 代码自动生成,支持Lua和C语言,C组件需要在service.json中添加`"language": "c",`配置.
149
+
150
+ 支持自动生成服务端和客户端C代码
151
+ """
152
+ argv = args[0]
153
+ # 未指定参数时,使用mds/service.json的配置
154
+ if "-i" not in argv and "-s" not in argv:
155
+ if os.path.isfile("mds/service.json"):
156
+ argv.append("-s")
157
+ argv.append("mds/service.json")
158
+ gen = GenComp(argv)
159
+ gen.run()
160
+
161
+ # build package
162
+ def build(self, *args):
163
+ """
164
+ 构建出包
165
+
166
+ 组件需要支持多种跨平台构建场景,典型的包括DT(X86-64)、交叉编译(arm64)
167
+ """
168
+ argv = args[0]
169
+ is_integrated, _ = self._is_integrated_project()
170
+ if is_integrated:
171
+ return self.frame_build(argv)
172
+ is_valid_component = self.__is_valid_component
173
+ if is_valid_component:
174
+ os.chdir(self.bconfig.component.folder)
175
+ build = BuildComp(self.bconfig, argv)
176
+ build.run()
177
+ os.chdir(cwd)
178
+ log.success("构建成功")
179
+ else:
180
+ log.error('注意:检测到当前目录即不是合法的组件(Component)目录也不是合法的产品(Manifest)目录')
181
+ return -1
182
+ return 0
183
+
184
+ def inte_publish(self, *args):
185
+ """
186
+ 构建版本发布包,-sc参数指定ToSupportE编码
187
+
188
+ 版本构建
189
+ """
190
+ is_integrated, _ = self._is_integrated_project()
191
+ if not is_integrated:
192
+ raise errors.NotIntegrateException("检测到当前环境中缺少frame.py,可能不是一个合法的manniest仓")
193
+ args = args[0]
194
+ args.append("-t")
195
+ args.append("publish")
196
+ return self.frame_build(args)
197
+
198
+ # test package
199
+ def test(self, *args):
200
+ """
201
+ 构建DT.
202
+
203
+ 组件DT用例执行
204
+ """
205
+ argv = args[0]
206
+ if self.__is_valid_component:
207
+ test = TestComp(self.bconfig, argv)
208
+ test.run()
209
+ else:
210
+ log.error("这可能是一个无效的 bingo 组件, 因为 mds/service.json 文件不存在, 构建终止")
211
+
212
+ # deploy package
213
+ def deploy(self, *args):
214
+ """
215
+ 将组件及其依赖部署至temp/rootfs目录
216
+ """
217
+ if not self.__is_valid_component:
218
+ log.error("这可能是一个无效的 bingo 组件, 因为 mds/service.json 文件不存在, 构建终止")
219
+ return -1
220
+ log.info("安装 package 目录到 ./temp, 开始!")
221
+ argv = args[0]
222
+
223
+ # 构建组件
224
+ build = BuildComp(self.bconfig, argv)
225
+ build.run()
226
+ os.chdir(cwd)
227
+ log.success("构建成功")
228
+ # 部署组件
229
+ deploy = DeployComp(self.bconfig, build.info)
230
+ deploy.run()
231
+ os.chdir(cwd)
232
+ log.success("部署 package 目录到 ./temp 成功!")
233
+ return 0
234
+
235
+ def run(self, *args):
236
+ """HIDDEN: entry point for executing commands, dispatcher to class
237
+ methods
238
+ """
239
+ try:
240
+ command = args[0][0]
241
+ except IndexError: # No parameters
242
+ self._show_help()
243
+ return 0
244
+ try:
245
+ if command in ["-v", "--version"]:
246
+ self._show_version()
247
+ return 0
248
+
249
+ self._warn_python_version()
250
+
251
+ if command in ["-h", "--help"]:
252
+ self._show_help()
253
+ return 0
254
+ valid_command = self._find_real_command(command)
255
+ # 命令参数
256
+ command_args = args[0][1:]
257
+ if isinstance(valid_command, misc.CommandInfo):
258
+ if ("-h" in command_args or "--help" in command_args) and valid_command.help_info is not None:
259
+ self._show_help_data("", valid_command.help_info)
260
+ return 0
261
+
262
+ module = valid_command.module(self.bconfig, command_args)
263
+ self._init_bmcgo_environ(valid_command.name)
264
+ return module.run()
265
+ elif isinstance(valid_command, str):
266
+ commands = self._commands(True)
267
+ method = commands.get(valid_command)
268
+ if method:
269
+ self._init_bmcgo_environ(valid_command)
270
+ return method(command_args)
271
+
272
+ except SystemExit as exc:
273
+ if exc.code != 0:
274
+ log.error("构建已退出, 退出码为: %d", exc.code)
275
+ return exc.code
276
+ except errors.ExitOk as exc:
277
+ log.info(str(exc))
278
+ return 0
279
+ except (errors.BmcGoException, errors.EnvironmentException, KeyboardInterrupt) as exc:
280
+ log.error(str(exc))
281
+ log.error("请查看日志信息")
282
+ return -1
283
+ except Exception as exc:
284
+ if os.environ.get("LOG"):
285
+ log.error(traceback.format_exc())
286
+ msg = str(exc)
287
+ log.error(msg)
288
+ log.error("请查看日志信息")
289
+ return -1
290
+ log.error("'%s' 不是 bingo 命令. 使用 'bingo -h' 查看帮助文档", command)
291
+ return -1
292
+
293
+ def _init_bmcgo_environ(self, command):
294
+ if command not in SKIP_CONFIG_COMMANDS and misc.ENV_CONST in self.bconfig.bmcgo_config_list:
295
+ log.info("检测到配置项环境变量,开始使用")
296
+ for env, value in self.bconfig.bmcgo_config_list[misc.ENV_CONST].items():
297
+ log.info("环境变量%s配置为: %s", env, value)
298
+ if os.environ.get(env.upper()):
299
+ os.environ[env.upper()] = value
300
+ os.environ[env.lower()] = value
301
+
302
+ def _find_real_command(self, command):
303
+ if command == misc.HELP:
304
+ return misc.HELP
305
+ # 全词匹配
306
+ full_match_command = self._match_real_command(command)
307
+ if full_match_command:
308
+ return full_match_command
309
+ # 前缀匹配
310
+ start_match_command = self._match_real_command(command, False)
311
+ if start_match_command:
312
+ return start_match_command
313
+ raise errors.CommandNotFoundException(f"未找到命令: {command}, 请执行bingo -h检查支持的命令")
314
+
315
+ def _match_real_command(self, command, is_full_match=True):
316
+ is_integrated, _ = self._is_integrated_project()
317
+ for group_name, comm_names in self._get_command_group():
318
+ is_component_valid = group_name.startswith("Component") and self.__is_valid_component
319
+ is_integrated_valid = group_name.startswith("Integrated") and is_integrated
320
+ is_conan_idx_valid = group_name.startswith("Conan Index") and self.bconfig.conan_index
321
+ is_ibmc_sdk_valid = group_name.startswith("SDK") and self.bconfig.ibmc_sdk
322
+ is_misc_valid = group_name.startswith("Misc")
323
+ is_studio_valid = group_name.startswith("Studio")
324
+ is_group_valid = is_component_valid or is_integrated_valid or is_misc_valid \
325
+ or is_studio_valid or is_conan_idx_valid or is_ibmc_sdk_valid
326
+ for name, real_method in comm_names.items():
327
+ if (is_group_valid and self._match_command(name, command, is_full_match)):
328
+ return real_method
329
+ return None
330
+
331
+ def _show_version(self):
332
+ log.info("bingo 版本为: %s", client_version)
333
+ studio_version = self._bmc_studio_version()
334
+ if studio_version:
335
+ log.info("bmc-studio 版本为: %s", studio_version)
336
+
337
+ def _bmc_studio_version(self):
338
+ """检查当前环境中正在使用的bmc studio版本,
339
+ 优先通过pip获取,获取不到通过bmc_studio/mds/server获取
340
+ """
341
+ package_info = tools.run_command('pip3 show hw_ibmc_bmc_studio', sudo=True,
342
+ command_echo=False, ignore_error=True, capture_output=True)
343
+ version = ""
344
+ if package_info:
345
+ version = package_info.stdout.replace("\n", " ")
346
+ match = re.match(r".*([0-9]+\.[0-9]+\.[0-9]+)", version)
347
+ if match:
348
+ return match.group(1)
349
+ studio_path = tools.get_studio_path()
350
+ bmc_studio_conf = os.path.join(f"{studio_path}/mds/service.json")
351
+ if not os.path.isfile(bmc_studio_conf):
352
+ return ""
353
+
354
+ with open(bmc_studio_conf, "r") as conf_fp:
355
+ conf_data = json.load(conf_fp)
356
+ if "version" not in conf_data:
357
+ return ""
358
+
359
+ return conf_data["version"]
360
+
361
+ def _gen_command_group(self):
362
+ self._command_group = []
363
+ self._command_group.append((misc.GRP_INTE, self.inte_cmds))
364
+ self._command_group.append((misc.GRP_COMP, self.comp_cmds))
365
+ self._command_group.append((misc.GRP_CONAN_IDX, self.conan_idx_cmds))
366
+ self._command_group.append((misc.GRP_IBMC_SDK, self.ibmc_sdk_cmds))
367
+ self._command_group.append((misc.GRP_MISC, self.misc_cmds))
368
+ self._command_group.append((misc.GRP_STUDIO, self.studio_cmds))
369
+ return self._command_group
370
+
371
+ def _load_functional(self, functional_path):
372
+ for file in os.listdir(functional_path):
373
+ if file.startswith("_"):
374
+ continue
375
+
376
+ file = os.path.join(functional_path, file)
377
+ if not os.path.isfile(file) or not file.endswith(".py"):
378
+ log.debug(f"{file} 不是一个目录或者不是以 .py 结尾的文件, 继续")
379
+ continue
380
+
381
+ module_name = os.path.basename(file)[:-3]
382
+ try:
383
+ # 先尝试卸载旧模块
384
+ if module_name in sys.modules:
385
+ del sys.modules[module_name]
386
+ # 使导入缓存失效
387
+ importlib.invalidate_caches()
388
+ module = self._import_from_path(module_name, file)
389
+ availabile_check = getattr(module, "if_available", None)
390
+ if availabile_check is None:
391
+ log.debug(f"方法 if_available 没有找到, 跳过 {module_name}")
392
+ continue
393
+ if not availabile_check(self.bconfig):
394
+ log.debug(f"方法 if_available 返回 false, 跳过 {module_name}")
395
+ continue
396
+ cmd_info: misc.CommandInfo = getattr(module, "command_info", None)
397
+ if cmd_info is None:
398
+ log.debug(f"属性 command_info 没找到, 跳过 {module_name}")
399
+ continue
400
+ cmd_info.module = getattr(module, "BmcgoCommand", None)
401
+ if cmd_info.module is None:
402
+ log.debug(f"类 BmcgoCommand 没找到, 跳过 {module_name}")
403
+ continue
404
+
405
+ if cmd_info.group in self.cmd_info_dict:
406
+ cmds = self.cmd_info_dict.get(cmd_info.group)
407
+ cmds[cmd_info.name] = cmd_info
408
+ else:
409
+ raise errors.ConfigException(f"未支持的组 {cmd_info.group}, 无法获取")
410
+ except ModuleNotFoundError:
411
+ log.info(f"导入模块 {module_name} 失败")
412
+
413
+ def _gen_command_group_base(self):
414
+ if not self.bconfig.partner_mode:
415
+ self.inte_cmds[misc.ANALYSIS] = misc.ANALYSIS
416
+ self._load_functional(self.bconfig.functional_path)
417
+
418
+ def _get_command_group(self):
419
+ if self._command_group:
420
+ return self._command_group
421
+ self._gen_command_group_base()
422
+ return self._gen_command_group()
423
+
424
+ def _show_command_help(self, commands, name, real_method):
425
+ # future-proof way to ensure tabular formatting
426
+ fmt = ' %s'
427
+ if len(name) > 16:
428
+ cmd_name = (fmt % (Fore.GREEN + name[:16] + Style.RESET_ALL))
429
+ else:
430
+ cmd_name = (fmt % (Fore.GREEN + name + Style.RESET_ALL))
431
+
432
+ if len(cmd_name) < 32:
433
+ space = " " * (32 - len(cmd_name))
434
+ cmd_name += space
435
+
436
+ if isinstance(real_method, str):
437
+ command = commands.get(real_method)
438
+ if command is None:
439
+ return
440
+ # Help will be all the lines up to the first empty one
441
+ docstring_lines = command.__doc__.split('\n')
442
+ elif isinstance(real_method, misc.CommandInfo):
443
+ if not log.is_debug and real_method.hidden:
444
+ return
445
+ docstring_lines = real_method.description
446
+ else:
447
+ return
448
+ data = self._doc_append(docstring_lines)
449
+ if len(name) > 16:
450
+ data.insert(0, name)
451
+ self._show_help_data(cmd_name, data)
452
+
453
+ def _show_help(self):
454
+ """
455
+ Prints a summary of all commands.
456
+ """
457
+
458
+ commands = self._commands()
459
+ for group_name, comm_names in self._get_command_group():
460
+ if not comm_names:
461
+ continue
462
+ if group_name == misc.GRP_INTE and not self.bconfig.manifest:
463
+ continue
464
+ if group_name == misc.GRP_COMP and not self.bconfig.component:
465
+ continue
466
+ log.info(group_name)
467
+ for name, real_method in comm_names.items():
468
+ self._show_command_help(commands, name, real_method)
469
+
470
+ log.info("")
471
+ if self.bconfig.manifest is None and self.bconfig.component is None:
472
+ log.warning("未找到 .bmcgo/config或mds/service.json 配置文件, 当前路径可能未包含bingo项目")
473
+ return
474
+ log.info('输入 "bingo <command> -h" 获取子命令帮助')
475
+
476
+ def _doc_append(self, lines):
477
+ start = False
478
+ data = []
479
+ for line in lines:
480
+ line = line.strip()
481
+ if not line:
482
+ if start:
483
+ break
484
+ start = True
485
+ continue
486
+ data.append(line)
487
+ return data
488
+
489
+ def _commands(self, show_hidden=False):
490
+ """ Returns a list of available commands.
491
+ """
492
+ result = {}
493
+ for member in inspect.getmembers(self, predicate=inspect.ismethod):
494
+ method_name = member[0]
495
+ if not method_name.startswith('_'):
496
+ method = member[1]
497
+ if method.__doc__ and (show_hidden or not method.__doc__.startswith('HIDDEN')):
498
+ result[method_name] = method
499
+ return result
500
+
501
+ def _warn_python_version(self):
502
+ width = 70
503
+ version = sys.version_info
504
+ if version.major < 3:
505
+ log.info("%s\n 不在提供 Python 2支持. 强烈推荐使用 Python >= 3.0\n", "*" * width)
506
+
507
+ def _show_help_data(self, cmd_name, help_lines):
508
+ log.info("%s%s", cmd_name, help_lines[0])
509
+ for help_line in help_lines[1:]:
510
+ split_lines = textwrap.wrap(help_line, 80)
511
+ for split_line in split_lines:
512
+ log.info(" %s", split_line)
513
+
514
+ def _is_integrated_project(self):
515
+ if os.path.isfile("build/frame.py"):
516
+ return True, os.getcwd()
517
+ if os.path.isfile("frame.py"):
518
+ return True, os.path.realpath(os.path.join(os.getcwd(), ".."))
519
+ if self.bconfig.manifest is not None:
520
+ return True, self.bconfig.manifest.folder
521
+ return False, None
522
+
523
+
524
+ def prepare_conan():
525
+ home = os.environ["HOME"]
526
+ settings_yml = os.path.join(home, ".conan", "settings.yml")
527
+ if not os.path.isfile(settings_yml):
528
+ return
529
+ with open(settings_yml, mode="r") as fp:
530
+ config_data = yaml.safe_load(fp)
531
+ gcc = config_data["compiler"].get("gcc")
532
+ if gcc.get("luajit") is None:
533
+ config_data["compiler"]["gcc"]["luajit"] = [
534
+ None, "1.7.x"
535
+ ]
536
+ if "Dt" not in config_data["build_type"]:
537
+ config_data["build_type"].append("Dt")
538
+ hm_os = "HongMeng"
539
+ if hm_os not in config_data["os_target"]:
540
+ config_data["os_target"].append(hm_os)
541
+ if config_data["os"].get(hm_os) is None:
542
+ config_data["os"][hm_os] = None
543
+ with os.fdopen(os.open(settings_yml, os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
544
+ stat.S_IWUSR | stat.S_IRUSR), 'w+') as file_handler:
545
+ file_handler.write(yaml.safe_dump(config_data, indent=2, sort_keys=False))
546
+
547
+
548
+ def main(args):
549
+ """ main entry point of the bmcgo application, using a Command to
550
+ parse parameters
551
+ """
552
+
553
+ def ctrl_c_handler(_, __):
554
+ log.info('你按下了 Ctrl+C! 构建终止!')
555
+ sys.exit(-3)
556
+
557
+ def sigterm_handler(_, __):
558
+ log.info('接收到信号 SIGTERM! 构建终止!')
559
+ sys.exit(-5)
560
+
561
+ def ctrl_break_handler(_, __):
562
+ log.info('你按下了 Ctrl+Break! 构建终止!')
563
+ sys.exit(-4)
564
+
565
+ signal.signal(signal.SIGINT, ctrl_c_handler)
566
+ signal.signal(signal.SIGTERM, sigterm_handler)
567
+
568
+ if sys.platform == 'win32':
569
+ signal.signal(signal.SIGBREAK, ctrl_break_handler)
570
+
571
+ try:
572
+ prepare_conan()
573
+ command = Command()
574
+ error = command.run(args)
575
+ except errors.ExitOk as exc:
576
+ log.info(str(exc))
577
+ error = 0
578
+ except Exception as exc:
579
+ if os.environ.get("LOG"):
580
+ log.error(traceback.format_exc())
581
+ msg = str(exc)
582
+ log.error(msg)
583
+ error = -1
584
+ return error
@@ -0,0 +1,14 @@
1
+ # coding: utf-8
2
+ # Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
+ # openUBMC is licensed under Mulan PSL v2.
4
+ # You can use this software according to the terms and conditions of the Mulan PSL v2.
5
+ # You may obtain a copy of Mulan PSL v2 at:
6
+ # http://license.coscl.org.cn/MulanPSL2
7
+ # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
8
+ # EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
9
+ # MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
10
+ # See the Mulan PSL v2 for more details.
11
+
12
+ # 非常重要,修改bmcgo后如果自动生成代码有变更的,必须变更__version__字段
13
+ # 该版本号会传入mako渲染,在自动生成变更时需要做到向下兼容,确保代码自动生成功能OK
14
+ __version__ = 18
@@ -0,0 +1,9 @@
1
+ # Copyright (c) 2024 Huawei Technologies Co., Ltd.
2
+ # openUBMC is licensed under Mulan PSL v2.
3
+ # You can use this software according to the terms and conditions of the Mulan PSL v2.
4
+ # You may obtain a copy of Mulan PSL v2 at:
5
+ # http://license.coscl.org.cn/MulanPSL2
6
+ # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7
+ # EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8
+ # MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9
+ # See the Mulan PSL v2 for more details.
@@ -0,0 +1,52 @@
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.helper import Helper
15
+ from bmcgo.logger import Logger
16
+
17
+ log = Logger("c_annotation")
18
+
19
+
20
+ class AnnotationBase():
21
+ def __init__(self, name, value):
22
+ self.name = name
23
+ self.value = value
24
+ self.comment = Comment()
25
+
26
+ @property
27
+ def deprecated(self):
28
+ if self.name == "bmc.kepler.annotition.Deprecated":
29
+ return False if (self.value.lower() == "false" or self.value.lower() == "0") else True
30
+ else:
31
+ return False
32
+
33
+ def is_private(self):
34
+ return self.name == "bmc.kepler.annotition.Property.Private" and self.value.lower() == "true"
35
+
36
+ def is_emit_changed_signal(self):
37
+ return self.name == "org.freedesktop.DBus.Property.EmitsChangedSignal"
38
+
39
+
40
+ class Annotation(AnnotationBase):
41
+ def __init__(self, node: Node, comment, prefix: str = ""):
42
+ prefix += " "
43
+ self.node = node
44
+ name = Helper.get_node_value(node, "name")
45
+ value = Helper.get_node_value(node, "value")
46
+ super(Annotation, self).__init__(name, value)
47
+ self.comment = comment or Comment()
48
+ if self.name is None:
49
+ log.error("注释缺少 'name' 属性")
50
+ if self.value is None:
51
+ log.error("注释 %s 缺少 'value' 属性" % ("self.name"))
52
+ log.debug("%s 注释, 名字: %s, 值: %s" % (prefix, self.name, self.value))