-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from RevoSucks/header_conflict
replace defunct calcprogress.py
- Loading branch information
Showing
2 changed files
with
98 additions
and
118 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# SPDX-FileCopyrightText: © 2023 ZeldaRET | ||
# SPDX-License-Identifier: MIT | ||
|
||
from __future__ import annotations | ||
|
||
import argparse | ||
import mapfile_parser | ||
from pathlib import Path | ||
|
||
|
||
ASMPATH = Path("asm") | ||
NONMATCHINGS = "nonmatchings" | ||
|
||
|
||
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]]: | ||
totalStats = mapfile_parser.ProgressStats() | ||
progressPerFolder: dict[str, mapfile_parser.ProgressStats] = dict() | ||
|
||
for segment in mapFile: | ||
for file in segment: | ||
if len(file) == 0: | ||
continue | ||
|
||
folder = file.filepath.parts[pathIndex] | ||
|
||
if ".a" in folder: | ||
folder = folder.split('.a')[0] | ||
|
||
if folder in aliases: | ||
folder = aliases[folder] | ||
|
||
if folder not in progressPerFolder: | ||
progressPerFolder[folder] = mapfile_parser.ProgressStats() | ||
|
||
originalFilePath = Path(*file.filepath.parts[pathIndex:]) | ||
|
||
extensionlessFilePath = originalFilePath | ||
while extensionlessFilePath.suffix: | ||
extensionlessFilePath = extensionlessFilePath.with_suffix("") | ||
|
||
fullAsmFile = asmPath / extensionlessFilePath.with_suffix(".s") | ||
wholeFileIsUndecomped = fullAsmFile.exists() | ||
|
||
|
||
for func in file: | ||
funcAsmPath = nonmatchings / extensionlessFilePath / f"{func.name}.s" | ||
|
||
symSize = 0 | ||
if func.size is not None: | ||
symSize = func.size | ||
|
||
if wholeFileIsUndecomped: | ||
totalStats.undecompedSize += symSize | ||
progressPerFolder[folder].undecompedSize += symSize | ||
elif funcAsmPath.exists(): | ||
totalStats.undecompedSize += symSize | ||
progressPerFolder[folder].undecompedSize += symSize | ||
else: | ||
totalStats.decompedSize += symSize | ||
progressPerFolder[folder].decompedSize += symSize | ||
|
||
return totalStats, progressPerFolder | ||
|
||
|
||
def getProgress(mapPath: Path, version: str) -> tuple[mapfile_parser.ProgressStats, dict[str, mapfile_parser.ProgressStats]]: | ||
mapFile = mapfile_parser.MapFile() | ||
mapFile.readMapFile(mapPath) | ||
|
||
for segment in mapFile: | ||
for file in segment: | ||
if len(file) == 0: | ||
continue | ||
|
||
filepathParts = list(file.filepath.parts) | ||
if version in filepathParts: | ||
filepathParts.remove(version) | ||
file.filepath = Path(*filepathParts) | ||
|
||
nonMatchingsPath = ASMPATH / version / NONMATCHINGS | ||
|
||
return getProgressFromMapFile(mapFile.filterBySectionType(".text"), ASMPATH / version, nonMatchingsPath, aliases={"ultralib": "libultra"}) | ||
|
||
def progressMain(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-v", "--version", help="version to process", default="us") | ||
|
||
args = parser.parse_args() | ||
|
||
mapPath = Path("build") / f"pokestadium-{args.version}.map" | ||
|
||
totalStats, progressPerFolder = getProgress(mapPath, args.version) | ||
|
||
mapfile_parser.progress_stats.printStats(totalStats, progressPerFolder) | ||
|
||
if __name__ == "__main__": | ||
progressMain() |