Skip to content

Commit e06400e

Browse files
committed
xrCore: build information (branch, commit hash, CI, CI build ID, builder)
You will see at least branch and commit hash, other info will be shown depending on it's availability
1 parent cc2474f commit e06400e

File tree

4 files changed

+78
-18
lines changed

4 files changed

+78
-18
lines changed

src/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
xrCore/.GitInfo.hpp
2+
13
# exclude binaries and temporary files
24
ipch/
35
packages/

src/xrCore/.GitInfo.cmd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
where git >nul 2>nul
2+
if %errorLevel% neq 0 (
3+
goto :EOF
4+
)
5+
6+
echo | set /p dummyName=#define GIT_INFO_CURRENT_COMMIT > .GitInfo.hpp
7+
git rev-parse --verify HEAD >> .GitInfo.hpp
8+
9+
echo | set /p dummyName=#define GIT_INFO_CURRENT_BRANCH >> .GitInfo.hpp
10+
git rev-parse --abbrev-ref HEAD >> .GitInfo.hpp

src/xrCore/xrCore.cpp

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
#include "Math/MathUtil.hpp"
1414
#include "xrCore/_std_extensions.h"
1515

16+
#if __has_include(".GitInfo.hpp")
17+
#include ".GitInfo.hpp"
18+
#endif
19+
20+
#ifndef GIT_INFO_CURRENT_BRANCH
21+
#define GIT_INFO_CURRENT_BRANCH unknown
22+
#endif
23+
24+
#ifndef GIT_INFO_CURRENT_COMMIT
25+
#define GIT_INFO_CURRENT_COMMIT unknown
26+
#endif
27+
1628
#include "Compression/compression_ppmd_stream.h"
1729
extern compression::ppmd::stream* trained_model;
1830

@@ -23,33 +35,51 @@ static u32 init_counter = 0;
2335
#define DO_EXPAND(VAL) VAL##1
2436
#define EXPAND(VAL) DO_EXPAND(VAL)
2537

38+
#ifdef CI
2639
#if EXPAND(CI) == 1
2740
#undef CI
2841
#endif
42+
#endif
2943

3044
#define HELPER(s) #s
3145
#define TO_STRING(s) HELPER(s)
3246

33-
void PrintCI()
47+
void PrintBuildInfo()
3448
{
35-
#if defined(CI)
36-
pcstr name = nullptr;
49+
pcstr name = "Custom";
3750
pcstr buildId = nullptr;
3851
pcstr builder = nullptr;
39-
pcstr commit = nullptr;
52+
pcstr commit = TO_STRING(GIT_INFO_CURRENT_COMMIT);
53+
pcstr branch = TO_STRING(GIT_INFO_CURRENT_BRANCH);
54+
55+
#if defined(CI)
4056
#if defined(APPVEYOR)
4157
name = "AppVeyor";
4258
buildId = TO_STRING(APPVEYOR_BUILD_VERSION);
4359
builder = TO_STRING(APPVEYOR_ACCOUNT_NAME);
44-
commit = TO_STRING(APPVEYOR_REPO_COMMIT);
60+
#elif defined(TRAVIS)
61+
name = "Travis";
62+
buildId = TO_STRING(TRAVIS_BUILD_NUMBER);
4563
#else
4664
#pragma TODO("PrintCI for other CIs")
47-
return;
65+
name = "CI";
66+
builder = "Unknown CI";
4867
#endif
49-
Msg("%s build %s from commit %s (built by %s)", name, buildId, commit, builder);
50-
#else
51-
Log("This is a custom build");
5268
#endif
69+
70+
string512 buf;
71+
strconcat(sizeof(buf), buf, name, " build "); // "%s build "
72+
73+
if (buildId)
74+
strconcat(sizeof(buf), buf, buf, buildId, " "); // "id "
75+
76+
strconcat(sizeof(buf), buf, buf, "from commit[", commit, "]"); // "from commit[hash]"
77+
strconcat(sizeof(buf), buf, buf, " branch[", branch, "]"); // " branch[name]"
78+
79+
if (builder)
80+
strconcat(sizeof(buf), buf, buf, " (built by ", builder, ")"); // " (built by builder)"
81+
82+
Log(buf); // "%s build %s from commit[%s] branch[%s] (built by %s)"
5383
}
5484

5585
void SDLLogOutput(void* /*userdata*/,
@@ -208,9 +238,9 @@ void xrCore::Initialize(pcstr _ApplicationName, LogCallback cb, bool init_fs, pc
208238
Memory._initialize();
209239

210240
SDL_LogSetOutputFunction(SDLLogOutput, nullptr);
211-
Msg("%s %s build %d, %s\n", "OpenXRay", GetBuildConfiguration(), buildId, buildDate);
212-
PrintCI();
213-
Msg("command line %s\n", Params);
241+
Msg("%s %s build %d, %s", "OpenXRay", GetBuildConfiguration(), buildId, buildDate);
242+
PrintBuildInfo();
243+
Msg("\ncommand line %s\n", Params);
214244
_initialize_cpu();
215245
R_ASSERT(CPU::ID.hasFeature(CpuFeature::Sse));
216246
ttapi.initialize();

src/xrCore/xrCore.vcxproj

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
104104
<ClCompile>
105105
<AdditionalIncludeDirectories>$(xrExternals);$(xrExternals)lzo\include;$(xrExternals)pugixml\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
106-
<PreprocessorDefinitions>_USRDLL;XRCORE_EXPORTS;CRYPTO_BUILD;CI=$(CI);APPVEYOR=$(APPVEYOR);APPVEYOR_BUILD_VERSION=$(APPVEYOR_BUILD_VERSION);APPVEYOR_ACCOUNT_NAME=$(APPVEYOR_ACCOUNT_NAME);APPVEYOR_REPO_COMMIT=$(APPVEYOR_REPO_COMMIT);%(PreprocessorDefinitions)</PreprocessorDefinitions>
106+
<PreprocessorDefinitions>_USRDLL;XRCORE_EXPORTS;CRYPTO_BUILD;CI=$(CI);APPVEYOR=$(APPVEYOR);APPVEYOR_BUILD_VERSION=$(APPVEYOR_BUILD_VERSION);APPVEYOR_ACCOUNT_NAME=$(APPVEYOR_ACCOUNT_NAME);%(PreprocessorDefinitions)</PreprocessorDefinitions>
107107
</ClCompile>
108108
<Link>
109109
<AdditionalDependencies>PowrProf.lib;DbgHelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -114,11 +114,14 @@
114114
<PostBuildEvent>
115115
<Message>Copying the required libraries ...</Message>
116116
</PostBuildEvent>
117+
<PreBuildEvent>
118+
<Command>call .GitInfo.cmd</Command>
119+
</PreBuildEvent>
117120
</ItemDefinitionGroup>
118121
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
119122
<ClCompile>
120123
<AdditionalIncludeDirectories>$(xrExternals);$(xrExternals)lzo\include;$(xrExternals)pugixml\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
121-
<PreprocessorDefinitions>_USRDLL;XRCORE_EXPORTS;CRYPTO_BUILD;CI=$(CI);APPVEYOR=$(APPVEYOR);APPVEYOR_BUILD_VERSION=$(APPVEYOR_BUILD_VERSION);APPVEYOR_ACCOUNT_NAME=$(APPVEYOR_ACCOUNT_NAME);APPVEYOR_REPO_COMMIT=$(APPVEYOR_REPO_COMMIT);%(PreprocessorDefinitions)</PreprocessorDefinitions>
124+
<PreprocessorDefinitions>_USRDLL;XRCORE_EXPORTS;CRYPTO_BUILD;CI=$(CI);APPVEYOR=$(APPVEYOR);APPVEYOR_BUILD_VERSION=$(APPVEYOR_BUILD_VERSION);APPVEYOR_ACCOUNT_NAME=$(APPVEYOR_ACCOUNT_NAME);%(PreprocessorDefinitions)</PreprocessorDefinitions>
122125
</ClCompile>
123126
<Link>
124127
<AdditionalDependencies>PowrProf.lib;DbgHelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -127,11 +130,14 @@
127130
<Command>for /r "$(xrSdkDir)binaries/$(PlatformShortName)" %%f in (*.dll *.pdb) do @xcopy /Q /D "%%f" "$(OutDir)"</Command>
128131
<Message>Copying the required libraries ...</Message>
129132
</PostBuildEvent>
133+
<PreBuildEvent>
134+
<Command>call .GitInfo.cmd</Command>
135+
</PreBuildEvent>
130136
</ItemDefinitionGroup>
131137
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
132138
<ClCompile>
133139
<AdditionalIncludeDirectories>$(xrExternals);$(xrExternals)lzo\include;$(xrExternals)pugixml\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
134-
<PreprocessorDefinitions>_USRDLL;XRCORE_EXPORTS;CRYPTO_BUILD;CI=$(CI);APPVEYOR=$(APPVEYOR);APPVEYOR_BUILD_VERSION=$(APPVEYOR_BUILD_VERSION);APPVEYOR_ACCOUNT_NAME=$(APPVEYOR_ACCOUNT_NAME);APPVEYOR_REPO_COMMIT=$(APPVEYOR_REPO_COMMIT);%(PreprocessorDefinitions)</PreprocessorDefinitions>
140+
<PreprocessorDefinitions>_USRDLL;XRCORE_EXPORTS;CRYPTO_BUILD;CI=$(CI);APPVEYOR=$(APPVEYOR);APPVEYOR_BUILD_VERSION=$(APPVEYOR_BUILD_VERSION);APPVEYOR_ACCOUNT_NAME=$(APPVEYOR_ACCOUNT_NAME);%(PreprocessorDefinitions)</PreprocessorDefinitions>
135141
</ClCompile>
136142
<Link>
137143
<AdditionalDependencies>PowrProf.lib;DbgHelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -142,11 +148,14 @@
142148
<PostBuildEvent>
143149
<Message>Copying the required libraries ...</Message>
144150
</PostBuildEvent>
151+
<PreBuildEvent>
152+
<Command>call .GitInfo.cmd</Command>
153+
</PreBuildEvent>
145154
</ItemDefinitionGroup>
146155
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
147156
<ClCompile>
148157
<AdditionalIncludeDirectories>$(xrExternals);$(xrExternals)lzo\include;$(xrExternals)pugixml\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
149-
<PreprocessorDefinitions>_USRDLL;XRCORE_EXPORTS;CRYPTO_BUILD;CI=$(CI);APPVEYOR=$(APPVEYOR);APPVEYOR_BUILD_VERSION=$(APPVEYOR_BUILD_VERSION);APPVEYOR_ACCOUNT_NAME=$(APPVEYOR_ACCOUNT_NAME);APPVEYOR_REPO_COMMIT=$(APPVEYOR_REPO_COMMIT);%(PreprocessorDefinitions)</PreprocessorDefinitions>
158+
<PreprocessorDefinitions>_USRDLL;XRCORE_EXPORTS;CRYPTO_BUILD;CI=$(CI);APPVEYOR=$(APPVEYOR);APPVEYOR_BUILD_VERSION=$(APPVEYOR_BUILD_VERSION);APPVEYOR_ACCOUNT_NAME=$(APPVEYOR_ACCOUNT_NAME);%(PreprocessorDefinitions)</PreprocessorDefinitions>
150159
</ClCompile>
151160
<Link>
152161
<AdditionalDependencies>PowrProf.lib;DbgHelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -155,11 +164,14 @@
155164
<Command>for /r "$(xrSdkDir)binaries/$(PlatformShortName)" %%f in (*.dll *.pdb) do @xcopy /Q /D "%%f" "$(OutDir)"</Command>
156165
<Message>Copying the required libraries ...</Message>
157166
</PostBuildEvent>
167+
<PreBuildEvent>
168+
<Command>call .GitInfo.cmd</Command>
169+
</PreBuildEvent>
158170
</ItemDefinitionGroup>
159171
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Mixed|Win32'">
160172
<ClCompile>
161173
<AdditionalIncludeDirectories>$(xrExternals);$(xrExternals)lzo\include;$(xrExternals)pugixml\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
162-
<PreprocessorDefinitions>_USRDLL;XRCORE_EXPORTS;CRYPTO_BUILD;CI=$(CI);APPVEYOR=$(APPVEYOR);APPVEYOR_BUILD_VERSION=$(APPVEYOR_BUILD_VERSION);APPVEYOR_ACCOUNT_NAME=$(APPVEYOR_ACCOUNT_NAME);APPVEYOR_REPO_COMMIT=$(APPVEYOR_REPO_COMMIT);%(PreprocessorDefinitions)</PreprocessorDefinitions>
174+
<PreprocessorDefinitions>_USRDLL;XRCORE_EXPORTS;CRYPTO_BUILD;CI=$(CI);APPVEYOR=$(APPVEYOR);APPVEYOR_BUILD_VERSION=$(APPVEYOR_BUILD_VERSION);APPVEYOR_ACCOUNT_NAME=$(APPVEYOR_ACCOUNT_NAME);%(PreprocessorDefinitions)</PreprocessorDefinitions>
163175
</ClCompile>
164176
<Link>
165177
<AdditionalDependencies>PowrProf.lib;DbgHelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -170,11 +182,14 @@
170182
<PostBuildEvent>
171183
<Message>Copying the required libraries ...</Message>
172184
</PostBuildEvent>
185+
<PreBuildEvent>
186+
<Command>call .GitInfo.cmd</Command>
187+
</PreBuildEvent>
173188
</ItemDefinitionGroup>
174189
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Mixed|x64'">
175190
<ClCompile>
176191
<AdditionalIncludeDirectories>$(xrExternals);$(xrExternals)lzo\include;$(xrExternals)pugixml\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
177-
<PreprocessorDefinitions>_USRDLL;XRCORE_EXPORTS;CRYPTO_BUILD;CI=$(CI);APPVEYOR=$(APPVEYOR);APPVEYOR_BUILD_VERSION=$(APPVEYOR_BUILD_VERSION);APPVEYOR_ACCOUNT_NAME=$(APPVEYOR_ACCOUNT_NAME);APPVEYOR_REPO_COMMIT=$(APPVEYOR_REPO_COMMIT);%(PreprocessorDefinitions)</PreprocessorDefinitions>
192+
<PreprocessorDefinitions>_USRDLL;XRCORE_EXPORTS;CRYPTO_BUILD;CI=$(CI);APPVEYOR=$(APPVEYOR);APPVEYOR_BUILD_VERSION=$(APPVEYOR_BUILD_VERSION);APPVEYOR_ACCOUNT_NAME=$(APPVEYOR_ACCOUNT_NAME);%(PreprocessorDefinitions)</PreprocessorDefinitions>
178193
</ClCompile>
179194
<Link>
180195
<AdditionalDependencies>PowrProf.lib;DbgHelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -183,6 +198,9 @@
183198
<Command>for /r "$(xrSdkDir)binaries/$(PlatformShortName)" %%f in (*.dll *.pdb) do @xcopy /Q /D "%%f" "$(OutDir)"</Command>
184199
<Message>Copying the required libraries ...</Message>
185200
</PostBuildEvent>
201+
<PreBuildEvent>
202+
<Command>call .GitInfo.cmd</Command>
203+
</PreBuildEvent>
186204
</ItemDefinitionGroup>
187205
<ItemGroup>
188206
<ClCompile Include="Animation\Bone.cpp" />

0 commit comments

Comments
 (0)