mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-29 18:48:09 +08:00
improve idl gen
This commit is contained in:
parent
8b2e81a416
commit
de75e9ae33
@ -1,5 +1,8 @@
|
||||
# 最新动态
|
||||
|
||||
2022/02/23
|
||||
* 修复导出IDL文件的时候因为查找不到依赖的类导致出现警告(感谢智明提供补丁)。
|
||||
|
||||
2022/02/22
|
||||
* 完善API注释。
|
||||
* 完善fscript调试器。
|
||||
|
@ -308,12 +308,22 @@ class AppHelperBase:
|
||||
print(self.DEF_FILE)
|
||||
else:
|
||||
return
|
||||
defDirlist = ''
|
||||
if self.APP_ROOT != self.AWTK_ROOT:
|
||||
defDirlist += os.path.abspath(self.AWTK_ROOT + '/tools/idl_gen/idl.json') + ';'
|
||||
for defLib in self.DEPENDS_LIBS :
|
||||
tmp_filename = os.path.abspath(defLib["root"] + '/idl/idl.json')
|
||||
if not os.path.exists(tmp_filename) :
|
||||
tmp_filename = os.path.abspath(defLib["root"] + '/idl.json')
|
||||
defDirlist += tmp_filename + ';'
|
||||
|
||||
idl_gen_tools = os.path.join(self.AWTK_ROOT, 'tools/idl_gen/index.js')
|
||||
dll_def_gen_tools = os.path.join(
|
||||
self.AWTK_ROOT, 'tools/dll_def_gen/index.js')
|
||||
|
||||
cmd = 'node ' + '"' + idl_gen_tools + '"' + ' idl/idl.json ' + self.SRC_DIR
|
||||
if defDirlist != '' :
|
||||
cmd += ' "' + defDirlist + '" '
|
||||
if os.system(cmd) != 0:
|
||||
print('exe cmd: ' + cmd + ' failed.')
|
||||
|
||||
|
@ -13,9 +13,13 @@
|
||||
* 1. 基本用法
|
||||
|
||||
```
|
||||
node index.js [输出的 IDL 文件名] [源代码路径]
|
||||
node index.js [outputIDL] [sourcesPath] [defDirList]
|
||||
```
|
||||
|
||||
* outputIDL 输出的 IDL 文件名。
|
||||
* sourcesPath 源代码的路径。
|
||||
* defDirList 导出 IDL 的源码依赖路径,如果没有依赖可以缺省,如果多个依赖路径需要通过分号隔开,如 "../awtk;../awtk-mvvm;"。
|
||||
|
||||
* 2. 生成 AWTK 的 IDL 文件。
|
||||
|
||||
```
|
||||
@ -24,10 +28,10 @@ node index.js
|
||||
|
||||
* 3. 生成外部项目的 IDL 文件。
|
||||
|
||||
生成外部项目的 IDL 文件时,需要指定**输出的 IDL 文件名**和**源代码的路径**。如:
|
||||
生成外部项目的 IDL 文件时,需要指定**输出的 IDL 文件名**和**源代码的路径**以及缺省设置**导出 IDL 的源码依赖路径**。如:
|
||||
|
||||
```
|
||||
node index.js slider_circle.idl ../../../awtk_slider_circle/src
|
||||
node index.js slider_circle.idl ../../../awtk_slider_circle/src "../../awtk;"
|
||||
```
|
||||
|
||||
## 三、合并多个 IDL 文件
|
||||
|
@ -373,9 +373,23 @@ class IDLGen {
|
||||
});
|
||||
}
|
||||
|
||||
getClassByDefDir(name) {
|
||||
let v = null;
|
||||
this.defInfoList.find(defInfo => {
|
||||
return defInfo.json.find(cls => {
|
||||
if (cls.type === 'class') {
|
||||
v = cls;
|
||||
return cls.name === name;
|
||||
}
|
||||
});
|
||||
});
|
||||
return v;
|
||||
}
|
||||
|
||||
updateLevel() {
|
||||
let json = this.result;
|
||||
let getClass = this.getClass.bind(this);
|
||||
let getClassByDefDir = this.getClassByDefDir.bind(this);
|
||||
|
||||
function updateLevel(cls) {
|
||||
if(cls.level) {
|
||||
@ -385,6 +399,9 @@ class IDLGen {
|
||||
cls.level = 1;
|
||||
if(cls.parent) {
|
||||
let parent = getClass(cls.parent);
|
||||
if (!parent) {
|
||||
parent = getClassByDefDir(cls.parent);
|
||||
}
|
||||
if(parent) {
|
||||
cls.level += updateLevel(parent);
|
||||
} else {
|
||||
@ -436,13 +453,30 @@ class IDLGen {
|
||||
}
|
||||
}
|
||||
|
||||
static gen(sourcesPath, outputIDL) {
|
||||
getDefInfoList(defDirlist) {
|
||||
if (typeof(defDirlist) !== 'undefined') {
|
||||
let arr = defDirlist.split(';');
|
||||
arr.forEach(filename => {
|
||||
if (filename.length > 0) {
|
||||
let json = JSON.parse(fs.readFileSync(filename).toString());
|
||||
let defInfo = {};
|
||||
defInfo.json = json;
|
||||
this.defInfoList.push(defInfo);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
static gen(sourcesPath, outputIDL, defDirlist) {
|
||||
let gen = new IDLGen();
|
||||
let arr = sourcesPath.split(';');
|
||||
|
||||
console.log(sourcesPath, arr);
|
||||
|
||||
gen.result = []
|
||||
gen.defInfoList = []
|
||||
|
||||
gen.getDefInfoList(defDirlist);
|
||||
arr.forEach(iter => {
|
||||
gen.run(path.normalize(iter));
|
||||
})
|
||||
|
@ -3,20 +3,24 @@ const path = require('path');
|
||||
const glob = require('glob')
|
||||
const IDLGen = require('./idl_gen.js')
|
||||
|
||||
let defDirlist = undefined;
|
||||
let outputIDL = 'idl.json';
|
||||
let sourcesPath = path.normalize(path.join(__dirname, '../../src'));
|
||||
|
||||
if(process.argv.length == 3) {
|
||||
outputIDL = process.argv[2];
|
||||
} else if(process.argv.length > 3) {
|
||||
if(process.argv.length > 2) {
|
||||
outputIDL = process.argv[2];
|
||||
}
|
||||
if(process.argv.length > 3) {
|
||||
sourcesPath = process.argv[3];
|
||||
}
|
||||
if(process.argv.length > 4) {
|
||||
defDirlist = process.argv[4];
|
||||
}
|
||||
|
||||
if(sourcesPath === '-h' || sourcesPath === '--help') {
|
||||
console.log('Usage: node index.js outputIDL sourcesPath');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
IDLGen.gen(sourcesPath, outputIDL)
|
||||
IDLGen.gen(sourcesPath, outputIDL, defDirlist)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user