1 Star 0 Fork 5.1K

youguilin / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ubuntu-build-environment.md 15.52 KB
一键复制 编辑 原始数据 按行查看 历史
mamingshuai 提交于 2021-06-02 01:00 . update OpenHarmony 2.0 Canary

Ubuntu Build Environment

Operating system: 64-bit version of Ubuntu 16.04 or later.

Perform the following steps to set up the build environment:

  1. Obtain source code.
  2. Install and configure Python.
  3. Install GN.
  4. Install Ninja.
  5. Installing hc-gen
  6. Install LLVM.
  7. Install hb.

NOTICE:

  • Docker is provided for the Ubuntu build environment, which encapsulates related build tools. If you use Docker to prepare the build environment, you do not need to perform the following steps in this section. Instead, refer to Using Docker to Prepare the Build Environment.
  • By default, basic software, such as Samba and Vim, is installed in the system. Adaptation on the software is required to support file sharing between the Linux server and the Windows workstation.
  • For details about the compilation and building subsystem of OpenHarmony, see the Compilation and Building Overview.

Obtaining Source Code and Tools

The following table describes the tools and source code required for setting up the general environment for a Linux server and how to obtain these tools and the source code.

Table 1 Source code and development tools and their obtaining methods

Item

Description

How to Obtain

Source code

Develops functions.

For details, see Source Code Acquisition.

Python3.7+

Executes script compilation.

Internet

gn

Generates ninja compilation scripts.

https://repo.huaweicloud.com/harmonyos/compiler/gn/1717/linux/gn-linux-x86-1717.tar.gz

ninja

Executes ninja compilation scripts.

https://repo.huaweicloud.com/harmonyos/compiler/ninja/1.9.0/linux/ninja.1.9.0.tar

hc-gen

Configures and compiles files.

https://repo.huaweicloud.com/harmonyos/compiler/hc-gen/0.65/linux/hc-gen-0.65-linux.tar

LLVM

Functions as the compiler toolchain.

https://repo.huaweicloud.com/harmonyos/compiler/clang/10.0.1-53907/linux/llvm.tar.gz

For the OpenHarmony_1.0.1_release, download LLVM from the following link:

https://repo.huaweicloud.com/harmonyos/compiler/clang/9.0.0-36191/linux/llvm-linux-9.0.0-36191.tar

hb

Compiles the OpenHarmony source code.

Internet

NOTICE:

  • If you acquire the source code using an HPM component or HPM CLI tool, you do not need to install compilation tools like gn and ninja.
  • (Recommended) If you obtain the source code via the mirror site or code repository, install compilation tools such as gn, ninja, and LLVM. When installing these tools, ensure that their environment variable paths are unique.

Obtaining OpenHarmony Source Code

You need to acquire source code, download it on a Linux server, and decompress it.

Installing and Configuring Python

  1. Start a Linux server.

  2. Check the Python version (Python 3.7 or later is required).

    python3 --version

    If Python version is earlier than 3.7, reinstall Python. Do as follows to install Python, for example, Python 3.8.

    1. Check the Ubuntu version.
    cat /etc/issue
    1. Install Python based on the Ubuntu version.
      • If the Ubuntu version is 18 or later, run the following command:

        sudo apt-get install python3.8
      • If the Ubuntu version is 16, perform the following steps:

        a. Install dependency packages.

        sudo apt update && sudo apt install software-properties-common

        b. Add the source of deadsnakes PPA and press Enter.

        sudo add-apt-repository ppa:deadsnakes/ppa

        c. Install Python 3.8.

        sudo apt upgrade && sudo apt install python3.8
  3. Set the soft link of python and python3 to python3.8.

    sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1
    sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
  4. Install and upgrade the Python package management tool (pip3) using either of the following methods:

    • Command line:

      sudo apt-get install python3-setuptools python3-pip -y
      sudo pip3 install --upgrade pip
    • Installation package:

      curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
      python get-pip.py

Installing gn

  1. Start a Linux server.

  2. Download gn.

  3. Create the gn folder in the root directory.

    mkdir ~/gn
  4. Decompress the gn installation package to ~/gn.

    tar -xvf gn-linux-x86-1717.tar.gz -C ~/gn
  5. Set an environment variable.

    vim ~/.bashrc

    Copy the following command to the last line of the .bashrc file, save the file, and exit.

    export PATH=~/gn:$PATH
  6. Validate the environment variable.

    source ~/.bashrc

Installing ninja

  1. Start a Linux server.

  2. Download ninja.

  3. Decompress the ninja installation package to ~/ninja.

    tar -xvf ninja.1.9.0.tar -C ~/
  4. Set an environment variable.

    vim ~/.bashrc

    Copy the following command to the last line of the .bashrc file, save the file, and exit.

    export PATH=~/ninja:$PATH
  5. Validate the environment variable.

    source ~/.bashrc

Installing hc-gen

  1. Start a Linux server.

  2. Download hc-gen.

  3. Decompress the hc-gen installation package to ~/hc-gen on the Linux server.

    tar -xvf hc-gen-0.65-linux.tar -C ~/
  4. Set an environment variable.

    vim ~/.bashrc

    Copy the following command to the last line of the .bashrc file, save the file, and exit.

    export PATH=~/hc-gen:$PATH
  5. Validate the environment variable.

    source ~/.bashrc

Installing LLVM

  1. Start a Linux server.

  2. Download LLVM.

    NOTE: For the OpenHarmony_1.0.1_release, click here to download LLVM.

  3. Decompress the LLVM installation package to ~/llvm.

    tar -zxvf llvm.tar.gz -C ~/

    NOTE: For the OpenHarmony_1.0.1_release, run the following command to decompress the LLVM installation package:

    tar -xvf llvm-linux-9.0.0-36191.tar -C ~/
  4. Set an environment variable.

    vim ~/.bashrc

    Copy the following command to the last line of the .bashrc file, save the file, and exit.

    export PATH=~/llvm/bin:$PATH
  5. Validate the environment variable.

    source ~/.bashrc

Installing hb

Prerequisites

Python 3.7.4 or later has been installed. For details, see Installing and Configuring Python.

Installation Procedure

  1. Install hb.

    python3 -m pip install --user ohos-build
  2. Set an environment variable.

    vim ~/.bashrc

    Copy the following command to the last line of the .bashrc file, save the file, and exit.

    export PATH=~/.local/bin:$PATH

    Update the environment variable.

    source ~/.bashrc
  3. 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

python3 -m pip uninstall ohos-build

NOTICE: If you encounter any problem during the installation, resort to the FAQ.

1
https://gitee.com/yougl/docs.git
git@gitee.com:yougl/docs.git
yougl
docs
docs
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891