Open Harmony migration: full sorting of build lite configuration directory

Abstract: This paper mainly introduces the purpose of the configuration directory involved in the build lite lightweight compilation and construction system, and analyzes the relevant source code.

This article is shared from Huawei cloud community< Transplantation cases and principles - full sorting of build lite configuration directory >, author: zhushy.

The command-line tool HB (abbreviation of harmony OS | OpenHarmony build compiler build system) is very familiar. This is a build system based on gn and ninja. It aims to support OpenHarmony component development and provides the following basic functions:

  • Support the assembly and compilation of products by components.
  • Independently build the source code of chip solution manufacturers.
  • Build individual components independently

The open source code warehouse corresponding to tool hb is build lite, and the code directory is as follows:

build/lite
├── components                  # Component description file
├── figure                      # Pictures in readme
├── hb                          # hb pip installation package source code
├── make_rootfs                 # File system image creation script
├── config                      # Compile configuration item
│   ├── component               # Component related template definitions
│   ├── kernel                  # Kernel related compilation configuration
│   └── subsystem               # Subsystem compilation configuration
├── platform                    # ld script
├── testfwk                     # Test compilation framework
└── toolchain                   # Compiler tool chain configuration, including compiler path, compilation options, link options, etc

This paper mainly combs the configuration directories involved in the build lite lightweight compilation and construction system. Some knowledge points can only be obtained from the code. There is no detailed description in the official data. I hope this article can supplement this.

Let's first look at some code snippets of related files.

1,build\lite\ohos_var.gni

File build\lite\ohos_var.gni defines the global variables of all parts, and this file is also used to read the configuration file config.config of the product solution The configuration item in JSON is resolved to gn variable. The file was deleted
openharmony\build\lite\config\BUILDCONFIG.gn includes import. The code snippet of this file is as follows. Let's mainly look at the configuration directory. (1) indicates that if the configuration file of the product solution is config If "vendor_adapter_dir" is defined in JSON, the environment variable ohos_vendor_adapter_dir,ohos_board_adapter_dir is set to the configured directory. This is the development board adaptation directory. From the comment "To be deleted, and will use board config." It can be seen that this configuration item is not recommended. To delete it, it is only for compatibility, and it will continue to be retained. The configuration item realizing the same function is the development board configuration file config Configuration item board in GNI_ adapter_ Dir, which will be analyzed in detail below.

(2) it is the product adaptation directory "product_adapter_dir". For some parts related to the product that need to be adapted, the adaptation file will be placed in the configured directory. (3) third_party_dir is used to maintain the directory of third-party software, although we all know that the third-party directory of openharmony is third_party, some subsystem components need to specify this directory explicitly.

    if (product_path != "") {
    product_config = read_file("${product_path}/config.json", "json")

    # Board selected by product.
    board_name = product_config.board
    device_company = product_config.device_company

    # Supported kernel: "liteos_a", "liteos_m", "linux"
    ohos_kernel_type = product_config.kernel_type
    if (defined(product_config.kernel_is_prebuilt)) {
        ohos_kernel_is_prebuilt = product_config.kernel_is_prebuilt
    }

    # To be deleted, and will use board config.
⑴  if (defined(product_config.vendor_adapter_dir)) {
        ohos_vendor_adapter_dir = product_config.vendor_adapter_dir
        ohos_board_adapter_dir = ohos_vendor_adapter_dir
    }
⑵  ohos_product_adapter_dir = product_config.product_adapter_dir
⑶  ohos_third_party_dir = product_config.third_party_dir
    }

2,build\lite\config\BUILDCONFIG.gn

File build \ Lite \ config \ buildconfig GN is used for configuration compilation and construction. This file will import the configuration files of product solutions and chip development board solutions. This file parses the development board configuration file config gni. As shown in (1), board_adapter_dir is the development board adaptation directory, which is used to store the adaptation files of OHOS components.

As we know from the above, the configuration file of the product solution is config JSON can also configure the development board adaptation directory. Here, we can know the development board configuration file config This configuration option of GNI has higher priority. Once configured, config. Will be overwritten The development board adaptation directory of the configuration in JSON. These two configuration items ohos_board_adapter_dir and ohos_vendor_adapter_dir uses the same alias.

    import("//build/lite/ohos_var.gni")
    import("${device_path}/config.gni")
    ......
    # Load board adapter dir from board config.
⑴  if (board_adapter_dir != "") {
    ohos_board_adapter_dir = board_adapter_dir
    ohos_vendor_adapter_dir = board_adapter_dir
    }

