已合并
fix: align run package version with devkit #136
Hyunbin创建于 8月26日
fix: align run package version with devkit #136
已合并
Hyunbin创建于 8月26日
共 12 个文件变更+322-149
@@ -10,7 +10,8 @@
10 10 
11cmake_minimum_required(VERSION 3.16)11cmake_minimum_required(VERSION 3.16)
12 12 
13-project(asc_comm LANGUAGES C CXX)13+include(version.cmake)
14+project(asc_comm VERSION "${ASCCOMM_VERSION}" LANGUAGES C CXX)
14 15 
15set(CMAKE_C_STANDARD 11)16set(CMAKE_C_STANDARD 11)
16set(CMAKE_C_STANDARD_REQUIRED ON)17set(CMAKE_C_STANDARD_REQUIRED ON)
@@ -166,14 +166,14 @@ bash build.sh --make_clean
166bash build.sh -t166bash build.sh -t
167```167```
168 168 
169-将仓库中当前Hcomm与Ain头文件制作为开发验证run包,并安装到已有CANN环境:169+将仓库中的asc-comm头文件制作为开发验证run包,并安装到已有CANN环境:
170 170 
171```bash171```bash
172bash build.sh --pkg172bash build.sh --pkg
173-./build_out/cann-asc-comm_1.0.0_linux-<arch>.run --full173+./build_out/cann-asc-comm_9.2.0_linux-<arch>.run --full
M
Mmyx_328月26日

9.2.0能不能改成一个指代版本号的变量?

