diff --git a/docs/guide/DEVELOP_ZH.md b/docs/guide/DEVELOP_ZH.md deleted file mode 100644 index c5e34992d874d410f79a522f5157aaaed13e14f1..0000000000000000000000000000000000000000 --- a/docs/guide/DEVELOP_ZH.md +++ /dev/null @@ -1,120 +0,0 @@ -# NAPI框架生成工具开发说明 - -若当前工具功能不满足开发者需求,开发者需增强工具能力,则可基于已有源码进行工具二次开发,编译打包生成自定义的可执行文件和插件。 - -## 工具开发 - -### 可执行文件开发说明 - -#### 环境说明 - -系统:建议Ubuntu 20.04或者Windows 10 - -#### 开发步骤 - -##### Linux - -1.安装typescript:在napi_generator/src目录下执行命令: - - npm i typescript - -2.安装stdio:在napi_generator目录下执行命令: - - npm i stdio - -3.安装pkg : 在napi_generator目录下执行命令: - - sudo npm i -g pkg - -4.集成clang-format(可选步骤): - - 如果需要工具自动格式化生成的C++代码,可执行此步骤。 - 将windows版的clang-format.exe程序和linux版的clang-format程序拷贝到napi_generator目录下。 - clang-format程序可从OpenHarmony编译环境获取: - windows版:OpenHarmony/prebuilts/clang/ohos/windows-x86_64/llvm/bin/clang-format.exe - Linux版:OpenHarmony/prebuilts/mingw-w64/ohos/linux-x86_64/clang-mingw/bin/clang-format - -5.打包三个版本 : 执行命令: - - pkg . - -执行以上步骤后,即可在napi_generator目录下生成Windows、linux、mac系统下的可执行程序: - - napi_generator-win.exe、napi_generator-linux、napi_generator-macos - -6.根据需求打包指定系统下的可执行文件。若想只打包windows系统下可执行文件,可执行命令: - - pkg -t node14-win . -o napi_generator-win.exe - -若想只打包linux系统下可执行文件,可执行命令: - - pkg -t node14-linux . -o napi_generator-linux - -若想只打包macos系统下可执行文件,可执行命令: - - pkg -t node14-macos . -o napi_generator-macos - -备注:参数-t为指定系统,参数-o为指定可执行文件名称。 - - -##### Windows - -1.安装typescript:使用管理员身份在napi_generator/src目录下执行命令: - - npm i typescript - -2.安装stdio:使用管理员身份在napi_generator目录下执行命令: - - npm i stdio - -3.安装pkg : 使用管理员身份在napi_generator目录下执行命令: - - npm i -g pkg - -4.集成clang-format(可选步骤): - - 如果需要工具自动格式化生成的C++代码,可执行此步骤。 - 将windows版的clang-format.exe程序和linux版的clang-format程序拷贝到napi_generator目录下。 - clang-format程序可从OpenHarmony编译环境获取: - windows版:OpenHarmony/prebuilts/clang/ohos/windows-x86_64/llvm/bin/clang-format.exe - Linux版:OpenHarmony/prebuilts/mingw-w64/ohos/linux-x86_64/clang-mingw/bin/clang-format - -5.打包三个版本 : 使用管理员身份执行命令: - - pkg . - -执行以上步骤后,即可在napi_generator目录下生成Windows、linux、mac系统下的可执行程序: - - napi_generator-win.exe、napi_generator-linux、napi_generator-macos - -6.根据需求打包指定系统下的可执行文件。若想只打包windows系统下可执行文件,可执行命令: - - pkg -t node14-win . -o napi_generator-win.exe - -若想只打包linux系统下可执行文件,可执行命令: - - pkg -t node14-linux . -o napi_generator-linux - -若想只打包macos系统下可执行文件,可执行命令: - - pkg -t node14-macos . -o napi_generator-macos - -### VS插件开发说明 - -具体的插件开发步骤,可以左键单击以下链接了解: - -[VS插件开发说明](https://gitee.com/openharmony/napi_generator/blob/master/napi_vs_plugin/docs/napi/DEVELOP_ZH.md) - -### DevEco Studio上使用的IntelliJ插件开发说明 - -具体的插件开发步骤,可以左键单击以下链接了解: - -[DevEco Studio上使用的IntelliJ插件开发说明](https://gitee.com/openharmony/napi_generator/blob/master/napi_IntelliJ_plugin/docs/napi/DEVELOP_ZH.md) - -## 工具测试 - 进行工具二次开发后,本地可进行单元测试、story特性测试确保工具的可用性。左键单击以下链接了解详情: - - [单元测试](https://gitee.com/openharmony/napi_generator/blob/master/test/unittest/README_ZH.md) - - [story测试](https://gitee.com/openharmony/napi_generator/blob/master/test/storytest/README_ZH.md) - diff --git a/docs/guide/ENSEMBLE_METHOD_4.0CFGCODE.md b/docs/guide/ENSEMBLE_METHOD_4.0CFGCODE.md deleted file mode 100644 index 0558607b20a7bebb6d2482505e9cdae5cdb3f921..0000000000000000000000000000000000000000 --- a/docs/guide/ENSEMBLE_METHOD_4.0CFGCODE.md +++ /dev/null @@ -1,171 +0,0 @@ -# 手动配置业务代码后集成到OpenHarmony的方法 - -## 场景说明 - -为了实现工具生成的接口被其它子系统或者应用调用,需将生成的代码编译集成到OpenHarmony系统中,使其生成动态库,供OpenHarmony应用层调用。 -本文介绍如何手动配置业务代码并将生成的代码集成到OpenHarmony 4.0 Release。 - -## 4.0 版本 - -### 建立模块位置 - -模块目录理论上可在OpenHarmony工程的任一位置,假设OpenHarmony代码库的目录为OHOS_SRC,在OHOS_SRC/foundation目录下,建测试模块目录:napitest。napitest目录结构如下: - - napitest - |-- binding.gyp - |-- BUILD.gn - |-- bundle.json - |-- napitest.cpp - |-- napitest.h - |-- napitest_middle.h - |-- napitest_middle.cpp - |-- test.sh - |-- tool_utility.cpp - |-- tool_utility.h - -其中bundle.json为新增的编译配置文件,其它为工具生成的代码。 - -### 编译修改点 - -#### 修改bundle.json文件 - -其中destPath选项中的"//foundation/napitest"指的是napitest目录,":napitest"指的是上面BUILD.gn中的目标ohos_shared_library("napitest")。 - -``` -{ - "name": "@ohos/napitest", - "description": "napitest provides atomic capabilities", - "version": "4.0", - "license": "Apache License 2.0", - "publishAs": "code-segment", - "segment": { - "destPath": "foundation/napitest" - }, - "dirs": {}, - "scripts": {}, - "component": { - "name": "napitest", - "subsystem": "napitest", - "features": [], - "adapted_system_type": [ - "standard" - ], - "rom": "10000KB", - "ram": "10000KB", - "deps": { - "components": [ - "ace_napi", - "ipc_core", - "libhilog" - ], - "third_party": [ - "node" - ] - }, - "build": { - "sub_component": [ - "//foundation/napitest:napitest" - ], - "inner_kits": [ - { - "header": { - "header_base": "//foundation/napitest", - "header_files": [ - "tool_utility.h", - "napitest.h", - "napitest_middle.h" - ] - }, - "name": "//foundation/napitest:napitest" - } - ] - } - } -} -``` - -#### 修改napitest.cpp文件 - -为方便调试,在napitest.cpp文件中增加业务代码。以修改napitest.cpp文件为例,在以下方法中增加业务代码, - -在sayHello方法中增加注册的object回调方法的调用: - -``` -... -// 业务代码调用 onSayHelloStart callback -napitest::napitest_interface::NodeISayHello::listener_.NodeISayHelloListener_onSayHelloStartCallback(info1); -// 业务代码调用 onSayHelloEnd callback -napitest::napitest_interface::NodeISayHello::listener_.NodeISayHelloListener_onSayHelloEndCallback(info2); -... -``` - -在sayHi方法中增加register注册的回调方法的调用: - -``` -... -napitest::napitest_interface::NodeISayHello *ptr = new napitest::napitest_interface::NodeISayHello(); -uint32_t callbackNum = 50; -ptr->CallbackfuncCallback(callbackNum); -delete ptr; -... -``` - -在sayHelloWithResponse方法中增加Promise回调方法的调用: - -``` -... -out.errMsg = ""; -out.response = "rec hello."; -out.result = 0; -... -``` - -在funcTest方法中增加普通函数的业务逻辑: - -``` -... -if (v) { - out = "ret is true"; -} else { - out = "ret is false"; -} -... -``` - -增加业务代码之后的文件如下所示: - -[napitest.cpp](https://gitee.com/openharmony/napi_generator/blob/master/examples/napitest.cpp) - -#### 增加子系统 - -在源码/build/subsystem_config.json中增加子系统选项。如下所示: - -``` -"napitest": { - "path": "foundation/napitest", - "name": "napitest" - } -``` - -### 添加功能模块 - -在产品配置中添加上述子系统的功能模块,编译到产品产出文件中,例如在源码vendor/hihope/rk3568/config.json中增加part选项,其中第一个napitest就是BUILD.gn文件中的subsystem_name,第二个napitest就是BUILD.gn文件中的part_name。 - -``` -{ - "subsystem": "napitest", - "components": [ - { - "component": "napitest", - "features": [] - } - ] -} -``` - -### 编译验证 - -编译成功后,就会在 /out/产品名/packages/phone/system/lib/module/ 生成libnapitest.z.so,如下所示: - - /out/rk3568/packages/phone/system/lib/module - diff --git a/docs/guide/ENSEMBLE_METHOD_ZH.md b/docs/guide/ENSEMBLE_METHOD_ZH.md deleted file mode 100644 index 11fe3110985d7dfe6d420afa416c85b65fdef03f..0000000000000000000000000000000000000000 --- a/docs/guide/ENSEMBLE_METHOD_ZH.md +++ /dev/null @@ -1,310 +0,0 @@ -# NAPI框架生成代码集成到OpenHarmony的方法 - -## 场景说明 - -为了实现工具生成的接口被其他子系统或者应用调用,需将生成的代码编译集成到OpenHarmony系统中,使其生成动态库,供OpenHarmony应用层调用。 -本文介绍如何将工具生成的源码利用OpenHarmony编译系统生成动态库供应用层调用,主要是有以下两种方式,分别为增加ohos.build文件方式和增加bundle.json文件方式。 - -## 4.0 版本 - -### 建立模块位置 - -模块目录理论上可在OpenHarmony工程的任一位置,假设OpenHarmony代码库的目录为OHOS_SRC,在OHOS_SRC/foundation目录下,建测试模块目录:napitest。napitest目录结构如下: - - napitest - |-- generatorCode // 工具代码部分 - |-- |-- binding.gyp - |-- |-- BUILD.gn - |-- |-- bundle.json - |-- |-- napitest.cpp - |-- |-- napitest.h - |-- |-- napitest_middle.h - |-- |-- napitest_middle.cpp - |-- |-- test.sh - |-- |-- tool_utility.cpp - |-- |-- tool_utility.h - |-- |-- napi_gen.log - |-- serviceCode // 放置业务代码部分 - |-- |-- NodeISayHello.h - |-- |-- NodeISayHello.cpp - -其中generatorCode为工具生成的代码,serviceCode 为用户配置的业务代码, bundle.json 为新增的编译配置文件。 - -### 编译修改点 - -#### 修改bundle.json文件 - -其中destPath选项中的"//foundation/napitest/generatorCode"指的是napitest目录,":napitest"指的是上面BUILD.gn中的目标ohos_shared_library("napitest")。 - -``` -{ - "name": "@ohos/napitest", - "description": "napitest provides atomic capabilities", - "version": "4.0", - "license": "Apache License 2.0", - "publishAs": "code-segment", - "segment": { - "destPath": "foundation/napitest/generatorCode" - }, - "dirs": {}, - "scripts": {}, - "component": { - "name": "napitest", - "subsystem": "napitest", - "features": [], - "adapted_system_type": [ - "standard" - ], - "rom": "10000KB", - "ram": "10000KB", - "deps": { - "components": [ - "ace_napi", - "ipc_core", - "libhilog" - ], - "third_party": [ - "node" - ] - }, - "build": { - "sub_component": [ - "//foundation/napitest/generatorCode:napitest" - ], - "inner_kits": [ - { - "header": { - "header_base": "//foundation/napitest/generatorCode", - "header_files": [ - "tool_utility.h", - "napitest.h", - "napitest_middle.h" - ] - }, - "name": "//foundation/napitest/generatorCode:napitest" - } - ] - } - } -} -``` - -#### 增加子系统 - -在源码/build/subsystem_config.json中增加子系统选项。如下所示: - -``` -"napitest": { - "path": "foundation/napitest/generatorCode", - "name": "napitest" - } -``` - -### 添加功能模块 - -在产品配置中添加上述子系统的功能模块,编译到产品产出文件中,例如在源码vendor/hihope/rk3568/config.json中增加part选项,其中第一个napitest就是BUILD.gn文件中的subsystem_name,第二个napitest就是BUILD.gn文件中的part_name。 - -``` -{ - "subsystem": "napitest", - "components": [ - { - "component": "napitest", - "features": [] - } - ] -} -``` - -### 编译验证 - -编译成功后,就会在 /out/产品名/packages/phone/system/lib/module/ 生成libnapitest.z.so,如下所示: - - /out/rk3568/packages/phone/system/lib/module - -### 备注 - -若自动配置业务代码不能满足业务场景,用户可以手动配置业务代码,以下为用户手动配置业务代码并集成到OpenHarmony上的方法: - -[4.0版本手动配置业务代码集成方法](https://gitee.com/openharmony/napi_generator/blob/master/docs/guide/ENSEMBLE_METHOD_4.0CFGCODE.md) - -## 3.2 版本 - -### 建立模块位置 - -模块目录理论上可在OpenHarmony工程的任一位置,假设OpenHarmony代码库的目录为OHOS_SRC,在OHOS_SRC/foundation目录下,建测试模块目录:napitest。napitest目录结构如下: - - napitest - |-- binding.gyp - |-- BUILD.gn - |-- bundle.json - |-- napitest.cpp - |-- napitest.h - |-- napitest_middle.h - |-- napitest_middle.cpp - |-- test.sh - |-- tool_utility.cpp - |-- tool_utility.h - -其中bundle.json为新建的编译配置文件,其它为工具生成的代码。 - -### 编译修改点 - -#### 修改bundle.json文件 - -其中destPath选项中的"//foundation/napitest"指的是napitest目录,":napitest"指的是上面BUILD.gn中的目标ohos_shared_library("napitest")。 - -``` -{ - "name": "@ohos/napitest", - "description": "napitest provides atomic capabilities", - "version": "3.2", - "license": "Apache License 2.0", - "publishAs": "code-segment", - "segment": { - "destPath": "foundation/napitest" - }, - "dirs": {}, - "scripts": {}, - "component": { - "name": "napitest", - "subsystem": "napitest", - "features": [], - "adapted_system_type": [ - "standard" - ], - "rom": "10000KB", - "ram": "10000KB", - "deps": { - "components": [ - "ace_napi", - "ipc_core", - "libhilog" - ], - "third_party": [ - "node" - ] - }, - "build": { - "sub_component": [ - "//foundation/napitest:napitest" - ], - "inner_kits": [ - { - "header": { - "header_base": "//foundation/napitest", - "header_files": [ - "tool_utility.h", - "napitest.h", - "napitest_middle.h" - ] - }, - "name": "//foundation/napitest:napitest" - } - ] - } - } -} -``` - -#### 修改napitest.cpp文件 - -为方便调试,在napitest.cpp文件中增加业务代码。以修改napitest.cpp文件为例,在以下方法中增加业务代码, - -在sayHello方法中增加注册的object回调方法的调用: - -``` -... -// 业务代码调用 onSayHelloStart callback -napitest::napitest_interface::NodeISayHello::listener_.NodeISayHelloListener_onSayHelloStartCallback(info1); -// 业务代码调用 onSayHelloEnd callback -napitest::napitest_interface::NodeISayHello::listener_.NodeISayHelloListener_onSayHelloEndCallback(info2); -... -``` - -在sayHi方法中增加register注册的回调方法的调用: - -``` -... -napitest::napitest_interface::NodeISayHello *ptr = new napitest::napitest_interface::NodeISayHello(); -uint32_t callbackNum = 50; -ptr->CallbackfuncCallback(callbackNum); -delete ptr; -... -``` - -在sayHelloWithResponse方法中增加Promise回调方法的调用: - -``` -... -out.errMsg = ""; -out.response = "rec hello."; -out.result = 0; -... -``` - -在funcTest方法中增加普通函数的业务逻辑: - -``` -... -if (v) { - out = "ret is true"; -} else { - out = "ret is false"; -} -... -``` - -增加业务代码之后的文件如下所示: - -[napitest.cpp](https://gitee.com/openharmony/napi_generator/blob/master/examples/napitest.cpp) - -#### 增加子系统 - -在源码/build/subsystem_config.json中增加子系统选项。如下所示: - -``` -"napitest": { - "path": "foundation/napitest", - "name": "napitest" - } -``` - -### 添加功能模块 - -在产品配置中添加上述子系统的功能模块,编译到产品产出文件中,例如在源码vendor/hihope/rk3568/config.json中增加part选项,其中第一个napitest就是BUILD.gn文件中的subsystem_name,第二个napitest就是BUILD.gn文件中的part_name。 - -``` -{ - "subsystem": "napitest", - "components": [ - { - "component": "napitest", - "features": [] - } - ] -} -``` - -### 编译验证 - -编译成功后,就会在 /out/产品名/packages/phone/system/lib/module/ 生成libnapitest.z.so,如下所示: - - /out/rk3568/packages/phone/system/lib/module - -## 3.1 版本 - -[3.1版本集成方法](https://gitee.com/openharmony/napi_generator/blob/master/docs/guide/ENSEMBLE_METHOD_3.1VERSION.md) - -## 总结 - -3.1版本两种集成方式使用场景说明: - -ohos.build方式集成:适合3.0前版本使用。 - -bundle.json方式集成:兼容ohos.build方式,但3.1及以后版本建议使用此种方式集成。 - -3.2版本适合使用bundle.json方式集成。 - -4.0版本适合使用bundle.json方式集成。 - diff --git a/docs/guide/INSTRUCTION_ZH.md b/docs/guide/INSTRUCTION_ZH.md deleted file mode 100644 index f89b9ef9007b60c05e7800c67bb8075e02eadf0e..0000000000000000000000000000000000000000 --- a/docs/guide/INSTRUCTION_ZH.md +++ /dev/null @@ -1,285 +0,0 @@ -# NAPI框架生成工具使用说明 -## 简介 - -NAPI框架生成工具支持三种入口,分别是可执行程序、VS Code插件、DevEco Studio上使用的IntelliJ插件,使用者可以根据自己的需要选择合适的工具。 - -1.可执行文件下载路径如下(由于网络原因,可能会导致有的下载链接失效,因此提供了以下三个下载链接): - -[可执行文件下载链接1](http://ftpkaihongdigi.i234.me:5000/sharing/yaRiKSjBI) - -[可执行文件下载链接2](http://ftp.kaihong.com:5000/fsdownload/yaRiKSjBI/) - -[可执行文件下载链接3](http://ftp.kaihongdigi.com:5000/fsdownload/yaRiKSjBI/) - -访问密码:kaihong - -压缩包解压密码:kaihong20231121 - -DevEco Studio上使用的IntelliJ插件下载路径如下: - -[DevEco Studio上使用的IntelliJ插件下载链接](https://plugins.jetbrains.com/plugin/19593-napi-generator/versions) - -## 工具介绍 - -通过NAPI框架生成工具,使用者可输入一个接口定义的ts文件,一键生成NAPI框架代码、业务代码框架、GN脚本等文件,并使用生成的NAPI接口及功能。使用者也可以输入一个定义方法的.h头文件,反向生成ts文件。 - -![](../../figures/pic-frm.png) - -## 预检查 - -napi_generator的可执行程序方式和插件方式都具有预检查的功能,如果.d.ts文件中存在语法错误,那么执行的时候命令行会打印出错误信息,指出代码中存在错误的行号。使用效果如下: - - joey@joey-virtual-machine:~/code/napi_test$ ./napi_generator-linux -f @ohos.napitest.d.ts - @ohos.napitest.d.ts (33,12): Identifier expected. - @ohos.napitest.d.ts (33,13): ';' expected. - @ohos.napitest.d.ts (33,13): An identifier or keyword cannot immediately follow a numeric literal. - @ohos.napitest.d.ts (33,13): Cannot find name 'shutdownDevice'. - @ohos.napitest.d.ts (33,28): Cannot find name 'reason'. - @ohos.napitest.d.ts (33,34): ',' expected. - @ohos.napitest.d.ts (33,36): 'string' only refers to a type, but is being used as a value here. - @ohos.napitest.d.ts (33,43): ';' expected. - @ohos.napitest.d.ts (33,49): Expression expected. - - joey@joey-virtual-machine:~/code/napi_test$ - -@ohos.napitest.d.ts (33,49),其中括号中第一个参数含义为行号,第二个参数含义为列号。 - -预检查的触发方式与生成框架的入口一致,使用方法参见生成框架描述。 - -## 生成框架 - -### 自动配置业务代码用例 - -1.ts文件用例 - - [@ohos.napitest.d.ts](https://gitee.com/openharmony/napi_generator/blob/master/examples/ts/@ohos.napitest.d.ts) - -注册关键字说明 - -(1) registerXXX/unRegisterXXX - -register与unRegister成对使用, registerXXX用于注册回调,其参数即为注册的回调函数,注册之后在其它普通方法中即可在C++层调用registerXXX注册的回调函数;unRegisterXXX用于注销回调,其参数即为需要注销的回调函数,注销之后将无法再在C++层调用注销的回调函数。如: - -``` -export class NodeISayHello -{ - ... - // register注册回调 - registerCallbackfunc(cb : (wid: number) => string); - // unRegister注销回调 - unRegisterCallbackfunc(cb : (wid: number) => string); - ... -} -``` - -其中注册/注销的回调方法为箭头函数 (wid: number) => string。注册回调之后,工具会生成回调方法CallbackfuncCallback,业务代码中用户自行定义回调时机进而通过回调接口调用回调,若回调被注销,则业务代码无法触发该回调。 - -(2) addXXX/removeXXX onXXX - -addXXX与removeXXX成对使用,addXXX用于注册回调,其参数为class对象, 将需要注册的回调函数放于class中,其写法为onXXX,class中可以有多个onXXX回调函数;removeXXX用于注销回调,其参数为class对象,用于注销addXXX注册的回调。如: - -``` -export class NodeISayHello -{ - ... - // 注册object回调 - addSayHelloListener(listener: NodeISayHelloListener); - // 注销object回调 - removeSayHelloListener(listener: NodeISayHelloListener); - ... -} -... -export class NodeISayHelloListener -{ // 定义回调 - onSayHelloStart(info: SayInfo); - onSayHelloEnd(info: SayInfo); -} -``` - -其中注册/注销的回调方法为onSayHelloStart(info: SayInfo); onSayHelloEnd(info: SayInfo); 注册回调之后,工具会生成两个回调接口供用户调用,业务代码中用户自行定义回调时机进而通过回调接口调用回调,若回调被注销,则业务代码无法触发回调。 - -2.自动配置业务代码用例使用的cfg.json - - [配置文件cfg.json用例](https://gitee.com/openharmony/napi_generator/blob/master/examples/cfg.json) - -3.自动配置业务代码使用的业务代码用例 - -业务代码用例如下: - -serviceCode/NodeISayHello.h - -[NodeISayHello.h](https://gitee.com/openharmony/napi_generator/blob/master/examples/serviceCode/NodeISayHello.h) - -serviceCode/NodeISayHello.cpp - -[NodeISayHello.cpp](https://gitee.com/openharmony/napi_generator/blob/master/examples/serviceCode/NodeISayHello.cpp) - -### 可执行程序使用方法 - -#### Linux - -1.将待转换的.d.ts文件、napi_generator-linux、依赖文件basic.d.ts、 配置文件cfg.json、业务代码文件夹serviceCode(其中serviceCode目录下放置业务代码的.h文件和.cpp文件)放在同级目录下。此处新建generatorCode文件夹,用于存放生成框架代码。整体目录文件如下: - - OpenHarmony@Ubuntu-64:~/service$ ls - napi_generator-linux @ohos.napitest.d.ts basic.d.ts generatorCode cfg.json serviceCode - -2.在终端中进入到之前可执行程序napi_generator-linux所在的目录,并运行napi_generator-linux,命令如下: - - OpenHarmony@Ubuntu-64:~/service$ ./napi_generator-linux -f @ohos.napitest.d.ts -o generatorCode -i false -n int -s cfg.json - -其中,参数详情如下: - - -f, 待转换的.d.ts文件,若同时转换多个文件,文件之间用“,”隔开; - - -d, 根据指定路径转换该文件夹中所有.d.ts文件; - - -i, 可选参数,默认false,待转换.d.ts文件中引用非basic.d.ts的ts文件时打开开关; - - -o, 可选参数,默认为当前目录,指定生成框架代码输出路径; - - -n, 可选参数,默认为uint32_t,指定生成框架代码中number类型全部为指定类型; - - -s, 可选参数,默认为不配置业务代码,指定生成框架代码的业务配置文件,用于粘合工具代码和业务代码的配置。 - - 备注1:-f与-d两个参数只选其中一个参数即可。 - - 备注2:若.d.ts文件中声明了basic.d.ts文件,将basic.d.ts文件放置在待转换.d.ts文件同一级目录;若除此之外还声明其它.d.ts文件,将此类文件放置在待转换.d.ts文件同级目录。 - -其中,cfg.json内容如下: - -``` -[ - { - "genPath": "/home/kaihong1/napi/myCommitNapiTest/generatorCode", - "includeName": "../serviceCode/NodeISayHello.h", - "cppName": "../serviceCode/NodeISayHello.cpp", - "interfaceName": "funcTest", - "serviceCode": "out = napitest::funcTest(v);" - "description": "includeName: 引入的业务代码.h文件相对路径, cppName: 引入的业务代码.cpp文件相对路径, interfaceName: ts文件中的使用接口名,业务代码就在该接口中调用;格式为:类名::方法名(如: TestClass::funcTest1),若无类名,则格式为:方法名(如: funcTest), serviceCode: 在接口中调用业务代码的调用语句。(该属性只做注释使用)" - } -] -``` - -cfg.json是一个数组,每一项配置对应一个方法的调用,需要对多少方法进行调用就配置多少项;其中 - -"genPath": 生成框架代码路径,用户的业务代码相对于该路径配置,如:"/home/kaihong1/napi/myCommitNapiTest/generatorCode" - -"includeName": 引入的业务代码.h文件相对路径, 如:"../serviceCode/NodeISayHello.h", - -"cppName": 引入的业务代码.cpp文件相对路径, 如:"../serviceCode/NodeISayHello.cpp", - -"interfaceName": ts文件中的使用接口名,业务代码就在该接口中调用;格式为:类名::方法名(如: TestClass::funcTest1),若无类名,则格式为:方法名(如: funcTest), - -"serviceCode": 在接口中调用业务代码的调用语句。此处调用的是实现该接口的业务代码, 如:"out = napitest::funcTest(v);", - -"description": 仅作为cfg.json文件中描述其它字段含义的属性,用户配置时,可以不用填写这个字段 - -3.运行成功后会在generatorCode目录下生成框架代码文件,如下所示: - - OpenHarmony@Ubuntu-64:~/linshi/napi_generator_8/examples/ts/generatorCode$ ls - binding.gyp BUILD.gn napi_gen.log napitest.cpp napitest.h napitest_middle.h napitest_middle.cpp test.sh tool_utility.cpp tool_utility.h - -#### Windows - -1.将待转换的.d.ts文件、napi_generator-win.exe、 配置文件cfg.json、依赖文件basic.d.ts、业务代码文件夹serviceCode(其中serviceCode目录下放置业务代码的.h文件和.cpp文件)放在同级目录下。此处新建generatorCode文件夹,用于存放生成框架代码。整体目录文件如下: - - E:\demo\napi>dir /B - @ohos.napitest.d.ts - basic.d.ts - napi_generator-win.exe - generatorCode - cfg.json - serviceCode - -2.在终端中进入到之前可执行程序napi_generator-win.exe所在的目录,并运行napi_generator-win.exe,命令如下: - - E:\demo\napi>napi_generator-win.exe -f @ohos.napitest.d.ts -o generatorCode -i false -n double -s cfg.json - -其中,参数详情如下: - - -f, 待转换的.d.ts文件,若同时转换多个文件,文件之间用“,”隔开; - - -d, 根据指定路径转换该文件夹中所有.d.ts文件; - - -i, 可选参数,默认false,待转换.d.ts文件中引用非basic.d.ts的ts文件时打开开关; - - -o, 可选参数,默认为当前目录,指定生成框架代码输出路径; - - -n, 可选参数,默认为uint32_t,指定生成框架代码中number类型全部为指定类型; - - -s, 可选参数,默认为不配置业务代码,指定生成框架代码的业务配置文件,用于粘合工具代码和业务代码的配置。 - - 备注1:-f与-d两个参数只选其中一个参数即可。 - - 备注2:若.d.ts文件中声明了basic.d.ts文件,将basic.d.ts文件放置在待转换.d.ts文件同一级目录;若除此之外还声明其它.d.ts文件,将此类文件放置在待转换.d.ts文件同级目录。 - -其中,cfg.json内容如下: - -``` -[ - { - "genPath": "E:\\napi_aboutTest\\testcase_napi_intellijPlugin\\generatorCode", - "includeName": "../serviceCode/NodeISayHello.h", - "cppName": "../serviceCode/NodeISayHello.cpp", - "interfaceName": "funcTest", - "serviceCode": "out = napitest::funcTest(v);" - "description": "includeName: 引入的业务代码.h文件相对路径, cppName: 引入的业务代码.cpp文件相对路径, interfaceName: ts文件中的使用接口名,业务代码就在该接口中调用;格式为:类名::方法名(如: TestClass::funcTest1),若无类名,则格式为:方法名(如: funcTest), serviceCode: 在接口中调用业务代码的调用语句。(该属性只做注释使用)" - } -] -``` - -cfg.json是一个数组,每一项配置对应一个方法的调用,需要对多少方法进行调用就配置多少项;其中 - -"genPath": 生成框架代码路径,用户的业务代码相对于该路径配置,如:"E:\\napi_aboutTest\\testcase_napi_intellijPlugin\\generatorCode" - -"includeName": 引入的业务代码.h文件相对路径, 如:"../serviceCode/NodeISayHello.h", - -"cppName": 引入的业务代码.cpp文件相对路径, 如:"../serviceCode/NodeISayHello.cpp", - -"interfaceName": ts文件中的使用接口名,业务代码就在该接口中调用;格式为:类名::方法名(如: TestClass::funcTest1),若无类名,则格式为:方法名(如: funcTest), - -"serviceCode": 在接口中调用业务代码的调用语句。此处调用的是实现该接口的业务代码, 如:"out = napitest::funcTest(v);", - -"description": 仅作为cfg.json文件中描述其它字段含义的属性,用户配置时,可以不用填写这个字段 - -3.运行成功后会在generatorCode目录下生成框架代码文件,如下所示: - - E:\demo\napi\generatorCode>dir /B - binding.gyp - BUILD.gn - napitest.cpp - napitest.h - napitest_middle.h - napitest_middle.cpp - napi_gen.log - test.sh - tool_utility.cpp - tool_utility.h - -#### Mac - -方法步骤参考windows、Linux的使用方法。 - -### 不配置cfg.json文件生成框架代码 - -若用户想手动配置业务代码,可不配置cfg.json文件生成框架代码之后手动增加业务代码,不配置cfg.json文件生成框架代码说明如下: - -[不配置cfg.json生成框架代码说明](https://gitee.com/openharmony/napi_generator/blob/master/docs/guide/ADD_SERVICECODE_INSTRUCTION.md) - -### VS Code插件使用方法 - -具体的插件使用步骤,可以左键单击以下链接了解: - -[VS插件使用说明](https://gitee.com/openharmony/napi_generator/blob/master/napi_vs_plugin/docs/napi/INSTRUCTION_ZH.md) - -### DevEco Studio上使用的IntelliJ插件使用方法 - -具体的插件使用步骤,可以左键单击以下链接了解: - -[DevEco Studio上使用的IntelliJ插件使用说明](https://gitee.com/openharmony/napi_generator/blob/master/napi_IntelliJ_plugin/docs/napi/INSTRUCTION_ZH.md) - -## 集成测试 -NAPI框架代码生成后,系统框架开发者进行二次开发后,即可集成到OpenHarmony编译系统,生成对应的库文件,供应用开发者调用接口。工具集成测试的具体操作步骤可以左键单击以下链接了解: - - [工具集成测试](https://gitee.com/openharmony/napi_generator/blob/master/docs/guide/INTEGRATION_TESTING_ZH.md) - diff --git a/docs/guide/INTEGRATION_TESTING_ZH.md b/docs/guide/INTEGRATION_TESTING_ZH.md deleted file mode 100644 index 30ceca01b4902158522d9c81f2c669079792dbd6..0000000000000000000000000000000000000000 --- a/docs/guide/INTEGRATION_TESTING_ZH.md +++ /dev/null @@ -1,274 +0,0 @@ -# NAPI框架生成工具集成测试 - -## 简介 - 本文主要介绍如何将NAPI框架生成代码集成到OpenHarmony系统,进而进行集成测试。 - -## 准备 - - 1.硬件:rk3568开发套件。 - - 2.系统镜像: - - 系统镜像的具体生成方法,可以左键单击以下链接了解: - - [生成代码集成到OpenHarmony](https://gitee.com/openharmony/napi_generator/blob/master/docs/guide/ENSEMBLE_METHOD_ZH.md) - - 3.应用hap包:hap包及源码路径如下: - -``` -napi_generator/examples/app -``` - - hap包的具体生成方法,可参考OpenHarmony/docs/zh-cn/application-dev文档中使用ArkTS语言开发(Stage模型)。 -### 修改点1:扩展SDK接口 -1. 查看SDK目录:打开DevEco Studio ,点击 Tools -> SDK Manager -> SDK - - ![](../../figures/DevEco_SDK_path.png) - -2. 将@ohos.napitest.d.ts文件拷贝到应用所使用的sdk目录下 的ets\api - - ![](../../figures/DevEco_add_interface.png) - -### 修改点2:增加新接口调用 -其中修改index.ets文件内容如下: - -[Index.ets](https://gitee.com/openharmony/napi_generator/blob/master/examples/Index.ets) - -关键代码说明: - -1.定义回调: - -1.1 定义object回调 - -``` -class NodeISayHelloListenerImpl { - onSayHelloStart(info: object) { - console.log('napiTestDemo ----onSayHelloStart', info); - AppStorage.SetOrCreate("textInfoStart", JSON.stringify(info)) - } - onSayHelloEnd(info: object) { - console.log('napiTestDemo ----onSayHelloEnd.', info); - AppStorage.SetOrCreate("textInfoEnd", JSON.stringify(info)) - } -} -let listener: NodeISayHelloListenerImpl = new NodeISayHelloListenerImpl() -``` - -1.2 定义register注册的回调 - -``` -function onCallbackfunnm(wid: number) { - AppStorage.SetOrCreate("callBackNum", JSON.stringify(wid)) - console.info("wid = " + wid) - return "ocCallbackfuncnm"; -} -``` - -2.注册回调: - -2.1 addXXX注册object回调 - -``` -ns.addSayHelloListener(listener); -``` - -2.2 registerXXX注册回调 - -``` -ns.registerCallbackfunc(onCallbackfunnm); -``` - -3.调用回调: - -3.1 调用sayHello普通函数,该函数业务实现会调用注册的object回调 - -``` -ns.sayHello("js1", "native1", napitest.SayType.kInitiative); -``` - -调用成功后,打印传入的参数 - -``` -I C02e00/NAPITESTNAPILayer: [NodeISayHello.cpp:37] NAPITEST_LOGI sayHello from = js1 -I C02e00/NAPITESTNAPILayer: [NodeISayHello.cpp:38] NAPITEST_LOGI sayHello to = native1 -I C02e00/NAPITESTNAPILayer: [NodeISayHello.cpp:39] NAPITEST_LOGI sayHello sayType = 0 -``` - -js层打印回调数据 - -``` -A03d00/JSAPP: napiTestDemo ----onSayHelloStart {"from":"js1","fromId":992,"to":"native1","toId":1014,"content":"hello1","saidTime":"123456789","isEnd":false} -... -A03d00/JSAPP: napiTestDemo ----onSayHelloEnd. {"from":"native","fromId":101,"to":"js","toId":99,"content":"hello","saidTime":"987654321","isEnd":true} -``` - -3.2 调用sayHi普通函数,该函数业务实现会调用register注册的object回调 - -``` -ns.sayHi("js3", "native3", napitest.SayType.kResponse); -``` - -调用成功后,打印传入的参数 - -``` -I C02e00/NAPITESTNAPILayer: sayHi:81 NAPITEST_LOGI sayHi from = js3 -I C02e00/NAPITESTNAPILayer: sayHi:82 NAPITEST_LOGI sayHi to = native3 -I C02e00/NAPITESTNAPILayer: sayHi:83 NAPITEST_LOGI sayHi sayType = 1 -``` - -js层打印回到数据 - -``` -I A03d00/JSAPP: napiTestDemo ----onCallbackfunnm wid = 50 -``` - -4.注销回调: - -4.1 removeXXX注销object回调 - -``` -ns.removeSayHelloListener(listener); -``` - -注销回调后再次调用sayHello方法,js层将无法再打印出回调数据 - -``` -ns.sayHello("js2", "native2", napitest.SayType.kInitiative); -``` - -4.2 unRegisterXXX注销回调 - -``` -ns.unRegisterCallbackfunc(onCallbackfunnm); -``` - -注销回调后再次调用sayHi方法,js层将无法再打印出回调数据 - -``` -ns.sayHi("js4", "native4", napitest.SayType.kResponse); -``` - -5.调用Promise回调 - -``` - await ns.sayHelloWithResponse("response from", "response to", napitest.SayType.kResponse).then((ret: object) => { - this.promiseRes = JSON.stringify(ret); - console.info("napiTestDemo ----sayHelloWithResponse ret = " + JSON.stringify(ret)); - }); -``` - -调用成功后,打印传入的参数 - -``` -I C02e00/NAPITESTNAPILayer: sayHelloWithResponse:107 NAPITEST_LOGI sayHelloWithResponse from = response from -I C02e00/NAPITESTNAPILayer: sayHelloWithResponse:108 NAPITEST_LOGI sayHelloWithResponse to = response to -I C02e00/NAPITESTNAPILayer: sayHelloWithResponse:109 NAPITEST_LOGI sayHelloWithResponse sayType = 1 -``` - -js层打印promise回调数据 - -``` -I A03d00/JSAPP: napiTestDemo ----sayHelloWithResponse ret = {"result":0,"errMsg":"","response":""} -``` - -6.调用普通方法funcTest - -``` -this.returnVal = napitest.funcTest(false); -console.info("napiTestDemo ----funcTest returnVal = " + this.returnVal) -``` - -调用成功后,在js层打印返回值 - -``` -I A03d00/JSAPP: napiTestDemo ----funcTest returnVal = "ret is false" -``` - -7.Text打印数据说明 - - -``` -// 调用sayHelloWithResponse后保存promise回调数据 -Text('promise回调: promiseResult = ' + this.promiseRes).margin({ top: 10 }) -// 调用sayHello方法后保留addXXX注册的回调方法数据 -Text('sayHelloStart回调: info = ' + this.textInfoStart).margin({ top: 10 }) -Text('sayHelloEnd回调: info = ' + this.textInfoEnd).margin({ top: 10 }) -// 调用sayHi方法后保留registerXXX注册的回调方法数据 -Text('register注册的回调: wid = ' + this.callBackNum).margin({ top: 10 }) -// 调用fucnTest方法后保存返回值 -Text('普通方法funcTest返回值: returnVal = ' + this.returnVal).margin({ top: 10 }) -``` - -## 使用说明 - -步骤一:安装镜像环境:将out/rk3568/packages/phone目录下的images镜像文件下载并烧录到开发板上。 - - OpenHarmony@Ubuntu-64:~/OpenHarmony/out/rk3568/packages/phone/images$ ll - total 767452 - drwxrwxrwx 2 root root 4096 Nov 21 05:32 ./ - drwxrwxrwx 15 root root 4096 Nov 21 05:32 ../ - -rwxrwxrwx 1 root root 67108864 Nov 21 05:04 boot_linux.img* - -rw-r--r-- 1 root root 52428800 Nov 21 05:32 chip_prod.img - -rwxrwxrwx 1 root root 8569 Nov 21 05:04 config.cfg* - -rw-r--r-- 1 root root 12582912 Nov 21 05:32 eng_system.img - -rwxrwxrwx 1 root root 455104 Nov 21 05:04 MiniLoaderAll.bin* - -rwxrwxrwx 1 root root 756 Nov 21 05:04 parameter.txt* - -rw-rw-r-- 1 root root 2507625 Nov 21 05:32 ramdisk.img - -rwxrwxrwx 1 root root 5639680 Nov 21 05:04 resource.img* - -rw-r--r-- 1 root root 52428800 Nov 21 05:32 sys_prod.img - -rw-r--r-- 1 root root 1610608640 Nov 21 05:32 system.img - -rwxrwxrwx 1 root root 4194304 Nov 21 05:04 uboot.img* - -rw-rw-r-- 1 root root 15806303 Nov 21 05:32 updater.img - -rw-r--r-- 1 root root 1468006400 Nov 21 05:32 userdata.img - -rw-r--r-- 1 root root 268431360 Nov 21 05:32 vendor.img - -步骤二:安装hap包。 - - Build Haps通过后,通过Run按钮将hap包安装到板子上。 - - 执行完成后,设备中会出现安装的APP。 - -步骤三:打印日志并验证结果。 - - hap包安装成功后,进入hdc shell - - 首先执行以下命令关闭hilog隐私权限 - -``` -hilog -p off -``` - - 输入命令实时打印日志并输出至windows中。 - - .\hdc.exe hilog > log.txt - - 然后单击设备中安装的APP,进入APP后单击测试按钮,执行完成后会在hdc安装目录下出现log.txt文件。 - -## 查看结果 - - log.txt中包含"NAPITEST_LOGI..."相关日志即为接口调用成功,如: - -``` -I C02e00/NAPITESTNAPILayer: [NodeISayHello.cpp:37] NAPITEST_LOGI sayHello from = js1 -I C02e00/NAPITESTNAPILayer: [NodeISayHello.cpp:38] NAPITEST_LOGI sayHello to = native1 -I C02e00/NAPITESTNAPILayer: [NodeISayHello.cpp:39] NAPITEST_LOGI sayHello sayType = 0 -I C02e00/NAPITESTNAPILayer: [NodeISayHello.cpp:64] NAPITEST_LOGI NodeISayHelloListener_onSayHelloStartCallback begin -I C02e00/NAPITESTNAPILayer: [NodeISayHello.cpp:66] NAPITEST_LOGI NodeISayHelloListener_onSayHelloStartCallback end -... -``` - -点击“注册object回调后SayHello调用回调”按钮,sayHelloStart回调info和sayHelloEnd回调info会显示出C++传到js层的回调数据; - -点击“注销object回调后SayHello调用回调”按钮,sayHelloStart回调info和sayHelloEnd回调info会显示出数据为空,即该回调已注销,C++无法调用回调,显示的为应用赋的空值; - -点击“Promise 回调”按钮,Promise回调的errMsg, result, response会出现C++传到js层的回调数据; - -点击“register回调后SayHi调用回调”按钮,register注册的回调会显示出wid = 50, wid值为C++传到js的回调数据; - -点击“unRegister回调后SayHi调用回调”按钮,register注册的回调会显示出wid 为空,即该回调已注销,C++无法调用回调,显示的为应用赋的空值; - -点击”调用funcTest方法“按钮,普通方法funcTest返回值显示出 returnVal = ret is false。 - -## 相关仓 - -暂无 diff --git a/docs/guide/ROADMAP_ZH.md b/docs/guide/ROADMAP_ZH.md deleted file mode 100644 index ad7fcddc6e4950cd349fd26e275e9bc0a9643993..0000000000000000000000000000000000000000 --- a/docs/guide/ROADMAP_ZH.md +++ /dev/null @@ -1,44 +0,0 @@ -# NAPI框架代码生成工具 - -## 版本规划 - -2024.03.30提供1.4.1版本 基本完善工具C++支持能力,具体特性见表1。 - -**表 1** 2024.03.30待支持特性 - - - - - - - - - - - - - - - - - - - - - -

类别

-

待开发特性

-

变量/返回值

-
  • 支持ts接口文件中namespace域的any类型之复合类型变量转换为对应C++类型变量
  • 支持ts接口文件中namespace域的多中类型合并成新类型之复合类型的变量转换为对应C++类型变量
-

函数

-
  • 支持箭头函数的参数是回调函数
  • 支持on/off第二个参数为object
  • 支持class中有参构造中有枚举类型
  • 箭头回调支持异步调用
  • on注册回调的箭头函数支持携带js返回值给C++
  • 支持js业务代码回调接口中的回调js函数
  • class2声明在class1之后时,支持class1中的有参构造的参数有class2
-

文件

-
  • 优化VSCode插件用户界面
  • 分离生成的工具代码普通方法和回调方法,防止嵌套使用头文件
-

可维护性

-
  • 增加debug信息
-
- - -## 相关链接 - -无 diff --git a/docs/guide/SOLUTION.md b/docs/guide/SOLUTION.md deleted file mode 100644 index 094bad65c9a978fc9c1e6af859cc02dcb735d3f8..0000000000000000000000000000000000000000 --- a/docs/guide/SOLUTION.md +++ /dev/null @@ -1,72 +0,0 @@ -# 当前已知不支持推荐方案 - -1.注册的object回调不支持箭头函数写法, 注册回调格式为addXXX,注销回调格式为removeXXX,且回调方法命名格式为onXXX, 例如: - -``` -export interface InterfaceB { - byClass: (listener: InterfaceA) => void; -} -export interface InterfaceA { - callFunction: (res: number) => void; -} -``` - -修改为: - -``` -export interface InterfaceB { - // object注册回调, 关键字:add - addByClass(listener: InterfaceA); - // object注销回调, 关键字:remove - removeByClass(listener: InterfaceA); -} -export interface InterfaceA { - onCallFunction(res: number): void; -} -``` - -2.注册回调只能支持单个参数, 且注册单个参数的注册回调方法命名格式为registerXXX, 例如: - -``` -export interface TestA { - bGyClass: (a: number, callback: (result: number) => void) => number; -} -``` - -修改为: - -``` -export interface TestA { - // 原bGyClass的参数 callback: (res: number) => void 改为registerXXX/unRegisterXXX形式 - // register形式注册回调, 关键字:register - registerTestACallback(callback: (dd: number) => void); - // unRegister形式注销回调, 关键字:unRegister - unRegisterTestACallback(callback: (dd: number) => void); - // gByClass用于调用回调 - bGyClass: (a: number) => number; -} -``` - -3.生成报错:The current version does not support generating parameter。 - -``` -genError:at paramGenerate [C:\snapshot\napi_generator\src\gen\generate\param_generate.js(899:17)] The current version does not support generating parameter [elementName] with type [ElementName] -``` - -ts文件为: - -``` -import { ElementName } from './bundleManager/ElementName'; - -declare namespace cardEmulation { - export class HceService { - start(elementName: ElementName, aidList: string[]): void; - stop(elementName: ElementName): void; - } -} -export default cardEmulation; -``` - -修改: - -文件中引用了 ElementName 类型, 需要把被引用的文件( import { ElementName } from './bundleManager/ElementName'; )放到转换路径下工具才可进行转换 \ No newline at end of file diff --git a/docs/guide/ts/DEVELOP_ZH.md b/docs/guide/ts/DEVELOP_ZH.md deleted file mode 100644 index ed7fef53e7aca09236be90d8fabe981f3e8255f8..0000000000000000000000000000000000000000 --- a/docs/guide/ts/DEVELOP_ZH.md +++ /dev/null @@ -1,139 +0,0 @@ -# TS接口文件生成工具开发说明 - -## 工具代码框架介绍 - -ts工具框架由C++语法解释器和代码生成器两部分组成。C++语法解释器解析用户输入的.h文件内容,通过C++语法解析,将文件内容分解为类、方法、入参、成员属性等元素;代码生成器根据从语法解析器得到的这些元素,转换为对应的typescript语法的接口、方法、参数代码,生成.ts文件。 - -## 工具开发 - -### 可执行文件编译说明 - -#### 环境说明 - -系统:建议Ubuntu 20.04或者Windows 10 - -#### 开发步骤 - -##### Linux - -**1.生成napi_generator程序** - -1.1 安装typescript:在napi_generator/src目录下执行命令: - - npm i typescript - -1.2 安装stdio:在napi_generator目录下执行命令: - - npm i stdio - -1.3 安装pkg : 在napi_generator目录下执行命令: - - sudo npm i -g pkg - -1.4 打包三个版本 : 执行命令: - - pkg . - -执行以上步骤后,即可在napi_generator目录下生成Windows、linux、mac系统下的可执行程序: - - napi_generator-win.exe、napi_generator-linux、napi_generator-macos - -1.4.1 (可选步骤) 根据需求打包指定系统下的可执行文件。若想只打包windows系统下可执行文件,可执行命令: - - pkg -t node14-win . -o napi_generator-win.exe - -若想只打包linux系统下可执行文件,可执行命令: - - pkg -t node14-linux . -o napi_generator-linux - -若想只打包macos系统下可执行文件,可执行命令: - - pkg -t node14-macos . -o napi_generator-macos - -备注:参数-t为指定系统,参数-o为指定可执行文件名称。 - -**2 生成header_parser程序** - -2.1 安装python库 CppHeaderParser,在header_parser/src_code中下载CppHeaderParser.zip,解压后替换本地Python文件夹中CppHeaderParser(如 /usr/local/lib/python3.8/dist-packages/CppHeaderParser)目录下的全部文件 - -[下载链接1](http://ftpkaihongdigi.i234.me:5000/sharing/kBG1c7CvT) - -[下载链接2](http://ftp.kaihong.com:5000/sharing/kBG1c7CvT) - -[下载链接3](http://ftp.kaihongdigi.com:5000/sharing/kBG1c7CvT) - -2.2 安装 pyinstaller - - sudo pip install pyinstaller - -2.3 将python脚本打包成独立可执行文件 -进入 napi_generator/src/tsGen 目录后执行如下命令: - - sudo pyinstaller -F header_parser.py - -打包后的可执行文件在dist目录中 -./src/tsGen/dist/header_parser - -##### Windows - -**1.生成napi_generator程序** - -1.1 安装typescript:使用管理员身份在napi_generator/src目录下执行命令: - - npm i typescript - -1.2 安装stdio:使用管理员身份在napi_generator目录下执行命令: - - npm i stdio - -1.3 安装pkg : 使用管理员身份在napi_generator目录下执行命令: - - npm i -g pkg - -1.4 打包三个版本 : 使用管理员身份执行命令: - - pkg . - -执行以上步骤后,即可在napi_generator目录下生成Windows、linux、mac系统下的可执行程序: - - napi_generator-win.exe、napi_generator-linux、napi_generator-macos - -1.4.1(可选步骤)根据需求打包指定系统下的可执行文件。若想只打包windows系统下可执行文件,可执行命令: - - pkg -t node14-win . -o napi_generator-win.exe - -若想只打包linux系统下可执行文件,可执行命令: - - pkg -t node14-linux . -o napi_generator-linux - -若想只打包macos系统下可执行文件,可执行命令: - - pkg -t node14-macos . -o napi_generator-macos - -**2.生成header_parser程序** - -2.1 安装python库 CppHeaderParser,在header_parser/src_code中下载CppHeaderParser.zip,解压后替换本地Python文件夹中CppHeaderParser(如 C:\Python310\Lib\site-packages\CppHeaderParser)目录下的全部文件 - -[下载链接1](http://ftpkaihongdigi.i234.me:5000/sharing/kBG1c7CvT) - -[下载链接2](http://ftp.kaihong.com:5000/sharing/kBG1c7CvT) - -[下载链接3](http://ftp.kaihongdigi.com:5000/sharing/kBG1c7CvT) - -2.2 安装 pyinstaller - - pip install pyinstaller - -2.3 将python脚本打包成独立可执行文件 -进入 napi_generator/src/tsGen 目录后执行如下命令: - - pyinstaller -F header_parser.py - -打包后的可执行文件header_parser.exe在dist目录中 -./src/tsGen/dist/header_parser.exe - -### IntelliJ 插件开发说明 - -具体的插件开发步骤,可以左键单击以下链接了解: - -[IntelliJ插件开发说明](https://gitee.com/openharmony/napi_generator/blob/master/hdc/ts/ts_IntelliJ_plugin/docs/DEVELOP_ZH.md) \ No newline at end of file diff --git a/docs/guide/ts/FAQ.md b/docs/guide/ts/FAQ.md deleted file mode 100644 index b1ddc8115b8cf0e2ed704c4c9927c47083758e54..0000000000000000000000000000000000000000 --- a/docs/guide/ts/FAQ.md +++ /dev/null @@ -1,12 +0,0 @@ -# Ts接口生成工具 问题反馈 - -## 问题反馈 - -1、使用工具转换.h文件时报错,显示header_parser.exe文件有误。 - -![](../../../figures/header_parser_not_exist.png) - -问题定位:使用可执行程序转换.h文件时,当前路径下没有header_parser.exe文件,导致转换失败。 - -问题解决:下载header_parser.exe文件,并放置在napi_generator-win.exe、待转换.h文件相同路径下,即可解解决以上问题。 - diff --git a/docs/guide/ts/INSTRUCTION_ZH.md b/docs/guide/ts/INSTRUCTION_ZH.md deleted file mode 100644 index 759479d84e0ffa1f63c1bb55879a12c555ee6197..0000000000000000000000000000000000000000 --- a/docs/guide/ts/INSTRUCTION_ZH.md +++ /dev/null @@ -1,98 +0,0 @@ -# Ts接口生成工具使用说明 -## 简介 - -Ts接口生成工具支持两种入口,分别是可执行程序、IntelliJ插件,使用者可以根据自己的需要选择合适的工具。可执行文件、IntelliJ插件下载路径如下。 - -[下载链接1](http://ftpkaihongdigi.i234.me:5000/sharing/kBG1c7CvT) - -[下载链接2](http://ftp.kaihong.com:5000/sharing/kBG1c7CvT) - -[下载链接3](http://ftp.kaihongdigi.com:5000/sharing/kBG1c7CvT) - -下载文件说明如下: - - │ │ |── generator.jar # IntelliJ插件 - │ │ |── header_parser - │ │ |── |── linux - │ │ |── |── |── header_parser # Linux下python脚本可执行程序 - │ │ |── |── windows - │ │ |── |── |── header_parser.exe # Windows下python脚本可执行程序 - │ │ |── |── src_code - │ │ |── |── |── CppHeaderParser.zip # CppHeaderParser源码 - │ │ |── |── readme.txt # readme.txt - │ │ |── napi_generator-linux # Linux可执行程序 - │ │ |── napi_generator-win.exe # Windows可执行程序 - │ │ └── napi_generator-macos # Mac可执行程序 - -## 工具介绍 - -通过Ts接口生成工具,使用者可以将已有的.h接口文件生成ts文件,进而将生成的ts文件作为NAPI框架生成代码工具的输入,生成NAPI框架代码,达到工具链的效果。工具的软件架构如下: - -![](../../../figures/ts_framework.png) - - -## 使用方法 - -### 可执行程序使用方法 - -#### Linux - -1.将待转换的.h文件、napi_generator-linux、header_parser放在同级目录下,此处新建out文件夹,用于存放生成.d.ts文件。整体目录文件如下: - - harmony@Ubuntu-64:~/service/linshi$ ls - baseapi.h header_parser napi_generator-linux out - -2.在终端中进入到之前可执行程序napi_generator-linux所在的目录,并运行napi_generator-linux,命令如下: - - harmony@Ubuntu-64:~/service/linshi$ ./napi_generator-linux -f baseapi.h -t true -o out - -其中,参数详情如下: - -f, 待转换的.h文件,若同时转换多个文件,文件之间用“,”隔开; - -d, 根据指定路径转换该文件夹中所有.h文件; - -t, 区分ts生成与napi转换工具,值为true时表示ts生成,false表示napi转换,默认为false; - -o, 可选参数,默认为当前目录,指定生成框架代码输出路径。 - - 备注:-f与-d两个参数只选其中一个参数即可。 - -3.运行成功后会在out目录下生成.d.ts文件,如下所示: - - harmony@Ubuntu-64:~/linshi/napi_generator_8/examples/ts/out$ ls - napi_gen.log baseapi.d.ts - -#### Windows - -1.将待转换的.h文件、napi_generator-win.exe、header_parser.exe放在同级目录下,此处新建out文件夹,用于存放生成.d.ts文件。整体目录文件如下: - - E:\demo\napi>dir /B - baseapi.h - header_parser.exe - napi_generator-win.exe - out - -2.在终端中进入到之前可执行程序napi_generator-win.exe所在的目录,并运行napi_generator-win.exe,命令如下: - - E:\demo\napi>napi_generator-win.exe -f baseapi.h -t true -o out - -其中,参数详情如下: - -f, 待转换的.h文件,若同时转换多个文件,文件之间用“,”隔开; - -d, 根据指定路径转换该文件夹中所有.h文件; - -t, 区分ts生成与napi转换工具,值为true时表示ts生成,false表示napi转换,默认为false; - -o, 可选参数,默认为当前目录,指定生成框架代码输出路径。 - - 备注:-f与-d两个参数只选其中一个参数即可。 - -3.运行成功后会在out目录下生成.d.ts文件,如下所示: - - E:\demo\napi\out>dir /B - napi_gen.log - baseapi.d.ts - -#### Mac - -方法步骤参考windows、Linux的使用方法。 - -### IntelliJ插件使用方法 - -具体的插件使用步骤,可以左键单击以下链接了解: - -[IntelliJ插件使用说明](https://gitee.com/openharmony/napi_generator/tree/master/hdc/ts/ts_IntelliJ_plugin/docs/INSTRUCTION_ZH.md) diff --git a/docs/guide/ts/ROADMAP_ZH.md b/docs/guide/ts/ROADMAP_ZH.md deleted file mode 100644 index b31531a52a463fa12c2db268e04d129f63ad60dd..0000000000000000000000000000000000000000 --- a/docs/guide/ts/ROADMAP_ZH.md +++ /dev/null @@ -1,41 +0,0 @@ -# TS接口文件生成工具 - -## 版本规划 - -2023.08.30提供1.1版本 基本完善工具C++支持能力,具体特性见表1。 - -**表 1** 2023.08.30待支持特性 - - - - - - - - - - - - - - - - - - -

