Skip to content

[tools] fix: replace console emoji in attachconfig.py to support non-UTF-8 consoles - #11908

Open
Yunlk wants to merge 1 commit into
RT-Thread:masterfrom
Yunlk:fix/attach-emoji-gbk
Open

Yunlk wants to merge 1 commit into
RT-Thread:masterfrom
Yunlk:fix/attach-emoji-gbk

Conversation

@Yunlk

@Yunlk Yunlk commented Oct 20, 2026

Copy link
Copy Markdown

拉取/合并请求描述:(PR description)

[

为什么提交这份PR (why to submit this PR)

关联 issue #11906。

scons --attach 的三种用法(--attach=?、--attach=<name>、--attach=default)都会先打印一句带 emoji 的状态提示。Windows 上 Python 的 stdout 编码跟随区域代码页,中文系统是 936/GBK,无法编码 U+2705 / U+274C,于是直接抛异常、整个命令中止:

UnicodeEncodeError: 'gbk' codec can't encode character '\u2705' in position 5: illegal multibyte sequence
  File "tools/building.py", line 396:
    GenAttachConfigProject()
  File "tools/attachconfig.py", line 18:
    print("\033[32m\u2705 AttachConfig has: \033[0m")

因为三条路径都走同一个函数,所以该命令在中文 Windows 上完全不可用。设置 PYTHONIOENCODING=utf-8 可以绕过,但普通用户不会知道这个办法。

你的解决方案是什么 (what is your solution)

把这 4 处 emoji 换成纯 ASCII 标记([OK] / [ERR]),保留原有的 ANSI 颜色码——tools/env_utility.py、tools/ci/bsp_buildings.py 等脚本本来就在用 ANSI 彩色输出,属于既有约定。

改动仅限 tools/attachconfig.py 的 4 行 print,不涉及逻辑。tools/ci/ 下那些 emoji 是写进 GitHub Actions summary 的 Markdown,由 UTF-8 渲染,不受控制台编码影响,因此未做改动。

请提供验证的bsp和config (provide the config and bsp)

  • BSP: bsp/renesas/ra6m3-hmi-board(目前唯一带 .ci/attachconfig/attachconfig.yml 的可用目录)
  • .config: 无需改动,沿用 BSP 默认配置
  • action: 未使用 GitHub Actions;本地 Windows 11 中文版 + 默认代码页 936 实测

修复前后对照(同一终端,未设置 PYTHONIOENCODING):

命令 修复前 修复后
scons --attach=? UnicodeEncodeError 中止 正常列出 system.nano / devices.gpio / devices.uart / devices.soft_i2c
scons --attach=devices.uart UnicodeEncodeError 中止 写入 .config 并生成 .origin 备份
scons --attach=no.such.config UnicodeEncodeError 中止 打印 [ERR] Without this AttachConfig:no.such.config
scons --attach=default UnicodeEncodeError 中止 还原并删除备份,git status 无变更

四条路径的退出码均为 0,执行完 --attach=default 后工作区干净。

备注:clang-format 相关检查项不适用于 Python 文件;本改动保持与文件内既有代码完全一致的风格(无空格调整、无重排)。

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用clang-format 源码格式化工具确保格式符合RT-Thread代码规范 This PR has been formatted with clang-format and complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

scons --attach prints a check mark / cross emoji as status prefix. On
Windows the standard output encoding follows the locale code page (936/GBK
on a Chinese system), which cannot encode U+2705/U+274C, so Python raises
UnicodeEncodeError and the command aborts:

    UnicodeEncodeError: 'gbk' codec can't encode character '\u2705'
      File "tools/attachconfig.py", line 18, in GenAttachConfigProject

All three commands go through the same function, so --attach=?,
--attach=<name> and --attach=default were all unusable on such systems.

Replace the emoji with plain ASCII markers and keep the existing ANSI colour
codes, which the other scripts under tools/ already use.

Refs RT-Thread#11906
@github-actions

Copy link
Copy Markdown

👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!

为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。
To ensure your code complies with RT-Thread's coding style, please run the code formatting workflow by following the steps below (If the formatting of CI fails to run).


🛠 操作步骤 | Steps

  1. 前往 Actions 页面 | Go to the Actions page
    点击进入工作流 → | Click to open workflow →

  2. 点击 Run workflow | Click Run workflow

  • Use workflow from 保持默认分支(通常为 master)
    Keep the default branch (usually master) in Use workflow from
  • 在 branch 输入框填写 PR 分支 fix/attach-emoji-gbk
    Enter PR branch fix/attach-emoji-gbk in the branch field
  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将作为独立提交推送至你的分支。
    The formatting changes will be pushed to your branch as a separate commit.

完成后,提交将自动更新至 fix/attach-emoji-gbk 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the fix/attach-emoji-gbk branch automatically, and the related Pull Request will be updated.

如有问题欢迎联系我们,再次感谢您的贡献!💐
If you have any questions, feel free to reach out. Thanks again for your contribution!

@github-actions github-actions Bot added the tools label Oct 20, 2026
@CLAassistant

CLAassistant commented Oct 20, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Yunlk

Yunlk commented Oct 20, 2026

Copy link
Copy Markdown
Author

MemBrowse 失败的与本 PR 无关,麻烦重跑一次

本 PR 的 MemBrowse Memory Report(run #1214)里 21 个 analyze job 全部在 "Set up job" 这一步失败,一个都没能进入实际分析。查下来是上游第三方 action 的问题:

Failed to load membrowse/membrowse-action/v1/action.yml
GitHub.DistributedTask.ObjectTemplating.TemplateValidationException:
  The template is not valid. membrowse/membrowse-action/v1/action.yml
  (Line: 77, Col: 18): Unrecognized named-value: 'github'.
  Located at position 1 within expression: github.workspace

membrowse-action 在 source_root 这个 input 的 description 里写了 ${{ github.workspace }},而这个位置不允许使用 github 上下文,导致 runner 加载 action manifest 时直接失败。

时间线(本地时间 UTC+8)对得上:

时间 事件
2026-10-19 14:19 membrowse-action #187 引入该问题
2026-10-20 16:12 本 PR 的运行开始,落在损坏窗口内
2026-10-20 17:06 membrowse-action #191 "Remove expression from source_root input description" 修复

现在 v1 标签已经指向修复后的提交(重新拉取 action.yml 里已无该表达式),重新运行应该可以通过。

我对 RT-Thread/rt-thread 没有 Actions 重跑权限(接口返回 Must have admin rights to Repository.),所以麻烦维护者点一次 Re-run failed jobs。

本 PR 其余检查均为通过状态,未受影响:

Check File Format and License      success
ToolsCI                            success
Static code analysis               success
utest_auto_run                     success
RT-Thread BSP Static Build Check   success
pkgs_test                          success
Auto Review Assistant / Labeler / PR Format Notification  success
license/cla                        success

本 PR 只改了 tools/attachconfig.py 的 4 行 print,与这些 BSP 构建、内存分析都没有交集 —— 何况失败发生在任何项目代码执行之前。

@Yunlk

Yunlk commented Oct 20, 2026

Copy link
Copy Markdown
Author

@Rbb666 打扰一下。本 PR 的 MemBrowse Memory Report 唯一失败项是 21 个 analyze job 全部倒在 "Set up job",一个都没进入分析阶段。原因是上游 membrowse/membrowse-action@v1 的 action.yml 自己坏了(source_root 的 description 里用了 github.workspace,该位置不允许 github 上下文),已于今天 17:06 在 membrowse-action#191 修好。细节见上一条评论。

我没有本仓库 Actions 的重跑权限(需要写权限),方便的话请帮忙点一次 Re-run failed jobs。

(这条检查不在必需列表里,不影响合并,只是希望 CI 干净。)本 PR 其余检查全部通过,改动仅 tools/attachconfig.py 的 4 行 print。

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants