minecraft-file-converter / scripts /build_world_engine.py
cpuai's picture
Deploy BlockBridge Minecraft file converter 2.1.0 with independent world conversion
7056f70 verified
Raw History Blame Contribute Delete
1.49 kB
"""从固定上游提交构建原生世界转换进程;不下载未知来源二进制。"""
from pathlib import Path
import argparse,os,shutil,subprocess,tempfile
PIN='8dfc4de1ba5c7f72e804abea8663380c0dbd5680'
p=argparse.ArgumentParser();p.add_argument('--output',required=True);p.add_argument('--jobs',type=int,default=2);a=p.parse_args()
root=Path(__file__).resolve().parents[1];out=Path(a.output).resolve();env=os.environ.copy();env['GIT_LFS_SKIP_SMUDGE']='1'
with tempfile.TemporaryDirectory(prefix='worldbridge-build-') as tmp:
src=Path(tmp)/'source';build=Path(tmp)/'build';src.mkdir()
def run(cmd):subprocess.run(cmd,check=True,env=env)
run(['git','init',str(src)])
run(['git','-C',str(src),'remote','add','origin','https://github.com/kbinani/je2be-core.git'])
run(['git','-C',str(src),'fetch','--depth','1','origin',PIN]);run(['git','-C',str(src),'checkout','--detach','FETCH_HEAD'])
with (src/'CMakeLists.txt').open('a') as f:f.write('\n'+(root/'native/target.cmake').read_text())
run(['cmake','-S',str(src),'-B',str(build),'-DCMAKE_BUILD_TYPE=Release','-DCMAKE_POLICY_VERSION_MINIMUM=3.5','-DWORLDBRIDGE_ADAPTER_DIR='+str(root/'native')])
run(['cmake','--build',str(build),'--target','worldbridge-native','--config','Release','--parallel',str(max(1,min(a.jobs,4)))])
binary=build/('Release/worldbridge-native.exe' if os.name=='nt' else 'worldbridge-native')
out.parent.mkdir(parents=True,exist_ok=True);shutil.copy2(binary,out);print(out)