未验证 提交 559f94f8 编写于 作者: B Bernard Xiong 提交者: GitHub

Merge pull request #2792 from armink/fix_eclipse

Fix eclipse
......@@ -167,15 +167,20 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
default = False,
help = 'make distribution for RT-Thread Studio IDE')
AddOption('--project-path',
dest = 'make-project-path',
dest = 'project-path',
type = 'string',
default = False,
help = 'set dist-ide project output path')
AddOption('--project-name',
dest = 'make-project-name',
dest = 'project-name',
type = 'string',
default = False,
help = 'set project name')
AddOption('--reset-project-config',
dest = 'reset-project-config',
action = 'store_true',
default = False,
help = 'reset the project configurations to default')
AddOption('--cscope',
dest = 'cscope',
action = 'store_true',
......@@ -847,7 +852,8 @@ def GenTargetProject(program = None):
if GetOption('target') == 'eclipse':
from eclipse import TargetEclipse
TargetEclipse(Env)
TargetEclipse(Env, GetOption('reset-project-config'), GetOption('project-name'))
def EndBuilding(target, program = None):
import rtconfig
......@@ -882,8 +888,8 @@ def EndBuilding(target, program = None):
need_exit = True
if GetOption('make-dist-ide') and program != None:
from mkdist import MkDist
project_path = GetOption('make-project-path')
project_name = GetOption('make-project-name')
project_path = GetOption('project-path')
project_name = GetOption('project-name')
if not isinstance(project_path, str) or len(project_path) == 0 :
print("\nwarning : --project-path=your_project_path parameter is required.")
......
......@@ -102,15 +102,15 @@ def ExcludeFiles(infiles, files):
# caluclate the exclude path for project
def ExcludePaths(filepath, paths):
def ExcludePaths(rootpath, paths):
ret = []
files = os.listdir(filepath)
files = os.listdir(rootpath)
for file in files:
if file.startswith('.'):
continue
fullname = os.path.join(filepath, file)
fullname = os.path.join(rootpath, file)
if os.path.isdir(fullname):
# print(fullname)
......@@ -128,7 +128,7 @@ def ConverToEclipsePathFormat(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'])
CPPDEFINES = project['CPPDEFINES']
......@@ -143,7 +143,11 @@ def HandleToolOption(tools, env, project):
include_paths = option.findall('listOptionValue')
project_paths = []
for item in include_paths:
project_paths += [item.get('value')]
if reset is True:
# clean all old configuration
option.remove(item)
else:
project_paths += [item.get('value')]
if len(project_paths) > 0:
cproject_paths = set(paths) - set(project_paths)
......@@ -159,7 +163,11 @@ def HandleToolOption(tools, env, project):
defs = option.findall('listOptionValue')
project_defs = []
for item in defs:
project_defs += [item.get('value')]
if reset is True:
# clean all old configuration
option.remove(item)
else:
project_defs += [item.get('value')]
if len(project_defs) > 0:
cproject_defs = set(CPPDEFINES) - set(project_defs)
else:
......@@ -194,61 +202,54 @@ def HandleToolOption(tools, env, project):
return
def UpdateProjectStructure(env):
def UpdateProjectStructure(env, prj_name):
bsp_root = env['BSP_ROOT']
rtt_root = env['RTT_ROOT']
if not rtt_root.startswith(bsp_root):
to_SubElement = True
# print('handle virtual root')
project = etree.parse('.project')
root = project.getroot()
# always use '/' path separator
rtt_root = rtt_root.replace('\\', '/')
if rtt_root.startswith(bsp_root):
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')
# root = project.getroot()
#
# linkedResources = root.find('linkedResources')
# if linkedResources == None:
# # add linkedResources
# linkedResources = SubElement(root, 'linkedResources')
# # print('add linkedResources')
# else:
# links = linkedResources.findall('link')
# # search exist 'rt-thread' virtual folder
# 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()
if prj_name:
name = root.find('name')
if name == None:
name = SubElement(root, 'name')
name.text = prj_name
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
def GenExcluding(env, project):
rtt_root = os.path.abspath(env['RTT_ROOT'])
bsp_root = os.path.abspath(env['BSP_ROOT'])
coll_dirs = CollectPaths(project['DIRS'])
all_paths = [OSPath(path) for path in coll_dirs]
exclude_paths = ExcludePaths(rtt_root, all_paths)
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)
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
exclude_paths = []
......@@ -292,7 +293,7 @@ def RelativeProjectPath(env, path):
return path
def UpdateCproject(env, project, excluding):
def UpdateCproject(env, project, excluding, reset):
excluding = sorted(excluding)
cproject = etree.parse('.cproject')
......@@ -301,7 +302,7 @@ def UpdateCproject(env, project, excluding):
cconfigurations = root.findall('storageModule/cconfiguration')
for cconfiguration in cconfigurations:
tools = cconfiguration.findall('storageModule/configuration/folderInfo/toolChain/tool')
HandleToolOption(tools, env, project)
HandleToolOption(tools, env, project, reset)
sourceEntries = cconfiguration.find('storageModule/configuration/sourceEntries')
entry = sourceEntries.find('entry')
......@@ -326,7 +327,7 @@ def UpdateCproject(env, project, excluding):
out.close()
def TargetEclipse(env):
def TargetEclipse(env, reset = False, prj_name = None):
global source_pattern
print('Update eclipse setting...')
......@@ -338,13 +339,13 @@ def TargetEclipse(env):
project = ProjectInfo(env)
# update the project file structure info on '.project' file
UpdateProjectStructure(env)
UpdateProjectStructure(env, prj_name)
# generate the exclude paths and files
excluding = GenExcluding(env, project)
# update the project configuration on '.cproject' file
UpdateCproject(env, project, excluding)
UpdateCproject(env, project, excluding, reset)
print('done!')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册