Skip to content

Conversation

wdfk-prog
Copy link
Contributor

@wdfk-prog wdfk-prog commented Sep 1, 2025

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

[

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

  1. 原先的命令scons --target=eclipse不大满足通用需求
  • 例如: 文件夹目录结构如下,两个工程共用一个rtt源码目录情况,且还有UserSrc目录
├─rt-thread
│ 
├─rtt_project1
│ 
├─rtt_project2
│ 
├─UserSrc
  • 这个pr进行了增强,通过rtconfig.py传入PROJECT_SOURCE_FOLDERS 进行链接
# Both relative and absolute paths are supported.
# Example:
# PROJECT_SOURCE_FOLDERS = ['../rt-thread']
# PROJECT_SOURCE_FOLDERS = ['D:/my_libraries/rt-thread', '../another_lib']
PROJECT_SOURCE_FOLDERS = ['../UserSrc', '../rt-thread'] 
  • 需要在SConstruct下传入文件夹路径
# inlcude UseSrc
objs.extend(SConscript('../UserSrc/SConscript', variant_dir='build/UserSrc', duplicate=0))
  • 执行命令后如下
    • .project
  <linkedResources>
    <link>
      <name>UserSrc</name>
      <type>2</type>
      <locationURI>PARENT-1-PROJECT_LOC/UserSrc</locationURI>
    </link>
    <link>
      <name>rt-thread</name>
      <type>2</type>
      <locationURI>PARENT-1-PROJECT_LOC/rt-thread</locationURI>
    </link>
  </linkedResources>
  • .cproject
        <sourceEntries>
          <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="" excluding=
          "cubemx/MDK-ARM|rt-thread/components/dfs|rt-thread/components/drivers/ata|rt-thread/components/drivers/audio" />
        </sourceEntries>
  1. scons --target=eclipse命令生成的.project项目名,总是会被改成project.
  • 这个pr进行了修复为正常的工程名,通过rtconfig.py传入
# project name
PROJECT_NAME = 'demo'

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

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

  • BSP:
  • .config:
  • action:

]

当前拉取/合并请求的状态 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
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

- Priority: 1. PROJECT_NAME in rtconfig.py -> 2. --project-name command line option -> 3. SCons default value ('project')
- Add project-name support for Eclipse target, allowing users to specify
  custom project names via the --project-name option
- Enhance .project file update mechanism to properly handle
  PROJECT_SOURCE_FOLDERS defined in rtconfig.py
- Support linking external folders located at different physical locations
- Improve path handling with Eclipse standard path variables (PARENT-* and PROJECT_LOC)
  for better project portability
@github-actions github-actions bot added the tools label Sep 1, 2025
@supperthomas supperthomas requested review from BernardXiong and Copilot and removed request for BernardXiong September 1, 2025 03:53
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the Eclipse project generation functionality by adding support for custom project names and linked source folders through configuration in rtconfig.py. The enhancement aims to better support project structures where multiple projects share common source directories outside the BSP root.

Key changes:

  • Adds PROJECT_NAME configuration option for custom project naming
  • Implements PROJECT_SOURCE_FOLDERS for linking external directories
  • Enhances Eclipse target processing to handle complex project structures

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
tools/targets/rt_studio.py Modifies gen_project_file to accept project_name parameter for template replacement
tools/targets/eclipse.py Major rewrite of UpdateProjectStructure function and adds UpdateProjectName function for enhanced Eclipse project generation
tools/building.py Updates GenTargetProject and EndBuilding functions to support project_name parameter and priority handling

Comment on lines +412 to +415
# Count how many levels up
levels_up = relative_link_path.count('../')
clean_path = relative_link_path.replace('../', '')
location_uri = f'PARENT-{levels_up}-PROJECT_LOC/{clean_path}'
Copy link
Preview

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

English: The indentation is inconsistent. Line 413 has extra spaces before the comment, while line 415 has proper indentation. Chinese: 缩进不一致。第413行注释前有额外的空格,而第415行有正确的缩进。

