Package: ohos-build
Compilation and Building (for Mini and Small Systems)IntroductionDirectory StructureUsageUsage GuidelinesRepositories InvolvedIntroductionThe compilation and building subsystem is a build framework based on Generate Ninja (GN) and Ninja, which supports component-based OpenHarmony development. This subsystem can be used to:Build products.Build chipset vendor components independently.Build a single component independently.It is considered best practice to learn the following basic concepts before you start development and build:ComponentA component is a reusable software unit that can contain source code, configuration files, resource files, and build scripts.GNGN is short for Generate Ninja, which is a build system used to generate Ninja files.NinjaNinja is a small high-speed build system.Build ProcessThe following figure shows the build process.Figure  1Build processhb set: Set the OpenHarmony source code directory and the product to build.hb build: Build the product, development board, or component. The process to build the solution is as follows:Reading configuration: Read the development board configuration, which covers the toolchain, linking commands, and build options.Running gn: Run thegn gencommand to read the product configuration (related to the development board, kernel, and system components) and generate theoutdirectory andninjafiles for the solution.Running Ninja: Runninja -C out/company/productto start build.Packaging: Package the build result to create a file system image.Directory Structurebuild/lite                      # Primary directory
├── components                  # Component description file
├── hb                          # hb pip installation package
├── make_rootfs                 # make script for the file system
├── config                      # Build configuration items
│   ├── component               # Definitions of component-related templates, including static libraries, dynamic libraries, extension components, and emulator libraries
│   ├── kernel                  # Build configuration parameters of the kernel
│   └── subsystem               # Subsystem template
├── ndk                          # NDK-related build scripts and configuration parameters
└── toolchain                   # Build toolchain, which contain the compiler directories, build options, and linking optionsUsageUsage GuidelinesPrerequisitesServer and OS version: Linux server running 64-bit Ubuntu 16.04 or laterPython version: 3.7.4 or laterRepository:build_liteof OpenHarmony source codeInstalling hbRun the following command in the root directory of the source code:python3 -m pip install --user build/liteRun thehb -hcommand. If the following information is displayed, the installation is successful:usage: hb

OHOS build system

positional arguments:
  {build,set,env,clean}
    build               Build source code
    set                 OHOS build settings
    env                 Show OHOS build env
    clean               Clean output

optional arguments:
  -h, --help            Show this help message and exitUninstalling hbRun the following command to uninstall hb:python3 -m pip uninstall ohos-buildBuild Commandshb sethb set -h
usage: hb set [-h] [-root [ROOT_PATH]] [-p]

optional arguments:
  -h, --help            Show this help message and exit.
  -root [ROOT_PATH], --root_path [ROOT_PATH]
                        Set OHOS root path.
  -p, --product         Set OHOS board and kernel.If you runhb setwith no argument, the default setting process starts.You can runhb set -root[ROOT_PATH]to set the root directory of the source code.hb set -p --productis used to set the product to build.hb envView the current configuration.hb env
[OHOS INFO] root path: xxx
[OHOS INFO] board: hispark_taurus
[OHOS INFO] kernel: liteos
[OHOS INFO] product: ipcamera
[OHOS INFO] product path: xxx/vendor/hisilicon/ipcamera
[OHOS INFO] device path: xxx/device/hisilicon/hispark_taurus/sdk_linux_4.19hb buildhb build -h
usage: hb build [-h] [-b BUILD_TYPE] [-c COMPILER] [-t [TEST [TEST ...]]]
                [--dmverity] [-p PRODUCT] [-f] [-n]
                [component [component ...]]

positional arguments:
  component             Name of the component.

optional arguments:
  -h, --help            Show this help message and exit.
  -b BUILD_TYPE, --build_type BUILD_TYPE
                        Release or debug version.
  -c COMPILER, --compiler COMPILER
                        Specify compiler.
  -t [TEST [TEST ...]], --test [TEST [TEST ...]]
                        Compile test suit.
  --dmverity            Enable dmverity.
  -p PRODUCT, --product PRODUCT
                        Build a specified product with
                        {product_name}@{company}, eg: ipcamera@hisilcon.
  -f, --full            Full code compilation.
  -T [TARGET [TARGET ...]], --target [TARGET [TARGET ...]]
                        Compile single targetIf you runhb buildwith no argument, the previously configured code directory, product, and options are used for build.You can runhb build{component}to build product components separately based on the development board and kernel set for the product, for example,hb build kv_store.You can runhb build -p PRODUCTto skip the setting step and build the product directly.You can runhb buildindevice/device_company/boardto select the kernel and start build based on the current development board and the selected kernel to generate an image that contains the kernel and driver only.hb cleanClear the build result of the product in theoutdirectory, and leave theargs.gnandbuild.logfiles only. To clear files in a specified directory, add the directory parameter to the command, for example,hb cleanxxx/out/xxx.hb clean
usage: hb clean [-h] [out_path]

positional arguments:
  out_path    Clean a specified path.

optional arguments:
  -h, --help  Show this help message and exit.Repositories InvolvedCompilation and building subsystembuild_lite