97 lines
8.4 KiB
PowerShell
97 lines
8.4 KiB
PowerShell
param([switch]$Test, [switch]$Integration, [switch]$Ocr, [switch]$Stage)
|
|
$ErrorActionPreference = 'Stop'
|
|
$root = $PSScriptRoot
|
|
$compiler = Join-Path $root '.tools\w64devkit\bin\g++.exe'
|
|
if (!(Test-Path $compiler)) {
|
|
$compiler = (Get-Command g++ -ErrorAction Stop).Source
|
|
}
|
|
$env:PATH = (Split-Path $compiler) + ';' + $env:PATH
|
|
$outDir = Join-Path $root 'build'
|
|
New-Item -ItemType Directory -Force $outDir | Out-Null
|
|
$executablePath = if ($Stage) { Join-Path $outDir 'staged\KSwitcher.exe' } else { Join-Path $outDir 'KSwitcher.exe' }
|
|
New-Item -ItemType Directory -Force (Split-Path $executablePath) | Out-Null
|
|
Set-Content -LiteralPath (Join-Path $outDir '.local-dev') -Value 'Local development build' -Encoding ascii
|
|
Set-Content -LiteralPath (Join-Path (Split-Path $executablePath) '.local-dev') -Value 'Local development build' -Encoding ascii
|
|
Push-Location $root
|
|
try {
|
|
$common = @('-std=c++20','-Os','-DNDEBUG','-DUNICODE','-D_UNICODE','-DWIN32_LEAN_AND_MEAN','-DNOMINMAX','-D_WIN32_WINNT=0x0A00','-Wall','-Wextra','-Wno-missing-field-initializers','-Isrc','-Ivendor','-ffunction-sections','-fdata-sections')
|
|
$libs = @('-lwinhttp','-luser32','-lshell32','-lshlwapi','-ladvapi32','-lcrypt32','-limm32','-lcomctl32','-lgdi32','-lole32','-loleaut32','-ltaskschd','-lcomdlg32','-luuid','-lwindowscodecs','-lruntimeobject','-luiautomationcore')
|
|
foreach ($name in @('core','platform','autostart','autocorrect','storage','sync','ocr','richtext','update','screenshot','screenshot_main','screenshot_notifications','screenshot_activation','screenshot_launcher','app','ui','main','configuration','config_main')) {
|
|
& $compiler @common -c "src/$name.cpp" -o "build/$name.o"
|
|
if ($LASTEXITCODE) { throw "Compilation failed: $name" }
|
|
}
|
|
& $compiler @common -DKS_RESIDENT_APP -c src/ui.cpp -o build/ui-resident.o
|
|
if ($LASTEXITCODE) { throw 'Resident UI compilation failed' }
|
|
& $compiler @common -DKS_CONFIG_APP -c src/ui.cpp -o build/ui-config.o
|
|
if ($LASTEXITCODE) { throw 'Configurator UI compilation failed' }
|
|
& windres --codepage=65001 resources/app.rc -O coff -o build/app-res.o
|
|
if ($LASTEXITCODE) { throw 'Resource compilation failed' }
|
|
& windres --codepage=65001 -DKS_SCREENSHOT_RESOURCES resources/app.rc -O coff -o build/screenshot-res.o
|
|
if ($LASTEXITCODE) { throw 'Screenshot resource compilation failed' }
|
|
New-Item -ItemType Directory -Force build/release | Out-Null
|
|
& $compiler -mwindows -municode -static -s '-Wl,--gc-sections' build/core.o build/platform.o build/autostart.o build/autocorrect.o build/storage.o build/sync.o build/ocr.o build/richtext.o build/update.o build/screenshot_launcher.o build/screenshot_activation.o build/screenshot_notifications.o build/app.o build/configuration.o build/ui-resident.o build/main.o build/app-res.o @libs -o $executablePath
|
|
if ($LASTEXITCODE) { throw 'Link failed' }
|
|
Copy-Item -LiteralPath $executablePath -Destination build/release/KSwitcher.exe -Force
|
|
$configPath = Join-Path (Split-Path $executablePath) 'KSwitcher.Config.exe'
|
|
& $compiler -mwindows -municode -static -s '-Wl,--gc-sections' build/core.o build/platform.o build/storage.o build/sync.o build/ocr.o build/configuration.o build/config_main.o build/ui-config.o build/app-res.o @libs -o $configPath
|
|
if ($LASTEXITCODE) { throw 'Configurator link failed' }
|
|
Copy-Item -LiteralPath $configPath -Destination build/release/KSwitcher.Config.exe -Force
|
|
$screenshotPath = Join-Path (Split-Path $executablePath) 'KSwitcher.Screenshot.exe'
|
|
& $compiler -mwindows -municode -static -s '-Wl,--gc-sections' build/core.o build/platform.o build/ocr.o build/screenshot.o build/screenshot_notifications.o build/screenshot_activation.o build/screenshot_main.o build/screenshot-res.o @libs -o $screenshotPath
|
|
if ($LASTEXITCODE) { throw 'Screenshot link failed' }
|
|
Copy-Item -LiteralPath $screenshotPath -Destination build/release/KSwitcher.Screenshot.exe -Force
|
|
if ($Test) {
|
|
& $compiler @common tests/sync.cpp build/core.o build/platform.o build/storage.o build/sync.o build/ocr.o @libs -static -s -o build/KSwitcherSyncTests.exe
|
|
if ($LASTEXITCODE) { throw 'Sync test build failed' }
|
|
& .\build\KSwitcherSyncTests.exe
|
|
if ($LASTEXITCODE) { throw 'Sync tests failed' }
|
|
& $compiler @common tests/scroll.cpp @libs -static -s -o build/KSwitcherScrollTests.exe
|
|
if ($LASTEXITCODE) { throw 'Scroll test build failed' }
|
|
& .\build\KSwitcherScrollTests.exe
|
|
if ($LASTEXITCODE) { throw 'Scroll tests failed' }
|
|
& $compiler @common tests/tests.cpp build/core.o build/platform.o build/autostart.o build/autocorrect.o build/storage.o build/sync.o build/ocr.o build/richtext.o build/update.o @libs -static -s -o build/KSwitcherTests.exe
|
|
if ($LASTEXITCODE) { throw 'Test build failed' }
|
|
& .\build\KSwitcherTests.exe
|
|
if ($LASTEXITCODE) { throw 'Tests failed' }
|
|
& $compiler @common tests/input.cpp build/core.o build/platform.o build/autostart.o build/autocorrect.o build/storage.o build/sync.o build/ocr.o build/richtext.o build/update.o build/screenshot.o build/screenshot_launcher.o build/screenshot_activation.o build/screenshot_notifications.o build/app.o build/configuration.o build/ui.o build/screenshot-res.o @libs -static -s -o build/KSwitcherInputTests.exe
|
|
if ($LASTEXITCODE) { throw 'Input test build failed' }
|
|
& .\build\KSwitcherInputTests.exe
|
|
if ($LASTEXITCODE) { throw 'Input tests failed' }
|
|
& $compiler @common tests/screenshot_ui.cpp build/core.o build/platform.o build/ocr.o build/screenshot-res.o @libs -static -s -o build/KSwitcherScreenshotUITests.exe
|
|
if ($LASTEXITCODE) { throw 'Screenshot UI test build failed' }
|
|
& .\build\KSwitcherScreenshotUITests.exe
|
|
if ($LASTEXITCODE) { throw 'Screenshot UI tests failed' }
|
|
& .\build\KSwitcherScreenshotUITests.exe --save-only
|
|
if ($LASTEXITCODE) { throw 'Screenshot save tests failed' }
|
|
$registrationTest = Join-Path (Split-Path $executablePath) 'KSwitcherRegistrationTests.exe'
|
|
try {
|
|
& $compiler @common tests/screenshot_registration.cpp build/core.o build/platform.o @libs -static '-Wl,--gc-sections' -s -o $registrationTest
|
|
if ($LASTEXITCODE) { throw 'Screenshot registration test build failed' }
|
|
& $registrationTest
|
|
if ($LASTEXITCODE) { throw 'Screenshot registration tests failed' }
|
|
} finally { Remove-Item -LiteralPath $registrationTest -ErrorAction SilentlyContinue }
|
|
|
|
& "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File tests/update.ps1 -Executable $executablePath
|
|
if ($LASTEXITCODE) { throw 'Updater tests failed' }
|
|
& "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File tests/update_progress.ps1
|
|
if ($LASTEXITCODE) { throw 'Updater progress UI tests failed' }
|
|
}
|
|
if ($Integration) {
|
|
& $compiler @common tests/integration.cpp build/core.o build/platform.o build/autostart.o build/autocorrect.o build/storage.o build/sync.o build/ocr.o build/richtext.o build/update.o build/screenshot.o build/screenshot_launcher.o build/screenshot_activation.o build/screenshot_notifications.o build/app.o build/configuration.o build/ui.o build/screenshot-res.o @libs -static -s -o build/KSwitcherIntegration.exe
|
|
if ($LASTEXITCODE) { throw 'Integration test build failed' }
|
|
& .\build\KSwitcherIntegration.exe
|
|
if ($LASTEXITCODE) { throw 'Integration tests failed' }
|
|
}
|
|
if ($Ocr) {
|
|
& $compiler @common tests/ocr.cpp build/core.o build/platform.o build/autostart.o build/autocorrect.o build/storage.o build/sync.o build/ocr.o build/richtext.o build/update.o build/screenshot.o build/screenshot_launcher.o build/screenshot_activation.o build/screenshot_notifications.o build/app.o build/configuration.o build/ui.o build/screenshot-res.o @libs -static -s -o build/KSwitcherOcrTests.exe
|
|
if ($LASTEXITCODE) { throw 'OCR test build failed' }
|
|
& .\build\KSwitcherOcrTests.exe
|
|
if ($LASTEXITCODE) { throw 'OCR tests failed' }
|
|
}
|
|
foreach ($folder in @('build/dictionaries','build/release/dictionaries','build/staged/dictionaries')) {
|
|
New-Item -ItemType Directory -Force $folder | Out-Null
|
|
Copy-Item -Path dictionaries/* -Destination $folder -Force
|
|
}
|
|
Get-Item build/release/KSwitcher.exe | Select-Object FullName,Length
|
|
} finally { Pop-Location }
|