diff --git a/.gitignore b/.gitignore index 72e84c0e..da3b0bf9 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ dist/ # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec +.upx/ # Dev settings settings.toml diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 9660b24e..e9d4be48 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -2,19 +2,21 @@ & "$PSScriptRoot/compile_resources.ps1" +$ProjectRoot = "$PSScriptRoot/.." $SupportsSplashScreen = [System.Convert]::ToBoolean($(uv run --active python -c "import _tkinter; print(hasattr(_tkinter, '__file__'))")) $arguments = @( - "$PSScriptRoot/../src/AutoSplit.py", + "$ProjectRoot/src/AutoSplit.py", '--onefile', '--windowed', - '--additional-hooks-dir=Pyinstaller/hooks', '--optimize 2', # Remove asserts and docstrings for smaller build - "--add-data=pyproject.toml$([System.IO.Path]::PathSeparator).", - '--icon=res/icon.ico') + "--additional-hooks-dir=$ProjectRoot/Pyinstaller/hooks", + "--add-data=$ProjectRoot/pyproject.toml$([System.IO.Path]::PathSeparator).", + "--upx-dir=$PSScriptRoot/.upx" + "--icon=$ProjectRoot/res/icon.ico") if ($SupportsSplashScreen) { # https://github.com/pyinstaller/pyinstaller/issues/9022 - $arguments += @('--splash=res/splash.png') + $arguments += @("--splash=$ProjectRoot/res/splash.png") } if ($IsWindows) { $arguments += @( @@ -25,10 +27,10 @@ if ($IsWindows) { Start-Process -Wait -NoNewWindow uv -ArgumentList $(@('run', '--active', 'pyinstaller') + $arguments) If ($IsLinux) { - Move-Item -Force $PSScriptRoot/../dist/AutoSplit $PSScriptRoot/../dist/AutoSplit.elf + Move-Item -Force $ProjectRoot/dist/AutoSplit $ProjectRoot/dist/AutoSplit.elf If ($?) { Write-Host 'Added .elf extension' } - chmod +x $PSScriptRoot/../dist/AutoSplit.elf + chmod +x $ProjectRoot/dist/AutoSplit.elf Write-Host 'Added execute permission' } diff --git a/scripts/install.ps1 b/scripts/install.ps1 index 941ddeac..e9430ad4 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -29,7 +29,7 @@ If ($IsLinux) { } } -# Installing Python dependencies +# Installing system dependencies If ($IsLinux) { If (-not $Env:GITHUB_JOB -or $Env:GITHUB_JOB -eq 'Build') { sudo apt-get update @@ -38,8 +38,23 @@ If ($IsLinux) { } } +# UPX is only used by PyInstaller on Windows +If ($IsWindows -and [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture -eq 'X64') { + $UPXVersion = '5.0.1' + $UPXFolderName = "upx-$UPXVersion-win64" + Write-Output "Installing $UPXFolderName" + if (Test-Path "$PSScriptRoot/.upx") { Remove-Item $PSScriptRoot/.upx -Recurse } + Invoke-WebRequest ` + -Uri https://github.com/upx/upx/releases/download/v$UPXVersion/$UPXFolderName.zip ` + -OutFile $Env:TEMP/$UPXFolderName.zip + # Automatically install in a local untracked folder. This makes it easy to version and replicate on CI + Expand-Archive $Env:TEMP/$UPXFolderName.zip $PSScriptRoot/.upx + Move-Item $PSScriptRoot/.upx/$UPXFolderName/* $PSScriptRoot/.upx + Remove-Item $PSScriptRoot/.upx/$UPXFolderName +} + $prod = If ($Env:GITHUB_JOB -eq 'Build') { '--no-dev' } Else { } -$lock = If ($Env:GITHUB_JOB) { '--locked' } Else { '--upgrade' } +$lock = If ($Env:GITHUB_JOB) { '--locked' } Else { } Write-Output "Installing Python dependencies with: uv sync $prod $lock" uv sync --active $prod $lock