下载
中文
注册
我要评分
文档获取效率
文档正确性
内容完整性
文档易理解
在线提单
论坛求助
昇腾小AI

执行构建

本章节指导用户构建自定义软件包。

操作步骤

  1. 根据实际情况,修改配置文件project.conf,文件路径为“{project_dir}/config/project_cfg/project.conf”。
    _ProductName="Ascend-AtlasSample-omsdk"     # 修改_ProductName字段为用户的工程名
    _Version="5.0.0"                            # 修改version.xml中的Version字段的版本号
    _Vendor="custom-sdk"                        # 修改version.xml中的Vendor字段的厂商信息,不能为huawei
    _NeedAdditionalDriver="no"                  # 配置编译打包模组开发示例,可选配置,默认关闭
    _NeedAddExtendRestfulInterface="no"         # 新增RESTful接口,可选配置,默认关闭
    _NeedAddExtendFusionDirectorInterface="no"  # 新增云边协同接口,可选配置,默认关闭
    _NeedCustomizedWebAssets="no"               # 配置自定义图片和厂商信息开关,可选配置,默认关闭
    _NeedCustomizedWebNav="no"                  # 动态加载组件功能开关,默认关闭
    _NeedBuildCustomizedWeb="no"                # 自定义前端编译功能,默认关闭
    _NeedCustomizedAlarmCheck="no"              # 配置自定义告警检测开关,可选配置,默认关闭
  2. 按照如下示例,编写构建脚本build.sh,脚本路径为“{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
    
        # 修改版本信息
        sed -i "s#{Version}#${_Version}#g" "${xml_version_file}"
    
        # 修改软件包名称
        local omsdk_name="${_ProductName}_${_Version}_linux-aarch64.zip"
        sed -i "/<Package>/,/<\/Package>/ s|<FileName>.*|<FileName>${omsdk_name}</FileName>|g" "${xml_version_file}"
    
        # 修改厂商信息
        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
    
        # 修改version.xml中的可配置字段
        if ! modify_version_xmlfile "${OMSDK_TAR_PATH}/version.xml"; then
            return 1
        fi
    
        # 添加自定义告警检测
        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/
            # 覆盖OM SDK软件包中告警相关的配置文件
            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
    
        # 添加扩展模组驱动
        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
    
        # 拷贝外设配置
        cp -rf "${TOP_DIR}"/src/app/add_extend_device/device_config.json "${OMSDK_TAR_PATH}"/software/ibma/lib/Linux/config/device_config.json
    
        # 添加扩展restful接口
        # build_extend_restful_interface.sh具体实现可参考对应章节实现
        if [[ "${_NeedAddExtendRestfulInterface}" == "yes" ]]; then
            if ! bash "${CUR_DIR}/../src/app/add_extend_restful_interface/build_extend_restful_interface.sh";then
                return 1
            fi
        fi
    
        #  添加扩展 fusion director 接口
        # build_extend_fusion_director_interface.sh具体实现可参考对应章节实现
        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
    
        # 自定义前端编译功能
        # build_customized_web_project.sh 具体实现可参考对应章节实现,本段代码需放在“_NeedCustomizedWebNav”和“_NeedCustomizedWebAssets”功能代码之前
        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
    
        # 配置自定义图片和厂商信息
        # build_customized_web_assets.sh具体实现可参考对应章节实现
        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
    
        # 动态加载组件
        # build_customized_web_nav.sh具体实现可参考对应章节实现
        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
        # 添加自定义签名工具
        # build_cms_verify.sh、replace_cms_so.sh具体实现可参考对应章节实现
        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"
        # 添加自定义omsdk软件配置
        bash "${PRODUCT_SCRIPT_PATH}/add_customized_config/replace_module_type.sh"
        # 重新打包omsdk.tar.gz
        if ! tar_omsdk_package; then
            echo "package omsdk.tar.gz failed"
        fi
        # 生成vercfg.xml
        gen_vercfg_xml
        # 生成omsdk.tar.gz、vercfg.xml、version.xml的签名文件与吊销列表
        # build_signature.sh需用户自行实现,该实现仅为实例
        build_sign_file
        # 重新打包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. 将om-sdk.tar.gz上传到{project_dir}/platform路径下。
  4. 执行以下命令,进入项目build目录。
    cd {project_dir}/build
  5. 执行以下命令,开始构建软件包。
    bash build.sh

    构建成功之后,在{project_dir}/output”目录下生成软件包{_ProductName}_{_Version}_linux-aarch64.zip。

搜索结果
找到“0”个结果

当前产品无相关内容

未找到相关内容,请尝试其他搜索词