未验证 提交 5a1349ab 编写于 作者: B Bernard Xiong 提交者: GitHub

Merge pull request #3154 from armink/master

完善 scons target=eclipse
...@@ -122,61 +122,100 @@ def ExcludePaths(rootpath, paths): ...@@ -122,61 +122,100 @@ def ExcludePaths(rootpath, paths):
return ret return ret
def ConverToEclipsePathFormat(path): rtt_path_prefix = '"${workspace_loc://${ProjName}//'
if path.startswith('.'):
path = path[1:]
return '"${workspace_loc:/${ProjName}/' + path + '}"' def ConverToRttEclipsePathFormat(path):
return rtt_path_prefix + path + '}"'
def IsRttEclipsePathFormat(path):
if path.startswith(rtt_path_prefix):
return True
else :
return False
def HandleToolOption(tools, env, project, reset): 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']
paths = [ConverToEclipsePathFormat(RelativeProjectPath(env, os.path.normpath(i)).replace('\\', '/')) for i in project['CPPPATH']] paths = [ConverToRttEclipsePathFormat(RelativeProjectPath(env, os.path.normpath(i)).replace('\\', '/')) for i in project['CPPPATH']]
for tool in tools: for tool in tools:
if tool.get('id').find('c.compile') != 1: if tool.get('id').find('c.compile') != 1:
options = tool.findall('option') options = tool.findall('option')
include_paths_option = None
include_files_option = None
defs_option = None
# find all compile options
for option in options: for option in options:
if option.get('id').find('c.compiler.include.paths') != -1 or option.get('id').find('c.compiler.option.includepaths') != -1: if option.get('id').find('c.compiler.include.paths') != -1 or option.get('id').find('c.compiler.option.includepaths') != -1:
# find all of paths in this project include_paths_option = option
include_paths = option.findall('listOptionValue') elif option.get('id').find('c.compiler.include.files') != -1 or option.get('id').find('c.compiler.option.includefiles') != -1 :
project_paths = [] include_files_option = option
for item in include_paths: elif option.get('id').find('c.compiler.defs') != -1 or option.get('id').find('c.compiler.option.definedsymbols') != -1:
if reset is True: defs_option = option
# clean all old configuration # change the inclue path
option.remove(item) if include_paths_option is not None :
else: option = include_paths_option
project_paths += [item.get('value')] # find all of paths in this project
include_paths = option.findall('listOptionValue')
if len(project_paths) > 0: for item in include_paths:
cproject_paths = set(paths) - set(project_paths) if reset is True or IsRttEclipsePathFormat(item.get('value')) :
else: # clean old configuration
cproject_paths = paths option.remove(item)
# print('c.compiler.include.paths')
# print('c.compiler.include.paths') paths = sorted(paths)
cproject_paths = sorted(cproject_paths) for item in paths:
for item in cproject_paths: SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': item})
SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': item}) # change the inclue files (default) or definitions
if include_files_option is not None:
if option.get('id').find('c.compiler.defs') != -1 or option.get('id').find('c.compiler.option.definedsymbols') != -1: option = include_files_option
defs = option.findall('listOptionValue') file_header = '''
project_defs = [] #ifndef RTCONFIG_PREINC_H__
for item in defs: #define RTCONFIG_PREINC_H__
if reset is True:
# clean all old configuration /* Automatically generated file; DO NOT EDIT. */
option.remove(item) /* RT-Thread pre-include file */
else:
project_defs += [item.get('value')] '''
if len(project_defs) > 0: file_tail = '\n#endif /*RTCONFIG_PREINC_H__*/\n'
cproject_defs = set(CPPDEFINES) - set(project_defs) rtt_pre_inc_item = '"${workspace_loc:/${ProjName}/rtconfig_preinc.h}"'
# save the CPPDEFINES in to rtconfig_preinc.h
with open('rtconfig_preinc.h', mode = 'w+') as f:
f.write(file_header)
for cppdef in CPPDEFINES:
f.write("#define " + cppdef + '\n')
f.write(file_tail)
# change the c.compiler.include.files
files = option.findall('listOptionValue')
find_ok = False
for item in files:
if item.get('value') == rtt_pre_inc_item:
find_ok = True
break
if find_ok is False:
SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': rtt_pre_inc_item})
elif defs_option is not None :
option = defs_option
defs = option.findall('listOptionValue')
project_defs = []
for item in defs:
if reset is True:
# clean all old configuration
option.remove(item)
else: else:
cproject_defs = CPPDEFINES project_defs += [item.get('value')]
if len(project_defs) > 0:
cproject_defs = set(CPPDEFINES) - set(project_defs)
else:
cproject_defs = CPPDEFINES
# print('c.compiler.defs') # print('c.compiler.defs')
cproject_defs = sorted(cproject_defs) cproject_defs = sorted(cproject_defs)
for item in cproject_defs: for item in cproject_defs:
SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': item}) SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': item})
if tool.get('id').find('c.linker') != -1: if tool.get('id').find('c.linker') != -1:
options = tool.findall('option') options = tool.findall('option')
...@@ -187,7 +226,7 @@ def HandleToolOption(tools, env, project, reset): ...@@ -187,7 +226,7 @@ def HandleToolOption(tools, env, project, reset):
items = env['LINKFLAGS'].split(' ') items = env['LINKFLAGS'].split(' ')
if '-T' in items: if '-T' in items:
linker_script = items[items.index('-T') + 1] linker_script = items[items.index('-T') + 1]
linker_script = ConverToEclipsePathFormat(linker_script) linker_script = ConverToRttEclipsePathFormat(linker_script)
listOptionValue = option.find('listOptionValue') listOptionValue = option.find('listOptionValue')
if listOptionValue != None: if listOptionValue != None:
...@@ -199,7 +238,7 @@ def HandleToolOption(tools, env, project, reset): ...@@ -199,7 +238,7 @@ def HandleToolOption(tools, env, project, reset):
if option.get('id').find('c.linker.option.script') != -1: if option.get('id').find('c.linker.option.script') != -1:
items = env['LINKFLAGS'].split(' ') items = env['LINKFLAGS'].split(' ')
if '-T' in items: if '-T' in items:
linker_script = ConverToEclipsePathFormat(items[items.index('-T') + 1]).strip('"') linker_script = ConverToRttEclipsePathFormat(items[items.index('-T') + 1]).strip('"')
option.set('value',linker_script) option.set('value',linker_script)
# update nostartfiles config # update nostartfiles config
...@@ -262,6 +301,7 @@ def UpdateProjectStructure(env, prj_name): ...@@ -262,6 +301,7 @@ def UpdateProjectStructure(env, prj_name):
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']) bsp_root = os.path.abspath(env['BSP_ROOT'])
...@@ -273,7 +313,17 @@ def GenExcluding(env, project): ...@@ -273,7 +313,17 @@ def GenExcluding(env, project):
exclude_paths = ExcludePaths(rtt_root, all_paths) exclude_paths = ExcludePaths(rtt_root, all_paths)
elif rtt_root.startswith(bsp_root): 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 # 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) check_path = []
exclude_paths = []
# analyze the primary folder which relative to BSP_ROOT and in all_paths
for path in all_paths :
if path.startswith(bsp_root) :
folders = RelativeProjectPath(env, path).split('\\')
if folders[0] != '.' and '\\' + folders[0] not in check_path:
check_path += ['\\' + folders[0]]
# exclue the folder which has managed by scons
for path in check_path:
exclude_paths += ExcludePaths(bsp_root + path, all_paths)
else: else:
exclude_paths = ExcludePaths(rtt_root, all_paths) exclude_paths = ExcludePaths(rtt_root, all_paths)
exclude_paths += ExcludePaths(bsp_root, all_paths) exclude_paths += ExcludePaths(bsp_root, all_paths)
...@@ -292,15 +342,16 @@ def GenExcluding(env, project): ...@@ -292,15 +342,16 @@ def GenExcluding(env, project):
exclude_paths += [path] exclude_paths += [path]
exclude_paths = [RelativeProjectPath(env, path).replace('\\', '/') for path in exclude_paths] exclude_paths = [RelativeProjectPath(env, path).replace('\\', '/') for path in exclude_paths]
env['ExPaths'] = exclude_paths
all_files = CollectFiles(all_paths, source_pattern) all_files = CollectFiles(all_paths, source_pattern)
src_files = project['FILES'] src_files = project['FILES']
exclude_files = ExcludeFiles(all_files, src_files) exclude_files = ExcludeFiles(all_files, src_files)
exclude_files = [RelativeProjectPath(env, file).replace('\\', '/') for file in exclude_files] exclude_files = [RelativeProjectPath(env, file).replace('\\', '/') for file in exclude_files]
env['ExPaths'] = exclude_paths
env['ExFiles'] = exclude_files env['ExFiles'] = exclude_files
return exclude_paths + exclude_files return exclude_paths + exclude_files
...@@ -315,7 +366,7 @@ def RelativeProjectPath(env, path): ...@@ -315,7 +366,7 @@ def RelativeProjectPath(env, path):
return 'rt-thread/' + _make_path_relative(rtt_root, path) return 'rt-thread/' + _make_path_relative(rtt_root, path)
# TODO add others folder # TODO add others folder
print('ERROR: the ' + path + 'not support') print('ERROR: the ' + path + ' not support')
return path return path
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册