forked from gtumanyan/SDI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVersion.ps1
More file actions
122 lines (111 loc) · 5.38 KB
/
Copy pathVersion.ps1
File metadata and controls
122 lines (111 loc) · 5.38 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# ------------------------------------------------------------
# PowerShell script to perform Version patching for SDI
# ToDo:
# - adapt $Build number in case of local machine builds
# ------------------------------------------------------------
param(
[string]$VerPatch = ""
)
# ------------------------------------------------------------
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop" ## Write-Error should throw ...
# ------------------------------------------------------------
$ScriptDir = Split-Path -Path "$(if ($PSVersionTable.PSVersion.Major -ge 3) { $PSCommandPath } else { & { $MyInvocation.ScriptName } })" -Parent
# ------------------------------------------------------------
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
$LastExitCode = 0
# ------------------------------------------------------------
# ============================================================
function DebugOutput($msg)
# ------------------------------------------------------------
{
#~return ## disabled debug output
if ($msg -ne $null) {
Write-Host ""
Write-Host "$msg"
}
}
# ------------------------------------------------------------
# ============================================================
try
{
$AppName = "SDI 2025"
$Major = [int]$(Get-Date -format yy)
$Minor = [int]$(Get-Date -format MM)
$Revis = [int]$(Get-Date -format dd)
$BuildPath = "Versions\build.txt"
if (!(Test-Path $BuildPath)) {
New-Item -Path $BuildPath -ItemType "file" -Value "0"
}
$Build = [int](Get-Content $BuildPath)
if (!$Build) { $Build = -1 }
$DayPath = "Versions\day.txt"
if (!(Test-Path $DayPath)) {
New-Item -Path $DayPath -ItemType "file" -Value "0"
}
$LastBuildDay = [string](Get-Content $DayPath)
if (!$LastBuildDay) { $LastBuildDay = 0 }
if ($LastBuildDay -ne "$Revis") {
$Revis | Set-Content -Path $DayPath
$Build = -1 # reset (local build)
}
# locally: increase build number and persist it
$Build = $Build + 1
# locally: read commit ID from .git\refs\heads\<first file>
$HeadDir = ".git\refs\heads"
$HeadMaster = Get-ChildItem -Path $HeadDir -Force -Recurse -File | Select-Object -First 1
$CommitID = [string](Get-Content "$HeadDir\$HeadMaster" -TotalCount 8)
if (!$CommitID) {
$length = ([string]($env:computername)).length
$CommitID = ([string]($env:computername)).substring(0,[math]::min($length,8)).ToLower()
}
$CommitID = $CommitID -replace '"', ''
$CommitID = $CommitID -replace "'", ''
$length = $CommitID.length
$CommitID = $CommitID.substring(0,[math]::min($length,8))
if (!$CommitID) { $CommitID = "---" }
$Build | Set-Content -Path $BuildPath
$CompleteVer = "$Major.$Minor.$Revis"
DebugOutput("SDI $CompleteVer $VerPatch")
if ((Get-Content "ext\libwebp\NEWS"-TotalCount 1) -match '[\d.]+$'){
$WebPVer = $Matches.0}
DebugOutput("WebP $WebPVer")
if (!$WebPVer) { $WebPVer = 0 }
$TorrentVer = ((Get-Content "ext\libtorrent\Makefile"-TotalCount 1) -split '=')[1]
DebugOutput("Libtorrent $TorrentVer")
if (!$TorrentVer) { $TorrentVer = "0.0.0" }
$BoostVer = (Get-Content "ext\boost\tools\boost_install\test\BoostVersion.cmake"-TotalCount 1).Substring(18,6)
if (!$BoostVer) { $BoostVer = "0.0.0" }
DebugOutput("Boost $BoostVer")
if ((Get-Content "ext\SevenZip\C\7zVersion.h"-TotalCount 4)[-1]-match '[\d.]+')
{$7zVer=$Matches.0} else { $7zVer = 0 }
DebugOutput("7-zip $7zVer")
#~if ($VerPatch) { $VerPatch = " $VerPatch" } # ensure space in front of string
Copy-Item -LiteralPath "Versions\VersionEx.h.tpl" -Destination "src\VersionEx.h" -Force
(Get-Content "src\VersionEx.h") | ForEach-Object { $_ -replace '\$APPNAME\$', "$AppName" } | Set-Content -Path "src\VersionEx.h"
(Get-Content "src\VersionEx.h") | ForEach-Object { $_ -replace '\$MAJOR\$', "$Major" } | Set-Content -Path "src\VersionEx.h"
(Get-Content "src\VersionEx.h") | ForEach-Object { $_ -replace '\$MINOR\$', "$Minor" } | Set-Content -Path "src\VersionEx.h"
(Get-Content "src\VersionEx.h") | ForEach-Object { $_ -replace '\$MAINT\$', "$Revis" } | Set-Content -Path "src\VersionEx.h"
(Get-Content "src\VersionEx.h") | ForEach-Object { $_ -replace '\$BUILD\$', "$Build" } | Set-Content -Path "src\VersionEx.h"
(Get-Content "src\VersionEx.h") | ForEach-Object { $_ -replace '\$7ZVER\$', "$7zVer" } | Set-Content -Path "src\VersionEx.h"
(Get-Content "src\VersionEx.h") | ForEach-Object { $_ -replace '\$WEBPVER\$', "$WebPVer" } | Set-Content -Path "src\VersionEx.h"
(Get-Content "src\VersionEx.h") | ForEach-Object { $_ -replace '\$BOOSTVER\$', "$BoostVer" } | Set-Content -Path "src\VersionEx.h"
(Get-Content "src\VersionEx.h") | ForEach-Object { $_ -replace '\$TORRENTVER\$', "$TorrentVer" } | Set-Content -Path "src\VersionEx.h"
(Get-Content "src\VersionEx.h") | ForEach-Object { $_ -replace '\$VERPATCH\$', "$VerPatch" } | Set-Content -Path "src\VersionEx.h"
(Get-Content "src\VersionEx.h") | ForEach-Object { $_ -replace '\$COMMITID\$', "$CommitID" } | Set-Content -Path "src\VersionEx.h"
}
catch
{
if ($LastExitCode -eq 0) { $LastExitCode = 99 }
$errorMessage = $_.Exception.Message
Write-Warning "Exception caught: `"$errorMessage`"!"
throw $_
}
finally
{
[Environment]::SetEnvironmentVariable("LASTEXITCODE", $LastExitCode, "User")
$host.SetShouldExit($LastExitCode)
Write-Host ""
Write-Host "VersionPatching: Done! Elapsed time: $($stopwatch.Elapsed)."
Exit $LastExitCode
}