# SEGGER Embedded Studio Project Generatorimport osimport sysimport xml.etree.ElementTree as etreefrom xml.etree.ElementTree import SubElementfrom utils import _make_path_relativefrom utils import xml_indentfrom utils import ProjectInfodef SDKAddGroup(parent, name, files, project_path):# don't add an empty groupif len(files) == 0:returngroup = SubElement(parent, 'folder', attrib={'Name': name})for f in files:fn = f.rfile()name = fn.namepath = 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={'file_name': elm_attr_name})return groupdef SESProject(env) :target = 'project.emProject'tree = etree.parse('template.emProject')# print(etree.dump(tree.getroot()))# etree.dump(tree.getroot())project = ProjectInfo(env)# print(project)# returnproject_path = os.path.abspath(env['BSP_ROOT'])script = env['project']root = tree.getroot()out = file(target, 'w')out.write('<!DOCTYPE CrossStudio_Project_File>\n')CPPPATH = []CPPDEFINES = []LINKFLAGS = ''CCFLAGS = ''project_node = tree.find('project')for group in script:# print(group)group_tree = SDKAddGroup(project_node, group['name'], group['src'], project_path)# get each group's cc flagsif group.has_key('CCFLAGS') and group['CCFLAGS']:if CCFLAGS:CCFLAGS += ' ' + group['CCFLAGS']else:CCFLAGS += group['CCFLAGS']# get each group's link flagsif group.has_key('LINKFLAGS') and group['LINKFLAGS']:if LINKFLAGS:LINKFLAGS += ' ' + group['LINKFLAGS']else:LINKFLAGS += group['LINKFLAGS']# write include path, definitions and link flagspath = ';'.join([_make_path_relative(project_path, os.path.normpath(i)) for i in project['CPPPATH']])path = path.replace('\\', '/')defines = ';'.join(set(project['CPPDEFINES']))node = tree.findall('project/configuration')for item in node:if item.get('c_preprocessor_definitions'):item.set('c_preprocessor_definitions', defines)if item.get('c_user_include_directories'):item.set('c_user_include_directories', path)xml_indent(root)out.write(etree.tostring(root, encoding='utf-8'))out.close()return
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。