From 3b75e30c8d908ded140e24529502a6b5f97f84f9 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Thu, 21 Mar 2019 23:04:37 +0800 Subject: [Tools] Add eclipse target --- tools/eclipse.py | 299 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 299 insertions(+) create mode 100644 tools/eclipse.py (limited to 'tools/eclipse.py') diff --git a/tools/eclipse.py b/tools/eclipse.py new file mode 100644 index 0000000000..dc86c7be5a --- /dev/null +++ b/tools/eclipse.py @@ -0,0 +1,299 @@ +import os +import sys +import glob + +from utils import * +from utils import _make_path_relative +from utils import xml_indent + +import xml.etree.ElementTree as etree +from xml.etree.ElementTree import SubElement + +source_pattern = ['*.c', '*.cpp', '*.cxx', '*.s', '*.S', '*.asm'] + +def OSPath(path): + import platform + + if type(path) == type('str'): + if platform.system() == 'Windows': + return path.replace('/', '\\') + else: + return path.replace('\\', '/') + else: + if platform.system() == 'Windows': + return [item.replace('/', '\\') for item in path] + else: + return [item.replace('\\', '/') for item in path] + +def CollectPaths(paths): + all_paths = [] + + def ParentPaths(path): + ret = os.path.dirname(path) + if ret == path or ret == '': + return [] + + return [ret] + ParentPaths(ret) + + for path in paths: + # path = os.path.abspath(path) + path = path.replace('\\', '/') + all_paths = all_paths + [path] + ParentPaths(path) + + all_paths = list(set(all_paths)) + return sorted(all_paths) + +''' +Collect all of files under paths +''' +def CollectFiles(paths, pattern): + files = [] + for path in paths: + if type(pattern) == type(''): + files = files + glob.glob(path + '/' + pattern) + else: + for item in pattern: + # print('--> %s' % (path + '/' + item)) + files = files + glob.glob(path + '/' + item) + + return sorted(files) + +def CollectAllFilesinPath(path, pattern): + files = [] + + for item in pattern: + files += glob.glob(path + '/' + item) + + list = os.listdir(path) + if len(list): + for item in list: + if item.startswith('.'): + continue + if item == 'bsp': + continue + + if os.path.isdir(os.path.join(path, item)): + files = files + CollectAllFilesinPath(os.path.join(path, item), pattern) + return files + +''' +Exclude files from infiles +''' +def ExcludeFiles(infiles, files): + in_files = set([OSPath(file) for file in infiles]) + exl_files = set([OSPath(file) for file in files]) + + exl_files = in_files - exl_files + + return exl_files + +def ExcludePaths(filepath, paths): + ret = [] + + files = os.listdir(filepath) + for file in files: + if file.startswith('.'): + continue + + fullname = os.path.join(filepath, file) + + if os.path.isdir(fullname): + # print(fullname) + if not fullname in paths: + ret = ret + [fullname] + else: + ret = ret + ExcludePaths(fullname, paths) + + return ret + +def HandleToolOption(tools, env): + project = ProjectInfo(env) + BSP_ROOT = os.path.abspath(env['BSP_ROOT']) + + CPPDEFINES = project['CPPDEFINES'] + paths = ['${ProjDirPath}/' + _make_path_relative(BSP_ROOT, os.path.normpath(i)).replace('\\', '/') for i in project['CPPPATH']] + + for tool in tools: + if tool.get('id').find('c.compile') != 1: + options = tool.findall('option') + for option in options: + if option.get('id').find('c.compiler.include.paths') != -1: + # find all of paths in this project + include_paths = option.findall('listOptionValue') + project_paths = [] + for item in include_paths: + project_paths += [item.get('value')] + + if len(project_paths) > 0: + cproject_paths = set(paths) - set(project_paths) + else: + cproject_paths = paths + + # print('c.compiler.include.paths') + cproject_paths = sorted(cproject_paths) + for item in cproject_paths: + SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': item}) + + if option.get('id').find('c.compiler.defs') != -1: + defs = option.findall('listOptionValue') + project_defs = [] + for item in defs: + 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') + cproject_defs = sorted(cproject_defs) + for item in cproject_defs: + SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': item}) + + if tool.get('id').find('c.linker') != -1: + options = tool.findall('option') + for option in options: + if option.get('id').find('c.linker.scriptfile') != -1: + linker_script = 'link.lds' + items = env['LINKFLAGS'].split(' ') + if '-T' in items: + linker_script = items[items.index('-T') + 1] + linker_script = '${ProjDirPath}/' + linker_script + + # print('c.linker.scriptfile') + listOptionValue = option.find('listOptionValue') + if listOptionValue != None: + listOptionValue.set('value', linker_script) + else: + SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': linker_script}) + + if option.get('id').find('c.linker.nostart') != -1: + if env['LINKFLAGS'].find('-nostartfiles') != -1: + option.set('value', 'true') + else: + option.set('value', 'false') + + return + +def HandleRTTRoot(env): + bsp_root = env['BSP_ROOT'] + rtt_root = env['RTT_ROOT'] + + if not rtt_root.startswith(bsp_root): + to_SubElement = True + # print('handle virtual root') + + # always use '/' path separator + rtt_root = rtt_root.replace('\\', '/') + + 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('\n') + xml_indent(root) + out.write(etree.tostring(root, encoding='utf-8')) + out.close() + + return + +def TargetEclipse(env): + global source_pattern + + print('Update eclipse setting...') + + if not os.path.exists('.cproject'): + print('no eclipse CDT project found!') + return + + HandleRTTRoot(env) + + project = ProjectInfo(env) + + all_paths = [OSPath(path) for path in CollectPaths(project['DIRS'])] + # print(all_paths) + bsp_root = os.path.abspath(env['BSP_ROOT']) + + exclude_paths = ExcludePaths(bsp_root, all_paths) + paths = exclude_paths + exclude_paths = [] + for path in paths: + # add bsp and libcpu folder and not collect source files (too more files) + if path.endswith('rt-thread\\bsp') or path.endswith('rt-thread\\libcpu'): + exclude_paths += [path] + continue + + set = CollectAllFilesinPath(path, source_pattern) + if len(set): + exclude_paths += [path] + + exclude_paths = [_make_path_relative(bsp_root, path).replace('\\', '/') for path in exclude_paths] + env['ExPaths'] = exclude_paths + + all_files = CollectFiles(all_paths, source_pattern) + src_files = project['FILES'] + + exclude_files = ExcludeFiles(all_files, src_files) + exclude_files = [_make_path_relative(bsp_root, file).replace('\\', '/') for file in exclude_files] + env['ExFiles'] = exclude_files + + cproject = etree.parse('.cproject') + + root = cproject.getroot() + cconfigurations = root.findall('storageModule/cconfiguration') + for cconfiguration in cconfigurations: + tools = cconfiguration.findall('storageModule/configuration/folderInfo/toolChain/tool') + HandleToolOption(tools, env) + + sourceEntries = cconfiguration.find('storageModule/configuration/sourceEntries') + entry = sourceEntries.find('entry') + if entry != None: + sourceEntries.remove(entry) + + excluding = exclude_paths + exclude_files + excluding = sorted(excluding) + value = '' + for item in excluding: + if value == '': + value = item + else: + value += '|' + item + excluding = value + + SubElement(sourceEntries, 'entry', {'excluding': excluding, 'flags': 'VALUE_WORKSPACE_PATH|RESOLVED', 'kind':'sourcePath', 'name':""}) + + # write back to .cproject + out = open('.cproject', 'w') + out.write('\n') + out.write('') + xml_indent(root) + out.write(etree.tostring(root, encoding='utf-8')) + out.close() + + print('done!') + + return -- cgit v1.3.1 From 6674e77986b1bd382980f418d7d374613264f771 Mon Sep 17 00:00:00 2001 From: armink Date: Mon, 29 Apr 2019 18:17:47 +0800 Subject: [tools][eclipse] Fix eclipse target update error. --- tools/building.py | 4 ++ tools/eclipse.py | 176 +++++++++++++++++++++++++++++++++++------------------- 2 files changed, 118 insertions(+), 62 deletions(-) (limited to 'tools/eclipse.py') diff --git a/tools/building.py b/tools/building.py index 4da64f6fcf..c037c2d068 100644 --- a/tools/building.py +++ b/tools/building.py @@ -830,6 +830,10 @@ def GenTargetProject(program = None): from makefile import TargetMakefile TargetMakefile(Env) + if GetOption('target') == 'eclipse': + from eclipse import TargetEclipse + TargetEclipse(Env) + def EndBuilding(target, program = None): import rtconfig diff --git a/tools/eclipse.py b/tools/eclipse.py index dc86c7be5a..78acc8904e 100644 --- a/tools/eclipse.py +++ b/tools/eclipse.py @@ -1,3 +1,14 @@ +# +# Copyright (c) 2006-2019, RT-Thread Development Team +# +# SPDX-License-Identifier: Apache-2.0 +# +# Change Logs: +# Date Author Notes +# 2019-03-21 Bernard the first version +# 2019-04-15 armink fix project update error +# + import os import sys import glob @@ -25,6 +36,8 @@ def OSPath(path): else: return [item.replace('\\', '/') for item in path] + +# collect the build source code path and parent path def CollectPaths(paths): all_paths = [] @@ -87,6 +100,8 @@ def ExcludeFiles(infiles, files): return exl_files + +# caluclate the exclude path for project def ExcludePaths(filepath, paths): ret = [] @@ -106,12 +121,18 @@ def ExcludePaths(filepath, paths): return ret -def HandleToolOption(tools, env): - project = ProjectInfo(env) + +def ConverToEclipsePathFormat(path): + if path.startswith('.'): + path = path[1:] + return '"${workspace_loc:/${ProjName}/' + path + '}"' + + +def HandleToolOption(tools, env, project): BSP_ROOT = os.path.abspath(env['BSP_ROOT']) CPPDEFINES = project['CPPDEFINES'] - paths = ['${ProjDirPath}/' + _make_path_relative(BSP_ROOT, os.path.normpath(i)).replace('\\', '/') for i in project['CPPPATH']] + paths = [ConverToEclipsePathFormat(RelativeProjectPath(env, os.path.normpath(i)).replace('\\', '/')) for i in project['CPPPATH']] for tool in tools: if tool.get('id').find('c.compile') != 1: @@ -157,9 +178,8 @@ def HandleToolOption(tools, env): items = env['LINKFLAGS'].split(' ') if '-T' in items: linker_script = items[items.index('-T') + 1] - linker_script = '${ProjDirPath}/' + linker_script + linker_script = ConverToEclipsePathFormat(linker_script) - # print('c.linker.scriptfile') listOptionValue = option.find('listOptionValue') if listOptionValue != None: listOptionValue.set('value', linker_script) @@ -174,7 +194,7 @@ def HandleToolOption(tools, env): return -def HandleRTTRoot(env): +def UpdateProjectStructure(env): bsp_root = env['BSP_ROOT'] rtt_root = env['RTT_ROOT'] @@ -185,62 +205,54 @@ def HandleRTTRoot(env): # always use '/' path separator rtt_root = rtt_root.replace('\\', '/') - 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('\n') - xml_indent(root) - out.write(etree.tostring(root, encoding='utf-8')) - out.close() + # TODO create the virtual folder + +# 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('\n') +# xml_indent(root) +# out.write(etree.tostring(root, encoding='utf-8')) +# out.close() return -def TargetEclipse(env): - global source_pattern +def GenExcluding(env, project): + rtt_root = os.path.abspath(env['RTT_ROOT']) + coll_dirs = CollectPaths(project['DIRS']) + all_paths = [OSPath(path) for path in coll_dirs] - print('Update eclipse setting...') - - if not os.path.exists('.cproject'): - print('no eclipse CDT project found!') - return + exclude_paths = ExcludePaths(rtt_root, all_paths) - HandleRTTRoot(env) - - project = ProjectInfo(env) - - all_paths = [OSPath(path) for path in CollectPaths(project['DIRS'])] - # print(all_paths) - bsp_root = os.path.abspath(env['BSP_ROOT']) - - exclude_paths = ExcludePaths(bsp_root, all_paths) paths = exclude_paths exclude_paths = [] + # remove the folder which not has source code by source_pattern for path in paths: # add bsp and libcpu folder and not collect source files (too more files) if path.endswith('rt-thread\\bsp') or path.endswith('rt-thread\\libcpu'): @@ -251,15 +263,37 @@ def TargetEclipse(env): if len(set): exclude_paths += [path] - exclude_paths = [_make_path_relative(bsp_root, 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) src_files = project['FILES'] exclude_files = ExcludeFiles(all_files, src_files) - exclude_files = [_make_path_relative(bsp_root, file).replace('\\', '/') for file in exclude_files] + exclude_files = [RelativeProjectPath(env, file).replace('\\', '/') for file in exclude_files] env['ExFiles'] = exclude_files + + return exclude_paths + exclude_files + + +def RelativeProjectPath(env, path): + project_root = os.path.abspath(env['BSP_ROOT']) + rtt_root = os.path.abspath(env['RTT_ROOT']) + + if path.startswith(project_root): + return _make_path_relative(project_root, path) + + if path.startswith(rtt_root): + return 'rt-thread/' + _make_path_relative(rtt_root, path) + + # TODO add others folder + print('ERROR: the ' + path + 'not support') + + return path + + +def UpdateCproject(env, project, excluding): + excluding = sorted(excluding) cproject = etree.parse('.cproject') @@ -267,24 +301,21 @@ def TargetEclipse(env): cconfigurations = root.findall('storageModule/cconfiguration') for cconfiguration in cconfigurations: tools = cconfiguration.findall('storageModule/configuration/folderInfo/toolChain/tool') - HandleToolOption(tools, env) + HandleToolOption(tools, env, project) sourceEntries = cconfiguration.find('storageModule/configuration/sourceEntries') entry = sourceEntries.find('entry') if entry != None: sourceEntries.remove(entry) - excluding = exclude_paths + exclude_files - excluding = sorted(excluding) value = '' for item in excluding: if value == '': value = item else: value += '|' + item - excluding = value - SubElement(sourceEntries, 'entry', {'excluding': excluding, 'flags': 'VALUE_WORKSPACE_PATH|RESOLVED', 'kind':'sourcePath', 'name':""}) + SubElement(sourceEntries, 'entry', {'excluding': value, 'flags': 'VALUE_WORKSPACE_PATH|RESOLVED', 'kind':'sourcePath', 'name':""}) # write back to .cproject out = open('.cproject', 'w') @@ -294,6 +325,27 @@ def TargetEclipse(env): out.write(etree.tostring(root, encoding='utf-8')) out.close() + +def TargetEclipse(env): + global source_pattern + + print('Update eclipse setting...') + + if not os.path.exists('.cproject'): + print('no eclipse CDT project found!') + return + + project = ProjectInfo(env) + + # update the project file structure info on '.project' file + UpdateProjectStructure(env) + + # generate the exclude paths and files + excluding = GenExcluding(env, project) + + # update the project configuration on '.cproject' file + UpdateCproject(env, project, excluding) + print('done!') return -- cgit v1.3.1 From ab81ff6815db0ee641dc11450076d733fb5d15a6 Mon Sep 17 00:00:00 2001 From: armink Date: Tue, 18 Jun 2019 20:08:00 +0800 Subject: [tools] Add project name set feature to eclipse target. --- tools/eclipse.py | 105 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 53 insertions(+), 52 deletions(-) (limited to 'tools/eclipse.py') diff --git a/tools/eclipse.py b/tools/eclipse.py index 78acc8904e..316a98b87a 100644 --- a/tools/eclipse.py +++ b/tools/eclipse.py @@ -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('\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('\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!') -- cgit v1.3.1 From 36d6326732a7081e04172dbc69eba503d52691d3 Mon Sep 17 00:00:00 2001 From: eddylin83 Date: Mon, 5 Aug 2019 18:00:20 +0800 Subject: add stm32cubeide support --- tools/eclipse.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'tools/eclipse.py') diff --git a/tools/eclipse.py b/tools/eclipse.py index 316a98b87a..e4c37892e9 100644 --- a/tools/eclipse.py +++ b/tools/eclipse.py @@ -138,7 +138,7 @@ def HandleToolOption(tools, env, project, reset): if tool.get('id').find('c.compile') != 1: options = tool.findall('option') for option in options: - if option.get('id').find('c.compiler.include.paths') != -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.findall('listOptionValue') project_paths = [] @@ -159,7 +159,7 @@ def HandleToolOption(tools, env, project, reset): for item in cproject_paths: SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': item}) - if option.get('id').find('c.compiler.defs') != -1: + if option.get('id').find('c.compiler.defs') != -1 or option.get('id').find('c.compiler.option.definedsymbols') != -1: defs = option.findall('listOptionValue') project_defs = [] for item in defs: @@ -194,6 +194,13 @@ def HandleToolOption(tools, env, project, reset): else: SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': linker_script}) + # scriptfile in stm32cubeIDE + if option.get('id').find('c.linker.option.script') != -1: + items = env['LINKFLAGS'].split(' ') + if '-T' in items: + linker_script = ConverToEclipsePathFormat(items[items.index('-T') + 1]).strip('"') + option.set('value',linker_script) + if option.get('id').find('c.linker.nostart') != -1: if env['LINKFLAGS'].find('-nostartfiles') != -1: option.set('value', 'true') -- cgit v1.3.1 From 4e136e4271d6a608e5ddbcda181825c2b38d3748 Mon Sep 17 00:00:00 2001 From: armink Date: Thu, 15 Aug 2019 10:21:46 +0800 Subject: [tools] Fix eclipse configuration for libs. --- tools/eclipse.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tools/eclipse.py') diff --git a/tools/eclipse.py b/tools/eclipse.py index e4c37892e9..bc4e670e36 100644 --- a/tools/eclipse.py +++ b/tools/eclipse.py @@ -181,6 +181,7 @@ def HandleToolOption(tools, env, project, reset): if tool.get('id').find('c.linker') != -1: options = tool.findall('option') for option in options: + # update linker script config if option.get('id').find('c.linker.scriptfile') != -1: linker_script = 'link.lds' items = env['LINKFLAGS'].split(' ') @@ -201,12 +202,22 @@ def HandleToolOption(tools, env, project, reset): linker_script = ConverToEclipsePathFormat(items[items.index('-T') + 1]).strip('"') option.set('value',linker_script) + # update nostartfiles config if option.get('id').find('c.linker.nostart') != -1: if env['LINKFLAGS'].find('-nostartfiles') != -1: option.set('value', 'true') else: option.set('value', 'false') + # update libs + if option.get('id').find('c.linker.libs') != -1 and env.has_key('LIBS'): + # remove old libs + for item in option.findall('listOptionValue'): + option.remove(item) + # add new libs + for lib in env['LIBS']: + SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': lib}) + return -- cgit v1.3.1 From e6a07139ce595d7045fc54748544708e5921f2b7 Mon Sep 17 00:00:00 2001 From: armink Date: Thu, 15 Aug 2019 10:22:29 +0800 Subject: [tools] Fix eclipse configuration for lib paths. --- tools/eclipse.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tools/eclipse.py') diff --git a/tools/eclipse.py b/tools/eclipse.py index bc4e670e36..d781a701cb 100644 --- a/tools/eclipse.py +++ b/tools/eclipse.py @@ -218,6 +218,15 @@ def HandleToolOption(tools, env, project, reset): for lib in env['LIBS']: SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': lib}) + # update lib paths + if option.get('id').find('c.linker.paths') != -1 and env.has_key('LIBPATH'): + # remove old lib paths + for item in option.findall('listOptionValue'): + option.remove(item) + # add new old lib paths + for path in env['LIBPATH']: + SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': path}) + return -- cgit v1.3.1 From 3333462d134759521d2c82c28b4397c1da0ba430 Mon Sep 17 00:00:00 2001 From: armink Date: Thu, 24 Oct 2019 19:11:18 +0800 Subject: [tools] add include file for scons --target=eclipse --- tools/building.py | 7 ++- tools/eclipse.py | 131 ++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 94 insertions(+), 44 deletions(-) (limited to 'tools/eclipse.py') diff --git a/tools/building.py b/tools/building.py index 8d461102bc..2c9719e398 100644 --- a/tools/building.py +++ b/tools/building.py @@ -181,6 +181,11 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ action = 'store_true', default = False, help = 'reset the project configurations to default') + AddOption('--mcu-type', + dest = 'mcu-type', + type = 'string', + default = False, + help = 'set mcu type name') AddOption('--cscope', dest = 'cscope', action = 'store_true', @@ -852,7 +857,7 @@ def GenTargetProject(program = None): if GetOption('target') == 'eclipse': from eclipse import TargetEclipse - TargetEclipse(Env, GetOption('reset-project-config'), GetOption('project-name')) + TargetEclipse(Env, GetOption('reset-project-config'), GetOption('project-name'), GetOption('mcu-type')) def EndBuilding(target, program = None): diff --git a/tools/eclipse.py b/tools/eclipse.py index d781a701cb..9f6f2f8dbd 100644 --- a/tools/eclipse.py +++ b/tools/eclipse.py @@ -128,7 +128,7 @@ def ConverToEclipsePathFormat(path): return '"${workspace_loc:/${ProjName}/' + path + '}"' -def HandleToolOption(tools, env, project, reset): +def HandleToolOption(tools, env, project, reset, mcu_type): BSP_ROOT = os.path.abspath(env['BSP_ROOT']) CPPDEFINES = project['CPPDEFINES'] @@ -137,46 +137,86 @@ def HandleToolOption(tools, env, project, reset): for tool in tools: if tool.get('id').find('c.compile') != 1: options = tool.findall('option') + include_paths_option = None + include_files_option = None + defs_option = None + # find all compile 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: - # find all of paths in this project - include_paths = option.findall('listOptionValue') - project_paths = [] - for item in include_paths: - 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) + include_paths_option = option + elif option.get('id').find('c.compiler.include.files') != -1 or option.get('id').find('c.compiler.option.includefiles') != -1 : + include_files_option = option + elif option.get('id').find('c.compiler.defs') != -1 or option.get('id').find('c.compiler.option.definedsymbols') != -1: + defs_option = option + # change the inclue path + if include_paths_option is not None : + option = include_paths_option + # find all of paths in this project + include_paths = option.findall('listOptionValue') + project_paths = [] + for item in include_paths: + if reset is True: + # clean all old configuration + option.remove(item) else: - cproject_paths = paths - - # print('c.compiler.include.paths') - cproject_paths = sorted(cproject_paths) - for item in cproject_paths: - SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': item}) - - if option.get('id').find('c.compiler.defs') != -1 or option.get('id').find('c.compiler.option.definedsymbols') != -1: - defs = option.findall('listOptionValue') - project_defs = [] - for item in defs: - 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) + project_paths += [item.get('value')] + + if len(project_paths) > 0: + cproject_paths = set(paths) - set(project_paths) + else: + cproject_paths = paths + + # print('c.compiler.include.paths') + cproject_paths = sorted(cproject_paths) + for item in cproject_paths: + SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': item}) + # change the inclue files (default) or definitions + if include_files_option is not None: + option = include_paths_option + file_header = ''' +#ifndef RTCONFIG_PREINC_H__ +#define RTCONFIG_PREINC_H__ + +/* Automatically generated file; DO NOT EDIT. */ +/* RT-Thread Configuration */ + +''' + file_tail = '\n#endif /*RTCONFIG_PREINC_H__*/\n' + 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: - 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') - cproject_defs = sorted(cproject_defs) - for item in cproject_defs: - SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': item}) + # print('c.compiler.defs') + cproject_defs = sorted(cproject_defs) + for item in cproject_defs: + SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': item}) if tool.get('id').find('c.linker') != -1: options = tool.findall('option') @@ -262,7 +302,7 @@ def UpdateProjectStructure(env, prj_name): return -def GenExcluding(env, project): +def GenExcluding(env, project, mcu_type): rtt_root = os.path.abspath(env['RTT_ROOT']) bsp_root = os.path.abspath(env['BSP_ROOT']) coll_dirs = CollectPaths(project['DIRS']) @@ -300,7 +340,12 @@ def GenExcluding(env, project): exclude_files = ExcludeFiles(all_files, src_files) exclude_files = [RelativeProjectPath(env, file).replace('\\', '/') for file in exclude_files] env['ExFiles'] = exclude_files - + + if mcu_type : + # TODO save the rt-thread and packages exclude folder only + # TODO exclude the libraries/STM32L4xx_HAL/CMSIS/Device/ST/STM32L4xx/Source/Templates/ arm|iar|gcc/xxx.s + pass + return exclude_paths + exclude_files @@ -320,7 +365,7 @@ def RelativeProjectPath(env, path): return path -def UpdateCproject(env, project, excluding, reset): +def UpdateCproject(env, project, excluding, reset, mcu_type): excluding = sorted(excluding) cproject = etree.parse('.cproject') @@ -329,7 +374,7 @@ def UpdateCproject(env, project, excluding, reset): cconfigurations = root.findall('storageModule/cconfiguration') for cconfiguration in cconfigurations: tools = cconfiguration.findall('storageModule/configuration/folderInfo/toolChain/tool') - HandleToolOption(tools, env, project, reset) + HandleToolOption(tools, env, project, reset, mcu_type) sourceEntries = cconfiguration.find('storageModule/configuration/sourceEntries') entry = sourceEntries.find('entry') @@ -354,7 +399,7 @@ def UpdateCproject(env, project, excluding, reset): out.close() -def TargetEclipse(env, reset = False, prj_name = None): +def TargetEclipse(env, reset = False, prj_name = None, mcu_type = None): global source_pattern print('Update eclipse setting...') @@ -369,10 +414,10 @@ def TargetEclipse(env, reset = False, prj_name = None): UpdateProjectStructure(env, prj_name) # generate the exclude paths and files - excluding = GenExcluding(env, project) + excluding = GenExcluding(env, project, mcu_type) # update the project configuration on '.cproject' file - UpdateCproject(env, project, excluding, reset) + UpdateCproject(env, project, excluding, reset, mcu_type) print('done!') -- cgit v1.3.1 From c8beffeee0cfcd0e22033d7b2e615e985da36313 Mon Sep 17 00:00:00 2001 From: armink Date: Fri, 25 Oct 2019 11:57:33 +0800 Subject: [tools] improve the eclipse project's exclude paths. --- tools/eclipse.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'tools/eclipse.py') diff --git a/tools/eclipse.py b/tools/eclipse.py index 9f6f2f8dbd..c8f749a6ca 100644 --- a/tools/eclipse.py +++ b/tools/eclipse.py @@ -172,7 +172,7 @@ def HandleToolOption(tools, env, project, reset, mcu_type): SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': item}) # change the inclue files (default) or definitions if include_files_option is not None: - option = include_paths_option + option = include_files_option file_header = ''' #ifndef RTCONFIG_PREINC_H__ #define RTCONFIG_PREINC_H__ @@ -313,7 +313,20 @@ def GenExcluding(env, project, mcu_type): 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) + if mcu_type is None : # BSP mode, not MCU mode + exclude_paths = ExcludePaths(bsp_root, all_paths) + else : + 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: exclude_paths = ExcludePaths(rtt_root, all_paths) exclude_paths += ExcludePaths(bsp_root, all_paths) @@ -332,19 +345,15 @@ def GenExcluding(env, project, mcu_type): exclude_paths += [path] exclude_paths = [RelativeProjectPath(env, path).replace('\\', '/') for path in exclude_paths] - env['ExPaths'] = exclude_paths all_files = CollectFiles(all_paths, source_pattern) src_files = project['FILES'] exclude_files = ExcludeFiles(all_files, src_files) exclude_files = [RelativeProjectPath(env, file).replace('\\', '/') for file in exclude_files] - env['ExFiles'] = exclude_files - if mcu_type : - # TODO save the rt-thread and packages exclude folder only - # TODO exclude the libraries/STM32L4xx_HAL/CMSIS/Device/ST/STM32L4xx/Source/Templates/ arm|iar|gcc/xxx.s - pass + env['ExPaths'] = exclude_paths + env['ExFiles'] = exclude_files return exclude_paths + exclude_files @@ -360,7 +369,7 @@ def RelativeProjectPath(env, path): return 'rt-thread/' + _make_path_relative(rtt_root, path) # TODO add others folder - print('ERROR: the ' + path + 'not support') + print('ERROR: the ' + path + ' not support') return path -- cgit v1.3.1 From 3d0ccf62c907c75f8aec115c41c6a8b0b1ef6e8f Mon Sep 17 00:00:00 2001 From: armink Date: Fri, 25 Oct 2019 12:03:31 +0800 Subject: [tools] change the eclipse default paths exclude mode. --- tools/building.py | 7 +------ tools/eclipse.py | 40 +++++++++++++++++++--------------------- 2 files changed, 20 insertions(+), 27 deletions(-) (limited to 'tools/eclipse.py') diff --git a/tools/building.py b/tools/building.py index 2c9719e398..8d461102bc 100644 --- a/tools/building.py +++ b/tools/building.py @@ -181,11 +181,6 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ action = 'store_true', default = False, help = 'reset the project configurations to default') - AddOption('--mcu-type', - dest = 'mcu-type', - type = 'string', - default = False, - help = 'set mcu type name') AddOption('--cscope', dest = 'cscope', action = 'store_true', @@ -857,7 +852,7 @@ def GenTargetProject(program = None): if GetOption('target') == 'eclipse': from eclipse import TargetEclipse - TargetEclipse(Env, GetOption('reset-project-config'), GetOption('project-name'), GetOption('mcu-type')) + TargetEclipse(Env, GetOption('reset-project-config'), GetOption('project-name')) def EndBuilding(target, program = None): diff --git a/tools/eclipse.py b/tools/eclipse.py index c8f749a6ca..840ed9f191 100644 --- a/tools/eclipse.py +++ b/tools/eclipse.py @@ -128,7 +128,7 @@ def ConverToEclipsePathFormat(path): return '"${workspace_loc:/${ProjName}/' + path + '}"' -def HandleToolOption(tools, env, project, reset, mcu_type): +def HandleToolOption(tools, env, project, reset): BSP_ROOT = os.path.abspath(env['BSP_ROOT']) CPPDEFINES = project['CPPDEFINES'] @@ -302,7 +302,8 @@ def UpdateProjectStructure(env, prj_name): return -def GenExcluding(env, project, mcu_type): + +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']) @@ -313,20 +314,17 @@ def GenExcluding(env, project, mcu_type): 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 - if mcu_type is None : # BSP mode, not MCU mode - exclude_paths = ExcludePaths(bsp_root, all_paths) - else : - 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) + 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: exclude_paths = ExcludePaths(rtt_root, all_paths) exclude_paths += ExcludePaths(bsp_root, all_paths) @@ -374,7 +372,7 @@ def RelativeProjectPath(env, path): return path -def UpdateCproject(env, project, excluding, reset, mcu_type): +def UpdateCproject(env, project, excluding, reset): excluding = sorted(excluding) cproject = etree.parse('.cproject') @@ -383,7 +381,7 @@ def UpdateCproject(env, project, excluding, reset, mcu_type): cconfigurations = root.findall('storageModule/cconfiguration') for cconfiguration in cconfigurations: tools = cconfiguration.findall('storageModule/configuration/folderInfo/toolChain/tool') - HandleToolOption(tools, env, project, reset, mcu_type) + HandleToolOption(tools, env, project, reset) sourceEntries = cconfiguration.find('storageModule/configuration/sourceEntries') entry = sourceEntries.find('entry') @@ -408,7 +406,7 @@ def UpdateCproject(env, project, excluding, reset, mcu_type): out.close() -def TargetEclipse(env, reset = False, prj_name = None, mcu_type = None): +def TargetEclipse(env, reset = False, prj_name = None): global source_pattern print('Update eclipse setting...') @@ -423,10 +421,10 @@ def TargetEclipse(env, reset = False, prj_name = None, mcu_type = None): UpdateProjectStructure(env, prj_name) # generate the exclude paths and files - excluding = GenExcluding(env, project, mcu_type) + excluding = GenExcluding(env, project) # update the project configuration on '.cproject' file - UpdateCproject(env, project, excluding, reset, mcu_type) + UpdateCproject(env, project, excluding, reset) print('done!') -- cgit v1.3.1 From 8dabc3be27ed7269bddd7da37d019a99213fa46e Mon Sep 17 00:00:00 2001 From: armink Date: Fri, 25 Oct 2019 15:56:34 +0800 Subject: [tools] change the eclipse project include path format --- bsp/stm32/stm32f103-dofly-M3S/.cproject | 34 ++++++++++---------- bsp/stm32/stm32f103-yf-ufun/.cproject | 33 ++++++++++--------- bsp/stm32/stm32f401-st-nucleo/.cproject | 32 +++++++++---------- bsp/stm32/stm32f407-atk-explorer/.cproject | 34 ++++++++++---------- bsp/stm32/stm32f411-st-nucleo/.cproject | 33 ++++++++++--------- bsp/stm32/stm32f429-atk-apollo/.cproject | 34 ++++++++++---------- bsp/stm32/stm32f429-fire-challenger/.cproject | 34 ++++++++++---------- bsp/stm32/stm32f767-atk-apollo/.cproject | 34 ++++++++++---------- bsp/stm32/stm32l475-atk-pandora/.cproject | 46 +++++++++++++-------------- tools/eclipse.py | 41 ++++++++++++------------ 10 files changed, 176 insertions(+), 179 deletions(-) (limited to 'tools/eclipse.py') diff --git a/bsp/stm32/stm32f103-dofly-M3S/.cproject b/bsp/stm32/stm32f103-dofly-M3S/.cproject index eaeea747e7..ebcf2b2323 100644 --- a/bsp/stm32/stm32f103-dofly-M3S/.cproject +++ b/bsp/stm32/stm32f103-dofly-M3S/.cproject @@ -60,22 +60,22 @@