137 lines
4.3 KiB
Python
137 lines
4.3 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
# -*- coding: utf-8 -*-
|
||
|
|
"""
|
||
|
|
PyMiniRacer DLL Auto-Fix Script
|
||
|
|
Automatically copy PyMiniRacer native DLL files after build
|
||
|
|
"""
|
||
|
|
|
||
|
|
import os
|
||
|
|
import shutil
|
||
|
|
import sys
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
def find_mini_racer_dll():
|
||
|
|
"""Find PyMiniRacer DLL files"""
|
||
|
|
print("Searching for PyMiniRacer DLL files...")
|
||
|
|
|
||
|
|
try:
|
||
|
|
import py_mini_racer
|
||
|
|
pkg_path = Path(py_mini_racer.__file__).parent
|
||
|
|
|
||
|
|
# Find DLL files
|
||
|
|
dll_files = list(pkg_path.glob("*.dll")) + list(pkg_path.glob("*.pyd"))
|
||
|
|
|
||
|
|
if dll_files:
|
||
|
|
print(f"OK: Found PyMiniRacer native library files:")
|
||
|
|
for dll in dll_files:
|
||
|
|
print(f" - {dll.name} ({dll.stat().st_size / 1024:.1f} KB)")
|
||
|
|
return dll_files
|
||
|
|
else:
|
||
|
|
print("WARN: No DLL files found")
|
||
|
|
# Try subdirectories
|
||
|
|
for subdir in pkg_path.iterdir():
|
||
|
|
if subdir.is_dir():
|
||
|
|
dll_files = list(subdir.glob("*.dll")) + list(subdir.glob("*.pyd"))
|
||
|
|
if dll_files:
|
||
|
|
print(f"OK: Found in subdirectory {subdir.name}:")
|
||
|
|
for dll in dll_files:
|
||
|
|
print(f" - {dll.name}")
|
||
|
|
return dll_files
|
||
|
|
|
||
|
|
return []
|
||
|
|
|
||
|
|
except ImportError:
|
||
|
|
print("ERROR: PyMiniRacer is not installed")
|
||
|
|
return []
|
||
|
|
except Exception as e:
|
||
|
|
print(f"ERROR: Failed to find DLL: {e}")
|
||
|
|
return []
|
||
|
|
|
||
|
|
def copy_dll_to_dist():
|
||
|
|
"""Copy DLL files to dist directory"""
|
||
|
|
print("\n" + "=" * 70)
|
||
|
|
print("PyMiniRacer DLL Auto-Fix Tool")
|
||
|
|
print("=" * 70)
|
||
|
|
|
||
|
|
# Find dist directory
|
||
|
|
dist_dir = Path("dist/MultiPlatformGUI/_internal")
|
||
|
|
|
||
|
|
if not dist_dir.exists():
|
||
|
|
print(f"ERROR: dist directory not found: {dist_dir}")
|
||
|
|
print(" Please run: python quick_build.py or python build_production.py")
|
||
|
|
return False
|
||
|
|
|
||
|
|
print(f"OK: Found dist directory: {dist_dir}")
|
||
|
|
|
||
|
|
# Find source DLL
|
||
|
|
dll_files = find_mini_racer_dll()
|
||
|
|
|
||
|
|
if not dll_files:
|
||
|
|
print("\nERROR: Cannot find PyMiniRacer DLL files")
|
||
|
|
print(" Please ensure it is installed: pip install py-mini-racer")
|
||
|
|
return False
|
||
|
|
|
||
|
|
# Copy DLL files
|
||
|
|
print(f"\nCopying DLL files to dist directory...")
|
||
|
|
|
||
|
|
success_count = 0
|
||
|
|
for dll_file in dll_files:
|
||
|
|
try:
|
||
|
|
# Target path (put in _internal root directory)
|
||
|
|
target = dist_dir / dll_file.name
|
||
|
|
|
||
|
|
# Copy file
|
||
|
|
shutil.copy2(dll_file, target)
|
||
|
|
print(f"OK: Copied {dll_file.name} -> {target}")
|
||
|
|
success_count += 1
|
||
|
|
|
||
|
|
# Also copy to py_mini_racer subdirectory (if exists)
|
||
|
|
py_mini_racer_dir = dist_dir / "py_mini_racer"
|
||
|
|
if py_mini_racer_dir.exists():
|
||
|
|
target2 = py_mini_racer_dir / dll_file.name
|
||
|
|
shutil.copy2(dll_file, target2)
|
||
|
|
print(f"OK: Copied {dll_file.name} -> {target2}")
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
print(f"ERROR: Failed to copy {dll_file.name}: {e}")
|
||
|
|
|
||
|
|
if success_count > 0:
|
||
|
|
print(f"\nSUCCESS: Copied {success_count} file(s)")
|
||
|
|
print("\nVerification:")
|
||
|
|
print(f" Checking if file exists: {dist_dir / 'mini_racer.dll'}")
|
||
|
|
|
||
|
|
if (dist_dir / 'mini_racer.dll').exists():
|
||
|
|
size = (dist_dir / 'mini_racer.dll').stat().st_size / (1024 * 1024)
|
||
|
|
print(f" OK: mini_racer.dll exists ({size:.1f} MB)")
|
||
|
|
|
||
|
|
print("\nYou can now run:")
|
||
|
|
print(" cd dist\\MultiPlatformGUI")
|
||
|
|
print(" .\\main.exe")
|
||
|
|
print("\n PDD platform should work properly now!")
|
||
|
|
return True
|
||
|
|
else:
|
||
|
|
print("\nERROR: No files were copied successfully")
|
||
|
|
return False
|
||
|
|
|
||
|
|
def auto_fix_after_build():
|
||
|
|
"""Auto-fix after build (called by build script)"""
|
||
|
|
return copy_dll_to_dist()
|
||
|
|
|
||
|
|
def main():
|
||
|
|
"""Main function"""
|
||
|
|
success = copy_dll_to_dist()
|
||
|
|
|
||
|
|
if not success:
|
||
|
|
print("\nAlternative solutions:")
|
||
|
|
print(" 1. Manually install Node.js (to enable execjs)")
|
||
|
|
print(" 2. Check if PyMiniRacer is installed correctly")
|
||
|
|
print(" 3. Try a different version of py-mini-racer")
|
||
|
|
sys.exit(1)
|
||
|
|
|
||
|
|
print("\nDLL fix completed successfully!")
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|
||
|
|
|
||
|
|
|