9

移植案例与原理 - HPM包描述文件Bundle.Json

 2 years ago
source link: https://os.51cto.com/article/703211.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
移植案例与原理 - HPM包描述文件Bundle.Json-51CTO.COM
移植案例与原理 - HPM包描述文件Bundle.Json
作者:zhushangyuan_ 2022-03-04 16:17:03
发现各个子系统、组件、三方库目录下都添加了bundle.json,了解下该文件的用途、用法并快速记录下。

655279a867979cdaa990819438ab0d1b015f3a.png

​想了解更多内容,请访问:​

​51CTO和华为官方合作共建的鸿蒙技术社区​

​https://ost.51cto.com​

1、HPM Bundle的基本概念

Bundle是OpenHarmony中一个用来表示分发单元的术语,等同于包,一个Bundle中通常包含以下内容:

  1. 被分发的二进制文件(二进制类型)。
  2. 被分发的源代码文件(源代码/代码片段类型)。
  3. 编译脚本(发行版类型需要)。
  4. 自身的说明文件。
  • bundle.json:元数据声明(名称,版本,依赖等)。
  • LICENSE:许可协议文本。
  • README.md:自述文件。
  • CHANGELOG.md:变更日志(可选)。

一个Bundle被发布到HPM服务器(https://hpm.harmonyos.com)后,另外一些开发者就可以通过hpm包管理器下载安装使用 。一个Bundle在命名空间内拥有唯一的名称(命名格式为:@scope/name),可以进行独立的版本演进。

一个bundle包通常具有如下代码组织结构:

demo
├── headers            # 头文件(样例)
│   └── main.h
└── src                # 源代码(样例)
│    └─ main.c
├── bundle.json        # 元数据声明文件
└── LICENSE            # 许可协议文本
└── Makefile           # 编译描述文件(样例)
└── README.md          # Bundle的自述文件

2、bundle.json文件格式定义

文件bundle.json一般具有如下格式,对各个属性值的解释见注释部分。因为是json文件,注意下是对象还是数组。对象由花括号{}括起来的逗号分割的成员构成,成员是字符串键和值由逗号分割的键值对组成。数组是由方括号[]括起来的一组值构成。

{
  "name": "@ohos/<component_name>",                                                     # HPM部件的英文名称, 由@符合、组织名称、部件名称组成。
  "description": "component description",                                               # 部件描述
  "version": "3.1.0",                                                                   # 版本号,3.1 应该取的OpenHarmony版本号
  "homePage": "https://gitee.com/openharmony",                                          # 部件的主页
  "license": "BSD 3-claus",                                                             # 部件的版权协议,根据部件license情况填写
  "publishAs": "code-segment",                                                          # 发布形式,一般为代码片段code-segment
  "segment": {                                                                          # 部件的代码路径
    "destPath": "<subsystem>/<component_name>"
  },
  "dirs": [],                                                                           # HPM包的目录结构
  "scripts": {},                                                                        # HPM包定义需要执行的脚本
  "component": {                                                                        # 部件的属性信息
    "name": "<component_name>"                                                          # 部件的名称,和"@ohos/<component_name>"中的名称应该是一致的。
    "subsystem": "xxx subsystem",                                                      # 部件所属子系统
    "syscap": [ "SystemCapability.<Subsystem>.<Feature>.<Subfeature>" ]                 # 部件为应用提供的系统能力
    "features": [ "<component_name>_<feature>" ]                                        # 部件的特性列表
    "adapted_system_type": [ "<system_type>" ]                                          # 部件适用的系统类型:轻量(mini)、小型(small)和标准(standard)
    "rom": "xxxKB",                                                                     # ROM占用
    "ram": "xxxKB",                                                                     # RAM占用
    "deps": {                                                                     
      "components": [                                                                   # 部件依赖的其他部件
        "xxx_component"
      ], 
      "third_party": [                                                                  # 部件依赖的三方开源软件
        "<third_party_software_name>"
      ]
    },
    "build": {                                                                          # 部件编译构建配置,可以多个
     "sub_component": [ "//<domain>/<subsystem>/<component_name>/<sub_component>" ],    # 部件的子部件编译入口
     "inner_kits": [                                                                    # 部件内部接口,可以多个
       {
         "header": {                                                                                    # 内部头文件信息
           "header_base": "<domain>/<subsystem>/<component_name>/interface/innerkits/<sub_component>",  # 内部头文件目录
           "header_files": [ "xxx.h" ]                                                                  # 头文件名称
         },
         "name": "<domain>/<subsystem>/<component_name>/interface/innerkits/<sub_component>"            # 内部接口名称
       }
     ]
     "test": [ "<domain>/<subsystem>/<component_name>/test" ]                           # 部件测试用例编译入口,可以多个测试套入口
   } 
  }
}

3、bundle.json示例

查看bundle.json文件的分布,在各个子系统,三方库下都存在。在开发板移植时,是不需要的。如果需要开发HPM包,是需要编写bundle.json文件的。可以随便打开一个查看具体的示例。

~/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包一样,在执行hpm install时,来安装这个hpm包。⑷处设置该hpm包属于哪个子系统,已经适配的子系统类型,包含的特性等。⑸设置依赖的其他部件和三方库。⑹处设置该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": [
          "//foundation/communication/dsoftbus/core:softbus_server",
          "//foundation/communication/dsoftbus/sdk:softbus_client",
          "//foundation/communication/dsoftbus/core/frame/standard/sa_profile:softbus_sa_profile",
          "//foundation/communication/dsoftbus/tools:tool"
        ],
        "inner_kits": [
          {
            "name": "//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": "//foundation/communication/dsoftbus/interfaces/kits"
            }
          }
        ],
⑺      "test": [
          "//foundation/communication/dsoftbus/tests/adapter/unittest:unittest",
          "//foundation/communication/dsoftbus/tests/sdk/discovery/unittest:unittest",
          "//foundation/communication/dsoftbus/tests/sdk/transmission/trans_channel:unittest",
          "//foundation/communication/dsoftbus/tests/sdk/bus_center/unittest:unittest",
          "//foundation/communication/dsoftbus/tests/core/authentication:unittest",
          "//foundation/communication/dsoftbus/tests/core/bus_center/lnn:unittest",
          "//foundation/communication/dsoftbus/tests/core/common/utils:unittest",
          "//foundation/communication/dsoftbus/tests/core/connection:connectionTest",
          "//foundation/communication/dsoftbus/tests/core/discovery/manager:unittest",
          "//foundation/communication/dsoftbus/tests/core/transmission/trans_channel/tcp_direct:unittest"
        ]
      }
    }
  }

OpenHarmony/docs/zh-cn/device-dev/bundles

本文介绍了HPM包描述文件bundle.json信息。

​想了解更多内容,请访问:​

​51CTO和华为官方合作共建的鸿蒙技术社区​

​https://ost.51cto.com​

09539be02d15cc92407809c946f39f8959d65e.jpg


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK