1 Star 0 Fork 965

Hailiang / build

forked from OpenHarmony / build 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

编译构建

简介

编译构建子系统提供了一个基于Gn和ninja的编译构建框架。

根据产品配置,编译生成对应的镜像包。其中编译构建流程为:

  1. 使用Gn配置构建目标。
  2. Gn运行后会生成ninja文件。
  3. 通过运行ninja来执行编译任务。

目录

/build                           # 编译构建主目录
├── config                       # 编译相关的配置项
├── core
│   └── gn                       # 编译入口BUILD.gn配置
├── loader                       # 各个部件配置加载、模板生成
├── ohos                         # OpenHarmony编译打包流程配置
│   ├── kits                     # kits编译打包模板和处理流程
│   ├── ndk                      # ndk模板和处理流程
│   ├── notice                   # notice模板和处理流程
│   ├── packages                 # 版本打包模板和处理流程
│   ├── sa_profile               # sa模板和处理流程
│   ├── sdk                      # sdk模板和处理流程,包括sdk中包含的模块配置
│   └── testfwk                  # 测试相关的处理
├── scripts                      # 编译相关的python脚本
├── templates                    # c/c++编译模板定义
└── toolchain                    # 编译工具链配置

约束与限制

  • 编译环境需要Ubuntu18.04及以上版本。

  • 安装编译所需的程序包。

    安装命令:

    sudo apt-get install binutils git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4

说明

  1. 代码根目录下执行全量版本的编译命令:

    ./build.sh --product-name {product_name}

    编译结果镜像输出在 out/ohos-arm-relese/packages/phone/images/目录下。

  2. 编译命令支持选项:

      --product-name    # 必须  编译的产品名称,如:Hi3516DV300
      --build-target    # 可选  指定编译目标,可以指定多个
      --gn-args         # 可选  gn参数,支持指定多个
      --ccache          # 可选  编译使用ccache,需要本地安装ccache
      --sparse-image    # 可选  生成sparse镜像,需要本地安装img2simg,默认镜像为raw
  3. 在已有部件中增加模块。

    支持的模板类型:

    ohos_executable
    ohos_shared_library
    ohos_static_library
    ohos_source_set
    
    # 预编译模板:
    ohos_prebuilt_executable
    ohos_prebuilt_shared_library
    ohos_prebuilt_etc

    在模块目录下配置BUILD.gn,根据类型选择对应的模板。

    例子:

    ohos_shared_library示例:

    import("//build/ohos.gni")
    ohos_shared_library("helloworld") {
      sources = []
      include_dirs = []
      cflags = []
      cflags_c = []
      cflags_cc = []
      ldflags = []
      configs = []
      deps =[]  # 部件内模块依赖
    
      # 跨部件模块依赖定义,
      # 定义格式为 "部件名:模块名称"
      # 这里依赖的模块必须是依赖的部件声明在inner_kits中的模块
      external_deps = [
        "part_name:module_name",
      ]
    
      output_name = "" # 可选,模块输出名
      output_extension = "" # 可选,模块名后缀
      module_install_dir = "" #可选,缺省在/system/lib64或/system/lib下, 模块安装路径,模块安装路径,从system/,vendor/后开始指定
      relative_install_dir = "" #可选,模块安装相对路径,相对于/system/lib64或/system/lib;如果有module_install_dir配置时,该配置不生效
    
      part_name = "" # 必选,所属部件名称
    }

    ohos_executable示例:

    ohos_executable模板属性和ohos_shared_library基本一致

    注意:可执行模块(即ohos_executable模板定义的)默认是不安装的,如果要安装,需要指定install_enable = true

    ohos_prebuilt_etc示例:

    import("//build/ohos.gni")
    ohos_prebuilt_etc("etc_file") {
      source = "file"
      deps = []  # 部件内模块依赖
      module_install_dir = "" #可选,模块安装路径,从system/,vendor/后开始指定
      relative_install_dir = "" #可选,模块安装相对路径,相对于system/etc;如果有module_install_dir配置时,该配置不生效
      part_name = "" # 必选,所属部件名称
    }
  4. 部件配置。

    部件配置在所属子系统的根目录下的 ohos.build文件中,一个子系统可以配置多个部件。

    一个部件包含module_list、inner_kits、system_kits、test_list四个部分的声明:

    • module_list:部件包含的模块列表
    • inner_kits:部件提供其它部件的接口
    • system_kits:部件提供给生成应用的接口
    • test_list:部件对应模块的测试用例

    ohos.build中各个配置,都只是声明,具体的模块配置还是在对应的BUILD.gn中。

  5. ohos-sdk编译。

    编译命令:

    ./build.sh --product-name ohos-sdk --ccache

    结果输出:

    out/ohos-arm64-release/packages/ohos-sdk/

    ohos-sdk模块配置:

    build/ohos/sdk/ohos_sdk_description_std.json

常见问题说明

如何将一个模块编译并打包到版本中?

  • 模块要指定part_name,指定它归属的部件,一个模块只能属于一个部件;
  • 部件的模块,要在部件配置的module_list中,或者可以被module_list中的模块依赖到;
  • 部件要加到对应产品的部件列表中;

关于deps和external_deps的使用 标准系统如何添加一个模板并参与编译 如何跟随系统使用gn编译hap

相关仓

编译构建子系统

build

Copyright (c) 2021 Huawei Device Co., Ltd. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *************************************************************** build, it is derived from the following: https://chromium.googlesource.com/chromium/src.git version 83.0.4098.1 *************************************************************** Copyright 2015 The Chromium Authors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

Compilation and building framework and scripts | 编译构建框架和脚本 展开 收起
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/allenpas/build.git
git@gitee.com:allenpas/build.git
allenpas
build
build
master

搜索帮助