Skip to content

Commit d850f92

Browse files
committed
Add Windows scripts to extract version information from base/version.h.
1 parent 5cdb3f7 commit d850f92

File tree

3 files changed

+96
-2
lines changed

3 files changed

+96
-2
lines changed

source/base/version.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@
5454
///
5555
/// @name Primary Version and Copyright Information
5656
///
57+
/// @note
58+
/// The macro definition in this section may be probed by external tools, and must therefore
59+
/// conform to the following rules:
60+
/// - The definitions must reside on a single line each.
61+
/// - The lines must not be disabled via conditional compilation or multi-line comments.
62+
/// - The lines must not contain any whitespace other than plain blanks (ASCII 0x20).
63+
/// - The macros must be defined as plain string literals, plain decimal integer literals,
64+
/// or plain empty, depending on their purpose.
65+
///
5766
/// @{
5867

5968
/// Copyright string.
@@ -74,7 +83,7 @@
7483
/// or complex bugfixes that require thorough testing.
7584
#define POV_RAY_REVISION_INT 0
7685

77-
/// Fourth numerical component of official source code version ("patch level") as integer.
86+
/// Fourth numerical component of official source code version ("maintenance patch level") as integer.
7887
/// Increment this field to indicate simple bugfixes.
7988
#define POV_RAY_PATCHLEVEL_INT 0
8089

@@ -91,7 +100,7 @@
91100
/// where `N` is a serial number starting at 1 in each phase, `TIME` is the number of minutes
92101
/// since 2000-01-01 00:00, and `FEATURE` is an arbitrary alphanumeric moniker for a particular
93102
/// experimental feature.
94-
#define POV_RAY_PRERELEASE "alpha"
103+
#define POV_RAY_PRERELEASE "alpha"
95104

96105
/// @def POVRAY_IS_BETA
97106
/// Whether this version is a beta.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@echo off
2+
3+
REM * Extract POV-Ray version information from `source/base/version.h`
4+
REM *
5+
REM * Run as follows:
6+
REM *
7+
REM * call "tools/windows/get-source-version.bat" "source/base/version.h"
8+
REM *
9+
REM * This will cause the followng envionment variables to be set:
10+
REM *
11+
REM * POV_SOURCE_GENERATION First two fields of the version string (`X.Y`)
12+
REM * POV_SOURCE_VERSION Full version string (`X.Y.Z`[`.P`][`-PRE`])
13+
REM * POV_SOURCE_PRERELEASE Pre-release tag portion of the version string (`PRE`), or undefined if not applicable
14+
15+
powershell -executionpolicy remotesigned -File "%~dp0get-source-version.ps1" "%~1" -bat version~.bat
16+
call version~.bat
17+
del version~.bat
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Extract POV-Ray version information from `source/base/version.h`
2+
#
3+
# From PowerShell scripts, run as follows:
4+
#
5+
# Set-ExecutionPolicy remotesigned -scope process -force
6+
# ./tools/windows/get-source-version.ps1 ./source/base/version.h
7+
#
8+
# From batch files, run as follows:
9+
#
10+
# powershell -executionpolicy remotesigned -File ./tools/windows/get-source-version.ps1 ./source/base/version.h -bat version~.bat
11+
# call version~.bat
12+
# del version~.bat
13+
#
14+
# Both procedures will cause the following envionment variables to be set:
15+
#
16+
# POV_SOURCE_GENERATION First two fields of the version string (`X.Y`)
17+
# POV_SOURCE_VERSION Full version string (`X.Y.Z`[`.P`][`-PRE`])
18+
# POV_SOURCE_PRERELEASE Pre-release tag portion of the version string (`PRE`), or empty[*] if not applicable
19+
#
20+
# [*In the batch version of the procedure, empty environment variables will be left undefined.]
21+
22+
param ([string]$version_h, [string]$bat)
23+
24+
function GetNumericMacro ([string]$file, [string]$macro) {
25+
$regexp = '^\s*#define\s+' + $macro + '\s+[0-9]+\s*$'
26+
$line = ( select-string -Path $file -Pattern $regexp | % { $_.Matches } | % { $_.Value } )
27+
$string = ( select-string -InputObject $line -Pattern '\s+[0-9]+' | % { $_.Matches } | % { $_.Value } )
28+
$value = ( select-string -InputObject $string -Pattern '[0-9]+' | % { $_.Matches } | % { $_.Value } )
29+
return [string]$value
30+
}
31+
32+
function GetStringMacro ([string]$file, [string]$macro) {
33+
$regexp = '^\s*#define\s+' + $macro + '\s*"[^"]+"\s*$'
34+
$line = ( select-string -Path $file -Pattern $regexp | % { $_.Matches } | % { $_.Value } )
35+
$string = ( select-string -InputObject $line -Pattern '"[^"]+"' | % { $_.Matches } | % { $_.Value } )
36+
$value = ( select-string -InputObject $string -Pattern '[^"]+' | % { $_.Matches } | % { $_.Value } )
37+
return [string]$value
38+
}
39+
40+
$major = GetNumericMacro $version_h 'POV_RAY_MAJOR_VERSION_INT'
41+
$minor = GetNumericMacro $version_h 'POV_RAY_MINOR_VERSION_INT'
42+
$revision = GetNumericMacro $version_h 'POV_RAY_REVISION_INT'
43+
$patchlevel = GetNumericMacro $version_h 'POV_RAY_PATCHLEVEL_INT'
44+
45+
$prerelease = GetStringMacro $version_h 'POV_RAY_PRERELEASE'
46+
47+
$generation = $major + "." + $minor
48+
if ([int]$patchlevel -eq 0) {
49+
$release = $generation + "." + $revision
50+
} else {
51+
$release = $generation + "." + $revision + "." + $patchlevel
52+
}
53+
if ($prerelease) {
54+
$version = $release + '-' + $prerelease
55+
} else {
56+
$version = $release
57+
}
58+
59+
$env:POV_SOURCE_GENERATION = $generation
60+
$env:POV_SOURCE_VERSION = $version
61+
$env:POV_SOURCE_PRERELEASE = $prerelease
62+
63+
if ($bat) {
64+
$text = "set POV_SOURCE_GENERATION=" + $env:POV_SOURCE_GENERATION + "`n"
65+
$text += "set POV_SOURCE_VERSION=" + $env:POV_SOURCE_VERSION + "`n"
66+
$text += "set POV_SOURCE_PRERELEASE=" + $env:POV_SOURCE_PRERELEASE + "`n"
67+
Out-File -LiteralPath $bat -Encoding ASCII -InputObject $text -NoNewline
68+
}

0 commit comments

Comments
 (0)