openubmc-bingo 0.5.243__py3-none-any.whl → 0.5.254__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 (67) hide show
  1. bmcgo/__init__.py +1 -1
  2. bmcgo/bmcgo_config.py +81 -1
  3. bmcgo/codegen/lua/Makefile +13 -0
  4. bmcgo/codegen/lua/codegen.py +6 -3
  5. bmcgo/codegen/lua/script/dto/options.py +1 -0
  6. bmcgo/codegen/lua/script/{render_utils/factory.py → factory.py} +1 -1
  7. bmcgo/codegen/lua/script/gen_entry.py +6 -3
  8. bmcgo/codegen/lua/script/gen_intf_rpc_json.py +12 -0
  9. bmcgo/codegen/lua/script/gen_schema.py +2 -0
  10. bmcgo/codegen/lua/script/merge_model.py +10 -3
  11. bmcgo/codegen/lua/script/render_utils/__init__.py +5 -4
  12. bmcgo/codegen/lua/script/render_utils/client_lua.py +2 -2
  13. bmcgo/codegen/lua/script/render_utils/controller_lua.py +2 -2
  14. bmcgo/codegen/lua/script/render_utils/db_lua.py +2 -2
  15. bmcgo/codegen/lua/script/render_utils/error_lua.py +2 -2
  16. bmcgo/codegen/lua/script/render_utils/ipmi_lua.py +2 -2
  17. bmcgo/codegen/lua/script/render_utils/ipmi_message_lua.py +2 -2
  18. bmcgo/codegen/lua/script/render_utils/mdb_lua.py +2 -2
  19. bmcgo/codegen/lua/script/render_utils/message_lua.py +2 -2
  20. bmcgo/codegen/lua/script/render_utils/messages_lua.py +2 -2
  21. bmcgo/codegen/lua/script/render_utils/model_lua.py +2 -2
  22. bmcgo/codegen/lua/script/render_utils/old_model_lua.py +2 -2
  23. bmcgo/codegen/lua/script/render_utils/plugin_lua.py +2 -2
  24. bmcgo/codegen/lua/script/render_utils/redfish_proto.py +2 -2
  25. bmcgo/codegen/lua/script/render_utils/request_lua.py +2 -2
  26. bmcgo/codegen/lua/script/render_utils/service_lua.py +3 -2
  27. bmcgo/codegen/lua/script/template.py +5 -1
  28. bmcgo/codegen/lua/script/utils.py +9 -2
  29. bmcgo/codegen/lua/templates/Makefile +8 -0
  30. bmcgo/codegen/lua/templates/apps/Makefile +27 -1
  31. bmcgo/codegen/lua/templates/apps/controller.lua.mako +20 -4
  32. bmcgo/codegen/lua/v1/script/gen_schema.py +328 -0
  33. bmcgo/codegen/lua/v1/script/render_utils/model_lua.py +458 -0
  34. bmcgo/codegen/lua/v1/templates/apps/model.lua.mako +62 -0
  35. bmcgo/codegen/lua/v1/templates/apps/service.lua.mako +193 -0
  36. bmcgo/component/build.py +26 -43
  37. bmcgo/component/component_helper.py +54 -0
  38. bmcgo/component/coverage/incremental_cov.py +25 -33
  39. bmcgo/frame.py +9 -6
  40. bmcgo/functional/conan_index_build.py +16 -41
  41. bmcgo/functional/config.py +7 -0
  42. bmcgo/functional/csr_build.py +313 -88
  43. bmcgo/functional/diff.py +3 -3
  44. bmcgo/functional/json_check.py +109 -0
  45. bmcgo/functional/upgrade.py +31 -1
  46. bmcgo/misc.py +32 -2
  47. bmcgo/target/install_sdk.yml +6 -0
  48. bmcgo/tasks/task.py +69 -43
  49. bmcgo/tasks/task_build_conan.py +6 -2
  50. bmcgo/tasks/task_build_wbd_up.py +4 -4
  51. bmcgo/utils/basic_enums.py +45 -0
  52. bmcgo/utils/config.py +20 -8
  53. bmcgo/utils/install_manager.py +75 -20
  54. bmcgo/utils/installations/base_installer.py +114 -7
  55. bmcgo/utils/installations/install_consts.py +3 -1
  56. bmcgo/utils/installations/install_plans/bingo.yml +2 -4
  57. bmcgo/utils/installations/install_workflow.py +6 -2
  58. bmcgo/utils/installations/installers/apt_installer.py +58 -136
  59. bmcgo/utils/installations/installers/pip_installer.py +52 -18
  60. bmcgo/utils/installations/version_util.py +1 -1
  61. bmcgo/utils/json_validator.py +241 -0
  62. {openubmc_bingo-0.5.243.dist-info → openubmc_bingo-0.5.254.dist-info}/METADATA +2 -1
  63. {openubmc_bingo-0.5.243.dist-info → openubmc_bingo-0.5.254.dist-info}/RECORD +67 -60
  64. /bmcgo/codegen/lua/script/{render_utils/base.py → base.py} +0 -0
  65. {openubmc_bingo-0.5.243.dist-info → openubmc_bingo-0.5.254.dist-info}/WHEEL +0 -0
  66. {openubmc_bingo-0.5.243.dist-info → openubmc_bingo-0.5.254.dist-info}/entry_points.txt +0 -0
  67. {openubmc_bingo-0.5.243.dist-info → openubmc_bingo-0.5.254.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,193 @@
1
+ ${make_header('lua')}
2
+ <%namespace name="imports" file="../../../templates/apps/utils/imports.mako"/>
3
+ <%namespace name="default_intf" file="../../../templates/apps/utils/default_intf.lua.mako"/>
4
+ <%namespace name="mdb_obj" file= "../../../templates/apps/utils/mdb_obj.lua.mako"/>
5
+ <% has_signal = root['signals']%>
6
+ <% has_mdb = any('path' in cls_data for cls, cls_data in root['class_require'].items())%>
7
+ <% has_default = any((rpc['default'] != '' and not rpc['override']) for rpc in root['methods'])%>
8
+ <% ClassName = root['package'] + '_service' %>
9
+
10
+ % if root['has_ipmi_cmd']:
11
+ local ipmi = require 'ipmi'
12
+ % endif
13
+ % if has_default or has_mdb:
14
+ local mdb = require 'mc.mdb'
15
+ % endif
16
+ % if utils_py.check_local_reset_db(root) or utils_py.check_local_temporary_db(root):
17
+ local skynet = require 'skynet'
18
+ % endif
19
+ local class = require 'mc.class'
20
+ % if has_signal:
21
+ local context = require 'mc.context'
22
+ % endif
23
+ local c = require 'mc.class_mgnt'
24
+ % if utils_py.check_need_mem_db(root):
25
+ local open_db = require '${project_name}.db'
26
+ % endif
27
+ local bootstrap = require 'mc.bootstrap'
28
+ % if utils_py.check_local_poweroff_db(root) or utils_py.check_local_reset_db(root) or utils_py.check_local_temporary_db(root):
29
+ local open_local_db = require '${project_name}.local_db'
30
+ % endif
31
+ % if (root['path_level'] == 2 and utils_py.check_db_open(root['package']) and utils_py.check_remote_per(root)) or root['class_require']:
32
+ local object_manage = require 'mc.mdb.object_manage'
33
+ % endif
34
+ % if root['path_level'] == 2 and utils_py.check_db_open(root['package']) and utils_py.check_remote_per(root):
35
+ local persist_client = require 'persistence.persist_client_lib'
36
+ % endif
37
+ % if utils_py.check_need_mem_db(root) or utils_py.check_need_local_db(root):
38
+ local ok, datas = pcall(require, '${project_name}.datas')
39
+ if not ok then
40
+ datas = nil -- 如果没有datas配置,证明当前组件不需要datas,仅打开数据库
41
+ end
42
+ % endif
43
+
44
+ % for intf, intf_data in root['intf_imports'].items():
45
+ local ${intf}Types = require '${project_name}.json_types.${intf}'
46
+ % endfor
47
+
48
+ % for cls, cls_data in root['class_require'].items():
49
+ ${mdb_obj.render(cls, cls_data['data'], root['class_require'])}
50
+ % endfor
51
+
52
+ % if root['path_level'] == 2:
53
+ local ${ClassName} = class(bootstrap.Service)
54
+ % else:
55
+ local ${ClassName} = class(bootstrap.Attach)
56
+ % endif
57
+
58
+ % if has_default:
59
+ ${default_intf.add_subs(ClassName)}
60
+ % endif
61
+ ${ClassName}.package = '${root['package']}'
62
+
63
+ % for rpc in root['methods']:
64
+ %if rpc['default'] != '' and not rpc['override']:
65
+ <% default_path = ClassName +'.'+ rpc['intf_class'] + 'Default' %>
66
+ require '${project_name}.json_types.${rpc['intf_class']}Default'
67
+ ${default_intf.render(default_path, ClassName, rpc['intf_class'] + "Default", rpc['interface'] + ".Default")}
68
+ %endif
69
+ % endfor
70
+ ## 动态对象生成创建接口,以便非CSR场景创建对象时使用
71
+ % for cls, cls_data in root['class_require'].items():
72
+ % if render_utils.is_dynamic_obj(cls_data['path']):
73
+
74
+ function ${ClassName}:Create${cls}(${", ".join(render_utils.get_path_params(render_utils.get_path(cls, root['class_require'])))}, prop_setting_cb)
75
+ local path = ${render_utils.make_path(render_utils.get_path(cls, root['class_require']))}
76
+ return object_manage.create_object("${cls}", path, path, prop_setting_cb)
77
+ end
78
+ % else:
79
+
80
+ function ${ClassName}:Create${cls}(prop_setting_cb)
81
+ return object_manage.create_object("${cls}", '${cls}_0', ${render_utils.make_path(render_utils.get_path(cls, root['class_require']))}, prop_setting_cb)
82
+ end
83
+ % endif
84
+ %endfor
85
+
86
+ ## 生成注册回调的接口,增加参数校验
87
+ % for rpc in root['methods']:
88
+ <% class_intf = rpc['class'] + '_' + rpc['intf_class'] %>
89
+ % if rpc['interface'] != "bmc.kepler.Object.Properties":
90
+ function ${ClassName}:Impl${rpc['name']}(cb)
91
+ c("${rpc['class']}"):_implement("${rpc['name']}", "${rpc['interface']}", "${rpc['func_name']}", cb)
92
+ end
93
+ % endif
94
+ % endfor
95
+
96
+ % for method, _ in root.get('private_class_require', {}).get('private', {}).get('data', {}).get('methods', {}).items():
97
+ function ${ClassName}:Impl${method}(cb)
98
+ c('private'):_implement("${method}", nil, "${method}", cb)
99
+ end
100
+
101
+ function ${ClassName}:${method}(...)
102
+ return c('private'):_call("${method}", ...)
103
+ end
104
+
105
+ % endfor
106
+ ## 生成发送信号的接口
107
+ % for signal in root['signals']:
108
+ <% params = render_utils.params(signal['signature'])%>
109
+ % if ':' in signal['path']:
110
+ ---@param mdb_object object
111
+ % endif
112
+ % for p in render_utils.props(signal['signature']): ## 生成参数注释
113
+ ---@param ${p['name']} ${utils_py.do_type_to_lua(p['type'], p['repeated'])}
114
+ % endfor
115
+ function ${ClassName}:${signal['name']}(${'mdb_object,' if (':' in signal['path']) else ''}${params})
116
+ self.bus:signal(${'mdb_object.path' if (':' in signal['path']) else ('"'+signal['path']+'"')}, '${signal['interface']}', '${signal['signal_name']}', 'a{ss}${utils_py.do_service_types_to_dbus(root, signal['signature'][1:])}', context.get_context() or {}${"" if params == '' else ", "}${params})
117
+ end
118
+
119
+ % endfor
120
+
121
+ % if root['has_ipmi_cmd']:
122
+ function ${ClassName}:register_ipmi_cmd(ipmi_cmd, cb)
123
+ self.ipmi_cmds[ipmi_cmd.name] = ipmi.register_ipmi_cmd(self.bus, self.service_name, ipmi_cmd, cb or self[ipmi_cmd.name])
124
+ end
125
+
126
+ function ${ClassName}:unregister_ipmi_cmd(ipmi_cmd)
127
+ local cmd_obj = self.ipmi_cmds[ipmi_cmd.name]
128
+ if not cmd_obj then
129
+ return
130
+ end
131
+
132
+ cmd_obj:unregister()
133
+ self.ipmi_cmds[ipmi_cmd.name] = nil
134
+ end
135
+ % endif
136
+
137
+ function ${ClassName}:ctor(${"" if root['path_level'] == 2 else "bus"})
138
+ self.name = '${project_name}'
139
+ % if utils_py.check_need_mem_db(root):
140
+ self.db = open_db(':memory:', datas)
141
+ % endif
142
+ % if root['path_level'] == 2:
143
+ % if utils_py.check_local_poweroff_db(root):
144
+ self.local_db = open_local_db(bootstrap.Service:get_local_db_path(self.name) .. '/${project_name}.db', datas, 'poweroff')
145
+ % endif
146
+ % endif
147
+ % if utils_py.check_local_reset_db(root) or utils_py.check_local_temporary_db(root):
148
+ if skynet.getenv('TEST_DATA_DIR') then
149
+ % if utils_py.check_local_reset_db(root):
150
+ self.reset_local_db = open_local_db(skynet.getenv('TEST_DATA_DIR')..'/${project_name}_reset.db', datas, "reset")
151
+ % endif
152
+ % if utils_py.check_local_temporary_db(root):
153
+ self.temporary_local_db = open_local_db(skynet.getenv('TEST_DATA_DIR')..'/${project_name}_temp.db', datas, "temporary")
154
+ % endif
155
+ else
156
+ % if utils_py.check_local_reset_db(root):
157
+ self.reset_local_db = open_local_db('/opt/bmc/pram/persistence.local/${project_name}.db', datas, "reset")
158
+ % endif
159
+ % if utils_py.check_local_temporary_db(root):
160
+ self.temporary_local_db = open_local_db('/dev/shm/persistence.local/${project_name}.db', datas, "temporary")
161
+ % endif
162
+ end
163
+ % endif
164
+ end
165
+
166
+ % if root['path_level'] == 2:
167
+ function ${ClassName}:pre_init()
168
+ ${ClassName}.super.pre_init(self)
169
+ % if utils_py.check_remote_per(root):
170
+ self.persist = persist_client.new(self.bus, self.db, self, ${render_utils.get_not_recover_tables(root)})
171
+ object_manage.set_persist_client(self.persist)
172
+ % endif
173
+ end
174
+ % endif
175
+
176
+ ## service初始化
177
+ function ${ClassName}:init()
178
+ % if root['path_level'] == 2:
179
+ ${ClassName}.super.init(self)
180
+ %endif
181
+ % if has_default:
182
+ self:SubscribeAll()
183
+ %endif
184
+ % for rpc in root['methods']:
185
+ %if not rpc['override'] :
186
+ self:Impl${rpc['name']}(function(obj, ctx, ...)
187
+ return self:Get${rpc['default']}Object():${rpc['func_name']}_PACKED(ctx, obj.path,...):unpack()
188
+ end)
189
+ %endif
190
+ % endfor
191
+ end
192
+
193
+ return ${ClassName}
bmcgo/component/build.py CHANGED
@@ -26,6 +26,7 @@ from bmcgo.errors import BmcGoException
26
26
  from bmcgo.component.package_info import InfoComp
27
27
  from bmcgo.component.component_helper import ComponentHelper
28
28
  from bmcgo import misc
29
+ from bmcgo.utils.json_validator import JSONValidator
29
30
 
30
31
  log = Logger()
31
32
  tool = Tools()
@@ -49,6 +50,21 @@ class BuildComp():
49
50
  process = subprocess.run(cmd, check=True, capture_output=True)
50
51
  return process.stdout.decode("UTF-8").strip().split("\n")
51
52
 
53
+ @staticmethod
54
+ def check_luac():
55
+ luac_path = os.path.join(os.path.expanduser('~'), ".conan", "bin", "luac")
56
+ if not os.path.isfile(luac_path):
57
+ raise BmcGoException(f"当前环境中未安装luac!请更新manifest仓代码,执行环境初始化脚本init.py重新部署环境!")
58
+
59
+ conan_bin = os.path.join(os.path.expanduser('~'), ".conan", "bin")
60
+ # 设置PLD_LIBRARY_PATH环境变量,luajit运行时需要加载so动态库
61
+ ld_library_path = conan_bin + ":" + os.environ.get("LD_LIBRARY_PATH", "")
62
+ os.environ["LD_LIBRARY_PATH"] = ld_library_path
63
+ # 设置PATH环境变量,luajit无需指定全路径
64
+ path = conan_bin + ":" + os.environ.get("PATH", "")
65
+ os.environ["PATH"] = path
66
+ os.environ["LUA_PATH"] = f"{conan_bin}/?.lua"
67
+
52
68
  def gen_conanbase(self, gen_conanbase, service_json):
53
69
  lookup = TemplateLookup(directories=os.path.join(cwd_script, "template"))
54
70
  if gen_conanbase:
@@ -123,47 +139,6 @@ class BuildComp():
123
139
  return http_proto + chunk[0] + chunk[1]
124
140
  return http_proto + chunk[0] + "/" + chunk[1]
125
141
 
126
- def install_luac(self):
127
- conan_bin = os.path.join(os.path.expanduser('~'), ".conan", "bin")
128
- # 设置PLD_LIBRARY_PATH环境变量,luajit运行时需要加载so动态库
129
- ld_library_path = conan_bin + ":" + os.environ.get("LD_LIBRARY_PATH", "")
130
- os.environ["LD_LIBRARY_PATH"] = ld_library_path
131
- # 设置PATH环境变量,luajit无需指定全路径
132
- path = conan_bin + ":" + os.environ.get("PATH", "")
133
- os.environ["PATH"] = path
134
- os.environ["LUA_PATH"] = f"{conan_bin}/?.lua"
135
-
136
- # 待安装的luajit版本
137
- channel = f"@{Tools().conan_user}/{misc.StageEnum.STAGE_STABLE.value}"
138
- luajit_pkg = f"luajit/2.1.0.B012{channel}"
139
- luajit_flag = luajit_pkg.split("@")[0].replace("/", "_")
140
- luajit_flag = os.path.join(conan_bin, luajit_flag)
141
-
142
- # 使能luajit时需要安装luajit
143
- luac_path = os.path.join(conan_bin, "luajit")
144
- # luajit版本一致且luac/luajit存在时赋权即可
145
- if os.path.isfile(luajit_flag) and os.path.exists(luac_path):
146
- os.chmod(luac_path, stat.S_IRWXU)
147
- return
148
- Tools.clean_conan_bin(conan_bin)
149
- # 其它情况都尝试安装luajit
150
- cmd = [misc.CONAN, "install", luajit_pkg]
151
- cmd += ("-pr profile.dt.ini -if=temp/.deploy -g deploy").split()
152
- if self.info.remote:
153
- cmd += ["-r", self.info.remote]
154
- Helper.run(cmd)
155
- cmd = ["cp", "temp/.deploy/luajit/usr/bin/luajit", f"{conan_bin}"]
156
- Helper.run(cmd)
157
- cmd = ["cp", "temp/.deploy/luajit/usr/lib64/liblua.so", f"{conan_bin}"]
158
- Helper.run(cmd)
159
- cmd = ["cp", "-r", "temp/.deploy/luajit/usr/bin/jit", f"{conan_bin}"]
160
- Helper.run(cmd)
161
- os.chmod(luac_path, stat.S_IRWXU)
162
- luajit2luac = shutil.which("luajit2luac.sh")
163
- cmd = ["cp", luajit2luac, f"{conan_bin}/luac"]
164
- Helper.run(cmd)
165
- pathlib.Path(luajit_flag).touch(exist_ok=True)
166
-
167
142
  def check_conan_profile(self):
168
143
  profile = os.path.join(tool.conan_profiles_dir, self.info.profile)
169
144
  luajit_profile = os.path.join(tool.conan_profiles_dir, "profile.luajit.ini")
@@ -198,9 +173,9 @@ class BuildComp():
198
173
  tool.run_command(cmd, show_log=True)
199
174
 
200
175
  def run(self):
201
- self.check_conan_profile()
202
- self.install_luac()
203
176
  tool.clean_locks()
177
+ self.check_conan_profile()
178
+ self.check_luac()
204
179
  from_source = "--build=missing"
205
180
  if self.info.from_source:
206
181
  from_source = "--build"
@@ -212,6 +187,7 @@ class BuildComp():
212
187
  cmd = [misc.CONAN, "create"]
213
188
  cmd += append.split()
214
189
  tool.run_command(cmd, show_log=True)
190
+ self._check_sr_validation(cache_dir)
215
191
  self.upload()
216
192
 
217
193
  def test(self):
@@ -220,3 +196,10 @@ class BuildComp():
220
196
  cmd += self.info.cmd_base.split()
221
197
  cmd += ["-tf", "test_package"]
222
198
  Helper.run(cmd)
199
+
200
+ def _check_sr_validation(self, dir_path):
201
+ # 检查所有 sr 文件是否合法
202
+ log.info("========== sr 文件检查开始 ==========")
203
+ jc = self.bconfig.bmcgo_config_list.get(misc.ENV_CONST, {}).get(misc.JSON_CHECKER, None)
204
+ JSONValidator().validate_files(dir_path, ['sr'], jc)
205
+ log.info("========== sr 文件检查结束 ==========")
@@ -16,6 +16,7 @@ import re
16
16
  from typing import List
17
17
  from multiprocessing import Process
18
18
  from tempfile import NamedTemporaryFile
19
+ from packaging import version
19
20
 
20
21
  from bmcgo.utils.tools import Tools
21
22
  from bmcgo.bmcgo_config import misc
@@ -58,6 +59,59 @@ class ComponentHelper:
58
59
  content = json.load(service_fp)
59
60
  return content.get("language", "lua")
60
61
 
62
+ @staticmethod
63
+ def compare_versions(version_str, target_version="1.80.35"):
64
+ # 处理简单版本号格式 a/1.1xxx
65
+ simple_match = re.match(r'[^/]+/(\d+\.\d+(?:\.\d+)?)', version_str)
66
+ if simple_match:
67
+ return version.parse(simple_match.group(1)) >= version.parse(target_version)
68
+
69
+ # 处理待条件的版本号
70
+ condition_match = re.findall(r'\[([^]]+)\]', version_str)
71
+ if condition_match:
72
+ conditions = condition_match[0].split()
73
+
74
+ # 只有>或>=
75
+ if len(conditions) == 1 and any(op in conditions[0] for op in [">", ">="]):
76
+ return True
77
+
78
+ # 包含<或<=
79
+ for cond in conditions:
80
+ if "<=" in cond:
81
+ ver = cond.lstrip("<=>")
82
+ return version.parse(ver) >= version.parse(target_version)
83
+ elif "<" in cond:
84
+ ver = cond.lstrip("<=>")
85
+ return version.parse(ver) > version.parse(target_version)
86
+
87
+ ver = conditions[0].lstrip("<=>")
88
+ return version.parse(ver) >= version.parse(target_version)
89
+
90
+ return False
91
+
92
+ @staticmethod
93
+ def enable_new_major_version(dependencies):
94
+ if not dependencies:
95
+ return False
96
+
97
+ for dependency in dependencies:
98
+ version_str = dependency.get("conan", "")
99
+ if not version_str.startswith("libmc4lua"):
100
+ continue
101
+ return ComponentHelper.compare_versions(version_str)
102
+
103
+ return False
104
+
105
+ @staticmethod
106
+ def get_major_version(service_json="mds/service.json"):
107
+ if not os.path.isfile(service_json):
108
+ raise RuntimeError(f"{service_json}文件不存在")
109
+ with open(service_json, "r", encoding="UTF-8") as service_fp:
110
+ content = json.load(service_fp)
111
+
112
+ return 1 if (ComponentHelper.enable_new_major_version(content.get("dependencies", {}).get("build", {})) or \
113
+ ComponentHelper.enable_new_major_version(content.get("dependencies", {}).get("test", {}))) else 0
114
+
61
115
  @staticmethod
62
116
  def get_config_value(json_data, key: str, default=None):
63
117
  for sub_key in key.split("/"):
@@ -127,30 +127,34 @@ class IncrementalCov(object):
127
127
  return True
128
128
  return False
129
129
 
130
- def get_lua_cov_map(self, path_list):
130
+ def get_lua_cov_map(self, changes, path_list):
131
131
  # 获取lua代码的校验字典
132
- covers = {}
132
+ lua_changes = {}
133
133
  uncovers = {}
134
134
  # 如果未覆盖到lua文件则返回空字典,path_list[1]为.out文件路径
135
135
  if not os.path.exists(path_list[1]):
136
- return covers, uncovers
137
- whole_lines = self.parse_data(path_list[0])
138
- check_list = self.parse_check_data(path_list[1])
139
- for key, value_list in whole_lines.items():
140
- value_check_list = check_list[key]
136
+ return lua_changes, uncovers
137
+ cov_lines = self.parse_data(path_list[0])
138
+ filter_lines = self.parse_check_data(path_list[1])
139
+ for file, change_lines in changes.items():
141
140
  temp_uncovers = []
142
- temp_covers = []
143
- index = 0
144
- for _ in value_list:
145
- if value_list[index] == 0 and value_check_list[index] == 1:
146
- temp_uncovers.append(index + 1)
147
- elif value_list[index] != 0 and value_check_list[index] == 1:
148
- temp_covers.append(index + 1)
149
- index = index + 1
150
- covers[key] = temp_covers
151
- uncovers[key] = temp_uncovers
152
-
153
- return covers, uncovers
141
+ temp_changes = []
142
+ filters = filter_lines[file]
143
+ if file not in cov_lines or file not in filter_lines:
144
+ continue
145
+ else:
146
+ cov = cov_lines[file]
147
+
148
+ for change in change_lines:
149
+ if filters[change] == 0:
150
+ continue
151
+ temp_changes.append(change)
152
+ if not cov or not cov[change]:
153
+ temp_uncovers.append(change)
154
+ lua_changes[file] = temp_changes
155
+ uncovers[file] = temp_uncovers
156
+
157
+ return lua_changes, uncovers
154
158
 
155
159
  def parse_data(self, file_path):
156
160
  # 解析lua覆盖率的统计文件
@@ -302,19 +306,7 @@ class IncrementalCov(object):
302
306
  os.path.join(path, "luacov.stats.out"),
303
307
  os.path.join(path, "luacov.stats.filter"),
304
308
  ]
