已合并
ops-nn安装优化改造,解压即安装 #2762
qinhan创建于 3月16日
ops-nn安装优化改造,解压即安装 #2762
已合并
从已删除 :master合入到cann/ops-nnmaster
共 14 个文件变更+418-118
| @@ -395,11 +395,11 @@ function(prepare_compile_from_config) | |||
| 395 | set(subDir "") | 395 | set(subDir "") |
| 396 | endif() | 396 | endif() |
| 397 | install(DIRECTORY ${CONFCMP_OUT_DIR}/bin/${CONFCMP_COMPUTE_UNIT}/${CONFCMP_OP_NAME} | 397 | install(DIRECTORY ${CONFCMP_OUT_DIR}/bin/${CONFCMP_COMPUTE_UNIT}/${CONFCMP_OP_NAME} |
| 398 | - DESTINATION ${BIN_KERNEL_INSTALL_DIR}/${CONFCMP_COMPUTE_UNIT}/${subDir} OPTIONAL | 398 | + DESTINATION ${BIN_KERNEL_INSTALL_DIR}/${CONFCMP_COMPUTE_UNIT}/${subDir} OPTIONAL FILE_PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE |
| 399 | ) | 399 | ) |
| 400 | file(GLOB CONFCMP_OP_NAME_JSON ${CONFCMP_OUT_DIR}/bin/config/${CONFCMP_COMPUTE_UNIT}/${CONFCMP_OP_NAME}*.json) | 400 | file(GLOB CONFCMP_OP_NAME_JSON ${CONFCMP_OUT_DIR}/bin/config/${CONFCMP_COMPUTE_UNIT}/${CONFCMP_OP_NAME}*.json) |
| 401 | install(FILES ${CONFCMP_OP_NAME_JSON} | 401 | install(FILES ${CONFCMP_OP_NAME_JSON} |
| 402 | - DESTINATION ${BIN_KERNEL_CONFIG_INSTALL_DIR}/${CONFCMP_COMPUTE_UNIT}/${subDir} OPTIONAL | 402 | + DESTINATION ${BIN_KERNEL_CONFIG_INSTALL_DIR}/${CONFCMP_COMPUTE_UNIT}/${subDir} OPTIONAL PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE |
| 403 | ) | 403 | ) |
| 404 | endif() | 404 | endif() |
| 405 | endfunction() | 405 | endfunction() |
| @@ -71,9 +71,21 @@ configure_file( | |||
| 71 | ) | 71 | ) |
| 72 | configure_file( | 72 | configure_file( |
| 73 | ${NN_VERSION_OUT_PUT} | 73 | ${NN_VERSION_OUT_PUT} |
| 74 | - ${STAGING_DIR}/share/info/ops_nn/ | 74 | + ${STAGING_DIR}/${CMAKE_SYSTEM_PROCESSOR}-linux/include/version/ops_nn_version.h |
| 75 | COPYONLY | 75 | COPYONLY |
| 76 | ) | 76 | ) |
| 77 | + | ||
| 78 | +# 统一设置安装的文件权限为555 | ||
| 79 | +execute_process( | ||
| 80 | + COMMAND find ${STAGING_DIR} -type f -exec chmod 555 {} \; | ||
| 81 | + RESULT_VARIABLE CHMOD_RESULT | ||
| 82 | +) | ||
| 83 | +if(EXISTS "${STAGING_DIR}/${CMAKE_SYSTEM_PROCESSOR}-linux/include/version/ops_nn_version.h") | ||
| 84 | + execute_process(COMMAND chmod 440 "${STAGING_DIR}/${CMAKE_SYSTEM_PROCESSOR}-linux/include/version/ops_nn_version.h") | ||
| 85 | +endif() | ||
| 86 | +if(EXISTS "${STAGING_DIR}/${CMAKE_SYSTEM_PROCESSOR}-linux/conf/path.cfg") | ||
| 87 | + execute_process(COMMAND chmod 440 "${STAGING_DIR}/${CMAKE_SYSTEM_PROCESSOR}-linux/conf/path.cfg") | ||
| 88 | +endif() | ||
| 77 | # makeself打包 | 89 | # makeself打包 |
| 78 | file(STRINGS ${CPACK_CMAKE_BINARY_DIR}/makeself.txt script_output) | 90 | file(STRINGS ${CPACK_CMAKE_BINARY_DIR}/makeself.txt script_output) |
| 79 | string(REPLACE " " ";" makeself_param_string "${script_output}") | 91 | string(REPLACE " " ";" makeself_param_string "${script_output}") |
| @@ -108,17 +108,11 @@ function(pack_built_in) | |||
| 108 | DESTINATION share/info/ops_nn | 108 | DESTINATION share/info/ops_nn |
| 109 | ) | 109 | ) |
| 110 | install(FILES ${CONF_FILES} | 110 | install(FILES ${CONF_FILES} |
| 111 | - DESTINATION ops_nn/conf | 111 | + DESTINATION ${CMAKE_SYSTEM_PROCESSOR}-linux/conf |
| 112 | ) | 112 | ) |
| 113 | install(FILES ${PACKAGE_FILES} | 113 | install(FILES ${PACKAGE_FILES} |
| 114 | DESTINATION share/info/ops_nn/script | 114 | DESTINATION share/info/ops_nn/script |
| 115 | ) | 115 | ) |
| 116 | - install(FILES ${LATEST_MANGER_FILES} | ||
| 117 | - DESTINATION latest_manager | ||
| 118 | - ) | ||
| 119 | - install(DIRECTORY ${CMAKE_SOURCE_DIR}/scripts/package/latest_manager/scripts/ | ||
| 120 | - DESTINATION latest_manager | ||
| 121 | - ) | ||
| 122 | 116 | ||
| 123 | string(FIND "${ASCEND_COMPUTE_UNIT}" ";" SEMICOLON_INDEX) | 117 | string(FIND "${ASCEND_COMPUTE_UNIT}" ";" SEMICOLON_INDEX) |
| 124 | if (SEMICOLON_INDEX GREATER -1) | 118 | if (SEMICOLON_INDEX GREATER -1) |
| @@ -69,10 +69,21 @@ function(gen_es_nn_lib_ready) | |||
| 69 | OUTPUT_PATH ${CMAKE_BINARY_DIR}/es_packages | 69 | OUTPUT_PATH ${CMAKE_BINARY_DIR}/es_packages |
| 70 | ) | 70 | ) |
| 71 | install( | 71 | install( |
| 72 | - DIRECTORY ${CMAKE_BINARY_DIR}/es_packages | 72 | + FILES ${CMAKE_BINARY_DIR}/es_packages/lib64/libes_nn.so |
| 73 | - DESTINATION ${VERSION_INFO_INSTALL_DIR} | 73 | + DESTINATION ${VERSION_INFO_INSTALL_DIR}/lib64 |
| 74 | OPTIONAL | 74 | OPTIONAL |
| 75 | ) | 75 | ) |
| 76 | + install( | ||
| 77 | + DIRECTORY ${CMAKE_BINARY_DIR}/es_packages/include/es_nn | ||
| 78 | + DESTINATION ${VERSION_INFO_INSTALL_DIR}/include/es | ||
| 79 | + OPTIONAL | ||
| 80 | + ) | ||
| 81 | + install( | ||
| 82 | + DIRECTORY ${CMAKE_BINARY_DIR}/es_packages/whl/ | ||
| 83 | + DESTINATION ${WHL_INSTALL_DIR}/es_packages/whl | ||
| 84 | + OPTIONAL | ||
| 85 | + ) | ||
| 86 | + | ||
| 76 | endfunction() | 87 | endfunction() |
| 77 | 88 | ||
| 78 | # gen es_nn for custom | 89 | # gen es_nn for custom |
| @@ -85,22 +85,25 @@ if(ENABLE_CUSTOM) | |||
| 85 | set(PACK_CUSTOM_NAME "cann-ops-nn-${VENDOR_NAME}_linux-${ARCH}") | 85 | set(PACK_CUSTOM_NAME "cann-ops-nn-${VENDOR_NAME}_linux-${ARCH}") |
| 86 | else() | 86 | else() |
| 87 | # built-in package install path | 87 | # built-in package install path |
| 88 | - set(ACLNN_INC_INSTALL_DIR opp/include/aclnnop) | 88 | + set(OPP_PREFIX "opp") |
| 89 | - set(ACLNN_OP_INC_INSTALL_DIR opp/include/aclnnop/level2) | 89 | + |
| 90 | - set(ACLNN_LIB_INSTALL_DIR opp/built-in/op_impl/ai_core/tbe/op_api/lib/linux/${CMAKE_SYSTEM_PROCESSOR}) | 90 | + set(ACLNN_INC_INSTALL_DIR ${CMAKE_SYSTEM_PROCESSOR}-linux/include/aclnnop) |
| 91 | - set(OPS_INFO_INSTALL_DIR opp/built-in/op_impl/ai_core/tbe/config) | 91 | + set(ACLNN_OP_INC_INSTALL_DIR ${CMAKE_SYSTEM_PROCESSOR}-linux/include/aclnnop/level2) |
| 92 | - set(IMPL_INSTALL_DIR opp/built-in/op_impl/ai_core/tbe/impl/ops_nn/ascendc) | 92 | + set(ACLNN_LIB_INSTALL_DIR ${CMAKE_SYSTEM_PROCESSOR}-linux/lib64) |
| 93 | - set(IMPL_DYNAMIC_INSTALL_DIR opp/built-in/op_impl/ai_core/tbe/impl/ops_nn/dynamic) | 93 | + set(OPS_INFO_INSTALL_DIR ${OPP_PREFIX}/built-in/op_impl/ai_core/tbe/config) |
| 94 | - set(BIN_KERNEL_INSTALL_DIR opp/built-in/op_impl/ai_core/tbe/kernel) | 94 | + set(IMPL_INSTALL_DIR ${OPP_PREFIX}/built-in/op_impl/ai_core/tbe/impl/ops_nn/ascendc) |
| 95 | - set(BIN_KERNEL_CONFIG_INSTALL_DIR opp/built-in/op_impl/ai_core/tbe/kernel/config) | 95 | + set(IMPL_DYNAMIC_INSTALL_DIR ${OPP_PREFIX}/built-in/op_impl/ai_core/tbe/impl/ops_nn/dynamic) |
| 96 | - set(OPHOST_LIB_INSTALL_PATH opp/built-in/op_impl/ai_core/tbe/op_host/lib/linux/${CMAKE_SYSTEM_PROCESSOR}) | 96 | + set(BIN_KERNEL_INSTALL_DIR ${OPP_PREFIX}/built-in/op_impl/ai_core/tbe/kernel) |
| 97 | - set(AICPU_KERNEL_IMPL opp/built-in/op_impl/aicpu/kernel) | 97 | + set(BIN_KERNEL_CONFIG_INSTALL_DIR ${OPP_PREFIX}/built-in/op_impl/ai_core/tbe/kernel/config) |
| 98 | - set(AICPU_JSON_CONFIG opp/built-in/op_impl/aicpu/config) | 98 | + set(OPHOST_LIB_INSTALL_PATH ${OPP_PREFIX}/built-in/op_impl/ai_core/tbe/op_host/lib/linux/${CMAKE_SYSTEM_PROCESSOR}) |
| 99 | + set(AICPU_KERNEL_IMPL ${OPP_PREFIX}/built-in/op_impl/aicpu/kernel) | ||
| 100 | + set(AICPU_JSON_CONFIG ${OPP_PREFIX}/built-in/op_impl/aicpu/config) | ||
| 99 | set(OPTILING_LIB_INSTALL_DIR ${OPHOST_LIB_INSTALL_PATH}) | 101 | set(OPTILING_LIB_INSTALL_DIR ${OPHOST_LIB_INSTALL_PATH}) |
| 100 | - set(OPGRAPH_INC_INSTALL_DIR opp/built-in/op_graph/inc) | 102 | + set(OPGRAPH_INC_INSTALL_DIR ${OPP_PREFIX}/built-in/op_graph/inc) |
| 101 | - set(OPGRAPH_LIB_INSTALL_DIR opp/built-in/op_graph/lib/linux/${CMAKE_SYSTEM_PROCESSOR}) | 103 | + set(OPGRAPH_LIB_INSTALL_DIR ${OPP_PREFIX}/built-in/op_graph/lib/linux/${CMAKE_SYSTEM_PROCESSOR}) |
| 102 | - set(ONNX_PLUGIN_LIB_INSTALL_DIR opp/built-in/framework/onnx) | 104 | + set(ONNX_PLUGIN_LIB_INSTALL_DIR ${OPP_PREFIX}/built-in/framework/onnx) |
| 103 | - set(VERSION_INFO_INSTALL_DIR ops_nn) | 105 | + set(VERSION_INFO_INSTALL_DIR ${CMAKE_SYSTEM_PROCESSOR}-linux) |
| 106 | + set(WHL_INSTALL_DIR ops_nn) | ||
| 104 | endif() | 107 | endif() |
| 105 | 108 | ||
| 106 | # util path | 109 | # util path |
| @@ -215,6 +215,7 @@ for runfile in kernel_*.run; do | |||
| 215 | ensure_dir $dest_conf_ascend_first | 215 | ensure_dir $dest_conf_ascend_first |
| 216 | # config文件拷贝 | 216 | # config文件拷贝 |
| 217 | cp -v $config_src_dir/* $dest_conf_ascend_first/ | 217 | cp -v $config_src_dir/* $dest_conf_ascend_first/ |
| 218 | + chmod 555 "$dest_conf_ascend_first/binary_info_config.json" | ||
| 218 | first_run=false | 219 | first_run=false |
| 219 | else | 220 | else |
| 220 | # 非第一个文件:增量合并 | 221 | # 非第一个文件:增量合并 |
| @@ -244,6 +245,7 @@ for runfile in kernel_*.run; do | |||
| 244 | --output-file=binary_info_config.json | 245 | --output-file=binary_info_config.json |
| 245 | # 覆盖HOST中的config文件 | 246 | # 覆盖HOST中的config文件 |
| 246 | mv -f binary_info_config.json $target_json | 247 | mv -f binary_info_config.json $target_json |
| 248 | + chmod 555 "$target_json" | ||
| 247 | else | 249 | else |
| 248 | cp -v "$json_file" "$dest_conf_ascend"/ || \ | 250 | cp -v "$json_file" "$dest_conf_ascend"/ || \ |
| 249 | die "Warning: failed to copy $json_file" | 251 | die "Warning: failed to copy $json_file" |
| @@ -33,6 +33,7 @@ from .utils.pkg_utils import ( | |||
| 33 | ContainAsteriskError, FAIL, BLOCK_CONFIG_PATH, | 33 | ContainAsteriskError, FAIL, BLOCK_CONFIG_PATH, |
| 34 | BlockConfigError, EnvNotSupported, IllegalVersionDir, | 34 | BlockConfigError, EnvNotSupported, IllegalVersionDir, |
| 35 | InstallScriptFormatError, InstallScriptNotInPackageInfo, PackageError, | 35 | InstallScriptFormatError, InstallScriptNotInPackageInfo, PackageError, |
| 36 | + MultiPkgModError, MultiPkgSoftlinkError, PkgInnerSoftlinkNotAllowed, | ||
| 36 | ParseOsArchError, VersionInfoNotExist, config_feature_to_set, | 37 | ParseOsArchError, VersionInfoNotExist, config_feature_to_set, |
| 37 | flatten, star_pipe, merge_dict, yield_if | 38 | flatten, star_pipe, merge_dict, yield_if |
| 38 | ) | 39 | ) |
| @@ -103,6 +104,7 @@ class ParseEnv(NamedTuple): | |||
| 103 | parse_option: ParseOption | 104 | parse_option: ParseOption |
| 104 | delivery_dir: str | 105 | delivery_dir: str |
| 105 | top_dir: str | 106 | top_dir: str |
| 107 | + package_attr: Dict | ||
| 106 | 108 | ||
| 107 | 109 | ||
| 108 | class BlockElement(NamedTuple): | 110 | class BlockElement(NamedTuple): |
| @@ -137,6 +139,18 @@ class FileInfoParsedResult(NamedTuple): | |||
| 137 | expand_infos: List[Dict[str, str]] | 139 | expand_infos: List[Dict[str, str]] |
| 138 | 140 | ||
| 139 | 141 | ||
| 142 | +class PkgMod(NamedTuple): | ||
| 143 | + """包内文件权限。""" | ||
| 144 | + path: str | ||
| 145 | + mod: int | ||
| 146 | + | ||
| 147 | + | ||
| 148 | +class PkgSoftlink(NamedTuple): | ||
| 149 | + """包内软链接。""" | ||
| 150 | + dst_path: str | ||
| 151 | + src_path: str | ||
| 152 | + | ||
| 153 | + | ||
| 140 | class BlockConfig(NamedTuple): | 154 | class BlockConfig(NamedTuple): |
| 141 | """块配置。""" | 155 | """块配置。""" |
| 142 | 156 | ||
| @@ -144,16 +158,18 @@ class BlockConfig(NamedTuple): | |||
| 144 | move_files: List[FileInfo] | 158 | move_files: List[FileInfo] |
| 145 | expand_content_list: List[Dict] | 159 | expand_content_list: List[Dict] |
| 146 | package_content_list: List[Dict] | 160 | package_content_list: List[Dict] |
| 161 | + pkg_mods: List[PkgMod] | ||
| 162 | + pkg_softlinks: List[PkgSoftlink] | ||
| 147 | generate_infos: List[GenerateInfo] | 163 | generate_infos: List[GenerateInfo] |
| 148 | 164 | ||
| 149 | 165 | ||
| 150 | class PackerConfig(NamedTuple): | 166 | class PackerConfig(NamedTuple): |
| 151 | - """安装相关配置。""" | 167 | + """打包相关配置。""" |
| 152 | fill_is_common_path: Callable[[FileList], Iterator[FileItem]] | 168 | fill_is_common_path: Callable[[FileList], Iterator[FileItem]] |
| 153 | 169 | ||
| 154 | 170 | ||
| 155 | class XmlConfig(NamedTuple): | 171 | class XmlConfig(NamedTuple): |
| 156 | - """安装xml配置。""" | 172 | + """打包xml配置。""" |
| 157 | default_config: Dict[str, str] | 173 | default_config: Dict[str, str] |
| 158 | package_attr: PackageAttr | 174 | package_attr: PackageAttr |
| 159 | version_info: VersionInfo | 175 | version_info: VersionInfo |
| @@ -184,6 +200,14 @@ class XmlConfig(NamedTuple): | |||
| 184 | def package_content_list(self): | 200 | def package_content_list(self): |
| 185 | return self._collect_list('package_content_list') | 201 | return self._collect_list('package_content_list') |
| 186 | 202 | ||
| 203 | + | ||
| 204 | + def pkg_mods(self) -> List[PkgMod]: | ||
| 205 | + return self._collect_list('pkg_mods') | ||
| 206 | + | ||
| 207 | + | ||
| 208 | + def pkg_softlinks(self) -> List[PkgSoftlink]: | ||
| 209 | + return self._collect_list('pkg_softlinks') | ||
| 210 | + | ||
| 187 | 211 | ||
| 188 | def generate_infos(self) -> List[GenerateInfo]: | 212 | def generate_infos(self) -> List[GenerateInfo]: |
| 189 | return self._collect_list('generate_infos') | 213 | return self._collect_list('generate_infos') |
| @@ -207,7 +231,7 @@ def parse_package_info(package_info_ele: Optional[ET.Element]) -> Dict: | |||
| 207 | # gen_version_info: 是否生成version.info文件 | 231 | # gen_version_info: 是否生成version.info文件 |
| 208 | bool_attrs = ( | 232 | bool_attrs = ( |
| 209 | 'expand_asterisk', 'parallel', 'parallel_limit', 'package_check', 'check_features', | 233 | 'expand_asterisk', 'parallel', 'parallel_limit', 'package_check', 'check_features', |
| 210 | - 'use_move', 'gen_version_info' | 234 | + 'use_move', 'gen_version_info', 'copy_all' |
| 211 | ) | 235 | ) |
| 212 | bool_values = ('t', 'true', 'y', 'yes') | 236 | bool_values = ('t', 'true', 'y', 'yes') |
| 213 | if ele.tag in bool_attrs: | 237 | if ele.tag in bool_attrs: |
| @@ -311,6 +335,7 @@ def render_semver(package_name: str, version: str) -> Iterator[Tuple[str, str]]: | |||
| 311 | yield f'{package_name}_MAJOR', str(major) | 335 | yield f'{package_name}_MAJOR', str(major) |
| 312 | yield f'{package_name}_MINOR', str(minor) | 336 | yield f'{package_name}_MINOR', str(minor) |
| 313 | yield f'{package_name}_PATCH', str(patch) | 337 | yield f'{package_name}_PATCH', str(patch) |
| 338 | + | ||
| 314 | # 计算基础版本值(主版本*10^7 + 次版本*10^5 + 修订号*10^3) | 339 | # 计算基础版本值(主版本*10^7 + 次版本*10^5 + 修订号*10^3) |
| 315 | # 预留10^3空间用于预发布版本,确保不同正式版本区间不重叠 | 340 | # 预留10^3空间用于预发布版本,确保不同正式版本区间不重叠 |
| 316 | expr_buffer.write(f'({major} * 10000000) + ({minor} * 100000) + ({patch} * 1000)') | 341 | expr_buffer.write(f'({major} * 10000000) + ({minor} * 100000) + ({patch} * 1000)') |
| @@ -614,6 +639,11 @@ def evaluate_info(info: Dict[str, str], | |||
| 614 | replace_env_func = partial(replace_env, env_dict) | 639 | replace_env_func = partial(replace_env, env_dict) |
| 615 | add_dst_path_func = partial(join_dst_path, loaded_block.dst_path) | 640 | add_dst_path_func = partial(join_dst_path, loaded_block.dst_path) |
| 616 | 641 | ||
| 642 | + def split_pkg_softlink(key: str, value: str) -> Tuple[str, str]: | ||
| 643 | + if key == 'pkg_softlink': | ||
| 644 | + return key, value.split(';') | ||
| 645 | + return key, value | ||
| 646 | + | ||
| 617 | def upper_value(key: str, value: str) -> Tuple[str, str]: | 647 | def upper_value(key: str, value: str) -> Tuple[str, str]: |
| 618 | if key == 'configurable': | 648 | if key == 'configurable': |
| 619 | return key, value.upper() | 649 | return key, value.upper() |
| @@ -630,7 +660,7 @@ def evaluate_info(info: Dict[str, str], | |||
| 630 | return key, 'NA' | 660 | return key, 'NA' |
| 631 | return key, value | 661 | return key, value |
| 632 | 662 | ||
| 633 | - def merge_feature(key: str, value: str) -> Tuple[str, str]: | 663 | + def merge_feature(key: str, value: str) -> Tuple[str, Set[str]]: |
| 634 | if key in ('chip', 'feature'): | 664 | if key in ('chip', 'feature'): |
| 635 | config_features = config_feature_to_set(value, key) | 665 | config_features = config_feature_to_set(value, key) |
| 636 | return key, config_features | getattr(loaded_block, f'{key}s') | 666 | return key, config_features | getattr(loaded_block, f'{key}s') |
| @@ -682,7 +712,18 @@ def parse_dir_info_elements(loaded_block: LoadedBlockElement, | |||
| 682 | return dir_infos | 712 | return dir_infos |
| 683 | 713 | ||
| 684 | 714 | ||
| 685 | -def expand_dir(file_info: FileInfo, get_dst_target_func: Callable[[FileInfo], str]): | 715 | +def get_target_name(target_conf) -> str: |
| 716 | + """获取目标名。""" | ||
| 717 | + rename = target_conf.get('rename') | ||
| 718 | + if rename: | ||
| 719 | + return rename | ||
| 720 | + | ||
| 721 | + value_list = target_conf.get('value').split('/') | ||
| 722 | + target_name = value_list[-1] if value_list[-1] else value_list[-2] | ||
| 723 | + return target_name | ||
| 724 | + | ||
| 725 | + | ||
| 726 | +def expand_dir(file_info: FileInfo, get_dst_target_func: Callable[[FileInfo], str], env: ParseEnv): | ||
| 686 | """ | 727 | """ |
| 687 | 如果file_info中配置的路径是文件夹,需要展开到文件 | 728 | 如果file_info中配置的路径是文件夹,需要展开到文件 |
| 688 | """ | 729 | """ |
| @@ -705,8 +746,8 @@ def expand_dir(file_info: FileInfo, get_dst_target_func: Callable[[FileInfo], st | |||
| 705 | if subdir_mod is not None: | 746 | if subdir_mod is not None: |
| 706 | dir_info_copy['install_mod'] = subdir_mod | 747 | dir_info_copy['install_mod'] = subdir_mod |
| 707 | # 被展开的当前目录不需要设置softlink | 748 | # 被展开的当前目录不需要设置softlink |
| 708 | - dir_info_copy['install_softlink'] = 'NA' | 749 | + dir_info_copy['install_softlink'] = '' |
| 709 | - dir_info_copy['pkg_inner_softlink'] = 'NA' | 750 | + dir_info_copy['pkg_inner_softlink'] = '' |
| 710 | dir_info_list.append(dir_info_copy) | 751 | dir_info_list.append(dir_info_copy) |
| 711 | 752 | ||
| 712 | for root, dirs, files in os.walk(dst_target, followlinks=True): | 753 | for root, dirs, files in os.walk(dst_target, followlinks=True): |
| @@ -721,8 +762,9 @@ def expand_dir(file_info: FileInfo, get_dst_target_func: Callable[[FileInfo], st | |||
| 721 | if os.path.islink(dirname) and not need_dereference(file_info): | 762 | if os.path.islink(dirname) and not need_dereference(file_info): |
| 722 | copy_file_info = create_file_info(dirname, dst_target, file_info, name, target_name) | 763 | copy_file_info = create_file_info(dirname, dst_target, file_info, name, target_name) |
| 723 | # 被展开的子文件不需要设置softlink | 764 | # 被展开的子文件不需要设置softlink |
| 724 | - copy_file_info['install_softlink'] = 'NA' | 765 | + copy_file_info['install_softlink'] = '' |
| 725 | - copy_file_info['pkg_inner_softlink'] = 'NA' | 766 | + copy_file_info['pkg_inner_softlink'] = '' |
| 767 | + deal_with_copy_all(copy_file_info, env.package_attr) | ||
| 726 | file_info_list.append(copy_file_info) | 768 | file_info_list.append(copy_file_info) |
| 727 | dirs_to_remove.append(name) | 769 | dirs_to_remove.append(name) |
| 728 | continue | 770 | continue |
| @@ -733,8 +775,8 @@ def expand_dir(file_info: FileInfo, get_dst_target_func: Callable[[FileInfo], st | |||
| 733 | file_info.get('install_path', ''), target_name, relative_dirname | 775 | file_info.get('install_path', ''), target_name, relative_dirname |
| 734 | ) | 776 | ) |
| 735 | # 被展开的子目录不需要设置softlink | 777 | # 被展开的子目录不需要设置softlink |
| 736 | - dir_info_copy['install_softlink'] = 'NA' | 778 | + dir_info_copy['install_softlink'] = '' |
| 737 | - dir_info_copy['pkg_inner_softlink'] = 'NA' | 779 | + dir_info_copy['pkg_inner_softlink'] = '' |
| 738 | # 子目录的权限按照xml中subdir_mod配置,如果没有配置subdir_mod按照install_mod配置 | 780 | # 子目录的权限按照xml中subdir_mod配置,如果没有配置subdir_mod按照install_mod配置 |
| 739 | subdir_mod = file_info.get("subdir_mod", None) | 781 | subdir_mod = file_info.get("subdir_mod", None) |
| 740 | if subdir_mod is not None: | 782 | if subdir_mod is not None: |
| @@ -743,6 +785,7 @@ def expand_dir(file_info: FileInfo, get_dst_target_func: Callable[[FileInfo], st | |||
| 743 | for name in files: | 785 | for name in files: |
| 744 | filename = os.path.join(root, name) | 786 | filename = os.path.join(root, name) |
| 745 | copy_file_info = create_file_info(filename, dst_target, file_info, name, target_name) | 787 | copy_file_info = create_file_info(filename, dst_target, file_info, name, target_name) |
| 788 | + deal_with_copy_all(copy_file_info, env.package_attr) | ||
| 746 | file_info_list.append(copy_file_info) | 789 | file_info_list.append(copy_file_info) |
| 747 | 790 | ||
| 748 | for name in dirs_to_remove: | 791 | for name in dirs_to_remove: |
| @@ -821,14 +864,30 @@ def need_expand(file_info: FileInfo, get_dst_target_func: Callable[[FileInfo], s | |||
| 821 | return False | 864 | return False |
| 822 | 865 | ||
| 823 | 866 | ||
| 867 | +def deal_with_copy_all(file_info: FileInfo, package_attr: PackageAttr): | ||
| 868 | + """处理copy_all选项。""" | ||
| 869 | + if not package_attr.get('copy_all'): | ||
| 870 | + return | ||
| 871 | + if file_info.get('pkg_inner_softlink'): | ||
| 872 | + raise PkgInnerSoftlinkNotAllowed(file_info) | ||
| 873 | + file_info['dst_path'] = file_info['install_path'] | ||
| 874 | + if file_info.get('install_softlink'): | ||
| 875 | + file_info['pkg_softlink'] = file_info['install_softlink'].split(';') | ||
| 876 | + if file_info.get('install_mod'): | ||
| 877 | + file_info['pkg_mod'] = file_info['install_mod'] | ||
| 878 | + | ||
| 879 | + | ||
| 824 | def expand_file_info(parsed_result: FileInfoParsedResult, | 880 | def expand_file_info(parsed_result: FileInfoParsedResult, |
| 825 | use_move: bool, | 881 | use_move: bool, |
| 826 | - get_dst_target_func: Callable[[FileInfo], str]) -> FileInfoParsedResult: | 882 | + get_dst_target_func: Callable[[FileInfo], str], |
| 883 | + env: ParseEnv) -> FileInfoParsedResult: | ||
| 827 | """展开FileInfoParsedResult中的目录。""" | 884 | """展开FileInfoParsedResult中的目录。""" |
| 885 | + deal_with_copy_all(parsed_result.file_info, env.package_attr) | ||
| 886 | + | ||
| 828 | file_info = parsed_result.file_info | 887 | file_info = parsed_result.file_info |
| 829 | if need_expand(file_info, get_dst_target_func): | 888 | if need_expand(file_info, get_dst_target_func): |
| 830 | # 如果当前是文件夹,需要展开计算 | 889 | # 如果当前是文件夹,需要展开计算 |
| 831 | - expand_infos, dir_infos = expand_dir(file_info, get_dst_target_func) | 890 | + expand_infos, dir_infos = expand_dir(file_info, get_dst_target_func, env) |
| 832 | # 实测发现,对于opp包,整体目录cp的安装速度要快于目录中各文件mv | 891 | # 实测发现,对于opp包,整体目录cp的安装速度要快于目录中各文件mv |
| 833 | # 可能的原因是,cp遍历目录的速度较快,并且目录中的文件都比较小。mv依赖shell迭代目录中的所有文件。 | 892 | # 可能的原因是,cp遍历目录的速度较快,并且目录中的文件都比较小。mv依赖shell迭代目录中的所有文件。 |
| 834 | return FileInfoParsedResult( | 893 | return FileInfoParsedResult( |
| @@ -874,7 +933,8 @@ def parse_file_element(file_ele: ET.Element, | |||
| 874 | partial( | 933 | partial( |
| 875 | expand_file_info, | 934 | expand_file_info, |
| 876 | use_move=loaded_block.use_move, | 935 | use_move=loaded_block.use_move, |
| 877 | - get_dst_target_func=partial(get_dst_target, env=env) | 936 | + get_dst_target_func=partial(get_dst_target, env=env), |
| 937 | + env=env | ||
| 878 | ) | 938 | ) |
| 879 | ), | 939 | ), |
| 880 | ) | 940 | ) |
| @@ -901,6 +961,70 @@ def parse_file_info_elements(loaded_block: LoadedBlockElement, | |||
| 901 | ) | 961 | ) |
| 902 | 962 | ||
| 903 | 963 | ||
| 964 | +def get_path_infos(pkg_ele: ET.Element, | ||
| 965 | + default_config: Dict[str, str], | ||
| 966 | + loaded_block: LoadedBlockElement, | ||
| 967 | + env: ParseEnv) -> List[Dict[str, str]]: | ||
| 968 | + """获取路径信息。""" | ||
| 969 | + return invoke( | ||
| 970 | + pipe( | ||
| 971 | + list, | ||
| 972 | + partial(map, attrgetter('attrib')), | ||
| 973 | + partial(map, partial(merge_dict, default_config)), | ||
| 974 | + partial( | ||
| 975 | + map, | ||
| 976 | + partial(evaluate_info, loaded_block=loaded_block, env_dict=env.env_dict, pkg=True) | ||
| 977 | + ), | ||
| 978 | + ), | ||
| 979 | + pkg_ele | ||
| 980 | + ) | ||
| 981 | + | ||
| 982 | + | ||
| 983 | +def get_path_infos_by_eles(pkg_eles: List[ET.Element], | ||
| 984 | + default_config: Dict[str, str], | ||
| 985 | + loaded_block: LoadedBlockElement, | ||
| 986 | + env: ParseEnv) -> List[Dict[str, str]]: | ||
| 987 | + """根据节点列表获取路径信息。""" | ||
| 988 | + return flatten([ | ||
| 989 | + get_path_infos(pkg_ele, default_config, loaded_block, env) | ||
| 990 | + for pkg_ele in pkg_eles | ||
| 991 | + ]) | ||
| 992 | + | ||
| 993 | + | ||
| 994 | +def parse_pkg_mods(path_infos: List[Dict[str, str]]) -> List[PkgMod]: | ||
| 995 | + """解析pkg元素。""" | ||
| 996 | + return [ | ||
| 997 | + PkgMod( | ||
| 998 | + path_info['value'], | ||
| 999 | + int(path_info['pkg_mod'], 8) | ||
| 1000 | + ) | ||
| 1001 | + for path_info in path_infos | ||
| 1002 | + ] | ||
| 1003 | + | ||
| 1004 | + | ||
| 1005 | +def parse_pkg_softlinks(path_infos: List[Dict[str, str]]) -> List[PkgSoftlink]: | ||
| 1006 | + """解析pkg_softlink元素。""" | ||
| 1007 | + return [ | ||
| 1008 | + PkgSoftlink( | ||
| 1009 | + dst_path=path_info['value'], | ||
| 1010 | + src_path=path_info['src_path'], | ||
| 1011 | + ) | ||
| 1012 | + for path_info in path_infos | ||
| 1013 | + ] | ||
| 1014 | + | ||
| 1015 | + | ||
| 1016 | +def parse_paths_element(root_ele: ET.Element, | ||
| 1017 | + tag_name: str, | ||
| 1018 | + ex: PackageError, | ||
| 1019 | + parse_func: Callable[[List[ET.Element]], List]) -> List: | ||
| 1020 | + """解析路径列表元素。""" | ||
| 1021 | + tag_eles = root_ele.findall(tag_name) | ||
| 1022 | + if len(tag_eles) > 1: | ||
| 1023 | + raise ex | ||
| 1024 | + | ||
| 1025 | + return parse_func(tag_eles) | ||
| 1026 | + | ||
| 1027 | + | ||
| 904 | def unique_infos(infos: Iterable) -> List[Dict[str, str]]: | 1028 | def unique_infos(infos: Iterable) -> List[Dict[str, str]]: |
| 905 | """infos去重。""" | 1029 | """infos去重。""" |
| 906 | cache: Set[str] = set() | 1030 | cache: Set[str] = set() |
| @@ -921,23 +1045,41 @@ def parse_block_config(loaded_block: LoadedBlockElement, | |||
| 921 | default_config = copy.copy(loaded_block.attrs) | 1045 | default_config = copy.copy(loaded_block.attrs) |
| 922 | default_config.update(loaded_block.root_ele.attrib) | 1046 | default_config.update(loaded_block.root_ele.attrib) |
| 923 | 1047 | ||
| 924 | - dir_infos = parse_dir_info_elements( | 1048 | + dir_infos = parse_dir_info_elements(loaded_block, default_config, |
| 925 | - loaded_block, | 1049 | + package_attr, parse_env, |
| 926 | - default_config, | ||
| 927 | - package_attr, | ||
| 928 | - parse_env, | ||
| 929 | ) | 1050 | ) |
| 930 | file_info_results = list( | 1051 | file_info_results = list( |
| 931 | chain( | 1052 | chain( |
| 932 | - parse_file_info_elements( | 1053 | + parse_file_info_elements(loaded_block, default_config, |
| 933 | - loaded_block, | 1054 | + package_attr, parse_env, |
| 934 | - default_config, | ||
| 935 | - package_attr, | ||
| 936 | - parse_env, | ||
| 937 | ) | 1055 | ) |
| 938 | ) | 1056 | ) |
| 939 | ) | 1057 | ) |
| 940 | 1058 | ||
| 1059 | + get_path_infos_func = partial( | ||
| 1060 | + get_path_infos_by_eles, | ||
| 1061 | + default_config=default_config, | ||
| 1062 | + loaded_block=loaded_block, | ||
| 1063 | + env=parse_env | ||
| 1064 | + ) | ||
| 1065 | + | ||
| 1066 | + parse_pkg_mods_func = pipe(get_path_infos_func, parse_pkg_mods) | ||
| 1067 | + pkg_mods = parse_paths_element( | ||
| 1068 | + loaded_block.root_ele, | ||
| 1069 | + 'pkg_mod', | ||
| 1070 | + MultiPkgModError(), | ||
| 1071 | + # tar.gz才处理pkg_mod元素 | ||
| 1072 | + lambda x: parse_pkg_mods_func(x) if package_attr.get('suffix') == 'tar.gz' else [], | ||
| 1073 | + ) | ||
| 1074 | + | ||
| 1075 | + parse_pkg_softlinks_func = pipe(get_path_infos_func, parse_pkg_softlinks) | ||
| 1076 | + pkg_softlinks = parse_paths_element( | ||
| 1077 | + loaded_block.root_ele, | ||
| 1078 | + 'pkg_softlink', | ||
| 1079 | + MultiPkgSoftlinkError(), | ||
| 1080 | + parse_pkg_softlinks_func, | ||
| 1081 | + ) | ||
| 1082 | + | ||
| 941 | generate_infos = parse_generate_infos_by_loaded_block( | 1083 | generate_infos = parse_generate_infos_by_loaded_block( |
| 942 | loaded_block, default_config, parse_env.env_dict | 1084 | loaded_block, default_config, parse_env.env_dict |
| 943 | ) | 1085 | ) |
| @@ -951,6 +1093,8 @@ def parse_block_config(loaded_block: LoadedBlockElement, | |||
| 951 | list(flatten(map(attrgetter('move_infos'), file_info_results))), | 1093 | list(flatten(map(attrgetter('move_infos'), file_info_results))), |
| 952 | list(flatten(map(attrgetter('expand_infos'), file_info_results))), | 1094 | list(flatten(map(attrgetter('expand_infos'), file_info_results))), |
| 953 | [result.file_info for result in file_info_results if result.file_info], | 1095 | [result.file_info for result in file_info_results if result.file_info], |
| 1096 | + pkg_mods, | ||
| 1097 | + pkg_softlinks, | ||
| 954 | generate_infos, | 1098 | generate_infos, |
| 955 | ) | 1099 | ) |
| 956 | 1100 | ||
| @@ -1018,7 +1162,6 @@ def get_block_filepath(block_element: BlockElement) -> str: | |||
| 1018 | def load_block_element(package_attr: PackageAttr, | 1162 | def load_block_element(package_attr: PackageAttr, |
| 1019 | block_element: BlockElement) -> LoadedBlockElement: | 1163 | block_element: BlockElement) -> LoadedBlockElement: |
| 1020 | """加载块配置。""" | 1164 | """加载块配置。""" |
| 1021 | - | ||
| 1022 | def with_filepath(block_xml: str): | 1165 | def with_filepath(block_xml: str): |
| 1023 | if not os.path.exists(block_xml): | 1166 | if not os.path.exists(block_xml): |
| 1024 | raise BlockConfigError(f"block's config xml {block_xml} does not exist!") | 1167 | raise BlockConfigError(f"block's config xml {block_xml} does not exist!") |
| @@ -1123,7 +1266,7 @@ def parse_xml_config(filepath: str, | |||
| 1123 | sys.exit(FAIL) | 1266 | sys.exit(FAIL) |
| 1124 | 1267 | ||
| 1125 | parse_env = ParseEnv( | 1268 | parse_env = ParseEnv( |
| 1126 | - env_dict, parse_option, delivery_dir, pkg_utils.TOP_SOURCE_DIR | 1269 | + env_dict, parse_option, delivery_dir, pkg_utils.TOP_SOURCE_DIR, package_attr |
| 1127 | ) | 1270 | ) |
| 1128 | 1271 | ||
| 1129 | blocks = parse_blocks( | 1272 | blocks = parse_blocks( |
| @@ -25,7 +25,7 @@ DELIVERY_PATH = "build/_CPack_Packages/makeself_staging" | |||
| 25 | CONFIG_SCRIPT_PATH = 'package' | 25 | CONFIG_SCRIPT_PATH = 'package' |
| 26 | BLOCK_CONFIG_PATH = 'package/module' | 26 | BLOCK_CONFIG_PATH = 'package/module' |
| 27 | 27 | ||
| 28 | -SUCCESS = 0 | 28 | +SUCC = 0 |
| 29 | FAIL = -1 | 29 | FAIL = -1 |
| 30 | 30 | ||
| 31 | 31 | ||
| @@ -44,6 +44,14 @@ class BlockConfigError(PackageError): | |||
| 44 | """块配置错误异常。""" | 44 | """块配置错误异常。""" |
| 45 | 45 | ||
| 46 | 46 | ||
| 47 | +class MultiPkgModError(PackageError): | ||
| 48 | + """多个pkg_mod元素报错。""" | ||
| 49 | + | ||
| 50 | + | ||
| 51 | +class MultiPkgSoftlinkError(PackageError): | ||
| 52 | + """多个pkg_softlink元素报错。""" | ||
| 53 | + | ||
| 54 | + | ||
| 47 | class ParseOsArchError(PackageError): | 55 | class ParseOsArchError(PackageError): |
| 48 | """解析os_arch失败异常。""" | 56 | """解析os_arch失败异常。""" |
| 49 | 57 | ||
| @@ -68,6 +76,10 @@ class UnknownOperateTypeError(PackageError): | |||
| 68 | """未知的操作类型。""" | 76 | """未知的操作类型。""" |
| 69 | 77 | ||
| 70 | 78 | ||
| 79 | +class PkgInnerSoftlinkNotAllowed(PackageError): | ||
| 80 | + """不允许使用pkg_inner_softlink。""" | ||
| 81 | + | ||
| 82 | + | ||
| 71 | class PackageNameEmptyError(PackageError): | 83 | class PackageNameEmptyError(PackageError): |
| 72 | """包名为空错误。""" | 84 | """包名为空错误。""" |
| 73 | 85 | ||
| @@ -961,21 +961,26 @@ do_copy_files() { | |||
| 961 | local feature_param="$5" | 961 | local feature_param="$5" |
| 962 | local total_uninstall_path exec_mode ret | 962 | local total_uninstall_path exec_mode ret |
| 963 | 963 | ||
| 964 | - if [ "$PARALLEL" = "true" ]; then | 964 | + if [ "$COPY_ALL" = "y" ]; then |
| 965 | - exec_mode="concurrency" | 965 | + cp -af * "$install_path" |
| 966 | + ret="$?" && [ $ret -ne 0 ] && return $ret | ||
| 966 | else | 967 | else |
| 967 | - exec_mode="normal" | 968 | + if [ "$PARALLEL" = "true" ]; then |
| 969 | + exec_mode="concurrency" | ||
| 970 | + else | ||
| 971 | + exec_mode="normal" | ||
| 972 | + fi | ||
| 973 | + if [ "${USE_MOVE}" = "true" ]; then | ||
| 974 | + foreach_filelist "NA" "copy_files" "$install_type" "$install_path" "move" "$filelist_path" "${feature_param}" \ | ||
| 975 | + "no" "$exec_mode" "--move" | ||
| 976 | + foreach_filelist "NA" "copy_files" "$install_type" "$install_path" "copy copy_entity" "$filelist_path" "${feature_param}" \ | ||
| 977 | + "no" "$exec_mode" | ||
| 978 | + else | ||
| 979 | + foreach_filelist "NA" "copy_files" "$install_type" "$install_path" "copy copy_entity move" "$filelist_path" "${feature_param}" \ | ||
| 980 | + "no" "$exec_mode" | ||
| 981 | + fi | ||
| 982 | + ret="$?" && [ $ret -ne 0 ] && return $ret | ||
| 968 | fi | 983 | fi |
| 969 | - if [ "${USE_MOVE}" = "true" ]; then | ||
| 970 | - foreach_filelist "NA" "copy_files" "$install_type" "$install_path" "move" "$filelist_path" "${feature_param}" \ | ||
| 971 | - "no" "$exec_mode" "--move" | ||
| 972 | - foreach_filelist "NA" "copy_files" "$install_type" "$install_path" "copy copy_entity" "$filelist_path" "${feature_param}" \ | ||
| 973 | - "no" "$exec_mode" | ||
| 974 | - else | ||
| 975 | - foreach_filelist "NA" "copy_files" "$install_type" "$install_path" "copy copy_entity move" "$filelist_path" "${feature_param}" \ | ||
| 976 | - "no" "$exec_mode" | ||
| 977 | - fi | ||
| 978 | - ret="$?" && [ $ret -ne 0 ] && return $ret | ||
| 979 | 984 | ||
| 980 | if [ "${package}" != "" ] && [ "${SET_CANN_UNINSTALL}" = "y" ]; then | 985 | if [ "${package}" != "" ] && [ "${SET_CANN_UNINSTALL}" = "y" ]; then |
| 981 | add_cann_uninstall_package "${install_path}" "${package}" "${USERNAME}" "${USERGROUP}" "${INSTALL_FOR_ALL}" | 986 | add_cann_uninstall_package "${install_path}" "${package}" "${USERNAME}" "${USERGROUP}" "${INSTALL_FOR_ALL}" |
| @@ -1057,8 +1062,10 @@ do_chmod_file_dir() { | |||
| 1057 | local package="$5" | 1062 | local package="$5" |
| 1058 | local ret | 1063 | local ret |
| 1059 | 1064 | ||
| 1060 | - foreach_filelist "NA" "change_mod_and_own_files" "$install_type" "$install_path" "copy del move" "$filelist_path" "${feature_param}" "no" "concurrency" | 1065 | + if [ "$COPY_ALL" != "y" ] || [ "$INSTALL_FOR_ALL" = "y" ]; then |
| 1061 | - ret="$?" && [ $ret -ne 0 ] && return $ret | 1066 | + foreach_filelist "NA" "change_mod_and_own_files" "$install_type" "$install_path" "copy del move" "$filelist_path" "${feature_param}" "no" "concurrency" |
| 1067 | + ret="$?" && [ $ret -ne 0 ] && return $ret | ||
| 1068 | + fi | ||
| 1062 | 1069 | ||
| 1063 | foreach_filelist "NA" "change_mod_and_own_files_recursive" "$install_type" "$install_path" "copy_entity" "$filelist_path" "${feature_param}" "no" "concurrency" | 1070 | foreach_filelist "NA" "change_mod_and_own_files_recursive" "$install_type" "$install_path" "copy_entity" "$filelist_path" "${feature_param}" "no" "concurrency" |
| 1064 | ret="$?" && [ $ret -ne 0 ] && return $ret | 1071 | ret="$?" && [ $ret -ne 0 ] && return $ret |
| @@ -1945,7 +1952,7 @@ IS_RECREATE_SOFTLINK="" | |||
| 1945 | WITH_DOCKER_ROOT_PREFIX="" | 1952 | WITH_DOCKER_ROOT_PREFIX="" |
| 1946 | FEATURE_EXCLUDE_ALL="n" | 1953 | FEATURE_EXCLUDE_ALL="n" |
| 1947 | REMOVE_INSTALL_INFO="n" # 卸载时移除ascend_install.info文件 | 1954 | REMOVE_INSTALL_INFO="n" # 卸载时移除ascend_install.info文件 |
| 1948 | -USE_SHARE_INFO="n" # 包信息安装到share/info目录下 | 1955 | +USE_SHARE_INFO="n" |
| 1949 | CHIP="all" | 1956 | CHIP="all" |
| 1950 | FEATURE="all" | 1957 | FEATURE="all" |
| 1951 | INCREMENT="n" # 增量安装 | 1958 | INCREMENT="n" # 增量安装 |
| @@ -1964,9 +1971,14 @@ DOCKER_ROOT="" | |||
| 1964 | INSTALL_PATH="" | 1971 | INSTALL_PATH="" |
| 1965 | # 输入的latest_dir | 1972 | # 输入的latest_dir |
| 1966 | INPUT_LATEST_DIR="" | 1973 | INPUT_LATEST_DIR="" |
| 1974 | +COPY_ALL="" | ||
| 1967 | 1975 | ||
| 1968 | while true; do | 1976 | while true; do |
| 1969 | case "$1" in | 1977 | case "$1" in |
| 1978 | + --copy_all) | ||
| 1979 | + COPY_ALL="y" | ||
| 1980 | + shift | ||
| 1981 | + ;; | ||
| 1970 | --spc-install | -i) | 1982 | --spc-install | -i) |
| 1971 | OPERATE_TYPE="spc_install" | 1983 | OPERATE_TYPE="spc_install" |
| 1972 | shift | 1984 | shift |
| @@ -1,6 +1,6 @@ | |||
| 1 | 1 | ||
| 2 | <block name="EngineeringFiles" install_own="$username:$usergroup" install_mod="440" install_type="all"> | 2 | <block name="EngineeringFiles" install_own="$username:$usergroup" install_mod="440" install_type="all"> |
| 3 | - <file_info value="conf" copy_type="source" src_path="build/release/config/common" dst_path="conf" install_path="$(TARGET_ENV)/conf"> | 3 | + <file_info value="conf" copy_type="source" src_path="build/release/config/common" dst_path="$(TARGET_ENV)/conf" install_path="$(TARGET_ENV)/conf"> |
| 4 | <file value="path.cfg"/> | 4 | <file value="path.cfg"/> |
| 5 | </file_info> | 5 | </file_info> |
| 6 | </block> | 6 | </block> |
| @@ -1,51 +1,51 @@ | |||
| 1 | 1 | ||
| 2 | <block name="OpsNNInfO" copy_type="delivery" src_path="lib/" dst_path="" install_path="" install_own="$username:$usergroup" install_mod="550" install_type="all"> | 2 | <block name="OpsNNInfO" copy_type="delivery" src_path="lib/" dst_path="" install_path="" install_own="$username:$usergroup" install_mod="550" install_type="all"> |
| 3 | 3 | ||
| 4 | - <file_info value="aclnn_api" copy_type="delivery" src_path="built-in/op_api" dst_path="built-in/op_impl/ai_core/tbe/op_api/lib/linux/$(ARCH)" install_path="$(TARGET_ENV)/lib64"> | 4 | + <file_info value="aclnn_api" copy_type="delivery" src_path="built-in/op_api" dst_path="$(TARGET_ENV)/lib64" install_path="$(TARGET_ENV)/lib64"> |
| 5 | <file value="libopapi_nn.so" optional="true" install_mod="555"/> | 5 | <file value="libopapi_nn.so" optional="true" install_mod="555"/> |
| 6 | </file_info> | 6 | </file_info> |
| 7 | 7 | ||
| 8 | - <file_info value="aclnn_inc" copy_type="delivery" src_path="built-in/op_api" dst_path="include" install_path="$(TARGET_ENV)/include"> | 8 | + <file_info value="aclnn_inc" copy_type="delivery" src_path="built-in/op_api" dst_path="$(TARGET_ENV)/include" install_path="$(TARGET_ENV)/include"> |
| 9 | <file value="aclnnop" optional="true" install_mod="555"/> | 9 | <file value="aclnnop" optional="true" install_mod="555"/> |
| 10 | </file_info> | 10 | </file_info> |
| 11 | 11 | ||
| 12 | - <file_info value="op_graph" copy_type="delivery" src_path="" dst_path="built-in/op_graph/inc" install_path="opp/built-in/op_graph/inc" install_type="all"> | 12 | + <file_info value="op_graph" copy_type="delivery" src_path="" dst_path="opp/built-in/op_graph/inc" install_path="opp/built-in/op_graph/inc" install_type="all"> |
| 13 | <file value="ops_proto_nn.h" install_mod="555"/> | 13 | <file value="ops_proto_nn.h" install_mod="555"/> |
| 14 | </file_info> | 14 | </file_info> |
| 15 | 15 | ||
| 16 | - <file_info value="ops_info" src_path="op_host" dst_path="built-in/op_impl/ai_core/tbe" install_path="opp/built-in/op_impl/ai_core/tbe"> | 16 | + <file_info value="ops_info" src_path="op_host" dst_path="opp/built-in/op_impl/ai_core/tbe" install_path="opp/built-in/op_impl/ai_core/tbe"> |
| 17 | <file value="config" install_mod="555"/> | 17 | <file value="config" install_mod="555"/> |
| 18 | </file_info> | 18 | </file_info> |
| 19 | 19 | ||
| 20 | - <file_info value="rtkb" copy_type="source" src_path="" dst_path="built-in/data" install_path="opp/built-in/data"> | 20 | + <file_info value="rtkb" copy_type="source" src_path="" dst_path="opp/built-in/data" install_path="opp/built-in/data"> |
| 21 | <file value="op" optional="true" install_mod="555"/> | 21 | <file value="op" optional="true" install_mod="555"/> |
| 22 | </file_info> | 22 | </file_info> |
| 23 | 23 | ||
| 24 | - <file_info value="op_graph" src_path="op_host" dst_path="built-in/op_graph/lib/linux/$(ARCH)" install_path="opp/built-in/op_graph/lib/linux/$(ARCH)"> | 24 | + <file_info value="op_graph" src_path="op_host" dst_path="opp/built-in/op_graph/lib/linux/$(ARCH)" install_path="opp/built-in/op_graph/lib/linux/$(ARCH)"> |
| 25 | <file value="libopgraph_nn.so" file_type="shared" install_mod="555"/> | 25 | <file value="libopgraph_nn.so" file_type="shared" install_mod="555"/> |
| 26 | </file_info> | 26 | </file_info> |
| 27 | 27 | ||
| 28 | - <file_info value="op_host" src_path="op_host" dst_path="built-in/op_impl/ai_core/tbe/op_host/lib/linux/$(ARCH)" install_path="opp/built-in/op_impl/ai_core/tbe/op_host/lib/linux/$(ARCH)"> | 28 | + <file_info value="op_host" src_path="op_host" dst_path="opp/built-in/op_impl/ai_core/tbe/op_host/lib/linux/$(ARCH)" install_path="opp/built-in/op_impl/ai_core/tbe/op_host/lib/linux/$(ARCH)"> |
| 29 | <file value="libophost_nn.so" file_type="shared" install_mod="555"/> | 29 | <file value="libophost_nn.so" file_type="shared" install_mod="555"/> |
| 30 | </file_info> | 30 | </file_info> |
| 31 | 31 | ||
| 32 | - <file_info value="kernel_src" src_path="op_host" dst_path="built-in/op_impl/ai_core/tbe/impl" install_path="opp/built-in/op_impl/ai_core/tbe/impl"> | 32 | + <file_info value="kernel_src" src_path="op_host" dst_path="opp/built-in/op_impl/ai_core/tbe/impl" install_path="opp/built-in/op_impl/ai_core/tbe/impl"> |
| 33 | <file value="ops_nn" entity="true" install_mod="555"/> | 33 | <file value="ops_nn" entity="true" install_mod="555"/> |
| 34 | </file_info> | 34 | </file_info> |
| 35 | 35 | ||
| 36 | - <file_info value="kernel" src_path="op_host" dst_path="built-in/op_impl/ai_core/tbe" install_path="opp/built-in/op_impl/ai_core/tbe"> | 36 | + <file_info value="kernel" src_path="op_host" dst_path="opp/built-in/op_impl/ai_core/tbe" install_path="opp/built-in/op_impl/ai_core/tbe"> |
| 37 | <file value="kernel" optional="true" install_mod="555"/> | 37 | <file value="kernel" optional="true" install_mod="555"/> |
| 38 | </file_info> | 38 | </file_info> |
| 39 | 39 | ||
| 40 | - <file_info value="aicpu_config" src_path="op_host" dst_path="built-in/op_impl/aicpu/config" install_path="opp/built-in/op_impl/aicpu/config"> | 40 | + <file_info value="aicpu_config" src_path="op_host" dst_path="opp/built-in/op_impl/aicpu/config" install_path="opp/built-in/op_impl/aicpu/config"> |
| 41 | <file value="aicpu_nn.json" entity="true" optional="true" install_mod="555"/> | 41 | <file value="aicpu_nn.json" entity="true" optional="true" install_mod="555"/> |
| 42 | </file_info> | 42 | </file_info> |
| 43 | 43 | ||
| 44 | - <file_info value="aicpu_kernel" src_path="op_host" dst_path="built-in/op_impl/aicpu/kernel" install_path="opp/built-in/op_impl/aicpu/kernel"> | 44 | + <file_info value="aicpu_kernel" src_path="op_host" dst_path="opp/built-in/op_impl/aicpu/kernel" install_path="opp/built-in/op_impl/aicpu/kernel"> |
| 45 | <file value="libnn_aicpu_kernels.so" entity="true" optional="true" install_mod="555"/> | 45 | <file value="libnn_aicpu_kernels.so" entity="true" optional="true" install_mod="555"/> |
| 46 | </file_info> | 46 | </file_info> |
| 47 | 47 | ||
| 48 | - <file_info value="op_nn_onnx_plugin_lib" src_path="" dst_path="built-in/framework/onnx" install_path="opp/built-in/framework/onnx"> | 48 | + <file_info value="op_nn_onnx_plugin_lib" src_path="" dst_path="opp/built-in/framework/onnx" install_path="opp/built-in/framework/onnx"> |
| 49 | <file value="libop_nn_onnx_plugin.so" entity="true" optional="true" install_mod="555"/> | 49 | <file value="libop_nn_onnx_plugin.so" entity="true" optional="true" install_mod="555"/> |
| 50 | </file_info> | 50 | </file_info> |
| 51 | 51 | ||
| @@ -9,8 +9,9 @@ | |||
| 9 | <version>package/ops_nn/version.xml</version> | 9 | <version>package/ops_nn/version.xml</version> |
| 10 | <cleanup>share/info/ops_nn/script/cleanup.sh</cleanup> | 10 | <cleanup>share/info/ops_nn/script/cleanup.sh</cleanup> |
| 11 | <check_features>true</check_features> | 11 | <check_features>true</check_features> |
| 12 | + <copy_all>true</copy_all> | ||
| 12 | </package_info> | 13 | </package_info> |
| 13 | - <generate_info value="ops_nn_version.h" dst_path="share/info/ops_nn" install_path="$(TARGET_ENV)/include/version" install_mod="440" install_type="devel" generator="version_header"> | 14 | + <generate_info value="ops_nn_version.h" dst_path="$(TARGET_ENV)/include/version" install_path="$(TARGET_ENV)/include/version" install_mod="440" install_type="devel" generator="version_header"> |
| 14 | <OPS_NN_VERSION>$(ASCEND_VER)</OPS_NN_VERSION> | 15 | <OPS_NN_VERSION>$(ASCEND_VER)</OPS_NN_VERSION> |
| 15 | <OPS_NN_TIMESTAMP>$(TIMESTAMP_NO)</OPS_NN_TIMESTAMP> | 16 | <OPS_NN_TIMESTAMP>$(TIMESTAMP_NO)</OPS_NN_TIMESTAMP> |
| 16 | </generate_info> | 17 | </generate_info> |
| @@ -25,22 +26,22 @@ | |||
| 25 | <file value="version.info"/> | 26 | <file value="version.info"/> |
| 26 | </file_info> | 27 | </file_info> |
| 27 | <file_info value="ops_es_packages_lib" copy_type="delivery" src_path="" | 28 | <file_info value="ops_es_packages_lib" copy_type="delivery" src_path="" |
| 28 | - dst_path="ops_nn/es_packages/lib64" | 29 | + dst_path="$(TARGET_ENV)/lib64" |
| 29 | install_path="$(TARGET_ENV)/lib64" install_mod="555"> | 30 | install_path="$(TARGET_ENV)/lib64" install_mod="555"> |
| 30 | <file value="libes_nn.so" | 31 | <file value="libes_nn.so" |
| 31 | file_type="shared"/> | 32 | file_type="shared"/> |
| 32 | </file_info> | 33 | </file_info> |
| 33 | <file_info copy_type="source" src_path="" | 34 | <file_info copy_type="source" src_path="" |
| 34 | - dst_path="ops_nn/es_packages/include" | 35 | + dst_path="$(TARGET_ENV)/include/es" |
| 35 | install_path="$(TARGET_ENV)/include/es" install_type="all"> | 36 | install_path="$(TARGET_ENV)/include/es" install_type="all"> |
| 36 | <file value="es_nn" install_mod="555" entity="true"/> | 37 | <file value="es_nn" install_mod="555" entity="true"/> |
| 37 | </file_info> | 38 | </file_info> |
| 38 | <!--block_info--> | 39 | <!--block_info--> |
| 39 | - <block_info dependtree="false" dst_path="ops_nn" block_conf_path="ascend"> | 40 | + <block_info dependtree="false" dst_path="" block_conf_path="ascend"> |
| 40 | <block name="EngineeringCommon"/> | 41 | <block name="EngineeringCommon"/> |
| 41 | <block name="EngineeringFiles"/> | 42 | <block name="EngineeringFiles"/> |
| 42 | </block_info> | 43 | </block_info> |
| 43 | - <block_info dependtree="false" dst_path="opp" block_conf_path="ascend"> | 44 | + <block_info dependtree="false" dst_path="" block_conf_path="ascend"> |
| 44 | <block name="OpsNNInfo"/> | 45 | <block name="OpsNNInfo"/> |
| 45 | </block_info> | 46 | </block_info> |
| 46 | <!--dir_info--> | 47 | <!--dir_info--> |
| @@ -348,6 +348,10 @@ install_es_whl() | |||
| 348 | local whl_install_dir_path="${TARGET_VERSION_DIR}/python/site-packages" | 348 | local whl_install_dir_path="${TARGET_VERSION_DIR}/python/site-packages" |
| 349 | chmod u+w "${whl_install_dir_path}" 2> /dev/null | 349 | chmod u+w "${whl_install_dir_path}" 2> /dev/null |
| 350 | install_whl_package "${es_whl_path}" "${python_es_whl_name}" "${whl_install_dir_path}" | 350 | install_whl_package "${es_whl_path}" "${python_es_whl_name}" "${whl_install_dir_path}" |
| 351 | + | ||
| 352 | + if [ -d "${TARGET_VERSION_DIR}/ops_nn" ]; then | ||
| 353 | + rm -rf "${TARGET_VERSION_DIR}/ops_nn" | ||
| 354 | + fi | ||
| 351 | } | 355 | } |
| 352 | 356 | ||
| 353 | add_init_py() { | 357 | add_init_py() { |
| @@ -379,7 +383,7 @@ install_opp() { | |||
| 379 | update_install_infos "${TARGET_USERNAME}" "${TARGET_USERGROUP}" "${INSTALL_TYPE}" "${relative_path_val}" | 383 | update_install_infos "${TARGET_USERNAME}" "${TARGET_USERGROUP}" "${INSTALL_TYPE}" "${relative_path_val}" |
| 380 | log_with_errorlevel "$?" "error" "[ERROR]: ERR_NO:${INSTALL_FAILED};ERR_DES:Update opp install info failed." | 384 | log_with_errorlevel "$?" "error" "[ERROR]: ERR_NO:${INSTALL_FAILED};ERR_DES:Update opp install info failed." |
| 381 | 385 | ||
| 382 | - bash "${COMMON_PARSER_FILE}" --package="${OPP_PLATFORM_DIR}" --install --username="${TARGET_USERNAME}" \ | 386 | + bash "${COMMON_PARSER_FILE}" --copy_all --package="${OPP_PLATFORM_DIR}" --install --username="${TARGET_USERNAME}" \ |
| 383 | --usergroup="${TARGET_USERGROUP}" --set-cann-uninstall --version=$RUN_PKG_VERSION \ | 387 | --usergroup="${TARGET_USERGROUP}" --set-cann-uninstall --version=$RUN_PKG_VERSION \ |
| 384 | --use-share-info --version-dir=$PKG_VERSION_DIR $INSTALL_OPTION ${INSTALL_FOR_ALL} "--feature=all" "--chip=all" \ | 388 | --use-share-info --version-dir=$PKG_VERSION_DIR $INSTALL_OPTION ${INSTALL_FOR_ALL} "--feature=all" "--chip=all" \ |
| 385 | "${INSTALL_TYPE}" "${TARGET_INSTALL_PATH}" "${FILELIST_FILE}" | 389 | "${INSTALL_TYPE}" "${TARGET_INSTALL_PATH}" "${FILELIST_FILE}" |
| @@ -12,6 +12,7 @@ | |||
| 12 | 12 | ||
| 13 | import os | 13 | import os |
| 14 | import sys | 14 | import sys |
| 15 | +import subprocess | ||
| 15 | import argparse | 16 | import argparse |
| 16 | import traceback | 17 | import traceback |
| 17 | import csv | 18 | import csv |
| @@ -32,11 +33,11 @@ from common.py.packer import ( | |||
| 32 | PackageName, create_makeself_pkg_params_factory, create_run_package_command, exec_pack_cmd | 33 | PackageName, create_makeself_pkg_params_factory, create_run_package_command, exec_pack_cmd |
| 33 | ) | 34 | ) |
| 34 | from common.py.pkg_parser import ( | 35 | from common.py.pkg_parser import ( |
| 35 | - ParseOption, XmlConfig, parse_xml_config, get_cann_version_info | 36 | + ParseOption, XmlConfig, parse_xml_config, get_cann_version_info, get_target_name |
| 36 | ) | 37 | ) |
| 37 | from common.py.utils.pkg_utils import ( | 38 | from common.py.utils.pkg_utils import ( |
| 38 | CONFIG_SCRIPT_PATH, CompressError, ContainAsteriskError, DELIVERY_PATH, FAIL, | 39 | CONFIG_SCRIPT_PATH, CompressError, ContainAsteriskError, DELIVERY_PATH, FAIL, |
| 39 | - FilelistError, GenerateFilelistError, PackageNameEmptyError, SUCCESS, TOP_DIR, | 40 | + FilelistError, GenerateFilelistError, PackageNameEmptyError, SUCC, TOP_DIR, |
| 40 | UnknownOperateTypeError, path_join | 41 | UnknownOperateTypeError, path_join |
| 41 | ) | 42 | ) |
| 42 | from common.py.utils.funcbase import invoke, pipe | 43 | from common.py.utils.funcbase import invoke, pipe |
| @@ -110,6 +111,95 @@ class PackageOption(PrivatePackageOption): | |||
| 110 | return super().__new__(cls, *package_option_args, **kwargs) | 111 | return super().__new__(cls, *package_option_args, **kwargs) |
| 111 | 112 | ||
| 112 | 113 | ||
| 114 | +def do_copy(target_conf=None, | ||
| 115 | + delivery_dir='', | ||
| 116 | + release_dir='', | ||
| 117 | + package_name=None): | ||
| 118 | + ''' | ||
| 119 | + 功能描述:根据拷贝类型来执行文件或目录拷贝 | ||
| 120 | + 返回值:SUCC/FAIL | ||
| 121 | + ''' | ||
| 122 | + if target_conf is None: | ||
| 123 | + target_conf = {} | ||
| 124 | + target_name = get_target_name(target_conf) | ||
| 125 | + dst_path = os.path.join(release_dir, target_conf.get('dst_path', '')) | ||
| 126 | + dst_fullpath = os.path.join(dst_path, target_name) | ||
| 127 | + | ||
| 128 | + pkg_softlink = target_conf.get('pkg_softlink') | ||
| 129 | + if pkg_softlink: | ||
| 130 | + rets = [ | ||
| 131 | + create_softlink(dst_fullpath, os.path.join(release_dir, link)) | ||
| 132 | + for link in pkg_softlink | ||
| 133 | + ] | ||
| 134 | + if not all(rets): | ||
| 135 | + return FAIL | ||
| 136 | + return SUCC | ||
| 137 | + | ||
| 138 | + | ||
| 139 | +def do_chmod(target_conf=None, release_dir=''): | ||
| 140 | + """打包时设置权限 。""" | ||
| 141 | + if target_conf is None: | ||
| 142 | + target_conf = {} | ||
| 143 | + target_name = get_target_name(target_conf) | ||
| 144 | + dst_path = os.path.join(release_dir, target_conf.get('dst_path', '')) | ||
| 145 | + dst_fullpath = os.path.join(dst_path, target_name) | ||
| 146 | + pkg_mod = target_conf.get('pkg_mod', '') | ||
| 147 | + if pkg_mod: | ||
| 148 | + # 将命令拆分为列表,不使用 shell=True | ||
| 149 | + cmd_list = ['chmod', '-R', pkg_mod, dst_fullpath] | ||
| 150 | + | ||
| 151 | + try: | ||
| 152 | + result = subprocess.run(cmd_list, capture_output=True, text=True, check=False) | ||
| 153 | + status = result.returncode | ||
| 154 | + output = result.stdout + result.stderr | ||
| 155 | + | ||
| 156 | + if status != 0: # 这里的 SUCC 通常对应 0 | ||
| 157 | + CommLog.cilog_error("chmod failed! Command: %s", " ".join(cmd_list)) | ||
| 158 | + CommLog.cilog_info("%s", output) | ||
| 159 | + return FAIL | ||
| 160 | + except Exception as e: | ||
| 161 | + CommLog.cilog_error("Execute chmod exception: %s", str(e)) | ||
| 162 | + return FAIL | ||
| 163 | + | ||
| 164 | + return SUCC | ||
| 165 | + | ||
| 166 | + | ||
| 167 | +def create_softlink(source, target) -> bool: | ||
| 168 | + ''' | ||
| 169 | + 功能描述:创建软连接 | ||
| 170 | + 参数:source, target | ||
| 171 | + 返回值:成功或失败 | ||
| 172 | + ''' | ||
| 173 | + source = os.path.abspath(source.strip()) | ||
| 174 | + target = os.path.abspath(target.strip()) | ||
| 175 | + | ||
| 176 | + link_target_path = os.path.dirname(target) | ||
| 177 | + link_target_name = os.path.basename(target) | ||
| 178 | + relative_path = os.path.relpath(source, link_target_path) | ||
| 179 | + if os.path.isfile(target): | ||
| 180 | + cmd_list = ['rm', '-f', target] | ||
| 181 | + try: | ||
| 182 | + result = subprocess.run(cmd_list, capture_output=True, text=True, check=False) | ||
| 183 | + status = result.returncode | ||
| 184 | + output = result.stdout + result.stderr | ||
| 185 | + if status != 0: | ||
| 186 | + CommLog.cilog_error("Error: rm -f %s failed, %s", target, output) | ||
| 187 | + return False | ||
| 188 | + except Exception as e: | ||
| 189 | + CommLog.cilog_error("Execute rm exception: %s", str(e)) | ||
| 190 | + return False | ||
| 191 | + if os.path.isdir(target): | ||
| 192 | + CommLog.cilog_warning("Warning: %s is already a directory, skipping soft link creation.", target) | ||
| 193 | + return True | ||
| 194 | + if not os.path.exists(link_target_path): | ||
| 195 | + os.makedirs(link_target_path) | ||
| 196 | + tmp_dir = os.getcwd() | ||
| 197 | + os.chdir(link_target_path) | ||
| 198 | + os.symlink(relative_path, link_target_name) | ||
| 199 | + os.chdir(tmp_dir) | ||
| 200 | + return True | ||
| 201 | + | ||
| 202 | + | ||
| 113 | def generate_info_content(target_conf, ext_name) -> List[str]: | 203 | def generate_info_content(target_conf, ext_name) -> List[str]: |
| 114 | """生成info内容。""" | 204 | """生成info内容。""" |
| 115 | 205 | ||
| @@ -161,7 +251,7 @@ def generate_customized_file(target_conf, ext_name): | |||
| 161 | CommLog.cilog_error(f"generate customized file {filepath} failed: {ex}!") | 251 | CommLog.cilog_error(f"generate customized file {filepath} failed: {ex}!") |
| 162 | return FAIL | 252 | return FAIL |
| 163 | 253 | ||
| 164 | - return SUCCESS | 254 | + return SUCC |
| 165 | 255 | ||
| 166 | 256 | ||
| 167 | def get_module(target_config) -> str: | 257 | def get_module(target_config) -> str: |
| @@ -236,9 +326,24 @@ def get_pkg_inner_softlink(target_config) -> List[str]: | |||
| 236 | return softlink_str.split(';') | 326 | return softlink_str.split(';') |
| 237 | 327 | ||
| 238 | 328 | ||
| 239 | -def parse_install_info(infos: List, | 329 | +def validate_path_consistency(target_config, target_name): |
| 240 | - operate_type, | 330 | + """验证 dst_path 和 install_path 一致性,不一致则抛出异常。""" |
| 241 | - filter_key) -> Iterator[FileItem]: | 331 | + dst_path_val = target_config.get('dst_path', '') |
| 332 | + install_path_val = target_config.get('install_path', '') | ||
| 333 | + | ||
| 334 | + if dst_path_val != install_path_val: | ||
| 335 | + value_path = target_config.get('value', 'unknown') | ||
| 336 | + CommLog.cilog_error( | ||
| 337 | + f"Configuration Error: 'dst_path' MUST be equal to 'install_path'.\n" | ||
| 338 | + f" - Current dst_path: {dst_path_val}\n" | ||
| 339 | + f" - Current install_path: {install_path_val}\n" | ||
| 340 | + ) | ||
| 341 | + raise GenerateFilelistError( | ||
| 342 | + f"dst_path ({dst_path_val}) does not match install_path ({install_path_val})" | ||
| 343 | + ) | ||
| 344 | + | ||
| 345 | + | ||
| 346 | +def parse_install_info(infos: List, operate_type, filter_key) -> Iterator[FileItem]: | ||
| 242 | """根据配置解析生成安装信息。""" | 347 | """根据配置解析生成安装信息。""" |
| 243 | for target_config in infos: | 348 | for target_config in infos: |
| 244 | target_name = get_target_name(target_config) | 349 | target_name = get_target_name(target_config) |
| @@ -253,6 +358,8 @@ def parse_install_info(infos: List, | |||
| 253 | relative_path_in_pkg = os.path.join(target_config.get('dst_path'), target_name) | 358 | relative_path_in_pkg = os.path.join(target_config.get('dst_path'), target_name) |
| 254 | relative_install_path = path_join(target_config.get('install_path'), target_name) | 359 | relative_install_path = path_join(target_config.get('install_path'), target_name) |
| 255 | is_dir = target_config.get('is_dir', False) | 360 | is_dir = target_config.get('is_dir', False) |
| 361 | + # 验证dst_path和install_path的一致性 | ||
| 362 | + validate_path_consistency(target_config, target_name) | ||
| 256 | elif operate_type == 'mkdir': | 363 | elif operate_type == 'mkdir': |
| 257 | relative_path_in_pkg = 'NA' | 364 | relative_path_in_pkg = 'NA' |
| 258 | relative_install_path = target_config.get('value') | 365 | relative_install_path = target_config.get('value') |
| @@ -283,8 +390,7 @@ def parse_install_info(infos: List, | |||
| 283 | get_owner_group(target_config), | 390 | get_owner_group(target_config), |
| 284 | install_type, | 391 | install_type, |
| 285 | get_softlink(target_config), | 392 | get_softlink(target_config), |
| 286 | - get_feature(target_config), | 393 | + get_feature(target_config), 'N', |
| 287 | - 'N', | ||
| 288 | get_configurable(target_config), | 394 | get_configurable(target_config), |
| 289 | get_hash_value(target_config), | 395 | get_hash_value(target_config), |
| 290 | get_block(target_config), | 396 | get_block(target_config), |
| @@ -296,22 +402,33 @@ def parse_install_info(infos: List, | |||
| 296 | yield file_item | 402 | yield file_item |
| 297 | 403 | ||
| 298 | 404 | ||
| 299 | -def execute_repack_process(xml_config: XmlConfig, | 405 | +def execute_repack_process(xmlconfig: XmlConfig, |
| 300 | delivery_dir: str, | 406 | delivery_dir: str, |
| 301 | pkg_args: Namespace, | 407 | pkg_args: Namespace, |
| 302 | package_name: PackageName = None, | 408 | package_name: PackageName = None, |
| 303 | package_option: PackageOption = None): | 409 | package_option: PackageOption = None): |
| 304 | """ | 410 | """ |
| 305 | 功能描述: 执行打包流程(拷贝--->签名--->打包) | 411 | 功能描述: 执行打包流程(拷贝--->签名--->打包) |
| 306 | - 返回值: SUCCESS/FAIL | 412 | + 返回值: SUCC/FAIL |
| 307 | """ | 413 | """ |
| 308 | - release_dir = os.path.join( | 414 | + status = SUCC |
| 309 | - delivery_dir, xml_config.default_config.get('name', 'default')) | 415 | + release_dir = delivery_dir |
| 310 | # 生成自定义文件 | 416 | # 生成自定义文件 |
| 311 | - for item in xml_config.generate_infos: | 417 | + for item in xmlconfig.generate_infos: |
| 312 | if generate_customized_file(item, package_option.ext_name): | 418 | if generate_customized_file(item, package_option.ext_name): |
| 313 | return FAIL | 419 | return FAIL |
| 314 | 420 | ||
| 421 | + for item in chain(xmlconfig.package_content_list, xmlconfig.move_content_list): | ||
| 422 | + #拷贝文件 | ||
| 423 | + if do_copy(item, | ||
| 424 | + delivery_dir, | ||
| 425 | + release_dir, | ||
| 426 | + package_name): | ||
| 427 | + status = FAIL | ||
| 428 | + continue | ||
| 429 | + if status != SUCC: | ||
| 430 | + return FAIL | ||
| 431 | + | ||
| 315 | # 校验包中文件或目录大小 | 432 | # 校验包中文件或目录大小 |
| 316 | if pkg_args.check_size == "True": | 433 | if pkg_args.check_size == "True": |
| 317 | limit_list, tag = processing_csv_file( | 434 | limit_list, tag = processing_csv_file( |
| @@ -326,20 +443,20 @@ def execute_repack_process(xml_config: XmlConfig, | |||
| 326 | if not result: | 443 | if not result: |
| 327 | return FAIL | 444 | return FAIL |
| 328 | try: | 445 | try: |
| 329 | - package_name = get_compress_cmd(pkg_args.pkg_output_dir, pkg_args, xml_config) | 446 | + package_name = get_compress_cmd(pkg_args.pkg_output_dir, pkg_args, xmlconfig) |
| 330 | except CompressError: | 447 | except CompressError: |
| 331 | return FAIL | 448 | return FAIL |
| 332 | 449 | ||
| 333 | CommLog.cilog_info("package %s generate filelist.csv and makeself cmd successfully!", | 450 | CommLog.cilog_info("package %s generate filelist.csv and makeself cmd successfully!", |
| 334 | package_name) | 451 | package_name) |
| 335 | - return SUCCESS | 452 | + return SUCC |
| 336 | 453 | ||
| 337 | 454 | ||
| 338 | def check_path_is_conflict(xml_config): | 455 | def check_path_is_conflict(xml_config): |
| 339 | """ | 456 | """ |
| 340 | 功能描述: 检查打包时安装路径与软连接路径是否冲突 | 457 | 功能描述: 检查打包时安装路径与软连接路径是否冲突 |
| 341 | 参数: xml_config | 458 | 参数: xml_config |
| 342 | - 返回值: SUCCESS/FAIL | 459 | + 返回值: SUCC/FAIL |
| 343 | """ | 460 | """ |
| 344 | install_path_list = set() | 461 | install_path_list = set() |
| 345 | pkg_softlink_list = set() | 462 | pkg_softlink_list = set() |
| @@ -357,7 +474,7 @@ def check_path_is_conflict(xml_config): | |||
| 357 | CommLog.cilog_info('intersection:{}'.format(install_path_list & pkg_softlink_list)) | 474 | CommLog.cilog_info('intersection:{}'.format(install_path_list & pkg_softlink_list)) |
| 358 | CommLog.cilog_info('path conflicting: pkg_inner_softlink dir equals install_path!!') | 475 | CommLog.cilog_info('path conflicting: pkg_inner_softlink dir equals install_path!!') |
| 359 | return FAIL | 476 | return FAIL |
| 360 | - return SUCCESS | 477 | + return SUCC |
| 361 | 478 | ||
| 362 | 479 | ||
| 363 | def checksum_value(limit_value, release_dir): | 480 | def checksum_value(limit_value, release_dir): |
| @@ -452,17 +569,6 @@ def check_add_dir(package_path, dirs, limit_list, ret=True): | |||
| 452 | return ret | 569 | return ret |
| 453 | 570 | ||
| 454 | 571 | ||
| 455 | -def get_target_name(target_conf) -> str: | ||
| 456 | - """获取目标名。""" | ||
| 457 | - rename = target_conf.get('rename') | ||
| 458 | - if rename: | ||
| 459 | - return rename | ||
| 460 | - | ||
| 461 | - value_list = target_conf.get('value').split('/') | ||
| 462 | - target_name = value_list[-1] if value_list[-1] else value_list[-2] | ||
| 463 | - return target_name | ||
| 464 | - | ||
| 465 | - | ||
| 466 | def gen_file_install_list(xml_config: XmlConfig, | 572 | def gen_file_install_list(xml_config: XmlConfig, |
| 467 | filter_key) -> Tuple[FileList, FileList]: | 573 | filter_key) -> Tuple[FileList, FileList]: |
| 468 | """生成filelist列表。""" | 574 | """生成filelist列表。""" |
| @@ -568,7 +674,7 @@ def main(pkg_name='', xml_file='', main_args=None): | |||
| 568 | """ | 674 | """ |
| 569 | 功能描述: 执行打包流程(解析配置--->生成文件列表--->执行拷贝/打包动作) | 675 | 功能描述: 执行打包流程(解析配置--->生成文件列表--->执行拷贝/打包动作) |
| 570 | 参数: pkg_name, os_arch, type | 676 | 参数: pkg_name, os_arch, type |
| 571 | - 返回值: SUCCESS/FAIL | 677 | + 返回值:SUCC/FAIL |
| 572 | """ | 678 | """ |
| 573 | delivery_dir = os.path.join(TOP_DIR, DELIVERY_PATH) | 679 | delivery_dir = os.path.join(TOP_DIR, DELIVERY_PATH) |
| 574 | if not os.path.exists(delivery_dir): | 680 | if not os.path.exists(delivery_dir): |