Skip to content

Commit

Permalink
fix encoding and path issues on Windows in tools/decomp.py
Browse files Browse the repository at this point in the history
  • Loading branch information
BR- committed Jan 24, 2024
1 parent ddb7eb1 commit 6f51c36
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ GitPython>=3.1.32
graphviz>=0.20.1
isort>=5.12.0
humanfriendly>=10.0
pycparser>=2.21
pcpp>=1.30
pyelftools>=0.29
Pygments>=2.15.0
Expand Down
9 changes: 7 additions & 2 deletions tools/decomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ def resolve_path(p: Path) -> str:


def run_cmd(cmd: list[str]) -> str:
result = subprocess.run(cmd, capture_output=True)
if cmd[0] == "python":
executable = sys.executable
else:
executable = None
result = subprocess.run(cmd, capture_output=True, executable=executable)
if result.returncode != 0:
print(" ".join(cmd))
print(" ".join(cmd), file=sys.stderr)
print(result.stdout.decode(), file=sys.stderr)
print(result.stderr.decode(), file=sys.stderr)
sys.exit(1)
else:
Expand Down
6 changes: 3 additions & 3 deletions tools/m2ctx/m2ctx.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@

def write_header(path: Path):
files = sorted({f"#include <{file.relative_to(src)}>" for file in src.rglob("*.h")})
path.write_text("\n".join(files))
path.write_text("\n".join(files), encoding="utf-8")


def try_import(c_command: List[str]):
Expand Down Expand Up @@ -180,7 +180,7 @@ def main():
output = output.strip()

if not args.no_file:
source_path.write_text(output)
source_path.write_text(output, encoding="utf-8")

if args.clipboard:
import pyperclip
Expand All @@ -190,7 +190,7 @@ def main():
if args.render:
template = template_path.read_text()
html = template.format(ctx=output)
render_path.write_text(html)
render_path.write_text(html, encoding="utf-8")

if not args.quiet:
if args.colorize:
Expand Down

0 comments on commit 6f51c36

Please sign in to comment.