lbkit 0.9.10__tar.gz → 0.9.12__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.9.10 → lbkit-0.9.12}/MANIFEST.in +1 -0
- {lbkit-0.9.10/lbkit.egg-info → lbkit-0.9.12}/PKG-INFO +2 -3
- lbkit-0.9.12/lbkit/__commit__.py +1 -0
- lbkit-0.9.12/lbkit/__init__.py +2 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/build_conan_parallel.py +6 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/cli.py +30 -16
- lbkit-0.9.12/lbkit/codegen/.clang-format +70 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/codegen/codegen.py +82 -24
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/codegen/ctype_defination.py +6 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/codegen/idf_interface.py +6 -0
- lbkit-0.9.12/lbkit/codegen/renderer.py +15 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/codegen/template/client.c.mako +16 -43
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/codegen/template/client.h.mako +187 -7
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/codegen/template/interface.introspect.xml.mako +7 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/codegen/template/public.c.mako +208 -20
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/codegen/template/public.h.mako +17 -5
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/codegen/template/server.c.mako +96 -88
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/codegen/template/server.h.mako +123 -18
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/component/arg_parser.py +6 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/component/build.py +12 -5
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/component/template/conanbase.mako +20 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/component/template/deploy.mako +3 -1
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/component/test.py +8 -2
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/download_cache.py +6 -0
- lbkit-0.9.12/lbkit/errors.py +60 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/helper.py +17 -10
- lbkit-0.9.12/lbkit/lbkit.py +17 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/log.py +6 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/misc.py +6 -0
- lbkit-0.9.12/lbkit/skill/__init__.py +10 -0
- lbkit-0.9.12/lbkit/skill/constants.py +27 -0
- lbkit-0.9.12/lbkit/skill/manager.py +119 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/tasks/config.py +6 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/tasks/executor.py +27 -7
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/tasks/image_maker/make_image.py +6 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/tasks/image_maker/make_qemu_image.py +6 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/tasks/image_maker/make_rockchip_image.py +6 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/tasks/task.py +6 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/tasks/task_build_image.py +6 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/tasks/task_build_manifest.py +8 -1
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/tasks/task_build_prepare.py +6 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/tasks/task_build_rootfs.py +60 -27
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/tasks/task_download.py +6 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/tools.py +15 -11
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/ukr/build.py +6 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/utils/env_detector.py +6 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/utils/fakeroot.py +6 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/utils/images/emmc.py +6 -0
- {lbkit-0.9.10 → lbkit-0.9.12/lbkit.egg-info}/PKG-INFO +2 -3
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit.egg-info/SOURCES.txt +8 -3
- {lbkit-0.9.10 → lbkit-0.9.12}/setup.py +8 -2
- {lbkit-0.9.10 → lbkit-0.9.12}/test/test_codegen.py +132 -35
- {lbkit-0.9.10 → lbkit-0.9.12}/test/test_config.py +6 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/test/test_helper.py +6 -0
- lbkit-0.9.12/test/test_permission.py +332 -0
- lbkit-0.9.12/test/test_skill.py +172 -0
- lbkit-0.9.10/LICENSE +0 -202
- lbkit-0.9.10/lbkit/__init__.py +0 -2
- lbkit-0.9.10/lbkit/codegen/renderer.py +0 -9
- lbkit-0.9.10/lbkit/codegen/template/interface.c.mako +0 -0
- lbkit-0.9.10/lbkit/errors.py +0 -92
- lbkit-0.9.10/lbkit/lbkit.py +0 -11
- {lbkit-0.9.10 → lbkit-0.9.12}/AUTHORS +0 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/README.md +0 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/ci_robot/__init__.py +0 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/codegen/__init__.py +0 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/component/__init__.py +0 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/tasks/__init__.py +0 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/tasks/image_maker/__init__.py +0 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/tasks/template/conanfile.py.mako +0 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/tasks/template/rootfs.py.mako +0 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/ukr/__init__.py +0 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/utils/__init__.py +0 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit/utils/images/__init__.py +0 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit.egg-info/dependency_links.txt +0 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit.egg-info/entry_points.txt +0 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit.egg-info/requires.txt +0 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/lbkit.egg-info/top_level.txt +0 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/setup.cfg +0 -0
- {lbkit-0.9.10 → lbkit-0.9.12}/test/__init__.py +0 -0
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lbkit
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.12
|
|
4
4
|
Summary: Tools provided by litebmc.com
|
|
5
5
|
Home-page: https://www.litebmc.com
|
|
6
6
|
Author: xuhj@litebmc.com
|
|
7
7
|
Author-email: xuhj@litebmc.com
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: License :: OSI Approved ::
|
|
9
|
+
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
|
10
10
|
Classifier: Operating System :: OS Independent
|
|
11
11
|
Description-Content-Type: text/markdown
|
|
12
|
-
License-File: LICENSE
|
|
13
12
|
License-File: AUTHORS
|
|
14
13
|
Requires-Dist: pyyaml
|
|
15
14
|
Requires-Dist: colorama
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__commit__ = 'e5ea324'
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
# Copyright (c) 2021-2024 litebmc.com
|
|
2
|
+
#
|
|
3
|
+
# This program is free software; you can redistribute it and/or modify it
|
|
4
|
+
# under the terms of the GNU General Public License as published by the
|
|
5
|
+
# Free Software Foundation; either version 3 of the License, or (at your
|
|
6
|
+
# option) any later version.
|
|
1
7
|
"""任务基础类"""
|
|
2
8
|
import os
|
|
3
9
|
import json
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
# Copyright (c) 2021-2024 litebmc.com
|
|
2
|
+
#
|
|
3
|
+
# This program is free software; you can redistribute it and/or modify it
|
|
4
|
+
# under the terms of the GNU General Public License as published by the
|
|
5
|
+
# Free Software Foundation; either version 3 of the License, or (at your
|
|
6
|
+
# option) any later version.
|
|
1
7
|
"""lbkit命令行入口"""
|
|
2
8
|
import inspect
|
|
3
9
|
import os
|
|
@@ -6,6 +12,10 @@ import sys
|
|
|
6
12
|
import argparse
|
|
7
13
|
import traceback
|
|
8
14
|
from lbkit import __version__ as client_version
|
|
15
|
+
try:
|
|
16
|
+
from lbkit.__commit__ import __commit__ as client_commit
|
|
17
|
+
except ImportError:
|
|
18
|
+
client_commit = ""
|
|
9
19
|
from lbkit.codegen.codegen import CodeGen
|
|
10
20
|
from lbkit.component.build import BuildComponent
|
|
11
21
|
from lbkit.component.test import TestComponent
|
|
@@ -16,6 +26,7 @@ from lbkit import misc
|
|
|
16
26
|
from lbkit import errors
|
|
17
27
|
from lbkit.ukr.build import UKRBuild
|
|
18
28
|
from lbkit.utils.env_detector import EnvDetector
|
|
29
|
+
from lbkit.skill.manager import sync as skill_sync
|
|
19
30
|
|
|
20
31
|
log = Logger()
|
|
21
32
|
|
|
@@ -60,15 +71,6 @@ class Command(object):
|
|
|
60
71
|
gen = CodeGen(argv)
|
|
61
72
|
gen.run()
|
|
62
73
|
|
|
63
|
-
# new package
|
|
64
|
-
def new(self, *args):
|
|
65
|
-
"""
|
|
66
|
-
按LiteBmc最佳实践创建一个新的组件.
|
|
67
|
-
|
|
68
|
-
你需要指定你需要使用的编程语言,当前仅支持C(基于litebmc框架)和C++(基于openbmc的sdbusplus)
|
|
69
|
-
"""
|
|
70
|
-
log.info("new package")
|
|
71
|
-
|
|
72
74
|
# build package
|
|
73
75
|
def build(self, *args):
|
|
74
76
|
"""
|
|
@@ -105,13 +107,22 @@ class Command(object):
|
|
|
105
107
|
build = TestComponent(argv)
|
|
106
108
|
build.run()
|
|
107
109
|
|
|
110
|
+
def skill(self, *args):
|
|
111
|
+
"""
|
|
112
|
+
同步AI技能包.
|
|
113
|
+
|
|
114
|
+
从技能仓库下载并复制所有skills到用户全局技能库(~/.claude/skills)
|
|
115
|
+
"""
|
|
116
|
+
skill_sync()
|
|
117
|
+
|
|
108
118
|
def _show_help(self):
|
|
109
119
|
"""
|
|
110
120
|
Prints a summary of all commands.
|
|
111
121
|
"""
|
|
112
122
|
grps = [("Code Generate commands", ["gen"]),
|
|
113
|
-
("Build Component commands", ["
|
|
123
|
+
("Build Component commands", ["build", "test"]),
|
|
114
124
|
("Build Product commands", ["build"]),
|
|
125
|
+
("AI Skill commands", ["skill"]),
|
|
115
126
|
("Misc commands", ["help"]),
|
|
116
127
|
]
|
|
117
128
|
|
|
@@ -194,7 +205,10 @@ class Command(object):
|
|
|
194
205
|
method = commands[command]
|
|
195
206
|
except KeyError as exc:
|
|
196
207
|
if command in ["-v", "--version"]:
|
|
197
|
-
|
|
208
|
+
ver = f"LiteBmc version {client_version}"
|
|
209
|
+
if client_commit:
|
|
210
|
+
ver += f" (commit {client_commit})"
|
|
211
|
+
log.info(ver)
|
|
198
212
|
return False
|
|
199
213
|
|
|
200
214
|
self._warn_python_version()
|
|
@@ -215,17 +229,17 @@ class Command(object):
|
|
|
215
229
|
if exc.code != 0:
|
|
216
230
|
log.error("Exiting with code: %d" % exc.code)
|
|
217
231
|
ret_code = exc.code
|
|
218
|
-
except
|
|
232
|
+
except errors.TestException as exc:
|
|
233
|
+
log.error("lbk exit with exception:")
|
|
234
|
+
log.error(exc)
|
|
235
|
+
ret_code = -1
|
|
236
|
+
except Exception as exc:
|
|
219
237
|
log.error("lbk exit with exception:")
|
|
220
238
|
if os.environ.get("LOG"):
|
|
221
239
|
print(traceback.format_exc())
|
|
222
240
|
ret_code = -1
|
|
223
241
|
msg = str(exc)
|
|
224
242
|
log.error(msg)
|
|
225
|
-
except errors.TestException:
|
|
226
|
-
log.error("lbk exit with exception:")
|
|
227
|
-
log.error(exc)
|
|
228
|
-
ret_code = -1
|
|
229
243
|
|
|
230
244
|
return ret_code
|
|
231
245
|
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
---
|
|
2
|
+
# LiteBMC 代码生成默认格式化配置
|
|
3
|
+
# 参考 Linux 内核风格, 适配 GLib/C 项目
|
|
4
|
+
# BasedOnStyle: LLVM
|
|
5
|
+
|
|
6
|
+
AccessModifierOffset: -4
|
|
7
|
+
AlignAfterOpenBracket: Align
|
|
8
|
+
AlignConsecutiveAssignments: false
|
|
9
|
+
AlignConsecutiveDeclarations: false
|
|
10
|
+
AlignEscapedNewlines: Left
|
|
11
|
+
AlignOperands: true
|
|
12
|
+
AlignTrailingComments: false
|
|
13
|
+
AllowAllParametersOfDeclarationOnNextLine: false
|
|
14
|
+
AllowShortBlocksOnASingleLine: false
|
|
15
|
+
AllowShortCaseLabelsOnASingleLine: false
|
|
16
|
+
AllowShortFunctionsOnASingleLine: None
|
|
17
|
+
AllowShortIfStatementsOnASingleLine: false
|
|
18
|
+
AllowShortLoopsOnASingleLine: false
|
|
19
|
+
AlwaysBreakAfterDefinitionReturnType: None
|
|
20
|
+
AlwaysBreakAfterReturnType: None
|
|
21
|
+
AlwaysBreakBeforeMultilineStrings: false
|
|
22
|
+
BinPackArguments: true
|
|
23
|
+
BinPackParameters: true
|
|
24
|
+
BraceWrapping:
|
|
25
|
+
AfterControlStatement: false
|
|
26
|
+
AfterEnum: false
|
|
27
|
+
AfterFunction: true
|
|
28
|
+
AfterStruct: false
|
|
29
|
+
BeforeCatch: false
|
|
30
|
+
BeforeElse: false
|
|
31
|
+
IndentBraces: false
|
|
32
|
+
BreakBeforeBinaryOperators: None
|
|
33
|
+
BreakBeforeBraces: Custom
|
|
34
|
+
BreakBeforeTernaryOperators: false
|
|
35
|
+
BreakStringLiterals: false
|
|
36
|
+
ColumnLimit: 120
|
|
37
|
+
CommentPragmas: '^ IWYU pragma:'
|
|
38
|
+
ConstructorInitializerIndentWidth: 4
|
|
39
|
+
ContinuationIndentWidth: 4
|
|
40
|
+
Cpp11BracedListStyle: false
|
|
41
|
+
DerivePointerAlignment: false
|
|
42
|
+
FixNamespaceComments: false
|
|
43
|
+
IndentCaseLabels: false
|
|
44
|
+
IndentGotoLabels: false
|
|
45
|
+
IndentPPDirectives: None
|
|
46
|
+
IndentWidth: 4
|
|
47
|
+
IndentWrappedFunctionNames: false
|
|
48
|
+
KeepEmptyLinesAtTheStartOfBlocks: false
|
|
49
|
+
MaxEmptyLinesToKeep: 1
|
|
50
|
+
PointerAlignment: Right
|
|
51
|
+
ReflowComments: false
|
|
52
|
+
SortIncludes: false
|
|
53
|
+
SpaceAfterCStyleCast: false
|
|
54
|
+
SpaceBeforeAssignmentOperators: true
|
|
55
|
+
SpaceBeforeParens: ControlStatementsExceptForEachMacros
|
|
56
|
+
SpacesBeforeTrailingComments: 1
|
|
57
|
+
SpacesInAngles: false
|
|
58
|
+
SpacesInContainerLiterals: false
|
|
59
|
+
SpacesInCStyleCastParentheses: false
|
|
60
|
+
SpacesInParentheses: false
|
|
61
|
+
SpacesInSquareBrackets: false
|
|
62
|
+
TabWidth: 4
|
|
63
|
+
UseTab: Never
|
|
64
|
+
PenaltyBreakAssignment: 10
|
|
65
|
+
PenaltyBreakBeforeFirstCallParameter: 30
|
|
66
|
+
PenaltyBreakComment: 10
|
|
67
|
+
PenaltyBreakFirstLessLess: 0
|
|
68
|
+
PenaltyBreakString: 10
|
|
69
|
+
PenaltyExcessCharacter: 100
|
|
70
|
+
PenaltyReturnTypeOnItsOwnLine: 60
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
# Copyright (c) 2021-2024 litebmc.com
|
|
2
|
+
#
|
|
3
|
+
# This program is free software; you can redistribute it and/or modify it
|
|
4
|
+
# under the terms of the GNU General Public License as published by the
|
|
5
|
+
# Free Software Foundation; either version 3 of the License, or (at your
|
|
6
|
+
# option) any later version.
|
|
1
7
|
"""
|
|
2
8
|
DBus接口代码自动生成
|
|
3
9
|
"""
|
|
@@ -7,6 +13,8 @@ import re
|
|
|
7
13
|
import json
|
|
8
14
|
import yaml
|
|
9
15
|
import argparse
|
|
16
|
+
import shutil
|
|
17
|
+
import subprocess
|
|
10
18
|
from concurrent.futures import ProcessPoolExecutor, as_completed
|
|
11
19
|
from lbkit.codegen.idf_interface import IdfInterface
|
|
12
20
|
|
|
@@ -62,45 +70,93 @@ class Version():
|
|
|
62
70
|
return True
|
|
63
71
|
return False
|
|
64
72
|
|
|
65
|
-
#
|
|
66
|
-
#
|
|
73
|
+
# 历史自动生成版本号,用于管理代码生成版本与lb_base的兼容性
|
|
74
|
+
# 新增兼容性变更时添加条目,格式:"版本号": CodeGenHistory("lb_base依赖范围", "变更描述", "compatible_required值")
|
|
67
75
|
history_versions = {
|
|
68
|
-
"5.3": CodeGenHistory("lb_base/[>=0.8.5 <0.9.0]", "支持32位操作系统", "8004"),
|
|
69
76
|
"5.4": CodeGenHistory("lb_base/[>=0.9.0 <0.10.0]", "LBInterface增加alias", "9000"),
|
|
70
77
|
}
|
|
78
|
+
|
|
79
|
+
# 最新的版本号
|
|
71
80
|
__version__=Version("5.4")
|
|
72
81
|
|
|
73
82
|
|
|
74
83
|
def version_check(ver_str: str):
|
|
75
84
|
if not re.match("^([0-9]|([1-9][0-9]*))\\.([0-9]|([1-9][0-9]*))$", ver_str):
|
|
76
85
|
raise Exception(f"Version string {ver_str} not match with regex ^([0-9]|([1-9][0-9]*))\\.([0-9]|([1-9][0-9]*))$")
|
|
77
|
-
if
|
|
86
|
+
if history_versions.get(ver_str):
|
|
87
|
+
return ver_str
|
|
88
|
+
if not history_versions:
|
|
78
89
|
return ver_str
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
raise Exception(f"Can't found the valid version for {ver_str}")
|
|
84
|
-
|
|
85
|
-
def codegen_version_max():
|
|
86
|
-
max_v = __version__
|
|
87
|
-
for ver_str, _ in history_versions.items():
|
|
88
|
-
next_ver = Version(ver_str)
|
|
89
|
-
if next_ver.bt(max_v.str):
|
|
90
|
-
max_v = next_ver
|
|
91
|
-
return max_v.str
|
|
90
|
+
log.error(f"Unkonw codegen version {ver_str}, supported versions:")
|
|
91
|
+
for ver, msg in history_versions.items():
|
|
92
|
+
log.error(f" {ver}: {msg}")
|
|
93
|
+
raise Exception(f"Can't found the valid version for {ver_str}")
|
|
92
94
|
|
|
93
95
|
def codegen_version_arg(parser: argparse.ArgumentParser, default=__version__.str, short_arg="-cv", full_arg="--codegen_version"):
|
|
94
|
-
|
|
95
|
-
help=f'''must less than or equal to {codegen_version_max()}, default: {default}
|
|
96
|
-
|
|
97
|
-
codegen versions:
|
|
98
|
-
'''
|
|
96
|
+
help=f'''default: {default}'''
|
|
99
97
|
for ver, detail in history_versions.items():
|
|
100
|
-
help += f"- {ver}: compatible with {detail.lb_base}, {detail.description}
|
|
98
|
+
help += f"\n - {ver}: compatible with {detail.lb_base}, {detail.description}"
|
|
101
99
|
parser.add_argument(short_arg, full_arg, help=help, type=str, default=__version__.str)
|
|
102
100
|
|
|
103
101
|
|
|
102
|
+
def _find_clang_format_config(idf_file):
|
|
103
|
+
"""查找 .clang-format 配置文件,优先级:IDF目录 > 组件目录 > toolkit默认"""
|
|
104
|
+
# 优先级1:IDF文件所在目录(接口仓库级配置)
|
|
105
|
+
idf_dir = os.path.dirname(os.path.realpath(idf_file))
|
|
106
|
+
candidate = os.path.join(idf_dir, ".clang-format")
|
|
107
|
+
if os.path.isfile(candidate):
|
|
108
|
+
return candidate
|
|
109
|
+
# 优先级2:组件源码目录(组件仓库级配置)
|
|
110
|
+
candidate = os.path.join(os.getcwd(), ".clang-format")
|
|
111
|
+
if os.path.isfile(candidate):
|
|
112
|
+
return candidate
|
|
113
|
+
# 优先级3:toolkit自带的默认配置
|
|
114
|
+
candidate = os.path.join(lb_cwd, ".clang-format")
|
|
115
|
+
if os.path.isfile(candidate):
|
|
116
|
+
return candidate
|
|
117
|
+
return None
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _format_generated_files(idf_file, directory, interface_alias):
|
|
121
|
+
"""使用 clang-format 格式化生成的 .c 和 .h 文件"""
|
|
122
|
+
clang_format_bin = shutil.which("clang-format")
|
|
123
|
+
if not clang_format_bin:
|
|
124
|
+
log.warn("clang-format not found, skipping auto-formatting of generated files")
|
|
125
|
+
return
|
|
126
|
+
|
|
127
|
+
style_file = _find_clang_format_config(idf_file)
|
|
128
|
+
if not style_file:
|
|
129
|
+
log.warn("No .clang-format config found, skipping auto-formatting")
|
|
130
|
+
return
|
|
131
|
+
|
|
132
|
+
files_to_format = []
|
|
133
|
+
for ct in ["server", "client", "public"]:
|
|
134
|
+
ct_dir = os.path.join(directory, ct)
|
|
135
|
+
if not os.path.isdir(ct_dir):
|
|
136
|
+
continue
|
|
137
|
+
for ext in [".c", ".h"]:
|
|
138
|
+
fpath = os.path.join(ct_dir, interface_alias + ext)
|
|
139
|
+
if os.path.isfile(fpath):
|
|
140
|
+
files_to_format.append(fpath)
|
|
141
|
+
|
|
142
|
+
if not files_to_format:
|
|
143
|
+
return
|
|
144
|
+
|
|
145
|
+
log.debug(f"Formatting {len(files_to_format)} generated files with clang-format (style: {style_file})")
|
|
146
|
+
for fpath in files_to_format:
|
|
147
|
+
try:
|
|
148
|
+
subprocess.run(
|
|
149
|
+
[clang_format_bin, f"--style=file:{style_file}", "-i", fpath],
|
|
150
|
+
check=True, capture_output=True, timeout=30
|
|
151
|
+
)
|
|
152
|
+
except subprocess.TimeoutExpired:
|
|
153
|
+
log.warn(f"clang-format timed out on {fpath}, skipping")
|
|
154
|
+
except subprocess.CalledProcessError as e:
|
|
155
|
+
log.warn(f"clang-format failed on {fpath}: {e.stderr.strip() if e.stderr else 'unknown error'}")
|
|
156
|
+
except Exception as e:
|
|
157
|
+
log.warn(f"clang-format error on {fpath}: {str(e)}")
|
|
158
|
+
|
|
159
|
+
|
|
104
160
|
def _gen_interface(idf_file, directory=".", code_type="all", codegen_version_str="5.4", log_level="NOTSET"):
|
|
105
161
|
"""模块级函数,供多进程调用"""
|
|
106
162
|
directory = os.path.realpath(directory)
|
|
@@ -137,6 +193,8 @@ def _gen_interface(idf_file, directory=".", code_type="all", codegen_version_str
|
|
|
137
193
|
with open(json_file, "w", encoding="utf-8") as fp:
|
|
138
194
|
yaml.dump(data, fp, encoding='utf-8', allow_unicode=True)
|
|
139
195
|
|
|
196
|
+
_format_generated_files(idf_file, directory, interface.alias)
|
|
197
|
+
|
|
140
198
|
|
|
141
199
|
class CodeGen(object):
|
|
142
200
|
def __init__(self, args):
|
|
@@ -215,7 +273,7 @@ class CodeGen(object):
|
|
|
215
273
|
raise ArgException(f"argument error, arguments -c/--cdf_file and -i/--idf_file are not set")
|
|
216
274
|
if not os.path.isfile(intf_file):
|
|
217
275
|
raise ArgException(f"argument -i/--idf_file: {args.idf_file} not exist")
|
|
218
|
-
if self.codegen_version.bt(
|
|
276
|
+
if self.codegen_version.bt(__version__.str):
|
|
219
277
|
raise ArgException(f"argument -cv/--codegen_version: validate failed, must less than or equal to {__version__.str}")
|
|
220
278
|
out_dir = os.path.join(os.getcwd(), args.directory)
|
|
221
279
|
if not intf_file.endswith(".yaml"):
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
# Copyright (c) 2021-2024 litebmc.com
|
|
2
|
+
#
|
|
3
|
+
# This program is free software; you can redistribute it and/or modify it
|
|
4
|
+
# under the terms of the GNU General Public License as published by the
|
|
5
|
+
# Free Software Foundation; either version 3 of the License, or (at your
|
|
6
|
+
# option) any later version.
|
|
1
7
|
"""语言相关类型定义"""
|
|
2
8
|
import sys
|
|
3
9
|
from lbkit.errors import OdfValidateException
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
# Copyright (c) 2021-2024 litebmc.com
|
|
2
|
+
#
|
|
3
|
+
# This program is free software; you can redistribute it and/or modify it
|
|
4
|
+
# under the terms of the GNU General Public License as published by the
|
|
5
|
+
# Free Software Foundation; either version 3 of the License, or (at your
|
|
6
|
+
# option) any later version.
|
|
1
7
|
import os
|
|
2
8
|
import re
|
|
3
9
|
import copy
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Copyright (c) 2021-2024 litebmc.com
|
|
2
|
+
#
|
|
3
|
+
# This program is free software; you can redistribute it and/or modify it
|
|
4
|
+
# under the terms of the GNU General Public License as published by the
|
|
5
|
+
# Free Software Foundation; either version 3 of the License, or (at your
|
|
6
|
+
# option) any later version.
|
|
7
|
+
from mako.lookup import TemplateLookup
|
|
8
|
+
|
|
9
|
+
class Renderer(object):
|
|
10
|
+
def __init__(self):
|
|
11
|
+
super(Renderer, self).__init__()
|
|
12
|
+
|
|
13
|
+
def render(self, lookup: TemplateLookup, template, **kwargs):
|
|
14
|
+
t = lookup.get_template(template)
|
|
15
|
+
return t.render(lookup=lookup, **kwargs)
|
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
<%
|
|
2
2
|
from inflection import underscore
|
|
3
3
|
%>\
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (c) 2021-2024 litebmc.com
|
|
6
|
+
* Auto-generated by lbkit, DO NOT EDIT.
|
|
7
|
+
*
|
|
8
|
+
* This library is free software; you can redistribute it and/or modify it
|
|
9
|
+
* under the terms of the GNU Lesser General Public License as published by the
|
|
10
|
+
* Free Software Foundation; either version 2.1 of the License, or (at your
|
|
11
|
+
* option) any later version.
|
|
12
|
+
*
|
|
13
|
+
* This library is distributed in the hope that it will be useful, but WITHOUT
|
|
14
|
+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15
|
+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
16
|
+
* for more details.
|
|
17
|
+
**/
|
|
18
|
+
|
|
4
19
|
#include "lb_base.h"
|
|
5
20
|
#include "${intf.alias}.h"
|
|
6
21
|
|
|
@@ -31,46 +46,6 @@ gint ${class_name}_set_${prop.name}(${class_name} obj,
|
|
|
31
46
|
return lb_impl.write_property((LBO *)obj, &${properties}.${prop.name}, tmp, error);
|
|
32
47
|
}
|
|
33
48
|
|
|
34
|
-
% endif
|
|
35
|
-
## 私有或只写属性不允许读
|
|
36
|
-
% if not prop.private and prop.access != "write":
|
|
37
|
-
% if prop.deprecated:
|
|
38
|
-
__deprecated gint ${class_name}_get_${prop.name}(${class_name} obj,
|
|
39
|
-
${", ".join(prop.out_declare()).replace("<arg_name>", "value").replace("<const>", "")}, GError **error)
|
|
40
|
-
% else:
|
|
41
|
-
gint ${class_name}_get_${prop.name}(${class_name} obj, ${", ".join(prop.out_declare()).replace("<arg_name>", "value").replace("<const>", "")}, GError **error)
|
|
42
|
-
% endif
|
|
43
|
-
{
|
|
44
|
-
% if "gsize n_" in prop.declare()[0]:
|
|
45
|
-
g_assert(n_value && value);
|
|
46
|
-
% else:
|
|
47
|
-
g_assert(value);
|
|
48
|
-
% endif
|
|
49
|
-
% for line in prop.declare():
|
|
50
|
-
% if "*" in line:
|
|
51
|
-
${line.strip().replace("<arg_name>", "tmp_value").replace("<const>", "")} = NULL;
|
|
52
|
-
% else:
|
|
53
|
-
${line.strip().replace("<arg_name>", "tmp_value").replace("<const>", "")};
|
|
54
|
-
% endif
|
|
55
|
-
% endfor
|
|
56
|
-
GVariant *out = NULL;
|
|
57
|
-
|
|
58
|
-
gint ret = lb_impl.read_property((LBO *)obj, &${properties}.${prop.name}, &out, error);
|
|
59
|
-
if (ret == 0 && out) {
|
|
60
|
-
% for line in prop.decode_func():
|
|
61
|
-
${line.replace("<arg_in>", "tmp_value").replace("<arg_name>", "out")};
|
|
62
|
-
% endfor
|
|
63
|
-
*value = tmp_value;
|
|
64
|
-
% if "gsize n_" in prop.declare()[0]:
|
|
65
|
-
*n_value = n_tmp_value;
|
|
66
|
-
% endif
|
|
67
|
-
}
|
|
68
|
-
if (out) {
|
|
69
|
-
g_variant_unref(out);
|
|
70
|
-
}
|
|
71
|
-
return ret;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
49
|
% endif
|
|
75
50
|
% endfor
|
|
76
51
|
|
|
@@ -116,10 +91,8 @@ static LBInterface _${class_name}_interface = {
|
|
|
116
91
|
.name = "${intf.name}",
|
|
117
92
|
.properties = (LBProperty *)&${properties},
|
|
118
93
|
.interface = NULL, /* load from usr/share/dbus-1/interfaces/${intf.name}.xml by lb_init */
|
|
119
|
-
#ifdef LB_CODEGEN_BE_5_4
|
|
120
94
|
.alias = "${class_name}",
|
|
121
95
|
.object_template = "${intf.object_path}",
|
|
122
|
-
#endif
|
|
123
96
|
};
|
|
124
97
|
|
|
125
98
|
static LBBase *_get_real_object(LBO *obj)
|
|
@@ -155,7 +128,7 @@ static void _${class_name}_destroy(LBO *obj)
|
|
|
155
128
|
*/
|
|
156
129
|
static LBO *_${class_name}_create(const gchar *name, gpointer opaque)
|
|
157
130
|
{
|
|
158
|
-
struct _${intf.alias} *obj =
|
|
131
|
+
struct _${intf.alias} *obj = g_malloc0(sizeof(struct _${intf.alias}) + sizeof(GVariant *) * ${intf.alias}_PROP_COUNT);
|
|
159
132
|
memcpy(obj->_base.magic, LB_MAGIC, strlen(LB_MAGIC) + 1);
|
|
160
133
|
obj->_base.lock = g_new0(GRecMutex, 1);
|
|
161
134
|
g_rec_mutex_init(obj->_base.lock);
|