Skip to content

[tools][keil] 支持keil工程多个配置 #8557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 110 additions & 92 deletions tools/keil.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,98 +215,116 @@ def MDK45Project(tree, target, script):
root = tree.getroot()
out = open(target, 'w')
out.write('<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n')

CPPPATH = []
CPPDEFINES = []
LINKFLAGS = ''
CXXFLAGS = ''
CCFLAGS = ''
CFLAGS = ''
ProjectFiles = []

# add group
groups = tree.find('Targets/Target/Groups')
if groups is None:
groups = SubElement(tree.find('Targets/Target'), 'Groups')
groups.clear() # clean old groups
for group in script:
group_tree = MDK4AddGroup(ProjectFiles, groups, group['name'], group['src'], project_path, group)

# get each include path
if 'CPPPATH' in group and group['CPPPATH']:
if CPPPATH:
CPPPATH += group['CPPPATH']
else:
CPPPATH += group['CPPPATH']

# get each group's definitions
if 'CPPDEFINES' in group and group['CPPDEFINES']:
if CPPDEFINES:
CPPDEFINES += group['CPPDEFINES']
else:
CPPDEFINES = group['CPPDEFINES']

# get each group's link flags
if 'LINKFLAGS' in group and group['LINKFLAGS']:
if LINKFLAGS:
LINKFLAGS += ' ' + group['LINKFLAGS']
else:
LINKFLAGS += group['LINKFLAGS']

# get each group's CXXFLAGS flags
if 'CXXFLAGS' in group and group['CXXFLAGS']:
if CXXFLAGS:
CXXFLAGS += ' ' + group['CXXFLAGS']
else:
CXXFLAGS += group['CXXFLAGS']

# get each group's CCFLAGS flags
if 'CCFLAGS' in group and group['CCFLAGS']:
if CCFLAGS:
CCFLAGS += ' ' + group['CCFLAGS']
else:
CCFLAGS += group['CCFLAGS']

# get each group's CFLAGS flags
if 'CFLAGS' in group and group['CFLAGS']:
if CFLAGS:
CFLAGS += ' ' + group['CFLAGS']
else:
CFLAGS += group['CFLAGS']

# get each group's LIBS flags
if 'LIBS' in group and group['LIBS']:
for item in group['LIBS']:
lib_path = ''
for path_item in group['LIBPATH']:
full_path = os.path.join(path_item, item + '.lib')
if os.path.isfile(full_path): # has this library
lib_path = full_path
break

if lib_path != '':
if group_tree != None:
MDK4AddLibToGroup(ProjectFiles, group_tree, group['name'], lib_path, project_path)
else:
group_tree = MDK4AddGroupForFN(ProjectFiles, groups, group['name'], lib_path, project_path)

# write include path, definitions and link flags
IncludePath = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/IncludePath')
IncludePath.text = ';'.join([_make_path_relative(project_path, os.path.normpath(i)) for i in set(CPPPATH)])

Define = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/Define')
Define.text = ', '.join(set(CPPDEFINES))

if 'c99' in CXXFLAGS or 'c99' in CCFLAGS or 'c99' in CFLAGS:
uC99 = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/uC99')
uC99.text = '1'

if 'gnu' in CXXFLAGS or 'gnu' in CCFLAGS or 'gnu' in CFLAGS:
uGnu = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/uGnu')
uGnu.text = '1'

Misc = tree.find('Targets/Target/TargetOption/TargetArmAds/LDads/Misc')
Misc.text = LINKFLAGS

#Addtion the name of OutputDir
for targcomoOp in root.findall('.//TargetCommonOption'):
OutputDir = targcomoOp.find('OutputDirectory')
OutputName = targcomoOp.find('OutputName')
#print(OutputDir.text)
#print(OutputName.text)
OutputDir.text += OutputName.text + '\\'
#print(OutputDir.text)

