• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# GN脚本转换工具可执行程序使用说明
2## 简介
3
4gn脚本生成工具目前支持两种入口,分别是可执行程序、VS Code插件,推荐使用VSCode插件。可执行文件、VS Code插件下载路径如下:
5
6[下载链接](http://ftpkaihongdigi.i234.me:5000/fsdownload/1OjtRhtGf/gn-gen-0.0.1)
7
8下载文件说明如下:
9
10	│   │   |── res                           # 工具所需make文件
11	│   │   |── gn-0.0.1.vsix                 # VS Code插件
12	│   │   |── gn-gen-linux                  # Linux可执行程序
13	│   │   |── gn-gen-win.exe                # Windows可执行程序
14	│   │   └── gn-gen-macos                  # Mac可执行程序
15
16## 工具介绍
17
18通过gn-gen生成工具,使用者可以基于OpenHarmony源码、已有编译脚本(目前支持cmake、make两种类型),生成OpenHarmony编译所需BUILD.gn脚本,实现将三方库移植到OpenHarmony上。gn-gen生成工具的软件架构如下:
19
20![](./../figures/gn_framework.png)
21
22## 可执行程序使用方法
23
24### 环境说明
25
261、安装cmake,安装命令如下:
27
28	sudo apt-get install cmake
29
30### 生成ohos.toolchain.cmake
31
321、Ubuntu中下载OpenHarmony源码,并编译成功一个产品的镜像包,此处以RK3568为例。源码如下所示:
33
34![](./../figures/pic-openharmony.png)
35
362、将待转换的三方库项目(路径:[三方库项目](https://gitee.com/openharmony/third_party_mbedtls))放置在third_party文件夹下,如下所示:
37
38![](./../figures/pic-mbedtls-development.png)
39
403、将下载的可执行程序gn-gen-linux与文件夹res放置在任意同一文件夹下。并将gn-gen-linux文件与res/linux/bin下文件赋可执行权限,如下所示:
41
42	 harmony@Ubuntu-64:~/service/example$ ls
43	 gn-gen-linux  res
44	 harmony@Ubuntu-64:~/service/example$ sudo chmod -R 777 ./*
45	 harmony@Ubuntu-64:~/service/example$ ll -A
46	 总用量 116572
47	 -rwxrwxrwx 1 harmony harmony 119361984 12月 15 09:41 gn-gen-linux*
48	 drwxrwxrwx 5 harmony harmony      4096 12月 14 15:33 res/
49
504、在终端中进入到可执行程序gn-gen-linux所在的目录,并运行gn-gen-linux,命令如下:
51
52	harmony@Ubuntu-64:~/service/example$ ./gn-gen-linux -o out/khdvk_rk3568_a -p /home/harmony/OpenHarmony -f third_party/mbedtls-development/CMakeLists.txt -t cmake -s test_subsystem -m mbedtls-development
53
54![](./../figures/pic-generate-command.png)
55
56其中,参数详情如下:
57
58  -o:必填参数,ohos产品输出相对路径(例如:out/khdvk_rk3568_a);
59
60  -p:必填参数,ohos项目路径(例如:/home/harmony/OpenHarmony);
61
62  -f:必选参数,待转换三方库cmake文件相对路径(例如:third_party/mbedtls-development/CMakeLists.txt);
63
64  -t:可选参数,默认为cmake;
65
66  -s:可选参数,默认填写“test_subsystem”,使用者可根据实际情况修改子系统名称;
67
68  -m:可选参数,工具默认填写“test_part”,使用者可根据实际情况修改组件名称;
69
70  -d:可选参数,工具默认填写待转换三方库cmake文件所在文件夹相对路径,使用者可根据实际情况修改路径;
71
72  -a:可选参数,待转换三方库中引用其它三方库时需填写该选项,具体填写方法可参考FAQ中libcoap转换时问题解决方法,详细FAQ内容可左键单击以下链接了解:[FAQ](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/cmake2gn/docs/guide/FAQ.md)73
745、运行完成后,进入/OpenHarmony/third_party/mbedtls-development/build_tmp目录下,查看是否存在ohos.toolchain.cmake文件,如下所示:
75
76	 harmony@Ubuntu-64:~/service/example$ cd /home/harmony/OpenHarmony/third_party/mbedtls-development/build_tmp/
77	 harmony@Ubuntu-64:~/OpenHarmony/third_party/mbedtls-development/build_tmp$ ll -A
78	 总用量 228
79	 drwxrwxr-x  3 harmony harmony   4096 12月 16 11:54 3rdparty/
80	 -rw-rw-r--  1 harmony harmony  14658 12月 16 11:55 BUILD.gn
81	 drwxrwxr-x  2 harmony harmony   4096 12月 16 11:54 cmake/
82	 -rw-rw-r--  1 harmony harmony  17144 12月 16 11:54 CMakeCache.txt
83	 drwxrwxr-x 10 harmony harmony   4096 12月 16 11:54 CMakeFiles/
84	 -rw-rw-r--  1 harmony harmony   3879 12月 16 11:54 cmake_install.cmake
85	 -rw-rw-r--  1 harmony harmony    432 12月 16 11:54 CTestTestfile.cmake
86	 -rwxr--r--  1 harmony harmony    110 12月 16 11:54 DartConfiguration.tcl*
87	 drwxrwxr-x  3 harmony harmony   4096 12月 16 11:54 include/
88	 drwxrwxr-x  3 harmony harmony   4096 12月 16 11:55 library/
89	 -rw-rw-r--  1 harmony harmony 122917 12月 16 11:54 Makefile
90	 -rw-rw-r--  1 harmony harmony   1851 12月 16 11:54 ohos.toolchain.cmake
91	 drwxrwxr-x 14 harmony harmony   4096 12月 16 11:54 programs/
92	 lrwxrwxrwx  1 harmony harmony     65 12月 16 11:54 scripts -> /home/harmony/OpenHarmony/third_party/mbedtls-development/scripts/
93	 drwxrwxr-x  4 harmony harmony  20480 12月 16 11:55 tests/
94
95### 运行cmake脚本
96
971、在终端中进入ohos.toolchain.cmake所在的build_tmp目录下,运行cmake,查看cmake环境是否可以正常使用,命令如下:
98
99	 harmony@Ubuntu-64:~/OpenHarmony/third_party/mbedtls-development/build_tmp$ cmake .. -DCMAKE_TOOLCHAIN_FILE=ohos.toolchain.cmake
100	 -- The C compiler identification is Clang 10.0.1
101	 -- Check for working C compiler: /home/harmony/OpenHarmony/prebuilts/clang/ohos/linux-x86_64/llvm/bin/clang
102	 -- Check for working C compiler: /home/harmony/OpenHarmony/prebuilts/clang/ohos/linux-x86_64/llvm/bin/clang -- works
103	 -- Detecting C compiler ABI info
104	 -- Detecting C compiler ABI info - done
105	 -- Detecting C compile features
106	 -- Detecting C compile features - done
107	 -- Configuring done
108	 -- Generating done
109	 -- Build files have been written to: /home/harmony/OpenHarmony/third_party/mbedtls-development/build_tmp
110
111根据以上日志可发现cmake运行成功,环境正常使用。若运行cmake失败,则根据报错信息修改,直到cmake运行成功,环境正常使用为止。
112
113### 生成gn脚本
114
1151、在终端中进入到可执行程序gn-gen-linux所在的目录,并运行gn-gen-linux,命令如下:
116
117	harmony@Ubuntu-64:~/service/example$ ./gn-gen-linux -o out/khdvk_rk3568_a -p /home/harmony/OpenHarmony -f  third_party/mbedtls-development/CMakeLists.txt -s test_subsystem -m mbedtls-development
118	INFO (1) -- The C compiler identification is Clang 10.0.1
119
120	INFO (2) -- Check for working C compiler: /home/harmony/OpenHarmony/prebuilts/clang/ohos/linux-x86_64/llvm/bin/clang
121
122	INFO (3) -- Check for working C compiler: /home/harmony/OpenHarmony/prebuilts/clang/ohos/linux-x86_64/llvm/bin/clang -- works
123
124	......
125
126	INFO (647) -------------------generate gn ok
127
128其中,参数详情如生成ohos.toolchain.cmake中步骤4。
129
1302.运行成功后会在/OpenHarmony/third_party/mbedtls-development目录下生成build_tmp文件夹,build_tmp文件夹中包含BUILD.gn文件,如下所示:
131
132![](./../figures/pic-build-tmp.png)
133
134## VS Code插件使用方法
135
136具体的插件使用步骤,可以左键单击以下链接了解:
137
138[VS插件使用说明](https://gitee.com/openharmony/napi_generator/tree/master/src/vscode_plugin/cmake2gn/gn_vs_plugin/docs/usage/INSTRUCTION_ZH.md)
139
140## 将三方库集成到OpenHarmony的方法
141
142具体的将三方库集成到OpenHarmony的步骤,可以左键单击以下链接了解:
143
144[将三方库集成到OpenHarmony的方法](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/cmake2gn/docs/usage/ENSEMBLE_METHOD_ZH.md)
145