Files
cadmic 65e87efb32 Switch build system to use ninja and dtk and support multiple versions (#127)
* Start dtk project based on oot-gc-dtk

* Add asm_processor build rules

* Encode shift-JIS strings

* Generate build for all versions at the same time

* Update diff.py for new build layout

* Implement per-version object completion

* Add ce-u and match emu files

* Fix config/ce-j/build.sha1

* Add dol-diff, dol-apply, and format scripts

* Add configure.py --non-matching

* Delete old build system

* Reorganize library files

* Make diff.py multi-version but remove target line-number support

* Update README for new build system

* Change diff.py build command to ninja

* ./dol-apply ce-u

* Recommend ./diff.py -mwo3

* Upgrade to dtk v0.8.3, use block_relocations instead of noreloc

* Mark soundGCN.c as matched
2024-05-20 17:27:48 -07:00

85 lines
2.4 KiB
Python
Executable File

#!/usr/bin/env python3
###
# Transforms .d files, converting Windows paths to Unix paths.
# Allows usage of the mwcc -MMD flag on platforms other than Windows.
#
# Usage:
# python3 tools/transform_dep.py build/src/file.d build/src/file.d
#
# If changes are made, please submit a PR to
# https://github.com/encounter/dtk-template
###
import argparse
import os
from platform import uname
wineprefix = os.path.join(os.environ["HOME"], ".wine")
if "WINEPREFIX" in os.environ:
wineprefix = os.environ["WINEPREFIX"]
winedevices = os.path.join(wineprefix, "dosdevices")
def in_wsl() -> bool:
return "microsoft-standard" in uname().release
def import_d_file(in_file: str) -> str:
out_text = ""
with open(in_file) as file:
for idx, line in enumerate(file):
if idx == 0:
if line.endswith(" \\\n"):
out_text += line[:-3].replace("\\", "/") + " \\\n"
else:
out_text += line.replace("\\", "/")
else:
suffix = ""
if line.endswith(" \\\n"):
suffix = " \\"
path = line.lstrip()[:-3]
else:
path = line.strip()
# lowercase drive letter
path = path[0].lower() + path[1:]
if path[0] == "z":
# shortcut for z:
path = path[2:].replace("\\", "/")
elif in_wsl():
path = path[0:1] + path[2:]
path = os.path.join("/mnt", path.replace("\\", "/"))
else:
# use $WINEPREFIX/dosdevices to resolve path
path = os.path.realpath(
os.path.join(winedevices, path.replace("\\", "/"))
)
out_text += "\t" + path + suffix + "\n"
return out_text
def main() -> None:
parser = argparse.ArgumentParser(
description="""Transform a .d file from Wine paths to normal paths"""
)
parser.add_argument(
"d_file",
help="""Dependency file in""",
)
parser.add_argument(
"d_file_out",
help="""Dependency file out""",
)
args = parser.parse_args()
output = import_d_file(args.d_file)
with open(args.d_file_out, "w", encoding="UTF-8") as f:
f.write(output)
if __name__ == "__main__":
main()