for child in root.findall('.//Target'):
CPPPATH = []
CPPDEFINES = []
LINKFLAGS = ''
CXXFLAGS = ''
CCFLAGS = ''
CFLAGS = ''
ProjectFiles = []
groups = child.find('Groups')
if groups is None:
groups = SubElement(child,'Groups')
groups.clear() # clean old groups

# add group
#groups = tree.find('Targets/Target/Groups')
#if groups is None:
#groups = SubElement(tree.find('Targets/Target'), 'Groups')
#groups.clear() # clean old groups
for group in script:
group_tree = MDK4AddGroup(ProjectFiles, groups, group['name'], group['src'], project_path, group)
# get each include path
if 'CPPPATH' in group and group['CPPPATH']:
if CPPPATH:
CPPPATH += group['CPPPATH']
else:
CPPPATH += group['CPPPATH']

# get each group's definitions
if 'CPPDEFINES' in group and group['CPPDEFINES']:
if CPPDEFINES:
CPPDEFINES += group['CPPDEFINES']
else:
CPPDEFINES = group['CPPDEFINES']

# get each group's link flags
if 'LINKFLAGS' in group and group['LINKFLAGS']:
if LINKFLAGS:
LINKFLAGS += ' ' + group['LINKFLAGS']
else:
LINKFLAGS += group['LINKFLAGS']

# get each group's CXXFLAGS flags
if 'CXXFLAGS' in group and group['CXXFLAGS']:
if CXXFLAGS:
CXXFLAGS += ' ' + group['CXXFLAGS']
else:
CXXFLAGS += group['CXXFLAGS']

# get each group's CCFLAGS flags
if 'CCFLAGS' in group and group['CCFLAGS']:
if CCFLAGS:
CCFLAGS += ' ' + group['CCFLAGS']
else:
CCFLAGS += group['CCFLAGS']

# get each group's CFLAGS flags
if 'CFLAGS' in group and group['CFLAGS']:
if CFLAGS:
CFLAGS += ' ' + group['CFLAGS']
else:
CFLAGS += group['CFLAGS']

# get each group's LIBS flags
if 'LIBS' in group and group['LIBS']:
for item in group['LIBS']:
lib_path = ''
for path_item in group['LIBPATH']:
full_path = os.path.join(path_item, item + '.lib')
if os.path.isfile(full_path): # has this library
lib_path = full_path
break

if lib_path != '':
if group_tree != None:
MDK4AddLibToGroup(ProjectFiles, group_tree, group['name'], lib_path, project_path)
else:
group_tree = MDK4AddGroupForFN(ProjectFiles, groups, group['name'], lib_path, project_path)
# write include path, definitions and link flags
IncludePath = child.find('TargetOption/TargetArmAds/Cads/VariousControls/IncludePath')
if(IncludePath.text != None):
IncludePath.text = IncludePath.text +';' + ';'.join([_make_path_relative(project_path, os.path.normpath(i)) for i in set(CPPPATH)])
else:
IncludePath.text = ';'.join([_make_path_relative(project_path, os.path.normpath(i)) for i in set(CPPPATH)])

Define = child.find('TargetOption/TargetArmAds/Cads/VariousControls/Define')
if(Define.text != None):
Define.text = Define.text +',' + ', '.join(set(CPPDEFINES))
else:
Define.text = ','.join(set(CPPDEFINES))

if 'c99' in CXXFLAGS or 'c99' in CCFLAGS or 'c99' in CFLAGS:
uC99 = child.find('TargetOption/TargetArmAds/Cads/uC99')
uC99.text = '1'

if 'gnu' in CXXFLAGS or 'gnu' in CCFLAGS or 'gnu' in CFLAGS:
uGnu = child.find('TargetOption/TargetArmAds/Cads/uGnu')
uGnu.text = '1'

Misc = child.find('TargetOption/TargetArmAds/LDads/Misc')
Misc.text = LINKFLAGS

xml_indent(root)
out.write(etree.tostring(root, encoding='utf-8').decode())
Expand Down