305
- lua_covers_map, lua_uncovers_map = self.get_lua_cov_map(path_list)
306
- uncovers = {}
307
- lua_changes = {}
308
- for f, lines in changes.items():
309
- if f not in lua_covers_map and f not in lua_uncovers_map:
310
- lua_changes[f] = lines
311
- uncovers[f] = lines
312
- continue
313
- lua_changes[f] = sorted(list(set(lua_uncovers_map[f] + lua_covers_map[f]) & set(lines)))
314
- uncov_lines = list(set(lua_uncovers_map[f]) & set(lines))
315
- if len(uncov_lines) != 0:
316
- uncovers[f] = sorted(uncov_lines)
317
- return lua_changes, uncovers
309
+ return self.get_lua_cov_map(changes, path_list)
318
310
 
319
311
  def find_and_return_file_path(self, filename):
320
312
  for root, _, files in os.walk(self.lcov_dir, topdown=True):
@@ -374,7 +366,7 @@ class IncrementalCov(object):
374
366
  uncov_linenum += len(v)
375
367
 
376
368
  cov_linenum = change_linenum - uncov_linenum
377
- coverage = round(cov_linenum * 1.0 / change_linenum if change_linenum > 0 else 1, 4)
369
+ coverage = round((cov_linenum * 1.0 / change_linenum) if change_linenum > 0 else 1, 4)
378
370
  script_dir = os.path.split(os.path.realpath(__file__))[0]
