Merged
refactor: 切换工程公共打包脚本 #1933
maohp_hwAdd on Apr 30
refactor: 切换工程公共打包脚本 #1933
Merged
Total: 37 files changed+33-13703
| @@ -1,129 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 2 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 3 | -# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | -# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | -# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 10 | - | ||
| 11 | -# makeself.cmake - 自定义 makeself 打包脚本 | ||
| 12 | -message(STATUS "CPACK_CMAKE_SOURCE_DIR = ${CPACK_CMAKE_SOURCE_DIR}") | ||
| 13 | -message(STATUS "CPACK_CMAKE_CURRENT_SOURCE_DIR = ${CPACK_CMAKE_CURRENT_SOURCE_DIR}") | ||
| 14 | -message(STATUS "CPACK_CMAKE_BINARY_DIR = ${CPACK_CMAKE_BINARY_DIR}") | ||
| 15 | -message(STATUS "CPACK_PACKAGE_FILE_NAME = ${CPACK_PACKAGE_FILE_NAME}") | ||
| 16 | -message(STATUS "STAGING_DIR = ${STAGING_DIR}") | ||
| 17 | -message(STATUS "CMAKE_COMMAND = ${CMAKE_COMMAND}") | ||
| 18 | -message(STATUS "CPACK_TEMPORARY_DIRECTORY = ${CPACK_TEMPORARY_DIRECTORY}") | ||
| 19 | - | ||
| 20 | -# 设置 makeself 路径 | ||
| 21 | -set(MAKESELF_EXE ${CPACK_MAKESELF_PATH}/makeself.sh) | ||
| 22 | -set(MAKESELF_HEADER_EXE ${CPACK_MAKESELF_PATH}/makeself-header.sh) | ||
| 23 | -if(NOT MAKESELF_EXE) | ||
| 24 | - message(FATAL_ERROR "makeself not found! Install it with: sudo apt install makeself") | ||
| 25 | -endif() | ||
| 26 | - | ||
| 27 | -# 创建临时安装目录 | ||
| 28 | -set(STAGING_DIR "${CPACK_CMAKE_BINARY_DIR}/_CPack_Packages/makeself_staging") | ||
| 29 | -file(MAKE_DIRECTORY "${STAGING_DIR}") | ||
| 30 | - | ||
| 31 | -# 执行安装到临时目录 | ||
| 32 | -execute_process( | ||
| 33 | - COMMAND "${CMAKE_COMMAND}" --install "${CPACK_CMAKE_BINARY_DIR}" --prefix "${STAGING_DIR}" --component asc-devkit | ||
| 34 | - RESULT_VARIABLE INSTALL_RESULT | ||
| 35 | -) | ||
| 36 | - | ||
| 37 | -if(NOT INSTALL_RESULT EQUAL 0) | ||
| 38 | - message(FATAL_ERROR "Installation to staging directory failed: ${INSTALL_RESULT}") | ||
| 39 | -endif() | ||
| 40 | - | ||
| 41 | -# 生成安装配置文件 | ||
| 42 | -set(CSV_OUTPUT ${STAGING_DIR}/filelist.csv) | ||
| 43 | -execute_process( | ||
| 44 | - COMMAND python3 ${CPACK_CMAKE_SOURCE_DIR}/scripts/package/package.py --pkg_name ${CPACK_PACKAGE_NAME} --os_arch linux-${CPACK_ARCH} | ||
| 45 | - WORKING_DIRECTORY ${CPACK_CMAKE_BINARY_DIR} | ||
| 46 | - OUTPUT_VARIABLE result | ||
| 47 | - ERROR_VARIABLE error | ||
| 48 | - RESULT_VARIABLE code | ||
| 49 | - OUTPUT_STRIP_TRAILING_WHITESPACE | ||
| 50 | -) | ||
| 51 | -message(STATUS "package.py result: ${code}") | ||
| 52 | -if (NOT code EQUAL 0) | ||
| 53 | - message(FATAL_ERROR "Filelist generation failed: ${error}") | ||
| 54 | -else () | ||
| 55 | - message(STATUS "Filelist generated successfully: ${result}") | ||
| 56 | - | ||
| 57 | - if (NOT EXISTS ${CSV_OUTPUT}) | ||
| 58 | - message(FATAL_ERROR "Output file not created: ${CSV_OUTPUT}") | ||
| 59 | - endif () | ||
| 60 | -endif () | ||
| 61 | - | ||
| 62 | -set(OUT_PUT_FILELIST_DIR | ||
| 63 | - ${STAGING_DIR}/share/info/asc-devkit/script | ||
| 64 | -) | ||
| 65 | -configure_file( | ||
| 66 | - ${CSV_OUTPUT} | ||
| 67 | - ${OUT_PUT_FILELIST_DIR} | ||
| 68 | - COPYONLY | ||
| 69 | -) | ||
| 70 | -file(REMOVE ${CSV_OUTPUT}) | ||
| 71 | - | ||
| 72 | -set(OUT_PUT_SCENE | ||
| 73 | - ${CPACK_CMAKE_BINARY_DIR}/share/info/asc-devkit/scene.info | ||
| 74 | -) | ||
| 75 | -set(OUT_PUT_SCENE_DIR | ||
| 76 | - ${STAGING_DIR}/share/info/asc-devkit | ||
| 77 | -) | ||
| 78 | -configure_file( | ||
| 79 | - ${OUT_PUT_SCENE} | ||
| 80 | - ${OUT_PUT_SCENE_DIR} | ||
| 81 | - COPYONLY | ||
| 82 | -) | ||
| 83 | - | ||
| 84 | -# 统一修正文件权限 | ||
| 85 | -if(EXISTS "${STAGING_DIR}/${CMAKE_SYSTEM_PROCESSOR}-linux/conf/path.cfg") | ||
| 86 | - execute_process(COMMAND chmod 440 "${STAGING_DIR}/${CMAKE_SYSTEM_PROCESSOR}-linux/conf/path.cfg") | ||
| 87 | -endif() | ||
| 88 | -if(EXISTS "${STAGING_DIR}/${CMAKE_SYSTEM_PROCESSOR}-linux/bin") | ||
| 89 | - execute_process(COMMAND find "${STAGING_DIR}/${CMAKE_SYSTEM_PROCESSOR}-linux/bin" -type f -exec chmod 550 {} +) | ||
| 90 | -endif() | ||
| 91 | -if(EXISTS "${STAGING_DIR}/${CMAKE_SYSTEM_PROCESSOR}-linux/lib64") | ||
| 92 | - execute_process(COMMAND find "${STAGING_DIR}/${CMAKE_SYSTEM_PROCESSOR}-linux/lib64" -type f -exec chmod 440 {} +) | ||
| 93 | -endif() | ||
| 94 | -if(EXISTS "${STAGING_DIR}/${CMAKE_SYSTEM_PROCESSOR}-linux/devlib") | ||
| 95 | - execute_process(COMMAND find "${STAGING_DIR}/${CMAKE_SYSTEM_PROCESSOR}-linux/devlib" -type f -exec chmod 440 {} +) | ||
| 96 | -endif() | ||
| 97 | -if(EXISTS "${STAGING_DIR}/${CMAKE_SYSTEM_PROCESSOR}-linux/include") | ||
| 98 | - execute_process(COMMAND find "${STAGING_DIR}/${CMAKE_SYSTEM_PROCESSOR}-linux/include" -type f -exec chmod 440 {} +) | ||
| 99 | -endif() | ||
| 100 | -if(EXISTS "${STAGING_DIR}/${CMAKE_SYSTEM_PROCESSOR}-linux/pkg_inc") | ||
| 101 | - execute_process(COMMAND find "${STAGING_DIR}/${CMAKE_SYSTEM_PROCESSOR}-linux/pkg_inc" -type f -exec chmod 440 {} +) | ||
| 102 | -endif() | ||
| 103 | -if(EXISTS "${STAGING_DIR}/opp/built-in/op_impl") | ||
| 104 | - execute_process(COMMAND find "${STAGING_DIR}/opp/built-in/op_impl" -type f -exec chmod 440 {} +) | ||
| 105 | -endif() | ||
| 106 | - | ||
| 107 | -# makeself打包 | ||
| 108 | -file(STRINGS ${CPACK_CMAKE_BINARY_DIR}/makeself.txt script_output) | ||
| 109 | -string(REPLACE " " ";" makeself_param_string "${script_output}") | ||
| 110 | - | ||
| 111 | -list(LENGTH makeself_param_string LIST_LENGTH) | ||
| 112 | -math(EXPR INSERT_INDEX "${LIST_LENGTH} - 2") | ||
| 113 | -list(INSERT makeself_param_string ${INSERT_INDEX} "${STAGING_DIR}") | ||
| 114 | - | ||
| 115 | -message(STATUS "script output: ${script_output}") | ||
| 116 | -message(STATUS "makeself: ${makeself_param_string}") | ||
| 117 | - | ||
| 118 | -execute_process(COMMAND bash ${MAKESELF_EXE} | ||
| 119 | - --header ${MAKESELF_HEADER_EXE} | ||
| 120 | - --help-header share/info/asc-devkit/script/help.info | ||
| 121 | - ${makeself_param_string} share/info/asc-devkit/script/install.sh | ||
| 122 | - WORKING_DIRECTORY ${STAGING_DIR} | ||
| 123 | - RESULT_VARIABLE EXEC_RESULT | ||
| 124 | - ERROR_VARIABLE EXEC_ERROR | ||
| 125 | -) | ||
| 126 | - | ||
| 127 | -if(NOT EXEC_RESULT EQUAL 0) | ||
| 128 | - message(FATAL_ERROR "makeself packaging failed: ${EXEC_ERROR}") | ||
| 129 | -endif() | ||
| @@ -85,12 +85,12 @@ parse_semantic_version( | |||
| 85 | # ------------------------- | 85 | # ------------------------- |
| 86 | configure_file( | 86 | configure_file( |
| 87 | ${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.h.in | 87 | ${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.h.in |
| 88 | - ${CPACK_CMAKE_BINARY_DIR}/scripts/package/asc-devkit/asc_devkit_version.h | 88 | + ${CMAKE_BINARY_DIR}/scripts/package/asc-devkit/asc_devkit_version.h |
| 89 | @ONLY | 89 | @ONLY |
| 90 | ) | 90 | ) |
| 91 | 91 | ||
| 92 | set(VERSION_FILES | 92 | set(VERSION_FILES |
| 93 | - ${CPACK_CMAKE_BINARY_DIR}/scripts/package/asc-devkit/asc_devkit_version.h | 93 | + ${CMAKE_BINARY_DIR}/scripts/package/asc-devkit/asc_devkit_version.h |
| 94 | ) | 94 | ) |
| 95 | 95 | ||
| 96 | install(FILES ${VERSION_FILES} | 96 | install(FILES ${VERSION_FILES} |
| @@ -1,11 +0,0 @@ | |||
| 1 | -#!/usr/bin/env python3 | ||
| 2 | -# -*- coding: UTF-8 -*- | ||
| 3 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 4 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 5 | -# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 6 | -# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 7 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 8 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 9 | -# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 10 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 11 | -# ---------------------------------------------------------------------------------------------------------- | ||
| @@ -1,2 +0,0 @@ | |||
| 1 | -CUSTOM_DATA_PATH=$HOME/Ascend/latest/data/ | ||
| 2 | -CUSTOM_CONF_PATH=$HOME/Ascend/latest/conf/ | ||
| @@ -1,11 +0,0 @@ | |||
| 1 | -#!/usr/bin/env python3 | ||
| 2 | -# -*- coding: UTF-8 -*- | ||
| 3 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 4 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 5 | -# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 6 | -# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 7 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 8 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 9 | -# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 10 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 11 | -# ---------------------------------------------------------------------------------------------------------- | ||
| @@ -1,511 +0,0 @@ | |||
| 1 | -#!/usr/bin/env python3 | ||
| 2 | -# -*- coding: UTF-8 -*- | ||
| 3 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 4 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 5 | -# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 6 | -# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 7 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 8 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 9 | -# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 10 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 11 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 12 | - | ||
| 13 | -"""filelist相关类。""" | ||
| 14 | - | ||
| 15 | -import itertools | ||
| 16 | -import os | ||
| 17 | -from enum import IntEnum | ||
| 18 | -from collections import Counter | ||
| 19 | -from functools import partial | ||
| 20 | -from itertools import chain, repeat | ||
| 21 | -from operator import and_, attrgetter, contains, itemgetter, lt, methodcaller, ne, not_ | ||
| 22 | -from typing import Callable, Iterator, List, NamedTuple, Set, Tuple | ||
| 23 | - | ||
| 24 | -from .utils.pkg_utils import (TOP_DIR, FilelistError, GenerateFilelistError, | ||
| 25 | - conditional_apply, pairwise, swap_args, config_feature_to_string) | ||
| 26 | -from .utils.funcbase import (any_, constant, dispatch, identity, invoke, pipe, side_effect, star_apply) | ||
| 27 | -from .utils.comm_log import CommLog | ||
| 28 | - | ||
| 29 | - | ||
| 30 | -class FileItem(NamedTuple): | ||
| 31 | - """文件条目""" | ||
| 32 | - module: str | ||
| 33 | - operation: str | ||
| 34 | - relative_path_in_pkg: str | ||
| 35 | - relative_install_path: str | ||
| 36 | - is_in_docker: str | ||
| 37 | - permission: str | ||
| 38 | - owner_group: str | ||
| 39 | - install_type: str | ||
| 40 | - softlink: List[str] | ||
| 41 | - feature: Set[str] | ||
| 42 | - is_common_path: str | ||
| 43 | - configurable: str | ||
| 44 | - hash_value: str | ||
| 45 | - block: str | ||
| 46 | - pkg_inner_softlink: List[str] | ||
| 47 | - chip: Set[str] | ||
| 48 | - is_dir: bool | ||
| 49 | - | ||
| 50 | - | ||
| 51 | -def create_file_item(*args, **kwargs) -> FileItem: | ||
| 52 | - """创建文件条目。""" | ||
| 53 | - file_item = FileItem(*args, **kwargs) | ||
| 54 | - | ||
| 55 | - if not isinstance(file_item.feature, set): | ||
| 56 | - raise TypeError('The feature parameter should be a set.') | ||
| 57 | - if not isinstance(file_item.chip, set): | ||
| 58 | - raise TypeError('The chip parameter should be a set.') | ||
| 59 | - if not isinstance(file_item.softlink, list): | ||
| 60 | - raise TypeError('The softlink parameter should be a list.') | ||
| 61 | - if not isinstance(file_item.pkg_inner_softlink, list): | ||
| 62 | - raise TypeError('The pkg_inner_softlink parameter should be a list.') | ||
| 63 | - | ||
| 64 | - return file_item | ||
| 65 | - | ||
| 66 | - | ||
| 67 | -# 文件列表 | ||
| 68 | -FileList = List[FileItem] | ||
| 69 | - | ||
| 70 | - | ||
| 71 | -def soft_links_to_string(soft_links: List[str]) -> str: | ||
| 72 | - """软链接转换为字符串。""" | ||
| 73 | - if not soft_links: | ||
| 74 | - return 'NA' | ||
| 75 | - return ';'.join(soft_links) | ||
| 76 | - | ||
| 77 | - | ||
| 78 | -def file_item_to_string(item: FileItem) -> str: | ||
| 79 | - """文件条目转换为字符串。""" | ||
| 80 | - return ','.join([ | ||
| 81 | - item.module, item.operation, item.relative_path_in_pkg, item.relative_install_path, | ||
| 82 | - item.is_in_docker, item.permission, item.owner_group, item.install_type, | ||
| 83 | - soft_links_to_string(item.softlink), config_feature_to_string(item.feature), | ||
| 84 | - item.is_common_path, item.configurable, item.hash_value, item.block, | ||
| 85 | - soft_links_to_string(item.pkg_inner_softlink), config_feature_to_string(item.chip) | ||
| 86 | - ]) | ||
| 87 | - | ||
| 88 | - | ||
| 89 | -def get_filelist_header_string() -> str: | ||
| 90 | - """获取文件列表表头。""" | ||
| 91 | - return ','.join([ | ||
| 92 | - 'module', 'operation', 'relative_path_in_pkg', 'relative_install_path', | ||
| 93 | - 'is_in_docker', 'permission', 'owner:group', 'install_type', | ||
| 94 | - 'softlink', 'feature', 'is_common_path', 'configurable', 'hash', | ||
| 95 | - 'block', 'pkg_inner_softlink', 'chip' | ||
| 96 | - ]) | ||
| 97 | - | ||
| 98 | - | ||
| 99 | -def get_soft_links_not_in_common_paths(filelist: FileList, target_env: str) -> Iterator[List[str]]: | ||
| 100 | - for file_item_t in filelist: | ||
| @@ -1,218 +0,0 @@ | |||
| 1 | -#!/usr/bin/env python3 | ||
| 2 | -# -*- coding: UTF-8 -*- | ||
| 3 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 4 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 5 | -# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 6 | -# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 7 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 8 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 9 | -# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 10 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 11 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 12 | - | ||
| 13 | -import os | ||
| 14 | -import shutil | ||
| 15 | -import subprocess | ||
| 16 | -from argparse import Namespace | ||
| 17 | -from itertools import chain | ||
| 18 | -from subprocess import PIPE, STDOUT | ||
| 19 | -from typing import Callable, Dict, List, NamedTuple, Optional, Tuple, Union | ||
| 20 | - | ||
| 21 | -from .utils.comm_log import CommLog | ||
| 22 | -from .utils.pkg_utils import CompressError | ||
| 23 | - | ||
| 24 | - | ||
| 25 | -class PackageName: | ||
| 26 | - """包名。""" | ||
| 27 | - | ||
| 28 | - def __init__(self, | ||
| 29 | - package_attr, | ||
| 30 | - args: Namespace, | ||
| 31 | - version: str): | ||
| 32 | - self.product_name = package_attr.get('product_name') | ||
| 33 | - self.chip_name = args.chip_name or package_attr.get('chip_name') | ||
| 34 | - self.suffix = args.suffix or package_attr.get('suffix') | ||
| 35 | - self.func_name = get_func_name(args.func_name, package_attr) | ||
| 36 | - self.chip_plat = package_attr.get('chip_plat') | ||
| 37 | - self.deploy_type = package_attr.get('deploy_type') | ||
| 38 | - self.version = version.lower() | ||
| 39 | - self.not_in_name_list = args.not_in_name.split(",") | ||
| 40 | - self.os_arch = args.os_arch | ||
| 41 | - self.package_suffix = args.package_suffix | ||
| 42 | - self.ext_name = args.ext_name | ||
| 43 | - if args.pkg_name_style == 'underline': | ||
| 44 | - self.name_sep = '_' | ||
| 45 | - else: | ||
| 46 | - self.name_sep = '-' | ||
| 47 | - | ||
| 48 | - def get_attribute(self, name: str) -> Optional[str]: | ||
| 49 | - """获取属性。""" | ||
| 50 | - if name in self.not_in_name_list: | ||
| 51 | - return None | ||
| 52 | - return getattr(self, name) | ||
| 53 | - | ||
| 54 | - def getvalue(self) -> str: | ||
| 55 | - product_name = self.get_attribute('product_name') | ||
| 56 | - chip_name = self.get_attribute('chip_name') | ||
| 57 | - func_name = self.get_attribute('func_name') | ||
| 58 | - version = self.get_attribute('version') | ||
| 59 | - os_arch = self.get_attribute('os_arch') | ||
| 60 | - chip_plat = self.get_attribute('chip_plat') | ||
| 61 | - deploy_type = self.get_attribute('deploy_type') | ||
| 62 | - ext_name = self.get_attribute('ext_name') | ||
| 63 | - package_suffix = "debug" if self.package_suffix == "debug" else None | ||
| 64 | - | ||
| 65 | - region1 = "-".join(filter(None, [product_name, remove_ascend(chip_name), func_name])) | ||
| 66 | - region2 = ".".join(filter(None, [version])) | ||
| 67 | - region3 = "-".join(filter(None, [os_arch, chip_plat, deploy_type, package_suffix, ext_name])) | ||
| 68 | - package_name = "_".join(filter(None, [region1, region2, region3])) | ||
| 69 | - | ||
| 70 | - return f"{package_name}.{self.suffix}" | ||
| 71 | - | ||
| 72 | - | ||
| 73 | -class MakeselfPkgParams(NamedTuple): | ||
| 74 | - """run包打包参数。""" | ||
| 75 | - package_name: str | ||
| 76 | - comments: str | ||
| 77 | - makeself_tool: Optional[str] = None | ||
| 78 | - makeself_header: Optional[str] = None | ||
| 79 | - help_info: Optional[str] = None | ||
| 80 | - source_target: Optional[str] = None | ||
| 81 | - | ||
| 82 | - install_script: Optional[str] = None | ||
| 83 | - independent_pkg: Optional[bool] = False | ||
| 84 | - cleanup: Optional[str] = None | ||
| 85 | - | ||
| 86 | - | ||
| 87 | -def remove_ascend(text): | ||
| 88 | - if text is None: | ||
| 89 | - return None | ||
| 90 | - text_lower = text.lower() | ||
| 91 | - if "ascend" in text_lower: | ||
| 92 | - return text_lower.replace("ascend", "") | ||
| 93 | - return text_lower | ||
| 94 | - | ||
| 95 | - | ||
| 96 | -def get_func_name(func_name: str, package_attr) -> str: | ||
| 97 | - """获取包func_name。""" | ||
| 98 | - return func_name or package_attr.get('func_name') | ||
| 99 | - | ||
| 100 | - | ||
| 101 | -def get_compress_tool() -> str: | ||
| 102 | - tools = ["pigz", "gzip", "bzip2", "xz"] | ||
| 103 | - for tool in tools: | ||
| 104 | - path = shutil.which(tool) | ||
| 105 | - if path: | ||
| 106 | - return "--" + tool | ||
| 107 | - CommLog.cilog_error("The system does not come with a compression tool pre-installed." | ||
| 108 | - "Please ensure at least one of the folllowing compression tools is available: %s", tools) | ||
| 109 | - return "" | ||
| 110 | - | ||
| 111 | - | ||
| 112 | -def get_compress_format() -> str: | ||
| 113 | - tar_format = "gnu" | ||
| 114 | - path = shutil.which("bsdtar") | ||
| 115 | - if path: | ||
| 116 | - tar_format = "ustar" | ||
| 117 | - return tar_format | ||
| 118 | - | ||
| 119 | - | ||
| 120 | -def compose_makeself_command(params: MakeselfPkgParams) -> str: | ||
| 121 | - """组装makeself包打包命令。""" | ||
| 122 | - | ||
| 123 | - def get_cleanup_commands() -> List[str]: | ||
| 124 | - if params.cleanup: | ||
| 125 | - return ['--cleanup', params.cleanup] | ||
| 126 | - return [] | ||
| 127 | - independent_pkg = params.independent_pkg | ||
| 128 | - compress_tool = get_compress_tool() | ||
| 129 | - tar_format = get_compress_format() | ||
| 130 | - if independent_pkg: | ||
| 131 | - commands = chain( | ||
| 132 | - [ | ||
| 133 | - 'TMPDIR=$PWD', params.makeself_tool, "--header", params.makeself_header, | ||
| 134 | - "--help-header", params.help_info, compress_tool, '--complevel', '4', | ||
| 135 | - '--nomd5', '--sha256', '--nooverwrite', '--chown', '--tar-format', tar_format, | ||
| 136 | - '--tar-extra', '--numeric-owner', '--tar-quietly' | ||
| 137 | - ], | ||
| 138 | - get_cleanup_commands(), | ||
| 139 | - [params.source_target, params.package_name, params.comments, params.install_script] | ||
| 140 | - ) | ||
| 141 | - else: | ||
| 142 | - commands = chain( | ||
| 143 | - [ | ||
| 144 | - compress_tool, '--complevel', '4', | ||
| 145 | - '--nomd5', '--sha256', '--nooverwrite', '--chown', '--tar-format', tar_format, | ||
| 146 | - '--tar-extra', '--numeric-owner', '--tar-quietly' | ||
| 147 | - ], | ||
| 148 | - get_cleanup_commands(), | ||
| 149 | - [params.package_name, params.comments] | ||
| 150 | - ) | ||
| 151 | - | ||
| 152 | - command = ' '.join(commands) | ||
| 153 | - return command | ||
| 154 | - | ||
| 155 | - | ||
| 156 | -def create_makeself_pkg_params_factory(source_target: str, | ||
| 157 | - package_name: str, | ||
| 158 | - comments: str | ||
| 159 | - ) -> Callable[[str, dict, bool], MakeselfPkgParams]: | ||
| 160 | - """创建Makeself打包参数工厂。""" | ||
| 161 | - | ||
| 162 | - def create_makeself_pkg_params(makeself_dir: str, | ||
| 163 | - package_attr: Dict, | ||
| 164 | - independent_pkg=False) -> MakeselfPkgParams: | ||
| 165 | - """创建Makeself打包参数。""" | ||
| 166 | - cleanup = package_attr.get('cleanup') | ||
| 167 | - | ||
| 168 | - if independent_pkg: | ||
| 169 | - install_script = str(package_attr.get('install_script')) | ||
| 170 | - help_info = str(package_attr.get('help')) | ||
| 171 | - makeself_tool = os.path.join(makeself_dir, 'makeself.sh') | ||
| 172 | - makeself_header = os.path.join(makeself_dir, 'makeself-header.sh') | ||
| 173 | - params = MakeselfPkgParams( | ||
| 174 | - package_name=package_name, | ||
| 175 | - comments=comments, | ||
| 176 | - makeself_tool=makeself_tool, | ||
| 177 | - makeself_header=makeself_header, | ||
| 178 | - help_info=help_info, | ||
| 179 | - source_target=source_target, | ||
| 180 | - | ||
| 181 | - install_script=install_script, | ||
| 182 | - independent_pkg=independent_pkg, | ||
| 183 | - cleanup=cleanup, | ||
| 184 | - ) | ||
| 185 | - else: | ||
| 186 | - params = MakeselfPkgParams( | ||
| 187 | - package_name=package_name, | ||
| 188 | - comments=comments, | ||
| 189 | - cleanup=cleanup, | ||
| 190 | - ) | ||
| 191 | - return params | ||
| 192 | - return create_makeself_pkg_params | ||
| 193 | - | ||
| 194 | - | ||
| 195 | -def create_run_package_command(params: MakeselfPkgParams | ||
| 196 | - ) -> Tuple[Optional[str], Optional[str]]: | ||
| 197 | - """ | ||
| 198 | - 功能描述: 组装打run包命令 | ||
| 199 | - 返回值: command | ||
| 200 | - """ | ||
| 201 | - return compose_makeself_command(params), None | ||
| 202 | - | ||
| 203 | - | ||
| 204 | -def exec_pack_cmd(delivery_dir: str, | ||
| 205 | - pack_cmd: str, | ||
| 206 | - package_name: str) -> str: | ||
| 207 | - """执行打包命令""" | ||
| 208 | - if delivery_dir: | ||
| 209 | - cmd = f'cd {delivery_dir} && {pack_cmd}' | ||
| 210 | - else: | ||
| 211 | - cmd = pack_cmd | ||
| 212 | - CommLog.cilog_info("package cmd:%s", cmd) | ||
| 213 | - result = subprocess.run(cmd, shell=True, check=False, stdout=PIPE, stderr=STDOUT) | ||
| 214 | - output = result.stdout.decode() | ||
| 215 | - if result.returncode != 0: | ||
| 216 | - CommLog.cilog_error(__file__, "compress package(%s) failed! %s.", package_name, output) | ||
| 217 | - raise CompressError(package_name) | ||
| 218 | - return package_name | ||
| @@ -1,63 +0,0 @@ | |||
| 1 | -#!/usr/bin/env python3 | ||
| 2 | -# -*- coding: UTF-8 -*- | ||
| 3 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 4 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 5 | -# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 6 | -# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 7 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 8 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 9 | -# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 10 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 11 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 12 | - | ||
| 13 | -import time | ||
| 14 | -import inspect | ||
| 15 | -import logging | ||
| 16 | - | ||
| 17 | -logging.basicConfig(format='[%(asctime)s] [%(levelname)s] [%(pathname)s] [line:%(lineno)d] %(message)s', | ||
| 18 | - level=logging.INFO) | ||
| 19 | - | ||
| 20 | - | ||
| 21 | -class CommLog: | ||
| 22 | - @staticmethod | ||
| 23 | - def cilog_get_timestamp(): | ||
| 24 | - return time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()) | ||
| 25 | - | ||
| 26 | - @staticmethod | ||
| 27 | - def cilog_print_element(cilog_element): | ||
| 28 | - print("["+cilog_element+"]", end=' ') | ||
| 29 | - return | ||
| 30 | - | ||
| 31 | - @staticmethod | ||
| 32 | - def cilog_logmsg(log_level, filename, line_no, log_msg, *log_paras): | ||
| 33 | - log_timestamp = CommLog.cilog_get_timestamp() | ||
| 34 | - CommLog.cilog_print_element(log_timestamp) | ||
| 35 | - CommLog.cilog_print_element(log_level) | ||
| 36 | - CommLog.cilog_print_element(filename) | ||
| 37 | - CommLog.cilog_print_element(str(line_no)) | ||
| 38 | - print(log_msg % log_paras[0]) | ||
| 39 | - return | ||
| 40 | - | ||
| 41 | - @staticmethod | ||
| 42 | - def cilog_error(log_msg, *log_paras): | ||
| 43 | - frame = inspect.currentframe().f_back | ||
| 44 | - line_no = frame.f_lineno | ||
| 45 | - filename = frame.f_code.co_filename | ||
| 46 | - CommLog.cilog_logmsg("ERROR", filename, line_no, log_msg, log_paras) | ||
| 47 | - return | ||
| 48 | - | ||
| 49 | - @staticmethod | ||
| 50 | - def cilog_warning(log_msg, *log_paras): | ||
| 51 | - frame = inspect.currentframe().f_back | ||
| 52 | - line_no = frame.f_lineno | ||
| 53 | - filename = frame.f_code.co_filename | ||
| 54 | - CommLog.cilog_logmsg("WARNING", filename, line_no, log_msg, log_paras) | ||
| 55 | - return | ||
| 56 | - | ||
| 57 | - @staticmethod | ||
| 58 | - def cilog_info(log_msg, *log_paras): | ||
| 59 | - frame = inspect.currentframe().f_back | ||
| 60 | - line_no = frame.f_lineno | ||
| 61 | - filename = frame.f_code.co_filename | ||
| 62 | - CommLog.cilog_logmsg("INFO", filename, line_no, log_msg, log_paras) | ||
| 63 | - return | ||
| @@ -1,89 +0,0 @@ | |||
| 1 | -#!/usr/bin/env python3 | ||
| 2 | -# -*- coding: UTF-8 -*- | ||
| 3 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 4 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 5 | -# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 6 | -# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 7 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 8 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 9 | -# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 10 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 11 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 12 | - | ||
| 13 | -"""函数基础库。""" | ||
| 14 | - | ||
| 15 | -import operator | ||
| 16 | -from typing import Callable, Iterator, TypeVar | ||
| 17 | - | ||
| 18 | - | ||
| 19 | -A = TypeVar('A') | ||
| 20 | - | ||
| 21 | - | ||
| 22 | -def constant(value: A) -> Callable[..., A]: | ||
| 23 | - """常量值。""" | ||
| 24 | - def constant_inner(*_args, **_kwargs) -> A: | ||
| 25 | - return value | ||
| 26 | - | ||
| 27 | - return constant_inner | ||
| 28 | - | ||
| 29 | - | ||
| 30 | -def dispatch(*funcs): | ||
| 31 | - """分派应用。""" | ||
| 32 | - def dispatch_inner(*args, **kwargs) -> Iterator: | ||
| 33 | - return (func(*args, **kwargs) for func in funcs) | ||
| 34 | - | ||
| 35 | - return dispatch_inner | ||
| 36 | - | ||
| 37 | - | ||
| 38 | -def pipe(*funcs): | ||
| 39 | - """串联多个函数。""" | ||
| 40 | - def pipe_func(*args, **k_args): | ||
| 41 | - result = funcs[0](*args, **k_args) | ||
| 42 | - for func in funcs[1:]: | ||
| 43 | - result = func(result) | ||
| 44 | - return result | ||
| 45 | - | ||
| 46 | - return pipe_func | ||
| 47 | - | ||
| 48 | - | ||
| 49 | -def identity(value: A) -> A: | ||
| 50 | - """同一。""" | ||
| 51 | - return value | ||
| 52 | - | ||
| 53 | - | ||
| 54 | -def invoke(func, *args, **kwargs): | ||
| 55 | - """调用。""" | ||
| 56 | - return func(*args, **kwargs) | ||
| 57 | - | ||
| 58 | - | ||
| 59 | -def side_effect(*funcs): | ||
| 60 | - """调用函数,产生副作用,但不影响管道结果。""" | ||
| 61 | - def side_effect_func(arg): | ||
| 62 | - for func in funcs: | ||
| 63 | - # 不保留结果 | ||
| 64 | - func(arg) | ||
| 65 | - return arg | ||
| 66 | - | ||
| 67 | - return side_effect_func | ||
| 68 | - | ||
| 69 | - | ||
| 70 | -def star_apply(func): | ||
| 71 | - """列表展开再应用。""" | ||
| 72 | - def star_apply_func(arg): | ||
| 73 | - return func(*arg) | ||
| 74 | - | ||
| 75 | - return star_apply_func | ||
| 76 | - | ||
| 77 | - | ||
| 78 | -def any_(*funcs) -> Callable: | ||
| 79 | - """高阶any。 | ||
| 80 | - 注意,any有短路效果。""" | ||
| 81 | - return pipe( | ||
| 82 | - dispatch(*funcs), | ||
| 83 | - any, | ||
| 84 | - ) | ||
| 85 | - | ||
| 86 | - | ||
| 87 | -def not_(func) -> Callable: | ||
| 88 | - """高阶not。""" | ||
| 89 | - return pipe(func, operator.not_) | ||
| @@ -1,202 +0,0 @@ | |||
| 1 | -#!/usr/bin/env python3 | ||
| 2 | -# -*- coding: UTF-8 -*- | ||
| 3 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 4 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 5 | -# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 6 | -# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 7 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 8 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 9 | -# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 10 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 11 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 12 | - | ||
| 13 | -"""基础构件。""" | ||
| 14 | - | ||
| 15 | -import os | ||
| 16 | -from functools import partial | ||
| 17 | -from itertools import chain, tee | ||
| 18 | -from operator import methodcaller | ||
| 19 | -from pathlib import Path | ||
| 20 | -from typing import Callable, Dict, Iterator, List, Optional, TypeVar, Set | ||
| 21 | - | ||
| 22 | -TOP_DIR = str(Path(__file__).resolve().parents[5]) | ||
| 23 | -TOP_SOURCE_DIR = TOP_DIR + '/scripts/' | ||
| 24 | -DELIVERY_PATH = "build/_CPack_Packages/makeself_staging" | ||
| 25 | -CONFIG_SCRIPT_PATH = 'package' | ||
| 26 | -BLOCK_CONFIG_PATH = 'package/module' | ||
| 27 | - | ||
| 28 | -SUCC = 0 | ||
| 29 | -FAIL = -1 | ||
| 30 | - | ||
| 31 | - | ||
| 32 | -A = TypeVar('A') | ||
| 33 | - | ||
| 34 | - | ||
| 35 | -class PackageError(Exception): | ||
| 36 | - """打包异常基类。""" | ||
| 37 | - | ||
| 38 | - | ||
| 39 | -class PackageConfigError(PackageError): | ||
| 40 | - """打包配置错误异常。""" | ||
| 41 | - | ||
| 42 | - | ||
| 43 | -class BlockConfigError(PackageError): | ||
| 44 | - """块配置错误异常。""" | ||
| 45 | - | ||
| 46 | - | ||
| 47 | -class MultiPkgModError(PackageError): | ||
| 48 | - """多个pkg_mod元素报错。""" | ||
| 49 | - | ||
| 50 | - | ||
| 51 | -class MultiPkgSoftlinkError(PackageError): | ||
| 52 | - """多个pkg_softlink元素报错。""" | ||
| 53 | - | ||
| 54 | - | ||
| 55 | -class ParseOsArchError(PackageError): | ||
| 56 | - """解析os_arch失败异常。""" | ||
| 57 | - | ||
| 58 | - | ||
| 59 | -class EnvNotSupported(PackageError): | ||
| 60 | - """环境变量不支持异常。""" | ||
| 61 | - | ||
| 62 | - | ||
| 63 | -class ContainAsteriskError(PackageError): | ||
| 64 | - """包含星号异常。""" | ||
| 65 | - | ||
| 66 | - def __init__(self, value: str): | ||
| 67 | - super().__init__() | ||
| 68 | - self.value = value | ||
| 69 | - | ||
| 70 | - | ||
| 71 | -class FilelistError(PackageError): | ||
| 72 | - """文件列表异常。""" | ||
| 73 | - | ||
| 74 | - | ||
| 75 | -class UnknownOperateTypeError(PackageError): | ||
| 76 | - """未知的操作类型。""" | ||
| 77 | - | ||
| 78 | - | ||
| 79 | -class PkgInnerSoftlinkNotAllowed(PackageError): | ||
| 80 | - """不允许使用pkg_inner_softlink。""" | ||
| 81 | - | ||
| 82 | - | ||
| 83 | -class PackageNameEmptyError(PackageError): | ||
| 84 | - """包名为空错误。""" | ||
| 85 | - | ||
| 86 | - | ||
| 87 | -class GenerateFilelistError(PackageError): | ||
| 88 | - """生成文件列表文件异常。""" | ||
| 89 | - | ||
| 90 | - def __init__(self, filename: str): | ||
| 91 | - super().__init__() | ||
| 92 | - self.filename = filename | ||
| 93 | - | ||
| 94 | - | ||
| 95 | -class IllegalVersionDir(PackageError): | ||
| 96 | - """version_dir配置错误。""" | ||
| 97 | - | ||
| 98 | - | ||
| 99 | -class CompressError(PackageError): | ||
| 100 | - """打包错误。""" | ||
| 101 | - | ||
| 102 | - def __init__(self, package_name: Optional[str]): | ||
| 103 | - super().__init__(package_name) | ||
| 104 | - self.package_name = package_name | ||
| 105 | - | ||
| 106 | - | ||
| 107 | -class InstallScriptNotInPackageInfo(PackageError): | ||
| 108 | - """package_info中没有配置install_script。""" | ||
| 109 | - | ||
| 110 | - | ||
| 111 | -class InstallScriptFormatError(PackageError): | ||
| 112 | - """install_script配置格式错误。""" | ||
| 113 | - | ||
| 114 | - | ||
| 115 | -class VersionInfoNotExist(PackageError): | ||
| 116 | - """version.info文件不存在。""" | ||
| 117 | - | ||
| 118 | - | ||
| 119 | -def flatten(list_of_lists): | ||
| 120 | - """Flatten one level of nesting""" | ||
| 121 | - return chain.from_iterable(list_of_lists) | ||
| 122 | - | ||
| 123 | - | ||
| 124 | -def merge_dict(base: Dict, *news: Dict): | ||
| 125 | - """合并两个字典。""" | ||
| 126 | - result = base.copy() | ||
| 127 | - for new in news: | ||
| 128 | - result.update(new) | ||
| 129 | - return result | ||
| 130 | - | ||
| 131 | - | ||
| 132 | -def star_pipe(*funcs): | ||
| 133 | - """串联多个函数。解包结果。""" | ||
| 134 | - def pipe_func(*args, **k_args): | ||
| 135 | - result = funcs[0](*args, **k_args) | ||
| 136 | - for func in funcs[1:]: | ||
| 137 | - # 解包元组或列表结果 | ||
| 138 | - result = func(*result) | ||
| 139 | - return result | ||
| 140 | - | ||
| 141 | - return pipe_func | ||
| 142 | - | ||
| 143 | - | ||
| 144 | -def swap_args(func): | ||
| 145 | - """交换函数前两个参数。""" | ||
| 146 | - def inner(fst, snd, *args, **k_args): | ||
| 147 | - return func(snd, fst, *args, **k_args) | ||
| 148 | - return inner | ||
| 149 | - | ||
| 150 | - | ||
| 151 | -def conditional_apply(predicate, func): | ||
| 152 | - """条件下应用函数。""" | ||
| 153 | - def conditional_apply_func(arg): | ||
| 154 | - if predicate(arg): | ||
| 155 | - return func(arg) | ||
| 156 | - return arg | ||
| 157 | - | ||
| 158 | - return conditional_apply_func | ||
| 159 | - | ||
| 160 | - | ||
| 161 | -def pairwise(iterable): | ||
| 162 | - """s -> (s0,s1), (s1,s2), (s2, s3), ...""" | ||
| 163 | - a, b = tee(iterable) | ||
| 164 | - next(b, None) | ||
| 165 | - return zip(a, b) | ||
| 166 | - | ||
| 167 | - | ||
| 168 | -def path_join(base: Optional, *others: str) -> Optional: | ||
| 169 | - """路径联合。""" | ||
| 170 | - if base is None: | ||
| 171 | - return None | ||
| 172 | - return os.path.join(base, *others) | ||
| 173 | - | ||
| 174 | - | ||
| 175 | -def yield_if(data, predicate: Callable) -> Iterator: | ||
| 176 | - """条件满足则产生。""" | ||
| 177 | - if predicate(data): | ||
| 178 | - yield data | ||
| 179 | - | ||
| 180 | - | ||
| 181 | -def config_feature_to_set(feature_str: str, feature_type: str = 'feature') -> Set[str]: | ||
| 182 | - """配置feature转换为集合。""" | ||
| 183 | - if feature_str is None: | ||
| 184 | - return set() | ||
| 185 | - | ||
| 186 | - if isinstance(feature_str, set): | ||
| 187 | - return feature_str | ||
| 188 | - | ||
| 189 | - if feature_str == '': | ||
| 190 | - raise PackageConfigError(f"Not allow to config {feature_type} empty.") | ||
| 191 | - | ||
| 192 | - features = set(feature_str.split(';')) | ||
| 193 | - if 'all' in features: | ||
| 194 | - raise PackageConfigError(f"Not allow to config {feature_type} all.") | ||
| 195 | - return features | ||
| 196 | - | ||
| 197 | - | ||
| 198 | -def config_feature_to_string(features: Set[str]) -> str: | ||
| 199 | - """配置feature集合转换为字符串。""" | ||
| 200 | - if not features: | ||
| 201 | - return 'all' | ||
| 202 | - return ';'.join(sorted(features)) | ||
| @@ -1,432 +0,0 @@ | |||
| 1 | -#!/usr/bin/env python3 | ||
| 2 | -# -*- coding: UTF-8 -*- | ||
| 3 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 4 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 5 | -# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 6 | -# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 7 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 8 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 9 | -# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 10 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 11 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 12 | - | ||
| 13 | -import os | ||
| 14 | -import re | ||
| 15 | -import sys | ||
| 16 | -import xml.etree.ElementTree as ET | ||
| 17 | -from functools import total_ordering | ||
| 18 | -from pathlib import Path | ||
| 19 | -from typing import Dict, List, NamedTuple, Optional, Tuple, Union | ||
| 20 | -from .utils.comm_log import CommLog | ||
| 21 | - | ||
| 22 | - | ||
| 23 | -class VersionInfoError(Exception): | ||
| 24 | - """版本信息异常基类。""" | ||
| 25 | - | ||
| 26 | - | ||
| 27 | -class VersionFormatNotMatch(VersionInfoError): | ||
| 28 | - """版本格式未匹配。""" | ||
| 29 | - | ||
| 30 | - | ||
| 31 | -class IntervalFormatNotMatch(VersionInfoError): | ||
| 32 | - """区间格式未匹配。""" | ||
| 33 | - | ||
| 34 | - | ||
| 35 | -class DuplicatedPkgConfig(VersionInfoError): | ||
| 36 | - """解析版本配置失败。重复的包配置。""" | ||
| 37 | - | ||
| 38 | - def __init__(self, pkg_name): | ||
| 39 | - super().__init__(pkg_name) | ||
| 40 | - self.pkg_name = pkg_name | ||
| 41 | - | ||
| 42 | - | ||
| 43 | -class ParseVersionFailed(VersionInfoError): | ||
| 44 | - """解析版本失败。""" | ||
| 45 | - | ||
| 46 | - | ||
| 47 | -class CollectRequiresFailed(VersionInfoError): | ||
| 48 | - """收集包需求失败。""" | ||
| 49 | - | ||
| 50 | - def __init__(self, pkg_name, version_str, msg): | ||
| 51 | - super().__init__(pkg_name, version_str, msg) | ||
| 52 | - self.pkg_name = pkg_name | ||
| 53 | - self.version_str = version_str | ||
| 54 | - self.msg = msg | ||
| 55 | - | ||
| 56 | - | ||
| 57 | -@total_ordering | ||
| 58 | -class Version: | ||
| 59 | - """版本号。""" | ||
| 60 | - | ||
| 61 | - def __init__(self, version): | ||
| 62 | - self.version = version | ||
| 63 | - | ||
| 64 | - @classmethod | ||
| 65 | - def match(cls, input_str): | ||
| 66 | - """输入字符串是否匹配版本号模式。""" | ||
| 67 | - m = re.match(r'[.a-zA-Z0-9]+$', input_str) | ||
| 68 | - return bool(m) | ||
| 69 | - | ||
| 70 | - @classmethod | ||
| 71 | - def parse(cls, input_str): | ||
| 72 | - """解析版本号。""" | ||
| 73 | - if not cls.match(input_str): | ||
| 74 | - raise VersionFormatNotMatch() | ||
| 75 | - | ||
| 76 | - return cls(input_str) | ||
| 77 | - | ||
| 78 | - @classmethod | ||
| 79 | - def try_convert_to_int_list(cls, str_list): | ||
| 80 | - """尝试转换为int数组。""" | ||
| 81 | - for idx, item in enumerate(str_list): | ||
| 82 | - try: | ||
| 83 | - int_item = int(item) | ||
| 84 | - str_list[idx] = int_item | ||
| 85 | - except ValueError: | ||
| 86 | - pass | ||
| 87 | - | ||
| 88 | - def to_required_list(self): | ||
| 89 | - """转换为版本需求字符串列表。""" | ||
| 90 | - return [self.version] | ||
| 91 | - | ||
| 92 | - def __eq__(self, other): | ||
| 93 | - """等于。""" | ||
| 94 | - if not isinstance(other, self.__class__): | ||
| 95 | - return False | ||
| 96 | - return self.version == other.version | ||
| 97 | - | ||
| 98 | - def __lt__(self, other): | ||
| 99 | - """小于。""" | ||
| 100 | - if not isinstance(other, self.__class__): | ||
| 101 | - return True | ||
| 102 | - | ||
| 103 | - self_list = self.version.split('.') | ||
| 104 | - other_list = other.version.split('.') | ||
| 105 | - | ||
| 106 | - self.try_convert_to_int_list(self_list) | ||
| 107 | - self.try_convert_to_int_list(other_list) | ||
| 108 | - | ||
| 109 | - self_tuple = tuple(self_list) | ||
| 110 | - other_tuple = tuple(other_list) | ||
| 111 | - | ||
| 112 | - return self_tuple < other_tuple | ||
| 113 | - | ||
| 114 | - def __str__(self): | ||
| 115 | - return self.version | ||
| 116 | - | ||
| 117 | - def __repr__(self): | ||
| 118 | - return repr(self.version) | ||
| 119 | - | ||
| 120 | - | ||
| 121 | -class Point(NamedTuple): | ||
| 122 | - """区间端点。""" | ||
| 123 | - type_: int # 类型,0为闭区间,1为开区间 | ||
| 124 | - value: Version | ||
| 125 | - | ||
| 126 | - | ||
| 127 | -class Interval(NamedTuple): | ||
| 128 | - """版本号区间。""" | ||
| 129 | - low: Point | ||
| 130 | - high: Point | ||
| 131 | - | ||
| 132 | - @classmethod | ||
| 133 | - def match(cls, input_str: str) -> bool: | ||
| 134 | - """输入字符串是否匹配区间模式。""" | ||
| 135 | - if not input_str.startswith('(') and not input_str.startswith('['): | ||
| 136 | - return False | ||
| 137 | - if not input_str.endswith(')') and not input_str.endswith(']'): | ||
| 138 | - return False | ||
| 139 | - input_str = input_str[1:-1] | ||
| 140 | - if input_str.count(',') > 1: | ||
| 141 | - return False | ||
| 142 | - return True | ||
| 143 | - | ||
| 144 | - @classmethod | ||
| 145 | - def parse(cls, input_str): | ||
| 146 | - """解析版本号区间。""" | ||
| 147 | - if not cls.match(input_str): | ||
| 148 | - raise IntervalFormatNotMatch() | ||
| 149 | - | ||
| 150 | - if input_str[0] == '[': | ||
| 151 | - low_type = 0 | ||
| 152 | - elif input_str[0] == '(': | ||
| 153 | - low_type = 1 | ||
| 154 | - else: | ||
| 155 | - assert False, 'should not go here.' | ||
| 156 | - | ||
| 157 | - if input_str[-1] == ']': | ||
| 158 | - high_type = 0 | ||
| 159 | - elif input_str[-1] == ')': | ||
| 160 | - high_type = 1 | ||
| 161 | - else: | ||
| 162 | - assert False, 'should not go here.' | ||
| 163 | - | ||
| 164 | - input_str = input_str[1:-1] | ||
| 165 | - input_list = input_str.split(',') | ||
| 166 | - low = input_list[0].strip() | ||
| 167 | - if len(input_list) > 1: | ||
| 168 | - high = input_list[1].strip() | ||
| 169 | - else: | ||
| 170 | - high = None | ||
| 171 | - | ||
| 172 | - if low: | ||
| 173 | - low_version = Point(low_type, Version(low)) | ||
| 174 | - else: | ||
| 175 | - low_version = None | ||
| 176 | - | ||
| 177 | - if high: | ||
| 178 | - high_version = Point(high_type, Version(high)) | ||
| 179 | - else: | ||
| 180 | - high_version = None | ||
| 181 | - | ||
| 182 | - return cls(low=low_version, high=high_version) | ||
| 183 | - | ||
| 184 | - def to_required_list(self): | ||
| 185 | - """转换为版本需求字符串列表。""" | ||
| 186 | - result = [] | ||
| 187 | - | ||
| 188 | - if self.low: | ||
| 189 | - if self.low.type_ == 0: | ||
| 190 | - operator = '>=' | ||
| 191 | - else: | ||
| 192 | - operator = '>' | ||
| 193 | - required_str = '{0}{1}'.format(operator, self.low.value.version) | ||
| 194 | - result.append(required_str) | ||
| 195 | - | ||
| 196 | - if self.high: | ||
| 197 | - if self.high.type_ == 0: | ||
| 198 | - operator = '<=' | ||
| 199 | - else: | ||
| 200 | - operator = '<' | ||
| 201 | - required_str = '{0}{1}'.format(operator, self.high.value.version) | ||
| 202 | - result.append(required_str) | ||
| 203 | - | ||
| 204 | - return result | ||
| 205 | - | ||
| 206 | - | ||
| 207 | -class Require(NamedTuple): | ||
| 208 | - """包需求。""" | ||
| 209 | - pkg_name: str | ||
| 210 | - versions: List | ||
| 211 | - | ||
| 212 | - @classmethod | ||
| 213 | - def _sort_key(cls, item) -> Tuple: | ||
| 214 | - """排序键。""" | ||
| 215 | - if isinstance(item, Interval): | ||
| 216 | - # 如果存在区间左值,则左值参与排序。 | ||
| 217 | - if item.low: | ||
| 218 | - return item.low.value, item.low.type_ | ||
| 219 | - # 否则使用区间右值,由于开区间更小,所以type_取负。 | ||
| 220 | - return item.high.value, -item.high.type_ | ||
| 221 | - | ||
| 222 | - return item, 0 | ||
| 223 | - | ||
| 224 | - @classmethod | ||
| 225 | - def _sort_versions(cls, versions: List) -> bool: | ||
| 226 | - """排序版本序列。""" | ||
| 227 | - versions.sort(key=cls._sort_key) | ||
| 228 | - return True | ||
| 229 | - | ||
| 230 | - @classmethod | ||
| 231 | - def _to_required_list(cls, versions: List) -> List[str]: | ||
| 232 | - """转换为版本需求字符串列表。""" | ||
| 233 | - result = [] | ||
| 234 | - for version in versions: | ||
| 235 | - requires = version.to_required_list() | ||
| 236 | - result.extend(requires) | ||
| 237 | - | ||
| 238 | - return result | ||
| 239 | - | ||
| 240 | - @classmethod | ||
| 241 | - def _to_required_str(cls, versions: List) -> str: | ||
| 242 | - """转换为版本需求字符串。""" | ||
| 243 | - requires = cls._to_required_list(versions) | ||
| 244 | - required_str = ', '.join(requires) | ||
| 245 | - | ||
| 246 | - return required_str | ||
| 247 | - | ||
| 248 | - def sort_versions(self) -> bool: | ||
| 249 | - """排序版本序列。""" | ||
| 250 | - return self._sort_versions(self.versions) | ||
| 251 | - | ||
| 252 | - def to_required_full_str(self) -> str: | ||
| 253 | - """转换为版本需求字符串。""" | ||
| 254 | - required_str = self._to_required_str(self.versions) | ||
| 255 | - required_full_str = 'required_package_{0}_version="{1}"'.format(self.pkg_name, required_str) | ||
| 256 | - return required_full_str | ||
| 257 | - | ||
| 258 | - | ||
| 259 | -class ItemElement(NamedTuple): | ||
| 260 | - """item元素。""" | ||
| 261 | - name: str | ||
| 262 | - version: str | ||
| 263 | - | ||
| 264 | - @classmethod | ||
| 265 | - def parse(cls, item_ele: ET.Element, cur_ver: str): | ||
| 266 | - """解析item元素。""" | ||
| 267 | - name = item_ele.attrib['name'] | ||
| 268 | - version = item_ele.attrib['version'].replace("$(CUR_VER)", cur_ver) | ||
| 269 | - return cls(name=name, version=version) | ||
| 270 | - | ||
| 271 | - @classmethod | ||
| 272 | - def skip(cls, item_ele: ET.Element): | ||
| 273 | - """是否跳过item元素。""" | ||
| 274 | - version = item_ele.attrib['version'] | ||
| 275 | - return version.strip() == '' | ||
| 276 | - | ||
| 277 | - | ||
| 278 | -class CompatibleElement(NamedTuple): | ||
| 279 | - """compatible元素。""" | ||
| 280 | - items: List | ||
| 281 | - | ||
| 282 | - @classmethod | ||
| 283 | - def parse(cls, compatible_ele: ET.Element, cur_ver: str): | ||
| 284 | - """解析compatible元素。""" | ||
| 285 | - items = [] | ||
| 286 | - for item_ele in compatible_ele.findall("./item"): | ||
| 287 | - if ItemElement.skip(item_ele): | ||
| 288 | - continue | ||
| 289 | - item = ItemElement.parse(item_ele, cur_ver) | ||
| 290 | - items.append(item) | ||
| 291 | - return cls(items=items) | ||
| 292 | - | ||
| 293 | - | ||
| 294 | -def is_version_number(version: str) -> bool: | ||
| 295 | - """字符串是否为版本号。""" | ||
| 296 | - has_slash = '/' in version | ||
| 297 | - return not has_slash and len(version.split(".")) >= 3 | ||
| 298 | - | ||
| 299 | - | ||
| 300 | -class VersionXml(NamedTuple): | ||
| 301 | - """版本配置。""" | ||
| 302 | - release_version: str | ||
| 303 | - version_dir: str | ||
| 304 | - packages: Dict | ||
| 305 | - | ||
| 306 | - @classmethod | ||
| 307 | - def match(cls, filepath: Union[Path, str]) -> bool: | ||
| 308 | - """文件路径是否匹配版本信息文件。""" | ||
| 309 | - return str(filepath).endswith('.xml') | ||
| 310 | - | ||
| 311 | - @classmethod | ||
| 312 | - def parse_version(cls, version_str: str): | ||
| 313 | - """解析版本配置。""" | ||
| 314 | - ret = Interval.match(version_str) | ||
| 315 | - if ret: | ||
| 316 | - result = Interval.parse(version_str) | ||
| 317 | - return result | ||
| 318 | - | ||
| 319 | - ret = Version.match(version_str) | ||
| 320 | - if ret: | ||
| 321 | - result = Version.parse(version_str) | ||
| 322 | - return result | ||
| 323 | - | ||
| 324 | - raise ParseVersionFailed() | ||
| 325 | - | ||
| 326 | - def get_release_version(self): | ||
| 327 | - """获取发布版本号。""" | ||
| 328 | - return self.release_version | ||
| 329 | - | ||
| 330 | - def get_version_dir(self): | ||
| 331 | - """获取多版本目录。""" | ||
| 332 | - return self.version_dir | ||
| 333 | - | ||
| 334 | - def collect_requires(self, package: str) -> List[Require]: | ||
| 335 | - """收集对应包的包需求列表。""" | ||
| 336 | - requires = {} | ||
| 337 | - | ||
| 338 | - if package not in self.packages: | ||
| 339 | - return [] | ||
| 340 | - | ||
| 341 | - compatible = self.packages[package] | ||
| 342 | - | ||
| 343 | - for item in compatible.items: | ||
| 344 | - pkg_name = item.name | ||
| 345 | - if pkg_name not in requires: | ||
| 346 | - requires[pkg_name] = Require(pkg_name=pkg_name, versions=[]) | ||
| 347 | - | ||
| 348 | - version_str = item.version | ||
| 349 | - try: | ||
| 350 | - version = self.parse_version(version_str) | ||
| 351 | - except ParseVersionFailed as ex: | ||
| 352 | - msg = f'parse pkg {pkg_name} version {version_str} failed' | ||
| 353 | - raise CollectRequiresFailed(pkg_name, version_str, msg) from ex | ||
| 354 | - | ||
| 355 | - requires[pkg_name].versions.append(version) | ||
| 356 | - | ||
| 357 | - result = [] | ||
| 358 | - for pkg_name in sorted(requires.keys()): | ||
| 359 | - requires[pkg_name].sort_versions() | ||
| 360 | - result.append(requires[pkg_name]) | ||
| 361 | - | ||
| 362 | - return result | ||
| 363 | - | ||
| 364 | - | ||
| 365 | -def get_version_dir(version_xml: Optional[VersionXml], | ||
| 366 | - disable_multi_version: bool, | ||
| 367 | - version_dir: Optional[str]) -> Optional[str]: | ||
| 368 | - """获取版本目录名。""" | ||
| 369 | - if disable_multi_version: | ||
| 370 | - return None | ||
| 371 | - | ||
| 372 | - if version_dir: | ||
| 373 | - return version_dir | ||
| 374 | - | ||
| 375 | - # 支持从version.xml中获取version_dir | ||
| 376 | - if version_xml and version_xml.get_version_dir(): | ||
| 377 | - return version_xml.get_version_dir() | ||
| 378 | - | ||
| 379 | - return None | ||
| 380 | - | ||
| 381 | - | ||
| 382 | -def is_multi_version(version_dir: str) -> bool: | ||
| 383 | - """是否多版本。""" | ||
| 384 | - return bool(version_dir) | ||
| 385 | - | ||
| 386 | - | ||
| 387 | -class VersionInfo(NamedTuple): | ||
| 388 | - """版本信息。""" | ||
| 389 | - install_version_info: bool | ||
| 390 | - install_version_info_attrib: Optional[Dict[str, str]] | ||
| 391 | - itf_versions: List[str] | ||
| 392 | - version: str | ||
| 393 | - version_xml: Optional[VersionXml] | ||
| 394 | - timestamp: Optional[str] | ||
| 395 | - | ||
| 396 | - | ||
| 397 | -class VersionInfoFile(NamedTuple): | ||
| 398 | - """生成的版本配置。""" | ||
| 399 | - version: str | ||
| 400 | - itf_version_info: Optional[str] = None | ||
| 401 | - requires: Optional[List[Require]] = None | ||
| 402 | - version_dir: Optional[str] = None | ||
| 403 | - timestamp: Optional[str] = None | ||
| 404 | - | ||
| 405 | - def _get_content(self) -> str: | ||
| 406 | - """获取版本配置内容。""" | ||
| 407 | - lines = ['Version={0}'.format(self.version)] | ||
| 408 | - if self.version_dir: | ||
| 409 | - lines.append('version_dir={0}'.format(self.version_dir)) | ||
| 410 | - if self.timestamp: | ||
| 411 | - lines.append('timestamp={0}'.format(self.timestamp)) | ||
| 412 | - if self.itf_version_info: | ||
| 413 | - lines.append(self.itf_version_info) | ||
| 414 | - | ||
| 415 | - if self.requires: | ||
| 416 | - requires_str = [require.to_required_full_str() for require in self.requires] | ||
| 417 | - lines.extend(requires_str) | ||
| 418 | - | ||
| 419 | - lines.append('') | ||
| 420 | - | ||
| 421 | - return '\n'.join(lines) | ||
| 422 | - | ||
| 423 | - def save(self, target_path: Union[Path, str]): | ||
| 424 | - """保存版本配置。""" | ||
| 425 | - content = self._get_content() | ||
| 426 | - | ||
| 427 | - target_dir = os.path.dirname(target_path) | ||
| 428 | - if not os.path.exists(target_dir): | ||
| 429 | - os.makedirs(target_dir) | ||
| 430 | - | ||
| 431 | - with open(target_path, 'w') as file: | ||
| 432 | - file.write(content) | ||
| @@ -1,281 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 2 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 3 | -# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | -# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | -# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 10 | - | ||
| 11 | -function strip(input) { | ||
| 12 | - sub("^ +", "", input) | ||
| 13 | - sub(" +$", "", input) | ||
| 14 | - return input | ||
| 15 | -} | ||
| 16 | - | ||
| 17 | -function check_compatible_le(version_arr, len_version_arr, require_arr, len_require_arr, i) { | ||
| 18 | - for (i = 1; i <= len_require_arr; i++) { | ||
| 19 | - if (require_arr[i] == "") { | ||
| 20 | - continue | ||
| 21 | - } | ||
| 22 | - # len_version_arr lt len_require_arr | ||
| 23 | - if (i > len_version_arr) { | ||
| 24 | - return 1 | ||
| 25 | - } | ||
| 26 | - if (version_arr[i] < require_arr[i]) { | ||
| 27 | - return 1 | ||
| 28 | - } | ||
| 29 | - if (version_arr[i] > require_arr[i]) { | ||
| 30 | - return 0 | ||
| 31 | - } | ||
| 32 | - } | ||
| 33 | - if (len_version_arr > len_require_arr) { | ||
| 34 | - return 1 | ||
| 35 | - } | ||
| 36 | - # len_version_arr eq len_require_arr | ||
| 37 | - return 1 | ||
| 38 | -} | ||
| 39 | - | ||
| 40 | -function check_compatible_lt(version_arr, len_version_arr, require_arr, len_require_arr, i) { | ||
| 41 | - for (i = 1; i <= len_require_arr; i++) { | ||
| 42 | - if (require_arr[i] == "") { | ||
| 43 | - continue | ||
| 44 | - } | ||
| 45 | - # len_version_arr lt len_require_arr | ||
| 46 | - if (i > len_version_arr) { | ||
| 47 | - return 1 | ||
| 48 | - } | ||
| 49 | - if (version_arr[i] < require_arr[i]) { | ||
| 50 | - return 1 | ||
| 51 | - } | ||
| 52 | - if (version_arr[i] > require_arr[i]) { | ||
| 53 | - return 0 | ||
| 54 | - } | ||
| 55 | - } | ||
| 56 | - if (len_version_arr > len_require_arr) { | ||
| 57 | - return 0 | ||
| 58 | - } | ||
| 59 | - # len_version_arr eq len_require_arr | ||
| 60 | - return 0 | ||
| 61 | -} | ||
| 62 | - | ||
| 63 | -function check_compatible_ge(version_arr, len_version_arr, require_arr, len_require_arr, i) { | ||
| 64 | - for (i = 1; i <= len_require_arr; i++) { | ||
| 65 | - if (require_arr[i] == "") { | ||
| 66 | - continue | ||
| 67 | - } | ||
| 68 | - # len_version_arr lt len_require_arr | ||
| 69 | - if (i > len_version_arr) { | ||
| 70 | - return 0 | ||
| 71 | - } | ||
| 72 | - if (version_arr[i] < require_arr[i]) { | ||
| 73 | - return 0 | ||
| 74 | - } | ||
| 75 | - if (version_arr[i] > require_arr[i]) { | ||
| 76 | - return 1 | ||
| 77 | - } | ||
| 78 | - } | ||
| 79 | - if (len_version_arr > len_require_arr) { | ||
| 80 | - return 1 | ||
| 81 | - } | ||
| 82 | - # len_version_arr eq len_require_arr | ||
| 83 | - return 1 | ||
| 84 | -} | ||
| 85 | - | ||
| 86 | -function check_compatible_gt(version_arr, len_version_arr, require_arr, len_require_arr, i) { | ||
| 87 | - for (i = 1; i <= len_require_arr; i++) { | ||
| 88 | - if (require_arr[i] == "") { | ||
| 89 | - continue | ||
| 90 | - } | ||
| 91 | - # len_version_arr lt len_require_arr | ||
| 92 | - if (i > len_version_arr) { | ||
| 93 | - return 0 | ||
| 94 | - } | ||
| 95 | - if (version_arr[i] < require_arr[i]) { | ||
| 96 | - return 0 | ||
| 97 | - } | ||
| 98 | - if (version_arr[i] > require_arr[i]) { | ||
| 99 | - return 1 | ||
| 100 | - } | ||
| 101 | - } | ||
| 102 | - if (len_version_arr > len_require_arr) { | ||
| 103 | - return 1 | ||
| 104 | - } | ||
| 105 | - # len_version_arr eq len_require_arr | ||
| 106 | - return 0 | ||
| 107 | -} | ||
| 108 | - | ||
| 109 | -function check_compatible_eq(version_arr, len_version_arr, require_arr, len_require_arr, i) { | ||
| 110 | - for (i = 1; i <= len_require_arr; i++) { | ||
| 111 | - if (require_arr[i] == "") { | ||
| 112 | - continue | ||
| 113 | - } | ||
| 114 | - # len_version_arr lt len_require_arr | ||
| 115 | - if (i > len_version_arr) { | ||
| 116 | - return 0 | ||
| 117 | - } | ||
| 118 | - if (version_arr[i] != require_arr[i]) { | ||
| 119 | - return 0 | ||
| 120 | - } | ||
| 121 | - } | ||
| 122 | - if (len_version_arr > len_require_arr) { | ||
| 123 | - return 1 | ||
| 124 | - } | ||
| 125 | - # len_version_arr eq len_require_arr | ||
| 126 | - return 1 | ||
| 127 | -} | ||
| 128 | - | ||
| 129 | -function check_compatible(version_arr, len_version_arr, require, require_arr, len_require_arr, pos) { | ||
| 130 | - len_require_arr = split(require, require_arr, ".") | ||
| 131 | - | ||
| 132 | - pos = match(require_arr[1], /^>=/) | ||
| 133 | - if (pos != 0) { | ||
| 134 | - require_arr[1] = substr(require_arr[1], pos + RLENGTH) | ||
| 135 | - return check_compatible_ge(version_arr, len_version_arr, require_arr, len_require_arr) | ||
| 136 | - } | ||
| 137 | - | ||
| 138 | - pos = match(require_arr[1], /^>/) | ||
| 139 | - if (pos != 0) { | ||
| 140 | - require_arr[1] = substr(require_arr[1], pos + RLENGTH) | ||
| 141 | - return check_compatible_gt(version_arr, len_version_arr, require_arr, len_require_arr) | ||
| 142 | - } | ||
| 143 | - | ||
| 144 | - pos = match(require_arr[1], /^<=/) | ||
| 145 | - if (pos != 0) { | ||
| 146 | - require_arr[1] = substr(require_arr[1], pos + RLENGTH) | ||
| 147 | - return check_compatible_le(version_arr, len_version_arr, require_arr, len_require_arr) | ||
| 148 | - } | ||
| 149 | - | ||
| 150 | - pos = match(require_arr[1], /^</) | ||
| 151 | - if (pos != 0) { | ||
| 152 | - require_arr[1] = substr(require_arr[1], pos + RLENGTH) | ||
| 153 | - return check_compatible_lt(version_arr, len_version_arr, require_arr, len_require_arr) | ||
| 154 | - } | ||
| 155 | - | ||
| 156 | - return check_compatible_eq(version_arr, len_version_arr, require_arr, len_require_arr) | ||
| 157 | -} | ||
| 158 | - | ||
| 159 | -BEGIN { | ||
| 160 | - len_all_required_arr = split(all_required, all_required_arr, ",") | ||
| 161 | - | ||
| 162 | - compated = 0 | ||
| 163 | - | ||
| 164 | - in_gt = 0 | ||
| 165 | - matched_gt = 0 | ||
| 166 | - | ||
| 167 | - len_version_arr = split(version, version_arr, ".") | ||
| 168 | - | ||
| 169 | - for (i = 1; i <= len_all_required_arr; i++) { | ||
| 170 | - all_required_arr[i] = strip(all_required_arr[i]) | ||
| 171 | - one_compated = check_compatible(version_arr, len_version_arr, all_required_arr[i]) | ||
| 172 | - | ||
| 173 | - pos = match(all_required_arr[i], /^>/) | ||
| 174 | - if (pos != 0) { | ||
| 175 | - gt_require = 1 | ||
| 176 | - lt_require = 0 | ||
| 177 | - eq_require = 0 | ||
| 178 | - } else { | ||
| 179 | - pos = match(all_required_arr[i], /^</) | ||
| 180 | - if (pos != 0) { | ||
| 181 | - gt_require = 0 | ||
| 182 | - lt_require = 1 | ||
| 183 | - eq_require = 0 | ||
| 184 | - } else { | ||
| 185 | - gt_require = 0 | ||
| 186 | - lt_require = 0 | ||
| 187 | - eq_require = 1 | ||
| 188 | - } | ||
| 189 | - } | ||
| 190 | - | ||
| 191 | - if (matched_gt) { | ||
| 192 | - if (one_compated) { | ||
| 193 | - # gt after gt, all compated. | ||
| 194 | - if (gt_require) { | ||
| 195 | - matched_gt = 1 | ||
| 196 | - in_gt = 1 | ||
| 197 | - continue | ||
| 198 | - } | ||
| 199 | - # lt after gt, all compated. | ||
| 200 | - if (lt_require) { | ||
| 201 | - compated = 1 | ||
| 202 | - matched_gt = 0 | ||
| 203 | - in_gt = 0 | ||
| 204 | - break | ||
| 205 | - } | ||
| 206 | - # eq after gt, all compated. | ||
| 207 | - if (eq_require) { | ||
| 208 | - # eq compated, go. | ||
| 209 | - compated = 1 | ||
| 210 | - break | ||
| 211 | - } | ||
| 212 | - } else { | ||
| 213 | - # miscompated. | ||
| 214 | - # gt after gt, compated first gt. miscompated second gt. | ||
| 215 | - if (gt_require) { | ||
| 216 | - matched_gt = 0 | ||
| 217 | - in_gt = 1 | ||
| 218 | - continue | ||
| 219 | - } | ||
| 220 | - # lt after gt, compated first gt. miscompated second lt. | ||
| 221 | - if (lt_require) { | ||
| 222 | - matched_gt = 0 | ||
| 223 | - in_gt = 0 | ||
| 224 | - continue | ||
| 225 | - } | ||
| 226 | - # eq after gt, compated first gt. miscompated second eq. | ||
| 227 | - if (eq_require) { | ||
| 228 | - continue | ||
| 229 | - } | ||
| 230 | - } | ||
| 231 | - } else { | ||
| 232 | - if (one_compated) { | ||
| 233 | - if (gt_require) { | ||
| 234 | - matched_gt = 1 | ||
| 235 | - in_gt = 1 | ||
| 236 | - continue | ||
| 237 | - } | ||
| 238 | - if (lt_require) { | ||
| 239 | - if (in_gt) { | ||
| 240 | - matched_gt = 0 | ||
| 241 | - in_gt = 0 | ||
| 242 | - continue | ||
| 243 | - } else { | ||
| 244 | - compated = 1 | ||
| 245 | - break | ||
| 246 | - } | ||
| 247 | - } | ||
| 248 | - if (eq_require) { | ||
| 249 | - # eq compated, go. | ||
| 250 | - compated = 1 | ||
| 251 | - break | ||
| 252 | - } | ||
| 253 | - } else { | ||
| 254 | - # miscompated. | ||
| 255 | - if (gt_require) { | ||
| 256 | - matched_gt = 0 | ||
| 257 | - in_gt = 1 | ||
| 258 | - continue | ||
| 259 | - } | ||
| 260 | - if (lt_require) { | ||
| 261 | - matched_gt = 0 | ||
| 262 | - in_gt = 0 | ||
| 263 | - continue | ||
| 264 | - } | ||
| 265 | - if (eq_require) { | ||
| 266 | - continue | ||
| 267 | - } | ||
| 268 | - } | ||
| 269 | - } | ||
| 270 | - } | ||
| 271 | - | ||
| 272 | - if (matched_gt) { | ||
| 273 | - compated = 1 | ||
| 274 | - } | ||
| 275 | - | ||
| 276 | - if (compated == 0) { | ||
| 277 | - printf("F") | ||
| 278 | - } else { | ||
| 279 | - printf("T") | ||
| 280 | - } | ||
| 281 | -} | ||
| @@ -1,14 +0,0 @@ | |||
| 1 | -#!/bin/sh | ||
| 2 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | -# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | -# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 11 | - | ||
| 12 | -set -e | ||
| 13 | - | ||
| 14 | -rm -rf $(pwd) | ||
| @@ -1,107 +0,0 @@ | |||
| 1 | -#!/bin/sh | ||
| 2 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | -# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | -# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 11 | - | ||
| 12 | -# 设置公共变量 | ||
| 13 | -set_global_vars() { | ||
| 14 | - local arch | ||
| 15 | - local scene_filepath="${curpath}/../scene.info" | ||
| 16 | - | ||
| 17 | - if [ -f "${scene_filepath}" ]; then | ||
| 18 | - get_scene_arch "arch" "${scene_filepath}" | ||
| 19 | - if [ "${arch}" != "" ]; then | ||
| 20 | - PKG_ARCH="${arch}" | ||
| 21 | - fi | ||
| 22 | - fi | ||
| 23 | -} | ||
| 24 | - | ||
| 25 | -# 获取并发进程数 | ||
| 26 | -get_thread_num() { | ||
| 27 | - local _outvar="$1" | ||
| 28 | - local _thread_num="$(cat /proc/cpuinfo | grep "^processor" | wc -l)" | ||
| 29 | - | ||
| 30 | - # 未取得CPU核数时,默认为1 | ||
| 31 | - if [ "$_thread_num" = "" ] || [ "$_thread_num" = "0" ]; then | ||
| 32 | - _thread_num="1" | ||
| 33 | - fi | ||
| 34 | - | ||
| 35 | - # CPU核数2倍 | ||
| 36 | - eval "${_outvar}=\"$((_thread_num*2))\"" | ||
| 37 | -} | ||
| 38 | - | ||
| 39 | -# 初始化fifo,用于并发控制 | ||
| 40 | -init_fifo() { | ||
| 41 | - local _outvar="$1" | ||
| 42 | - local _thread_num="$2" | ||
| 43 | - local _tmppath_if tmp | ||
| 44 | - local _skip_msg="skip init fifo" | ||
| 45 | - | ||
| 46 | - # 并发数为空时,默认为1 | ||
| 47 | - if [ "$_thread_num" = "" ]; then | ||
| 48 | - _thread_num="1" | ||
| 49 | - comm_log "WARNING" "thread number is empty, use ${_thread_num}." | ||
| 50 | - fi | ||
| 51 | - # 并发数<=0时,默认为1 | ||
| 52 | - if [ $_thread_num -le 0 ]; then | ||
| 53 | - comm_log "WARNING" "thread number is ${_thread_num}, use 1." | ||
| 54 | - _thread_num="1" | ||
| 55 | - fi | ||
| 56 | - | ||
| 57 | - get_tmp_file _tmppath_if "fifo" | ||
| 58 | - if [ -e "$_tmppath_if" ]; then | ||
| 59 | - rm -rf "$_tmppath_if" | ||
| 60 | - check_ret_warning "$?" "remove old file $_tmppath_if failed, ${_skip_msg}." | ||
| 61 | - ret="$?" && [ $ret -ne 0 ] && return $ret | ||
| 62 | - fi | ||
| 63 | - | ||
| 64 | - mkfifo "$_tmppath_if" | ||
| 65 | - check_ret_warning "$?" "make fifo $_tmppath_if failed, ${_skip_msg}." | ||
| 66 | - ret="$?" && [ $ret -ne 0 ] && return $ret | ||
| 67 | - | ||
| 68 | - # 使用文件描述符8作并发控制 | ||
| 69 | - exec 8<> "$_tmppath_if" # 创建文件描述符8 | ||
| 70 | - check_ret_warning "$?" "open fifo $_tmppath_if file descriptor failed, ${_skip_msg}." | ||
| 71 | - ret="$?" && [ $ret -ne 0 ] && return $ret | ||
| 72 | - | ||
| 73 | - rm -f "$_tmppath_if" | ||
| 74 | - check_ret_warning "$?" "remove fifo $_tmppath_if failed, ${_skip_msg}." | ||
| 75 | - ret="$?" && [ $ret -ne 0 ] && return $ret | ||
| 76 | - | ||
| 77 | - for tmp in $(seq $_thread_num); do | ||
| 78 | - echo >&8 | ||
| 79 | - check_ret_warning "$?" "echo fifo $_tmppath_if failed, ${_skip_msg}." | ||
| 80 | - ret="$?" && [ $ret -ne 0 ] && return $ret | ||
| 81 | - done | ||
| 82 | - | ||
| 83 | - eval "${_outvar}=\"${_tmppath_if}\"" | ||
| 84 | -} | ||
| 85 | - | ||
| 86 | -# 根据参数执行 | ||
| 87 | -exec_with_param() { | ||
| 88 | - local param="$1" | ||
| 89 | - shift 1 | ||
| 90 | - local exec_mode fifo_path="$PARALLEL_FIFO" tmp | ||
| 91 | - extract_1st "exec_mode" "$param" | ||
| 92 | - if [ "$exec_mode" = "concurrency" ]; then | ||
| 93 | - if [ "$fifo_path" = "none" ] || [ "$fifo_path" = "" ]; then | ||
| 94 | - "$@" & | ||
| 95 | - else | ||
| 96 | - read tmp <&8 | ||
| 97 | - { | ||
| 98 | - "$@" | ||
| 99 | - ret="$?" | ||
| 100 | - echo >&8 | ||
| 101 | - exit $ret | ||
| 102 | - } & | ||
| 103 | - fi | ||
| 104 | - else | ||
| 105 | - "$@" | ||
| 106 | - fi | ||
| 107 | -} | ||
| @@ -1,55 +0,0 @@ | |||
| 1 | -#!/bin/sh | ||
| 2 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | -# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | -# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 11 | - | ||
| 12 | -# 通知latest管理器创建版本软链 | ||
| 13 | -notify_latest_manager_create_version_softlink() { | ||
| 14 | - local curpath install_path version_dir var_path | ||
| 15 | - | ||
| 16 | - set_comm_log "Notifier" | ||
| 17 | - | ||
| 18 | - curpath="$(dirname $(readlink -f "${BASH_SOURCE:-$0}"))" | ||
| 19 | - install_path="$(readlink -f "$curpath/..")" | ||
| 20 | - version_dir="$(basename "$curpath")" | ||
| 21 | - var_path="$install_path/$LATEST_DIR/var" | ||
| 22 | - | ||
| 23 | - if [ ! -f "$var_path/manager.sh" ]; then | ||
| 24 | - comm_log "ERROR" "$var_path/manager.sh doesn't exist!" | ||
| 25 | - exit 2 | ||
| 26 | - fi | ||
| 27 | - | ||
| 28 | - if ! "$var_path/manager.sh" --version-dir "$version_dir" create_version_softlink; then | ||
| 29 | - comm_log "ERROR" "create version softlink failed!" | ||
| 30 | - exit 1 | ||
| 31 | - fi | ||
| 32 | - return 0 | ||
| 33 | -} | ||
| 34 | - | ||
| 35 | -# 通知latest管理器删除latest软链 | ||
| 36 | -notify_latest_manager_remove_latest_softlink() { | ||
| 37 | - local curpath install_path var_path | ||
| 38 | - | ||
| 39 | - set_comm_log "Notifier" | ||
| 40 | - | ||
| 41 | - curpath="$(dirname $(readlink -f "${BASH_SOURCE:-$0}"))" | ||
| 42 | - install_path="$(readlink -f "$curpath/..")" | ||
| 43 | - var_path="$install_path/$LATEST_DIR/var" | ||
| 44 | - | ||
| 45 | - if [ ! -f "$var_path/manager.sh" ]; then | ||
| 46 | - comm_log "ERROR" "$var_path/manager.sh doesn't exist!" | ||
| 47 | - exit 2 | ||
| 48 | - fi | ||
| 49 | - | ||
| 50 | - if ! "$var_path/manager.sh" remove_latest_softlink; then | ||
| 51 | - comm_log "ERROR" "remove latest softlink failed!" | ||
| 52 | - exit 1 | ||
| 53 | - fi | ||
| 54 | - return 0 | ||
| 55 | -} | ||
| @@ -1,61 +0,0 @@ | |||
| 1 | -#!/bin/sh | ||
| 2 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | -# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | -# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 11 | - | ||
| 12 | -mk_custom_path() { | ||
| 13 | - if [ $(id -u) -eq 0 ]; then | ||
| 14 | - return 0 | ||
| 15 | - fi | ||
| 16 | - local _custom_path_file="$1" | ||
| 17 | - while read line || [ -n "$line" ] | ||
| 18 | - do | ||
| 19 | - local _custom_path="$(echo "$line" | cut --only-delimited -d= -f2)" | ||
| 20 | - if [ -z "$_custom_path" ]; then | ||
| 21 | - continue | ||
| 22 | - fi | ||
| 23 | - eval "_custom_path=$_custom_path" | ||
| 24 | - if [ ! -d "$_custom_path" ]; then | ||
| 25 | - mkdir -p "$_custom_path" | ||
| 26 | - if [ $? -ne 0 ]; then | ||
| 27 | - cur_date="$(date +"%Y-%m-%d %H:%M:%S")" | ||
| 28 | - echo "[Common] [$cur_date] [ERROR]: create $_custom_path failed." | ||
| 29 | - return 1 | ||
| 30 | - fi | ||
| 31 | - fi | ||
| 32 | - done < $_custom_path_file | ||
| 33 | - return 0 | ||
| 34 | -} | ||
| 35 | - | ||
| 36 | -py_version_check(){ | ||
| 37 | - local pyver_set="3.7 3.8 3.9 3.10 3.11" | ||
| 38 | - local cur_date="$(date +"%Y-%m-%d %H:%M:%S")" | ||
| 39 | - which python3 > /dev/null 2>&1 | ||
| 40 | - if [ $? -eq 0 ]; then | ||
| 41 | - local python_version="$(python3 --version 2>&1 | head -n 1)" | ||
| 42 | - local python3_version=$(echo "$python_version" | sed -n 's/.*[^\.0-9]\([0-9]\+\.[0-9]\+\).*/\1/p') | ||
| 43 | - if [ "x$python3_version" != "x" ]; then | ||
| 44 | - for ver in $pyver_set; do | ||
| 45 | - if [ "x$ver" = "x$python3_version" ]; then | ||
| 46 | - return 0 | ||
| 47 | - fi | ||
| 48 | - done | ||
| 49 | - | ||
| 50 | - echo "[Common] [$cur_date] [WARNING]: $python_version is not in Python3.7.x, Python3.8.x, Python3.9.x, Python3.10.x, Python3.11.x." | ||
| 51 | - return 1 | ||
| 52 | - else | ||
| 53 | - echo "[Common] [$cur_date] [WARNING]: $python_version cannot be identified as a standard version, please check manually." | ||
| 54 | - return 1 | ||
| 55 | - fi | ||
| 56 | - else | ||
| 57 | - echo "[Common] [$cur_date] [WARNING]: python3 is not found." | ||
| 58 | - return 1 | ||
| 59 | - fi | ||
| 60 | -} | ||
| 61 | - | ||
| @@ -1,37 +0,0 @@ | |||
| 1 | -#!/bin/csh | ||
| 2 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | -# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | -# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 11 | - | ||
| 12 | -set func_name = "$1" | ||
| 13 | -switch ( "$func_name" ) | ||
| 14 | - case "mk_custom_path": | ||
| 15 | - if ( "`id -u`" == 0 ) then | ||
| 16 | - exit 0 | ||
| 17 | - endif | ||
| 18 | - set file_path = "$2" | ||
| 19 | - foreach line ("` cat $file_path `") | ||
| 20 | - set custom_path = "`echo '$line' | cut --only-delimited -d= -f2`" | ||
| 21 | - if ( "$custom_path" == "" ) then | ||
| 22 | - continue | ||
| 23 | - endif | ||
| 24 | - set custom_path = "` eval echo $custom_path `" | ||
| 25 | - if ( ! -d "$custom_path" ) then | ||
| 26 | - mkdir -p "$custom_path" | ||
| 27 | - if ( $status != 0 ) then | ||
| 28 | - set cur_date = "`date +'%Y-%m-%d %H:%M:%S'`" | ||
| 29 | - echo "[Common] [$cur_date] [ERROR]: create $custom_path failed." | ||
| 30 | - exit 1 | ||
| 31 | - endif | ||
| 32 | - endif | ||
| 33 | - end | ||
| 34 | - breaksw | ||
| 35 | - default: | ||
| 36 | - breaksw | ||
| 37 | -endsw | ||
| @@ -1,33 +0,0 @@ | |||
| 1 | -#!/usr/bin/env fish | ||
| 2 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | -# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | -# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 11 | - | ||
| 12 | -function mk_custom_path | ||
| 13 | - set -l custom_file_path $argv[1] | ||
| 14 | - if test (id -u) -eq 0 | ||
| 15 | - return 0 | ||
| 16 | - end | ||
| 17 | - while read line | ||
| 18 | - set -l _custom_path (echo "$line" | cut --only-delimited -d= -f2) | ||
| 19 | - if test -z $_custom_path | ||
| 20 | - continue | ||
| 21 | - end | ||
| 22 | - set -l _custom_path (eval echo "$_custom_path") | ||
| 23 | - if not test -d $_custom_path | ||
| 24 | - mkdir -p "$_custom_path" | ||
| 25 | - if not test $status -eq 0 | ||
| 26 | - set -l cur_date (date +"%Y-%m-%d %H:%M:%S") | ||
| 27 | - echo "[Common] [$cur_date] [ERROR]: create $_custom_path failed." | ||
| 28 | - return 1 | ||
| 29 | - end | ||
| 30 | - end | ||
| 31 | - end < $custom_file_path | ||
| 32 | - return 0 | ||
| 33 | -end | ||
| @@ -1,61 +0,0 @@ | |||
| 1 | -#!/bin/sh | ||
| 2 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | -# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | -# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 11 | - | ||
| 12 | -mk_custom_path() { | ||
| 13 | - if [ $(id -u) -eq 0 ]; then | ||
| 14 | - return 0 | ||
| 15 | - fi | ||
| 16 | - local _custom_path_file="$1" | ||
| 17 | - while read line || [ -n "$line" ] | ||
| 18 | - do | ||
| 19 | - local _custom_path="$(echo "$line" | cut --only-delimited -d= -f2)" | ||
| 20 | - if [ -z "$_custom_path" ]; then | ||
| 21 | - continue | ||
| 22 | - fi | ||
| 23 | - eval "_custom_path=$_custom_path" | ||
| 24 | - if [ ! -d "$_custom_path" ]; then | ||
| 25 | - mkdir -p "$_custom_path" | ||
| 26 | - if [ $? -ne 0 ]; then | ||
| 27 | - cur_date="$(date +"%Y-%m-%d %H:%M:%S")" | ||
| 28 | - echo "[Common] [$cur_date] [ERROR]: create $_custom_path failed." | ||
| 29 | - return 1 | ||
| 30 | - fi | ||
| 31 | - fi | ||
| 32 | - done < $_custom_path_file | ||
| 33 | - return 0 | ||
| 34 | -} | ||
| 35 | - | ||
| 36 | -py_version_check(){ | ||
| 37 | - local pyver_set="3.7 3.8 3.9 3.10 3.11" | ||
| 38 | - local cur_date="$(date +"%Y-%m-%d %H:%M:%S")" | ||
| 39 | - which python3 > /dev/null 2>&1 | ||
| 40 | - if [ $? -eq 0 ]; then | ||
| 41 | - local python_version="$(python3 --version 2>&1 | head -n 1)" | ||
| 42 | - local python3_version=$(echo "$python_version" | sed -n 's/.*[^\.0-9]\([0-9]\+\.[0-9]\+\).*/\1/p') | ||
| 43 | - if [ "x$python3_version" != "x" ]; then | ||
| 44 | - for ver in $pyver_set; do | ||
| 45 | - if [ "x$ver" = "x$python3_version" ]; then | ||
| 46 | - return 0 | ||
| 47 | - fi | ||
| 48 | - done | ||
| 49 | - | ||
| 50 | - echo "[Common] [$cur_date] [WARNING]: $python_version is not in Python3.7.x, Python3.8.x, Python3.9.x, Python3.10.x, Python3.11.x." | ||
| 51 | - return 1 | ||
| 52 | - else | ||
| 53 | - echo "[Common] [$cur_date] [WARNING]: $python_version cannot be identified as a standard version, please check manually." | ||
| 54 | - return 1 | ||
| 55 | - fi | ||
| 56 | - else | ||
| 57 | - echo "[Common] [$cur_date] [WARNING]: python3 is not found." | ||
| 58 | - return 1 | ||
| 59 | - fi | ||
| 60 | -} | ||
| 61 | - | ||
| @@ -1,305 +0,0 @@ | |||
| 1 | -#!/bin/sh | ||
| 2 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | -# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | -# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | -# ---------------------------------------------------------------------------------------------------------- | ||
| 11 | - | ||
| 12 | -# 多版本函数库 | ||
| 13 | -# 创建版本目录 | ||
| 14 | -create_version_dir() { | ||
| 15 | - local install_path="$1" | ||
| 16 | - local version_dir="$2" | ||
| 17 | - local username="$3" | ||
| 18 | - local usergroup="$4" | ||
| 19 | - local install_for_all="$5" | ||
| 20 | - local ret | ||
| 21 | - | ||
| 22 | - if [ ! -d "${install_path}/${version_dir}" ]; then | ||
| 23 | - make_dir "${install_path}/${version_dir}" | ||
| 24 | - ret="$?" && [ $ret -ne 0 ] && return $ret | ||
| 25 | - fi | ||
| 26 | - | ||
| 27 | - # 约束版本号目录权限 | ||
| 28 | - change_mod "${install_path}/${version_dir}" "750" "${install_for_all}" | ||
| 29 | - ret="$?" && [ $ret -ne 0 ] && return $ret | ||
| 30 | - | ||
| 31 | - change_own "${install_path}/${version_dir}" "${username}:${usergroup}" | ||
| 32 | - ret="$?" && [ $ret -ne 0 ] && return $ret | ||
| 33 | - | ||
| 34 | - return 0 | ||
| 35 | -} | ||
| 36 | - | ||
| 37 | -# 检查版本包安装结果 | ||
| 38 | -check_version_install() { | ||
| 39 | - local install_path="$1" | ||
| 40 | - local version_dir="$2" | ||
| 41 | - local package="$3" | ||
| 42 | - local version_info_path | ||
| 43 | - | ||
| 44 | - get_package_version_info "version_info_path" "$install_path" "$version_dir" "$package" | ||
| 45 | - | ||
| 46 | - if [ ! -f "$version_info_path" ]; then | ||
| 47 | - comm_log "ERROR" "$version_info_path doesn't exist in check version install!" | ||
| 48 | - return 1 | ||
| 49 | - fi | ||
| 50 | - return 0 | ||
| 51 | -} | ||
| 52 | - | ||
| 53 | -# 安装latest管理器 | ||
| 54 | -install_latest_manager() { | ||
| 55 | - local var_path="$1" | ||
| 56 | - shift 1 | ||
| 57 | - sh latest_manager/install.sh --install-path="$var_path" "$@" | ||
| 58 | -} | ||
| 59 | - | ||
| 60 | -# 卸载latest管理器 | ||
| 61 | -uninstall_latest_manager_for_upgrade() { | ||
| 62 | - local var_path="$1" | ||
| 63 | - ${var_path}/manager/uninstall.sh --upgrade | ||
| 64 | -} | ||
| 65 | - | ||
| 66 | -# 升级latest管理器 | ||
| 67 | -upgrade_latest_manager() { | ||
| 68 | - local var_path="$1" | ||
| 69 | - local latest_version_info latest_manager_version local_manager_version | ||
| 70 | - | ||
| 71 | - latest_version_info="$var_path/manager/version.info" | ||
| 72 | - if [ -f "$latest_version_info" ]; then | ||
| 73 | - get_version latest_manager_version "$latest_version_info" | ||
| 74 | - get_version local_manager_version "latest_manager/version.info" | ||
| 75 | - | ||
| 76 | - set_default "latest_manager_version" "$latest_manager_version" "0" | ||
| 77 | - set_default "local_manager_version" "$local_manager_version" "0" | ||
| 78 | - | ||
| 79 | - if [ "$latest_manager_version" -lt "$local_manager_version" ]; then | ||
| 80 | - uninstall_latest_manager_for_upgrade "$var_path" | ||
| 81 | - install_latest_manager "$var_path" "--upgrade" | ||
| 82 | - fi | ||
| 83 | - else | ||
| 84 | - install_latest_manager "$var_path" | ||
| 85 | - fi | ||
| 86 | -} | ||
| 87 | - | ||
| 88 | -get_install_for_all_param() { | ||
| 89 | - local _outvar="$1" | ||
| 90 | - local _install_for_all="$2" | ||
| 91 | - local _result="" | ||
| 92 | - | ||
| 93 | - if [ "$_install_for_all" = "y" ]; then | ||
| 94 | - _result="--install-for-all" | ||
| 95 | - fi | ||
| 96 | - | ||
| 97 | - eval "${_outvar}=\"${_result}\"" | ||
| 98 | -} | ||
| 99 | - | ||
| 100 | -get_docker_root_param() { | ||
| 101 | - local _outvar="$1" | ||
| 102 | - local _docker_root="$2" | ||
| 103 | - local _result="" | ||
| 104 | - | ||
| 105 | - if [ "$_docker_root" != "" ]; then | ||
| 106 | - _result="--docker-root \\\"$_docker_root\\\"" | ||
| 107 | - fi | ||
| 108 | - | ||
| 109 | - eval "${_outvar}=\"${_result}\"" | ||
| 110 | -} | ||
| 111 | - | ||
| 112 | -# 通知latest管理器 | ||
| 113 | -notify_latest_manager() { | ||
| 114 | - local var_path="$1" | ||
| 115 | - local package="$2" | ||
| 116 | - local version="$3" | ||
| 117 | - local version_dir="$4" | ||
| 118 | - local install_for_all="$5" | ||
| 119 | - local docker_root="$6" | ||
| 120 | - local ext_params="$7" | ||
| 121 | - local operation="$8" | ||
| 122 | - local ret package_dir install_for_all_param docker_root_param | ||
| 123 | - | ||
| 124 | - if [ ! -f "$var_path/manager.sh" ]; then | ||
| 125 | - return 1 | ||
| 126 | - fi | ||
| 127 | - | ||
| 128 | - if [ "$USE_SHARE_INFO" = "y" ]; then | ||
| 129 | - ext_params="$ext_params --use-share-info" | ||
| 130 | - fi | ||
| 131 | - | ||
| 132 | - get_package_dir package_dir "$package" | ||
| 133 | - get_install_for_all_param "install_for_all_param" "$install_for_all" | ||
| 134 | - get_docker_root_param "docker_root_param" "$docker_root" | ||
| 135 | - | ||
| 136 | - eval "\"$var_path/manager.sh\"" --version "\"$version\"" --version-dir "\"$version_dir\"" \ | ||
| 137 | - --package "\"$package\"" --package-dir "\"$package_dir\"" \ | ||
| 138 | - "$install_for_all_param" "$docker_root_param" "$ext_params" "$operation" | ||
| 139 | - ret="$?" && [ $ret -ne 0 ] && return $ret | ||
| 140 | - | ||
| 141 | - return 0 | ||
| 142 | -} | ||
| 143 | - | ||
| 144 | -# 通知latest管理器安装完成 | ||
| 145 | -notify_latest_manager_installed() { | ||
| 146 | - local local_manager_version | ||
| 147 | - local ext_params | ||
| 148 | - | ||
| 149 | - get_version local_manager_version "latest_manager/version.info" | ||
| 150 | - set_default "local_manager_version" "$local_manager_version" "0" | ||
| 151 | - | ||
| 152 | - if [ "$INCREMENT" = "y" ]; then | ||
| 153 | - ext_params="--serial $local_manager_version --increment" | ||
| 154 | - else | ||
| 155 | - ext_params="--serial $local_manager_version" | ||
| 156 | - fi | ||
| 157 | - | ||
| 158 | - notify_latest_manager "$@" "$ext_params" "package_installed" | ||
| 159 | -} | ||
| 160 | - | ||
| 161 | -# 通知latest管理器创建软链 | ||
| 162 | -# 老版本全部卸载后,latest回滚到新版本时,会用老版本的install_common_parser.sh, | ||
| 163 | -# 调用新版本的--create-package-latest-softlink,会走到这个流程。 | ||
| 164 | -notify_latest_manager_create_softlink() { | ||
| 165 | - notify_latest_manager "$@" "" "package_create_softlink" | ||
| 166 | -} | ||
| 167 | - | ||
| 168 | -# 通知latest管理器删除软链 | ||
| 169 | -notify_latest_manager_remove_softlink() { | ||
| 170 | - notify_latest_manager "$@" "" "package_remove_softlink" | ||
| 171 | -} | ||
| 172 | - | ||
| 173 | -# 通知latest管理器准备卸载 | ||
| 174 | -notify_latest_manager_pre_uninstall() { | ||
| 175 | - notify_latest_manager "$@" "" "package_pre_uninstall" | ||
| 176 | -} | ||
| 177 | - | ||
| 178 | -# 通知latest管理器卸载完成 | ||
| 179 | -notify_latest_manager_uninstalled() { | ||
| 180 | - local is_recreate_softlink="$1" | ||
| 181 | - local recreate_softlink="" | ||
| 182 | - local ret | ||
| 183 | - shift 1 | ||
| 184 | - | ||
| 185 | - if [ "$is_recreate_softlink" = "y" ]; then | ||
| 186 | - recreate_softlink="--recreate-softlink" | ||
| 187 | - fi | ||
| 188 | - | ||
| 189 | - notify_latest_manager "$@" "$recreate_softlink" "package_uninstalled" | ||
| 190 | - ret="$?" && [ $ret -ne 0 ] && return $ret | ||
| 191 | - | ||
| 192 | - return 0 | ||
| 193 | -} | ||
| 194 | - | ||
| 195 | -# 多版本安装流程 | ||
| 196 | -multi_version_install() { | ||
| 197 | - local install_type="$1" | ||
| 198 | - local install_path="$2" | ||
| 199 | - local filelist_path="$3" | ||
| 200 | - local package="$4" | ||
| 201 | - local feature_param="$5" | ||
| 202 | - local version="$6" | ||
| 203 | - local version_dir="$7" | ||
| 204 | - local username="$8" | ||
| 205 | - local usergroup="$9" | ||
| 206 | - local setenv="${10}" | ||
| 207 | - local is_upgrade="${11}" | ||
| 208 | - local docker_root="${12}" | ||
| 209 | - local custom_options="${13}" | ||
| 210 | - local install_for_all="${14}" | ||
| 211 | - local ret total_ret="0" pkg_running_version version_pair_arr last_version last_version_dir | ||
| 212 | - | ||
| 213 | - create_version_dir "${install_path}" "${version_dir}" "${username}" "${usergroup}" "${install_for_all}" | ||
| 214 | - ret="$?" && [ $ret -ne 0 ] && return $ret | ||
| 215 | - | ||
| 216 | - version_install "${install_type}" "${install_path}" "${filelist_path}" "${package}" "${feature_param}" \ | ||
| 217 | - "${version_dir}" "${username}" "${usergroup}" "${setenv}" "${is_upgrade}" "${docker_root}" "${custom_options}" | ||
| 218 | - ret="$?" && [ $ret -ne 0 ] && return $ret | ||
| 219 | - | ||
| 220 | - check_version_install "$install_path" "$version_dir" "$package" | ||
| 221 | - ret="$?" && [ $ret -ne 0 ] && return $ret | ||
| 222 | - | ||
| 223 | - return ${total_ret} | ||
| 224 | -} | ||
| 225 | - | ||
| 226 | -# 删除latest下空目录 | ||
| 227 | -del_empty_dirs_in_latest() { | ||
| 228 | - local install_type="$1" | ||
| 229 | - local install_path="$2" | ||
| 230 | - local latest_dir="$3" | ||
| 231 | - local filelist_path="$4" | ||
| 232 | - local feature_param="$5" | ||
| 233 | - local ret | ||
| 234 | - | ||
| 235 | - create_stash_mod "${install_path}/${latest_dir}" | ||
| 236 | - ret="$?" && [ $ret -ne 0 ] && return $ret | ||
| 237 | - | ||
| 238 | - foreach_filelist "filter_common_dirs" "reset_mod_dirs_with_stash_mod" "${install_type}" "${install_path}/${latest_dir}" "mkdir" \ | ||
| 239 | - "${filelist_path}" "${feature_param}" "no" "normal" | ||
| 240 | - ret="$?" && [ $ret -ne 0 ] && return $ret | ||
| 241 | - | ||
| 242 | - foreach_filelist "filter_common_dirs" "remove_install_dirs" "${install_type}" "${install_path}/${latest_dir}" "mkdir" \ | ||
| 243 | - "${filelist_path}" "${feature_param}" "reverse" "normal" | ||
| 244 | - ret="$?" && [ $ret -ne 0 ] && return $ret | ||
| 245 | - | ||
| 246 | - foreach_stashmod "restore_stash_mod" "${install_path}/${latest_dir}" "reverse" | ||
| 247 | - ret="$?" && [ $ret -ne 0 ] && return $ret | ||
| 248 | - | ||
| 249 | - remove_stash_mod "${install_path}/${latest_dir}" | ||
| 250 | - ret="$?" && [ $ret -ne 0 ] && return $ret | ||
| 251 | - | ||
| 252 | - return 0 | ||
| 253 | -} | ||
| 254 | - | ||
| 255 | -# 多版本卸载流程 | ||
| 256 | -multi_version_uninstall() { | ||
| 257 | - local install_type="$1" | ||
| 258 | - local install_path="$2" | ||
| 259 | - local filelist_path="$3" | ||
| 260 | - local package="$4" | ||
| 261 | - local feature_param="$5" | ||
| 262 | - local version="$6" | ||
| 263 | - local version_dir="$7" | ||
| 264 | - local username="$8" | ||
| 265 | - local usergroup="$9" | ||
| 266 | - local docker_root="${10}" | ||
| 267 | - local custom_options="${11}" | ||
| 268 | - local is_recreate_softlink="${12}" | ||
| 269 | - local tmp_root tmp_filelist_path | ||
| 270 | - local ret total_ret=0 install_path_full="" is_running="" is_upgrade | ||
| 271 | - local running_packages is_final_running="false" | ||
| 272 | - | ||
| 273 | - check_param_not_empty "usergroup" "need set usergroup parameter in multi version uninstall!" | ||
| 274 | - ret="$?" && [ ${ret} -ne 0 ] && return ${ret} | ||
| 275 | - | ||
| 276 | - get_tmp_root "tmp_root" | ||
| 277 | - tmp_filelist_path=$(mktemp "$tmp_root/filelist_XXXXXX" || exit 1) | ||
| 278 | - cp -f "${filelist_path}" "${tmp_filelist_path}" | ||
| 279 | - | ||
| 280 | - if [ $? -ne 0 ]; then | ||
| 281 | - log "ERROR" "cp -f ${filelist_path} ${tmp_filelist_path} failed!" | ||
| 282 | - exit 1 | ||
| 283 | - fi | ||
| 284 | - | ||
| 285 | - del_tmp_filelist="rm -f \"${tmp_filelist_path}\"" | ||
| 286 | - | ||
| 287 | - version_uninstall "${install_type}" "${install_path}" "${filelist_path}" "${package}" "${feature_param}" \ | ||
| 288 | - "${version_dir}" "${username}" "${docker_root}" "${custom_options}" | ||
| 289 | - if [ $? -ne 0 ]; then | ||
| 290 | - eval "${del_tmp_filelist}" | ||
| 291 | - return 1 | ||
| 292 | - fi | ||
| 293 | - | ||
| 294 | - # 删除临时文件tmp_filelist_path | ||
| 295 | - eval "${del_tmp_filelist}" | ||
| 296 | - | ||
| 297 | - # 删除版本空目录 | ||
| 298 | - is_dir_empty "${install_path}/${version_dir}" | ||
| 299 | - if [ $? -eq 0 ]; then | ||
| 300 | - remove_dir_icp "${install_path}/${version_dir}" | ||
| 301 | - ret="$?" && [ $ret -ne 0 ] && total_ret="1" | ||
| 302 | - fi | ||
| 303 | - | ||
| 304 | - return ${total_ret} | ||
| 305 | -} | ||