TRX/tools/sort_imports

98 lines
2.9 KiB
Text
Raw Permalink Normal View History

2024-10-02 10:23:23 +02:00
#!/usr/bin/env python3
import argparse
2024-10-09 18:00:27 +02:00
from pathlib import Path
2024-10-02 10:23:23 +02:00
2024-10-09 18:00:27 +02:00
from shared.files import find_versioned_files, is_binary_file
2024-10-02 10:23:23 +02:00
from shared.import_sorter import sort_imports
from shared.paths import SHARED_SRC_DIR, SRC_DIR, TR1Paths, TR2Paths
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument("path", type=Path, nargs="*")
return parser.parse_args()
def main() -> None:
args = parse_args()
if args.path:
paths = [path.absolute() for path in args.path]
else:
paths = [
path
2024-10-09 18:00:27 +02:00
for path in find_versioned_files(SRC_DIR)
2024-10-02 10:23:23 +02:00
if path.suffix in [".c", ".h"]
]
sort_imports(
2024-10-05 23:10:36 +02:00
paths=[
path for path in paths if path.is_relative_to(TR1Paths.src_dir)
],
2024-10-02 10:23:23 +02:00
root_dir=TR1Paths.src_dir,
system_include_dirs=[SRC_DIR],
own_include_map={
"game/game/game.c": "game/game.h",
"game/game/game_cutscene.c": "game/game.h",
"game/game/game_demo.c": "game/game.h",
"game/game/game_draw.c": "game/game.h",
"game/game/game_pause.c": "game/game.h",
"game/gun/gun.c": "game/gun.h",
"game/inventry.c": "game/inv.h",
"game/invfunc.c": "game/inv.h",
"game/invvars.c": "game/inv.h",
"game/lara/lara.c": "game/lara.h",
"game/option/option.c": "game/option.h",
"game/savegame/savegame.c": "game/savegame.h",
},
fix_map={"libavcodec/version_major.h": "libavcodec/version.h"},
forced_order=[],
)
sort_imports(
2024-10-05 23:10:36 +02:00
paths=[
path for path in paths if path.is_relative_to(TR2Paths.src_dir)
],
2024-10-02 10:23:23 +02:00
root_dir=TR2Paths.src_dir,
system_include_dirs=[SRC_DIR],
own_include_map={
"game/music/music_main.c": "game/music.h",
},
fix_map={},
forced_order=[
"<mmeapi.h>",
"<dsound.h>",
"<ddrawi.h>",
"<d3dhal.h>"
],
2024-10-02 10:23:23 +02:00
)
sort_imports(
paths=[path for path in paths if path.is_relative_to(SHARED_SRC_DIR)],
root_dir=SHARED_SRC_DIR,
system_include_dirs=[],
own_include_map={
"json/bson_write.c": "bson.h",
"json/bson_parse.c": "bson.h",
"json/json_base.c": "json.h",
"json/json_write.c": "json.h",
"json/json_parse.c": "json.h",
"log_unknown.c": "log.h",
"log_linux.c": "log.h",
"log_windows.c": "log.h",
2024-10-05 23:10:36 +02:00
"engine/audio.c": "audio_internal.h",
"engine/audio_sample.c": "audio_internal.h",
"engine/audio_stream.c": "audio_internal.h",
2024-10-02 10:23:23 +02:00
},
fix_map={},
forced_order=[
"<dsound.h>",
2024-10-02 10:23:23 +02:00
"<windows.h>",
"<dbghelp.h>",
"<tlhelp32.h>",
],
)
2024-10-05 23:10:36 +02:00
if __name__ == "__main__":
main()