fix dist-strip compile_commands path parsing#11551
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 (why to submit this PR)
本 PR 用于修复 RT-Thread
tools/中--dist-strip依赖compile_commands.json推导最小发布包保留路径时的路径解析问题,以及解析结果为空时仍继续执行源码清理的问题。该问题属于普通构建/发布工具的软件逻辑缺陷
--dist-strip的目标是根据compile_commands.json中记录的实际编译路径,生成只保留必要源码的最小发布包。当前实现对 compile database 的解析不完整,在部分标准输入格式和跨平台路径场景下,可能漏掉实际需要保留的源码目录或 include 目录,进而影响最小发布包的正确性。主要问题如下:
tools/compile_commands.py只解析command字符串,未支持 compile database 标准允许的arguments数组;command.split()解析编译命令,无法正确处理-I path分离写法、带引号路径以及 Windows 反斜杠路径;file路径和相对 include 路径没有基于 compile database entry 的directory字段进行归一化,导致标准格式的compile_commands.json中有效源码路径和 include 路径可能被漏掉;tools/mkdist.py中MkDist_Strip()在compile_commands.json缺失、解析失败或解析结果为空时,仍继续执行源码清理,可能删除 dist 包中实际需要保留的源码文件。修复前,使用如下标准 compile database entry 时,
get_minimal_dist_paths()无法正确识别相对源码目录和 include 目录:[ { "directory": "/tmp/rt-thread", "arguments": [ "gcc", "-I", "components/foo/include", "-c", "components/foo/foo.c" ], "file": "components/foo/foo.c" } ]修复前实际行为:
这会导致
--dist-strip后续清理逻辑缺少可靠的保留路径依据。你的解决方案是什么 (what is your solution)
本 PR 的解决方案主要包括以下几个部分:
增强
compile_commands.jsonentry 解析逻辑arguments数组;command字符串使用shlex.split(..., posix=False)解析,避免 Windows 反斜杠路径被错误转义;-Ifoo-I foo/Ifoo/I foo-isystem path-iquote path-idirafter path增强路径归一化逻辑
file路径基于 compile database entry 的directory字段归一化;directory字段归一化;修复
MkDist_Strip()的空结果处理compile_commands.json缺失、解析失败或没有解析到任何使用路径时,跳过源码清理;新增回归测试
新增
tools/testcases/test_compile_commands_paths.py,覆盖以下场景:arguments数组和相对路径解析;used_paths为空时,MkDist_Strip()不应删除源码;请提供验证的bsp和config (provide the config and bsp)
本 PR 修改的是
tools/下的构建/发布辅助脚本,不依赖具体 BSP 或真实开发板。Host-side verification was used for this tools-only change.
未修改
.config。本 PR 不涉及 BSP 配置项变更。
Fork branch:
https://github.com/yanhu7150-tech/rt-thread/tree/bugfix-dist-strip-compile-commands
Action page:
https://github.com/yanhu7150-tech/rt-thread/actions?query=branch%3Abugfix-dist-strip-compile-commands
本地验证环境:
本地验证命令:
验证结果:
变更范围:
提交分支:
提交信息:
代码质量 Code Quality: 我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo
已经仔细查看过代码改动的对比 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
已经使用 formatting 等源码格式化工具确保格式符合 RT-Thread 代码规范