移植案例與原理 - HPM包描述文件Bundle.Json
1、HPM Bundle的基本概念
Bundle是OpenHarmony中一個用來表示分發(fā)單元的術語,等同于包,一個Bundle中通常包含以下內(nèi)容:
- 被分發(fā)的二進制文件(二進制類型)。
- 被分發(fā)的源代碼文件(源代碼/代碼片段類型)。
- 編譯腳本(發(fā)行版類型需要)。
- 自身的說明文件。
- bundle.json:元數(shù)據(jù)聲明(名稱,版本,依賴等)。
- LICENSE:許可協(xié)議文本。
- README.md:自述文件。
- CHANGELOG.md:變更日志(可選)。
一個Bundle被發(fā)布到HPM服務器(https://hpm.harmonyos.com)后,另外一些開發(fā)者就可以通過hpm包管理器下載安裝使用 。一個Bundle在命名空間內(nèi)擁有唯一的名稱(命名格式為:@scope/name),可以進行獨立的版本演進。
一個bundle包通常具有如下代碼組織結構:
demo
├── headers # 頭文件(樣例)
│ └── main.h
└── src # 源代碼(樣例)
│ └─ main.c
├── bundle.json # 元數(shù)據(jù)聲明文件
└── LICENSE # 許可協(xié)議文本
└── Makefile # 編譯描述文件(樣例)
└── README.md # Bundle的自述文件
2、bundle.json文件格式定義
文件bundle.json一般具有如下格式,對各個屬性值的解釋見注釋部分。因為是json文件,注意下是對象還是數(shù)組。對象由花括號{}括起來的逗號分割的成員構成,成員是字符串鍵和值由逗號分割的鍵值對組成。數(shù)組是由方括號[]括起來的一組值構成。
{
"name": "@ohos/<component_name>", # HPM部件的英文名稱, 由@符合、組織名稱、部件名稱組成。
"description": "component description", # 部件描述
"version": "3.1.0", # 版本號,3.1 應該取的OpenHarmony版本號
"homePage": "https://gitee.com/openharmony", # 部件的主頁
"license": "BSD 3-claus", # 部件的版權協(xié)議,根據(jù)部件license情況填寫
"publishAs": "code-segment", # 發(fā)布形式,一般為代碼片段code-segment
"segment": { # 部件的代碼路徑
"destPath": "<subsystem>/<component_name>"
},
"dirs": [], # HPM包的目錄結構
"scripts": {}, # HPM包定義需要執(zhí)行的腳本
"component": { # 部件的屬性信息
"name": "<component_name>" # 部件的名稱,和"@ohos/<component_name>"中的名稱應該是一致的。
"subsystem": "xxx subsystem", # 部件所屬子系統(tǒng)
"syscap": [ "SystemCapability.<Subsystem>.<Feature>.<Subfeature>" ] # 部件為應用提供的系統(tǒng)能力
"features": [ "<component_name>_<feature>" ] # 部件的特性列表
"adapted_system_type": [ "<system_type>" ] # 部件適用的系統(tǒng)類型:輕量(mini)、小型(small)和標準(standard)
"rom": "xxxKB", # ROM占用
"ram": "xxxKB", # RAM占用
"deps": {
"components": [ # 部件依賴的其他部件
"xxx_component"
],
"third_party": [ # 部件依賴的三方開源軟件
"<third_party_software_name>"
]
},
"build": { # 部件編譯構建配置,可以多個
"sub_component": [ "http://<domain>/<subsystem>/<component_name>/<sub_component>" ], # 部件的子部件編譯入口
"inner_kits": [ # 部件內(nèi)部接口,可以多個
{
"header": { # 內(nèi)部頭文件信息
"header_base": "<domain>/<subsystem>/<component_name>/interface/innerkits/<sub_component>", # 內(nèi)部頭文件目錄
"header_files": [ "xxx.h" ] # 頭文件名稱
},
"name": "<domain>/<subsystem>/<component_name>/interface/innerkits/<sub_component>" # 內(nèi)部接口名稱
}
]
"test": [ "<domain>/<subsystem>/<component_name>/test" ] # 部件測試用例編譯入口,可以多個測試套入口
}
}
}
3、bundle.json示例
查看bundle.json文件的分布,在各個子系統(tǒng),三方庫下都存在。在開發(fā)板移植時,是不需要的。如果需要開發(fā)HPM包,是需要編寫bundle.json文件的??梢噪S便打開一個查看具體的示例。
~/openharmony$ find ./ -name bundle.json
./ark/js_runtime/bundle.json
./base/account/os_account/bundle.json
./build/common/bundle.json
./developtools/bytrace_standard/bundle.json
./drivers/adapter/bundle.json
./drivers/peripheral/audio/bundle.json
./foundation/aafwk/standard/bundle.json
./kernel/linux/build/bundle.json
./kernel/liteos_a/bundle.json
./kernel/liteos_m/bundle.json
./test/xts/acts/bundle.json
./third_party/abseil-cpp/bundle.json
./utils/native/bundle.json
看下分布式軟總線的示例openharmony\foundation\communication\dsoftbus\bundle.json。⑴處定義HPM包的名字,和⑶處的部件名稱一樣,都為dsoftbus_standard。⑵處的腳本,類似npm包一樣,在執(zhí)行hpm install時,來安裝這個hpm包。⑷處設置該hpm包屬于哪個子系統(tǒng),已經(jīng)適配的子系統(tǒng)類型,包含的特性等。⑸設置依賴的其他部件和三方庫。⑹處設置該hpm包的編譯構建信息。⑺處設置該hpm包的測試套信息。
{
⑴ "name": "@openharmony/dsoftbus_standard",
"version": "3.1.0",
"description": "dsoftbus_standard",
"publishAs": "code-segment",
"scripts": {
⑵ "install": "DEST_PATH=${DEP_BUNDLE_BASE}/foundation/communication/dsoftbus && mkdir -p $DEST_PATH && cp -r ./* $DEST_PATH"
},
"author": {},
"repository": "",
"license": "Apache License 2.0",
"component": {
⑶ "name": "dsoftbus_standard",
⑷ "subsystem": "communication",
"adapted_system_type": [
"mini",
"small",
"standard"
],
"features": [
"dsoftbus_standard_feature_conn_p2p",
"dsoftbus_standard_feature_disc_ble",
"dsoftbus_standard_feature_conn_br",
"dsoftbus_standard_feature_conn_ble"
],
"rom": "967KB",
"ram": "28MB",
⑸ "deps": {
"components": [
"libhilog",
"libipc_single",
"libwifi_sdk",
"libsystem_ability_fwk",
"libsyspara",
"samgr_proxy",
"utils_base"
],
"third_party": [
"libcoap",
"libmbedtls",
"bounds_checking_function"
]
},
⑹ "build": {
"sub_component": [
"http://foundation/communication/dsoftbus/core:softbus_server",
"http://foundation/communication/dsoftbus/sdk:softbus_client",
"http://foundation/communication/dsoftbus/core/frame/standard/sa_profile:softbus_sa_profile",
"http://foundation/communication/dsoftbus/tools:tool"
],
"inner_kits": [
{
"name": "http://foundation/communication/dsoftbus/sdk:softbus_client",
"header": {
"header_files": [
"bus_center/softbus_bus_center.h",
"common/softbus_common.h",
"discovery/discovery_service.h",
"transport/session.h"
],
"header_base": "http://foundation/communication/dsoftbus/interfaces/kits"
}
}
],
⑺ "test": [
"http://foundation/communication/dsoftbus/tests/adapter/unittest:unittest",
"http://foundation/communication/dsoftbus/tests/sdk/discovery/unittest:unittest",
"http://foundation/communication/dsoftbus/tests/sdk/transmission/trans_channel:unittest",
"http://foundation/communication/dsoftbus/tests/sdk/bus_center/unittest:unittest",
"http://foundation/communication/dsoftbus/tests/core/authentication:unittest",
"http://foundation/communication/dsoftbus/tests/core/bus_center/lnn:unittest",
"http://foundation/communication/dsoftbus/tests/core/common/utils:unittest",
"http://foundation/communication/dsoftbus/tests/core/connection:connectionTest",
"http://foundation/communication/dsoftbus/tests/core/discovery/manager:unittest",
"http://foundation/communication/dsoftbus/tests/core/transmission/trans_channel/tcp_direct:unittest"
]
}
}
}
參考站點
OpenHarmony/docs/zh-cn/device-dev/bundles
小結
本文介紹了HPM包描述文件bundle.json信息。