From 3333462d134759521d2c82c28b4397c1da0ba430 Mon Sep 17 00:00:00 2001 From: armink Date: Thu, 24 Oct 2019 19:11:18 +0800 Subject: [PATCH 1/7] [tools] add include file for scons --target=eclipse --- tools/building.py | 7 ++- tools/eclipse.py | 127 +++++++++++++++++++++++++++++++--------------- 2 files changed, 92 insertions(+), 42 deletions(-) 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 + project_paths += [item.get('value')] - # print('c.compiler.include.paths') - cproject_paths = sorted(cproject_paths) - for item in cproject_paths: - SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': item}) + if len(project_paths) > 0: + cproject_paths = set(paths) - set(project_paths) + else: + cproject_paths = paths - 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) + # 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!') From c8beffeee0cfcd0e22033d7b2e615e985da36313 Mon Sep 17 00:00:00 2001 From: armink Date: Fri, 25 Oct 2019 11:57:33 +0800 Subject: [PATCH 2/7] [tools] improve the eclipse project's exclude paths. --- tools/eclipse.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) 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 From 3d0ccf62c907c75f8aec115c41c6a8b0b1ef6e8f Mon Sep 17 00:00:00 2001 From: armink Date: Fri, 25 Oct 2019 12:03:31 +0800 Subject: [PATCH 3/7] [tools] change the eclipse default paths exclude mode. --- tools/building.py | 7 +------ tools/eclipse.py | 40 +++++++++++++++++++--------------------- 2 files changed, 20 insertions(+), 27 deletions(-) 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!') From 21e5a706e0c0460a4b8ad87b6fb6c2e8d504e424 Mon Sep 17 00:00:00 2001 From: armink Date: Fri, 25 Oct 2019 13:53:34 +0800 Subject: [PATCH 4/7] [bsp/stm32] update the eclipse project config. --- bsp/stm32/stm32f103-dofly-M3S/.cproject | 6 ++++-- bsp/stm32/stm32f103-yf-ufun/.cproject | 6 ++++-- bsp/stm32/stm32f401-st-nucleo/.cproject | 6 ++++-- bsp/stm32/stm32f407-atk-explorer/.cproject | 6 ++++-- bsp/stm32/stm32f411-st-nucleo/.cproject | 6 ++++-- bsp/stm32/stm32f429-atk-apollo/.cproject | 6 ++++-- bsp/stm32/stm32f429-fire-challenger/.cproject | 6 ++++-- bsp/stm32/stm32f767-atk-apollo/.cproject | 6 ++++-- bsp/stm32/stm32l475-atk-pandora/.cproject | 6 ++++-- 9 files changed, 36 insertions(+), 18 deletions(-) diff --git a/bsp/stm32/stm32f103-dofly-M3S/.cproject b/bsp/stm32/stm32f103-dofly-M3S/.cproject index 0a7b7602a0..8cc4104435 100644 --- a/bsp/stm32/stm32f103-dofly-M3S/.cproject +++ b/bsp/stm32/stm32f103-dofly-M3S/.cproject @@ -86,8 +86,10 @@