[Tools] Add target=vsc in building script.
This commit is contained in:
parent
fe691c2ab3
commit
fd0ae67289
|
@ -123,6 +123,11 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
|
||||||
|
|
||||||
Env = env
|
Env = env
|
||||||
Rtt_Root = os.path.abspath(root_directory)
|
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')]
|
sys.path = sys.path + [os.path.join(Rtt_Root, 'tools')]
|
||||||
|
|
||||||
# add compability with Keil MDK 4.6 which changes the directory of armcc.exe
|
# 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',
|
AddOption('--target',
|
||||||
dest='target',
|
dest='target',
|
||||||
type='string',
|
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)}
|
#{target_name:(CROSS_TOOL, PLATFORM)}
|
||||||
tgt_dict = {'mdk':('keil', 'armcc'),
|
tgt_dict = {'mdk':('keil', 'armcc'),
|
||||||
|
@ -268,6 +273,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
|
||||||
'iar':('iar', 'iar'),
|
'iar':('iar', 'iar'),
|
||||||
'vs':('msvc', 'cl'),
|
'vs':('msvc', 'cl'),
|
||||||
'vs2012':('msvc', 'cl'),
|
'vs2012':('msvc', 'cl'),
|
||||||
|
'vsc' : ('gcc', 'gcc'),
|
||||||
'cb':('keil', 'armcc'),
|
'cb':('keil', 'armcc'),
|
||||||
'ua':('gcc', 'gcc')}
|
'ua':('gcc', 'gcc')}
|
||||||
tgt_name = GetOption('target')
|
tgt_name = GetOption('target')
|
||||||
|
@ -320,6 +326,12 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
|
||||||
mk_rtconfig(configfn)
|
mk_rtconfig(configfn)
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
AddOption('--test',
|
||||||
|
dest='test',
|
||||||
|
action='store_true',
|
||||||
|
default=False,
|
||||||
|
help='some test feature')
|
||||||
|
|
||||||
# add comstr option
|
# add comstr option
|
||||||
AddOption('--verbose',
|
AddOption('--verbose',
|
||||||
dest='verbose',
|
dest='verbose',
|
||||||
|
@ -531,7 +543,7 @@ def DefineGroup(name, src, depend, **parameters):
|
||||||
group = parameters
|
group = parameters
|
||||||
group['name'] = name
|
group['name'] = name
|
||||||
group['path'] = group_path
|
group['path'] = group_path
|
||||||
if type(src) == type(['src1']):
|
if type(src) == type([]):
|
||||||
group['src'] = File(src)
|
group['src'] = File(src)
|
||||||
else:
|
else:
|
||||||
group['src'] = src
|
group['src'] = src
|
||||||
|
@ -692,6 +704,9 @@ def DoBuilding(target, objects):
|
||||||
def EndBuilding(target, program = None):
|
def EndBuilding(target, program = None):
|
||||||
import rtconfig
|
import rtconfig
|
||||||
|
|
||||||
|
Env['target'] = program
|
||||||
|
Env['project'] = Projects
|
||||||
|
|
||||||
Env.AddPostAction(target, rtconfig.POST_ACTION)
|
Env.AddPostAction(target, rtconfig.POST_ACTION)
|
||||||
# Add addition clean files
|
# Add addition clean files
|
||||||
Clean(target, 'cconfig.h')
|
Clean(target, 'cconfig.h')
|
||||||
|
@ -745,6 +760,10 @@ def EndBuilding(target, program = None):
|
||||||
from ua import PrepareUA
|
from ua import PrepareUA
|
||||||
PrepareUA(Projects, Rtt_Root, str(Dir('#')))
|
PrepareUA(Projects, Rtt_Root, str(Dir('#')))
|
||||||
|
|
||||||
|
if GetOption('target') == 'vsc':
|
||||||
|
from vsc import GenerateVSCode
|
||||||
|
GenerateVSCode(Env)
|
||||||
|
|
||||||
BSP_ROOT = Dir('#').abspath
|
BSP_ROOT = Dir('#').abspath
|
||||||
if GetOption('copy') and program != None:
|
if GetOption('copy') and program != None:
|
||||||
from mkdist import MakeCopy
|
from mkdist import MakeCopy
|
||||||
|
@ -830,5 +849,3 @@ def PackageSConscript(package):
|
||||||
from package import BuildPackage
|
from package import BuildPackage
|
||||||
|
|
||||||
return BuildPackage(package)
|
return BuildPackage(package)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -66,14 +66,13 @@ def walk_kconfig(RTT_ROOT, source_list):
|
||||||
pathfile = os.path.join(parent, 'KConfig')
|
pathfile = os.path.join(parent, 'KConfig')
|
||||||
source_list.append(pathfile)
|
source_list.append(pathfile)
|
||||||
|
|
||||||
|
|
||||||
def MakeCopy(program, BSP_ROOT, RTT_ROOT, Env):
|
def MakeCopy(program, BSP_ROOT, RTT_ROOT, Env):
|
||||||
global source_list
|
global source_list
|
||||||
|
|
||||||
target_path = os.path.join(BSP_ROOT, 'rt-thread')
|
target_path = os.path.join(BSP_ROOT, 'rt-thread')
|
||||||
|
|
||||||
if target_path.startswith(RTT_ROOT):
|
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
|
return
|
||||||
|
|
||||||
for item in program:
|
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')
|
target_path = os.path.join(BSP_ROOT, 'rt-thread')
|
||||||
|
|
||||||
if target_path.startswith(RTT_ROOT):
|
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
|
return
|
||||||
|
|
||||||
for item in program:
|
for item in program:
|
||||||
|
@ -186,7 +185,7 @@ def MkDist(program, BSP_ROOT, RTT_ROOT, Env):
|
||||||
|
|
||||||
# copy BSP files
|
# copy BSP files
|
||||||
do_copy_folder(os.path.join(BSP_ROOT), dist_dir,
|
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
|
global source_list
|
||||||
|
|
||||||
|
|
116
tools/utils.py
116
tools/utils.py
|
@ -124,3 +124,119 @@ def walk_children(child):
|
||||||
if children != []:
|
if children != []:
|
||||||
for item in children:
|
for item in children:
|
||||||
walk_children(item)
|
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
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue