lbkit 0.5.20__tar.gz → 0.5.23__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.23}/PKG-INFO +2 -2
- lbkit-0.5.23/lbkit/__init__.py +2 -0
- lbkit-0.5.23/lbkit/build_conan_parallel.py +197 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/cli.py +10 -2
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/codegen/codegen.py +42 -19
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/codegen/ctype_defination.py +52 -52
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/codegen/idf_interface.py +11 -12
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/codegen/template/client.c.mako +24 -24
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/codegen/template/client.h.mako +2 -2
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/codegen/template/public.c.mako +62 -17
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/codegen/template/public.h.mako +15 -15
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/codegen/template/server.c.mako +29 -29
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/codegen/template/server.h.mako +2 -2
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/component/build.py +29 -59
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/component/template/conanbase.mako +4 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/component/template/deploy.mako +4 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/component/test.py +3 -2
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/helper.py +1 -1
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/integration/build_manifest.py +41 -18
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/integration/build_prepare.py +3 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/integration/build_rootfs.py +27 -9
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/integration/config.py +7 -3
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/integration/task.py +11 -8
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/integration/template/conanfile.py.mako +4 -0
- lbkit-0.5.23/lbkit/log.py +84 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/misc.py +7 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/tools.py +31 -16
- {lbkit-0.5.20 → lbkit-0.5.23/lbkit.egg-info}/PKG-INFO +2 -2
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit.egg-info/SOURCES.txt +1 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit.egg-info/requires.txt +1 -1
- {lbkit-0.5.20 → lbkit-0.5.23}/setup.py +1 -1
- {lbkit-0.5.20 → lbkit-0.5.23}/test/test_codegen.py +4 -4
- lbkit-0.5.20/lbkit/__init__.py +0 -2
- lbkit-0.5.20/lbkit/log.py +0 -39
- {lbkit-0.5.20 → lbkit-0.5.23}/AUTHORS +0 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/LICENSE +0 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/MANIFEST.in +0 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/README.md +0 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/ci_robot/__init__.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/ci_robot/gitee.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/codegen/__init__.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/codegen/renderer.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/codegen/template/interface.c.mako +0 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/codegen/template/interface.introspect.xml.mako +0 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/component/__init__.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/component/arg_parser.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/errors.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/integration/__init__.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/integration/build_image.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit/lbkit.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit.egg-info/dependency_links.txt +0 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit.egg-info/entry_points.txt +0 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/lbkit.egg-info/top_level.txt +0 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/setup.cfg +0 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/test/__init__.py +0 -0
- {lbkit-0.5.20 → lbkit-0.5.23}/test/test_helper.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: lbkit
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.23
|
|
4
4
|
Summary: Tools provided by litebmc.com
|
|
5
5
|
Home-page: https://www.litebmc.com
|
|
6
6
|
Author: xuhj@litebmc.com
|
|
@@ -16,7 +16,7 @@ Requires-Dist: colorama
|
|
|
16
16
|
Requires-Dist: mako
|
|
17
17
|
Requires-Dist: node-semver==0.6.1
|
|
18
18
|
Requires-Dist: jsonschema
|
|
19
|
-
Requires-Dist: conan
|
|
19
|
+
Requires-Dist: conan
|
|
20
20
|
Requires-Dist: requests
|
|
21
21
|
Requires-Dist: gitpython
|
|
22
22
|
Requires-Dist: inflection
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"""任务基础类"""
|
|
2
|
+
import os
|
|
3
|
+
import json
|
|
4
|
+
from queue import Queue
|
|
5
|
+
from threading import Thread
|
|
6
|
+
from lbkit.log import Logger
|
|
7
|
+
from lbkit.errors import LiteBmcException
|
|
8
|
+
from lbkit import misc
|
|
9
|
+
from lbkit.tools import Tools
|
|
10
|
+
|
|
11
|
+
tools = Tools("comp_build")
|
|
12
|
+
log = Logger("comp_build")
|
|
13
|
+
|
|
14
|
+
class ConanPackage():
|
|
15
|
+
def __init__(self, node):
|
|
16
|
+
self.node = node
|
|
17
|
+
self.deps: dict[str, ConanPackage] = {}
|
|
18
|
+
self.build_deps: dict[str, ConanPackage] = {}
|
|
19
|
+
self.ref = node.get("ref")
|
|
20
|
+
self.pkg = self.ref.split("#")[0]
|
|
21
|
+
self.name = self.pkg.split("/")[0]
|
|
22
|
+
self.context = node.get("context")
|
|
23
|
+
self.building = False
|
|
24
|
+
self.is_host = self.context == "host"
|
|
25
|
+
binary = node.get("binary")
|
|
26
|
+
self.binary_exist = (binary in ["Cache"])
|
|
27
|
+
|
|
28
|
+
def append_dep(self, dep):
|
|
29
|
+
self.deps[dep.pkg] = dep
|
|
30
|
+
|
|
31
|
+
def append_build_dep(self, dep):
|
|
32
|
+
self.build_deps[dep.pkg] = dep
|
|
33
|
+
|
|
34
|
+
# 间接构建依赖更新为直接依赖
|
|
35
|
+
def update_indirect_build_dep(self):
|
|
36
|
+
deps = {}
|
|
37
|
+
for _, dep in self.build_deps.items():
|
|
38
|
+
sub_deps = dep.update_indirect_build_dep()
|
|
39
|
+
deps.update(sub_deps)
|
|
40
|
+
self.build_deps.update(deps)
|
|
41
|
+
return self.build_deps
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def options(self):
|
|
45
|
+
return self.node.get("options", {})
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def settings(self):
|
|
49
|
+
return self.node.get("settings", {})
|
|
50
|
+
|
|
51
|
+
@property
|
|
52
|
+
def default_options(self):
|
|
53
|
+
return self.node.get("default_options", {})
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class BuildConanParallel(object):
|
|
57
|
+
def __init__(self, graphinfo, lockfile, cmd, force_build):
|
|
58
|
+
self.queue = Queue()
|
|
59
|
+
self.cmd = ""
|
|
60
|
+
chunks = cmd.split()
|
|
61
|
+
skip = False
|
|
62
|
+
for chunk in chunks:
|
|
63
|
+
if skip:
|
|
64
|
+
skip = False
|
|
65
|
+
continue
|
|
66
|
+
if chunk in ["--user", "--channel", "--version", "--name"]:
|
|
67
|
+
skip = True
|
|
68
|
+
continue
|
|
69
|
+
self.cmd += f"{chunk} "
|
|
70
|
+
self.graphinfo = os.path.realpath(graphinfo)
|
|
71
|
+
self.lockfile = os.path.realpath(lockfile)
|
|
72
|
+
if not os.path.isfile(graphinfo):
|
|
73
|
+
raise LiteBmcException(f"graph file {graphinfo} not exist")
|
|
74
|
+
self.exception = None
|
|
75
|
+
self.force_build = force_build
|
|
76
|
+
|
|
77
|
+
def build_dep(self, cp: ConanPackage, options):
|
|
78
|
+
for name, value in cp.settings.items():
|
|
79
|
+
options += f" -s {name}={value}"
|
|
80
|
+
|
|
81
|
+
cmd = f"conan install --requires={cp.ref} {self.cmd} {options}"
|
|
82
|
+
if self.force_build:
|
|
83
|
+
cmd += f" --build=\"{cp.name}/*\""
|
|
84
|
+
cmd += " --build=missing"
|
|
85
|
+
cmd += f" --lockfile={self.lockfile}"
|
|
86
|
+
try:
|
|
87
|
+
log.info(f">>>> build {cp.ref} start")
|
|
88
|
+
log.debug(f">>>> {cmd}")
|
|
89
|
+
tools.exec(cmd, echo_cmd=False, log_name=f"{misc.LOG_DIR}/conan_{cp.name}.log")
|
|
90
|
+
log.success(f"<<<< build {cp.ref} finished")
|
|
91
|
+
except Exception as e:
|
|
92
|
+
self.exception = e
|
|
93
|
+
self.queue.put(cp)
|
|
94
|
+
|
|
95
|
+
def build(self):
|
|
96
|
+
with open(self.graphinfo, "r") as fp:
|
|
97
|
+
grapth = json.load(fp)
|
|
98
|
+
nodes = grapth.get("graph", {}).get("nodes", {})
|
|
99
|
+
packages: dict[str, ConanPackage] = {}
|
|
100
|
+
|
|
101
|
+
build_works = {}
|
|
102
|
+
for id, node in nodes.items():
|
|
103
|
+
if id == "0":
|
|
104
|
+
continue
|
|
105
|
+
cp = ConanPackage(node)
|
|
106
|
+
packages[cp.pkg] = cp
|
|
107
|
+
build_works[cp.name] = False
|
|
108
|
+
for id, node in nodes.items():
|
|
109
|
+
if id == "0":
|
|
110
|
+
continue
|
|
111
|
+
ref = node.get("ref")
|
|
112
|
+
if ref.startswith("litebmc/"):
|
|
113
|
+
continue
|
|
114
|
+
cp = packages[ref.split("#")[0]]
|
|
115
|
+
deps = node.get("dependencies", {})
|
|
116
|
+
for _, dep in deps.items():
|
|
117
|
+
dep_ref = dep.get("ref")
|
|
118
|
+
direct = dep.get("direct")
|
|
119
|
+
if not direct:
|
|
120
|
+
continue
|
|
121
|
+
dep_cp = packages[dep_ref]
|
|
122
|
+
if dep_cp.is_host:
|
|
123
|
+
cp.append_dep(dep_cp)
|
|
124
|
+
else:
|
|
125
|
+
cp.append_build_dep(dep_cp)
|
|
126
|
+
options = ""
|
|
127
|
+
for _, cp in packages.items():
|
|
128
|
+
for name, value in cp.options.items():
|
|
129
|
+
if value is None:
|
|
130
|
+
continue
|
|
131
|
+
def_val = cp.default_options.get(name)
|
|
132
|
+
conan_name = cp.pkg.split("@")[0]
|
|
133
|
+
if isinstance(def_val, bool):
|
|
134
|
+
if (def_val and "False" == value) or (not def_val and "True" == value):
|
|
135
|
+
options += f" -o {conan_name}:{name}={value}"
|
|
136
|
+
elif def_val != value:
|
|
137
|
+
options += f" -o {conan_name}:{name}={value}"
|
|
138
|
+
# 工具间接依赖变更为直接依赖
|
|
139
|
+
for name, pkg in packages.items():
|
|
140
|
+
pkg.update_indirect_build_dep()
|
|
141
|
+
wait_finished = 0
|
|
142
|
+
while True:
|
|
143
|
+
for _, cp in packages.items():
|
|
144
|
+
if wait_finished >= 4:
|
|
145
|
+
continue
|
|
146
|
+
if cp.ref.startswith("litebmc/"):
|
|
147
|
+
continue
|
|
148
|
+
# 如果是构建工具,不参与构建
|
|
149
|
+
if not cp.is_host:
|
|
150
|
+
continue
|
|
151
|
+
# 如果还有依赖未构建完成,不参与构建
|
|
152
|
+
if len(cp.deps) != 0:
|
|
153
|
+
continue
|
|
154
|
+
# 如果正在构建
|
|
155
|
+
if cp.building:
|
|
156
|
+
continue
|
|
157
|
+
# 相同名称的组件正在构建时不启动新的构建
|
|
158
|
+
if build_works[cp.name]:
|
|
159
|
+
continue
|
|
160
|
+
if not cp.binary_exist or self.force_build:
|
|
161
|
+
# 当依赖的构建工具存在正在构建的组件时不能构建
|
|
162
|
+
need_build = True
|
|
163
|
+
for _, dep in cp.build_deps.items():
|
|
164
|
+
# 正在构建且未构建出制品时
|
|
165
|
+
if not dep.binary_exist and dep.building:
|
|
166
|
+
need_build = False
|
|
167
|
+
break
|
|
168
|
+
if not need_build:
|
|
169
|
+
continue
|
|
170
|
+
cp.building = True
|
|
171
|
+
# 启动构建前将其依赖的构建工具置为正在构建
|
|
172
|
+
for _, dep in cp.build_deps.items():
|
|
173
|
+
dep.building = True
|
|
174
|
+
build_works[cp.name] = True
|
|
175
|
+
wait_finished += 1
|
|
176
|
+
thread = Thread(target=self.build_dep, args=(cp, options,))
|
|
177
|
+
thread.start()
|
|
178
|
+
else:
|
|
179
|
+
cp.building = True
|
|
180
|
+
build_works[cp.name] = True
|
|
181
|
+
wait_finished += 1
|
|
182
|
+
self.queue.put(cp)
|
|
183
|
+
if not wait_finished:
|
|
184
|
+
return
|
|
185
|
+
cp = self.queue.get()
|
|
186
|
+
if self.exception:
|
|
187
|
+
raise self.exception
|
|
188
|
+
build_works[cp.name] = False
|
|
189
|
+
wait_finished -= 1
|
|
190
|
+
for _, sub_cp in packages.items():
|
|
191
|
+
if sub_cp.deps.get(cp.pkg):
|
|
192
|
+
sub_cp.deps.pop(cp.pkg)
|
|
193
|
+
# 构建完成后,组件的构建依赖工具一定构建完成且制品存在
|
|
194
|
+
for _, dep in cp.build_deps.items():
|
|
195
|
+
dep.building = False
|
|
196
|
+
dep.binary_exist = True
|
|
197
|
+
|
|
@@ -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):
|
|
@@ -220,19 +224,23 @@ class Command(object):
|
|
|
220
224
|
|
|
221
225
|
method(args[0][1:])
|
|
222
226
|
except KeyboardInterrupt as exc:
|
|
227
|
+
log.error("lbk exit with exception:")
|
|
223
228
|
log.error(exc)
|
|
224
229
|
ret_code = 0
|
|
225
230
|
except SystemExit as exc:
|
|
231
|
+
log.error("lbk exit with exception:")
|
|
226
232
|
if exc.code != 0:
|
|
227
233
|
log.error("Exiting with code: %d" % exc.code)
|
|
228
234
|
ret_code = exc.code
|
|
229
235
|
except (errors.LiteBmcException, errors.RunCommandException, errors.ArgException, errors.PackageConfigException, Exception, errors.OdfValidateException) as exc:
|
|
236
|
+
log.error("lbk exit with exception:")
|
|
230
237
|
if os.environ.get("LOG"):
|
|
231
238
|
print(traceback.format_exc())
|
|
232
239
|
ret_code = -1
|
|
233
240
|
msg = str(exc)
|
|
234
241
|
log.error(misc.Color.RED + msg + misc.Color.RESET_ALL)
|
|
235
242
|
except errors.TestException:
|
|
243
|
+
log.error("lbk exit with exception:")
|
|
236
244
|
log.error(exc)
|
|
237
245
|
ret_code = -1
|
|
238
246
|
|
|
@@ -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 lb_base/0.7.x
|
|
71
|
+
2: compatible with lb_base/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,该版本配套lb_base/0.6.0版本,其LBProperty无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", ".")
|
|
@@ -544,8 +544,8 @@ CTYPE_OBJS = {
|
|
|
544
544
|
"string": CTypeBase(
|
|
545
545
|
["<const>gchar *<arg_name>"],
|
|
546
546
|
["gchar **<arg_name>"],
|
|
547
|
-
["
|
|
548
|
-
["<arg_out> =
|
|
547
|
+
["lb_free_p((void **)&<arg_name>)"],
|
|
548
|
+
["<arg_out> = lb_string_encode(<arg_name>)"],
|
|
549
549
|
["<arg_in> = g_strdup(g_variant_get_string(<arg_name>, NULL))"],
|
|
550
550
|
StringValidator("^.*$"),
|
|
551
551
|
["const gchar *<arg_name>"],
|
|
@@ -555,8 +555,8 @@ CTYPE_OBJS = {
|
|
|
555
555
|
"object_path": CTypeBase(
|
|
556
556
|
["<const>gchar *<arg_name>"],
|
|
557
557
|
["gchar **<arg_name>"],
|
|
558
|
-
["
|
|
559
|
-
["<arg_out> =
|
|
558
|
+
["lb_free_p((void **)&<arg_name>)"],
|
|
559
|
+
["<arg_out> = lb_object_path_encode(<arg_name>)"],
|
|
560
560
|
["<arg_in> = g_strdup(g_variant_get_string(<arg_name>, NULL))"],
|
|
561
561
|
StringValidator("^(/[A-Z0-9a-z_]+)*$"),
|
|
562
562
|
["const gchar *<arg_name>"],
|
|
@@ -566,8 +566,8 @@ CTYPE_OBJS = {
|
|
|
566
566
|
"signature": CTypeBase(
|
|
567
567
|
["<const>gchar *<arg_name>"],
|
|
568
568
|
["gchar **<arg_name>"],
|
|
569
|
-
["
|
|
570
|
-
["<arg_out> =
|
|
569
|
+
["lb_free_p((void **)&<arg_name>)"],
|
|
570
|
+
["<arg_out> = lb_signature_encode(<arg_name>)"],
|
|
571
571
|
["<arg_in> = g_strdup(g_variant_get_string(<arg_name>, NULL))"],
|
|
572
572
|
StringValidator("^([abynqiuxtdsogv\\\\{\\\\}\\\\(\\\\)])+$"),
|
|
573
573
|
["const gchar *<arg_name>"],
|
|
@@ -577,7 +577,7 @@ CTYPE_OBJS = {
|
|
|
577
577
|
"variant": CTypeBase(
|
|
578
578
|
["GVariant *<arg_name>"],
|
|
579
579
|
["GVariant **<arg_name>"],
|
|
580
|
-
["
|
|
580
|
+
["lb_unref_p((GVariant **)&<arg_name>)"],
|
|
581
581
|
["g_variant_take_ref(<arg_name>)", "<arg_out> = g_variant_new_variant(<arg_name>)"],
|
|
582
582
|
["<arg_in> = g_variant_get_variant(<arg_name>)"],
|
|
583
583
|
IdfValidator()
|
|
@@ -585,121 +585,121 @@ CTYPE_OBJS = {
|
|
|
585
585
|
"array[boolean]": CTypeBase(
|
|
586
586
|
["gsize n_<arg_name>" ,"<const>gboolean *<arg_name>"],
|
|
587
587
|
["gsize *n_<arg_name>" ,"gboolean **<arg_name>"],
|
|
588
|
-
["
|
|
589
|
-
["<arg_out> =
|
|
590
|
-
["<arg_in> =
|
|
588
|
+
["lb_free_p((void **)&<arg_name>)"],
|
|
589
|
+
["<arg_out> = lb_array_boolean_encode(<arg_name>, n_<arg_name>)"],
|
|
590
|
+
["<arg_in> = lb_array_boolean_decode(<arg_name>, &n_<arg_in>)"],
|
|
591
591
|
BoolArrayValidator()
|
|
592
592
|
),
|
|
593
593
|
"array[byte]": CTypeBase(
|
|
594
594
|
["gsize n_<arg_name>" ,"<const>guint8 *<arg_name>"],
|
|
595
595
|
["gsize *n_<arg_name>" ,"guint8 **<arg_name>"],
|
|
596
|
-
["
|
|
597
|
-
["<arg_out> =
|
|
598
|
-
["<arg_in> =
|
|
596
|
+
["lb_free_p((void **)&<arg_name>)"],
|
|
597
|
+
["<arg_out> = lb_array_byte_encode(<arg_name>, n_<arg_name>)"],
|
|
598
|
+
["<arg_in> = lb_array_byte_decode(<arg_name>, &n_<arg_in>)"],
|
|
599
599
|
IntegerArrayValidator(0xff, 0)
|
|
600
600
|
),
|
|
601
601
|
"array[int16]": CTypeBase(
|
|
602
602
|
["gsize n_<arg_name>" ,"<const>gint16 *<arg_name>"],
|
|
603
603
|
["gsize *n_<arg_name>" ,"gint16 **<arg_name>"],
|
|
604
|
-
["
|
|
605
|
-
["<arg_out> =
|
|
606
|
-
["<arg_in> =
|
|
604
|
+
["lb_free_p((void **)&<arg_name>)"],
|
|
605
|
+
["<arg_out> = lb_array_int16_encode(<arg_name>, n_<arg_name>)"],
|
|
606
|
+
["<arg_in> = lb_array_int16_decode(<arg_name>, &n_<arg_in>)"],
|
|
607
607
|
IntegerArrayValidator(0x7fff, -(0x8000), True)
|
|
608
608
|
),
|
|
609
609
|
"array[uint16]": CTypeBase(
|
|
610
610
|
["gsize n_<arg_name>" ,"<const>guint16 *<arg_name>"],
|
|
611
611
|
["gsize *n_<arg_name>" ,"guint16 **<arg_name>"],
|
|
612
|
-
["
|
|
613
|
-
["<arg_out> =
|
|
614
|
-
["<arg_in> =
|
|
612
|
+
["lb_free_p((void **)&<arg_name>)"],
|
|
613
|
+
["<arg_out> = lb_array_uint16_encode(<arg_name>, n_<arg_name>)"],
|
|
614
|
+
["<arg_in> = lb_array_uint16_decode(<arg_name>, &n_<arg_in>)"],
|
|
615
615
|
IntegerArrayValidator(0xffff, 0)
|
|
616
616
|
),
|
|
617
617
|
"array[int32]": CTypeBase(
|
|
618
618
|
["gsize n_<arg_name>" ,"<const>gint32 *<arg_name>"],
|
|
619
619
|
["gsize *n_<arg_name>" ,"gint32 **<arg_name>"],
|
|
620
|
-
["
|
|
621
|
-
["<arg_out> =
|
|
622
|
-
["<arg_in> =
|
|
620
|
+
["lb_free_p((void **)&<arg_name>)"],
|
|
621
|
+
["<arg_out> = lb_array_int32_encode(<arg_name>, n_<arg_name>)"],
|
|
622
|
+
["<arg_in> = lb_array_int32_decode(<arg_name>, &n_<arg_in>)"],
|
|
623
623
|
IntegerArrayValidator(0x7fff_ffff, -(0x80000000), True)
|
|
624
624
|
),
|
|
625
625
|
"array[uint32]": CTypeBase(
|
|
626
626
|
["gsize n_<arg_name>" ,"<const>guint32 *<arg_name>"],
|
|
627
627
|
["gsize *n_<arg_name>" ,"guint32 **<arg_name>"],
|
|
628
|
-
["
|
|
629
|
-
["<arg_out> =
|
|
630
|
-
["<arg_in> =
|
|
628
|
+
["lb_free_p((void **)&<arg_name>)"],
|
|
629
|
+
["<arg_out> = lb_array_uint32_encode(<arg_name>, n_<arg_name>)"],
|
|
630
|
+
["<arg_in> = lb_array_uint32_decode(<arg_name>, &n_<arg_in>)"],
|
|
631
631
|
IntegerArrayValidator(0xffff_ffff, 0)
|
|
632
632
|
),
|
|
633
633
|
"array[int64]": CTypeBase(
|
|
634
634
|
["gsize n_<arg_name>" ,"<const>gint64 *<arg_name>"],
|
|
635
635
|
["gsize *n_<arg_name>" ,"gint64 **<arg_name>"],
|
|
636
|
-
["
|
|
637
|
-
["<arg_out> =
|
|
638
|
-
["<arg_in> =
|
|
636
|
+
["lb_free_p((void **)&<arg_name>)"],
|
|
637
|
+
["<arg_out> = lb_array_int64_encode(<arg_name>, n_<arg_name>)"],
|
|
638
|
+
["<arg_in> = lb_array_int64_decode(<arg_name>, &n_<arg_in>)"],
|
|
639
639
|
IntegerArrayValidator(0x7fff_ffff_ffff_ffff, -(0x8000_0000_0000_0000), True)
|
|
640
640
|
),
|
|
641
641
|
"array[uint64]": CTypeBase(
|
|
642
642
|
["gsize n_<arg_name>" ,"<const>guint64 *<arg_name>"],
|
|
643
643
|
["gsize *n_<arg_name>" ,"guint64 **<arg_name>"],
|
|
644
|
-
["
|
|
645
|
-
["<arg_out> =
|
|
646
|
-
["<arg_in> =
|
|
644
|
+
["lb_free_p((void **)&<arg_name>)"],
|
|
645
|
+
["<arg_out> = lb_array_uint64_encode(<arg_name>, n_<arg_name>)"],
|
|
646
|
+
["<arg_in> = lb_array_uint64_decode(<arg_name>, &n_<arg_in>)"],
|
|
647
647
|
IntegerArrayValidator(0xffff_ffff_ffff_ffff, 0)
|
|
648
648
|
),
|
|
649
649
|
"array[ssize]": CTypeBase(
|
|
650
650
|
["gsize n_<arg_name>" ,"<const>gssize *<arg_name>"],
|
|
651
651
|
["gsize *n_<arg_name>" ,"gssize **<arg_name>"],
|
|
652
|
-
["
|
|
653
|
-
["<arg_out> =
|
|
654
|
-
["<arg_in> =
|
|
652
|
+
["lb_free_p((void **)&<arg_name>)"],
|
|
653
|
+
["<arg_out> = lb_array_int64_encode(<arg_name>, n_<arg_name>)"],
|
|
654
|
+
["<arg_in> = lb_array_int64_decode(<arg_name>, &n_<arg_in>)"],
|
|
655
655
|
IntegerArrayValidator(0x7fff_ffff_ffff_ffff, -(0x8000_0000_0000_0000), True)
|
|
656
656
|
),
|
|
657
657
|
"array[size]": CTypeBase(
|
|
658
658
|
["gsize n_<arg_name>" ,"<const>gsize *<arg_name>"],
|
|
659
659
|
["gsize *n_<arg_name>" ,"gsize **<arg_name>"],
|
|
660
|
-
["
|
|
661
|
-
["<arg_out> =
|
|
662
|
-
["<arg_in> =
|
|
660
|
+
["lb_free_p((void **)&<arg_name>)"],
|
|
661
|
+
["<arg_out> = lb_array_uint64_encode(<arg_name>, n_<arg_name>)"],
|
|
662
|
+
["<arg_in> = lb_array_uint64_decode(<arg_name>, &n_<arg_in>)"],
|
|
663
663
|
IntegerArrayValidator(0xffff_ffff_ffff_ffff, 0)
|
|
664
664
|
),
|
|
665
665
|
"array[double]": CTypeBase(
|
|
666
666
|
["gsize n_<arg_name>" ,"<const>gdouble *<arg_name>"],
|
|
667
667
|
["gsize *n_<arg_name>" ,"gdouble **<arg_name>"],
|
|
668
|
-
["
|
|
669
|
-
["<arg_out> =
|
|
670
|
-
["<arg_in> =
|
|
668
|
+
["lb_free_p((void **)&<arg_name>)"],
|
|
669
|
+
["<arg_out> = lb_array_double_encode(<arg_name>, n_<arg_name>)"],
|
|
670
|
+
["<arg_in> = lb_array_double_decode(<arg_name>, &n_<arg_in>)"],
|
|
671
671
|
FloatArrayValidator()
|
|
672
672
|
),
|
|
673
673
|
"array[unixfd]": CTypeBase(
|
|
674
674
|
["gsize n_<arg_name>" ,"<const>gint32 *<arg_name>"],
|
|
675
675
|
["gsize *n_<arg_name>" ,"gint32 **<arg_name>"],
|
|
676
|
-
["
|
|
677
|
-
["<arg_out> =
|
|
678
|
-
["<arg_in> =
|
|
676
|
+
["lb_free_p((void **)&<arg_name>)"],
|
|
677
|
+
["<arg_out> = lb_array_handle_encode(<arg_name>, n_<arg_name>)"],
|
|
678
|
+
["<arg_in> = lb_array_handle_decode(<arg_name>, &n_<arg_in>)"],
|
|
679
679
|
IntegerArrayValidator(0x7fff_ffff_ffff_ffff, 0, True)
|
|
680
680
|
),
|
|
681
681
|
"array[string]": CTypeBase(
|
|
682
682
|
["gchar *<const>*<arg_name>"],
|
|
683
683
|
["gchar ***<arg_name>"],
|
|
684
|
-
["
|
|
685
|
-
["<arg_out> =
|
|
686
|
-
["<arg_in> =
|
|
684
|
+
["lb_strfreev_p(&<arg_name>)"],
|
|
685
|
+
["<arg_out> = lb_array_string_encode(<arg_name>)"],
|
|
686
|
+
["<arg_in> = lb_array_string_decode(<arg_name>)"],
|
|
687
687
|
StringArrayValidator("^.*$")
|
|
688
688
|
),
|
|
689
689
|
"array[object_path]": CTypeBase(
|
|
690
690
|
["gchar *<const>*<arg_name>"],
|
|
691
691
|
["gchar ***<arg_name>"],
|
|
692
|
-
["
|
|
693
|
-
["<arg_out> =
|
|
694
|
-
["<arg_in> =
|
|
692
|
+
["lb_strfreev_p(&<arg_name>)"],
|
|
693
|
+
["<arg_out> = lb_array_object_path_encode(<arg_name>)"],
|
|
694
|
+
["<arg_in> = lb_array_object_path_decode(<arg_name>)"],
|
|
695
695
|
StringArrayValidator("^(/[A-Z0-9a-z_]+)*$")
|
|
696
696
|
),
|
|
697
697
|
"array[signature]": CTypeBase(
|
|
698
698
|
["gchar *<const>*<arg_name>"],
|
|
699
699
|
["gchar ***<arg_name>"],
|
|
700
|
-
["
|
|
701
|
-
["<arg_out> =
|
|
702
|
-
["<arg_in> =
|
|
700
|
+
["lb_strfreev_p(&<arg_name>)"],
|
|
701
|
+
["<arg_out> = lb_array_signature_encode(<arg_name>)"],
|
|
702
|
+
["<arg_in> = lb_array_signature_decode(<arg_name>)"],
|
|
703
703
|
StringArrayValidator("^([abynqiuxtdsogv\\\\{\\\\}\\\\(\\\\)])+$")
|
|
704
704
|
)
|
|
705
705
|
}
|
|
@@ -366,7 +366,7 @@ class IdfCtypeRender():
|
|
|
366
366
|
_, stru_name = get_intfname_and_ctype(match.group(2))
|
|
367
367
|
if match.group(1) == "enum":
|
|
368
368
|
if is_array:
|
|
369
|
-
return [f"
|
|
369
|
+
return [f"lb_free_p((void **)&<arg_name>)"]
|
|
370
370
|
return []
|
|
371
371
|
else:
|
|
372
372
|
if is_array:
|
|
@@ -587,17 +587,17 @@ class IdfProperty(IdfCtypeRender):
|
|
|
587
587
|
|
|
588
588
|
c_flags = []
|
|
589
589
|
if self.private:
|
|
590
|
-
c_flags.append("
|
|
590
|
+
c_flags.append("LB_FLAGS_PROPERTY_PRIVATE")
|
|
591
591
|
elif "const" in flags:
|
|
592
|
-
c_flags.append("
|
|
592
|
+
c_flags.append("LB_FLAGS_PROPERTY_EMIT_CONST")
|
|
593
593
|
elif "emits_false" in flags:
|
|
594
|
-
c_flags.append("
|
|
594
|
+
c_flags.append("LB_FLAGS_PROPERTY_EMIT_FALSE")
|
|
595
595
|
elif "emits_invalidation" in flags:
|
|
596
|
-
c_flags.append("
|
|
596
|
+
c_flags.append("LB_FLAGS_PROPERTY_EMIT_INVALIDATES")
|
|
597
597
|
else:
|
|
598
|
-
c_flags.append("
|
|
598
|
+
c_flags.append("LB_FLAGS_PROPERTY_EMIT_TRUE")
|
|
599
599
|
if self.deprecated:
|
|
600
|
-
c_flags.append("
|
|
600
|
+
c_flags.append("LB_FLAGS_PROPERTY_DEPRECATED")
|
|
601
601
|
if len(c_flags) == 0:
|
|
602
602
|
self.desc_flags = "0"
|
|
603
603
|
else:
|
|
@@ -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)
|