tools: harden attachconfig handling#11555
Open
yanhu7150-tech wants to merge 1 commit into
Open
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
拉取/合并请求描述:(PR description)
为什么提交这份PR (why to submit this PR)
本 PR 修复 RT-Thread Python 构建工具和 CI 脚本中 attachconfig 处理流程的若干健壮性问题。
修复前,在一些正常的 attachconfig 异常输入或缺省配置场景下,脚本可能直接抛出 Python 异常,或者在 BSP 目录中残留临时备份文件,影响后续构建流程的稳定性。具体问题包括:
tools/ci/bsp_buildings.py中直接使用os.getenv('SRTT_BSP').split(',')解析环境变量。当SRTT_BSP未设置或为空时,脚本会触发AttributeError,并输出 Python traceback,而不是给出明确的 CI 配置错误提示。tools/attachconfig.py在执行 attachconfig 查询模式时,会直接访问attachconfig[0]。当当前 BSP 没有任何 attachconfig 配置项时,会触发IndexError: list index out of range。在 YAML attachconfig 构建流程中,如果某个 project 缺少
kconfig字段,旧逻辑可能已经创建.config.origin备份文件后直接continue,导致.config.origin残留在 BSP 目录中,并跳过正常的.config恢复流程。一些 YAML 可选命令字段,例如
pre_build、build_cmd、post_build、msh_cmd,旧代码在未检查字段是否存在的情况下直接调用.splitlines()。当这些可选字段缺失时,可能触发非预期异常。以上问题属于普通构建工具健壮性缺陷,不涉及安全漏洞。
你的解决方案是什么 (what is your solution)
本 PR 对 attachconfig 处理流程进行了以下改进:
增加逗号分隔环境变量的安全解析逻辑:
SRTT_BSP前先检查环境变量是否存在且非空;SRTT_BSP缺失或为空时,输出明确错误信息:::error::SRTT_BSP is not set or empty;strip,并过滤空字符串;ATTACHCONFIG_RTT_BSP对 attachconfig BSP 过滤的原有行为。修复 attachconfig 查询结果为空时的异常:
scons --attach=?没有找到任何 attachconfig 项时,输出No AttachConfig found.;IndexError。增强 YAML 可选命令字段处理:
None调用.splitlines();改进
.config备份和恢复流程:kconfig的 YAML project,在创建.config.origin前直接跳过;.config.origin的构建流程使用try/finally保护;.config,并删除.config.origin;新增回归测试,覆盖以下场景:
SRTT_BSP未设置;kconfig;bsp_board_info缺少可选命令字段。请提供验证的bsp和config (provide the config and bsp)
本 PR 只修改 Python 构建/CI 辅助脚本,并新增对应回归测试,不涉及具体 BSP 源码修改。
本 PR 不需要修改任何 BSP
.config选项。本 PR 已在本地完成 Python 语法检查和回归测试。提交 PR 后,可继续以 GitHub Actions 的结果为准。
本地验证命令如下:
本地测试结果如下:
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up