Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions tools/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# 2025-01-05 Bernard Add logging as Env['log']
# 2025-03-02 ZhaoCake Add MkDist_Strip
# 2025-01-05 Assistant Refactor SCons PreProcessor patch to independent class
# 2025-09-01 wdfk-prog Add project-name option for custom project naming in IDE targets

import os
import sys
Expand Down Expand Up @@ -802,19 +803,21 @@ def local_group(group, objects):

EndBuilding(target, program)

def GenTargetProject(program = None):
def GenTargetProject(program = None, project_name = None):
if project_name is None:
project_name = GetOption('project-name')

if GetOption('target') in ['mdk', 'mdk4', 'mdk5']:
from targets.keil import MDK2Project, MDK4Project, MDK5Project, ARMCC_Version

if os.path.isfile('template.uvprojx') and GetOption('target') not in ['mdk4']: # Keil5
MDK5Project(Env, GetOption('project-name') + '.uvprojx', Projects)
MDK5Project(Env, project_name + '.uvprojx', Projects)
print("Keil5 project is generating...")
elif os.path.isfile('template.uvproj') and GetOption('target') not in ['mdk5']: # Keil4
MDK4Project(Env, GetOption('project-name') + '.uvproj', Projects)
MDK4Project(Env, project_name + '.uvproj', Projects)
print("Keil4 project is generating...")
elif os.path.isfile('template.Uv2') and GetOption('target') not in ['mdk4', 'mdk5']: # Keil2
MDK2Project(Env, GetOption('project-name') + '.Uv2', Projects)
MDK2Project(Env, project_name + '.Uv2', Projects)
print("Keil2 project is generating...")
else:
print ('No template project file found.')
Expand All @@ -825,20 +828,20 @@ def GenTargetProject(program = None):
if GetOption('target') == 'iar':
from targets.iar import IARProject, IARVersion
print("IAR Version: " + IARVersion())
IARProject(Env, GetOption('project-name') + '.ewp', Projects)
IARProject(Env, project_name + '.ewp', Projects)
print("IAR project has generated successfully!")

if GetOption('target') == 'vs':
from targets.vs import VSProject
VSProject(GetOption('project-name') + '.vcproj', Projects, program)
VSProject(project_name + '.vcproj', Projects, program)

if GetOption('target') == 'vs2012':
from targets.vs2012 import VS2012Project
VS2012Project(GetOption('project-name') + '.vcxproj', Projects, program)
VS2012Project(project_name + '.vcxproj', Projects, program)

if GetOption('target') == 'cb':
from targets.codeblocks import CBProject
CBProject(GetOption('project-name') + '.cbp', Projects, program)
CBProject(project_name + '.cbp', Projects, program)

if GetOption('target') == 'ua':
from targets.ua import PrepareUA
Expand All @@ -857,7 +860,7 @@ def GenTargetProject(program = None):

if GetOption('target') == 'cdk':
from targets.cdk import CDKProject
CDKProject(GetOption('project-name') + '.cdkproj', Projects)
CDKProject(project_name + '.cdkproj', Projects)

if GetOption('target') == 'ses':
from targets.ses import SESProject
Expand All @@ -869,15 +872,17 @@ def GenTargetProject(program = None):

if GetOption('target') == 'eclipse':
from targets.eclipse import TargetEclipse
TargetEclipse(Env, GetOption('reset-project-config'), GetOption('project-name'))
from utils import ProjectInfo
project = ProjectInfo(Env)
TargetEclipse(Env, project, GetOption('reset-project-config'), project_name)

if GetOption('target') == 'codelite':
from targets.codelite import TargetCodelite
TargetCodelite(Projects, program)

if GetOption('target') == 'cmake' or GetOption('target') == 'cmake-armclang':
from targets.cmake import CMakeProject
CMakeProject(Env, Projects, GetOption('project-name'))
CMakeProject(Env, Projects, project_name)

if GetOption('target') == 'xmake':
from targets.xmake import XMakeProject
Expand Down Expand Up @@ -912,13 +917,20 @@ def EndBuilding(target, program = None):
Clean(target, 'rtua.pyc')
Clean(target, '.sconsign.dblite')

# Priority: 1. PROJECT_NAME in rtconfig.py ->
# 2. --project-name command line option ->
# 3. SCons default value ('project')
Comment on lines +920 to +922
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.

project_name = GetOption('project-name')
if hasattr(rtconfig, 'PROJECT_NAME') and rtconfig.PROJECT_NAME:
project_name = rtconfig.PROJECT_NAME


if GetOption('target'):
Comment on lines +924 to 928
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.

GenTargetProject(program)
GenTargetProject(program, project_name)
need_exit = True

BSP_ROOT = Dir('#').abspath

project_name = GetOption('project-name')
project_path = GetOption('project-path')

# 合并处理打包相关选项
Expand Down
Loading