[tools] Add project name set feature to eclipse target.

This commit is contained in:
armink 2019-06-18 20:08:00 +08:00
parent 0c45bb6f96
commit ab81ff6815
1 changed files with 53 additions and 52 deletions

View File

@ -102,15 +102,15 @@ def ExcludeFiles(infiles, files):
# caluclate the exclude path for project # caluclate the exclude path for project
def ExcludePaths(filepath, paths): def ExcludePaths(rootpath, paths):
ret = [] ret = []
files = os.listdir(filepath) files = os.listdir(rootpath)
for file in files: for file in files:
if file.startswith('.'): if file.startswith('.'):
continue continue
fullname = os.path.join(filepath, file) fullname = os.path.join(rootpath, file)
if os.path.isdir(fullname): if os.path.isdir(fullname):
# print(fullname) # print(fullname)
@ -128,7 +128,7 @@ def ConverToEclipsePathFormat(path):
return '"${workspace_loc:/${ProjName}/' + path + '}"' return '"${workspace_loc:/${ProjName}/' + path + '}"'
def HandleToolOption(tools, env, project): def HandleToolOption(tools, env, project, reset):
BSP_ROOT = os.path.abspath(env['BSP_ROOT']) BSP_ROOT = os.path.abspath(env['BSP_ROOT'])
CPPDEFINES = project['CPPDEFINES'] CPPDEFINES = project['CPPDEFINES']
@ -143,6 +143,10 @@ def HandleToolOption(tools, env, project):
include_paths = option.findall('listOptionValue') include_paths = option.findall('listOptionValue')
project_paths = [] project_paths = []
for item in include_paths: for item in include_paths:
if reset is True:
# clean all old configuration
option.remove(item)
else:
project_paths += [item.get('value')] project_paths += [item.get('value')]
if len(project_paths) > 0: if len(project_paths) > 0:
@ -159,6 +163,10 @@ def HandleToolOption(tools, env, project):
defs = option.findall('listOptionValue') defs = option.findall('listOptionValue')
project_defs = [] project_defs = []
for item in defs: for item in defs:
if reset is True:
# clean all old configuration
option.remove(item)
else:
project_defs += [item.get('value')] project_defs += [item.get('value')]
if len(project_defs) > 0: if len(project_defs) > 0:
cproject_defs = set(CPPDEFINES) - set(project_defs) cproject_defs = set(CPPDEFINES) - set(project_defs)
@ -194,61 +202,54 @@ def HandleToolOption(tools, env, project):
return return
def UpdateProjectStructure(env):
def UpdateProjectStructure(env, prj_name):
bsp_root = env['BSP_ROOT'] bsp_root = env['BSP_ROOT']
rtt_root = env['RTT_ROOT'] rtt_root = env['RTT_ROOT']
if not rtt_root.startswith(bsp_root): project = etree.parse('.project')
to_SubElement = True root = project.getroot()
# print('handle virtual root')
# always use '/' path separator if rtt_root.startswith(bsp_root):
rtt_root = rtt_root.replace('\\', '/') linkedResources = root.find('linkedResources')
if linkedResources == None:
linkedResources = SubElement(root, 'linkedResources')
# TODO create the virtual folder links = linkedResources.findall('link')
# delete all RT-Thread folder links
for link in links:
if link.find('name').text.startswith('rt-thread'):
linkedResources.remove(link)
# project = etree.parse('.project') if prj_name:
# root = project.getroot() name = root.find('name')
# if name == None:
# linkedResources = root.find('linkedResources') name = SubElement(root, 'name')
# if linkedResources == None: name.text = prj_name
# # add linkedResources
# linkedResources = SubElement(root, 'linkedResources') out = open('.project', 'w')
# # print('add linkedResources') out.write('<?xml version="1.0" encoding="UTF-8"?>\n')
# else: xml_indent(root)
# links = linkedResources.findall('link') out.write(etree.tostring(root, encoding = 'utf-8'))
# # search exist 'rt-thread' virtual folder out.close()
# for link in links:
# if link.find('name').text == 'rt-thread':
# # handle location
# to_SubElement = False
# location = link.find('location')
# location.text = rtt_root
#
# if to_SubElement:
# # print('to subelement for virtual folder')
# link = SubElement(linkedResources, 'link')
# name = SubElement(link, 'name')
# name.text = 'rt-thread'
# type = SubElement(link, 'type')
# type.text = '2'
# location = SubElement(link, 'location')
# location.text = rtt_root
#
# out = open('.project', 'w')
# out.write('<?xml version="1.0" encoding="UTF-8"?>\n')
# xml_indent(root)
# out.write(etree.tostring(root, encoding='utf-8'))
# out.close()
return return
def GenExcluding(env, project): def GenExcluding(env, project):
rtt_root = os.path.abspath(env['RTT_ROOT']) rtt_root = os.path.abspath(env['RTT_ROOT'])
bsp_root = os.path.abspath(env['BSP_ROOT'])
coll_dirs = CollectPaths(project['DIRS']) coll_dirs = CollectPaths(project['DIRS'])
all_paths = [OSPath(path) for path in coll_dirs] all_paths = [OSPath(path) for path in coll_dirs]
if bsp_root.startswith(rtt_root):
# bsp folder is in the RT-Thread root folder, such as the RT-Thread source code on GitHub
exclude_paths = ExcludePaths(rtt_root, all_paths) exclude_paths = ExcludePaths(rtt_root, all_paths)
elif rtt_root.startswith(bsp_root):
# RT-Thread root folder is in the bsp folder, such as project folder which generate by 'scons --dist' cmd
exclude_paths = ExcludePaths(bsp_root, all_paths)
else:
exclude_paths = ExcludePaths(rtt_root, all_paths)
exclude_paths += ExcludePaths(bsp_root, all_paths)
paths = exclude_paths paths = exclude_paths
exclude_paths = [] exclude_paths = []
@ -292,7 +293,7 @@ def RelativeProjectPath(env, path):
return path return path
def UpdateCproject(env, project, excluding): def UpdateCproject(env, project, excluding, reset):
excluding = sorted(excluding) excluding = sorted(excluding)
cproject = etree.parse('.cproject') cproject = etree.parse('.cproject')
@ -301,7 +302,7 @@ def UpdateCproject(env, project, excluding):
cconfigurations = root.findall('storageModule/cconfiguration') cconfigurations = root.findall('storageModule/cconfiguration')
for cconfiguration in cconfigurations: for cconfiguration in cconfigurations:
tools = cconfiguration.findall('storageModule/configuration/folderInfo/toolChain/tool') tools = cconfiguration.findall('storageModule/configuration/folderInfo/toolChain/tool')
HandleToolOption(tools, env, project) HandleToolOption(tools, env, project, reset)
sourceEntries = cconfiguration.find('storageModule/configuration/sourceEntries') sourceEntries = cconfiguration.find('storageModule/configuration/sourceEntries')
entry = sourceEntries.find('entry') entry = sourceEntries.find('entry')
@ -326,7 +327,7 @@ def UpdateCproject(env, project, excluding):
out.close() out.close()
def TargetEclipse(env): def TargetEclipse(env, reset = False, prj_name = None):
global source_pattern global source_pattern
print('Update eclipse setting...') print('Update eclipse setting...')
@ -338,13 +339,13 @@ def TargetEclipse(env):
project = ProjectInfo(env) project = ProjectInfo(env)
# update the project file structure info on '.project' file # update the project file structure info on '.project' file
UpdateProjectStructure(env) UpdateProjectStructure(env, prj_name)
# generate the exclude paths and files # generate the exclude paths and files
excluding = GenExcluding(env, project) excluding = GenExcluding(env, project)
# update the project configuration on '.cproject' file # update the project configuration on '.cproject' file
UpdateCproject(env, project, excluding) UpdateCproject(env, project, excluding, reset)
print('done!') print('done!')