Skip to content

Commit

Permalink
Merge pull request #10 from Decompollaborate/develop
Browse files Browse the repository at this point in the history
2.1.2
  • Loading branch information
AngheloAlf authored Aug 30, 2023
2 parents fc1596b + d64920d commit f6cd42b
Show file tree
Hide file tree
Showing 62 changed files with 4,639,427 additions and 75 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Tests cases

# Build on every branch push, tag push, and pull request change:
on: [push, pull_request]

jobs:
tests_cases:
name: Tests cases
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Install local mapfile_parser
run: pip install .

- name: Update tests outputs
run: python3 tests/update_outputs.py

- name: Check if there are any changes in the test cases
id: tests_changes
uses: tj-actions/verify-changed-files@v14

- name: tables changes
if: steps.tests_changes.outputs.files_changed == 'true'
run: |
echo "Changed files: ${{ steps.tests_changes.outputs.changed_files }}"
echo "Please install the latest changes, run \`python3 tests/update_outputs.py\`, check the changes are desirable and commit the result"
exit 1
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,3 @@ cython_debug/
#
.vscode/


tests

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[project]
name = "mapfile_parser"
version = "2.1.1"
version = "2.1.2.dev1"
description = "Map file parser library focusing decompilation projects"
readme = "README.md"
requires-python = ">=3.7"
Expand Down
4 changes: 2 additions & 2 deletions src/mapfile_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from __future__ import annotations

__version_info__ = (2, 1, 1)
__version__ = ".".join(map(str, __version_info__))
__version_info__ = (2, 1, 2)
__version__ = ".".join(map(str, __version_info__)) + ".dev1"
__author__ = "Decompollaborate"

from . import utils as utils
Expand Down
8 changes: 5 additions & 3 deletions src/mapfile_parser/frontends/jsonify.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
from .. import mapfile


def doJsonify(mapPath: Path, outputPath: Path|None) -> int:
def doJsonify(mapPath: Path, outputPath: Path|None, humanReadable: bool=True) -> int:
mapFile = mapfile.MapFile()
mapFile.readMapFile(mapPath)

jsonStr = json.dumps(mapFile.toJson(), indent=4)
jsonStr = json.dumps(mapFile.toJson(humanReadable=humanReadable), indent=4)

if outputPath is None:
print(jsonStr)
Expand All @@ -30,13 +30,15 @@ def doJsonify(mapPath: Path, outputPath: Path|None) -> int:
def processArguments(args: argparse.Namespace):
mapPath: Path = args.mapfile
outputPath: Path|None = Path(args.output) if args.output is not None else None
machine: bool = args.machine

exit(doJsonify(mapPath, outputPath))
exit(doJsonify(mapPath, outputPath, humanReadable=not machine))

def addSubparser(subparser: argparse._SubParsersAction[argparse.ArgumentParser]):
parser = subparser.add_parser("jsonify", help="Converts a mapfile into a json format.")

parser.add_argument("mapfile", help="Path to a map file", type=Path)
parser.add_argument("-o", "--output", help="Output path of for the generated json. If omitted then stdout is used instead.")
parser.add_argument("-m", "--machine", help="Emit numbers as numbers instead of outputting them as pretty strings.", action="store_true")

parser.set_defaults(func=processArguments)
36 changes: 28 additions & 8 deletions src/mapfile_parser/frontends/symbol_sizes_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,44 @@
from .. import mapfile


def processArguments(args: argparse.Namespace):
def doSymbolSizesCsv(mapPath: Path, outputPath: Path|None, filterSection: str|None=None, sameFolder: bool=False, symbolsSummary: bool=False, allFiles: bool=False) -> int:
mapFile = mapfile.MapFile()
mapFile.readMapFile(args.mapfile)
if args.filter_section is not None:
mapFile = mapFile.filterBySectionType(args.filter_section)
mapFile.readMapFile(mapPath)

if filterSection is not None:
mapFile = mapFile.filterBySectionType(filterSection)

if args.same_folder:
if sameFolder:
mapFile = mapFile.mixFolders()

if args.symbols:
mapFile.printSymbolsCsv()
if symbolsSummary:
output = mapFile.toCsvSymbols()
else:
output = mapFile.toCsv(printVram=not sameFolder, skipWithoutSymbols=not allFiles)

if outputPath is None:
print(output)
else:
mapFile.printAsCsv(printVram=not args.same_folder, skipWithoutSymbols=not args.all)
outputPath.parent.mkdir(parents=True, exist_ok=True)
outputPath.write_text(output)

return 0

def processArguments(args: argparse.Namespace):
mapPath: Path = args.mapfile
outputPath: Path|None = Path(args.output) if args.output is not None else None
filterSection: str|None = args.filter_section
sameFolder: bool = args.same_folder
symbolsSummary: bool = args.symbols
allFiles: bool = args.all

exit(doSymbolSizesCsv(mapPath, outputPath, filterSection, sameFolder, symbolsSummary, allFiles))

def addSubparser(subparser: argparse._SubParsersAction[argparse.ArgumentParser]):
parser = subparser.add_parser("symbol_sizes_csv", help="Produces a csv summarizing the files sizes by parsing a map file.")

parser.add_argument("mapfile", help="Path to a map file", type=Path)
parser.add_argument("-o", "--output", help="Output path of for the generated csv. If omitted then stdout is used instead.")
parser.add_argument("--same-folder", help="Mix files in the same folder.", action="store_true")
parser.add_argument("--symbols", help="Prints the size of every symbol instead of a summary.", action="store_true")
parser.add_argument("-a", "--all", help="Don't skip files without symbols.", action="store_true")
Expand Down
Loading

0 comments on commit f6cd42b

Please sign in to comment.