SmartLockerTools/resources/build.ps1

131 lines
4.4 KiB
PowerShell
Raw Normal View History

2024-11-05 19:22:20 +08:00
param($type)
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
2024-10-02 14:44:51 +08:00
$MsvcScript = 'D:\Program Files\Microsoft Visual Studio\2022\\Community\Common7\Tools\Launch-VsDevShell.ps1'
if (!(Test-Path $MsvcScript)) { $MsvcScript = 'D:\Program Files\Microsoft Visual Studio\2022\\Professional\Common7\Tools\Launch-VsDevShell.ps1' }
. $MsvcScript -SkipAutomaticLocation -Arch amd64
2024-10-16 00:10:50 +08:00
$qtHome = "D:\Qt\6.8.0\msvc2022_64"
2024-10-02 14:44:51 +08:00
$openSSLRoot = "D:\Qt\Tools\OpenSSLv3\Win_x64"
2024-10-02 15:41:57 +08:00
$librariesPath = "E:\Projects\Libraries"
if (!(Test-Path $librariesPath)) { $librariesPath = "D:\Projects\Libraries" }
$boostRoot = "$librariesPath\boost_1_86_0_msvc2022_64bit"
$ffmpegRoot = "$librariesPath\ffmpeg-7.0.2-full_build-shared"
2024-10-02 14:44:51 +08:00
$projectPath = Get-Location
$buildPath = Join-Path -Path $projectPath -ChildPath "build"
2024-11-05 19:22:20 +08:00
$fileContent = (Get-Content -Path "CMakeLists.txt") -join " "
if ($fileContent -match 'project\([^\)]+VERSION\s+([0-9]+\.[0-9]+)') {
$version = $Matches[1]
} else {
Write-Output "未找到版本号"
}
$deployPath = Join-Path -Path $buildPath -ChildPath "SmartLockerTools_v$version"
$zipFilePath = Join-Path -Path $buildPath -ChildPath "SmartLockerTools_v$version.zip"
2024-10-02 16:48:17 +08:00
$changelogPath = Join-Path -Path $buildPath -ChildPath "CHANGELOG.txt"
2024-10-02 14:44:51 +08:00
function Build() {
if (!(Test-Path $buildPath\CMakeCache.txt)) {
cmake.exe -G Ninja -S . -B build `
-DCMAKE_BUILD_TYPE=Release `
-DCMAKE_PREFIX_PATH=$qtHome `
-DQT_DIR="$qtHome\lib\cmake\Qt6" `
-DQt6_DIR="$qtHome\lib\cmake\Qt6" `
-DQt6CoreTools_DIR="$qtHome\lib\cmake\Qt6CoreTools" `
2024-10-02 15:41:57 +08:00
-DQt6QmlTools_DIR="$qtHome\lib\cmake\Qt6QmlTools" `
-DLibraries_ROOT="$librariesPath"
2024-11-14 15:08:24 +08:00
$content = Get-Content -Path "build\CMakeFiles\rules.ninja" -Encoding Default
Set-Content -Path "build\CMakeFiles\rules.ninja" -Value $content -Encoding UTF8
2024-10-02 14:44:51 +08:00
}
cmake.exe --build $buildPath --target all
}
function Deploy() {
if (Test-Path $deployPath) {
Remove-Item $deployPath -Recurse -Force
}
New-Item $deployPath -ItemType Directory
Copy-Item $buildPath\Analyser\Analyser.exe $deployPath\Analyser.exe
Copy-Item $buildPath\OtaUpdate\SmartLockerUpdater.exe $deployPath\SmartLockerUpdater.exe
2024-11-05 19:22:20 +08:00
$executables = @(
@("Analyser.exe", "掌静脉测试工具.exe"),
@("SmartLockerUpdater.exe", "掌静脉模组升级工具.exe")
)
foreach ($executablePair in $executables) {
$oldName = $executablePair[0]
$newName = $executablePair[1]
& $qtHome\bin\windeployqt.exe $deployPath\$oldName --qmldir=$qtHome\qml
Rename-Item -Path $deployPath\$oldName -NewName $deployPath\$newName
2024-10-02 14:44:51 +08:00
}
$modules = "QmlCore"
foreach ($module in $modules) {
Copy-Item -Path $qtHome\bin\Qt6$module.dll -Destination $deployPath
}
2024-10-04 07:49:05 +08:00
if (-Not (Test-Path -Path $deployPath\qml\QtCore)) {
New-Item $deployPath\qml\QtCore -ItemType Directory
$plugins = "qtqmlcoreplugin.dll", "qmldir", "plugins.qmltypes"
foreach ($plugin in $plugins) {
Copy-Item -Path $QtHome\qml\QtCore\$plugin -Destination $deployPath\qml\QtCore
}
2024-10-02 14:44:51 +08:00
}
Copy-Item $openSSLRoot\bin\libssl-3-x64.dll $deployPath
Copy-Item $openSSLRoot\bin\libcrypto-3-x64.dll $deployPath
2024-11-05 19:22:20 +08:00
$boosts = "thread", "filesystem", "log", "json"
2024-10-02 14:44:51 +08:00
foreach ($boost in $boosts) {
Copy-Item -Path $boostRoot\lib\boost_$boost-vc143-mt-x64-1_86.dll -Destination $deployPath
}
$ffmpegs = "avcodec-61", "avdevice-61", "avfilter-10", "avformat-61", "avutil-59", "postproc-58", "swresample-5", "swscale-8"
foreach ($ffmpeg in $ffmpegs) {
Copy-Item -Path $ffmpegRoot\bin\$ffmpeg.dll -Destination $deployPath
}
Compress-Archive -Path $deployPath -DestinationPath $zipFilePath -Force
}
function Clean() {
if (Test-Path $buildPath) {
Remove-Item $buildPath -Recurse -Force
}
}
2024-10-02 16:48:17 +08:00
function Changelog() {
$commit_message = git log -1 --pretty=format:"%B"
Write-Output "Latest commit message:"
Write-Output $commit_message
$commit_message | Out-File -FilePath $changelogPath -Encoding utf8
Write-Output "Commit message has been written to $changelogPath"
}
2024-10-02 14:44:51 +08:00
switch ($type) {
"build" {
Build
}
"deploy" {
Deploy
}
"clean" {
Clean
}
"installer" {
Installer
}
2024-10-02 16:48:17 +08:00
"changelog" {
Changelog
}
2024-10-02 14:44:51 +08:00
"update" {
UpdateServer
}
}