379
371
  if type_name == "c":
380
372
  template = open(os.path.join(script_dir, "c_incremental_cov_report.template"), "r").read()
bmcgo/frame.py CHANGED
@@ -168,12 +168,7 @@ class Frame(object):
168
168
  signal.raise_signal(signal.SIGINT)
169
169
 
170
170
  def run(self):
171
- tool.sudo_passwd_check()
172
- shutil.rmtree(misc.CACHE_DIR)
173
- os.makedirs(misc.CACHE_DIR)
174
- os.chmod(misc.CACHE_DIR, 0o777)
175
- if shutil.which(misc.CONAN) is not None:
176
- tool.run_command("conan remove --locks")
171
+ self._prepare()
177
172
  # 启动全局状态服务
178
173
  signal.signal(signal.SIGINT, self.sigint_handler)
179
174
  signal.signal(signal.SIGTERM, self.sigterm_handler)
@@ -215,3 +210,11 @@ class Frame(object):
215
210
  time.sleep(2)
216
211
  raise errors.BmcGoException(f"任务 {args.target} 执行失败")
217
212
  return 0
213
+
214
+ def _prepare(self):
215
+ tool.sudo_passwd_check()
216
+ shutil.rmtree(misc.CACHE_DIR)
217
+ os.makedirs(misc.CACHE_DIR)
218
+ os.chmod(misc.CACHE_DIR, 0o777)
219
+ if shutil.which(misc.CONAN) is not None:
220
+ tool.run_command("conan remove --locks")
@@ -92,6 +92,21 @@ class BmcgoCommand:
92
92
  uptrace = kwargs.get("uptrace", 1)
