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