3. Example of directory configuration in configuration file in migration case

After reading the code fragments related to build lite, let's take a look at the configuration file fragments of several migration cases.

File openharmony \ vendor \ bearpi \ bearpi_ hm_ nano\config. The directory of JSON configuration includes three-party directory and product adaptation directory third_party_dir.

   "third_party_dir": "//device/soc/hisilicon/hi3861v100/sdk_liteos/third_party",
    "product_adapter_dir": "//vendor/bearpi/bearpi_hm_nano/hals"

File openharmony \ vendor \ GOODIX \ gr5515_ sk_ iotlink_ demo\config. The directory of JSON configuration includes the chip development board adaptation directory vendor_adapter_dir and product adaptation directory product_adapter_dir.

  "third_party_dir": "",
  "vendor_adapter_dir": "//device/soc/goodix/gr551x/adapter",
  "product_adapter_dir": "//vendor/goodix/gr5515_sk_iotlink_demo/hals"

In the file openharmony \ device \ board \ GOODIX \ gr5515_ sk\liteos_ m\config. In GNI, the development board adaptation directory board is also configured_ adapter_ dir. The two configuration files are configured. According to the above analysis of the code of build lite, it is only in config It can be configured once in GNI.

# Board adapter dir for OHOS components.
board_adapter_dir = "//device/soc/goodix/gr551x/adapter"

3,product_adapter_dir product adaptation directory

When developing products, which subsystems or components need to place adaptation files in the product adaptation directory? We execute grep ohos in the OpenHarmony code directory_ product_ adapter_ dir -rn ./, The output is as follows. It can be seen that the components to be adapted at present include: the permission permission permission management component of the security subsystem and the syspara of the startup subsystem_ Lite system parameter components. For the permission permission management part, you need to create security / permission in the product adaptation directory_ Lite directory. For syspara_ For Lite system parameter components, you need to create utils / sys in the product adaptation directory_ Param, utils/token directory. These directories cannot be named arbitrarily, because they are in the build of subsystem components It's written dead in GN. Which documents need to be adapted and implemented shall be provided when analyzing relevant components.

./base/security/permission/services/permission_lite/pms/BUILD.gn:42:    "${ohos_product_adapter_dir}/security/permission_lite:hal_pms",
./base/security/permission/services/permission_lite/ipc_auth/BUILD.gn:25:    "${ohos_product_adapter_dir}/security/permission_lite/ipc_auth/include",
./base/startup/syspara_lite/frameworks/parameter/src/BUILD.gn:31:    deps = [ "$ohos_product_adapter_dir/utils/sys_param:hal_sysparam" ]
./base/startup/syspara_lite/frameworks/parameter/src/BUILD.gn:54:      "$ohos_product_adapter_dir/utils/sys_param:hal_sysparam",
./base/startup/syspara_lite/frameworks/token/BUILD.gn:30:      "$ohos_product_adapter_dir/utils/token:haltoken_shared",
./base/startup/syspara_lite/frameworks/token/BUILD.gn:47:    deps = [ "$ohos_product_adapter_dir/utils/token:hal_token_static" ]

4,board_adapter_dir chip development board adaptation directory

When developing products, which subsystems or components need to place adaptation files in the adaptation directory of the chip development board? We execute grep ohos in the OpenHarmony code directory_ board_ adapter_ dir -rn ./, The output is as follows. It can be seen that the components to be adapted at present include: File component of Utils subsystem, multimedia subsystem and WiFi of communication subsystem_ aware,wifi_lite, bluetooth and other components, IOT_ OTA of hardware subsystem and update subsystem_ Lite components. The adaptation directory of each subsystem or component cannot be named arbitrarily, because it is in the build of subsystem components It's written dead in GN. For specific directories, please refer to the following search results. Which documents need to be adapted and implemented shall be provided when analyzing relevant components.

