mirror of
https://gitee.com/openharmony/napi_generator
synced 2024-11-23 08:20:01 +00:00
根据评审意见修改工具文档
Signed-off-by: chen-zhongwei050 <chenzhongwei050@chinasoftinc.com>
This commit is contained in:
parent
3bf52ea62d
commit
6ffb56de0d
@ -1,18 +1,17 @@
|
||||
# Develop guide
|
||||
# Develop Guide
|
||||
|
||||
## h2hdf工具使用场景
|
||||
|
||||
在OpenHarmony系统中,上层应用或服务层通过调用HDF框架提供的HDI接口,能够以一种标准化和抽象化的方式与底层硬件设备进行交互。使用h2hdf工具,用户只需提供一个drivername,工具会自动生成整个框架的代码,包含驱动配置文件、idl接口、驱动程序driver和驱动服务框架。
|
||||
|
||||
![image-20240724093743837](./figures/pic_frame.png))
|
||||
![image-20240724093743837](./figures/pic_code_frame.png)
|
||||
|
||||
## h2hdf工具代码框架说明
|
||||
|
||||
```
|
||||
napi_generator/src/cli/h2hdf
|
||||
|
||||
h2hdf
|
||||
├── docs # 文档
|
||||
│ ├── figures # 图片资源
|
||||
│ ├── usage.md # 使用文档
|
||||
│ ├── develop.md # 设计文档
|
||||
├── src
|
||||
@ -21,21 +20,25 @@ h2hdf
|
||||
│ │ │ ├── hcsconfigTemplete.gen # hcs配置模板
|
||||
│ │ ├── IdlInterfaceTemplete
|
||||
│ │ │ ├── buildgnTemplete.gen # idl接口BUILD.gn模板
|
||||
│ │ │ ├── bundlejsonTemplete.gen # idl接口bundle.json模板
|
||||
│ │ │ ├── v4_1
|
||||
│ │ │ │ ├── bundlejsonTemplete.gen # idl接口bundle.json模板
|
||||
│ │ │ ├── idlInterfaceTemplete.gen # idl接口定义文件模板
|
||||
│ │ ├── PeripheralTemplete
|
||||
│ │ │ ├── DumpExampleTemplete # dump示例
|
||||
│ │ │ │ ├── buildgnTemplete.gen # BUILD.gn模板
|
||||
│ │ │ │ ├── v4_1
|
||||
│ │ │ │ │ ├── buildgnTemplete.gen # BUILD.gn模板
|
||||
│ │ │ │ ├── dumpCTemplete.gen # dump实现示例模板
|
||||
│ │ │ │ ├── dumpHTemplete.gen # dump h文件模板
|
||||
│ │ │ ├── HdiServiceTemplete # hdi_service 模板
|
||||
│ │ │ │ ├── buildgnTemplete.gen # BUILD.gn模板
|
||||
│ │ │ │ ├── v4_1
|
||||
│ │ │ │ │ ├── buildgnTemplete.gen # BUILD.gn模板
|
||||
│ │ │ │ ├── driverTemplete.gen # driver模板
|
||||
│ │ │ │ ├── logHTemplte.gen # 日志文件模板
|
||||
│ │ │ │ ├── serviceCppTemplete.gen # 驱动服务模板
|
||||
│ │ │ │ ├── serviceHTemplete.gen # 驱动服务 h 文件模板
|
||||
│ │ │ ├── buildgnTemplete.gen # hdi service BUILD.gn模板
|
||||
│ │ │ ├── bundlejsonTemplete.gen # hdi service bundle.json模板
|
||||
│ │ │ ├── v4_1
|
||||
│ │ │ │ ├── bundlejsonTemplete.gen # hdi service bundle.json模板
|
||||
│ │ ├── framework.json # 存储模板对应相对路径
|
||||
│ ├── generate.js # 使用templete中对应的模板生成代码。
|
||||
│ ├── main.js # 工具入口文件,定义输入参数,调用generate.js来启动代码生成过程。
|
||||
@ -46,50 +49,60 @@ h2hdf
|
||||
|
||||
![image-20240724093743837](./figures/pic_code_frame.png)
|
||||
|
||||
// 脚本重要函数
|
||||
main.js为脚本入口,其中使用stdio.getopt获取参数,参数分别为: -n, drivername,例如:hello;-v, 可选参数,版本,默认为4.1;-o, 可选参数,默认为当前目录,指定生成框架代码输出路径。
|
||||
|
||||
```
|
||||
// main.js
|
||||
|
||||
let ops = stdio.getopt({
|
||||
// 输入driver name ,输入一个字符串,默认为hello
|
||||
'drivername': { key: 'n', args: 1, description: 'driver name', default: 'hello' },
|
||||
// 输入版本号
|
||||
'version': { key: 'v', args: 1, description: 'source version', default: '4.1' },
|
||||
// 输出文件夹路径
|
||||
'out': { key: 'o', args: 1, description: 'output directory', default: '.' },
|
||||
'out': { key: 'o', args: 1, description: 'output directory', default: '' },
|
||||
});
|
||||
```
|
||||
|
||||
对输入的参数值进行校验:checkInput对输入的drivername进行校验,输入的drivername必须符合命名规范;isValidValue对输入的版本号进行校验,输入的版本号必须包含在版本号数组中,该数组后续可持续更新:
|
||||
|
||||
```
|
||||
// generate.js
|
||||
...
|
||||
const allowedVersion = ['4.0', '4.1', '5.0', '5.1'];
|
||||
function isValidValue(value, allowedVersion) {
|
||||
return allowedVersion.includes(value);
|
||||
}
|
||||
|
||||
function checkInput(input) {
|
||||
const regex = /\b[a-zA-Z_][a-zA-Z0-9_]*\b/;
|
||||
return regex.test(input);
|
||||
}
|
||||
```
|
||||
|
||||
使用getJsonCfg读取json文件中hdf框架模板的路径:
|
||||
|
||||
```
|
||||
function getJsonCfg(jsonFilePath) {
|
||||
let jsonCfg = null;
|
||||
let jsonFile = fs.readFileSync(jsonFilePath, { encoding: 'utf8' });
|
||||
jsonCfg = JSON.parse(jsonFile);
|
||||
return jsonCfg;
|
||||
}
|
||||
```
|
||||
|
||||
获取到每个模板的路径后,根据路径读取模板文件,并替换模板文件中的drivername等:
|
||||
|
||||
```
|
||||
/* 根据用户输入的driver名字生成framework框架
|
||||
* drivername:用户输入的驱动名,out:生成框架路径
|
||||
* 1. 读取json文件模板
|
||||
* 2. 替换模板中的名字并写文件输出
|
||||
* drivername:用户输入的驱动名,frameworkJson: 模板内容,out:生成框架路径
|
||||
* 替换模板中的名字并写文件输出
|
||||
*/
|
||||
function genDriverFramework(driverName, out = '') {
|
||||
// 读取Json文件,获取各模板路径
|
||||
let frameworkJsonPath = path.join(__dirname, './templete/framework.json');
|
||||
let frameworkJson = getJsonCfg(frameworkJsonPath);
|
||||
|
||||
let frameworkPath = pathJoin(out, 'hdf');
|
||||
|
||||
let namespaceName = driverName.substring(0,1).toUpperCase() + driverName.substring(1, driverName.length);
|
||||
let idlFileName = 'I' + namespaceName + 'Interface';
|
||||
let rootInfo = {
|
||||
'driverName': driverName,
|
||||
'namespaceName': namespaceName,
|
||||
'idlFileName': idlFileName,
|
||||
}
|
||||
|
||||
function genDriverFramework(driverName, frameworkJson, version, out = '') {
|
||||
...
|
||||
// 生成Hcs配置文件
|
||||
genHcsconfigFile(frameworkJson, driverName, frameworkPath);
|
||||
|
||||
// 生成Idl接口
|
||||
genInterface(frameworkPath, frameworkJson, rootInfo);
|
||||
|
||||
// 生成hdi_service
|
||||
genPeripheral(frameworkPath,frameworkJson, rootInfo);
|
||||
genPeripheral(frameworkPath, frameworkJson, rootInfo);
|
||||
}
|
||||
```
|
||||
|
||||
@ -115,11 +128,14 @@ node main.js -n hello
|
||||
|
||||
-n, drivername,例如:hello
|
||||
|
||||
-v, 可选参数,版本,默认为4.1
|
||||
|
||||
-o, 可选参数,默认为当前目录,指定生成框架代码输出路径。
|
||||
|
||||
6.执行成功后在napi_generator/src/cli/h2hdf/src/下生成hellohdf文件夹,文件夹中目录结构如下所示:
|
||||
|
||||
```
|
||||
hellohdf
|
||||
├── HcsConfig # hcs配置文件
|
||||
│ ├── device_info.hcs # 内容配置到源码vendor/hihope/rk3568/hdf_config/uhdf/device_info.hcs文件中
|
||||
├── IdlInterface
|
||||
@ -148,29 +164,56 @@ node main.js -n hello
|
||||
|
||||
### 编译
|
||||
|
||||
1.将hellohdf/Peripheral文件夹下的hello文件夹拷贝到源码drivers/peripheral目录下,将hellohdf/IdlInterface文件夹下的hello文件夹拷贝到源码drivers/interface目录下,将hellohdf/HcsConfig/device_info.hcs中的内容拷贝到源码vendor/hihope/rk3568/hdf_config/uhdf/device_info.hcs文件中
|
||||
1.将hellohdf/Peripheral文件夹下的hello文件夹拷贝到源码drivers/peripheral目录下
|
||||
|
||||
2.配置产品:在源码productdefine/common/inherit/rich.json文件中增加以下代码:
|
||||
```
|
||||
cp hellohdf/Peripheral/hello 源码/drivers/peripheral
|
||||
```
|
||||
|
||||
将hellohdf/IdlInterface文件夹下的hello文件夹拷贝到源码drivers/interface目录下
|
||||
|
||||
```
|
||||
cp hellohdf/IdlInterface/hello 源码/drivers/interface
|
||||
```
|
||||
|
||||
将hellohdf/HcsConfig/device_info.hcs中的内容拷贝到源码vendor/hihope/rk3568/hdf_config/uhdf/device_info.hcs文件中,如下所示:
|
||||
|
||||
```
|
||||
root {
|
||||
device_info {
|
||||
...
|
||||
hello :: host {
|
||||
hostName = "hello_host";
|
||||
priority = 50;
|
||||
hello_device :: device {
|
||||
device0 :: deviceNode {
|
||||
preload = 0;
|
||||
policy = 2;
|
||||
priority = 100;
|
||||
moduleName = "libhello_driver.z.so";
|
||||
serviceName = "hello_interface_service";
|
||||
}
|
||||
}
|
||||
}
|
||||
...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2.配置产品:以rk3568为例,在源码vendor/hihope/rk3568/config.json文件中hdf子系统的components中增加以下内容:
|
||||
|
||||
```
|
||||
{
|
||||
"component": "drivers_interface_hello",
|
||||
"features": []
|
||||
"component": "drivers_interface_hello",
|
||||
"features": []
|
||||
},
|
||||
```
|
||||
|
||||
其中drivers_interface_hello为drivers/interface/hello/v1_0/BUILD.gn中的part_name。
|
||||
|
||||
在源码productdefine/common/inherit/chipset_common.json文件中增加以下代码:
|
||||
|
||||
```
|
||||
{
|
||||
"component": "drivers_peripheral_hello",
|
||||
"features": []
|
||||
},
|
||||
"component": "drivers_peripheral_hello",
|
||||
"features": []
|
||||
}
|
||||
```
|
||||
|
||||
其中drivers_peripheral_hello为drivers/peripheral/hello/bundle.json中的component。
|
||||
注意:drivers_interface_hello为drivers/interface/hello/v1_0/BUILD.gn中的part_name。drivers_peripheral_hello为drivers/peripheral/hello/bundle.json中的component。
|
||||
|
||||
3.编译,在源码下执行以下命令进行编译:
|
||||
|
||||
@ -200,6 +243,10 @@ cat hdf_devhost.cfg
|
||||
./hdf_devhost 14 hello_host
|
||||
```
|
||||
|
||||
![image-20240903114845035](./figures/pic_show_exe.png)
|
||||
|
||||
注意 :不可将进程kill
|
||||
|
||||
3.查看host是否加载:新开一个命令行窗口,hdc进入开发板,执行以下命令查看进程是否拉起:
|
||||
|
||||
```
|
||||
@ -220,14 +267,6 @@ ps -A | grep host
|
||||
|
||||
![image-20240724093543096](./figures/pic_show_host.png)
|
||||
|
||||
```
|
||||
----------------------------------HdfDeviceServiceManager--------------------------------
|
||||
hdf device information in user space, format:
|
||||
...
|
||||
hello_host :0xf
|
||||
device0 :0xf000101 :hello_interface_service
|
||||
```
|
||||
|
||||
使用hidumper查看更多信息
|
||||
|
||||
```
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 36 KiB |
BIN
src/cli/h2hdf/docs/figures/pic_show_exe.png
Normal file
BIN
src/cli/h2hdf/docs/figures/pic_show_exe.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 855 B |
@ -3,7 +3,7 @@
|
||||
## 简介
|
||||
在OpenHarmony系统中,上层应用或服务层通过调用HDF框架提供的HDI接口,能够以一种标准化和抽象化的方式与底层硬件设备进行交互。使用h2hdf工具,用户只需提供一个drivername,工具会自动生成整个框架的代码,包含驱动配置文件、idl接口、驱动程序driver和驱动服务框架。
|
||||
|
||||
![image-20240724093743837](./figures/pic_frame.png)
|
||||
![image-20240724093743837](./figures/pic_code_frame.png)
|
||||
|
||||
## 约束
|
||||
系统:建议Ubuntu 20.04或者Windows 10
|
||||
@ -32,11 +32,14 @@ node main.js -n hello
|
||||
|
||||
-n, drivername,例如:hello
|
||||
|
||||
-v, 可选参数,版本,默认为4.1
|
||||
|
||||
-o, 可选参数,默认为当前目录,指定生成框架代码输出路径。
|
||||
|
||||
6.执行成功后在napi_generator/src/cli/h2hdf/src/下生成hellohdf文件夹,文件夹中目录结构如下所示:
|
||||
|
||||
```
|
||||
hellohdf
|
||||
├── HcsConfig # hcs配置文件
|
||||
│ ├── device_info.hcs # 内容配置到源码vendor/hihope/rk3568/hdf_config/uhdf/device_info.hcs文件中
|
||||
├── IdlInterface
|
||||
@ -65,29 +68,56 @@ node main.js -n hello
|
||||
|
||||
### 编译
|
||||
|
||||
1.将hellohdf/Peripheral文件夹下的hello文件夹拷贝到源码drivers/peripheral目录下,将hellohdf/IdlInterface文件夹下的hello文件夹拷贝到源码drivers/interface目录下,将hellohdf/HcsConfig/device_info.hcs中的内容拷贝到源码vendor/hihope/rk3568/hdf_config/uhdf/device_info.hcs文件中
|
||||
1.将hellohdf/Peripheral文件夹下的hello文件夹拷贝到源码drivers/peripheral目录下
|
||||
|
||||
2.配置产品:在源码productdefine/common/inherit/rich.json文件中增加以下代码:
|
||||
```
|
||||
cp hellohdf/Peripheral/hello 源码/drivers/peripheral
|
||||
```
|
||||
|
||||
将hellohdf/IdlInterface文件夹下的hello文件夹拷贝到源码drivers/interface目录下
|
||||
|
||||
```
|
||||
cp hellohdf/IdlInterface/hello 源码/drivers/interface
|
||||
```
|
||||
|
||||
将hellohdf/HcsConfig/device_info.hcs中的内容拷贝到源码vendor/hihope/rk3568/hdf_config/uhdf/device_info.hcs文件中,如下所示:
|
||||
|
||||
```
|
||||
root {
|
||||
device_info {
|
||||
...
|
||||
hello :: host {
|
||||
hostName = "hello_host";
|
||||
priority = 50;
|
||||
hello_device :: device {
|
||||
device0 :: deviceNode {
|
||||
preload = 0;
|
||||
policy = 2;
|
||||
priority = 100;
|
||||
moduleName = "libhello_driver.z.so";
|
||||
serviceName = "hello_interface_service";
|
||||
}
|
||||
}
|
||||
}
|
||||
...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2.配置产品:以rk3568为例,在源码vendor/hihope/rk3568/config.json文件中hdf子系统的components中增加以下内容:
|
||||
|
||||
```
|
||||
{
|
||||
"component": "drivers_interface_hello",
|
||||
"features": []
|
||||
"component": "drivers_interface_hello",
|
||||
"features": []
|
||||
},
|
||||
```
|
||||
|
||||
其中drivers_interface_hello为drivers/interface/hello/v1_0/BUILD.gn中的part_name。
|
||||
|
||||
在源码productdefine/common/inherit/chipset_common.json文件中增加以下代码:
|
||||
|
||||
```
|
||||
{
|
||||
"component": "drivers_peripheral_hello",
|
||||
"features": []
|
||||
},
|
||||
"component": "drivers_peripheral_hello",
|
||||
"features": []
|
||||
}
|
||||
```
|
||||
|
||||
其中drivers_peripheral_hello为drivers/peripheral/hello/bundle.json中的component。
|
||||
注意:drivers_interface_hello为drivers/interface/hello/v1_0/BUILD.gn中的part_name。drivers_peripheral_hello为drivers/peripheral/hello/bundle.json中的component。
|
||||
|
||||
3.编译,在源码下执行以下命令进行编译:
|
||||
|
||||
@ -117,6 +147,10 @@ cat hdf_devhost.cfg
|
||||
./hdf_devhost 14 hello_host
|
||||
```
|
||||
|
||||
![image-20240903114845035](./figures/pic_show_exe.png)
|
||||
|
||||
注意 :不可将进程kill
|
||||
|
||||
3.查看host是否加载:新开一个命令行窗口,hdc进入开发板,执行以下命令查看进程是否拉起:
|
||||
|
||||
```
|
||||
@ -137,14 +171,6 @@ ps -A | grep host
|
||||
|
||||
![image-20240724093543096](./figures/pic_show_host.png)
|
||||
|
||||
```
|
||||
----------------------------------HdfDeviceServiceManager--------------------------------
|
||||
hdf device information in user space, format:
|
||||
...
|
||||
hello_host :0xf
|
||||
device0 :0xf000101 :hello_interface_service
|
||||
```
|
||||
|
||||
使用hidumper查看更多信息
|
||||
|
||||
```
|
||||
@ -157,4 +183,5 @@ hidumper -s HdfDeviceServiceManager -a "-host hello_host -c"
|
||||
|
||||
#### 静态加载
|
||||
|
||||
// todo 待补充
|
||||
// todo 待补充
|
||||
|
@ -17,18 +17,18 @@
|
||||
"assets": [
|
||||
"./src/templete/HcsconfigTemplete/hcsconfigTemplete.gen",
|
||||
"./src/templete/IdlInterfaceTemplete/buildgnTemplete.gen",
|
||||
"./src/templete/IdlInterfaceTemplete/bundlejsonTemplete.gen",
|
||||
"./src/templete/v4_1/IdlInterfaceTemplete/bundlejsonTemplete.gen",
|
||||
"./src/templete/IdlInterfaceTemplete/idlInterfaceTemplete.gen",
|
||||
"./src/templete/PeripheralTemplete/DumpExampleTemplete/buildgnTemplete.gen",
|
||||
"./src/templete/PeripheralTemplete/DumpExampleTemplete/v4_1/buildgnTemplete.gen",
|
||||
"./src/templete/PeripheralTemplete/DumpExampleTemplete/dumpCTemplete.gen",
|
||||
"./src/templete/PeripheralTemplete/DumpExampleTemplete/dumpHTemplete.gen",
|
||||
"./src/templete/PeripheralTemplete/HdiServiceTemplete/buildgnTemplete.gen",
|
||||
"./src/templete/PeripheralTemplete/HdiServiceTemplete/v4_1/buildgnTemplete.gen",
|
||||
"./src/templete/PeripheralTemplete/HdiServiceTemplete/driverTemplete.gen",
|
||||
"./src/templete/PeripheralTemplete/HdiServiceTemplete/logHTemplete.gen",
|
||||
"./src/templete/PeripheralTemplete/HdiServiceTemplete/serviceCppTemplete.gen",
|
||||
"./src/templete/PeripheralTemplete/HdiServiceTemplete/serviceHTemplete.gen",
|
||||
"./src/templete/PeripheralTemplete/buildgnTemplete.gen",
|
||||
"./src/templete/PeripheralTemplete/bundlejsonTemplete.gen"
|
||||
"./src/templete/PeripheralTemplete/v4_1/bundlejsonTemplete.gen"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -22,13 +22,6 @@ function replaceAll(s, sfrom, sto) {
|
||||
return s;
|
||||
}
|
||||
|
||||
function getJsonCfg(jsonFilePath) {
|
||||
let jsonCfg = null;
|
||||
let jsonFile = fs.readFileSync(jsonFilePath, { encoding: 'utf8' });
|
||||
jsonCfg = JSON.parse(jsonFile);
|
||||
return jsonCfg;
|
||||
}
|
||||
|
||||
function pathJoin(...args) {
|
||||
return path.join(...args);
|
||||
}
|
||||
@ -88,20 +81,16 @@ function writeFile(fn, str) {
|
||||
}
|
||||
|
||||
/* 根据用户输入的driver名字生成framework框架
|
||||
* drivername:用户输入的驱动名,out:生成框架路径
|
||||
* 1. 读取json文件模板
|
||||
* 2. 替换模板中的名字并写文件输出
|
||||
* drivername:用户输入的驱动名,frameworkJson: 模板内容,out:生成框架路径
|
||||
* 替换模板中的名字并写文件输出
|
||||
*/
|
||||
function genDriverFramework(driverName, out = '') {
|
||||
// 读取Json文件,获取各模板路径
|
||||
let frameworkJsonPath = path.join(__dirname, './templete/framework.json');
|
||||
let frameworkJson = getJsonCfg(frameworkJsonPath);
|
||||
|
||||
function genDriverFramework(driverName, frameworkJson, version, out = '') {
|
||||
let frameworkPath = pathJoin(out, driverName + 'hdf');
|
||||
|
||||
let namespaceName = driverName.substring(0, 1).toUpperCase() + driverName.substring(1, driverName.length);
|
||||
let idlFileName = 'I' + namespaceName + 'Interface';
|
||||
let rootInfo = {
|
||||
'version': version,
|
||||
'driverName': driverName,
|
||||
'namespaceName': namespaceName,
|
||||
'idlFileName': idlFileName,
|
||||
@ -139,7 +128,11 @@ function genPeripheral(frameworkPath, frameworkJson, rootInfo) {
|
||||
function genBuildFile(peripheralPath, frameworkJson, rootInfo) {
|
||||
// out/hdf/Peripheral/xxx/bundle.json
|
||||
let genBundlejsonPath = pathJoin(peripheralPath, 'bundle.json');
|
||||
let bundlejsonPath = path.join(__dirname, frameworkJson.PeripheralTemplete.bundlejsonTemplete);
|
||||
let bundlejsonPath = '';
|
||||
if (rootInfo.version === 'v4_1') {
|
||||
bundlejsonPath = path.join(__dirname, frameworkJson.PeripheralTemplete.bundlejsonTemplete.v4_1);
|
||||
}
|
||||
// let bundlejsonPath = path.join(__dirname, frameworkJson.PeripheralTemplete.bundlejsonTemplete);
|
||||
let bundlejsonContent = readFile(bundlejsonPath);
|
||||
bundlejsonContent = replaceAll(bundlejsonContent, '[driver_name]', rootInfo.driverName);
|
||||
writeFile(genBundlejsonPath, bundlejsonContent);
|
||||
@ -199,7 +192,11 @@ function genHdiService(peripheralPath, frameworkJson, rootInfo) {
|
||||
|
||||
// 生成hdi_service下面的BUILD.gn: out/hdf/Peripheral/xxx/hdi_service/
|
||||
let genHdiServiceGnPath = pathJoin(hdiPath, 'BUILD.gn');
|
||||
let serviceGnPath = path.join(__dirname, frameworkJson.PeripheralTemplete.HdiServiceTemplete.buildgnTemplete);
|
||||
let serviceGnPath = '';
|
||||
if (rootInfo.version === 'v4_1') {
|
||||
serviceGnPath = path.join(__dirname, frameworkJson.PeripheralTemplete.HdiServiceTemplete.buildgnTemplete.v4_1);
|
||||
}
|
||||
// let serviceGnPath = path.join(__dirname, frameworkJson.PeripheralTemplete.HdiServiceTemplete.buildgnTemplete);
|
||||
let serviceGnContent = readFile(serviceGnPath);
|
||||
serviceGnContent = replaceAll(serviceGnContent, '[driver_name]', rootInfo.driverName);
|
||||
writeFile(genHdiServiceGnPath, serviceGnContent);
|
||||
@ -209,7 +206,11 @@ function genExampleDumpfile(peripheralPath, frameworkJson, rootInfo) {
|
||||
let dumpExamplePath = pathJoin(peripheralPath, 'hal');
|
||||
createDirectorySync(dumpExamplePath);
|
||||
let genDumpExampleGnPath = pathJoin(dumpExamplePath, 'BUILD.gn');
|
||||
let dumpExampleGnPath = path.join(__dirname, frameworkJson.PeripheralTemplete.DumpExampleTemplete.buildgnTemplete);
|
||||
let dumpExampleGnPath = '';
|
||||
if (rootInfo.version === 'v4_1') {
|
||||
dumpExampleGnPath = path.join(__dirname, frameworkJson.PeripheralTemplete.DumpExampleTemplete.buildgnTemplete.v4_1);
|
||||
}
|
||||
// let dumpExampleGnPath = path.join(__dirname, frameworkJson.PeripheralTemplete.DumpExampleTemplete.buildgnTemplete);
|
||||
let dumpExampleGnContent = readFile(dumpExampleGnPath);
|
||||
dumpExampleGnContent = replaceAll(dumpExampleGnContent, '[driver_name]', rootInfo.driverName);
|
||||
writeFile(genDumpExampleGnPath, dumpExampleGnContent);
|
||||
@ -246,7 +247,11 @@ function genInterface(frameworkPath, frameworkJson, rootInfo) {
|
||||
|
||||
// idl接口bundlejson路径 out/hdf/IdlInterface/foo/bundle.json
|
||||
let genIdlBundlejsonPath = pathJoin(idlPath, 'bundle.json');
|
||||
let idlBundlejsonPath = path.join(__dirname, frameworkJson.IdlInterfaceTemplete.bundlejsonTemplete);
|
||||
let idlBundlejsonPath = '';
|
||||
if (rootInfo.version === 'v4_1') {
|
||||
idlBundlejsonPath = path.join(__dirname, frameworkJson.IdlInterfaceTemplete.bundlejsonTemplete.v4_1);
|
||||
}
|
||||
|
||||
let idlBundlejsonContent = readFile(idlBundlejsonPath);
|
||||
idlBundlejsonContent = replaceAll(idlBundlejsonContent, '[driver_name]', rootInfo.driverName);
|
||||
writeFile(genIdlBundlejsonPath, idlBundlejsonContent);
|
||||
|
@ -12,24 +12,61 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const stdio = require('stdio');
|
||||
const main = require('./generate');
|
||||
|
||||
let ops = stdio.getopt({
|
||||
// 输入driver name ,输入一个字符串,默认为hello
|
||||
'drivername': { key: 'n', args: 1, description: 'driver name', default: 'hello' },
|
||||
// 输入版本号
|
||||
'version': { key: 'v', args: 1, description: 'source version', default: '4.1' },
|
||||
// 输出文件夹路径
|
||||
'out': { key: 'o', args: 1, description: 'output directory', default: '.' },
|
||||
'out': { key: 'o', args: 1, description: 'output directory', default: '' },
|
||||
});
|
||||
|
||||
const allowedVersion = ['4.1', '4-1', '4_1', '4.0', '5.0', '5.1'];
|
||||
|
||||
let drivername = ops.drivername;
|
||||
let version = ops.version;
|
||||
// 若drivername不为空,则生成,否则打印错误信息
|
||||
if (drivername.trim().length !== 0 && checkInput(drivername)) {
|
||||
main.genDriverFramework(drivername);
|
||||
console.info('Generate Success');
|
||||
}
|
||||
if (!isValidValue(version, allowedVersion)) {
|
||||
// 版本号不符合规则 请输入正确的版本号
|
||||
console.log('请输入正确的版本号!如:4.1');
|
||||
return;
|
||||
}
|
||||
// 在这里读取cfg文件
|
||||
let frameworkJsonPath = path.join(__dirname, './templete/framework.json');
|
||||
let frameworkJson = getJsonCfg(frameworkJsonPath);
|
||||
if (version === '4.1' || version === '4-1' || version === '4_1') {
|
||||
version = 'v4_1';
|
||||
} else {
|
||||
console.log('其他版本暂不支持...');
|
||||
return;
|
||||
}
|
||||
|
||||
// 然后再调用templete生成模板
|
||||
main.genDriverFramework(drivername, frameworkJson, version, ops.out);
|
||||
console.log('Generate Success');
|
||||
} else {
|
||||
// 输入的名字不符合规则
|
||||
console.log('请输入正确的drivername!');
|
||||
}
|
||||
|
||||
function isValidValue(value, allowedVersion) {
|
||||
return allowedVersion.includes(value);
|
||||
}
|
||||
|
||||
function checkInput(input) {
|
||||
const regex = /\b[a-zA-Z_][a-zA-Z0-9_]*\b/;
|
||||
return regex.test(input);
|
||||
}
|
||||
|
||||
function getJsonCfg(jsonFilePath) {
|
||||
let jsonCfg = null;
|
||||
let jsonFile = fs.readFileSync(jsonFilePath, { encoding: 'utf8' });
|
||||
jsonCfg = JSON.parse(jsonFile);
|
||||
return jsonCfg;
|
||||
}
|
||||
|
@ -2,23 +2,31 @@
|
||||
"HcsconfigTemplete":"./templete/HcsconfigTemplete/hcsconfigTemplete.gen",
|
||||
"IdlInterfaceTemplete":{
|
||||
"buildgnTemplete":"./templete/IdlInterfaceTemplete/buildgnTemplete.gen",
|
||||
"bundlejsonTemplete":"./templete/IdlInterfaceTemplete/bundlejsonTemplete.gen",
|
||||
"bundlejsonTemplete":{
|
||||
"v4_1": "./templete/IdlInterfaceTemplete/v4_1/bundlejsonTemplete.gen"
|
||||
},
|
||||
"idlInterfaceTemplete":"./templete/IdlInterfaceTemplete/idlInterfaceTemplete.gen"
|
||||
},
|
||||
"PeripheralTemplete": {
|
||||
"DumpExampleTemplete": {
|
||||
"buildgnTemplete":"./templete/PeripheralTemplete/DumpExampleTemplete/buildgnTemplete.gen",
|
||||
"buildgnTemplete":{
|
||||
"v4_1": "./templete/PeripheralTemplete/DumpExampleTemplete/v4_1/buildgnTemplete.gen"
|
||||
},
|
||||
"dumpCTemplete":"./templete/PeripheralTemplete/DumpExampleTemplete/dumpCTemplete.gen",
|
||||
"dumpHTemplete":"./templete/PeripheralTemplete/DumpExampleTemplete/dumpHTemplete.gen"
|
||||
},
|
||||
"HdiServiceTemplete": {
|
||||
"buildgnTemplete":"./templete/PeripheralTemplete/HdiServiceTemplete/buildgnTemplete.gen",
|
||||
"buildgnTemplete":{
|
||||
"v4_1": "./templete/PeripheralTemplete/HdiServiceTemplete/v4_1/buildgnTemplete.gen"
|
||||
},
|
||||
"driverTemplete":"./templete/PeripheralTemplete/HdiServiceTemplete/driverTemplete.gen",
|
||||
"logHTemplete":"./templete/PeripheralTemplete/HdiServiceTemplete/logHTemplete.gen",
|
||||
"serviceCppTemplete":"./templete/PeripheralTemplete/HdiServiceTemplete/serviceCppTemplete.gen",
|
||||
"serviceHTemplete":"./templete/PeripheralTemplete/HdiServiceTemplete/serviceHTemplete.gen"
|
||||
},
|
||||
"buildgnTemplete":"./templete/PeripheralTemplete/buildgnTemplete.gen",
|
||||
"bundlejsonTemplete":"./templete/PeripheralTemplete/bundlejsonTemplete.gen"
|
||||
"bundlejsonTemplete":{
|
||||
"v4_1": "./templete/PeripheralTemplete/v4_1/bundlejsonTemplete.gen"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user