Skip to content

Commit

Permalink
search IAR install path
Browse files Browse the repository at this point in the history
  • Loading branch information
tianxiaoMCU committed Apr 19, 2019
1 parent e50e55d commit 5791da8
Showing 1 changed file with 51 additions and 18 deletions.
69 changes: 51 additions & 18 deletions si4project_filelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,42 @@
projectfilename = ''
sourcefile = ''
outputfile = ''
TOOLKIT_PATH = ''

for entry in os.scandir():
if entry.is_file():
if entry.name.endswith('.eww'):
projectfilename = entry.name

# find current target
# check IAR install path and get TOOLKIT_DIR
if os.path.exists(r'C:\Program Files (x86)\IAR Systems') == False:
print(r'Please input the TOOLKIT path(e.g. C:\Program Files (x86)\IAR Systems\Embedded Workbench 8.0\arm) or press ENTER to ignor')
TOOLKIT_PATH = input()
if os.path.exists(TOOLKIT_PATH) == False:
print('Path not exist, ignor this part of file')
TOOLKIT_PATH = ''
elif os.path.exists(os.path.join(TOOLKIT_PATH, 'inc')) == False:
print('Path error, ignor this part of file')
TOOLKIT_PATH = ''
else:
for DIR in os.scandir(r'C:\Program Files (x86)\IAR Systems'):
if DIR.name.startswith('Embedded Workbench'):
TOOLKIT_PATH = r'C:\Program Files (x86)\IAR Systems\Embedded Workbench 8.0\arm'.replace(
'Embedded Workbench 8.0', DIR.name)

# find current target
wsdtfile = os.path.join(os.getcwd(), 'settings')
wsdtfile = os.path.join(wsdtfile, entry.name.replace('.eww', '.wsdt'))
wsdtfile = os.path.join(
wsdtfile, entry.name.replace('.eww', '.wsdt'))

if os.path.exists(wsdtfile):
tree = ET.ElementTree(file=wsdtfile)
ConfigDictionary = tree.find('ConfigDictionary')
CurrentConfigs = ConfigDictionary.find('CurrentConfigs')
TargetName = CurrentConfigs.find('Project').text.split('/')[1]

depfilename = CurrentConfigs.find('Project').text.split('/')[0] + '.dep'
depfilename = CurrentConfigs.find(
'Project').text.split('/')[0] + '.dep'
if os.path.exists(depfilename):
sourcefile = depfilename
outputfile = os.path.splitext(projectfilename)[0]
Expand Down Expand Up @@ -62,7 +81,8 @@
Extensions = tree.find('Extensions')
if None == Extensions.findtext('nMigrate'):
# ide is keil4
depfilename = os.path.splitext(projectfilename)[0] + '_' + TargetName + '.dep'
depfilename = os.path.splitext(projectfilename)[
0] + '_' + TargetName + '.dep'
if os.path.exists(depfilename):
sourcefile = depfilename
outputfile = os.path.splitext(projectfilename)[0]
Expand All @@ -73,12 +93,17 @@
for tag in tree.find('Targets').findall('Target'):
if tag.find('TargetName').text == TargetName:
TargetOption = tag.find('TargetOption')
TargetCommonOption = TargetOption.find('TargetCommonOption')
OutputDirectory = TargetCommonOption.find('OutputDirectory').text
OutputDirectory = os.path.normpath(os.path.join(os.getcwd(), OutputDirectory))

depfilename = os.path.splitext(projectfilename)[0] + '_' + TargetName + '.dep'
depfilename = os.path.join(OutputDirectory, depfilename)
TargetCommonOption = TargetOption.find(
'TargetCommonOption')
OutputDirectory = TargetCommonOption.find(
'OutputDirectory').text
OutputDirectory = os.path.normpath(
os.path.join(os.getcwd(), OutputDirectory))

depfilename = os.path.splitext(projectfilename)[
0] + '_' + TargetName + '.dep'
depfilename = os.path.join(
OutputDirectory, depfilename)

if os.path.exists(depfilename):
sourcefile = depfilename
Expand All @@ -97,7 +122,7 @@
input()
sys.exit(0)

#2、parse the seleted dep file
# 2、parse the seleted dep file
parsefile = open(sourcefile, 'r')
si4filelist = []
if projectfilename.endswith('.eww'):
Expand All @@ -109,27 +134,35 @@
for elem in output_tag.findall('file'):
if elem.text.startswith('$PROJ_DIR$'):
if elem.text.endswith('.c') or elem.text.endswith('.s') or elem.text.endswith('.h'):
si4filelist.append(os.path.abspath(elem.text.replace('$PROJ_DIR$', os.getcwd()))+'\n')
si4filelist.append(os.path.abspath(
elem.text.replace('$PROJ_DIR$', os.getcwd()))+'\n')
elif TOOLKIT_PATH != '' and elem.text.startswith('$TOOLKIT_DIR$'):
if elem.text.endswith('.c') or elem.text.endswith('.s') or elem.text.endswith('.h'):
si4filelist.append(elem.text.replace(
'$TOOLKIT_DIR$', TOOLKIT_PATH)+'\n')
break

elif projectfilename.endswith('.uvproj') or projectfilename.endswith('.uvprojx'):
for line in parsefile.readlines():
m = re.search(r"^F \(.*?\)(?=\([\dxa-fA-F]{10}\))|^I \(.*?\)(?=\([\dxa-fA-F]{10}\))", line)
m = re.search(
r"^F \(.*?\)(?=\([\dxa-fA-F]{10}\))|^I \(.*?\)(?=\([\dxa-fA-F]{10}\))", line)
if None != m:
relpath = m.group(0)[3:-1]
si4filelist.append(os.path.abspath(relpath)+'\n')
si4filelist = set(si4filelist)

#3、save the lists
# 3、save the lists
outputfile = open(outputfile + '.si4project_filelist.txt', 'w')
outputfile.write('; Source Insight Project File List\n')
outputfile.write('; Project Name: '+os.path.splitext(sourcefile)[0]+'\n')
outputfile.write('; Generated by si4project_filelist.py at '+datetime.now().strftime('%Y/%m/%d %H:%M:%S')+'\n')
outputfile.write('; Generated by si4project_filelist.py at ' +
datetime.now().strftime('%Y/%m/%d %H:%M:%S')+'\n')
outputfile.write('; Version=4.00.xxxx\n')
outputfile.write(';\n')
outputfile.write('; Each line should contain either a file name, a wildcard, or a sub-directory name.\n')
outputfile.write('; File paths are relative to the project source root directory.\n')
outputfile.write(
'; Each line should contain either a file name, a wildcard, or a sub-directory name.\n')
outputfile.write(
'; File paths are relative to the project source root directory.\n')
outputfile.write(';\n')
outputfile.writelines(si4filelist)
outputfile.close()

0 comments on commit 5791da8

Please sign in to comment.