likedislike
Hyunbin
Hyunbin
29 天前 评论:
174```174```
175 175 
176-制包脚本会递归收集`include/aicore/hcomm/`、`src/aicore/hcomm/`、`include/aicore/ain/`和`src/aicore/ain/`中的头文件,目录映射及Hcomm软链与asc-devkit当前出包逻辑一致。安装时会备份目标CANN中的原文件和软链状态;对于安装前不存在的新增内容,卸载时会将其删除。详细的目录映射、参数和限制见[构建与测试](./docs/zh/guide/build_and_test.md)。176+制包脚本会递归收集`include/`和`src/`中的头文件,其中Hcomm安装到`adv_api`,其他头文件按相对路径安装到`comm_api`。安装目录、命令参数、权限和卸载说明见[构建与测试](./docs/zh/guide/build_and_test.md)。
177 177 
178如需直接使用CMake构建UT,可指定CANN三方依赖目录:178如需直接使用CMake构建UT,可指定CANN三方依赖目录:
179 179 
@@ -147,14 +147,14 @@ Build and execute Hcomm and Ain unit tests:
147bash build.sh -t147bash build.sh -t
148```148```
149 149 
150-Build the current Hcomm and Ain headers into a development run package and install it into an existing CANN environment:150+Build the asc-comm headers into a development run package and install it into an existing CANN environment:
151 151 
152```bash152```bash
153bash build.sh --pkg153bash build.sh --pkg
154-./build_out/cann-asc-comm_1.0.0_linux-<arch>.run --full154+./build_out/cann-asc-comm_9.2.0_linux-<arch>.run --full
155```155```
156 156 
157-The packaging script recursively collects headers under `include/aicore/hcomm/`, `src/aicore/hcomm/`, `include/aicore/ain/`, and `src/aicore/ain/`. Its directory mapping and Hcomm symbolic links match the current asc-devkit packaging logic. Installation backs up existing target files and link state, while content that did not exist before installation is removed during uninstallation. See [Build & Test](./docs/en/guide/build_and_test.md) for directory mappings, options, and limitations.157+The packaging script recursively collects headers under `include/` and `src/`. Hcomm is installed under `adv_api`; other headers preserve their relative paths under `comm_api`. See [Build & Test](./docs/en/guide/build_and_test.md) for installation paths, command options, permissions, and uninstallation instructions.
158 158 
159To build UTs directly via CMake, specify the CANN third-party library path:159To build UTs directly via CMake, specify the CANN third-party library path:
160```bash160```bash
@@ -175,7 +175,7 @@ main(){
175 175 
176 if [[ "${PACKAGE}" == true ]]; then176 if [[ "${PACKAGE}" == true ]]; then
177 bash "${SCRIPT_DIR}/scripts/package/build_package.sh" \177 bash "${SCRIPT_DIR}/scripts/package/build_package.sh" \
178- --cann-path="${Ascend_CANN_PACKAGE_PATH}" || return $?178+ --cann_path="${Ascend_CANN_PACKAGE_PATH}" || return $?
179 fi179 fi
180 180 
181 if [[ "${TEST}" != true ]]; then181 if [[ "${TEST}" != true ]]; then
@@ -33,7 +33,7 @@ build/ut-hcomm
33 33 
34## Build a Development Run Package34## Build a Development Run Package
35 35 
36-After modifying Hcomm or Ain headers locally, build a lightweight development package to install the relevant headers from the current worktree into an existing CANN environment without rebuilding the complete toolkit package:36+After modifying asc-comm headers locally, build a lightweight development package to install the relevant headers from the current worktree into an existing CANN environment without rebuilding the complete toolkit package:
37 37 
38```bash38```bash
39bash build.sh --pkg39bash build.sh --pkg
@@ -42,7 +42,7 @@ bash build.sh --pkg
42The generated file is placed in `build_out/` by default:42The generated file is placed in `build_out/` by default:
43 43 
44```text44```text
45-cann-asc-comm_1.0.0_linux-<arch>.run45+cann-asc-comm_9.2.0_linux-<arch>.run
46```46```
47 47 
48`<arch>` is `aarch64` or `x86_64`. At packaging time, every `.h` file under the following directories is collected recursively:48`<arch>` is `aarch64` or `x86_64`. At packaging time, every `.h` file under the following directories is collected recursively:
@@ -51,27 +51,31 @@ cann-asc-comm_1.0.0_linux-<arch>.run
51| --- | --- |51| --- | --- |
52| `include/aicore/hcomm/` | `asc/include/adv_api/hcomm/` |52| `include/aicore/hcomm/` | `asc/include/adv_api/hcomm/` |
53| `src/aicore/hcomm/` | `asc/impl/adv_api/detail/hcomm/` |53| `src/aicore/hcomm/` | `asc/impl/adv_api/detail/hcomm/` |
54-| `include/aicore/ain/` | `asc/include/comm_api/aicore/ain/` |54+| Other directories under `include/` | `asc/include/comm_api/`, preserving relative paths |
55-| `src/aicore/ain/` | `asc/impl/comm_api/aicore/ain/` |55+| Other directories under `src/` | `asc/impl/comm_api/`, preserving relative paths |
56 56 
57-This mapping matches the current packaging rules in asc-devkit's `cmake/third_party/asc-comm.cmake`, and relative subdirectories within each source directory are preserved. Installation also creates these Hcomm symbolic links:57+The installation paths follow the asc-devkit subpackage layout. Relative subdirectories within each source directory are preserved. Installation also creates these Hcomm symbolic links:
58 58 
59```text59```text
60asc/include/comm_api/aicore/hcomm -> ../../adv_api/hcomm60asc/include/comm_api/aicore/hcomm -> ../../adv_api/hcomm
61asc/impl/comm_api/aicore/hcomm -> ../../adv_api/detail/hcomm61asc/impl/comm_api/aicore/hcomm -> ../../adv_api/detail/hcomm
62```62```
63 63 
64-Consequently, a new `.h` file under any scan directory is automatically included the next time the package is built. File names, source file counts, and installed file counts are not fixed; other file types are excluded. The package manifest describes only headers present at packaging time and does not represent a complete mirror of the target directories. On a first installation, a path already deleted or renamed in the repository is absent from the manifest, so the installer cannot remove the corresponding old path from CANN. Do not rely solely on this run package to verify the final directory state of deletions or renames.64+For example, `include/aicore/ain/` is installed under `asc/include/comm_api/aicore/ain/`, and `include/ccu/` is installed under `asc/include/comm_api/ccu/`. The run package collects only `.h` files that exist under these directories at packaging time; other file types such as `.cpp` and `.inc` are not included. New headers are included automatically the next time the package is built.
65+ 
66+> Note: The run package does not remove files from the target CANN installation when they are absent from its manifest. Before validating a header deletion or rename, remove the corresponding old file from the target CANN installation.
65 67 
66Common options are listed below:68Common options are listed below:
67 69 
68| Option | Description |70| Option | Description |
69| --- | --- |71| --- | --- |
70-| `--full` | Install or update all packaged Hcomm and Ain headers and Hcomm links in full mode. |72+| `--full` | Install or update all packaged asc-comm headers and Hcomm links in full mode. |
71| `--uninstall` | Restore original files from the baseline and remove files that were previously absent. |73| `--uninstall` | Restore original files from the baseline and remove files that were previously absent. |
72| `--check` | Verify the run archive, payload, and dependency compatibility without modifying CANN. |74| `--check` | Verify the run archive, payload, and dependency compatibility without modifying CANN. |
73| `--install-path=<PATH>` | Select the Ascend installation root; defaults to `/usr/local/Ascend` for root or `$HOME/Ascend` for non-root users. |75| `--install-path=<PATH>` | Select the Ascend installation root; defaults to `/usr/local/Ascend` for root or `$HOME/Ascend` for non-root users. |
74-| `--force` | Override installed-patch file consistency checks. |76+| `--install-for-all` | Allow all users to read and access packaged files during installation; enabled by default for root. |
77+| `--force` | Discard user modifications to package-managed files during installation or uninstallation. |
78+| `--quiet` | Run quietly for scripted use. |
75| `--list` | List files in the run package; provided by the makeself wrapper. |79| `--list` | List files in the run package; provided by the makeself wrapper. |
76| `-h`, `--help` | Display help information. |80| `-h`, `--help` | Display help information. |
77 81 
@@ -82,78 +86,82 @@ Common options are listed below:
82Before installation, verify the archive and payload checksums and print the package version, source commit, architecture, required asc-devkit, hcomm, and runtime versions, and file count. This does not modify CANN:86Before installation, verify the archive and payload checksums and print the package version, source commit, architecture, required asc-devkit, hcomm, and runtime versions, and file count. This does not modify CANN:
83 87 
84```bash88```bash
85-./build_out/cann-asc-comm_1.0.0_linux-<arch>.run --check89+./build_out/cann-asc-comm_9.2.0_linux-<arch>.run --check
86```90```
87 91 
88List the files embedded in the run package:92List the files embedded in the run package:
89 93 
90```bash94```bash
91-./build_out/cann-asc-comm_1.0.0_linux-<arch>.run --list95+./build_out/cann-asc-comm_9.2.0_linux-<arch>.run --list
92```96```
93 97 
94-### Install and Uninstall98+### Install
95 99 
96Install into the default Ascend root:100Install into the default Ascend root:
97 101 
98```bash102```bash
99-./build_out/cann-asc-comm_1.0.0_linux-<arch>.run --full103+./build_out/cann-asc-comm_9.2.0_linux-<arch>.run --full
100```104```
101 105 
102Alternatively, select an installation location with an absolute path:106Alternatively, select an installation location with an absolute path:
103 107 
104```bash108```bash
105-./build_out/cann-asc-comm_1.0.0_linux-<arch>.run \109+./build_out/cann-asc-comm_9.2.0_linux-<arch>.run \
106 --full --install-path=/path/to/cann110 --full --install-path=/path/to/cann
107```111```
108 112 
109The installer tries the `--install-path` value itself, `<install-path>/cann`, and `<install-path>/ascend-toolkit/latest` as the CANN root. The resolved directory must contain `asc/include/adv_api/`, `asc/impl/adv_api/detail/`, and `share/info/`. The current user must own the resolved CANN root.113The installer tries the `--install-path` value itself, `<install-path>/cann`, and `<install-path>/ascend-toolkit/latest` as the CANN root. The resolved directory must contain `asc/include/adv_api/`, `asc/impl/adv_api/detail/`, and `share/info/`. The current user must own the resolved CANN root.
110 114 
111-On the first installation, baseline state is stored under the resolved CANN root:115+For a non-root installation that needs to be available to other users, run:
112 116 
113-```text117+```bash
114-var/asc-comm-dev-patch/baseline/118+./build_out/cann-asc-comm_9.2.0_linux-<arch>.run \
119+ --full --install-for-all --install-path=/path/to/cann
115```120```
116 121 
117-- If a target file already exists, the installer saves the original before replacement. Uninstallation restores the original file and its permissions.122+- Permission behavior follows the asc-devkit subpackage. A root installation sets header files to mode `555`, Hcomm directories to mode `755`, and managed directories under `comm_api` to mode `555`.
118-- If a target file does not exist, the installer records it as `absent` before creating it. Uninstallation removes that file.123+- A non-root installation uses modes `550`, `750`, and `550` by default. With `--install-for-all`, it uses `555`, `755`, and `555`. The target CANN root and its parent directories must allow other users to read and traverse them; otherwise, the installer refuses to proceed.
119-- For a non-root installation, AICore Hcomm and Ain files use mode `550`, Hcomm directories use mode `750`, and managed directories under `comm_api` use mode `550`. Consistent with the devkit and hcomm packages, a root installation automatically enables access for all users and changes these modes to `555`, `755`, and `555`, respectively. The installer records original directory permissions; reinstallation, uninstallation, or failed-operation rollback restores them without recursively changing unrelated directories.124+- The installer saves existing managed files and valid Hcomm links. It does not overwrite an incorrect link target or a regular file or directory occupying a link path.
120-- The installer records whether each Hcomm link existed before the first installation. Uninstallation preserves a pre-existing correct link and removes a link created by this package. A wrong-target link, regular file, or directory occupying either link path is never overwritten.125+- The package records the major and minor versions of asc-devkit, hcomm, and runtime, as well as the system architecture. The architecture must match. An incompatible dependency version produces a warning and installation continues.
121-- On repeated installation into the same CANN directory, the installer first restores the previous patch and then rebuilds the baseline for the new package from the restored CANN tree. Files from the previous patch are never saved as originals.126+ 
122-- If a path from the previous asc-comm patch is absent from a new package, repeated installation restores that path and stops managing it; later uninstallation does not touch it. The installer cannot handle an old CANN file that was never recorded by a patch and is also absent from the current package.127+### Reinstall
128+ 
129+Install a new run package into the same CANN directory with `--full` to update it. Files from before the first installation remain available for later uninstallation.
130+ 
131+If a package-managed file or link has been modified manually, reinstallation refuses to overwrite it. To discard those modifications, run:
132+ 
133+```bash
134+./build_out/cann-asc-comm_9.2.0_linux-<arch>.run \
135+ --full --force --install-path=/path/to/cann
136+```
137+ 
138+`--force` cannot bypass the architecture or payload checks. It also cannot overwrite an incorrect link target or a regular file or directory occupying a link path.
139+ 
140+### Uninstall
123 141 
124Restore the files to their pre-installation state. If `--install-path` was used for installation, pass the same path when uninstalling:142Restore the files to their pre-installation state. If `--install-path` was used for installation, pass the same path when uninstalling:
125 143 
126```bash144```bash
127-./build_out/cann-asc-comm_1.0.0_linux-<arch>.run --uninstall145+./build_out/cann-asc-comm_9.2.0_linux-<arch>.run --uninstall
128# Corresponding command for an installation with an explicit path146# Corresponding command for an installation with an explicit path
129-./build_out/cann-asc-comm_1.0.0_linux-<arch>.run \147+./build_out/cann-asc-comm_9.2.0_linux-<arch>.run \
130 --uninstall --install-path=/path/to/cann148 --uninstall --install-path=/path/to/cann
131```149```
132 150 
133-The package records the major and minor versions of asc-devkit, hcomm, and runtime, as well as the system architecture, at build time. Installation requires a matching system architecture. Incompatible dependency versions follow the CANN package convention: a warning is emitted and installation continues. Before a repeated installation or uninstallation, the installer also verifies the currently installed patch files so that direct modifications under CANN are not silently overwritten or discarded.151+Uninstallation restores files and permissions that existed before installation and removes files and links created by the run package. If a package-managed file or link has been modified manually, uninstallation refuses to proceed. Add `--force` to the uninstall command to discard those modifications.
134 152 
135-Use `--force` only when the overwrite risk is understood. During installation, it can override modifications to installed patch files. During uninstallation, it can discard modifications to installed patch files and restore the baseline. `--force` cannot override the system architecture check or payload checksum verification.153+Installation, reinstallation, and uninstallation operations write logs. Root writes under `/var/log/ascend_seclog`, while non-root users write under `$HOME/var/log/ascend_seclog`. Process logs are appended to `ascend_install.log`, and operation audit records are appended to `operation.log`.
136- 
137-Install, upgrade, and uninstall operations write logs using the CANN package convention. Root writes under `/var/log/ascend_seclog`, while non-root users write under `$HOME/var/log/ascend_seclog`. Process logs are appended to `ascend_install.log`, and operation audit records are appended to `operation.log`.
138 154 
139After installation, recompile the target Ascend C kernel before verification. Existing `.o` and `.bin` files are not updated automatically.155After installation, recompile the target Ascend C kernel before verification. Existing `.o` and `.bin` files are not updated automatically.
140 156 
141-To specify the package version, output directory, and CANN environment used for packaging, invoke the packaging script directly:157+The run package version is read from `version.cmake` in the repository root. To specify the output directory and CANN environment used for packaging, invoke the packaging script directly:
142 158 
143```bash159```bash
144bash scripts/package/build_package.sh \160bash scripts/package/build_package.sh \
145- --cann-path=/path/to/cann \161+ --cann_path=/path/to/cann \
146- --package-version=1.0.0 \
147 --output-dir=/path/to/output162 --output-dir=/path/to/output
148```163```
149 164 
150-To verify installation, repeated installation, file protection, and uninstall restoration against a temporary CANN directory:
151- 
152-```bash
153-bash tests/package/test_run_package.sh \
154- build_out/cann-asc-comm_1.0.0_linux-<arch>.run
155-```
156- 
157## CMake Entry165## CMake Entry
158The CMake entry for unit tests is:166The CMake entry for unit tests is:
159```text167```text
@@ -39,7 +39,7 @@ build/ut-hcomm
39 39 
40## 构建开发验证run包40## 构建开发验证run包
41 41 
42-本地修改Hcomm或Ain头文件后,可生成轻量开发验证包,将当前工作树中的相关头文件安装到已有CANN环境,无需重新生成完整toolkit包:42+本地修改asc-comm头文件后,可生成轻量开发验证包,将当前工作树中的相关头文件安装到已有CANN环境,无需重新生成完整toolkit包:
43 43 
44```bash44```bash
45bash build.sh --pkg45bash build.sh --pkg
@@ -48,7 +48,7 @@ bash build.sh --pkg
48生成文件默认位于`build_out/`:48生成文件默认位于`build_out/`:
49 49 
50```text50```text
51-cann-asc-comm_1.0.0_linux-<arch>.run51+cann-asc-comm_9.2.0_linux-<arch>.run
52```52```
53 53 
54其中`<arch>`为`aarch64`或`x86_64`。制包时会递归扫描以下目录中的全部`.h`文件:54其中`<arch>`为`aarch64`或`x86_64`。制包时会递归扫描以下目录中的全部`.h`文件:
@@ -57,27 +57,31 @@ cann-asc-comm_1.0.0_linux-<arch>.run
57| --- | --- |57| --- | --- |
58| `include/aicore/hcomm/` | `asc/include/adv_api/hcomm/` |58| `include/aicore/hcomm/` | `asc/include/adv_api/hcomm/` |
59| `src/aicore/hcomm/` | `asc/impl/adv_api/detail/hcomm/` |59| `src/aicore/hcomm/` | `asc/impl/adv_api/detail/hcomm/` |
60-| `include/aicore/ain/` | `asc/include/comm_api/aicore/ain/` |60+| `include/`中的其他目录 | `asc/include/comm_api/`,保留相对路径 |
61-| `src/aicore/ain/` | `asc/impl/comm_api/aicore/ain/` |61+| `src/`中的其他目录 | `asc/impl/comm_api/`,保留相对路径 |
62 62 
63-该映射与asc-devkit当前`cmake/third_party/asc-comm.cmake`中的出包规则一致,各扫描目录内部的相对目录结构会保留。安装时还会创建以下Hcomm软链:63+安装目录沿用asc-devkit子包布局,各扫描目录内部的相对目录结构会保留。安装时还会创建以下Hcomm软链:
64 64 
65```text65```text
66asc/include/comm_api/aicore/hcomm -> ../../adv_api/hcomm66asc/include/comm_api/aicore/hcomm -> ../../adv_api/hcomm
67asc/impl/comm_api/aicore/hcomm -> ../../adv_api/detail/hcomm67asc/impl/comm_api/aicore/hcomm -> ../../adv_api/detail/hcomm
68```68```
69 69 
70-因此,在上述扫描目录中新增`.h`文件后重新制包,新文件会自动进入run包。文件名、源码文件数量和安装文件数量均不固定,其他类型的文件不会进入包。run包清单只描述制包时存在的头文件,不是目标目录的完整镜像。首次安装时,仓库中已经删除或重命名的路径不会出现在清单中,安装器无法据此删除CANN中原有的旧路径文件。涉及删除或重命名时,不应仅依赖该run包验证目录最终状态。70+例如,`include/aicore/ain/`安装到`asc/include/comm_api/aicore/ain/`,`include/ccu/`安装到`asc/include/comm_api/ccu/`。run包仅收集上述目录中制包时存在的`.h`文件;`.cpp`、`.inc`等其他类型的文件不会进入包。在这些目录中新增头文件后重新制包,新文件会自动进入run包。
71+ 
72+> 注意:run包不会清理目标CANN中未列入包清单的文件。验证头文件删除或重命名时,需要先清理目标CANN中的对应旧文件。
71 73 
72常用参数如下:74常用参数如下:
73 75 
74| 参数 | 说明 |76| 参数 | 说明 |
75| --- | --- |77| --- | --- |
76-| `--full` | 以full模式安装或更新包内全部Hcomm与Ain头文件及Hcomm软链。 |78+| `--full` | 以full模式安装或更新包内全部asc-comm头文件及Hcomm软链。 |
77| `--uninstall` | 恢复基线中的原文件,并删除安装前不存在的文件。 |79| `--uninstall` | 恢复基线中的原文件,并删除安装前不存在的文件。 |
78| `--check` | 校验run包归档、payload和依赖兼容性,不修改CANN。 |80| `--check` | 校验run包归档、payload和依赖兼容性,不修改CANN。 |
79| `--install-path=<PATH>` | 指定Ascend安装根目录;root默认使用`/usr/local/Ascend`,非root默认使用`$HOME/Ascend`。 |81| `--install-path=<PATH>` | 指定Ascend安装根目录;root默认使用`/usr/local/Ascend`,非root默认使用`$HOME/Ascend`。 |
80-| `--force` | 忽略已安装补丁文件的一致性检查。 |82+| `--install-for-all` | 安装时允许所有用户读取和访问包内文件;root安装默认启用。 |
83+| `--force` | 安装或卸载时丢弃包管理文件中的用户修改。 |
84+| `--quiet` | 静默执行,适用于脚本调用。 |
81| `--list` | 列出run包中的文件,由run包的makeself外层提供。 |85| `--list` | 列出run包中的文件,由run包的makeself外层提供。 |
82| `-h`、`--help` | 显示帮助信息。 |86| `-h`、`--help` | 显示帮助信息。 |
83 87 
@@ -88,78 +92,82 @@ asc/impl/comm_api/aicore/hcomm -> ../../adv_api/detail/hcomm
88安装前可以检查归档和payload校验和,并查看包版本、源码提交、架构、要求的asc-devkit、hcomm、runtime版本及文件数量。该操作不会修改CANN:92安装前可以检查归档和payload校验和,并查看包版本、源码提交、架构、要求的asc-devkit、hcomm、runtime版本及文件数量。该操作不会修改CANN:
89 93 
90```bash94```bash
91-./build_out/cann-asc-comm_1.0.0_linux-<arch>.run --check95+./build_out/cann-asc-comm_9.2.0_linux-<arch>.run --check
92```96```
93 97 
94列出run包内的文件:98列出run包内的文件:
95 99 
96```bash100```bash
97-./build_out/cann-asc-comm_1.0.0_linux-<arch>.run --list101+./build_out/cann-asc-comm_9.2.0_linux-<arch>.run --list
98```102```
99 103 
100-### 安装与卸载104+### 安装
101 105 
102安装到默认Ascend根目录:106安装到默认Ascend根目录:
103 107 
104```bash108```bash
105-./build_out/cann-asc-comm_1.0.0_linux-<arch>.run --full109+./build_out/cann-asc-comm_9.2.0_linux-<arch>.run --full
106```110```
107 111 
108也可以通过绝对路径明确指定安装位置:112也可以通过绝对路径明确指定安装位置:
109 113 
110```bash114```bash
111-./build_out/cann-asc-comm_1.0.0_linux-<arch>.run \115+./build_out/cann-asc-comm_9.2.0_linux-<arch>.run \
112 --full --install-path=/path/to/cann116 --full --install-path=/path/to/cann
113```117```
114 118 
115安装器依次尝试将`--install-path`本身、`<install-path>/cann`或`<install-path>/ascend-toolkit/latest`解析为CANN根目录。解析后的目录必须包含`asc/include/adv_api/`、`asc/impl/adv_api/detail/`和`share/info/`,且当前用户必须是该CANN根目录的属主。119安装器依次尝试将`--install-path`本身、`<install-path>/cann`或`<install-path>/ascend-toolkit/latest`解析为CANN根目录。解析后的目录必须包含`asc/include/adv_api/`、`asc/impl/adv_api/detail/`和`share/info/`,且当前用户必须是该CANN根目录的属主。
116 120 
117-首次安装时,备份状态保存在解析后的CANN根目录下:121+非root用户需要允许其他用户使用安装内容时,执行:
118 122 
119-```text123+```bash
120-var/asc-comm-dev-patch/baseline/124+./build_out/cann-asc-comm_9.2.0_linux-<arch>.run \
125+ --full --install-for-all --install-path=/path/to/cann
121```126```
122 127 
123-- 如果目标文件已经存在,安装器会保存原文件后再替换;卸载时恢复原文件及其权限。128+- 权限行为与asc-devkit子包一致。root安装时,头文件权限为`555`,Hcomm目录权限为`755`,`comm_api`下的受管目录权限为`555`。
124-- 如果目标文件原本不存在,安装器会将其记录为`absent`后创建;卸载时删除该文件。129+- 非root安装默认将上述权限分别设置为`550`、`750`和`550`;使用`--install-for-all`后设置为`555`、`755`和`555`。目标CANN根目录及其父目录需要允许其他用户读取和进入,否则安装器会拒绝操作。
125-- 非root安装时,AICore Hcomm和Ain文件权限为`550`,Hcomm目录权限为`750`,`comm_api`下的受管目录权限为`550`。与devkit和hcomm包一致,root安装会自动启用全用户访问,将上述权限分别调整为`555`、`755`和`555`。安装器会记录目录原有权限;重复安装、卸载或安装失败回滚时会恢复原权限,不会递归修改无关目录。130+- 安装器会保存安装前已存在的受管文件和正确的Hcomm软链。目标错误的软链,或者占用软链路径的普通文件、目录,不会被覆盖。
126-- 安装器会记录两条Hcomm软链在首次安装前是否存在。卸载时,安装器会保留原本已存在且指向正确的软链,删除由本包新建的软链;目标错误的软链或占用软链路径的普通文件、目录不会被覆盖。131+- 制包时会记录asc-devkit、hcomm、runtime的主次版本和系统架构。系统架构必须匹配;依赖版本不兼容时会输出告警并继续安装。
127-- 同一CANN目录中重复安装run包时,安装器会先恢复上一个补丁,再基于恢复后的CANN为新包重建基线,不会把上一次安装的补丁文件保存为原文件。132+ 
128-- 如果上一个asc-comm补丁中的路径不再出现在新包中,重复安装会将该路径恢复到原始状态并停止管理;后续卸载不会再处理该路径。但安装器无法处理从未被补丁记录、且本次包中也不存在的旧CANN文件。133+### 重复安装
134+ 
135+使用`--full`将新run包安装到同一CANN目录即可更新。安装器会保留第一次安装前的文件,用于后续卸载。
136+ 
137+如果包管理的文件或软链被手工修改,重复安装会拒绝覆盖。确认可以丢弃这些修改后,使用:
138+ 
139+```bash
140+./build_out/cann-asc-comm_9.2.0_linux-<arch>.run \
141+ --full --force --install-path=/path/to/cann
142+```
143+ 
144+`--force`不能跳过系统架构检查、包内payload校验,也不会覆盖目标错误的软链或占用软链路径的普通文件、目录。
145+ 
146+### 卸载
129 147 
130恢复安装前的文件。使用过`--install-path`安装时,卸载也应传入相同路径:148恢复安装前的文件。使用过`--install-path`安装时,卸载也应传入相同路径:
131 149 
132```bash150```bash
133-./build_out/cann-asc-comm_1.0.0_linux-<arch>.run --uninstall151+./build_out/cann-asc-comm_9.2.0_linux-<arch>.run --uninstall
134# 指定路径安装对应的卸载方式152# 指定路径安装对应的卸载方式
135-./build_out/cann-asc-comm_1.0.0_linux-<arch>.run \153+./build_out/cann-asc-comm_9.2.0_linux-<arch>.run \
136 --uninstall --install-path=/path/to/cann154 --uninstall --install-path=/path/to/cann
137```155```
138 156 
139-制包时会记录asc-devkit、hcomm、runtime的主次版本和系统架构。安装时要求系统架构匹配;依赖版本不兼容时按CANN正式包行为输出告警并继续。重复安装或卸载前还会校验当前已安装的补丁文件,防止覆盖或丢弃用户在CANN目录中直接进行的修改。157+卸载会恢复安装前已存在的文件及其权限,并删除由run包新增的文件和软链。如果包管理的文件或软链被手工修改,卸载会拒绝操作;确认可以丢弃这些修改后,在卸载命令中增加`--force`。
140 158 
141-仅在明确了解数据覆盖风险时使用`--force`。安装时,该参数可以跳过已安装补丁文件被修改的检查;卸载时,可以强制丢弃已安装补丁文件上的修改并恢复基线。`--force`不能绕过系统架构检查或包内payload校验。159+安装、重复安装和卸载过程会写入日志。root用户日志目录为`/var/log/ascend_seclog`,非root用户为`$HOME/var/log/ascend_seclog`;过程日志写入`ascend_install.log`,操作审计写入`operation.log`。
142 160 
143-安装、升级和卸载过程会按CANN包约定写入日志。root用户日志目录为`/var/log/ascend_seclog`,非root用户为`$HOME/var/log/ascend_seclog`;过程日志写入`ascend_install.log`,操作审计写入`operation.log`。161+安装完成后需要重新编译待验证的内容,已有`.o`或`.bin`不会自动更新。
144 162 
145-安装完成后需要重新编译待验证的Ascend C Kernel,已有`.o`或`.bin`不会自动更新。163+run包版本从仓库根目录的`version.cmake`读取。可以直接调用制包脚本指定输出目录和制包所用CANN:
146- 
147-可以直接调用制包脚本指定版本、输出目录和制包所用CANN:
148 164 
149```bash165```bash
150bash scripts/package/build_package.sh \166bash scripts/package/build_package.sh \
151- --cann-path=/path/to/cann \167+ --cann_path=/path/to/cann \
152- --package-version=1.0.0 \
153 --output-dir=/path/to/output168 --output-dir=/path/to/output
154```169```
155 170 
156-在临时构造的CANN目录中验证安装、重复安装、文件保护和卸载恢复:
157- 
158-```bash
159-bash tests/package/test_run_package.sh \
160- build_out/cann-asc-comm_1.0.0_linux-<arch>.run
161-```
162- 
163## CMake入口171## CMake入口
164 172 
165UT的CMake入口为:173UT的CMake入口为:
The file is empty
@@ -16,15 +16,14 @@ PROJECT_ROOT=$(cd -- "${SCRIPT_DIR}/../.." && pwd)
16 16 
17CANN_PATH=${ASCEND_HOME_PATH:-}17CANN_PATH=${ASCEND_HOME_PATH:-}
18OUTPUT_DIR="${PROJECT_ROOT}/build_out"18OUTPUT_DIR="${PROJECT_ROOT}/build_out"
19-PACKAGE_VERSION=${ASCCOMM_PACKAGE_VERSION:-1.0.0}19+PACKAGE_VERSION=""
20STAGING_DIR="${PROJECT_ROOT}/build/package/asc-comm"20STAGING_DIR="${PROJECT_ROOT}/build/package/asc-comm"
21PACKAGE_INPUT_PATHS=(21PACKAGE_INPUT_PATHS=(
22 build.sh22 build.sh
23- include/aicore/ain23+ include
24- include/aicore/hcomm24+ src
25- src/aicore/ain
26- src/aicore/hcomm
27 scripts/package25 scripts/package
26+ version.cmake
28)27)
29 28 
30usage()29usage()
@@ -33,9 +32,8 @@ usage()
33Usage: bash scripts/package/build_package.sh [OPTION]...32Usage: bash scripts/package/build_package.sh [OPTION]...
34 33 
35Options:34Options:
36- --cann-path=<PATH> CANN installation root. Default: ASCEND_HOME_PATH35+ --cann_path=<PATH> CANN installation root. Default: ASCEND_HOME_PATH
37 --output-dir=<PATH> Output directory. Default: ${OUTPUT_DIR}36 --output-dir=<PATH> Output directory. Default: ${OUTPUT_DIR}
38- --package-version=<VER> Package version. Default: ${PACKAGE_VERSION}
39 -h, --help Display this help37 -h, --help Display this help
40EOF38EOF
41}39}
@@ -55,15 +53,12 @@ parse_args()
55{53{
56 while [[ $# -gt 0 ]]; do54 while [[ $# -gt 0 ]]; do
57 case "$1" in55 case "$1" in
58- --cann-path=*)56+ --cann_path=*)
59 CANN_PATH=${1#*=}57 CANN_PATH=${1#*=}
60 ;;58 ;;
61 --output-dir=*)59 --output-dir=*)
62 OUTPUT_DIR=${1#*=}60 OUTPUT_DIR=${1#*=}
Y
YYeZZzzz18月26日

🤖 CANN 检视意见

严重性: ✅ Low 置信度: ✅ 较确定 问题类别: 解析健壮性/可读性

问题详情: read_project_version 用 sed 正则 set\(ASCCOMM_VERSION[[:space:]]+"([^"]+)"\) 从 version.cmake 提取版本。该正则对格式较敏感:若 version.cmake 中该 set 行加了行内注释、用单引号、或 set 与括号间格式变化,解析会失败或取空。虽然后面有唯一性/非空校验兜底(fail),但把"版本号真值"用两套语言(cmake set + shell sed)各解析一次,二者格式假设需保持同步。

修改建议: 可接受当前实现(有 fail 兜底)。若追求健壮,建议由 CMake configure 生成一个纯文本版本文件供 shell 读取,或统一用一处解析,避免 cmake/shell 两处正则假设漂移。同一正则在 test_run_package.sh 里又重复了一遍(EXPECTED_PACKAGE_VERSION),建议抽取共享。

likedislike
Hyunbin
Hyunbin
29 天前 评论:
63 ;;61 ;;
64- --package-version=*)
65- PACKAGE_VERSION=${1#*=}
66- ;;
67 -h|--help)62 -h|--help)
68 usage63 usage
69 exit 064 exit 0
@@ -76,6 +71,20 @@ parse_args()
76 done71 done
77}72}
78 73 
74+read_project_version()
75+{
Y
YYeZZzzz18月26日

🤖 CANN 检视意见

严重性: ✅ Low 置信度: ✅ 较确定 问题类别: 可读性/注释完善 (BIZ-03)

问题详情: copy_headers 新增了可变数量的"排除路径"尾参(shift 3 后遍历 $@),并把"至少收集到一个文件"的校验从 count>0 放宽为 count>0 || $#>0(即带排除项时允许 0 文件)。这两处逻辑改动没有函数头注释说明:排除参数的语义(相对 source_root 的路径前缀)、以及为何带排除时允许空结果(因 include/ 顶层聚合调用可能把全部内容排除到 hcomm)。读者不易理解 $# -gt 0 兜底的意图。

修改建议: 给 copy_headers 补一段函数注释,说明参数约定($1 源根 $2 目标根 $3 权限 4..排除路径前缀)与"带排除项时允许0命中"的原因;排除匹配‘"4.. 排除路径前缀)与"带排除项时允许 0 命中"的原因;排除匹配 `"{excluded_path}"|"${excluded_path}/"*` 的 glob 语义也值得一行注释。

likedislike
Hyunbin
Hyunbin
29 天前 评论:
76+ local version_file="${PROJECT_ROOT}/version.cmake"
77+ local version
78+ 
79+ [[ -f "${version_file}" ]] || fail "project version file not found: ${version_file}"
80+ version=$(sed -nE \
81+ 's/^[[:space:]]*set\(ASCCOMM_VERSION[[:space:]]+"([^"]+)"\)[[:space:]]*$/\1/p' \
82+ "${version_file}")
83+ [[ -n "${version}" && "${version}" != *$'\n'* ]] || \
84+ fail "failed to read a unique ASCCOMM_VERSION from ${version_file}"
85+ echo "${version}"
86+}
87+ 
79normalize_arch()88normalize_arch()
80{89{
81 case "$(uname -m)" in90 case "$(uname -m)" in
@@ -148,22 +157,37 @@ read_package_compat_version()
148 echo "${compat_version}"157 echo "${compat_version}"
149}158}
150 159 
160+# Copy headers while preserving paths relative to source_root. Arguments after
161+# mode are excluded relative path prefixes; a filtered source may copy no files.
151copy_headers()162copy_headers()
152{163{
153 local source_root=$1164 local source_root=$1
154 local destination_root=$2165 local destination_root=$2
155 local mode=$3166 local mode=$3
167+ shift 3
168+ local excluded_path
156 local source_file169 local source_file
157 local relative_path170 local relative_path
158 local count=0171 local count=0
172+ local skip
159 173 
160 while IFS= read -r -d '' source_file; do174 while IFS= read -r -d '' source_file; do
161 relative_path=${source_file#"${source_root}/"}175 relative_path=${source_file#"${source_root}/"}
176+ skip=false
177+ for excluded_path in "$@"; do
178+ case "${relative_path}" in
179+ "${excluded_path}"|"${excluded_path}/"*)
180+ skip=true
181+ break
182+ ;;
183+ esac
184+ done
185+ [[ "${skip}" == false ]] || continue
162 install -D -m "${mode}" "${source_file}" "${destination_root}/${relative_path}"186 install -D -m "${mode}" "${source_file}" "${destination_root}/${relative_path}"
163 count=$((count + 1))187 count=$((count + 1))
164 done < <(find "${source_root}" -type f -name '*.h' -print0 | sort -z)188 done < <(find "${source_root}" -type f -name '*.h' -print0 | sort -z)
165 189 
166- [[ ${count} -gt 0 ]] || fail "no header files found under ${source_root}"190+ [[ ${count} -gt 0 || $# -gt 0 ]] || fail "no header files found under ${source_root}"
167}191}
168 192 
169write_manifest()193write_manifest()
@@ -227,10 +251,11 @@ build_package()
227 local version_checker_dir251 local version_checker_dir
228 local run_file252 local run_file
229 253 
230- [[ -n "${CANN_PATH}" ]] || fail "CANN path is not set; source set_env.sh or use --cann-path"254+ [[ -n "${CANN_PATH}" ]] || fail "CANN path is not set; source set_env.sh or use --cann_path"
231 [[ "${CANN_PATH}" = /* ]] || fail "CANN path must be absolute: ${CANN_PATH}"255 [[ "${CANN_PATH}" = /* ]] || fail "CANN path must be absolute: ${CANN_PATH}"
232 CANN_PATH=$(readlink -f -- "${CANN_PATH}")256 CANN_PATH=$(readlink -f -- "${CANN_PATH}")
233 [[ -d "${CANN_PATH}" ]] || fail "CANN path does not exist: ${CANN_PATH}"257 [[ -d "${CANN_PATH}" ]] || fail "CANN path does not exist: ${CANN_PATH}"
258+ PACKAGE_VERSION=$(read_project_version)
234 [[ "${PACKAGE_VERSION}" =~ ^[0-9A-Za-z._+-]+$ ]] || fail "invalid package version: ${PACKAGE_VERSION}"259 [[ "${PACKAGE_VERSION}" =~ ^[0-9A-Za-z._+-]+$ ]] || fail "invalid package version: ${PACKAGE_VERSION}"
235 260 
236 arch=$(normalize_arch)261 arch=$(normalize_arch)
@@ -256,13 +281,15 @@ build_package()
256 "${STAGING_DIR}/payload/asc/impl/adv_api/detail/hcomm" \281 "${STAGING_DIR}/payload/asc/impl/adv_api/detail/hcomm" \
257 550282 550
258 copy_headers \283 copy_headers \
259- "${PROJECT_ROOT}/include/aicore/ain" \284+ "${PROJECT_ROOT}/include" \
260- "${STAGING_DIR}/payload/asc/include/comm_api/aicore/ain" \285+ "${STAGING_DIR}/payload/asc/include/comm_api" \
261- 550286+ 550 \
287+ aicore/hcomm
262 copy_headers \288 copy_headers \
263- "${PROJECT_ROOT}/src/aicore/ain" \289+ "${PROJECT_ROOT}/src" \
264- "${STAGING_DIR}/payload/asc/impl/comm_api/aicore/ain" \290+ "${STAGING_DIR}/payload/asc/impl/comm_api" \
265- 550291+ 550 \
292+ aicore/hcomm
266 write_manifest293 write_manifest
267 write_link_manifest294 write_link_manifest
268 write_version_info \295 write_version_info \
@@ -1,18 +1,18 @@
1asc-comm development patch package1asc-comm development patch package
2 2 
3- --full Install or update packaged Hcomm and Ain headers3+ --full Install or update packaged asc-comm headers
4 --uninstall Restore first-install originals and remove new files4 --uninstall Restore first-install originals and remove new files
5 --check Verify payload and dependencies without modifying CANN5 --check Verify payload and dependencies without modifying CANN
6 --install-path=<ASCEND_ROOT> Select the Ascend install root; default follows6 --install-path=<ASCEND_ROOT> Select the Ascend install root; default follows
7 CANN packages (/usr/local/Ascend or $HOME/Ascend)7 CANN packages (/usr/local/Ascend or $HOME/Ascend)
8+ --install-for-all Allow all users to read and traverse installed files
8 --force Override installed-file consistency checks9 --force Override installed-file consistency checks
9 10 
10Hcomm headers are installed under asc/include/adv_api/hcomm/ and11Hcomm headers are installed under asc/include/adv_api/hcomm/ and
11asc/impl/adv_api/detail/hcomm/. Ain headers are installed under12asc/impl/adv_api/detail/hcomm/. Ain headers are installed under
12-asc/include/comm_api/aicore/ain/ and asc/impl/comm_api/aicore/ain/. Hcomm13+asc/include/comm_api/aicore/ain/ and asc/impl/comm_api/aicore/ain/. Other
13-links are created under comm_api/aicore/. Existing files and link state are14+headers preserve their paths under asc/include/comm_api/ or
14-backed up under var/asc-comm-dev-patch/baseline/. This package is intended15+asc/impl/comm_api/. Hcomm links are created under comm_api/aicore/. Recompile
15-only for local development verification. Recompile the target Ascend C kernel16+the target Ascend C kernel after installation. Pass the same --install-path
16-after installation. Only paths present in the package manifest are managed;17+when uninstalling. --force discards local changes to managed files, but does
17-this is not a full directory mirror. --force does not override architecture18+not override architecture or payload checksum checks.
18-or payload checksum checks.
@@ -65,6 +65,7 @@ Options:
65 --check Verify payload and dependency compatibility without modifying CANN65 --check Verify payload and dependency compatibility without modifying CANN
66 --install-path=<PATH> Ascend install root; defaults to /usr/local/Ascend for root66 --install-path=<PATH> Ascend install root; defaults to /usr/local/Ascend for root
67 or \$HOME/Ascend for a non-root user67 or \$HOME/Ascend for a non-root user
68+ --install-for-all Allow all users to read and traverse installed files
68 --force Ignore installed-file consistency checks69 --force Ignore installed-file consistency checks
69 -h, --help Display this help70 -h, --help Display this help
70EOF71EOF
@@ -201,6 +202,9 @@ parse_args()
201 --install-path=*)202 --install-path=*)
202 INSTALL_PATH=${1#*=}203 INSTALL_PATH=${1#*=}
203 ;;204 ;;
205+ --install-for-all)
206+ INSTALL_FOR_ALL=true
207+ ;;
204 --force)208 --force)
205 FORCE=true209 FORCE=true
206 ;;210 ;;
@@ -266,6 +270,76 @@ check_owner()
266 "current user uid ${current_uid} does not own CANN path ${CANN_ROOT} (uid ${owner_uid})"270 "current user uid ${current_uid} does not own CANN path ${CANN_ROOT} (uid ${owner_uid})"
267}271}
268 272 
273+collect_install_for_all_parent_directories()
274+{
275+ local path=$1
276+ local managed_directories=$2
277+ local output=$3
278+ local directory
279+ local relative_directory
280+ 
281+ # Avoid a double slash when the CANN root itself is `/`; some dirname
282+ # implementations preserve `//`, which would otherwise never reach `/`.
283+ directory=$(dirname -- "${CANN_ROOT%/}/${path}")
284+ while :; do
285+ if [[ "${directory}" == "${CANN_ROOT}" ]]; then
286+ relative_directory=""
287+ elif [[ "${CANN_ROOT}" == "/" ]]; then
288+ relative_directory=${directory#/}
289+ elif [[ "${directory}" == "${CANN_ROOT}/"* ]]; then
290+ relative_directory=${directory#"${CANN_ROOT}/"}
291+ else
292+ relative_directory=""
293+ fi
294+ if [[ -z "${relative_directory}" ]] || \
295+ ! grep -Fqx -- "${relative_directory}" "${managed_directories}"; then
296+ if [[ -d "${directory}" ]]; then
297+ printf '%s\n' "${directory}" >> "${output}"
298+ fi
299+ fi
300+ [[ "${directory}" == "/" ]] && break
301+ directory=$(dirname -- "${directory}")
302+ done
303+}
304+ 
305+check_install_for_all()
306+{
307+ local package_paths=$1
308+ local managed_directories=$2
309+ local directories_to_check="${WORK_DIR}/install-for-all.directories"
310+ local path
311+ local directory
312+ local mode
313+ local other_mode
314+ 
315+ [[ "${INSTALL_FOR_ALL}" == true ]] || return 0
316+ : > "${directories_to_check}"
317+ 
318+ # Check every existing parent of a package path. Directories recorded in
319+ # managed_directories receive an explicit mode later and do not need this
320+ # pre-check; their un-managed parents must already be traversable by all users.
321+ while IFS= read -r path; do
322+ collect_install_for_all_parent_directories \
323+ "${path}" "${managed_directories}" "${directories_to_check}"
324+ done < "${package_paths}"
325+ while IFS=$'\t' read -r path _; do
326+ collect_install_for_all_parent_directories \
327+ "${path}" "${managed_directories}" "${directories_to_check}"
328+ done < "${PACKAGE_LINKS}"
329+ 
330+ while IFS= read -r directory; do
331+ mode=$(stat -c %a -- "${directory}")
332+ other_mode=${mode: -1}
333+ case "${other_mode}" in
334+ 5|7)
335+ ;;
336+ *)
337+ fail "directory ${directory} permission ${mode} does not support --install-for-all"
338+ ;;
339+ esac
340+ done < <(sort -u "${directories_to_check}")
341+}
342+ 
269acquire_install_lock()343acquire_install_lock()
270{344{
271 command -v flock >/dev/null 2>&1 || fail "command flock was not found"345 command -v flock >/dev/null 2>&1 || fail "command flock was not found"
@@ -325,7 +399,7 @@ is_allowed_path()
325 local path=$1399 local path=$1
326 case "${path}" in400 case "${path}" in
327 asc/include/adv_api/*/*.h|asc/impl/adv_api/detail/*/*.h|\401 asc/include/adv_api/*/*.h|asc/impl/adv_api/detail/*/*.h|\
328- asc/include/comm_api/aicore/*/*.h|asc/impl/comm_api/aicore/*/*.h)402+ asc/include/comm_api/*.h|asc/impl/comm_api/*.h)
329 ;;403 ;;
330 *)404 *)
331 return 1405 return 1
@@ -341,8 +415,8 @@ is_allowed_directory_path()
341 local path=$1415 local path=$1
342 case "${path}" in416 case "${path}" in
343 asc/include/adv_api/*|asc/impl/adv_api/detail/*|\417 asc/include/adv_api/*|asc/impl/adv_api/detail/*|\
344- asc/include/comm_api|asc/include/comm_api/aicore|asc/include/comm_api/aicore/*|\418+ asc/include/comm_api|asc/include/comm_api/*|\
345- asc/impl/comm_api|asc/impl/comm_api/aicore|asc/impl/comm_api/aicore/*)419+ asc/impl/comm_api|asc/impl/comm_api/*)
346 ;;420 ;;
347 *)421 *)
348 return 1422 return 1
@@ -360,7 +434,7 @@ payload_file_mode()
360 434 
361 case "${path}" in435 case "${path}" in
362 asc/include/adv_api/*|asc/impl/adv_api/detail/*|\436 asc/include/adv_api/*|asc/impl/adv_api/detail/*|\
363- asc/include/comm_api/aicore/*|asc/impl/comm_api/aicore/*)437+ asc/include/comm_api/*|asc/impl/comm_api/*)
364 mode=550438 mode=550
365 ;;439 ;;
366 *)440 *)
@@ -379,8 +453,8 @@ managed_directory_mode()
379 asc/include/adv_api/*|asc/impl/adv_api/detail/*)453 asc/include/adv_api/*|asc/impl/adv_api/detail/*)
380 mode=750454 mode=750
381 ;;455 ;;
382- asc/include/comm_api|asc/include/comm_api/aicore|asc/include/comm_api/aicore/*|\456+ asc/include/comm_api|asc/include/comm_api/*|\
383- asc/impl/comm_api|asc/impl/comm_api/aicore|asc/impl/comm_api/aicore/*)457+ asc/impl/comm_api|asc/impl/comm_api/*)
384 mode=550458 mode=550
385 ;;459 ;;
386 *)460 *)
@@ -428,10 +502,10 @@ collect_managed_directories()
428 module=${relative_path%%/*}502 module=${relative_path%%/*}
429 managed_root="asc/impl/adv_api/detail/${module}"503 managed_root="asc/impl/adv_api/detail/${module}"
430 ;;504 ;;
431- asc/include/comm_api/aicore/*)505+ asc/include/comm_api/*)
432 managed_root="asc/include/comm_api"506 managed_root="asc/include/comm_api"
433 ;;507 ;;
434- asc/impl/comm_api/aicore/*)508+ asc/impl/comm_api/*)
435 managed_root="asc/impl/comm_api"509 managed_root="asc/impl/comm_api"
436 ;;510 ;;
437 esac511 esac
@@ -1151,6 +1225,7 @@ install_patch()
1151 1225 
1152 collect_checksum_paths "${PACKAGE_MANIFEST}" "${package_paths}"1226 collect_checksum_paths "${PACKAGE_MANIFEST}" "${package_paths}"
1153 collect_managed_directories "${package_paths}" "${package_directories}"1227 collect_managed_directories "${package_paths}" "${package_directories}"
1228+ check_install_for_all "${package_paths}" "${package_directories}"
1154 verify_checksums "${PAYLOAD_DIR}" "${PACKAGE_MANIFEST}" || fail "package payload checksum verification failed"1229 verify_checksums "${PAYLOAD_DIR}" "${PACKAGE_MANIFEST}" || fail "package payload checksum verification failed"
1155 : > "${baseline_paths}"1230 : > "${baseline_paths}"
1156 : > "${active_paths}"1231 : > "${active_paths}"
@@ -21,6 +21,7 @@ RUN_FILE=$(readlink -f -- "${RUN_FILE}")
21 21 
22TEST_ROOT=$(mktemp -d)22TEST_ROOT=$(mktemp -d)
23trap 'rm -rf -- "${TEST_ROOT}"' EXIT23trap 'rm -rf -- "${TEST_ROOT}"' EXIT
24+chmod 755 "${TEST_ROOT}"
24EXTRACT_DIR="${TEST_ROOT}/extracted"25EXTRACT_DIR="${TEST_ROOT}/extracted"
25FAKE_CANN="${TEST_ROOT}/cann"26FAKE_CANN="${TEST_ROOT}/cann"
26BASELINE_DIR="${TEST_ROOT}/baseline"27BASELINE_DIR="${TEST_ROOT}/baseline"
@@ -77,6 +78,10 @@ write_dependency_versions()
77# build.sh must propagate packaging failures to CI and other callers.78# build.sh must propagate packaging failures to CI and other callers.
78expect_failure env ASCEND_HOME_PATH="${TEST_ROOT}/missing-cann" \79expect_failure env ASCEND_HOME_PATH="${TEST_ROOT}/missing-cann" \
79 bash "${PROJECT_ROOT}/build.sh" --pkg80 bash "${PROJECT_ROOT}/build.sh" --pkg
81+expect_failure bash "${PROJECT_ROOT}/scripts/package/build_package.sh" \
82+ --cann-path="${TEST_ROOT}/missing-cann"
83+bash "${PROJECT_ROOT}/scripts/package/build_package.sh" --help > "${ERROR_LOG}"
84+grep -q -- '--cann_path=<PATH>' "${ERROR_LOG}"
80 85 
81"${RUN_FILE}" --noexec --extract="${EXTRACT_DIR}" >/dev/null86"${RUN_FILE}" --noexec --extract="${EXTRACT_DIR}" >/dev/null
82REQUIRED_ASC_DEVKIT_VERSION=$(read_required_version "asc-devkit")87REQUIRED_ASC_DEVKIT_VERSION=$(read_required_version "asc-devkit")
@@ -89,11 +94,17 @@ REQUIRED_RUNTIME_VERSION=$(read_required_version "runtime")
89PACKAGE_GIT_DIRTY=$(awk -F= '$1 == "GitDirty" {print $2; exit}' "${EXTRACT_DIR}/version.info")94PACKAGE_GIT_DIRTY=$(awk -F= '$1 == "GitDirty" {print $2; exit}' "${EXTRACT_DIR}/version.info")
90EXPECTED_GIT_DIRTY=true95EXPECTED_GIT_DIRTY=true
91if [[ -z "$(git -C "${PROJECT_ROOT}" status --porcelain --untracked-files=all -- \96if [[ -z "$(git -C "${PROJECT_ROOT}" status --porcelain --untracked-files=all -- \
92- build.sh include/aicore/ain include/aicore/hcomm \97+ build.sh include src scripts/package version.cmake)" ]]; then
93- src/aicore/ain src/aicore/hcomm scripts/package)" ]]; then
94 EXPECTED_GIT_DIRTY=false98 EXPECTED_GIT_DIRTY=false
95fi99fi
96[[ "${PACKAGE_GIT_DIRTY}" == "${EXPECTED_GIT_DIRTY}" ]]100[[ "${PACKAGE_GIT_DIRTY}" == "${EXPECTED_GIT_DIRTY}" ]]
101+EXPECTED_PACKAGE_VERSION=$(sed -nE \
102+ 's/^[[:space:]]*set\(ASCCOMM_VERSION[[:space:]]+"([^"]+)"\)[[:space:]]*$/\1/p' \
103+ "${PROJECT_ROOT}/version.cmake")
104+[[ "$(awk -F= '$1 == "PackageVersion" {print $2; exit}' "${EXTRACT_DIR}/version.info")" == \
105+ "${EXPECTED_PACKAGE_VERSION}" ]]
106+[[ "$(awk -F= '$1 == "Version" {print $2; exit}' "${EXTRACT_DIR}/version.info")" == \
107+ "${EXPECTED_PACKAGE_VERSION}" ]]
97 108 
98# Reject module-directory links that would redirect package writes outside CANN_ROOT.109# Reject module-directory links that would redirect package writes outside CANN_ROOT.
99EXTERNAL_LINK_CANN="${TEST_ROOT}/external-link-cann"110EXTERNAL_LINK_CANN="${TEST_ROOT}/external-link-cann"
@@ -141,14 +152,17 @@ run_package --uninstall --install-path="${INTERNAL_LINK_CANN}"
141 152 
142HCOMM_PUBLIC_HEADER_COUNT=$(find "${PROJECT_ROOT}/include/aicore/hcomm" -type f -name '*.h' | wc -l)153HCOMM_PUBLIC_HEADER_COUNT=$(find "${PROJECT_ROOT}/include/aicore/hcomm" -type f -name '*.h' | wc -l)
143HCOMM_IMPL_HEADER_COUNT=$(find "${PROJECT_ROOT}/src/aicore/hcomm" -type f -name '*.h' | wc -l)154HCOMM_IMPL_HEADER_COUNT=$(find "${PROJECT_ROOT}/src/aicore/hcomm" -type f -name '*.h' | wc -l)
144-AIN_PUBLIC_HEADER_COUNT=$(find "${PROJECT_ROOT}/include/aicore/ain" -type f -name '*.h' | wc -l)155+COMM_API_PUBLIC_HEADER_COUNT=$(find "${PROJECT_ROOT}/include" -type f -name '*.h' \
145-AIN_IMPL_HEADER_COUNT=$(find "${PROJECT_ROOT}/src/aicore/ain" -type f -name '*.h' | wc -l)156+ ! -path "${PROJECT_ROOT}/include/aicore/hcomm/*" | wc -l)
157+COMM_API_IMPL_HEADER_COUNT=$(find "${PROJECT_ROOT}/src" -type f -name '*.h' \
158+ ! -path "${PROJECT_ROOT}/src/aicore/hcomm/*" | wc -l)
146EXPECTED_FILE_COUNT=$((HCOMM_PUBLIC_HEADER_COUNT + HCOMM_IMPL_HEADER_COUNT + \159EXPECTED_FILE_COUNT=$((HCOMM_PUBLIC_HEADER_COUNT + HCOMM_IMPL_HEADER_COUNT + \
147- AIN_PUBLIC_HEADER_COUNT + AIN_IMPL_HEADER_COUNT))160+ COMM_API_PUBLIC_HEADER_COUNT + COMM_API_IMPL_HEADER_COUNT))
148[[ "$(wc -l < "${EXTRACT_DIR}/manifest.sha256")" -eq "${EXPECTED_FILE_COUNT}" ]]161[[ "$(wc -l < "${EXTRACT_DIR}/manifest.sha256")" -eq "${EXPECTED_FILE_COUNT}" ]]
149[[ ! -e "${EXTRACT_DIR}/payload/asc/include/adv_api/ain" ]]162[[ ! -e "${EXTRACT_DIR}/payload/asc/include/adv_api/ain" ]]
150[[ ! -e "${EXTRACT_DIR}/payload/asc/impl/adv_api/hcomm" ]]163[[ ! -e "${EXTRACT_DIR}/payload/asc/impl/adv_api/hcomm" ]]
151[[ ! -e "${EXTRACT_DIR}/payload/asc/impl/adv_api/detail/ain" ]]164[[ ! -e "${EXTRACT_DIR}/payload/asc/impl/adv_api/detail/ain" ]]
165+[[ -f "${EXTRACT_DIR}/payload/asc/include/comm_api/ccu/ccu_host_launch.h" ]]
152[[ ! -e "${EXTRACT_DIR}/payload/aarch64-linux" ]]166[[ ! -e "${EXTRACT_DIR}/payload/aarch64-linux" ]]
153[[ ! -e "${EXTRACT_DIR}/payload/x86_64-linux" ]]167[[ ! -e "${EXTRACT_DIR}/payload/x86_64-linux" ]]
154diff -u <(printf '%s\t%s\n' \168diff -u <(printf '%s\t%s\n' \
@@ -167,31 +181,18 @@ while IFS= read -r -d '' source_file; do
167done < <(find "${PROJECT_ROOT}/src/aicore/hcomm" -type f -name '*.h' -print0 | sort -z)181done < <(find "${PROJECT_ROOT}/src/aicore/hcomm" -type f -name '*.h' -print0 | sort -z)
168 182 
169while IFS= read -r -d '' source_file; do183while IFS= read -r -d '' source_file; do
170- relative_path=${source_file#"${PROJECT_ROOT}/include/aicore/ain/"}184+ relative_path=${source_file#"${PROJECT_ROOT}/include/"}
171 cmp "${source_file}" \185 cmp "${source_file}" \
172- "${EXTRACT_DIR}/payload/asc/include/comm_api/aicore/ain/${relative_path}"186+ "${EXTRACT_DIR}/payload/asc/include/comm_api/${relative_path}"
173-done < <(find "${PROJECT_ROOT}/include/aicore/ain" -type f -name '*.h' -print0 | sort -z)187+done < <(find "${PROJECT_ROOT}/include" -type f -name '*.h' \
188+ ! -path "${PROJECT_ROOT}/include/aicore/hcomm/*" -print0 | sort -z)
174 189 
175while IFS= read -r -d '' source_file; do190while IFS= read -r -d '' source_file; do
176- relative_path=${source_file#"${PROJECT_ROOT}/src/aicore/ain/"}191+ relative_path=${source_file#"${PROJECT_ROOT}/src/"}
177 cmp "${source_file}" \192 cmp "${source_file}" \
178- "${EXTRACT_DIR}/payload/asc/impl/comm_api/aicore/ain/${relative_path}"193+ "${EXTRACT_DIR}/payload/asc/impl/comm_api/${relative_path}"
179-done < <(find "${PROJECT_ROOT}/src/aicore/ain" -type f -name '*.h' -print0 | sort -z)194+done < <(find "${PROJECT_ROOT}/src" -type f -name '*.h' \
180- 195+ ! -path "${PROJECT_ROOT}/src/aicore/hcomm/*" -print0 | sort -z)
181-RELATIVE_DETAIL_INCLUDE_COUNT=0
182-while IFS= read -r -d '' source_file; do
183- relative_path=${source_file#"${PROJECT_ROOT}/include/aicore/hcomm/"}
184- packaged_header="${EXTRACT_DIR}/payload/asc/include/adv_api/hcomm/${relative_path}"
185- while IFS= read -r include_path; do
186- case "${include_path}" in
187- ../../../impl/adv_api/detail/*)
188- [[ -f "$(dirname -- "${packaged_header}")/${include_path}" ]]
189- RELATIVE_DETAIL_INCLUDE_COUNT=$((RELATIVE_DETAIL_INCLUDE_COUNT + 1))
190- ;;
191- esac
192- done < <(awk -F '"' '/^[[:space:]]*#[[:space:]]*include[[:space:]]*"/ {print $2}' "${packaged_header}")
193-done < <(find "${PROJECT_ROOT}/include/aicore/hcomm" -type f -name '*.h' -print0 | sort -z)
194-[[ ${RELATIVE_DETAIL_INCLUDE_COUNT} -gt 0 ]]
195 196 
196mkdir -p \197mkdir -p \
197 "${FAKE_CANN}/asc/include/adv_api/hcomm" \198 "${FAKE_CANN}/asc/include/adv_api/hcomm" \
@@ -227,6 +228,7 @@ done < "${EXTRACT_DIR}/manifest.sha256"
227[[ "$(stat -c %a -- "${FAKE_CANN}/asc/include/comm_api")" == "${EXPECTED_COMM_API_DIR_MODE}" ]]228[[ "$(stat -c %a -- "${FAKE_CANN}/asc/include/comm_api")" == "${EXPECTED_COMM_API_DIR_MODE}" ]]
228[[ "$(stat -c %a -- "${FAKE_CANN}/asc/include/comm_api/aicore")" == "${EXPECTED_COMM_API_DIR_MODE}" ]]229[[ "$(stat -c %a -- "${FAKE_CANN}/asc/include/comm_api/aicore")" == "${EXPECTED_COMM_API_DIR_MODE}" ]]
229[[ "$(stat -c %a -- "${FAKE_CANN}/asc/include/comm_api/aicore/ain")" == "${EXPECTED_COMM_API_DIR_MODE}" ]]230[[ "$(stat -c %a -- "${FAKE_CANN}/asc/include/comm_api/aicore/ain")" == "${EXPECTED_COMM_API_DIR_MODE}" ]]
231+[[ "$(stat -c %a -- "${FAKE_CANN}/asc/include/comm_api/ccu")" == "${EXPECTED_COMM_API_DIR_MODE}" ]]
230[[ "$(stat -c %a -- "${FAKE_CANN}/asc/impl/comm_api")" == "${EXPECTED_COMM_API_DIR_MODE}" ]]232[[ "$(stat -c %a -- "${FAKE_CANN}/asc/impl/comm_api")" == "${EXPECTED_COMM_API_DIR_MODE}" ]]
231[[ "$(stat -c %a -- "${FAKE_CANN}/asc/impl/comm_api/aicore")" == "${EXPECTED_COMM_API_DIR_MODE}" ]]233[[ "$(stat -c %a -- "${FAKE_CANN}/asc/impl/comm_api/aicore")" == "${EXPECTED_COMM_API_DIR_MODE}" ]]
232[[ "$(stat -c %a -- "${FAKE_CANN}/asc/impl/comm_api/aicore/ain")" == "${EXPECTED_COMM_API_DIR_MODE}" ]]234[[ "$(stat -c %a -- "${FAKE_CANN}/asc/impl/comm_api/aicore/ain")" == "${EXPECTED_COMM_API_DIR_MODE}" ]]
@@ -235,7 +237,7 @@ done < "${EXTRACT_DIR}/manifest.sha256"
235[[ -L "${FAKE_CANN}/asc/impl/comm_api/aicore/hcomm" ]]237[[ -L "${FAKE_CANN}/asc/impl/comm_api/aicore/hcomm" ]]
236[[ "$(readlink -- "${FAKE_CANN}/asc/impl/comm_api/aicore/hcomm")" == "../../adv_api/detail/hcomm" ]]238[[ "$(readlink -- "${FAKE_CANN}/asc/impl/comm_api/aicore/hcomm")" == "../../adv_api/detail/hcomm" ]]
237 239 
238-# Relative Ain includes must resolve from their deeper comm_api/aicore layout.240+# Relative includes must resolve through the installed layout and Hcomm links.
239while IFS= read -r installed_header; do241while IFS= read -r installed_header; do
240 while IFS= read -r include_path; do242 while IFS= read -r include_path; do
241 case "${include_path}" in243 case "${include_path}" in
@@ -246,8 +248,10 @@ while IFS= read -r installed_header; do
246 done < <(awk -F '"' '/^[[:space:]]*#[[:space:]]*include[[:space:]]*"/ {print $2}' \248 done < <(awk -F '"' '/^[[:space:]]*#[[:space:]]*include[[:space:]]*"/ {print $2}' \
247 "${installed_header}")249 "${installed_header}")
248done < <(find \250done < <(find \
249- "${FAKE_CANN}/asc/include/comm_api/aicore/ain" \251+ "${FAKE_CANN}/asc/include/adv_api/hcomm" \
250- "${FAKE_CANN}/asc/impl/comm_api/aicore/ain" \252+ "${FAKE_CANN}/asc/impl/adv_api/detail/hcomm" \
253+ "${FAKE_CANN}/asc/include/comm_api" \
254+ "${FAKE_CANN}/asc/impl/comm_api" \
251 -type f -name '*.h' | sort)255 -type f -name '*.h' | sort)
252 256 
253[[ -f "${FAKE_CANN}/var/asc-comm-dev-patch/active.manifest.sha256" ]]257[[ -f "${FAKE_CANN}/var/asc-comm-dev-patch/active.manifest.sha256" ]]
@@ -309,6 +313,45 @@ run_package --uninstall --install-path="${PREEXISTING_LINK_CANN}"
309[[ "$(readlink -- "${PREEXISTING_LINK_CANN}/asc/impl/comm_api/aicore/hcomm")" == \313[[ "$(readlink -- "${PREEXISTING_LINK_CANN}/asc/impl/comm_api/aicore/hcomm")" == \
310 "../../adv_api/detail/hcomm" ]]314 "../../adv_api/detail/hcomm" ]]
311 315 
316+# Match devkit's --install-for-all behavior for a non-root installation as well.
317+INSTALL_FOR_ALL_CANN="${TEST_ROOT}/install-for-all-cann"
318+mkdir -p \
319+ "${INSTALL_FOR_ALL_CANN}/asc/include/adv_api" \
320+ "${INSTALL_FOR_ALL_CANN}/asc/impl/adv_api/detail"
321+chmod 755 "${INSTALL_FOR_ALL_CANN}"
322+write_dependency_versions "${INSTALL_FOR_ALL_CANN}"
323+run_package --full --install-for-all --install-path="${INSTALL_FOR_ALL_CANN}"
324+while read -r _ path; do
325+ [[ "$(stat -c %a -- "${INSTALL_FOR_ALL_CANN}/${path}")" == "555" ]]
326+done < "${EXTRACT_DIR}/manifest.sha256"
327+[[ "$(stat -c %a -- "${INSTALL_FOR_ALL_CANN}/asc/include/adv_api/hcomm")" == "755" ]]
328+[[ "$(stat -c %a -- "${INSTALL_FOR_ALL_CANN}/asc/include/comm_api")" == "555" ]]
329+run_package --uninstall --install-path="${INSTALL_FOR_ALL_CANN}"
330+ 
331+# A restrictive public parent directory must reject install-for-all before mutation.
332+RESTRICTED_PARENT_CANN="${TEST_ROOT}/restricted-parent-cann"
333+mkdir -p \
334+ "${RESTRICTED_PARENT_CANN}/asc/include/adv_api" \
335+ "${RESTRICTED_PARENT_CANN}/asc/impl/adv_api/detail"
336+chmod 755 "${RESTRICTED_PARENT_CANN}"
337+chmod 750 "${RESTRICTED_PARENT_CANN}/asc"
338+write_dependency_versions "${RESTRICTED_PARENT_CANN}"
339+expect_failure run_package --full --install-for-all --install-path="${RESTRICTED_PARENT_CANN}"
340+grep -q 'directory .* does not support --install-for-all' "${ERROR_LOG}"
341+[[ ! -e "${RESTRICTED_PARENT_CANN}/var/asc-comm-dev-patch" ]]
342+ 
343+if [[ $(id -u) -ne 0 ]]; then
344+ RESTRICTED_CANN="${TEST_ROOT}/restricted-cann"
345+ mkdir -p \
346+ "${RESTRICTED_CANN}/asc/include/adv_api" \
347+ "${RESTRICTED_CANN}/asc/impl/adv_api/detail"
348+ chmod 750 "${RESTRICTED_CANN}"
349+ write_dependency_versions "${RESTRICTED_CANN}"
350+ expect_failure run_package --full --install-for-all --install-path="${RESTRICTED_CANN}"
351+ grep -q 'does not support --install-for-all' "${ERROR_LOG}"
352+ [[ ! -e "${RESTRICTED_CANN}/var/asc-comm-dev-patch" ]]
353+fi
354+ 
312# Wrong links and non-link occupants are never overwritten, including with --force.355# Wrong links and non-link occupants are never overwritten, including with --force.
313INVALID_LINK_CANN="${TEST_ROOT}/invalid-link-cann"356INVALID_LINK_CANN="${TEST_ROOT}/invalid-link-cann"
314mkdir -p \357mkdir -p \
@@ -0,0 +1,11 @@
1+# -----------------------------------------------------------------------------------------------------------
2+# Copyright (c) 2026 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+set(ASCCOMM_VERSION "9.2.0")