Add a function such that cn.exe will print build signature (build path, builder, build time, build branch) on start-up.

(useful when there are a lot of versions)

It assumed environment "%USERNAME% is set and "hostname" is in path, which
should be true on most machines.

If users have not put "git" in their PATH, branch and commit SHA1 will not be
shown.
This commit is contained in:
erw 2015-02-01 23:51:12 -08:00
Родитель 986fac41ca
Коммит ebf1ab9f8b
4 изменённых файлов: 65 добавлений и 0 удалений

6
.gitignore поставляемый
Просмотреть файл

@ -160,3 +160,9 @@ $RECYCLE.BIN/
*.lyx~
*.bak
*.lyx#
# =========================
# prebuild file
# =========================
MachineLearning/cn/buildinfo.h

Просмотреть файл

@ -28,6 +28,7 @@
#include "io.h"
#endif
#include "hostname.h"
#include "buildinfo.h"
#ifdef LEAKDETECT
#include "vld.h" // for memory leak detection
#endif
@ -619,8 +620,26 @@ int MPIAPI MPI_Init(_In_opt_ int *argc, _Inout_count_(*argc) wchar_t*** argv)
}
#endif
void PrintBuiltInfo()
{
fprintf(stderr, "-------------------------------------------------------------------\n");
fprintf(stderr, "Build info: \n\n");
fprintf(stderr, "\t\tBuilt time: %s %s\n", __DATE__, __TIME__);
fprintf(stderr, "\t\tLast modified date: %s\n", __TIMESTAMP__);
fprintf(stderr, "\t\tBuilt by %s on %s\n", _BUILDER_, _BUILDMACHINE_);
fprintf(stderr, "\t\tBuild Path: %s\n", _BUILDPATH_);
#ifdef _GIT_EXIST
fprintf(stderr, "\t\tBuild Branch: %s\n", _BUILDBRANCH_);
fprintf(stderr, "\t\tBuild SHA1: %s\n", _BUILDSHA1_);
#endif
fprintf(stderr, "-------------------------------------------------------------------\n");
}
int wmain(int argc, wchar_t* argv[])
{
try
{
#ifdef MPI_SUPPORT
@ -670,6 +689,10 @@ int wmain(int argc, wchar_t* argv[])
#endif
}
PrintBuiltInfo();
std::string timestamp = TimeDateStamp();
if (myRank == 0) // main process

Просмотреть файл

@ -139,6 +139,9 @@
<TreatOutputAsContent>true</TreatOutputAsContent>
<Message>Copy content files to target directory</Message>
</CustomBuildStep>
<PreBuildEvent>
<Command>prebuild.bat</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
@ -199,6 +202,9 @@
<Message>
</Message>
</CustomBuildStep>
<PreBuildEvent>
<Command>prebuild.bat</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<Text Include="DefaultMacros.txt" />

Просмотреть файл

@ -0,0 +1,30 @@
@echo off
echo #ifndef _BUILDINFO_H > buildinfo.h
echo #define _BUILDINFO_H >> buildinfo.h
FOR /F "usebackq" %%i IN (`hostname`) DO SET HOST=%%i
:: assuming hostname always exists
:: not sure whether git in path ?
git --version 2 > nul
if not %ERRORLEVEL% == 9909 (
echo #define _GIT_EXIST >> buildinfo.h
FOR /F "usebackq" %%i IN (`git rev-parse --abbrev-ref HEAD`) DO SET BRANCH=%%i
FOR /F "usebackq" %%i IN (`git rev-parse HEAD`) DO SET COMMIT=%%i
echo #define _BUILDBRANCH_ "%BRANCH%" >> buildinfo.h
echo #define _BUILDSHA1_ "%COMMIT%" >> buildinfo.h
)
echo #define _BUILDER_ "%USERNAME%" >> buildinfo.h
echo #define _BUILDMACHINE_ "%HOST%" >> buildinfo.h
set a=%~dp0
set buildpath="%a:\=\\%"
echo #define _BUILDPATH_ %buildpath% >> buildinfo.h
echo #endif >> buildinfo.h