Difficult-Rocket/scripts/compile_mod.py

48 lines
1.3 KiB
Python
Raw Normal View History

2024-05-26 10:47:05 +08:00
import os
import sys
2023-12-24 15:51:44 +08:00
import argparse
import subprocess
2024-05-26 10:47:05 +08:00
from pathlib import Path
2023-12-24 15:51:44 +08:00
2023-12-30 22:07:01 +08:00
if __name__ == "__main__":
2023-12-24 15:51:44 +08:00
parser = argparse.ArgumentParser()
# script -py <py_version> (3.8 ~ 3.12)
2023-12-30 22:07:01 +08:00
parser.add_argument("-py", type=str, help="python version")
parser.add_argument("-all", help="用所有的python版本编译", action="store_true")
2024-05-26 10:47:05 +08:00
parser.add_argument("-clean", help="清理编译文件", action="store_true")
2023-12-24 15:51:44 +08:00
args = parser.parse_args()
# 移动到项目根目录
2023-12-30 22:07:01 +08:00
os.chdir("./mods/dr_game/Difficult_Rocket_rs/src")
2024-05-16 00:33:25 +08:00
os.chdir("./src")
subprocess.run(["cargo", "fmt", "--all"])
2024-05-26 10:47:05 +08:00
if args.clean:
subprocess.run(["cargo", "clean"])
2024-05-16 00:33:25 +08:00
os.chdir("../")
2023-12-24 15:51:44 +08:00
2024-05-26 10:47:05 +08:00
if args.clean:
subprocess.run([sys.executable, "setup.py", "clean"])
sys.exit(0)
2023-12-24 15:51:44 +08:00
if not args.py:
if args.all:
2023-12-30 22:07:01 +08:00
all_version = ("38", "39", "310", "311", "312")
2023-12-24 15:51:44 +08:00
for py_version in all_version:
try:
2023-12-30 22:07:01 +08:00
subprocess.run([f"python{py_version}", "setup.py", "build"])
2023-12-24 15:51:44 +08:00
except FileNotFoundError:
2023-12-30 22:07:01 +08:00
print(f"python{py_version} not found")
2023-12-24 15:51:44 +08:00
else:
2023-12-30 22:07:01 +08:00
subprocess.run([sys.executable, "setup.py", "build"])
2023-12-24 15:51:44 +08:00
else:
2023-12-30 22:07:01 +08:00
subprocess.run([args.py, "setup.py", "build"])
2023-12-24 15:51:44 +08:00
# post
2023-12-30 22:07:01 +08:00
subprocess.run([sys.executable, "post_build.py"])