-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.ps1
65 lines (57 loc) · 2.24 KB
/
build.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# PowerShell script to build the keyboard files and binary archive.
[CmdletBinding(SupportsShouldProcess=$true)]
param([switch]$NoPause = $false)
# A function to exit this script.
function Exit-Script([string]$Message = "")
{
if ($Message -ne "") {
Write-Host "ERROR: $Message"
}
if (-not $NoPause) {
pause
}
exit
}
# Create a new directory (delete previous one), return the directory object.
function Create-NewDirectory([string]$DirName)
{
Remove-Item $DirName -Recurse -Force -ErrorAction SilentlyContinue
return New-Item -ItemType Directory -Force $DirName
}
# Get first solution file in the same directory as the script.
$SolutionFile = Get-ChildItem "$PSScriptRoot\*.sln" | Select-Object -First 1
if ($SolutionFile -eq $null) {
Exit-Script "No solution file found in $PSScriptRoot"
}
$ProjectName = $SolutionFile.BaseName
Write-Output "Solution file: $SolutionFile"
# Find MSBuild
Write-Output "Searching MSBuild..."
$MSRoots = @("C:\Program Files*\MSBuild", "C:\Program Files*\Microsoft Visual Studio")
$MSBuild = Get-ChildItem $MSRoots -Recurse -Include MSBuild.exe -ErrorAction Ignore | ForEach-Object { $_.FullName} | Select-Object -First 1
if ($MSBuild -eq $null) {
Exit-Script "MSBuild not found"
}
Write-Output "MSBuild: $MSBuild"
# Build the project for each architecture.
foreach ($Arch in ("x86", "x64", "arm64")) {
Write-Output "Building for $Arch ..."
& $MSBuild $SolutionFile /nologo /property:Configuration=Release /property:Platform=$Arch
}
# Build archive binaries.
$Archive = "$PSScriptRoot\$ProjectName.zip"
Write-Output "Archive: $Archive"
$TempRoot = Create-NewDirectory "$PSScriptRoot\tmp"
$InstallRoot = Create-NewDirectory "$TempRoot\$ProjectName"
Copy-Item "$PSScriptRoot\install.ps1" -Destination $InstallRoot
foreach ($Arch in ("x86", "x64", "arm64")) {
$Files = Get-ChildItem "$PSScriptRoot\$Arch\Release\kbd*.dll"
if ($Files -ne $null) {
Copy-Item $Files -Destination $(Create-NewDirectory "$InstallRoot\$Arch")
Copy-Item "$PSScriptRoot\$Arch\Release\kbdadmin.exe" "$InstallRoot\$Arch\setup.exe"
}
}
$ProgressPreference = "SilentlyContinue"
Compress-Archive $InstallRoot -DestinationPath "$Archive" -Force
Remove-Item $TempRoot -Recurse -Force
Exit-Script