diff --git a/compile/compile_batchpatcher.ps1 b/compile/compile_batchpatcher.ps1 index 02c303c6a..f52c6213c 100644 --- a/compile/compile_batchpatcher.ps1 +++ b/compile/compile_batchpatcher.ps1 @@ -14,11 +14,6 @@ $this_noprompt_arg = if ($this_noprompt) {'-noprompt'} else {''} $venv_name_arg = if ($venv_name) {"-venv_name $venv_name"} else {''} . $rootPath/install_python_venv.ps1 $this_noprompt_arg $venv_name_arg -Write-Host "Initializing python virtual environment..." -$this_noprompt_arg = if ($this_noprompt) {'-noprompt'} else {''} -$venv_name_arg = if ($venv_name) {"-venv_name $venv_name"} else {''} -. $rootPath/install_python_venv.ps1 $this_noprompt_arg $venv_name_arg - $current_working_dir = (Get-Location).Path Set-Location -LiteralPath (Resolve-Path -LiteralPath "$rootPath/Tools/BatchPatcher/src").Path @@ -40,7 +35,6 @@ if (Test-Path -Path $finalExecutablePath) { Write-Host "Compiling BatchPatcher..." $pyInstallerArgs = @{ 'exclude-module' = @( - '' 'dl_translate', 'torch' 'PyQt5' @@ -48,13 +42,15 @@ $pyInstallerArgs = @{ 'PyGLM' 'numpy' 'multiprocessing' - 'pykotor-gl ' + 'pykotor-gl' ) + 'clean' = $true 'console' = $true 'onefile' = $true 'noconfirm' = $true 'name' = 'K_BatchPatcher' 'distpath' = ($rootPath + $pathSep + 'dist') + 'upx-dir' = "C:\GitHub\upx-win64" } $pyInstallerArgs = $pyInstallerArgs.GetEnumerator() | ForEach-Object { @@ -63,8 +59,11 @@ $pyInstallerArgs = $pyInstallerArgs.GetEnumerator() | ForEach-Object { if ($value -is [System.Array]) { # Handle array values - $value -join "--$key=" - $value = "--$key=$value" + $arr = @() + foreach ($elem in $value) { + $arr += "--$key=$elem" + } + $arr } else { # Handle key-value pair arguments if ($value -eq $true) { diff --git a/compile/compile_gui_duplicator.ps1 b/compile/compile_gui_duplicator.ps1 index 0b96b1406..662a169f9 100644 --- a/compile/compile_gui_duplicator.ps1 +++ b/compile/compile_gui_duplicator.ps1 @@ -13,15 +13,33 @@ $this_noprompt_arg = if ($this_noprompt) {'-noprompt'} else {''} $venv_name_arg = if ($venv_name) {"-venv_name $venv_name"} else {''} . $rootPath/install_python_venv.ps1 $this_noprompt_arg $venv_name_arg -Write-Host "Installing required packages to build the holocron toolset..." +Write-Host "Installing required packages to build the gui duplicator..." . $pythonExePath -m pip install --upgrade pip --prefer-binary --progress-bar on . $pythonExePath -m pip install pyinstaller --prefer-binary --progress-bar on . $pythonExePath -m pip install -r ($rootPath + $pathSep + "Libraries" + $pathSep + "PyKotor" + $pathSep + "requirements.txt") --prefer-binary --compile --progress-bar on -U +$current_working_dir = (Get-Location).Path +Set-Location -LiteralPath (Resolve-Path -LiteralPath "$rootPath/Tools/GuiDuplicator/src").Path + +# Determine the final executable path +$finalExecutablePath = $null +if ((Get-OS) -eq "Windows") { + $finalExecutablePath = "$rootPath\dist\GuiDuplicator.exe" +} elseif ((Get-OS) -eq "Linux") { + $finalExecutablePath = "$rootPath/dist/GuiDuplicator" +} elseif ((Get-OS) -eq "Mac") { + $finalExecutablePath = "$rootPath/dist/GuiDuplicator.app" +} + +# Delete the final executable if it exists +if (Test-Path -Path $finalExecutablePath) { + Remove-Item -Path $finalExecutablePath -Force +} + +Write-Host "Compiling GuiDuplicator..." Write-Host "EXTRA PYTHONPATH: '$env:PYTHONPATH'" $pyInstallerArgs = @{ 'exclude-module' = @( - '', 'numpy', 'PyQt5', 'PIL', @@ -57,62 +75,60 @@ $pyInstallerArgs = @{ 'install_playwright', 'greenlet', 'cssselect', - 'beautifulsoup4 ' + 'beautifulsoup4' ) 'clean' = $true 'console' = $true 'onefile' = $true 'noconfirm' = $true 'name' = "GuiDuplicator" - 'distpath'=($rootPath + $pathSep + "dist") - 'upx-dir' = "C:\GitHub\upx-win32" + 'distpath' = ($rootPath + $pathSep + 'dist') + 'upx-dir' = "C:\GitHub\upx-win64" } -$pyInstallerArgsString = ($pyInstallerArgs.GetEnumerator() | ForEach-Object { + +$pyInstallerArgs = $pyInstallerArgs.GetEnumerator() | ForEach-Object { $key = $_.Key $value = $_.Value if ($value -is [System.Array]) { # Handle array values - $value -join " --$key=" - $value = " --$key=$value " + $arr = @() + foreach ($elem in $value) { + $arr += "--$key=$elem" + } + $arr } else { # Handle key-value pair arguments if ($value -eq $true) { - "--$key " + "--$key" + } elseif ($value -eq $false) { } else { - "--$key=$value " + "--$key=$value" } } -}) -join '' - -# Format PYTHONPATH paths and add them to the pyInstallerArgsString -$pythonPaths = $env:PYTHONPATH -split ';' -$pythonPathArgs = $pythonPaths | ForEach-Object { "--path=$_" } -$pythonPathArgsString = $pythonPathArgs -join ' ' +} -# Determine the final executable path -$finalExecutablePath = $null -if ((Get-OS) -eq "Windows") { - $finalExecutablePath = "$rootPath\dist\GuiDuplicator.exe" -} elseif ((Get-OS) -eq "Linux") { - $finalExecutablePath = "$rootPath/dist/GuiDuplicator" -} elseif ((Get-OS) -eq "Mac") { - $finalExecutablePath = "$rootPath/dist/GuiDuplicator.app" +# Add PYTHONPATH paths as arguments +$env:PYTHONPATH -split ';' | ForEach-Object { + $pyInstallerArgs += "--path=$_" } -# Delete the final executable if it exists -if (Test-Path -Path $finalExecutablePath) { - Remove-Item -Path $finalExecutablePath -Force +# Define each argument as an element in an array +$argumentsArray = @( + "-m", + "PyInstaller" +) +# Unpack $pyInstallerArgs into $argumentsArray +foreach ($arg in $pyInstallerArgs) { + $argumentsArray += $arg } -# Combine pyInstallerArgsString with pythonPathArgsString -$finalPyInstallerArgsString = "$pythonPathArgsString $pyInstallerArgsString" +# Append the final script path +$argumentsArray += "__main__.py" -$current_working_dir = (Get-Location).Path -Set-Location -LiteralPath (Resolve-Path -LiteralPath "$rootPath/Tools/GuiDuplicator/src").Path -$command = "$pythonExePath -m PyInstaller $finalPyInstallerArgsString `"__main__.py`"" -Write-Host $command -Invoke-Expression $command +# Use the call operator with the arguments array +Write-Host "Executing command: $pythonExePath $argumentsArray" +& $pythonExePath $argumentsArray # Check if the final executable exists if (-not (Test-Path -Path $finalExecutablePath)) { diff --git a/compile/compile_holopatcher.ps1 b/compile/compile_holopatcher.ps1 index 27b069c85..2d5f47aea 100644 --- a/compile/compile_holopatcher.ps1 +++ b/compile/compile_holopatcher.ps1 @@ -36,7 +36,6 @@ Write-Host "Compiling HoloPatcher..." $iconExtension = if ((Get-OS) -eq 'Mac') {'icns'} else {'ico'} $pyInstallerArgs = @{ 'exclude-module' = @( - '', 'numpy', 'PyQt5', 'PIL', @@ -72,7 +71,7 @@ $pyInstallerArgs = @{ 'install_playwright', 'greenlet', 'cssselect', - 'beautifulsoup4 ' + 'beautifulsoup4' ) 'clean' = $true 'noconsole' = $true @@ -90,8 +89,11 @@ $pyInstallerArgs = $pyInstallerArgs.GetEnumerator() | ForEach-Object { if ($value -is [System.Array]) { # Handle array values - $value -join "--$key=" - $value = "--$key=$value" + $arr = @() + foreach ($elem in $value) { + $arr += "--$key=$elem" + } + $arr } else { # Handle key-value pair arguments if ($value -eq $true) { diff --git a/compile/compile_kotordiff.ps1 b/compile/compile_kotordiff.ps1 index 44c2ed9e8..36afd6f18 100644 --- a/compile/compile_kotordiff.ps1 +++ b/compile/compile_kotordiff.ps1 @@ -13,17 +13,33 @@ $this_noprompt_arg = if ($this_noprompt) {'-noprompt'} else {''} $venv_name_arg = if ($venv_name) {"-venv_name $venv_name"} else {''} . $rootPath/install_python_venv.ps1 $this_noprompt_arg $venv_name_arg -Write-Host "Installing required packages to build kotordiff..." +Write-Host "Installing required packages to build the kotordiff tool..." . $pythonExePath -m pip install --upgrade pip --prefer-binary --progress-bar on . $pythonExePath -m pip install pyinstaller --prefer-binary --progress-bar on -. $pythonExePath -m pip install -r ($rootPath + $pathSep + "Tools" + $pathSep + "KotorDiff" + $pathSep + "requirements.txt") --prefer-binary --progress-bar on -U -. $pythonExePath -m pip install -r ($rootPath + $pathSep + "Tools" + $pathSep + "KotorDiff" + $pathSep + "recommended.txt") --prefer-binary --progress-bar on -U -. $pythonExePath -m pip install -r ($rootPath + $pathSep + "Libraries" + $pathSep + "PyKotor" + $pathSep + "requirements.txt") --prefer-binary --progress-bar on -U +. $pythonExePath -m pip install -r ($rootPath + $pathSep + "Libraries" + $pathSep + "PyKotor" + $pathSep + "requirements.txt") --prefer-binary --compile --progress-bar on -U + +$current_working_dir = (Get-Location).Path +Set-Location -LiteralPath (Resolve-Path -LiteralPath "$rootPath/Tools/KotorDiff/src").Path + +# Determine the final executable path +$finalExecutablePath = $null +if ((Get-OS) -eq "Windows") { + $finalExecutablePath = "$rootPath\dist\KotorDiff.exe" +} elseif ((Get-OS) -eq "Linux") { + $finalExecutablePath = "$rootPath/dist/KotorDiff" +} elseif ((Get-OS) -eq "Mac") { + $finalExecutablePath = "$rootPath/dist/KotorDiff.app" +} + +# Delete the final executable if it exists +if (Test-Path -Path $finalExecutablePath) { + Remove-Item -Path $finalExecutablePath -Force +} Write-Host "Compiling KotorDiff..." +Write-Host "EXTRA PYTHONPATH: '$env:PYTHONPATH'" $pyInstallerArgs = @{ 'exclude-module' = @( - '', 'numpy', 'PyQt5', 'PIL', @@ -49,7 +65,9 @@ $pyInstallerArgs = @{ 'ruff', 'pylint', 'pykotor.gl', + 'pykotorgl', 'pykotor.font', + 'pykotorfont' 'pykotor.secure_xml', 'mypy-extensions', 'mypy', @@ -57,62 +75,60 @@ $pyInstallerArgs = @{ 'install_playwright', 'greenlet', 'cssselect', - 'beautifulsoup4 ' + 'beautifulsoup4' ) 'clean' = $true - 'noconsole' = $true + 'console' = $true 'onefile' = $true 'noconfirm' = $true - 'distpath' = ($rootPath + $pathSep + "dist") - 'name' = 'KotorDiff' - 'upx-dir' = "$env:USERPROFILE\Documents\GitHub\upx-win32" + 'name' = "KotorDiff" + 'distpath' = ($rootPath + $pathSep + 'dist') + 'upx-dir' = "C:\GitHub\upx-win64" } -$pyInstallerArgsString = ($pyInstallerArgs.GetEnumerator() | ForEach-Object { + +$pyInstallerArgs = $pyInstallerArgs.GetEnumerator() | ForEach-Object { $key = $_.Key $value = $_.Value if ($value -is [System.Array]) { # Handle array values - $value -join " --$key=" - $value = " --$key=$value " + $arr = @() + foreach ($elem in $value) { + $arr += "--$key=$elem" + } + $arr } else { # Handle key-value pair arguments if ($value -eq $true) { - "--$key " + "--$key" + } elseif ($value -eq $false) { } else { - "--$key=$value " + "--$key=$value" } } -}) -join '' - -# Format PYTHONPATH paths and add them to the pyInstallerArgsString -$pythonPaths = $env:PYTHONPATH -split ';' -$pythonPathArgs = $pythonPaths | ForEach-Object { "--path=$_" } -$pythonPathArgsString = $pythonPathArgs -join ' ' +} -# Determine the final executable path -$finalExecutablePath = $null -if ((Get-OS) -eq "Windows") { - $finalExecutablePath = "$rootPath\dist\KotorDiff.exe" -} elseif ((Get-OS) -eq "Linux") { - $finalExecutablePath = "$rootPath/dist/KotorDiff" -} elseif ((Get-OS) -eq "Mac") { - $finalExecutablePath = "$rootPath/dist/KotorDiff.app" +# Add PYTHONPATH paths as arguments +$env:PYTHONPATH -split ';' | ForEach-Object { + $pyInstallerArgs += "--path=$_" } -# Delete the final executable if it exists -if (Test-Path -Path $finalExecutablePath) { - Remove-Item -Path $finalExecutablePath -Recurse -Force +# Define each argument as an element in an array +$argumentsArray = @( + "-m", + "PyInstaller" +) +# Unpack $pyInstallerArgs into $argumentsArray +foreach ($arg in $pyInstallerArgs) { + $argumentsArray += $arg } -# Combine pyInstallerArgsString with pythonPathArgsString -$finalPyInstallerArgsString = "$pythonPathArgsString $pyInstallerArgsString" +# Append the final script path +$argumentsArray += "__main__.py" -$current_working_dir = (Get-Location).Path -Set-Location -LiteralPath (Resolve-Path -LiteralPath "$rootPath/Tools/KotorDiff/src").Path -$command = "$pythonExePath -m PyInstaller $finalPyInstallerArgsString `"__main__.py`"" -Write-Host $command -Invoke-Expression $command +# Use the call operator with the arguments array +Write-Host "Executing command: $pythonExePath $argumentsArray" +& $pythonExePath $argumentsArray # Check if the final executable exists if (-not (Test-Path -Path $finalExecutablePath)) { @@ -125,4 +141,4 @@ Set-Location -LiteralPath $current_working_dir if (-not $this_noprompt) { Write-Host "Press any key to exit..." $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") -} \ No newline at end of file +} diff --git a/compile/compile_toolset.ps1 b/compile/compile_toolset.ps1 index 5e9642e04..60318be50 100644 --- a/compile/compile_toolset.ps1 +++ b/compile/compile_toolset.ps1 @@ -36,9 +36,8 @@ Write-Host "Extra PYTHONPATH paths:\n'$env:PYTHONPATH'\n\n" $iconExtension = if ((Get-OS) -eq 'Mac') {'icns'} else {'ico'} $pyInstallerArgs = @{ 'exclude-module' = @( - '', 'dl_translate', - 'torch ' + 'torch' ) 'clean' = $true 'console' = $true @@ -56,8 +55,11 @@ $pyInstallerArgs = $pyInstallerArgs.GetEnumerator() | ForEach-Object { if ($value -is [System.Array]) { # Handle array values - $value -join "--$key=" - $value = "--$key=$value" + $arr = @() + foreach ($elem in $value) { + $arr += "--$key=$elem" + } + $arr } else { # Handle key-value pair arguments if ($value -eq $true) {