Skip to content

Commit 9810afa

Browse files
authored
Merge pull request #101 from RevoSucks/header_conflict
replace defunct calcprogress.py
2 parents 5863908 + d53ccb3 commit 9810afa

File tree

2 files changed

+98
-118
lines changed

2 files changed

+98
-118
lines changed

calcprogress.py

-118
This file was deleted.

progress.py

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env python3
2+
3+
# SPDX-FileCopyrightText: © 2023 ZeldaRET
4+
# SPDX-License-Identifier: MIT
5+
6+
from __future__ import annotations
7+
8+
import argparse
9+
import mapfile_parser
10+
from pathlib import Path
11+
12+
13+
ASMPATH = Path("asm")
14+
NONMATCHINGS = "nonmatchings"
15+
16+
17+
def getProgressFromMapFile(mapFile: mapfile_parser.MapFile, asmPath: Path, nonmatchings: Path, aliases: dict[str, str]=dict(), pathIndex: int=2) -> tuple[mapfile_parser.ProgressStats, dict[str, mapfile_parser.ProgressStats]]:
18+
totalStats = mapfile_parser.ProgressStats()
19+
progressPerFolder: dict[str, mapfile_parser.ProgressStats] = dict()
20+
21+
for segment in mapFile:
22+
for file in segment:
23+
if len(file) == 0:
24+
continue
25+
26+
folder = file.filepath.parts[pathIndex]
27+
28+
if ".a" in folder:
29+
folder = folder.split('.a')[0]
30+
31+
if folder in aliases:
32+
folder = aliases[folder]
33+
34+
if folder not in progressPerFolder:
35+
progressPerFolder[folder] = mapfile_parser.ProgressStats()
36+
37+
originalFilePath = Path(*file.filepath.parts[pathIndex:])
38+
39+
extensionlessFilePath = originalFilePath
40+
while extensionlessFilePath.suffix:
41+
extensionlessFilePath = extensionlessFilePath.with_suffix("")
42+
43+
fullAsmFile = asmPath / extensionlessFilePath.with_suffix(".s")
44+
wholeFileIsUndecomped = fullAsmFile.exists()
45+
46+
47+
for func in file:
48+
funcAsmPath = nonmatchings / extensionlessFilePath / f"{func.name}.s"
49+
50+
symSize = 0
51+
if func.size is not None:
52+
symSize = func.size
53+
54+
if wholeFileIsUndecomped:
55+
totalStats.undecompedSize += symSize
56+
progressPerFolder[folder].undecompedSize += symSize
57+
elif funcAsmPath.exists():
58+
totalStats.undecompedSize += symSize
59+
progressPerFolder[folder].undecompedSize += symSize
60+
else:
61+
totalStats.decompedSize += symSize
62+
progressPerFolder[folder].decompedSize += symSize
63+
64+
return totalStats, progressPerFolder
65+
66+
67+
def getProgress(mapPath: Path, version: str) -> tuple[mapfile_parser.ProgressStats, dict[str, mapfile_parser.ProgressStats]]:
68+
mapFile = mapfile_parser.MapFile()
69+
mapFile.readMapFile(mapPath)
70+
71+
for segment in mapFile:
72+
for file in segment:
73+
if len(file) == 0:
74+
continue
75+
76+
filepathParts = list(file.filepath.parts)
77+
if version in filepathParts:
78+
filepathParts.remove(version)
79+
file.filepath = Path(*filepathParts)
80+
81+
nonMatchingsPath = ASMPATH / version / NONMATCHINGS
82+
83+
return getProgressFromMapFile(mapFile.filterBySectionType(".text"), ASMPATH / version, nonMatchingsPath, aliases={"ultralib": "libultra"})
84+
85+
def progressMain():
86+
parser = argparse.ArgumentParser()
87+
parser.add_argument("-v", "--version", help="version to process", default="us")
88+
89+
args = parser.parse_args()
90+
91+
mapPath = Path("build") / f"pokestadium-{args.version}.map"
92+
93+
totalStats, progressPerFolder = getProgress(mapPath, args.version)
94+
95+
mapfile_parser.progress_stats.printStats(totalStats, progressPerFolder)
96+
97+
if __name__ == "__main__":
98+
progressMain()

0 commit comments

Comments
 (0)