已合并
refactor: 重构异构安装逻辑,提取handle_multi_arch_install函数 #1614
refactor: 重构异构安装逻辑,提取handle_multi_arch_install函数 #1614
已合并
liulinxiang创建于 3月12日
liulinxiang成员
3月12日

描述

本 PR 重构了异构安装脚本的代码结构:

  1. 提取通用函数 `handle_multi_arch_install`

    • 将重复的目录权限处理和 so 文件拷贝逻辑提取为独立函数
    • 函数负责:创建目标目录、处理目录写权限、拷贝 so 文件、恢复权限
  2. 简化调用逻辑

    • 原来的 20+ 行重复代码简化为 2 行函数调用
    • 提高代码可读性和可维护性
  3. 修复权限处理问题

    • 修复异构安装路径变量问题
    • 操作前检查目录写权限,无权限时临时添加
    • 操作完成后恢复原始权限

关联的Issue

https://gitcode.com/cann/ops-math/issues/911

测试

文档更新

无需更新文档

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 liulinxiang 的贡献)
Lliulinxiang成员
3月12日 创建了 pull request,commit e96f88bb
CANN-robotCANN-robot成员
3月12日 添加了label:stat/needs-squash
CANN-robot
CANN-robot成员
3月12日 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-cann/ops-math ✅ wangrui_, songkai111 (2/2) ✅ wangrui_, songkai111 (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)
likedislike
CANN-robotCANN-robot成员
3月12日 将zhou-qilong,wangrui_,rxtfeng,loov1,songkai111,llimwang,gubaocheng设为评审人
CANN-robotCANN-robot成员
3月12日 将zhou-qilong,wangrui_,rxtfeng,loov1,songkai111,llimwang,gubaocheng设为审查人
CANN-robot
CANN-robot成员
3月12日 评论:

🔵 source code change are detected, tasks labels is removed in this pull request!

likedislike
CANN-robotCANN-robot成员
3月12日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
3月12日 评论:

问题/功能描述

本次PR主要优化了安装脚本中针对异构架构(如x86_64与aarch64)的共享库(.so文件)安装与卸载逻辑。解决了原有脚本在跨架构安装时权限处理不完善、代码冗余以及卸载时目录清理不彻底的问题,提升了脚本的健壮性和可维护性。

修改方案描述

本次修改通过代码重构,将分散、硬编码的逻辑抽象为统一的函数。具体包括:1)创建 handle_multi_arch_install 函数,统一处理目录创建、权限检查与恢复、文件拷贝,确保操作安全;2)创建 remove_so_and_empty_dir 函数,统一处理文件删除和空目录的递归清理,并具备相同的权限安全机制;3)修正了 GRAPH_SO_PATH 和 HOST_SO_PATH 的源文件路径前缀,确保路径引用准确。

likedislike
CANN-robot
CANN-robot成员3月12日进行代码检视2
scripts/package/ops_math/scripts/install.sh
已过期
@@ -51,8 +51,8 @@ OPP_COMMON_FILE="${CURR_PATH}/opp_common.sh"
5151 
5252ARCH_INFO=$(grep -e "arch" "$RUN_PKG_INFO_FILE" | cut --only-delimited -d"=" -f2-)
5353# 包内路径
54-GRAPH_SO_PATH="${CURR_PATH}/../../../../${OPP_PLATFORM_DIR}/built-in/op_graph/lib/linux/${ARCH_INFO}/libopgraph_math.so"
CANN-robot
CANN-robot3月12日评论:
路径硬编码: 代码第54行将路径中的变量 ${OPP_PLATFORM_DIR} 替换为硬编码的 'opp'。这破坏了代码的通用性,使得脚本只能用于特定的 'opp' 目录结构,而无法适配由 OPP_PLATFORM_DIR 变量定义的其他平台目录。这种硬编码降低了脚本的可维护性和可复用性。
问题类型: 路径硬编码
文件路径: scripts/package/ops_math/scripts/install.sh
行号: 54
问题代码:
GRAPH_SO_PATH="${CURR_PATH}/../../../../opp/built-in/op_graph/lib/linux/${ARCH_INFO}/libopgraph_math.so"
修改建议:
恢复使用变量 ${OPP_PLATFORM_DIR},以确保路径配置的灵活性和一致性。修改为:GRAPH_SO_PATH="${CURR_PATH}/../../../../${OPP_PLATFORM_DIR}/built-in/op_graph/lib/linux/${ARCH_INFO}/libopgraph_math.so"
---
此评论由代码审查工具自动生成
likedislike
System
系统消息系统
3月12日 评论:

