Building a Package

This section describes how to build a custom software package.

Procedure

  1. Modify the project.conf configuration file in {project_dir}/config/project_cfg/project.conf.
    _ProductName="Ascend-AtlasSample-omsdk"     # Change the value of the _ProductName field to the project name.
    _Version="6.0.RC2"                            # Change the value of Version in the version.xml file.
    _Vendor="custom-sdk"                        # Change the value of Vendor in the version.xml file, which cannot be huawei.
    _NeedAdditionalDriver="no"                  # Development example of configuring the compilation and packaging module (optional, disabled by default).
    _NeedAddExtendRestfulInterface="no"         # New RESTful API (optional, disabled by default).
    _NeedAddExtendFusionDirectorInterface="no"  # New cloud-edge collaboration API (optional, disabled by default).
    _NeedCustomizedWebAssets="no"               # Whether to configure customized images and vendor information (optional, disabled by default).
    _NeedCustomizedWebNav="no"                  # Whether to dynamically load components (optional, disabled by default).
    _NeedBuildCustomizedWeb="no"                # Customized frontend compilation (optional, disabled by default).
    _NeedCustomizedAlarmCheck="no"              # Whether to configure customized alarms (optional, disabled by default).
  2. Compile the build script build.sh in {project_dir}/build/build.sh.
    #!/bin/bash
    
    CUR_DIR="$(dirname "$(readlink -f "$0")")"
    TOP_DIR="$(dirname "${CUR_DIR}")"
    PRODUCT_CFG_PATH="${TOP_DIR}/config/project_cfg/project.conf"
    PLATFORM_PATH="${TOP_DIR}/platform"
    PACKAGE_PATH="${PLATFORM_PATH}/package"
    OMSDK_TAR_PATH="${PLATFORM_PATH}/omsdk"
    PRODUCT_SCRIPT_PATH="${TOP_DIR}/src/app"
    OUTPUT_PATH="${TOP_DIR}/output"
    
    function modify_version_xmlfile()
    {
        local xml_version_file=$1
        if [ ! -f "${xml_version_file}" ];then
            echo "modify_version_xmlfile failed, ${xml_version_file} not exist"
            return 1
        fi
    
        # Modify the version information.
        sed -i "s#{Version}#${_Version}#g" "${xml_version_file}"
    
        # Changed the software package names.
        local omsdk_name="${_ProductName}_${_Version}_linux-aarch64.zip"
        sed -i "/<Package>/,/<\/Package>/ s|<FileName>.*|<FileName>${omsdk_name}</FileName>|g" "${xml_version_file}"
    
        # Modify vendor information.
        sed -i "/<Package>/,/<\/Package>/ s|<Version>.*|<Version>${_Version}</Version>|g" "${xml_version_file}"
        if [[ $(echo "${_Vendor}" | tr [:upper:] [:lower:]) == "huawei" ]]; then
            echo "manufacturer information is invalid"
            return 1
        fi
        sed -i "s|<Vendor>.*</Vendor>|<Vendor>${_Vendor}</Vendor>|g" "${xml_version_file}"
        return 0
    }
    function build_package()
    {
        if [[ -d "${OMSDK_TAR_PATH}" ]]; then
            rm -rf "${OMSDK_TAR_PATH}"
        fi
        mkdir -p "${OMSDK_TAR_PATH}"
        if [[ -d "${PACKAGE_PATH}" ]]; then
            rm -rf "${PACKAGE_PATH}"
        fi
        mkdir -p "${PACKAGE_PATH}"
        if [[ -d "${OUTPUT_PATH}" ]]; then
            rm -rf "${OUTPUT_PATH}"
        fi
        mkdir -p "${OUTPUT_PATH}"
        local omsdk_tar_path="$(find "${PLATFORM_PATH}/" -maxdepth 1 -name "om-sdk.tar.gz")"
        if ! tar -zxf "${omsdk_tar_path}" -C "${OMSDK_TAR_PATH}"; then
            return 1
        fi
    
        # Modify configurable fields in the version.xml file.
        if ! modify_version_xmlfile "${OMSDK_TAR_PATH}/version.xml"; then
            return 1
        fi
    
        # Add customized alarm detection.
        if [[ "${_NeedCustomizedAlarmCheck}" == "yes" ]]; then
            if ! bash "${TOP_DIR}/src/app/add_customized_alarm/build_customized_alarm.sh";then
                return 1
            fi
            cp -rf "${TOP_DIR}"/src/app/add_customized_alarm/build/libcustomized_alarm.so "${OMSDK_TAR_PATH}"/lib/
            # Overwrite the alarm-related configuration files in the OM SDK software package.
            cp -rf "${TOP_DIR}"/src/app/add_customized_alarm/alarm_info_en.json "${OMSDK_TAR_PATH}"/config/alarm_info_en.json
            cp -rf "${TOP_DIR}"/src/app/add_customized_alarm/all_alarm_for_manager.json "${OMSDK_TAR_PATH}"/software/ibma/config/all_alarm_for_manager.json
            cp -rf "${TOP_DIR}"/src/app/add_customized_alarm/all_alarm_for_manager_web.json "${OMSDK_TAR_PATH}"/software/nginx/html/manager/config/all_alarm_for_manager.json
            cp -rf "${TOP_DIR}"/src/app/add_customized_alarm/alarm_info_solution_en.json "${OMSDK_TAR_PATH}"/software/nginx/html/manager/config/alarm_info_solution_en.json
            cp -rf "${TOP_DIR}"/src/app/add_customized_alarm/alarm_info_solution_zh.json "${OMSDK_TAR_PATH}"/software/nginx/html/manager/config/alarm_info_solution_zh.json
        fi
    
        # Add the driver for the extended module.
        if [[ "${_NeedAdditionalDriver}" == "yes" ]]; then
            if ! bash "${TOP_DIR}"/src/app/add_extend_driver_adapter/build_extend_driver_adapter.sh;then
                return 1
            fi
            cp -rf "${TOP_DIR}"/src/app/add_extend_driver_adapter/build/libdemo_adapter.so "${OMSDK_TAR_PATH}"/lib/
            # copy additional configurations
            cp -rf "${TOP_DIR}"/config/module_def/*.json "${OMSDK_TAR_PATH}"/software/ibma/config/devm_configs/
        fi
    
        # Copy the external device configuration.
        cp -rf "${TOP_DIR}"/src/app/add_extend_device/device_config.json "${OMSDK_TAR_PATH}"/software/ibma/lib/Linux/config/device_config.json
    
        # Add an extended RESTful API.
        # For details about the implementation of build_extend_restful_interface.sh, see the corresponding section.
        if [[ "${_NeedAddExtendRestfulInterface}" == "yes" ]]; then
            if ! bash "${CUR_DIR}/../src/app/add_extend_restful_interface/build_extend_restful_interface.sh";then
                return 1
            fi
        fi
    
        # Add the extended fusion director API.
        # For details about the implementation of build_extend_fusion_director_interface.sh, see the corresponding section.
        if [[ "${_NeedAddExtendFusionDirectorInterface}" == "yes" ]]; then
            if ! bash "${TOP_DIR}/src/app/add_extend_fusion_director_interface/build_extend_fusion_director_interface.sh";then
                return 1
            fi
        fi
    
        # Customize the frontend compilation function.
        # For details about the implementation of build_customized_web_project.sh, see the corresponding section. The code must be placed before the code of the _NeedCustomizedWebNav and _NeedCustomizedWebAssets functions.
        if [ "${_NeedBuildCustomizedWeb}" == "yes" ];then
             bash "${TOP_DIR}/src/app/build_customized_web_project/build_customized_web_project.sh" "${OMSDK_TAR_PATH}/software/nginx/html/manager"
             ret=$?
            if [ "$ret" != "0" ];then
                return 1
             fi
        fi
    
        # Configure the customized image and vendor information.
        # For details about the implementation of build_customized_web_assets.sh, see the corresponding section.
        if [ "${_NeedCustomizedWebAssets}" == "yes" ]; then
            if ! bash "${TOP_DIR}/src/app/add_customized_web_assets/build_customized_web_assets.sh" "${TOP_DIR}";then
                return 1
            fi
        fi
    
        # Dynamically load components.
        # For details about the implementation of build_customized_web_nav.sh, see the corresponding section.
        if [ "${_NeedCustomizedWebNav}" == "yes" ];then
            bash "${TOP_DIR}/src/app/set_customized_web_nav/build_customized_web_nav.sh" "${TOP_DIR}"
            ret=$?
            if [ "$ret" != "0" ];then
                return 1
            fi
        fi
        # Add a custom signature tool.
        # For details about the implementation of build_cms_verify.sh and replace_cms_so.sh, see the corresponding sections.
        bash "${PRODUCT_SCRIPT_PATH}/add_custom_define_cms_verify/build_cms_verify.sh"
        bash "${PRODUCT_SCRIPT_PATH}/add_custom_define_cms_verify/replace_cms_so.sh"
        # Add the custom OM SDK software configuration.
        bash "${PRODUCT_SCRIPT_PATH}/add_customized_config/replace_module_type.sh"
        # Repack omsdk.tar.gz.
        if ! tar_omsdk_package; then
            echo "package omsdk.tar.gz failed"
        fi
        # Generate vercfg.xml.
        gen_vercfg_xml
        # Generate the signature files and CRLs of omsdk.tar.gz, vercfg.xml, and version.xml.
        # build_signature.sh needs to be implemented by you. This implementation is only an example.
        build_sign_file
        # Package omsdk.zip.
        zip_omsdk_package
        return 0
    }
    function build_sign_file()
    {
        echo "vercfg.xml.cms" > "${PACKAGE_PATH}/vercfg.xml.cms"
        echo "vercfg.xml.crl" > "${PACKAGE_PATH}/vercfg.xml.crl"
        local om_package_name="${_ProductName}_${_Version}_linux-aarch64.tar.gz"
        echo "${om_package_name}" > "${PACKAGE_PATH}/${om_package_name}.cms"
        echo "${om_package_name}" > "${PACKAGE_PATH}/${om_package_name}.crl"
        echo "version.xml.cms" > "${PACKAGE_PATH}/version.xml.cms"
        echo "version.xml.crl" > "${PACKAGE_PATH}/version.xml.crl"
    }
    function tar_omsdk_package()
    {
        local om_package_name="${_ProductName}_${_Version}_linux-aarch64.tar.gz"
        cd "${OMSDK_TAR_PATH}"
        if ! tar -czf "${om_package_name}" *; then
            return 1
        fi
        cp "${OMSDK_TAR_PATH}/${om_package_name}" "${PACKAGE_PATH}/"
        cp "${OMSDK_TAR_PATH}/version.xml" "${PACKAGE_PATH}/"
        cd "${TOP_DIR}"
        return 0
    }
    function gen_vercfg_xml()
    {
        local vercfg_xml_path="${PACKAGE_PATH}/vercfg.xml"
        touch "${vercfg_xml_path}"
        chmod 600 "${vercfg_xml_path}"
        echo -e '<?xml version="1.0" encoding="utf-8"?>\n<Package>\n</Package>' > "${vercfg_xml_path}"
        local sdk_tar_gz="$(find "${PACKAGE_PATH}" -maxdepth 1 -name "${_ProductName}_${_Version}_linux-aarch64.tar.gz")"
        sed -i "3 i \ \t<File>\n\t\t<FilePath>$(basename "${sdk_tar_gz}")</FilePath>\n\t\t<SHAValue>$(sha256sum "${sdk_tar_gz}" | awk '{print $1}')</SHAValue>\n\t</File>" "${vercfg_xml_path}"
        local version_xml_path="${PACKAGE_PATH}/version.xml"
        sed -i "3 i \ \t<File>\n\t\t<FilePath>$(basename "${version_xml_path}")</FilePath>\n\t\t<SHAValue>$(sha256sum "${version_xml_path}" | awk '{print $1}')</SHAValue>\n\t</File>" "${vercfg_xml_path}"
    }
    function zip_omsdk_package()
    {
        local sdk_zip_name="${_ProductName}_${_Version}_linux-aarch64.zip"
        cd "${PACKAGE_PATH}"
        if ! zip "${OUTPUT_PATH}/${sdk_zip_name}" *; then
            echo "zip failed"
            return 1
        fi
        echo "zip software file successfully!"
    }
    function main()
    {
        echo "**********************do build start!**********************"
        if [ ! -e "${PRODUCT_CFG_PATH}" ];then
            echo "error: ${PRODUCT_CFG_PATH}"
            return 1
        else
            source "${PRODUCT_CFG_PATH}"
        fi
        build_package
        return $?
        echo "**********************do build end!**********************"
    }
    main
  3. Upload om-sdk.tar.gz to the {project_dir}/platform directory.
  4. Run the following command to go to the build directory of the project:
    cd {project_dir}/build
  5. Run the following command to build the software package:
    bash build.sh

    After the build is successful, the software package {_ProductName}_{_Version}_linux-aarch64.zip is generated in the {project_dir}/output.