加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
prebuild.py 3.05 KB
一键复制 编辑 原始数据 按行查看 历史
程序鸭 提交于 2023-10-29 21:32 . [*] update build
#!/usr/bin/python3
# Copyright (c) 2023 DoubleByte.
# This is licensed under Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#
# http://license.coscl.org.cn/MulanPSL2
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
import lzma
import os
import sys
import tarfile
import urllib.request
from core.util.path import PREBUILD_PATH, BIN_PATH, CORE_PATH
sys.path.append(CORE_PATH)
from core.util.color import Color
from core.util.log_util import LogUtil
URL = "https://chengxuya.top/share/" + sys.platform
OPT_PATH = PREBUILD_PATH + "/opt"
def download_gn():
gn = BIN_PATH + "/gn"
if os.path.exists(gn):
return
gn_xz = BIN_PATH + "/gn.xz"
if not os.path.exists(gn_xz):
LogUtil.info("downloading gn")
file = URL + "/gn.xz"
response = urllib.request.urlopen(file)
with open(gn_xz, "wb") as xz:
xz.write(response.read())
with lzma.open(gn_xz, "rb") as xz, open(gn, "wb") as exe:
LogUtil.info("decompressing gn")
exe.write(xz.read())
os.chmod(gn, 0o777)
if os.path.exists(gn_xz):
os.remove(gn_xz)
def download_ninja():
ninja = BIN_PATH + "/ninja"
if os.path.exists(ninja):
return
ninja_xz = BIN_PATH + "/ninja.xz"
if not os.path.exists(ninja_xz):
LogUtil.info("downloading ninja")
file = URL + "/ninja.xz"
response = urllib.request.urlopen(file)
with open(ninja_xz, "wb") as xz:
xz.write(response.read())
with lzma.open(ninja_xz, "rb") as xz, open(ninja, "wb") as exe:
LogUtil.info("decompressing ninja")
exe.write(xz.read())
os.chmod(ninja, 0o777)
if os.path.exists(ninja_xz):
os.remove(ninja_xz)
def download_python():
python = BIN_PATH + "/python"
if os.path.exists(python):
return
file = URL + "/python.tar.xz"
python_tar_xz = OPT_PATH + "/python.tar.xz"
if not os.path.exists(python_tar_xz):
response = urllib.request.urlopen(file)
LogUtil.info("downloading python")
with open(python_tar_xz, "wb") as xz:
xz.write(response.read())
if not os.path.exists(OPT_PATH + "/python"):
with tarfile.open(python_tar_xz, "r") as tar:
LogUtil.info("decompressing python")
tar.extractall(OPT_PATH)
os.symlink(OPT_PATH + "/python/bin/python3", python)
def prebuild():
download_gn()
download_ninja()
download_python()
def main():
if not os.path.exists(PREBUILD_PATH):
os.makedirs(PREBUILD_PATH)
if not os.path.exists(OPT_PATH):
os.makedirs(OPT_PATH)
if not os.path.exists(BIN_PATH):
os.makedirs(BIN_PATH)
prebuild()
result: str = Color.info + "prebuild successful" + Color.end
LogUtil.info(result)
if __name__ == '__main__':
main()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化