2023-09-28 15:55:11 +02:00
#!/usr/bin/python3
2023-11-01 12:33:19 +01:00
# SPDX-License-Identifier: LicenseRef-EliasSteurerTachiom OR AGPL-3.0-only
2023-09-28 15:55:11 +02:00
import os
import util
2023-10-12 13:25:10 +02:00
import shutil
2023-09-28 15:55:11 +02:00
import defines
from pathlib import Path
from execute_util import execute
import argparse
def main ( ) :
# Parse build folder as arugment
2023-11-29 10:36:58 +01:00
parser = argparse . ArgumentParser ( description = ' Build K3000Map to the bin build folder: D:/Backup/Code/Qt/build_ScreenPlay_Qt_6.6.1_MSVC_Debug/bin ' )
2023-09-28 15:55:11 +02:00
parser . add_argument ( ' --build_path ' , dest = " build_path " , type = str , help = ' Build folder ' )
parser . add_argument ( ' --skip_if_exists ' , dest = " skip_if_exists " , default = False , action = " store_true " , help = ' Skips the build if the index.html file exists. This is used for faster CMake configure ' )
args = parser . parse_args ( )
if not args . build_path :
print ( " ERROR: Please specify the build folder " )
2023-11-29 10:36:58 +01:00
print ( " py build_godot.py --build_path D:/Backup/Code/Qt/build_ScreenPlay_Qt_6.6.1_MSVC_Debug/bin/ " )
2023-09-28 15:55:11 +02:00
exit ( )
# if build path exists and contains a index.html file, skip the build
if args . skip_if_exists :
screenPlayWallpaperGodot_executable = Path ( args . build_path ) . joinpath ( defines . SCREENPLAYWALLPAPER_GODOT_EXECUTABLE )
if screenPlayWallpaperGodot_executable . exists :
print ( f " Skipping build, because { defines . SCREENPLAYWALLPAPER_GODOT_EXECUTABLE } exists " )
exit ( 1 )
abs_build_path = args . build_path
if not os . path . isabs ( args . build_path ) :
abs_build_path = os . path . abspath ( os . path . join ( os . getcwd ( ) , args . build_path ) )
2023-11-02 12:50:29 +01:00
if ' Debug ' in abs_build_path :
build_type = " debug "
else :
build_type = " release "
2023-09-28 15:55:11 +02:00
2023-11-02 12:50:29 +01:00
build_godot ( abs_build_path , build_type )
2023-09-28 15:55:11 +02:00
2023-11-02 12:50:29 +01:00
def build_godot ( abs_build_path : str , build_type : str ) :
2023-09-28 15:55:11 +02:00
project_path = Path ( util . repo_root_path ( ) ) . joinpath ( " ScreenPlayWallpaper/Godot/ScreenPlayGodot " ) . resolve ( )
2023-11-02 12:50:29 +01:00
apps_path = os . path . join ( defines . THIRDPATH_PATH , " Godot " )
2023-09-28 15:55:11 +02:00
godot_executable = os . path . join ( apps_path , defines . GODOT_EDITOR_EXECUTABLE )
screenPlayWallpaperGodot_executable = Path ( abs_build_path ) . joinpath ( defines . SCREENPLAYWALLPAPER_GODOT_EXECUTABLE ) . resolve ( )
2023-10-12 13:25:10 +02:00
2023-11-02 12:50:29 +01:00
if ' debug ' in build_type :
2023-10-12 13:25:10 +02:00
export_type = " --export-debug "
else :
export_type = " --export-release "
export_command = f ' " { godot_executable } " -v --headless { export_type } " Windows Desktop " " { screenPlayWallpaperGodot_executable } " '
2023-09-28 15:55:11 +02:00
# We get random error on successful export, so lets ignore it
execute ( command = export_command , workingDir = project_path , ignore_error = True )
2023-10-12 13:25:10 +02:00
if ' Debug ' in abs_build_path :
lib_name = " ScreenPlayGodotWallpaper-d.dll "
else :
lib_name = " ScreenPlayGodotWallpaper.dll "
# Construct the source path for the DLL
dll_source_path = project_path . joinpath ( f " ScreenPlayGodotWallpaper/lib/Windows-AMD64/ { lib_name } " )
# Print a warning message
print ( f " ⚠️ Copying { dll_source_path } to { abs_build_path } " )
# Copy the DLL
shutil . copy ( dll_source_path , abs_build_path )
2023-09-28 15:55:11 +02:00
if __name__ == " __main__ " :
main ( )