93
93
  kwargs["uptrace"] = uptrace
94
94
  return tool.run_command(command, ignore_error, sudo, **kwargs)
95
+
96
+ @staticmethod
97
+ def check_luac():
98
+ luac_path = os.path.join(os.path.expanduser('~'), ".conan", "bin", "luac")
99
+ if not os.path.isfile(luac_path):
100
+ raise errors.BmcGoException(f"当前环境中未安装luac!请更新manifest仓代码,执行环境初始化脚本init.py重新部署环境!")
101
+
102
+ conan_bin = os.path.join(os.path.expanduser('~'), ".conan", "bin")
103
+ # 设置PLD_LIBRARY_PATH环境变量,luajit运行时需要加载so动态库
104
+ ld_library_path = conan_bin + ":" + os.environ.get("LD_LIBRARY_PATH", "")
105
+ os.environ["LD_LIBRARY_PATH"] = ld_library_path
106
+ # 设置PATH环境变量,luajit无需指定全路径
107
+ path = conan_bin + ":" + os.environ.get("PATH", "")
108
+ os.environ["PATH"] = path
109
+ os.environ["LUA_PATH"] = f"{conan_bin}/?.lua"
95
110
 
96
111
  def initialize(self):
97
112
  self.set_package(self.args.conan_package)
