lbkit 0.5.20__tar.gz → 0.5.21__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.5.20/lbkit.egg-info → lbkit-0.5.21}/PKG-INFO +1 -1
- lbkit-0.5.21/lbkit/__init__.py +2 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/cli.py +6 -2
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/codegen/codegen.py +42 -19
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/codegen/idf_interface.py +4 -5
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/codegen/template/public.c.mako +45 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/component/build.py +2 -2
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/helper.py +1 -1
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/misc.py +7 -0
- {lbkit-0.5.20 → lbkit-0.5.21/lbkit.egg-info}/PKG-INFO +1 -1
- lbkit-0.5.20/lbkit/__init__.py +0 -2
- {lbkit-0.5.20 → lbkit-0.5.21}/AUTHORS +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/LICENSE +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/MANIFEST.in +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/README.md +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/ci_robot/__init__.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/ci_robot/gitee.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/codegen/__init__.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/codegen/ctype_defination.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/codegen/renderer.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/codegen/template/client.c.mako +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/codegen/template/client.h.mako +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/codegen/template/interface.c.mako +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/codegen/template/interface.introspect.xml.mako +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/codegen/template/public.h.mako +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/codegen/template/server.c.mako +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/codegen/template/server.h.mako +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/component/__init__.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/component/arg_parser.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/component/template/conanbase.mako +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/component/template/deploy.mako +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/component/test.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/errors.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/integration/__init__.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/integration/build_image.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/integration/build_manifest.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/integration/build_prepare.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/integration/build_rootfs.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/integration/config.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/integration/task.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/integration/template/conanfile.py.mako +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/lbkit.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/log.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit/tools.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit.egg-info/SOURCES.txt +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit.egg-info/dependency_links.txt +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit.egg-info/entry_points.txt +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit.egg-info/requires.txt +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/lbkit.egg-info/top_level.txt +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/setup.cfg +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/setup.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/test/__init__.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/test/test_codegen.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.21}/test/test_helper.py +0 -0
|
@@ -57,8 +57,12 @@ class Command(object):
|
|
|
57
57
|
|
|
58
58
|
支持自动生成服务端和客户端C代码
|
|
59
59
|
"""
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
argv = sys.argv[2:]
|
|
61
|
+
if "-i" not in argv and "-c" not in argv:
|
|
62
|
+
if os.path.isfile("./metadata/package.yml"):
|
|
63
|
+
argv.extend(["-c", "./metadata/package.yml"])
|
|
64
|
+
gen = CodeGen(argv)
|
|
65
|
+
gen.run()
|
|
62
66
|
|
|
63
67
|
# new package
|
|
64
68
|
def new(self, *args):
|
|
@@ -17,11 +17,12 @@ from lbkit.misc import SmartFormatter
|
|
|
17
17
|
lb_cwd = os.path.split(os.path.realpath(__file__))[0]
|
|
18
18
|
log = Logger("codegen")
|
|
19
19
|
|
|
20
|
-
__version__=
|
|
20
|
+
__version__=3
|
|
21
21
|
|
|
22
22
|
class CodeGen(object):
|
|
23
23
|
def __init__(self, args):
|
|
24
24
|
self.args = args
|
|
25
|
+
self.codegen_version = __version__
|
|
25
26
|
pass
|
|
26
27
|
|
|
27
28
|
def _gen(self, idf_file, directory="."):
|
|
@@ -32,12 +33,12 @@ class CodeGen(object):
|
|
|
32
33
|
lookup = TemplateLookup(directories=os.path.join(lb_cwd, "template"))
|
|
33
34
|
interface = IdfInterface(lookup, idf_file)
|
|
34
35
|
out_file = os.path.join(directory, "public", interface.name + ".xml")
|
|
35
|
-
interface.render_dbus_xml("interface.introspect.xml.mako", out_file)
|
|
36
|
+
interface.render_dbus_xml("interface.introspect.xml.mako", out_file, self.codegen_version)
|
|
36
37
|
for code_type in ["server", "client", "public"]:
|
|
37
38
|
out_file = os.path.join(directory, code_type, interface.name + ".h")
|
|
38
|
-
interface.render_c_source(code_type + ".h.mako", out_file)
|
|
39
|
+
interface.render_c_source(code_type + ".h.mako", out_file, self.codegen_version)
|
|
39
40
|
out_file = os.path.join(directory, code_type, interface.name + ".c")
|
|
40
|
-
interface.render_c_source(code_type + ".c.mako", out_file)
|
|
41
|
+
interface.render_c_source(code_type + ".c.mako", out_file, self.codegen_version)
|
|
41
42
|
json_file = os.path.join(directory, "package.yml")
|
|
42
43
|
data = {
|
|
43
44
|
"version": interface.version,
|
|
@@ -54,37 +55,59 @@ class CodeGen(object):
|
|
|
54
55
|
json.dump(odf_data, fp, sort_keys=False, indent=4)
|
|
55
56
|
|
|
56
57
|
|
|
57
|
-
def run(self
|
|
58
|
+
def run(self):
|
|
58
59
|
"""
|
|
59
60
|
代码自动生成.
|
|
60
61
|
|
|
61
62
|
支持自动生成服务端和客户端C代码
|
|
62
63
|
"""
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
parser = argparse.ArgumentParser(description=self.run.__doc__,
|
|
65
|
+
prog="lbkit gen",
|
|
66
|
+
formatter_class=SmartFormatter)
|
|
67
|
+
# 默认的自动生成工具版本号为2
|
|
68
|
+
parser.add_argument("-cv", "--codegen_version", help=f'''must less than or equal to {__version__}, default: 2
|
|
69
|
+
description of changes:
|
|
70
|
+
3: compatible with libgcom/0.7.x
|
|
71
|
+
2: compatible with libgcom/0.6.x
|
|
72
|
+
''',
|
|
73
|
+
type=int, default=2)
|
|
74
|
+
parser.add_argument("-d", "--directory", help='generate code directory', default=".")
|
|
75
|
+
group2 = parser.add_argument_group('cdf file', 'Generate code using the specified CDF file')
|
|
76
|
+
group2.add_argument("-c", "--cdf_file", help='component description file, default metadata/package.yml', default=None)
|
|
77
|
+
group1 = parser.add_argument_group('idf file', 'Generate code using the specified IDF file')
|
|
78
|
+
group1.add_argument("-i", "--idf_file", help='A IDF file to be processed e.g.: com.litebmc.Upgrade.xml', default=None)
|
|
79
|
+
|
|
80
|
+
args = parser.parse_args(self.args)
|
|
81
|
+
|
|
82
|
+
if args.cdf_file:
|
|
83
|
+
if not os.path.isfile(args.cdf_file):
|
|
84
|
+
raise ArgException(f"argument -c/--cdf_file: {args.cdf_file} not exist")
|
|
85
|
+
configs = Helper.read_yaml(args.cdf_file, "codegen", [])
|
|
86
|
+
# 为保障兼容,package.yml未指定版本号的,默认使用2,该版本配套libgcom/0.6.0版本,其GclProperty无set/get成员
|
|
87
|
+
self.codegen_version = Helper.read_yaml(args.cdf_file, "codegen_version", 2)
|
|
65
88
|
for cfg in configs:
|
|
66
89
|
file = cfg.get("file")
|
|
67
90
|
if file is None:
|
|
68
|
-
log.error("%s的自动代码生成配置不正确, 缺少file元素指定描述文件",
|
|
91
|
+
log.error("%s的自动代码生成配置不正确, 缺少file元素指定描述文件", args.cdf_file)
|
|
69
92
|
sys.exit(-1)
|
|
70
93
|
if not file.endswith(".yaml") :
|
|
71
|
-
log.error("%s的自动代码生成配置不正确, %s的文件名不是以.yaml结束",
|
|
94
|
+
log.error("%s的自动代码生成配置不正确, %s的文件名不是以.yaml结束", args.cdf_file, file)
|
|
72
95
|
sys.exit(-1)
|
|
73
96
|
if not os.path.isfile(file):
|
|
74
|
-
log.error("%s的自动代码生成配置不正确, %s不是一个文件",
|
|
97
|
+
log.error("%s的自动代码生成配置不正确, %s不是一个文件", args.cdf_file, file)
|
|
75
98
|
sys.exit(-1)
|
|
76
99
|
outdir = cfg.get("outdir", os.getcwd())
|
|
77
100
|
self._gen(file, outdir)
|
|
78
101
|
return
|
|
79
102
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
103
|
+
intf_file = args.idf_file
|
|
104
|
+
if not intf_file:
|
|
105
|
+
raise ArgException(f"argument error, arguments -c/--cdf_file and -i/--idf_file are not set")
|
|
106
|
+
if not os.path.isfile(intf_file):
|
|
107
|
+
raise ArgException(f"argument -i/--idf_file: {args.idf_file} not exist")
|
|
108
|
+
if args.codegen_version > __version__ or args.codegen_version <= 0:
|
|
109
|
+
raise ArgException(f"argument -v/--codegen_version: validate failed, must less than or equal to {__version__} and bigger than 0")
|
|
110
|
+
self.codegen_version = args.codegen_version
|
|
88
111
|
out_dir = os.path.join(os.getcwd(), args.directory)
|
|
89
112
|
if not intf_file.endswith(".yaml"):
|
|
90
113
|
raise ArgException(f"The IDF file ({intf_file}) not endswith .yaml")
|
|
@@ -96,5 +119,5 @@ class CodeGen(object):
|
|
|
96
119
|
self._gen(intf_file, out_dir)
|
|
97
120
|
|
|
98
121
|
if __name__ == "__main__":
|
|
99
|
-
gen = CodeGen(
|
|
122
|
+
gen = CodeGen(sys.argv)
|
|
100
123
|
gen._gen("com.litebmc.test.xml", ".")
|
|
@@ -1102,9 +1102,8 @@ class IdfInterface(IdfInterfaceBase):
|
|
|
1102
1102
|
intf_stru = IdfStructure(self, idf, propety_key="properties")
|
|
1103
1103
|
self.structures[self.alias] = intf_stru
|
|
1104
1104
|
|
|
1105
|
-
def render_dbus_xml(self, template, out_file):
|
|
1106
|
-
|
|
1107
|
-
out = self.render(self.lookup, template, intf=self)
|
|
1105
|
+
def render_dbus_xml(self, template, out_file, codegen_version):
|
|
1106
|
+
out = self.render(self.lookup, template, intf=self, codegen_version=codegen_version)
|
|
1108
1107
|
hash = hashlib.sha256()
|
|
1109
1108
|
hash.update(out.encode('utf-8'))
|
|
1110
1109
|
self.introspect_xml_sha256 = hash.hexdigest()
|
|
@@ -1112,8 +1111,8 @@ class IdfInterface(IdfInterfaceBase):
|
|
|
1112
1111
|
with open(out_file, "w") as fd:
|
|
1113
1112
|
fd.write(out)
|
|
1114
1113
|
|
|
1115
|
-
def render_c_source(self, template, out_file):
|
|
1114
|
+
def render_c_source(self, template, out_file, codegen_version):
|
|
1116
1115
|
|
|
1117
|
-
out = self.render(self.lookup, template, intf=self)
|
|
1116
|
+
out = self.render(self.lookup, template, intf=self, codegen_version=codegen_version)
|
|
1118
1117
|
with open(out_file, "w") as fd:
|
|
1119
1118
|
fd.write(out)
|
|
@@ -785,6 +785,45 @@ static GDBusPropertyInfo ${class_name}_property_${prop.name} =
|
|
|
785
785
|
|
|
786
786
|
% endif
|
|
787
787
|
% endfor
|
|
788
|
+
% if len(intf.properties):
|
|
789
|
+
GclBase *_get_real_object(const ${class_name} *object)
|
|
790
|
+
{
|
|
791
|
+
GclBase *real = (GclBase *)strstr((const char *)object, GCL_MAGIC);
|
|
792
|
+
if ((gconstpointer)real != (gconstpointer)object) {
|
|
793
|
+
log_error("Get real object fail, Perhaps the memory has been freed, call abort() now");
|
|
794
|
+
abort();
|
|
795
|
+
}
|
|
796
|
+
return real;
|
|
797
|
+
}
|
|
798
|
+
% endif
|
|
799
|
+
## 只有自动生成工具版本号大于等于3的才会生成get和set方法
|
|
800
|
+
% if codegen_version >= 3:
|
|
801
|
+
% for prop in intf.properties:
|
|
802
|
+
static void ${class_name}_set_${prop.name}_variant(GclObject *object, GVariant *value)
|
|
803
|
+
{
|
|
804
|
+
g_assert(value && object);
|
|
805
|
+
${class_name} *real_obj = (${class_name} *)_get_real_object(object);
|
|
806
|
+
% for line in prop.free_func():
|
|
807
|
+
${line.replace("<arg_name>", "real_obj->" + prop.name)};
|
|
808
|
+
% endfor
|
|
809
|
+
% for line in prop.decode_func():
|
|
810
|
+
${line.replace("n_<arg_in>", "real_obj->n_" + prop.name).replace("<arg_in>", "real_obj->" + prop.name).replace("<arg_name>", "value")};
|
|
811
|
+
% endfor
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
static GVariant *${class_name}_get_${prop.name}_variant(GclObject *object)
|
|
815
|
+
{
|
|
816
|
+
g_assert(object);
|
|
817
|
+
GVariant *out = NULL;
|
|
818
|
+
${class_name} *real_obj = (${class_name} *)_get_real_object(object);
|
|
819
|
+
% for line in prop.encode_func():
|
|
820
|
+
${line.replace("<arg_out>", "out").replace("n_<arg_name>", "real_obj->n_" + prop.name).replace("<arg_name>", "real_obj->" + prop.name)};
|
|
821
|
+
% endfor
|
|
822
|
+
return out;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
%endfor
|
|
826
|
+
%endif
|
|
788
827
|
static ${class_name}_Properties _${class_name}_properties =
|
|
789
828
|
{
|
|
790
829
|
<% id = 0 %>\
|
|
@@ -798,7 +837,13 @@ static ${class_name}_Properties _${class_name}_properties =
|
|
|
798
837
|
.info = NULL, /* load from /usr/share/dbus-1/interfaces/${intf.name} by gcl_init */
|
|
799
838
|
% endif
|
|
800
839
|
.offset = offsetof(${class_name}, ${prop.name}),
|
|
840
|
+
% if codegen_version >= 3:
|
|
841
|
+
.flags = ${prop.desc_flags},
|
|
842
|
+
.set = ${class_name}_set_${prop.name}_variant,
|
|
843
|
+
.get = ${class_name}_get_${prop.name}_variant
|
|
844
|
+
% else:
|
|
801
845
|
.flags = ${prop.desc_flags}
|
|
846
|
+
% endif
|
|
802
847
|
},
|
|
803
848
|
<% id = id + 1 %>\
|
|
804
849
|
% endfor
|
|
@@ -306,8 +306,8 @@ class BuildComponent():
|
|
|
306
306
|
def run(self):
|
|
307
307
|
cmd = f"conan remove {self.package} -c"
|
|
308
308
|
tools.exec(cmd)
|
|
309
|
-
gen = CodeGen([])
|
|
310
|
-
gen.run(
|
|
309
|
+
gen = CodeGen(["-c", "./metadata/package.yml"])
|
|
310
|
+
gen.run()
|
|
311
311
|
self._build_dependencies()
|
|
312
312
|
log.success(f"start build {self.package}")
|
|
313
313
|
cmd = "conan create . {} -tf=\"\"".format(self.base_cmd)
|
|
@@ -50,6 +50,13 @@ class SmartFormatter(argparse.HelpFormatter):
|
|
|
50
50
|
text = textwrap.dedent(text)
|
|
51
51
|
return ''.join(indent + line for line in text.splitlines(True))
|
|
52
52
|
|
|
53
|
+
# 优化帮助文本打印:支持换行符
|
|
54
|
+
def _split_lines(self, text, width):
|
|
55
|
+
ret = []
|
|
56
|
+
for line in text.split("\n"):
|
|
57
|
+
ret.extend(super()._split_lines(line, width))
|
|
58
|
+
return ret
|
|
59
|
+
|
|
53
60
|
def get_json_schema_file(yml_file, default_json_schema_file):
|
|
54
61
|
"""使用json schema文件校验yml_file配置文件"""
|
|
55
62
|
with open(yml_file, "r") as fp:
|
lbkit-0.5.20/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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|