Skip to main content

OHOS build command line tool

Project description

Compilation and Building (for Mini and Small Systems)

Introduction

The 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:

  • Component

    A component is a reusable software unit that can contain source code, configuration files, resource files, and build scripts.

  • GN

    GN is short for Generate Ninja, which is a build system used to generate Ninja files.

  • Ninja

    Ninja is a small high-speed build system.

Build Process

The following figure shows the build process.

Figure 1 Build process

  1. hb set: Set the OpenHarmony source code directory and the product to build.
  2. 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 the gn gen command to read the product configuration (related to the development board, kernel, and system components) and generate the out directory and ninja files for the solution.
    • Running Ninja: Run ninja -C out/company/product to start build.
    • Packaging: Package the build result to create a file system image.

Directory Structure

build/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 options

Usage

Usage Guidelines

  1. Prerequisites

    • Server and OS version: Linux server running 64-bit Ubuntu 16.04 or later
    • Python version: 3.7.4 or later
    • Repository: build_lite of OpenHarmony source code
  2. Installing hb

    • Run the following command in the root directory of the source code:

      python3 -m pip install --user build/lite
      
    • Run the hb -h command. 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 exit
      
    • Uninstalling hb

      Run the following command to uninstall hb:

      python3 -m pip uninstall ohos-build
      
  3. Build Commands

    1. hb set

      hb 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 run hb set with no argument, the default setting process starts.
      • You can run hb set -root [ROOT_PATH] to set the root directory of the source code.
      • hb set -p --product is used to set the product to build.
    2. hb env

      View 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.19
      
    3. hb build

      hb 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 target
      
      • If you run hb build with no argument, the previously configured code directory, product, and options are used for build.
      • You can run hb 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 run hb build -p PRODUCT to skip the setting step and build the product directly.
      • You can run hb build in device/device_company/board to 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.
    4. hb clean

      Clear the build result of the product in the out directory, and leave the args.gn and build.log files only. To clear files in a specified directory, add the directory parameter to the command, for example, hb clean xxx/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 Involved

Compilation and building subsystem

build_lite

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ohos-build-0.4.3.tar.gz (35.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ohos_build-0.4.3-py3-none-any.whl (50.3 kB view details)

Uploaded Python 3

File details

Details for the file ohos-build-0.4.3.tar.gz.

File metadata

  • Download URL: ohos-build-0.4.3.tar.gz
  • Upload date:
  • Size: 35.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.4

File hashes

Hashes for ohos-build-0.4.3.tar.gz
Algorithm Hash digest
SHA256 0d6d6686b097120f1235b7d49419929e003a4ff54dd3f7c50e5f3edcd6abc003
MD5 5e55e18903a32a5b22a867532e11b481
BLAKE2b-256 a983ca0cf4a41b46fdb7440e08c92b55e58d4a8931c662ffc75171db4eb74485

See more details on using hashes here.

File details

Details for the file ohos_build-0.4.3-py3-none-any.whl.

File metadata

  • Download URL: ohos_build-0.4.3-py3-none-any.whl
  • Upload date:
  • Size: 50.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.4

File hashes

Hashes for ohos_build-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 650c65b4f292b8a1e61bbe3bce64ed7331175339b2fa4468d834b1b1bf87ecc3
MD5 e6e641d85e18b9e055e741b977a62d7c
BLAKE2b-256 2846b2cf711e6d636f1857a73f10bf714c87968e368653051c36a2fc8208d75f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page