Difficult-Rocket/nuitka_build.py
shenjack f9eeafe322
好活!
readme update

看起来更像 Dear ImGui 一些(looks more like Dear ImGui

and some intersting feature to the button

remove debug

确认一下action

404 修改

writing theme

looks good

better?

a ?

alpha=255 not 256

looks better

try new pyglet first

看起来好一些

sync pyglet

水一手

这波必须得水一手了,要不然commit太少了(确信

丢点正经东西上去

顺手继承一下Options

补充docs

坏了,忘记水commit了(

至少我能早睡了(

这里还能水一点来着(

试试再说

reee

保证能跑(

同步lib not dr 的修改

忘记带上 None了

还是加上一个额外的判断参数吧

刷点commit也不错

先更新一下依赖版本

水commit啦

理论可行,实践开始!

构建参数喜加一

reeeee

更新一下 pyproject 的依赖

fix typing

looks better

水一个(

测试?

sync pyglet to master

A | Try use rust-cache

looks good?

what?

C | sync pyglet

A | 添加了一个 Button Draw Theme

A | Magic Number (确信)

A | 尽量不继承Options

sync pyglet

A | Add theme

A | Add more Theme information

Enhance | Theme

sync pyglet

Add | add unifont

Enhance | use os.walk in font loading

Enhance | Use i18n in font loading

Enhance | doc

sync pyglet

Add | add 3.12 build option to build_rs

Fix | Button position have a z

sync pyglet

A | Logger.py 启动!

sync pyglet

Changed | Bump pyo3 to 0.20.0

add logger.py update

logger!

Add | more logger!

Add | lib-not-dr

some lib-not-dr
2023-11-20 20:12:56 +08:00

148 lines
6.3 KiB
Python

# -------------------------------
# Difficult Rocket
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
# All rights reserved
# -------------------------------
import os
import sys
import time
import shutil
import tomlkit
import platform
import traceback
import subprocess
from typing import Tuple, Dict
from pathlib import Path
from libs.utils import nuitka
if __name__ == '__main__':
compiler = nuitka.CompilerHelper()
# 修改 python 执行文件 为 运行时的 python
compiler.python_cmd = sys.executable
compiler.xml_path = Path(f"./build/compile_data-{time.time()}.xml")
compiler.report_path = Path(f"./build/compile_report-{time.time()}.xml")
# 检测 --github 参数
is_github = False
if '--github' in sys.argv:
is_github = True
compiler.use_ccache = False
compiler.show_memory = False
compiler.show_progress = False
compiler.output_path = Path('./build/github')
compiler.python_cmd = 'python'
compiler.save_xml = False
# 检测 --xml 参数
if '--xml' in sys.argv:
compiler.save_xml = True
sys.argv.remove('--xml')
if '--report' in sys.argv:
compiler.save_report = True
sys.argv.remove('--report')
# 检测 --output xx 参数
if '--output' in sys.argv:
# 输入的是输出目录
out_path = sys.argv[sys.argv.index('--output') + 1]
compiler.output_path = Path(out_path)
sys.argv.remove('--output')
sys.argv.remove(out_path)
# 检测 --no-pyglet-opt 参数
pyglet_optimizations = True
if pyglet_optimizations and '--no-pyglet-opt' not in sys.argv:
compiler.no_follow_import += [f'pyglet.app.{x}' for x in ['win32', 'xlib', 'cocoa']]
compiler.no_follow_import += [f'pyglet.input.{x}' for x in ['win32', 'linux', 'macos']]
compiler.no_follow_import += [f'pyglet.libs.{x}' for x in ['win32', 'x11', 'wayland', 'darwin', 'egl', 'headless']]
compiler.no_follow_import += [f'pyglet.window.{x}' for x in ['win32', 'xlib', 'cocoa', 'headless']]
compiler.no_follow_import += [f'pyglet.canvas.{x}' for x in ['win32', 'xlib', 'xlib_vidmoderstore', 'cocoa', 'headless']]
compiler.no_follow_import += [f'pyglet.gl.{x}' for x in ['win32', 'xlib', 'cocoa', 'headless']]
mult_plat_libs = ['app', 'input', 'libs', 'window', 'canvas', 'gl']
if platform.system() == "Windows":
for lib in mult_plat_libs:
compiler.no_follow_import.remove(f'pyglet.{lib}.win32')
elif platform.system() == "Linux":
for lib in mult_plat_libs:
for name in ('xlib', 'x11', 'wayland', 'egl'):
if f'pyglet.{lib}.{name}' in compiler.no_follow_import:
compiler.no_follow_import.remove(f'pyglet.{lib}.{name}')
compiler.no_follow_import.remove('pyglet.canvas.xlib_vidmoderstore')
elif platform.system() == "Darwin":
for lib in mult_plat_libs:
for name in ('cocoa', 'darwin', 'macos'):
if f'pyglet.{lib}.{name}' in compiler.no_follow_import:
compiler.no_follow_import.remove(f'pyglet.{lib}.{name}')
if is_github:
from pprint import pprint
pprint(compiler.option())
else:
compiler.output_path = Path(f'./build/nuitka-{platform.system().lower()}')
print(compiler.as_markdown())
print(compiler.gen_subprocess_cmd())
# 确认是否需要编译
# 如果包含 -y 参数 则直接编译
if (('-y' or '-n') not in sys.argv) and (not is_github):
while (do_compile := input('Do you want to compile this file? (y/n) ')) not in ['y', 'n']:
pass
elif '-y' in sys.argv:
do_compile = 'y'
elif is_github:
do_compile = 'y'
else:
do_compile = 'n'
if do_compile == 'y':
# 编译
time.sleep(1) # 等待 1s
start_time = time.time_ns()
subprocess.run(compiler.gen_subprocess_cmd())
print('Compile Done!')
print(f'Compile Time: {time.time_ns() - start_time} ns ({(time.time_ns() - start_time) / 1000_000_000} s)')
if is_github:
# 去除无用字体文件 (其实现在也不会打包字体文件了 因为 git lfs 没宽带了)
try:
shutil.rmtree(compiler.output_path / 'DR.dist/libs/fonts' / 'Fira_Code', ignore_errors=True)
shutil.rmtree(compiler.output_path / 'DR.dist/libs/fonts' / 'scientifica', ignore_errors=True)
shutil.rmtree(compiler.output_path / 'DR.dist/libs/fonts' / 'HarmonyOS_Sans' / 'HarmonyOS_Sans_Condensed', ignore_errors=True)
shutil.rmtree(compiler.output_path / 'DR.dist/libs/fonts' / 'HarmonyOS_Sans' / 'HarmonyOS_Sans', ignore_errors=True)
os.remove(compiler.output_path / 'DR.dist/libs/fonts' / 'Monocraft.otf')
os.remove(compiler.output_path / 'DR.dist/libs/fonts' / 'SmileySans-Oblique.ttf')
except Exception:
traceback.print_exc()
print('Remove Useless Files Done!')
else:
dist_dir_size = 0
dist_file_size: Dict[str, Tuple[int, float]] = {}
for path, sub_paths, sub_files in os.walk(compiler.output_path / 'DR.dist'):
for file in sub_files:
file_path = os.path.join(path, file)
dist_dir_size += os.path.getsize(file_path)
# 排除不需要记录的文件
if any(x in file_path for x in ('config', 'libs', 'assets')):
continue
dist_file_size[file_path] = (os.path.getsize(file_path), os.path.getsize(file_path) / 1024 / 1024)
compile_data = {'compile_time_ns': time.time_ns() - start_time,
'compile_time_s': (time.time_ns() - start_time) / 1000_000_000,
'dist_size': dist_dir_size,
'dist_size_mb': dist_dir_size / 1024 / 1024,
'compiler_data': compiler.str_option(),
'dist_file_size': dist_file_size}
with open(compiler.output_path / f'../compile_data-{time.time()}.toml', 'w', encoding='utf-8') as compile_data_file:
tomlkit.dump(compile_data, compile_data_file)
sys.exit(0)