Skip to content

Commit

Permalink
change auto selete current configuration of IAR project
Browse files Browse the repository at this point in the history
  • Loading branch information
tianxiaoMCU committed Jul 1, 2018
1 parent 7a270fb commit 78207f7
Showing 1 changed file with 28 additions and 39 deletions.
67 changes: 28 additions & 39 deletions si4project_filelist.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'''
This tool will generate source insight 4 project file list
from IAR build output file (*.dep),then we can import the
from build output file (*.dep),then we can import the
file list in the source insight 4 project.
'''
import os
Expand All @@ -18,11 +18,20 @@
if entry.is_file():
if entry.name.endswith('.eww'):
projectfilename = entry.name
for entry in os.scandir():
if entry.is_file() and entry.name.endswith('.dep'):
sourcefile = entry.name
outputfile = os.path.splitext(entry.name)[0]
break

if os.path.exists('settings'):
sourcefile = entry.name.replace('.eww', '.dep')
outputfile = os.path.splitext(entry.name)[0]
wsdtfilepath = os.path.join(os.getcwd(), 'settings'+'\\'+entry.name.replace('.eww', '.wsdt'))

parsefile = open(wsdtfilepath, 'r')
tree = ET.ElementTree(file=parsefile)
ConfigDictionary = tree.find('ConfigDictionary')
CurrentConfigs = ConfigDictionary.find('CurrentConfigs')
TargetName = CurrentConfigs.find('Project').text
TargetName = os.path.basename(TargetName)
break

if '' == sourcefile:
print('Please build the project once')
input()
Expand All @@ -43,6 +52,7 @@
IsCurrentTarget = int(OPTFL.find('IsCurrentTarget').text)
if IsCurrentTarget:
TargetName = tag.find('TargetName').text
break

tree = ET.ElementTree(file=entry.name)
for tag in tree.find('Targets').findall('Target'):
Expand All @@ -63,6 +73,7 @@
print('Please build the project once')
input()
sys.exit(0)
break

if '' == projectfilename:
print('Can not find project file, enter any key to exit')
Expand All @@ -74,39 +85,17 @@
si4filelist = []
if projectfilename.endswith('.eww'):
tree = ET.ElementTree(file=parsefile)
tag_cfg_list = tree.findall('configuration')
output_tag = ''

listsize = len(tag_cfg_list)
if listsize > 1:
print("There are multiple configuration:")
for index in range(0, listsize):
print("%d %s" % (index+1, tag_cfg_list[index].find('name').text))

print("Enter the index num to selete one:")
strin = input()
if strin.isdigit():
selnum = int(strin)
if (selnum < (listsize + 1)):
output_tag = tag_cfg_list[selnum - 1].find('outputs')
else:
print("Please restart the tool, the input shounld be a number")
input()
sys.exit(0)

elif listsize == 1:
output_tag = tag_cfg_list[0].find('outputs')
else:
print("Please check the project configuration")
input()
sys.exit(0)

for elem in output_tag.iterfind('file'):
if elem.text.startswith('$PROJ_DIR$'):
if elem.text.endswith('.c'):
si4filelist.append(os.path.abspath(elem.text.replace('$PROJ_DIR$', os.getcwd()))+'\n')
elif elem.text.endswith('.h'):
si4filelist.append(os.path.abspath(elem.text.replace('$PROJ_DIR$', os.getcwd()))+'\n')
for tag in tree.findall('configuration'):
if TargetName == tag.find('name').text:
output_tag = tag.find('outputs')

for elem in output_tag.iterfind('file'):
if elem.text.startswith('$PROJ_DIR$'):
if elem.text.endswith('.c'):
si4filelist.append(os.path.abspath(elem.text.replace('$PROJ_DIR$', os.getcwd()))+'\n')
elif elem.text.endswith('.h'):
si4filelist.append(os.path.abspath(elem.text.replace('$PROJ_DIR$', os.getcwd()))+'\n')
break

elif projectfilename.endswith('.uvproj') or projectfilename.endswith('.uvprojx'):
for line in parsefile.readlines():
Expand Down

0 comments on commit 78207f7

Please sign in to comment.