Skip to content

Commit 6d61514

Browse files
committed
[tool]Add project-name option for custom project naming in IDE targets
- Priority: 1. PROJECT_NAME in rtconfig.py -> 2. --project-name command line option -> 3. SCons default value ('project')
1 parent bc4c036 commit 6d61514

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

tools/building.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
# 2025-01-05 Bernard Add logging as Env['log']
2828
# 2025-03-02 ZhaoCake Add MkDist_Strip
2929
# 2025-01-05 Assistant Refactor SCons PreProcessor patch to independent class
30+
# 2025-09-01 wdfk-prog Add project-name option for custom project naming in IDE targets
3031

3132
import os
3233
import sys
@@ -802,19 +803,21 @@ def local_group(group, objects):
802803

803804
EndBuilding(target, program)
804805

805-
def GenTargetProject(program = None):
806+
def GenTargetProject(program = None, project_name = None):
807+
if project_name is None:
808+
project_name = GetOption('project-name')
806809

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

810813
if os.path.isfile('template.uvprojx') and GetOption('target') not in ['mdk4']: # Keil5
811-
MDK5Project(Env, GetOption('project-name') + '.uvprojx', Projects)
814+
MDK5Project(Env, project_name + '.uvprojx', Projects)
812815
print("Keil5 project is generating...")
813816
elif os.path.isfile('template.uvproj') and GetOption('target') not in ['mdk5']: # Keil4
814-
MDK4Project(Env, GetOption('project-name') + '.uvproj', Projects)
817+
MDK4Project(Env, project_name + '.uvproj', Projects)
815818
print("Keil4 project is generating...")
816819
elif os.path.isfile('template.Uv2') and GetOption('target') not in ['mdk4', 'mdk5']: # Keil2
817-
MDK2Project(Env, GetOption('project-name') + '.Uv2', Projects)
820+
MDK2Project(Env, project_name + '.Uv2', Projects)
818821
print("Keil2 project is generating...")
819822
else:
820823
print ('No template project file found.')
@@ -825,20 +828,20 @@ def GenTargetProject(program = None):
825828
if GetOption('target') == 'iar':
826829
from targets.iar import IARProject, IARVersion
827830
print("IAR Version: " + IARVersion())
828-
IARProject(Env, GetOption('project-name') + '.ewp', Projects)
831+
IARProject(Env, project_name + '.ewp', Projects)
829832
print("IAR project has generated successfully!")
830833

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

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

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

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

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

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

870873
if GetOption('target') == 'eclipse':
871874
from targets.eclipse import TargetEclipse
872-
TargetEclipse(Env, GetOption('reset-project-config'), GetOption('project-name'))
875+
from utils import ProjectInfo
876+
project = ProjectInfo(Env)
877+
TargetEclipse(Env, project, GetOption('reset-project-config'), project_name)
873878

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

878883
if GetOption('target') == 'cmake' or GetOption('target') == 'cmake-armclang':
879884
from targets.cmake import CMakeProject
880-
CMakeProject(Env, Projects, GetOption('project-name'))
885+
CMakeProject(Env, Projects, project_name)
881886

882887
if GetOption('target') == 'xmake':
883888
from targets.xmake import XMakeProject
@@ -912,13 +917,20 @@ def EndBuilding(target, program = None):
912917
Clean(target, 'rtua.pyc')
913918
Clean(target, '.sconsign.dblite')
914919

920+
# Priority: 1. PROJECT_NAME in rtconfig.py ->
921+
# 2. --project-name command line option ->
922+
# 3. SCons default value ('project')
923+
project_name = GetOption('project-name')
924+
if hasattr(rtconfig, 'PROJECT_NAME') and rtconfig.PROJECT_NAME:
925+
project_name = rtconfig.PROJECT_NAME
926+
927+
915928
if GetOption('target'):
916-
GenTargetProject(program)
929+
GenTargetProject(program, project_name)
917930
need_exit = True
918931

919932
BSP_ROOT = Dir('#').abspath
920933

921-
project_name = GetOption('project-name')
922934
project_path = GetOption('project-path')
923935

924936
# 合并处理打包相关选项

0 commit comments

Comments
 (0)