已合并
[feat] add json validator #5068
sjtulxh创建于 26 天前
[feat] add json validator #5068
已合并
sjtulxh创建于 26 天前
sjtulxh成员
26 天前

[feat] add resource manifest validation

描述

新增资源清单 JSON 校验器,对 manifest 的基础字段、资源路径、编译选项、Kernel、常量、Object、Command、输出引用及占位符语法进行完整校验。

主要改动:

  • 将资源目录字段由 base_dir 切换为 resource_path,加载资源前执行 manifest 校验。
  • 新增安全相对路径检查,拒绝绝对路径、路径穿越、反斜杠及非法路径格式。
  • 加强资源目录的符号链接、特殊文件和目录深度检查。
  • file_utils.cpp 中的 ASCENDLOGW 调整为 ASCENDLOGE
  • asc_compile_exporter 增加 -h--help 选项。
  • 编译失败或捕获异常时,提示用户通过 plog 查看详细日志。
  • 补充资源清单校验器、CLI、Repository 和 FileUtils 相关单元测试。

关联的Issue

无。

测试

  • 重新构建 asc_compile_exporter 生产目标,构建成功。
  • 重新构建 ascendc_ut_asc_compile_exporter 单元测试目标,构建成功。
  • 执行完整单元测试:58/58 通过。
  • resource_manifest_validator.cpp 行覆盖率:100%(283/283)。
  • resource_manifest_validator.cpp 函数覆盖率:100%(20/20)。
  • 新增校验器源文件通过 clang-format 检查。
  • git diff --check 检查通过。

文档更新

无文档更新。

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 sjtulxh 的贡献)
Ssjtulxh成员
26 天前 创建了 pull request,commit 9b6efbc9
atomgit-bot
atomgit-bot
26 天前 评论:

变更摘要

本 PR 主要新增资源清单 JSON 校验器,对 manifest 的基础字段、资源路径、编译选项、Kernel、常量、Object、Command、输出引用及占位符语法进行完整校验,并将资源目录字段由 base_dir 切换为 resource_path,在加载资源前执行校验。同时新增安全相对路径检查与相关单元测试,并优化了 CLI 的帮助输出和异常/失败时的日志提示。

主要改动

  • 新增 resource_manifest_validator:新增 resource_manifest_validator.h/.cpp,通过 ValidateResourceManifest 校验 manifest 的 schema_versionresource_idsoc_versionkernels 等基础字段,以及常量、对象、命令、编译选项、${resource}${output} 等占位符语法与输出引用一致性。
  • 资源目录字段切换为 resource_pathcollected_manifest_repository.cpp 中的 ReadBaseDir 改为 ReadResourcePath,在读取 manifest 时调用 ValidateResourceManifest,并以 resource_path 替代原 base_dir 解析和加载资源目录。
  • 新增安全相对路径检查file_utils.h/.cpp 新增 FileUtils::IsSafeRelativePath,用于拒绝绝对路径、路径穿越、反斜杠、./.. 组件、重复分隔符及嵌入 NUL 等非法路径格式。
  • CLI 行为增强asc_compile_exporter.cpp 新增 IsHelpRequestedRunWithExceptionHandling,支持 -h/--help 输出用法到标准输出并以 0 退出,编译失败或捕获异常时向用户提示通过 plog 查看详细日志。
  • 日志级别与函数签名调整file_utils.cpp 将多处 ASCENDLOGW 调整为 ASCENDLOGE,并将 FileUtils::RemoveAll 声明为 noexcept,相应调整其错误日志输出方式。
  • 补充单元测试:新增 test_resource_manifest_validator.cpp,并扩展 test_asc_compile_exporter.cpptest_asc_compile_exporter_unit.cpptest_collected_manifest_repository.cpptest_file_utils.cpptest_support.h,覆盖校验器、CLI help、异常提示、路径安全及 repository 加载等场景。
likedislike
不准确?
atomgit-bot
atomgit-bot
26 天前 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
26 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
26 天前 评论:

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
For more, you also can visit HICANN


PR Approval Progress

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

Module Approval Details

module lgtm status approve status
repo-cann/asc-devkit 诸葛洵, XuebinYang (2/2) 诸葛洵, XuebinYang (2/1)
tools/build XuebinYang, 诸葛洵 (2/2) XuebinYang (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

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

likedislike
此处折叠了154条消息 查看更多
zhugexun_sjtu
zhugexun_sjtu成员
25 天前 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
25 天前 添加了label:lgtm
XuebinYang成员
25 天前 评论:

/approve

likedislike
CANN-robotCANN-robot成员
25 天前 添加了label:approved
CANN-robotCANN-robot成员
25 天前 合入了pull request