[Tools] merge v2.1.0 LOCAL_CPPPATH feature to v2.0.x branch

This commit is contained in:
Bernard Xiong 2015-09-17 17:48:36 +08:00
parent 540d6ebf54
commit 8c3781ade9
1 changed files with 80 additions and 9 deletions

View File

@ -20,6 +20,8 @@
# Change Logs:
# Date Author Notes
# 2015-01-20 Bernard Add copyright information
# 2015-07-25 Bernard Add LOCAL_CCFLAGS/LOCAL_CPPPATH/LOCAL_CPPDEFINES for
# group definition.
#
import os
@ -112,6 +114,8 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
# add program path
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
# add rtconfig.h path
env.Append(CPPPATH = [str(Dir('#').abspath)])
# add library build action
act = SCons.Action.Action(BuildLibInstallAction, 'Install compiled library... $TARGET')
@ -186,7 +190,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
AddOption('--target',
dest='target',
type='string',
help='set target project: mdk/iar/vs/ua')
help='set target project: mdk/mdk4/iar/vs/ua')
#{target_name:(CROSS_TOOL, PLATFORM)}
tgt_dict = {'mdk':('keil', 'armcc'),
@ -196,7 +200,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
'vs':('msvc', 'cl'),
'vs2012':('msvc', 'cl'),
'cb':('keil', 'armcc'),
'ua':('keil', 'armcc')}
'ua':('gcc', 'gcc')}
tgt_name = GetOption('target')
if tgt_name:
# --target will change the toolchain settings which clang-analyzer is
@ -256,15 +260,24 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
return objs
def PrepareModuleBuilding(env, root_directory):
def PrepareModuleBuilding(env, root_directory, bsp_directory):
import rtconfig
global BuildOptions
global Env
global Rtt_Root
Env = env
Rtt_Root = root_directory
# parse bsp rtconfig.h to get used component
PreProcessor = SCons.cpp.PreProcessor()
f = file(bsp_directory + '/rtconfig.h', 'r')
contents = f.read()
f.close()
PreProcessor.process_contents(contents)
BuildOptions = PreProcessor.cpp_namespace
# add build/clean library option for library checking
AddOption('--buildlib',
dest='buildlib',
@ -324,6 +337,24 @@ def MergeGroup(src_group, group):
src_group['CPPDEFINES'] = src_group['CPPDEFINES'] + group['CPPDEFINES']
else:
src_group['CPPDEFINES'] = group['CPPDEFINES']
# for local CCFLAGS/CPPPATH/CPPDEFINES
if group.has_key('LOCAL_CCFLAGS'):
if src_group.has_key('LOCAL_CCFLAGS'):
src_group['LOCAL_CCFLAGS'] = src_group['LOCAL_CCFLAGS'] + group['LOCAL_CCFLAGS']
else:
src_group['LOCAL_CCFLAGS'] = group['LOCAL_CCFLAGS']
if group.has_key('LOCAL_CPPPATH'):
if src_group.has_key('LOCAL_CPPPATH'):
src_group['LOCAL_CPPPATH'] = src_group['LOCAL_CPPPATH'] + group['LOCAL_CPPPATH']
else:
src_group['LOCAL_CPPPATH'] = group['LOCAL_CPPPATH']
if group.has_key('LOCAL_CPPDEFINES'):
if src_group.has_key('LOCAL_CPPDEFINES'):
src_group['LOCAL_CPPDEFINES'] = src_group['LOCAL_CPPDEFINES'] + group['LOCAL_CPPDEFINES']
else:
src_group['LOCAL_CPPDEFINES'] = group['LOCAL_CPPDEFINES']
if group.has_key('LINKFLAGS'):
if src_group.has_key('LINKFLAGS'):
src_group['LINKFLAGS'] = src_group['LINKFLAGS'] + group['LINKFLAGS']
@ -362,13 +393,13 @@ def DefineGroup(name, src, depend, **parameters):
group['src'] = src
if group.has_key('CCFLAGS'):
Env.Append(CCFLAGS = group['CCFLAGS'])
Env.AppendUnique(CCFLAGS = group['CCFLAGS'])
if group.has_key('CPPPATH'):
Env.Append(CPPPATH = group['CPPPATH'])
Env.AppendUnique(CPPPATH = group['CPPPATH'])
if group.has_key('CPPDEFINES'):
Env.Append(CPPDEFINES = group['CPPDEFINES'])
Env.AppendUnique(CPPDEFINES = group['CPPDEFINES'])
if group.has_key('LINKFLAGS'):
Env.Append(LINKFLAGS = group['LINKFLAGS'])
Env.AppendUnique(LINKFLAGS = group['LINKFLAGS'])
# check whether to clean up library
if GetOption('cleanlib') and os.path.exists(os.path.join(group['path'], GroupLibFullName(name, Env))):
@ -385,13 +416,15 @@ def DefineGroup(name, src, depend, **parameters):
else : group['LIBPATH'] = [GetCurrentDir()]
if group.has_key('LIBS'):
Env.Append(LIBS = group['LIBS'])
Env.AppendUnique(LIBS = group['LIBS'])
if group.has_key('LIBPATH'):
Env.Append(LIBPATH = group['LIBPATH'])
Env.AppendUnique(LIBPATH = group['LIBPATH'])
# check whether to build group library
if group.has_key('LIBRARY'):
objs = Env.Library(name, group['src'])
else:
# only add source
objs = group['src']
# merge group
@ -447,6 +480,39 @@ def BuildLibInstallAction(target, source, env):
break
def DoBuilding(target, objects):
# merge all objects into one list
def one_list(l):
lst = []
for item in l:
if type(item) == type([]):
lst += one_list(item)
else:
lst.append(item)
return lst
objects = one_list(objects)
# remove source files with local flags setting
for group in Projects:
if group.has_key('LOCAL_CCFLAGS') or group.has_key('LOCAL_CPPPATH') or group.has_key('LOCAL_CPPDEFINES'):
for source in group['src']:
for obj in objects:
if source.abspath == obj.abspath or (len(obj.sources) > 0 and source.abspath == obj.sources[0].abspath):
objects.remove(obj)
# re-add the source files to the objects
for group in Projects:
if group.has_key('LOCAL_CCFLAGS') or group.has_key('LOCAL_CPPPATH') or group.has_key('LOCAL_CPPDEFINES'):
CCFLAGS = Env.get('CCFLAGS', '') + group.get('LOCAL_CCFLAGS', '')
CPPPATH = Env.get('CPPPATH', ['']) + group.get('LOCAL_CPPPATH', [''])
CPPDEFINES = Env.get('CPPDEFINES', ['']) + group.get('LOCAL_CPPDEFINES', [''])
for source in group['src']:
objects += Env.Object(source, CCFLAGS = CCFLAGS,
CPPPATH = CPPPATH,
CPPDEFINES = CPPDEFINES)
program = None
# check whether special buildlib option
lib_name = GetOption('buildlib')
@ -586,6 +652,11 @@ def GlobSubDir(sub_dir, ext_name):
dst.append(os.path.relpath(item, sub_dir))
return dst
def PackageSConscript(package):
from package import BuildPackage
return BuildPackage(package)
def file_path_exist(path, *args):
return os.path.exists(os.path.join(path, *args))