-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_version.ps1
More file actions
56 lines (52 loc) · 2 KB
/
Copy pathgenerate_version.ps1
File metadata and controls
56 lines (52 loc) · 2 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
<#
.SYNOPSIS
Generates version_info.h from the current git tag.
Falls back to 0.0.0 when git is unavailable or no tag is found.
.PARAMETER Output
Path to write version_info.h (default: version_info.h next to this script).
#>
param(
[string]$Output = "$PSScriptRoot\version_info.h",
[string]$Version = '' # Optional override (e.g. from CI tag); falls back to git describe.
)
$major = 0; $minor = 0; $patch = 0
$tag = $Version
if (-not $tag) {
try {
$tag = & git -C $PSScriptRoot describe --tags --exact-match HEAD 2>$null
if (-not $tag) {
$tag = & git -C $PSScriptRoot describe --tags --abbrev=0 2>$null
}
} catch {}
}
if ($tag -match '^v?(\d+)\.(\d+)\.(\d+)') {
$major = [int]$Matches[1]
$minor = [int]$Matches[2]
$patch = [int]$Matches[3]
}
$content = @"
#pragma once
// Auto-generated by generate_version.ps1 - do not edit by hand.
#define VER_MAJOR $major
#define VER_MINOR $minor
#define VER_PATCH $patch
#define VER_BUILD 0
#define VER_FILEVERSION $major,$minor,$patch,0
#define VER_PRODUCTVERSION $major,$minor,$patch,0
#define VER_FILEVERSION_STR "$major.$minor.$patch.0"
#define VER_PRODUCTVERSION_STR "$major.$minor.$patch.0"
#define VER_COMPANY_STR "LANCommander"
#define VER_PRODUCT_STR "LANCommander Interposer"
#define VER_COPYRIGHT_STR "Copyright (c) 2024-2026 LANCommander Contributors. MIT License."
"@
# Only write when content differs to avoid spurious rebuilds.
# Use .NET directly for UTF-8 without BOM (compatible with PowerShell 5.x and 7+).
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
$existing = if (Test-Path $Output) { [System.IO.File]::ReadAllText($Output) } else { '' }
$content = $content + "`n"
if ($content -ne $existing) {
[System.IO.File]::WriteAllText($Output, $content, $utf8NoBom)
Write-Host "version_info.h: updated to $major.$minor.$patch"
} else {
Write-Host "version_info.h: up to date ($major.$minor.$patch)"
}