summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/building.py25
-rw-r--r--tools/mkdist.py7
-rw-r--r--tools/utils.py116
-rw-r--r--tools/vsc.py46
4 files changed, 186 insertions, 8 deletions
diff --git a/tools/building.py b/tools/building.py
index 22350b28b7..b859f30eb4 100644
--- a/tools/building.py
+++ b/tools/building.py
@@ -123,6 +123,11 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
Env = env
Rtt_Root = os.path.abspath(root_directory)
+ # set RTT_ROOT in ENV
+ Env['RTT_ROOT'] = Rtt_Root
+ # set BSP_ROOT in ENV
+ Env['BSP_ROOT'] = Dir('#').abspath
+
sys.path = sys.path + [os.path.join(Rtt_Root, 'tools')]
# add compability with Keil MDK 4.6 which changes the directory of armcc.exe
@@ -259,7 +264,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
AddOption('--target',
dest='target',
type='string',
- help='set target project: mdk/mdk4/iar/vs/ua')
+ help='set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua')
#{target_name:(CROSS_TOOL, PLATFORM)}
tgt_dict = {'mdk':('keil', 'armcc'),
@@ -268,6 +273,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
'iar':('iar', 'iar'),
'vs':('msvc', 'cl'),
'vs2012':('msvc', 'cl'),
+ 'vsc' : ('gcc', 'gcc'),
'cb':('keil', 'armcc'),
'ua':('gcc', 'gcc')}
tgt_name = GetOption('target')
@@ -320,6 +326,12 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
mk_rtconfig(configfn)
exit(0)
+ AddOption('--test',
+ dest='test',
+ action='store_true',
+ default=False,
+ help='some test feature')
+
# add comstr option
AddOption('--verbose',
dest='verbose',
@@ -531,7 +543,7 @@ def DefineGroup(name, src, depend, **parameters):
group = parameters
group['name'] = name
group['path'] = group_path
- if type(src) == type(['src1']):
+ if type(src) == type([]):
group['src'] = File(src)
else:
group['src'] = src
@@ -692,6 +704,9 @@ def DoBuilding(target, objects):
def EndBuilding(target, program = None):
import rtconfig
+ Env['target'] = program
+ Env['project'] = Projects
+
Env.AddPostAction(target, rtconfig.POST_ACTION)
# Add addition clean files
Clean(target, 'cconfig.h')
@@ -745,6 +760,10 @@ def EndBuilding(target, program = None):
from ua import PrepareUA
PrepareUA(Projects, Rtt_Root, str(Dir('#')))
+ if GetOption('target') == 'vsc':
+ from vsc import GenerateVSCode
+ GenerateVSCode(Env)
+
BSP_ROOT = Dir('#').abspath
if GetOption('copy') and program != None:
from mkdist import MakeCopy
@@ -830,5 +849,3 @@ def PackageSConscript(package):
from package import BuildPackage
return BuildPackage(package)
-
-
diff --git a/tools/mkdist.py b/tools/mkdist.py
index 4a9f37035a..62dadc909a 100644
--- a/tools/mkdist.py
+++ b/tools/mkdist.py
@@ -66,14 +66,13 @@ def walk_kconfig(RTT_ROOT, source_list):
pathfile = os.path.join(parent, 'KConfig')
source_list.append(pathfile)
-
def MakeCopy(program, BSP_ROOT, RTT_ROOT, Env):
global source_list
target_path = os.path.join(BSP_ROOT, 'rt-thread')
if target_path.startswith(RTT_ROOT):
- print('please use scons --dist to make a distribution')
+ print('please use scons --copy to copy rt-thread to local bsp')
return
for item in program:
@@ -140,7 +139,7 @@ def MakeCopyHeader(program, BSP_ROOT, RTT_ROOT, Env):
target_path = os.path.join(BSP_ROOT, 'rt-thread')
if target_path.startswith(RTT_ROOT):
- print('please use scons --dist to make a distribution')
+ print('please use scons --copy-header to copy header files only')
return
for item in program:
@@ -186,7 +185,7 @@ def MkDist(program, BSP_ROOT, RTT_ROOT, Env):
# copy BSP files
do_copy_folder(os.path.join(BSP_ROOT), dist_dir,
- ignore_patterns('build', 'dist', '*.pyc', '*.old', '*.map', 'rtthread.bin', '.sconsign.dblite', '*.elf', '*.axf'))
+ ignore_patterns('build', 'dist', '*.pyc', '*.old', '*.map', 'rtthread.bin', '.sconsign.dblite', '*.elf', '*.axf', 'cconfig.h'))
global source_list
diff --git a/tools/utils.py b/tools/utils.py
index b0472b6f2e..fa501096a4 100644
--- a/tools/utils.py
+++ b/tools/utils.py
@@ -124,3 +124,119 @@ def walk_children(child):
if children != []:
for item in children:
walk_children(item)
+
+def PrefixPath(prefix, path):
+ path = os.path.abspath(path)
+ prefix = os.path.abspath(prefix)
+
+ if sys.platform == 'win32':
+ prefix = prefix.lower()
+ path = path.lower()
+
+ if path.startswith(prefix):
+ return True
+
+ return False
+
+def ListMap(l):
+ ret_list = []
+ for item in l:
+ if type(item) == type(()):
+ ret = ListMap(item)
+ ret_list += ret
+ elif type(item) == type([]):
+ ret = ListMap(item)
+ ret_list += ret
+ else:
+ ret_list.append(item)
+
+ return ret_list
+
+def TargetGetList(env, postfix):
+ global source_ext
+ global source_list
+
+ target = env['target']
+
+ source_ext = postfix
+ for item in target:
+ walk_children(item)
+
+ source_list.sort()
+
+ return source_list
+
+def ProjectInfo(env):
+
+ project = env['project']
+ RTT_ROOT = env['RTT_ROOT']
+ BSP_ROOT = env['BSP_ROOT']
+
+ FILES = []
+ DIRS = []
+ HEADERS = []
+ CPPPATH = []
+ CPPDEFINES = []
+
+ for group in project:
+ # get each files
+ if group.has_key('src') and group['src']:
+ FILES += group['src']
+
+ # get each include path
+ if group.has_key('CPPPATH') and group['CPPPATH']:
+ CPPPATH += group['CPPPATH']
+
+ if env.has_key('CPPDEFINES'):
+ CPPDEFINES = env['CPPDEFINES']
+ CPPDEFINES = ListMap(CPPDEFINES)
+
+ # process FILES and DIRS
+ if len(FILES):
+ # use absolute path
+ for i in range(len(FILES)):
+ FILES[i] = os.path.abspath(str(FILES[i]))
+ DIRS.append(os.path.dirname(FILES[i]))
+
+ FILES.sort()
+ DIRS = list(set(DIRS))
+ DIRS.sort()
+
+ # process HEADERS
+ HEADERS = TargetGetList(env, ['h'])
+
+ # process CPPPATH
+ if len(CPPPATH):
+ # use absolute path
+ for i in range(len(CPPPATH)):
+ CPPPATH[i] = os.path.abspath(CPPPATH[i])
+
+ # remove repeat path
+ paths = [i for i in set(CPPPATH)]
+ CPPPATH = []
+ for path in paths:
+ if PrefixPath(RTT_ROOT, path):
+ CPPPATH += [os.path.abspath(path).replace('\\', '/')]
+
+ elif PrefixPath(BSP_ROOT, path):
+ CPPPATH += [os.path.abspath(path).replace('\\', '/')]
+
+ else:
+ CPPPATH += ['"%s",' % path.replace('\\', '/')]
+
+ CPPPATH.sort()
+
+ # process CPPDEFINES
+ if len(CPPDEFINES):
+ CPPDEFINES = [i for i in set(CPPDEFINES)]
+
+ CPPDEFINES.sort()
+
+ proj = {}
+ proj['FILES'] = FILES
+ proj['DIRS'] = DIRS
+ proj['HEADERS'] = HEADERS
+ proj['CPPPATH'] = CPPPATH
+ proj['CPPDEFINES'] = CPPDEFINES
+
+ return proj
diff --git a/tools/vsc.py b/tools/vsc.py
new file mode 100644
index 0000000000..b5ca0d583b
--- /dev/null
+++ b/tools/vsc.py
@@ -0,0 +1,46 @@
+"""
+Utils for VSCode
+"""
+
+import os
+import json
+import utils
+import rtconfig
+
+def GenerateCFiles(env):
+ """
+ Generate c_cpp_properties files
+ """
+ if not os.path.exists('.vscode'):
+ os.mkdir('.vscode')
+
+ vsc_file = file('.vscode/c_cpp_properties.json', 'wb')
+ if vsc_file:
+ info = utils.ProjectInfo(env)
+
+ cc = os.path.join(rtconfig.EXEC_PATH, rtconfig.CC)
+ cc = os.path.abspath(cc).replace('\\', '/')
+
+ config_obj = {}
+ config_obj['name'] = 'Win32'
+ config_obj['includePath'] = info['CPPPATH']
+ config_obj['defines'] = info['CPPDEFINES']
+ config_obj['intelliSenseMode'] = 'clang-x64'
+ config_obj['compilerPath'] = cc
+ config_obj['cStandard'] = "c99"
+ config_obj['cppStandard'] = "c++11"
+
+ json_obj = {}
+ json_obj['configurations'] = [config_obj]
+
+ vsc_file.write(json.dumps(json_obj))
+ vsc_file.close()
+
+ return
+
+def GenerateVSCode(env):
+ print('Update setting files for VSCode...'),
+ GenerateCFiles(env)
+ print('Done!')
+
+ return