未验证 提交 9839dcd5 编写于 作者: B Bernard Xiong 提交者: GitHub

Merge pull request #2637 from armink/target_eclipse

更新 Eclipse 工程的生成
此差异已折叠。
*.pyc
*.map
*.dblite
*.elf
*.bin
*.hex
*.axf
*.exe
*.pdb
*.idb
*.ilk
*.old
build
Debug
documentation/html
packages/
*~
*.o
*.obj
*.out
*.bak
*.dep
*.lib
*.i
*.d
.DS_Stor*
.config 3
.config 4
.config 5
Midea-X1
*.uimg
GPATH
GRTAGS
GTAGS
.vscode
JLinkLog.txt
JLinkSettings.ini
DebugConfig/
RTE/
settings/
*.uvguix*
cconfig.h
.settings
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>qemu-vexpress-a9</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
<linkedResources>
<link>
<name>rt-thread</name>
<type>2</type>
<locationURI>virtual:/virtual</locationURI>
</link>
<link>
<name>rt-thread/components</name>
<type>2</type>
<locationURI>$%7BPARENT-2-PROJECT_LOC%7D/components</locationURI>
</link>
<link>
<name>rt-thread/include</name>
<type>2</type>
<locationURI>$%7BPARENT-2-PROJECT_LOC%7D/include</locationURI>
</link>
<link>
<name>rt-thread/libcpu</name>
<type>2</type>
<locationURI>$%7BPARENT-2-PROJECT_LOC%7D/libcpu</locationURI>
</link>
<link>
<name>rt-thread/src</name>
<type>2</type>
<locationURI>$%7BPARENT-2-PROJECT_LOC%7D/src</locationURI>
</link>
</linkedResources>
</projectDescription>
clean2:
-$(RM) $(CC_DEPS)$(C++_DEPS)$(C_UPPER_DEPS)$(CXX_DEPS)$(SECONDARY_FLASH)$(SECONDARY_SIZE)$(ASM_DEPS)$(S_UPPER_DEPS)$(C_DEPS)$(CPP_DEPS)
-$(RM) $(OBJS) *.elf
-@echo ' '
\ No newline at end of file
......@@ -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
......
#
# 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('<?xml version="1.0" encoding="UTF-8"?>\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('<?xml version="1.0" encoding="UTF-8"?>\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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册