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
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env python
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
+ 功 能:buildgppbin脚本,该脚本 make pme jffs2 cramfs gpp bin image
14
+ 版权信息:华为技术有限公司,版本所有(C) 2019-2020
15
+ """
16
+
17
+ import os
18
+ import re
19
+ import shutil
20
+
21
+ from bmcgo.tasks.task import Task
22
+ from bmcgo import errors
23
+ from bmcgo import misc
24
+
25
+
26
+ class TaskClass(Task):
27
+ def copy_files(self):
28
+ # 复制gpp需要使用的文件,记录rootfs.img、rootfs.img.cms、cms.crl、rootca.der、Hi1711_boot_4096.bin、Hi1711_boot_pmode.bin共六个文件
29
+ files = self.get_manufacture_config(f"gpp/files")
30
+ if files is None:
31
+ raise errors.BmcGoException("获取 manifest.yml 中 gpp 配置失败, 退出码: -1")
32
+ # 复制构建emmc gpp镜像所需的文件
33
+ self.copy_manifest_files(files)
34
+
35
+ def copy_gpp_headers_files(self):
36
+ files = self.get_manufacture_config(f"gpp/pkg_headers")
37
+ if files is None:
38
+ if self.config.chip != "1711":
39
+ raise errors.BmcGoException("获取 manifest.yml 中 gpp/pkg_headers 配置失败, 退出码: -1")
40
+ else:
41
+ files = []
42
+ files.append({"file": "/usr/local/bin/hpm_header.config", "dst": "hpm_header.config"})
43
+ self.copy_manifest_files(files)
44
+
45
+ def build_gpp_hpm_bin(self):
46
+ self.info("构建 gpp 二进制文件")
47
+ self.chdir(self.config.hpm_build_dir)
48
+ self.copy_files()
49
+ self.copy_gpp_headers_files()
50
+
51
+ # 复制cms.crl
52
+ self.run_command("gpp_header hpm")
53
+
54
+ if not os.path.exists("hpm_top_header"):
55
+ raise errors.BmcGoException(f"hpm_top_header 不存在 ! 创建 hpm_sub_header 失败!")
56
+
57
+ if not os.path.exists("hpm_sub_header"):
58
+ raise errors.BmcGoException(f"hpm_sub_header 不存在 ! 创建 hpm_sub_header 失败!")
59
+
60
+ if self.config.chip == "1711":
61
+ pmode_file = "Hi1711_boot_pmode.bin "
62
+ else:
63
+ pmode_file = ""
64
+
65
+
66
+ self.info(f"打包: {self.config.board_name}_gpp.bin")
67
+ cmd = f"ls -al hpm_top_header Hi1711_boot_4096.bin {pmode_file}"
68
+ cmd += "hpm_sub_header rootca.der rootfs_BMC.img.cms cms.crl rootfs_BMC.tar.gz"
69
+ self.run_command(cmd, show_log=True)
70
+
71
+ target_path = f"{self.config.work_out}/{self.config.board_name}_gpp.bin"
72
+ cmd = f"cat hpm_top_header Hi1711_boot_4096.bin {pmode_file}"
73
+ cmd += "hpm_sub_header rootca.der rootfs_BMC.img.cms cms.crl rootfs_BMC.tar.gz"
74
+ self.info("执行命令: " + cmd)
75
+ self.pipe_command([cmd], target_path)
76
+
77
+ def run(self):
78
+ self._move_dependency()
79
+ self.build_gpp_hpm_bin()
80
+ self.info(f"目录 {self.config.work_out} 包含文件:\n{os.listdir(self.config.work_out)}")
81
+
82
+ def _move_dependency(self):
83
+ # 移动到tools/build_tools目录中
84
+ self.chdir(self.config.sdk_path)
85
+ if self.config.chip == "1711":
86
+ self.run_command(f"dd if=Hi1711_boot_4096_pmode.bin of=Hi1711_boot_pmode.bin bs=1k count=1024 skip=768")
87
+ self.run_command(f"dd if=Hi1711_boot_4096_pmode_debug.bin of=Hi1711_boot_pmode_debug.bin bs=1k " +
88
+ "count=1024 skip=768")
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env python
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
+ 文件名:buildhpm_ext4.py
15
+ 功能:编译生成 hpm 包
16
+ 输入参数:板名 board_name
17
+ 调用方法:python3 -B buildhpm_ext4.py -b board_name -l support_list(-l 可选)
18
+ 版权信息:华为技术有限公司,版本所有(C) 2019-2020
19
+ """
20
+
21
+ import os
22
+ import stat
23
+ import shutil
24
+ import subprocess
25
+ from bmcgo.tasks.task import Task
26
+
27
+
28
+ class TaskClass(Task):
29
+ def __init__(self, config, work_name=""):
30
+ super(TaskClass, self).__init__(config, work_name)
31
+
32
+ def create_empty_text_file(self, file_name):
33
+ with os.fdopen(os.open(file_name, os.O_RDWR | os.O_CREAT | os.O_TRUNC,
34
+ stat.S_IWUSR | stat.S_IRUSR), 'w+') as file_fp:
35
+ file_fp.close
36
+
37
+ def exit_with_create_flag(self, board_name):
38
+ flag_file = f"{self.config.temp_path}/buildhpm_flag_{board_name}"
39
+ if not os.path.isfile(flag_file):
40
+ self.create_empty_text_file(flag_file)
41
+
42
+ def build_hpm(self, board_name):
43
+ self.chdir(self.config.hpm_build_dir)
44
+ self.info(f"构建 {board_name} hpm 包...")
45
+ cmd = f"ls -al {self.config.work_out}/{board_name}_gpp.bin"
46
+ self.run_command(cmd)
47
+ cmd = f"./packethpm_ext4.sh {self.config.work_out}/{board_name}_gpp.bin hpm_ipmc_ext4.config"
48
+ self.run_command(cmd)
49
+ cmd = f"mv ipmc-crypt-image.hpm {self.config.work_out}/rootfs_{board_name}.hpm -f"
50
+ self.run_command(cmd)
51
+
52
+ self.info("hpm 构建成功 !!")
53
+ self.exit_with_create_flag(board_name)
54
+ return
55
+
56
+ def sign(self, filelist, hpm_file):
57
+ self.chdir(self.config.work_out)
58
+ digest = self.get_manufacture_config("base/signature/hpm_digest", ["sha256"])
59
+ with os.fdopen(os.open(filelist, os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
60
+ stat.S_IWUSR | stat.S_IRUSR), 'w') as f:
61
+ f.write('Manifest Version: 1.0\n')
62
+ f.write('Create By: openUBMC\n')
63
+ f.write(f'Name: {hpm_file}\n')
64
+ if "sha256" in digest:
65
+ sha256sum = shutil.which("sha256sum")
66
+ cmd = [sha256sum, hpm_file]
67
+ sha = subprocess.run(cmd, capture_output=True).stdout.decode().strip('\n').split(" ")[0]
68
+ f.write(f"SHA256-Digest: {sha}\n")
69
+ if "sha512" in digest:
70
+ sha512sum = shutil.which("sha512sum")
71
+ cmd = [sha512sum, hpm_file]
72
+ sha = subprocess.run(cmd, capture_output=True).stdout.decode().strip('\n').split(" ")[0]
73
+ f.write(f"SHA512-Digest: {sha}\n")
74
+
75
+ def sign_filelist(self):
76
+ hpm_file_list = os.path.join(self.config.work_out, f'rootfs_{self.config.board_name}.filelist')
77
+ self.sign(hpm_file_list, f'rootfs_{self.config.board_name}.hpm')
78
+ self.info(f"构建 {self.config.board_name} hpm 包结束 !")
79
+
80
+ def run(self):
81
+ self.build_hpm(self.config.board_name)
82
+ self.sign_filelist()
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env python
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
+ import os
14
+ import shutil
15
+ from functools import wraps
16
+ from bmcgo.utils.config import Config
17
+ from bmcgo.tasks.task import Task
18
+ from bmcgo.utils.mapping_config_patch import MappingConfigGenerate
19
+ from bmcgo import misc
20
+
21
+
22
+ class TaskClass(Task):
23
+ def __init__(self, config: Config, work_name=""):
24
+ super(TaskClass, self).__init__(config, work_name)
25
+ self.interface_config_path = os.path.join(os.path.dirname(self.config.inner_path), "interface_config")
26
+ self.product_path = os.path.join(self.interface_config_path, "Product/interface_config_Product")
27
+ self.interface_config_temp_path = os.path.join(self.config.build_path, 'temp_interface_config')
28
+ self.product_temp_path = os.path.join(self.interface_config_temp_path, "resource")
29
+ self.rootfs_path = os.path.join(self.config.buildimg_dir, 'rtos_with_driver/rootfs')
30
+ self.custom_list = {}
31
+
32
+ @staticmethod
33
+ def execute_all_interface(func):
34
+ interface_list = ["redfish", "web_backend", misc.CLI, "snmp"]
35
+
36
+ @wraps(func)
37
+ def wrapper(*args, **kwargs):
38
+ for interface in interface_list:
39
+ # 遍历所有北向接口
40
+ func(interface=interface, *args, **kwargs)
41
+
42
+ return wrapper
43
+
44
+ def clear_dir(self, dst_file_path, if_init=True):
45
+ if os.path.exists(dst_file_path):
46
+ shutil.rmtree(dst_file_path)
47
+ if if_init:
48
+ os.makedirs(dst_file_path, exist_ok=True)
49
+
50
+ @execute_all_interface
51
+ def get_resource_config_file(self, interface):
52
+ config_path = os.path.join(self.rootfs_path, "opt/bmc/apps", interface, "interface_config")
53
+ if not os.path.isdir(config_path):
54
+ self.error(f"{interface}接口配置文件不存在")
55
+ return
56
+ os.makedirs(self.product_temp_path, exist_ok=True)
57
+ output_config_path = os.path.join(self.product_temp_path, interface)
58
+ if os.path.exists(output_config_path):
59
+ shutil.rmtree(output_config_path)
60
+ shutil.copytree(config_path, output_config_path)
61
+
62
+ @execute_all_interface
63
+ def get_custom_list(self, interface):
64
+ custom_dir_path = os.path.join(self.product_temp_path, interface, "customer")
65
+ if os.path.isdir(custom_dir_path):
66
+ for custom in os.listdir(custom_dir_path):
67
+ self.custom_list[custom] = True
68
+
69
+ @execute_all_interface
70
+ def custom_config_patch(self, interface, custom_temp_path, custom):
71
+ config_file_path = os.path.join(custom_temp_path, interface)
72
+ if not os.path.exists(config_file_path):
73
+ return
74
+ generate_work = MappingConfigGenerate(self.config, config_path=config_file_path, custom=custom)
75
+ try:
76
+ generate_work.run()
77
+ except Exception as e:
78
+ self.error("生成{}接口配置时发生错误: {}".format(custom, e))
79
+
80
+ @execute_all_interface
81
+ def remove_custom_patch(self, interface, custom):
82
+ customer_patch_file = os.path.join(self.interface_config_temp_path, custom, interface, "customer")
83
+ if os.path.exists(customer_patch_file):
84
+ shutil.rmtree(customer_patch_file)
85
+
86
+ def create_custom_config(self):
87
+ for custom in self.custom_list:
88
+ custom_temp_path = os.path.join(self.interface_config_temp_path, custom)
89
+ if os.path.exists(custom_temp_path):
90
+ shutil.rmtree(custom_temp_path)
91
+ shutil.copytree(self.product_temp_path, custom_temp_path)
92
+ self.custom_config_patch(custom_temp_path=custom_temp_path, custom=custom)
93
+ self.remove_custom_patch(custom=custom)
94
+ custom_path = os.path.join(self.interface_config_path, custom, "interface_config_" + custom)
95
+ self.clear_dir(os.path.dirname(custom_path))
96
+ shutil.make_archive(custom_path, "zip", custom_temp_path)
97
+ self.remove_custom_patch(custom="resource")
98
+ self.clear_dir(os.path.dirname(self.product_path))
99
+ shutil.make_archive(self.product_path, "zip", self.product_temp_path)
100
+
101
+ def create_interface_config(self):
102
+ self.clear_dir(self.interface_config_path)
103
+ self.clear_dir(self.interface_config_temp_path)
104
+
105
+ os.makedirs(self.product_temp_path, exist_ok=True)
106
+ # 获取配置文件
107
+ self.get_resource_config_file()
108
+ # 获取客户定制厂商名
109
+ self.get_custom_list()
110
+ # 生成映射配置
111
+ self.create_custom_config()
112
+ # 清理临时目录
113
+ self.clear_dir(self.interface_config_temp_path, if_init=False)
114
+
115
+ def run(self):
116
+ try:
117
+ self.info("开始生成全量接口配置")
118
+ self.create_interface_config()
119
+ self.info("生成全量接口配置完成")
120
+
121
+ except Exception as e:
122
+ self.error("生成全量接口配置时发生错误: {}".format(e))
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/python
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
+ 功 能:下载并安装rtos/hcc工具
15
+ 修改记录:2021-10-11 创建
16
+ '''
17
+ import os
18
+ import shutil
19
+
20
+ from bmcgo.tasks.task import Task
21
+ from bmcgo.tasks.misc import BUILD_TOOLS_SHA256_PATH
22
+ from bmcgo.utils.config import Config
23
+ from bmcgo import misc
24
+
25
+
26
+ class DownloadDefaultBuildtools(Task):
27
+ def __init__(self, config: Config):
28
+ super(DownloadDefaultBuildtools, self).__init__(config, "DownloadDefaultBuildtools")
29
+ self.rtos_sdk_dir = f"{self.config.tools_path}/rtos-sdk-arm64"
30
+ self.buildtools_new_sha256 = f"{self.config.tools_path}/buildtools_new.sha256"
31
+ self.skip_install = False
32
+
33
+ def download_tools(self):
34
+ self.info(f"移除下载路径: {self.rtos_sdk_dir}")
35
+ self.run_command(f"rm -rf {self.rtos_sdk_dir}", ignore_error=True, sudo=True)
36
+ self.info('开始下载依赖工具...')
37
+ partner_tools_dir = f"{os.path.expanduser('~')}/rtos_compiler"
38
+ if self.config.partner_mode:
39
+ self.info(f"从缓存目录{partner_tools_dir}复制编译器工具")
40
+ self.run_command(f"cp -rf {partner_tools_dir}/. {self.rtos_sdk_dir}")
41
+
42
+ def install_buildtools(self):
43
+ is_ubuntu = self.tools.is_ubuntu
44
+ self.chdir(self.rtos_sdk_dir)
45
+ self.info("删除目录 /opt/RTOS")
46
+ self.run_command(f"rm -rf {BUILD_TOOLS_SHA256_PATH}", sudo=True)
47
+ self.run_command("rm -rf /opt/RTOS", sudo=True)
48
+ self.info("安装 rpm 包")
49
+ for rpm in os.listdir("./"):
50
+ if not os.path.isfile(rpm) or not rpm.endswith(".rpm"):
51
+ continue
52
+ self.info("安装 {}".format(rpm))
53
+ if not is_ubuntu:
54
+ self.run_command("rpm -ivh {}".format(rpm), sudo=True)
55
+ else:
56
+ self.pipe_command(["rpm2cpio {}".format(rpm), "sudo cpio -id -D /"])
57
+
58
+ self.info("删除目录 /opt/hcc_arm64le")
59
+ self.run_command("rm -rf /opt/hcc_arm64le", sudo=True)
60
+ self.info("解压 hcc_arm64le")
61
+ self.run_command("tar -xzf hcc_arm64le.tar.gz -C /opt", sudo=True)
62
+
63
+ logname = os.getenv(misc.ENV_LOGNAME, None)
64
+ if logname and logname != "root":
65
+ user_group = f"{os.getuid():{os.getgid()}}"
66
+ self.run_command(f"chown {user_group} /opt/hcc_arm64le -R", sudo=True)
67
+ self.run_command(f"chown {user_group} /opt/RTOS -R", sudo=True)
68
+ self.chdir(self.config.code_path)
69
+
70
+ libstdcpp_install_path = f"{self.config.sysroot}/usr/"
71
+ os.makedirs(libstdcpp_install_path, exist_ok=True)
72
+ self.run_command(f"cp -rf {self.config.cross_compile_install_path}/{self.config.cross_prefix}/lib64/" +
73
+ f" {libstdcpp_install_path}")
74
+ self.run_command("cp -af {} {}".format(self.buildtools_new_sha256, BUILD_TOOLS_SHA256_PATH), sudo=True)
75
+
76
+ def run(self):
77
+ self.download_tools()
78
+ self.info("下载依赖工具结束")
79
+
80
+ def install(self):
81
+ self.skip_install = not self.check_need_install(self.rtos_sdk_dir, BUILD_TOOLS_SHA256_PATH,
82
+ self.buildtools_new_sha256)
83
+ if self.skip_install:
84
+ self.info("buildtools版本匹配,跳过安装")
85
+ return
86
+ # 检查rtos是否安装,未安装或版本不匹配时安装
87
+ self.install_buildtools()
88
+
89
+
90
+ class TaskClass(Task):
91
+ def __init__(self, config, work_name=""):
92
+ super(TaskClass, self).__init__(config, work_name)
93
+ self.download_buildtools = DownloadDefaultBuildtools(config)
94
+
95
+ def run(self):
96
+ self.download_buildtools.run()
97
+
98
+ def install(self):
99
+ self.download_buildtools.install()
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/python
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
+ 功 能:
15
+ 版权信息:华为技术有限公司,版本所有(C) 2021
16
+ 修改记录:2021-10-11 创建
17
+ '''
18
+ import os
19
+ import re
20
+ import shutil
21
+
22
+ from bmcgo.tasks.task import Task
23
+ from bmcgo import misc
24
+ from bmcgo.tasks.misc import MODULE_SYMVERS, SDK_PATH, SDK_SHA256_PATH
25
+
26
+
27
+ class TaskClass(Task):
28
+ def __init__(self, config, work_name=""):
29
+ super().__init__(config, work_name)
30
+ self.sdk_dir = f"{self.config.tools_path}/sdk"
31
+ self.sdk_new_sha256 = f"{self.config.tools_path}/sdk_new.sha256"
32
+ self.skip_install = False
33
+
34
+ def download_dependency(self):
35
+ self.info('开始下载依赖组件 ...')
36
+ partner_sdk_dir = f"{os.path.expanduser('~')}/sdk"
37
+ self.info(f"从缓存目录{partner_sdk_dir}复制sdk和rtos二进制文件")
38
+ self.run_command(f"cp -rf {partner_sdk_dir}/. {self.sdk_dir}")
39
+
40
+ def move_dependency(self):
41
+ # 移动到tools/build_tools目录中
42
+ if os.path.isdir(self.config.sdk_path):
43
+ shutil.rmtree(self.config.sdk_path)
44
+ self.run_command(f"cp -rf {self.sdk_dir} {self.config.sdk_path}")
45
+ self.info("移动依赖组件结束")
46
+ self.chdir(self.config.sdk_path)
47
+ for file in os.listdir("."):
48
+ if re.match("^Hi1711_[0-9]{8}_[0-9a-f]{40}.tar.gz$", file) is None:
49
+ continue
50
+ self.run_command(f"tar -xvf {file}")
51
+ break
52
+ if self.skip_install:
53
+ self.info("sdk版本匹配")
54
+ return
55
+ old_sdk_dir = "/opt/hi1711sdk"
56
+ self.run_command(f"rm -rf {SDK_SHA256_PATH}", sudo=True)
57
+ self.run_command(f"rm -rf {SDK_PATH}", sudo=True)
58
+ self.run_command(f"rm -rf {old_sdk_dir}", sudo=True)
59
+ self.run_command(f"mkdir -p {SDK_PATH}", ignore_error=True, sudo=True)
60
+ self.run_command(f"tar -xzf hi1711sdk.tar.gz -C {SDK_PATH} {MODULE_SYMVERS}", sudo=True)
61
+ logname = os.getenv(misc.ENV_LOGNAME, None)
62
+ if logname and logname != "root":
63
+ user_group = f"{os.getuid():{os.getgid()}}"
64
+ self.run_command(f"chown {user_group} {SDK_PATH} -R", sudo=True)
65
+ self.run_command(f"ln -s {SDK_PATH} {old_sdk_dir}", sudo=True)
66
+ self.run_command("cp -af {} {}".format(self.sdk_new_sha256, SDK_SHA256_PATH), sudo=True)
67
+
68
+ def run(self):
69
+ self.download_dependency()
70
+ self.info('下载依赖组件结束')
71
+ self.skip_install = not self.check_need_install(self.sdk_dir, SDK_SHA256_PATH, self.sdk_new_sha256)
72
+ self.move_dependency()
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env 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 os
13
+ import subprocess
14
+ import time
15
+ from multiprocessing import Process
16
+ from bmcgo.tasks.task import Task
17
+ from bmcgo import errors
18
+
19
+
20
+ class SignProcess(Process):
21
+ def __init__(self, work: Task):
22
+ super().__init__()
23
+ self.work = work
24
+ self.config = self.work.config
25
+
26
+ def run(self):
27
+ self.work.work_name = "sign_rootfs_image"
28
+ self.work.chdir(self.config.build_path)
29
+ self.work.tools.pipe_command([f"echo 'cms placeholder'"], out_file=f"{self.config.work_out}/rootfs_BMC.img.cms")
30
+
31
+
32
+ class TarImageProcess(Process):
33
+ def __init__(self, work):
34
+ super().__init__()
35
+ self.work: Task = work
36
+ self.config = self.work.config
37
+
38
+ def run(self):
39
+ self.work.work_name = "tar_rootfs_image"
40
+ self.work.chdir(self.config.work_out)
41
+ self.work.run_command("tar --format=gnu --exclude BMC_rootfs.tar.gz -czf rootfs_BMC.tar.gz rootfs_BMC.img")
42
+ self.work.success("tar BMC_rootfs.tar.gz successfully")
43
+
44
+
45
+ class TaskClass(Task):
46
+ skip_post_hpm = False
47
+
48
+ @staticmethod
49
+ def get_shell_command_result(cmd):
50
+ ret = subprocess.getstatusoutput(cmd)
51
+ if ret[0] == 1:
52
+ raise Exception(f"运行命令 {cmd} 失败")
53
+ return ret[1]
54
+
55
+ def set_skip_post_hpm(self, value):
56
+ if value:
57
+ self.skip_post_hpm = True
58
+ else:
59
+ self.skip_post_hpm = False
60
+
61
+ def copy_file_or_dir(self, src_dir, dst_dir):
62
+ self.pipe_command(["yes y", f"cp -ai {src_dir} {dst_dir}"])
63
+ return
64
+
65
+ def prepare_hpm(self):
66
+ hpm_build_dir = self.config.hpm_build_dir
67
+ hpm_build_dir_src = f"/usr/share/bmcgo/ipmcimage"
68
+ self.tools.copy_all(hpm_build_dir_src, hpm_build_dir)
69
+
70
+ self.run_command(f"cp {self.config.board_path}/update_ext4.cfg {hpm_build_dir}/update.cfg")
71
+
72
+ self.chdir(hpm_build_dir)
73
+ if not self.skip_post_hpm:
74
+ self._component_cust_action("post_hpm")
75
+
76
+ curr_ver = self.get_shell_command_result("cat update.cfg | grep '^Version=' | awk -F '=' '{print $2}'")
77
+
78
+ # 读取发布时用的包名
79
+ vs = self.config.version.split(".")
80
+ if self.manufacture_version_check(f"{self.config.board_path}/manifest.yml") is True:
81
+ vs[3] = str(int(vs[3]) + 1).zfill(2)
82
+ ver = f"{vs[0]}.{vs[1]}.{vs[2]}.{vs[3]}"
83
+
84
+ # 正常包
85
+ self.info(f"bmc 版本: {ver}")
86
+ self.run_command(
87
+ f"sed -i \"/^Version=/s/{curr_ver}/{ver}/g\" update.cfg")
88
+ self.run_command("chmod +x . -R")
89
+
90
+ def run(self):
91
+ # 创建签名进程
92
+ sign = SignProcess(self)
93
+ sign.start()
94
+
95
+ self.prepare_hpm()
96
+
97
+ # 创建压缩进程
98
+ tar = TarImageProcess(self)
99
+ tar.start()
100
+ while True:
101
+ if not sign.is_alive():
102
+ if sign.exitcode is not None and sign.exitcode != 0:
103
+ raise errors.BmcGoException(f"签名进程发生错误, 返回值: {sign.exitcode}")
104
+ break
105
+ time.sleep(0.1)
106
+ while True:
107
+ if not tar.is_alive():
108
+ if tar.exitcode is not None and tar.exitcode != 0:
109
+ raise errors.BmcGoException(f"打包进程发生错误, 返回值: {tar.exitcode}")
110
+ break
111
+ time.sleep(0.1)
112
+
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env python
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 os
13
+ import shutil
14
+ import time
15
+ import xml.etree.ElementTree as ET
16
+
17
+ from bmcgo.tasks.task import Task
18
+ from bmcgo.utils.config import Config
19
+ from bmcgo import errors
20
+
21
+ PACKAGE = "Package"
22
+
23
+
24
+ class TaskClass(Task):
25
+ def __init__(self, config: Config, work_name=""):
26
+ super().__init__(config, work_name)
27
+
28
+ def version_xml_update(self, hpm_name, version_name):
29
+ version_file = os.path.join(self.config.board_path, version_name)
30
+ if not os.path.exists(version_file):
31
+ return
32
+ srv_tree = ET.parse(version_file)
33
+ srv_root = srv_tree.getroot()
34
+ package_name = srv_root.find(PACKAGE).find('PackageName').text
35
+ vs = self.config.version.split(".")
36
+ # 修正版本号
37
+ if self.manufacture_version_check(f"{self.config.board_path}/manifest.yml") is True:
38
+ vs[3] = str(int(vs[3]) + 1).zfill(2)
39
+ ver = ".".join(vs[0:4])
40
+ srv_root.find(PACKAGE).find('Version').text = ver
41
+ srv_root.find(PACKAGE).find('PackageName').text = package_name.replace("TMP_VERSION", ver)
42
+ srv_root.find(PACKAGE).find('FileName').text = \
43
+ srv_root.find(PACKAGE).find('FileName').text.replace("TMP_VERSION", ver)
44
+ srv_root.find(PACKAGE).find('Size').text = str(os.path.getsize(hpm_name))
45
+ srv_tree.write(version_file)
46
+
47
+ def run(self):
48
+ if self.config.manufacture_code is not None:
49
+ self.info(f"编码为 {self.config.manufacture_code} 为 togdp 编码, 跳过构建 tosupporte 包")
50
+ return
51
+ # 要打包的编码的配置
52
+ supporte_config = "tosupporte/" + self.config.tosupporte_code
53
+ build_type = self.get_manufacture_config(supporte_config + "/build_type")
54
+ if build_type is not None and build_type != self.config.build_type:
55
+ raise errors.BmcGoException("构建类型不匹配, 参数配置为: {}, 包 {} 对应构建类型配置为: {}".format(\
56
+ self.config.build_type, supporte_config + "/build_type", build_type))
57
+ # 文件的配置路径以及其名字
58
+ package_name = self.get_manufacture_config(supporte_config + "/package_name")
59
+ package_name = time.strftime(package_name, self.config.date)
60
+ # 获取到文件名
61
+ zip_name = os.path.basename(package_name)
62
+ # 文件名同名目录
63
+ build_path = os.path.join(self.config.temp_path, self.config.board_name, self.config.tosupporte_code,
64
+ zip_name.replace(".zip", ""))
65
+ self.info("构建 {}, 工作目录: {}".format(package_name, build_path))
66
+ shutil.rmtree(build_path, ignore_errors=True)
67
+ os.makedirs(build_path, exist_ok=True)
68
+
69
+ # 切换到打包目录
70
+ self.chdir(build_path)
71
+ # 复制所需文件
72
+ files = self.get_manufacture_config(supporte_config + "/files")
73
+ self.version_xml_update(f"{self.config.work_out}/rootfs_{self.config.board_name}.hpm", "version.xml")
74
+ self.copy_manifest_files(files)
75
+
76
+ # 由于tosupporte解压后没有文件夹
77
+ cmd = "zip -1 -rq {} .".format(zip_name)
78
+ self.run_command(cmd)
79
+ # 组装并新建目标目录
80
+ dirname = os.path.dirname(package_name)
81
+ target_dir = os.path.join(self.config.output_path, "packet", dirname)
82
+ os.makedirs(target_dir, exist_ok=True)
83
+ # 硬链接文件目标目录
84
+ self.link(zip_name, os.path.join(target_dir, zip_name))
85
+
86
+ self.chdir(self.config.temp_path)
87
+ shutil.rmtree(build_path, ignore_errors=True)