1e41f4b71Sopenharmony_ci# Reference 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci## deps and external_deps 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ciWhen 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. 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci**Dependency Types** 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ciThe dependency between modules can be classified into **deps** (left in the figure above) and **external_deps** (right in the figure above). 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci- **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. 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci- **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. 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci- Example of **deps**: 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci ```shell 20e41f4b71Sopenharmony_ci import("//build/ohos.gni") 21e41f4b71Sopenharmony_ci ohos_shared_library("module1") { 22e41f4b71Sopenharmony_ci ... 23e41f4b71Sopenharmony_ci part_name = "part1" # (Mandatory) Name of the component to which the module belongs. 24e41f4b71Sopenharmony_ci ... 25e41f4b71Sopenharmony_ci } 26e41f4b71Sopenharmony_ci ``` 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci ```shell 29e41f4b71Sopenharmony_ci import("//build/ohos.gni") 30e41f4b71Sopenharmony_ci ohos_shared_library("module2") { 31e41f4b71Sopenharmony_ci ... 32e41f4b71Sopenharmony_ci deps = [ 33e41f4b71Sopenharmony_ci "GN target of module 1", 34e41f4b71Sopenharmony_ci ... 35e41f4b71Sopenharmony_ci ] # Intra-component dependency 36e41f4b71Sopenharmony_ci part_name = "part1" # (Mandatory) Name of the component to which the module belongs. 37e41f4b71Sopenharmony_ci } 38e41f4b71Sopenharmony_ci ``` 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci- Example of **external_deps**: 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci ```shell 43e41f4b71Sopenharmony_ci import("//build/ohos.gni") 44e41f4b71Sopenharmony_ci ohos_shared_library("module1") { 45e41f4b71Sopenharmony_ci ... 46e41f4b71Sopenharmony_ci part_name = "part1" # (Mandatory) Name of the component to which the module belongs. 47e41f4b71Sopenharmony_ci ... 48e41f4b71Sopenharmony_ci } 49e41f4b71Sopenharmony_ci ``` 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci ```shell 52e41f4b71Sopenharmony_ci import("//build/ohos.gni") 53e41f4b71Sopenharmony_ci ohos_shared_library("module2") { 54e41f4b71Sopenharmony_ci ... 55e41f4b71Sopenharmony_ci external_deps = [ 56e41f4b71Sopenharmony_ci "part1:module1", 57e41f4b71Sopenharmony_ci ... 58e41f4b71Sopenharmony_ci ] # Inter-component dependency. The dependent module must be declared in inner_kits by the dependent component. 59e41f4b71Sopenharmony_ci part_name = "part2" # (Mandatory) Name of the component to which the module belongs. 60e41f4b71Sopenharmony_ci } 61e41f4b71Sopenharmony_ci ``` 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci > **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**. 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci## Using Sanitizer 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ciWhen 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 and **false** by default. You can also leave it empty. 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ciSanitizer configuration example: 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci``` shell 72e41f4b71Sopenharmony_ci ohos_shared_library("example") { 73e41f4b71Sopenharmony_ci sanitize = { 74e41f4b71Sopenharmony_ci cfi = true # Enable the CFI check. 75e41f4b71Sopenharmony_ci cfi_cross_dso = true # Enable the cross-DSO CFI check. 76e41f4b71Sopenharmony_ci integer_overflow = true # Enable the integer overflow check. 77e41f4b71Sopenharmony_ci boundary_sanitize = true # Enable the bounds check. 78e41f4b71Sopenharmony_ci ubsan = true # Enable some UBSAN options. 79e41f4b71Sopenharmony_ci all_ubsan = true # Enable all UBSAN options. 80e41f4b71Sopenharmony_ci debug = true # Enable the debug mode, which is disabled by default. 81e41f4b71Sopenharmony_ci blocklist = "./blocklist.txt" # Path of the blocklist. 82e41f4b71Sopenharmony_ci } 83e41f4b71Sopenharmony_ci ... 84e41f4b71Sopenharmony_ci } 85e41f4b71Sopenharmony_ci``` 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci**Supported Sanitizer Types** 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ciCurrently, Sanitizers provides the following functions: 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci- **integer_overflow**: provides check of unsigned integer overflow (unsigned_integer_overflow), check of signed integer overflow (signed_integer_overflow), or both (integer_overflow). 92e41f4b71Sopenharmony_ci- CFI: provides CFI and cross-DSO CFI checks. 93e41f4b71Sopenharmony_ci- **boundary_sanitize**: provides the bounds check. 94e41f4b71Sopenharmony_ci- **ubsan**: checks some Undefined Behavior Sanitizer (UBSAN) options, including **bool**, **integer-divide-by-zero**, **return**, **returns-nonnull-attribute**, **shift-exponent**, **unreachable**, and **vla-bound**. 95e41f4b71Sopenharmony_ci- **all_ubsan**: checks all UBSAN options. 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci**Release and Debug Modes** 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci**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. 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci- 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. 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci- 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. 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ci**Blocklist** 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ciThe 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. 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ciBlocklist example: 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci``` 113e41f4b71Sopenharmony_ci[cfi] 114e41f4b71Sopenharmony_cifun:*([Tt]est|TEST)* 115e41f4b71Sopenharmony_cifun: main 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ci[integer] 118e41f4b71Sopenharmony_cisrc:example/*.cpp 119e41f4b71Sopenharmony_ci``` 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ci## Information Collected by the Open Source Software Notice 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ciAn open source software notice is a file related to the project open source. It collects license information to comply with open source specifications. 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci**Information to Collect** 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ciThe 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. 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ciA 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. 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ciThe final **Notice.txt** file must include all licenses used by the files in the image and the mapping between modules and licenses. 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ciThe **Notice.txt** file is located in the **/system/etc/** directory. 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ci**Rules for Collecting Information** 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ciLicenses are collected by priority, which ranges from 1 to 4 in descending order of seniority. 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci1. Licenses that are directly declared in a module's **BUILD.gn** are given the top priority. The following is an example: 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci ```shell 143e41f4b71Sopenharmony_ci ohos_shared_library("example") { 144e41f4b71Sopenharmony_ci ... 145e41f4b71Sopenharmony_ci license_file = "path-to-license-file" 146e41f4b71Sopenharmony_ci ... 147e41f4b71Sopenharmony_ci } 148e41f4b71Sopenharmony_ci ``` 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci2. 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. 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci3. 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. 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ci4. If no license is found, the default license (Apache License 2.0) will be used. 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ciPay attention to the following: 157e41f4b71Sopenharmony_ci 158e41f4b71Sopenharmony_ci- 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. 159e41f4b71Sopenharmony_ci- 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. 160e41f4b71Sopenharmony_ci- 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**. 161e41f4b71Sopenharmony_ci 162e41f4b71Sopenharmony_ci## Parameters for Accelerating Local Build 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ciThe following parameters can be added to the build command to speed up the build process: 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_ci- **--ccache** 167e41f4b71Sopenharmony_ci - 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. 168e41f4b71Sopenharmony_ci - Installing ccache: 169e41f4b71Sopenharmony_ci - Quick installation: Run the **sudo apt-get install ccache** command. 170e41f4b71Sopenharmony_ci - Download the binary file from the [official website](https://ccache.dev/download.html) and configure the ccache path to the environment variable. 171e41f4b71Sopenharmony_ci - Usage: Run the **./build.sh --product-name** *Product_name* **--ccache** command. 172e41f4b71Sopenharmony_ci- **--fast-rebuild** 173e41f4b71Sopenharmony_ci - 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. 174e41f4b71Sopenharmony_ci - Usage: Run the **./build.sh --product-name** *Product_name* **--fast-rebuild** command. 175e41f4b71Sopenharmony_ci- **enable_notice_collection=false** 176e41f4b71Sopenharmony_ci - Adding this parameter can skip the process of collecting the module licenses of the open-source software. 177e41f4b71Sopenharmony_ci - Usage: Run the **./build.sh --product-name** *Product_name* **--gn-args --enable_notice_collection=false --ccache** command. 178e41f4b71Sopenharmony_ci- **--build-target** 179e41f4b71Sopenharmony_ci - This parameter specifies the module to compile. You can obtain the module name as follows: 180e41f4b71Sopenharmony_ci - Pay attention to keywords such as **group**, **ohos_shared_library**, and **ohos_executable** in **BUILD.gn**. 181e41f4b71Sopenharmony_ci - 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. 182e41f4b71Sopenharmony_ci - Usage: Run the **./build.sh --product-name** *Product_name* **--build-target ark_js_host_linux_tools_packages** command. 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci## Viewing Ninja Build Information 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ciThe **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. 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ciThe four columns are start time, end time, modified timestamp (mtime), and command hash from left to right. 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ci 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ciYou can graphically display the build time as follows: 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ci- Open **build.trace** locally. 195e41f4b71Sopenharmony_ci Decompress **out/rk3568/build.trace.gz** and drag **build.trace** to **chrome://tracing/**. 196e41f4b71Sopenharmony_ci- Open **build.trace** at **ci.openharmony.cn/events**. 197e41f4b71Sopenharmony_ci You can open the **build.trace.html** file in each compilation output as follows: 198e41f4b71Sopenharmony_ci 1. Click **Success** under **Static Check**. 199e41f4b71Sopenharmony_ci 200e41f4b71Sopenharmony_ci 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. 201e41f4b71Sopenharmony_ci 202e41f4b71Sopenharmony_ci## Customizing the chip_prod Image 203e41f4b71Sopenharmony_ci 204e41f4b71Sopenharmony_ci### When to Use 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_ciThe different capabilities for the products in the same chip solution are placed in the **chip_prod** partition. You need to generate the **chip_prod.img** specific to the product. 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci### Procedure 209e41f4b71Sopenharmony_ci1. Configure the **config.json** file. 210e41f4b71Sopenharmony_ci 211e41f4b71Sopenharmony_ci In the **config.json** file, add **chipprod_config_path**, which specifies the path of the product definition file. 212e41f4b71Sopenharmony_ci The file is named **chip_product_list.gni**, and in the **chip_product_list = ["productA", "productB", ...]** format. 213e41f4b71Sopenharmony_ci 214e41f4b71Sopenharmony_ci Example: 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_ci To customize **chip_prod.img** for **MyProduct**, modify the **//vendor/Product vendor/MyProduct/config.json** as follows: 217e41f4b71Sopenharmony_ci 218e41f4b71Sopenharmony_ci ```shell 219e41f4b71Sopenharmony_ci { 220e41f4b71Sopenharmony_ci "product_name": "MyProduct", # Product name. 221e41f4b71Sopenharmony_ci "version": "3.0", # config.json version, which is 3.0. 222e41f4b71Sopenharmony_ci "chipprod_config_path": "", # (Optional) Path of the chipprod configuration file. 223e41f4b71Sopenharmony_ci "subsystems": [ 224e41f4b71Sopenharmony_ci { 225e41f4b71Sopenharmony_ci "subsystem": "arkui", # Subsystem of the product. 226e41f4b71Sopenharmony_ci "components": [ 227e41f4b71Sopenharmony_ci { 228e41f4b71Sopenharmony_ci "component": "ace_engine", 229e41f4b71Sopenharmony_ci "features":[ "ace_engine_feature_enable_web = true", 230e41f4b71Sopenharmony_ci "ace_engine_feature_enable_accessibility = true" ] } 231e41f4b71Sopenharmony_ci ] 232e41f4b71Sopenharmony_ci }, 233e41f4b71Sopenharmony_ci { 234e41f4b71Sopenharmony_ci ... 235e41f4b71Sopenharmony_ci } 236e41f4b71Sopenharmony_ci ... 237e41f4b71Sopenharmony_ci More subsystems and components. 238e41f4b71Sopenharmony_ci } 239e41f4b71Sopenharmony_ci } 240e41f4b71Sopenharmony_ci ``` 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ci2. Configure the module. 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_ci If the configuration file has different product configurations, for example, to generate **chip_prod.img** for product A, you need to configure **install_images** and **module_install_dir** for module compilation. 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ci The following uses **ohos_prebuilt_executable** as an example: 247e41f4b71Sopenharmony_ci 248e41f4b71Sopenharmony_ci ```shell 249e41f4b71Sopenharmony_ci ohos_prebuilt_executable("moduleXXX"){ 250e41f4b71Sopenharmony_ci install_images = [ "chip_prod" ] 251e41f4b71Sopenharmony_ci module_install_dir = "productA/etc/***" # The path must start with productA. 252e41f4b71Sopenharmony_ci } 253e41f4b71Sopenharmony_ci ``` 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_ci3. Run the build command. 256e41f4b71Sopenharmony_ci```shell 257e41f4b71Sopenharmony_ci./build.sh --product-name {product_name} --build-target chip_prod_image 258e41f4b71Sopenharmony_ci``` 259e41f4b71Sopenharmony_ci 260e41f4b71Sopenharmony_ci4. Generate the images. 261e41f4b71Sopenharmony_ci If products A and B are defined (**chip_product_list = ["productA", "productB"]**) and a module is installed in the products, the following images are generated: 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_ci ``` 264e41f4b71Sopenharmony_ci images/productA/chip_prod.img 265e41f4b71Sopenharmony_ci images/productB/chip_prod.img 266e41f4b71Sopenharmony_ci ``` 267