lbkit 0.7.3__tar.gz → 0.8.0__tar.gz
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.
- {lbkit-0.7.3/lbkit.egg-info → lbkit-0.8.0}/PKG-INFO +1 -1
- lbkit-0.8.0/lbkit/__init__.py +2 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/codegen/codegen.py +69 -33
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/codegen/ctype_defination.py +7 -14
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/codegen/idf_interface.py +14 -9
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/codegen/template/client.c.mako +1 -1
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/codegen/template/client.h.mako +1 -1
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/codegen/template/public.c.mako +3 -3
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/codegen/template/public.h.mako +1 -1
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/codegen/template/server.c.mako +2 -2
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/codegen/template/server.h.mako +1 -1
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/component/arg_parser.py +5 -2
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/component/build.py +2 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/component/test.py +9 -6
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/integration/build_manifest.py +5 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/misc.py +3 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/tools.py +4 -3
- lbkit-0.8.0/lbkit/utils/version.py +38 -0
- {lbkit-0.7.3 → lbkit-0.8.0/lbkit.egg-info}/PKG-INFO +1 -1
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit.egg-info/SOURCES.txt +1 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/test/test_codegen.py +71 -4
- lbkit-0.7.3/lbkit/__init__.py +0 -2
- {lbkit-0.7.3 → lbkit-0.8.0}/AUTHORS +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/LICENSE +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/MANIFEST.in +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/README.md +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/build_conan_parallel.py +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/ci_robot/__init__.py +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/ci_robot/gitee.py +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/cli.py +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/codegen/__init__.py +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/codegen/renderer.py +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/codegen/template/interface.c.mako +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/codegen/template/interface.introspect.xml.mako +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/component/__init__.py +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/component/template/conanbase.mako +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/component/template/deploy.mako +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/errors.py +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/helper.py +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/integration/__init__.py +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/integration/build_image.py +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/integration/build_prepare.py +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/integration/build_rootfs.py +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/integration/config.py +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/integration/task.py +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/integration/template/conanfile.py.mako +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/integration/template/rootfs.py.mako +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/lbkit.py +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/log.py +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/utils/__init__.py +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/utils/images/__init__.py +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit/utils/images/emmc.py +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit.egg-info/dependency_links.txt +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit.egg-info/entry_points.txt +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit.egg-info/requires.txt +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/lbkit.egg-info/top_level.txt +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/setup.cfg +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/setup.py +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/test/__init__.py +0 -0
- {lbkit-0.7.3 → lbkit-0.8.0}/test/test_helper.py +0 -0
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
"""
|
|
4
4
|
import os
|
|
5
5
|
import sys
|
|
6
|
+
import re
|
|
6
7
|
import json
|
|
7
8
|
import yaml
|
|
8
9
|
import argparse
|
|
9
10
|
from lbkit.codegen.idf_interface import IdfInterface
|
|
11
|
+
from lbkit.utils.version import Version, X_VER
|
|
10
12
|
|
|
11
13
|
from mako.lookup import TemplateLookup
|
|
12
14
|
from lbkit.log import Logger
|
|
@@ -17,27 +19,69 @@ from lbkit.misc import SmartFormatter
|
|
|
17
19
|
lb_cwd = os.path.split(os.path.realpath(__file__))[0]
|
|
18
20
|
log = Logger("codegen")
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
|
|
23
|
+
class CodeGenHistory():
|
|
24
|
+
def __init__(self, lb_base: str, description: str):
|
|
25
|
+
self.lb_base = lb_base
|
|
26
|
+
self.description = description
|
|
27
|
+
|
|
28
|
+
# 历史自动生成版本号,计划用于用于生成代码稳定性测试
|
|
29
|
+
# TODO: 支持生成代码稳定性测试,确保生成的代码一致性
|
|
30
|
+
history_versions = {
|
|
31
|
+
"5.0": CodeGenHistory("lb_base/[>=0.8.1 <0.9.0]", "简化接口类名定义;简化枚举变量在接口间传递时的字符串定义")
|
|
32
|
+
}
|
|
33
|
+
__version__=Version("5.0")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def version_check(ver_str: str):
|
|
37
|
+
if not re.match("^([0-9]|([1-9][0-9]*))\\.([0-9]|([1-9][0-9]*))$", ver_str):
|
|
38
|
+
raise Exception(f"Version string {ver_str} not match with regex ^([0-9]|([1-9][0-9]*))\\.([0-9]|([1-9][0-9]*))$")
|
|
39
|
+
if "x" not in ver_str:
|
|
40
|
+
return ver_str
|
|
41
|
+
if not history_versions.get(ver_str):
|
|
42
|
+
log.error(f"Unkonw codegen version {ver_str}, supported versions:")
|
|
43
|
+
for ver, msg in history_versions.items():
|
|
44
|
+
log.error(f" {ver}: {msg}")
|
|
45
|
+
raise Exception(f"Can't found the valid version for {ver_str}")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def codegen_version_arg(parser: argparse.ArgumentParser, default=__version__.str, short_arg="-cv", full_arg="--codegen_version"):
|
|
49
|
+
# 默认的自动生成工具版本号为2
|
|
50
|
+
help=f'''must less than or equal to {__version__.str}, default: {default}
|
|
51
|
+
|
|
52
|
+
codegen versions:
|
|
53
|
+
'''
|
|
54
|
+
for ver, detail in history_versions.items():
|
|
55
|
+
help += f"- {ver}: compatible with {detail.lb_base}, {detail.description}\n"
|
|
56
|
+
parser.add_argument(short_arg, full_arg, help=help, type=str, default=__version__.str)
|
|
57
|
+
|
|
21
58
|
|
|
22
59
|
class CodeGen(object):
|
|
23
60
|
def __init__(self, args):
|
|
24
61
|
self.args = args
|
|
25
62
|
self.codegen_version = __version__
|
|
26
|
-
pass
|
|
27
63
|
|
|
28
|
-
def _gen(self, idf_file, directory="."):
|
|
64
|
+
def _gen(self, idf_file, directory=".", code_type="all"):
|
|
29
65
|
directory = os.path.realpath(directory)
|
|
30
|
-
os.makedirs(os.path.join(directory, "public"), exist_ok=True)
|
|
31
|
-
os.makedirs(os.path.join(directory, "server"), exist_ok=True)
|
|
32
|
-
os.makedirs(os.path.join(directory, "client"), exist_ok=True)
|
|
33
66
|
interface = self.get_interface(idf_file)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
out_file = os.path.join(directory,
|
|
40
|
-
interface.
|
|
67
|
+
code_types = ["server", "client", "public"]
|
|
68
|
+
if code_type != "all":
|
|
69
|
+
code_types = [code_type]
|
|
70
|
+
for ct in code_types:
|
|
71
|
+
os.makedirs(os.path.join(directory, ct), exist_ok=True)
|
|
72
|
+
out_file = os.path.join(directory, ct, interface.name + ".xml")
|
|
73
|
+
interface.render_dbus_xml("interface.introspect.xml.mako", out_file)
|
|
74
|
+
out_file = os.path.join(directory, ct, interface.name + ".h")
|
|
75
|
+
interface.render_c_source(ct + ".h.mako", out_file)
|
|
76
|
+
out_file = os.path.join(directory, ct, interface.name + ".c")
|
|
77
|
+
interface.render_c_source(ct + ".c.mako", out_file)
|
|
78
|
+
if "server" == ct:
|
|
79
|
+
# 生成接口schema文件
|
|
80
|
+
odf_file = os.path.join(directory, "server", "schema", f"{interface.name}.json")
|
|
81
|
+
os.makedirs(os.path.dirname(odf_file), exist_ok=True)
|
|
82
|
+
odf_data = interface.odf_schema
|
|
83
|
+
with open(odf_file, "w", encoding="utf-8") as fp:
|
|
84
|
+
json.dump(odf_data, fp, sort_keys=False, indent=4)
|
|
41
85
|
json_file = os.path.join(directory, "package.yml")
|
|
42
86
|
data = {
|
|
43
87
|
"version": interface.version,
|
|
@@ -46,16 +90,9 @@ class CodeGen(object):
|
|
|
46
90
|
with open(json_file, "w", encoding="utf-8") as fp:
|
|
47
91
|
yaml.dump(data, fp, encoding='utf-8', allow_unicode=True)
|
|
48
92
|
|
|
49
|
-
# 生成接口schema文件
|
|
50
|
-
odf_file = os.path.join(directory, "server", "schema", f"{interface.name}.json")
|
|
51
|
-
os.makedirs(os.path.dirname(odf_file), exist_ok=True)
|
|
52
|
-
odf_data = interface.odf_schema
|
|
53
|
-
with open(odf_file, "w", encoding="utf-8") as fp:
|
|
54
|
-
json.dump(odf_data, fp, sort_keys=False, indent=4)
|
|
55
|
-
|
|
56
93
|
def get_interface(self, idf_file):
|
|
57
94
|
lookup = TemplateLookup(directories=os.path.join(lb_cwd, "template"))
|
|
58
|
-
return IdfInterface(lookup, idf_file,
|
|
95
|
+
return IdfInterface(lookup, idf_file, self.codegen_version)
|
|
59
96
|
|
|
60
97
|
def run(self):
|
|
61
98
|
"""
|
|
@@ -66,14 +103,9 @@ class CodeGen(object):
|
|
|
66
103
|
parser = argparse.ArgumentParser(description=self.run.__doc__,
|
|
67
104
|
prog="lbkit gen",
|
|
68
105
|
formatter_class=SmartFormatter)
|
|
69
|
-
|
|
70
|
-
parser.add_argument("-cv", "--codegen_version", help=f'''must less than or equal to {__version__}, default: 2
|
|
71
|
-
description of changes:
|
|
72
|
-
3: compatible with lb_base/0.7.x
|
|
73
|
-
2: compatible with lb_base/0.6.x
|
|
74
|
-
''',
|
|
75
|
-
type=int, default=2)
|
|
106
|
+
codegen_version_arg(parser)
|
|
76
107
|
parser.add_argument("-d", "--directory", help='generate code directory', default=".")
|
|
108
|
+
parser.add_argument("-t", "--codetype", help='code type, default: all', default="all", choices=["public", "server", "client", "all"])
|
|
77
109
|
group2 = parser.add_argument_group('cdf file', 'Generate code using the specified CDF file')
|
|
78
110
|
group2.add_argument("-c", "--cdf_file", help='component description file, default metadata/package.yml', default=None)
|
|
79
111
|
group1 = parser.add_argument_group('idf file', 'Generate code using the specified IDF file')
|
|
@@ -86,7 +118,9 @@ class CodeGen(object):
|
|
|
86
118
|
raise ArgException(f"argument -c/--cdf_file: {args.cdf_file} not exist")
|
|
87
119
|
configs = Helper.read_yaml(args.cdf_file, "codegen", [])
|
|
88
120
|
# 为保障兼容,package.yml未指定版本号的,默认使用2,该版本配套lb_base/0.6.0版本,其LBProperty无set/get成员
|
|
89
|
-
|
|
121
|
+
ver_str = Helper.read_yaml(args.cdf_file, "codegen_version", args.codegen_version)
|
|
122
|
+
version_check(ver_str)
|
|
123
|
+
self.codegen_version = Version(ver_str)
|
|
90
124
|
for cfg in configs:
|
|
91
125
|
file = cfg.get("file")
|
|
92
126
|
if file is None:
|
|
@@ -101,15 +135,17 @@ class CodeGen(object):
|
|
|
101
135
|
outdir = cfg.get("outdir", os.getcwd())
|
|
102
136
|
self._gen(file, outdir)
|
|
103
137
|
return
|
|
138
|
+
else:
|
|
139
|
+
version_check(args.codegen_version)
|
|
140
|
+
self.codegen_version = Version(args.codegen_version)
|
|
104
141
|
|
|
105
142
|
intf_file = args.idf_file
|
|
106
143
|
if not intf_file:
|
|
107
144
|
raise ArgException(f"argument error, arguments -c/--cdf_file and -i/--idf_file are not set")
|
|
108
145
|
if not os.path.isfile(intf_file):
|
|
109
146
|
raise ArgException(f"argument -i/--idf_file: {args.idf_file} not exist")
|
|
110
|
-
if
|
|
111
|
-
raise ArgException(f"argument -
|
|
112
|
-
self.codegen_version = args.codegen_version
|
|
147
|
+
if self.codegen_version.bt(__version__.str):
|
|
148
|
+
raise ArgException(f"argument -cv/--codegen_version: validate failed, must less than or equal to {__version__.str}")
|
|
113
149
|
out_dir = os.path.join(os.getcwd(), args.directory)
|
|
114
150
|
if not intf_file.endswith(".yaml"):
|
|
115
151
|
raise ArgException(f"The IDF file ({intf_file}) not endswith .yaml")
|
|
@@ -118,7 +154,7 @@ class CodeGen(object):
|
|
|
118
154
|
if not os.path.isdir(out_dir):
|
|
119
155
|
log.warning(f"Directory {args.directory} not exist, try create")
|
|
120
156
|
os.makedirs(out_dir)
|
|
121
|
-
self._gen(intf_file, out_dir)
|
|
157
|
+
self._gen(intf_file, out_dir, args.codetype)
|
|
122
158
|
|
|
123
159
|
if __name__ == "__main__":
|
|
124
160
|
gen = CodeGen(sys.argv)
|
|
@@ -4,20 +4,19 @@ from lbkit.errors import OdfValidateException
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
class IdfValidator():
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
def __init__(self):
|
|
8
|
+
self.validator = {}
|
|
9
|
+
self.name = ""
|
|
9
10
|
|
|
10
11
|
def set_validator(self, value, name):
|
|
11
12
|
self.validator = value
|
|
12
13
|
self.name = name
|
|
13
14
|
|
|
14
15
|
def odf_validate(self):
|
|
15
|
-
idf_validator = idf_validator
|
|
16
16
|
return []
|
|
17
17
|
|
|
18
18
|
def odf_schema(self, allow_ref):
|
|
19
19
|
allow_ref = allow_ref
|
|
20
|
-
idf_validator = idf_validator
|
|
21
20
|
return None
|
|
22
21
|
|
|
23
22
|
|
|
@@ -73,9 +72,6 @@ class BoolArrayValidator(BoolValidator):
|
|
|
73
72
|
|
|
74
73
|
|
|
75
74
|
class IntegerValidator(IdfValidator):
|
|
76
|
-
maximum = sys.maxsize * 2
|
|
77
|
-
minimum = -(sys.maxsize + 1) * 2
|
|
78
|
-
|
|
79
75
|
def __init__(self, max, min, signed=False):
|
|
80
76
|
self.maximum = max
|
|
81
77
|
self.minimum = min
|
|
@@ -188,13 +184,11 @@ class IntegerArrayValidator(IntegerValidator):
|
|
|
188
184
|
|
|
189
185
|
|
|
190
186
|
class FloatValidator(IdfValidator):
|
|
191
|
-
maximum = sys.float_info.max
|
|
192
|
-
minimum = -sys.float_info.max
|
|
193
|
-
|
|
194
|
-
exclusive_max = None
|
|
195
|
-
exclusive_min = None
|
|
196
|
-
|
|
197
187
|
def __init__(self):
|
|
188
|
+
self.maximum = sys.float_info.max
|
|
189
|
+
self.minimum = -sys.float_info.max
|
|
190
|
+
self.exclusive_max = None
|
|
191
|
+
self.exclusive_min = None
|
|
198
192
|
self.max_key = "maximum"
|
|
199
193
|
self.max_val = self.maximum
|
|
200
194
|
self.min_key = "minimum"
|
|
@@ -294,7 +288,6 @@ class FloatArrayValidator(FloatValidator):
|
|
|
294
288
|
|
|
295
289
|
|
|
296
290
|
class StringValidator(IdfValidator):
|
|
297
|
-
pattern = None
|
|
298
291
|
def __init__(self, pattern):
|
|
299
292
|
self.pattern = pattern
|
|
300
293
|
super().__init__()
|
|
@@ -9,6 +9,7 @@ from lbkit.codegen.ctype_defination import CTYPE_OBJS, RefObjArrayValidator, Ref
|
|
|
9
9
|
from lbkit.misc import load_yml_with_json_schema_validate
|
|
10
10
|
from lbkit.errors import OdfValidateException, LiteBmcException
|
|
11
11
|
from lbkit.helper import SigInvalidException, validate_glib_signature
|
|
12
|
+
from lbkit.utils.version import Version
|
|
12
13
|
|
|
13
14
|
log = Logger("gen_interface")
|
|
14
15
|
|
|
@@ -35,7 +36,7 @@ class IdfInterfaceBase(Renderer):
|
|
|
35
36
|
self.description = None
|
|
36
37
|
self.version = None
|
|
37
38
|
self.alias = None
|
|
38
|
-
self.codegen_version:
|
|
39
|
+
self.codegen_version: Version = None
|
|
39
40
|
|
|
40
41
|
class IdfAnnotation():
|
|
41
42
|
def __init__(self, name, value):
|
|
@@ -239,7 +240,7 @@ class IdfCtypeRender():
|
|
|
239
240
|
if "refobj" in self.flags:
|
|
240
241
|
valiator = RefObjValidator()
|
|
241
242
|
return valiator.odf_schema(allow_ref)
|
|
242
|
-
ctype_obj = CTYPE_OBJS.get(self.ctype)
|
|
243
|
+
ctype_obj = copy.deepcopy(CTYPE_OBJS.get(self.ctype))
|
|
243
244
|
validator = ctype_obj.validator
|
|
244
245
|
if validator_cfg:
|
|
245
246
|
validator.set_validator(validator_cfg, self.name)
|
|
@@ -930,7 +931,7 @@ class IdfEnumeration(IdfBase):
|
|
|
930
931
|
def odf_schema(self):
|
|
931
932
|
values = []
|
|
932
933
|
for prop in self.values.parameters:
|
|
933
|
-
if self.intf.codegen_version
|
|
934
|
+
if self.intf.codegen_version.lt("5.0"):
|
|
934
935
|
val = self.intf.name + "." + self.name + "." + prop.name
|
|
935
936
|
else:
|
|
936
937
|
val = prop.name
|
|
@@ -1034,7 +1035,7 @@ class IdfDictionary():
|
|
|
1034
1035
|
|
|
1035
1036
|
|
|
1036
1037
|
class IdfInterface(IdfInterfaceBase):
|
|
1037
|
-
def __init__(self, lookup, idf_file, codegen_version):
|
|
1038
|
+
def __init__(self, lookup, idf_file, codegen_version: Version):
|
|
1038
1039
|
if not idf_file.endswith(".yaml") and not idf_file.endswith(".yml"):
|
|
1039
1040
|
raise IDFException(f"IDF file {idf_file} neither endswith .yaml nor endswith .yml")
|
|
1040
1041
|
super().__init__()
|
|
@@ -1066,13 +1067,17 @@ class IdfInterface(IdfInterfaceBase):
|
|
|
1066
1067
|
realpath = None
|
|
1067
1068
|
while cwd != "/":
|
|
1068
1069
|
tmp_path = os.path.join(cwd, intf_path)
|
|
1070
|
+
if os.path.isfile(tmp_path):
|
|
1071
|
+
realpath = tmp_path
|
|
1072
|
+
break
|
|
1073
|
+
tmp_path = os.path.join(cwd, intf + ".yaml")
|
|
1069
1074
|
if os.path.isfile(tmp_path):
|
|
1070
1075
|
realpath = tmp_path
|
|
1071
1076
|
break
|
|
1072
1077
|
cwd = os.path.dirname(cwd)
|
|
1073
1078
|
|
|
1074
1079
|
if not realpath:
|
|
1075
|
-
raise FileNotFoundError(f"Dependency interface {intf} not exist")
|
|
1080
|
+
raise FileNotFoundError(f"Dependency interface {intf} not exist, cwd: {os.getcwd()}")
|
|
1076
1081
|
log.debug(f"Found dependency interface: {realpath}")
|
|
1077
1082
|
deps[intf] = (IdfInterface(self.lookup, realpath, self.codegen_version))
|
|
1078
1083
|
return deps
|
|
@@ -1238,8 +1243,8 @@ class IdfInterface(IdfInterfaceBase):
|
|
|
1238
1243
|
intf_stru = IdfStructure(self, idf, propety_key="properties")
|
|
1239
1244
|
self.structures[self.alias] = intf_stru
|
|
1240
1245
|
|
|
1241
|
-
def render_dbus_xml(self, template, out_file
|
|
1242
|
-
out = self.render(self.lookup, template, intf=self, codegen_version=codegen_version)
|
|
1246
|
+
def render_dbus_xml(self, template, out_file):
|
|
1247
|
+
out = self.render(self.lookup, template, intf=self, codegen_version=self.codegen_version)
|
|
1243
1248
|
hash = hashlib.sha256()
|
|
1244
1249
|
hash.update(out.encode('utf-8'))
|
|
1245
1250
|
self.introspect_xml_sha256 = hash.hexdigest()
|
|
@@ -1247,9 +1252,9 @@ class IdfInterface(IdfInterfaceBase):
|
|
|
1247
1252
|
with open(out_file, "w") as fd:
|
|
1248
1253
|
fd.write(out)
|
|
1249
1254
|
|
|
1250
|
-
def render_c_source(self, template, out_file
|
|
1255
|
+
def render_c_source(self, template, out_file):
|
|
1251
1256
|
|
|
1252
|
-
out = self.render(self.lookup, template, intf=self, codegen_version=codegen_version)
|
|
1257
|
+
out = self.render(self.lookup, template, intf=self, codegen_version=self.codegen_version)
|
|
1253
1258
|
with open(out_file, "w") as fd:
|
|
1254
1259
|
fd.write(out)
|
|
1255
1260
|
|
|
@@ -192,7 +192,7 @@ ${class_name}_Properties *${class_name}_properties(void)
|
|
|
192
192
|
return &${properties};
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
% if codegen_version
|
|
195
|
+
% if codegen_version.be("4.0"):
|
|
196
196
|
${class_name} ${class_name}_get(const gchar *well_known, const gchar *name)
|
|
197
197
|
{
|
|
198
198
|
return lb_impl._cli_get(&_${class_name}_interface, well_known, name);
|
|
@@ -110,7 +110,7 @@ ${class_name}_Properties *${class_name}_properties(void);
|
|
|
110
110
|
LBInterface *${class_name}_interface(void);
|
|
111
111
|
#define ${hump2underline(class_name).upper()} ${class_name}_interface()
|
|
112
112
|
|
|
113
|
-
% if codegen_version
|
|
113
|
+
% if codegen_version.be("4.0"):
|
|
114
114
|
/* notes: 对象变更加回调函数 */
|
|
115
115
|
typedef void (*${class_name}_on_changed_hook)(${class_name} lb_obj, gpointer user_data);
|
|
116
116
|
/* notes: 属性变更后回调,远程对象或本地对象变更后都会调用 */
|
|
@@ -265,7 +265,7 @@ gboolean _validate_odf_as_struct_${name}_v(yaml_document_t *doc, yaml_node_t *no
|
|
|
265
265
|
|
|
266
266
|
%endfor
|
|
267
267
|
% for name, enum in intf.enumerations.items():
|
|
268
|
-
% if codegen_version
|
|
268
|
+
% if codegen_version.be("5.0"):
|
|
269
269
|
## 枚举序列化和反序列化函数
|
|
270
270
|
static const gchar *_${name}StrMap[] = {
|
|
271
271
|
% for value in enum.values.parameters:
|
|
@@ -888,7 +888,7 @@ static GDBusPropertyInfo ${class_name}_property_${prop.name} =
|
|
|
888
888
|
% endif
|
|
889
889
|
% endfor
|
|
890
890
|
## 只有自动生成工具版本号大于等于3的才会生成get和set方法
|
|
891
|
-
% if codegen_version
|
|
891
|
+
% if codegen_version.be("3.0"):
|
|
892
892
|
% if len(intf.properties):
|
|
893
893
|
static LBBase *_get_real_object(${class_name} object)
|
|
894
894
|
{
|
|
@@ -939,7 +939,7 @@ static ${class_name}_Properties _${class_name}_properties =
|
|
|
939
939
|
.info = NULL, /* load from /usr/share/dbus-1/interfaces/${intf.name} by lb_init */
|
|
940
940
|
% endif
|
|
941
941
|
.offset = offsetof(struct _${class_name}, ${prop.name}),
|
|
942
|
-
% if codegen_version
|
|
942
|
+
% if codegen_version.be("3.0"):
|
|
943
943
|
.flags = ${prop.desc_flags},
|
|
944
944
|
.set = ${class_name}_set_${prop.name}_variant,
|
|
945
945
|
.get = ${class_name}_get_${prop.name}_variant
|
|
@@ -86,7 +86,7 @@ struct _${name} **_load_odf_as_${name}_v(yaml_document_t *doc, yaml_node_t *node
|
|
|
86
86
|
% for name, enum in intf.enumerations.items():
|
|
87
87
|
${name} _load_odf_as_${name}(yaml_document_t *doc, yaml_node_t *node)
|
|
88
88
|
{
|
|
89
|
-
% if codegen_version
|
|
89
|
+
% if codegen_version.be("5.0"):
|
|
90
90
|
g_assert(node->type == YAML_SCALAR_NODE);
|
|
91
91
|
if (node->type != YAML_SCALAR_NODE) {
|
|
92
92
|
return _${name}_Invalid;
|
|
@@ -482,7 +482,7 @@ ${class_name}_Properties *${class_name}_properties(void)
|
|
|
482
482
|
return &${properties};
|
|
483
483
|
}
|
|
484
484
|
|
|
485
|
-
% if codegen_version
|
|
485
|
+
% if codegen_version.be("4.0"):
|
|
486
486
|
${class_name} ${class_name}_get(const gchar *name)
|
|
487
487
|
{
|
|
488
488
|
return lb_impl._get(&_${class_name}_interface, name);
|
|
@@ -56,7 +56,7 @@ ${class_name}_Properties *${class_name}_properties(void);
|
|
|
56
56
|
|
|
57
57
|
#define ${hump2underline(class_name).upper()} ${class_name}_interface()
|
|
58
58
|
|
|
59
|
-
% if codegen_version
|
|
59
|
+
% if codegen_version.be("4.0"):
|
|
60
60
|
/* notes: 对象变更加回调函数 */
|
|
61
61
|
typedef void (*${class_name}_on_changed_hook)(${class_name} lb_obj, gpointer user_data);
|
|
62
62
|
/* notes: 属性变更后回调,远程对象或本地对象变更后都会调用 */
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"""组件公共参数"""
|
|
2
2
|
import argparse
|
|
3
3
|
import os
|
|
4
|
-
from
|
|
4
|
+
from lbkit.misc import SmartFormatter
|
|
5
|
+
from lbkit.codegen.codegen import codegen_version_arg
|
|
5
6
|
|
|
6
7
|
cwd = os.getcwd()
|
|
7
8
|
lb_cwd = os.path.split(os.path.realpath(__file__))[0]
|
|
@@ -11,7 +12,7 @@ class ArgParser():
|
|
|
11
12
|
@staticmethod
|
|
12
13
|
def new(add_help=True):
|
|
13
14
|
parser = argparse.ArgumentParser(
|
|
14
|
-
description="Build component", add_help=add_help, formatter_class=
|
|
15
|
+
description="Build component", add_help=add_help, formatter_class=SmartFormatter)
|
|
15
16
|
parser.add_argument("-t", "--build_type", default="Debug",
|
|
16
17
|
help="Build type(Same as conan's settings.build_type), only Debug,Release can be accepted")
|
|
17
18
|
parser.add_argument("-pr", "--profile", default="default",
|
|
@@ -35,4 +36,6 @@ class ArgParser():
|
|
|
35
36
|
parser.add_argument(
|
|
36
37
|
"-c", "--channel", help='Provide a channel if not specified in mds/package.yml\ndefault value: dev', default="dev")
|
|
37
38
|
parser.add_argument('-o','--pkg_options', action='append', help='Define options values (host machine), e.g.: -o pkg/*:shared=True', required=False, default=[])
|
|
39
|
+
# 默认的自动生成工具版本号为
|
|
40
|
+
codegen_version_arg(parser, None)
|
|
38
41
|
return parser
|
|
@@ -83,6 +83,8 @@ class BuildComponent():
|
|
|
83
83
|
self.base_cmd += f" -o {self.name}/*:test=True"
|
|
84
84
|
for pkg_option in self.options.pkg_options:
|
|
85
85
|
self.base_cmd += " -o " + pkg_option
|
|
86
|
+
if self.options.codegen_version:
|
|
87
|
+
self.base_cmd += f" -o */*:codegen_version={self.options.codegen_version}"
|
|
86
88
|
|
|
87
89
|
def get_package_version(self):
|
|
88
90
|
"""
|
|
@@ -75,14 +75,17 @@ class TestComponent():
|
|
|
75
75
|
res = tool.run(cmd)
|
|
76
76
|
files = res.stdout.strip().split("\n")
|
|
77
77
|
ld_library_path = os.environ.get("LD_LIBRARY_PATH", "").strip()
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
paths = []
|
|
79
|
+
for path in ld_library_path.split(":"):
|
|
80
|
+
if not path:
|
|
81
|
+
continue
|
|
82
|
+
if not ".temp/rootfs" in path:
|
|
83
|
+
paths.append(path)
|
|
81
84
|
for file in files:
|
|
82
85
|
dir = os.path.dirname(file)
|
|
83
|
-
if dir not in
|
|
84
|
-
|
|
85
|
-
os.environ["LD_LIBRARY_PATH"] = ":".join(
|
|
86
|
+
if dir not in paths:
|
|
87
|
+
paths.append(dir)
|
|
88
|
+
os.environ["LD_LIBRARY_PATH"] = ":".join(paths)
|
|
86
89
|
|
|
87
90
|
def run(self):
|
|
88
91
|
# 构建组件
|
|
@@ -9,6 +9,7 @@ from lbkit.log import Logger
|
|
|
9
9
|
from lbkit.build_conan_parallel import BuildConanParallel
|
|
10
10
|
from concurrent.futures import ThreadPoolExecutor
|
|
11
11
|
from lbkit.errors import LiteBmcException
|
|
12
|
+
from lbkit.codegen.codegen import __version__ as codegen_version
|
|
12
13
|
|
|
13
14
|
log = Logger("product_build")
|
|
14
15
|
|
|
@@ -35,6 +36,10 @@ class BuildManifest(Task):
|
|
|
35
36
|
self.common_args = "-r " + self.config.remote
|
|
36
37
|
self.common_args += " -pr:b {} -pr:h {}".format(self.config.profile_build, self.config.profile_host)
|
|
37
38
|
self.common_args += " -o */*:test=False"
|
|
39
|
+
cv = self.get_manifest_config("metadata/codegen_version")
|
|
40
|
+
if cv == "latest":
|
|
41
|
+
cv = codegen_version.str
|
|
42
|
+
self.common_args += " -o */*:codegen_version=" + cv
|
|
38
43
|
|
|
39
44
|
def deploy(self, graph_file):
|
|
40
45
|
with open(graph_file, "r") as fp:
|
|
@@ -17,9 +17,10 @@ from lbkit.misc import Color
|
|
|
17
17
|
|
|
18
18
|
class Tools(object):
|
|
19
19
|
"""基础工具类"""
|
|
20
|
-
def __init__(self, log_name: str):
|
|
21
|
-
os.
|
|
22
|
-
|
|
20
|
+
def __init__(self, log_name: str, log_dir: str=".temp"):
|
|
21
|
+
self.log_dir = os.path.realpath(log_dir)
|
|
22
|
+
os.makedirs(self.log_dir, exist_ok=True)
|
|
23
|
+
self.log_name = os.path.join(self.log_dir, f"{log_name}.log")
|
|
23
24
|
self.log: Logger = Logger(log_name)
|
|
24
25
|
|
|
25
26
|
@staticmethod
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""环境准备"""
|
|
2
|
+
import re
|
|
3
|
+
|
|
4
|
+
X_VER = 0x7fff_ffff
|
|
5
|
+
|
|
6
|
+
class Version():
|
|
7
|
+
def __init__(self, ver_str):
|
|
8
|
+
if not re.match("^([0-9]|([1-9][0-9]*))\\.([0-9]|([1-9][0-9]*))$", ver_str):
|
|
9
|
+
raise Exception("Version string {ver_str} not match with regex ^([0-9]|([1-9][0-9]*))\\.([0-9]|([1-9][0-9]*))$")
|
|
10
|
+
chunks = ver_str.split(".")
|
|
11
|
+
self.major = int(chunks[0])
|
|
12
|
+
self.minor = int(chunks[1])
|
|
13
|
+
self.str = str(self.major) + "." + str(self.minor)
|
|
14
|
+
|
|
15
|
+
def bt(self, next_ver):
|
|
16
|
+
next = Version(next_ver)
|
|
17
|
+
if self.major > next.major or (self.major == next.major and self.minor > next.minor):
|
|
18
|
+
return True
|
|
19
|
+
return False
|
|
20
|
+
|
|
21
|
+
def be(self, next_ver):
|
|
22
|
+
next = Version(next_ver)
|
|
23
|
+
if self.major > next.major or (self.major == next.major and self.minor >= next.minor):
|
|
24
|
+
return True
|
|
25
|
+
return False
|
|
26
|
+
|
|
27
|
+
def lt(self, next_ver):
|
|
28
|
+
next = Version(next_ver)
|
|
29
|
+
if self.major < next.major or (self.major == next.major and self.minor < next.minor):
|
|
30
|
+
return True
|
|
31
|
+
return False
|
|
32
|
+
|
|
33
|
+
def le(self, next_ver):
|
|
34
|
+
next = Version(next_ver)
|
|
35
|
+
if self.major < next.major or (self.major == next.major and self.minor <= next.minor):
|
|
36
|
+
return True
|
|
37
|
+
return False
|
|
38
|
+
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import unittest
|
|
2
2
|
import tempfile
|
|
3
3
|
import os
|
|
4
|
+
import json
|
|
4
5
|
import tracemalloc
|
|
5
6
|
|
|
6
7
|
tracemalloc.start()
|
|
7
8
|
from lbkit.codegen.idf_interface import IdfInterface
|
|
8
9
|
from lbkit import errors
|
|
9
10
|
from lbkit.codegen.codegen import __version__ as codegen_version
|
|
11
|
+
from lbkit.codegen.codegen import history_versions as codegen_history
|
|
12
|
+
from lbkit.utils.version import Version
|
|
10
13
|
|
|
11
14
|
schema_dir = os.path.realpath(os.path.join(os.getcwd(), "..", "schema"))
|
|
12
15
|
|
|
@@ -27,7 +30,7 @@ class TestCodeGenClass(unittest.TestCase):
|
|
|
27
30
|
def mk_interface_with_number_property(self, name, type, max, min, default_val):
|
|
28
31
|
with open(self.tmp_file, mode="w+") as fp:
|
|
29
32
|
fp.write(f"# yaml-language-server: $schema={schema_dir}/idf.v1.json\n")
|
|
30
|
-
fp.write("version:
|
|
33
|
+
fp.write("version: 1\n")
|
|
31
34
|
fp.write("description: 测试接口,用于验证lb_base/lb_core,同时验证自动生成逻辑\n")
|
|
32
35
|
fp.write("alias: Test\n")
|
|
33
36
|
fp.write("properties:\n")
|
|
@@ -41,7 +44,7 @@ class TestCodeGenClass(unittest.TestCase):
|
|
|
41
44
|
def mk_interface_with_string_property(self, name, type, pattern, default_val):
|
|
42
45
|
with open(self.tmp_file, mode="w+") as fp:
|
|
43
46
|
fp.write(f"# yaml-language-server: $schema={schema_dir}/idf.v1.json\n")
|
|
44
|
-
fp.write("version:
|
|
47
|
+
fp.write("version: 1\n")
|
|
45
48
|
fp.write("description: 测试接口,用于验证lb_base/lb_core,同时验证自动生成逻辑\n")
|
|
46
49
|
fp.write("alias: Test\n")
|
|
47
50
|
fp.write("properties:\n")
|
|
@@ -55,7 +58,7 @@ class TestCodeGenClass(unittest.TestCase):
|
|
|
55
58
|
def mk_interface_with_double_property(self, name, type, default_val, max=None, min=None, exclusive_max=None, exclusive_min=None):
|
|
56
59
|
with open(self.tmp_file, mode="w+") as fp:
|
|
57
60
|
fp.write(f"# yaml-language-server: $schema={schema_dir}/idf.v1.json\n")
|
|
58
|
-
fp.write("version:
|
|
61
|
+
fp.write("version: 1\n")
|
|
59
62
|
fp.write("description: 测试接口,用于验证lb_base/lb_core,同时验证自动生成逻辑\n")
|
|
60
63
|
fp.write("alias: Test\n")
|
|
61
64
|
fp.write("properties:\n")
|
|
@@ -76,7 +79,7 @@ class TestCodeGenClass(unittest.TestCase):
|
|
|
76
79
|
def validate_boolean(self, name, type, default):
|
|
77
80
|
with open(self.tmp_file, mode="w+") as fp:
|
|
78
81
|
fp.write(f"# yaml-language-server: $schema={schema_dir}/idf.v1.json\n")
|
|
79
|
-
fp.write("version:
|
|
82
|
+
fp.write("version: 1\n")
|
|
80
83
|
fp.write("description: 测试接口,用于验证lb_base/lb_core,同时验证自动生成逻辑\n")
|
|
81
84
|
fp.write("alias: Test\n")
|
|
82
85
|
fp.write("properties:\n")
|
|
@@ -280,5 +283,69 @@ class TestCodeGenClass(unittest.TestCase):
|
|
|
280
283
|
IdfInterface(None, self.tmp_file, codegen_version)
|
|
281
284
|
|
|
282
285
|
|
|
286
|
+
class TestVersionClass(unittest.TestCase):
|
|
287
|
+
def test_version_bt(self):
|
|
288
|
+
self.assertTrue(Version("6.3").bt("5.2"))
|
|
289
|
+
self.assertTrue(Version("6.2").bt("5.2"))
|
|
290
|
+
self.assertTrue(Version("6.1").bt("5.2"))
|
|
291
|
+
self.assertTrue(Version("5.3").bt("5.2"))
|
|
292
|
+
self.assertFalse(Version("5.2").bt("5.2"))
|
|
293
|
+
self.assertFalse(Version("5.1").bt("5.2"))
|
|
294
|
+
self.assertFalse(Version("4.3").bt("5.2"))
|
|
295
|
+
self.assertFalse(Version("4.2").bt("5.2"))
|
|
296
|
+
self.assertFalse(Version("4.1").bt("5.2"))
|
|
297
|
+
|
|
298
|
+
def test_version_be(self):
|
|
299
|
+
self.assertTrue(Version("6.3").be("5.2"))
|
|
300
|
+
self.assertTrue(Version("6.2").be("5.2"))
|
|
301
|
+
self.assertTrue(Version("6.1").be("5.2"))
|
|
302
|
+
self.assertTrue(Version("5.3").be("5.2"))
|
|
303
|
+
self.assertTrue(Version("5.2").be("5.2"))
|
|
304
|
+
self.assertFalse(Version("5.1").be("5.2"))
|
|
305
|
+
self.assertFalse(Version("4.3").be("5.2"))
|
|
306
|
+
self.assertFalse(Version("4.2").be("5.2"))
|
|
307
|
+
self.assertFalse(Version("4.1").be("5.2"))
|
|
308
|
+
|
|
309
|
+
def test_version_le(self):
|
|
310
|
+
self.assertFalse(Version("6.3").le("5.2"))
|
|
311
|
+
self.assertFalse(Version("6.2").le("5.2"))
|
|
312
|
+
self.assertFalse(Version("6.1").le("5.2"))
|
|
313
|
+
self.assertFalse(Version("5.3").le("5.2"))
|
|
314
|
+
self.assertTrue(Version("5.2").le("5.2"))
|
|
315
|
+
self.assertTrue(Version("5.1").le("5.2"))
|
|
316
|
+
self.assertTrue(Version("4.3").le("5.2"))
|
|
317
|
+
self.assertTrue(Version("4.2").le("5.2"))
|
|
318
|
+
self.assertTrue(Version("4.1").le("5.2"))
|
|
319
|
+
|
|
320
|
+
def test_version_lt(self):
|
|
321
|
+
self.assertFalse(Version("6.3").lt("5.2"))
|
|
322
|
+
self.assertFalse(Version("6.2").lt("5.2"))
|
|
323
|
+
self.assertFalse(Version("6.1").lt("5.2"))
|
|
324
|
+
self.assertFalse(Version("5.3").lt("5.2"))
|
|
325
|
+
self.assertFalse(Version("5.2").lt("5.2"))
|
|
326
|
+
self.assertTrue(Version("5.1").lt("5.2"))
|
|
327
|
+
self.assertTrue(Version("4.3").lt("5.2"))
|
|
328
|
+
self.assertTrue(Version("4.2").lt("5.2"))
|
|
329
|
+
self.assertTrue(Version("4.1").lt("5.2"))
|
|
330
|
+
|
|
331
|
+
def test_codegen_version_schema(self):
|
|
332
|
+
"""
|
|
333
|
+
测试pdf模式文件的metadata/codegen_version可选值与codegen.py的history_versions是否保持一致
|
|
334
|
+
"""
|
|
335
|
+
pdf_file = os.path.join("..", "schema", "pdf.v1.json")
|
|
336
|
+
pdf_file = os.path.realpath(pdf_file)
|
|
337
|
+
with open(pdf_file, "r") as fp:
|
|
338
|
+
data = json.load(fp)
|
|
339
|
+
data = data.get("properties", {}).get("metadata", {})
|
|
340
|
+
data = data.get("properties", {}).get("codegen_version", {})
|
|
341
|
+
data = data.get("enum", [])
|
|
342
|
+
data.sort()
|
|
343
|
+
# latest表示最新的版本生成工具版本号
|
|
344
|
+
versions = ["latest"]
|
|
345
|
+
for ver, _ in codegen_history.items():
|
|
346
|
+
versions.append(ver)
|
|
347
|
+
versions.sort()
|
|
348
|
+
self.assertTrue(data == versions)
|
|
349
|
+
|
|
283
350
|
if __name__ == "__main__":
|
|
284
351
|
unittest.main()
|
lbkit-0.7.3/lbkit/__init__.py
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|