@@ -136,48 +151,8 @@ class BmcgoCommand:
136
151
  if self.stage != "dev":
137
152
  self.tag_check()
138
153
 
139
- def install_luac(self):
140
- conan_bin = os.path.join(os.path.expanduser('~'), ".conan", "bin")
141
- # 设置PLD_LIBRARY_PATH环境变量,luajit运行时需要加载so动态库
142
- ld_library_path = conan_bin + ":" + os.environ.get("LD_LIBRARY_PATH", "")
143
- os.environ["LD_LIBRARY_PATH"] = ld_library_path
144
- # 设置PATH环境变量,luajit无需指定全路径
145
- path = conan_bin + ":" + os.environ.get("PATH", "")
146
- os.environ["PATH"] = path
147
- os.environ["LUA_PATH"] = f"{conan_bin}/?.lua"
148
-
149
- # 待安装的luajit版本
150
- luajit_pkg = f"luajit/2.1.0.B012@{tool.conan_user}/{misc.StageEnum.STAGE_STABLE.value}"
151
- luajit_flag = luajit_pkg.split("@")[0].replace("/", "_")
152
- luajit_flag = os.path.join(conan_bin, luajit_flag)
153
-
154
- # 使能luajit时需要安装luajit
155
- luac_path = os.path.join(conan_bin, "luajit")
156
- # luajit版本一致且luac/luajit存在时赋权即可
157
- if os.path.isfile(luajit_flag) and os.path.exists(luac_path):
158
- os.chmod(luac_path, stat.S_IRWXU)
159
- return
160
- Tools.clean_conan_bin(conan_bin)
161
- # 其它情况都尝试安装luajit
162
- cmd = ["conan", "install", luajit_pkg]
163
- cmd += ("-pr profile.dt.ini -if=temp/.deploy -g deploy").split()
164
- if self.remote:
165
- cmd += ["-r", self.remote]
166
- self.run_command(cmd)
167
- cmd = ["cp", "temp/.deploy/luajit/usr/bin/luajit", f"{conan_bin}"]
168
- self.run_command(cmd)
169
- cmd = ["cp", "temp/.deploy/luajit/usr/lib64/liblua.so", f"{conan_bin}"]
170
- self.run_command(cmd)
171
- cmd = ["cp", "-r", "temp/.deploy/luajit/usr/bin/jit", f"{conan_bin}"]
172
- self.run_command(cmd)
173
- os.chmod(luac_path, stat.S_IRWXU)
174
- luajit2luac = shutil.which("luajit2luac.sh")
175
- cmd = ["cp", luajit2luac, f"{conan_bin}/luac"]
176
- self.run_command(cmd)
177
- pathlib.Path(luajit_flag).touch(exist_ok=True)
178
-
179
154
  def run(self):
