Fix env git clone handling#11591
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 修复
tools/env_utility.py中 RT-Thread ENV 初始化时git clone处理不健壮的问题。在
scons menuconfig、scons guiconfig、scons defconfig等配置入口中,building.py::PrepareBuilding()会调用tools/env_utility.py中的menuconfig()/guiconfig()/defconfig(),这些函数会先执行kconfiglib_check_installed()。当系统中尚未安装 RT-Thread ENV 工具、且PKGS_DIR不存在时,非 Windows 平台会进入touch_env()自动初始化.env目录和相关工具。原实现中,
touch_env()使用类似下面的方式执行git clone:该实现存在两个问题:
os.system()会通过 shell 执行命令,目标路径会被 shell 按空格拆分,导致git clone参数错误。例如用户目录或临时目录中包含空格时,目标路径可能被拆成多个参数,git clone会报Too many arguments或 clone 到错误位置。git clone因网络、缺少 git 工具、路径错误等原因失败后,原逻辑会继续执行后续初始化流程。此时如果.env/tools/scripts/Kconfig等文件不存在,后续shutil.copy()会抛出未解释的FileNotFoundError,导致错误信息不清晰,并可能留下未完整初始化的.env目录结构。该问题属于 ENV 初始化工具链的普通软件缺陷。ENV 初始化脚本应当能够正确处理包含空格的路径,并在 clone 失败时及时停止后续流程,而不是继续访问不存在的文件。
你的解决方案是什么 (what is your solution)
本 PR 只修改
tools/env_utility.py,未修改 BSP、Kconfig、Rust、CI 或其它无关模块。主要修改如下:
run_git_clone(url, dest)helper使用:
os.system('git clone %s %s' % (...))。这样
git clone参数会以 argv list 形式传递,不再经过 shell 分词,因此目标路径中即使包含空格,也会作为完整路径传给 git。touch_env()中三处 clone 逻辑以下三类仓库 clone 均改为使用
run_git_clone():这样三处 clone 行为一致,均避免 shell 分词问题。
当任意 clone 失败时:
help_info();touch_env()返回False;shutil.copy()。需要说明的是,本 PR 没有尝试删除整个
.env基础目录,以避免误删用户已有 ENV 内容;这里只清理当前失败的 clone 目标目录,并阻止后续流程继续执行。scripts/Kconfig前增加存在性检查原逻辑直接执行:
FileNotFoundError。修改后会先检查
scripts/Kconfig是否存在;如果不存在,则输出清晰错误并返回False,不再抛出未解释的异常。touch_env()失败结果kconfiglib_check_installed()中调用touch_env()后,会检查返回值。若 ENV 初始化失败,则输出错误并sys.exit(1),避免继续执行menuconfig/guiconfig/defconfig后续逻辑。本 PR 保持成功路径行为不变,仅修复路径含空格和 clone 失败场景下的错误处理。
请提供验证的bsp和config (provide the config and bsp)
本 PR 修改的是
tools/env_utility.py中的 ENV 初始化辅助逻辑,不涉及具体 BSP 源码、驱动或板级配置。无特定 BSP 要求。
本 PR 不修改任何 BSP 的
.config,也不要求开启或关闭额外配置项。无
.config变更。本 PR 为工具脚本修复,已完成本地脚本级验证。PR 创建后可由 GitHub Actions 自动触发进一步检查。
本地验证如下:
python -m py_compile tools\env_utility.py构造包含空格的目标路径,例如:
os.system('git clone %s %s')会通过 shell 执行命令,目标路径会被空格拆分,导致git clone参数错误。修复后,
subprocess.run(['git', 'clone', url, dest])接收到的 argv 中,目标路径作为单独完整参数传入,不会被空格拆分。通过模拟
git clone返回失败,验证touch_env()行为。修复前:
.env/tools/scripts/Kconfig时可能抛出FileNotFoundError。修复后:
touch_env()返回False;shutil.copy()不再执行;kconfiglib_check_installed()检测失败并退出;FileNotFoundError。scripts/Kconfig场景验证:当
.env/tools/scripts/Kconfig不存在时,修复后会输出清晰错误信息并返回False,不会直接抛出FileNotFoundError。mk_rtconfig()回归验证:使用临时
.config验证以下内容:rtconfig.h中结果仍为:.config -> rtconfig.h的解析逻辑,也未引入相关回归。]
当前拉取/合并请求的状态 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