类别

-

待开发特性

-

入口平台

-

变量/返回值

-
  • 支持C++语言中enum复合类型变量/函数入参自动转换为对应TS接口中的变量/函数
  • 支持C++语言中std::map转换为对应TS接口中的Map<>
  • 支持C++语言中std::any转换为对应TS接口中的any
  • 支持C++语言中namespace域嵌套namespace转换为对应TS接口中的实现
  • 支持C++语言数组类型为using定义的NUMBER_TYPE类型转换为对应TS接口中的变量
-
  • 可执行文件-Windows/Ubuntu/Mac
  • IntelliJ插件-Windows
  • VSCode插件-Windows/Ubuntu/Mac
-

namespace

-
  • 支持.h文件中namespace域class继承转换为对应TS文件中继承的class
-
  • 可执行文件-Windows/Ubuntu/Mac
  • IntelliJ插件-Windows
  • VSCode插件-Windows/Ubuntu/Mac
-
- - -## 相关链接 - -无 - diff --git a/docs/guide/ts/ts_Gen-1.0.md b/docs/guide/ts/ts_Gen-1.0.md deleted file mode 100644 index decb5880cf9cc1b7302e0163776f99f0a8607b5c..0000000000000000000000000000000000000000 --- a/docs/guide/ts/ts_Gen-1.0.md +++ /dev/null @@ -1,61 +0,0 @@ -# ts_Gen-1.0(2023-01-30) - -## 版本概述 - -发布ts_Gen-1.0。 - -## 版本特性 - -**表 1** 已支持特性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

类别

-

支持特性

-

入口平台

-

变量/返回值

-
  • 支持C++语言中string、std::string、char、wchar_t、char16_t、char32_t、short、int、int16_t、uint16_t、int32_t、uint32_t、int64_t、uint64_t、double_t、float_t、size_t、long、long long、float、double、long double、bool基础类型的变量/函数入参自动转换为对应TS接口中变量/入参
  • 支持C++语言中string、std::string、char、wchar_t、char16_t、char32_t、short、int、int16_t、uint16_t、int32_t、uint32_t、int64_t、uint64_t、double_t、float_t、size_t、long、long long、float、double、long double、bool数组类型的变量/函数入参自动转换为对应TS接口中变量/入参,数组书写方式为std::vector<>
  • 支持C++语言string、std::string、char、wchar_t、char16_t、char32_t、short、int、int16_t、uint16_t、int32_t、uint32_t、int64_t、uint64_t、double_t、float_t、size_t、long、long long、float、double、long double、bool基础类型的返回值自动转换为对应TS接口中返回值
-
  • 可执行文件-Windows/Ubuntu/Mac
  • IntelliJ插件-Windows
-

函数类型

-
  • 支持ts接口文件中namespace域的static函数自动转换为对应TS接口中的函数
-
  • 可执行文件-Windows/Ubuntu/Mac
  • IntelliJ插件-Windows
-

class

-
  • 支持C++语言中class的变量、函数自动转换为对应TS接口中的变量、函数
-
  • 可执行文件-Windows/Ubuntu/Mac
  • IntelliJ插件-Windows
-

namespace

-
  • 支持C++语言中namespace域的变量、函数自动转换为对应TS接口中的变量、函数
  • 支持.h文件中namespace域class转换为对应TS接口中的class
-
  • 可执行文件-Windows/Ubuntu/Mac
  • IntelliJ插件-Windows
-

文件

-
  • 支持.h文件中namespace数据类型转换为对应TS接口中的数据类型
  • 支持C++文件名格式A.h的文件转换
  • 支持命令行方式转换时参数为多个文件路径,相互之间用英文逗号分开
  • 支持命令行方式转换时指定文件夹路径方式转换
-
  • 可执行文件-Windows/Ubuntu/Mac
  • IntelliJ插件-Windows