changed this line on d135d5d0 view diff detail

CANN-robot
CANN-robot成员3月12日进行代码检视2
scripts/package/ops_math/scripts/install.sh
已过期
@@ -54,2 +54,2 @@
54-GRAPH_SO_PATH="${CURR_PATH}/../../../../${OPP_PLATFORM_DIR}/built-in/op_graph/lib/linux/${ARCH_INFO}/libopgraph_math.so"
55-HOST_SO_PATH="${CURR_PATH}/../../../../${OPP_PLATFORM_DIR}/built-in/op_impl/ai_core/tbe/op_host/lib/linux/${ARCH_INFO}/libophost_math.so"
54+GRAPH_SO_PATH="${CURR_PATH}/../../../../opp/built-in/op_graph/lib/linux/${ARCH_INFO}/libopgraph_math.so"
55+HOST_SO_PATH="${CURR_PATH}/../../../../opp/built-in/op_impl/ai_core/tbe/op_host/lib/linux/${ARCH_INFO}/libophost_math.so"
CANN-robot
CANN-robot3月12日评论:
路径硬编码: 代码第55行存在与第54行相同的问题,将路径中的变量 ${OPP_PLATFORM_DIR} 替换为硬编码的 'opp'。这同样破坏了脚本的通用性,使其无法适应不同的平台目录配置。
问题类型: 路径硬编码
文件路径: scripts/package/ops_math/scripts/install.sh
行号: 55
问题代码:
HOST_SO_PATH="${CURR_PATH}/../../../../opp/built-in/op_impl/ai_core/tbe/op_host/lib/linux/${ARCH_INFO}/libophost_math.so"
修改建议:
恢复使用变量 ${OPP_PLATFORM_DIR}。修改为:HOST_SO_PATH="${CURR_PATH}/../../../../${OPP_PLATFORM_DIR}/built-in/op_impl/ai_core/tbe/op_host/lib/linux/${ARCH_INFO}/libophost_math.so"
---
此评论由代码审查工具自动生成
likedislike
System
系统消息系统
3月12日 评论:

changed this line on d135d5d0 view diff detail

Lliulinxiang成员
3月12日 预合并成功(commit_id: 740b1bf3886c16ab7657b74739237abe1fb3a878)
Lliulinxiang成员
3月12日 强制推送  1 个提交:d135d5d0-refactor: 重构异构安装逻辑,提取handle_multi_arch_install函数
Lliulinxiang成员
3月12日 预合并成功(commit_id: 8b6198c6a8c2e5a36a7f76719d00e716391da2bb)
CANN-robotCANN-robot成员
3月12日 删除了label:stat/needs-squash
CANN-robot
CANN-robot成员
3月12日 评论:

🔵 source code change are detected, tasks labels is removed in this pull request!

likedislike
Lliulinxiang成员
3月12日 解决了最后一个问题
Lliulinxiang成员
3月12日 修改了pull request 的描述
Lliulinxiang成员
3月12日 修改了pull request 的描述
Lliulinxiang成员
3月12日 修改了pull request 的描述
liulinxiang成员
3月12日 评论:

compile

likedislike
CANN-robotCANN-robot成员
3月12日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
3月12日 评论:

