• Home
Name Date Size #Lines LOC

..--

docs/12-May-2024-390258

figures/12-May-2024-

gn-gen/12-May-2024-1,6221,424

gn_IntelliJ_plugin/12-May-2024-2,5011,656

gn_vs_plugin/12-May-2024-1,8971,553

FAQ.mdD12-May-20247.8 KiB16085

README_ZH.mdD12-May-202419.2 KiB291247

README_ZH.md

1# GN脚本转换工具
2
3## 简介
4
5本文主要介绍gn脚本生成工具,它可以根据三方库的CMakeLists.txt文件,编译转换生成BUILD.gn脚本文件。当前OpenHarmony源码只支持BUILD.gn文件编译,开发者无法移植CMakeLists.txt编译方式的三方库到OpenHarmony中。此时,开发者可使用GN脚本转换工具,根据CMakeLists.txt文件生成BUILD.gn脚本文件,降低移植难度,提高开发效率。目前工具支持可执行文件、VS Code插件两种入口。
6
7更多工具的架构和实现原理详情,可以左键单击以下链接了解:
8
9[工具使用说明](https://gitee.com/openharmony/napi_generator/tree/master/hdc/gn/docs/INSTRUCTION_ZH.md)
10
11	├── napi_generator                           # NAPI框架代码生成工具
12	│   ├── ...                                  # 其他文档
13	│   ├── hdc
14	│   │   ├── ...                              # 其他工具
15	│   │   ├── gn                               # GN脚本转换工具
16	│   │   |   ├── gn_vs_plugin                 # VS Code插件源码
17	│   │   |   ├── gn-gen                       # GN工具源码
18	│   │   |   |   ├── main.js                  # 工具源码入口
19	│   │   |   |   ├── package.json             # package.json文件
20	│   │   |   |   |── src
21	│   │   |   |   |   |── analyze_cmake.js     # cmake解析器
22	│   │   |   |   |   |── analyze_command.js   # command解析器
23	│   │   |   |   |   |── analyze_make.js      # make解析器
24	│   │   |   |   |   |── generate_gn.js       # 生成器
25	│   │   |   |   |   |── logger.js            # log日志
26	│   │   |   |   |   |── tool.js              # 公共模块代码
27
28## 约束
29系统:建议Ubuntu 20.04或者Windows 10
30
31依赖版本:VS Code 1.62.0
32
33## 使用方法
34
35### 使用对象
36
37系统开发者
38### 使用场景
39
401) 移植CMakeLists.txt编译方式的三方库到OpenHarmony源码中。
41
42### 工具使用
43
44工具有两种类型,分别是可执行文件、VS Code插件。其中的可执行文件可根据工具使用者的开发环境选择,支持Windows,Linux和Mac。可执行文件、VS Code插件下载路径如下:
45
46[下载链接](http://ftpkaihongdigi.i234.me:5000/fsdownload/1OjtRhtGf/gn-gen-0.0.1)
47
48具体的工具使用步骤,可以左键单击以下链接了解:
49
50[工具使用说明](https://gitee.com/openharmony/napi_generator/tree/master/hdc/gn/docs/INSTRUCTION_ZH.md)
51
52### 工具输出
53
54根据使用者指定三方库的CMakeLists.txt文件,工具会输出对应的BUILD.gn文件。为了方便使用者快速上手工具,可供测试的三方库项目目录如下:
55
56```
57harmony@Ubuntu-64:~/OpenHarmony/third_party/mbedtls-development$ ls
583rdparty  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
59```
60
61在linux环境下的,根据输入三方库项目的CMakeLists.txt文件,生成的输出文件,如下所示:
62
63	harmony@Ubuntu-64:~/OpenHarmony/third_party/mbedtls-development$ ls
64	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
65	harmony@Ubuntu-64:~/OpenHarmony/third_party/mbedtls-development$ cd build_tmp/
66	harmony@Ubuntu-64:~/OpenHarmony/third_party/mbedtls-development/build_tmp$ ls
67	3rdparty  BUILD.gn  cmake  CMakeCache.txt  CMakeFiles  cmake_install.cmake  CTestTestfile.cmake  DartConfiguration.tcl  include  library  Makefile  ohos.toolchain.cmake  programs  scripts  tests
68
69其中生成的BUILD.gn文件,内容如下所示:
70
71```
72import("//build/ohos.gni")
73
74group("all_targets") {
75    deps = [
76        #静态库
77        "//third_party/mbedtls-development/build_tmp/library:mbedcrypto",
78        "//third_party/mbedtls-development/build_tmp/library:mbedx509",
79        "//third_party/mbedtls-development/build_tmp/library:mbedtls",
80
81        #可执行程序
82        "//third_party/mbedtls-development/build_tmp/programs/aes:crypt_and_hash",
83        "//third_party/mbedtls-development/build_tmp/programs/cipher:cipher_aead_demo",
84        "//third_party/mbedtls-development/build_tmp/programs/fuzz:fuzz_x509crl",
85        "//third_party/mbedtls-development/build_tmp/programs/fuzz:fuzz_x509csr",
86        "//third_party/mbedtls-development/build_tmp/programs/fuzz:fuzz_pubkey",
87        "//third_party/mbedtls-development/build_tmp/programs/fuzz:fuzz_pkcs7",
88        "//third_party/mbedtls-development/build_tmp/programs/fuzz:fuzz_privkey",
89        "//third_party/mbedtls-development/build_tmp/programs/fuzz:fuzz_client",
90        "//third_party/mbedtls-development/build_tmp/programs/fuzz:fuzz_dtlsserver",
91        "//third_party/mbedtls-development/build_tmp/programs/fuzz:fuzz_dtlsclient",
92        "//third_party/mbedtls-development/build_tmp/programs/fuzz:fuzz_x509crt",
93        "//third_party/mbedtls-development/build_tmp/programs/fuzz:fuzz_server",
94        "//third_party/mbedtls-development/build_tmp/programs/hash:generic_sum",
95        "//third_party/mbedtls-development/build_tmp/programs/hash:hello",
96        "//third_party/mbedtls-development/build_tmp/programs/hash:md_hmac_demo",
97        "//third_party/mbedtls-development/build_tmp/programs/pkey:mpi_demo",
98        "//third_party/mbedtls-development/build_tmp/programs/pkey:key_app",
99        "//third_party/mbedtls-development/build_tmp/programs/pkey:pk_encrypt",
100        "//third_party/mbedtls-development/build_tmp/programs/pkey:gen_key",
101        "//third_party/mbedtls-development/build_tmp/programs/pkey:ecdsa",
102        "//third_party/mbedtls-development/build_tmp/programs/pkey:rsa_encrypt",
103        "//third_party/mbedtls-development/build_tmp/programs/pkey:dh_client",
104        "//third_party/mbedtls-development/build_tmp/programs/pkey:dh_server",
105        "//third_party/mbedtls-development/build_tmp/programs/pkey:dh_genprime",
106        "//third_party/mbedtls-development/build_tmp/programs/pkey:ecdh_curve25519",
107        "//third_party/mbedtls-development/build_tmp/programs/pkey:pk_decrypt",
108        "//third_party/mbedtls-development/build_tmp/programs/pkey:pk_sign",
109        "//third_party/mbedtls-development/build_tmp/programs/pkey:key_app_writer",
110        "//third_party/mbedtls-development/build_tmp/programs/pkey:pk_verify",
111        "//third_party/mbedtls-development/build_tmp/programs/pkey:rsa_decrypt",
112        "//third_party/mbedtls-development/build_tmp/programs/pkey:rsa_genkey",
113        "//third_party/mbedtls-development/build_tmp/programs/pkey:rsa_sign",
114        "//third_party/mbedtls-development/build_tmp/programs/pkey:rsa_sign_pss",
115        "//third_party/mbedtls-development/build_tmp/programs/pkey:rsa_verify",
116        "//third_party/mbedtls-development/build_tmp/programs/pkey:rsa_verify_pss",
117        "//third_party/mbedtls-development/build_tmp/programs/psa:key_ladder_demo",
118        "//third_party/mbedtls-development/build_tmp/programs/psa:crypto_examples",
119        "//third_party/mbedtls-development/build_tmp/programs/psa:aead_demo",
120        "//third_party/mbedtls-development/build_tmp/programs/psa:hmac_demo",
121        "//third_party/mbedtls-development/build_tmp/programs/psa:psa_constant_names",
122        "//third_party/mbedtls-development/build_tmp/programs/random:gen_entropy",
123        "//third_party/mbedtls-development/build_tmp/programs/random:gen_random_ctr_drbg",
124        "//third_party/mbedtls-development/build_tmp/programs/ssl:ssl_pthread_server",
125        "//third_party/mbedtls-development/build_tmp/programs/ssl:ssl_client1",
126        "//third_party/mbedtls-development/build_tmp/programs/ssl:ssl_client2",
127        "//third_party/mbedtls-development/build_tmp/programs/ssl:mini_client",
128        "//third_party/mbedtls-development/build_tmp/programs/ssl:dtls_server",
129        "//third_party/mbedtls-development/build_tmp/programs/ssl:dtls_client",
130        "//third_party/mbedtls-development/build_tmp/programs/ssl:ssl_server",
131        "//third_party/mbedtls-development/build_tmp/programs/ssl:ssl_server2",
132        "//third_party/mbedtls-development/build_tmp/programs/ssl:ssl_context_info",
133        "//third_party/mbedtls-development/build_tmp/programs/ssl:ssl_fork_server",
134        "//third_party/mbedtls-development/build_tmp/programs/ssl:ssl_mail_client",
135        "//third_party/mbedtls-development/build_tmp/programs/test:selftest",
136        "//third_party/mbedtls-development/build_tmp/programs/test:benchmark",
137        "//third_party/mbedtls-development/build_tmp/programs/test:udp_proxy",
138        "//third_party/mbedtls-development/build_tmp/programs/test:query_compile_time_config",
139        "//third_party/mbedtls-development/build_tmp/programs/test:zeroize",
140        "//third_party/mbedtls-development/build_tmp/programs/util:pem2der",
141        "//third_party/mbedtls-development/build_tmp/programs/util:strerror",
142        "//third_party/mbedtls-development/build_tmp/programs/x509:load_roots",
143        "//third_party/mbedtls-development/build_tmp/programs/x509:cert_req",
144        "//third_party/mbedtls-development/build_tmp/programs/x509:cert_write",
145        "//third_party/mbedtls-development/build_tmp/programs/x509:crl_app",
146        "//third_party/mbedtls-development/build_tmp/programs/x509:req_app",
147        "//third_party/mbedtls-development/build_tmp/programs/x509:cert_app",
148        "//third_party/mbedtls-development/build_tmp/tests:test_suite_x509write",
149        "//third_party/mbedtls-development/build_tmp/tests:test_suite_x509parse",
150        "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_its",
151        "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_storage_format.current",
152        "//third_party/mbedtls-development/build_tmp/tests:test_suite_timing",
153        "//third_party/mbedtls-development/build_tmp/tests:test_suite_ssl",
154        "//third_party/mbedtls-development/build_tmp/tests:test_suite_rsa",
155        "//third_party/mbedtls-development/build_tmp/tests:test_suite_entropy",
156        "//third_party/mbedtls-development/build_tmp/tests:test_suite_shax",
157        "//third_party/mbedtls-development/build_tmp/tests:test_suite_hmac_drbg.pr",
158        "//third_party/mbedtls-development/build_tmp/tests:test_suite_dhm",
159        "//third_party/mbedtls-development/build_tmp/tests:test_suite_ecdsa",
160        "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.des",
161        "//third_party/mbedtls-development/build_tmp/tests:test_suite_poly1305",
162        "//third_party/mbedtls-development/build_tmp/tests:test_suite_ctr_drbg",
163        "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.null",
164        "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.gcm",
165        "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_storage_format.misc",
166        "//third_party/mbedtls-development/build_tmp/tests:test_suite_ccm",
167        "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.camellia",
168        "//third_party/mbedtls-development/build_tmp/tests:test_suite_chachapoly",
169        "//third_party/mbedtls-development/build_tmp/tests:test_suite_mdx",
170        "//third_party/mbedtls-development/build_tmp/tests:test_suite_des",
171        "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.chacha20",
172        "//third_party/mbedtls-development/build_tmp/tests:test_suite_bignum.generated",
173        "//third_party/mbedtls-development/build_tmp/tests:test_suite_bignum_mod",
174        "//third_party/mbedtls-development/build_tmp/tests:test_suite_chacha20",
175        "//third_party/mbedtls-development/build_tmp/tests:test_suite_aria",
176        "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_not_supported.generated",
177        "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.padding",
178        "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.nist_kw",
179        "//third_party/mbedtls-development/build_tmp/tests:test_suite_aes.ofb",
180        "//third_party/mbedtls-development/build_tmp/tests:test_suite_hmac_drbg.nopr",
181        "//third_party/mbedtls-development/build_tmp/tests:test_suite_aes.ecb",
182        "//third_party/mbedtls-development/build_tmp/tests:test_suite_hkdf",
183        "//third_party/mbedtls-development/build_tmp/tests:test_suite_aes.cfb",
184        "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.ccm",
185        "//third_party/mbedtls-development/build_tmp/tests:test_suite_pkcs5",
186        "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.aes",
187        "//third_party/mbedtls-development/build_tmp/tests:test_suite_bignum.misc",
188        "//third_party/mbedtls-development/build_tmp/tests:test_suite_aes.rest",
189        "//third_party/mbedtls-development/build_tmp/tests:test_suite_cmac",
190        "//third_party/mbedtls-development/build_tmp/tests:test_suite_camellia",
191        "//third_party/mbedtls-development/build_tmp/tests:test_suite_ecdh",
192        "//third_party/mbedtls-development/build_tmp/tests:test_suite_md",
193        "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.chachapoly",
194        "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_storage_format.v0",
195        "//third_party/mbedtls-development/build_tmp/tests:test_suite_asn1parse",
196        "//third_party/mbedtls-development/build_tmp/tests:test_suite_asn1write",
197        "//third_party/mbedtls-development/build_tmp/tests:test_suite_base64",
198        "//third_party/mbedtls-development/build_tmp/tests:test_suite_bignum_mod_raw.generated",
199        "//third_party/mbedtls-development/build_tmp/tests:test_suite_oid",
200        "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.misc",
201        "//third_party/mbedtls-development/build_tmp/tests:test_suite_bignum_core.misc",
202        "//third_party/mbedtls-development/build_tmp/tests:test_suite_ecjpake",
203        "//third_party/mbedtls-development/build_tmp/tests:test_suite_bignum_core.generated",
204        "//third_party/mbedtls-development/build_tmp/tests:test_suite_bignum_mod_raw",
205        "//third_party/mbedtls-development/build_tmp/tests:test_suite_random",
206        "//third_party/mbedtls-development/build_tmp/tests:test_suite_aes.cbc",
207        "//third_party/mbedtls-development/build_tmp/tests:test_suite_pk",
208        "//third_party/mbedtls-development/build_tmp/tests:test_suite_version",
209        "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_se_driver_hal_mocks",
210        "//third_party/mbedtls-development/build_tmp/tests:test_suite_bignum_mod.generated",
211        "//third_party/mbedtls-development/build_tmp/tests:test_suite_debug",
212        "//third_party/mbedtls-development/build_tmp/tests:test_suite_pkcs1_v21",
213        "//third_party/mbedtls-development/build_tmp/tests:test_suite_gcm.aes128_de",
214        "//third_party/mbedtls-development/build_tmp/tests:test_suite_cipher.aria",
215        "//third_party/mbedtls-development/build_tmp/tests:test_suite_gcm.aes128_en",
216        "//third_party/mbedtls-development/build_tmp/tests:test_suite_gcm.aes192_de",
217        "//third_party/mbedtls-development/build_tmp/tests:test_suite_gcm.camellia",
218        "//third_party/mbedtls-development/build_tmp/tests:test_suite_gcm.aes192_en",
219        "//third_party/mbedtls-development/build_tmp/tests:test_suite_gcm.aes256_de",
220        "//third_party/mbedtls-development/build_tmp/tests:test_suite_gcm.aes256_en",
221        "//third_party/mbedtls-development/build_tmp/tests:test_suite_gcm.misc",
222        "//third_party/mbedtls-development/build_tmp/tests:test_suite_hmac_drbg.misc",
223        "//third_party/mbedtls-development/build_tmp/tests:test_suite_hmac_drbg.no_reseed",
224        "//third_party/mbedtls-development/build_tmp/tests:test_suite_lms",
225        "//third_party/mbedtls-development/build_tmp/tests:test_suite_mps",
226        "//third_party/mbedtls-development/build_tmp/tests:test_suite_memory_buffer_alloc",
227        "//third_party/mbedtls-development/build_tmp/tests:test_suite_net",
228        "//third_party/mbedtls-development/build_tmp/tests:test_suite_nist_kw",
229        "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_metadata",
230        "//third_party/mbedtls-development/build_tmp/tests:test_suite_pkparse",
231        "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_hash",
232        "//third_party/mbedtls-development/build_tmp/tests:test_suite_pem",
233        "//third_party/mbedtls-development/build_tmp/tests:test_suite_pkcs12",
234        "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_attributes",
235        "//third_party/mbedtls-development/build_tmp/tests:test_suite_aes.xts",
236        "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_op_fail.generated",
237        "//third_party/mbedtls-development/build_tmp/tests:test_suite_pkcs1_v15",
238        "//third_party/mbedtls-development/build_tmp/tests:test_suite_pkcs7",
239        "//third_party/mbedtls-development/build_tmp/tests:test_suite_pkwrite",
240        "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto",
241        "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_not_supported.misc",
242        "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_driver_wrappers",
243        "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_entropy",
244        "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_generate_key.generated",
245        "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_init",
246        "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_op_fail.misc",
247        "//third_party/mbedtls-development/build_tmp/tests:test_suite_error",
248        "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_pake",
249        "//third_party/mbedtls-development/build_tmp/tests:test_suite_lmots",
250        "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_persistent_key",
251        "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_se_driver_hal",
252        "//third_party/mbedtls-development/build_tmp/tests:test_suite_ecp",
253        "//third_party/mbedtls-development/build_tmp/tests:test_suite_psa_crypto_slot_management",
254
255    ]
256}
257
258```
259
260## 工具开发说明
261
262### 对象
263
264工具的开发者
265
266### 开发场景
267
268若当前工具的功能已经不能满足开发者的全部需求,则开发者可以基于已有的源码对工具进行二次开发,来增强工具的能力,编译打包生成自定义的可执行文件和插件。
269
270### 开发步骤
271
272开发者可以根据如下的步骤来完成对工具的开发:
273
274 [工具开发说明](https://gitee.com/openharmony/napi_generator/tree/master/hdc/gn/docs/DEVELOP_ZH.md)
275
276## 版本说明
277
278[版本说明](https://gitee.com/openharmony/napi_generator/tree/master/hdc/gn/docs/gn-gen-release-notes-0.0.2.md)
279
280## FAQ
281
282  [FAQ](https://gitee.com/openharmony/napi_generator/tree/master/hdc/gn/FAQ.md)
283
284## 参与贡献
285
286暂无
287
288## 相关仓
289
290暂无
291