From 6289a1aa25ebe292cad744fa614ef85438842bc1 Mon Sep 17 00:00:00 2001 From: bernard Date: Mon, 24 Mar 2014 14:50:47 +0800 Subject: [PATCH] Add UA building script. --- tools/building.py | 38 +++++++++++++++++++-------- tools/ua.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 11 deletions(-) create mode 100644 tools/ua.py diff --git a/tools/building.py b/tools/building.py index 6427e7c0dd..54193fcf2f 100644 --- a/tools/building.py +++ b/tools/building.py @@ -145,7 +145,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ AddOption('--target', dest='target', type='string', - help='set target project: mdk/iar/vs') + help='set target project: mdk/iar/vs/ua') #{target_name:(CROSS_TOOL, PLATFORM)} tgt_dict = {'mdk':('keil', 'armcc'), @@ -153,7 +153,8 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ 'iar':('iar', 'iar'), 'vs':('msvc', 'cl'), 'vs2012':('msvc', 'cl'), - 'cb':('keil', 'armcc')} + 'cb':('keil', 'armcc'), + 'ua':('keil', 'armcc')} tgt_name = GetOption('target') if tgt_name: # --target will change the toolchain settings which clang-analyzer is @@ -209,17 +210,25 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ return objs def PrepareModuleBuilding(env, root_directory): - import SCons.cpp import rtconfig - global BuildOptions - global Projects global Env global Rtt_Root Env = env Rtt_Root = root_directory + # add build/clean library option for library checking + AddOption('--buildlib', + dest='buildlib', + type='string', + help='building library of a component') + AddOption('--cleanlib', + dest='cleanlib', + action='store_true', + default=False, + help='clean up the library by --buildlib') + # add program path env.PrependENVPath('PATH', rtconfig.EXEC_PATH) @@ -418,16 +427,13 @@ def DoBuilding(target, objects): def EndBuilding(target, program = None): import rtconfig - from keil import MDKProject - from keil import MDK4Project - from iar import IARProject - from vs import VSProject - from vs2012 import VS2012Project - from codeblocks import CBProject Env.AddPostAction(target, rtconfig.POST_ACTION) if GetOption('target') == 'mdk': + from keil import MDKProject + from keil import MDK4Project + template = os.path.isfile('template.Uv2') if template: MDKProject('project.Uv2', Projects) @@ -439,20 +445,30 @@ def EndBuilding(target, program = None): print 'No template project file found.' if GetOption('target') == 'mdk4': + from keil import MDKProject + from keil import MDK4Project MDK4Project('project.uvproj', Projects) if GetOption('target') == 'iar': + from iar import IARProject IARProject('project.ewp', Projects) if GetOption('target') == 'vs': + from vs import VSProject VSProject('project.vcproj', Projects, program) if GetOption('target') == 'vs2012': + from vs2012 import VS2012Project VS2012Project('project.vcxproj', Projects, program) if GetOption('target') == 'cb': + from codeblocks import CBProject CBProject('project.cbp', Projects, program) + if GetOption('target') == 'ua': + from ua import PrepareUA + PrepareUA(Projects, Rtt_Root, str(Dir('#'))) + if GetOption('copy') and program != None: MakeCopy(program) if GetOption('copy-header') and program != None: diff --git a/tools/ua.py b/tools/ua.py new file mode 100644 index 0000000000..89d3190e23 --- /dev/null +++ b/tools/ua.py @@ -0,0 +1,66 @@ +import os +import sys +from utils import _make_path_relative + +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 PrepareUA(project, RTT_ROOT, BSP_ROOT): + with open('rtua.py', 'w') as ua: + # ua.write('import os\n') + # ua.write('import sys\n') + ua.write('\n') + + print RTT_ROOT + + CPPPATH = [] + CPPDEFINES = [] + + for group in project: + # get each include path + if group.has_key('CPPPATH') and group['CPPPATH']: + CPPPATH += group['CPPPATH'] + + # get each group's definitions + if group.has_key('CPPDEFINES') and group['CPPDEFINES']: + CPPDEFINES += group['CPPDEFINES'] + + if len(CPPPATH): + # remove repeat path + paths = [i for i in set(CPPPATH)] + CPPPATH = [] + for path in paths: + if PrefixPath(RTT_ROOT, path): + CPPPATH += ['RTT_ROOT + "/%s",' % _make_path_relative(RTT_ROOT, path).replace('\\', '/')] + + elif PrefixPath(BSP_ROOT, path): + CPPPATH += ['BSP_ROOT + "/%s",' % _make_path_relative(RTT_ROOT, path).replace('\\', '/')] + else: + CPPPATH += ['"%s",' % path.replace('\\', '/')] + + CPPPATH.sort() + ua.write('def GetCPPPATH(BSP_ROOT, RTT_ROOT):\n') + ua.write('\tCPPPATH=[\n') + for path in CPPPATH: + ua.write('\t\t%s\n' % path) + ua.write('\t]\n\n') + ua.write('\treturn CPPPATH\n\n') + + if len(CPPDEFINES): + CPPDEFINES = [i for i in set(CPPDEFINES)] + + ua.write('def GetCPPDEFINES():\n') + ua.write('\tCPPDEFINES=%s\n' % str(CPPDEFINES)) + ua.write('\treturn CPPDEFINES\n\n') + + print CPPDEFINES