-
- -**表 2** - -[待开发特性](https://gitee.com/openharmony/napi_generator/blob/master/docs/guide/ts/ROADMAP_ZH.md) \ No newline at end of file diff --git a/docs/log/release-notes.md b/docs/log/release-notes.md index eb8a2e4107e500fa4d19141f516533b8f4f33692..9682698e8dbd0ed42f3f99a1e0b3c6fd2c9bca05 100644 --- a/docs/log/release-notes.md +++ b/docs/log/release-notes.md @@ -20,18 +20,10 @@ 暂无 -## h2ets - -暂无 - ## scan(API扫描工具) 暂无 -## hdf(HCS可视化工具) - -暂无 - # roadmap ## dts2cpp(NAPI框架代码生成工具) @@ -54,14 +46,7 @@ 暂无 -## h2ets - -暂无 - ## scan(API扫描工具) 暂无 -## hdf(HCS可视化工具) - -暂无 \ No newline at end of file diff --git a/docs/readme.md b/docs/readme.md index 77c6ae6df263c380fc624ac499e61f234ea174c9..8c92f98b45ae9f318228887987342cad653fd76a 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -2,23 +2,19 @@ ## dts2cpp(NAPI框架代码生成工具) -[readme](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/dts2cpp/README_zh.md) +[readme](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/dts2cpp/dts2cpp_README_zh.md) ## h2dts(TS接口生成工具) -[readme](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2dts/README_zh.md) +[readme](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2dts/h2dts_README_ZH.md) ## cmake2gn(GN脚本生成工具) -[readme](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/cmake2gn/README_zh.md) +[readme](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/cmake2gn/cmake2gn_README_ZH.md) ## h2sa(SERVICE框架生成工具) -[readme](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2sa/README_zh.md) - -## dts2ets - -暂无 +[readme](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2sa/h2sa_README_ZH.md) ## h2dtscpp(NATIVE生成工具) @@ -26,8 +22,4 @@ ## scan(API扫描工具) -[readme](https://gitee.com/openharmony/napi_generator/blob/master/src/tool/api/README_zh.md) - -## hdf(HCS可视化工具) - -[readme](https://gitee.com/openharmony/drivers_hdf_core/tree/master/framework/tools/hcs-view/README_zh.md) \ No newline at end of file +[readme](https://gitee.com/openharmony/napi_generator/blob/master/src/tool/api/scan_README_ZH.md) \ No newline at end of file diff --git a/docs/requirement/To-do_list.md b/docs/requirement/To-do_list.md deleted file mode 100644 index c2089f92570b76faf2377ea2ab81bfe2495e881c..0000000000000000000000000000000000000000 --- a/docs/requirement/To-do_list.md +++ /dev/null @@ -1,36 +0,0 @@ -# To-do list - -## History - -| 版本号 | 修订人 | 修订日期 | 修订描述 | -| ------ | ------ | ------------- | -------- | -| V0.1 | 苟晶晶 | 2024年3月25日 | 新建 | -| | | | | - -## Requirement - -| issue | 描述 | 分析 | 结论 | ToDo | -| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | ---------- | ---- | -| 【需求】[napi_tool]:工具生成代码中增加打印调试信息 | 工具生成代码中增加关键节点信息打印,便于开发者确认流程 | 开发者通过关键信息打印,可以迅速定位问题 | 优先级低 | | -| 【需求】[napi_tool]: 箭头函数参数为回调函数时,编译报错 | 箭头函数的参数是箭头函数形式的回调函数时,编译报错。
.d.ts文件内容如下:
declare namespace napitest {
export class A {
a: string;
}
export interface InterfaceA {
callFunction: (result: number) => void;
}
export interface InterfaceB {
funcByClass: (a: A, b: number, callback: (result: number) => void, c: InterfaceA) => number;
}
// export const addByClass: (a: A, b: number, callback: (result: number) => void, c: InterfaceA) => number;
}
export default napitest; | 扩展工具的特性范围,提高工具可用性 | 优先级低 | | -| 【需求】[napi_tool]:(等待更佳解决方案)分离生成的工具代码普通方法和回调方法,防止嵌套使用头文件 | 需求背景: 当前工具生成的中间代码,普通方法和回调方法的接口均在一个头文件里,这样会导致嵌套使用头文件造成可读性不强,需要整改生成代码将普通方法和回调方法的接口分离到不同头文件,增加易用性和可读性
需求阻塞点:
由于工具生成的中间代码均在 XXXmiddle.cpp 中,将XXX.h分离成XXXToC.h与XXXToJs.h之后,XXXmiddle.cpp中include, 若.d.ts中的文件声明一个interface类中全部定义为注册回调的方法,按照预期应该将该interface声明在XXXToJs.h中,而由于注册回调的中间代码都在XXXmiddle.cpp中, XXXmiddle.cpp中该interface的构造函数用到了XXXToJs.h中定义的类,这时若要解决这个问题,就需将XXXmiddle.cpp文件进行拆分,这样代码改动太大,需寻求更佳的解决方案
当前进展:
当前修改无法跑过test_on测试用例集 | 需求调研,提高工具可用性 | 优先级降低 | | -| 【需求】[napi_tool]: on/off第二个参数支持object | [napi_tool] on/off第二个参数支持object,其中object中定义需要注册的回调
function on(type: 'missionEvent', listener: MissionListener): number;
export interface MissionListener {
onMissionCreated(mission: number): void;
onMissionDestroyed(mission: number): void;
} | 扩展注册的使用场景,增加工具易用性 | 优先级中 | | -| 【需求】[napi_tool]: on注册回调的箭头函数支持携带js返回值给C++ | on注册回调的箭头函数支持携带js返回值给C++;
1130后支持 | 需求调研,业务需要根据回调返回值进行后续处理的场景 | 优先级低 | | -| 【需求】[napi_tool]: 支持js业务代码回调接口中的回调js函数 | function_direct处理逻辑覆盖此场景,需要增加只传递回调,不触发的场景
.d.ts定义:
function callbackWrapper(original: Function): (err: Object, value: Object) => void;
调用方式:
function callbackWrapper(original) {
if (typeof original !== 'function') {
let error = new BusinessError(`Parameter error.The type of ${original} must be function`);
throw error;
}
const descriptors = getOwnPropertyDescriptors(original);
if (typeof descriptors.length.value === 'number') {
descriptors.length.value++;
}
if (typeof descriptors.name.value === 'string') {
descriptors.name.value += 'callbackified';
}
function cb(...args) {
callbackified(original, ...args);
}
Object.defineProperties(cb, descriptors);
return cb;
} | 需求调研,扩展工具的特性范围,提高工具可用性。 | 优先级低 | | -| 【需求】[napi_tool]: type, interface支持成员变量any, object, Enum为可选参数 | type, interface当前成员变量支持any, object, Enum可选参数的转换
当前interface/type支持可选参数类型已经包括:number, string, boolean, Array, string/number/boolean[], Map, {[key:string]:string/number/boolean}, number \| string \|boolean
待支持类型:any, object, Enum
.d.ts文件如下所示:
export enum LaunchReason {
UNKNOWN = 0,
START_ABILITY = 1,
CALL = 2,
CONTINUATION = 3,
}
type test =
{
param1?: object;
param2?: any;
param3?: Array;
param4?: Map;
$param5?: any;
param6?: Array;
param7?: Map;
param8?: LaunchReason;
}
interface interfaceTest
{
param1?: object;
param2?: any;
param3?: Array;
param4?: Map;
$param5?: any;
param6?: Array;
param7?: Map;
param8?: LaunchReason;
}
function func(v1: test, v2: interfaceTest): void; | 使用场景较少,建议暂不支持 | 优先级低 | | -| 【需求】[gn, api, service, ts]:modify gn faq and add storytest for api, service, ts tools | 修改gn工具faq文档并为ts, api, service工具增加storytest,可自动化测试 | 确认需继续维护的工具可增加storytest和unittest | 优先级中 | | -| 【需求】[napi_tool]:ts接口定义入参/变量为any,JS调用时部分参数类型报错 | ts接口定义入参/变量为any,JS调用时参数类型为map、array、interface、interface(enum)嵌套时报错
ts定义如下:
function fun1(v: any, v1: string): number;
JS调用如下:
// map> --当前不支持
ret = test.fun1({"test": ["okay", "okay"], "test1": ["res", "res"]}, 'aaa');
assert.strictEqual(ret, 0);
// Array> --当前不支持
ret = test.fun1([{"test": 15, "test1": 18}, {"test": 15, "test1": 18}], 'aaa');
assert.strictEqual(ret, 0);
// interface --当前不支持
ret = test.fun1({'name': 'aaaa', 'age': 18}, 'aaa');
assert.strictEqual(ret, 0);
// interface --当前不支持
ret = test.fun1({'type': LaunchReason.CALL, 'age': 'aaa'}, 'aaa');
assert.strictEqual(ret, 0); | 需求调研 | 优先级低 | | -| 【bug】[napi_tool]on回调&箭头函数回调,回调方式默认为同步,需约定异步回调方式入口 | on回调 & 箭头函数回调,回调方式默认为同步,无异步回调方式入口 | 扩展注册的使用场景,增加工具易用性,建议转需求 | 优先级中 | | -| 【bug】[napi_tool]函数返回值支持array、array<{[key:string]:any}> | 函数返回值不支持array、array<{[key:string]:any}> | 使用场景较少,建议暂不支持 | 优先级低 | | -| 【bug】[napi_tool]支持ts接口文件中namespace域的new函数 | 目前不支持ts接口文件中namespace域interface中带参数的new函数,如:new (value?: { width?: string \| number; height?: string \| number }): PolygonAttribute; | 使用场景较少,建议暂不支持 | 优先级低 | | -| 【bug】[napi_tool]工具代码中若在class1中构造函数使用的class2在class1之后,生成后的代码编译报错 | 若class1中的有参构造的参数有class2时,且class2声明在class1之后,编译时报错:field ‘aPro’ has incomplete type ‘example::A’
.d.ts文件如下所示:
declare namespace example {
class Demo {
constructor(intPro: number, strPro: string, boolPro: boolean, aPro: A);
intPro: number;
strPro: string;
boolPro: boolean;
aPro: A;
}
class A
{
constructor(proA: number, proB: string, proC: boolean);
func1(pro: number);
func2(pro: string);
func3(pro: boolean);
proA: number;
proB: string;
proC: boolean;
}
} | 该bug实际是为了支持class构造函数包含class的情况,建议转需求调研 | 优先级中 | | - - - -## Change Log - -| 计划 | 进展 | 结论 | 时间 | -| ---- | ---- | ---- | ---- | -| | | | | -| | | | | - diff --git a/docs/usage.md b/docs/usage.md index d366fc2661833ba5071e20f1aab03feae9821c30..bcc59cd6705a1f3f6fd78da82b1f5ab3c8aa7a3a 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -12,7 +12,7 @@ vscode插件开发说明:[vscode插件开发说明](https://gitee.com/openharm **使用说明** -可执行程序使用说明:[可执行程序使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/dts2cpp/docs/usage/INSTRUCTION_ZH.md) +可执行程序使用说明:[可执行程序使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/dts2cpp/docs/usage/dts2cpp_INSTRUCTION_ZH.md) intelliJ插件使用说明:[intelliJ插件使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/intellij_plugin/dts2cpp/napi_IntelliJ_plugin/docs/usage/INSTRUCTION_ZH.md) @@ -26,8 +26,6 @@ vscode插件使用说明:[vscode插件使用说明](https://gitee.com/openharm intelliJ插件开发说明:[intelliJ插件开发说明](https://gitee.com/openharmony/napi_generator/blob/master/src/intellij_plugin/h2dts/ts_IntelliJ_plugin/docs/guide/DEVELOP_zh.md) -// vscode 是否支持? - vscode插件开发说明:[vscode插件开发说明](https://gitee.com/openharmony/napi_generator/blob/master/src/vscode_plugin/h2dts/ts_vs_plugin/docs/guide/DEVELOP_zh.md) **使用说明** @@ -48,7 +46,7 @@ vscode插件开发说明:暂无 **使用说明** -可执行程序使用说明:[可执行程序使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2sa/docs/usage/INSTRUCTION_ZH.md) +可执行程序使用说明:[可执行程序使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2sa/docs/usage/h2sa_INSTRUCTION_ZH.md) vscode插件使用说明:[vscode插件使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/vscode_plugin/h2sa/service_vs_plugin/docs/usage/INSTRUCTION_ZH.md) @@ -70,41 +68,20 @@ vscode插件使用说明:[vscode插件使用说明](https://gitee.com/openharm **开发说明** -可执行程序开发说明:暂无 - -intelliJ插件开发说明:暂无 +可执行程序开发说明:[可执行程序开发说明](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2dtscpp/docs/guide/DEVELOP_ZH.md) **使用说明** 可执行程序使用说明:[可执行程序使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2dtscpp/docs/usage/INSTRUCTION_ZH.md) -intelliJ插件使用说明:暂无 - - -## dts2ets - -暂无 - ## scan(API扫描工具) **开发说明** -暂无 +可执行程序使用说明:[可执行程序开发说明](https://gitee.com/openharmony/napi_generator/blob/master/src/tool/api/docs/scan_DEVELOP_ZH.md) **使用说明** -可执行程序使用说明:[可执行程序使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/tool/api/docs/INSTRUCTION_ZH.md) - -intelliJ插件使用说明:暂无 +可执行程序使用说明:[可执行程序使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/tool/api/docs/scan_INSTRUCTION_ZH.md) vscode插件使用说明:[vscode插件使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/tool/api/api_scan_vs_plugin/docs/INSTRUCTION_ZH.md) - -## hdf(HCS可视化工具) - -**开发说明** - -工具开发说明:[开发说明](https://gitee.com/openharmony/drivers_hdf_core/blob/master/framework/tools/hcs-view/docs/DEVELOP_zh.md) - -**使用说明** - -工具使用说明:[使用说明](https://gitee.com/openharmony/drivers_hdf_core/blob/master/framework/tools/hcs-view/docs/INSTRUCTION_zh.md) \ No newline at end of file diff --git a/src/.eslintrc.json b/src/.eslintrc.json deleted file mode 100644 index d25565bb97aa415ae7970c49a8e5a3bc6a56d37e..0000000000000000000000000000000000000000 --- a/src/.eslintrc.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "env": { - "browser": false, - "commonjs": true, - "es6": true, - "node": true, - "mocha": true - }, - "parserOptions": { - "ecmaVersion": 2018, - "ecmaFeatures": { - "jsx": true - }, - "sourceType": "module" - }, - "rules": { - "no-const-assign": "warn", - "no-this-before-super": "warn", - "no-undef": "warn", - "no-unreachable": "warn", - "no-unused-vars": "warn", - "constructor-super": "warn", - "valid-typeof": "warn" - } -} diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md deleted file mode 100644 index 5b631eac1593fe76ca57eeaa4859c6cf642662ea..0000000000000000000000000000000000000000 --- a/src/CHANGELOG.md +++ /dev/null @@ -1,9 +0,0 @@ -# Change Log - -All notable changes to the "gnapi" extension will be documented in this file. - -Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. - -## [Unreleased] - -- Initial release \ No newline at end of file diff --git a/src/README.md b/src/README.md deleted file mode 100644 index 5a79211aa5de8b2108d4279349b89e072dcd0607..0000000000000000000000000000000000000000 --- a/src/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# gnapi README - -1,右键单击@ohos.xxxx.d.ts文件 - -2,单击菜单[.d.ts生成c++] diff --git a/src/cli/cmake2gn/cmake2gn_README_ZH.md b/src/cli/cmake2gn/cmake2gn_README_ZH.md new file mode 100644 index 0000000000000000000000000000000000000000..02d8d09144498a2be5e070c4190dc13f1361a4b5 --- /dev/null +++ b/src/cli/cmake2gn/cmake2gn_README_ZH.md @@ -0,0 +1,299 @@ +# cmake2gn工具 + +## 简介 + +cmake2gn工具,即GN脚本转换工具,它可以根据三方库的CMakeLists.txt文件,编译转换生成BUILD.gn脚本文件。当前OpenHarmony源码只支持BUILD.gn文件编译,开发者无法移植CMakeLists.txt编译方式的三方库到OpenHarmony中。此时,开发者可使用GN脚本转换工具,根据CMakeLists.txt文件生成BUILD.gn脚本文件,降低移植难度,提高开发效率。目前工具支持可执行文件、VS Code插件两种入口。 + + ├── napi_generator # 工具集 + │ ├── ... # 其它文件 + │ ├── src + │ │ ├── ... + │ │ ├── cli + │ │ | ├── ... # 其它工具 + │ │ | ├── cmake2gn + │ │ | | ├── src + │ │ | | | ├── main.js # 工具源码入口 + │ │ | | | ├── package.json # package.json文件 + │ │ | | | |── src + │ │ | | | | |── analyze_cmake.js # cmake解析器 + │ │ | | | | |── analyze_command.js # command解析器 + │ │ | | | | |── analyze_make.js # make解析器 + │ │ | | | | |── generate_gn.js # 生成器 + │ │ | | | | |── logger.js # log日志 + │ │ | | | | |── tool.js # 公共模块代码 + +## 约束 +系统:建议Ubuntu 20.04或者Windows 10 + +依赖版本:VS Code 1.62.0 + +## 使用方法 + +### 使用对象 + +系统开发者 +### 使用场景 + +1) 移植CMakeLists.txt编译方式的三方库到OpenHarmony源码中。 + +### 工具获取 + +工具有两种类型,分别是可执行文件、VS Code插件。其中的可执行文件可根据工具使用者的开发环境选择,支持Windows,Linux和Mac。可执行文件、VS Code插件下载路径如下: + +[下载链接](http://ftpkaihongdigi.i234.me:5000/fsdownload/1OjtRhtGf/gn-gen-0.0.1) + +### 工具输入 + +以CmakeLists.txt编译方式的三方库 + +根据使用者指定三方库的CMakeLists.txt文件,工具会输出对应的BUILD.gn文件。为了方便使用者快速上手工具,可供测试的三方库项目目录如下: + +``` +Openharmony@Ubuntu-64:~/OpenHarmony/third_party/mbedtls-development$ ls +3rdparty BUGS.md ChangeLog cmake configs DartConfiguration.tcl docs include LICENSE programs scripts SUPPORT.md visualc BRANCHES.md ChangeLog.d CMakeLists.txt CONTRIBUTING.md dco.txt doxygen library Makefile README.md SECURITY.md tests +``` + +### 工具使用 + +具体的工具使用步骤,可以左键单击以下链接了解: + +[工具使用说明](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/cmake2gn/docs/usage/INSTRUCTION_ZH.md) + +### 工具输出 + +在linux环境下的,根据输入三方库项目的CMakeLists.txt文件,生成的输出文件,如下所示: + + OpenHarmony@Ubuntu-64:~/OpenHarmony/third_party/mbedtls-development$ ls + 3rdparty BUGS.md ChangeLog cmake configs DartConfiguration.tcl docs include LICENSE programs scripts SUPPORT.md visualc BRANCHES.md build_tmp ChangeLog.d CMakeLists.txt CONTRIBUTING.md dco.txt doxygen library Makefile README.md SECURITY.md tests + OpenHarmony@Ubuntu-64:~/OpenHarmony/third_party/mbedtls-development$ cd build_tmp/ + OpenHarmony@Ubuntu-64:~/OpenHarmony/third_party/mbedtls-development/build_tmp$ ls + 3rdparty BUILD.gn cmake CMakeCache.txt CMakeFiles cmake_install.cmake CTestTestfile.cmake DartConfiguration.tcl include library Makefile ohos.toolchain.cmake programs scripts tests + +其中生成的BUILD.gn文件,内容如下所示: + +``` +import("//build/ohos.gni") + +group("all_targets") { + deps = [ + #静态库 + "//third_party/mbedtls-development/build_tmp/library:mbedcrypto", + "//third_party/mbedtls-development/build_tmp/library:mbedx509", + "//third_party/mbedtls-development/build_tmp/library:mbedtls", + + #可执行程序 + "//third_party/mbedtls-development/build_tmp/programs/aes:crypt_and_hash", + "//third_party/mbedtls-development/build_tmp/programs/cipher:cipher_aead_demo", + "//third_party/mbedtls-development/build_tmp/programs/fuzz:fuzz_x509crl", + "//third_party/mbedtls-development/build_tmp/programs/fuzz:fuzz_x509csr", + "//third_party/mbedtls-development/build_tmp/programs/fuzz:fuzz_pubkey", + "//third_party/mbedtls-development/build_tmp/programs/fuzz:fuzz_pkcs7", + "//third_party/mbedtls-development/build_tmp/programs/fuzz:fuzz_privkey", + "//third_party/mbedtls-development/build_tmp/programs/fuzz:fuzz_client", + "//third_party/mbedtls-development/build_tmp/programs/fuzz:fuzz_dtlsserver", + "//third_party/mbedtls-development/build_tmp/programs/fuzz:fuzz_dtlsclient", + "//third_party/mbedtls-development/build_tmp/programs/fuzz:fuzz_x509crt", + "//third_party/mbedtls-development/build_tmp/programs/fuzz:fuzz_server", + "//third_party/mbedtls-development/build_tmp/programs/hash:generic_sum", + "//third_party/mbedtls-development/build_tmp/programs/hash:hello", + "//third_party/mbedtls-development/build_tmp/programs/hash:md_hmac_demo", + "//third_party/mbedtls-development/build_tmp/programs/pkey:mpi_demo", + "//third_party/mbedtls-development/build_tmp/programs/pkey:key_app", + "//third_party/mbedtls-development/build_tmp/programs/pkey:pk_encrypt", + "//third_party/mbedtls-development/build_tmp/programs/pkey:gen_key", + "//third_party/mbedtls-development/build_tmp/programs/pkey:ecdsa", + "//third_party/mbedtls-development/build_tmp/programs/pkey:rsa_encrypt", + "//third_party/mbedtls-development/build_tmp/programs/pkey:dh_client", + "//third_party/mbedtls-development/build_tmp/programs/pkey:dh_server", + "//third_party/mbedtls-development/build_tmp/programs/pkey:dh_genprime", + "//third_party/mbedtls-development/build_tmp/programs/pkey:ecdh_curve25519", + "//third_party/mbedtls-development/build_tmp/programs/pkey:pk_decrypt", + "//third_party/mbedtls-development/build_tmp/programs/pkey:pk_sign", + "//third_party/mbedtls-development/build_tmp/programs/pkey:key_app_writer", + "//third_party/mbedtls-development/build_tmp/programs/pkey:pk_verify", + "//third_party/mbedtls-development/build_tmp/programs/pkey:rsa_decrypt", + "//third_party/mbedtls-development/build_tmp/programs/pkey:rsa_genkey", + "//third_party/mbedtls-development/build_tmp/programs/pkey:rsa_sign", + "//third_party/mbedtls-development/build_tmp/programs/pkey:rsa_sign_pss", + "//third_party/mbedtls-development/build_tmp/programs/pkey:rsa_verify", + "//third_party/mbedtls-development/build_tmp/programs/pkey:rsa_verify_pss", + "//third_party/mbedtls-development/build_tmp/programs/psa:key_ladder_demo", + "//third_party/mbedtls-development/build_tmp/programs/psa:crypto_examples", + "//third_party/mbedtls-development/build_tmp/programs/psa:aead_demo", + "//third_party/mbedtls-development/build_tmp/programs/psa:hmac_demo", + "//third_party/mbedtls-development/build_tmp/programs/psa:psa_constant_names", + "//third_party/mbedtls-development/build_tmp/programs/random:gen_entropy", + "//third_party/mbedtls-development/build_tmp/programs/random:gen_random_ctr_drbg", + "//third_party/mbedtls-development/build_tmp/programs/ssl:ssl_pthread_server", + "//third_party/mbedtls-development/build_tmp/programs/ssl:ssl_client1", + "//third_party/mbedtls-development/build_tmp/programs/ssl:ssl_client2", + "//third_party/mbedtls-development/build_tmp/programs/ssl:mini_client", + "//third_party/mbedtls-development/build_tmp/programs/ssl:dtls_server", + "//third_party/mbedtls-development/build_tmp/programs/ssl:dtls_client", + "//third_party/mbedtls-development/build_tmp/programs/ssl:ssl_server", + "//third_party/mbedtls-development/build_tmp/programs/ssl:ssl_server2", + "//third_party/mbedtls-development/build_tmp/programs/ssl:ssl_context_info", + "//third_party/mbedtls-development/build_tmp/programs/ssl:ssl_fork_server", + "//third_party/mbedtls-development/build_tmp/programs/ssl:ssl_mail_client", + "//third_party/mbedtls-development/build_tmp/programs/test:selftest", + "//third_party/mbedtls-development/build_tmp/programs/test:benchmark", + "//third_party/mbedtls-development/build_tmp/programs/test:udp_proxy", + "//third_party/mbedtls-development/build_tmp/programs/test:query_compile_time_config", + "//third_party/mbedtls-development/build_tmp/programs/test:zeroize", + "//third_party/mbedtls-development/build_tmp/programs/util:pem2der", + "//third_party/mbedtls-development/build_tmp/programs/util:strerror", + "//third_party/mbedtls-development/build_tmp/programs/x509:load_roots", + "//third_party/mbedtls-development/build_tmp/programs/x509:cert_req", + "//third_party/mbedtls-development/build_tmp/programs/x509:cert_write", + "//third_party/mbedtls-development/build_tmp/programs/x509:crl_app", + "//third_party/mbedtls-development/build_tmp/programs/x509:req_app", + "//third_party/mbedtls-development/build_tmp/programs/x509:cert_app", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_x509write", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_x509parse", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_its", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_storage_format.current", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_timing", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_ssl", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_rsa", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_entropy", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_shax", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_hmac_drbg.pr", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_dhm", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_ecdsa", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.des", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_poly1305", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_ctr_drbg", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.null", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.gcm", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_storage_format.misc", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_ccm", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.camellia", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_chachapoly", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_mdx", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_des", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.chacha20", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_bignum.generated", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_bignum_mod", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_chacha20", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_aria", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_not_supported.generated", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.padding", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.nist_kw", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_aes.ofb", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_hmac_drbg.nopr", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_aes.ecb", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_hkdf", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_aes.cfb", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.ccm", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_pkcs5", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.aes", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_bignum.misc", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_aes.rest", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_cmac", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_camellia", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_ecdh", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_md", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.chachapoly", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_storage_format.v0", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_asn1parse", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_asn1write", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_base64", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_bignum_mod_raw.generated", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_oid", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.misc", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_bignum_core.misc", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_ecjpake", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_bignum_core.generated", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_bignum_mod_raw", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_random", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_aes.cbc", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_pk", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_version", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_se_driver_hal_mocks", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_bignum_mod.generated", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_debug", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_pkcs1_v21", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_gcm.aes128_de", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.aria", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_gcm.aes128_en", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_gcm.aes192_de", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_gcm.camellia", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_gcm.aes192_en", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_gcm.aes256_de", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_gcm.aes256_en", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_gcm.misc", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_hmac_drbg.misc", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_hmac_drbg.no_reseed", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_lms", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_mps", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_memory_buffer_alloc", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_net", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_nist_kw", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_metadata", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_pkparse", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_hash", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_pem", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_pkcs12", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_attributes", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_aes.xts", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_op_fail.generated", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_pkcs1_v15", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_pkcs7", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_pkwrite", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_not_supported.misc", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_driver_wrappers", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_entropy", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_generate_key.generated", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_init", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_op_fail.misc", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_error", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_pake", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_lmots", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_persistent_key", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_se_driver_hal", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_ecp", + "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_slot_management", + + ] +} + +``` + +### 集成 + +具体的将三方库集成到OpenHarmony的步骤,可以左键单击以下链接了解: + +[将三方库集成到OpenHarmony的方法](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/cmake2gn/docs/usage/ENSEMBLE_METHOD_ZH.md) + +## 工具开发说明 + +### 对象 + +工具的开发者 + +### 开发场景 + +若当前工具的功能已经不能满足开发者的全部需求,则开发者可以基于已有的源码对工具进行二次开发,来增强工具的能力,编译打包生成自定义的可执行文件和插件。 + +### 开发步骤 + +开发者可以根据如下的步骤来完成对工具的开发: + + [工具开发说明](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/cmake2gn/docs/guide/DEVELOP_ZH.md) + +## 版本说明 + +[版本说明](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/cmake2gn/docs/release-notes/gn-gen-release-notes-0.0.2.md) + +## FAQ + + [FAQ](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/cmake2gn/docs/guide/FAQ.md) + +## 参与贡献 + +暂无 + +## 相关仓 + +暂无 diff --git a/src/cli/dts2cpp/docs/figures/pic-d-ts-transition_result.png b/src/cli/dts2cpp/docs/figures/pic-d-ts-transition_result.png new file mode 100644 index 0000000000000000000000000000000000000000..22661b7435f4ed6e4f709d5209a4d386966914e2 Binary files /dev/null and b/src/cli/dts2cpp/docs/figures/pic-d-ts-transition_result.png differ diff --git a/docs/guide/ENSEMBLE_METHOD_3.1VERSION.md b/src/cli/dts2cpp/docs/usage/dts2cpp_ENSEMBLE_METHOD_ZH.md similarity index 41% rename from docs/guide/ENSEMBLE_METHOD_3.1VERSION.md rename to src/cli/dts2cpp/docs/usage/dts2cpp_ENSEMBLE_METHOD_ZH.md index 0bfdc0ff6444a876181f94cc68bdd490cd04737b..5a5c6b32f9f20bb99080114a43c6a8229ea76eae 100644 --- a/docs/guide/ENSEMBLE_METHOD_3.1VERSION.md +++ b/src/cli/dts2cpp/docs/usage/dts2cpp_ENSEMBLE_METHOD_ZH.md @@ -1,15 +1,13 @@ -# 集成到OpenHarmony 3.1 Release的方法 +# NAPI框架生成代码集成到OpenHarmony的方法 ## 场景说明 为了实现工具生成的接口被其它子系统或者应用调用,需将生成的代码编译集成到OpenHarmony系统中,使其生成动态库,供OpenHarmony应用层调用。 -本文介绍如何将工具生成的源码利用OpenHarmony编译系统生成动态库供应用层调用,集成到OpenHarmony 3.1 Release主要是有以下两种方式,分别为增加ohos.build文件方式和增加bundle.json文件方式。 +本文介绍如何将工具生成的源码利用OpenHarmony编译系统生成动态库供应用层调用,主要是有以下两种方式,分别为增加ohos.build文件方式和增加bundle.json文件方式。 -## 3.1 版本 - -### bundle.json方式集成 +## 4.1版本 -#### 建立模块位置 +### 建立模块位置 模块目录理论上可在OpenHarmony工程的任一位置,假设OpenHarmony代码库的目录为OHOS_SRC,在OHOS_SRC/foundation目录下,建测试模块目录:napitest。napitest目录结构如下: @@ -27,11 +25,68 @@ 其中bundle.json为新增的编译配置文件,其它为工具生成的代码。 -#### 编译修改点 +### 编译修改点 -##### 修改BUILD.gn文件 +#### 修改bundle.json文件 -将deps中"//foundation/arkui/napi:ace_napi"的修改为"//foundation/ace/napi:ace_napi",修改后的BUILD.gn文件内容如下所示: +其中destPath选项中的"//foundation/napitest"指的是napitest目录,":napitest"指的是上面BUILD.gn中的目标ohos_shared_library("napitest")。 + +``` +{ + "name": "@ohos/napitest", + "description": "napitest provides atomic capabilities", + "version": "4.1", + "license": "Apache License 2.0", + "publishAs": "code-segment", + "segment": { + "destPath": "foundation/napitest" + }, + "dirs": {}, + "scripts": {}, + "component": { + "name": "napitest", + "subsystem": "napitest", + "features": [], + "adapted_system_type": [ + "standard" + ], + "rom": "10000KB", + "ram": "10000KB", + "deps": { + "components": [ + "napi", + "ipc_core", + "libhilog" + ], + "third_party": [ + "node" + ] + }, + "build": { + "sub_component": [ + "//foundation/napitest:napitest" + ], + "inner_kits": [ + { + "header": { + "header_base": "//foundation/napitest", + "header_files": [ + "tool_utility.h", + "napitest.h", + "napitest_middle.h" + ] + }, + "name": "//foundation/napitest:napitest" + } + ] + } + } +} +``` + +#### 修改BUILD.gn文件 + +删除ohos_shared_library("napitest")中的deps,并新增external_deps = [ "napi:ace_napi" ] 修改后的BUILD.gn文件内容如下所示: ``` import("//build/ohos.gni") @@ -40,7 +95,6 @@ ohos_shared_library("napitest") { sources = [ "napitest_middle.cpp", - "../serviceCode/NodeISayHello.cpp", # 将业务代码编译进去 "napitest.cpp", "tool_utility.cpp", ] @@ -48,10 +102,7 @@ ohos_shared_library("napitest") ".", "//third_party/node/src", ] - deps=[ - "//foundation/ace/napi:ace_napi", - "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", - ] + external_deps = [ "napi:ace_napi" ] remove_configs = [ "//build/config/compiler:no_rtti" ] cflags=[ ] @@ -67,9 +118,70 @@ ohos_shared_library("napitest") } ``` -若用户需要修改子系统和部件名称,则根据自身需求修改BUILD.gn文件和bundle.json文件中子系统与部件名称即可。 +#### 修改napitest.cpp文件 -##### 修改bundle.json文件 +在funcTest方法中增加业务逻辑: + +``` +out = v1 + v2; +``` + +#### 增加子系统 + +在源码/build/subsystem_config.json中增加子系统选项。如下所示: + +``` +"napitest": { + "path": "foundation/napitest", + "name": "napitest" + } +``` + +### 添加功能模块 + +在产品配置中添加上述子系统的功能模块,编译到产品产出文件中,例如在源码vendor/hihope/rk3568/config.json中增加part选项,其中第一个napitest就是BUILD.gn文件中的subsystem_name,第二个napitest就是BUILD.gn文件中的part_name。 + +``` +{ + "subsystem": "napitest", + "components": [ + { + "component": "napitest", + "features": [] + } + ] +} +``` + +### 编译验证 + +编译成功后,就会在 /out/产品名/packages/phone/system/lib/module/ 生成libnapitest.z.so,如下所示: + + /out/rk3568/packages/phone/system/lib/module + +## 4.0 版本 + +### 建立模块位置 + +模块目录理论上可在OpenHarmony工程的任一位置,假设OpenHarmony代码库的目录为OHOS_SRC,在OHOS_SRC/foundation目录下,建测试模块目录:napitest。napitest目录结构如下: + + napitest + |-- binding.gyp + |-- BUILD.gn + |-- bundle.json + |-- napitest.cpp + |-- napitest.h + |-- napitest_middle.h + |-- napitest_middle.cpp + |-- test.sh + |-- tool_utility.cpp + |-- tool_utility.h + +其中bundle.json为新增的编译配置文件,其它为工具生成的代码。 + +### 编译修改点 + +#### 修改bundle.json文件 其中destPath选项中的"//foundation/napitest"指的是napitest目录,":napitest"指的是上面BUILD.gn中的目标ohos_shared_library("napitest")。 @@ -77,7 +189,7 @@ ohos_shared_library("napitest") { "name": "@ohos/napitest", "description": "napitest provides atomic capabilities", - "version": "3.1", + "version": "4.0", "license": "Apache License 2.0", "publishAs": "code-segment", "segment": { @@ -126,57 +238,295 @@ ohos_shared_library("napitest") } ``` -##### 修改napitest.cpp文件 +#### 修改napitest.cpp文件 -为方便调试,在napitest.cpp文件中增加业务代码。以修改napitest.cpp文件为例,在以下方法中增加业务代码, +在funcTest方法中增加业务逻辑: -在sayHello方法中增加注册的object回调方法的调用: +``` +out = v1 + v2; +``` + +#### 增加子系统 + +在源码/build/subsystem_config.json中增加子系统选项。如下所示: ``` -... -// 业务代码调用 onSayHelloStart callback -napitest::napitest_interface::NodeISayHello::listener_.NodeISayHelloListener_onSayHelloStartCallback(info1); -// 业务代码调用 onSayHelloEnd callback -napitest::napitest_interface::NodeISayHello::listener_.NodeISayHelloListener_onSayHelloEndCallback(info2); -... +"napitest": { + "path": "foundation/napitest", + "name": "napitest" + } ``` -在sayHi方法中增加register注册的回调方法的调用: +### 添加功能模块 + +在产品配置中添加上述子系统的功能模块,编译到产品产出文件中,例如在源码vendor/hihope/rk3568/config.json中增加part选项,其中第一个napitest就是BUILD.gn文件中的subsystem_name,第二个napitest就是BUILD.gn文件中的part_name。 ``` -... -napitest::napitest_interface::NodeISayHello *ptr = new napitest::napitest_interface::NodeISayHello(); -uint32_t callbackNum = 50; -ptr->CallbackfuncCallback(callbackNum); -delete ptr; -... +{ + "subsystem": "napitest", + "components": [ + { + "component": "napitest", + "features": [] + } + ] +} ``` -在sayHelloWithResponse方法中增加Promise回调方法的调用: +### 编译验证 + +编译成功后,就会在 /out/产品名/packages/phone/system/lib/module/ 生成libnapitest.z.so,如下所示: + + /out/rk3568/packages/phone/system/lib/module + +## 3.2 版本 + +### 建立模块位置 + +模块目录理论上可在OpenHarmony工程的任一位置,假设OpenHarmony代码库的目录为OHOS_SRC,在OHOS_SRC/foundation目录下,建测试模块目录:napitest。napitest目录结构如下: + + napitest + |-- binding.gyp + |-- BUILD.gn + |-- bundle.json + |-- napitest.cpp + |-- napitest.h + |-- napitest_middle.h + |-- napitest_middle.cpp + |-- test.sh + |-- tool_utility.cpp + |-- tool_utility.h + +其中bundle.json为新建的编译配置文件,其它为工具生成的代码。 + +### 编译修改点 + +#### 修改bundle.json文件 + +其中destPath选项中的"//foundation/napitest"指的是napitest目录,":napitest"指的是上面BUILD.gn中的目标ohos_shared_library("napitest")。 ``` -... -out.errMsg = ""; -out.response = "rec hello."; -out.result = 0; -... +{ + "name": "@ohos/napitest", + "description": "napitest provides atomic capabilities", + "version": "3.2", + "license": "Apache License 2.0", + "publishAs": "code-segment", + "segment": { + "destPath": "foundation/napitest" + }, + "dirs": {}, + "scripts": {}, + "component": { + "name": "napitest", + "subsystem": "napitest", + "features": [], + "adapted_system_type": [ + "standard" + ], + "rom": "10000KB", + "ram": "10000KB", + "deps": { + "components": [ + "ace_napi", + "ipc_core", + "libhilog" + ], + "third_party": [ + "node" + ] + }, + "build": { + "sub_component": [ + "//foundation/napitest:napitest" + ], + "inner_kits": [ + { + "header": { + "header_base": "//foundation/napitest", + "header_files": [ + "tool_utility.h", + "napitest.h", + "napitest_middle.h" + ] + }, + "name": "//foundation/napitest:napitest" + } + ] + } + } +} +``` + +#### 修改napitest.cpp文件 + +在funcTest方法中增加业务逻辑: + +``` +out = v1 + v2; +``` + +#### 增加子系统 + +在源码/build/subsystem_config.json中增加子系统选项。如下所示: + +``` +"napitest": { + "path": "foundation/napitest", + "name": "napitest" + } +``` + +### 添加功能模块 + +在产品配置中添加上述子系统的功能模块,编译到产品产出文件中,例如在源码vendor/hihope/rk3568/config.json中增加part选项,其中第一个napitest就是BUILD.gn文件中的subsystem_name,第二个napitest就是BUILD.gn文件中的part_name。 + +``` +{ + "subsystem": "napitest", + "components": [ + { + "component": "napitest", + "features": [] + } + ] +} +``` + +### 编译验证 + +编译成功后,就会在 /out/产品名/packages/phone/system/lib/module/ 生成libnapitest.z.so,如下所示: + + /out/rk3568/packages/phone/system/lib/module + +## 3.1 版本 + +### bundle.json方式集成 + +#### 建立模块位置 + +模块目录理论上可在OpenHarmony工程的任一位置,假设OpenHarmony代码库的目录为OHOS_SRC,在OHOS_SRC/foundation目录下,建测试模块目录:napitest。napitest目录结构如下: + + napitest + |-- binding.gyp + |-- BUILD.gn + |-- bundle.json + |-- napitest.cpp + |-- napitest.h + |-- napitest_middle.h + |-- napitest_middle.cpp + |-- test.sh + |-- tool_utility.cpp + |-- tool_utility.h + +其中bundle.json为新增的编译配置文件,其它为工具生成的代码。 + +#### 编译修改点 + +##### 修改BUILD.gn文件 + +将deps中"//foundation/arkui/napi:ace_napi"的修改为"//foundation/ace/napi:ace_napi",修改后的BUILD.gn文件内容如下所示: + +``` +import("//build/ohos.gni") + +ohos_shared_library("napitest") +{ + sources = [ + "napitest_middle.cpp", + "../serviceCode/NodeISayHello.cpp", # 将业务代码编译进去 + "napitest.cpp", + "tool_utility.cpp", + ] + include_dirs = [ + ".", + "//third_party/node/src", + ] + deps=[ + "//foundation/ace/napi:ace_napi", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + ] + remove_configs = [ "//build/config/compiler:no_rtti" ] + cflags=[ + ] + cflags_cc=[ + "-frtti", + ] + ldflags = [ + ] + + relative_install_dir = "module" + part_name = "napitest" + subsystem_name = "napitest" +} ``` -在funcTest方法中增加普通函数的业务逻辑: +若用户需要修改子系统和部件名称,则根据自身需求修改BUILD.gn文件和bundle.json文件中子系统与部件名称即可。 + +##### 修改bundle.json文件 + +其中destPath选项中的"//foundation/napitest"指的是napitest目录,":napitest"指的是上面BUILD.gn中的目标ohos_shared_library("napitest")。 ``` -... -if (v) { - out = "ret is true"; -} else { - out = "ret is false"; +{ + "name": "@ohos/napitest", + "description": "napitest provides atomic capabilities", + "version": "3.1", + "license": "Apache License 2.0", + "publishAs": "code-segment", + "segment": { + "destPath": "foundation/napitest" + }, + "dirs": {}, + "scripts": {}, + "component": { + "name": "napitest", + "subsystem": "napitest", + "features": [], + "adapted_system_type": [ + "standard" + ], + "rom": "10000KB", + "ram": "10000KB", + "deps": { + "components": [ + "ace_napi", + "ipc_core", + "libhilog" + ], + "third_party": [ + "node" + ] + }, + "build": { + "sub_component": [ + "//foundation/napitest:napitest" + ], + "inner_kits": [ + { + "header": { + "header_base": "//foundation/napitest", + "header_files": [ + "tool_utility.h", + "napitest.h", + "napitest_middle.h" + ] + }, + "name": "//foundation/napitest:napitest" + } + ] + } + } } -... ``` -增加业务代码之后的文件如下所示: +##### 修改napitest.cpp文件 + +在funcTest方法中增加业务逻辑: -[napitest.cpp](https://gitee.com/openharmony/napi_generator/blob/master/examples/napitest.cpp) +``` +out = v1 + v2; +``` ##### 增加子系统 @@ -285,56 +635,12 @@ ohos_shared_library("napitest") ##### 修改napitest.cpp文件 -为方便调试,在napitest.cpp文件中增加业务代码。以修改napitest.cpp文件为例,在以下方法中增加业务代码, +在funcTest方法中增加业务逻辑: -在sayHello方法中增加注册的object回调方法的调用: - -``` -... -// 业务代码调用 onSayHelloStart callback -napitest::napitest_interface::NodeISayHello::listener_.NodeISayHelloListener_onSayHelloStartCallback(info1); -// 业务代码调用 onSayHelloEnd callback -napitest::napitest_interface::NodeISayHello::listener_.NodeISayHelloListener_onSayHelloEndCallback(info2); -... -``` - -在sayHi方法中增加register注册的回调方法的调用: - -``` -... -napitest::napitest_interface::NodeISayHello *ptr = new napitest::napitest_interface::NodeISayHello(); -uint32_t callbackNum = 50; -ptr->CallbackfuncCallback(callbackNum); -delete ptr; -... ``` - -在sayHelloWithResponse方法中增加Promise回调方法的调用: - -``` -... -out.errMsg = ""; -out.response = "rec hello."; -out.result = 0; -... +out = v1 + v2; ``` -在funcTest方法中增加普通函数的业务逻辑: - -``` -... -if (v) { - out = "ret is true"; -} else { - out = "ret is false"; -} -... -``` - -增加业务代码之后的文件如下所示: - -[napitest.cpp](https://gitee.com/openharmony/napi_generator/blob/master/examples/napitest.cpp) - ##### 增加子系统 在源码/build/subsystem_config.json中增加子系统选项。如下所示: @@ -360,3 +666,17 @@ if (v) { /out/ohos-arm-release/packages/phone/system/lib/module +## 总结 + +3.1版本两种集成方式使用场景说明: + +ohos.build方式集成:适合3.0前版本使用。 + +bundle.json方式集成:兼容ohos.build方式,但3.1及以后版本建议使用此种方式集成。 + +3.2版本适合使用bundle.json方式集成。 + +4.0版本适合使用bundle.json方式集成。 + +4.1版本适合使用bundle.json方式集成。 + diff --git a/docs/guide/ADD_SERVICECODE_INSTRUCTION.md b/src/cli/dts2cpp/docs/usage/dts2cpp_INSTRUCTION_ZH.md similarity index 53% rename from docs/guide/ADD_SERVICECODE_INSTRUCTION.md rename to src/cli/dts2cpp/docs/usage/dts2cpp_INSTRUCTION_ZH.md index a9280702dfe5847864e7234d5f24a5e8b30b3ba3..1722c535ff4ae9fd78ebadd9e56d583d9928638d 100644 --- a/docs/guide/ADD_SERVICECODE_INSTRUCTION.md +++ b/src/cli/dts2cpp/docs/usage/dts2cpp_INSTRUCTION_ZH.md @@ -1,7 +1,29 @@ -# 手动配置业务代码说明 +# dts2cpp工具使用说明 ## 简介 -工具生成框架代码时支持使用cfg.json文件配置业务代码,当用户自动配置业务代码无法达成目的时也可手动进行业务代码配置,本文主要介绍不使用配置文件cfg.json进行业务代码配置并生成框架代码的过程。 +dts2cpp工具即NAPI框架生成工具,该工具支持三种入口,分别是可执行程序、VS Code插件、DevEco Studio上使用的IntelliJ插件,使用者可以根据自己的需要选择合适的工具。 + +1.可执行文件下载路径如下(由于网络原因,可能会导致有的下载链接失效,因此提供了以下三个下载链接): + +[可执行文件下载链接1](http://ftpkaihongdigi.i234.me:5000/sharing/yaRiKSjBI) + +[可执行文件下载链接2](http://ftp.kaihong.com:5000/fsdownload/yaRiKSjBI/) + +[可执行文件下载链接3](http://ftp.kaihongdigi.com:5000/fsdownload/yaRiKSjBI/) + +访问密码:kaihong + +压缩包解压密码:kaihong20231121 + +DevEco Studio上使用的IntelliJ插件下载路径如下: + +[DevEco Studio上使用的IntelliJ插件下载链接](https://plugins.jetbrains.com/plugin/19593-napi-generator/versions) + +## 工具介绍 + +通过NAPI框架生成工具,使用者可输入一个接口定义的ts文件,一键生成NAPI框架代码、业务代码框架、GN脚本等文件,并使用生成的NAPI接口及功能。使用者也可以输入一个定义方法的.h头文件,反向生成ts文件。 + +![](../figures/pic-frm.png) ## 生成框架 @@ -9,14 +31,14 @@ #### Linux -1.将待转换的.d.ts文件、依赖文件basic.d.ts、napi_generator-linux放在同级目录下。此处新建generatorCode文件夹,用于存放生成框架代码。整体目录文件如下: +1.将待转换的.d.ts文件、napi_generator-linux放在同级目录下。此处新建out文件夹,用于存放生成框架代码。整体目录文件如下: OpenHarmony@Ubuntu-64:~/service$ ls - napi_generator-linux @ohos.napitest.d.ts basic.d.ts generatorCode + napi_generator-linux @ohos.napitest.d.ts out 2.在终端中进入到之前可执行程序napi_generator-linux所在的目录,并运行napi_generator-linux,命令如下: - OpenHarmony@Ubuntu-64:~/service$ ./napi_generator-linux -f @ohos.napitest.d.ts -o generatorCode -i false -n int + OpenHarmony@Ubuntu-64:~/service$ ./napi_generator-linux -f @ohos.napitest.d.ts -o out 其中,参数详情如下: @@ -34,26 +56,25 @@ 备注1:-f与-d两个参数只选其中一个参数即可。 - 备注2:若.d.ts文件中声明了basic.d.ts文件,将basic.d.ts文件放置在待转换.d.ts文件同一级目录;若除此之外还声明其它.d.ts文件,将此类文件放置在待转换.d.ts文件同级目录。 + 备注2:若.d.ts文件中声明其它.d.ts文件,将此类文件放置在待转换.d.ts文件同级目录。 -3.运行成功后会在generatorCode目录下生成框架代码文件,如下所示: +3.运行成功后会在out目录下生成框架代码文件,如下所示: - OpenHarmony@Ubuntu-64:~/linshi/napi_generator_8/examples/ts/generatorCode$ ls + OpenHarmony@Ubuntu-64:~/linshi/napi_generator_8/examples/ts/out$ ls binding.gyp BUILD.gn napi_gen.log napitest.cpp napitest.h napitest_middle.h napitest_middle.cpp test.sh tool_utility.cpp tool_utility.h #### Windows -1.将待转换的.d.ts文件、依赖文件basic.d.ts、napi_generator-win.exe放在同级目录下。此处新建generatorCode文件夹,用于存放生成框架代码。整体目录文件如下: +1.将待转换的.d.ts文件、napi_generator-win.exe放在同级目录下。此处新建out文件夹,用于存放生成框架代码。整体目录文件如下: E:\demo\napi>dir /B @ohos.napitest.d.ts - basic.d.ts napi_generator-win.exe - generatorCode + out 2.在终端中进入到之前可执行程序napi_generator-win.exe所在的目录,并运行napi_generator-win.exe,命令如下: - E:\demo\napi>napi_generator-win.exe -f @ohos.napitest.d.ts -o generatorCode -i false -n double + E:\demo\napi>napi_generator-win.exe -f @ohos.napitest.d.ts -o out 其中,参数详情如下: @@ -71,11 +92,11 @@ 备注1:-f与-d两个参数只选其中一个参数即可。 - 备注2:若.d.ts文件中声明了basic.d.ts文件,将basic.d.ts文件放置在待转换.d.ts文件同一级目录;若除此之外还声明其它.d.ts文件,将此类文件放置在待转换.d.ts文件同级目录。 + 备注2:若.d.ts文件中声明了其它.d.ts文件,将此类文件放置在待转换.d.ts文件同级目录。 -3.运行成功后会在generatorCode目录下生成框架代码文件,如下所示: +3.运行成功后会在out目录下生成框架代码文件,如下所示: - E:\demo\napi\generatorCode>dir /B + E:\demo\napi\out>dir /B binding.gyp BUILD.gn napitest.cpp @@ -95,16 +116,16 @@ 具体的插件使用步骤,可以左键单击以下链接了解: -[VS插件使用说明](https://gitee.com/openharmony/napi_generator/blob/master/napi_vs_plugin/docs/napi/INSTRUCTION_ZH.md) +[VS插件使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/vscode_plugin/dts2cpp/napi_vs_plugin/docs/usage/INSTRUCTION_ZH.md) ### DevEco Studio上使用的IntelliJ插件使用方法 具体的插件使用步骤,可以左键单击以下链接了解: -[DevEco Studio上使用的IntelliJ插件使用说明](https://gitee.com/openharmony/napi_generator/blob/master/napi_IntelliJ_plugin/docs/napi/INSTRUCTION_ZH.md) +[DevEco Studio上使用的IntelliJ插件使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/intellij_plugin/dts2cpp/napi_IntelliJ_plugin/docs/usage/INSTRUCTION_ZH.md) ## 集成测试 NAPI框架代码生成后,系统框架开发者进行二次开发后,即可集成到OpenHarmony编译系统,生成对应的库文件,供应用开发者调用接口。工具集成测试的具体操作步骤可以左键单击以下链接了解: - [工具集成测试](https://gitee.com/openharmony/napi_generator/blob/master/docs/guide/INTEGRATION_TESTING_ZH.md) +[工具集成测试](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/dts2cpp/docs/usage/dts2cpp_INTEGRATION_TESTING_ZH.md) diff --git a/src/cli/dts2cpp/docs/usage/dts2cpp_INTEGRATION_TESTING_ZH.md b/src/cli/dts2cpp/docs/usage/dts2cpp_INTEGRATION_TESTING_ZH.md new file mode 100644 index 0000000000000000000000000000000000000000..09cc4828040b8c3df3b97894782bc37630435a8b --- /dev/null +++ b/src/cli/dts2cpp/docs/usage/dts2cpp_INTEGRATION_TESTING_ZH.md @@ -0,0 +1,106 @@ +# NAPI框架生成工具集成测试 + +## 简介 + 本文主要介绍如何将NAPI框架生成代码集成到OpenHarmony系统,进而进行集成测试。 + +## 准备 + + 1.硬件:rk3568开发套件。 + + 2.系统镜像: + + 系统镜像的具体生成方法,可以左键单击以下链接了解: + + [生成代码集成到OpenHarmony](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/dts2cpp/docs/usage/dts2cpp_ENSEMBLE_METHOD_ZH.md) + +3. hap包 + +hap包的具体生成方法,可参考OpenHarmony/docs/zh-cn/application-dev文档中使用ArkTS语言开发(Stage模型)。 + +### 修改点1:扩展SDK接口 +1. 查看SDK目录:打开DevEco Studio ,点击 Tools -> SDK Manager -> SDK + + ![](../figures/DevEco_SDK_path.png) + +2. 将@ohos.napitest.d.ts文件拷贝到应用所使用的sdk目录下 的ets\api + + ![](../figures/DevEco_add_interface.png) + +### 修改点2:增加新接口调用 +其中修改index.ets文件内容如下: + +``` +import napitest from '@ohos.napitest'; + +@Entry +@Component +struct Index { + @State returnVal: number = 0 + + build() { + Row() { + Column() { + + // 调用普通函数 + Button() { + Text('调用funcTest方法') + .fontSize(20) + .fontWeight(FontWeight.Bold) + } + .type(ButtonType.Capsule) + .margin({ + top: 10 + }) + .backgroundColor('#0D9FFB') + .width('90%') + .height('5%') + .onClick( () => { + this.returnVal = napitest.funcTest(2, 3); + console.info("napiTestDemo ----funcTest returnVal = " + this.returnVal) + }) + + Text('funcTest返回值: returnVal = ' + this.returnVal).margin({ top: 10 }) + } + .width('100%') + } + .height('100%') + } +} +``` + +## 使用说明 + +步骤一:安装镜像环境:将out/rk3568/packages/phone目录下的images镜像文件下载并烧录到开发板上。 + + OpenHarmony@Ubuntu-64:~/OpenHarmony/out/rk3568/packages/phone/images$ ll + total 767452 + drwxrwxrwx 2 root root 4096 Nov 21 05:32 ./ + drwxrwxrwx 15 root root 4096 Nov 21 05:32 ../ + -rwxrwxrwx 1 root root 67108864 Nov 21 05:04 boot_linux.img* + -rw-r--r-- 1 root root 52428800 Nov 21 05:32 chip_prod.img + -rwxrwxrwx 1 root root 8569 Nov 21 05:04 config.cfg* + -rw-r--r-- 1 root root 12582912 Nov 21 05:32 eng_system.img + -rwxrwxrwx 1 root root 455104 Nov 21 05:04 MiniLoaderAll.bin* + -rwxrwxrwx 1 root root 756 Nov 21 05:04 parameter.txt* + -rw-rw-r-- 1 root root 2507625 Nov 21 05:32 ramdisk.img + -rwxrwxrwx 1 root root 5639680 Nov 21 05:04 resource.img* + -rw-r--r-- 1 root root 52428800 Nov 21 05:32 sys_prod.img + -rw-r--r-- 1 root root 1610608640 Nov 21 05:32 system.img + -rwxrwxrwx 1 root root 4194304 Nov 21 05:04 uboot.img* + -rw-rw-r-- 1 root root 15806303 Nov 21 05:32 updater.img + -rw-r--r-- 1 root root 1468006400 Nov 21 05:32 userdata.img + -rw-r--r-- 1 root root 268431360 Nov 21 05:32 vendor.img + +步骤二:安装hap包。 + + Build Haps通过后,通过Run按钮将hap包安装到板子上。 + + 执行完成后,设备中会出现安装的APP。 + +## 查看结果 + +点击”调用funcTest方法“按钮,funcTest返回值显示出 returnVal = 5 + +## 相关仓 + +暂无 diff --git a/README_zh.md b/src/cli/dts2cpp/dts2cpp_README.md old mode 100755 new mode 100644 similarity index 40% rename from README_zh.md rename to src/cli/dts2cpp/dts2cpp_README.md index a54c3f6194288caef54ad5c089ca748e27e52280..1f5e5d52f9dc212c6d869f1996c49684cbe53842 --- a/README_zh.md +++ b/src/cli/dts2cpp/dts2cpp_README.md @@ -1,149 +1,133 @@ -# NAPI框架生成工具 - -## 简介 -本文主要介绍NAPI框架代码生成工具,它可以根据用户指定路径下的ts(typescript)接口文件一键生成NAPI框架代码、业务代码框架、GN文件等。在开发JS应用与NAPI间接口时,底层框架开发者无需关注Nodejs语法、C++与JS之间的数据类型转换等上层应用转换逻辑,只关注底层业务逻辑即可,专业的人做专业的事,从而可以大大提高开发效率。目前工具支持可执行文件、VS Code插件、DevEco Studio上使用的IntelliJ插件三种入口。 - -更多工具的架构和实现原理详情,可以左键单击以下链接了解: - -[工具使用说明](https://gitee.com/openharmony/napi_generator/blob/master/docs/INSTRUCTION_ZH.md) - -## 目录 - - ├── napi_generator # NAPI框架代码生成工具 - │ ├── docs # 工具说明、版本规划 - │ ├── examples # 工具需要的文件样例 - │ ├── figures # 图片资源文件 - │ ├── hdc # hdc相关工具 - │ ├── napi_IntelliJ_plugin # Intellij IDEA插件代码 - │ ├── napi_vs_plugin # VS Code插件代码 - │ ├── release-notes # 发布说明 - │ ├── src # 工具源码 - │ │ ├── gen # napi工具源码 - │ │ | ├── analyze # 解析器 - │ │ | |── extend # 扩展模块,包括gn文件生成、linux环境适配代码等 - │ │ | |── generate # 生成器 - │ │ | └── tools # 公共模块代码,包括消息体校验、文件读写、正则表达式转换等 - │ │ ├── tsGen # TS工具源码 - │ ├── test # UT、ST测试 - │ ├── FAQ # NAPI框架工具问题反馈 - │ └── README # 工具使用指导 - -## 约束 -系统:建议Ubuntu 20.04或者Windows 10 - -依赖版本:VS Code 1.62.0 - -## 使用方法 - -### 使用对象 - -系统开发者 - -### 使用场景 - -1) 系统框架层新增子系统,需对应用层提供接口。 -2) 系统框架层子系统能力增强后,需对应用层提供新接口。 - -### 工具使用 - -工具有三种类型,分别是可执行文件、VS Code插件、DevEco Studio上使用的IntelliJ插件。其中的可执行文件可根据工具使用者的开发环境选择,支持Windows,Linux和Mac。可执行文件下载路径如下(由于网络原因,可能会导致有的下载链接失效,因此提供了以下三个下载链接): - -[可执行文件下载链接1](http://ftpkaihongdigi.i234.me:5000/sharing/yaRiKSjBI) - -[可执行文件下载链接2](http://ftp.kaihong.com:5000/fsdownload/yaRiKSjBI/) - -[可执行文件下载链接3](http://ftp.kaihongdigi.com:5000/fsdownload/yaRiKSjBI/) - -访问密码:kaihong - -压缩包解压密码:kaihong20231121 - -DevEco Studio上使用的IntelliJ插件下载路径如下: - -[DevEco Studio上使用的IntelliJ插件下载链接](https://plugins.jetbrains.com/plugin/19593-napi-generator/versions) - -具体的工具使用步骤,可以左键单击以下链接了解: - -[工具使用说明](https://gitee.com/openharmony/napi_generator/blob/master/docs/INSTRUCTION_ZH.md) - -### 工具输出 - -根据使用者指定的typescript文件,工具会输出NAPI框架代码、业务代码框架、GN脚本等文件。 - -为了方便使用者快速上手工具,可供测试的typescript文件存放在以下路径: - -``` -napi_generator/examples/ts -``` - -在window环境下的,根据输入文件@ohos.napitest.d.ts和basic.d.ts生成的输出文件,如下所示: - -![](./figures/pic-d-ts-transition.png) - -其中生成的"napitest.h"文件,定义了框架代码的接口,生成的部分接口如下所示: - -``` -... -class NodeISayHello { -public: - bool addSayHelloListener(NodeISayHelloListener& listener); - static NodeISayHelloListener listener_; - bool removeSayHelloListener(NodeISayHelloListener& listener); - bool registerCallbackfunc(); - // 供业务调用的回调接口 - void CallbackfuncCallback(NUMBER_TYPE_2& wid); - - bool unRegisterCallbackfunc(); - bool sayHello(std::string& from, std::string& to, NUMBER_TYPE_9& sayType); - bool sayHi(std::string& from, std::string& to, NUMBER_TYPE_10& sayType); - bool sayHelloWithResponse(std::string& from, std::string& to, NUMBER_TYPE_11& sayType, uint32_t& outErrCode, AUTO_INTERFACE_5& out); - static AUTO_INTERFACE_5 auto_interface_5OutRes; - void auto_interface_5SetCbValue(NUMBER_TYPE_6 result, std::string errMsg, std::string response); -}; -... -``` - -### 代码集成 - -为了实现工具生成的接口被其他子系统或者应用调用,需将生成的代码编译集成到OpenHarmony系统中,编译生成动态库。 - -把工具的生成代码集成到OpenHarmony的具体操作步骤,可以左键单击以下链接了解: - -[生成代码集成到OpenHarmony的方法](https://gitee.com/openharmony/napi_generator/blob/master/docs/ENSEMBLE_METHOD_ZH.md) - -## 工具开发说明 - -### 对象 - -工具的开发者 - -### 开发场景 - -若当前工具的功能已经不能满足开发者的全部需求,则开发者可以基于已有的源码对工具进行二次开发,来增强工具的能力,编译打包生成自定义的可执行文件和插件。 - -### 开发步骤 - -开发者可以根据如下的步骤来完成对工具的开发: - - [工具开发说明](https://gitee.com/openharmony/napi_generator/blob/master/docs/DEVELOP_ZH.md) - -## 版本说明 - - 当前版本已支持的特性和待开发的特性,如下所示: - - [已支持特性](https://gitee.com/openharmony/napi_generator/blob/master/release-notes) - - [待支持特性](https://gitee.com/openharmony/napi_generator/blob/master/docs/ROADMAP_ZH.md) - -## FAQ -对于常见问题解决方法指导如下: - - [FAQ](https://gitee.com/openharmony/napi_generator/blob/master/FAQ.md) - -## 参与贡献 - -暂无 - -## 相关仓 - -[ts生成工具README_zh](https://gitee.com/openharmony/napi_generator/blob/master/docs/ts/README_ZH.md) \ No newline at end of file +# dts2cpp工具 + +## 简介 +dts2cpp工具,即NAPI框架生成工具,它可以根据用户指定路径下的ts(typescript)接口文件一键生成NAPI框架代码、业务代码框架、GN文件等。在开发JS应用与NAPI间接口时,底层框架开发者无需关注js语法、C++与JS之间的数据类型转换等上层应用转换逻辑,只关注底层业务逻辑即可,专业的人做专业的事,从而可以大大提高开发效率。目前工具支持可执行文件、VS Code插件、DevEco Studio上使用的IntelliJ插件三种入口。 + +## 目录 + + ├── napi_generator # 工具集 + │ ├── ... # 其它文件 + │ ├── src + │ │ ├── ... + │ │ ├── cli + │ │ | ├── ... # 其它工具 + │ │ | ├── dts2cpp + │ │ | | ├── src/gen # napi工具源码 + │ │ | | | ├── analyze # 解析器 + │ │ | | | |── extend # 扩展模块,包括gn文件生成、linux环境适配代码等 + │ │ | | | |── generate # 生成器 + │ │ | | | └── tools # 公共模块代码,包括消息体校验、文件读写、正则表达式转换等 + │ │ | │ └── README # 工具使用指导 + +## 约束 +系统:建议Ubuntu 20.04或者Windows 10 + +依赖版本:VS Code 1.62.0 + +## 使用方法 + +### 使用对象 + +系统开发者 + +### 使用场景 + +1) 系统框架层新增子系统,需对应用层提供接口。 +2) 系统框架层子系统能力增强后,需对应用层提供新接口。 + +### 工具获取 + +工具有三种类型,分别是可执行文件、VS Code插件、DevEco Studio上使用的IntelliJ插件。其中的可执行文件可根据工具使用者的开发环境选择,支持Windows,Linux和Mac。 + +可执行文件下载路径如下(由于网络原因,可能会导致有的下载链接失效,因此提供了以下三个下载链接): + +[可执行文件下载链接1](http://ftpkaihongdigi.i234.me:5000/sharing/yaRiKSjBI) + +[可执行文件下载链接2](http://ftp.kaihong.com:5000/fsdownload/yaRiKSjBI/) + +[可执行文件下载链接3](http://ftp.kaihongdigi.com:5000/fsdownload/yaRiKSjBI/) + +访问密码:kaihong + +压缩包解压密码:kaihong20231121 + +DevEco Studio上使用的IntelliJ插件下载路径如下: + +[DevEco Studio上使用的IntelliJ插件下载链接](https://plugins.jetbrains.com/plugin/19593-napi-generator/versions) + +### 工具输入 + +根据使用者指定的typescript文件,工具会输出NAPI框架代码、业务代码框架、GN脚本等文件。 + +为了方便使用者快速上手工具,可供测试的typescript文件@ohos.napitest.d.ts示例如下: + +``` +declare namespace napitest { + function funcTest(v1: number, v2: number): number; +} + +export default napitest; +``` + +### 工具使用 + +具体的工具使用步骤,可以左键单击以下链接了解: + +[工具使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/dts2cpp/docs/usage/dts2cpp_INSTRUCTION_ZH.md) + +### 工具输出 + +在window环境下的,根据输入文件@ohos.napitest.d.ts生成的输出文件,如下所示: + +![](./docs/figures/pic-d-ts-transition_result.png) + +### 代码集成 + +为了实现工具生成的接口被其它子系统或者应用调用,需将生成的代码编译集成到OpenHarmony系统中,编译生成动态库。 + +把工具的生成代码集成到OpenHarmony的具体操作步骤,可以左键单击以下链接了解: + +[生成代码集成到OpenHarmony的方法](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/dts2cpp/docs/usage/dts2cpp_ENSEMBLE_METHOD_ZH.md) + +### 测试调用 + +为验证工具生成的接口是否可被应用调用,需编写app进行测试。具体如何操作可左键单击以下链接了解: + +[工具集成测试](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/dts2cpp/docs/usage/dts2cpp_INTEGRATION_TESTING_ZH.md) + +## 工具开发说明 + +### 对象 + +工具的开发者 + +### 开发场景 + +若当前工具的功能已经不能满足开发者的全部需求,则开发者可以基于已有的源码对工具进行二次开发,来增强工具的能力,编译打包生成自定义的可执行文件和插件。 + +### 开发步骤 + +开发者可以根据如下的步骤来完成对工具的开发: + + [工具开发说明](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/dts2cpp/docs/guide/DEVELOP_ZH.md) + +## 版本说明 + + 当前版本已支持的特性和待开发的特性,如下所示: + + [已支持特性](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/dts2cpp/docs/release-notes) + + [待支持特性](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/dts2cpp/docs/requirement/ROADMAP_ZH.md) + +## FAQ +对于常见问题解决方法指导如下: + + [FAQ](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/dts2cpp/docs/guide/FAQ.md) + +## 参与贡献 + +暂无 + +## 相关仓 + +[ts生成工具README_zh](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2dts/README_ZH.md) \ No newline at end of file diff --git a/docs/guide/ts/README_ZH.md b/src/cli/h2dts/h2dts_README_ZH.md similarity index 61% rename from docs/guide/ts/README_ZH.md rename to src/cli/h2dts/h2dts_README_ZH.md index 4d7538f645ac71cc704e687414e0915ced2a3374..7762c3ce0161c22751bdfed95ab7de2ea7689f3f 100644 --- a/docs/guide/ts/README_ZH.md +++ b/src/cli/h2dts/h2dts_README_ZH.md @@ -1,20 +1,18 @@ -# Ts接口生成工具 +# h2dts工具 ## 简介 -本文主要介绍ts(type-script)接口生成工具,它可以根据定义在c++头文件中的接口,生成type-script语言的ts接口文件。若某个服务实现方式为c++,且供应用层访问的接口已在.h文件中定义,此时,NAPI接口开发者使用此工具可一键生成对应的ts文件,进而将生成的ts文件作为NAPI框架生成代码工具的输入,生成NAPI框架代码。串行使用ts接口生成工具、NAPI框架代码生成工具,形成工具链,达到降低NAPI接口开发难度,提高开发效率。目前工具支持可执行文件、IntelliJ插件两种入口。 - -更多工具的架构和实现原理详情,可以左键单击以下链接了解: - -[工具使用说明](https://gitee.com/openharmony/napi_generator/tree/master/docs/guide/ts/INSTRUCTION_ZH.md) - - ├── napi_generator # NAPI框架代码生成工具 - │ ├── ... # 其他文档 - │ ├── src # 工具源码 - │ │ ├── gen # NAPI框架工具源码 - │ │ ├── tsGen # Ts框架工具源码 - │ │ | ├── header_parser.py # 解析C++头文件并生成表示类的数据结构 - │ │ | |── tsMain.js # Ts框架工具源码入口 - │ │ ├── ... # 其他文件 +h2dts工具,即Ts接口生成工具,它可以根据定义在c++头文件中的接口,生成type-script语言的ts接口文件。若某个服务实现方式为c++,且供应用层访问的接口已在.h文件中定义,此时,NAPI接口开发者使用此工具可一键生成对应的ts文件,进而将生成的ts文件作为NAPI框架生成代码工具的输入,生成NAPI框架代码。串行使用ts接口生成工具、NAPI框架代码生成工具,形成工具链,达到降低NAPI接口开发难度,提高开发效率。目前工具支持可执行文件、IntelliJ插件两种入口。 + + ├── napi_generator # 工具集 + │ ├── ... # 其它文件 + │ ├── src + │ │ ├── ... + │ │ ├── cli + │ │ | ├── ... # 其它工具 + │ │ | ├── h2dts/src # 工具源码 + │ │ │ │ ├── tsGen # Ts框架工具源码 + │ │ | │ │ ├── header_parser.py # 解析C++头文件并生成表示类的数据结构 + │ │ | │ │ |── tsMain.js # Ts框架工具源码入口 ## 约束 系统:建议Ubuntu 20.04或者Windows 10 @@ -33,17 +31,13 @@ 2) 系统框架层子系统能力增强后,需对应用层提供新接口。 3) 应用层引入C++三方库,需增加OpenHarmony应用层接口。 -### 工具使用 +### 工具获取 -工具有两种类型,分别是可执行文件、IntelliJ插件。其中的可执行文件可根据工具使用者的开发环境选择,支持Windows,Linux和Mac。可执行文件、IntelliJ插下载路径如下,选择napi_generator_outputs.zip中generator.jar下载: +工具有两种类型,分别是可执行文件、IntelliJ插件。其中的可执行文件可根据工具使用者的开发环境选择,支持Windows,Linux和Mac。可执行文件、IntelliJ插下载路径如下: [下载链接](http://ftp.kaihongdigi.com:5000/fsdownload/mKjfCmPjk/generator_outputs_NAPI_0930) -具体的工具使用步骤,可以左键单击以下链接了解: - -[工具使用说明](https://gitee.com/openharmony/napi_generator/tree/master/docs/guide/ts/INSTRUCTION_ZH.md) - -### 工具输出 +### 工具输入 根据使用者指定的.h文件,工具会输出对应的ts接口文件。为了方便使用者快速上手工具,可供测试的test.h文件样例如下: @@ -70,9 +64,17 @@ } ``` +### 工具使用 + +具体的工具使用步骤,可以左键单击以下链接了解: + +[工具使用说明](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/h2dts/docs/usage/INSTRUCTION_ZH.md) + +### 工具输出 + 在window环境下的,根据输入文件test.h,生成的输出文件,如下所示: -![](../../../figures/h-2-ts-succ.png) +![](./docs/figures/h-2-ts-succ.png) 其中生成的"test.d.ts"文件,定义了应用开发接口,如下所示: @@ -107,15 +109,15 @@ 开发者可以根据如下的步骤来完成对工具的开发: - [工具开发说明](https://gitee.com/openharmony/napi_generator/tree/master/docs/guide/ts/DEVELOP_ZH.md) + [工具开发说明](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/h2dts/docs/guide/DEVELOP_ZH.md) ## 版本说明 - [版本说明](https://gitee.com/openharmony/napi_generator/blob/master/docs/guide/ts/ts_Gen-1.0.md) + [版本说明](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2dts/docs/release-notes/ts_Gen-1.0.md) ## FAQ - [FAQ](https://gitee.com/openharmony/napi_generator/tree/master/docs/guide/ts/FAQ.md) + [FAQ](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/h2dts/docs/guide/FAQ.md) ## 参与贡献 diff --git a/src/cli/h2dtscpp/README.md b/src/cli/h2dtscpp/README.md index 4e887e29de4301439b852f1c6dd9e77407492f7f..3a4179bf45b48afd470629d6645383c25d413eee 100644 --- a/src/cli/h2dtscpp/README.md +++ b/src/cli/h2dtscpp/README.md @@ -1,8 +1,8 @@ -# NATIVE生成工具 +# h2dtscpp工具 ## 简介 -native生成工具由由C++语法解释器和代码生成器两部分组成。C++语法解释器解析用户输入的.h文件内容,通过C++语法解析,将文件内容分解为类、方法、入参、成员属性等元素;代码生成器根据从语法解析器得到的这些元素,转换为对应的typescript语法的接口、方法、参数代码,生成.ts文件内容;同时通过语法解析器得到的元素,生成.h文件对应的napi框架代码和接口调用测试代码。 +h2dtscpp工具即NATIVE生成工具,该工具由C++语法解释器和代码生成器两部分组成。C++语法解释器解析用户输入的.h文件内容,通过C++语法解析,将文件内容分解为类、方法、入参、成员属性等元素;代码生成器根据从语法解析器得到的这些元素,转换为对应的typescript语法的接口、方法、参数代码,生成.ts文件内容;同时通过语法解析器得到的元素,生成.h文件对应的napi框架代码和接口调用测试代码。 ## 目录 @@ -11,8 +11,8 @@ native生成工具由由C++语法解释器和代码生成器两部分组成。C+ │ ├── ... # 其他文档 │ ├── src │ │ ├── ... -│ │ ├── cml # 命令行 -│ │ | ├── h2dtscpp/src # 工具源码 +│ │ ├── cli # 命令行 +│ │ | ├── h2dtscpp/src # 工具源码 │ │ | | ├── src │ │ | | | ├── json # 生成框架模板 │ │ | | | ├── napiGen # 生成.cpp框架代码文件和.test.ets测试文件 @@ -37,13 +37,37 @@ native生成工具由由C++语法解释器和代码生成器两部分组成。C+ 应用层引入C++三方库,需增加OpenHarmony应用层接口。 +### 工具输入 + +.h接口文件,如 [cJSON测试三方库](https://gitee.com/openharmony/napi_generator/releases/tag/测试用资源) 的cJSON.h + ### 工具使用 [工具使用说明](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/h2dtscpp/docs/usage/INSTRUCTION_ZH.md) +### 工具输出 + +输出dts声明文件、接口测试文件.test.ets、接口实现文件.cpp文件 + +输出整体文件夹目录如下: + +![](./docs/figures/h2dtscpp_out_example.png) + +tsout文件夹下内容如下所示: + +![](./docs/figures/h2dtscpp_dtsout_example.png) + +testout文件夹下内容如下所示: + +![](./docs/figures/h2dtscpp_testout_example.png) + +cppout文件夹下内容(部分文件截图)如下所示: + +![](./docs/figures/h2dtscpp_cppout_example.png) + ## 工具开发说明 -暂无 +[工具使用说明](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/h2dtscpp/docs/guide/DEVELOP_ZH.md) ## 版本说明 diff --git a/src/cli/h2dtscpp/docs/figures/h2dtscpp_cppout_example.png b/src/cli/h2dtscpp/docs/figures/h2dtscpp_cppout_example.png new file mode 100644 index 0000000000000000000000000000000000000000..1b9166bfe7537f80f3c652738b7eea3bcf67d926 Binary files /dev/null and b/src/cli/h2dtscpp/docs/figures/h2dtscpp_cppout_example.png differ diff --git a/src/cli/h2dtscpp/docs/figures/h2dtscpp_dtsout_example.png b/src/cli/h2dtscpp/docs/figures/h2dtscpp_dtsout_example.png new file mode 100644 index 0000000000000000000000000000000000000000..a64ed6ec6210d1361a33c8c2c06273c0629c0ae7 Binary files /dev/null and b/src/cli/h2dtscpp/docs/figures/h2dtscpp_dtsout_example.png differ diff --git a/src/cli/h2dtscpp/docs/figures/h2dtscpp_out_example.png b/src/cli/h2dtscpp/docs/figures/h2dtscpp_out_example.png new file mode 100644 index 0000000000000000000000000000000000000000..3df9386f434003ab62e2284804ba19e91b4304ec Binary files /dev/null and b/src/cli/h2dtscpp/docs/figures/h2dtscpp_out_example.png differ diff --git a/src/cli/h2dtscpp/docs/figures/h2dtscpp_testout_example.png b/src/cli/h2dtscpp/docs/figures/h2dtscpp_testout_example.png new file mode 100644 index 0000000000000000000000000000000000000000..c14b3398cb96901356a1cb9a83032ebae9eb909b Binary files /dev/null and b/src/cli/h2dtscpp/docs/figures/h2dtscpp_testout_example.png differ diff --git a/src/cli/h2sa/docs/usage/h2sa_ENSEMBLE_METHOD_ZH.md b/src/cli/h2sa/docs/usage/h2sa_ENSEMBLE_METHOD_ZH.md new file mode 100644 index 0000000000000000000000000000000000000000..7f28db3283afaad8c3ac64521340c42293196dd5 --- /dev/null +++ b/src/cli/h2sa/docs/usage/h2sa_ENSEMBLE_METHOD_ZH.md @@ -0,0 +1,330 @@ +# h2sa工具集成到OpenHarmony的方法 + +## 场景说明 + +为了实现工具生成的接口被其它子系统或者应用调用,需将生成的代码经系统框架开发者二次开发后编译集成到OpenHarmony系统中,使其生成动态库,供OpenHarmony应用层调用。本文介绍如何将工具生成的源码利用OpenHarmony编译系统生成动态库供应用层调用。 + +## 编译 + +将生成的整个testservice目录复制到OpenHarmony源码根目录下(与base、foundation目录平级) + +### OpenHarmony 3.1 release + +#### 修改系统公共文件 + +1. 服务配置 + foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include/system_ability_definition.h增加以下两行(ID说明: TEST_SERVICE_ID值与用户指定的ID一致;TEST_SERVICE_ID宏值定义必须为这个,因为代码中使用的就是这个) + + ``` + TEST_SERVICE_ID = 9016, + {TEST_SERVICE_ID, "testservice" }, + ``` + +2. 子系统配置 + build/subsystem_config.json + 增加以下内容 + + ``` + "testservice": { + "path":"testservice", + "name": "testservice" + } + ``` + +3. 产品配置,如Hi3516DV300 + productdefine/common/products/Hi3516DV300.json + +``` + "testservice:testservice_part":{} +``` + +### OpenHarmony 3.2 release + +#### 修改编译文件 + +1. 修改testservice/BUILD.gn文件,将utils/native 改为 commonlibrary/c_utils,将samgr_standard改为samgr。修改后的BUILD.gn文件内容如下所示: + + ``` + import("//build/ohos.gni") + + ohos_shared_library("testservice") { + sources = [ + "//testservice/src/i_test_service.cpp", + "//testservice/src/test_service_stub.cpp", + "//testservice/src/test_service.cpp" + ] + include_dirs = [ + "//testservice/include", + "//testservice/interface", + "//commonlibrary/c_utils/base/include" + ] + + deps = [ + "//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara", + "//commonlibrary/c_utils/base:utils", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "startup_l2:syspara", + ] + + part_name = "testservice_part" + subsystem_name = "testservice" + } + + ohos_executable("testclient") { + sources = [ + "//testservice/src/i_test_service.cpp", + "//testservice/src/test_service_proxy.cpp", + "//testservice/src/test_client.cpp" + ] + + include_dirs = [ + "//testservice/include", + "//testservice/interface", + "//commonlibrary/c_utils/base/include" + ] + + deps = [ + "//commonlibrary/c_utils/base:utils", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] + + part_name = "testservice_part" + subsystem_name = "testservice" + } + + ``` + +2. 修改testservice/bundle.json文件,将"name": "@ohos/testservice"修改为 "name": "@ohos/testservice_part";将"samgr_standard"改为"samgr","utils_base"修改为"c_utils";修改后的bundle.json文件内容如下所示: + + ``` + { + "name": "@ohos/testservice_part", + "description": "system ability framework test", + "homePage": "https://gitee.com/", + "version": "3.1", + "license": "Apache License 2.0", + "repository": "", + "publishAs": "code-segment", + "segment": { + "destPath": "testservice" + }, + "dirs": {}, + "scripts": {}, + "component": { + "name": "testservice_part", + "subsystem": "testservice", + "adapted_system_type": [ + "standard" + ], + "rom": "2048KB", + "ram": "~4096KB", + "deps": { + "components": [ + "hiviewdfx_hilog_native", + "ipc", + "samgr", + "c_utils", + "safwk", + "startup_l2" + ], + "third_party": [ "libxml2" ] + }, + "build": { + "sub_component": [ + "//testservice:testservice", + "//testservice/sa_profile:testservice_sa_profile", + "//testservice:testclient", + "//testservice/etc:test_service_init" + ], + "inner_kits": [ + ], + "test": [ + ] + } + } + } + ``` + +#### 修改系统公共文件 + +##### 基础配置 + +1. 服务配置 + + foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include/system_ability_definition.h增加以下两行(ID说明: TEST_SERVICE_ID值与用户指定的ID一致;TEST_SERVICE_ID宏值定义必须为这个,因为代码中使用的就是这个) + + ``` + TEST_SERVICE_ID = 9016, + {TEST_SERVICE_ID, "testservice" }, + ``` + +2. 子系统配置 + + build/subsystem_config.json + + 增加以下内容 + + ``` + "testservice": { + "path":"testservice", + "name": "testservice" + } + ``` + +3. 产品配置,如rk3568 + + vendor/hihope/rk3568/config.json + + 若用户不需要配置selinux,则将"build_selinux"属性改为false + + ``` + "build_selinux": false, + ``` + + 增加以下内容 + + ``` + { + "subsystem": "testservice", + "components": [ + { + "component": "testservice_part", + "features": [] + } + ] + } + ``` + + 注意:若用户需要配置selinux相关配置,则将开关改为true,再根据自身需求进行相关配置 + +4. 权限配置 + + 在相应产品目录下 + + vendor/hihope/rk3568/security_config/high_privilege_process_list.json + + 增加以下内容 + + ``` + { + "name": "testservice", + "uid": "system", + "gid": ["root", "system"] + } + ``` + +##### selinux权限配置 + +若要配置selinux权限,首先应将vendor/hihope/rk3568/config.json中"build_selinux"属性改为true,然后修改以下文件: + +1. testservice/etc/sample_service.cfg + + ``` + "secon" : "u:r:testservice:s0" + ``` + +2. base/security/selinux/sepolicy/base/public/service_contexts + + ``` + 9016 u:object_r:sa_testservice:s0 + ``` + +3. base/security/selinux/sepolicy/base/public/service.te + + ``` + type sa_testservice, sa_service_attr; + ``` + +4. base/security/selinux/sepolicy/base/te/init.te + + ``` + allow init testservice:process { getattr rlimitinh siginh transition }; + ``` + +5. base/security/selinux/sepolicy/base/public/type.te + + ``` + type testservice, sadomain, domain; + ``` + +6. /base/security/selinux/sepolicy/base/te目录下增加新service的te文件,新增文件名即为服务名,例如:testservice + + ``` + allow testservice init_param:file { map open read }; + allow testservice sa_testservice:samgr_class { add get }; + ``` + +### OpenHarmony 4.1 release + +[Service框架生成代码集成到OpenHarmony 4.1 Release的方法](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2sa/docs/usage/h2sa_ENSEMBLE_METHOD_ZH_4-1RELEASE.md) + +### 补充 服务端/客户端 业务逻辑实现 + +**服务端** +test_service.cpp +在testservice/src/test_service.cpp注释“// TODO: Invoke the business implementation”处添加各个接口的服务端实现代码,当前版本生成服务端代码需要用户先初始化,给int ret值赋初值0,如下所示: + +![](./../figures/service_init_example.png) + +远程方法的参数包装已在生成代码test_service_stub.cpp中统一处理,开发人员无需关注 + +**客户端** +test_client.cpp 为自动生成的客户端样例代码。编译烧录后,会在/system/bin/目录下生成可执行程序test_client +在testservice/src/test_client.cpp的main函数中使用proxy对象进行远程方法调用,参考注释示例。如下图: + +![](./../figures/service_client_proxy_example.png) + +远程方法的参数包装已在生成代码test_service_proxy.cpp中统一处理,开发人员无需关注 + +编码完成后,执行镜像编译命令 + +``` +./build.sh --product-name 产品名 +``` + +如:若编译Hi3516DV300开发板,则执行 + +``` +./build.sh --product-name Hi3516DV300 +``` + +若编译rk3568开发板,则执行 + +``` +./build.sh --product-name rk3568 +``` + +## 运行 + +将编译好的镜像烧录到开发板后,使用hdc_std shell登录开发板。 +查看服务端进程是否已正常启动 + +``` +ps -ef | grep testservice +system 288 1 0 00:02:13 ? 00:00:00 testservice_sa --- 服务进程已正常运行 +``` + +如下图所示: + +![](./../figures/service_init_success.png) + +运行客户端 + +``` +/system/bin/testclient +``` + + + (客户端具体执行哪些远程调用方法请在test_client.cpp的main方法中实现) + diff --git a/src/cli/h2sa/docs/usage/h2sa_ENSEMBLE_METHOD_ZH_4-1RELEASE.md b/src/cli/h2sa/docs/usage/h2sa_ENSEMBLE_METHOD_ZH_4-1RELEASE.md new file mode 100644 index 0000000000000000000000000000000000000000..e0c388efde6a30438661fb10eee38ad196d48df7 --- /dev/null +++ b/src/cli/h2sa/docs/usage/h2sa_ENSEMBLE_METHOD_ZH_4-1RELEASE.md @@ -0,0 +1,238 @@ +# h2sa工具集成到OpenHarmony 4.1 Release的方法 + +## 场景说明 + +为了实现工具生成的接口被其它子系统或者应用调用,需将生成的代码经系统框架开发者二次开发后编译集成到OpenHarmony系统中,使其生成动态库,供OpenHarmony应用层调用。本文介绍如何将工具生成的源码集成到OpenHarmony 4.1 relsease + +## OpenHarmony 4.1 release + +### 修改编译文件 + +1. 修改testservice/BUILD.gn文件,将utils/native 改为 commonlibrary/c_utils,将samgr_standard改为samgr,− 将hiviewdfx_hilog_native改为hilog,在ohos_shared_library("testservice")中include_dirs内新增"//base/startup/init/interfaces/innerkits/include/syspara",将ohos_shared_library("testservice")中的deps删除,并删除external_deps中的"startup_l2:syspara",同时在external_deps中新增"c_utils:utils", 将ohos_executable("testclient")中的deps删除,同时在external_deps中新增"c_utils:utils"。修改后的BUILD.gn文件内容如下所示: + + ``` + import("//build/ohos.gni") + + ohos_shared_library("testservice") { + sources = [ + "//testservice/src/i_test_service.cpp", + "//testservice/src/test_service_stub.cpp", + "//testservice/src/test_service.cpp" + ] + include_dirs = [ + "//testservice/include", + "//testservice/interface", + "//commonlibrary/c_utils/base/include", + "//base/startup/init/interfaces/innerkits/include/syspara", + ] + + external_deps = [ + "hilog:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "c_utils:utils", + ] + + part_name = "testservice_part" + subsystem_name = "testservice" + } + + ohos_executable("testclient") { + sources = [ + "//testservice/src/i_test_service.cpp", + "//testservice/src/test_service_proxy.cpp", + "//testservice/src/test_client.cpp" + ] + + include_dirs = [ + "//testservice/include", + "//testservice/interface", + "//commonlibrary/c_utils/base/include", + ] + + external_deps = [ + "hilog:libhilog", + "ipc:ipc_core", + "samgr:samgr_proxy", + "c_utils:utils", + ] + + part_name = "testservice_part" + subsystem_name = "testservice" + } + ``` + +2. 修改testservice/bundle.json文件,将"name": "@ohos/testservice"修改为 "name": "@ohos/testservice_part";将"samgr_standard"改为"samgr","utils_base"修改为"c_utils";将"hiviewdfx_hilog_native"修改为"hilog";− 将"deps":"components"下的"starup_l2"删除。修改后的bundle.json文件内容如下所示: + + ``` + { + "name": "@ohos/testservice_part", + "description": "system ability framework test", + "homePage": "https://gitee.com/", + "version": "4.1", + "license": "Apache License 2.0", + "repository": "", + "publishAs": "code-segment", + "segment": { + "destPath": "testservice" + }, + "dirs": {}, + "scripts": {}, + "component": { + "name": "testservice_part", + "subsystem": "testservice", + "adapted_system_type": [ + "standard" + ], + "rom": "2048KB", + "ram": "~4096KB", + "deps": { + "components": [ + "hilog", + "ipc", + "samgr", + "c_utils", + "safwk" + ], + "third_party": [ "libxml2" ] + }, + "build": { + "sub_component": [ + "//testservice:testservice", + "//testservice/sa_profile:testservice_sa_profile", + "//testservice:testclient", + "//testservice/etc:test_service_init" + ], + "inner_kits": [ + ], + "test": [ + ] + } + } + } + ``` + +3. 步骤 1 修改testservice/sa_profile下的文件以及testservice/etc/test_service.cfg文件, 将testservice/sa_profile/9016.xml文件重命名为9016.json,并将内容修改为json格式,修改后的9016.json文件如下所示: + + ``` + { +   "process":"testservice_sa", +       "systemability":[ +           { +               "name":9016, +               "libpath":"libtestservice.z.so", +               "run-on-create":false, +               "auto-restart":true, +               "distributed":false, +               "dump-level":1 +           } +       ] + } + ``` + + 修改testservice/sa_profile/BUILD.gn文件:将sources = [ "9016.xml" ]修改为sources = [ "9016.json" ] + + 修改testservice/etc/test_service.cfg文件:将"path"内的testservice_sa.xml修改为testservice_sa.json + +### 修改系统公共文件 + +#### 基础配置 + +1. 服务配置 + + 在foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include/ + + system_ability_definition.h增加以下一行: + + ``` + TEST_SERVICE_ID = 9016, + ``` + + 其中,TEST_SERVICE_ID宏值与用户定义的serviceID一致。 + +2. 子系统配置 + + 在build/subsystem_config.json中增加以下内容。 + + ``` + "testservice": { + "path":"testservice", + "name": "testservice" + } + ``` + +3. 产品配置,如rk3568 + + 在vendor/kaihong/rk3568/config.json中增加以下内容: + + ``` + { + "subsystem": "testservice", + "components": [ + { + "component": "testservice_part", + "features": [] + } + ] + } + ``` + +4. 权限配置 + + 在相应的产品目录的vendor/kaihong/rk3568/security_config/high_privilege_process_list.json中增加以下内容: + + ``` + { + "name": "testservice", + "uid": "system", + "gid": ["root", "system"] + } + ``` + +#### selinux权限配置 + +上述基础配置时关闭了selinux 权限配置,用户新增服务时需根据自身需求配置selinux 权限 。 + +若要配置selinux权限,首先应将vendor/hihope/rk3568/config.json中"build_selinux"属性改为true,然后修改以下文件: + +1. testservice/etc/sample_service.cfg + + ``` + "secon" : "u:r:testservice:s0" + ``` + +2. base/security/selinux_adapter/sepolicy/base/public/service_contexts + + ``` + 9016 u:object_r:sa_testservice:s0 + ``` + +3. base/security/selinux_adapter/sepolicy/base/public/service.te + + ``` + type sa_testservice, sa_service_attr; + ``` + +4. base/security/selinux_adapter/sepolicy/ohos_policy/startup/init/system/init.te + + ``` + allow init testservice:process { getattr rlimitinh siginh transition }; + ``` + +5. base/security/selinux/sepolicy/base/public/type.te + + ``` + type testservice, sadomain, domain; + ``` + +6. /base/security/selinux/sepolicy/base/te目录下增加新service的te文件,新增文件名即为服务名,例如:testservice.te + + ``` + allow testservice init_param:file { map open read }; + allow testservice sa_testservice:samgr_class { add get }; + ``` + + + + diff --git a/src/cli/h2sa/docs/usage/h2sa_INSTRUCTION_ZH.md b/src/cli/h2sa/docs/usage/h2sa_INSTRUCTION_ZH.md new file mode 100644 index 0000000000000000000000000000000000000000..c11a89ce3a86037afbff4ff123ace84f00ba372b --- /dev/null +++ b/src/cli/h2sa/docs/usage/h2sa_INSTRUCTION_ZH.md @@ -0,0 +1,95 @@ +# h2sa工具使用说明 +## 简介 + +h2sa工具,即SERVICE框架生成工具,该工具支持命令行和VS Code插件,使用者可以根据自己的需要下载工具使用。 + +## 工具介绍 + +通过SERVICE框架生成工具,使用者只需提供一个定义远程方法的.h头文件,一键生成SERVICE框架代码,主要包含Ability注册、proxy/stub类实现、MessageParcel数据包构造、Service子系统编译及开机自启动相关配置文件。 + +![](../figures/pic-service-frm.png) + +## 准备 + +下载python脚本可执行程序header_parser.exe(linux系统为header_parser),下载链接如下: + +[下载链接1](http://ftpkaihongdigi.i234.me:5000/sharing/kBG1c7CvT) + +[下载链接2](http://ftp.kaihong.com:5000/sharing/kBG1c7CvT) + +[下载链接3](http://ftp.kaihongdigi.com:5000/sharing/kBG1c7CvT) + +获取命令行可执行程序service-gen-win.exe、service-gen-linux,用户可根据以下步骤生成命令行可执行程序: + +[工具开发说明](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/h2sa/docs/guide/DEVELOP_ZH.md) + +## 生成框架 + +### 可执行程序使用方法 + +#### Linux + +1.将待转换的.h文件放到任意目录下,建议放到可执行程序service-gen-linux与header_parser同级目录下,如下所示: + + OpenHarmony@Ubuntu-64:~/service/napi_generator_8/hdc/service-gen/examples$ ls + test.h header_parser service-gen-linux + +2.在终端中进入到可执行程序service-gen-linux所在的目录,并运行service-gen-linux,命令如下: + + OpenHarmony@Ubuntu-64:~/service/napi_generator_8/hdc/service-gen/examples$ ./service-gen-linux -f test.h -o ./ -s 9016 + +其中,参数详情如下: + -f,定义远程服务的.h文件; + -l, 日志级别(0-3),默认为1; + -o, 生成框架代码输入到指定路径下; + -s, 指定serviceID。 + +3.运行成功后会在当前目录下生成对应的文件,如下所示: + + OpenHarmony@Ubuntu-64:~/service/napi_generator_8/hdc/service-gen/examples$ ls + test.h header_parser napi_gen.log service-gen-linux testservice + +#### Windows + +1.将要转换的.h文件放到任意目录下,建议放到可执行程序service-gen-win.exe与header_parser.exe同级目录下,如下所示: + + E:\demo\service>dir /B + test.h + header_parser.exe + service-gen-win.exe + +2.在终端中进入到可执行程序service-gen-win.exe所在的目录,并运行service-gen-win.exe,命令如下: + + E:\demo\service>service-gen-win.exe -f test.h -o ./ -s 9016 + +其中,参数详情如下: + -f,定义远程服务的.h文件; + -l, 日志级别(0-3),默认为1; + -o,生成框架代码输入到指定路径下; + -s,指定serviceID。 + +3.运行成功后会在当前目录下生成对应的文件,如下所示: + + E:\demo\service>dir /B + test.h + header_parser.exe + napi_gen.log + service-gen-win.exe + testservice + +#### Mac + +方法步骤参考windows、Linux的使用方法。 + +### VS Code插件使用方法 + +具体的插件使用步骤,可以左键单击以下链接了解: + +[VS插件使用说明](https://gitee.com/openharmony/napi_generator/tree/master/src/vscode_plugin/h2sa/service_vs_plugin/docs/usage/INSTRUCTION_ZH.md) + +## 集成 + +Service框架代码生成后,系统框架开发者进行二次开发后,即可集成到OpenHarmony编译系统,生成对应的库文件,供应用开发者调用接口。工具集成到OpenHarmony的具体操作步骤可以左键单击以下链接了解: + +[工具集成](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2sa/docs/usage/h2sa_ENSEMBLE_METHOD_ZH.md) + diff --git a/src/cli/h2sa/h2sa_README_ZH.md b/src/cli/h2sa/h2sa_README_ZH.md new file mode 100644 index 0000000000000000000000000000000000000000..3187be99b81b95872c2603eb687e2a549784b37d --- /dev/null +++ b/src/cli/h2sa/h2sa_README_ZH.md @@ -0,0 +1,119 @@ +# h2sa工具 + +## 简介 + +h2sa工具,即SERVICE框架生成工具,当开发者为OpenHarmony系统框架开发某些功能时,有时需要将这个功能包装成一个独立的服务进程运行在系统中,为了其它应用进程能够调用此服务,开发人员需要基于系统IPC通信框架编写一套远程接口调用实现。实现Service远程调用接口需要开发人员熟悉IPC通信框架,了解proxy/stub的继承与实现方式,掌握C++类型转为MessageParcel数据包的各种API方法,有一定的学习成本。而Service代码生成工具能够帮助使用者生成框架代码,提升开发效率。用户只需提供一个定义远程方法的.h头文件,工具会自动生成整个Service框架的代码,包含Ability注册、proxy/stub类实现、MessageParcel数据包构造、Service子系统编译及开机自启动相关配置文件。目前工具支持命令行和VS Code插件两种入口。 + + ├── napi_generator # NAPI框架代码生成工具 + │ ├── ... # 其它文档 + │ ├── src + │ │ ├── ... + │ │ ├── cli # 脚手架源码 + │ │ | ├── h2sa/src # 工具源码 + │ │ | | ├── src + │ │ | | | ├── tools # 公共模块代码,包括消息体校验、文件读写、正则表达式转换等 + │ │ | | | ├── gen # 生成器 + │ │ | | ├── package.json # 配置文件 + │ │ | ├── ... # 其它工具 + +## 约束 +系统:建议Ubuntu 20.04或者Windows 10 + +依赖版本:VS Code 1.62.0 + +## 使用方法 + +### 使用对象 + +系统开发者 +### 使用场景 + +1) 开发者为OpenHarmony系统框架开发某些功能,并将该功能包装成一个独立的服务进程运行在系统中。 + +### 工具输入 + +根据使用者指定的.h头文件,工具会输出SERVICE框架代码。为了方便使用者快速上手工具,可供测试的.h文件如下所示: + +``` +#ifndef TEST_H +#define TEST_H + +namespace OHOS { + namespace Example { + /** + * @brief service服务,提供IPC调用接口 + * @ServiceClass + */ + class test { + public: + int testFunc(int v1, int v2, bool v3); + }; + } // namespace Example +} // namespace OHOS +#endif // TEST_H +``` + +注意:.h文件中待生成的主class必须加注释:@brief service服务,提供IPC调用接口 ,如下所示: + +``` +/** + * @brief service服务,提供IPC调用接口 + * @ServiceClass + */ +``` + +### 工具使用 + +#### 命令行使用方法 + +[命令行使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2sa/docs/usage/h2sa_INSTRUCTION_ZH.md) + +#### VS Code插件使用方法 + +具体的插件使用步骤,可以左键单击以下链接了解: + +[vscode工具使用说明](https://gitee.com/openharmony/napi_generator/tree/master/src/vscode_plugin/h2sa/service_vs_plugin/docs/usage/INSTRUCTION_ZH.md) + +### 工具输出 + +在window环境下的,根据输入.h文件生成的输出文件,如下所示: + +![](./docs/figures/service_framework.png) + +### 工具集成 + +[工具输出文件集成到OpenHarmony](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2sa/docs/usage/h2sa_ENSEMBLE_METHOD_ZH.md) + +## 工具开发说明 + +### 对象 + +工具的开发者 + +### 开发场景 + +若当前工具的功能已经不能满足开发者的全部需求,则开发者可以基于已有的源码对工具进行二次开发,来增强工具的能力,编译打包生成自定义的可执行文件和插件。 + +### 开发步骤 + +开发者可以根据如下的步骤来完成对工具的开发: + + [工具开发说明](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/h2sa/docs/guide/DEVELOP_ZH.md) + +## 版本说明 + +[已支持特性](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2sa/docs/release-notes/Service-1.0.md) + +[待开发特性](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2sa/docs/requirement/ROADMAP_ZH.md) + +## FAQ + +[FAQ](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/h2sa/docs/guide/FAQ.md) + +## 参与贡献 + +暂无 + +## 相关仓 + +暂无 diff --git a/src/config.html b/src/config.html deleted file mode 100644 index 6d1689280550e30d5c8cae93b7cb7c7fc7982018..0000000000000000000000000000000000000000 --- a/src/config.html +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - - Napi - - - - - -
- 选择方式: - .d.ts文件(多个文件之间用,号分割) - 文件夹 -
-
-
- 选择接口文件: -
- -
- 生成框架路径: -
- -
- 编译脚本路径: -
-
- - - - - -
- - - \ No newline at end of file diff --git a/src/jsconfig.json b/src/jsconfig.json deleted file mode 100644 index 53b981c57b79a7a2dac9995ee4ce04b8c94e0b17..0000000000000000000000000000000000000000 --- a/src/jsconfig.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "target": "ES2020", - "checkJs": true, /* Typecheck .js files. */ - "lib": [ - "ES2020" - ] - }, - "exclude": [ - "node_modules" - ] -} diff --git a/src/package.json b/src/package.json deleted file mode 100644 index 5ab858b640b24730862b2a871466efdc51e99c9f..0000000000000000000000000000000000000000 --- a/src/package.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "name": "gnapi", - "displayName": "gnapi", - "description": "test", - "version": "0.0.1", - "engines": { - "vscode": "^1.62.0" - }, - "categories": [ - "Other" - ], - "activationEvents": [ - "*" - ], - "scripts": { - "lint": "eslint .", - "pretest": "npm run lint", - "test": "node ./test/runTest.js" - }, - "devDependencies": { - "@types/glob": "^7.1.4", - "@types/mocha": "^9.0.0", - "@types/node": "14.x", - "@types/vscode": "^1.62.0", - "@vscode/test-electron": "^1.6.2", - "eslint": "^8.1.0", - "glob": "^7.1.7", - "mocha": "^9.1.3", - "webpack": "^5.64.4", - "webpack-cli": "^4.9.1" - }, - "dependencies": { - "node-gyp": "^9.0.0", - "stdio": "^2.1.1", - "typescript": "^4.9.4", - "vsce": "^2.6.7" - } -} diff --git a/src/tool/api/docs/scan_DEVELOP_ZH.md b/src/tool/api/docs/scan_DEVELOP_ZH.md new file mode 100644 index 0000000000000000000000000000000000000000..3bd5c64e1c00e3332e9ebd873fdbbae0fba951b7 --- /dev/null +++ b/src/tool/api/docs/scan_DEVELOP_ZH.md @@ -0,0 +1,95 @@ +# scan工具开发说明 + +若当前工具功能不满足开发者需求,开发者需增强工具能力,则可基于已有源码进行工具二次开发,编译打包生成自定义的可执行文件和插件。 + +## 工具开发 + +### 可执行文件开发说明 + +#### 环境说明 + +系统:建议Ubuntu 20.04或者Windows 10 + +#### 开发步骤 + +##### Linux +1.下载Andr_N_Games_api.xlsx文件,并放置在napi_generator/src/tool/api/src文件夹下,下载链接如下: + +//待增加链接 + +2.安装typescript:在napi_generator/src/tool/api/src目录下执行命令: + + npm i typescript + +3.安装stdio:在napi_generator/src/tool/api/src目录下执行命令: + + npm i stdio + +4.安装pkg : 在napi_generator/src/tool/api/src目录下执行命令: + + sudo npm i -g pkg + +5.打包三个版本 : 在napi_generator/src/tool/api/src目录下执行命令: + + pkg . + +执行以上步骤后,即可在napi_generator/src/tool/api/src目录下生成Windows、linux、mac系统下的可执行程序: + + search-win.exe、search-linux、search-macos + +6.根据需求打包指定系统下的可执行文件。若想只打包windows系统下可执行文件,可执行命令: + + pkg -t node14-win . -o search-win.exe + +若想只打包linux系统下可执行文件,可执行命令: + + pkg -t node14-linux . -o search-linux + +若想只打包macos系统下可执行文件,可执行命令: + + pkg -t node14-macos . -o search-macos + +备注:参数-t为指定系统,参数-o为指定可执行文件名称。 + + +##### Windows + +1.下载Andr_N_Games_api.xlsx文件,并放置在napi_generator/src/tool/api/src文件夹下,下载链接如下: + +//待增加链接 + +2.使用管理员身份进入终端: + +![](../figures/pic_admin.png) + +3.安装typescript:使用管理员身份在napi_generator/src/tool/api/src目录下执行命令: + + npm i typescript + +4.安装stdio:使用管理员身份在napi_generator/src/tool/api/src目录下执行命令: + + npm i stdio + +5.安装pkg : 使用管理员身份在napi_generator/src/tool/api/src目录下执行命令: + + npm i -g pkg + +6.打包三个版本 : 使用管理员身份在napi_generator/src/tool/api/src目录下执行命令: + + pkg . + +执行以上步骤后,即可在napi_generator/hdc/api目录下生成Windows、linux、mac系统下的可执行程序: + + search-win.exe、search-linux、search-macos + +7.根据需求打包指定系统下的可执行文件。若想只打包windows系统下可执行文件,可执行命令: + + pkg -t node14-win . -o search-win.exe + +若想只打包linux系统下可执行文件,可执行命令: + + pkg -t node14-linux . -o search-linux + +若想只打包macos系统下可执行文件,可执行命令: + + pkg -t node14-macos . -o search-macos diff --git a/src/tool/api/docs/scan_INSTRUCTION_ZH.md b/src/tool/api/docs/scan_INSTRUCTION_ZH.md new file mode 100644 index 0000000000000000000000000000000000000000..35bd79a5a0785f774aa84f9af28d45717ec2206a --- /dev/null +++ b/src/tool/api/docs/scan_INSTRUCTION_ZH.md @@ -0,0 +1,104 @@ +# scan工具使用说明 +## 简介 + +scan工具,即API扫描工具,支持两种入口,分别是可执行程序、VS Code插件,使用者可以根据自己的需要选择合适的工具。 + +## 工具介绍 + +通过API扫描工具,开发者可以扫描输出三方库中存在,而OpenHarmony源码中不存在的风险接口,移植之前预知风险,降低移植难度,提高开发效率。 + +![](./../figures/pic-api-frm.png) + +## 生成result文件 + +### 准备 + +可执行程序打包步骤如下: + +[工具开发说明](https://gitee.com/openharmony/napi_generator/blob/master/src/tool/api/docs/scan_DEVELOP_ZH.md) + +### 可执行程序使用方法 + +#### Linux +1、Ubuntu中存在将要扫描的三方库源码,如下所示: + + Openharmony@Ubuntu-64:~/service$ ls /home/harmony/linshi/ + opencv + +2、将打包的search-linux可执行程序放置任意路径下,如下所示: + + Openharmony@Ubuntu-64:~/service$ ls + search-linux + +3、进入到search-linux可执行程序路径下,并执行可执行程序,执行命令如下: + + Openharmony@Ubuntu-64:~/service$ ./search-linux -d /home/linshi/opencv/ -o ./ + +其中,参数详情如下: + -d, 被扫描项目的路径; + -o, 可选参数,默认为当前路径下,输出结果存放路径。 + +4、运行成功后会在当前目录下生成result.xlsx文件: + + Openharmony@Ubuntu-64:~/service$ ls + result.xlsx search-linux + +并在屏幕上打出风险接口名称: + +``` +{ + function: Set(70) { + 'AndroidBitmap_getInfo', + ...... + 'ANativeWindow_release' + }, + include: Set(3) { 'bitmap.h', 'input.h', 'log.h' } +} +``` + +#### Windows + +1、E:\workspace\杂七杂八\service\目录下存在将要扫描的项目opencv。 + +2、将下载的search-win.exe可执行程序放置任意路径下,如下所示: + + E:\demo\api>dir /B + search-win.exe + +3、进入search-win.exe可执行程序路径下,并执行可执行程序,执行过程如下: + + E:\demo\api>search-win.exe -d E:\workspace\service\opencv -o ./ + +其中,参数详情如下: + -d, 被扫描项目的路径 + -o, 可选参数,默认为当前路径下,输出结果存放路径。 + +4、运行成功后会在当前目录下生成result.xlsx文件: + + E:\demo\api>dir /B + result.xlsx + search-win.exe + +并在屏幕上打出风险接口名称: + +``` +{ + function: Set(70) { + 'AndroidBitmap_getInfo', + ...... + 'ANativeWindow_release' + }, + include: Set(3) { 'bitmap.h', 'input.h', 'log.h' } +} +``` + +#### Mac + +方法步骤参考windows、Linux的使用方法。 + +### VS Code插件使用方法 + +具体的插件使用步骤,可以左键单击以下链接了解: + +[VS插件开发说明](https://gitee.com/openharmony/napi_generator/blob/master/src/tool/api/api_scan_vs_plugin/docs/INSTRUCTION_ZH.md) + diff --git a/src/tool/api/scan_README_ZH.md b/src/tool/api/scan_README_ZH.md new file mode 100644 index 0000000000000000000000000000000000000000..eac9153d52dc8cdb45e66faef5427c6ce10fe5df --- /dev/null +++ b/src/tool/api/scan_README_ZH.md @@ -0,0 +1,84 @@ +# scan工具 + +## 简介 + +scan工具即API扫描工具,它可以扫描三方库中包含OpenHarmony源码不包含的接口,并输出result.xlsx文档。开发者移植三方库到OpenHarmony源码中,若三方库中包含一些OpenHarmony中不存在的接口,便会增加移植难度。此时可使用API扫描工具,提前预知风险接口,降低移植难度,提高开发效率。目前工具支持命令行和VS Code插件两种入口。 + + ├── napi_generator + │ ├── ... # 其它文档 + │ ├── src/tool + │ │ ├── api # api扫描工具 + │ │ | ├── api_scan_vs_plugin # VS Code插件源码 + │ │ | ├── ... + +## 约束 +系统:建议Ubuntu 20.04或者Windows 10 + +依赖版本:VS Code 1.62.0 + +## 使用方法 + +### 使用对象 + +系统开发者 +### 使用场景 + +移植三方库到OpenHarmony前预知风险接口。 + +### 工具获取 + +#### 命令行 + +命令行工具可根据源码自行打包,打包步骤如下: + +[工具开发说明](https://gitee.com/openharmony/napi_generator/tree/master/src/tool/api/api_scan_vs_plugin/docs/DEVELOP_ZH.md) + +#### vscode插件 + +工具支持VS Code插件,可在VS Code插件市场直接下载。 + +### 工具输入 + +根据使用者指定三方库项目源码,工具会输出风险接口。为了方便使用者快速上手工具,此处使用opencv项目为例,项目目录如下: + +![](./figures/opencv.png) + +### 工具使用 + +#### 命令行 + +[命令行使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/tool/api/docs/scan_INSRTUCTION_ZH.md) + +#### vscode插件 + +具体的工具使用步骤,可以左键单击以下链接了解: + +[工具使用说明](https://gitee.com/openharmony/napi_generator/tree/master/src/tool/api/api_scan_vs_plugin/docs/INSTRUCTION_ZH.md) + +### 工具输出 + +在window环境下的,根据输入三方库项目,生成的输出文件result.xlsx,如下所示: + +![](./figures/opencv_result.png) + +其中生成的result.xlsx文件,风险接口如下所示: + +![](./figures/opencv_include.png) + +![](./figures/opencv_h.png) + +## 版本说明 + +暂无 + +## FAQ + + [FAQ](https://gitee.com/openharmony/napi_generator/tree/master/src/tool/api/FAQ.md) + +## 参与贡献 + +暂无 + +## 相关仓 + +暂无 diff --git a/src/vsc-extension-quickstart.md b/src/vsc-extension-quickstart.md deleted file mode 100644 index e6da2a5c8e5a2590cb867d8a5fc207800b190639..0000000000000000000000000000000000000000 --- a/src/vsc-extension-quickstart.md +++ /dev/null @@ -1,39 +0,0 @@ -# Welcome to your VS Code Extension - -## What's in the folder - -* This folder contains all of the files necessary for your extension. -* `package.json` - this is the manifest file in which you declare your extension and command. - * The sample plugin registers a command and defines its title and command name. With this information VS Code can show the command in the command palette. It doesn’t yet need to load the plugin. -* `extension.js` - this is the main file where you will provide the implementation of your command. - * The file exports one function, `activate`, which is called the very first time your extension is activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`. - * We pass the function containing the implementation of the command as the second parameter to `registerCommand`. - -## Get up and running straight away - -* Press `F5` to open a new window with your extension loaded. -* Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`. -* Set breakpoints in your code inside `extension.js` to debug your extension. -* Find output from your extension in the debug console. - -## Make changes - -* You can relaunch the extension from the debug toolbar after changing code in `extension.js`. -* You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes. - -## Explore the API - -* You can open the full set of our API when you open the file `node_modules/@types/vscode/index.d.ts`. - -## Run tests - -* Open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the launch configuration dropdown pick `Extension Tests`. -* Press `F5` to run the tests in a new window with your extension loaded. -* See the output of the test result in the debug console. -* Make changes to `src/test/suite/extension.test.js` or create new test files inside the `test/suite` folder. - * The provided test runner will only consider files matching the name pattern `**.test.ts`. - * You can create folders inside the `test` folder to structure your tests any way you want. -## Go further - - * [Publish your extension](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) on the VSCode extension marketplace. - * Automate builds by setting up [Continuous Integration](https://code.visualstudio.com/api/working-with-extensions/continuous-integration).