Add UA building script.

This commit is contained in:
bernard 2014-03-24 14:50:47 +08:00
parent 04b5a46179
commit 6289a1aa25
2 changed files with 93 additions and 11 deletions

View File

@ -145,7 +145,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/iar/vs') help='set target project: mdk/iar/vs/ua')
#{target_name:(CROSS_TOOL, PLATFORM)} #{target_name:(CROSS_TOOL, PLATFORM)}
tgt_dict = {'mdk':('keil', 'armcc'), tgt_dict = {'mdk':('keil', 'armcc'),
@ -153,7 +153,8 @@ 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'),
'cb':('keil', 'armcc')} 'cb':('keil', 'armcc'),
'ua':('keil', 'armcc')}
tgt_name = GetOption('target') tgt_name = GetOption('target')
if tgt_name: if tgt_name:
# --target will change the toolchain settings which clang-analyzer is # --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 return objs
def PrepareModuleBuilding(env, root_directory): def PrepareModuleBuilding(env, root_directory):
import SCons.cpp
import rtconfig import rtconfig
global BuildOptions
global Projects
global Env global Env
global Rtt_Root global Rtt_Root
Env = env Env = env
Rtt_Root = root_directory 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 # add program path
env.PrependENVPath('PATH', rtconfig.EXEC_PATH) env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
@ -418,16 +427,13 @@ def DoBuilding(target, objects):
def EndBuilding(target, program = None): def EndBuilding(target, program = None):
import rtconfig 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) Env.AddPostAction(target, rtconfig.POST_ACTION)
if GetOption('target') == 'mdk': if GetOption('target') == 'mdk':
from keil import MDKProject
from keil import MDK4Project
template = os.path.isfile('template.Uv2') template = os.path.isfile('template.Uv2')
if template: if template:
MDKProject('project.Uv2', Projects) MDKProject('project.Uv2', Projects)
@ -439,20 +445,30 @@ def EndBuilding(target, program = None):
print 'No template project file found.' print 'No template project file found.'
if GetOption('target') == 'mdk4': if GetOption('target') == 'mdk4':
from keil import MDKProject
from keil import MDK4Project
MDK4Project('project.uvproj', Projects) MDK4Project('project.uvproj', Projects)
if GetOption('target') == 'iar': if GetOption('target') == 'iar':
from iar import IARProject
IARProject('project.ewp', Projects) IARProject('project.ewp', Projects)
if GetOption('target') == 'vs': if GetOption('target') == 'vs':
from vs import VSProject
VSProject('project.vcproj', Projects, program) VSProject('project.vcproj', Projects, program)
if GetOption('target') == 'vs2012': if GetOption('target') == 'vs2012':
from vs2012 import VS2012Project
VS2012Project('project.vcxproj', Projects, program) VS2012Project('project.vcxproj', Projects, program)
if GetOption('target') == 'cb': if GetOption('target') == 'cb':
from codeblocks import CBProject
CBProject('project.cbp', Projects, program) 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: if GetOption('copy') and program != None:
MakeCopy(program) MakeCopy(program)
if GetOption('copy-header') and program != None: if GetOption('copy-header') and program != None:

66
tools/ua.py Normal file
View File

@ -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