This commit is contained in:
恍兮惚兮 2024-04-26 23:13:46 +08:00
parent 087ceabbab
commit f558b0c0c1
3 changed files with 75 additions and 120 deletions

View File

@ -35,9 +35,7 @@ jobs:
python-version: '3.11' python-version: '3.11'
architecture: x64 architecture: x64
- name: Install Python 3.11 req - name: Install Python 3.11 req
run: | run: pip install cmake pefile requests
pip install --upgrade pip
pip install cmake pefile requests
- name: Run build script - name: Run build script
run: | run: |
python build.py --github-actions --arch ${{ matrix.architecture }} python build.py --github-actions --arch ${{ matrix.architecture }}

View File

@ -37,9 +37,7 @@ jobs:
python-version: '3.11' python-version: '3.11'
architecture: x64 architecture: x64
- name: Install Python 3.11 req - name: Install Python 3.11 req
run: | run: pip install cmake pefile requests
pip install --upgrade pip
pip install cmake pefile requests
- name: Run build script - name: Run build script
run: | run: |
python build.py --github-actions --arch ${{ matrix.architecture }} python build.py --github-actions --arch ${{ matrix.architecture }}

183
build.py
View File

@ -1,14 +1,8 @@
import argparse import os, sys
import os import shutil
import shutil,json
import subprocess import subprocess
import requests import requests
py37Path32 = os.path.join(
os.environ["LOCALAPPDATA"], "Programs\\Python\\Python37-32\\python.exe"
)
py37Path64 = os.path.join(
os.environ["LOCALAPPDATA"], "Programs\\Python\\Python37\\python.exe"
)
msbuildPath = "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\MSBuild\\Current\\Bin\\MSBuild.exe" msbuildPath = "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\MSBuild\\Current\\Bin\\MSBuild.exe"
vcvars32Path = "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvars32.bat" vcvars32Path = "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvars32.bat"
vcvars64Path = "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat" vcvars64Path = "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat"
@ -35,8 +29,6 @@ ocrModelUrl = "https://github.com/HIllya51/RESOURCES/releases/download/ocr_model
availableLocales = ["cht", "en", "ja", "ko", "ru", "zh"] availableLocales = ["cht", "en", "ja", "ko", "ru", "zh"]
prebuiltcommon="https://github.com/HIllya51/LunaTranslator_extra_build/releases/download/common/ALL.zip"
rootDir = os.path.dirname(__file__) rootDir = os.path.dirname(__file__)
@ -50,20 +42,6 @@ def createPluginDirs():
os.mkdir(pluginDir) os.mkdir(pluginDir)
def installDependencies(arch):
os.chdir(rootDir)
if arch=='x86':
subprocess.run(f"{py37Path32} -m pip install --upgrade pip")
else:
subprocess.run(f"{py37Path64} -m pip install --upgrade pip")
os.chdir(rootDir + "\\LunaTranslator")
if arch=='x86':
subprocess.run(f"{py37Path32} -m pip install -r requirements.txt")
else:
subprocess.run(f"{py37Path64} -m pip install -r requirements.txt")
def installVCLTL(): def installVCLTL():
os.chdir(rootDir + "\\temp") os.chdir(rootDir + "\\temp")
subprocess.run(f"curl -LO {vcltlFile}") subprocess.run(f"curl -LO {vcltlFile}")
@ -94,8 +72,26 @@ def downloadBrotli():
def downloadcommon(): def downloadcommon():
os.chdir(rootDir + "\\temp") os.chdir(rootDir + "\\temp")
subprocess.run(f"curl -LO {prebuiltcommon}") subprocess.run(
subprocess.run(f"7z x ALL.zip -oALL") f"curl -LO https://github.com/HIllya51/RESOURCES/releases/download/common/lr.zip"
)
subprocess.run(f"7z x lr.zip -oALL")
subprocess.run(
f"curl -LO https://github.com/HIllya51/RESOURCES/releases/download/common/mecab.zip"
)
subprocess.run(f"7z x mecab.zip -oALL")
subprocess.run(
f"curl -LO https://github.com/HIllya51/RESOURCES/releases/download/common/ocr.zip"
)
subprocess.run(f"7z x ocr.zip -oALL")
subprocess.run(
f"curl -LO https://github.com/HIllya51/RESOURCES/releases/download/common/webview.zip"
)
subprocess.run(f"7z x webview.zip -oALL")
subprocess.run(
f"curl -LO https://github.com/HIllya51/RESOURCES/releases/download/common/magpie.zip"
)
subprocess.run(f"7z x magpie.zip -oALL")
def move_directory_contents(source_dir, destination_dir): def move_directory_contents(source_dir, destination_dir):
contents = os.listdir(source_dir) contents = os.listdir(source_dir)
@ -106,12 +102,13 @@ def downloadcommon():
shutil.move(item_path, destination_dir) shutil.move(item_path, destination_dir)
except: except:
for k in os.listdir(item_path): for k in os.listdir(item_path):
shutil.move(os.path.join(item_path,k), os.path.join(destination_dir,item)) shutil.move(
os.path.join(item_path, k), os.path.join(destination_dir, item)
move_directory_contents(
"ALL/ALL", f"{rootDir}/LunaTranslator/files/plugins"
) )
move_directory_contents("ALL/ALL", f"{rootDir}/LunaTranslator/files/plugins")
def downloadLocaleEmulator(): def downloadLocaleEmulator():
os.chdir(rootDir + "\\temp") os.chdir(rootDir + "\\temp")
subprocess.run(f"curl -LO {localeEmulatorFile}") subprocess.run(f"curl -LO {localeEmulatorFile}")
@ -170,10 +167,11 @@ def downloadOCRModel(locale):
os.remove(f"{locale}.zip") os.remove(f"{locale}.zip")
def buildLunaHook(): def buildLunaHook():
for ass in requests.get('https://api.github.com/repos/HIllya51/LunaHook/releases/latest').json()['assets']: for ass in requests.get(
if ass['name']=='Release_English.zip': "https://api.github.com/repos/HIllya51/LunaHook/releases/latest"
).json()["assets"]:
if ass["name"] == "Release_English.zip":
os.chdir(rootDir + "\\temp") os.chdir(rootDir + "\\temp")
subprocess.run(f"curl -LO {ass['browser_download_url']}") subprocess.run(f"curl -LO {ass['browser_download_url']}")
subprocess.run(f"7z x Release_English.zip") subprocess.run(f"7z x Release_English.zip")
@ -194,6 +192,7 @@ def buildLunaHook():
f"{rootDir}/LunaTranslator/files/plugins/LunaHook", f"{rootDir}/LunaTranslator/files/plugins/LunaHook",
) )
def buildPlugins(): def buildPlugins():
os.chdir(rootDir + "\\plugins\\scripts") os.chdir(rootDir + "\\plugins\\scripts")
subprocess.run( subprocess.run(
@ -212,85 +211,14 @@ def buildPlugins():
subprocess.run(f"python copytarget.py 0") subprocess.run(f"python copytarget.py 0")
def buildLunaTranslator(arch):
os.chdir(rootDir + "\\LunaTranslator")
if arch=='x86':
subprocess.run(
f"{py37Path32} -m nuitka --standalone --assume-yes-for-downloads --windows-disable-console --plugin-enable=pyqt5 --output-dir=..\\build\\x86 LunaTranslator\\LunaTranslator_main.py --windows-icon-from-ico=..\\plugins\\exec\\luna.ico"
)
subprocess.run(f"cmd /c pack32.cmd")
else:
subprocess.run(
f"{py37Path64} -m nuitka --standalone --assume-yes-for-downloads --windows-disable-console --plugin-enable=pyqt5 --output-dir=..\\build\\x64 LunaTranslator\\LunaTranslator_main.py --windows-icon-from-ico=..\\plugins\\exec\\luna.ico"
)
subprocess.run(f"cmd /c pack64.cmd")
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser() arch = sys.argv[1]
parser.add_argument(
"--skip-download",
action="store_true",
default=False,
help="Skip download steps",
)
parser.add_argument(
"--skip-python-dependencies",
action="store_true",
default=False,
help="Skip Python dependencies installation",
)
parser.add_argument(
"--skip-vc-ltl",
action="store_true",
default=False,
help="Skip VC-LTL installation",
)
parser.add_argument(
"--skip-build", action="store_true", default=False, help="Skip build steps"
)
parser.add_argument(
"--clean-temp",
action="store_true",
default=False,
help="Clean temp directory before building",
)
parser.add_argument(
"--clean-plugins",
action="store_true",
default=False,
help="Clean plugins directory before building",
)
parser.add_argument(
"--github-actions",
action="store_true",
default=False,
help="Specify if running in a GitHub Actions environment",
)
parser.add_argument(
"--arch",
)
args = parser.parse_args()
os.chdir(rootDir) os.chdir(rootDir)
if args.clean_temp: os.makedirs("temp", exist_ok=True)
os.system('powershell.exe -Command "Remove-Item -Path .\\temp -Recurse -Force"')
if not os.path.exists("temp"):
os.mkdir("temp")
if args.clean_plugins:
os.system(
'powershell.exe -Command "Remove-Item -Path .\\LunaTranslator\\files\\plugins -Recurse -Force"'
)
createPluginDirs() createPluginDirs()
if args.github_actions: def __1():
py37Path32 = "C:\\hostedtoolcache\\windows\\Python\\3.7.9\\x86\\python.exe"
py37Path64 = "C:\\hostedtoolcache\\windows\\Python\\3.7.9\\x64\\python.exe"
if not args.skip_python_dependencies:
installDependencies(args.arch)
if not args.skip_download:
downloadBrotli() downloadBrotli()
downloadLocaleEmulator() downloadLocaleEmulator()
downloadNtlea() downloadNtlea()
@ -298,8 +226,39 @@ if __name__ == "__main__":
downloadOCRModel("ja") downloadOCRModel("ja")
downloadcommon() downloadcommon()
buildLunaHook() buildLunaHook()
if not args.skip_build:
if not args.skip_vc_ltl: def __2():
installVCLTL() installVCLTL()
buildPlugins() buildPlugins()
buildLunaTranslator(args.arch)
def __3():
os.chdir(rootDir)
py37Path32 = "C:\\hostedtoolcache\\windows\\Python\\3.7.9\\x86\\python.exe"
py37Path64 = "C:\\hostedtoolcache\\windows\\Python\\3.7.9\\x64\\python.exe"
if arch == "x86":
subprocess.run(f"{py37Path32} -m pip install --upgrade pip")
else:
subprocess.run(f"{py37Path64} -m pip install --upgrade pip")
os.chdir(rootDir + "\\LunaTranslator")
if arch == "x86":
subprocess.run(f"{py37Path32} -m pip install -r requirements.txt")
subprocess.run(
f"{py37Path32} -m nuitka --standalone --assume-yes-for-downloads --windows-disable-console --plugin-enable=pyqt5 --output-dir=..\\build\\x86 LunaTranslator\\LunaTranslator_main.py --windows-icon-from-ico=..\\plugins\\exec\\luna.ico"
)
else:
subprocess.run(f"{py37Path64} -m pip install -r requirements.txt")
subprocess.run(
f"{py37Path64} -m nuitka --standalone --assume-yes-for-downloads --windows-disable-console --plugin-enable=pyqt5 --output-dir=..\\build\\x64 LunaTranslator\\LunaTranslator_main.py --windows-icon-from-ico=..\\plugins\\exec\\luna.ico"
)
__1()
__2()
__3()
if arch == "x86":
subprocess.run(f"cmd /c pack32.cmd")
else:
subprocess.run(f"cmd /c pack64.cmd")