流水线任务触发成功
任务链接 [a3835caa4ef146eea6a0aa7807155133][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
anti_virus ✅ SUCCESS >>>>>
Check_Pr ✅ SUCCESS >>>>>
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5 ✅ SUCCESS >>>>> >>>>>
API_Check ✅ SUCCESS >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_X86_mobile_station_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_X86_experimental_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_X86_A5_ubuntu24 ✅ SUCCESS >>>>>
harmony-infer ✅ SUCCESS
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_ARM_experimental_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_single_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_ARM_A5_ubuntu24 ✅ SUCCESS >>>>>
UT_Test ✅ SUCCESS
UT_Test_experimental ✅ SUCCESS
UT_Test_kernel ✅ SUCCESS
Smoke_A900_npupool ✅ SUCCESS >>>>>

[2026-03-12 11:05:40]    CI执行结束

likedislike
CANN-robotCANN-robot成员
3月12日 添加了label:api-check-pass
CANN-robotCANN-robot成员
3月12日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
3月12日 添加了label:ci-pipeline-passed
llimwang成员3月12日进行代码检视2
scripts/package/ops_math/scripts/install.sh
@@ -497,0 +515,4 @@
515+ else
516+ mkdir -p "${target_dir}"
517+ fi
518+ cp -f "${so_file}" "${target_dir}"
llimwang3月12日评论:

问题: 重构后缺失对so文件设置可执行权限

原代码在异构安装时会执行 chmod 755 ${graph_so_dir_path}/* 来确保 .so 文件具有可执行权限。新的 handle_multi_arch_install 函数虽然成功重构了目录创建、权限处理和文件拷贝逻辑,但遗漏了对拷贝后 so 文件设置可执行权限的步骤。

建议: 在 cp -f "${so_file}" "${target_dir}" 后添加对拷贝文件的权限设置,例如:

chmod 755 "${target_dir}"/*

或针对特定文件:

chmod 755 "${target_dir}/$(basename "${so_file}")"
likedislike
liulinxiang成员
3月12日 评论:

已修改

Lliulinxiang成员
3月12日 预合并成功(commit_id: 04d4fcf318a9556833c5f85415454946957e9025)
Lliulinxiang成员
3月12日 强制推送  1 个提交:e9931005-refactor: 重构异构安装逻辑,提取handle_multi_arch_install函数
Lliulinxiang成员
3月12日 预合并成功(commit_id: 10d664c6a62334c1f4193867f6b301dbda5ddd08)
CANN-robotCANN-robot成员
3月12日 删除了label:ci-pipeline-passed
CANN-robot
CANN-robot成员
3月12日 评论:

Notification

This pull request source branch has changed, so removes the following label(s): ci-pipeline-passed.

likedislike
CANN-robot
CANN-robot成员
3月12日 评论:

CLA Signature Pass

liulinxiang, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robot
CANN-robot成员
3月12日 评论:

🔵 source code change are detected, tasks labels is removed in this pull request!

likedislike
liulinxiang成员
3月12日 评论:

compile

likedislike
CANN-robotCANN-robot成员
3月12日 添加了label:ci-pipeline-running
CANN-robotCANN-robot成员
3月12日 删除了label:api-check-pass
CANN-robot
CANN-robot成员
3月12日 评论:

流水线任务触发成功
任务链接 [8bd6ec64a1104dcfb4cabc5506ed86a8][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
anti_virus ✅ SUCCESS >>>>>
Check_Pr ✅ SUCCESS >>>>>
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5 ✅ SUCCESS >>>>> >>>>>
API_Check ✅ SUCCESS >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_X86_mobile_station_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_X86_experimental_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_X86_A5_ubuntu24 ✅ SUCCESS >>>>>
harmony-infer ✅ SUCCESS
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_ARM_experimental_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_single_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_ARM_A5_ubuntu24 ✅ SUCCESS >>>>>
UT_Test ✅ SUCCESS
UT_Test_experimental ✅ SUCCESS
UT_Test_kernel ✅ SUCCESS
Smoke_A900_npupool ✅ SUCCESS >>>>>

[2026-03-12 16:23:33]    CI执行结束

likedislike
CANN-robotCANN-robot成员
3月12日 添加了label:api-check-pass
CANN-robotCANN-robot成员
3月12日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
3月12日 添加了label:ci-pipeline-passed
songkai111成员
3月12日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
3月12日 添加了label:approved
RuiWang_成员
3月12日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
3月12日 添加了label:lgtm
CANN-robot
CANN-robot成员
3月12日 评论:

Review Guide

This pull-request passes review.
Committers who wrote a comment of /approve are: songkai111, wangrui_.
Reviewers who wrote a comment of /lgtm are: wangrui_, songkai111.

likedislike
CANN-robot
CANN-robot成员
3月12日 评论:

The MR can not be merged, because of CodeReview discussion not resolved

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
Lliulinxiang成员
3月12日 解决了最后一个问题
CANN-robot
CANN-robot成员
3月12日 评论:

Review Guide

This pull-request passes review.
Committers who wrote a comment of /approve are: songkai111, wangrui_.
Reviewers who wrote a comment of /lgtm are: songkai111, wangrui_.

likedislike
CANN-robotCANN-robot成员
3月12日 合入了pull request