./utils/native/lite/file/BUILD.gn:22:  deps = [ "$ohos_board_adapter_dir/hals/utils/file:hal_file_static" ]
./foundation/multimedia/utils/lite/BUILD.gn:42:      "$ohos_board_adapter_dir/media:hardware_media_sdk",
./foundation/multimedia/utils/lite/BUILD.gn:43:      "$ohos_board_adapter_dir/middleware:middleware_source_sdk",
./foundation/communication/wifi_aware/BUILD.gn:20:    "$ohos_board_adapter_dir/hals/communication/wifi_lite/wifiservice/source",
./foundation/communication/wifi_aware/BUILD.gn:22:  deps = [ "$ohos_board_adapter_dir/hals/communication/wifi_lite/wifiaware:hal_wifiaware" ]
./foundation/communication/bluetooth/services/bluetooth/BUILD.gn:18:    "$ohos_board_adapter_dir/hals/communication/bluetooth/services:btservice",
./base/iot_hardware/peripheral/BUILD.gn:18:    "$ohos_board_adapter_dir/hals/iot_hardware/wifiiot_lite:hal_iothardware",
./base/iot_hardware/peripheral/BUILD.gn:25:      "$ohos_board_adapter_dir/hals/iot_hardware/wifiiot_lite:hal_iothardware",
./base/update/ota_lite/frameworks/test/unittest/common/BUILD.gn:36:    deps += [ "$ohos_board_adapter_dir/hals/update:hal_update_static" ]
./base/update/ota_lite/frameworks/test/unittest/common/BUILD.gn:39:    deps += [ "$ohos_board_adapter_dir/update:hal_update" ]
./base/update/ota_lite/frameworks/source/BUILD.gn:36:    deps += [ "$ohos_board_adapter_dir/hals/update:hal_update_static" ]
./base/update/ota_lite/frameworks/source/BUILD.gn:64:    deps += [ "$ohos_board_adapter_dir/update:hal_update" ]

5. Kernel configuration folder_ configs

In the folder openharmony \ vendor \ GOODIX \ gr5515 under the root directory of the product solution_ sk_ iotlink_ demo\kernel_ Configs is the kernel folder. At present, the following is the kernel feature clipping configuration file debug config,release.config, wait. How to use this configuration folder and the following files from the file kernel\liteos_m\liteos.gni can find the answer, and the code snippet is as follows. It can be seen that the specific file to use is determined according to the compilation and construction type, such as debug, release, tee, etc.

liteos_config_file = "${ohos_build_type}.config"

liteos_config_file =
    rebase_path(liteos_config_file, "", "$product_path/kernel_configs")
print("liteos_config_file:", liteos_config_file)

6. ACE configuration folder ace_lite_config

If ace of ACE subsystem is configured_ engine_ For Lite components, you need to create a directory ace under the product solution directory_ lite_ Config, which stores the corresponding header file to configure and define the components. You can view the file foundation \ ace \ ace_engine_lite\frameworks\targets\BUILD. Learn more about code snippets in GN.

config("ace_lite_target_config") {
  if (enable_ohos_ace_engine_lite_product_config) {
    defines = [ "ENABLE_OHOS_ACELITE_PRODUCT_CONFIG=1" ]
  }
  include_dirs = [ "$product_path/ace_lite_config" ]
 ......
}

7. Third party software folder_ party_ dir

It has been known above that some components depend on third-party software. Specifically, which components depend on third-party software, we execute grep ohos in the OpenHarmony code directory_ third_ party_ dir -rn ./, The output is as follows. It can be seen that the components to be adapted at present include communication and ota_lite components.

./foundation/communication/softbus_lite/discovery/BUILD.gn:32:      "$ohos_third_party_dir/lwip_sack/include",
./foundation/communication/softbus_lite/trans_service/BUILD.gn:31:      "$ohos_third_party_dir/lwip_sack/include",
./foundation/communication/softbus_lite/trans_service/BUILD.gn:32:      "$ohos_third_party_dir/mbedtls/include",
./foundation/communication/softbus_lite/authmanager/BUILD.gn:31:      "$ohos_third_party_dir/mbedtls/include",
./base/update/ota_lite/frameworks/source/BUILD.gn:31:      "$ohos_third_party_dir/mbedtls/include",
./base/update/ota_lite/frameworks/source/BUILD.gn:32:      "$ohos_third_party_dir/lwip_sack/include",
./base/update/ota_lite/frameworks/source/BUILD.gn:55:      "$ohos_third_party_dir/mbedtls/include",
./base/update/ota_lite/frameworks/source/BUILD.gn:56:      "$ohos_third_party_dir/lwip_sack/include

8. Other

There are also driver configuration folders hdf_config, burn partition folder flash_partition_dir. It will be supplemented later.

Reference site

Refer to the following sites or recommend readers to read the following sites for more information.

 

Click follow to learn about Huawei's new cloud technology for the first time~

Posted by nigeledge on Fri, 06 May 2022 15:25:51 +0300