移植案例与原理 - HPM包描述文件bundle.json

799 篇文章 5 订阅
606 篇文章 11 订阅

发现各个子系统、组件、三方库目录下都添加了bundle.json,了解下该文件的用途、用法并快速记录下。

1、HPM Bundle的基本概念

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

  • 被分发的二进制文件(二进制类型)
  • 被分发的源代码文件(源代码/代码片段类型)
  • 编译脚本(发行版类型需要)
  • 自身的说明文件
    • 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"
        ]
      }
    }
  }

小结

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

如果大家想要更加深入的学习 OpenHarmony(鸿蒙南向) 开发的全栈内容,不妨可以参考以下相关学习文档进行学习,助你快速提升自己:

OpenHarmony 开发环境搭建:https://qr18.cn/CgxrRy

《OpenHarmony源码解析》:https://qr18.cn/CgxrRy

  • 搭建开发环境
  • Windows 开发环境的搭建
  • Ubuntu 开发环境搭建
  • Linux 与 Windows 之间的文件共享
  • ……

系统架构分析:https://qr18.cn/CgxrRy

  • 构建子系统
  • 启动流程
  • 子系统
  • 分布式任务调度子系统
  • 分布式通信子系统
  • 驱动子系统
  • ……

OpenHarmony 设备开发学习手册:https://qr18.cn/CgxrRy

在这里插入图片描述

OpenHarmony面试题(内含参考答案):https://qr18.cn/CgxrRy

写在最后

  • 如果你觉得这篇内容对你还蛮有帮助,我想邀请你帮我三个小忙:
  • 点赞,转发,有你们的 『点赞和评论』,才是我创造的动力。
  • 关注小编,同时可以期待后续文章ing🚀,不定期分享原创知识。
  • 想要获取更多完整鸿蒙最新学习资源,请移步前往小编:https://qr21.cn/FV7h05

  • 12
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值