From 4e937887f6cfe67275d87a7b9d102520bcc1a9b0 Mon Sep 17 00:00:00 2001 From: liang yongxiang Date: Tue, 5 Jun 2018 14:23:05 +0800 Subject: [PATCH] [tools] add target=cdk in building script --- tools/building.py | 10 +++- tools/cdk.py | 128 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 tools/cdk.py diff --git a/tools/building.py b/tools/building.py index 4f75811e11..6c4587b37e 100644 --- a/tools/building.py +++ b/tools/building.py @@ -264,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/mdk5/iar/vs/vsc/ua') + help='set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua/cdk') #{target_name:(CROSS_TOOL, PLATFORM)} tgt_dict = {'mdk':('keil', 'armcc'), @@ -275,8 +275,10 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ 'vs2012':('msvc', 'cl'), 'vsc' : ('gcc', 'gcc'), 'cb':('keil', 'armcc'), - 'ua':('gcc', 'gcc')} + 'ua':('gcc', 'gcc'), + 'cdk':('gcc', 'gcc')} tgt_name = GetOption('target') + if tgt_name: # --target will change the toolchain settings which clang-analyzer is # depend on @@ -770,6 +772,10 @@ def EndBuilding(target, program = None): if GetOption('target') == 'vsc': from vsc import GenerateVSCode GenerateVSCode(Env) + + if GetOption('target') == 'cdk': + from cdk import CDKProject + CDKProject('project.cdkproj', Projects) BSP_ROOT = Dir('#').abspath if GetOption('copy') and program != None: diff --git a/tools/cdk.py b/tools/cdk.py new file mode 100644 index 0000000000..8f995981aa --- /dev/null +++ b/tools/cdk.py @@ -0,0 +1,128 @@ +# +# File : keil.py +# This file is part of RT-Thread RTOS +# COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Change Logs: +# Date Author Notes +# 2017-10-16 Tanek Add CDK IDE support +# + +import os +import sys +import string + +import xml.etree.ElementTree as etree +from xml.etree.ElementTree import SubElement +from utils import _make_path_relative +from utils import xml_indent + +def SDKAddGroup(ProjectFiles, parent, name, files, project_path): + # don't add an empty group + if len(files) == 0: + return + + group = SubElement(parent, 'VirtualDirectory', attrib={'Name': name}) + + for f in files: + fn = f.rfile() + name = fn.name + path = os.path.dirname(fn.abspath) + + basename = os.path.basename(path) + path = _make_path_relative(project_path, path) + elm_attr_name = os.path.join(path, name) + + file = SubElement(group, 'File', attrib={'Name': elm_attr_name}) + + return group + +def _CDKProject(tree, target, script): + + project_path = os.path.dirname(os.path.abspath(target)) + + root = tree.getroot() + out = file(target, 'wb') + out.write('\n') + + CPPPATH = [] + CPPDEFINES = [] + LINKFLAGS = '' + CCFLAGS = '' + ProjectFiles = [] + + for child in root: + if child.tag == 'VirtualDirectory': + root.remove(child) + + for group in script: + group_tree = SDKAddGroup(ProjectFiles, root, group['name'], group['src'], project_path) + + # get each include path + if group.has_key('CPPPATH') and group['CPPPATH']: + if CPPPATH: + CPPPATH += group['CPPPATH'] + else: + CPPPATH += group['CPPPATH'] + + # get each group's definitions + if group.has_key('CPPDEFINES') and group['CPPDEFINES']: + if CPPDEFINES: + CPPDEFINES += group['CPPDEFINES'] + else: + CPPDEFINES += group['CPPDEFINES'] + + # get each group's cc flags + if group.has_key('CCFLAGS') and group['CCFLAGS']: + if CCFLAGS: + CCFLAGS += ' ' + group['CCFLAGS'] + else: + CCFLAGS += group['CCFLAGS'] + + # get each group's link flags + if group.has_key('LINKFLAGS') and group['LINKFLAGS']: + if LINKFLAGS: + LINKFLAGS += ' ' + group['LINKFLAGS'] + else: + LINKFLAGS += group['LINKFLAGS'] + + # todo: cdk add lib + + # write include path, definitions and link flags + text = ';'.join([_make_path_relative(project_path, os.path.normpath(i)) for i in CPPPATH]) + IncludePath = tree.find('BuildConfigs/BuildConfig/Compiler/IncludePath') + IncludePath.text = text + IncludePath = tree.find('BuildConfigs/BuildConfig/Asm/IncludePath') + IncludePath.text = text + + Define = tree.find('BuildConfigs/BuildConfig/Compiler/Define') + Define.text = ', '.join(set(CPPDEFINES)) + + CC_Misc = tree.find('BuildConfigs/BuildConfig/Compiler/OtherFlags') + CC_Misc.text = CCFLAGS + + LK_Misc = tree.find('BuildConfigs/BuildConfig/Linker/OtherFlags') + LK_Misc.text = LINKFLAGS + + xml_indent(root) + out.write(etree.tostring(root, encoding='utf-8')) + out.close() + +def CDKProject(target, script): + template_tree = etree.parse('template.cdkproj') + + _CDKProject(template_tree, target, script)