• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# GN脚本转换工具使用说明
2
3## 简介
4
5gn脚本生成工具目前支持两种入口,分别是可执行程序、VS Code插件,推荐使用VS Code插件。可执行文件、VS Code插件下载路径如下:
6
7[下载链接](http://ftpkaihongdigi.i234.me:5000/fsdownload/1OjtRhtGf/gn-gen-0.0.1)
8
9下载文件说明如下:
10
11	│   │   |── res                           # 工具所需make文件
12	│   │   |── gn-0.0.1.vsix                 # VS Code插件
13	│   │   |── gn-gen-linux                  # Linux可执行程序
14	│   │   |── gn-gen-win.exe                # Windows可执行程序
15	│   │   └── gn-gen-macos                  # Mac可执行程序
16
17## 工具介绍
18
19通过gn-gen生成工具,使用者可以基于OpenHarmony源码、已有编译脚本(目前支持cmake、make两种类型),生成OpenHarmony编译所需BUILD.gn脚本,实现将三方库移植到OpenHarmony上。gn-gen生成工具的软件架构如下:
20
21![](./../../figures/gn_framework.png)
22
23## 使用工具生成gn脚本
24
25### VS Code插件使用方法
26
27#### 环境说明
28
291、安装cmake,安装命令如下:
30
31	sudo apt-get install cmake
32
33#### 生成ohos.toolchain.cmake
34
351、Ubuntu中下载OpenHarmony源码,并编译成功一个产品的镜像包,此处以RK3568为例。源码如下所示:
36
37![](./../../figures/pic-openharmony.png)
38
392、将待转换的三方库项目(路径:[三方库项目](https://gitee.com/openharmony/third_party_mbedtls))放置在third_party文件夹下,如下所示:
40
41![](./../../figures/pic-mbedtls-development.png)
42
433、打开VS Code,在左侧边栏中选择插件安装。
44
45![](./../../figures/pic-plug-in-search.png)
46
474、 在应用商店搜索gn-gen插件,再单击安装。
48
49![](./../../figures/pic-plug-in-select.png)
50
515、 安装完成后就会在VS Code的插件管理器中能看到gn这个插件了。
52
53![](./../../figures/pic-plug-in-gn.png)
54
556、 选中任意文件或文件夹,点击右键,选择“Gn Generate Frame”选项。
56
57![](./../../figures/pic-plug-in-gn-c++.png)
58
597、 Gn Generate Frame中参数填写完成之后,点击ok,如下所示:
60
61![](./../../figures/pic-gn-frame.png)
62
63参数详情如下:
64
65工程输出路径:必填参数,ohos产品输出相对路径(例如:out/khdvk_rk3568_a);
66
67工程源码路径:必填参数,ohos项目路径(例如:/home/harmony/OpenHarmony);
68
69输入脚本路径:必选参数,待转换三方库cmake文件相对路径(例如:third_party/mbedtls-development/CMakeLists.txt);
70
71输入脚本类型: 可选参数,默认为cmake;
72
73GN生成路径: 可选参数,工具默认填写待转换三方库cmake文件所在文件夹相对路径,使用者可根据实际情况修改路径;
74
75子系统名称: 可选参数,默认填写“test_subsystem”,使用者可根据实际情况修改名称;
76
77组件名称:可选参数,工具默认填写“test_part”,使用者可根据实际情况修改名称;
78
79编译选项:可选参数,待转换三方库中引用其它三方库时需填写该选项,具体填写方法可参考FAQ中libpng转换时问题解决方法,详细FAQ内容可左键单击以下链接了解:[FAQ](https://gitee.com/openharmony/napi_generator/blob/master/hdc/gn/FAQ.md)80
81扩展文件类型:默认为否,部分三方库编译脚本需要支持的特殊文件类型,具体填写方法可参考FAQ中libpng转换时问题解决方法,详细FAQ内容可左键单击以下链接了解:[FAQ](https://gitee.com/openharmony/napi_generator/blob/master/hdc/gn/FAQ.md)82
83扩展编译选项:默认为否,部分三方库编译脚本需要支持的特殊编译选项,具体填写方法可参考FAQ中curl转换时步骤3解决方法,详细FAQ内容可左键单击以下链接了解:[FAQ](https://gitee.com/openharmony/napi_generator/blob/master/hdc/gn/FAQ.md)84
858.运行完成后,进入/OpenHarmony/third_party/mbedtls-development/build_tmp目录下,查看是否存在ohos.toolchain.cmake文件,如下所示:
86
87	 harmony@Ubuntu-64:~/service/example$ cd /home/harmony/OpenHarmony/third_party/mbedtls-development/build_tmp/
88	 harmony@Ubuntu-64:~/OpenHarmony/third_party/mbedtls-development/build_tmp$ ll -A
89	 总用量 228
90	 drwxrwxr-x  3 harmony harmony   4096 12月 16 11:54 3rdparty/
91	 -rw-rw-r--  1 harmony harmony  14658 12月 16 11:55 BUILD.gn
92	 drwxrwxr-x  2 harmony harmony   4096 12月 16 11:54 cmake/
93	 -rw-rw-r--  1 harmony harmony  17144 12月 16 11:54 CMakeCache.txt
94	 drwxrwxr-x 10 harmony harmony   4096 12月 16 11:54 CMakeFiles/
95	 -rw-rw-r--  1 harmony harmony   3879 12月 16 11:54 cmake_install.cmake
96	 -rw-rw-r--  1 harmony harmony    432 12月 16 11:54 CTestTestfile.cmake
97	 -rwxr--r--  1 harmony harmony    110 12月 16 11:54 DartConfiguration.tcl*
98	 drwxrwxr-x  3 harmony harmony   4096 12月 16 11:54 include/
99	 drwxrwxr-x  3 harmony harmony   4096 12月 16 11:55 library/
100	 -rw-rw-r--  1 harmony harmony 122917 12月 16 11:54 Makefile
101	 -rw-rw-r--  1 harmony harmony   1851 12月 16 11:54 ohos.toolchain.cmake
102	 drwxrwxr-x 14 harmony harmony   4096 12月 16 11:54 programs/
103	 lrwxrwxrwx  1 harmony harmony     65 12月 16 11:54 scripts -> /home/harmony/OpenHarmony/third_party/mbedtls-development/scripts/
104	 drwxrwxr-x  4 harmony harmony  20480 12月 16 11:55 tests/
105
106#### 运行make脚本
107
1081、若build_tmp下存在ohos.toolchain.cmake文件,在终端中进入build_tmp目录下,运行make,查看cmake环境是否可以正常使用,命令如下:
109
110	 harmony@Ubuntu-64:~/OpenHarmony/third_party/mbedtls-development/build_tmp$ cmake .. -DCMAKE_TOOLCHAIN_FILE=ohos.toolchain.cmake
111	 -- The C compiler identification is Clang 10.0.1
112	 -- Check for working C compiler: /home/harmony/OpenHarmony/prebuilts/clang/ohos/linux-x86_64/llvm/bin/clang
113	 -- Check for working C compiler: /home/harmony/OpenHarmony/prebuilts/clang/ohos/linux-x86_64/llvm/bin/clang -- works
114	 -- Detecting C compiler ABI info
115	 -- Detecting C compiler ABI info - done
116	 -- Detecting C compile features
117	 -- Detecting C compile features - done
118	 -- Configuring done
119	 -- Generating done
120	 -- Build files have been written to: /home/harmony/OpenHarmony/third_party/mbedtls-development/build_tmp
121
122根据以上日志可发现make运行成功,环境正常使用。若运行make失败,则根据报错信息修改,直到make运行成功,环境正常使用为止。
123
124#### 生成gn脚本
125
1261、 Gn Generate Frame中参数填写如下:
127
128![](./../../figures/pic-gn-frame.png)
129
130具体参数填写参考生成ohos.toolchain.cmake中步骤7。
131
1322.运行成功后会在/OpenHarmony/third_party/mbedtls-development目录下生成build_tmp文件夹,build_tmp文件夹中包含BUILD.gn文件,如下所示:
133
134![](./../../figures/pic-build-tmp.png)
135
136### 可执行程序使用方法
137
138具体可执行程序使用步骤,可以左键单击以下链接了解:
139
140[可执行程序使用说明](https://gitee.com/openharmony/napi_generator/blob/master/hdc/gn/docs/INSTRUCTION_ZH.md)
141
142## 将三方库集成到OpenHarmony的方法
143
144具体的将三方库集成到OpenHarmony的步骤,可以左键单击以下链接了解:
145
146[将三方库集成到OpenHarmony的方法](https://gitee.com/openharmony/napi_generator/tree/master/hdc/gn/docs/ENSEMBLE_METHOD_ZH.md)
147