Skip to content

Commit 23f1723

Browse files
author
Vysakh Pillai - I16658
committed
accept project configuration argument. improved sanity checks
1 parent 711a5c2 commit 23f1723

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

mapfileParse.py

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import pprint
1010
import sys
1111
import time
12+
import argparse
1213

1314
# -------------------------------------------------------------------------------------------
1415
# Globals to store common variables
@@ -20,6 +21,7 @@
2021
mapFilePath = ""
2122
elfFilePath = ""
2223
aMapPath = ""
24+
configName = ""
2325

2426
compDefinition = {
2527
"Wifi Driver": ["/driver/wifi/"],
@@ -58,9 +60,17 @@ def setPaths(inputPath):
5860
aMapPath = os.path.join(os.path.dirname(os.path.abspath(
5961
inspect.getfile(inspect.currentframe()))), "amap.exe")
6062

63+
global configName
64+
if not configName:
65+
configName = projectName
66+
6167
global outputFolder, buildMode
6268
outputFolder = os.path.join(
63-
projectPath, f"dist\\{projectName}\\{buildMode}")
69+
projectPath, f"dist\\{configName}\\{buildMode}")
70+
71+
if not os.path.exists(outputFolder):
72+
print("Output Folder does not exist. Please check configuration Name")
73+
exit(-2)
6474

6575
global mapFilePath
6676
mapFilePath = os.path.join(
@@ -78,7 +88,7 @@ def setPaths(inputPath):
7888

7989
def checkTools():
8090
global elfFilePath
81-
command = f"xc32-size.exe {elfFilePath}"
91+
command = f"xc32-addr2line.exe -v"
8292
status, result = subprocess.getstatusoutput(
8393
shlex.split(command, posix=False))
8494
if status:
@@ -394,6 +404,9 @@ def cleanupMapFile(fileName):
394404

395405
cleanFile.write(lineItem)
396406

407+
# -------------------------------------------------------------------------------------------
408+
# main execution flow
409+
397410

398411
def main(projectPath):
399412
global cleanFileExt, mapFilePath, outputFolder
@@ -434,13 +447,30 @@ def main(projectPath):
434447
print("See results at :", outputFolder)
435448

436449

437-
if __name__ == "__main__":
438-
if 2 != len(sys.argv):
439-
print(" Usage: Enter project path as argument until .X")
450+
# -------------------------------------------------------------------------------------------
451+
# parse input arguments
452+
def parseArguments():
453+
global configName, projectPath
454+
parser = argparse.ArgumentParser(
455+
description="Tool to parse map file and provide component-wise memory usage of an embedded project")
456+
parser.add_argument("-c", "--config",
457+
help="specify a configuration name", metavar="<project config>", type=str)
458+
parser.add_argument('prjPathArg', nargs=1,
459+
metavar="<project path to .X>")
460+
args = parser.parse_args()
461+
if (args.config):
462+
configName = args.config
463+
if not args.prjPathArg:
464+
parser.error("please provide a project path to .X")
440465
exit(-1)
441466
else:
442-
# r"C:\Microchip\Bitbucket_pic32mzw1\wireless\apps\paho_mqtt_client\firmware\pic32mz_w1_curiosity.X"
443-
projectPath = sys.argv[1]
467+
projectPath = args.prjPathArg[0]
468+
469+
470+
if __name__ == "__main__":
471+
parser = argparse.ArgumentParser()
472+
parseArguments()
473+
444474
start = time.time()
445475
main(projectPath)
446476
print(f"Process completed in : {time.time() - start}s")

0 commit comments

Comments
 (0)