diff --git a/README.md b/README.md index 72688fc5fa60aff812623477cba7279184701f1f..04d479ff25f8e7d51e0f4f53ad8383b146623109 100644 --- a/README.md +++ b/README.md @@ -1,118 +1,33 @@ -# Readme - -## 简介 - -napi_generator仓包含以下工具:NAPI框架代码生成工具(dts2cpp)可以根据用户指定路径下的ts(typescript)接口文件一键生成NAPI框架代码、业务代码框架、GN文件等。TS接口生成工具(h2dts)可以根据定义在c++头文件中的接口,生成type-script语言的ts接口文件。GN脚本生成工具(cmake2gn),它可以根据三方库的CMakeLists.txt文件,编译转换生成BUILD.gn脚本文件。SERVICE框架生成工具(h2sa),它可以根据一个定义远程方法的.h头文件,生成整个Service框架的代码,包含Ability注册、proxy/stub类实现、MessageParcel数据包构造、Service子系统编译及开机自启动相关配置文件。NATIVE生成工具(h2dtscpp),它可以根据定义在c++头文件中的接口,生成type-script语言的ts接口文件、NAPI框架代码、和自动化测试用例代码。dts2ets工具,它可以根据用户指定路径下的ts(typescript)接口文件生成ets页面代码。API扫描工具,它可以扫描三方库中包含OpenHarmony源码不包含的接口,并输出result.xlsx文档。 - -## 目录 - -``` -├── napi_generator # 工具集 -│ ├── docs # 工具索引文档 -│ │ ├── readme.md # 所有工具 readme 索引 -│ │ ├── develop.md # 工具设计文档索引 -│ │ ├── usage.md # 工具使用文档索引 -│ │ ├── log -│ │ │ ├── meeting.md # 会议纪要 -│ │ │ ├── release-notes.md # 工具版本说明和规划索引 -│ ├── src # 工具源码 -│ │ ├── cli # 脚手架源码 -│ │ | ├── cmake2gn # gn脚本生成工具 -│ │ | | ├── docs -│ │ | | | ├── figures # 文档图片资源 -│ │ | | | ├── guide # 开发文档 -│ │ | | | ├── usage # 使用文档 -│ │ | | | ├── release-notes # 版本说明文档 -│ │ | | ├── src # 源码 -│ │ | | ├── README_ZH.md -│ │ | |── dts2cpp # napi框架生成工具 -│ │ | | ├── docs -│ │ | | | ├── figures # 文档图片资源 -│ │ | | | ├── guide # 开发文档 -│ │ | | | ├── usage # 使用文档 -│ │ | | | ├── release-notes # 版本说明文档 -│ │ | | | ├── requirement # roadmap.md -│ │ | | ├── src # 源码 -│ │ | | ├── README_ZH.md -│ │ | |── dts2ets # ets页面生成工具 -│ │ | | ├── appCodeGen # 源码 -│ │ | |── h2dts # ts生成工具 -│ │ | | ├── docs -│ │ | | | ├── figures # 文档图片资源 -│ │ | | | ├── guide # 开发文档 -│ │ | | | ├── usage # 使用文档 -│ │ | | | ├── release-notes # 版本说明文档 -│ │ | | | ├── requirement # roadmap.md -│ │ | | ├── src # 源码 -│ │ | | ├── examples # 工具输入示例.h文件 -│ │ | | ├── README_ZH.md -│ │ | |── h2dtscpp # native生成工具 -│ │ | | ├── docs -│ │ | | | ├── figures # 文档图片资源 -│ │ | | | ├── guide # 开发文档 -│ │ | | | ├── usage # 使用文档 -│ │ | | ├── src # 源码 -│ │ | | ├── README_ZH.md -│ │ | |── h2sa # service生成工具 -│ │ | | ├── docs -│ │ | | | ├── figures # 文档图片资源 -│ │ | | | ├── guide # 开发文档 -│ │ | | | ├── usage # 使用文档 -│ │ | | | ├── release-notes # 版本说明文档 -│ │ | | | ├── requirement # roadmap.md -│ │ | | ├── src # 源码 -│ │ | | ├── examples # 工具输入示例.h文件 -│ │ | | ├── README_ZH.md -│ │ ├── intellij_plugin -│ │ | ├── cmake2gn # gn脚本生成工具 -│ │ | | | ├── gn_IntelliJ_plugin # IntelliJ插件 -│ │ | |── dts2cpp # napi框架生成工具 -│ │ | | | ├── napi_IntelliJ_plugin # IntelliJ插件 -│ │ | |── h2dts # ts生成工具 -│ │ | | | ├── ts_IntelliJ_plugin # IntelliJ插件 -│ │ | |── h2dtscpp # native生成工具 -│ │ | | | ├── native_IntelliJ_plugin # IntelliJ插件 -│ │ | |── h2sa # service生成工具 -│ │ | | | ├── service_IntelliJ_plugin # IntelliJ插件 -│ │ | |── assist # 统一入口插件 -│ │ | | | ├── assist_tools_IntelliJ_plugin # IntelliJ插件 -│ │ ├── vscode_plugin -│ │ | ├── cmake2gn # gn脚本生成工具 -│ │ | | | ├── gn_vs_plugin # vs插件 -│ │ | |── dts2cpp # napi框架生成工具 -│ │ | | | ├── napi_vs_plugin # vs插件 -│ │ | |── h2dts # ts生成工具 -│ │ | | | ├── ts_vs_plugin # vs插件 -│ │ | |── h2sa # service生成工具 -│ │ | | | ├── service_vs_plugin # vs插件 -│ │ | |── assist # 统一入口插件 -│ │ | | | ├── assist_tools_vs_plugin # vs插件 -│ │ ├── tool -│ │ | |── api # api扫描工具 -│ │ | | ├── api_scan_IntelliJ_plugin # api扫描工具IntelliJ插件 -│ │ | | ├── api_scan_vs_plugin # api扫描工具vs插件 -│ │ | | ├── docs # 文档 -│ │ | | ├── figures # 文档图片资源 -│ │ | | ├── src # api扫描工具源码 -│ │ | | ├── FAQ.md -│ │ | | ├── README_ZH.md -│ ├── test -│ │ ├── dts2cpp # dts2cpp工具使用example -│ │ | |── ts -│ │ | |── README.md -│ │ ├── storytest # dts2cpp工具st -│ │ ├── unittest # dts2cpp工具ut -│ │ ├── debug_entry.js -│ │ ├── README_zh.md -│ ├── sample # 样例 -│ │ ├── napitutorials -│ └── README.md # readme -``` - -## 工具介绍 - -所有工具相关文档介绍如下所示: -[readme索引](https://gitee.com/openharmony/napi_generator/blob/master/docs/readme.md) -[usage索引](https://gitee.com/openharmony/napi_generator/blob/master/docs/usage.md) -[develop索引](https://gitee.com/openharmony/napi_generator/blob/master/docs/develop.md) -[release-notes索引](https://gitee.com/openharmony/napi_generator/blob/master/docs/log/release-notes.md) \ No newline at end of file +# 简介 + +- dts2cpp工具可以根据用户指定路径下的ts(typescript)接口文件一键生成NAPI框架代码、业务代码框架、GN文件等。 + + [readme](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/dts2cpp/dts2cpp_README_ZH.md) + + [版本说明](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/dts2cpp/docs/release-notes) + +- h2dts工具可以根据定义在c++头文件中的接口,生成type-script语言的ts接口文件。 + + [readme](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2dts/h2dts_README_ZH.md) + + [版本说明](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/h2dts/docs/release-notes/ts_Gen-1.0.md) + +- cmake2gn工具可以根据三方库的CMakeLists.txt文件,编译转换生成BUILD.gn脚本文件。 + + [readme](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/cmake2gn/cmake2gn_README_ZH.md) + + [版本说明](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/cmake2gn/docs/release-notes/gn-gen-release-notes-0.0.2.md) + +- h2sa工具可以根据一个定义远程方法的.h头文件,生成整个Service框架的代码,包含Ability注册、proxy/stub类实现、MessageParcel数据包构造、Service子系统编译及开机自启动相关配置文件。 + + [readme](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2sa/h2sa_README_ZH.md) + + [版本说明](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/h2sa/docs/release-notes/Service-1.0.md) + +- h2dtscpp工具可以根据定义在c++头文件中的接口,生成type-script语言的ts接口文件、NAPI框架代码、和自动化测试用例代码。 + + [readme](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2dtscpp/h2dtscpp_README_ZH.md) + +- scan工具,它可以扫描三方库中包含OpenHarmony源码不包含的接口,并输出result.xlsx文档。 + + [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/src/cli/cmake2gn/cmake2gn_README_ZH.md b/src/cli/cmake2gn/cmake2gn_README_ZH.md index 02d8d09144498a2be5e070c4190dc13f1361a4b5..925d01e0443bc7b10b65d6543520a8f447430af7 100644 --- a/src/cli/cmake2gn/cmake2gn_README_ZH.md +++ b/src/cli/cmake2gn/cmake2gn_README_ZH.md @@ -2,25 +2,7 @@ ## 简介 -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 # 公共模块代码 +cmake2gn工具,它可以根据三方库的CMakeLists.txt文件,编译转换生成BUILD.gn脚本文件。当前OpenHarmony源码只支持BUILD.gn文件编译,开发者无法移植CMakeLists.txt编译方式的三方库到OpenHarmony中。此时,开发者可使用GN脚本转换工具,根据CMakeLists.txt文件生成BUILD.gn脚本文件,降低移植难度,提高开发效率。 ## 约束 系统:建议Ubuntu 20.04或者Windows 10 @@ -29,271 +11,63 @@ cmake2gn工具,即GN脚本转换工具,它可以根据三方库的CMakeLists ## 使用方法 -### 使用对象 +### 生成 -系统开发者 -### 使用场景 +1、安装cmake,安装命令如下: -1) 移植CMakeLists.txt编译方式的三方库到OpenHarmony源码中。 + sudo apt-get install cmake -### 工具获取 +2.下载res文件夹,并放置到napi_generator/src/cli/cmake2gn/src目录下,下载链接如下: -工具有两种类型,分别是可执行文件、VS Code插件。其中的可执行文件可根据工具使用者的开发环境选择,支持Windows,Linux和Mac。可执行文件、VS Code插件下载路径如下: +// todo -[下载链接](http://ftpkaihongdigi.i234.me:5000/fsdownload/1OjtRhtGf/gn-gen-0.0.1) +3.安装typescript:在napi_generator/src/cli/cmake2gn/src/src目录下执行命令: -### 工具输入 + npm i typescript -以CmakeLists.txt编译方式的三方库 +4.安装stdio:在napi_generator/src/cli/cmake2gn/src目录下执行命令: -根据使用者指定三方库的CMakeLists.txt文件,工具会输出对应的BUILD.gn文件。为了方便使用者快速上手工具,可供测试的三方库项目目录如下: + npm i stdio + +5.根据使用者指定三方库的CMakeLists.txt文件,工具会输出对应的BUILD.gn文件。将待转换的三方库拷贝到OpenHarmony/third_party下,为了方便使用者快速上手工具,可供测试的三方库项目目录如下: ``` 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文件,内容如下所示: +6.在napi_generator/src/cli/cmake2gn/src/src下执行以下命令: ``` -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", - - ] -} - +node main.js -o out/rk3568 -p /home/OpenHarmony -f third_party/mbedtls-development/CMakeLists.txt -t cmake -s test_subsystem -m mbedtls-development ``` -### 集成 +其中,参数详情如下: -具体的将三方库集成到OpenHarmony的步骤,可以左键单击以下链接了解: - -[将三方库集成到OpenHarmony的方法](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/cmake2gn/docs/usage/ENSEMBLE_METHOD_ZH.md) - -## 工具开发说明 + -o:必填参数,ohos产品输出相对路径(例如:out/rk3568); -### 对象 + -p:必填参数,ohos项目路径(例如:/home/OpenHarmony); -工具的开发者 + -f:必选参数,待转换三方库cmake文件相对路径(例如:third_party/mbedtls-development/CMakeLists.txt); -### 开发场景 + -t:可选参数,默认为cmake; -若当前工具的功能已经不能满足开发者的全部需求,则开发者可以基于已有的源码对工具进行二次开发,来增强工具的能力,编译打包生成自定义的可执行文件和插件。 + -s:可选参数,默认填写“test_subsystem”,使用者可根据实际情况修改子系统名称; -### 开发步骤 + -m:可选参数,工具默认填写“test_part”,使用者可根据实际情况修改组件名称; -开发者可以根据如下的步骤来完成对工具的开发: + -d:可选参数,工具默认填写待转换三方库cmake文件所在文件夹相对路径,使用者可根据实际情况修改路径; - [工具开发说明](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/cmake2gn/docs/guide/DEVELOP_ZH.md) + -a:可选参数,待转换三方库中引用其它三方库时需填写该选项,具体填写方法可参考FAQ中libcoap转换时问题解决方法,详细FAQ内容可左键单击以下链接了解:[FAQ](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/cmake2gn/docs/guide/FAQ.md); -## 版本说明 +7.运行成功后会在/OpenHarmony/third_party/mbedtls-development目录下生成build_tmp文件夹,build_tmp文件夹中包含BUILD.gn文件,如下所示: -[版本说明](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/cmake2gn/docs/release-notes/gn-gen-release-notes-0.0.2.md) +![](./docs/figures/pic-build-tmp.png) -## FAQ - - [FAQ](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/cmake2gn/docs/guide/FAQ.md) +### 集成 -## 参与贡献 +具体的将三方库集成到OpenHarmony的步骤,可以左键单击以下链接了解: -暂无 +[将三方库集成到OpenHarmony的方法](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/cmake2gn/docs/usage/ENSEMBLE_METHOD_ZH.md) -## 相关仓 -暂无 diff --git a/src/cli/dts2cpp/docs/figures/dts2cpp_outResult.png b/src/cli/dts2cpp/docs/figures/dts2cpp_outResult.png new file mode 100644 index 0000000000000000000000000000000000000000..fc689ae660fcf0b2bbf1d149a0818ae63dea38a4 Binary files /dev/null and b/src/cli/dts2cpp/docs/figures/dts2cpp_outResult.png differ diff --git a/src/cli/dts2cpp/dts2cpp_README.md b/src/cli/dts2cpp/dts2cpp_README.md deleted file mode 100644 index 1f5e5d52f9dc212c6d869f1996c49684cbe53842..0000000000000000000000000000000000000000 --- a/src/cli/dts2cpp/dts2cpp_README.md +++ /dev/null @@ -1,133 +0,0 @@ -# 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/src/cli/dts2cpp/dts2cpp_README_ZH.md b/src/cli/dts2cpp/dts2cpp_README_ZH.md new file mode 100644 index 0000000000000000000000000000000000000000..7c47b22fff919d3e5aa5ccdd3c05a3062bb669b4 --- /dev/null +++ b/src/cli/dts2cpp/dts2cpp_README_ZH.md @@ -0,0 +1,68 @@ +# dts2cpp工具 + +## 简介 +dts2cpp工具,它可以根据用户指定路径下的ts(typescript)接口文件一键生成NAPI框架代码、业务代码框架、GN文件等。在开发JS应用与NAPI间接口时,底层框架开发者无需关注js语法、C++与JS之间的数据类型转换等上层应用转换逻辑,只关注底层业务逻辑即可,专业的人做专业的事,从而可以大大提高开发效率。 + +## 约束 +系统:建议Ubuntu 20.04或者Windows 10 + +依赖版本:VS Code 1.62.0 + +## 使用方法 + +### 生成框架 + +1.安装typescript:在napi_generator/src/cli/dts2cpp/src目录下执行命令: + + npm i typescript + +2.安装stdio:在napi_generator/src/cli/dts2cpp目录下执行命令: + + npm i stdio + +3.将待转换的文件@ohos.napitest.d.ts拷贝到napi_generator/src/cli/dts2cpp/src下,并在该目录下新建out目录;@ohos.napitest.d.ts如下所示: + +``` +declare namespace napitest { + function funcTest(v: boolean): string; +} +export default napitest; +``` + +4.在napi_generator/src/cli/dts2cpp/src下执行以下命令生成napi框架代码: + +``` +node gen\cmd_gen.js -f @ohos.napitest.d.ts -o out +``` + +其中,参数详情如下: + + -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文件中声明了其它.d.ts文件,将此类文件放置在待转换.d.ts文件同级目录。 + +5.输出文件如下所示: + +![](./docs/figures/dts2cpp_outResult.png) + +### 集成 + +[生成代码集成到OpenHarmony的方法](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/dts2cpp/docs/usage/dts2cpp_ENSEMBLE_METHOD_ZH.md) + +### 调用 + +NAPI框架代码生成后,系统框架开发者进行二次开发后,即可集成到OpenHarmony编译系统,生成对应的库文件,供应用开发者调用接口。工具集成测试的具体操作步骤可以左键单击以下链接了解: + +[工具集成测试](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/dts2cpp/docs/usage/dts2cpp_INTEGRATION_TESTING_ZH.md) \ No newline at end of file diff --git a/src/cli/dts2cpp/src/gen/cmd_gen.js b/src/cli/dts2cpp/src/gen/cmd_gen.js index 609bcb2dba3951191f2ca66c167e4cf748e7047c..51284bc79a2d1cb510d0aa5444f924ff8911c495 100644 --- a/src/cli/dts2cpp/src/gen/cmd_gen.js +++ b/src/cli/dts2cpp/src/gen/cmd_gen.js @@ -13,7 +13,6 @@ * limitations under the License. */ const main = require('./main'); -const tsMain = require('../tsGen/tsMain'); const re = require('./tools/re'); const { checkFileError } = require('./tools/common'); const { NapiLog } = require('./tools/NapiLog'); @@ -114,12 +113,6 @@ function getJsonCfg(currentPath) { function checkGenerate(fileName) { NapiLog.logInfo('check file []'.format(fileName)); - let suffix = fileName.split('.').pop().toLowerCase(); - if (ops.tsGen === 'true' && suffix === 'h') { - NapiLog.logInfo('convert .h file to .ts file...'); - tsMain.doGenerate(fileName, ops.out); - return; - } let fn = re.getFileInPath(fileName); let tt = re.match('(@ohos\.)*([.a-z_A-Z0-9]+).d.ts', fn); if (tt) { diff --git a/src/cli/h2dts/h2dts_README_ZH.md b/src/cli/h2dts/h2dts_README_ZH.md index 7762c3ce0161c22751bdfed95ab7de2ea7689f3f..feab44e7de2510641c9ca0aec8421885917d45bd 100644 --- a/src/cli/h2dts/h2dts_README_ZH.md +++ b/src/cli/h2dts/h2dts_README_ZH.md @@ -1,18 +1,7 @@ # h2dts工具 ## 简介 -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框架工具源码入口 +h2dts工具,即Ts接口生成工具,它可以根据定义在c++头文件中的接口,生成type-script语言的ts接口文件。若某个服务实现方式为c++,且供应用层访问的接口已在.h文件中定义,此时,NAPI接口开发者使用此工具可一键生成对应的ts文件,进而将生成的ts文件作为NAPI框架生成代码工具的输入,生成NAPI框架代码。串行使用ts接口生成工具、NAPI框架代码生成工具,形成工具链,达到降低NAPI接口开发难度,提高开发效率。 ## 约束 系统:建议Ubuntu 20.04或者Windows 10 @@ -21,108 +10,53 @@ h2dts工具,即Ts接口生成工具,它可以根据定义在c++头文件中 ## 使用方法 -### 使用对象 +1.安装typescript:在napi_generator/src/cli/h2dts/src目录下执行命令: -系统开发者、应用Native开发者 + npm i typescript -### 使用场景 +2.安装stdio:在napi_generator/src/cli/h2dts目录下执行命令: -1) 系统框架层新增子系统,需对应用层提供接口。 -2) 系统框架层子系统能力增强后,需对应用层提供新接口。 -3) 应用层引入C++三方库,需增加OpenHarmony应用层接口。 + npm i stdio -### 工具获取 - -工具有两种类型,分别是可执行文件、IntelliJ插件。其中的可执行文件可根据工具使用者的开发环境选择,支持Windows,Linux和Mac。可执行文件、IntelliJ插下载路径如下: - -[下载链接](http://ftp.kaihongdigi.com:5000/fsdownload/mKjfCmPjk/generator_outputs_NAPI_0930) - -### 工具输入 - -根据使用者指定的.h文件,工具会输出对应的ts接口文件。为了方便使用者快速上手工具,可供测试的test.h文件样例如下: +3.将待转换的文件tsTest.h拷贝到napi_generator/src/cli/h2dts/src/tsGen下;TsGenTest.h文件如下所示: ``` - - #include < string > - #include < vector > - using namespace std; - - class TestA { - public: - char16_t string1; - void add(string v, long double v1[]); - }; - double count(double v, double v1[]); - - namespace Space { - class TestBB { - public: - short string4; - bool ifExist(bool v, bool v1[]); - }; - uint32_t max(uint32_t v, uint32_t v1[]); - } +#ifndef TSGENTEST_H +#define TSGENTEST_H + +#include +#include +#include + +namespace OHOS { +class TsGenTest { +public: + std::string getServName(); + std::string getServTime(); + int32_t doSum(int32_t num1, int32_t num2); + double addCount(double newNum); +}; +} +#endif ``` -### 工具使用 - -具体的工具使用步骤,可以左键单击以下链接了解: - -[工具使用说明](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/h2dts/docs/usage/INSTRUCTION_ZH.md) - -### 工具输出 - -在window环境下的,根据输入文件test.h,生成的输出文件,如下所示: - -![](./docs/figures/h-2-ts-succ.png) - - -其中生成的"test.d.ts"文件,定义了应用开发接口,如下所示: - - declare class TestA { - string1: string; - add(v: string, v1: Array): void; - } - declare namespace Space { - function max(v: number, v1: Array): number; - class TestBB { - string4: number; - ifExist(v: boolean, v1: Array): boolean; - } - } - declare function count(v: number, v1: Array): number; - - export default Space; - +4.在napi_generator/src/cli/h2dts/src/tsGen下执行以下命令生成ts声明文件: -## 工具开发说明 - -### 对象 - -工具的开发者 - -### 开发场景 - -若当前工具的功能已经不能满足开发者的全部需求,则开发者可以基于已有的源码对工具进行二次开发,来增强工具的能力,编译打包生成自定义的可执行文件和插件。 - -### 开发步骤 - -开发者可以根据如下的步骤来完成对工具的开发: - - [工具开发说明](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/h2dts/docs/guide/DEVELOP_ZH.md) - -## 版本说明 - - [版本说明](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2dts/docs/release-notes/ts_Gen-1.0.md) - -## FAQ +``` +node cmd_gen.js -f TsGenTest.h +``` - [FAQ](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/h2dts/docs/guide/FAQ.md) +其中,参数详情如下: + -f, 待转换的.h文件,若同时转换多个文件,文件之间用“,”隔开; + -d, 根据指定路径转换该文件夹中所有.h文件; + -t, 区分ts生成与napi转换工具,值为true时表示ts生成,false表示napi转换,默认为false; + -o, 可选参数,默认为当前目录,指定生成框架代码输出路径。 -## 参与贡献 + 备注:-f与-d两个参数只选其中一个参数即可。 -暂无 +5.执行成功后在napi_generator/src/cli/h2dts/src/tsGen下生成TsGenTest.d.ts声明文件 -## 相关仓 +``` +TsGenTest.d.ts +``` -暂无 diff --git a/src/cli/h2dts/src/tsGen/cmd_gen.js b/src/cli/h2dts/src/tsGen/cmd_gen.js new file mode 100644 index 0000000000000000000000000000000000000000..88422f137c1bed1064165bbfcf8c9b133dadba5a --- /dev/null +++ b/src/cli/h2dts/src/tsGen/cmd_gen.js @@ -0,0 +1,124 @@ +/* +* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +const tsMain = require('./tsMain'); +const { NapiLog } = require('./tools/NapiLog'); +const path = require('path'); +const stdio = require('stdio'); +var fs = require('fs'); +const util = require('util'); + +let ops = stdio.getopt({ + 'filename': { key: 'f', args: 1, description: '.d.ts file', default: '' }, + 'directory': { key: 'd', args: 1, description: '.d.ts directory', default: '' }, + 'out': { key: 'o', args: 1, description: 'output directory', default: '.' }, + 'loglevel': { key: 'l', args: 1, description: 'Log Level : 0~3', default: '1' }, + 'tsGen':{key: 't', args: 1, description: 'enable or disable generate typescript file', default: false }, +}); + +let vscode = null; +try { + vscode = require('vscode'); +} +catch (err) { + vscode = null; +} + +NapiLog.init(ops.loglevel, path.join('' + ops.out, 'napi_gen.log')); + +let fileNames = ops.filename; +var pathDir = ops.directory; +if (fileNames == null && pathDir == null) { + NapiLog.logInfo('fileNames and pathDir both cannot be empty at the same time'); +} else if (pathDir !== '') { + readDirFiles(); +} else if (fileNames !== '') { + readFiles(); +} + +function print(...args) { + if (vscode) { + vscode.window.showInformationMessage(...args); + } + console.log(...args); +} + +function readFiles() { + fileNames = fileNames.replace(/(^\s*)|(\s*$)/g, ''); // trim before and after espace + let regex = ','; + let filenameArray = fileNames.toString().split(regex); + + let n = filenameArray.length; + for (let i = 0; i < n; i++) { + let fileName = filenameArray[i]; + if (fileName !== ' ') { + fileName = fileName.replace(/(^\s*)|(\s*$)/g, ''); + checkGenerate(fileName); + } + } +} + +function handleDirFiles(files) { + if (0 === files.length) { + NapiLog.logInfo(util.format('[Func: readDirFiles] No files in path %s!', pathDir)); + return; + } + (function iterator(i) { + if (i === files.length) { + return; + } + let data = fs.statSync(path.join(pathDir + '', files[i])); + if (data.isFile()) { + let fileName = files[i]; + checkGenerate(pathDir + '/' + fileName); + } + iterator(i + 1); + })(0); +} + +function readDirFiles() { + let fileList; + try { + fileList = fs.readdirSync(pathDir + ''); + } catch (err) { + NapiLog.logError('readdir file error ' + err); + return; + } + + handleDirFiles(fileList); +} + +function checkGenerate(fileName) { + NapiLog.logInfo(util.format('check file []', fileName)); + let suffix = fileName.split('.').pop().toLowerCase(); + if (suffix === 'h') { + NapiLog.logInfo('convert .h file to .ts file...'); + tsMain.doGenerate(fileName, ops.out); + return; + } + else { + NapiLog.logError('file name ' + fileName + ' format invalid in function of checkGenerate!'); + } +} + +let ret = NapiLog.getResult(); +if (ret[0]) { + print('success'); + NapiLog.logInfo('success'); +} +else { + print('fail\n' + ret[1]); + NapiLog.logInfo('fail\n' + ret[1]); +} diff --git a/src/cli/h2dts/src/tsGen/tools/FileRW.js b/src/cli/h2dts/src/tsGen/tools/FileRW.js new file mode 100644 index 0000000000000000000000000000000000000000..648b691862145ba6bcf482baf2eec86e177c928d --- /dev/null +++ b/src/cli/h2dts/src/tsGen/tools/FileRW.js @@ -0,0 +1,140 @@ +/* +* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +const fs = require('fs'); + +function utf8ArrayToStr(array) { + var out, i, len, c; + var char2, char3; + + out = ''; + len = array.length; + i = 0; + while (i < len) { + c = array[i++]; + switch (c >> 4) { + case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: + // 0xxxxxxx + out += String.fromCharCode(c); + break; + case 12: case 13: + // 110x xxxx 10xx xxxx + char2 = array[i++]; + out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F)); + break; + case 14: + // 1110 xxxx 10xx xxxx 10xx xxxx + char2 = array[i++]; + char3 = array[i++]; + out += String.fromCharCode(((c & 0x0F) << 12) | + ((char2 & 0x3F) << 6) | + ((char3 & 0x3F) << 0)); + break; + } + } + + return out; +} + +function stringToUint8Array(string, options = { stream: false }) { + if (options.stream) { + throw new Error(`Failed to encode: the 'stream' option is unsupported.`); + } + let pos = 0; + const len = string.length; + let at = 0; // output position + let tlen = Math.max(32, len + (len >> 1) + 7); // 1.5x size + let target = new Uint8Array((tlen >> 3) << 3); // ... but at 8 byte offset + + while (pos < len) { + let value = string.charCodeAt(pos++); + let isContinue = false; + if (value >= 0xd800 && value <= 0xdbff) { + if (pos < len) { // high surrogate + const extra = string.charCodeAt(pos); + if ((extra & 0xfc00) === 0xdc00) { + ++pos; + value = ((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000; + } + } + if (value >= 0xd800 && value <= 0xdbff) { + isContinue = true; // drop lone surrogate + } + } + + if (!isContinue) { + // expand the buffer if we couldn't write 4 bytes + if (at + 4 > target.length) { + tlen += 8; // minimum extra + tlen *= (1.0 + (pos / string.length) * 2); // take 2x the remaining + tlen = (tlen >> 3) << 3; // 8 byte offset + + target = uint8Array(tlen, target); + } + + let calculateResult = calculate(value, target, at); + isContinue = calculateResult[0]; + target = calculateResult[1]; + at = calculateResult[2]; + } + } + return target.slice(0, at); +} + +function calculate(value, target, at) { + let isContinue = false; + if ((value & 0xffffff80) === 0) { // 1-byte + target[at++] = value; // ASCII + isContinue = true; + } else if ((value & 0xfffff800) === 0) { // 2-byte + target[at++] = ((value >> 6) & 0x1f) | 0xc0; + } else if ((value & 0xffff0000) === 0) { // 3-byte + target[at++] = ((value >> 12) & 0x0f) | 0xe0; + target[at++] = ((value >> 6) & 0x3f) | 0x80; + } else if ((value & 0xffe00000) === 0) { // 4-byte + target[at++] = ((value >> 18) & 0x07) | 0xf0; + target[at++] = ((value >> 12) & 0x3f) | 0x80; + target[at++] = ((value >> 6) & 0x3f) | 0x80; + } else { + isContinue = true; + } + if (!isContinue) { + target[at++] = (value & 0x3f) | 0x80; + } + return [isContinue, target, at]; +} + +function uint8Array(tlen, target) { + const update = new Uint8Array(tlen); + update.set(target); + return update; +} + +function readFile(fn) { + if (!fs.existsSync(fn)) { + return ''; + } + let data = fs.readFileSync(fn); + data = utf8ArrayToStr(data); + return data; +} +function writeFile(fn, str) { + let data = stringToUint8Array(str); + fs.writeFileSync(fn, data); +} + +module.exports = { + readFile, + writeFile, +}; \ No newline at end of file diff --git a/src/cli/h2dts/src/tsGen/tools/NapiLog.js b/src/cli/h2dts/src/tsGen/tools/NapiLog.js new file mode 100644 index 0000000000000000000000000000000000000000..135741d304574a765f57b2982ea14e24a6b87caf --- /dev/null +++ b/src/cli/h2dts/src/tsGen/tools/NapiLog.js @@ -0,0 +1,142 @@ +/* +* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +const fs = require('fs'); +const path = require('path'); +const util = require('util'); + +let vscode = null; +try { + vscode = require('vscode'); +} +catch (err) { + vscode = null; +} + +class NapiLog { + constructor() { + } +} +NapiLog.LEV_NONE = 0; +NapiLog.LEV_ERROR = 1; +NapiLog.LEV_DEBUG = 2; +NapiLog.LEV_INFO = 3; + +const LEV_STR = ['[NON]', '[ERR]', '[DBG]', '[INF]']; +var logLevel = NapiLog.LEV_ERROR; +var logFileName = null; +var logResultMessage = [true, '']; + +function getDateString() { + let nowDate = new Date(); + return nowDate.toLocaleString(); +} + +function saveLog(dateStr, levStr, detail) { + if (logFileName) { + let logStr = dateStr + ' ' + levStr + ' ' + detail + '\n'; + fs.appendFileSync(logFileName, logStr); + } +} + +NapiLog.init = function (level, fileName) { + logLevel = level in [NapiLog.LEV_NONE, NapiLog.LEV_ERROR, NapiLog.LEV_DEBUG, NapiLog.LEV_INFO] + ? level : NapiLog.LEV_ERROR; + logFileName = fileName ? fileName : 'napi_generator.log'; +}; + +/** + * 通过调用栈获取当前正在执行的方法名,代码行数及文件路径 + * @param {} callerFuncName 指定取调用栈中哪个方法名所在的帧作为目标帧 + * @returns + */ +NapiLog.getCallPath = function (callerFuncName = null) { + let callPath = ''; + let stackArray = new Error().stack.split('\n'); + + // 如果没有指定目标方法,默认在调用栈中查找当前方法"getCallPath"所在的帧 + let destFuncName = callerFuncName != null ? callerFuncName : 'getCallPath'; + + for (let i = stackArray.length - 1; i >= 0; --i) { + // debug模式和打包后的可执行程序调用栈函数名不同, 以NapiLog.log()方法为例: + // vscode debug模式下调用栈打印的方法名为NapiLog.log,而可执行程序的调用栈中显示为Function.log() + let callerMatch = (stackArray[i].indexOf('NapiLog.' + destFuncName) > 0 || + stackArray[i].indexOf('Function.' + destFuncName) > 0); + if (callerMatch) { + let stackMsg = stackArray[i + 1].trim(); + let leftIndex = stackMsg.indexOf('('); + let rightIndex = stackMsg.indexOf(')'); + + if (leftIndex > 0 && rightIndex > 0) { + let funInfo = stackMsg.substring(0, leftIndex); + let srcPath = stackMsg.substring(leftIndex + 1, rightIndex); + let colNumIndex = srcPath.lastIndexOf(':'); + let colNum = srcPath.substring(colNumIndex + 1, srcPath.length); + let lineNumIndex = srcPath.lastIndexOf(':', colNumIndex - 1); + let lineNum = srcPath.substring(lineNumIndex + 1, colNumIndex); + let filePath = srcPath.substring(0, lineNumIndex); + + callPath = util.format('%s[%s(%s:%s)]', funInfo, filePath, lineNum, colNum); + } + break; + } + } + + return callPath; +}; + +function print(...args) { + if (vscode) { + vscode.window.showInformationMessage(...args); + } + console.log(args + ''); +} + +function recordLog(lev, ...args) { + let origMsgInfo = args; + let callPath = NapiLog.getCallPath('log'); + let dataStr = getDateString(); + let detail = args.join(' '); + saveLog(dataStr + ' ' + callPath, LEV_STR[lev], detail); + if (lev === NapiLog.LEV_ERROR) { + logResultMessage = [false, detail]; + } + let logStr = callPath + ' ' + detail; + if (logLevel <= lev) { + return logStr; + } + NapiLog.logInfo(origMsgInfo[0]); + return logStr; +} + +NapiLog.logError = function (...args) { + let logInfo = recordLog(NapiLog.LEV_ERROR, args); + print(logInfo); +}; + +NapiLog.logDebug = function (...args) { + recordLog(NapiLog.LEV_DEBUG, args); +}; + +NapiLog.logInfo = function (...args) { + recordLog(NapiLog.LEV_INFO, args); +}; + +NapiLog.getResult = function () { + return logResultMessage; +}; + +module.exports = { + NapiLog, +}; \ No newline at end of file diff --git a/src/cli/h2dts/src/tsGen/tools/re.js b/src/cli/h2dts/src/tsGen/tools/re.js new file mode 100644 index 0000000000000000000000000000000000000000..5bb9dc2762e9210452aec4603414e5c2b8ffe31b --- /dev/null +++ b/src/cli/h2dts/src/tsGen/tools/re.js @@ -0,0 +1,84 @@ +/* +* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +const path = require('path'); + +function search(ss, data) { + ss = replaceAll(ss, '\\.', '\\.'); + let reg = new RegExp(ss); + let tt = reg.exec(data); + if (tt == null) { + return null; + } + let ret = { 'regs': [] }; + for (let i = 0; i < tt.length; i++) { + let p = data.indexOf(tt[i]); + if (tt[i] == null) { + ret.regs.push([-1, -1]); + } + else { + ret.regs.push([p, p + tt[i].length]); + } + } + + return ret; +} + +function match(ss, data) { + let tt = search(ss, data); + if (tt !== null && tt !== undefined && tt.regs[0][0] === 0) { + return tt; + } + return null; +} + +function removeReg(data, reg) { + return data.substring(0, reg[0]) + data.substring(reg[1], data.length); +} + +function getReg(data, reg) { + return data.substring(reg[0], reg[1]); +} + +function getFileInPath(tpath) { + return path.parse(tpath).base; +} + +function getPathInPath(tpath) { + return path.parse(tpath).dir; +} + +function all(sfrom) { + return new RegExp(sfrom, 'g'); +} + +function replaceAll(ss, sfrom, sto) { + return ss.replace(all(sfrom), sto); +} + +function pathJoin(...args) { + return path.join(...args); +} + +module.exports = { + search, + match, + removeReg, + getReg, + getFileInPath, + getPathInPath, + pathJoin, + replaceAll, + all, +}; \ No newline at end of file diff --git a/src/cli/h2dts/src/tsGen/tsMain.js b/src/cli/h2dts/src/tsGen/tsMain.js index ee77776da39197b2651a81a73a54fdf27e3eb6e3..23e1e88fe91ff96c72df89b7f2c38f9e0360c5b6 100644 --- a/src/cli/h2dts/src/tsGen/tsMain.js +++ b/src/cli/h2dts/src/tsGen/tsMain.js @@ -12,12 +12,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const { NapiLog } = require('../gen/tools/NapiLog'); -const { writeFile } = require('../gen/tools/FileRW'); +const { NapiLog } = require('./tools/NapiLog'); +const { writeFile } = require('./tools/FileRW'); const path = require('path'); -const re = require('../gen/tools/re'); +const re = require('./tools/re'); const fs = require('fs'); const os = require('os'); +const util = require('util'); function parseFileAll(hFilePath) { let execSync = require('child_process').execSync; @@ -132,7 +133,7 @@ function getJsTypeFromC(cType, typeInfo) { } let jsType = basicC2js(basicCtype); if (typeInfo.array) { - jsType = 'Array<%s>'.format(jsType); + jsType = util.format('Array<%s>', jsType); } return jsType; } @@ -188,7 +189,7 @@ function putFuncIntoNamespace(funcInfo, namespaces) { return; } } - NapiLog.logError('The namespace [%s] of function %s is not found.'.format(funcInfo.namespace, funcInfo.name)); + NapiLog.logError(util.format('The namespace [%s] of function %s is not found.', funcInfo.namespace, funcInfo.name)); } function analyzeRootFunction(rootInfo, parseResult) { @@ -248,7 +249,7 @@ function putClassIntoNamespace(classInfo, namespaces) { return; } } - NapiLog.logError('The namespace [%s] of class %s is not found.'.format(classInfo.namespace, classInfo.name)); + NapiLog.logError(util.format('The namespace [%s] of class %s is not found.', classInfo.namespace, classInfo.name)); } function analyzeClasses(rootInfo, parseResult) { @@ -283,7 +284,7 @@ function genFunction(func, tabLv, needDeclare = false) { funcParams += func.params[i].name + ': ' + func.params[i].type; } let declareStr = needDeclare ? 'declare ' : ''; - return '%s%s%s%s%s(%s): %s;\n'.format(tab, declareStr, funcPrefix, func.static, func.name, funcParams, func.retType); + return util.format('%s%s%s%s%s(%s): %s;\n', tab, declareStr, funcPrefix, func.static, func.name, funcParams, func.retType); } function genClass(classInfo, tabLv, needDeclare = false) { @@ -292,7 +293,7 @@ function genClass(classInfo, tabLv, needDeclare = false) { let tsClass = tab + declareStr + 'class ' + classInfo.name + ' {\n'; let tab1 = getTab(tabLv + 1); for (var i = 0; i < classInfo.properties.length; ++i) { - tsClass += '%s%s: %s;\n'.format(tab1, classInfo.properties[i].name, classInfo.properties[i].type); + tsClass += util.format('%s%s: %s;\n', tab1, classInfo.properties[i].name, classInfo.properties[i].type); } for (var i = 0; i < classInfo.functions.length; ++i) { tsClass += genFunction(classInfo.functions[i], tabLv + 1); @@ -303,7 +304,7 @@ function genClass(classInfo, tabLv, needDeclare = false) { function genNamespace(namespace, tabLv) { let tab = getTab(tabLv); - let tsNamespace = tab + 'declare namespace %s {\n'.format(namespace.name); + let tsNamespace = tab + util.format('declare namespace %s {\n', namespace.name); for (var i = 0; i < namespace.functions.length; ++i) { tsNamespace += genFunction(namespace.functions[i], tabLv + 1); } @@ -331,7 +332,7 @@ function genTsContent(rootInfo) { if (rootInfo.namespaces.length > 0) { // export the first namespace as default - tsContent += '\nexport default %s;'.format(rootInfo.namespaces[0].name); + tsContent += util.format('\nexport default %s;', rootInfo.namespaces[0].name); } return tsContent; diff --git a/src/cli/h2dtscpp/h2dtscpp_README.md b/src/cli/h2dtscpp/h2dtscpp_README.md new file mode 100644 index 0000000000000000000000000000000000000000..cd14bb49431f9956bc9ffa75c02f55d0660227d7 --- /dev/null +++ b/src/cli/h2dtscpp/h2dtscpp_README.md @@ -0,0 +1,63 @@ +# h2dtscpp工具 + +## 简介 + +h2dtscpp工具即NATIVE生成工具,该工具由C++语法解释器和代码生成器两部分组成。C++语法解释器解析用户输入的.h文件内容,通过C++语法解析,将文件内容分解为类、方法、入参、成员属性等元素;代码生成器根据从语法解析器得到的这些元素,转换为对应的typescript语法的接口、方法、参数代码,生成.ts文件内容;同时通过语法解析器得到的元素,生成.h文件对应的napi框架代码和接口调用测试代码。 + +## 约束 + +系统:建议Windows 10 + +## 使用方法 + +### 生成 + +1.安装typescript:使用管理员身份在napi_generator/src/cli/h2dtscpp/src目录下执行命令: + + npm i typescript + +2.安装stdio:使用管理员身份在napi_generator/src/cli/h2dtscpp/src目录下执行命令: + + npm i stdio + +3.将待转换的.h文件拷贝到napi_generator/src/cli/h2dtscpp/src下,如 [cJSON测试三方库](https://gitee.com/openharmony/napi_generator/releases/tag/测试用资源) 的cJSON.h,并新建out目录。 + +4.在napi_generator/src/cli/h2dtscpp/src执行以下命令: + +``` +node src\main.js -f cJSON.h -o out +``` + +其中,参数详情如下: + +-f, 必选参数,待转换的.h文件;如cJSON.h。 + +-t, 可选参数,测试用例文件Ability.test.ets文件路径,默认路径为.h文件目录下testout文件夹下创建的xxxAbility.test.ets文件路径(如:testout/cJSONAbility.test.ets)。 + +-i, 可选参数,ts声明文件index.s.ts文件路径,默认路径为.h文件目录下tsout文件夹下创建的index.d.ts文件路径(如:tsout/index.d.ts) + +index.d.ts文件路径; + +-o, 可选参数,生成的.cpp文件所在路径,默认路径为.h文件目录下创建的cppout文件夹路径; + +5.执行成功后在out目录下生成以下文件夹 + +![](./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/usage/INSTRUCTION_ZH.md) \ No newline at end of file diff --git a/src/cli/h2sa/docs/figures/h2sa_outRes.png b/src/cli/h2sa/docs/figures/h2sa_outRes.png new file mode 100644 index 0000000000000000000000000000000000000000..44d248df72f23296679e3ead80d08e3a931687b6 Binary files /dev/null and b/src/cli/h2sa/docs/figures/h2sa_outRes.png differ diff --git a/src/cli/h2sa/h2sa_README_ZH.md b/src/cli/h2sa/h2sa_README_ZH.md index 3187be99b81b95872c2603eb687e2a549784b37d..05dfb94418e52a6baf5696df59292ee059c48bc7 100644 --- a/src/cli/h2sa/h2sa_README_ZH.md +++ b/src/cli/h2sa/h2sa_README_ZH.md @@ -2,19 +2,7 @@ ## 简介 -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 # 配置文件 - │ │ | ├── ... # 其它工具 +h2sa工具,即SERVICE框架生成工具,当开发者为OpenHarmony系统框架开发某些功能时,有时需要将这个功能包装成一个独立的服务进程运行在系统中,为了其它应用进程能够调用此服务,开发人员需要基于系统IPC通信框架编写一套远程接口调用实现。实现Service远程调用接口需要开发人员熟悉IPC通信框架,了解proxy/stub的继承与实现方式,掌握C++类型转为MessageParcel数据包的各种API方法,有一定的学习成本。而Service代码生成工具能够帮助使用者生成框架代码,提升开发效率。用户只需提供一个定义远程方法的.h头文件,工具会自动生成整个Service框架的代码,包含Ability注册、proxy/stub类实现、MessageParcel数据包构造、Service子系统编译及开机自启动相关配置文件。 ## 约束 系统:建议Ubuntu 20.04或者Windows 10 @@ -23,16 +11,17 @@ h2sa工具,即SERVICE框架生成工具,当开发者为OpenHarmony系统框 ## 使用方法 -### 使用对象 +### 生成 -系统开发者 -### 使用场景 +1.安装typescript:在napi_generator/src/cli/h2sa/src/src目录下执行命令: -1) 开发者为OpenHarmony系统框架开发某些功能,并将该功能包装成一个独立的服务进程运行在系统中。 + npm i typescript -### 工具输入 +2.安装stdio:在napi_generator/src/cli/h2sa/src目录下执行命令: -根据使用者指定的.h头文件,工具会输出SERVICE框架代码。为了方便使用者快速上手工具,可供测试的.h文件如下所示: + npm i stdio + +3.将待转换的文件test.h文件拷贝到napi_generator/src/cli/h2sa/src/src/gen目录下;test.h文件示例如下所示: ``` #ifndef TEST_H @@ -62,58 +51,27 @@ namespace OHOS { */ ``` -### 工具使用 - -#### 命令行使用方法 - -[命令行使用说明](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) - -### 工具集成 +4.在napi_generator/src/cli/h2sa/src目录下执行命令生成service框架代码: -[工具输出文件集成到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) +``` +node main.js -f test.h +``` -## 版本说明 +其中,参数详情如下: + -f,定义远程服务的.h文件; + -l, 日志级别(0-3),默认为1; + -o,生成框架代码输入到指定路径下; + -s,指定serviceID。 -[已支持特性](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2sa/docs/release-notes/Service-1.0.md) +5.输出testservice文件夹,其中的文件如下所示: -[待开发特性](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2sa/docs/requirement/ROADMAP_ZH.md) +![](./docs/figures/h2sa_outRes.png) -## FAQ +### 集成 -[FAQ](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/h2sa/docs/guide/FAQ.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/tool/api/scan_README_ZH.md b/src/tool/api/scan_README_ZH.md index eac9153d52dc8cdb45e66faef5427c6ce10fe5df..bd352c7f96d728b5772e02971f85ce4916778d2f 100644 --- a/src/tool/api/scan_README_ZH.md +++ b/src/tool/api/scan_README_ZH.md @@ -2,14 +2,7 @@ ## 简介 -scan工具即API扫描工具,它可以扫描三方库中包含OpenHarmony源码不包含的接口,并输出result.xlsx文档。开发者移植三方库到OpenHarmony源码中,若三方库中包含一些OpenHarmony中不存在的接口,便会增加移植难度。此时可使用API扫描工具,提前预知风险接口,降低移植难度,提高开发效率。目前工具支持命令行和VS Code插件两种入口。 - - ├── napi_generator - │ ├── ... # 其它文档 - │ ├── src/tool - │ │ ├── api # api扫描工具 - │ │ | ├── api_scan_vs_plugin # VS Code插件源码 - │ │ | ├── ... +scan工具可以扫描三方库中包含OpenHarmony源码不包含的接口,并输出result.xlsx文档。开发者移植三方库到OpenHarmony源码中,若三方库中包含一些OpenHarmony中不存在的接口,便会增加移植难度。此时可使用API扫描工具,提前预知风险接口,降低移植难度,提高开发效率。 ## 约束 系统:建议Ubuntu 20.04或者Windows 10 @@ -18,46 +11,33 @@ scan工具即API扫描工具,它可以扫描三方库中包含OpenHarmony源 ## 使用方法 -### 使用对象 - -系统开发者 -### 使用场景 - -移植三方库到OpenHarmony前预知风险接口。 - -### 工具获取 - -#### 命令行 +1.下载Andr_N_Games_api.xlsx文件,并放置在napi_generator/src/tool/api/src文件夹下,下载链接如下: -命令行工具可根据源码自行打包,打包步骤如下: +// todo -[工具开发说明](https://gitee.com/openharmony/napi_generator/tree/master/src/tool/api/api_scan_vs_plugin/docs/DEVELOP_ZH.md) +2.安装typescript:在napi_generator/src/tool/api/src目录下执行命令: -#### vscode插件 + npm i typescript -工具支持VS Code插件,可在VS Code插件市场直接下载。 +3.安装stdio:在napi_generator/src/tool/api/src目录下执行命令: -### 工具输入 + npm i stdio -根据使用者指定三方库项目源码,工具会输出风险接口。为了方便使用者快速上手工具,此处使用opencv项目为例,项目目录如下: +4.根据使用者指定三方库项目源码,工具会输出风险接口。为了方便使用者快速上手工具,此处使用opencv项目为例,项目目录如下: ![](./figures/opencv.png) -### 工具使用 - -#### 命令行 - -[命令行使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/tool/api/docs/scan_INSRTUCTION_ZH.md) - -#### vscode插件 - -具体的工具使用步骤,可以左键单击以下链接了解: +5.在napi_generator/src/tool/api/src下执行以下命令: -[工具使用说明](https://gitee.com/openharmony/napi_generator/tree/master/src/tool/api/api_scan_vs_plugin/docs/INSTRUCTION_ZH.md) +``` +node scan.js -d E:\aboutTest\opencv-4.x\opencv-4.x -o E:\aboutTest\opencv-4.x\opencv-4.x +``` -### 工具输出 +其中,参数详情如下: + -d, 被扫描项目的路径 + -o, 可选参数,默认为当前路径下,输出结果存放路径。 -在window环境下的,根据输入三方库项目,生成的输出文件result.xlsx,如下所示: +6.在window环境下的,根据输入三方库项目,生成的输出文件result.xlsx,如下所示: ![](./figures/opencv_result.png) @@ -66,19 +46,3 @@ scan工具即API扫描工具,它可以扫描三方库中包含OpenHarmony源 ![](./figures/opencv_include.png) ![](./figures/opencv_h.png) - -## 版本说明 - -暂无 - -## FAQ - - [FAQ](https://gitee.com/openharmony/napi_generator/tree/master/src/tool/api/FAQ.md) - -## 参与贡献 - -暂无 - -## 相关仓 - -暂无