Update versioning script.
This commit is contained in:
@@ -1,85 +1,165 @@
|
|||||||
# Update_Version.ps1
|
# Update Version v2.0
|
||||||
|
# Required module: PSIni
|
||||||
|
# Installation: Install-Module -Name PsIni
|
||||||
|
|
||||||
$date = Get-Date
|
$date = Get-Date
|
||||||
|
|
||||||
function ParseString ([string]$searchString) {
|
function addLeadingZero([int]$nvar) {
|
||||||
[string]$result = (Select-String -Path '.\VersionInfo.h' -Pattern $searchString -SimpleMatch).Line
|
[string]$svar = $null
|
||||||
if ([string]::IsNullOrEmpty($result)) { return -1 }
|
if ($nvar -lt 10) { $svar = '0' + $nvar.ToString() }
|
||||||
return ($result -split "\s+", 3).Trim('"')[2]
|
else { $svar = $nvar.ToString() }
|
||||||
|
return $svar
|
||||||
}
|
}
|
||||||
|
|
||||||
$currentYear = $date.Year
|
function getValue([string]$var) {
|
||||||
$buildDateTime = "Build date: $($date.GetDateTimeFormats('u').Replace('Z', ''))"
|
switch -CaseSensitive ($var) {
|
||||||
$spanDays = [math]::Round((New-TimeSpan -Start $(Get-Date -Month 1 -Day 1 -Year 2000) -End $date).TotalDays)
|
"%y" { $var = $currentYear; break }
|
||||||
$spanSecs = [math]::Round((New-TimeSpan -Start $($date.Date) -End $($date.DateTime)).TotalSeconds)
|
"%m" { $var = $currentMonth; break }
|
||||||
|
"%d" { $var = $currentDay; break }
|
||||||
if (-not (Test-Path .\Version.h)) {
|
"%t" { $var = -join ((addLeadingZero($currentHour)), (addLeadingZero($currentMinute)), (addLeadingZero($currentSecond))); break }
|
||||||
Write-Host "Can't find file 'Version.h'"
|
"%D" { $var = $spanDays; break }
|
||||||
Start-Sleep -Seconds 3
|
"%S" { $var = $spanSecs; break }
|
||||||
exit
|
"%C" { $var = $gitCommitCount; break }
|
||||||
|
"%c" { $var = $gitRevCount; break }
|
||||||
|
}
|
||||||
|
return $var
|
||||||
}
|
}
|
||||||
Copy-Item .\Version.h .\VersionInfo.h
|
|
||||||
|
|
||||||
$verMajor = ParseString("V_MAJOR")
|
function makeVersionString([string]$vmaj, [string]$vmin, [string]$vbld, [string]$vrev) {
|
||||||
$verMinor = ParseString("V_MINOR")
|
[string]$vstr = $null
|
||||||
$verPatch = ParseString("V_PATCH")
|
if ($vmin -eq "") { $vmin = $vbld = $vrev = 0; $vstr = ($vmaj) -join '.' }
|
||||||
$pn = ParseString("PRODUCT_NAME")
|
else {
|
||||||
$pa = ParseString("PRODUCT_AUTHORS")
|
if ($vbld -eq "") { $vbld = $vrev = 0; $vstr = ($vmaj, $vmin) -join '.' }
|
||||||
$pys = ParseString("PRODUCT_YEAR_START")
|
else {
|
||||||
$aboutBuild = ""
|
if ($vrev -eq "") { $vrev = 0; $vstr = ($vmaj, $vmin, $vbld) -join '.' }
|
||||||
$pnf = ""
|
else { $vstr = ($vmaj, $vmin, $vbld, $vrev) -join '.' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[string]$nstr = ($vmaj, $vmin, $vbld, $vrev) -join ','
|
||||||
|
$res = @($vstr, $nstr)
|
||||||
|
return $res
|
||||||
|
}
|
||||||
|
|
||||||
if ($pys -eq $currentYear) {
|
#region Initializing variables
|
||||||
$pcf = "Copyright (C) $pys by $pa"
|
[string]$verMajor = [string]$verMinor = [string]$verBuild = [string]$verRevision = $null
|
||||||
} else {
|
[string]$pn = [string]$pa = [string]$aboutBuild = [string]$pnf = [string]$pcf = $null
|
||||||
$pcf = "Copyright (C) $pys-$currentYear by $pa"
|
[string]$buildDateTime = [string]$vs = [string]$vn = [string]$intName = [string]$origName = $null
|
||||||
}
|
[int]$pys = [int]$spanDays = [int]$spanSecs = $null
|
||||||
|
[int]$currentYear = [int]$currentMonth = [int]$currentDay = [int]$currentHour = [int]$currentMinute = [int]$currentSecond = $null
|
||||||
|
[string]$iniFile = ".\Version.ini"
|
||||||
|
#endregion
|
||||||
|
|
||||||
if (Test-Path .\.git) {
|
if (-not (Test-Path $iniFile)) {
|
||||||
$gitCommitCount = Invoke-Expression -Command "git rev-list --count HEAD"
|
Write-Error "Can't find file '$iniFile'"
|
||||||
$gitRevBranch = Invoke-Expression -Command "git symbolic-ref --short HEAD"
|
# Start-Sleep -Seconds 3
|
||||||
$gitRevDate = Invoke-Expression -Command "git log -1 --date=rfc --pretty=format:%ad%n"
|
exit 1
|
||||||
$gitVerStr = Invoke-Expression -Command "git describe --long"
|
}
|
||||||
|
|
||||||
|
[bool]$isGit = $false
|
||||||
|
if (Test-Path ".\.git") {
|
||||||
|
$isGit = $true
|
||||||
|
[int]$gitCommitCount = [int]$gitRevCount = $null
|
||||||
|
[string]$gitRevDate = [string]$gitVerStr = $null
|
||||||
|
$gitCommitCount = $(git rev-list --count HEAD)
|
||||||
|
$gitRevDate = $(git log -1 HEAD --date=rfc --pretty=format:%ad%n)
|
||||||
|
$gitVerStr = $(git describe HEAD --long)
|
||||||
if ($LastExitCode -eq 0) {
|
if ($LastExitCode -eq 0) {
|
||||||
$gitVerStr = $gitVerStr.Replace('-g', '-')
|
$gitVerStr = $gitVerStr.Replace('-g', '-')
|
||||||
$gitRevCount = $gitVerStr.Split('-')[-2]
|
$gitRevCount = $gitVerStr.Split('-')[-2]
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$gitVerStr = ""
|
$gitVerStr = ""
|
||||||
$gitRevCount = $gitCommitCount
|
$gitRevCount = $gitCommitCount
|
||||||
}
|
}
|
||||||
|
|
||||||
$vs = [string]::Join(".", $verMajor, $verMinor, $verPatch, $gitRevCount)
|
}
|
||||||
$vn = [string]::Join(",", $verMajor, $verMinor, $verPatch, $gitRevCount)
|
|
||||||
|
|
||||||
if ($gitVerStr -eq "") {
|
#region Reading values from INI file
|
||||||
$pnf = "$pn v$vs"
|
$config = $null
|
||||||
} else {
|
$config = (Get-IniContent -FilePath $iniFile)["Config"]
|
||||||
$pnf = "$pn $gitVerStr".Trim()
|
$verMajor = $config.Major
|
||||||
}
|
$verMinor = $config.Minor
|
||||||
|
$verBuild = $config.Build
|
||||||
|
$verRevision = $config.Revision
|
||||||
|
$pys = $config.ProductYearStart
|
||||||
|
$pn = $config.ProductName
|
||||||
|
$pa = $config.ProductAutors
|
||||||
|
$pd = $config.ProductDescription
|
||||||
|
#endregion
|
||||||
|
|
||||||
"#define GIT_VERSION_STR `"$gitVerStr`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
if ($verMajor -eq "") {
|
||||||
"#define GIT_REV_BRANCH `"$gitRevBranch`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
Write-Error "Major version cannot be empty!"
|
||||||
"#define GIT_REV_DATE `"Git date: $gitRevDate`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
# Start-Sleep -Seconds 3
|
||||||
"#define GIT_REV_COUNT $gitRevCount" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
exit 2
|
||||||
"#define GIT_COMMIT_COUNT $gitCommitCount" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
}
|
||||||
$aboutBuild = "Git date: $gitRevDate"
|
|
||||||
} else {
|
|
||||||
$vs = [string]::Join(".", $verMajor, $verMinor, $verPatch)
|
|
||||||
$vn = [string]::Join(",", $verMajor, $verMinor, $verPatch)
|
|
||||||
$pnf = "$pn v$vs"
|
|
||||||
$aboutBuild = $buildDateTime
|
|
||||||
}
|
|
||||||
|
|
||||||
$intName = "$pn`C++"
|
#region Variables preparation
|
||||||
|
$currentYear = $date.Year
|
||||||
|
$currentMonth = $date.Month
|
||||||
|
$currentDay = $date.Day
|
||||||
|
$currentHour = $date.Hour
|
||||||
|
$currentMinute = $date.Minute
|
||||||
|
$currentSecond = $date.Second
|
||||||
|
$buildDateTime = "Build date: $($date.GetDateTimeFormats('u').Replace('Z', ''))"
|
||||||
|
$spanDays = [math]::Round((New-TimeSpan -Start $(Get-Date -Month 1 -Day 1 -Year 2000) -End $date).TotalDays)
|
||||||
|
$spanSecs = [math]::Round((New-TimeSpan -Start $($date.Date) -End $($date.DateTime)).TotalSeconds)
|
||||||
|
if ($pys -eq $currentYear) { $pcf = "Copyright (C) $pys by $pa" } else { $pcf = "Copyright (C) $pys-$currentYear by $pa" }
|
||||||
|
$intName = "$pn-C++"
|
||||||
$origName = "$pn.exe"
|
$origName = "$pn.exe"
|
||||||
|
$verMajor = getValue $verMajor
|
||||||
|
$verMinor = getValue $verMinor
|
||||||
|
$verBuild = getValue $verBuild
|
||||||
|
$verRevision = getValue $verRevision
|
||||||
|
#endregion
|
||||||
|
|
||||||
"#define ABOUT_BUILD `"$aboutBuild`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
$vs = (makeVersionString $verMajor $verMinor $verBuild $verRevision)[0]
|
||||||
|
$vn = (makeVersionString $verMajor $verMinor $verBuild $verRevision)[1]
|
||||||
|
|
||||||
|
if ([string]::IsNullOrEmpty($gitVerStr)) { $pnf = "$pn v$vs" } else { $pnf = "$pn $gitVerStr" }
|
||||||
|
if ($isGit) { $aboutBuild = "Git date: $gitRevDate" } else { $aboutBuild = $buildDateTime }
|
||||||
|
|
||||||
|
#region Save all variables to file
|
||||||
|
"// $pn" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode
|
||||||
|
"// VersionInfo.h" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
||||||
|
"#pragma once" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
||||||
|
"#define PRODUCT_NAME `"$pn`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
||||||
"#define PRODUCT_NAME_FULL `"$pnf`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
"#define PRODUCT_NAME_FULL `"$pnf`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
||||||
|
"#define PRODUCT_AUTHORS `"$pa`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
||||||
|
"#define PRODUCT_DESCRIPTION `"$pd`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
||||||
|
"#define ABOUT_BUILD `"$aboutBuild`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
||||||
"#define INTERNAL_NAME `"$intName`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
"#define INTERNAL_NAME `"$intName`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
||||||
"#define ORIG_FILE_NAME `"$origName`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
"#define ORIG_FILE_NAME `"$origName`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
||||||
"#define PRODUCT_COPYRIGHT `"$pcf`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
"#define PRODUCT_COPYRIGHT `"$pcf`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
||||||
"#define VERSION_STR `"$vs`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
"#define VERSION_STR `"$vs`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
||||||
"#define VERSION_NUM $vn" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
"#define VERSION_NUM $vn" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
||||||
"#define SPAN_DAYS $spanDays" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
# "#define SPAN_DAYS $spanDays" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
||||||
"#define SPAN_SECS $spanSecs" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
# "#define SPAN_SECS $spanSecs" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
||||||
|
if ($isGit) {
|
||||||
|
"#define GIT_VERSION_STR `"$gitVerStr`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
||||||
|
# "#define GIT_REV_DATE `"Git date: $gitRevDate`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
||||||
|
# "#define GIT_REV_COUNT $gitRevCount" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
||||||
|
# "#define GIT_COMMIT_COUNT $gitCommitCount" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Print out all variables
|
||||||
|
# echo " verMajor: [$verMajor]"
|
||||||
|
# echo " verMinor: [$verMinor]"
|
||||||
|
# echo " verBuild: [$verBuild]"
|
||||||
|
# echo " verRevision: [$verRevision]"
|
||||||
|
# echo ""
|
||||||
|
# echo " aboutBuild: [$aboutBuild]"
|
||||||
|
# echo " productNameFull: [$pnf]"
|
||||||
|
# echo "productCopyrightFull: [$pcf]"
|
||||||
|
# echo " internalName: [$intName]"
|
||||||
|
# echo " originalName: [$origName]"
|
||||||
|
# echo " versionStr: [$vs]"
|
||||||
|
# echo " versionNum: [$vn]"
|
||||||
|
# echo " spanDays: [$spanDays]"
|
||||||
|
# echo " spanSecs: [$spanSecs]"
|
||||||
|
# echo ""
|
||||||
|
# echo " gitCommitCount: [$gitCommitCount]"
|
||||||
|
# echo " gitRevCount: [$gitRevCount]"
|
||||||
|
# echo " gitRevDate: [$gitRevDate]"
|
||||||
|
# echo " gitVerStr: [$gitVerStr]"
|
||||||
|
#endregion
|
||||||
|
|||||||
BIN
Version.ini
Normal file
BIN
Version.ini
Normal file
Binary file not shown.
@@ -7,7 +7,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wCenterWindow", "wCenterWin
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C7B4FD1E-DC1B-46A4-842C-5130F09EFCB5}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C7B4FD1E-DC1B-46A4-842C-5130F09EFCB5}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
Update_Version.ps1 = Update_Version.ps1
|
Version.h = Version.h
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
|
|||||||
Reference in New Issue
Block a user