一、编译构建简介
Openharmony的编译构建流程在鸿蒙的开源版本中以V3.1为分界线,流程略有变化。但其中都是ninja与python通过配置文件json,调用不同的交叉工具链来对源码进行编译,然后生成镜像文件。本文首先以Openharmony V3.1版本为例讲解下其编译构建的过程,并以实例的方式对如何添加子系统、模块等进行说明。
后续会对Openharmony V3.2其及衍生的版本进行扩展说明。
二、Openharmony v3.1 L2设备整体编译流程
2.1 编译扫描说明
在编译的时候,需要扫描相应的子系统配置文件。子系统配置文件包含以下三个文件
- subsystem_config.json
- {产品名称}.json
- {产品设备名称}.json
通过此三个文件,加载该产品需要参与编译的所有子部件及配置信息。
2.2 {产品名称}.json
product配置文件,在//productdefine/common/products目录下,以下编译rk3568为例:
当在Openharmony根目录下输入
./build.sh --product-name rk3568
此时首先进入preloader阶段,根据参数rk3568找到//productdefine/common/products/rk3568.json文件,
该配置文件主要包含产品名称,产品厂商,产品设备名,产品类型,产品对应子系统路径,产品所包含的部件等信息。配置该产品对应子系统时在该文件中添加product_build_path表示产品子系统目录。preloader阶段从该目录下加载对应子系统部件配置信息。
{
"product_name": "rk3568", # 产品名称
"product_company": "hihope", # 产品厂商
"product_device": "rk3568", # 产品设备名 ({产品设备名称}.json)
"version": "2.0",
"type": "standard", # 产品类型
"product_build_path": "device/hihope/build", # 产品子系统目录
"parts":{ # 产品所包含的部件
"ace:ace_engine_standard":{},
"ace:napi":{},
"account:os_account_standard":{},
"barrierfree:accessibility":{},
......
}
}
2.3 {产品设备名称}.json
device配置文件,根据2.2描述文件名也为rk3568.json,此文件完整路径即为//productdefine/common/device/rk3568.json,该配置文件主要包含设备名称,设备厂商,设备的目标os与目标cpu,设备对应子系统路径等信息。配置该设备对应子系统时在该文件中添加device_build_path表示设备子系统目录,preloader阶段从该目录下加载对应子系统部件配置信息。
{
"device_name": "rk3568", # 设备名称
"device_company": "hihope", # 设备厂商
"target_os": "ohos", # 设备的目标os
"target_cpu": "arm", # 设备的目标cpu
"kernel_version": "",
"device_build_path": "device/hihope/build", # 设备子系统目录
"enable_ramdisk": true,
"build_selinux": true
}
根据设备子系统目录device/hihope/build,找到当前目录下的ohos.build,找到设备子系统与子部件。
{
"subsystem": "rockchip_products", #设备子系统
"parts": { #子部件
"rockchip_products": {
"module_list": [
"//device/hihope/build:products_group",
"//vendor/hihope/rk3568/bluetooth:libbt_vendor",
"//vendor/hihope/rk3568/bluetooth:BCM4362A2.hcd"
]
}
}
}
2.4 subsystem_config.json
在//build/subsystem_config.json文件中,主要包含子系统名称与路径信息,在preloader阶段被加载,根据子系统名称和路径信息查找该路径下的ohos.build文件。
{
"ace": {
"path": "foundation/ace",
"name": "ace"
},
"ai": {
"path": "foundation/ai",
"name": "ai"
},
"account": {
"path": "base/account",
"name": "account"
},
......
}
在2.2的{产品名称}.json中,子部件"account:os_account_standard":{},根据subsystem_config.json的映射,扫描base/account此目录下的所有bundle.json文件,找到子组件名为os_account_standard的bundle.json(可以有多个),即参与编译的bundle.json文件为base/account/os_account/bundle.json。
bundle.json中包含子部件中参与的编译的所有模块。
三、编译部件与模块
3.1 bundle.json
编译部件配置文件。以base/account/os_account/bundle.json为例:
“component”描述子部件名称,所在子系统等信息。
“build”包含参与编译的子组件模块"sub_component"与内部组件"inner_kits"与测试模块"test"。
{
"name": "@ohos/os_account",
"description": "Allowing apps to use OS account-related functions",
"version": "3.1",
"license": "Apache License 2.0",
"publishAs": "code-segment",
"segment": {
"destPath": "base/account/os_account"
},
"dirs": {},
"scripts": {},
"component": {
"name": "os_account_standard", # 子部件名称
"subsystem": "account", # 子系统名称
"syscap": [
"SystemCapability.Account.AppAccount",
"SystemCapability.Account.OsAccount"
],
"features": [
"os_account_standard_enable_app_account = true",
"os_account_standard_enable_os_account = true"
],
"hisysevent_config": [
"//base/account/os_account/hisysevent.yaml"
],
"adapted_system_type": [
"standard"
],
"rom": "4096KB",
"ram": "82000KB",
"deps": {
"components": [
"ability_base",
"ability_runtime",
"bundle_framework",
"ces_standard",
"distributeddatamgr",
"hisysevent_native",
"hiviewdfx_hilog_native",
"ipc",
"safwk",
"samgr_standard",
"startup_l2"
],
"third_party": [
"jsoncpp"
]
},
"build": {
"sub_component": [
"//base/account/os_account/services:services_target",
"//base/account/os_account/services/accountmgr/src/appaccount:app_account_service_core",
"//base/account/os_account/frameworks/appaccount/native:app_account_innerkits",
"//base/account/os_account/frameworks/osaccount/core:os_account_core",
"//base/account/os_account/frameworks/common:common_target",
"//base/account/os_account/frameworks/osaccount/native:os_account_innerkits",
"//base/account/os_account/interfaces/kits/napi/appaccount:appaccount",
"//base/account/os_account/interfaces/kits/napi/distributedaccount:distributedaccount",
"//base/account/os_account/interfaces/kits/napi/osaccount:osaccount",
"//base/account/os_account/sa_profile:account_sa_profile",
"//base/account/os_account/tools:os_account_tools",
"//base/account/os_account:HelloOpenHarmony"
],
"inner_kits": [
{
"header": {
"header_base":"//base/account/os_account/interfaces/innerkits/ohosaccount/native/include",
"header_files": [
"account_info.h",
"device_account_info.h",
"iaccount.h",
"ohos_account_kits.h"
]
},
"name": "//base/account/os_account/frameworks/ohosaccount/native:libaccountkits"
},
{
"header":{
"header_base":"//base/account/os_account/interfaces/innerkits/osaccount/native/include",
"header_files": [
"os_account_constants.h",
"os_account_info.h",
"os_account_manager.h",
"os_account_subscribe_info.h",
"os_account_subscriber.h"
]
},
"name": "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits"
},
{
"header": {
"header_base":"//base/account/os_account/interfaces/innerkits/appaccount/native/include",
"header_files": [
"app_account_manager.h"
]
},
"name": "//base/account/os_account/frameworks/appaccount/native:app_account_innerkits"
}
],
"test": [
"//base/account/os_account/frameworks/common/test:unittest",
"//base/account/os_account/services/accountmgr/test:unittest",
"//base/account/os_account/frameworks/ohosaccount/test:moduletest",
"//base/account/os_account/frameworks/osaccount/core/test:unittest",
"//base/account/os_account/frameworks/osaccount/native/test/moduletest:moduletest",
"//base/account/os_account/services/accountmgr/test/moduletest/os_account:moduletest",
"//base/account/os_account/frameworks/ohosaccount/test:moduletest",
"//base/account/os_account/frameworks/osaccount/native/test/unittest:unittest",
"//base/account/os_account/tools:unittest",
"//base/account/os_account/tools:moduletest",
"//base/account/os_account/test/systemtest:systemtest",
"//base/account/os_account/frameworks/appaccount/native/test:moduletest",
"//base/account/os_account/frameworks/appaccount/native/test:unittest",
"//base/account/os_account/services/accountmgr/test/moduletest/app_account:moduletest",
"//base/account/os_account/services/accountmgr/test/unittest/app_account:unittest"
]
}
}
}
每一行模块可以找到相对应的BUILD.gn文件,以"sub_component"中第一行为例
"//base/account/os_account/services:services_target",
可以在//base/account/os_account/services目录下找到BUILD.gn。
3.2 BUILD.gn
模块文件,承接上文,以//base/account/os_account/services/BUILD.gn为例,
group("services_target") {
deps = [ "accountmgr:accountmgr_target" ]
}
//base/account/os_account/services:services_target,即对应group("services_target")模板,此模板依赖"accountmgr:accountmgr_target",再接着往下查找BUILD.gn,得到//base/account/os_account/services/accountmgr/BUILD.gn。
import("//base/account/os_account/os_account.gni")
import("//build/ohos.gni")
ohos_prebuilt_etc("accountmgr.init") {
...
}
ohos_prebuilt_etc("osaccount_constraint") {
...
}
ohos_prebuilt_etc("constraints_list_collection") {
...
}
group("accountmgr_target") {
deps = [
":accountmgr",
":accountmgr.init",
":constraints_list_collection",
":osaccount_constraint",
]
}
......
ohos_shared_library("accountmgr") {
......
}
由此文件可以得出,此模块的group("accountmgr_target")会编译出一个动态库(accountmgr)及三个预编译配置项(accountmgr.init、osaccount_constraint、constraints_list_collection)。
关于BUILD.gn的介绍,在下一单对此作详细解释说明。此时生成的动态库名称为libaccountmgr.z.so。在Openharmony里的动态库一般会加上前缀lib以及后缀.z.so.
后续更精彩
1.Openharmony编译构建--进阶篇
标签:Openharmony,account,--,编译,json,base,accountmgr,os,子系统 From: https://blog.51cto.com/u_15304012/6216922