|
Name |
|
Date |
Size |
#Lines |
LOC |
| .. | | - | - |
| build_scripts/ | | 12-May-2024 | - | 380 | 256 |
| common/ | | 12-May-2024 | - | 198 | 176 |
| config/ | | 12-May-2024 | - | 6,208 | 5,381 |
| core/ | | 12-May-2024 | - | 792 | 529 |
| docs/ | | 12-May-2024 | - | 467 | 344 |
| lite/ | | 12-May-2024 | - | 16,773 | 13,622 |
| loader/ | | 12-May-2024 | - | 1,983 | 1,552 |
| misc/ | | 12-May-2024 | - | 844 | 443 |
| ohos/ | | 12-May-2024 | - | 10,615 | 8,420 |
| scripts/ | | 12-May-2024 | - | 4,195 | 3,066 |
| templates/ | | 12-May-2024 | - | 2,193 | 1,884 |
| toolchain/ | | 12-May-2024 | - | 2,287 | 1,678 |
| tools/ | | 12-May-2024 | - | 801 | 550 |
| .gitattributes | D | 12-May-2024 | 631 | 16 | 15 |
| .gitignore | D | 12-May-2024 | 43 | 6 | 5 |
| LICENSE | D | 12-May-2024 | 2.2 KiB | 47 | 39 |
| OAT.xml | D | 12-May-2024 | 12 KiB | 148 | 91 |
| README_zh.md | D | 12-May-2024 | 6.2 KiB | 186 | 129 |
| bundle.json | D | 12-May-2024 | 1.4 KiB | 58 | 58 |
| gn_helpers.py | D | 12-May-2024 | 12 KiB | 360 | 266 |
| ohos.gni | D | 12-May-2024 | 1.1 KiB | 31 | 25 |
| ohos_system.prop | D | 12-May-2024 | 867 | 28 | 21 |
| ohos_var.gni | D | 12-May-2024 | 5.2 KiB | 203 | 156 |
| prebuilts_download.sh | D | 12-May-2024 | 11.9 KiB | 270 | 221 |
| print_python_deps.py | D | 12-May-2024 | 5 KiB | 139 | 108 |
| subsystem_config.json | D | 12-May-2024 | 4 KiB | 183 | 182 |
| subsystem_config_example.json | D | 12-May-2024 | 170 | 9 | 8 |
| test.gni | D | 12-May-2024 | 11.7 KiB | 433 | 387 |
| version.gni | D | 12-May-2024 | 953 | 34 | 29 |
| zip.py | D | 12-May-2024 | 1.2 KiB | 45 | 28 |
README_zh.md
1# 编译构建<a name="ZH-CN_TOPIC_0000001124588563"></a>
2
3- [简介](#section11660541593)
4- [目录](#section161941989596)
5- [约束与限制](#section2029921310472)
6- [说明](#section1312121216216)
7- [常见问题说明](#section131336181)
8- [相关仓](#section1371113476307)
9
10## 简介<a name="section11660541593"></a>
11
12编译构建子系统提供了一个基于Gn和ninja的编译构建框架。
13
14根据产品配置,编译生成对应的镜像包。其中编译构建流程为:
15
161. 使用Gn配置构建目标。
172. Gn运行后会生成ninja文件。
183. 通过运行ninja来执行编译任务。
19
20## 目录<a name="section161941989596"></a>
21
22```
23/build # 编译构建主目录
24├── config # 编译相关的配置项
25├── core
26│ └── gn # 编译入口BUILD.gn配置
27├── loader # 各个部件配置加载、模板生成
28├── ohos # OpenHarmony编译打包流程配置
29│ ├── kits # kits编译打包模板和处理流程
30│ ├── ndk # ndk模板和处理流程
31│ ├── notice # notice模板和处理流程
32│ ├── packages # 版本打包模板和处理流程
33│ ├── sa_profile # sa模板和处理流程
34│ ├── sdk # sdk模板和处理流程,包括sdk中包含的模块配置
35│ └── testfwk # 测试相关的处理
36├── scripts # 编译相关的python脚本
37├── templates # c/c++编译模板定义
38└── toolchain # 编译工具链配置
39```
40
41## 约束与限制<a name="section2029921310472"></a>
42
43- 编译环境需要Ubuntu18.04及以上版本。
44
45- 安装编译所需的程序包。
46
47 安装命令:
48
49 ```
50 sudo apt-get install binutils git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4
51 ```
52
53
54## 说明<a name="section1312121216216"></a>
55
561. 代码根目录下执行全量版本的编译命令:
57
58 ```
59 ./build.sh --product-name {product_name}
60 ```
61
62 编译结果镜像输出在 out/ohos-arm-relese/packages/phone/images/目录下。
63
642. 编译命令支持选项:
65
66 ```
67 --product-name # 必须 编译的产品名称,如:Hi3516DV300
68 --build-target # 可选 指定编译目标,可以指定多个
69 --gn-args # 可选 gn参数,支持指定多个
70 --ccache # 可选 编译使用ccache,需要本地安装ccache
71 --sparse-image # 可选 生成sparse镜像,需要本地安装img2simg,默认镜像为raw
72 ```
73
743. 在已有部件中增加模块。
75
76 **支持的模板类型:**
77
78 ```
79 ohos_executable
80 ohos_shared_library
81 ohos_static_library
82 ohos_source_set
83
84 # 预编译模板:
85 ohos_prebuilt_executable
86 ohos_prebuilt_shared_library
87 ohos_prebuilt_etc
88 ```
89
90 在模块目录下配置BUILD.gn,根据类型选择对应的模板。
91
92 **例子:**
93
94 _ohos\_shared\_library示例:_
95
96 ```
97 import("//build/ohos.gni")
98 ohos_shared_library("helloworld") {
99 sources = []
100 include_dirs = []
101 cflags = []
102 cflags_c = []
103 cflags_cc = []
104 ldflags = []
105 configs = []
106 deps =[] # 部件内模块依赖
107
108 # 跨部件模块依赖定义,
109 # 定义格式为 "部件名:模块名称"
110 # 这里依赖的模块必须是依赖的部件声明在inner_kits中的模块
111 external_deps = [
112 "part_name:module_name",
113 ]
114
115 output_name = "" # 可选,模块输出名
116 output_extension = "" # 可选,模块名后缀
117 module_install_dir = "" #可选,缺省在/system/lib64或/system/lib下, 模块安装路径,模块安装路径,从system/,vendor/后开始指定
118 relative_install_dir = "" #可选,模块安装相对路径,相对于/system/lib64或/system/lib;如果有module_install_dir配置时,该配置不生效
119
120 part_name = "" # 必选,所属部件名称
121 }
122 ```
123
124 _ohos\_executable示例:_
125
126 ohos\_executable模板属性和ohos\_shared\_library基本一致
127
128 _注意:可执行模块(即ohos\_executable模板定义的)默认是不安装的,如果要安装,需要指定install\_enable = true_
129
130 _ohos\_prebuilt\_etc示例:_
131
132 ```
133 import("//build/ohos.gni")
134 ohos_prebuilt_etc("etc_file") {
135 source = "file"
136 deps = [] # 部件内模块依赖
137 module_install_dir = "" #可选,模块安装路径,从system/,vendor/后开始指定
138 relative_install_dir = "" #可选,模块安装相对路径,相对于system/etc;如果有module_install_dir配置时,该配置不生效
139 part_name = "" # 必选,所属部件名称
140 }
141 ```
142
1434. 部件配置。
144
145 部件配置在所属子系统的根目录下的 ohos.build文件中,一个子系统可以配置多个部件。
146
147 一个部件包含module\_list、inner\_kits、system\_kits、test\_list四个部分的声明:
148
149 - module\_list:部件包含的模块列表
150 - inner\_kits:部件提供其它部件的接口
151 - system\_kits:部件提供给生成应用的接口
152 - test\_list:部件对应模块的测试用例
153
154 ohos.build中各个配置,都只是声明,具体的模块配置还是在对应的BUILD.gn中。
155
1565. ohos-sdk编译。
157
158 **编译命令:**
159
160 ``` ./build.sh --product-name ohos-sdk --ccache ```
161
162 **结果输出:**
163
164 ``` out/ohos-arm64-release/packages/ohos-sdk/ ```
165
166 **ohos-sdk模块配置:**
167
168 ``` build/ohos/sdk/ohos_sdk_description_std.json ```
169
170
171
172## 常见问题说明<a name="section131336181"></a>
173
174**如何将一个模块编译并打包到版本中?**
175
176- 模块要指定part\_name,指定它归属的部件,一个模块只能属于一个部件;
177- 部件的模块,要在部件配置的module\_list中,或者可以被module\_list中的模块依赖到;
178- 部件要加到对应产品的部件列表中;
179
180## 相关仓<a name="section1371113476307"></a>
181
182编译构建子系统
183
184**build**
185
186