awtk/tools/dll_def_gen/index.js

79 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-04-28 09:34:09 +08:00
const fs = require('fs')
const path = require('path')
let exportIndex = 1;
class DefGenerator {
2020-05-25 17:31:12 +08:00
genMethod(iter) {
let name = iter.name;
if (iter.export) {
if (iter.export === 'none') {
console.log('skip:' + iter.name);
return;
} else {
name = iter.export
2020-04-28 09:34:09 +08:00
}
2020-05-25 17:31:12 +08:00
}
this.result += ` ${name} @${exportIndex++}\n`
}
genOneClass(cls) {
cls.methods.forEach(iter => this.genMethod(iter));
2020-04-28 09:34:09 +08:00
}
genOne(cls) {
if (cls.type === 'class') {
2020-05-25 17:31:12 +08:00
this.genOneClass(cls);
} else if (cls.type === 'method') {
this.genMethod(cls);
2020-04-28 09:34:09 +08:00
}
}
2020-05-20 17:27:56 +08:00
writeResult(filename, result) {
2020-04-28 09:34:09 +08:00
fs.writeFileSync(filename, result);
console.log("write to " + filename)
}
2020-05-20 17:27:56 +08:00
genJsonAll(json, outputDef) {
let ext = path.extname(outputDef);
let name = path.basename(outputDef, ext);
2020-04-28 09:34:09 +08:00
this.result = ''
this.result += `LIBRARY ${name}\n`
this.result += 'EXPORTS\n'
2020-05-20 17:27:56 +08:00
console.log(outputDef, name)
2020-04-28 09:34:09 +08:00
json.forEach(iter => {
this.genOne(iter);
});
2020-05-20 17:27:56 +08:00
this.writeResult(outputDef, this.result);
2020-04-28 09:34:09 +08:00
}
2020-05-20 17:27:56 +08:00
genAll(filename, outputDef) {
this.genJsonAll(JSON.parse(fs.readFileSync(filename).toString()), outputDef);
2020-04-28 09:34:09 +08:00
}
2020-05-20 17:27:56 +08:00
static gen(inputIDL, outputDef) {
2020-04-28 09:34:09 +08:00
const gen = new DefGenerator();
2020-05-20 17:27:56 +08:00
gen.genAll(inputIDL, outputDef);
2020-04-28 09:34:09 +08:00
2020-05-20 17:27:56 +08:00
console.log(`${inputIDL} => ${outputDef}`);
2020-04-28 09:34:09 +08:00
}
}
let inputIDL = path.normalize(path.join(__dirname, '../idl_gen/idl.json'));
2020-05-20 17:27:56 +08:00
let outputDef = '../../dllexports/awtk.def'
if(process.argv.length == 4) {
inputIDL = process.argv[2];
outputDef = process.argv[3];
} else if(process.argv.length != 2) {
console.log('Usage: node index.js inputIDL outputDef');
process.exit(0);
}
DefGenerator.gen(inputIDL, outputDef);