Repository navigation
fix[tools]: attach group LOCAL_CPPDEFINES to source files in Eclipse export - #11930
AZE-BlackCore wants to merge 1 commit into
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: kernelReviewers: @GorrayLi @ReviewSun @hamburger-os @lianux-mm @wdfk-prog @xu18838022837 Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-10-25 17:04 CST)
📝 Review Instructions
|
| group = DefineGroup('Kernel', src, depend=[''], CPPPATH=inc, | ||
| LINKFLAGS=LINKFLAGS, LOCAL_CFLAGS=LOCAL_CFLAGS, | ||
| CPPDEFINES=['__RTTHREAD__'], LOCAL_CPPDEFINES=['__RT_KERNEL_SOURCE__']) | ||
| CPPDEFINES=['__RTTHREAD__', '__RT_KERNEL_SOURCE__']) |
There was a problem hiding this comment.
建议保留原来的配置,让 Eclipse 导出器将各组的 LOCAL_CPPDEFINES 配置到对应源文件上。不要直接汇总到全局 rtconfig_preinc.h,否则仍会扩大作用域。
There was a problem hiding this comment.
感谢您的评审意见!已按建议调整方案:
-
src/SConscript 保持原配置不变(LOCAL_CPPDEFINES=['RT_KERNEL_SOURCE'],与 master 无差异),不再改动内核构建脚本;
-
修改落在 tools/targets/eclipse.py:新增 CollectLocalDefines / UpdateLocalDefinesFileInfo,导出时收集各组的 LOCAL_CPPDEFINES,作为 CDT per-file Defined Symbols(fileInfo) 挂到该组对应的源文件上(Kernel 组 15 个源文件),不再汇总进全局 preinc;
-
验证结果:生成的 .cproject 含 Kernel 组 15 个 per-file fileInfo(含 RT_KERNEL_SOURCE),rtconfig_preinc.h 不含该宏(宏作用域不扩大);以 Studio 同参(GCC 5.4.1 + per-file -D)编译 5 个内核文件 0 警告,main.c(不带 -D)0 警告;scons 命令行构建行为不变。
PR 已更新(commit 1613695,仅 eclipse.py,+76/-2),请再帮忙看一下,谢谢!
Rbb666
left a comment
There was a problem hiding this comment.
当前实现存在两处影响 Eclipse/RT-Thread Studio 工程加载和编译的问题,详见行内评论。请修复后重新验证 Studio 工程加载及完整构建,确认局部宏与原有编译选项均进入实际编译命令。此次检查已执行 Python/XML 最小重现并核对 CDT 源码,未执行 Studio 完整构建。
|
|
||
| for rp, defines in local_defines.items(): | ||
| fi_id = ccfg_id + _rtt_local_marker + rp.replace('/', '.').strip('.') | ||
| fi = SubElement(configuration, 'fileInfo', {'id': fi_id, 'name': '/' + rp}) |
There was a problem hiding this comment.
[P1] 为 fileInfo 添加 resourcePath
这里生成的 fileInfo 只有 id 和 name,但 CDT 使用 resourcePath 关联源文件,name 不能替代该属性。对于包含 LOCAL_CPPDEFINES 的工程(例如默认 Kernel 组),这些节点加载后 getPath() 为 null,Configuration.addResourceConfiguration() 调用 getPath().segmentCount() 时会触发异常,导致工程配置无法正常加载。请添加 resourcePath=rp,使用相对于工程根目录的源文件路径,并验证生成的 .cproject 能被 Studio 正常重新加载。
There was a problem hiding this comment.
收到,感谢指正!已废弃原方案(将 RT_KERNEL_SOURCE 并入 Kernel 组全局 CPPDEFINES),按您的建议修改:保持 src/SConscript 的 LOCAL_CPPDEFINES 配置原样不动,改在 tools/targets/eclipse.py 中收集各组的 LOCAL_CPPDEFINES,作为 CDT per-file Defined Symbols(fileInfo) 挂到该组对应的源文件上。
这样宏作用域不扩大:rtconfig_preinc.h 仍只含全局宏,RT_KERNEL_SOURCE 仅作用于 Kernel 组自身源文件(与 scons 命令行构建的 LOCAL 语义一致);CDT 生成 makefile 时,带 fileInfo 的文件编译命令会自动追加 -D。
已验证:导出工程 .cproject 为 Kernel 组 15 个源文件生成 per-file fileInfo(含 RT_KERNEL_SOURCE);rtconfig_preinc.h 不含该宏;模拟 CDT 编译(Studio 同参,GCC 5.4.1)5 个内核文件 0 警告、main.c 无 -D 0 警告;scons 命令行构建行为不变。PR 已更新,请再帮忙看一下,谢谢!
| fi_id = ccfg_id + _rtt_local_marker + rp.replace('/', '.').strip('.') | ||
| fi = SubElement(configuration, 'fileInfo', {'id': fi_id, 'name': '/' + rp}) | ||
| tool = SubElement(fi, 'tool', {'id': fi_id + '.tool', | ||
| 'superClass': 'ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler'}) |
There was a problem hiding this comment.
[P1] 继承当前工程已配置的编译器实例
这里的 superClass 指向插件的基础 C 编译器,绕过了当前工程 folderInfo/toolChain 中已经配置的编译器实例。即使补齐 resourcePath,生成的文件级工具仍无法继承 HandleToolOption() 写入工程编译器的头文件搜索路径和 -include rtconfig_preinc.h 等选项,内核源文件会因缺少头文件路径或全局宏而编译失败。请根据源文件所属目录选择实际编译器,将文件级工具的 superClass 指向该实例的完整 ID,再添加局部宏;验证实际编译命令同时保留原有 -I、-include 和新增 -D。
There was a problem hiding this comment.
已按两条意见修复并完成 Studio 实测:
① fileInfo 现携带 resourcePath(相对工程根路径),CDT 可正常关联源文件,工程在 RT-Thread Studio 中正常加载;
② 文件级 的 superClass 由基础插件类改为实际编译器实例 id(GetCompilerInstanceId 按源文件所属目录前缀匹配 folderInfo/toolChain 中的编译器实例),per-file -D 叠加在原有选项之上。
Studio 实测(stm32l475-atk-pandora,2026-10-26):工程正常加载,Clean 后完整构建 0 errors / 0 warnings(Flash 96.66 KB / RAM 6.58 KB)。核对 CDT 生成的 Debug/rt-thread/src/subdir.mk:Kernel 组 15 个源文件编译规则均含 -D__RT_KERNEL_SOURCE_,并保留 -include rtconfig_preinc.h 与全部 -I 路径;klibc/drivers/applications 规则不含该宏 ——局部宏与原有编译选项均进入实际编译命令,宏作用域未扩大。
PR 已更新(commit 57c7318,仅 eclipse.py,+143/-2),请再帮忙看一下,谢谢!
| # per-folder compiler instances: folder name -> tool instance id | ||
| folders = [] | ||
| for fi in configuration.findall('folderInfo'): | ||
| name = fi.get('name', '/') |
There was a problem hiding this comment.
[P2] 使用 resourcePath 匹配源文件所属目录
folderInfo.name 不是相对于工程根目录的路径,目录级配置可能沿用根配置的显示名称 /。例如同时存在根配置 name="/" resourcePath="" 和子目录配置 name="/" resourcePath="rt-thread/src" 时,这里把两者都当成空目录前缀,后续最长前缀比较无法区分它们。已复现 rt-thread/src/clock.c 仍选择根目录编译器,导致子目录编译器上的自定义选项(例如 -fno-builtin)被跳过。
请改为读取 fi.get('resourcePath', ''),按实际目录路径进行最长前缀匹配。建议覆盖根目录、嵌套目录及目录外文件三种情况;在最小复现中改用 resourcePath 后,内核文件选中子目录编译器,applications/main.c 仍选中根目录编译器。
There was a problem hiding this comment.
已按 [P2] 意见修复:GetCompilerInstanceId 不再用 folderInfo.name(显示名可能均为 "/"),改读 fi.get('resourcePath', '') 按真实目录路径做最长前缀匹配。
验证:① 最小复现(根 + 子目录 rt-thread/src + 嵌套 rt-thread/src/klibc,name 均为 "/"):rt-thread/src/clock.c 正确选中子目录编译器、嵌套文件选中嵌套编译器、applications/main.c 与目录外文件选中根编译器、.cpp 选 cpp 编译器 —— 全部通过;② RT-Thread Studio 实测(2026-10-26):工程正常加载、完整构建 0 errors / 0 warnings;CDT makefile 核对 Kernel 15 条规则含 -D__RT_KERNEL_SOURCE_ 且保留 -I/-include,klibc/drivers/applications 无宏;③ 固件尺寸与修复前一致(Flash 96.66 KB / RAM 6.58 KB)。
PR 已更新(commit cd78b54,仅 eclipse.py),请再帮忙看一下,谢谢!
|
…export The Eclipse project generator (tools/targets/eclipse.py) only writes the global CPPDEFINES into rtconfig_preinc.h, while per-group LOCAL_CPPDEFINES (e.g. __RT_KERNEL_SOURCE__ for the Kernel group in src/SConscript) are not collected. As a result, Eclipse/RT-Thread Studio builds of dist-exported projects report 24 -Wimplicit-function-declaration warnings for the rt_sched_* internal scheduler APIs, and GCC 14+ turns the same warnings into hard errors. Keep the original LOCAL_CPPDEFINES scoping and let the Eclipse exporter attach each group's LOCAL_CPPDEFINES to the corresponding source files as CDT per-file defined symbols (fileInfo). Each fileInfo carries 'resourcePath' (required by CDT to associate the file) and its tool inherits the real folder/toolchain compiler instance id, so the per-file -D is applied on top of the existing -I / '-include rtconfig_preinc.h' options. The compiler instance is selected by the longest matching folderInfo 'resourcePath' (not the display 'name', which is often '/' for every folder), so kernel sources pick up their directory-level compiler options while root and outside-folder files fall back to the root compiler. Verified: .cproject carries 15 per-file fileInfo for the Kernel group with resourcePath and the real compiler instance id; the generated rtconfig_preinc.h has no __RT_KERNEL_SOURCE__ (macro scope unchanged); compiling the 5 kernel files with the full Studio flags plus the per-file -D yields 0 warnings (GCC 5.4.1), while non-kernel files compile without it; Studio build of the exported stm32l475-atk-pandora project: 0 errors / 0 warnings, and the CDT-generated makefile keeps -I / '-include' and adds the per-file -D only for the Kernel group (15 rules).
…pse/Studio builds
The rt_sched_* scheduler APIs in include/rtsched.h are guarded by RT_KERNEL_SOURCE / RT_IPC_SOURCE. The gcc/armclang branch of src/SConscript injects the macro via LOCAL_CPPDEFINES, which is honored by scons command-line builds but is NOT collected by the Eclipse project generator (tools/targets/eclipse.py) that RT-Thread Studio runs before each make build. As a result, Studio builds of dist-exported projects report 24 -Wimplicit-function-declaration warnings (clock.c 1, ipc.c 7, thread.c 12, timer.c 1, scheduler_comm.c 3).
Move RT_KERNEL_SOURCE into the global CPPDEFINES of the Kernel group, matching the existing msvc branch. The macro then lands in the generated rtconfig_preinc.h automatically and the warnings disappear, with no change to scons command-line build behavior or generated firmware.
Verified: Studio rebuild 0 errors / 0 warnings; firmware size unchanged.
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
通过
scons --dist-ide导出的项目在 RT-Thread Studio / Eclipse(构建前运行scons --target=eclipse)下使用 gcc/armclang 工具链编译时,内核 5 个源文件(src/clock.c、src/ipc.c、src/thread.c、src/timer.c、src/scheduler_comm.c)报 24 条-Wimplicit-function-declaration警告(rt_sched_*内部调度 API 隐式声明)。该问题在最新 master(
a59e72fb5c)上已独立复现;且 GCC 14 起-Wimplicit-function-declaration默认升级为 error,同一问题在 GCC 14+/15 工具链下会导致编译失败,直接阻断构建。修复可同时消除警告并避免新工具链下的硬错误。你的解决方案是什么 (what is your solution)
根因:
include/rtsched.h中rt_sched_*声明被#if defined(__RT_KERNEL_SOURCE__) || defined(__RT_IPC_SOURCE__)包裹;scons 命令行构建通过src/SConscript的LOCAL_CPPDEFINES注入该宏,但 Studio 构建链路的 Eclipse 工程生成器(tools/targets/eclipse.py)只收集全局project['CPPDEFINES']写入rtconfig_preinc.h,不收集LOCAL_CPPDEFINES,导致 preinc 缺宏、声明不可见。修复(按维护者评审意见调整为最终方案):保持
src/SConscript的LOCAL_CPPDEFINES原样不动,修改tools/targets/eclipse.py,让 Eclipse 导出器将各组的LOCAL_CPPDEFINES作为 CDT per-file Defined Symbols(fileInfo) 挂到该组对应的源文件上:rtconfig_preinc.h仍只含全局宏,__RT_KERNEL_SOURCE__仅作用于 Kernel 组自身源文件(与 scons 命令行构建的 LOCAL 语义一致);fileInfo的源文件编译命令自动追加各自的-D,等价于命令行构建的效果;tools/targets/eclipse.py,+76/-2),scons 命令行构建、rtconfig_preinc.h内容、固件产物均无任何变化。.cproject生成效果示例:请提供验证的bsp和config (provide the config and bsp)
bsp/stm32/stm32l475-atk-pandoratools/targets/eclipse.py)纯生成层修改,不涉及任何配置项,验证使用bsp/stm32/stm32l475-atk-pandora默认配置即可复现(无需改动 .config)。复现 / 验证方式:scons --dist-ide --project-name=stm32l475-atk-pandora导出后,在 RT-Thread Studio 中 Clean + 重新构建。pull_request_target平台策略提示、Node.js 20 弃用提示)。编译类检查结果以 PR 页面 CI 状态为准。测试情况(已确认,板卡:stm32l475-atk-pandora):① 导出工程静态验证:
.cproject为 Kernel 组 15 个源文件生成 per-file fileInfo(含__RT_KERNEL_SOURCE__),rtconfig_preinc.h不含该宏(作用域不扩大),重复生成幂等;② 模拟 CDT 编译(Studio 同参-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -O0 -Wall -std=gnu99 -include rtconfig_preinc.h+ 完整包含路径,GCC 5.4.1):5 个内核文件带 per-file-D编译 0 警告,applications/main.c不带-D编译 0 警告(作用域对照);③ scons 命令行构建回归通过(src/SConscript未改动);④ 最新 master 对照:问题独立复现(GCC 5.4.1 下 24 警告、GCC 15.2.1 下编译失败);⑤ dev 导出项目内 A/B 对照:不带修复 24 警告 → 带修复 0 警告。]
当前拉取/合并请求的状态 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