summaryrefslogtreecommitdiff
path: root/tools/eclipse.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/eclipse.py')
-rw-r--r--tools/eclipse.py133
1 files changed, 98 insertions, 35 deletions
diff --git a/tools/eclipse.py b/tools/eclipse.py
index ef546fb15a..4f3cda92b8 100644
--- a/tools/eclipse.py
+++ b/tools/eclipse.py
@@ -9,23 +9,21 @@
# 2019-04-15 armink fix project update error
#
-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
+import rt_studio
from building import *
+from utils import *
+from utils import _make_path_relative
+from utils import xml_indent
-MODULE_VER_NUM = 3
+MODULE_VER_NUM = 6
source_pattern = ['*.c', '*.cpp', '*.cxx', '*.s', '*.S', '*.asm']
+
def OSPath(path):
import platform
@@ -60,9 +58,12 @@ def CollectPaths(paths):
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:
@@ -75,6 +76,7 @@ def CollectFiles(paths, pattern):
return sorted(files)
+
def CollectAllFilesinPath(path, pattern):
files = []
@@ -93,11 +95,14 @@ def CollectAllFilesinPath(path, pattern):
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])
+ in_files = set([OSPath(file) for file in infiles])
exl_files = set([OSPath(file) for file in files])
exl_files = in_files - exl_files
@@ -136,14 +141,29 @@ def ConverToRttEclipsePathFormat(path):
def IsRttEclipsePathFormat(path):
if path.startswith(rtt_path_prefix):
return True
- else :
+ else:
return False
-
-
+
+
+# all libs added by scons should be ends with five whitespace as a flag
+rtt_lib_flag = 5 * " "
+
+
+def ConverToRttEclipseLibFormat(lib):
+ return str(lib) + str(rtt_lib_flag)
+
+
+def IsRttEclipseLibFormat(path):
+ if path.endswith(rtt_lib_flag):
+ return True
+ else:
+ return False
+
+
def IsCppProject():
return GetDepend('RT_USING_CPLUSPLUS')
-
+
def HandleToolOption(tools, env, project, reset):
is_cpp_prj = IsCppProject()
BSP_ROOT = os.path.abspath(env['BSP_ROOT'])
@@ -189,7 +209,7 @@ def HandleToolOption(tools, env, project, reset):
linker_script_option = option
elif option.get('id').find('linker.nostart') != -1:
linker_nostart_option = option
- elif option.get('id').find('linker.libs') != -1 and env.has_key('LIBS'):
+ elif option.get('id').find('linker.libs') != -1:
linker_libs_option = option
elif option.get('id').find('linker.paths') != -1 and env.has_key('LIBPATH'):
linker_paths_option = option
@@ -288,16 +308,22 @@ def HandleToolOption(tools, env, project, reset):
else:
option.set('value', 'false')
# update libs
- if linker_libs_option is not None :
+ if linker_libs_option is not None:
option = linker_libs_option
# remove old libs
for item in option.findall('listOptionValue'):
- option.remove(item)
+ if IsRttEclipseLibFormat(item.get("value")):
+ option.remove(item)
+
# add new libs
- for lib in env['LIBS']:
- SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': lib})
+ if env.has_key('LIBS'):
+ for lib in env['LIBS']:
+ formatedLib = ConverToRttEclipseLibFormat(lib)
+ SubElement(option, 'listOptionValue', {
+ 'builtIn': 'false', 'value': formatedLib})
+
# update lib paths
- if linker_paths_option is not None :
+ if linker_paths_option is not None:
option = linker_paths_option
# remove old lib paths
for item in option.findall('listOptionValue'):
@@ -338,7 +364,7 @@ def UpdateProjectStructure(env, 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.write(etree.tostring(root, encoding='utf-8'))
out.close()
return
@@ -348,12 +374,13 @@ 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]
+ all_paths_temp = [OSPath(path) for path in coll_dirs]
+ all_paths = []
- # remove unused path
- for path in all_paths:
- if not path.startswith(rtt_root) and not path.startswith(bsp_root):
- all_paths.remove(path)
+ # add used path
+ for path in all_paths_temp:
+ if path.startswith(rtt_root) or path.startswith(bsp_root):
+ all_paths.append(path)
if bsp_root.startswith(rtt_root):
# bsp folder is in the RT-Thread root folder, such as the RT-Thread source code on GitHub
@@ -363,8 +390,8 @@ def GenExcluding(env, project):
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) :
+ 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]]
@@ -399,16 +426,16 @@ def GenExcluding(env, project):
env['ExPaths'] = exclude_paths
env['ExFiles'] = exclude_files
- return exclude_paths + 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)
@@ -426,9 +453,9 @@ def HandleExcludingOption(entry, sourceEntries, excluding):
value = ''
for item in old_excluding:
- if item.startswith('//') :
+ if item.startswith('//'):
old_excluding.remove(item)
- else :
+ else:
if value == '':
value = item
else:
@@ -477,14 +504,50 @@ def UpdateCproject(env, project, excluding, reset, prj_name):
out.close()
-def TargetEclipse(env, reset = False, prj_name = None):
+def TargetEclipse(env, reset=False, prj_name=None):
global source_pattern
print('Update eclipse setting...')
+ # generate cproject file
if not os.path.exists('.cproject'):
- print('no eclipse CDT project found!')
- return
+ if rt_studio.gen_cproject_file(os.path.abspath(".cproject")) is False:
+ print('Fail!')
+ return
+
+ # generate project file
+ if not os.path.exists('.project'):
+ if rt_studio.gen_project_file(os.path.abspath(".project")) is False:
+ print('Fail!')
+ return
+
+ # generate projcfg.ini file
+ if not os.path.exists('.settings/projcfg.ini'):
+ # if search files with uvprojx or uvproj suffix
+ file = ""
+ items = os.listdir(".")
+ if len(items) > 0:
+ for item in items:
+ if item.endswith(".uvprojx") or item.endswith(".uvproj"):
+ file = os.path.abspath(item)
+ break
+ chip_name = rt_studio.get_mcu_info(file)
+ if rt_studio.gen_projcfg_ini_file(chip_name, prj_name, os.path.abspath(".settings/projcfg.ini")) is False:
+ print('Fail!')
+ return
+
+ # enable lowwer .s file compiled in eclipse cdt
+ if not os.path.exists('.settings/org.eclipse.core.runtime.prefs'):
+ if rt_studio.gen_org_eclipse_core_runtime_prefs(
+ os.path.abspath(".settings/org.eclipse.core.runtime.prefs")) is False:
+ print('Fail!')
+ return
+
+ # add clean2 target to fix issues when files too many
+ if not os.path.exists('makefile.targets'):
+ if rt_studio.gen_makefile_targets(os.path.abspath("makefile.targets")) is False:
+ print('Fail!')
+ return
project = ProjectInfo(env)