• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Reference
2
3## deps and external_deps
4
5When adding a module, you must declare its dependencies in **BUILD.gn**. **deps** specifies dependent modules in the same component, and **external_deps** specifies dependent modules between components.
6
7**Dependency Types**
8
9![Dependency Types](figures/dependency_types.png)
10
11The dependency between modules can be classified into **deps** (left in the figure above) and **external_deps** (right in the figure above).
12
13- **deps**: The dependent module to be added belongs to the same part with the current module. For example, module 2 depends on module 1, and both modules 1 and 2 belong to the same component.
14
15- **external_deps**: The dependent module to be added belongs to another component. For example, module 2 depends on module 1, and modules 1 and 2 belong to different components.
16
17- Example of **deps**:
18
19  ```shell
20  import("//build/ohos.gni")
21  ohos_shared_library("module1") {
22    ...
23    part_name = "part1"   # (Mandatory) Name of the component to which the module belongs.
24    ...
25  }
26  ```
27
28  ```shell
29  import("//build/ohos.gni")
30  ohos_shared_library("module2") {
31    ...
32    deps = [
33      "GN target of module 1",
34    ...
35   ]                      # Intra-component dependency
36  part_name = "part1"     # (Mandatory) Name of the component to which the module belongs.
37  }
38  ```
39
40- Example of **external_deps**:
41
42  ```shell
43  import("//build/ohos.gni")
44  ohos_shared_library("module1") {
45    ...
46    part_name = "part1"   # (Mandatory) Name of the component to which the module belongs.
47    ...
48  }
49  ```
50
51  ```shell
52  import("//build/ohos.gni")
53  ohos_shared_library("module2") {
54    ...
55    external_deps = [
56      "part1:module1",
57    ...
58    ]                     # Inter-component dependency. The dependent module must be declared in inner_kits by the dependent component.
59    part_name = "part2"   # (Mandatory) Name of the component to which the module belongs.
60  }
61  ```
62
63  ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>The dependency between components must be written in the format of **Component name:Module name** in **external_deps**. The dependent module must be declared in **inner_kits**.
64
65## Using Sanitizer
66
67When adding a module, you can enable the Sanitizer, such as the integer overflow check and control-flow integrity (CFI), provided by the compiler as required. You can also enable the debug or release mode and configure a blocklist. Each configuration item is optional. It is **false** by default. You can also leave it empty.
68
69Sanitizer configuration example:
70
71``` shell
72  ohos_shared_library("example") {
73    sanitize = {
74      cfi = true
75      integer_overflow = true
76      debug = true                           # Optional. The debug mode is disabled by default.
77      blocklist = "./blocklist.txt"          # Optional. Enter the path of the blocklist.
78    }
79    ...
80  }
81```
82
83**Supported Sanitizer Types**
84
85Currently, the following two types of Sanitizers are supported:
86
87- Integer overflow check: provides check of unsigned integer overflow (unsigned_integer_overflow), check of signed integer overflow (signed_integer_overflow), or both (integer_overflow).
88- CFI: prevents malware attacks from redirecting the control flow of a program.
89
90**Release and Debug Modes**
91
92**Debug** specifies whether the debug mode or the release mode is used. The default value **false** indicates that the release mode is used. The value **true** explicitly declares the debug mode. The **debug** option takes effect only for the Sanitizer and does not determine whether a module is debuggable. In the build configuration for a module in release version, you are advised to set **debug** to **false** (enable the release mode) or leave it unspecified.
93
94- Debug mode: If debug mode is enabled, abundant error-related information is provided to help locate faults. When an error occurs, the application will be resumed instead of being interrupted to further identify subsequent errors.
95
96- Release mode: If release mode is enabled, the application will be directly interrupted when an error occurs. This can protect the system against errors or maliciously attacks.
97
98**Blocklist**
99
100The blocklist specifies the functions or source programs that are not affected by Sanitizer in the module. It prevents benign behavior from being identified as errors or prevents hotspot functions from generating unreasonable and unacceptable overheads. Exercise caution when using this function.
101
102Blocklist example:
103
104```
105[cfi]
106fun:*([Tt]est|TEST)*
107fun: main
108
109[integer]
110src:example/*.cpp
111```
112
113
114## Information Collected by the Open Source Software Notice
115
116An open source software notice is a file related to the project open source. It collects license information to comply with open source specifications.
117
118**Information to Collect**
119
120The notice collects only the licenses of the modules packaged in the image. For example, the licenses of the tools (such as Clang, Python, and Ninja) used during the build process are not collected.
121
122A static library itself is not packaged. However, if it is packaged into the system as part of a dynamic library or an executable file, the license of the static library will be collected for completeness.
123
124The final **Notice.txt** file must include all licenses used by the files in the image and the mapping between modules and licenses.
125
126The **Notice.txt** file is located in the **/system/etc/** directory.
127
128**Rules for Collecting Information**
129
130Licenses are collected by priority, which ranges from 1 to 4 in descending order of seniority.
131
1321. Licenses that are directly declared in a module's **BUILD.gn** are given the top priority. The following is an example:
133
134   ```shell
135   ohos_shared_library("example") {
136       ...
137       license_file = "path-to-license-file"
138       ...
139   }
140   ```
141
1422. If there is no explicitly declared license, the build script searches for the **Readme.OpenSource** file in the directory of **BUILD.gn**, parses the file, and collects the obtained licenses. If the **Readme.OpenSource** file does not contain license information, an error will be reported.
143
1443. If the **Readme.OpenSource** file does not exist, the build script searches for the **License**, **Copyright**, and **Notice** files from the current directory to the root directory of the source code by default. The obtained license information will be used as the licenses of the module.
145
1464. If no license is found, the default license (Apache License 2.0) will be used.
147
148Pay attention to the following:
149
150- For third-party open-source software, such as OpenSSL and ICU, **Readme.OpenSource** must be configured in the source code directory. Check whether **Readme.OpenSource** is in the same directory as **BUILD.gn** and whether the licenses configured in **Readme.OpenSource** are valid.
151- If the source code is not licensed under Apache License 2.0, the corresponding license file must be provided in the source code directory or declared in **license_file** for the module.
152- If the source code file added to **BUILD.gn** is not from the current directory, check whether the license in the repository where the source code file is located is the same as that in the repository of **BUILD.gn**.
153
154## Parameters for Accelerating Local Build
155
156The following parameters can be added to the build command to speed up the build process:
157
158- **--ccache**
159  - Ccache caches the output of C/C++ compilation. If the compilation input remains unchanged the next time, the compilation can be skipped and the output can be taken from the cache.
160  - Installing ccache:
161    - Quick installation: Run the **sudo apt-get install ccache** command.
162    - Download the binary file from the [official website](https://ccache.dev/download.html) and configure the ccache path to the environment variable.
163  - Usage: Run the **./build.sh --product-name** *Product_name* **--ccache** command.
164- **--fast-rebuild**
165  - The compilation process includes preloader -> loader -> GN -> Ninja. If the GN and product configuration files are not modified locally, adding **--fast-rebuild** will start from Ninja directly.
166  - Usage: Run the **./build.sh --product-name** *Product_name* **--fast-rebuild** command.
167- **enable_notice_collection=false**
168  - Adding this parameter can skip the process of collecting the module licenses of the open-source software.
169  - Usage: Run the **./build.sh --product-name** *Product_name* **--gn-args --enable_notice_collection=false --ccache** command.
170- **--build-target**
171  - This parameter specifies the module to compile. You can obtain the module name as follows:
172    - Pay attention to keywords such as **group**, **ohos_shared_library**, and **ohos_executable** in **BUILD.gn**.
173    - Run **./build.sh --product-name** *Product_name* **--build-target** *Module_name* **--build-only-gn** to generate **build.ninja** and locate the related module name in the file.
174  - Usage: Run the **./build.sh --product-name** *Product_name* **--build-target ark_js_host_linux_tools_packages** command.
175
176## Viewing Ninja Build Information
177
178The **out/rk3568/.ninja_log** file records the build start time and end time (ms) of each module. A shorter interval indicates a faster build and higher compilation performance.
179
180The four columns are start time, end time, modified timestamp (mtime), and command hash from left to right.
181
182![Ninja_Trace](figures/Ninja_Trace.png)
183
184You can graphically display the build time as follows:
185
186- Open **build.trace** locally.
187  Decompress **out/rk3568/build.trace.gz** and drag **build.trace** to **chrome://tracing/**.
188- Open **build.trace** at **ci.openharmony.cn/events**.
189  You can open the **build.trace.html** file in each compilation output as follows:
190  1. Click **Success** under **Static Check**.
191
192  2. Click **Output** in the **Output** column. The **build.trace.html** file is displayed in the **build_trace** column on the left. Click the file to open it.
193