55 lines
2.5 KiB
Python
55 lines
2.5 KiB
Python
import subprocess
|
|
import sys
|
|
import os
|
|
|
|
def run_command(cmd: str) -> None:
|
|
"""执行shell命令,失败直接退出整个脚本"""
|
|
print(f"\n==== 执行:{cmd} ====")
|
|
result = subprocess.run(cmd, shell=True)
|
|
if result.returncode != 0:
|
|
print(f"\n❌ 命令执行失败,返回码 {result.returncode},脚本终止")
|
|
sys.exit(result.returncode)
|
|
|
|
def read_binary(path: str) -> bytes:
|
|
if not os.path.isfile(path):
|
|
raise FileNotFoundError(f"找不到文件:{path}")
|
|
with open(path, "rb") as f:
|
|
return f.read()
|
|
|
|
def binary_diff_count(file_paths: list[str]) -> int:
|
|
datas = [(p, read_binary(p)) for p in file_paths]
|
|
base_path, base_buf = datas[0]
|
|
# 校验所有文件长度一致
|
|
for p, buf in datas[1:]:
|
|
if len(buf) != len(base_buf):
|
|
raise RuntimeError(f"文件长度不一致!{base_path}:{len(base_buf)} | {p}:{len(buf)}")
|
|
diff_bytes = 0
|
|
for offset in range(len(base_buf)):
|
|
vals = {buf[offset] for _, buf in datas}
|
|
if len(vals) > 1:
|
|
diff_bytes += 1
|
|
return diff_bytes
|
|
|
|
def main():
|
|
# 按顺序执行所有编译构建命令,任意失败直接停止
|
|
run_command(r"python Projectrans.py --project TransPyV/project.json --clean --rebuild-includes --clear-cache --asan")
|
|
run_command(r".\TransPyV\output\TransPyV.exe --project ./TransPyV/project.vpj --clean --run")
|
|
run_command(r".\TransPyV\.tpv_build\output\TransPyV.exe --project ./TransPyV/project.vpj --clean --run --build-dir ./TransPyV/.tpv_build2")
|
|
run_command(r".\TransPyV\.tpv_build2\output\TransPyV.exe --project ./TransPyV/project.vpj --clean --run --build-dir ./TransPyV/.tpv_build3")
|
|
run_command(r".\TransPyV\.tpv_build3\output\TransPyV.exe --project ./TransPyV/project.vpj --clean --run --build-dir ./TransPyV/.tpv_build4")
|
|
|
|
# 对比 build / build2 / build3 的exe
|
|
# 更新对比列表,添加build4的可执行文件路径以包含所有构建版本
|
|
compare_list = [
|
|
r".\TransPyV\.tpv_build\output\TransPyV.exe",
|
|
r".\TransPyV\.tpv_build2\output\TransPyV.exe",
|
|
r".\TransPyV\.tpv_build3\output\TransPyV.exe",
|
|
r".\TransPyV\.tpv_build4\output\TransPyV.exe",
|
|
]
|
|
print("\n==== 开始二进制对比 ====")
|
|
diff_cnt = binary_diff_count(compare_list)
|
|
print(f"\n✅ 对比完成,build/build2/build3/build4 之间总差异字节数:{diff_cnt}")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|