1e41f4b71Sopenharmony_ci# Compilation and Building Guide 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci## Overview 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ciThe OpenHarmony Compilation and Building subsystem provides a build framework based on Generate Ninja (GN) and Ninja. It abstracts the build and configuration granularity by component, and provides function enhancement for built-in modules and function extension for service modules. The OpenHarmony Compilation and Building subsystem provides the following functions: 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci- Allows products to be assembled and independently built by component. 8e41f4b71Sopenharmony_ci- Supports version builds for mini, small, and standard systems and build of the software development kit (SDK), which facilitates application developers to use the Integrated development environment (IDE). 9e41f4b71Sopenharmony_ci- Supports customization and independent build based on different chipset solutions. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci### Application Scope 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ciThis guide is applicable to mini, small, and standard systems. The [Chipset Solution](subsys-build-chip_solution.md) applies only to mini and small systems. 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci### Basic Concepts 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ciLearn the following basic concepts before you get started: 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci- Platform 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci A platform consists of a development board and the kernel. The subsystems and components vary with the platform. 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci- Product 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci A product is a collection of components. The product image built can run on different development boards. 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci- Subsystem 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci OpenHarmony is designed with a layered architecture, which consists of the kernel layer, system service layer, framework layer, and application layer from bottom up. For details, see [OpenHarmony Technical Architecture](https://gitee.com/openharmony#technical-architecture). System functions are built from components, subsystems, and then to the system. In a multi-device deployment, you can customize subsystems and components as required. A subsystem, as a logical concept, consists of the least required components. 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci- Component 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci A component is a reusable software binary unit that contains source code, configuration files, resource files, and build scripts. It can be built independently, integrated in binary mode, and tested independently. The chipset solution mentioned in this guide is a special component in nature. 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci- Module 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci A module is a target to build. A component can also be a target to build. 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci- Feature 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci A component can provide differentiated functions through features. 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci- GN 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci GN is used to generate Ninja files. 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci- Ninja 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci Ninja is a small high-speed build system. 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci- hb 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci hb is an OpenHarmony command line tool used to execute build commands. 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ciThe Compilation and Build subsystem implements compilation and packaging through configuration. The following describes the relationships between the product, subsystem, component, and module. 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci**Figure 1** Relationships between product, subsystem, component, and module 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ciThe relationships between the product, subsystem, component, and module are as follows: 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci- A subsystem is a collection of all components. A component can belong to only one subsystem. 65e41f4b71Sopenharmony_ci- A component is a collection of modules. A module can belong to only one component. 66e41f4b71Sopenharmony_ci- The product configuration file contains the configuration of all the components of the product. The component configuration can be reused. 67e41f4b71Sopenharmony_ci- A component used in different products can provide differentiated functions through variants or features. 68e41f4b71Sopenharmony_ci- A module is a target to build, and a component can also be a target to build. 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci### Working Principles 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ciA product, component, and module can be built, but a subsystem cannot. The figure below shows the build process. 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci**Figure 2** Build process 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci1. Run **hb set** to set the product to build. 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci2. Use **hb build** to build a product, development board, or component. 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci The procedure is as follows: 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci 1. Read the **config.gni** file of the development board selected. The file contains the build toolchain, linking commands, and build options. 85e41f4b71Sopenharmony_ci 2. Run the **gn gen** command to read the product configuration and generate the **out** directory and **ninja** files for the product solution. 86e41f4b71Sopenharmony_ci 3. Run **ninja -C out/board/product** to start the build. 87e41f4b71Sopenharmony_ci 4. Package the files built, set the file attributes and permissions, and create a file system image. 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci### Constraints 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ciCurrently, only Ubuntu18.04 and Ubuntu20.04 are supported. Ubuntu22.04 is not supported. 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci### Environment Configuration 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ciYou must install the software packages required for build. The command is as follows: 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci- Method 1: Run the script in the project directory. 98e41f4b71Sopenharmony_ci ```shell 99e41f4b71Sopenharmony_ci ./build/build_scripts/env_setup.sh 100e41f4b71Sopenharmony_ci ``` 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci- Method 2: Run the **apt-get install** and **pip3 install** commands. 103e41f4b71Sopenharmony_ci ```shell 104e41f4b71Sopenharmony_ci apt-get update -y 105e41f4b71Sopenharmony_ci apt-get install -y 106e41f4b71Sopenharmony_ci # Install Python 3.9 for Ubuntu 20.04, and install Python 3.8 for Ubuntu 18.04. 107e41f4b71Sopenharmony_ci apt-get install -y apt-utils binutils bison flex bc build-essential make mtd-utils gcc-arm-linux-gnueabi u-boot-tools python3.9 python3-pip git zip unzip curl wget gcc g++ ruby dosfstools mtools default-jre default-jdk scons python3-distutils perl openssl libssl-dev cpio git-lfs m4 ccache zlib1g-dev tar rsync liblz4-tool genext2fs binutils-dev device-tree-compiler e2fsprogs git-core gnupg gnutls-bin gperf lib32ncurses5-dev libffi-dev zlib* libelf-dev libx11-dev libgl1-mesa-dev lib32z1-dev xsltproc x11proto-core-dev libc6-dev-i386 libxml2-dev lib32z-dev libdwarf-dev 108e41f4b71Sopenharmony_ci apt-get install -y grsync xxd libglib2.0-dev libpixman-1-dev kmod jfsutils reiserfsprogs xfsprogs squashfs-tools pcmciautils quota ppp libtinfo-dev libtinfo5 libncurses5 libncurses5-dev libncursesw5 libstdc++6 gcc-arm-none-eabi vim ssh locales doxygen 109e41f4b71Sopenharmony_ci apt-get install -y libxinerama-dev libxcursor-dev libxrandr-dev libxi-dev 110e41f4b71Sopenharmony_ci # The following modules must be installed for Python. You can obtain the repo file from the source code of the build environment you use. 111e41f4b71Sopenharmony_ci chmod +x /usr/bin/repo 112e41f4b71Sopenharmony_ci pip3 install --trusted-host https://repo.huaweicloud.com -i https://repo.huaweicloud.com/repository/pypi/simple requests setuptools pymongo kconfiglib pycryptodome ecdsa ohos-build pyyaml prompt_toolkit==1.0.14 redis json2html yagmail python-jenkins 113e41f4b71Sopenharmony_ci pip3 install esdk-obs-python --trusted-host pypi.org 114e41f4b71Sopenharmony_ci pip3 install six --upgrade --ignore-installed six 115e41f4b71Sopenharmony_ci #Install LLVM, hc-gen, gcc_riscv32, Ninja, node-v14.15.4-linux-x64, and GN. If the shell in use is not bash or zsh, configure the following environment variables: 116e41f4b71Sopenharmony_ci # export PATH=/home/tools/llvm/bin:$PATH 117e41f4b71Sopenharmony_ci # export PATH=/home/tools/hc-gen:$PATH 118e41f4b71Sopenharmony_ci # export PATH=/home/tools/gcc_riscv32/bin:$PATH 119e41f4b71Sopenharmony_ci # export PATH=/home/tools/ninja:$PATH 120e41f4b71Sopenharmony_ci # export PATH=/home/tools/node-v12.20.0-linux-x64/bin:$PATH 121e41f4b71Sopenharmony_ci # export PATH=/home/tools/gn:$PATH 122e41f4b71Sopenharmony_ci # export PATH=~/.local/bin:$PATH 123e41f4b71Sopenharmony_ci ``` 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ci >**NOTE** 126e41f4b71Sopenharmony_ci > 127e41f4b71Sopenharmony_ci >The hb tool will be installed during the installation of **ohos-build**. If hb tool fails to be installed, [install hb](../../device-dev/quick-start/quickstart-pkg-install-tool.md#hb-installation) again. 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ci## Configuration Rules 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ciTo ensure that chipset and product solutions are decoupled from OpenHarmony, you need to follow certain rules during the configuration. 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci- [Product Configuration Rules](subsys-build-product.md#configuration-rules) 135e41f4b71Sopenharmony_ci- [Subsystem Configuration Rules](subsys-build-subsystem.md#configuration-rules) 136e41f4b71Sopenharmony_ci- [Component Configuration Rules](subsys-build-component.md#configuration-rules) 137e41f4b71Sopenharmony_ci- [Module Configuration Rules](subsys-build-module.md#configuration-rules) 138e41f4b71Sopenharmony_ci- [Rust Module Configuration Rules](subsys-build-rust-compilation.md#configuration-rules) 139e41f4b71Sopenharmony_ci- [Chipset Solution Configuration Rules](subsys-build-chip_solution.md#configuration-rules) 140e41f4b71Sopenharmony_ci- [Feature Configuration Rules](subsys-build-feature.md#configuration-rules) 141e41f4b71Sopenharmony_ci- [System Capability Configuration Rules](subsys-build-syscap.md) 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci## Guidelines 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ci### Directory Structure 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci```shell 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ci/build # Directory for build 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci├── __pycache__ 152e41f4b71Sopenharmony_ci├── build_scripts/ # Python scripts for build 153e41f4b71Sopenharmony_ci├── common/ 154e41f4b71Sopenharmony_ci├── config/ # Build-related configuration 155e41f4b71Sopenharmony_ci├── core 156e41f4b71Sopenharmony_ci│ └── gn/ # BUILD.gn configuration 157e41f4b71Sopenharmony_ci └── build_scripts/ 158e41f4b71Sopenharmony_ci├── docs 159e41f4b71Sopenharmony_cign_helpers.py* 160e41f4b71Sopenharmony_cilite/ # hb and preloader entry 161e41f4b71Sopenharmony_cimisc/ 162e41f4b71Sopenharmony_ci├── ohos # Configuration of OpenHarmony build and packaging 163e41f4b71Sopenharmony_ci│ ├── kits # Kits build and packaging templates and processing 164e41f4b71Sopenharmony_ci│ ├── ndk # NDK templates and processing 165e41f4b71Sopenharmony_ci│ ├── notice # Notice templates and processing 166e41f4b71Sopenharmony_ci│ ├── packages # Distribution packaging templates and processing 167e41f4b71Sopenharmony_ci│ ├── sa_profile # SA profiles and processing 168e41f4b71Sopenharmony_ci│ ├── sdk # SDK templates and processing, which contains the module configuration in the SDK 169e41f4b71Sopenharmony_ci│ └── testfwk # Testing-related processing 170e41f4b71Sopenharmony_ci├── ohos.gni* # Common .gni files (facilitating one-time import of each module) 171e41f4b71Sopenharmony_ci├── ohos_system.prop 172e41f4b71Sopenharmony_ci├── ohos_var.gni* 173e41f4b71Sopenharmony_ci├── prebuilts_download.sh* 174e41f4b71Sopenharmony_ci├── print_python_deps.py* 175e41f4b71Sopenharmony_ci├── scripts/ 176e41f4b71Sopenharmony_ci├── subsystem_config.json 177e41f4b71Sopenharmony_ci├── subsystem_config_example.json 178e41f4b71Sopenharmony_ci├── templates/ # C/C++ build templates 179e41f4b71Sopenharmony_ci├── test.gni* 180e41f4b71Sopenharmony_ci├── toolchain # Build toolchain configuration 181e41f4b71Sopenharmony_ci├── tools # Common tools 182e41f4b71Sopenharmony_ci├── version.gni 183e41f4b71Sopenharmony_ci├── zip.py* 184e41f4b71Sopenharmony_ci 185e41f4b71Sopenharmony_ci``` 186e41f4b71Sopenharmony_ci 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci 189e41f4b71Sopenharmony_ci### Build Commands 190e41f4b71Sopenharmony_ci 191e41f4b71Sopenharmony_ciRun the **prebuilts** script in the root directory of the source code to perform precompilation and install the compiler and binary tool. 192e41f4b71Sopenharmony_ci 193e41f4b71Sopenharmony_ci```shell 194e41f4b71Sopenharmony_cibash build/prebuilts_download.sh 195e41f4b71Sopenharmony_ci``` 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_ciThen, run the build commands in command line (CLI) mode or hb mode. 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_ci1. Using the CLI 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci - Run the following command in the root directory of the source code to build a full distribution: 202e41f4b71Sopenharmony_ci 203e41f4b71Sopenharmony_ci Release version: 204e41f4b71Sopenharmony_ci 205e41f4b71Sopenharmony_ci ```shell 206e41f4b71Sopenharmony_ci ./build.sh --product-name {product_name} 207e41f4b71Sopenharmony_ci ``` 208e41f4b71Sopenharmony_ci 209e41f4b71Sopenharmony_ci Debug version: 210e41f4b71Sopenharmony_ci 211e41f4b71Sopenharmony_ci ```shell 212e41f4b71Sopenharmony_ci ./build.sh --product-name {product_name} --gn-args is_debug=true 213e41f4b71Sopenharmony_ci ``` 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ci > **CAUTION** 216e41f4b71Sopenharmony_ci > 217e41f4b71Sopenharmony_ci > Due to the limitation of the image size, the full build for the debug version may fail to be burnt. You are advised to build the binary file for each module separately. Run the following command to build a module separately: 218e41f4b71Sopenharmony_ci > 219e41f4b71Sopenharmony_ci > ``` 220e41f4b71Sopenharmony_ci > ./build.sh --product-name {product_name} --gn-args is_debug=true --build-target {target_name} 221e41f4b71Sopenharmony_ci > ``` 222e41f4b71Sopenharmony_ci > 223e41f4b71Sopenharmony_ci > **{product_name}** specifies the product platform supported by the current distribution, for example, **hispark_taurus_standard**. 224e41f4b71Sopenharmony_ci > 225e41f4b71Sopenharmony_ci > The image generated is stored in the **out/{device_name}/packages/phone/images/** directory. 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci - The **./build.sh** command supports the following options: 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ci ```shell 230e41f4b71Sopenharmony_ci -h, --help # Display help information and exit. 231e41f4b71Sopenharmony_ci --source-root-dir=SOURCE_ROOT_DIR # Specify the path. 232e41f4b71Sopenharmony_ci --product-name=PRODUCT_NAME # Specify the product name. 233e41f4b71Sopenharmony_ci --device-name=DEVICE_NAME # Specify the device name. 234e41f4b71Sopenharmony_ci --target-cpu=TARGET_CPU # Specify the CPU. 235e41f4b71Sopenharmony_ci --target-os=TARGET_OS # Specify the operating system. 236e41f4b71Sopenharmony_ci -T BUILD_TARGET, --build-target=BUILD_TARGET # Specify one or more targets to build. 237e41f4b71Sopenharmony_ci --gn-args=GN_ARGS # Specify GN parameters. 238e41f4b71Sopenharmony_ci --ninja-args=NINJA_ARGS # Specify Ninja parameters. 239e41f4b71Sopenharmony_ci -v, --verbose # Display all commands used. 240e41f4b71Sopenharmony_ci --keep-ninja-going # Keep Ninja going until 1,000,000 jobs fail. 241e41f4b71Sopenharmony_ci --jobs=JOBS 242e41f4b71Sopenharmony_ci --export-para=EXPORT_PARA 243e41f4b71Sopenharmony_ci --build-only-gn # Perform GN parsing and do not run Ninja. 244e41f4b71Sopenharmony_ci --ccache # (Optional) Use ccache for build. You need to install ccache locally. 245e41f4b71Sopenharmony_ci --fast-rebuild # Specify whether to allow fast rebuild. The default value is False. 246e41f4b71Sopenharmony_ci --log-level=LOG_LEVEL # Specify the log level used in the build process. The options are debug, info, and error. The default value is info. 247e41f4b71Sopenharmony_ci --device-type=DEVICE_TYPE # Specify the device type. The default value is default. 248e41f4b71Sopenharmony_ci --build-variant=BUILD_VARIANT #Specify the device operation mode. The default value is user. 249e41f4b71Sopenharmony_ci ``` 250e41f4b71Sopenharmony_ci 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ci 253e41f4b71Sopenharmony_ci2. Using the hb tool 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_ci **hb** is an OpenHarmony command line tool for executing build commands. Common hb commands are described as follows: 256e41f4b71Sopenharmony_ci 257e41f4b71Sopenharmony_ci **hb set** 258e41f4b71Sopenharmony_ci 259e41f4b71Sopenharmony_ci Sets the product to build. 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_ci ```shell 262e41f4b71Sopenharmony_ci hb set -h 263e41f4b71Sopenharmony_ci usage: hb set [-h] [-root [ROOT_PATH]] [-p] 264e41f4b71Sopenharmony_ci 265e41f4b71Sopenharmony_ci optional arguments: 266e41f4b71Sopenharmony_ci -h, --help show this help message and exit 267e41f4b71Sopenharmony_ci -root [ROOT_PATH], --root_path [ROOT_PATH] 268e41f4b71Sopenharmony_ci Set OHOS root path 269e41f4b71Sopenharmony_ci -p, --product Set OHOS board and kernel 270e41f4b71Sopenharmony_ci ``` 271e41f4b71Sopenharmony_ci 272e41f4b71Sopenharmony_ci - If you run **hb set** with no argument, the default setting process starts. 273e41f4b71Sopenharmony_ci 274e41f4b71Sopenharmony_ci - You can run **hb set -root** *dir* to set the root directory of the source code. 275e41f4b71Sopenharmony_ci 276e41f4b71Sopenharmony_ci - You can run **hb set -p** to set the product to build. 277e41f4b71Sopenharmony_ci 278e41f4b71Sopenharmony_ci 279e41f4b71Sopenharmony_ci 280e41f4b71Sopenharmony_ci **hb env** 281e41f4b71Sopenharmony_ci 282e41f4b71Sopenharmony_ci Displays current settings. 283e41f4b71Sopenharmony_ci 284e41f4b71Sopenharmony_ci ```shell 285e41f4b71Sopenharmony_ci hb env 286e41f4b71Sopenharmony_ci [OHOS INFO] root path: xxx 287e41f4b71Sopenharmony_ci [OHOS INFO] board: hispark_taurus 288e41f4b71Sopenharmony_ci [OHOS INFO] kernel: liteos 289e41f4b71Sopenharmony_ci [OHOS INFO] product: ipcamera 290e41f4b71Sopenharmony_ci [OHOS INFO] product path: xxx/vendor/hisilicon/ipcamera 291e41f4b71Sopenharmony_ci [OHOS INFO] device path: xxx/device/hisilicon/hispark_taurus/sdk_linux_4.19 292e41f4b71Sopenharmony_ci ``` 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ci 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci **hb build** 297e41f4b71Sopenharmony_ci 298e41f4b71Sopenharmony_ci Builds a product, component, module, or chipset solution. 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ci ```shell 301e41f4b71Sopenharmony_ci hb build -h 302e41f4b71Sopenharmony_ci usage: hb build [-h] [-b BUILD_TYPE] [-c COMPILER] [-t [TEST [TEST ...]]] [-cpu TARGET_CPU] [--dmverity] [--tee] 303e41f4b71Sopenharmony_ci [-p PRODUCT] [-f] [-n] [-T [TARGET [TARGET ...]]] [-v] [-shs] [--patch] [--compact-mode] 304e41f4b71Sopenharmony_ci [--gn-args GN_ARGS] [--keep-ninja-going] [--build-only-gn] [--log-level LOG_LEVEL] [--fast-rebuild] 305e41f4b71Sopenharmony_ci [--device-type DEVICE_TYPE] [--build-variant BUILD_VARIANT] 306e41f4b71Sopenharmony_ci [component [component ...]] 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ci positional arguments: 309e41f4b71Sopenharmony_ci component name of the component, mini/small only 310e41f4b71Sopenharmony_ci 311e41f4b71Sopenharmony_ci optional arguments: 312e41f4b71Sopenharmony_ci -h, --help show this help message and exit 313e41f4b71Sopenharmony_ci -b BUILD_TYPE, --build_type BUILD_TYPE 314e41f4b71Sopenharmony_ci release or debug version, mini/small only 315e41f4b71Sopenharmony_ci -c COMPILER, --compiler COMPILER 316e41f4b71Sopenharmony_ci specify compiler, mini/small only 317e41f4b71Sopenharmony_ci -t [TEST [TEST ...]], --test [TEST [TEST ...]] 318e41f4b71Sopenharmony_ci compile test suit 319e41f4b71Sopenharmony_ci -cpu TARGET_CPU, --target-cpu TARGET_CPU 320e41f4b71Sopenharmony_ci select cpu 321e41f4b71Sopenharmony_ci --dmverity enable dmverity 322e41f4b71Sopenharmony_ci --tee Enable tee 323e41f4b71Sopenharmony_ci -p PRODUCT, --product PRODUCT 324e41f4b71Sopenharmony_ci build a specified product with {product_name}@{company} 325e41f4b71Sopenharmony_ci -f, --full full code compilation 326e41f4b71Sopenharmony_ci -n, --ndk compile ndk 327e41f4b71Sopenharmony_ci -T [TARGET [TARGET ...]], --target [TARGET [TARGET ...]] 328e41f4b71Sopenharmony_ci compile single target 329e41f4b71Sopenharmony_ci -v, --verbose show all command lines while building 330e41f4b71Sopenharmony_ci -shs, --sign_haps_by_server 331e41f4b71Sopenharmony_ci sign haps by server 332e41f4b71Sopenharmony_ci --patch apply product patch before compiling 333e41f4b71Sopenharmony_ci --compact-mode compatible with standard build system set to false if we use build.sh as build entrance 334e41f4b71Sopenharmony_ci --gn-args GN_ARGS specifies gn build arguments, eg: --gn-args="foo="bar" enable=true blah=7" 335e41f4b71Sopenharmony_ci --keep-ninja-going keeps ninja going until 1000000 jobs fail 336e41f4b71Sopenharmony_ci --build-only-gn only do gn parse, do not run ninja 337e41f4b71Sopenharmony_ci --log-level LOG_LEVEL 338e41f4b71Sopenharmony_ci specifies the log level during compilationyou can select three levels: debug, info and error 339e41f4b71Sopenharmony_ci --fast-rebuild it will skip prepare, preloader, gn_gen steps so we can enable it only when there is no change 340e41f4b71Sopenharmony_ci for gn related script 341e41f4b71Sopenharmony_ci --device-type DEVICE_TYPE 342e41f4b71Sopenharmony_ci specifies device type 343e41f4b71Sopenharmony_ci --build-variant BUILD_VARIANT 344e41f4b71Sopenharmony_ci specifies device operating mode 345e41f4b71Sopenharmony_ci ``` 346e41f4b71Sopenharmony_ci 347e41f4b71Sopenharmony_ci - If you run **hb build** with no argument, the previously configured code directory, product, and options are used for the build. The **-f** option deletes all products to be built. It is equivalent to running **hb clean** and **hb build**. 348e41f4b71Sopenharmony_ci 349e41f4b71Sopenharmony_ci - You can run **hb build** *{component_name}* to build product components separately based on the development board and kernel set for the product, for example, **hb build kv_store**. 350e41f4b71Sopenharmony_ci 351e41f4b71Sopenharmony_ci - You can run **hb build -p ipcamera@hisilicon** to skip the setting step and build the product directly. 352e41f4b71Sopenharmony_ci 353e41f4b71Sopenharmony_ci - You can run **hb build** in **device/board/device_company** to select the kernel and build an image that contains the kernel and drivers only based on the current development board and the selected kernel. 354e41f4b71Sopenharmony_ci 355e41f4b71Sopenharmony_ci 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_ci **hb clean** 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_ci Deletes all the files except **args.gn** and **build.log** in the **out** directory (default). To clear files in a specified directory, add the directory parameter to the command, for example, **hb clean out/board/product**. 360e41f4b71Sopenharmony_ci 361e41f4b71Sopenharmony_ci ```shell 362e41f4b71Sopenharmony_ci hb clean 363e41f4b71Sopenharmony_ci usage: hb clean [-h] [out_path] 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_ci positional arguments: 366e41f4b71Sopenharmony_ci out_path clean a specified path. 367e41f4b71Sopenharmony_ci 368e41f4b71Sopenharmony_ci optional arguments: 369e41f4b71Sopenharmony_ci -h, --help show this help message and exit 370e41f4b71Sopenharmony_ci ``` 371e41f4b71Sopenharmony_ci 372e41f4b71Sopenharmony_ci > **NOTE** 373e41f4b71Sopenharmony_ci > 374e41f4b71Sopenharmony_ci > - For details about how to set up the build environment and perform the build, see the related topics in [Getting Started](../quick-start/quickstart-overview.md). 375e41f4b71Sopenharmony_ci > - OpenHarmony also provides the Docker environment, which spares the installation of the build tool. For details, see [Docker Environment](../get-code/gettools-acquire.md). 376e41f4b71Sopenharmony_ci 377e41f4b71Sopenharmony_ci### Building Procedures 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ciYou can add and build a product, component, chipset solution, and module. For details, see: 380e41f4b71Sopenharmony_ci 381e41f4b71Sopenharmony_ci- [Adding and Building a Product](subsys-build-product.md#adding-and-building-a-product) 382e41f4b71Sopenharmony_ci- [Adding and Building a Component](subsys-build-component.md#adding-and-building-a-component) 383e41f4b71Sopenharmony_ci- [Adding and Building a Module](subsys-build-module.md#adding-and-building-a-module) 384e41f4b71Sopenharmony_ci- [Adding and Building a Chipset Solution](subsys-build-chip_solution.md#adding-and-building-a-chipset-solution) 385e41f4b71Sopenharmony_ci 386e41f4b71Sopenharmony_ci## FAQs 387e41f4b71Sopenharmony_ci 388e41f4b71Sopenharmony_ci- [Common Build Problems and Solutions](subsys-build-FAQ.md) 389e41f4b71Sopenharmony_ci 390e41f4b71Sopenharmony_ci## Reference 391e41f4b71Sopenharmony_ci 392e41f4b71Sopenharmony_ci- [deps and external_deps](subsys-build-reference.md#deps-and-external_deps) 393e41f4b71Sopenharmony_ci- [Using Sanitizer](subsys-build-reference.md#using-sanitizer) 394e41f4b71Sopenharmony_ci- [Information Collected by the Open Source Software Notice](subsys-build-reference.md#information-collected-by-the-open-source-software-notice) 395e41f4b71Sopenharmony_ci- [Parameters for Accelerating Local Build](subsys-build-reference.md#parameters-for-accelerating-local-build) 396e41f4b71Sopenharmony_ci- [Viewing Ninja Build Information](subsys-build-reference.md#viewing-ninja-build-information) 397e41f4b71Sopenharmony_ci- [Customizing the chip_prod Image](subsys-build-reference.md#customizing-the-chip_prod-image) 398e41f4b71Sopenharmony_ci 399