From e57fa5d28ed84cf167193a9ec2d563b63198ee7c Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 11 Jun 2018 19:54:33 -0500 Subject: [PATCH] Add a version display based on the git tag. --- sdk/SMX.h | 4 +++ sdk/Windows/.gitignore | 3 ++ sdk/Windows/SMX.cpp | 2 ++ sdk/Windows/SMX.vcxproj | 9 ++++++ sdk/Windows/SMX.vcxproj.filters | 3 ++ sdk/Windows/update-build-version.bat | 43 ++++++++++++++++++++++++++++ smx-config/MainWindow.xaml | 22 +++++++++----- smx-config/MainWindow.xaml.cs | 3 ++ smx-config/SMX.cs | 19 +++++++++++- smx-config/SMXConfig.csproj | 2 +- 10 files changed, 101 insertions(+), 9 deletions(-) create mode 100644 sdk/Windows/.gitignore create mode 100644 sdk/Windows/update-build-version.bat diff --git a/sdk/SMX.h b/sdk/SMX.h index cbff240..43f52e0 100644 --- a/sdk/SMX.h +++ b/sdk/SMX.h @@ -100,6 +100,10 @@ extern "C" SMX_API void SMX_ForceRecalibration(int pad); extern "C" SMX_API void SMX_SetTestMode(int pad, SensorTestMode mode); extern "C" SMX_API bool SMX_GetTestData(int pad, SMXSensorTestModeData *data); +// Return the build version of the DLL, which is based on the git tag at build time. This +// is only intended for diagnostic logging, and it's also the version we show in SMXConfig. +extern "C" SMX_API const char *SMX_Version(); + // General info about a connected controller. This can be retrieved with SMX_GetInfo. struct SMXInfo { diff --git a/sdk/Windows/.gitignore b/sdk/Windows/.gitignore new file mode 100644 index 0000000..0c0aeb0 --- /dev/null +++ b/sdk/Windows/.gitignore @@ -0,0 +1,3 @@ +# Ignore updates to the auto-generated build version. +SMXBuildVersion.h + diff --git a/sdk/Windows/SMX.cpp b/sdk/Windows/SMX.cpp index 0fd7e43..a9f48f8 100644 --- a/sdk/Windows/SMX.cpp +++ b/sdk/Windows/SMX.cpp @@ -6,6 +6,7 @@ #include "../SMX.h" #include "SMXManager.h" #include "SMXDevice.h" +#include "SMXBuildVersion.h" using namespace std; using namespace SMX; @@ -63,3 +64,4 @@ SMX_API void SMX_SetTestMode(int pad, SensorTestMode mode) { g_pSMX->GetDevice(p SMX_API bool SMX_GetTestData(int pad, SMXSensorTestModeData *data) { return g_pSMX->GetDevice(pad)->GetTestData(*data); } SMX_API void SMX_SetLights(const char lightsData[864]) { g_pSMX->SetLights(string(lightsData, 864)); } SMX_API void SMX_ReenableAutoLights() { g_pSMX->ReenableAutoLights(); } +SMX_API const char *SMX_Version() { return SMX_BUILD_VERSION; } diff --git a/sdk/Windows/SMX.vcxproj b/sdk/Windows/SMX.vcxproj index cfd449d..e6017b1 100644 --- a/sdk/Windows/SMX.vcxproj +++ b/sdk/Windows/SMX.vcxproj @@ -13,6 +13,7 @@ + @@ -90,6 +91,10 @@ hid.lib;setupapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)/out/$(TargetName)$(TargetExt) + + $(SolutionDir)sdk\Windows\update-build-version.bat + + @@ -125,6 +130,10 @@ + + $(SolutionDir)sdk\Windows\update-build-version.bat + + diff --git a/sdk/Windows/SMX.vcxproj.filters b/sdk/Windows/SMX.vcxproj.filters index 7b343b7..573ae71 100644 --- a/sdk/Windows/SMX.vcxproj.filters +++ b/sdk/Windows/SMX.vcxproj.filters @@ -31,6 +31,9 @@ Source Files + + Source Files + diff --git a/sdk/Windows/update-build-version.bat b/sdk/Windows/update-build-version.bat new file mode 100644 index 0000000..8986d37 --- /dev/null +++ b/sdk/Windows/update-build-version.bat @@ -0,0 +1,43 @@ +@echo off +setlocal ENABLEDELAYEDEXPANSION + +rem A good old 80s batch file, because it's guaranteed to always be available. +rem This assumes git is in the path. + +for /F %%I in ('git describe --always --dirty') do set GITVER=%%I +if "%GITVER%" == "" goto git_error + +rem Replace -dirty with -devel, to indicate builds with uncommitted changes. +set GITVER=%GITVER:-dirty=-devel% + +goto continue + +:git_error +rem If calling git fails for some reason, put a message in the version instead of +rem letting it be blank. +set GITVER=git failed + +:continue + +rem Output the current version to a temp file. +set TEMP_FILE=%TEMP%\temp-SMXBuildVersion.h +set OUTPUT_FILE=SMXBuildVersion.h + +echo // This file is auto-generated by update-build-version.bat. > %TEMP_FILE% +echo. >> %TEMP_FILE% +echo #ifndef SMXBuildVersion_h >> %TEMP_FILE% +echo #define SMXBuildVersion_h >> %TEMP_FILE% +echo. >> %TEMP_FILE% +echo #define SMX_BUILD_VERSION "%GITVER%" >> %TEMP_FILE% +echo. >> %TEMP_FILE% +echo #endif >> %TEMP_FILE% + +rem Compare the temp file to any existing file. Only copy the new file over the old +rem one if it's different, so we don't trigger dependency rebuilds every time. +fc %TEMP_FILE% %OUTPUT_FILE% > nul +if %errorlevel% == 0 goto end + +echo Updated to version %GITVER% +copy %TEMP_FILE% %OUTPUT_FILE% > nul + +:end diff --git a/smx-config/MainWindow.xaml b/smx-config/MainWindow.xaml index 7ff9bf4..74ed898 100644 --- a/smx-config/MainWindow.xaml +++ b/smx-config/MainWindow.xaml @@ -636,8 +636,11 @@ Use if the platform is too sensitive. - + + @@ -709,6 +712,13 @@ Use if the platform is too sensitive.