Skip to content

Commit be7a3ec

Browse files
committed
chore: Improve version number code
1 parent a7f3a99 commit be7a3ec

File tree

3 files changed

+35
-39
lines changed

3 files changed

+35
-39
lines changed

Build.cmd

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,10 @@ IF "%Mode%" == "Stable" (
8686
)
8787
)
8888

89-
REM Get code revision.
90-
SET Revision=000
91-
IF EXIST ".svn" (
92-
FOR /F "usebackq tokens=1" %%R IN (`svn --non-interactive info --show-item revision .`) DO SET Revision=%%R
93-
)
94-
IF EXIST ".git" (
95-
FOR /F "usebackq tokens=1" %%R IN (`git describe --first-parent --always`) DO SET Revision=%%R
96-
)
97-
IF "%Revision%" == "000" (
98-
>&2 ECHO WARNING: No Subversion or Git revision found.
99-
)
89+
REM Get product version and code revision.
90+
FOR /F "usebackq tokens=1* delims==" %%A IN (`CALL GetVersion.cmd`) DO SET %%A=%%B
91+
SET Version=%OpenRails_Version%
92+
SET Revision=%OpenRails_Revision%
10093

10194
REM Recreate Program directory for output.
10295
CALL :recreate "Program" || GOTO :error
@@ -113,16 +106,16 @@ REM Set update channel.
113106
ECHO Set update channel to "%Mode%".
114107

115108
REM Set version number.
116-
IF NOT "%Version%" == "" (
117-
>Program\Version.txt ECHO %Version%. || GOTO :error
109+
IF "%Mode%" == "Stable" (
110+
>Program\Version.txt ECHO %Version% || GOTO :error
118111
ECHO Set version number to "%Version%".
119112
) ELSE (
120-
>Program\Version.txt ECHO X || GOTO :error
121-
ECHO Set version number to none.
113+
>Program\Version.txt ECHO %Mode:~0,1%%Version% || GOTO :error
114+
ECHO Set version number to "%Mode:~0,1%%Version%".
122115
)
123116

124117
REM Set revision number.
125-
>Program\Revision.txt ECHO $Revision: %Revision% $ || GOTO :error
118+
>Program\Revision.txt ECHO %Revision% || GOTO :error
126119
ECHO Set revision number to "%Revision%".
127120

128121
REM Build locales.
@@ -139,11 +132,7 @@ ECHO Created large address aware version of RunActivity.exe.
139132

140133
REM Copy version number from OpenRails.exe into all other 1st party files
141134
SET VersionInfoVersion=0.0.0.0
142-
IF NOT "%Version%" == "" (
143-
SET VersionInfoVersion=%Version%.%Revision%
144-
) ELSE (
145-
FOR /F "usebackq tokens=1" %%V IN (`rcedit-x86.exe "Program\OpenRails.exe" --get-version-string FileVersion`) DO SET VersionInfoVersion=%%V
146-
)
135+
FOR /F "usebackq tokens=1 delims=-" %%V IN (`ECHO %Revision%`) DO SET VersionInfoVersion=%Version%.%%V
147136
IF "%VersionInfoVersion%" == "0.0.0.0" (
148137
>&2 ECHO ERROR: No VersionInfoVersion found in "Program\OpenRails.exe".
149138
GOTO :error

GetVersion.cmd

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
@ECHO OFF
22
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
33

4-
REM Parse command line.
5-
SET Mode=%~1
6-
7-
REM Get product version.
8-
REM TODO!
9-
10-
REM Get code revision.
11-
REM For Subversion, this is a positive integer.
12-
REM For Git, this is the stable version, new commits, and latest commit ID hyphenated.
4+
REM Get product version and code revision.
5+
SET Version=
136
SET Revision=
14-
IF EXIST ".svn" (
15-
FOR /F "usebackq tokens=1" %%R IN (`svn --non-interactive info --show-item revision .`) DO SET Revision=%%R
7+
FOR /F "usebackq tokens=2" %%B IN (`git branch --points-at HEAD`) DO SET Branch=%%B
8+
FOR /F "usebackq tokens=1* delims=-" %%V IN (`git describe --first-parent --always --long`) DO (
9+
SET Version=%%V
10+
SET Revision=%%W
1611
)
17-
IF EXIST ".git" (
18-
FOR /F "usebackq tokens=1" %%R IN (`git describe --first-parent --always`) DO SET Revision=%%R
12+
IF "%Branch%" == "unstable" (
13+
SET TZ=UTC
14+
FOR /F "usebackq tokens=1* delims=-" %%V IN (`git log -1 --pretty^=format:^%%ad --date^=format-local:^%%Y^.%%m^.%%d-^%%H^%%M`) DO (
15+
SET Version=%%V
16+
SET Revision=%%W
17+
)
1918
)
20-
IF "%Revision%" == "" (
21-
>&2 ECHO WARNING: No Subversion or Git revision found.
19+
IF "%Version%" == "" (
20+
>&2 ECHO WARNING: No Git repository found.
2221
)
2322

2423
REM Output version numbers.
24+
ECHO OpenRails_Branch=%Branch%
2525
ECHO OpenRails_Version=%Version%
2626
ECHO OpenRails_Revision=%Revision%

Source/ORTS.Common/VersionInfo.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,15 @@ static string GetRevision(string fileName)
4646
using (var f = new StreamReader(Path.Combine(ApplicationPath, fileName)))
4747
{
4848
var revision = f.ReadLine().Trim();
49-
if (revision.StartsWith("$Revision:") && revision.EndsWith("$") && !revision.Contains(" 000 "))
50-
return revision.Substring(10, revision.Length - 11).Trim();
49+
if (revision.StartsWith("$Revision:") && revision.EndsWith("$"))
50+
{
51+
if (!revision.Contains(" 000 "))
52+
return revision.Substring(10, revision.Length - 11).Trim();
53+
}
54+
else
55+
{
56+
return revision;
57+
}
5158
}
5259
}
5360
catch
@@ -64,7 +71,7 @@ static string GetVersion(string fileName)
6471
{
6572
var version = f.ReadLine().Trim();
6673
if (!String.IsNullOrEmpty(Revision))
67-
return version + Revision;
74+
return version + "-" + Revision;
6875
}
6976
}
7077
catch

0 commit comments

Comments
 (0)