Copilot generated this review using guidance from repository custom instructions.

Comment on lines +560 to +563
xml_indent(root)
with open('.project', 'w', encoding='utf-8') as f:
f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
f.write(etree.tostring(root, encoding='utf-8').decode('utf-8'))
Copy link
Preview

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

English: Line 562 has extra spaces before the f.write call, creating inconsistent indentation within the with block. Chinese: 第562行在f.write调用前有额外的空格,在with块内创建了不一致的缩进。

Copilot generated this review using guidance from repository custom instructions.

Comment on lines +920 to +922
# Priority: 1. PROJECT_NAME in rtconfig.py ->
# 2. --project-name command line option ->
# 3. SCons default value ('project')
Copy link
Preview

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

English: The comment describes priority logic that doesn't match the implementation. The code sets project_name from GetOption first, then overwrites it if rtconfig.PROJECT_NAME exists, which makes rtconfig.PROJECT_NAME higher priority, not GetOption. Chinese: 注释描述的优先级逻辑与实现不匹配。代码首先从GetOption设置project_name,然后如果rtconfig.PROJECT_NAME存在就覆盖它,这使得rtconfig.PROJECT_NAME具有更高的优先级,而不是GetOption。

Copilot generated this review using guidance from repository custom instructions.

Comment on lines +924 to 928
if hasattr(rtconfig, 'PROJECT_NAME') and rtconfig.PROJECT_NAME:
project_name = rtconfig.PROJECT_NAME


if GetOption('target'):
Copy link
Preview

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

English: There are unnecessary blank lines (lines 926-927) that should be reduced to a single blank line for better code formatting. Chinese: 有不必要的空行(第926-927行),应该减少为单个空行以获得更好的代码格式。

Copilot generated this review using guidance from repository custom instructions.

- Add pre-build and post-build steps in the cproject file
- Support custom pre-build and post-build steps
@kurisaW
Copy link
Member

kurisaW commented Sep 8, 2025

基于你提出的两个优化项:

1.这个自动生成链接,我看你硬编码成了PARENT-{levels_up}-PROJECT_LOC,但是这个应该只适用于你自己设定的目录名称吧,通用性没做好,实际查找路径会存在问题(这个功能我觉得自己如果有这方面需求,写个脚本自动转一下就好了,不建议提交到主线上,studio里提供两个导入选项,一个是导入bsp,也就是针对主线上的bsp,这个是支持一键导入的,只不过需要确保.settings下的配置正确;还有是导入studio项目,这个是专门为了rtt的sdk项目做的,两个功能不都是正常的嘛)

2.建议你的这个导入studio后名称修改为实际名称,这里可以用环境变量获取实际的项目名称,而不是让用户手动在源码里加入PROJECT_NAME此项

@kurisaW kurisaW added the -1 No vote label Sep 8, 2025
@wdfk-prog
Copy link
Contributor Author

wdfk-prog commented Sep 8, 2025

基于你提出的两个优化项:

1.这个自动生成链接,我看你硬编码成了PARENT-{levels_up}-PROJECT_LOC,但是这个应该只适用于你自己设定的目录名称吧,通用性没做好,实际查找路径会存在问题(这个功能我觉得自己如果有这方面需求,写个脚本自动转一下就好了,不建议提交到主线上,studio里提供两个导入选项,一个是导入bsp,也就是针对主线上的bsp,这个是支持一键导入的,只不过需要确保.settings下的配置正确;还有是导入studio项目,这个是专门为了rtt的sdk项目做的,两个功能不都是正常的嘛)

2.建议你的这个导入studio后名称修改为实际名称,这里可以用环境变量获取实际的项目名称,而不是让用户手动在源码里加入PROJECT_NAME此项

  • o(╥﹏╥)o好的
  • 的确我自己验证的话,是0没办法保证通用性.

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.

3 participants