180
- self.install_luac()
155
+ self.check_luac()
181
156
  if self.path == "" or self.version == "":
182
157
  raise errors.BmcGoException(f"Path({self.path}) or version({self.version}) error")
183
158
  os.chdir(self.bconfig.conan_index.folder)
@@ -14,6 +14,7 @@ import os
14
14
  import stat
15
15
  import re
16
16
  import argparse
17
+ from pathlib import Path
17
18
 
18
19
  from bmcgo import misc
19
20
  from bmcgo.utils.tools import Tools
@@ -59,6 +60,12 @@ _CONFIGS = {
59
60
  misc.JARSIGNER_HTTP_PROXY: {
60
61
  misc.DESCRIPTION: "",
61
62
  misc.PATTERN: r"^((https?://)?[a-zA-Z0-9.]+:[0-9]+)?$"
63
+ },
64
+ misc.JSON_CHECKER: {
65
+ misc.DESCRIPTION: "检查 json 文件的工具"
66
+ },
67
+ misc.CUSTOM_PLUGINS: {
68
+ misc.DESCRIPTION: f"设置插件地址,默认 {Path(misc.DEFAULT_PLUGINS_PATH).resolve()}"
62
69
  }
63
70
  },
64
71
  misc.DEPLOY_HOST_CONST: {